upgrade to 1.1.0

This commit is contained in:
ben committed 2026-10-23 18:49:11 +00:00
1 parent 02c95d89bb
commit f5893a107d
46 files changed
+3764 -2891

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
export function produceAgreement({ data, shortName, role, archive }: {
data: any;
shortName: any;
role: any;
archive: any;
}): Promise<any>;
export function processAgreement({ agreementId, shortName, role, archive }: {
agreementId: any;
shortName: any;
role: any;
archive: any;
}): Promise<any>;
export function getAgreement({ agreementId, includeSignatures }: {
agreementId: any;
includeSignatures: any;
}): Promise<any>;
+36
View File
@@ -0,0 +1,36 @@
"use strict";
const axios = require('axios');
const { getConfig, getDefault } = require('./config.js');
function _getUrl(path) {
const cfg = getConfig();
return `${cfg.apiUrl}${path}`;
}
function _headers(token) {
return {
'Authorization': `Bearer ${token || getConfig().apiKey}`,
};
}
async function produceAgreement({ data, shortName, role, archive }) {
const cfg = getConfig();
const defaultArchive = { url: cfg.archiveUrl, key: cfg.archiveKey };
return (await axios.post(_getUrl('/api/v1/data/agreement/produce'), {
data,
shortName,
role,
archive: archive || defaultArchive,
}, { headers: _headers() })).data;
}
async function processAgreement({ agreementId, shortName, role, archive }) {
const cfg = getConfig();
const defaultArchive = { url: cfg.archiveUrl, key: cfg.archiveKey };
return (await axios.post(_getUrl('/api/v1/data/agreement/process'), {
agreementId: agreementId || getDefault('agreementId'),
shortName,
role,
archive: archive || defaultArchive,
}, { headers: _headers() })).data;
}
async function getAgreement({ agreementId, includeSignatures }) {
return (await axios.post(_getUrl('/api/v1/data/agreement/get'), { agreementId: agreementId || getDefault('agreementId'), includeSignatures }, { headers: _headers() })).data;
}
module.exports = { produceAgreement, processAgreement, getAgreement };
+9
View File
@@ -0,0 +1,9 @@
export function getAudits({ agreementId, eventId, meta }: {
agreementId: any;
eventId: any;
meta: any;
}): Promise<any>;
export function verifyAudit({ audits, shortNames }: {
audits: any;
shortNames: any;
}): Promise<any>;
+23
View File
@@ -0,0 +1,23 @@
"use strict";
const axios = require('axios');
const { getConfig, getDefault } = require('./config.js');
function _getUrl(path) {
const cfg = getConfig();
return `${cfg.apiUrl}${path}`;
}
function _getArchiveUrl(path) {
const cfg = getConfig();
return `${cfg.archiveUrl}${path}`;
}
function _headers(token) {
return {
'Authorization': `Bearer ${token || getConfig().apiKey}`,
};
}
async function getAudits({ agreementId, eventId, meta }) {
return (await axios.post(_getArchiveUrl('/api/v1/audit/get'), { agreementId: agreementId || getDefault('agreementId'), eventId, meta }, { headers: _headers(getConfig().archiveKey) })).data;
}
async function verifyAudit({ audits, shortNames }) {
return (await axios.post(_getUrl('/api/v1/data/audit/verify'), { audits, shortNames }, { headers: _headers() })).data;
}
module.exports = { getAudits, verifyAudit };
+5
View File
@@ -0,0 +1,5 @@
export function auth({ subject, action, resource }: {
subject: any;
action: any;
resource: any;
}): Promise<any>;
+16
View File
@@ -0,0 +1,16 @@
"use strict";
const axios = require('axios');
const { getConfig } = require('./config.js');
function _getUrl(path) {
const cfg = getConfig();
return `${cfg.apiUrl}${path}`;
}
function _headers(token) {
return {
'Authorization': `Bearer ${token || getConfig().apiKey}`,
};
}
async function auth({ subject, action, resource }) {
return (await axios.post(_getUrl('/api/v1/auth'), { subject, action, resource }, { headers: _headers() })).data;
}
module.exports = { auth };
+4
View File
@@ -0,0 +1,4 @@
export function init(cfg: any, defaultOpts: any): void;
export function getConfig(): {};
export function getDefaults(): {};
export function getDefault(key: any): any;
+19
View File
@@ -0,0 +1,19 @@
"use strict";
let config = {};
let defaults = {};
function init(cfg, defaultOpts) {
config = { ...cfg };
if (defaultOpts) {
defaults = { ...defaultOpts };
}
}
function getConfig() {
return config;
}
function getDefaults() {
return defaults;
}
function getDefault(key) {
return defaults[key];
}
module.exports = { init, getConfig, getDefaults, getDefault };
+14
View File
@@ -0,0 +1,14 @@
export function getDomains({ fedidUrl, auth: authPayload }: {
fedidUrl: any;
auth: any;
}): Promise<any>;
export function getEntity({ shortName }: {
shortName: any;
}): Promise<axios.AxiosResponse<any, {
shortName: any;
}, {}, any>>;
export function createEntity({ fedidUrl, shortName }: {
fedidUrl: any;
shortName: any;
}): Promise<any>;
import axios = require("axios");
+30
View File
@@ -0,0 +1,30 @@
"use strict";
const axios = require('axios');
const { getConfig } = require('./config.js');
function _getUrl(path) {
const cfg = getConfig();
return `${cfg.apiUrl}${path}`;
}
function _headers(token) {
return {
'Authorization': `Bearer ${token || getConfig().apiKey}`,
};
}
async function getDomains({ fedidUrl, auth: authPayload }) {
const cfg = getConfig();
return (await axios.post(_getUrl('/api/v1/data/entity/domains/get'), {
fedidUrl: fedidUrl || cfg.fedidUrl,
auth: authPayload,
}, { headers: _headers() })).data;
}
async function createEntity({ fedidUrl, shortName }) {
const cfg = getConfig();
return (await axios.post(_getUrl('/api/v1/data/entity/create'), {
fedidUrl: fedidUrl || cfg.fedidUrl,
shortName,
}, { headers: _headers() })).data;
}
async function getEntity({ shortName }) {
return (await axios.post(_getUrl('/api/v1/data/entity/get'), { shortName }, { headers: _headers() }));
}
module.exports = { getDomains, getEntity, createEntity };
+18
View File
@@ -0,0 +1,18 @@
export function produceEvent({ type, senderShortName, recipientShortName, agreementId, meta, data, archive }: {
type: any;
senderShortName: any;
recipientShortName: any;
agreementId: any;
meta: any;
data: any;
archive: any;
}): Promise<any>;
export function getEvent({ eventId, meta }: {
eventId: any;
meta: any;
}): Promise<any>;
export function processEvent({ eventId, shortName, archive }: {
eventId: any;
shortName: any;
archive: any;
}): Promise<any>;
+38
View File
@@ -0,0 +1,38 @@
"use strict";
const axios = require('axios');
const { getConfig, getDefault } = require('./config.js');
function _getUrl(path) {
const cfg = getConfig();
return `${cfg.apiUrl}${path}`;
}
function _headers(token) {
return {
'Authorization': `Bearer ${token || getConfig().apiKey}`,
};
}
async function produceEvent({ type, senderShortName, recipientShortName, agreementId, meta, data, archive }) {
const cfg = getConfig();
const defaultArchive = { url: cfg.archiveUrl, key: cfg.archiveKey };
return (await axios.post(_getUrl('/api/v1/data/event/produce'), {
type,
senderShortName,
recipientShortName,
agreementId: agreementId || getDefault('agreementId'),
meta,
data,
archive: archive || defaultArchive,
}, { headers: _headers() })).data;
}
async function getEvent({ eventId, meta }) {
return (await axios.post(_getUrl('/api/v1/data/event/get'), { eventId, meta }, { headers: _headers() })).data;
}
async function processEvent({ eventId, shortName, archive }) {
const cfg = getConfig();
const defaultArchive = { url: cfg.archiveUrl, key: cfg.archiveKey };
return (await axios.post(_getUrl('/api/v1/data/event/process'), {
eventId,
shortName,
archive: archive || defaultArchive,
}, { headers: _headers() })).data;
}
module.exports = { produceEvent, getEvent, processEvent };
+13 -58
View File
@@ -1,58 +1,13 @@
export type JLINCConfig = {
debug?: boolean | undefined;
systemPrefix?: string | undefined;
defaultAgreementId?: string | undefined;
domain?: string | null | undefined;
dataStoreApiUrl?: string | null | undefined;
dataStoreApiKey?: string | null | undefined;
archiveApiUrl?: string | null | undefined;
archiveApiKey?: string | null | undefined;
};
export type JLINCProduceEventData = {
to?: string | undefined;
from?: string | undefined;
agreementId?: string | null | undefined;
payload?: any;
auth?: any;
};
export type JLINCProcessEventData = {
to?: string | undefined;
eventId?: string | undefined;
auth?: any;
};
export type JLINCProduceAgreementData = {
requiredSigners?: string[] | undefined;
signer?: string | undefined;
uri?: string | undefined;
purposes?: string[] | undefined;
caveats?: string[] | undefined;
validRoles?: string[] | undefined;
role?: string | undefined;
auth?: any;
};
export type JLINCProcessAgreementData = {
agreementId?: string | undefined;
signer?: string | undefined;
role?: string | undefined;
auth?: any;
};
/**
* @param {JLINCConfig} data - The configuration object for the application.
*/
export function jlincInit(data: JLINCConfig): void;
/**
* @param {JLINCProduceEventData} data - The data required for producing an event.
*/
export function jlincProduceEvent(data: JLINCProduceEventData): Promise<any>;
/**
* @param {JLINCProcessEventData} data - The data required for processing an event.
*/
export function jlincProcessEvent(data: JLINCProcessEventData): Promise<any>;
/**
* @param {JLINCProduceAgreementData} data - The data required for producing an agreement.
*/
export function jlincProduceAgreement(data: JLINCProduceAgreementData): Promise<any>;
/**
* @param {JLINCProcessAgreementData} data - The data required for processing an agreement.
*/
export function jlincProcessAgreement(data: JLINCProcessAgreementData): Promise<any>;
export let init: typeof import("./config.js").init;
export let auth: typeof import("./auth.js").auth;
export let getDomains: typeof import("./entity.js").getDomains;
export let getEntity: typeof import("./entity.js").getEntity;
export let createEntity: typeof import("./entity.js").createEntity;
export let produceAgreement: typeof import("./agreement.js").produceAgreement;
export let processAgreement: typeof import("./agreement.js").processAgreement;
export let getAgreement: typeof import("./agreement.js").getAgreement;
export let produceEvent: typeof import("./event.js").produceEvent;
export let getEvent: typeof import("./event.js").getEvent;
export let processEvent: typeof import("./event.js").processEvent;
export let getAudits: typeof import("./audit.js").getAudits;
export let verifyAudit: typeof import("./audit.js").verifyAudit;
+15 -262
View File
@@ -1,263 +1,16 @@
const axios = require("axios");
/**
* @typedef {Object} JLINCConfig
* @property {boolean} [debug]
* @property {string} [systemPrefix]
* @property {string} [defaultAgreementId]
* @property {string|null} [domain]
* @property {string|null} [dataStoreApiUrl]
* @property {string|null} [dataStoreApiKey]
* @property {string|null} [archiveApiUrl]
* @property {string|null} [archiveApiKey]
*/
/**
* @typedef {Object} JLINCProduceEventData
* @property {string} [to]
* @property {string} [from]
* @property {string|null} [agreementId]
* @property {any} [payload]
* @property {any} [auth]
*/
/**
* @typedef {Object} JLINCProcessEventData
* @property {string} [to]
* @property {string} [eventId]
* @property {any} [auth]
*/
/**
* @typedef {Object} JLINCProduceAgreementData
* @property {Array<string>} [requiredSigners]
* @property {string} [signer]
* @property {string} [uri]
* @property {Array<string>} [purposes]
* @property {Array<string>} [caveats]
* @property {Array<string>} [validRoles]
* @property {string} [role]
* @property {any} [auth]
*/
/**
* @typedef {Object} JLINCProcessAgreementData
* @property {string} [agreementId]
* @property {string} [signer]
* @property {string} [role]
* @property {any} [auth]
*/
/**
* @param {JLINCConfig} config - The configuration object for the library
*/
let config = {
debug: false,
systemPrefix: 'my-system',
defaultAgreementId: '00000000-0000-0000-0000-000000000000',
domain: null,
dataStoreApiUrl: null,
dataStoreApiKey: null,
archiveApiUrl: null,
archiveApiKey: null,
}
const entities = new Set();
/**
* @param {string} input
* @returns {string}
*/
function sanitize(input) {
return input.replace(/[^a-zA-Z0-9._-]/g, '_');
}
/**
* @param {string} dir
* @param {any} payload
* @returns {Promise<any>}
*/
async function postToApi(dir, payload) {
const response = await axios.post(
`${config.dataStoreApiUrl}/api/v1/data/${dir}`,
payload,
{
headers: {
'Authorization': `Bearer ${config.dataStoreApiKey}`,
}
}
);
return response.data;
}
/**
* @param {string} entityShortName
* @returns {Promise<string>}
*/
async function setEntity(name) {
const entityShortName = `${config.systemPrefix}-${sanitize(name)}@${config.domain}`;
if (!entities.has(entityShortName)) {
try {
await postToApi(`entity/get`, { shortName: entityShortName });
} catch (e) {
await postToApi(`entity/create`, { shortName: entityShortName });
}
entities.add(entityShortName);
}
return entityShortName
}
/**
* @param {JLINCConfig} data - The configuration object for the application.
*/
function jlincInit(data) {
config = {
...config,
...data,
}
}
async function getDomain() {
if (!config.domain) {
const domains = await postToApi(`entity/domains/get`, {});
config.domain = domains[0];
}
}
/**
* @param {JLINCProduceEventData} data - The data required for producing an event.
*/
async function jlincProduceEvent(data) {
let res = null;
try {
await getDomain();
const senderShortName = await setEntity(data.from)
const recipientShortName = await setEntity(data.to)
const agreementId = data.agreementId ?? config.defaultAgreementId;
const postData = {
type: 'data',
senderShortName,
recipientShortName,
agreementId,
data: data.payload,
archive: {
url: config.archiveApiUrl,
key: config.archiveApiKey,
}
};
if (data.auth) postData.auth = data.auth;
res = await postToApi(`event/produce`, postData);
if (config.debug) {
console.log(JSON.stringify({ res }, null, 2));
}
} catch (error) {
console.error("[JLINC] Failed to produce event:", error.message);
if (config.debug) console.error(error)
}
return res;
}
/**
* @param {JLINCProcessEventData} data - The data required for processing an event.
*/
async function jlincProcessEvent(data) {
let res = null;
try {
await getDomain();
const shortName = await setEntity(data.to)
const postData = {
type: 'data',
shortName,
eventId: data.eventId,
archive: {
url: config.archiveApiUrl,
key: config.archiveApiKey,
}
};
if (data.auth) postData.auth = data.auth;
res = await postToApi(`event/process`, postData);
if (config.debug) {
console.log(JSON.stringify({ res }, null, 2));
}
} catch (error) {
console.error("[JLINC] Failed to process event:", error.message);
if (config.debug) console.error(error)
}
return res;
}
/**
* @param {JLINCProduceAgreementData} data - The data required for producing an agreement.
*/
async function jlincProduceAgreement(data) {
let res = null;
try {
await getDomain();
const shortNames = [];
for (const id of data.requiredSigners) {
shortNames.push(await setEntity(id))
}
const shortName = await setEntity(data.signer)
const postData = {
data: {
uri: data.uri,
purposes: data.purposes,
caveats: data.caveats,
shortNames,
validRoles: data.validRoles,
},
shortName,
role: data.role,
archive: {
url: config.archiveApiUrl,
key: config.archiveApiKey,
}
};
if (data.auth) postData.auth = data.auth;
res = await postToApi(`agreement/produce`, postData);
if (config.debug) {
console.log(JSON.stringify({ res }, null, 2));
}
} catch (error) {
console.error("[JLINC] Failed to produce agreement:", error.message);
if (config.debug) console.error(error)
}
return res;
}
/**
* @param {JLINCProcessAgreementData} data - The data required for processing an agreement.
*/
async function jlincProcessAgreement(data) {
let res = null;
try {
await getDomain();
const shortName = await setEntity(data.signer)
const postData = {
agreementId: data.agreementId,
shortName,
role: data.role,
archive: {
url: config.archiveApiUrl,
key: config.archiveApiKey,
}
};
if (data.auth) postData.auth = data.auth;
res = await postToApi(`agreement/process`, postData);
if (config.debug) {
console.log(JSON.stringify({ res }, null, 2));
}
} catch (error) {
console.error("[JLINC] Failed to process agreement:", error.message);
if (config.debug) console.error(error)
}
return res;
}
"use strict";
module.exports = {
jlincInit,
jlincProduceEvent,
jlincProcessEvent,
jlincProduceAgreement,
jlincProcessAgreement,
}
init: require('./config.js').init,
auth: require('./auth.js').auth,
getDomains: require('./entity.js').getDomains,
getEntity: require('./entity.js').getEntity,
createEntity: require('./entity.js').createEntity,
produceAgreement: require('./agreement.js').produceAgreement,
processAgreement: require('./agreement.js').processAgreement,
getAgreement: require('./agreement.js').getAgreement,
produceEvent: require('./event.js').produceEvent,
getEvent: require('./event.js').getEvent,
processEvent: require('./event.js').processEvent,
getAudits: require('./audit.js').getAudits,
verifyAudit: require('./audit.js').verifyAudit,
};
+1
View File
@@ -0,0 +1 @@
export { init, getConfig, getDefaults, getDefault } from "./config.js";
+8
View File
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDefault = exports.getDefaults = exports.getConfig = exports.init = void 0;
var config_js_1 = require("./config.js");
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return config_js_1.init; } });
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_js_1.getConfig; } });
Object.defineProperty(exports, "getDefaults", { enumerable: true, get: function () { return config_js_1.getDefaults; } });
Object.defineProperty(exports, "getDefault", { enumerable: true, get: function () { return config_js_1.getDefault; } });
+2
View File
@@ -0,0 +1,2 @@
const jlinc = require('./index.js');
module.exports = jlinc;
+16
View File
@@ -0,0 +1,16 @@
declare const _exports: {
init: (cfg: object, defaultOpts?: object) => void;
auth: (params: { subject: any; action: any; resource: any }) => Promise<any>;
getDomains: (params: { fedidUrl?: string; auth?: any }) => Promise<any>;
getEntity: (params: { shortName: string }) => Promise<any>;
createEntity: (params: { fedidUrl?: string; shortName: string }) => Promise<any>;
produceAgreement: (params: { data: any; shortName: string; role: string; archive?: any }) => Promise<any>;
processAgreement: (params: { agreementId?: string; shortName: string; role: string; archive?: any }) => Promise<any>;
getAgreement: (params: { agreementId?: string; includeSignatures?: boolean }) => Promise<any>;
produceEvent: (params: { type: string; senderShortName: string; recipientShortName: string; agreementId?: string; meta?: any; data: any; archive?: any }) => Promise<any>;
getEvent: (params: { eventId?: string; meta?: any }) => Promise<any>;
processEvent: (params: { eventId: string; shortName: string; archive?: any }) => Promise<any>;
getAudits: (params: { agreementId?: string; eventId?: string; meta?: any }) => Promise<any>;
verifyAudit: (params: { audits: string[]; shortNames: string[] }) => Promise<any>;
};
export = _exports;
+13
View File
@@ -0,0 +1,13 @@
export function init(cfg: object, defaultOpts?: object): void;
export function auth(params: { subject: any; action: any; resource: any }): Promise<any>;
export function getDomains(params: { fedidUrl?: string; auth?: any }): Promise<any>;
export function getEntity(params: { shortName: string }): Promise<any>;
export function createEntity(params: { fedidUrl?: string; shortName: string }): Promise<any>;
export function produceAgreement(params: { data: any; shortName: string; role: string; archive?: any }): Promise<any>;
export function processAgreement(params: { agreementId?: string; shortName: string; role: string; archive?: any }): Promise<any>;
export function getAgreement(params: { agreementId?: string; includeSignatures?: boolean }): Promise<any>;
export function produceEvent(params: { type: string; senderShortName: string; recipientShortName: string; agreementId?: string; meta?: any; data: any; archive?: any }): Promise<any>;
export function getEvent(params: { eventId?: string; meta?: any }): Promise<any>;
export function processEvent(params: { eventId: string; shortName: string; archive?: any }): Promise<any>;
export function getAudits(params: { agreementId?: string; eventId?: string; meta?: any }): Promise<any>;
export function verifyAudit(params: { audits: string[]; shortNames: string[] }): Promise<any>;
+9
View File
@@ -0,0 +1,9 @@
import jlinc from './index.js';
export const { init, getConfig, getDefaults, getDefault } = jlinc;
export const { auth } = jlinc;
export const { getDomains, getEntity, createEntity } = jlinc;
export const { produceAgreement, processAgreement, getAgreement } = jlinc;
export const { produceEvent, getEvent, processEvent } = jlinc;
export const { getAudits, verifyAudit } = jlinc;
export default jlinc;