@opensaas/stack-core 0.44.0-alpha.6 → 0.44.0-alpha.7
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/CHANGELOG.md +655 -0
- package/dist/.build-hash +1 -1
- package/dist/access/actor.d.ts +56 -0
- package/dist/access/actor.d.ts.map +1 -0
- package/dist/access/actor.js +66 -0
- package/dist/access/actor.js.map +1 -0
- package/dist/access/decide-advertisement.d.ts +55 -0
- package/dist/access/decide-advertisement.d.ts.map +1 -0
- package/dist/access/decide-advertisement.js +125 -0
- package/dist/access/decide-advertisement.js.map +1 -0
- package/dist/access/declared-dependencies.d.ts +4 -89
- package/dist/access/declared-dependencies.d.ts.map +1 -1
- package/dist/access/declared-dependencies.js +14 -84
- package/dist/access/declared-dependencies.js.map +1 -1
- package/dist/access/depth-limits.d.ts +2 -0
- package/dist/access/depth-limits.d.ts.map +1 -1
- package/dist/access/depth-limits.js +2 -0
- package/dist/access/depth-limits.js.map +1 -1
- package/dist/access/engine.d.ts +1 -24
- package/dist/access/engine.d.ts.map +1 -1
- package/dist/access/engine.js +0 -35
- package/dist/access/engine.js.map +1 -1
- package/dist/access/field-access.d.ts +21 -19
- package/dist/access/field-access.d.ts.map +1 -1
- package/dist/access/field-access.js +100 -122
- package/dist/access/field-access.js.map +1 -1
- package/dist/access/index.d.ts +3 -6
- package/dist/access/index.d.ts.map +1 -1
- package/dist/access/index.js +3 -6
- package/dist/access/index.js.map +1 -1
- package/dist/access/rule-item.d.ts +7 -7
- package/dist/access/rule-item.d.ts.map +1 -1
- package/dist/access/rule-item.js +38 -38
- package/dist/access/rule-item.js.map +1 -1
- package/dist/access/session-vocabulary.d.ts +124 -0
- package/dist/access/session-vocabulary.d.ts.map +1 -0
- package/dist/access/session-vocabulary.js +366 -0
- package/dist/access/session-vocabulary.js.map +1 -0
- package/dist/access/transaction-registry.d.ts +6 -0
- package/dist/access/transaction-registry.d.ts.map +1 -1
- package/dist/access/transaction-registry.js +19 -2
- package/dist/access/transaction-registry.js.map +1 -1
- package/dist/access/types.d.ts +55 -6
- package/dist/access/types.d.ts.map +1 -1
- package/dist/access/vocabulary-filter-specs.d.ts +17 -0
- package/dist/access/vocabulary-filter-specs.d.ts.map +1 -0
- package/dist/access/vocabulary-filter-specs.js +27 -0
- package/dist/access/vocabulary-filter-specs.js.map +1 -0
- package/dist/client-safe.d.ts +8 -0
- package/dist/client-safe.d.ts.map +1 -0
- package/dist/client-safe.js +8 -0
- package/dist/client-safe.js.map +1 -0
- package/dist/config/field-kind.d.ts +7 -21
- package/dist/config/field-kind.d.ts.map +1 -1
- package/dist/config/field-kind.js +8 -5
- package/dist/config/field-kind.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +3 -2
- package/dist/config/index.js.map +1 -1
- package/dist/config/mcp-default-tools.d.ts +3 -0
- package/dist/config/mcp-default-tools.d.ts.map +1 -0
- package/dist/config/mcp-default-tools.js +14 -0
- package/dist/config/mcp-default-tools.js.map +1 -0
- package/dist/config/mcp-tool-names.d.ts +2 -0
- package/dist/config/mcp-tool-names.d.ts.map +1 -1
- package/dist/config/mcp-tool-names.js +17 -5
- package/dist/config/mcp-tool-names.js.map +1 -1
- package/dist/config/nav-count.d.ts +8 -16
- package/dist/config/nav-count.d.ts.map +1 -1
- package/dist/config/nav-count.js +20 -32
- package/dist/config/nav-count.js.map +1 -1
- package/dist/config/plugin-engine.d.ts.map +1 -1
- package/dist/config/plugin-engine.js +6 -0
- package/dist/config/plugin-engine.js.map +1 -1
- package/dist/config/types.d.ts +141 -28
- package/dist/config/types.d.ts.map +1 -1
- package/dist/context/engine-context.d.ts +2 -0
- package/dist/context/engine-context.d.ts.map +1 -1
- package/dist/context/engine-context.js +8 -0
- package/dist/context/engine-context.js.map +1 -1
- package/dist/context/hook-pipeline.d.ts +2 -1
- package/dist/context/hook-pipeline.d.ts.map +1 -1
- package/dist/context/hook-pipeline.js +4 -2
- package/dist/context/hook-pipeline.js.map +1 -1
- package/dist/context/index.d.ts +5 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +156 -84
- package/dist/context/index.js.map +1 -1
- package/dist/context/junction.d.ts +28 -21
- package/dist/context/junction.d.ts.map +1 -1
- package/dist/context/junction.js +74 -69
- package/dist/context/junction.js.map +1 -1
- package/dist/context/plugin-field-write.d.ts.map +1 -1
- package/dist/context/plugin-field-write.js +19 -25
- package/dist/context/plugin-field-write.js.map +1 -1
- package/dist/context/process-lifetime.d.ts +8 -0
- package/dist/context/process-lifetime.d.ts.map +1 -0
- package/dist/context/process-lifetime.js +14 -0
- package/dist/context/process-lifetime.js.map +1 -0
- package/dist/context/relationship-input.d.ts +2 -15
- package/dist/context/relationship-input.d.ts.map +1 -1
- package/dist/context/relationship-input.js +44 -85
- package/dist/context/relationship-input.js.map +1 -1
- package/dist/context/transaction-boundary.d.ts +3 -2
- package/dist/context/transaction-boundary.d.ts.map +1 -1
- package/dist/context/transaction-boundary.js +17 -2
- package/dist/context/transaction-boundary.js.map +1 -1
- package/dist/context/write-pipeline.d.ts +5 -19
- package/dist/context/write-pipeline.d.ts.map +1 -1
- package/dist/context/write-pipeline.js +40 -98
- package/dist/context/write-pipeline.js.map +1 -1
- package/dist/context/write-target.d.ts +52 -0
- package/dist/context/write-target.d.ts.map +1 -0
- package/dist/context/write-target.js +118 -0
- package/dist/context/write-target.js.map +1 -0
- package/dist/contract/dependencies.d.ts +24 -10
- package/dist/contract/dependencies.d.ts.map +1 -1
- package/dist/contract/dependencies.js +120 -80
- package/dist/contract/dependencies.js.map +1 -1
- package/dist/contract/derive.d.ts +6 -11
- package/dist/contract/derive.d.ts.map +1 -1
- package/dist/contract/derive.js +256 -211
- package/dist/contract/derive.js.map +1 -1
- package/dist/contract/id-boundary.js +1 -1
- package/dist/contract/id-boundary.js.map +1 -1
- package/dist/contract/strategy.d.ts +13 -0
- package/dist/contract/strategy.d.ts.map +1 -0
- package/dist/contract/strategy.js +38 -0
- package/dist/contract/strategy.js.map +1 -0
- package/dist/db/client-alias.d.ts +12 -0
- package/dist/db/client-alias.d.ts.map +1 -0
- package/dist/db/client-alias.js +8 -0
- package/dist/db/client-alias.js.map +1 -0
- package/dist/extend.d.ts +1 -1
- package/dist/extend.d.ts.map +1 -1
- package/dist/extend.js.map +1 -1
- package/dist/fields/index.d.ts +0 -3
- package/dist/fields/index.d.ts.map +1 -1
- package/dist/fields/index.js +25 -10
- package/dist/fields/index.js.map +1 -1
- package/dist/filter/collect.d.ts +28 -39
- package/dist/filter/collect.d.ts.map +1 -1
- package/dist/filter/collect.js +46 -68
- package/dist/filter/collect.js.map +1 -1
- package/dist/filter/index.d.ts +1 -1
- package/dist/filter/index.d.ts.map +1 -1
- package/dist/filter/index.js +1 -1
- package/dist/filter/index.js.map +1 -1
- package/dist/filter/map.d.ts +4 -0
- package/dist/filter/map.d.ts.map +1 -1
- package/dist/filter/map.js +36 -3
- package/dist/filter/map.js.map +1 -1
- package/dist/hooks/index.d.ts +4 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +34 -5
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +5 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +4 -5
- package/dist/internal.js.map +1 -1
- package/dist/mcp/advertise.d.ts +5 -13
- package/dist/mcp/advertise.d.ts.map +1 -1
- package/dist/mcp/advertise.js +7 -22
- package/dist/mcp/advertise.js.map +1 -1
- package/dist/mcp/arguments.d.ts.map +1 -1
- package/dist/mcp/arguments.js +8 -11
- package/dist/mcp/arguments.js.map +1 -1
- package/dist/mcp/field-schema.d.ts +4 -15
- package/dist/mcp/field-schema.d.ts.map +1 -1
- package/dist/mcp/field-schema.js +41 -71
- package/dist/mcp/field-schema.js.map +1 -1
- package/dist/mcp/handler.d.ts +111 -18
- package/dist/mcp/handler.d.ts.map +1 -1
- package/dist/mcp/handler.js +168 -73
- package/dist/mcp/handler.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/procedure-tools.d.ts +63 -0
- package/dist/mcp/procedure-tools.d.ts.map +1 -0
- package/dist/mcp/procedure-tools.js +139 -0
- package/dist/mcp/procedure-tools.js.map +1 -0
- package/dist/mcp/projection.d.ts.map +1 -1
- package/dist/mcp/projection.js +28 -36
- package/dist/mcp/projection.js.map +1 -1
- package/dist/mcp/reachability.d.ts +5 -1
- package/dist/mcp/reachability.d.ts.map +1 -1
- package/dist/mcp/reachability.js +24 -5
- package/dist/mcp/reachability.js.map +1 -1
- package/dist/mcp/relation-member.d.ts +15 -0
- package/dist/mcp/relation-member.d.ts.map +1 -0
- package/dist/mcp/relation-member.js +50 -0
- package/dist/mcp/relation-member.js.map +1 -0
- package/dist/mcp/types.d.ts +12 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/where-id-boundary.d.ts.map +1 -1
- package/dist/mcp/where-id-boundary.js +12 -24
- package/dist/mcp/where-id-boundary.js.map +1 -1
- package/dist/mcp/where-reachability.d.ts +2 -0
- package/dist/mcp/where-reachability.d.ts.map +1 -1
- package/dist/mcp/where-reachability.js +39 -23
- package/dist/mcp/where-reachability.js.map +1 -1
- package/dist/members/claims.d.ts +71 -0
- package/dist/members/claims.d.ts.map +1 -0
- package/dist/members/claims.js +199 -0
- package/dist/members/claims.js.map +1 -0
- package/dist/members/list-members.d.ts +87 -0
- package/dist/members/list-members.d.ts.map +1 -0
- package/dist/members/list-members.js +250 -0
- package/dist/members/list-members.js.map +1 -0
- package/dist/procedures/client.d.ts +163 -0
- package/dist/procedures/client.d.ts.map +1 -0
- package/dist/procedures/client.js +152 -0
- package/dist/procedures/client.js.map +1 -0
- package/dist/procedures/codes.d.ts +23 -0
- package/dist/procedures/codes.d.ts.map +1 -0
- package/dist/procedures/codes.js +46 -0
- package/dist/procedures/codes.js.map +1 -0
- package/dist/procedures/context-face.d.ts +4 -0
- package/dist/procedures/context-face.d.ts.map +1 -0
- package/dist/procedures/context-face.js +31 -0
- package/dist/procedures/context-face.js.map +1 -0
- package/dist/procedures/failures.d.ts +31 -0
- package/dist/procedures/failures.d.ts.map +1 -0
- package/dist/procedures/failures.js +51 -0
- package/dist/procedures/failures.js.map +1 -0
- package/dist/procedures/http.d.ts +114 -0
- package/dist/procedures/http.d.ts.map +1 -0
- package/dist/procedures/http.js +224 -0
- package/dist/procedures/http.js.map +1 -0
- package/dist/procedures/index.d.ts +7 -0
- package/dist/procedures/index.d.ts.map +1 -0
- package/dist/procedures/index.js +11 -0
- package/dist/procedures/index.js.map +1 -0
- package/dist/procedures/procedure.d.ts +204 -0
- package/dist/procedures/procedure.d.ts.map +1 -0
- package/dist/procedures/procedure.js +123 -0
- package/dist/procedures/procedure.js.map +1 -0
- package/dist/procedures/result.d.ts +42 -0
- package/dist/procedures/result.d.ts.map +1 -0
- package/dist/procedures/result.js +51 -0
- package/dist/procedures/result.js.map +1 -0
- package/dist/procedures/run.d.ts +36 -0
- package/dist/procedures/run.d.ts.map +1 -0
- package/dist/procedures/run.js +76 -0
- package/dist/procedures/run.js.map +1 -0
- package/dist/procedures/server.d.ts +131 -0
- package/dist/procedures/server.d.ts.map +1 -0
- package/dist/procedures/server.js +115 -0
- package/dist/procedures/server.js.map +1 -0
- package/dist/procedures/validate.d.ts +60 -0
- package/dist/procedures/validate.d.ts.map +1 -0
- package/dist/procedures/validate.js +254 -0
- package/dist/procedures/validate.js.map +1 -0
- package/dist/procedures/web-session.d.ts +12 -0
- package/dist/procedures/web-session.d.ts.map +1 -0
- package/dist/procedures/web-session.js +35 -0
- package/dist/procedures/web-session.js.map +1 -0
- package/dist/query/relationship-options.d.ts +2 -0
- package/dist/query/relationship-options.d.ts.map +1 -1
- package/dist/query/relationship-options.js +3 -2
- package/dist/query/relationship-options.js.map +1 -1
- package/dist/secured/binding.d.ts +84 -0
- package/dist/secured/binding.d.ts.map +1 -0
- package/dist/secured/binding.js +52 -0
- package/dist/secured/binding.js.map +1 -0
- package/dist/secured/declared-branch.d.ts +11 -0
- package/dist/secured/declared-branch.d.ts.map +1 -0
- package/dist/secured/declared-branch.js +17 -0
- package/dist/secured/declared-branch.js.map +1 -0
- package/dist/secured/field-visibility.d.ts +56 -0
- package/dist/secured/field-visibility.d.ts.map +1 -0
- package/dist/secured/field-visibility.js +624 -0
- package/dist/secured/field-visibility.js.map +1 -0
- package/dist/secured/include.d.ts +68 -41
- package/dist/secured/include.d.ts.map +1 -1
- package/dist/secured/include.js +217 -115
- package/dist/secured/include.js.map +1 -1
- package/dist/secured/lower.d.ts.map +1 -1
- package/dist/secured/lower.js +1 -3
- package/dist/secured/lower.js.map +1 -1
- package/dist/secured/read.d.ts +11 -108
- package/dist/secured/read.d.ts.map +1 -1
- package/dist/secured/read.js +46 -633
- package/dist/secured/read.js.map +1 -1
- package/dist/secured/select.d.ts +0 -24
- package/dist/secured/select.d.ts.map +1 -1
- package/dist/secured/select.js +60 -153
- package/dist/secured/select.js.map +1 -1
- package/dist/secured/vocabulary.d.ts +13 -1
- package/dist/secured/vocabulary.d.ts.map +1 -1
- package/dist/secured/vocabulary.js +173 -83
- package/dist/secured/vocabulary.js.map +1 -1
- package/dist/testing/untyped-rule.d.ts +8 -0
- package/dist/testing/untyped-rule.d.ts.map +1 -0
- package/dist/testing/untyped-rule.js +4 -0
- package/dist/testing/untyped-rule.js.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/rows.d.ts +18 -1
- package/dist/types/rows.d.ts.map +1 -1
- package/dist/validation/config-refusal.d.ts +3 -1
- package/dist/validation/config-refusal.d.ts.map +1 -1
- package/dist/validation/database-config.d.ts +1 -0
- package/dist/validation/database-config.d.ts.map +1 -1
- package/dist/validation/database-config.js +1 -1
- package/dist/validation/database-config.js.map +1 -1
- package/dist/validation/default-value.d.ts.map +1 -1
- package/dist/validation/default-value.js +3 -8
- package/dist/validation/default-value.js.map +1 -1
- package/dist/validation/extension-packs.d.ts.map +1 -1
- package/dist/validation/extension-packs.js +1 -0
- package/dist/validation/extension-packs.js.map +1 -1
- package/dist/validation/field-config.d.ts +3 -2
- package/dist/validation/field-config.d.ts.map +1 -1
- package/dist/validation/field-config.js +3 -1
- package/dist/validation/field-config.js.map +1 -1
- package/dist/validation/field-names.d.ts +2 -1
- package/dist/validation/field-names.d.ts.map +1 -1
- package/dist/validation/field-names.js +76 -63
- package/dist/validation/field-names.js.map +1 -1
- package/dist/validation/identifier-names.d.ts +1 -0
- package/dist/validation/identifier-names.d.ts.map +1 -1
- package/dist/validation/identifier-names.js +17 -9
- package/dist/validation/identifier-names.js.map +1 -1
- package/dist/validation/needs-closure.d.ts +30 -14
- package/dist/validation/needs-closure.d.ts.map +1 -1
- package/dist/validation/needs-closure.js +184 -31
- package/dist/validation/needs-closure.js.map +1 -1
- package/dist/validation/schema.d.ts +1 -0
- package/dist/validation/schema.d.ts.map +1 -1
- package/dist/validation/schema.js +4 -2
- package/dist/validation/schema.js.map +1 -1
- package/package.json +20 -4
- package/dist/access/field-visibility.d.ts +0 -11
- package/dist/access/field-visibility.d.ts.map +0 -1
- package/dist/access/field-visibility.js +0 -366
- package/dist/access/field-visibility.js.map +0 -1
- package/dist/access/query-validation.d.ts +0 -30
- package/dist/access/query-validation.d.ts.map +0 -1
- package/dist/access/query-validation.js +0 -49
- package/dist/access/query-validation.js.map +0 -1
- package/dist/access/system-fields.d.ts +0 -2
- package/dist/access/system-fields.d.ts.map +0 -1
- package/dist/access/system-fields.js +0 -7
- package/dist/access/system-fields.js.map +0 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// The reserved failure codes, the host's refusal statuses and the name and code
|
|
2
|
+
// patterns. Imports nothing, so the browser client shares them with the host.
|
|
3
|
+
/** The failure codes the stack owns. A procedure cannot declare one of these. */
|
|
4
|
+
export const RESERVED_FAILURE_CODES = [
|
|
5
|
+
'UNAUTHENTICATED',
|
|
6
|
+
'DENIED',
|
|
7
|
+
'INVALID_INPUT',
|
|
8
|
+
'VALIDATION',
|
|
9
|
+
'RETRY',
|
|
10
|
+
'CONFLICT',
|
|
11
|
+
'INTERNAL',
|
|
12
|
+
];
|
|
13
|
+
const RESERVED = new Set(RESERVED_FAILURE_CODES);
|
|
14
|
+
/** Whether `code` is one of the codes the stack owns. */
|
|
15
|
+
export function isReservedFailureCode(code) {
|
|
16
|
+
return RESERVED.has(code);
|
|
17
|
+
}
|
|
18
|
+
export const FAILURE_STATUS = {
|
|
19
|
+
UNAUTHENTICATED: 401,
|
|
20
|
+
DENIED: 403,
|
|
21
|
+
INVALID_INPUT: 400,
|
|
22
|
+
VALIDATION: 400,
|
|
23
|
+
RETRY: 409,
|
|
24
|
+
CONFLICT: 409,
|
|
25
|
+
INTERNAL: 500,
|
|
26
|
+
};
|
|
27
|
+
/** What a procedure name is. A host serves no other. */
|
|
28
|
+
export const PROCEDURE_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
|
|
29
|
+
/** What a declared failure code is. */
|
|
30
|
+
export const DECLARED_FAILURE_CODE_PATTERN = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
31
|
+
/**
|
|
32
|
+
* The statuses the HTTP host refuses a request under before the pipeline
|
|
33
|
+
* runs, each answered `{ error: "<message>" }` rather than with the envelope.
|
|
34
|
+
*/
|
|
35
|
+
export const REFUSAL_STATUS = {
|
|
36
|
+
NOT_FOUND: 404,
|
|
37
|
+
METHOD_NOT_ALLOWED: 405,
|
|
38
|
+
BODY_TOO_LARGE: 413,
|
|
39
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
40
|
+
};
|
|
41
|
+
const REFUSALS = new Set(Object.values(REFUSAL_STATUS));
|
|
42
|
+
/** Whether `status` is one the HTTP host refuses a request under. */
|
|
43
|
+
export function isRefusalStatus(status) {
|
|
44
|
+
return REFUSALS.has(status);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=codes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codes.js","sourceRoot":"","sources":["../../src/procedures/codes.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,8EAA8E;AAE9E,iFAAiF;AACjF,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,iBAAiB;IACjB,QAAQ;IACR,eAAe;IACf,YAAY;IACZ,OAAO;IACP,UAAU;IACV,UAAU;CACF,CAAA;AAIV,MAAM,QAAQ,GAAwB,IAAI,GAAG,CAAS,sBAAsB,CAAC,CAAA;AAE7E,yDAAyD;AACzD,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AAC3B,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GAAkD;IAC3E,eAAe,EAAE,GAAG;IACpB,MAAM,EAAE,GAAG;IACX,aAAa,EAAE,GAAG;IAClB,UAAU,EAAE,GAAG;IACf,KAAK,EAAE,GAAG;IACV,QAAQ,EAAE,GAAG;IACb,QAAQ,EAAE,GAAG;CACd,CAAA;AAED,wDAAwD;AACxD,MAAM,CAAC,MAAM,sBAAsB,GAAG,+BAA+B,CAAA;AAErE,uCAAuC;AACvC,MAAM,CAAC,MAAM,6BAA6B,GAAG,wBAAwB,CAAA;AAErE;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,SAAS,EAAE,GAAG;IACd,kBAAkB,EAAE,GAAG;IACvB,cAAc,EAAE,GAAG;IACnB,sBAAsB,EAAE,GAAG;CACnB,CAAA;AAEV,MAAM,QAAQ,GAAwB,IAAI,GAAG,CAAS,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAA;AAEpF,qEAAqE;AACrE,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,OAAO,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AAC7B,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProcedureContext, ProcedureHostContext, ProcedureHostTransactionContext } from './procedure.js';
|
|
2
|
+
/** The runtime-narrowed context a procedure is handed. See ADR-0086. */
|
|
3
|
+
export declare function procedureContextOf<C extends ProcedureHostContext<Tx>, Tx extends ProcedureHostTransactionContext>(context: C): ProcedureContext<C, Tx>;
|
|
4
|
+
//# sourceMappingURL=context-face.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-face.d.ts","sourceRoot":"","sources":["../../src/procedures/context-face.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EACpB,+BAA+B,EAEhC,MAAM,gBAAgB,CAAA;AAqBvB,wEAAwE;AACxE,wBAAgB,kBAAkB,CAChC,CAAC,SAAS,oBAAoB,CAAC,EAAE,CAAC,EAClC,EAAE,SAAS,+BAA+B,EAC1C,OAAO,EAAE,CAAC,GAAG,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,CAarC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { throwReturnedFailure } from './failures.js';
|
|
2
|
+
function transactionContextOf(transaction) {
|
|
3
|
+
const face = Object.freeze({
|
|
4
|
+
db: transaction.db,
|
|
5
|
+
session: transaction.session,
|
|
6
|
+
storage: transaction.storage,
|
|
7
|
+
plugins: transaction.plugins,
|
|
8
|
+
advisoryLock: (key) => transaction.advisoryLock(key),
|
|
9
|
+
transaction: (fn) => transaction.transaction(async () => {
|
|
10
|
+
const result = await fn(face);
|
|
11
|
+
throwReturnedFailure(result);
|
|
12
|
+
return result;
|
|
13
|
+
}),
|
|
14
|
+
});
|
|
15
|
+
return face;
|
|
16
|
+
}
|
|
17
|
+
/** The runtime-narrowed context a procedure is handed. See ADR-0086. */
|
|
18
|
+
export function procedureContextOf(context) {
|
|
19
|
+
return Object.freeze({
|
|
20
|
+
db: context.db,
|
|
21
|
+
session: context.session,
|
|
22
|
+
storage: context.storage,
|
|
23
|
+
plugins: context.plugins,
|
|
24
|
+
transaction: (fn) => context.transaction(async (transaction) => {
|
|
25
|
+
const result = await fn(transactionContextOf(transaction));
|
|
26
|
+
throwReturnedFailure(result);
|
|
27
|
+
return result;
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=context-face.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-face.js","sourceRoot":"","sources":["../../src/procedures/context-face.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAQpD,SAAS,oBAAoB,CAC3B,WAAe;IAEf,MAAM,IAAI,GAAoC,MAAM,CAAC,MAAM,CAAC;QAC1D,EAAE,EAAE,WAAW,CAAC,EAAE;QAClB,OAAO,EAAE,WAAW,CAAC,OAAO;QAC5B,OAAO,EAAE,WAAW,CAAC,OAAO;QAC5B,OAAO,EAAE,WAAW,CAAC,OAAO;QAC5B,YAAY,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC;QAC5D,WAAW,EAAE,CAAI,EAA8D,EAAE,EAAE,CACjF,WAAW,CAAC,WAAW,CAAC,KAAK,IAAI,EAAE;YACjC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,CAAA;YAC7B,oBAAoB,CAAC,MAAM,CAAC,CAAA;YAC5B,OAAO,MAAM,CAAA;QACf,CAAC,CAAC;KACL,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,kBAAkB,CAGhC,OAAU;IACV,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,WAAW,EAAE,CAAI,EAA8D,EAAE,EAAE,CACjF,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;YACxC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAA;YAC1D,oBAAoB,CAAC,MAAM,CAAC,CAAA;YAC5B,OAAO,MAAM,CAAA;QACf,CAAC,CAAC;KACL,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constructs one of a procedure's declared failures, for `run` to **throw**.
|
|
3
|
+
* Throwing is what rolls back an open transaction. A failure returned from
|
|
4
|
+
* `run` or from a `context.transaction` callback is treated as thrown.
|
|
5
|
+
*
|
|
6
|
+
* @param code - one of the codes the procedure declares in `failures`.
|
|
7
|
+
* @param message - replaces the declared message for this one failure.
|
|
8
|
+
*/
|
|
9
|
+
export type ProcedureFail<TCode extends string> = (code: TCode, message?: string) => ProcedureFailureError<TCode>;
|
|
10
|
+
/**
|
|
11
|
+
* A declared failure, as `fail` constructs it. A host answers one thrown by
|
|
12
|
+
* the procedure whose `fail` constructed it with `{ success: false, error: {
|
|
13
|
+
* code, message } }`; thrown anywhere else it is an unexpected error.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ProcedureFailureError<TCode extends string = string> extends Error {
|
|
16
|
+
readonly code: TCode;
|
|
17
|
+
constructor(code: TCode, message: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The code and message of a failure constructed by the `fail` of the procedure
|
|
21
|
+
* whose frozen `failures` object is given, or `undefined` for anything else.
|
|
22
|
+
*/
|
|
23
|
+
export declare function declaredFailureOf(error: unknown, failures: object): {
|
|
24
|
+
code: string;
|
|
25
|
+
message: string;
|
|
26
|
+
} | undefined;
|
|
27
|
+
/** Throws `value` when any procedure's `fail` constructed it, so a returned failure acts as a thrown one. */
|
|
28
|
+
export declare function throwReturnedFailure(value: unknown): void;
|
|
29
|
+
/** The `fail` helper for a procedure declaring `failures`. */
|
|
30
|
+
export declare function failWith<TCode extends string>(failures: Readonly<Partial<Record<TCode, string>>>): ProcedureFail<TCode>;
|
|
31
|
+
//# sourceMappingURL=failures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failures.d.ts","sourceRoot":"","sources":["../../src/procedures/failures.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,CAAC,KAAK,SAAS,MAAM,IAAI,CAChD,IAAI,EAAE,KAAK,EACX,OAAO,CAAC,EAAE,MAAM,KACb,qBAAqB,CAAC,KAAK,CAAC,CAAA;AAEjC;;;;GAIG;AACH,qBAAa,qBAAqB,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,KAAK;IAC7E,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;IAEpB,YAAY,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAIvC;CACF;AAcD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM,GACf;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAI/C;AAED,6GAA6G;AAC7G,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAEzD;AAED,8DAA8D;AAC9D,wBAAgB,QAAQ,CAAC,KAAK,SAAS,MAAM,EAC3C,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,GACjD,aAAa,CAAC,KAAK,CAAC,CAStB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { processGlobal } from '../lib/process-global.js';
|
|
2
|
+
/**
|
|
3
|
+
* A declared failure, as `fail` constructs it. A host answers one thrown by
|
|
4
|
+
* the procedure whose `fail` constructed it with `{ success: false, error: {
|
|
5
|
+
* code, message } }`; thrown anywhere else it is an unexpected error.
|
|
6
|
+
*/
|
|
7
|
+
export class ProcedureFailureError extends Error {
|
|
8
|
+
code;
|
|
9
|
+
constructor(code, message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = 'ProcedureFailureError';
|
|
12
|
+
this.code = code;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function isWeakMap(value) {
|
|
16
|
+
return value instanceof WeakMap;
|
|
17
|
+
}
|
|
18
|
+
function failureOwners() {
|
|
19
|
+
return processGlobal('procedure-failure-owners', isWeakMap, () => new WeakMap());
|
|
20
|
+
}
|
|
21
|
+
function hasStringCode(value) {
|
|
22
|
+
return 'code' in value && typeof value.code === 'string';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The code and message of a failure constructed by the `fail` of the procedure
|
|
26
|
+
* whose frozen `failures` object is given, or `undefined` for anything else.
|
|
27
|
+
*/
|
|
28
|
+
export function declaredFailureOf(error, failures) {
|
|
29
|
+
if (!(error instanceof Error) || failureOwners().get(error) !== failures)
|
|
30
|
+
return undefined;
|
|
31
|
+
if (!hasStringCode(error) || !Object.hasOwn(failures, error.code))
|
|
32
|
+
return undefined;
|
|
33
|
+
return { code: error.code, message: error.message };
|
|
34
|
+
}
|
|
35
|
+
/** Throws `value` when any procedure's `fail` constructed it, so a returned failure acts as a thrown one. */
|
|
36
|
+
export function throwReturnedFailure(value) {
|
|
37
|
+
if (value instanceof Error && failureOwners().has(value))
|
|
38
|
+
throw value;
|
|
39
|
+
}
|
|
40
|
+
/** The `fail` helper for a procedure declaring `failures`. */
|
|
41
|
+
export function failWith(failures) {
|
|
42
|
+
return (code, message) => {
|
|
43
|
+
if (!Object.hasOwn(failures, code)) {
|
|
44
|
+
throw new Error(`Failure code ${JSON.stringify(code)} is not declared by this procedure.`);
|
|
45
|
+
}
|
|
46
|
+
const error = new ProcedureFailureError(code, message ?? failures[code] ?? code);
|
|
47
|
+
failureOwners().set(error, failures);
|
|
48
|
+
return error;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=failures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failures.js","sourceRoot":"","sources":["../../src/procedures/failures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAexD;;;;GAIG;AACH,MAAM,OAAO,qBAAqD,SAAQ,KAAK;IACpE,IAAI,CAAO;IAEpB,YAAY,IAAW,EAAE,OAAe;QACtC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAA;QACnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,KAAK,YAAY,OAAO,CAAA;AACjC,CAAC;AAED,SAAS,aAAa;IACpB,OAAO,aAAa,CAAC,0BAA0B,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,OAAO,EAAkB,CAAC,CAAA;AAClG,CAAC;AAED,SAAS,aAAa,CAAC,KAAa;IAClC,OAAO,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAA;AAC1D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAc,EACd,QAAgB;IAEhB,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,IAAI,aAAa,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAA;IAC1F,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAA;IACnF,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAA;AACrD,CAAC;AAED,6GAA6G;AAC7G,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,IAAI,KAAK,YAAY,KAAK,IAAI,aAAa,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,MAAM,KAAK,CAAA;AACvE,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,QAAQ,CACtB,QAAkD;IAElD,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;QACvB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAA;QAC5F,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,qBAAqB,CAAC,IAAI,EAAE,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAA;QAChF,aAAa,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QACpC,OAAO,KAAK,CAAA;IACd,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { OpenSaasConfig } from '../config/types.js';
|
|
2
|
+
import type { ProcedureHostContext, ProcedureRegistry } from './procedure.js';
|
|
3
|
+
/** The session type an application context carries, without its `null`. */
|
|
4
|
+
export type SessionOf<C extends ProcedureHostContext> = Exclude<C['session'], null>;
|
|
5
|
+
/** Options for {@link createProcedureHandler}. */
|
|
6
|
+
export interface ProcedureHandlerOptions<C extends ProcedureHostContext> {
|
|
7
|
+
/** The application's procedure registry. Only procedures exposing `'web'` are reachable. */
|
|
8
|
+
procedures: ProcedureRegistry<C>;
|
|
9
|
+
/**
|
|
10
|
+
* The resolved config. Procedure names share one namespace with MCP tools,
|
|
11
|
+
* and with the config the host refuses a procedure named like one of its
|
|
12
|
+
* list custom tools or plugin-registered tools. A config with plugins is a
|
|
13
|
+
* promise, so pass `await config`. Without it only the reserved
|
|
14
|
+
* `list_<list>_<operation>` pattern is refused.
|
|
15
|
+
*/
|
|
16
|
+
config?: OpenSaasConfig;
|
|
17
|
+
/** The generated `getContext`: called with the resolved session, or with nothing when anonymous. */
|
|
18
|
+
getContext: (session?: SessionOf<C>) => Promise<C>;
|
|
19
|
+
/**
|
|
20
|
+
* Resolve the cookie session for a request. Called only when the request
|
|
21
|
+
* carries a `Cookie` header from an allowed origin, with a body-less `GET`
|
|
22
|
+
* copy of the request carrying its URL and headers; a request with no
|
|
23
|
+
* credential is anonymous without asking. Resolving `null` or `undefined`
|
|
24
|
+
* means no session; resolving anything else that is not an object fails
|
|
25
|
+
* the call with `INTERNAL` and is reported to `onUnexpectedError`.
|
|
26
|
+
*
|
|
27
|
+
* The host sets `session.actor` to a human actor carrying the session's
|
|
28
|
+
* `userId` as given, in place of any `actor` the resolved session holds.
|
|
29
|
+
* `userId` must be an own data property (not a getter) of the session holding a non-empty
|
|
30
|
+
* string or a finite number; otherwise the call fails with `INTERNAL` and
|
|
31
|
+
* the cause is reported to `onUnexpectedError`. The session handed to
|
|
32
|
+
* `getContext` is a copy that keeps the resolved object's prototype.
|
|
33
|
+
*/
|
|
34
|
+
getSession: (request: Request) => Promise<SessionOf<C> | null | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* The origins a cookie-authenticated request may come from, as absolute
|
|
37
|
+
* URLs (`https://app.example.com`). A request carrying a cookie from any
|
|
38
|
+
* other origin, or from none, is refused.
|
|
39
|
+
*/
|
|
40
|
+
allowedOrigins: readonly string[];
|
|
41
|
+
/** The path the routes are mounted under; each procedure is `POST <basePath>/<name>`. Default `/api/procedures`. */
|
|
42
|
+
basePath?: string;
|
|
43
|
+
/**
|
|
44
|
+
* The largest request body accepted, in bytes. Default 1 MiB. The body is
|
|
45
|
+
* read only once the access rule has admitted the call.
|
|
46
|
+
*/
|
|
47
|
+
maxBodyBytes?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Told of every failure the operator should see, with the procedure's name:
|
|
50
|
+
* every error whose message is withheld from the caller, every database
|
|
51
|
+
* failure other than a unique-constraint violation or a serialization
|
|
52
|
+
* failure (the driver's detail is on `error.cause`), and every engine
|
|
53
|
+
* refusal of a payload the procedure itself wrote. Default `console.error`,
|
|
54
|
+
* which is also the fallback when this function throws or returns a promise
|
|
55
|
+
* that rejects.
|
|
56
|
+
*/
|
|
57
|
+
onUnexpectedError?: (error: unknown, procedureName: string) => void;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A web-standard `Request` → `Response` handler that serves an application's
|
|
61
|
+
* procedures over HTTP: `POST <basePath>/<name>`, JSON in and JSON out. It
|
|
62
|
+
* runs under any framework that speaks the Fetch API.
|
|
63
|
+
*
|
|
64
|
+
* Identity comes from the host alone. A request with no credential is
|
|
65
|
+
* anonymous and the procedure's access rule decides; a request with a cookie
|
|
66
|
+
* must come from an allowed origin and is resolved by `getSession`; a request
|
|
67
|
+
* carrying an `Authorization` header is refused, with or without a cookie.
|
|
68
|
+
* Nothing in the body can supply a session. A resolved session carries a human
|
|
69
|
+
* `actor`, which the host sets itself.
|
|
70
|
+
*
|
|
71
|
+
* A call that reaches the pipeline answers with the result envelope:
|
|
72
|
+
* `{ success: true, data }`, or `{ success: false, error: { code, message,
|
|
73
|
+
* fieldErrors? } }` with `UNAUTHENTICATED` 401, `DENIED` 403,
|
|
74
|
+
* `INVALID_INPUT`/`VALIDATION` 400, `RETRY`/`CONFLICT` 409 and `INTERNAL` 500.
|
|
75
|
+
* A failure the procedure declares is an expected outcome and answers 200
|
|
76
|
+
* with its own code. The host never retries a call: `RETRY` reports that the
|
|
77
|
+
* transaction rolled back and leaves running it again to the caller.
|
|
78
|
+
* An unexpected error's message is passed to `onUnexpectedError` and never to
|
|
79
|
+
* the client. An empty or missing body is `undefined` input, which the input
|
|
80
|
+
* schema accepts or refuses; a body that is not JSON is `INVALID_INPUT`.
|
|
81
|
+
*
|
|
82
|
+
* A transport failure does not use the envelope. It answers
|
|
83
|
+
* `{ error: "<message>" }`, where `error` is a string: 404 for an unknown name
|
|
84
|
+
* or a procedure not exposed to `'web'` (the two are indistinguishable), 405
|
|
85
|
+
* for a method other than `POST`, 415 for a content type other than
|
|
86
|
+
* `application/json`, and 413 for a body over `maxBodyBytes`. A client should
|
|
87
|
+
* branch on the status before reading `success`.
|
|
88
|
+
*
|
|
89
|
+
* The host refuses, when it is created, a registry it cannot serve safely: a
|
|
90
|
+
* schema that cannot be carried on the wire or accepts open-ended values, a
|
|
91
|
+
* name that clashes with an MCP tool, and a procedure declaring a reserved
|
|
92
|
+
* failure code. See {@link assertProcedureRegistry}.
|
|
93
|
+
*
|
|
94
|
+
* @throws {ProcedureHostError} for an invalid option, name, schema or registry entry,
|
|
95
|
+
* or a procedure declaring a reserved failure code.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* // app/api/procedures/[name]/route.ts
|
|
100
|
+
* import { createProcedureHandler } from '@opensaas/stack-core/procedures'
|
|
101
|
+
* import { getContext } from '@/.opensaas/context'
|
|
102
|
+
* import { procedures } from '@/lib/procedures'
|
|
103
|
+
* import { getSession } from '@/lib/auth'
|
|
104
|
+
*
|
|
105
|
+
* export const POST = createProcedureHandler({
|
|
106
|
+
* procedures,
|
|
107
|
+
* getContext,
|
|
108
|
+
* getSession: (request) => getSession(request.headers),
|
|
109
|
+
* allowedOrigins: [process.env.APP_ORIGIN ?? 'http://localhost:3000'],
|
|
110
|
+
* })
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare function createProcedureHandler<C extends ProcedureHostContext>(options: ProcedureHandlerOptions<C>): (request: Request) => Promise<Response>;
|
|
114
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":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K,OAAO,CAAC,QAAQ,CAAC,CAiFzC"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { REFUSAL_STATUS } from './codes.js';
|
|
2
|
+
import { FAILURE_STATUS, failure, isReservedFailureCode } from './result.js';
|
|
3
|
+
import { guardReporter, runProcedure } from './run.js';
|
|
4
|
+
import { assertProcedureRegistry, ProcedureHostError } from './validate.js';
|
|
5
|
+
import { webProcedureOf, webSessionOf } from './web-session.js';
|
|
6
|
+
const DEFAULT_BASE_PATH = '/api/procedures';
|
|
7
|
+
const DEFAULT_MAX_BODY_BYTES = 1024 * 1024;
|
|
8
|
+
const RESPONSE_HEADERS = {
|
|
9
|
+
'content-type': 'application/json; charset=utf-8',
|
|
10
|
+
'cache-control': 'no-store',
|
|
11
|
+
'x-content-type-options': 'nosniff',
|
|
12
|
+
};
|
|
13
|
+
function json(status, body, headers = {}) {
|
|
14
|
+
return new Response(JSON.stringify(body), {
|
|
15
|
+
status,
|
|
16
|
+
headers: { ...RESPONSE_HEADERS, ...headers },
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const notFound = () => json(REFUSAL_STATUS.NOT_FOUND, { error: 'Not found' });
|
|
20
|
+
function statusOf(result) {
|
|
21
|
+
if (result.success)
|
|
22
|
+
return 200;
|
|
23
|
+
const { code } = result.error;
|
|
24
|
+
return isReservedFailureCode(code) ? FAILURE_STATUS[code] : 200;
|
|
25
|
+
}
|
|
26
|
+
function resultResponse(result) {
|
|
27
|
+
return json(statusOf(result), result);
|
|
28
|
+
}
|
|
29
|
+
function defaultUnexpectedError(error, procedureName) {
|
|
30
|
+
console.error(`Procedure "${procedureName}" failed:`, error);
|
|
31
|
+
}
|
|
32
|
+
function normaliseBasePath(basePath) {
|
|
33
|
+
if (!basePath.startsWith('/')) {
|
|
34
|
+
throw new ProcedureHostError(`createProcedureHandler: basePath "${basePath}" must start with "/".`);
|
|
35
|
+
}
|
|
36
|
+
return basePath.replace(/\/+$/, '');
|
|
37
|
+
}
|
|
38
|
+
function normaliseOrigins(origins) {
|
|
39
|
+
const normalised = new Set();
|
|
40
|
+
for (const origin of origins) {
|
|
41
|
+
let parsed;
|
|
42
|
+
try {
|
|
43
|
+
parsed = new URL(origin);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
throw new ProcedureHostError(`createProcedureHandler: allowed origin "${origin}" is not an absolute URL.`);
|
|
47
|
+
}
|
|
48
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
|
|
49
|
+
throw new ProcedureHostError(`createProcedureHandler: allowed origin "${origin}" must be an http(s) origin.`);
|
|
50
|
+
}
|
|
51
|
+
normalised.add(parsed.origin);
|
|
52
|
+
}
|
|
53
|
+
return normalised;
|
|
54
|
+
}
|
|
55
|
+
function isJsonContentType(header) {
|
|
56
|
+
if (header === null)
|
|
57
|
+
return false;
|
|
58
|
+
const mediaType = header.split(';', 1)[0]?.trim().toLowerCase();
|
|
59
|
+
return mediaType === 'application/json';
|
|
60
|
+
}
|
|
61
|
+
async function readBodyWithin(request, limit) {
|
|
62
|
+
if (request.body === null)
|
|
63
|
+
return '';
|
|
64
|
+
const reader = request.body.getReader();
|
|
65
|
+
const chunks = [];
|
|
66
|
+
let received = 0;
|
|
67
|
+
for (;;) {
|
|
68
|
+
const { done, value } = await reader.read();
|
|
69
|
+
if (done)
|
|
70
|
+
break;
|
|
71
|
+
received += value.byteLength;
|
|
72
|
+
if (received > limit) {
|
|
73
|
+
void reader.cancel().catch(() => { });
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
chunks.push(value);
|
|
77
|
+
}
|
|
78
|
+
const bytes = new Uint8Array(received);
|
|
79
|
+
let offset = 0;
|
|
80
|
+
for (const chunk of chunks) {
|
|
81
|
+
bytes.set(chunk, offset);
|
|
82
|
+
offset += chunk.byteLength;
|
|
83
|
+
}
|
|
84
|
+
return new TextDecoder().decode(bytes);
|
|
85
|
+
}
|
|
86
|
+
function parseJson(text) {
|
|
87
|
+
if (text === '')
|
|
88
|
+
return { ok: true, value: undefined };
|
|
89
|
+
try {
|
|
90
|
+
const value = JSON.parse(text);
|
|
91
|
+
return { ok: true, value };
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return { ok: false };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A web-standard `Request` → `Response` handler that serves an application's
|
|
99
|
+
* procedures over HTTP: `POST <basePath>/<name>`, JSON in and JSON out. It
|
|
100
|
+
* runs under any framework that speaks the Fetch API.
|
|
101
|
+
*
|
|
102
|
+
* Identity comes from the host alone. A request with no credential is
|
|
103
|
+
* anonymous and the procedure's access rule decides; a request with a cookie
|
|
104
|
+
* must come from an allowed origin and is resolved by `getSession`; a request
|
|
105
|
+
* carrying an `Authorization` header is refused, with or without a cookie.
|
|
106
|
+
* Nothing in the body can supply a session. A resolved session carries a human
|
|
107
|
+
* `actor`, which the host sets itself.
|
|
108
|
+
*
|
|
109
|
+
* A call that reaches the pipeline answers with the result envelope:
|
|
110
|
+
* `{ success: true, data }`, or `{ success: false, error: { code, message,
|
|
111
|
+
* fieldErrors? } }` with `UNAUTHENTICATED` 401, `DENIED` 403,
|
|
112
|
+
* `INVALID_INPUT`/`VALIDATION` 400, `RETRY`/`CONFLICT` 409 and `INTERNAL` 500.
|
|
113
|
+
* A failure the procedure declares is an expected outcome and answers 200
|
|
114
|
+
* with its own code. The host never retries a call: `RETRY` reports that the
|
|
115
|
+
* transaction rolled back and leaves running it again to the caller.
|
|
116
|
+
* An unexpected error's message is passed to `onUnexpectedError` and never to
|
|
117
|
+
* the client. An empty or missing body is `undefined` input, which the input
|
|
118
|
+
* schema accepts or refuses; a body that is not JSON is `INVALID_INPUT`.
|
|
119
|
+
*
|
|
120
|
+
* A transport failure does not use the envelope. It answers
|
|
121
|
+
* `{ error: "<message>" }`, where `error` is a string: 404 for an unknown name
|
|
122
|
+
* or a procedure not exposed to `'web'` (the two are indistinguishable), 405
|
|
123
|
+
* for a method other than `POST`, 415 for a content type other than
|
|
124
|
+
* `application/json`, and 413 for a body over `maxBodyBytes`. A client should
|
|
125
|
+
* branch on the status before reading `success`.
|
|
126
|
+
*
|
|
127
|
+
* The host refuses, when it is created, a registry it cannot serve safely: a
|
|
128
|
+
* schema that cannot be carried on the wire or accepts open-ended values, a
|
|
129
|
+
* name that clashes with an MCP tool, and a procedure declaring a reserved
|
|
130
|
+
* failure code. See {@link assertProcedureRegistry}.
|
|
131
|
+
*
|
|
132
|
+
* @throws {ProcedureHostError} for an invalid option, name, schema or registry entry,
|
|
133
|
+
* or a procedure declaring a reserved failure code.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* // app/api/procedures/[name]/route.ts
|
|
138
|
+
* import { createProcedureHandler } from '@opensaas/stack-core/procedures'
|
|
139
|
+
* import { getContext } from '@/.opensaas/context'
|
|
140
|
+
* import { procedures } from '@/lib/procedures'
|
|
141
|
+
* import { getSession } from '@/lib/auth'
|
|
142
|
+
*
|
|
143
|
+
* export const POST = createProcedureHandler({
|
|
144
|
+
* procedures,
|
|
145
|
+
* getContext,
|
|
146
|
+
* getSession: (request) => getSession(request.headers),
|
|
147
|
+
* allowedOrigins: [process.env.APP_ORIGIN ?? 'http://localhost:3000'],
|
|
148
|
+
* })
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export function createProcedureHandler(options) {
|
|
152
|
+
const { procedures, getContext, getSession } = options;
|
|
153
|
+
const basePath = normaliseBasePath(options.basePath ?? DEFAULT_BASE_PATH);
|
|
154
|
+
const allowedOrigins = normaliseOrigins(options.allowedOrigins);
|
|
155
|
+
const maxBodyBytes = options.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES;
|
|
156
|
+
const onUnexpectedError = guardReporter(options.onUnexpectedError ?? defaultUnexpectedError);
|
|
157
|
+
if (!Number.isSafeInteger(maxBodyBytes) || maxBodyBytes <= 0) {
|
|
158
|
+
throw new ProcedureHostError('createProcedureHandler: maxBodyBytes must be a positive integer.');
|
|
159
|
+
}
|
|
160
|
+
assertProcedureRegistry(procedures, { config: options.config });
|
|
161
|
+
return async (request) => {
|
|
162
|
+
const prefix = `${basePath}/`;
|
|
163
|
+
const { pathname } = new URL(request.url);
|
|
164
|
+
if (!pathname.startsWith(prefix))
|
|
165
|
+
return notFound();
|
|
166
|
+
const name = pathname.slice(prefix.length, pathname.endsWith('/') ? -1 : undefined);
|
|
167
|
+
const procedure = webProcedureOf(procedures, name);
|
|
168
|
+
if (procedure === undefined)
|
|
169
|
+
return notFound();
|
|
170
|
+
if (request.method !== 'POST')
|
|
171
|
+
return json(REFUSAL_STATUS.METHOD_NOT_ALLOWED, { error: 'Method not allowed' }, { allow: 'POST' });
|
|
172
|
+
if (request.headers.has('authorization'))
|
|
173
|
+
return resultResponse(failure('UNAUTHENTICATED'));
|
|
174
|
+
if (!isJsonContentType(request.headers.get('content-type'))) {
|
|
175
|
+
return json(REFUSAL_STATUS.UNSUPPORTED_MEDIA_TYPE, {
|
|
176
|
+
error: 'Content-Type must be application/json',
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const declaredLength = Number(request.headers.get('content-length') ?? '0');
|
|
180
|
+
if (Number.isFinite(declaredLength) && declaredLength > maxBodyBytes) {
|
|
181
|
+
return json(REFUSAL_STATUS.BODY_TOO_LARGE, { error: 'Request body too large' });
|
|
182
|
+
}
|
|
183
|
+
let session = null;
|
|
184
|
+
if (request.headers.has('cookie')) {
|
|
185
|
+
const origin = request.headers.get('origin');
|
|
186
|
+
if (origin === null || !allowedOrigins.has(origin)) {
|
|
187
|
+
return resultResponse(failure('DENIED'));
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
session = webSessionOf(await getSession(new Request(request.url, { headers: request.headers })));
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
onUnexpectedError(error, name);
|
|
194
|
+
return resultResponse(failure('INTERNAL'));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const transport = {};
|
|
198
|
+
const result = await runProcedure({
|
|
199
|
+
name,
|
|
200
|
+
procedure,
|
|
201
|
+
context: () => (session === null ? getContext() : getContext(session)),
|
|
202
|
+
readInput: async () => {
|
|
203
|
+
const body = await readBodyWithin(request, maxBodyBytes);
|
|
204
|
+
if (body === null) {
|
|
205
|
+
transport.bodyTooLarge = true;
|
|
206
|
+
return { ok: false };
|
|
207
|
+
}
|
|
208
|
+
return parseJson(body);
|
|
209
|
+
},
|
|
210
|
+
onUnexpectedError,
|
|
211
|
+
});
|
|
212
|
+
if (transport.bodyTooLarge === true) {
|
|
213
|
+
return json(REFUSAL_STATUS.BODY_TOO_LARGE, { error: 'Request body too large' });
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
return resultResponse(result);
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
onUnexpectedError(error, name);
|
|
220
|
+
return resultResponse(failure('INTERNAL'));
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/procedures/http.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,qBAAqB,EAAwB,MAAM,aAAa,CAAA;AAClG,OAAO,EAAE,aAAa,EAAE,YAAY,EAAiB,MAAM,UAAU,CAAA;AACrE,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAC3E,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AA4D/D,MAAM,iBAAiB,GAAG,iBAAiB,CAAA;AAC3C,MAAM,sBAAsB,GAAG,IAAI,GAAG,IAAI,CAAA;AAC1C,MAAM,gBAAgB,GAAG;IACvB,cAAc,EAAE,iCAAiC;IACjD,e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der, type ProcedureContext, type ProcedureDefinition, type ProcedureExposure, type ProcedureFailures, type ProcedureHostContext, type ProcedureHostTransactionContext, type ProcedureRegistry, type ProcedureResultOf, type ProcedureRunArgs, type ProcedureSurface, type ProcedureTransactionContext, type TransactionContextOf, } from './procedure.js';
|
|
2
|
+
export { ProcedureFailureError, type ProcedureFail } from './failures.js';
|
|
3
|
+
export { createProcedureHandler, type ProcedureHandlerOptions, type SessionOf } from './http.js';
|
|
4
|
+
export { createServerCaller, type RegistryContextOf, type ServerCaller, type ServerCallerOptions, } from './server.js';
|
|
5
|
+
export { assertProcedureNamesAvailable, assertProcedureRegistry, assertProcedureSchemas, ProcedureHostError, type ProcedureRegistryChecks, type ProcedureSchemaSide, type ProcedureSchemas, } from './validate.js';
|
|
6
|
+
export { RESERVED_FAILURE_CODES, type ProcedureFailure, type ProcedureResult, type ReservedFailureCode, } from './result.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/procedures/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,wBAAwB,EACxB,KAAK,SAAS,EACd,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,+BAA+B,EACpC,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,GAC1B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,qBAAqB,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAA;AACzE,OAAO,EAAE,sBAAsB,EAAE,KAAK,uBAAuB,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAA;AAChG,OAAO,EACL,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,mBAAmB,GACzB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,GACtB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,sBAAsB,EACtB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,mBAAmB,GACzB,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @opensaas/stack-core/procedures
|
|
2
|
+
//
|
|
3
|
+
// Procedures: named, typed actions an application defines once and exposes on
|
|
4
|
+
// the surfaces it names. See ADR-0086.
|
|
5
|
+
export { createProcedureBuilder, isProcedure, ProcedureDefinitionError, } from './procedure.js';
|
|
6
|
+
export { ProcedureFailureError } from './failures.js';
|
|
7
|
+
export { createProcedureHandler } from './http.js';
|
|
8
|
+
export { createServerCaller, } from './server.js';
|
|
9
|
+
export { assertProcedureNamesAvailable, assertProcedureRegistry, assertProcedureSchemas, ProcedureHostError, } from './validate.js';
|
|
10
|
+
export { RESERVED_FAILURE_CODES, } from './result.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/procedures/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,EAAE;AACF,8EAA8E;AAC9E,uCAAuC;AAEvC,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,wBAAwB,GAgBzB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,qBAAqB,EAAsB,MAAM,eAAe,CAAA;AACzE,OAAO,EAAE,sBAAsB,EAAgD,MAAM,WAAW,CAAA;AAChG,OAAO,EACL,kBAAkB,GAInB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,GAInB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,sBAAsB,GAIvB,MAAM,aAAa,CAAA"}
|