@entifix/business 0.10.1 → 0.11.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.
Files changed (57) hide show
  1. package/dist/compose/compose.d.ts +100 -0
  2. package/dist/compose/compose.d.ts.map +1 -0
  3. package/dist/compose/compose.js +143 -0
  4. package/dist/compose/compose.js.map +1 -0
  5. package/dist/compose/index.d.ts +2 -0
  6. package/dist/compose/index.d.ts.map +1 -0
  7. package/dist/compose/index.js +3 -0
  8. package/dist/compose/index.js.map +1 -0
  9. package/dist/flow/catalog.d.ts +51 -0
  10. package/dist/flow/catalog.d.ts.map +1 -0
  11. package/dist/flow/catalog.js +63 -0
  12. package/dist/flow/catalog.js.map +1 -0
  13. package/dist/flow/fragment.d.ts +105 -0
  14. package/dist/flow/fragment.d.ts.map +1 -0
  15. package/dist/flow/fragment.js +77 -0
  16. package/dist/flow/fragment.js.map +1 -0
  17. package/dist/flow/index.d.ts +5 -0
  18. package/dist/flow/index.d.ts.map +1 -0
  19. package/dist/flow/index.js +6 -0
  20. package/dist/flow/index.js.map +1 -0
  21. package/dist/flow/slip.d.ts +126 -0
  22. package/dist/flow/slip.d.ts.map +1 -0
  23. package/dist/flow/slip.js +68 -0
  24. package/dist/flow/slip.js.map +1 -0
  25. package/dist/flow/validate.d.ts +49 -0
  26. package/dist/flow/validate.d.ts.map +1 -0
  27. package/dist/flow/validate.js +126 -0
  28. package/dist/flow/validate.js.map +1 -0
  29. package/dist/idempotency/idempotency-store.d.ts +53 -0
  30. package/dist/idempotency/idempotency-store.d.ts.map +1 -0
  31. package/dist/idempotency/idempotency-store.js +5 -0
  32. package/dist/idempotency/idempotency-store.js.map +1 -0
  33. package/dist/idempotency/index.d.ts +2 -0
  34. package/dist/idempotency/index.d.ts.map +1 -0
  35. package/dist/idempotency/index.js +3 -0
  36. package/dist/idempotency/index.js.map +1 -0
  37. package/dist/index.d.ts +2 -0
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +2 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/resolve/index.d.ts +3 -0
  42. package/dist/resolve/index.d.ts.map +1 -0
  43. package/dist/resolve/index.js +4 -0
  44. package/dist/resolve/index.js.map +1 -0
  45. package/dist/resolve/resolve.d.ts +70 -0
  46. package/dist/resolve/resolve.d.ts.map +1 -0
  47. package/dist/resolve/resolve.js +69 -0
  48. package/dist/resolve/resolve.js.map +1 -0
  49. package/dist/resolve/verified-context.d.ts +45 -0
  50. package/dist/resolve/verified-context.d.ts.map +1 -0
  51. package/dist/resolve/verified-context.js +8 -0
  52. package/dist/resolve/verified-context.js.map +1 -0
  53. package/dist/verified/index.d.ts +10 -0
  54. package/dist/verified/index.d.ts.map +1 -0
  55. package/dist/verified/index.js +10 -0
  56. package/dist/verified/index.js.map +1 -0
  57. package/package.json +17 -2
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './health/health-registry.js';\nexport * from './repository/config.repository.js';\nexport * from './repository/entity.repository.js';\nexport * from './repository/entity-facet-counter.js';\nexport * from './repository/entity-link-resolver.repository.js';\nexport * from './repository/entity-mixins.repository.js';\nexport * from './repository/entity-repository-factory.js';\nexport * from './sessions/one-time-token-store.js';\nexport * from './sessions/session-store.js';\nexport * from './shutdown/shutdown-registry.js';\nexport * from './tenancy/index.js';\nexport * from './tokens/token-failures.js';\nexport * from './tokens/token-service.js';\nexport * from './use-case/delete/index.js';\nexport * from './use-case/facets/index.js';\nexport * from './use-case/get/index.js';\nexport * from './use-case/load/index.js';\nexport * from './use-case/save/index.js';\nexport * from './wiring/wiring-registry.js';\n"],"names":[],"mappings":"AAAA,cAAc,8BAA8B;AAC5C,cAAc,oCAAoC;AAClD,cAAc,oCAAoC;AAClD,cAAc,uCAAuC;AACrD,cAAc,kDAAkD;AAChE,cAAc,2CAA2C;AACzD,cAAc,4CAA4C;AAC1D,cAAc,qCAAqC;AACnD,cAAc,8BAA8B;AAC5C,cAAc,kCAAkC;AAChD,cAAc,qBAAqB;AACnC,cAAc,6BAA6B;AAC3C,cAAc,4BAA4B;AAC1C,cAAc,6BAA6B;AAC3C,cAAc,6BAA6B;AAC3C,cAAc,0BAA0B;AACxC,cAAc,2BAA2B;AACzC,cAAc,2BAA2B;AACzC,cAAc,8BAA8B"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './health/health-registry.js';\nexport * from './idempotency/index.js';\nexport * from './repository/config.repository.js';\nexport * from './repository/entity.repository.js';\nexport * from './repository/entity-facet-counter.js';\nexport * from './repository/entity-link-resolver.repository.js';\nexport * from './repository/entity-mixins.repository.js';\nexport * from './repository/entity-repository-factory.js';\nexport * from './resolve/index.js';\nexport * from './sessions/one-time-token-store.js';\nexport * from './sessions/session-store.js';\nexport * from './shutdown/shutdown-registry.js';\nexport * from './tenancy/index.js';\nexport * from './tokens/token-failures.js';\nexport * from './tokens/token-service.js';\nexport * from './use-case/delete/index.js';\nexport * from './use-case/facets/index.js';\nexport * from './use-case/get/index.js';\nexport * from './use-case/load/index.js';\nexport * from './use-case/save/index.js';\nexport * from './wiring/wiring-registry.js';\n"],"names":[],"mappings":"AAAA,cAAc,8BAA8B;AAC5C,cAAc,yBAAyB;AACvC,cAAc,oCAAoC;AAClD,cAAc,oCAAoC;AAClD,cAAc,uCAAuC;AACrD,cAAc,kDAAkD;AAChE,cAAc,2CAA2C;AACzD,cAAc,4CAA4C;AAC1D,cAAc,qBAAqB;AACnC,cAAc,qCAAqC;AACnD,cAAc,8BAA8B;AAC5C,cAAc,kCAAkC;AAChD,cAAc,qBAAqB;AACnC,cAAc,6BAA6B;AAC3C,cAAc,4BAA4B;AAC1C,cAAc,6BAA6B;AAC3C,cAAc,6BAA6B;AAC3C,cAAc,0BAA0B;AACxC,cAAc,2BAA2B;AACzC,cAAc,2BAA2B;AACzC,cAAc,8BAA8B"}
@@ -0,0 +1,3 @@
1
+ export * from './resolve.js';
2
+ export * from './verified-context.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resolve/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './resolve.js';
2
+ export * from './verified-context.js';
3
+
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/resolve/index.ts"],"sourcesContent":["export * from './resolve.js';\nexport * from './verified-context.js';\n"],"names":[],"mappings":"AAAA,cAAc,eAAe;AAC7B,cAAc,wBAAwB"}
@@ -0,0 +1,70 @@
1
+ import { Context, Effect, Schema } from 'effect';
2
+ import type { FragmentRequirements } from '../flow/fragment.js';
3
+ import { type VerifiedContext, VerifiedContextTag } from './verified-context.js';
4
+ /** One implementation of a use case, and what a caller must hold to be given it. */
5
+ export interface Variant<S> {
6
+ readonly name: string;
7
+ readonly requires?: FragmentRequirements;
8
+ readonly impl: S;
9
+ }
10
+ /** A predicate over the verified context. Never over request input. */
11
+ export type ContextPredicate = (context: VerifiedContext) => boolean;
12
+ /** One ordered rule: when the predicate holds, use the variant. */
13
+ export interface ResolutionRule<S> {
14
+ readonly when: ContextPredicate;
15
+ readonly variant: Variant<S>;
16
+ }
17
+ /** Starts a rule: `When(isVendor).use(counterSale)`. */
18
+ export declare const When: (when: ContextPredicate) => {
19
+ use: <S>(variant: Variant<S>) => ResolutionRule<S>;
20
+ };
21
+ /** The last rule: matches every context that met the variant's requirements. */
22
+ export declare const Otherwise: {
23
+ readonly use: <S>(variant: Variant<S>) => ResolutionRule<S>;
24
+ };
25
+ declare const Unresolvable_base: Schema.Class<Unresolvable, Schema.TaggedStruct<"Unresolvable", {
26
+ readonly useCase: Schema.String;
27
+ }>, import("effect/Cause").YieldableError & import("@entifix/core").FailureFacts<"variantUnavailable", "forbidden">>;
28
+ /**
29
+ * No rule chose an implementation for this caller — forbidden, because the
30
+ * caller is not entitled to any variant of the use case it asked for.
31
+ */
32
+ export declare class Unresolvable extends Unresolvable_base {
33
+ }
34
+ /** Which variant the rules would choose, and by which rule — without running it. */
35
+ export interface DryRun {
36
+ readonly variant: string;
37
+ readonly rule: number;
38
+ }
39
+ /**
40
+ * Walks the rules in order and answers the first whose variant the caller
41
+ * meets the requirements of **and** whose predicate holds. A variant's
42
+ * requirements are checked first: an unentitled variant is skipped, never
43
+ * chosen and then refused.
44
+ */
45
+ export declare const dryRun: <S>(rules: readonly ResolutionRule<S>[], context: VerifiedContext) => DryRun | undefined;
46
+ /**
47
+ * Resolves a use case's variant for a verified context, annotating the current
48
+ * span with `entifix.use_case` and `entifix.variant`.
49
+ */
50
+ export declare const resolve: <S>(useCase: string, rules: readonly ResolutionRule<S>[]) => (context: VerifiedContext) => Effect.Effect<Variant<S>, Unresolvable>;
51
+ /**
52
+ * A use case's variants and the rules that choose between them — a value,
53
+ * not a `Layer`, so the layer graph is built once at boot and the choice is
54
+ * made per request.
55
+ */
56
+ export interface DefinedVariants<I, S> {
57
+ readonly tag: Context.Key<I, S>;
58
+ readonly useCase: string;
59
+ readonly variants: readonly Variant<S>[];
60
+ readonly rules: readonly ResolutionRule<S>[];
61
+ }
62
+ export declare const defineVariants: <I, S>(tag: Context.Key<I, S>, rules: readonly ResolutionRule<S>[], useCase?: string) => DefinedVariants<I, S>;
63
+ /**
64
+ * Provides the variant the current request resolves to, through
65
+ * `Effect.provideService`: two requests with different contexts run different
66
+ * implementations over one layer graph.
67
+ */
68
+ export declare const provideResolved: <I, S>(defined: DefinedVariants<I, S>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E | Unresolvable, Exclude<R, I> | VerifiedContextTag>;
69
+ export {};
70
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/resolve/resolve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MA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+ /** Starts a rule: `When(isVendor).use(counterSale)`. */ export const When = (when)=>({
5
+ use: (variant)=>({
6
+ when,
7
+ variant
8
+ })
9
+ });
10
+ /** The last rule: matches every context that met the variant's requirements. */ export const Otherwise = {
11
+ use: (variant)=>({
12
+ when: ()=>true,
13
+ variant
14
+ })
15
+ };
16
+ /**
17
+ * No rule chose an implementation for this caller — forbidden, because the
18
+ * caller is not entitled to any variant of the use case it asked for.
19
+ */ export class Unresolvable extends Failure.forbidden()('Unresolvable', 'variantUnavailable', {
20
+ useCase: Schema.String
21
+ }, {
22
+ message: ({ useCase })=>`no variant of '${useCase}' is available`
23
+ }) {
24
+ }
25
+ const meets = (requires, context)=>{
26
+ var _ref, _ref1, _context_partyRole, _context_channel;
27
+ return ((_ref = requires == null ? void 0 : requires.entitlements) != null ? _ref : []).every((entitlement)=>context.entitlements.includes(entitlement)) && ((_ref1 = requires == null ? void 0 : requires.roles) != null ? _ref1 : []).every((role)=>context.roles.includes(role)) && ((requires == null ? void 0 : requires.partyRoles) === undefined || requires.partyRoles.includes((_context_partyRole = context.partyRole) != null ? _context_partyRole : '')) && ((requires == null ? void 0 : requires.channels) === undefined || requires.channels.includes((_context_channel = context.channel) != null ? _context_channel : ''));
28
+ };
29
+ /**
30
+ * Walks the rules in order and answers the first whose variant the caller
31
+ * meets the requirements of **and** whose predicate holds. A variant's
32
+ * requirements are checked first: an unentitled variant is skipped, never
33
+ * chosen and then refused.
34
+ */ export const dryRun = (rules, context)=>{
35
+ const index = rules.findIndex((rule)=>meets(rule.variant.requires, context) && rule.when(context));
36
+ const chosen = rules[index];
37
+ return chosen === undefined ? undefined : {
38
+ variant: chosen.variant.name,
39
+ rule: index
40
+ };
41
+ };
42
+ /**
43
+ * Resolves a use case's variant for a verified context, annotating the current
44
+ * span with `entifix.use_case` and `entifix.variant`.
45
+ */ export const resolve = (useCase, rules)=>(context)=>{
46
+ const chosen = dryRun(rules, context);
47
+ const rule = chosen === undefined ? undefined : rules[chosen.rule];
48
+ return rule === undefined ? Effect.fail(new Unresolvable({
49
+ useCase
50
+ })) : Effect.as(Effect.annotateCurrentSpan({
51
+ 'entifix.use_case': useCase,
52
+ 'entifix.variant': rule.variant.name
53
+ }), rule.variant);
54
+ };
55
+ export const defineVariants = (tag, rules, useCase = tag.key)=>({
56
+ tag,
57
+ useCase,
58
+ variants: [
59
+ ...new Set(rules.map((rule)=>rule.variant))
60
+ ],
61
+ rules
62
+ });
63
+ /**
64
+ * Provides the variant the current request resolves to, through
65
+ * `Effect.provideService`: two requests with different contexts run different
66
+ * implementations over one layer graph.
67
+ */ export const provideResolved = (defined)=>(effect)=>Effect.flatMap(VerifiedContextTag, (context)=>Effect.flatMap(resolve(defined.useCase, defined.rules)(context), (variant)=>Effect.provideService(effect, defined.tag, variant.impl)));
68
+
69
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/resolve/resolve.ts"],"sourcesContent":["import { Failure } from '@entifix/core';\nimport { Context, Effect, Schema } from 'effect';\n\nimport type { FragmentRequirements } from '../flow/fragment.js';\nimport {\n type VerifiedContext,\n VerifiedContextTag,\n} from './verified-context.js';\n\n/** One implementation of a use case, and what a caller must hold to be given it. */\nexport interface Variant<S> {\n readonly name: string;\n readonly requires?: FragmentRequirements;\n readonly impl: S;\n}\n\n/** A predicate over the verified context. Never over request input. */\nexport type ContextPredicate = (context: VerifiedContext) => boolean;\n\n/** One ordered rule: when the predicate holds, use the variant. */\nexport interface ResolutionRule<S> {\n readonly when: ContextPredicate;\n readonly variant: Variant<S>;\n}\n\n/** Starts a rule: `When(isVendor).use(counterSale)`. */\nexport const When = (when: ContextPredicate) => ({\n use: <S>(variant: Variant<S>): ResolutionRule<S> => ({ when, variant }),\n});\n\n/** The last rule: matches every context that met the variant's requirements. */\nexport const Otherwise = {\n use: <S>(variant: Variant<S>): ResolutionRule<S> => ({\n when: () => true,\n variant,\n }),\n} as const;\n\n/**\n * No rule chose an implementation for this caller — forbidden, because the\n * caller is not entitled to any variant of the use case it asked for.\n */\nexport class Unresolvable extends Failure.forbidden<Unresolvable>()(\n 'Unresolvable',\n 'variantUnavailable',\n { useCase: Schema.String },\n { message: ({ useCase }) => `no variant of '${useCase}' is available` },\n) {}\n\nconst meets = (\n requires: FragmentRequirements | undefined,\n context: VerifiedContext,\n): boolean =>\n (requires?.entitlements ?? []).every(entitlement =>\n context.entitlements.includes(entitlement),\n ) &&\n (requires?.roles ?? []).every(role => context.roles.includes(role)) &&\n (requires?.partyRoles === undefined ||\n requires.partyRoles.includes(context.partyRole ?? '')) &&\n (requires?.channels === undefined ||\n requires.channels.includes(context.channel ?? ''));\n\n/** Which variant the rules would choose, and by which rule — without running it. */\nexport interface DryRun {\n readonly variant: string;\n readonly rule: number;\n}\n\n/**\n * Walks the rules in order and answers the first whose variant the caller\n * meets the requirements of **and** whose predicate holds. A variant's\n * requirements are checked first: an unentitled variant is skipped, never\n * chosen and then refused.\n */\nexport const dryRun = <S>(\n rules: readonly ResolutionRule<S>[],\n context: VerifiedContext,\n): DryRun | undefined => {\n const index = rules.findIndex(\n rule => meets(rule.variant.requires, context) && rule.when(context),\n );\n const chosen = rules[index];\n return chosen === undefined\n ? undefined\n : { variant: chosen.variant.name, rule: index };\n};\n\n/**\n * Resolves a use case's variant for a verified context, annotating the current\n * span with `entifix.use_case` and `entifix.variant`.\n */\nexport const resolve =\n <S>(useCase: string, rules: readonly ResolutionRule<S>[]) =>\n (context: VerifiedContext): Effect.Effect<Variant<S>, Unresolvable> => {\n const chosen = dryRun(rules, context);\n const rule = chosen === undefined ? undefined : rules[chosen.rule];\n return rule === undefined\n ? Effect.fail(new Unresolvable({ useCase }))\n : Effect.as(\n Effect.annotateCurrentSpan({\n 'entifix.use_case': useCase,\n 'entifix.variant': rule.variant.name,\n }),\n rule.variant,\n );\n };\n\n/**\n * A use case's variants and the rules that choose between them — a value,\n * not a `Layer`, so the layer graph is built once at boot and the choice is\n * made per request.\n */\nexport interface DefinedVariants<I, S> {\n readonly tag: Context.Key<I, S>;\n readonly useCase: string;\n readonly variants: readonly Variant<S>[];\n readonly rules: readonly ResolutionRule<S>[];\n}\n\nexport const defineVariants = <I, S>(\n tag: Context.Key<I, S>,\n rules: readonly ResolutionRule<S>[],\n useCase: string = tag.key,\n): DefinedVariants<I, S> => ({\n tag,\n useCase,\n variants: [...new Set(rules.map(rule => rule.variant))],\n rules,\n});\n\n/**\n * Provides the variant the current request resolves to, through\n * `Effect.provideService`: two requests with different contexts run different\n * implementations over one layer graph.\n */\nexport const provideResolved =\n <I, S>(defined: DefinedVariants<I, S>) =>\n <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n ): Effect.Effect<A, E | Unresolvable, Exclude<R, I> | VerifiedContextTag> =>\n Effect.flatMap(VerifiedContextTag, context =>\n Effect.flatMap(\n resolve(defined.useCase, defined.rules)(context),\n variant => Effect.provideService(effect, defined.tag, variant.impl),\n ),\n );\n"],"names":["Failure","Effect","Schema","VerifiedContextTag","When","when","use","variant","Otherwise","Unresolvable","forbidden","useCase","String","message","meets","requires","context","entitlements","every","entitlement","includes","roles","role","partyRoles","undefined","partyRole","channels","channel","dryRun","rules","index","findIndex","rule","chosen","name","resolve","fail","as","annotateCurrentSpan","defineVariants","tag","key","variants","Set","map","provideResolved","defined","effect","flatMap","provideService","impl"],"mappings":"AAAA,SAASA,OAAO,QAAQ,gBAAgB;AACxC,SAAkBC,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAGjD,SAEEC,kBAAkB,QACb,wBAAwB;AAkB/B,sDAAsD,GACtD,OAAO,MAAMC,OAAO,CAACC,OAA4B,CAAA;QAC/CC,KAAK,CAAIC,UAA4C,CAAA;gBAAEF;gBAAME;YAAQ,CAAA;IACvE,CAAA,EAAG;AAEH,8EAA8E,GAC9E,OAAO,MAAMC,YAAY;IACvBF,KAAK,CAAIC,UAA4C,CAAA;YACnDF,MAAM,IAAM;YACZE;QACF,CAAA;AACF,EAAW;AAEX;;;CAGC,GACD,OAAO,MAAME,qBA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AI,CAAC;QAClE,OAAOA,SAASR,YACZvB,OAAOmC,IAAI,CAAC,IAAI3B,aAAa;YAAEE;QAAQ,MACvCV,OAAOoC,EAAE,CACPpC,OAAOqC,mBAAmB,CAAC;YACzB,oBAAoB3B;YACpB,mBAAmBqB,KAAKzB,OAAO,CAAC2B,IAAI;QACtC,IACAF,KAAKzB,OAAO;IAEpB,EAAE;AAcJ,OAAO,MAAMgC,iBAAiB,CAC5BC,KACAX,OACAlB,UAAkB6B,IAAIC,GAAG,GACE,CAAA;QAC3BD;QACA7B;QACA+B,UAAU;eAAI,IAAIC,IAAId,MAAMe,GAAG,CAACZ,CAAAA,OAAQA,KAAKzB,OAAO;SAAG;QACvDsB;IACF,CAAA,EAAG;AAEH;;;;CAIC,GACD,OAAO,MAAMgB,kBACX,CAAOC,UACP,CACEC,SAEA9C,OAAO+C,OAAO,CAAC7C,oBAAoBa,CAAAA,UACjCf,OAAO+C,OAAO,CACZb,QAAQW,QAAQnC,OAAO,EAAEmC,QAAQjB,KAAK,EAAEb,UACxCT,CAAAA,UAAWN,OAAOgD,cAAc,CAACF,QAAQD,QAAQN,GAAG,EAAEjC,QAAQ2C,IAAI,IAEpE"}
@@ -0,0 +1,45 @@
1
+ import { Context } from 'effect';
2
+ /**
3
+ * The brand that makes a {@link VerifiedContext} impossible to write by hand.
4
+ * Declared and never exported: no module outside this package can name it, so
5
+ * an object literal cannot carry it, and the only way to hold a value of the
6
+ * type is the constructor at `@entifix/business/verified`.
7
+ */
8
+ declare const verified: unique symbol;
9
+ /**
10
+ * What is known about the caller once the shell has verified them — the only
11
+ * input a variant may be chosen from
12
+ * ([ADR 0015](../../../../../docs/adr/0015-composed-flows-and-use-case-resolution.md)).
13
+ *
14
+ * Every member comes from a verified credential or from configuration, never
15
+ * from the request body: a predicate that read request input would let a
16
+ * caller choose its own implementation.
17
+ */
18
+ export interface VerifiedFacts {
19
+ readonly organizationId?: string;
20
+ readonly partyId?: string;
21
+ readonly partyRole?: string;
22
+ readonly entitlements: readonly string[];
23
+ readonly roles: readonly string[];
24
+ /** Where the request came in: `storefront`, `counter`. */
25
+ readonly channel?: string;
26
+ /** Segment tags the caller belongs to. */
27
+ readonly segment?: Readonly<Record<string, string>>;
28
+ /** Feature flags on for this caller. */
29
+ readonly flags: readonly string[];
30
+ /** Configuration dials a predicate may read. */
31
+ readonly config: Readonly<Record<string, unknown>>;
32
+ }
33
+ /** {@link VerifiedFacts}, branded: proof that a shell built it from a verified principal. */
34
+ export type VerifiedContext = VerifiedFacts & {
35
+ readonly [verified]: true;
36
+ };
37
+ declare const VerifiedContextTag_base: Context.ServiceClass<VerifiedContextTag, "@entifix/business/VerifiedContext", VerifiedContext>;
38
+ /**
39
+ * The verified context of the request in progress, provided per request by the
40
+ * service shell and read by `provideResolved`.
41
+ */
42
+ export declare class VerifiedContextTag extends VerifiedContextTag_base {
43
+ }
44
+ export {};
45
+ //# sourceMappingURL=verified-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verified-context.d.ts","sourceRoot":"","sources":["../../src/resolve/verified-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC;;;;;GAKG;AACH,OAAO,CAAC,MAAM,QAAQ,EAAE,OAAO,MAAM,CAAC;AAEtC;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,0DAA0D;IAC1D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,0CAA0C;IAC1C,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,wCAAwC;IACxC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACpD;AAED,6FAA6F;AAC7F,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG;IAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;;AAE5E;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,uBAGA;CAAG"}
@@ -0,0 +1,8 @@
1
+ import { Context } from 'effect';
2
+ /**
3
+ * The verified context of the request in progress, provided per request by the
4
+ * service shell and read by `provideResolved`.
5
+ */ export class VerifiedContextTag extends Context.Service()('@entifix/business/VerifiedContext') {
6
+ }
7
+
8
+ //# sourceMappingURL=verified-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/resolve/verified-context.ts"],"sourcesContent":["import { Context } from 'effect';\n\n/**\n * The brand that makes a {@link VerifiedContext} impossible to write by hand.\n * Declared and never exported: no module outside this package can name it, so\n * an object literal cannot carry it, and the only way to hold a value of the\n * type is the constructor at `@entifix/business/verified`.\n */\ndeclare const verified: unique symbol;\n\n/**\n * What is known about the caller once the shell has verified them — the only\n * input a variant may be chosen from\n * ([ADR 0015](../../../../../docs/adr/0015-composed-flows-and-use-case-resolution.md)).\n *\n * Every member comes from a verified credential or from configuration, never\n * from the request body: a predicate that read request input would let a\n * caller choose its own implementation.\n */\nexport interface VerifiedFacts {\n readonly organizationId?: string;\n readonly partyId?: string;\n readonly partyRole?: string;\n readonly entitlements: readonly string[];\n readonly roles: readonly string[];\n /** Where the request came in: `storefront`, `counter`. */\n readonly channel?: string;\n /** Segment tags the caller belongs to. */\n readonly segment?: Readonly<Record<string, string>>;\n /** Feature flags on for this caller. */\n readonly flags: readonly string[];\n /** Configuration dials a predicate may read. */\n readonly config: Readonly<Record<string, unknown>>;\n}\n\n/** {@link VerifiedFacts}, branded: proof that a shell built it from a verified principal. */\nexport type VerifiedContext = VerifiedFacts & { readonly [verified]: true };\n\n/**\n * The verified context of the request in progress, provided per request by the\n * service shell and read by `provideResolved`.\n */\nexport class VerifiedContextTag extends Context.Service<\n VerifiedContextTag,\n VerifiedContext\n>()('@entifix/business/VerifiedContext') {}\n"],"names":["Context","VerifiedContextTag","Service"],"mappings":"AAAA,SAASA,OAAO,QAAQ,SAAS;AAsCjC;;;CAGC,GACD,OAAO,MAAMC,2BAA2BD,QAAQE,OAAO,GAGnD;AAAsC"}
@@ -0,0 +1,10 @@
1
+ import type { VerifiedContext, VerifiedFacts } from '../resolve/verified-context.js';
2
+ /**
3
+ * Builds a {@link VerifiedContext} from facts a shell has verified.
4
+ *
5
+ * ⚠️ The only constructor, and deliberately on a subpath of its own: a tier-2
6
+ * adapter or a tier-5 double may not import it, so nothing below the shell can
7
+ * mint a context a resolver would trust.
8
+ */
9
+ export declare const verifiedContext: (facts: VerifiedFacts) => VerifiedContext;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/verified/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACd,MAAM,gCAAgC,CAAC;AAExC;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,aAAa,KAAG,eACpB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * Builds a {@link VerifiedContext} from facts a shell has verified.
4
+ *
5
+ * ⚠️ The only constructor, and deliberately on a subpath of its own: a tier-2
6
+ * adapter or a tier-5 double may not import it, so nothing below the shell can
7
+ * mint a context a resolver would trust.
8
+ */ export const verifiedContext = (facts)=>_extends({}, facts);
9
+
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/verified/index.ts"],"sourcesContent":["import type {\n VerifiedContext,\n VerifiedFacts,\n} from '../resolve/verified-context.js';\n\n/**\n * Builds a {@link VerifiedContext} from facts a shell has verified.\n *\n * ⚠️ The only constructor, and deliberately on a subpath of its own: a tier-2\n * adapter or a tier-5 double may not import it, so nothing below the shell can\n * mint a context a resolver would trust.\n */\nexport const verifiedContext = (facts: VerifiedFacts): VerifiedContext =>\n ({ ...facts }) as VerifiedContext;\n"],"names":["verifiedContext","facts"],"mappings":";AAKA;;;;;;CAMC,GACD,OAAO,MAAMA,kBAAkB,CAACC,QAC7B,aAAKA,OAA4B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/business",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "The ports every adapter implements — repository, session, token, health — and the generic get, load, save and delete use-cases.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -21,6 +21,21 @@
21
21
  "types": "./dist/index.d.ts",
22
22
  "import": "./dist/index.js",
23
23
  "default": "./dist/index.js"
24
+ },
25
+ "./flow": {
26
+ "types": "./dist/flow/index.d.ts",
27
+ "import": "./dist/flow/index.js",
28
+ "default": "./dist/flow/index.js"
29
+ },
30
+ "./verified": {
31
+ "types": "./dist/verified/index.d.ts",
32
+ "import": "./dist/verified/index.js",
33
+ "default": "./dist/verified/index.js"
34
+ },
35
+ "./compose": {
36
+ "types": "./dist/compose/index.d.ts",
37
+ "import": "./dist/compose/index.js",
38
+ "default": "./dist/compose/index.js"
24
39
  }
25
40
  },
26
41
  "files": [
@@ -51,7 +66,7 @@
51
66
  },
52
67
  "dependencies": {
53
68
  "@swc/helpers": "0.5.23",
54
- "@entifix/core": "0.10.1"
69
+ "@entifix/core": "0.11.0"
55
70
  },
56
71
  "peerDependencies": {
57
72
  "effect": "^4.0.6"