@things-factory/guild-overlay 0.0.0-stage → 10.1.313
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/capture.d.ts +8 -0
- package/dist-server/capture.js +36 -0
- package/dist-server/contract.d.ts +73 -0
- package/dist-server/contract.js +17 -0
- package/dist-server/define-kinds.d.ts +14 -0
- package/dist-server/define-kinds.js +63 -0
- package/dist-server/emit.d.ts +45 -0
- package/dist-server/emit.js +52 -0
- package/dist-server/hub-route.d.ts +27 -0
- package/dist-server/hub-route.js +51 -0
- package/dist-server/index.d.ts +14 -0
- package/dist-server/index.js +33 -0
- package/dist-server/manifest-boot.d.ts +5 -0
- package/dist-server/manifest-boot.js +43 -0
- package/dist-server/record-rules.d.ts +73 -0
- package/dist-server/record-rules.js +121 -0
- package/dist-server/seams/activity-callback-seam.d.ts +2 -0
- package/dist-server/seams/activity-callback-seam.js +20 -0
- package/dist-server/seams/fact-change-seam.d.ts +24 -0
- package/dist-server/seams/fact-change-seam.js +48 -0
- package/dist-server/settings.d.ts +70 -0
- package/dist-server/settings.js +64 -0
- package/package.json +46 -4
- package/things-factory.config.js +1 -0
- package/translations/en.json +9 -0
- package/translations/es.json +9 -0
- package/translations/ja.json +9 -0
- package/translations/ko.json +9 -0
- package/translations/ms.json +9 -0
- package/translations/zh.json +9 -0
- package/README.md +0 -3
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type EntityManager, type EntitySubscriberInterface, type TransactionStartEvent } from 'typeorm';
|
|
2
|
+
import type { ContributionRecord } from './contract.js';
|
|
3
|
+
export declare function noteContribution(tx: EntityManager, record: ContributionRecord): void;
|
|
4
|
+
/** The facts emitted in this transaction, in the order they were. */
|
|
5
|
+
export declare function capturedContributions(tx: EntityManager): ContributionRecord[];
|
|
6
|
+
export declare class GuildCaptureSubscriber implements EntitySubscriberInterface {
|
|
7
|
+
afterTransactionStart(event: TransactionStartEvent): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GuildCaptureSubscriber = void 0;
|
|
4
|
+
exports.noteContribution = noteContribution;
|
|
5
|
+
exports.capturedContributions = capturedContributions;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const typeorm_1 = require("typeorm");
|
|
8
|
+
/*
|
|
9
|
+
* **What a transaction emitted** - for a product's tests: 「when this work finishes, one fact of that kind is made」
|
|
10
|
+
* (design §3-1). Kept per transaction runner, and forgotten when the runner starts its next top-level transaction - a
|
|
11
|
+
* pooled driver hands each transaction a runner of its own, but sqlite keeps one runner for every transaction, so the
|
|
12
|
+
* list would otherwise carry the last work's facts into the next. Readable during the work and after its commit.
|
|
13
|
+
*/
|
|
14
|
+
const CAPTURED = new WeakMap();
|
|
15
|
+
const keyOf = (tx) => tx.queryRunner ?? tx;
|
|
16
|
+
function noteContribution(tx, record) {
|
|
17
|
+
const key = keyOf(tx);
|
|
18
|
+
const list = CAPTURED.get(key) ?? [];
|
|
19
|
+
list.push(record);
|
|
20
|
+
CAPTURED.set(key, list);
|
|
21
|
+
}
|
|
22
|
+
/** The facts emitted in this transaction, in the order they were. */
|
|
23
|
+
function capturedContributions(tx) {
|
|
24
|
+
return [...(CAPTURED.get(keyOf(tx)) ?? [])];
|
|
25
|
+
}
|
|
26
|
+
let GuildCaptureSubscriber = class GuildCaptureSubscriber {
|
|
27
|
+
afterTransactionStart(event) {
|
|
28
|
+
if ((event.queryRunner.transactionDepth ?? 1) <= 1)
|
|
29
|
+
CAPTURED.delete(event.queryRunner);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.GuildCaptureSubscriber = GuildCaptureSubscriber;
|
|
33
|
+
exports.GuildCaptureSubscriber = GuildCaptureSubscriber = tslib_1.__decorate([
|
|
34
|
+
(0, typeorm_1.EventSubscriber)()
|
|
35
|
+
], GuildCaptureSubscriber);
|
|
36
|
+
//# sourceMappingURL=capture.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export declare const CONTRIBUTION_VERBS: readonly ["CREATED", "REVISED", "VERIFIED", "UTILIZED", "REVERTED", "COMPLETED"];
|
|
2
|
+
export type ContributionVerb = (typeof CONTRIBUTION_VERBS)[number];
|
|
3
|
+
export declare const CONTRIBUTION_LAYERS: readonly ["ONBOARD", "DILIGENCE", "CONTRIBUTION", "IMPACT"];
|
|
4
|
+
export type ContributionLayer = (typeof CONTRIBUTION_LAYERS)[number];
|
|
5
|
+
export declare const VERIFIER_KINDS: readonly ["HUMAN", "RULE", "SYSTEM"];
|
|
6
|
+
export type VerifierKind = (typeof VERIFIER_KINDS)[number];
|
|
7
|
+
/** The webhook scopes an application sends to the hub on (design §2-3). */
|
|
8
|
+
export declare const GUILD_SCOPES: {
|
|
9
|
+
readonly contribution: "contribution";
|
|
10
|
+
readonly manifest: "manifest";
|
|
11
|
+
readonly opportunity: "opportunity";
|
|
12
|
+
readonly metric: "metric";
|
|
13
|
+
};
|
|
14
|
+
/** A label in one or more languages - `{ ko, en }`. A plain string is read as every language's. */
|
|
15
|
+
export type GuildLabel = string | Record<string, string>;
|
|
16
|
+
/** One kind of contribution a product can send - declared once at boot (`defineContributionKinds`). */
|
|
17
|
+
export interface ContributionKind {
|
|
18
|
+
/** `office.counterparty.merged` - unique within the product. */
|
|
19
|
+
kind: string;
|
|
20
|
+
verb: ContributionVerb;
|
|
21
|
+
/** The product's proposal; a rule may override it. */
|
|
22
|
+
layer: ContributionLayer;
|
|
23
|
+
subjectType: string;
|
|
24
|
+
label: GuildLabel;
|
|
25
|
+
description?: GuildLabel;
|
|
26
|
+
/** The page the contribution happens on - where a quest leads and where the page's chip shows. */
|
|
27
|
+
route?: string;
|
|
28
|
+
/** One line for the prospect bubble. */
|
|
29
|
+
prospectHint?: GuildLabel;
|
|
30
|
+
/** The signal names this kind may carry. A signal not listed is dropped on the way in. */
|
|
31
|
+
signals?: string[];
|
|
32
|
+
}
|
|
33
|
+
/** The kinds of one product, with a version that changes when the list does. */
|
|
34
|
+
export interface ContributionManifest {
|
|
35
|
+
product: string;
|
|
36
|
+
version: string;
|
|
37
|
+
kinds: ContributionKind[];
|
|
38
|
+
}
|
|
39
|
+
/** A person as the sending application knows them - its own user id, and the company mail as a hint for binding. */
|
|
40
|
+
export interface ContributionPerson {
|
|
41
|
+
sourceUserId: string;
|
|
42
|
+
email?: string;
|
|
43
|
+
}
|
|
44
|
+
/** The canonical contribution fact (charter §5-2). Its application is not in it - the hub takes that from the source. */
|
|
45
|
+
export interface ContributionRecord {
|
|
46
|
+
v: 1;
|
|
47
|
+
factId: string;
|
|
48
|
+
kind: string;
|
|
49
|
+
verb: ContributionVerb;
|
|
50
|
+
subject: {
|
|
51
|
+
type: string;
|
|
52
|
+
id: string;
|
|
53
|
+
title?: string;
|
|
54
|
+
path?: string;
|
|
55
|
+
};
|
|
56
|
+
contributor: ContributionPerson;
|
|
57
|
+
verifier?: ContributionPerson;
|
|
58
|
+
verifierKind: VerifierKind;
|
|
59
|
+
/** When it was confirmed - ISO time. */
|
|
60
|
+
occurredAt: string;
|
|
61
|
+
/** The business day it belongs to - YYYY-MM-DD. */
|
|
62
|
+
eventAt?: string;
|
|
63
|
+
signals?: Record<string, number>;
|
|
64
|
+
evidence?: {
|
|
65
|
+
activityInstanceId?: string;
|
|
66
|
+
factChangeIds?: string[];
|
|
67
|
+
};
|
|
68
|
+
practice?: boolean;
|
|
69
|
+
/** For `REVERTED`: the fact it takes back. */
|
|
70
|
+
revertsFactId?: string;
|
|
71
|
+
/** For `REVERTED`: why, as a short code or line. */
|
|
72
|
+
reason?: string;
|
|
73
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* **What an application hands the guild hub** (operato-guild design §2-6 · §3-1) - the kinds it declares and the
|
|
4
|
+
* contribution facts it sends. One shape for both roads: the same server calls the hub inside the work's transaction,
|
|
5
|
+
* another server queues the same record on its webhook outbox. The hub reads the record again on arrival and keeps only
|
|
6
|
+
* what is listed here (`fact-rules.ts` in `@things-factory/guild`).
|
|
7
|
+
*
|
|
8
|
+
* No enums: the rule files that read these run under a strip-only runner.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.GUILD_SCOPES = exports.VERIFIER_KINDS = exports.CONTRIBUTION_LAYERS = exports.CONTRIBUTION_VERBS = void 0;
|
|
12
|
+
exports.CONTRIBUTION_VERBS = ['CREATED', 'REVISED', 'VERIFIED', 'UTILIZED', 'REVERTED', 'COMPLETED'];
|
|
13
|
+
exports.CONTRIBUTION_LAYERS = ['ONBOARD', 'DILIGENCE', 'CONTRIBUTION', 'IMPACT'];
|
|
14
|
+
exports.VERIFIER_KINDS = ['HUMAN', 'RULE', 'SYSTEM'];
|
|
15
|
+
/** The webhook scopes an application sends to the hub on (design §2-3). */
|
|
16
|
+
exports.GUILD_SCOPES = { contribution: 'contribution', manifest: 'manifest', opportunity: 'opportunity', metric: 'metric' };
|
|
17
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ContributionKind, type ContributionManifest } from './contract.js';
|
|
2
|
+
/** Once at boot - the contribution kinds this product can send. Declaring a product again replaces its list. */
|
|
3
|
+
export declare function defineContributionKinds(product: string, kinds: ContributionKind[]): void;
|
|
4
|
+
/** The declared kind and its product, or undefined for a kind nobody declared. */
|
|
5
|
+
export declare function declaredKind(kind: string): {
|
|
6
|
+
product: string;
|
|
7
|
+
kind: ContributionKind;
|
|
8
|
+
} | undefined;
|
|
9
|
+
/** The products that declared kinds, in the order they did. */
|
|
10
|
+
export declare function contributionProducts(): string[];
|
|
11
|
+
/** One product's manifest - its kinds and their version. */
|
|
12
|
+
export declare function contributionManifestOf(product: string): ContributionManifest | undefined;
|
|
13
|
+
/** For tests: forget every declaration. */
|
|
14
|
+
export declare function forgetContributionKinds(): void;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineContributionKinds = defineContributionKinds;
|
|
4
|
+
exports.declaredKind = declaredKind;
|
|
5
|
+
exports.contributionProducts = contributionProducts;
|
|
6
|
+
exports.contributionManifestOf = contributionManifestOf;
|
|
7
|
+
exports.forgetContributionKinds = forgetContributionKinds;
|
|
8
|
+
const contract_js_1 = require("./contract.js");
|
|
9
|
+
const record_rules_js_1 = require("./record-rules.js");
|
|
10
|
+
/*
|
|
11
|
+
* **The kinds each product declared at boot** (design §2-5 · §3-1). The hub on the same server reads them from here; an
|
|
12
|
+
* application whose hub is elsewhere sends them on the `manifest` scope.
|
|
13
|
+
*/
|
|
14
|
+
const BY_PRODUCT = new Map();
|
|
15
|
+
const PRODUCT_OF_KIND = new Map();
|
|
16
|
+
/** Once at boot - the contribution kinds this product can send. Declaring a product again replaces its list. */
|
|
17
|
+
function defineContributionKinds(product, kinds) {
|
|
18
|
+
if (!product)
|
|
19
|
+
throw new Error('defineContributionKinds needs the product name');
|
|
20
|
+
const seen = new Set();
|
|
21
|
+
for (const one of kinds) {
|
|
22
|
+
if (!one?.kind || !/^[a-z0-9][a-z0-9._-]*$/.test(one.kind))
|
|
23
|
+
throw new Error(`${product}: '${one?.kind}' is not a contribution kind name`);
|
|
24
|
+
if (seen.has(one.kind))
|
|
25
|
+
throw new Error(`${product}: '${one.kind}' is declared twice`);
|
|
26
|
+
if (!contract_js_1.CONTRIBUTION_VERBS.includes(one.verb))
|
|
27
|
+
throw new Error(`${product}: '${one.kind}' has no verb the guild knows`);
|
|
28
|
+
if (!contract_js_1.CONTRIBUTION_LAYERS.includes(one.layer))
|
|
29
|
+
throw new Error(`${product}: '${one.kind}' has no layer the guild knows`);
|
|
30
|
+
if (!one.subjectType || !one.label)
|
|
31
|
+
throw new Error(`${product}: '${one.kind}' names its subject type and label`);
|
|
32
|
+
const owner = PRODUCT_OF_KIND.get(one.kind);
|
|
33
|
+
if (owner && owner !== product)
|
|
34
|
+
throw new Error(`${product}: '${one.kind}' is already declared by ${owner}`);
|
|
35
|
+
seen.add(one.kind);
|
|
36
|
+
}
|
|
37
|
+
for (const one of BY_PRODUCT.get(product) ?? [])
|
|
38
|
+
PRODUCT_OF_KIND.delete(one.kind);
|
|
39
|
+
BY_PRODUCT.set(product, kinds.map(one => ({ ...one })));
|
|
40
|
+
for (const one of kinds)
|
|
41
|
+
PRODUCT_OF_KIND.set(one.kind, product);
|
|
42
|
+
}
|
|
43
|
+
/** The declared kind and its product, or undefined for a kind nobody declared. */
|
|
44
|
+
function declaredKind(kind) {
|
|
45
|
+
const product = PRODUCT_OF_KIND.get(kind);
|
|
46
|
+
const found = product && BY_PRODUCT.get(product)?.find(one => one.kind === kind);
|
|
47
|
+
return found ? { product, kind: found } : undefined;
|
|
48
|
+
}
|
|
49
|
+
/** The products that declared kinds, in the order they did. */
|
|
50
|
+
function contributionProducts() {
|
|
51
|
+
return [...BY_PRODUCT.keys()];
|
|
52
|
+
}
|
|
53
|
+
/** One product's manifest - its kinds and their version. */
|
|
54
|
+
function contributionManifestOf(product) {
|
|
55
|
+
const kinds = BY_PRODUCT.get(product);
|
|
56
|
+
return kinds ? (0, record_rules_js_1.manifestOf)(product, kinds) : undefined;
|
|
57
|
+
}
|
|
58
|
+
/** For tests: forget every declaration. */
|
|
59
|
+
function forgetContributionKinds() {
|
|
60
|
+
BY_PRODUCT.clear();
|
|
61
|
+
PRODUCT_OF_KIND.clear();
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=define-kinds.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { EntityManager } from 'typeorm';
|
|
2
|
+
import type { VerifierKind } from './contract.js';
|
|
3
|
+
type UserLike = {
|
|
4
|
+
id: string;
|
|
5
|
+
email?: string | null;
|
|
6
|
+
userType?: string | null;
|
|
7
|
+
};
|
|
8
|
+
export interface ContributionFactInput {
|
|
9
|
+
/** A declared kind. */
|
|
10
|
+
kind: string;
|
|
11
|
+
subject: {
|
|
12
|
+
type: string;
|
|
13
|
+
id: string;
|
|
14
|
+
title?: string;
|
|
15
|
+
path?: string;
|
|
16
|
+
};
|
|
17
|
+
/** Who did the work. */
|
|
18
|
+
contributor: UserLike;
|
|
19
|
+
/** Who confirmed it - empty when a rule or the system did. */
|
|
20
|
+
verifier?: UserLike;
|
|
21
|
+
verifierKind?: VerifierKind;
|
|
22
|
+
/** The business day. */
|
|
23
|
+
eventAt?: Date;
|
|
24
|
+
signals?: Record<string, number>;
|
|
25
|
+
evidence?: {
|
|
26
|
+
activityInstanceId?: string;
|
|
27
|
+
factChangeIds?: string[];
|
|
28
|
+
};
|
|
29
|
+
practice?: boolean;
|
|
30
|
+
/** When one record is confirmed more than once - `approved` · `paid`. */
|
|
31
|
+
stage?: string;
|
|
32
|
+
}
|
|
33
|
+
export declare function emitContribution(tx: EntityManager, domain: {
|
|
34
|
+
id: string;
|
|
35
|
+
}, fact: ContributionFactInput): Promise<void>;
|
|
36
|
+
/** A confirmation taken back - undone, deleted or deactivated. Points at the original fact's key. */
|
|
37
|
+
export declare function emitContributionReverted(tx: EntityManager, domain: {
|
|
38
|
+
id: string;
|
|
39
|
+
}, input: {
|
|
40
|
+
kind: string;
|
|
41
|
+
factId: string;
|
|
42
|
+
reason: string;
|
|
43
|
+
actor: UserLike;
|
|
44
|
+
}): Promise<void>;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emitContribution = emitContribution;
|
|
4
|
+
exports.emitContributionReverted = emitContributionReverted;
|
|
5
|
+
const capture_js_1 = require("./capture.js");
|
|
6
|
+
const define_kinds_js_1 = require("./define-kinds.js");
|
|
7
|
+
const hub_route_js_1 = require("./hub-route.js");
|
|
8
|
+
const record_rules_js_1 = require("./record-rules.js");
|
|
9
|
+
function kindOrThrow(kind) {
|
|
10
|
+
const declared = (0, define_kinds_js_1.declaredKind)(kind);
|
|
11
|
+
if (!declared)
|
|
12
|
+
throw new Error(`guild: '${kind}' is not a declared contribution kind - declare it with defineContributionKinds`);
|
|
13
|
+
return declared;
|
|
14
|
+
}
|
|
15
|
+
async function emitContribution(tx, domain, fact) {
|
|
16
|
+
const declared = kindOrThrow(fact.kind);
|
|
17
|
+
if (!fact.contributor?.id || (0, record_rules_js_1.isMachineUser)(fact.contributor))
|
|
18
|
+
return;
|
|
19
|
+
const road = await (0, hub_route_js_1.hubRoadOf)(tx, domain);
|
|
20
|
+
if (road.kind === 'off')
|
|
21
|
+
return;
|
|
22
|
+
const record = (0, record_rules_js_1.contributionRecordOf)({
|
|
23
|
+
product: declared.product,
|
|
24
|
+
domainId: domain.id,
|
|
25
|
+
kind: declared.kind,
|
|
26
|
+
subject: fact.subject,
|
|
27
|
+
contributor: fact.contributor,
|
|
28
|
+
verifier: fact.verifier,
|
|
29
|
+
verifierKind: fact.verifierKind,
|
|
30
|
+
eventAt: fact.eventAt,
|
|
31
|
+
signals: fact.signals,
|
|
32
|
+
evidence: fact.evidence,
|
|
33
|
+
practice: fact.practice,
|
|
34
|
+
stage: fact.stage,
|
|
35
|
+
now: new Date()
|
|
36
|
+
});
|
|
37
|
+
(0, capture_js_1.noteContribution)(tx, record);
|
|
38
|
+
await (0, hub_route_js_1.handToHub)(tx, domain, road, declared.product, [record]);
|
|
39
|
+
}
|
|
40
|
+
/** A confirmation taken back - undone, deleted or deactivated. Points at the original fact's key. */
|
|
41
|
+
async function emitContributionReverted(tx, domain, input) {
|
|
42
|
+
const declared = kindOrThrow(input.kind);
|
|
43
|
+
if (!input.factId || !input.actor?.id)
|
|
44
|
+
return;
|
|
45
|
+
const road = await (0, hub_route_js_1.hubRoadOf)(tx, domain);
|
|
46
|
+
if (road.kind === 'off')
|
|
47
|
+
return;
|
|
48
|
+
const record = (0, record_rules_js_1.revertRecordOf)({ kind: declared.kind, factId: input.factId, reason: input.reason, actor: input.actor, now: new Date() });
|
|
49
|
+
(0, capture_js_1.noteContribution)(tx, record);
|
|
50
|
+
await (0, hub_route_js_1.handToHub)(tx, domain, road, declared.product, [record]);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=emit.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { EntityManager } from 'typeorm';
|
|
2
|
+
import { type ContributionRecord } from './contract.js';
|
|
3
|
+
export interface LocalGuildHub {
|
|
4
|
+
/** Take these records for the application in this transaction - what the intake door does with a remote batch. */
|
|
5
|
+
accept(tx: EntityManager, domain: {
|
|
6
|
+
id: string;
|
|
7
|
+
}, application: string, records: ContributionRecord[]): Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
export declare function registerLocalGuildHub(hub: LocalGuildHub): void;
|
|
10
|
+
/** For tests. */
|
|
11
|
+
export declare function forgetLocalGuildHub(): void;
|
|
12
|
+
export type HubRoad = {
|
|
13
|
+
kind: 'off';
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'local';
|
|
16
|
+
hub: LocalGuildHub;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'remote';
|
|
19
|
+
peer: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function hubRoadOf(tx: EntityManager, domain: {
|
|
22
|
+
id: string;
|
|
23
|
+
}): Promise<HubRoad>;
|
|
24
|
+
/** Hand records over on the road the domain's settings name. */
|
|
25
|
+
export declare function handToHub(tx: EntityManager, domain: {
|
|
26
|
+
id: string;
|
|
27
|
+
}, road: HubRoad, application: string, records: ContributionRecord[]): Promise<void>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerLocalGuildHub = registerLocalGuildHub;
|
|
4
|
+
exports.forgetLocalGuildHub = forgetLocalGuildHub;
|
|
5
|
+
exports.hubRoadOf = hubRoadOf;
|
|
6
|
+
exports.handToHub = handToHub;
|
|
7
|
+
const env_1 = require("@things-factory/env");
|
|
8
|
+
const webhook_1 = require("@things-factory/webhook");
|
|
9
|
+
const contract_js_1 = require("./contract.js");
|
|
10
|
+
const settings_js_1 = require("./settings.js");
|
|
11
|
+
let localHub;
|
|
12
|
+
function registerLocalGuildHub(hub) {
|
|
13
|
+
localHub = hub;
|
|
14
|
+
}
|
|
15
|
+
/** For tests. */
|
|
16
|
+
function forgetLocalGuildHub() {
|
|
17
|
+
localHub = undefined;
|
|
18
|
+
}
|
|
19
|
+
const warned = new Set();
|
|
20
|
+
function warnOnce(key, what) {
|
|
21
|
+
if (warned.has(key))
|
|
22
|
+
return;
|
|
23
|
+
warned.add(key);
|
|
24
|
+
env_1.logger.warn(`[guild-overlay] ${what}`);
|
|
25
|
+
}
|
|
26
|
+
async function hubRoadOf(tx, domain) {
|
|
27
|
+
const place = await (0, settings_js_1.guildPlaceOf)(domain, tx);
|
|
28
|
+
if (!place.enabled)
|
|
29
|
+
return { kind: 'off' };
|
|
30
|
+
if (place.hub && localHub) {
|
|
31
|
+
if (place.hubPeer)
|
|
32
|
+
warnOnce(`both:${domain.id}`, `domain ${domain.id}: Guild::hub and Guild::hubPeer are both set - the hub on this server is used`);
|
|
33
|
+
return { kind: 'local', hub: localHub };
|
|
34
|
+
}
|
|
35
|
+
if (place.hub && !localHub)
|
|
36
|
+
warnOnce(`nohub:${domain.id}`, `domain ${domain.id}: Guild::hub is on but this server carries no guild hub module`);
|
|
37
|
+
if (place.hubPeer)
|
|
38
|
+
return { kind: 'remote', peer: place.hubPeer };
|
|
39
|
+
return { kind: 'off' };
|
|
40
|
+
}
|
|
41
|
+
/** Hand records over on the road the domain's settings name. */
|
|
42
|
+
async function handToHub(tx, domain, road, application, records) {
|
|
43
|
+
if (!records.length || road.kind === 'off')
|
|
44
|
+
return;
|
|
45
|
+
if (road.kind === 'local') {
|
|
46
|
+
await road.hub.accept(tx, domain, application, records);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
(0, webhook_1.queueOutboxAtCommit)(tx, { domainId: domain.id, peer: road.peer, scope: contract_js_1.GUILD_SCOPES.contribution }, records.map(record => ({ record, eventId: record.factId, eventTime: new Date(record.occurredAt) })));
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=hub-route.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GuildCaptureSubscriber } from './capture.js';
|
|
2
|
+
import { GuildFactChangeSeam } from './seams/fact-change-seam.js';
|
|
3
|
+
export * from './contract.js';
|
|
4
|
+
export * from './settings.js';
|
|
5
|
+
export * from './define-kinds.js';
|
|
6
|
+
export * from './hub-route.js';
|
|
7
|
+
export * from './emit.js';
|
|
8
|
+
export * from './capture.js';
|
|
9
|
+
export * from './manifest-boot.js';
|
|
10
|
+
export * from './seams/fact-change-seam.js';
|
|
11
|
+
export * from './seams/activity-callback-seam.js';
|
|
12
|
+
export { contributionFactId, revertFactId, manifestOf, keptSignals, stableJson } from './record-rules.js';
|
|
13
|
+
/** Loaded by the shell from every module: a transaction's captured facts reset, and the fact-change seam (§3-3). */
|
|
14
|
+
export declare const subscribers: (typeof GuildCaptureSubscriber | typeof GuildFactChangeSeam)[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subscribers = exports.stableJson = exports.keptSignals = exports.manifestOf = exports.revertFactId = exports.contributionFactId = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const env_1 = require("@things-factory/env");
|
|
6
|
+
const capture_js_1 = require("./capture.js");
|
|
7
|
+
const manifest_boot_js_1 = require("./manifest-boot.js");
|
|
8
|
+
const fact_change_seam_js_1 = require("./seams/fact-change-seam.js");
|
|
9
|
+
tslib_1.__exportStar(require("./contract.js"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./settings.js"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./define-kinds.js"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./hub-route.js"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./emit.js"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./capture.js"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./manifest-boot.js"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./seams/fact-change-seam.js"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./seams/activity-callback-seam.js"), exports);
|
|
18
|
+
var record_rules_js_1 = require("./record-rules.js");
|
|
19
|
+
Object.defineProperty(exports, "contributionFactId", { enumerable: true, get: function () { return record_rules_js_1.contributionFactId; } });
|
|
20
|
+
Object.defineProperty(exports, "revertFactId", { enumerable: true, get: function () { return record_rules_js_1.revertFactId; } });
|
|
21
|
+
Object.defineProperty(exports, "manifestOf", { enumerable: true, get: function () { return record_rules_js_1.manifestOf; } });
|
|
22
|
+
Object.defineProperty(exports, "keptSignals", { enumerable: true, get: function () { return record_rules_js_1.keptSignals; } });
|
|
23
|
+
Object.defineProperty(exports, "stableJson", { enumerable: true, get: function () { return record_rules_js_1.stableJson; } });
|
|
24
|
+
/** Loaded by the shell from every module: a transaction's captured facts reset, and the fact-change seam (§3-3). */
|
|
25
|
+
exports.subscribers = [capture_js_1.GuildCaptureSubscriber, fact_change_seam_js_1.GuildFactChangeSeam];
|
|
26
|
+
/*
|
|
27
|
+
* The guild overlay (operato-guild design §3): every application loads it; a product declares its contribution kinds in
|
|
28
|
+
* its own `server/guild/` and emits facts from the work that confirms them. Off (`Guild::enabled`), nothing happens.
|
|
29
|
+
*/
|
|
30
|
+
process.on('bootstrap-module-start', () => {
|
|
31
|
+
(0, manifest_boot_js_1.sendManifestsAtBoot)().catch(error => env_1.logger.error(`[guild-overlay] sending the contribution kinds failed - ${String(error).slice(0, 200)}`));
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queueManifestsFor = queueManifestsFor;
|
|
4
|
+
exports.sendManifestsAtBoot = sendManifestsAtBoot;
|
|
5
|
+
const env_1 = require("@things-factory/env");
|
|
6
|
+
const shell_1 = require("@things-factory/shell");
|
|
7
|
+
const webhook_1 = require("@things-factory/webhook");
|
|
8
|
+
const contract_js_1 = require("./contract.js");
|
|
9
|
+
const define_kinds_js_1 = require("./define-kinds.js");
|
|
10
|
+
const hub_route_js_1 = require("./hub-route.js");
|
|
11
|
+
/*
|
|
12
|
+
* **The kinds go to a hub on another server at boot** (design §2-5 · §3-2) - one envelope per product, `{ manifest }`, on
|
|
13
|
+
* the same numbered line as the facts, so the hub never reads a fact before the list that declares its kind. The hub changes its kind table only when the version changed, so sending at every boot
|
|
14
|
+
* costs one row. A hub on this server reads the kinds from this module directly and needs none.
|
|
15
|
+
*
|
|
16
|
+
* A domain that sends to another server needs the outbox pump; it is started here - starting it twice does nothing.
|
|
17
|
+
*/
|
|
18
|
+
async function queueManifestsFor(tx, domain) {
|
|
19
|
+
const road = await (0, hub_route_js_1.hubRoadOf)(tx, domain);
|
|
20
|
+
if (road.kind !== 'remote')
|
|
21
|
+
return 0;
|
|
22
|
+
const manifests = (0, define_kinds_js_1.contributionProducts)()
|
|
23
|
+
.map(product => (0, define_kinds_js_1.contributionManifestOf)(product))
|
|
24
|
+
.filter(Boolean);
|
|
25
|
+
return (0, webhook_1.queueOutboxAtCommit)(tx, { domainId: domain.id, peer: road.peer, scope: contract_js_1.GUILD_SCOPES.contribution }, manifests.map(manifest => ({ record: { manifest }, eventId: `manifest:${manifest.product}:${manifest.version}:${Date.now()}` })));
|
|
26
|
+
}
|
|
27
|
+
async function sendManifestsAtBoot() {
|
|
28
|
+
if (!(0, define_kinds_js_1.contributionProducts)().length)
|
|
29
|
+
return;
|
|
30
|
+
const domains = await (0, shell_1.getRepository)(shell_1.Domain).find();
|
|
31
|
+
let remote = 0;
|
|
32
|
+
for (const domain of domains) {
|
|
33
|
+
try {
|
|
34
|
+
remote += await (0, shell_1.getRepository)(shell_1.Domain).manager.transaction(tx => queueManifestsFor(tx, domain));
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
env_1.logger.warn(`[guild-overlay] domain ${domain.subdomain}: the contribution kinds were not queued - ${String(error).slice(0, 200)}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (remote)
|
|
41
|
+
(0, webhook_1.startWebhookPump)();
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=manifest-boot.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ContributionKind, ContributionManifest, ContributionPerson, ContributionRecord, VerifierKind } from './contract.js';
|
|
2
|
+
/** The same parts give the same key, so a resent fact is counted once by the hub. */
|
|
3
|
+
export declare function contributionFactId(parts: {
|
|
4
|
+
product: string;
|
|
5
|
+
domainId: string;
|
|
6
|
+
kind: string;
|
|
7
|
+
subjectId: string;
|
|
8
|
+
stage?: string;
|
|
9
|
+
}): string;
|
|
10
|
+
/** The key of the fact that takes `factId` back - one revert per fact, however often it is sent. */
|
|
11
|
+
export declare function revertFactId(factId: string): string;
|
|
12
|
+
/** Whether a user is a machine account - those never earn (auth-base `userType`: `application` · `appliance`). */
|
|
13
|
+
export declare function isMachineUser(user: {
|
|
14
|
+
userType?: string | null;
|
|
15
|
+
} | null | undefined): boolean;
|
|
16
|
+
/** The person as the hub reads them - this server's user id, and the mail in lower case. */
|
|
17
|
+
export declare function personOf(user: {
|
|
18
|
+
id: string;
|
|
19
|
+
email?: string | null;
|
|
20
|
+
}): ContributionPerson;
|
|
21
|
+
/** Finite numbers only, and only the names the kind lists when it lists any. */
|
|
22
|
+
export declare function keptSignals(signals: Record<string, unknown> | undefined, allowed?: readonly string[]): Record<string, number> | undefined;
|
|
23
|
+
/** YYYY-MM-DD of a date, in the server's calendar. */
|
|
24
|
+
export declare function dayOf(date: Date): string;
|
|
25
|
+
export interface RecordInput {
|
|
26
|
+
product: string;
|
|
27
|
+
domainId: string;
|
|
28
|
+
kind: ContributionKind;
|
|
29
|
+
subject: {
|
|
30
|
+
type: string;
|
|
31
|
+
id: string;
|
|
32
|
+
title?: string;
|
|
33
|
+
path?: string;
|
|
34
|
+
};
|
|
35
|
+
contributor: {
|
|
36
|
+
id: string;
|
|
37
|
+
email?: string | null;
|
|
38
|
+
};
|
|
39
|
+
verifier?: {
|
|
40
|
+
id: string;
|
|
41
|
+
email?: string | null;
|
|
42
|
+
};
|
|
43
|
+
verifierKind?: VerifierKind;
|
|
44
|
+
eventAt?: Date;
|
|
45
|
+
signals?: Record<string, number>;
|
|
46
|
+
evidence?: {
|
|
47
|
+
activityInstanceId?: string;
|
|
48
|
+
factChangeIds?: string[];
|
|
49
|
+
};
|
|
50
|
+
practice?: boolean;
|
|
51
|
+
stage?: string;
|
|
52
|
+
now: Date;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The canonical record. Someone confirming their own work is marked, not stopped - the hub's rules judge it
|
|
56
|
+
* (`signals.selfVerified = 1`). A verifier is kept only for a person's confirmation.
|
|
57
|
+
*/
|
|
58
|
+
export declare function contributionRecordOf(input: RecordInput): ContributionRecord;
|
|
59
|
+
/** The fact that takes another back - the person who took it back stands as its contributor. */
|
|
60
|
+
export declare function revertRecordOf(input: {
|
|
61
|
+
kind: ContributionKind;
|
|
62
|
+
factId: string;
|
|
63
|
+
reason: string;
|
|
64
|
+
actor: {
|
|
65
|
+
id: string;
|
|
66
|
+
email?: string | null;
|
|
67
|
+
};
|
|
68
|
+
now: Date;
|
|
69
|
+
}): ContributionRecord;
|
|
70
|
+
/** A manifest's version - the same list gives the same version, whatever order its kinds were declared in. */
|
|
71
|
+
export declare function manifestOf(product: string, kinds: readonly ContributionKind[]): ContributionManifest;
|
|
72
|
+
/** JSON with keys in order - two equal values give the same text. */
|
|
73
|
+
export declare function stableJson(value: unknown): string;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.contributionFactId = contributionFactId;
|
|
4
|
+
exports.revertFactId = revertFactId;
|
|
5
|
+
exports.isMachineUser = isMachineUser;
|
|
6
|
+
exports.personOf = personOf;
|
|
7
|
+
exports.keptSignals = keptSignals;
|
|
8
|
+
exports.dayOf = dayOf;
|
|
9
|
+
exports.contributionRecordOf = contributionRecordOf;
|
|
10
|
+
exports.revertRecordOf = revertRecordOf;
|
|
11
|
+
exports.manifestOf = manifestOf;
|
|
12
|
+
exports.stableJson = stableJson;
|
|
13
|
+
const node_crypto_1 = require("node:crypto");
|
|
14
|
+
/*
|
|
15
|
+
* **How the sending side shapes a fact** (design §3-1) - pure: no database, no settings. `emit.ts` reads the settings and
|
|
16
|
+
* the user, then asks these.
|
|
17
|
+
*/
|
|
18
|
+
/** The same parts give the same key, so a resent fact is counted once by the hub. */
|
|
19
|
+
function contributionFactId(parts) {
|
|
20
|
+
const { product, domainId, kind, subjectId, stage } = parts;
|
|
21
|
+
for (const [name, value] of Object.entries({ product, domainId, kind, subjectId })) {
|
|
22
|
+
if (typeof value !== 'string' || !value)
|
|
23
|
+
throw new Error(`contributionFactId needs ${name}`);
|
|
24
|
+
}
|
|
25
|
+
const digest = (0, node_crypto_1.createHash)('sha256').update([product, domainId, kind, subjectId, stage ?? ''].join('\u001f')).digest('hex');
|
|
26
|
+
return `${kind}:${digest.slice(0, 32)}`;
|
|
27
|
+
}
|
|
28
|
+
/** The key of the fact that takes `factId` back - one revert per fact, however often it is sent. */
|
|
29
|
+
function revertFactId(factId) {
|
|
30
|
+
return `${factId}:reverted`;
|
|
31
|
+
}
|
|
32
|
+
/** Whether a user is a machine account - those never earn (auth-base `userType`: `application` · `appliance`). */
|
|
33
|
+
function isMachineUser(user) {
|
|
34
|
+
const type = user?.userType;
|
|
35
|
+
return !!type && type !== 'user';
|
|
36
|
+
}
|
|
37
|
+
/** The person as the hub reads them - this server's user id, and the mail in lower case. */
|
|
38
|
+
function personOf(user) {
|
|
39
|
+
const email = typeof user.email === 'string' && user.email.trim() ? user.email.trim().toLowerCase() : undefined;
|
|
40
|
+
return { sourceUserId: String(user.id), ...(email ? { email } : {}) };
|
|
41
|
+
}
|
|
42
|
+
/** Finite numbers only, and only the names the kind lists when it lists any. */
|
|
43
|
+
function keptSignals(signals, allowed) {
|
|
44
|
+
if (!signals || typeof signals !== 'object')
|
|
45
|
+
return undefined;
|
|
46
|
+
const kept = {};
|
|
47
|
+
for (const [name, value] of Object.entries(signals)) {
|
|
48
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
49
|
+
continue;
|
|
50
|
+
if (allowed && !allowed.includes(name))
|
|
51
|
+
continue;
|
|
52
|
+
kept[name] = value;
|
|
53
|
+
}
|
|
54
|
+
return Object.keys(kept).length ? kept : undefined;
|
|
55
|
+
}
|
|
56
|
+
/** YYYY-MM-DD of a date, in the server's calendar. */
|
|
57
|
+
function dayOf(date) {
|
|
58
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
59
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The canonical record. Someone confirming their own work is marked, not stopped - the hub's rules judge it
|
|
63
|
+
* (`signals.selfVerified = 1`). A verifier is kept only for a person's confirmation.
|
|
64
|
+
*/
|
|
65
|
+
function contributionRecordOf(input) {
|
|
66
|
+
const { product, domainId, kind, subject, contributor, verifier, now } = input;
|
|
67
|
+
const verifierKind = input.verifierKind ?? (verifier ? 'HUMAN' : 'SYSTEM');
|
|
68
|
+
const selfVerified = verifierKind === 'HUMAN' && !!verifier && String(verifier.id) === String(contributor.id);
|
|
69
|
+
const signals = keptSignals({ ...(input.signals ?? {}), ...(selfVerified ? { selfVerified: 1 } : {}) }, kind.signals && [...kind.signals, 'selfVerified']);
|
|
70
|
+
return {
|
|
71
|
+
v: 1,
|
|
72
|
+
factId: contributionFactId({ product, domainId, kind: kind.kind, subjectId: subject.id, stage: input.stage }),
|
|
73
|
+
kind: kind.kind,
|
|
74
|
+
verb: kind.verb,
|
|
75
|
+
subject: { type: subject.type, id: String(subject.id), ...(subject.title ? { title: subject.title } : {}), ...(subject.path ? { path: subject.path } : {}) },
|
|
76
|
+
contributor: personOf(contributor),
|
|
77
|
+
...(verifierKind === 'HUMAN' && verifier ? { verifier: personOf(verifier) } : {}),
|
|
78
|
+
verifierKind,
|
|
79
|
+
occurredAt: now.toISOString(),
|
|
80
|
+
...(input.eventAt ? { eventAt: dayOf(input.eventAt) } : {}),
|
|
81
|
+
...(signals ? { signals } : {}),
|
|
82
|
+
...(input.evidence ? { evidence: input.evidence } : {}),
|
|
83
|
+
...(input.practice ? { practice: true } : {})
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/** The fact that takes another back - the person who took it back stands as its contributor. */
|
|
87
|
+
function revertRecordOf(input) {
|
|
88
|
+
const { kind, factId, reason, actor, now } = input;
|
|
89
|
+
return {
|
|
90
|
+
v: 1,
|
|
91
|
+
factId: revertFactId(factId),
|
|
92
|
+
kind: kind.kind,
|
|
93
|
+
verb: 'REVERTED',
|
|
94
|
+
subject: { type: kind.subjectType, id: factId },
|
|
95
|
+
contributor: personOf(actor),
|
|
96
|
+
verifierKind: 'SYSTEM',
|
|
97
|
+
occurredAt: now.toISOString(),
|
|
98
|
+
revertsFactId: factId,
|
|
99
|
+
reason: String(reason ?? '').slice(0, 200)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** A manifest's version - the same list gives the same version, whatever order its kinds were declared in. */
|
|
103
|
+
function manifestOf(product, kinds) {
|
|
104
|
+
const sorted = [...kinds].sort((a, b) => a.kind.localeCompare(b.kind));
|
|
105
|
+
const version = (0, node_crypto_1.createHash)('sha256').update(stableJson(sorted)).digest('hex').slice(0, 16);
|
|
106
|
+
return { product, version, kinds: sorted };
|
|
107
|
+
}
|
|
108
|
+
/** JSON with keys in order - two equal values give the same text. */
|
|
109
|
+
function stableJson(value) {
|
|
110
|
+
if (Array.isArray(value))
|
|
111
|
+
return `[${value.map(stableJson).join(',')}]`;
|
|
112
|
+
if (value && typeof value === 'object') {
|
|
113
|
+
return `{${Object.keys(value)
|
|
114
|
+
.sort()
|
|
115
|
+
.filter(key => value[key] !== undefined)
|
|
116
|
+
.map(key => `${JSON.stringify(key)}:${stableJson(value[key])}`)
|
|
117
|
+
.join(',')}}`;
|
|
118
|
+
}
|
|
119
|
+
return JSON.stringify(value);
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=record-rules.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrapActivityCallback = wrapActivityCallback;
|
|
4
|
+
const worklist_1 = require("@things-factory/worklist");
|
|
5
|
+
const WRAPPED = new Set();
|
|
6
|
+
function wrapActivityCallback(activityName, listener) {
|
|
7
|
+
const template = worklist_1.ActivityInstallations.get(activityName);
|
|
8
|
+
if (!template)
|
|
9
|
+
throw new Error(`guild: no activity named '${activityName}' is installed - wrap it after it is installed`);
|
|
10
|
+
if (WRAPPED.has(activityName))
|
|
11
|
+
throw new Error(`guild: '${activityName}' is wrapped twice`);
|
|
12
|
+
const own = template.callback;
|
|
13
|
+
template.callback = async (activityInstance, addendum, context) => {
|
|
14
|
+
if (own)
|
|
15
|
+
await own(activityInstance, addendum, context);
|
|
16
|
+
await listener(activityInstance, addendum, context);
|
|
17
|
+
};
|
|
18
|
+
WRAPPED.add(activityName);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=activity-callback-seam.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type EntityManager, type EntitySubscriberInterface, type InsertEvent } from 'typeorm';
|
|
2
|
+
import { FactChange } from '@things-factory/fact-change';
|
|
3
|
+
export interface FactChangeWatch {
|
|
4
|
+
factKind: string;
|
|
5
|
+
field: string;
|
|
6
|
+
/** Only a change to this value; `null` - only a field cleared. Left out - every change of the field. */
|
|
7
|
+
to?: string | null;
|
|
8
|
+
}
|
|
9
|
+
export type FactChangeListener = (tx: EntityManager, change: FactChange, domain: {
|
|
10
|
+
id: string;
|
|
11
|
+
}) => Promise<void>;
|
|
12
|
+
export declare function onFactChange(watch: FactChangeWatch, listener: FactChangeListener): void;
|
|
13
|
+
/** Pure: whether a change is what a watch waits for. */
|
|
14
|
+
export declare function factChangeMatches(watch: FactChangeWatch, change: {
|
|
15
|
+
factKind?: string;
|
|
16
|
+
field?: string;
|
|
17
|
+
toValue?: string | null;
|
|
18
|
+
}): boolean;
|
|
19
|
+
/** For tests. */
|
|
20
|
+
export declare function forgetFactChangeWatches(): void;
|
|
21
|
+
export declare class GuildFactChangeSeam implements EntitySubscriberInterface<FactChange> {
|
|
22
|
+
listenTo(): typeof FactChange;
|
|
23
|
+
afterInsert(event: InsertEvent<FactChange>): Promise<void>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GuildFactChangeSeam = void 0;
|
|
4
|
+
exports.onFactChange = onFactChange;
|
|
5
|
+
exports.factChangeMatches = factChangeMatches;
|
|
6
|
+
exports.forgetFactChangeWatches = forgetFactChangeWatches;
|
|
7
|
+
const tslib_1 = require("tslib");
|
|
8
|
+
const typeorm_1 = require("typeorm");
|
|
9
|
+
const fact_change_1 = require("@things-factory/fact-change");
|
|
10
|
+
const WATCHES = [];
|
|
11
|
+
function onFactChange(watch, listener) {
|
|
12
|
+
if (!watch?.factKind || !watch.field)
|
|
13
|
+
throw new Error('onFactChange watches a fact kind and a field');
|
|
14
|
+
WATCHES.push({ watch, listener });
|
|
15
|
+
}
|
|
16
|
+
/** Pure: whether a change is what a watch waits for. */
|
|
17
|
+
function factChangeMatches(watch, change) {
|
|
18
|
+
if (change.factKind !== watch.factKind || change.field !== watch.field)
|
|
19
|
+
return false;
|
|
20
|
+
if (watch.to === undefined)
|
|
21
|
+
return true;
|
|
22
|
+
const to = change.toValue === undefined || change.toValue === '' ? null : change.toValue;
|
|
23
|
+
return to === watch.to;
|
|
24
|
+
}
|
|
25
|
+
/** For tests. */
|
|
26
|
+
function forgetFactChangeWatches() {
|
|
27
|
+
WATCHES.length = 0;
|
|
28
|
+
}
|
|
29
|
+
let GuildFactChangeSeam = class GuildFactChangeSeam {
|
|
30
|
+
listenTo() {
|
|
31
|
+
return fact_change_1.FactChange;
|
|
32
|
+
}
|
|
33
|
+
async afterInsert(event) {
|
|
34
|
+
const change = event.entity;
|
|
35
|
+
const domainId = change?.domain?.id ?? change?.domainId;
|
|
36
|
+
if (!change || !domainId || !WATCHES.length)
|
|
37
|
+
return;
|
|
38
|
+
for (const { watch, listener } of WATCHES) {
|
|
39
|
+
if (factChangeMatches(watch, change))
|
|
40
|
+
await listener(event.manager, change, { id: domainId });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.GuildFactChangeSeam = GuildFactChangeSeam;
|
|
45
|
+
exports.GuildFactChangeSeam = GuildFactChangeSeam = tslib_1.__decorate([
|
|
46
|
+
(0, typeorm_1.EventSubscriber)()
|
|
47
|
+
], GuildFactChangeSeam);
|
|
48
|
+
//# sourceMappingURL=fact-change-seam.js.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { EntityManager } from 'typeorm';
|
|
2
|
+
export declare const GUILD_SETTINGS: {
|
|
3
|
+
table: {
|
|
4
|
+
enabled: {
|
|
5
|
+
name: string;
|
|
6
|
+
type: "boolean";
|
|
7
|
+
level: "domain";
|
|
8
|
+
section: "connection";
|
|
9
|
+
card: string;
|
|
10
|
+
label: string;
|
|
11
|
+
hint: string;
|
|
12
|
+
order: number;
|
|
13
|
+
write: {
|
|
14
|
+
category: string;
|
|
15
|
+
privilege: "mutation";
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
hub: {
|
|
19
|
+
name: string;
|
|
20
|
+
type: "boolean";
|
|
21
|
+
level: "domain";
|
|
22
|
+
section: "connection";
|
|
23
|
+
card: string;
|
|
24
|
+
label: string;
|
|
25
|
+
hint: string;
|
|
26
|
+
order: number;
|
|
27
|
+
write: {
|
|
28
|
+
category: string;
|
|
29
|
+
privilege: "mutation";
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
hubPeer: {
|
|
33
|
+
name: string;
|
|
34
|
+
type: "string";
|
|
35
|
+
level: "domain";
|
|
36
|
+
section: "connection";
|
|
37
|
+
card: string;
|
|
38
|
+
label: string;
|
|
39
|
+
hint: string;
|
|
40
|
+
maxLength: number;
|
|
41
|
+
pattern: string;
|
|
42
|
+
order: number;
|
|
43
|
+
write: {
|
|
44
|
+
category: string;
|
|
45
|
+
privilege: "mutation";
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
text: (domain: {
|
|
50
|
+
id: string;
|
|
51
|
+
}, key: "enabled" | "hub" | "hubPeer", manager?: EntityManager) => Promise<string>;
|
|
52
|
+
number: (domain: {
|
|
53
|
+
id: string;
|
|
54
|
+
}, key: "enabled" | "hub" | "hubPeer", manager?: EntityManager) => Promise<number>;
|
|
55
|
+
flag: (domain: {
|
|
56
|
+
id: string;
|
|
57
|
+
}, key: "enabled" | "hub" | "hubPeer", manager?: EntityManager) => Promise<boolean>;
|
|
58
|
+
json: <V = unknown>(domain: {
|
|
59
|
+
id: string;
|
|
60
|
+
}, key: "enabled" | "hub" | "hubPeer", manager?: EntityManager) => Promise<V>;
|
|
61
|
+
};
|
|
62
|
+
export interface GuildPlace {
|
|
63
|
+
enabled: boolean;
|
|
64
|
+
hub: boolean;
|
|
65
|
+
hubPeer?: string;
|
|
66
|
+
}
|
|
67
|
+
/** The three settings, read through the work's own manager so a test's or a door's transaction sees them. */
|
|
68
|
+
export declare function guildPlaceOf(domain: {
|
|
69
|
+
id: string;
|
|
70
|
+
}, manager?: EntityManager): Promise<GuildPlace>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GUILD_SETTINGS = void 0;
|
|
4
|
+
exports.guildPlaceOf = guildPlaceOf;
|
|
5
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
6
|
+
const setting_base_1 = require("@things-factory/setting-base");
|
|
7
|
+
/*
|
|
8
|
+
* **Where the guild is for a domain** (design §9) - three domain settings every application carries, declared here
|
|
9
|
+
* because every application loads this module and only some load the hub.
|
|
10
|
+
*
|
|
11
|
+
* - `Guild::enabled` - off, the application sends nothing and draws nothing; its screens stay as they are.
|
|
12
|
+
* - `Guild::hub` - this domain's hub is on this server: facts go to it in the work's own transaction.
|
|
13
|
+
* - `Guild::hubPeer` - the hub is on another server: facts go out on the webhook outbox to this peer.
|
|
14
|
+
*
|
|
15
|
+
* They are changed by whoever runs the guild (`guild-admin`).
|
|
16
|
+
*/
|
|
17
|
+
(0, auth_base_1.declarePrivileges)('guild-overlay', [['guild-admin', 'mutation']]);
|
|
18
|
+
exports.GUILD_SETTINGS = (0, setting_base_1.declareDomainSettings)('guild-overlay', {
|
|
19
|
+
enabled: {
|
|
20
|
+
name: 'Guild::enabled',
|
|
21
|
+
type: 'boolean',
|
|
22
|
+
level: 'domain',
|
|
23
|
+
section: 'connection',
|
|
24
|
+
card: 'title.guild',
|
|
25
|
+
label: 'label.guild-enabled',
|
|
26
|
+
hint: 'text.guild-enabled-hint',
|
|
27
|
+
order: 1,
|
|
28
|
+
write: { category: 'guild-admin', privilege: 'mutation' }
|
|
29
|
+
},
|
|
30
|
+
hub: {
|
|
31
|
+
name: 'Guild::hub',
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
level: 'domain',
|
|
34
|
+
section: 'connection',
|
|
35
|
+
card: 'title.guild',
|
|
36
|
+
label: 'label.guild-hub',
|
|
37
|
+
hint: 'text.guild-hub-hint',
|
|
38
|
+
order: 2,
|
|
39
|
+
write: { category: 'guild-admin', privilege: 'mutation' }
|
|
40
|
+
},
|
|
41
|
+
hubPeer: {
|
|
42
|
+
name: 'Guild::hubPeer',
|
|
43
|
+
type: 'string',
|
|
44
|
+
level: 'domain',
|
|
45
|
+
section: 'connection',
|
|
46
|
+
card: 'title.guild',
|
|
47
|
+
label: 'label.guild-hub-peer',
|
|
48
|
+
hint: 'text.guild-hub-peer-hint',
|
|
49
|
+
maxLength: 60,
|
|
50
|
+
pattern: '^[a-z0-9][a-z0-9-]*$',
|
|
51
|
+
order: 3,
|
|
52
|
+
write: { category: 'guild-admin', privilege: 'mutation' }
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
/** The three settings, read through the work's own manager so a test's or a door's transaction sees them. */
|
|
56
|
+
async function guildPlaceOf(domain, manager) {
|
|
57
|
+
const enabled = await exports.GUILD_SETTINGS.flag(domain, 'enabled', manager);
|
|
58
|
+
if (!enabled)
|
|
59
|
+
return { enabled: false, hub: false };
|
|
60
|
+
const hub = await exports.GUILD_SETTINGS.flag(domain, 'hub', manager);
|
|
61
|
+
const hubPeer = (await exports.GUILD_SETTINGS.text(domain, 'hubPeer', manager)) || undefined;
|
|
62
|
+
return { enabled, hub, ...(hubPeer ? { hubPeer } : {}) };
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=settings.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/guild-overlay",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "10.1.313",
|
|
4
|
+
"main": "dist-server/index.js",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist-server",
|
|
7
|
+
"things-factory.config.js",
|
|
8
|
+
"translations",
|
|
9
|
+
"!**/*.map",
|
|
10
|
+
"!**/*.test.*",
|
|
11
|
+
"!**/*.spec.*",
|
|
12
|
+
"!**/test/**",
|
|
13
|
+
"!**/tests/**",
|
|
14
|
+
"!**/__tests__/**",
|
|
15
|
+
"!**/*.tsbuildinfo",
|
|
16
|
+
"!**/.DS_Store"
|
|
17
|
+
],
|
|
18
|
+
"things-factory": true,
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "heartyoh <heartyoh@hatiolab.com>",
|
|
21
|
+
"description": "The guild overlay every application loads - it declares the contribution kinds a product sends and hands confirmed contributions to the guild hub, on this server in the same transaction or on another over the webhook outbox (operato-guild)",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public",
|
|
24
|
+
"@things-factory:registry": "https://registry.npmjs.org"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/hatiolab/things-factory.git",
|
|
29
|
+
"directory": "packages/guild-overlay"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "npm run build:server",
|
|
33
|
+
"build:server": "npm run clean:server && npx tsc --p ./server/tsconfig.json",
|
|
34
|
+
"clean:server": "rm -rf dist-server",
|
|
35
|
+
"clean": "npm run clean:server",
|
|
36
|
+
"test": "npm run build:server && node --import ./test/resolve-ts-siblings.mjs --test test/*.test.ts"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@things-factory/auth-base": "^10.1.304",
|
|
40
|
+
"@things-factory/env": "^10.1.298",
|
|
41
|
+
"@things-factory/fact-change": "^10.1.304",
|
|
42
|
+
"@things-factory/setting-base": "^10.1.304",
|
|
43
|
+
"@things-factory/shell": "^10.1.304",
|
|
44
|
+
"@things-factory/webhook": "^10.1.304",
|
|
45
|
+
"@things-factory/worklist": "^10.1.306"
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "dd6234d77e322c6de3f2a264b157ac6428189edc"
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title.guild": "Contribution rewards (guild)",
|
|
3
|
+
"label.guild-enabled": "Use contribution rewards",
|
|
4
|
+
"text.guild-enabled-hint": "Off, this application sends no contribution facts and adds nothing to its screens.",
|
|
5
|
+
"label.guild-hub": "Use the hub on this server",
|
|
6
|
+
"text.guild-hub-hint": "On, contribution facts go to the hub on this server in the work's own transaction.",
|
|
7
|
+
"label.guild-hub-peer": "Webhook peer of the hub on another server",
|
|
8
|
+
"text.guild-hub-peer-hint": "The peer's name when the hub is on another server. Its address is kept on the webhook destination."
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title.guild": "Recompensas de contribución (guild)",
|
|
3
|
+
"label.guild-enabled": "Usar recompensas de contribución",
|
|
4
|
+
"text.guild-enabled-hint": "Desactivado, esta aplicación no envía hechos de contribución ni añade nada a sus pantallas.",
|
|
5
|
+
"label.guild-hub": "Usar el centro de este servidor",
|
|
6
|
+
"text.guild-hub-hint": "Activado, los hechos de contribución van al centro de este servidor en la misma transacción del trabajo.",
|
|
7
|
+
"label.guild-hub-peer": "Par de webhook del centro en otro servidor",
|
|
8
|
+
"text.guild-hub-peer-hint": "El nombre del par cuando el centro está en otro servidor. Su dirección se guarda en el destino del webhook."
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title.guild": "貢献報酬(guild)",
|
|
3
|
+
"label.guild-enabled": "貢献報酬を使う",
|
|
4
|
+
"text.guild-enabled-hint": "オフにすると、このアプリは貢献の事実を送らず、画面にも何も加えません。",
|
|
5
|
+
"label.guild-hub": "このサーバーのハブを使う",
|
|
6
|
+
"text.guild-hub-hint": "オンにすると、貢献の事実を同じサーバーのハブに業務と同じトランザクションで渡します。",
|
|
7
|
+
"label.guild-hub-peer": "別サーバーのハブの webhook 相手名",
|
|
8
|
+
"text.guild-hub-peer-hint": "ハブが別サーバーにある場合の相手名です。宛先アドレスは webhook の宛先に置きます。"
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title.guild": "기여 보상(guild)",
|
|
3
|
+
"label.guild-enabled": "기여 보상 사용",
|
|
4
|
+
"text.guild-enabled-hint": "끄면 이 앱은 기여 사실을 보내지 않고 화면에도 아무것도 붙이지 않습니다.",
|
|
5
|
+
"label.guild-hub": "이 서버의 허브 사용",
|
|
6
|
+
"text.guild-hub-hint": "켜면 기여 사실을 같은 서버의 허브에 업무와 같은 트랜잭션으로 넘깁니다.",
|
|
7
|
+
"label.guild-hub-peer": "다른 서버 허브의 webhook 상대 이름",
|
|
8
|
+
"text.guild-hub-peer-hint": "허브가 다른 서버에 있을 때 그 상대 이름. 목적지 주소는 webhook 목적지에 둡니다."
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title.guild": "Ganjaran sumbangan (guild)",
|
|
3
|
+
"label.guild-enabled": "Guna ganjaran sumbangan",
|
|
4
|
+
"text.guild-enabled-hint": "Jika dimatikan, aplikasi ini tidak menghantar fakta sumbangan dan tidak menambah apa-apa pada skrinnya.",
|
|
5
|
+
"label.guild-hub": "Guna hab pada pelayan ini",
|
|
6
|
+
"text.guild-hub-hint": "Jika dihidupkan, fakta sumbangan diserahkan kepada hab pada pelayan ini dalam transaksi kerja yang sama.",
|
|
7
|
+
"label.guild-hub-peer": "Rakan webhook bagi hab pada pelayan lain",
|
|
8
|
+
"text.guild-hub-peer-hint": "Nama rakan apabila hab berada pada pelayan lain. Alamatnya disimpan pada destinasi webhook."
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title.guild": "贡献奖励(guild)",
|
|
3
|
+
"label.guild-enabled": "使用贡献奖励",
|
|
4
|
+
"text.guild-enabled-hint": "关闭后,本应用不发送贡献事实,界面也不添加任何内容。",
|
|
5
|
+
"label.guild-hub": "使用本服务器的中心",
|
|
6
|
+
"text.guild-hub-hint": "开启后,贡献事实将在同一事务中交给本服务器的中心。",
|
|
7
|
+
"label.guild-hub-peer": "其他服务器中心的 webhook 对端名称",
|
|
8
|
+
"text.guild-hub-peer-hint": "中心在其他服务器时的对端名称。目标地址保存在 webhook 目标中。"
|
|
9
|
+
}
|
package/README.md
DELETED