@blue-repository/types 0.8.0 → 0.10.0
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/README.md +1 -1
- package/dist/meta.d.ts +2 -2
- package/dist/meta.d.ts.map +1 -1
- package/dist/meta.js +2 -0
- package/dist/meta.js.map +1 -1
- package/dist/packages/conversation/blue-ids.d.ts +11 -8
- package/dist/packages/conversation/blue-ids.d.ts.map +1 -1
- package/dist/packages/conversation/blue-ids.js +11 -8
- package/dist/packages/conversation/blue-ids.js.map +1 -1
- package/dist/packages/conversation/contents/AcceptChangeWorkflow.d.ts +1 -1
- package/dist/packages/conversation/contents/AcceptChangeWorkflow.js +1 -1
- package/dist/packages/conversation/contents/AcceptChangeWorkflow.js.map +1 -1
- package/dist/packages/conversation/contents/ChangeOperation.d.ts +1 -1
- package/dist/packages/conversation/contents/ChangeOperation.js +1 -1
- package/dist/packages/conversation/contents/ChangeRequest.d.ts +12 -6
- package/dist/packages/conversation/contents/ChangeRequest.d.ts.map +1 -1
- package/dist/packages/conversation/contents/ChangeRequest.js +12 -6
- package/dist/packages/conversation/contents/ChangeRequest.js.map +1 -1
- package/dist/packages/conversation/contents/ChangeWorkflow.d.ts +2 -2
- package/dist/packages/conversation/contents/ChangeWorkflow.js +2 -2
- package/dist/packages/conversation/contents/ChangeWorkflow.js.map +1 -1
- package/dist/packages/conversation/contents/ContractsChangePolicy.d.ts +14 -0
- package/dist/packages/conversation/contents/ContractsChangePolicy.d.ts.map +1 -0
- package/dist/packages/conversation/contents/ContractsChangePolicy.js +14 -0
- package/dist/packages/conversation/contents/ContractsChangePolicy.js.map +1 -0
- package/dist/packages/conversation/contents/DocumentSection.d.ts +15 -3
- package/dist/packages/conversation/contents/DocumentSection.d.ts.map +1 -1
- package/dist/packages/conversation/contents/DocumentSection.js +15 -3
- package/dist/packages/conversation/contents/DocumentSection.js.map +1 -1
- package/dist/packages/conversation/contents/DocumentSectionChangeEntry.d.ts +29 -0
- package/dist/packages/conversation/contents/DocumentSectionChangeEntry.d.ts.map +1 -0
- package/dist/packages/conversation/contents/DocumentSectionChangeEntry.js +29 -0
- package/dist/packages/conversation/contents/DocumentSectionChangeEntry.js.map +1 -0
- package/dist/packages/conversation/contents/DocumentSectionChanges.d.ts +32 -0
- package/dist/packages/conversation/contents/DocumentSectionChanges.d.ts.map +1 -0
- package/dist/packages/conversation/contents/DocumentSectionChanges.js +32 -0
- package/dist/packages/conversation/contents/DocumentSectionChanges.js.map +1 -0
- package/dist/packages/conversation/contents/ProposeChangeOperation.d.ts +1 -1
- package/dist/packages/conversation/contents/ProposeChangeOperation.js +1 -1
- package/dist/packages/conversation/contents/ProposeChangeWorkflow.d.ts +2 -2
- package/dist/packages/conversation/contents/ProposeChangeWorkflow.js +2 -2
- package/dist/packages/conversation/contents/ProposeChangeWorkflow.js.map +1 -1
- package/dist/packages/conversation/contents/RejectChangeWorkflow.d.ts +1 -1
- package/dist/packages/conversation/contents/RejectChangeWorkflow.js +1 -1
- package/dist/packages/conversation/contents/index.d.ts +242 -149
- package/dist/packages/conversation/contents/index.d.ts.map +1 -1
- package/dist/packages/conversation/contents/index.js +31 -22
- package/dist/packages/conversation/contents/index.js.map +1 -1
- package/dist/packages/conversation/index.d.ts +2768 -207
- package/dist/packages/conversation/index.d.ts.map +1 -1
- package/dist/packages/conversation/meta.d.ts +62 -32
- package/dist/packages/conversation/meta.d.ts.map +1 -1
- package/dist/packages/conversation/meta.js +57 -24
- package/dist/packages/conversation/meta.js.map +1 -1
- package/dist/packages/conversation/schemas/ChangeOperation.d.ts +436 -5
- package/dist/packages/conversation/schemas/ChangeOperation.d.ts.map +1 -1
- package/dist/packages/conversation/schemas/ChangeRequest.d.ts +348 -3
- package/dist/packages/conversation/schemas/ChangeRequest.d.ts.map +1 -1
- package/dist/packages/conversation/schemas/ChangeRequest.js +3 -1
- package/dist/packages/conversation/schemas/ChangeRequest.js.map +1 -1
- package/dist/packages/conversation/schemas/ChangeWorkflow.d.ts +436 -5
- package/dist/packages/conversation/schemas/ChangeWorkflow.d.ts.map +1 -1
- package/dist/packages/conversation/schemas/ContractsChangePolicy.d.ts +25 -0
- package/dist/packages/conversation/schemas/ContractsChangePolicy.d.ts.map +1 -0
- package/dist/packages/conversation/schemas/ContractsChangePolicy.js +10 -0
- package/dist/packages/conversation/schemas/ContractsChangePolicy.js.map +1 -0
- package/dist/packages/conversation/schemas/DocumentSection.d.ts +6 -0
- package/dist/packages/conversation/schemas/DocumentSection.d.ts.map +1 -1
- package/dist/packages/conversation/schemas/DocumentSection.js +2 -0
- package/dist/packages/conversation/schemas/DocumentSection.js.map +1 -1
- package/dist/packages/conversation/schemas/DocumentSectionChangeEntry.d.ts +88 -0
- package/dist/packages/conversation/schemas/DocumentSectionChangeEntry.d.ts.map +1 -0
- package/dist/packages/conversation/schemas/DocumentSectionChangeEntry.js +13 -0
- package/dist/packages/conversation/schemas/DocumentSectionChangeEntry.js.map +1 -0
- package/dist/packages/conversation/schemas/DocumentSectionChanges.d.ts +262 -0
- package/dist/packages/conversation/schemas/DocumentSectionChanges.d.ts.map +1 -0
- package/dist/packages/conversation/schemas/DocumentSectionChanges.js +12 -0
- package/dist/packages/conversation/schemas/DocumentSectionChanges.js.map +1 -0
- package/dist/packages/conversation/schemas/InformUserAboutPendingAction.d.ts +2 -2
- package/dist/packages/conversation/schemas/ProposeChangeOperation.d.ts +436 -5
- package/dist/packages/conversation/schemas/ProposeChangeOperation.d.ts.map +1 -1
- package/dist/packages/conversation/schemas/ProposeChangeWorkflow.d.ts +436 -5
- package/dist/packages/conversation/schemas/ProposeChangeWorkflow.d.ts.map +1 -1
- package/dist/packages/conversation/schemas/index.d.ts +2477 -33
- package/dist/packages/conversation/schemas/index.d.ts.map +1 -1
- package/dist/packages/conversation/schemas/index.js +17 -8
- package/dist/packages/conversation/schemas/index.js.map +1 -1
- package/dist/packages/myos/index.d.ts +32 -32
- package/dist/packages/myos/schemas/DocumentSessionBootstrap.d.ts +24 -24
- package/dist/packages/myos/schemas/LinkedDocumentsPermissionGrantToAccount.d.ts +2 -2
- package/dist/packages/myos/schemas/LinkedDocumentsPermissionGrantToDocument.d.ts +2 -2
- package/dist/packages/myos/schemas/SingleDocumentPermissionGrantToAccount.d.ts +2 -2
- package/dist/packages/myos/schemas/SingleDocumentPermissionGrantToDocument.d.ts +2 -2
- package/dist/packages/myos/schemas/index.d.ts +32 -32
- package/dist/packages/paynote/index.d.ts +4 -4
- package/dist/packages/paynote/schemas/PayNote.d.ts +4 -4
- package/dist/packages/paynote/schemas/index.d.ts +4 -4
- package/dist/repository.d.ts +2828 -267
- package/dist/repository.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const DocumentSectionChanges: {
|
|
2
|
+
readonly add: {
|
|
3
|
+
readonly description: "New sections to create with their Document Section and contracts.";
|
|
4
|
+
readonly itemType: {
|
|
5
|
+
readonly blueId: "9xv7YjqsSn7W7P8rnUhSpdWGfSrgL4Jt3cmiACJT5VQs";
|
|
6
|
+
};
|
|
7
|
+
readonly type: {
|
|
8
|
+
readonly blueId: "6aehfNAxHLC1PHHoDr3tYtFH3RWNbiWdFancJ1bypXEY";
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
readonly description: "Structured /contracts changes grouped by logical sections, used by change workflows.";
|
|
12
|
+
readonly modify: {
|
|
13
|
+
readonly description: "Existing sections to update with a full contracts map.";
|
|
14
|
+
readonly itemType: {
|
|
15
|
+
readonly blueId: "9xv7YjqsSn7W7P8rnUhSpdWGfSrgL4Jt3cmiACJT5VQs";
|
|
16
|
+
};
|
|
17
|
+
readonly type: {
|
|
18
|
+
readonly blueId: "6aehfNAxHLC1PHHoDr3tYtFH3RWNbiWdFancJ1bypXEY";
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
readonly name: "Document Section Changes";
|
|
22
|
+
readonly remove: {
|
|
23
|
+
readonly description: "Section keys to remove (also removes the section's related contracts).";
|
|
24
|
+
readonly itemType: {
|
|
25
|
+
readonly blueId: "DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K";
|
|
26
|
+
};
|
|
27
|
+
readonly type: {
|
|
28
|
+
readonly blueId: "6aehfNAxHLC1PHHoDr3tYtFH3RWNbiWdFancJ1bypXEY";
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=DocumentSectionChanges.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DocumentSectionChanges.d.ts","sourceRoot":"","sources":["../../../../src/packages/conversation/contents/DocumentSectionChanges.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCzB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const DocumentSectionChanges = {
|
|
2
|
+
add: {
|
|
3
|
+
description: 'New sections to create with their Document Section and contracts.',
|
|
4
|
+
itemType: {
|
|
5
|
+
blueId: '9xv7YjqsSn7W7P8rnUhSpdWGfSrgL4Jt3cmiACJT5VQs',
|
|
6
|
+
},
|
|
7
|
+
type: {
|
|
8
|
+
blueId: '6aehfNAxHLC1PHHoDr3tYtFH3RWNbiWdFancJ1bypXEY',
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
description: 'Structured /contracts changes grouped by logical sections, used by change workflows.',
|
|
12
|
+
modify: {
|
|
13
|
+
description: 'Existing sections to update with a full contracts map.',
|
|
14
|
+
itemType: {
|
|
15
|
+
blueId: '9xv7YjqsSn7W7P8rnUhSpdWGfSrgL4Jt3cmiACJT5VQs',
|
|
16
|
+
},
|
|
17
|
+
type: {
|
|
18
|
+
blueId: '6aehfNAxHLC1PHHoDr3tYtFH3RWNbiWdFancJ1bypXEY',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
name: 'Document Section Changes',
|
|
22
|
+
remove: {
|
|
23
|
+
description: "Section keys to remove (also removes the section's related contracts).",
|
|
24
|
+
itemType: {
|
|
25
|
+
blueId: 'DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K',
|
|
26
|
+
},
|
|
27
|
+
type: {
|
|
28
|
+
blueId: '6aehfNAxHLC1PHHoDr3tYtFH3RWNbiWdFancJ1bypXEY',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=DocumentSectionChanges.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DocumentSectionChanges.js","sourceRoot":"","sources":["../../../../src/packages/conversation/contents/DocumentSectionChanges.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,GAAG,EAAE;QACH,WAAW,EACT,mEAAmE;QACrE,QAAQ,EAAE;YACR,MAAM,EAAE,8CAA8C;SACvD;QACD,IAAI,EAAE;YACJ,MAAM,EAAE,8CAA8C;SACvD;KACF;IACD,WAAW,EACT,sFAAsF;IACxF,MAAM,EAAE;QACN,WAAW,EAAE,wDAAwD;QACrE,QAAQ,EAAE;YACR,MAAM,EAAE,8CAA8C;SACvD;QACD,IAAI,EAAE;YACJ,MAAM,EAAE,8CAA8C;SACvD;KACF;IACD,IAAI,EAAE,0BAA0B;IAChC,MAAM,EAAE;QACN,WAAW,EACT,wEAAwE;QAC1E,QAAQ,EAAE;YACR,MAAM,EAAE,8CAA8C;SACvD;QACD,IAAI,EAAE;YACJ,MAAM,EAAE,8CAA8C;SACvD;KACF;CACO,CAAC"}
|
|
@@ -3,7 +3,7 @@ export declare const ProposeChangeOperation: {
|
|
|
3
3
|
readonly name: "Propose Change Operation";
|
|
4
4
|
readonly request: {
|
|
5
5
|
readonly type: {
|
|
6
|
-
readonly blueId: "
|
|
6
|
+
readonly blueId: "9KDfK6k1HBAyHckj5VuWXFMLkgY5cJBESKT4eoq1bnrw";
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
9
|
readonly type: {
|
|
@@ -10,7 +10,7 @@ export declare const ProposeChangeWorkflow: {
|
|
|
10
10
|
readonly request: {
|
|
11
11
|
readonly description: "Expected request payload for this workflow.";
|
|
12
12
|
readonly type: {
|
|
13
|
-
readonly blueId: "
|
|
13
|
+
readonly blueId: "9KDfK6k1HBAyHckj5VuWXFMLkgY5cJBESKT4eoq1bnrw";
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
readonly steps: {
|
|
@@ -19,7 +19,7 @@ export declare const ProposeChangeWorkflow: {
|
|
|
19
19
|
readonly type: {
|
|
20
20
|
readonly blueId: "DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K";
|
|
21
21
|
};
|
|
22
|
-
readonly value: "const issues = [];\n\nconst request = event.message.request || {};\n\nconst proposedChangesetDescription = request.changesetDescription;\nconst proposedChangeset = request.changeset;\n\nif (!proposedChangesetDescription) {\n issues.push('changesetDescription is missing');\n}\n\nif (!proposedChangeset) {\n issues.push('changeset is missing');\n}\n\nif (issues.length > 0) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: issues.join('; ')\n }\n ]\n }\n}\n\nconst postfix = currentContract.postfix ?? ''\nconst path = '/proposedChange' + postfix\n\nconst existing = document(path)\nif (existing) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: \"Can not propose change when it already exists at \" + path\n }\n ]\n }\n}\n\nreturn {\n changeset: [{\n op: 'add',\n path,\n val: {\n changesetDescription: proposedChangesetDescription,\n changeset: proposedChangeset\n }\n }]\n};\n";
|
|
22
|
+
readonly value: "const issues = [];\n\nconst request = event.message.request || {};\n\nconst changeDescription = request.changeDescription;\nconst rawChangeset = request.changeset;\nconst rawSectionChanges = request.sectionChanges;\nconst requestSectionChanges = rawSectionChanges || {};\n\nconst toText = (value) => {\n const raw = value && value.value ? value.value : value;\n return raw && raw.trim ? raw.trim() : '';\n};\nconst asList = (value) => Array.isArray(value) ? value : [];\nconst hasType = (value) => value && value.type;\nconst escapePointer = (value) => {\n const text = toText(value);\n return text.split('~').join('~0').split('/').join('~1');\n};\nconst requestChangeset = asList(rawChangeset);\n\nconst uniqueKeys = (values, label) => {\n const seen = new Set();\n const output = [];\n for (const value of values) {\n const key = toText(value);\n if (!key) {\n issues.push(label + ' contains invalid key');\n continue;\n }\n if (seen.has(key)) {\n issues.push(label + ' contains duplicate key: ' + key);\n continue;\n }\n seen.add(key);\n output.push(key);\n }\n return output;\n};\n\nconst sameStringSet = (left, right) => {\n if (left.length !== right.length) return false;\n const set = new Set(left);\n if (set.size !== right.length) return false;\n for (const value of right) {\n if (!set.has(value)) return false;\n }\n return true;\n};\n\nconst contracts = Object(document('/contracts') || {});\n\nconst isDocumentSection = (contract) =>\n !!contract && Array.isArray(contract.relatedContracts);\n\nconst isContractsChangePolicy = (contract) => {\n if (!contract) return false;\n return 'requireSectionChanges' in contract;\n};\n\nconst findPolicy = () => {\n for (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isContractsChangePolicy(contract)) {\n return contract;\n }\n }\n return null;\n};\n\nconst policy = findPolicy();\nconst policyEnabled = !!policy && policy.requireSectionChanges !== false;\n\nif (!toText(changeDescription)) {\n issues.push('changeDescription is missing');\n}\n\nconst hasChangeset = !!rawChangeset;\nconst hasSectionChanges = !!rawSectionChanges;\n\nif (!hasChangeset && !hasSectionChanges) {\n issues.push('changeset or sectionChanges is required');\n}\n\nconst isContractsPath = (path) => {\n const value = toText(path);\n return value === '/contracts' || value.startsWith('/contracts/');\n};\nif (policyEnabled && hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isContractsPath(entry.path)) {\n issues.push('changeset cannot modify /contracts when Contracts Change Policy is enabled');\n break;\n }\n }\n}\nconst isProposedChangePath = (path) =>\n toText(path).startsWith('/proposedChange');\nif (hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isProposedChangePath(entry.path)) {\n issues.push('changeset cannot modify /proposedChange');\n break;\n }\n }\n}\n\nconst existingSections = {};\nfor (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isDocumentSection(contract)) {\n existingSections[key] = contract;\n }\n}\n\nconst contractIndex = {};\nfor (const sectionKey of Object.keys(existingSections)) {\n const section = existingSections[sectionKey];\n const related = asList(section.relatedContracts);\n for (const relatedKey of related) {\n const contractKey = toText(relatedKey);\n if (!contractKey) continue;\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n contractIndex[contractKey] = null;\n } else if (!contractIndex[contractKey]) {\n contractIndex[contractKey] = sectionKey;\n }\n }\n}\n\nconst normalizeSectionDefinition = (sectionDef, label) => {\n if (!sectionDef) {\n issues.push(label + ' entry must be an object');\n return null;\n }\n const sectionKey = toText(sectionDef.sectionKey);\n if (!sectionKey) {\n issues.push(label + ' sectionKey is missing');\n return null;\n }\n const section = sectionDef.section;\n if (!section) {\n issues.push(label + ' section is missing');\n return null;\n }\n\n const rawContractsMap = sectionDef.contracts && sectionDef.contracts.value\n ? sectionDef.contracts.value\n : sectionDef.contracts || {};\n const contractDefs = [];\n const contractKeys = [];\n for (const [rawKey, contract] of Object.entries(rawContractsMap)) {\n if (\n rawKey === 'type' ||\n rawKey === 'keyType' ||\n rawKey === 'valueType' ||\n rawKey === 'description'\n ) {\n continue;\n }\n const key = toText(rawKey);\n if (!key) {\n issues.push(label + ' contract key is missing');\n continue;\n }\n if (!contract) {\n issues.push(label + ' contract ' + key + ' is missing or invalid');\n continue;\n }\n if (!hasType(contract)) {\n issues.push(label + ' contract ' + key + ' is missing type');\n }\n contractDefs.push({ key, contract });\n contractKeys.push(key);\n }\n\n if (!hasType(section)) {\n issues.push(label + ' section ' + sectionKey + ' is missing type');\n }\n\n const related = section.relatedContracts\n ? uniqueKeys(asList(section.relatedContracts), label + ' section ' + sectionKey + ' relatedContracts')\n : null;\n if (related && !sameStringSet(related, contractKeys)) {\n issues.push(label + ' section ' + sectionKey + ' relatedContracts must match contracts');\n }\n\n const normalizedRelated = related || contractKeys;\n const normalizedSection = Object.assign({}, section, {\n type: 'Conversation/Document Section',\n relatedContracts: normalizedRelated\n });\n\n return {\n sectionKey,\n section: normalizedSection,\n contractDefs,\n contractKeys\n };\n};\n\nconst sectionChangeset = [];\nconst seenSectionKeys = new Set();\nconst seenContractKeys = new Set();\n\nconst addList = asList(requestSectionChanges.add);\nconst modifyList = asList(requestSectionChanges.modify);\nconst removeList = asList(requestSectionChanges.remove);\n\nfor (const entry of addList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.add');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n if (contracts[sectionKey]) {\n issues.push('section key already exists at /contracts/' + sectionKey);\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contracts[contractKey]) {\n issues.push('contract key already exists at /contracts/' + contractKey);\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nfor (const entry of modifyList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.modify');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n } else if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n }\n\n const existingRelated =\n existingSection && existingSection.relatedContracts\n ? asList(existingSection.relatedContracts)\n : [];\n if (existingSection && !existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n const op = contracts[contractDef.key] ? 'replace' : 'add';\n sectionChangeset.push({\n op,\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n\n const toRemove = uniqueKeys(existingRelated, 'sectionChanges.modify remove list').filter(\n (key) => !normalized.contractKeys.includes(key)\n );\n for (const contractKey of toRemove) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n\n sectionChangeset.push({\n op: 'replace',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nconst removeKeys = uniqueKeys(removeList, 'sectionChanges.remove');\nfor (const sectionKey of removeKeys) {\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n continue;\n }\n if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n continue;\n }\n\n const related = existingSection.relatedContracts\n ? uniqueKeys(asList(existingSection.relatedContracts), 'sectionChanges.remove relatedContracts')\n : [];\n if (!existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of related) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(sectionKey)\n });\n}\nconst combinedChangeset = sectionChangeset.concat(hasChangeset ? requestChangeset : []);\n\nif (combinedChangeset.length === 0) {\n issues.push('no changes provided');\n}\n\nif (issues.length > 0) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: issues.join('; ')\n }\n ]\n }\n}\n\nconst postfixValue = currentContract.postfix || '';\nconst path = '/proposedChange' + postfixValue;\n\nif (document(path)) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: \"Can not propose change when it already exists at \" + path\n }\n ]\n }\n}\n\nconst proposedPayload = {\n changeDescription\n};\n\nproposedPayload.preparedChangeset = combinedChangeset;\n\nif (hasChangeset) {\n proposedPayload.changeset = requestChangeset;\n}\n\nconst hasSectionChangesData = addList.length || modifyList.length || removeList.length;\nif (hasSectionChangesData) {\n proposedPayload.sectionChanges = rawSectionChanges;\n}\n\nreturn {\n changeset: [{\n op: 'add',\n path,\n val: proposedPayload\n }]\n};\n";
|
|
23
23
|
};
|
|
24
24
|
readonly name: "Prepare";
|
|
25
25
|
readonly type: {
|
|
@@ -10,7 +10,7 @@ export const ProposeChangeWorkflow = {
|
|
|
10
10
|
request: {
|
|
11
11
|
description: 'Expected request payload for this workflow.',
|
|
12
12
|
type: {
|
|
13
|
-
blueId: '
|
|
13
|
+
blueId: '9KDfK6k1HBAyHckj5VuWXFMLkgY5cJBESKT4eoq1bnrw',
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
16
|
steps: {
|
|
@@ -20,7 +20,7 @@ export const ProposeChangeWorkflow = {
|
|
|
20
20
|
type: {
|
|
21
21
|
blueId: 'DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K',
|
|
22
22
|
},
|
|
23
|
-
value: "const issues = [];\n\nconst request = event.message.request || {};\n\nconst proposedChangesetDescription = request.changesetDescription;\nconst proposedChangeset = request.changeset;\n\nif (!proposedChangesetDescription) {\n issues.push('changesetDescription is missing');\n}\n\nif (!proposedChangeset) {\n issues.push('changeset is missing');\n}\n\nif (issues.length > 0) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: issues.join('; ')\n }\n ]\n }\n}\n\nconst postfix = currentContract.postfix ?? ''\nconst path = '/proposedChange' + postfix\n\nconst existing = document(path)\nif (existing) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: \"Can not propose change when it already exists at \" + path\n }\n ]\n }\n}\n\nreturn {\n changeset: [{\n op: 'add',\n path,\n val: {\n changesetDescription: proposedChangesetDescription,\n changeset: proposedChangeset\n }\n }]\n};\n",
|
|
23
|
+
value: "const issues = [];\n\nconst request = event.message.request || {};\n\nconst changeDescription = request.changeDescription;\nconst rawChangeset = request.changeset;\nconst rawSectionChanges = request.sectionChanges;\nconst requestSectionChanges = rawSectionChanges || {};\n\nconst toText = (value) => {\n const raw = value && value.value ? value.value : value;\n return raw && raw.trim ? raw.trim() : '';\n};\nconst asList = (value) => Array.isArray(value) ? value : [];\nconst hasType = (value) => value && value.type;\nconst escapePointer = (value) => {\n const text = toText(value);\n return text.split('~').join('~0').split('/').join('~1');\n};\nconst requestChangeset = asList(rawChangeset);\n\nconst uniqueKeys = (values, label) => {\n const seen = new Set();\n const output = [];\n for (const value of values) {\n const key = toText(value);\n if (!key) {\n issues.push(label + ' contains invalid key');\n continue;\n }\n if (seen.has(key)) {\n issues.push(label + ' contains duplicate key: ' + key);\n continue;\n }\n seen.add(key);\n output.push(key);\n }\n return output;\n};\n\nconst sameStringSet = (left, right) => {\n if (left.length !== right.length) return false;\n const set = new Set(left);\n if (set.size !== right.length) return false;\n for (const value of right) {\n if (!set.has(value)) return false;\n }\n return true;\n};\n\nconst contracts = Object(document('/contracts') || {});\n\nconst isDocumentSection = (contract) =>\n !!contract && Array.isArray(contract.relatedContracts);\n\nconst isContractsChangePolicy = (contract) => {\n if (!contract) return false;\n return 'requireSectionChanges' in contract;\n};\n\nconst findPolicy = () => {\n for (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isContractsChangePolicy(contract)) {\n return contract;\n }\n }\n return null;\n};\n\nconst policy = findPolicy();\nconst policyEnabled = !!policy && policy.requireSectionChanges !== false;\n\nif (!toText(changeDescription)) {\n issues.push('changeDescription is missing');\n}\n\nconst hasChangeset = !!rawChangeset;\nconst hasSectionChanges = !!rawSectionChanges;\n\nif (!hasChangeset && !hasSectionChanges) {\n issues.push('changeset or sectionChanges is required');\n}\n\nconst isContractsPath = (path) => {\n const value = toText(path);\n return value === '/contracts' || value.startsWith('/contracts/');\n};\nif (policyEnabled && hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isContractsPath(entry.path)) {\n issues.push('changeset cannot modify /contracts when Contracts Change Policy is enabled');\n break;\n }\n }\n}\nconst isProposedChangePath = (path) =>\n toText(path).startsWith('/proposedChange');\nif (hasChangeset) {\n for (const entry of requestChangeset) {\n if (entry && isProposedChangePath(entry.path)) {\n issues.push('changeset cannot modify /proposedChange');\n break;\n }\n }\n}\n\nconst existingSections = {};\nfor (const key of Object.keys(contracts)) {\n const contract = contracts[key];\n if (isDocumentSection(contract)) {\n existingSections[key] = contract;\n }\n}\n\nconst contractIndex = {};\nfor (const sectionKey of Object.keys(existingSections)) {\n const section = existingSections[sectionKey];\n const related = asList(section.relatedContracts);\n for (const relatedKey of related) {\n const contractKey = toText(relatedKey);\n if (!contractKey) continue;\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n contractIndex[contractKey] = null;\n } else if (!contractIndex[contractKey]) {\n contractIndex[contractKey] = sectionKey;\n }\n }\n}\n\nconst normalizeSectionDefinition = (sectionDef, label) => {\n if (!sectionDef) {\n issues.push(label + ' entry must be an object');\n return null;\n }\n const sectionKey = toText(sectionDef.sectionKey);\n if (!sectionKey) {\n issues.push(label + ' sectionKey is missing');\n return null;\n }\n const section = sectionDef.section;\n if (!section) {\n issues.push(label + ' section is missing');\n return null;\n }\n\n const rawContractsMap = sectionDef.contracts && sectionDef.contracts.value\n ? sectionDef.contracts.value\n : sectionDef.contracts || {};\n const contractDefs = [];\n const contractKeys = [];\n for (const [rawKey, contract] of Object.entries(rawContractsMap)) {\n if (\n rawKey === 'type' ||\n rawKey === 'keyType' ||\n rawKey === 'valueType' ||\n rawKey === 'description'\n ) {\n continue;\n }\n const key = toText(rawKey);\n if (!key) {\n issues.push(label + ' contract key is missing');\n continue;\n }\n if (!contract) {\n issues.push(label + ' contract ' + key + ' is missing or invalid');\n continue;\n }\n if (!hasType(contract)) {\n issues.push(label + ' contract ' + key + ' is missing type');\n }\n contractDefs.push({ key, contract });\n contractKeys.push(key);\n }\n\n if (!hasType(section)) {\n issues.push(label + ' section ' + sectionKey + ' is missing type');\n }\n\n const related = section.relatedContracts\n ? uniqueKeys(asList(section.relatedContracts), label + ' section ' + sectionKey + ' relatedContracts')\n : null;\n if (related && !sameStringSet(related, contractKeys)) {\n issues.push(label + ' section ' + sectionKey + ' relatedContracts must match contracts');\n }\n\n const normalizedRelated = related || contractKeys;\n const normalizedSection = Object.assign({}, section, {\n type: 'Conversation/Document Section',\n relatedContracts: normalizedRelated\n });\n\n return {\n sectionKey,\n section: normalizedSection,\n contractDefs,\n contractKeys\n };\n};\n\nconst sectionChangeset = [];\nconst seenSectionKeys = new Set();\nconst seenContractKeys = new Set();\n\nconst addList = asList(requestSectionChanges.add);\nconst modifyList = asList(requestSectionChanges.modify);\nconst removeList = asList(requestSectionChanges.remove);\n\nfor (const entry of addList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.add');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n if (contracts[sectionKey]) {\n issues.push('section key already exists at /contracts/' + sectionKey);\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contracts[contractKey]) {\n issues.push('contract key already exists at /contracts/' + contractKey);\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n sectionChangeset.push({\n op: 'add',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nfor (const entry of modifyList) {\n const normalized = normalizeSectionDefinition(entry, 'sectionChanges.modify');\n if (!normalized) continue;\n const sectionKey = normalized.sectionKey;\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n } else if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n }\n\n const existingRelated =\n existingSection && existingSection.relatedContracts\n ? asList(existingSection.relatedContracts)\n : [];\n if (existingSection && !existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of normalized.contractKeys) {\n if (seenContractKeys.has(contractKey)) {\n issues.push('contract key used by multiple sections in request: ' + contractKey);\n continue;\n }\n seenContractKeys.add(contractKey);\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n }\n }\n\n for (const contractDef of normalized.contractDefs) {\n const op = contracts[contractDef.key] ? 'replace' : 'add';\n sectionChangeset.push({\n op,\n path: '/contracts/' + escapePointer(contractDef.key),\n val: contractDef.contract\n });\n }\n\n const toRemove = uniqueKeys(existingRelated, 'sectionChanges.modify remove list').filter(\n (key) => !normalized.contractKeys.includes(key)\n );\n for (const contractKey of toRemove) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n\n sectionChangeset.push({\n op: 'replace',\n path: '/contracts/' + escapePointer(sectionKey),\n val: normalized.section\n });\n}\n\nconst removeKeys = uniqueKeys(removeList, 'sectionChanges.remove');\nfor (const sectionKey of removeKeys) {\n if (seenSectionKeys.has(sectionKey)) {\n issues.push('section key duplicated in sectionChanges: ' + sectionKey);\n continue;\n }\n seenSectionKeys.add(sectionKey);\n\n const existingSection = contracts[sectionKey];\n if (!existingSection) {\n issues.push('section key does not exist at /contracts/' + sectionKey);\n continue;\n }\n if (!isDocumentSection(existingSection)) {\n issues.push('existing section at /contracts/' + sectionKey + ' is not a Document Section');\n continue;\n }\n\n const related = existingSection.relatedContracts\n ? uniqueKeys(asList(existingSection.relatedContracts), 'sectionChanges.remove relatedContracts')\n : [];\n if (!existingSection.relatedContracts) {\n issues.push('existing section ' + sectionKey + ' is missing relatedContracts');\n }\n\n for (const contractKey of related) {\n if (contractIndex[contractKey] && contractIndex[contractKey] !== sectionKey) {\n issues.push('contract key ' + contractKey + ' is linked to another section');\n continue;\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(contractKey)\n });\n }\n sectionChangeset.push({\n op: 'remove',\n path: '/contracts/' + escapePointer(sectionKey)\n });\n}\nconst combinedChangeset = sectionChangeset.concat(hasChangeset ? requestChangeset : []);\n\nif (combinedChangeset.length === 0) {\n issues.push('no changes provided');\n}\n\nif (issues.length > 0) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: issues.join('; ')\n }\n ]\n }\n}\n\nconst postfixValue = currentContract.postfix || '';\nconst path = '/proposedChange' + postfixValue;\n\nif (document(path)) {\n return {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: \"Can not propose change when it already exists at \" + path\n }\n ]\n }\n}\n\nconst proposedPayload = {\n changeDescription\n};\n\nproposedPayload.preparedChangeset = combinedChangeset;\n\nif (hasChangeset) {\n proposedPayload.changeset = requestChangeset;\n}\n\nconst hasSectionChangesData = addList.length || modifyList.length || removeList.length;\nif (hasSectionChangesData) {\n proposedPayload.sectionChanges = rawSectionChanges;\n}\n\nreturn {\n changeset: [{\n op: 'add',\n path,\n val: proposedPayload\n }]\n};\n",
|
|
24
24
|
},
|
|
25
25
|
name: 'Prepare',
|
|
26
26
|
type: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProposeChangeWorkflow.js","sourceRoot":"","sources":["../../../../src/packages/conversation/contents/ProposeChangeWorkflow.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,WAAW,EAAE,0DAA0D;IACvE,IAAI,EAAE,yBAAyB;IAC/B,OAAO,EAAE;QACP,WAAW,EACT,iEAAiE;QACnE,IAAI,EAAE;YACJ,MAAM,EAAE,8CAA8C;SACvD;KACF;IACD,OAAO,EAAE;QACP,WAAW,EAAE,6CAA6C;QAC1D,IAAI,EAAE;YACJ,MAAM,EAAE,8CAA8C;SACvD;KACF;IACD,KAAK,EAAE;QACL,KAAK,EAAE;YACL;gBACE,IAAI,EAAE;oBACJ,IAAI,EAAE;wBACJ,MAAM,EAAE,8CAA8C;qBACvD;oBACD,KAAK,EACH
|
|
1
|
+
{"version":3,"file":"ProposeChangeWorkflow.js","sourceRoot":"","sources":["../../../../src/packages/conversation/contents/ProposeChangeWorkflow.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,WAAW,EAAE,0DAA0D;IACvE,IAAI,EAAE,yBAAyB;IAC/B,OAAO,EAAE;QACP,WAAW,EACT,iEAAiE;QACnE,IAAI,EAAE;YACJ,MAAM,EAAE,8CAA8C;SACvD;KACF;IACD,OAAO,EAAE;QACP,WAAW,EAAE,6CAA6C;QAC1D,IAAI,EAAE;YACJ,MAAM,EAAE,8CAA8C;SACvD;KACF;IACD,KAAK,EAAE;QACL,KAAK,EAAE;YACL;gBACE,IAAI,EAAE;oBACJ,IAAI,EAAE;wBACJ,MAAM,EAAE,8CAA8C;qBACvD;oBACD,KAAK,EACH,+6XAA+6X;iBACl7X;gBACD,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE;oBACJ,MAAM,EAAE,8CAA8C;iBACvD;aACF;YACD;gBACE,SAAS,EAAE;oBACT,IAAI,EAAE;wBACJ,MAAM,EAAE,8CAA8C;qBACvD;oBACD,KAAK,EAAE,4BAA4B;iBACpC;gBACD,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE;oBACJ,MAAM,EAAE,8CAA8C;iBACvD;aACF;SACF;KACF;IACD,IAAI,EAAE;QACJ,MAAM,EAAE,8CAA8C;KACvD;CACO,CAAC"}
|
|
@@ -13,7 +13,7 @@ export declare const RejectChangeWorkflow: {
|
|
|
13
13
|
readonly type: {
|
|
14
14
|
readonly blueId: "DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K";
|
|
15
15
|
};
|
|
16
|
-
readonly value: "const postfix = currentContract.postfix
|
|
16
|
+
readonly value: "const postfix = currentContract.postfix || ''\nconst path = '/proposedChange' + postfix\n\nconst proposedChange = document(path)\nif (proposedChange) {\n return {\n changeset: [{ op: 'remove', path }]\n }\n}\n\nreturn {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: \"Proposed change does not exist at \" + path\n }\n ]\n};\n";
|
|
17
17
|
};
|
|
18
18
|
readonly name: "Prepare";
|
|
19
19
|
readonly type: {
|
|
@@ -14,7 +14,7 @@ export const RejectChangeWorkflow = {
|
|
|
14
14
|
type: {
|
|
15
15
|
blueId: 'DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K',
|
|
16
16
|
},
|
|
17
|
-
value: "const postfix = currentContract.postfix
|
|
17
|
+
value: "const postfix = currentContract.postfix || ''\nconst path = '/proposedChange' + postfix\n\nconst proposedChange = document(path)\nif (proposedChange) {\n return {\n changeset: [{ op: 'remove', path }]\n }\n}\n\nreturn {\n changeset: [],\n events: [\n {\n type: \"Conversation/Proposed Change Invalid\",\n reason: \"Proposed change does not exist at \" + path\n }\n ]\n};\n",
|
|
18
18
|
},
|
|
19
19
|
name: 'Prepare',
|
|
20
20
|
type: {
|