@ontemper/sdk 0.0.0 → 0.2.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 (98) hide show
  1. package/README.md +221 -2
  2. package/dist/AxiosError.d.ts +46 -0
  3. package/dist/AxiosError.d.ts.map +1 -0
  4. package/dist/AxiosError.js +118 -0
  5. package/dist/AxiosError.js.map +1 -0
  6. package/dist/Contract/Invocation.d.ts +21 -0
  7. package/dist/Contract/Invocation.d.ts.map +1 -0
  8. package/dist/Contract/Invocation.js +2 -0
  9. package/dist/Contract/Invocation.js.map +1 -0
  10. package/dist/Contract/Manifest.d.ts +125 -0
  11. package/dist/Contract/Manifest.d.ts.map +1 -0
  12. package/dist/Contract/Manifest.js +59 -0
  13. package/dist/Contract/Manifest.js.map +1 -0
  14. package/dist/Contract/RuntimeApi.d.ts +143 -0
  15. package/dist/Contract/RuntimeApi.d.ts.map +1 -0
  16. package/dist/Contract/RuntimeApi.js +148 -0
  17. package/dist/Contract/RuntimeApi.js.map +1 -0
  18. package/dist/Contract/index.d.ts +4 -0
  19. package/dist/Contract/index.d.ts.map +1 -0
  20. package/dist/Contract/index.js +3 -0
  21. package/dist/Contract/index.js.map +1 -0
  22. package/dist/Correlation.d.ts +33 -0
  23. package/dist/Correlation.d.ts.map +1 -0
  24. package/dist/Correlation.js +57 -0
  25. package/dist/Correlation.js.map +1 -0
  26. package/dist/HttpApiResource.d.ts +32 -0
  27. package/dist/HttpApiResource.d.ts.map +1 -0
  28. package/dist/HttpApiResource.js +35 -0
  29. package/dist/HttpApiResource.js.map +1 -0
  30. package/dist/HttpClient.d.ts +10 -0
  31. package/dist/HttpClient.d.ts.map +1 -0
  32. package/dist/HttpClient.js +167 -0
  33. package/dist/HttpClient.js.map +1 -0
  34. package/dist/HttpPayload.d.ts +9 -0
  35. package/dist/HttpPayload.d.ts.map +1 -0
  36. package/dist/HttpPayload.js +32 -0
  37. package/dist/HttpPayload.js.map +1 -0
  38. package/dist/Invocation.d.ts +7 -0
  39. package/dist/Invocation.d.ts.map +1 -0
  40. package/dist/Invocation.js +4 -0
  41. package/dist/Invocation.js.map +1 -0
  42. package/dist/LogContext.d.ts +59 -0
  43. package/dist/LogContext.d.ts.map +1 -0
  44. package/dist/LogContext.js +47 -0
  45. package/dist/LogContext.js.map +1 -0
  46. package/dist/Logger.d.ts +5 -0
  47. package/dist/Logger.d.ts.map +1 -0
  48. package/dist/Logger.js +314 -0
  49. package/dist/Logger.js.map +1 -0
  50. package/dist/Manifest.d.ts +8 -0
  51. package/dist/Manifest.d.ts.map +1 -0
  52. package/dist/Manifest.js +101 -0
  53. package/dist/Manifest.js.map +1 -0
  54. package/dist/Middleware.d.ts +13 -0
  55. package/dist/Middleware.d.ts.map +1 -0
  56. package/dist/Middleware.js +287 -0
  57. package/dist/Middleware.js.map +1 -0
  58. package/dist/Redaction.d.ts +27 -0
  59. package/dist/Redaction.d.ts.map +1 -0
  60. package/dist/Redaction.js +149 -0
  61. package/dist/Redaction.js.map +1 -0
  62. package/dist/Resource.d.ts +66 -0
  63. package/dist/Resource.d.ts.map +1 -0
  64. package/dist/Resource.js +57 -0
  65. package/dist/Resource.js.map +1 -0
  66. package/dist/ResourcesErrors.d.ts +36 -0
  67. package/dist/ResourcesErrors.d.ts.map +1 -0
  68. package/dist/ResourcesErrors.js +27 -0
  69. package/dist/ResourcesErrors.js.map +1 -0
  70. package/dist/ResourcesToken.d.ts +10 -0
  71. package/dist/ResourcesToken.d.ts.map +1 -0
  72. package/dist/ResourcesToken.js +63 -0
  73. package/dist/ResourcesToken.js.map +1 -0
  74. package/dist/RuntimeResources.d.ts +26 -0
  75. package/dist/RuntimeResources.d.ts.map +1 -0
  76. package/dist/RuntimeResources.js +115 -0
  77. package/dist/RuntimeResources.js.map +1 -0
  78. package/dist/Trigger.d.ts +17 -0
  79. package/dist/Trigger.d.ts.map +1 -0
  80. package/dist/Trigger.js +4 -0
  81. package/dist/Trigger.js.map +1 -0
  82. package/dist/Workflow.d.ts +36 -0
  83. package/dist/Workflow.d.ts.map +1 -0
  84. package/dist/Workflow.js +80 -0
  85. package/dist/Workflow.js.map +1 -0
  86. package/dist/cli.d.ts +3 -0
  87. package/dist/cli.d.ts.map +1 -0
  88. package/dist/cli.js +447 -0
  89. package/dist/cli.js.map +1 -0
  90. package/dist/index.d.ts +17 -0
  91. package/dist/index.d.ts.map +1 -0
  92. package/dist/index.js +16 -0
  93. package/dist/index.js.map +1 -0
  94. package/dist/testing.d.ts +42 -0
  95. package/dist/testing.d.ts.map +1 -0
  96. package/dist/testing.js +49 -0
  97. package/dist/testing.js.map +1 -0
  98. package/package.json +57 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Resource.js","sourceRoot":"","sources":["../src/Resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAiB,MAAM,EAAE,MAAM,QAAQ,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAyB,MAAM,wBAAwB,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAmC,MAAM,sBAAsB,CAAC;AAC7F,OAAO,EAAkB,gBAAgB,EAAuB,MAAM,uBAAuB,CAAC;AAmD9F,wGAAwG;AACxG,MAAM,QAAQ,GAAG,IAAI,OAAO,EAA8B,CAAC;AAE3D,oEAAoE;AACpE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,UAAwC,EAAkC,EAAE,CACxG,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;AAE9E,qFAAqF;AACrF,MAAM,YAAY,GAAG,CAAC,MAAkB,EAA+B,EAAE;IACvE,MAAM,QAAQ,GAAG,MAAM,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;IACrD,MAAM,IAAI,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I,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,SAAS,EAAE,EAAE,CAChH,MAAM,CAAC,OAAO,CAAC;IACb,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAChB,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAClB,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACtE,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAChG,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IACxB,CAAC,CAAC;CACL,CAAC,CACH,CAAC;AAEN,kHAAkH;AAClH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,UAAwC,EAAE,OAA2B,EAAE,EAAE,CACxG,KAAK,CAAC,MAAM;AACV,sGAAsG;AACtG,UAAU,EACV,MAAM,CAAC,GAAG,CACR,gBAAgB,EAChB,CAAC,SAAS,EAA4D,EAAE,CACtE,CAAC,UAAU,EAAE,EAAE,CACb,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAC9D,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CACvD,CACN,CACF,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { Schema } from 'effect';
2
+ declare const ResourceNotFoundError_base: Schema.Class<ResourceNotFoundError, Schema.TaggedStruct<"ResourceNotFoundError", {
3
+ readonly target: Schema.String;
4
+ readonly message: Schema.String;
5
+ }>, import("effect/Cause").YieldableError>;
6
+ /** Nothing answers to the key or selector. For a selector this is the caller's answer (an unknown tenant), not a fault. */
7
+ export declare class ResourceNotFoundError extends ResourceNotFoundError_base {
8
+ }
9
+ declare const ResourceNotSelectableError_base: Schema.Class<ResourceNotSelectableError, Schema.TaggedStruct<"ResourceNotSelectableError", {
10
+ readonly target: Schema.String;
11
+ readonly message: Schema.String;
12
+ }>, import("effect/Cause").YieldableError>;
13
+ /** The selector was refused: its field is not the type's `x-selectable` one, or the match is empty or names several fields. */
14
+ export declare class ResourceNotSelectableError extends ResourceNotSelectableError_base {
15
+ }
16
+ declare const InvalidResourceError_base: Schema.Class<InvalidResourceError, Schema.TaggedStruct<"InvalidResourceError", {
17
+ readonly target: Schema.String;
18
+ readonly message: Schema.String;
19
+ }>, import("effect/Cause").YieldableError>;
20
+ /** The record exists but cannot serve this read: a reference cycle, several records matching one selector, or a value the caller's schema rejects. */
21
+ export declare class InvalidResourceError extends InvalidResourceError_base {
22
+ }
23
+ declare const ResourcesUnauthorizedError_base: Schema.Class<ResourcesUnauthorizedError, Schema.TaggedStruct<"ResourcesUnauthorizedError", {
24
+ readonly message: Schema.String;
25
+ }>, import("effect/Cause").YieldableError>;
26
+ /** The runtime identity is missing or refused: no API URL or runtime token, a provider that never published a fresh token, or a 401/403. */
27
+ export declare class ResourcesUnauthorizedError extends ResourcesUnauthorizedError_base {
28
+ }
29
+ declare const ResourcesUnavailableError_base: Schema.Class<ResourcesUnavailableError, Schema.TaggedStruct<"ResourcesUnavailableError", {
30
+ readonly message: Schema.String;
31
+ }>, import("effect/Cause").YieldableError>;
32
+ /** The runtime API gave no usable answer: a transport failure, a timeout, a 5xx, or a body the SDK cannot read. */
33
+ export declare class ResourcesUnavailableError extends ResourcesUnavailableError_base {
34
+ }
35
+ export {};
36
+ //# sourceMappingURL=ResourcesErrors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResourcesErrors.d.ts","sourceRoot":"","sources":["../src/ResourcesErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;;AAIhC,2HAA2H;AAC3H,qBAAa,qBAAsB,SAAQ,0BAGzC;CAAG;;;;;AAEL,+HAA+H;AAC/H,qBAAa,0BAA2B,SAAQ,+BAM/C;CAAG;;;;;AAEJ,sJAAsJ;AACtJ,qBAAa,oBAAqB,SAAQ,yBAGxC;CAAG;;;;AAEL,4IAA4I;AAC5I,qBAAa,0BAA2B,SAAQ,+BAG/C;CAAG;;;;AAEJ,mHAAmH;AACnH,qBAAa,yBAA0B,SAAQ,8BAG9C;CAAG"}
@@ -0,0 +1,27 @@
1
+ import { Schema } from 'effect';
2
+ // `target` names what was asked for — `key <key>` or `<type> matching <field>` — never a presented match value.
3
+ /** Nothing answers to the key or selector. For a selector this is the caller's answer (an unknown tenant), not a fault. */
4
+ export class ResourceNotFoundError extends Schema.TaggedError()('ResourceNotFoundError', {
5
+ target: Schema.String,
6
+ message: Schema.String,
7
+ }) {
8
+ }
9
+ /** The selector was refused: its field is not the type's `x-selectable` one, or the match is empty or names several fields. */
10
+ export class ResourceNotSelectableError extends Schema.TaggedError()('ResourceNotSelectableError', {
11
+ target: Schema.String,
12
+ message: Schema.String,
13
+ }) {
14
+ }
15
+ /** The record exists but cannot serve this read: a reference cycle, several records matching one selector, or a value the caller's schema rejects. */
16
+ export class InvalidResourceError extends Schema.TaggedError()('InvalidResourceError', {
17
+ target: Schema.String,
18
+ message: Schema.String,
19
+ }) {
20
+ }
21
+ /** The runtime identity is missing or refused: no API URL or runtime token, a provider that never published a fresh token, or a 401/403. */
22
+ export class ResourcesUnauthorizedError extends Schema.TaggedError()('ResourcesUnauthorizedError', { message: Schema.String }) {
23
+ }
24
+ /** The runtime API gave no usable answer: a transport failure, a timeout, a 5xx, or a body the SDK cannot read. */
25
+ export class ResourcesUnavailableError extends Schema.TaggedError()('ResourcesUnavailableError', { message: Schema.String }) {
26
+ }
27
+ //# sourceMappingURL=ResourcesErrors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResourcesErrors.js","sourceRoot":"","sources":["../src/ResourcesErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,gHAAgH;AAEhH,2HAA2H;AAC3H,MAAM,OAAO,qBAAsB,SAAQ,MAAM,CAAC,WAAW,EAAyB,CAAC,uBAAuB,EAAE;IAC9G,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG;AAEL,+HAA+H;AAC/H,MAAM,OAAO,0BAA2B,SAAQ,MAAM,CAAC,WAAW,EAA8B,CAC9F,4BAA4B,EAC5B;IACE,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CACF;CAAG;AAEJ,sJAAsJ;AACtJ,MAAM,OAAO,oBAAqB,SAAQ,MAAM,CAAC,WAAW,EAAwB,CAAC,sBAAsB,EAAE;IAC3G,MAAM,EAAE,MAAM,CAAC,MAAM;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG;AAEL,4IAA4I;AAC5I,MAAM,OAAO,0BAA2B,SAAQ,MAAM,CAAC,WAAW,EAA8B,CAC9F,4BAA4B,EAC5B,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAC3B;CAAG;AAEJ,mHAAmH;AACnH,MAAM,OAAO,yBAA0B,SAAQ,MAAM,CAAC,WAAW,EAA6B,CAC5F,2BAA2B,EAC3B,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAC3B;CAAG"}
@@ -0,0 +1,10 @@
1
+ import { Effect } from 'effect';
2
+ import { ResourcesUnauthorizedError } from './ResourcesErrors.js';
3
+ export interface RuntimeTokens {
4
+ /** The provider's token when it outlives the refresh window, otherwise the next one it publishes. */
5
+ readonly current: Effect.Effect<string, ResourcesUnauthorizedError>;
6
+ /** The first usable token other than the one the runtime API just refused. */
7
+ readonly replacing: (refused: string) => Effect.Effect<string, ResourcesUnauthorizedError>;
8
+ }
9
+ export declare const makeRuntimeTokens: Effect.Effect<RuntimeTokens>;
10
+ //# sourceMappingURL=ResourcesToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResourcesToken.d.ts","sourceRoot":"","sources":["../src/ResourcesToken.ts"],"names":[],"mappings":"AACA,OAAO,EAAkC,MAAM,EAAsC,MAAM,QAAQ,CAAC;AACpG,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAuElE,MAAM,WAAW,aAAa;IAC5B,qGAAqG;IACrG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;IACpE,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;CAC5F;AAED,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAWzD,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { Cache, Clock, Config, Duration, Effect, Option, Redacted, Schedule, Schema } from 'effect';
3
+ import { ResourcesUnauthorizedError } from './ResourcesErrors.js';
4
+ /** A token this close to `exp` could lapse mid-request, so it counts as spent. */
5
+ const REFRESH_WINDOW_MS = 30_000;
6
+ /** Providers republish well inside this: the k8s refresher every 30 s, the Firecracker host on every renewal. */
7
+ const PUBLISH_TIMEOUT = Duration.seconds(35);
8
+ const POLL_INTERVAL = Duration.millis(100);
9
+ const TokenExpiry = Schema.StringFromBase64Url.pipe(Schema.decodeTo(Schema.fromJsonString(Schema.Struct({ exp: Schema.Number }))));
10
+ const decodeTokenExpiry = Schema.decodeUnknownOption(TokenExpiry);
11
+ /** Only a JWT that outlives the refresh window is sent; one without `exp` never is, as in `@ontemper/resources`. */
12
+ const outlivesRefreshWindow = (token, now) => Option.match(decodeTokenExpiry(token.split('.')[1]), {
13
+ onNone: () => false,
14
+ onSome: ({ exp }) => exp * 1000 - now > REFRESH_WINDOW_MS,
15
+ });
16
+ const TokenSources = Config.all({
17
+ file: Config.option(Config.String('UNNBOUND_RUNTIME_TOKEN_FILE')),
18
+ token: Config.option(Config.Redacted('UNNBOUND_RUNTIME_TOKEN')),
19
+ }).pipe(Effect.mapError((error) => new ResourcesUnauthorizedError({ message: `Runtime token settings are unreadable: ${error.message}` })));
20
+ /**
21
+ * The provider's file wins over the env token and both are re-read on every call, so a rotation is seen at once.
22
+ * An unreadable or empty file falls back to the env token; with neither configured nothing can ever authenticate.
23
+ */
24
+ const readToken = Effect.gen(function* () {
25
+ const sources = yield* TokenSources;
26
+ const file = Option.filter(sources.file, (path) => path.length > 0);
27
+ const token = Option.filter(Option.map(sources.token, Redacted.value), (value) => value.length > 0);
28
+ if (Option.isNone(file) && Option.isNone(token)) {
29
+ return yield* new ResourcesUnauthorizedError({
30
+ message: 'No runtime token is configured: set UNNBOUND_RUNTIME_TOKEN_FILE or UNNBOUND_RUNTIME_TOKEN.',
31
+ });
32
+ }
33
+ if (Option.isSome(file)) {
34
+ const contents = yield* Effect.option(Effect.tryPromise(() => readFile(file.value, 'utf8')));
35
+ const published = Option.filter(Option.map(contents, (text) => text.trim()), (text) => text.length > 0);
36
+ if (Option.isSome(published))
37
+ return published;
38
+ }
39
+ return token;
40
+ });
41
+ /** Polls the provider until it publishes a usable token other than `refused`. */
42
+ const awaitPublished = (refused) => Effect.gen(function* () {
43
+ const token = yield* readToken;
44
+ const now = yield* Clock.currentTimeMillis;
45
+ return Option.filter(token, (candidate) => candidate !== refused && outlivesRefreshWindow(candidate, now));
46
+ }).pipe(Effect.repeat({ schedule: Schedule.spaced(POLL_INTERVAL), until: Option.isSome }), Effect.map((published) => published.value), Effect.timeoutOrElse({
47
+ duration: PUBLISH_TIMEOUT,
48
+ orElse: () => Effect.fail(new ResourcesUnauthorizedError({ message: 'Runtime resolver token provider did not publish a fresh token.' })),
49
+ }));
50
+ export const makeRuntimeTokens = Effect.gen(function* () {
51
+ // Waiters on one refused token share a single poll; a refusal of a newer token starts its own.
52
+ const published = yield* Cache.makeWith(awaitPublished, { capacity: 8, timeToLive: () => Duration.zero });
53
+ const replacing = (refused) => Cache.get(published, refused);
54
+ const current = Effect.gen(function* () {
55
+ const token = yield* readToken;
56
+ const now = yield* Clock.currentTimeMillis;
57
+ if (Option.isSome(token) && outlivesRefreshWindow(token.value, now))
58
+ return token.value;
59
+ return yield* replacing(Option.getOrElse(token, () => ''));
60
+ });
61
+ return { current, replacing };
62
+ });
63
+ //# sourceMappingURL=ResourcesToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResourcesToken.js","sourceRoot":"","sources":["../src/ResourcesToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACpG,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAElE,kFAAkF;AAClF,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACjC,iHAAiH;AACjH,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAC7C,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAE3C,MAAM,WAAW,GAAG,MAAM,CAAC,mBAAmB,CAAC,IAAI,CACjD,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAA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AAO,KAAK,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAChC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { Context, Effect, Layer, Redacted, Schema } from 'effect';
2
+ import { HttpClient } from 'effect/unstable/http';
3
+ import { type SelectResourceRuntimeInputSchema } from './Contract/RuntimeApi.js';
4
+ import { InvalidResourceError, ResourceNotFoundError, ResourceNotSelectableError, ResourcesUnauthorizedError, ResourcesUnavailableError } from './ResourcesErrors.js';
5
+ /** Finds the one record of a type whose `x-selectable` field equals the value a tenant presented. */
6
+ export type ResourceSelector = typeof SelectResourceRuntimeInputSchema.Type;
7
+ export type ReadError = ResourceNotFoundError | ResourcesUnauthorizedError | ResourcesUnavailableError;
8
+ /** What declared resources read through: the Temper runtime API in production, fixed values in tests. */
9
+ export interface ResourceReader {
10
+ /** A Variable's live value; `Redacted` because the platform, not the caller, decides what is secret. */
11
+ readonly variable: (key: string) => Effect.Effect<Redacted.Redacted<string>, ReadError>;
12
+ /** The record's value with every secret filled in, still undecoded. */
13
+ readonly resolve: (key: string) => Effect.Effect<Schema.Json, ReadError | InvalidResourceError>;
14
+ /** The key of the one record whose `x-selectable` field matches. */
15
+ readonly select: (selector: ResourceSelector) => Effect.Effect<string, ReadError | ResourceNotSelectableError | InvalidResourceError>;
16
+ }
17
+ declare const RuntimeResources_base: Context.ServiceClass<RuntimeResources, "@temper/workflow/RuntimeResources", ResourceReader>;
18
+ /**
19
+ * Variables and resources read live from the Temper runtime API with the workflow's runtime identity
20
+ * (`UNNBOUND_API_URL` plus `UNNBOUND_RUNTIME_TOKEN_FILE` or `UNNBOUND_RUNTIME_TOKEN`), cached for 30 s.
21
+ */
22
+ export declare class RuntimeResources extends RuntimeResources_base {
23
+ static readonly layer: Layer.Layer<RuntimeResources, never, HttpClient.HttpClient>;
24
+ }
25
+ export {};
26
+ //# sourceMappingURL=RuntimeResources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RuntimeResources.d.ts","sourceRoot":"","sources":["../src/RuntimeResources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,OAAO,EAAY,MAAM,EAAQ,KAAK,EAAU,QAAQ,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;AAErH,OAAO,EAAE,UAAU,EAA2C,MAAM,sBAAsB,CAAC;AAE3F,OAAO,EAQL,KAAK,gCAAgC,EACtC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EAC1B,MAAM,sBAAsB,CAAC;AAY9B,qGAAqG;AACrG,MAAM,MAAM,gBAAgB,GAAG,OAAO,gCAAgC,CAAC,IAAI,CAAC;AAE5E,MAAM,MAAM,SAAS,GAAG,qBAAqB,GAAG,0BAA0B,GAAG,yBAAyB,CAAC;AA2KvG,yGAAyG;AACzG,MAAM,WAAW,cAAc;IAC7B,wGAAwG;IACxG,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;IACxF,uEAAuE;IACvE,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,oBAAoB,CAAC,CAAC;IAChG,oEAAoE;IACpE,QAAQ,CAAC,MAAM,EAAE,CACf,QAAQ,EAAE,gBAAgB,KACvB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,0BAA0B,GAAG,oBAAoB,CAAC,CAAC;CAC3F;;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,qBAErC;IAEC,MAAM,CAAC,QAAQ,CAAC,KAAK,8DAAiD;CACvE"}
@@ -0,0 +1,115 @@
1
+ import { Cache, Config, Context, Duration, Effect, Exit, Layer, Option, Redacted, Schema } from 'effect';
2
+ import { constTrue } from 'effect/Function';
3
+ import { HttpClient, HttpClientRequest } from 'effect/unstable/http';
4
+ import { HttpApiClient } from 'effect/unstable/httpapi';
5
+ import { ResourcesRuntimeApi, } from './Contract/RuntimeApi.js';
6
+ import { registerSecrets } from './Redaction.js';
7
+ import { InvalidResourceError, ResourceNotFoundError, ResourceNotSelectableError, ResourcesUnauthorizedError, ResourcesUnavailableError, } from './ResourcesErrors.js';
8
+ import { makeRuntimeTokens } from './ResourcesToken.js';
9
+ // Resolved values are live configuration: an edit, or a revoked secret, reaches a warm process within this window.
10
+ const CACHE_TTL = Duration.seconds(30);
11
+ // Bounds memory for a workflow that selects across many tenants; the least recently read entry goes first.
12
+ const CACHE_CAPACITY = 1_024;
13
+ const REQUEST_TIMEOUT = Duration.seconds(5);
14
+ const Endpoints = ResourcesRuntimeApi.groups.resourcesRuntime.endpoints;
15
+ // A 401 on the first attempt ends it before its body is read, so the retry never waits on a refused answer.
16
+ class TokenRefused extends Schema.TaggedError()('TokenRefused', {}) {
17
+ }
18
+ class ApiUrlMissing extends Schema.TaggedError()('ApiUrlMissing', {}) {
19
+ }
20
+ // The status each declared runtime error answers with (see `Contract/RuntimeApi.ts`).
21
+ const statusOfRuntimeError = {
22
+ RuntimeResourcesBadRequestError: 400,
23
+ RuntimeResourcesUnauthorizedError: 401,
24
+ RuntimeResourcesForbiddenError: 403,
25
+ RuntimeResourcesNotFoundError: 404,
26
+ RuntimeResourcesConflictError: 409,
27
+ RuntimeResourcesUnavailableError: 503,
28
+ };
29
+ const ResourcesMake = Effect.gen(function* () {
30
+ const tokens = yield* makeRuntimeTokens;
31
+ // Each attempt's scope owns its request: leaving the scope aborts it, so no response outlives its attempt.
32
+ const platform = HttpClient.withScope(yield* HttpClient.HttpClient).pipe(HttpClient.mapRequestEffect((request) => Config.NonEmptyString('UNNBOUND_API_URL').pipe(Effect.map((apiUrl) => HttpClientRequest.prependUrl(request, apiUrl)), Effect.mapError(() => new ApiUrlMissing()))));
33
+ // A 401's body is the fixed `Unauthorized`; failing before it is read lets a refused attempt end at once.
34
+ const client = yield* HttpApiClient.makeWith(ResourcesRuntimeApi, {
35
+ httpClient: platform.pipe(HttpClient.filterOrFail((response) => response.status !== 401, () => new TokenRefused())),
36
+ });
37
+ // One call to the runtime API; a 401 swaps in the provider's next token and tries once more.
38
+ const call = (operation, target, send, refuse = () => undefined) => {
39
+ const failed = (detail) => `Runtime resolver ${Endpoints[operation].path} failed for ${target}: ${detail}`;
40
+ // A status the contract does not declare, or a body the SDK cannot read, leaves the resolver unavailable.
41
+ const toReadError = (error) => {
42
+ switch (error._tag) {
43
+ case 'ApiUrlMissing':
44
+ return new ResourcesUnauthorizedError({ message: failed('UNNBOUND_API_URL is not set') });
45
+ case 'TokenRefused':
46
+ return new ResourcesUnauthorizedError({ message: failed('401 Unauthorized') });
47
+ case 'HttpClientError':
48
+ return new ResourcesUnavailableError({
49
+ message: failed(error.response === undefined ? error.message : `${error.response.status}`),
50
+ });
51
+ case 'SchemaError':
52
+ return new ResourcesUnavailableError({ message: failed('unreadable answer') });
53
+ default: {
54
+ const status = statusOfRuntimeError[error._tag];
55
+ const message = failed(`${status} ${error.error}`);
56
+ if (status === 401 || status === 403)
57
+ return new ResourcesUnauthorizedError({ message });
58
+ if (status === 404)
59
+ return new ResourceNotFoundError({ target, message });
60
+ return refuse(status, message) ?? new ResourcesUnavailableError({ message });
61
+ }
62
+ }
63
+ };
64
+ // One request under one deadline that also covers reading its body; the attempt aborts the request as it ends.
65
+ const attempt = (attemptClient, token) => send(attemptClient, `Bearer ${token}`).pipe(Effect.scoped, Effect.timeoutOrElse({
66
+ duration: REQUEST_TIMEOUT,
67
+ orElse: () => Effect.fail(new ResourcesUnavailableError({
68
+ message: failed(`no answer within ${Duration.toMillis(REQUEST_TIMEOUT)} ms`),
69
+ })),
70
+ }),
71
+ // Resolver traffic is Temper's own transport, not the customer's work: no protocol lines, no span (T-3831).
72
+ Effect.provideService(HttpClient.TracerDisabledWhen, constTrue));
73
+ return Effect.gen(function* () {
74
+ const token = yield* tokens.current;
75
+ const first = yield* attempt(client.resourcesRuntime, token).pipe(Effect.map(Option.some), Effect.catchTag('TokenRefused', () => Effect.succeedNone));
76
+ if (Option.isSome(first))
77
+ return first.value;
78
+ return yield* attempt(client.resourcesRuntime, yield* tokens.replacing(token));
79
+ }).pipe(Effect.catchIf((error) => error._tag !== 'ResourcesUnauthorizedError' && error._tag !== 'ResourcesUnavailableError', (error) => Effect.fail(toReadError(error))));
80
+ };
81
+ const cache = (lookup) => Cache.makeWith(lookup, {
82
+ capacity: CACHE_CAPACITY,
83
+ // A failure is not kept: the next read asks the resolver again.
84
+ timeToLive: (exit) => (Exit.isSuccess(exit) ? CACHE_TTL : Duration.zero),
85
+ });
86
+ const variables = yield* cache((key) => call('resolveVariable', `key ${key}`, (api, authorization) => api.resolveVariable({ headers: { authorization }, payload: { key } })));
87
+ const values = yield* cache((key) => call('resolveResource', `key ${key}`, (api, authorization) => api.resolveResource({ headers: { authorization }, payload: { key } }), (status, message) => (status === 409 ? new InvalidResourceError({ target: `key ${key}`, message }) : undefined)));
88
+ // Keyed by value: `{a,b}` and `{b,a}` share one entry, and each tenant's presented value gets its own.
89
+ const selections = yield* cache((selector) => {
90
+ const target = `${selector.resourceTypeKey} matching ${Object.keys(selector.match).join(', ')}`;
91
+ return call('selectResource', target, (api, authorization) => api.selectResource({ headers: { authorization }, payload: selector }), (status, message) => status === 400
92
+ ? new ResourceNotSelectableError({ target, message })
93
+ : status === 409
94
+ ? new InvalidResourceError({ target, message })
95
+ : undefined);
96
+ });
97
+ // Registers the answer's secrets in the caller's context, so a cached read masks them like a fresh one.
98
+ const unwrap = (read) => read.pipe(Effect.tap(({ redactionMasks }) => registerSecrets(redactionMasks ?? [])), Effect.map(({ value }) => value));
99
+ return RuntimeResources.of({
100
+ variable: (key) => Effect.map(unwrap(Cache.get(variables, key)), Redacted.make),
101
+ // Each caller gets its own copy: the cached value is shared across requests for 30 s.
102
+ resolve: (key) => Effect.map(unwrap(Cache.get(values, key)), (value) => structuredClone(value)),
103
+ // A fresh key: Effect caches an object's hash by reference, so a reused, mutated selector could hit another tenant's entry.
104
+ select: (selector) => Effect.map(unwrap(Cache.get(selections, { resourceTypeKey: selector.resourceTypeKey, match: { ...selector.match } })), (selected) => selected.key),
105
+ });
106
+ });
107
+ /**
108
+ * Variables and resources read live from the Temper runtime API with the workflow's runtime identity
109
+ * (`UNNBOUND_API_URL` plus `UNNBOUND_RUNTIME_TOKEN_FILE` or `UNNBOUND_RUNTIME_TOKEN`), cached for 30 s.
110
+ */
111
+ export class RuntimeResources extends Context.Service()('@temper/workflow/RuntimeResources') {
112
+ // Needs `HttpClient`, which `workflow()` provides.
113
+ static layer = Layer.effect(RuntimeResources, ResourcesMake);
114
+ }
115
+ //# sourceMappingURL=RuntimeResources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RuntimeResources.js","sourceRoot":"","sources":["../src/RuntimeResources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;AACrH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAwB,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC3F,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EACL,mBAAmB,GAQpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EACL,oBAAoB,EACpB,qBAAq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CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAC1G,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAC3B;KACJ,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAcH;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,OAAO,CAAC,OAAO,EAAoC,CACvF,mCAAmC,CACpC;IACC,mDAAmD;IACnD,MAAM,CAAU,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC;CACvE"}
@@ -0,0 +1,17 @@
1
+ import { Context } from 'effect';
2
+ declare const Trigger_base: Context.ServiceClass<Trigger, "@temper/workflow/Trigger", {
3
+ readonly kind: "http";
4
+ readonly response?: "ack" | "wait" | undefined;
5
+ } | {
6
+ readonly kind: "schedule";
7
+ readonly cron?: string | undefined;
8
+ readonly timezone?: string | undefined;
9
+ } | {
10
+ readonly kind: "manual";
11
+ } | {
12
+ readonly kind: "internal";
13
+ }>;
14
+ export declare class Trigger extends Trigger_base {
15
+ }
16
+ export {};
17
+ //# sourceMappingURL=Trigger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Trigger.d.ts","sourceRoot":"","sources":["../src/Trigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;;;;;;;;;;;;;AAGjC,qBAAa,OAAQ,SAAQ,YAAuE;CAAG"}
@@ -0,0 +1,4 @@
1
+ import { Context } from 'effect';
2
+ export class Trigger extends Context.Service()('@temper/workflow/Trigger') {
3
+ }
4
+ //# sourceMappingURL=Trigger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Trigger.js","sourceRoot":"","sources":["../src/Trigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGjC,MAAM,OAAO,OAAQ,SAAQ,OAAO,CAAC,OAAO,EAA4B,CAAC,0BAA0B,CAAC;CAAG"}
@@ -0,0 +1,36 @@
1
+ import { Clock, ConfigProvider, Layer } from 'effect';
2
+ import { type HttpClient, HttpRouter } from 'effect/unstable/http';
3
+ import { HttpApi, type HttpApiGroup } from 'effect/unstable/httpapi';
4
+ import type { InvocationContext } from './Contract/Invocation.js';
5
+ import type { WorkflowManifest } from './Contract/Manifest.js';
6
+ import { type OutboundFetch } from './HttpClient.js';
7
+ import { Invocation } from './Invocation.js';
8
+ import { type AnyDeclaration } from './Resource.js';
9
+ import { type ResourceReader } from './RuntimeResources.js';
10
+ /** Platform services a test or local tool may replace; production uses every default. */
11
+ export interface WorkflowPlatform {
12
+ /** Receives one JSON line per log. Defaults to stdout, which the platform reads. */
13
+ readonly writeLog?: ((line: string) => void) | undefined;
14
+ /** Answers `Config` reads. Defaults to the live process environment. */
15
+ readonly configProvider?: ConfigProvider.ConfigProvider | undefined;
16
+ /** Sends the requests of the workflow's `HttpClient`. Defaults to the global `fetch`. */
17
+ readonly outboundFetch?: OutboundFetch | undefined;
18
+ /** Times the invocation deadline and log spans. Defaults to the system clock. */
19
+ readonly clock?: Clock.Clock | undefined;
20
+ /** Answers declared resources and variables. Defaults to the Temper runtime API. */
21
+ readonly resources?: ResourceReader | undefined;
22
+ }
23
+ export interface WorkflowModule<Api extends HttpApi.Constraint = HttpApi.Constraint> {
24
+ readonly api: Api;
25
+ readonly manifest: WorkflowManifest;
26
+ readonly fetch: (request: Request, context: InvocationContext) => Promise<Response>;
27
+ readonly dispose: () => Promise<void>;
28
+ /** The same workflow over replaced platform services; the caller disposes it. */
29
+ readonly withPlatform: (platform: WorkflowPlatform) => WorkflowModule<Api>;
30
+ }
31
+ export interface WorkflowOptions<Id extends string, Groups extends HttpApiGroup.Constraint> extends WorkflowPlatform {
32
+ readonly api: HttpApi.HttpApi<Id, Groups>;
33
+ readonly handlers: Layer.Layer<HttpApiGroup.ToService<Id, Groups>, never, HttpRouter.Request.From<'Requires', Invocation> | HttpClient.HttpClient | AnyDeclaration>;
34
+ }
35
+ export declare const workflow: <Id extends string, Groups extends HttpApiGroup.Constraint>(options: WorkflowOptions<Id, Groups>) => WorkflowModule<HttpApi.HttpApi<Id, Groups>>;
36
+ //# sourceMappingURL=Workflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Workflow.d.ts","sourceRoot":"","sources":["../src/Workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,cAAc,EAAuB,KAAK,EAAQ,MAAM,QAAQ,CAAC;AACjF,OAAO,EAAQ,KAAK,UAAU,EAAgB,UAAU,EAAkC,MAAM,sBAAsB,CAAC;AACvH,OAAO,EAAE,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACrF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAK7C,OAAO,EAAE,KAAK,cAAc,EAAmC,MAAM,eAAe,CAAC;AACrF,OAAO,EAAoB,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAkB9E,yFAAyF;AACzF,MAAM,WAAW,gBAAgB;IAC/B,oFAAoF;IACpF,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACzD,wEAAwE;IACxE,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC,cAAc,GAAG,SAAS,CAAC;IACpE,yFAAyF;IACzF,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACnD,iFAAiF;IACjF,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;IACzC,oFAAoF;IACpF,QAAQ,CAAC,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2
+ import { Etag, HttpPlatform, HttpRouter, HttpServer, HttpServerResponse } from 'effect/unstable/http';
3
+ import { HttpApi, HttpApiBuilder } from 'effect/unstable/httpapi';
4
+ import { httpClientLayer } from './HttpClient.js';
5
+ import { Invocation } from './Invocation.js';
6
+ import { loggerLayer, writeStdoutLine } from './Logger.js';
7
+ import { HEALTHCHECK_PATH, makeManifest } from './Manifest.js';
8
+ import { EventRequestMiddleware, UnmatchedRequestMiddleware } from './Middleware.js';
9
+ import { makeSecretMasks, SecretMasks } from './Redaction.js';
10
+ import { declarationLayer, declarationOf } from './Resource.js';
11
+ import { RuntimeResources } from './RuntimeResources.js';
12
+ /**
13
+ * Kubernetes probes every workflow pod on `GET /healthcheck` (startup, liveness, readiness). The
14
+ * runtime owns that route so a migrated workflow cannot crash-loop by omitting it. It is composed
15
+ * onto the router ahead of the user API, so it is served regardless of the user's `Api` and never
16
+ * appears in the manifest, which rejects an API declaring it. Like legacy, it runs outside any
17
+ * request trace and logs nothing.
18
+ */
19
+ const PlatformRoutes = HttpRouter.add('GET', HEALTHCHECK_PATH, HttpServerResponse.jsonUnsafe({ status: 'ok' }));
20
+ const InMemoryHttpPlatform = Layer.mergeAll(HttpPlatform.layer.pipe(Layer.provide(FileSystem.layerNoop({}))), FileSystem.layerNoop({}), Path.layer, Etag.layerWeak);
21
+ /**
22
+ * Standard Effect services the workflow depends on: `Effect.log*` as legacy JSON lines, `Config`
23
+ * over the environment, and the platform `HttpClient`. One secret registry lives per module.
24
+ */
25
+ const platformLayer = (platform) => Layer.mergeAll(loggerLayer(platform.writeLog ?? writeStdoutLine), httpClientLayer(platform.outboundFetch ?? ((url, init) => globalThis.fetch(url, init)))).pipe(Layer.provideMerge(Layer.mergeAll(
26
+ // Legacy `process.env.X ?? fallback` treated an empty variable as set.
27
+ ConfigProvider.layer(platform.configProvider ?? ConfigProvider.fromEnvRecord(process.env, { preserveEmptyStrings: true })), Layer.succeed(SecretMasks, makeSecretMasks()), platform.clock === undefined ? Layer.empty : Layer.succeed(Clock.Clock, platform.clock))));
28
+ /** Platform run metadata travels in `context`; the header copies are removed so handlers cannot drift onto them. */
29
+ const stripPlatformHeaders = (request) => {
30
+ const names = [];
31
+ request.headers.forEach((_value, name) => {
32
+ if (name.startsWith('x-temper-'))
33
+ names.push(name);
34
+ });
35
+ for (const name of names)
36
+ request.headers.delete(name);
37
+ };
38
+ /** One middleware layer per resource, variable, and resource type the API's endpoints declare. */
39
+ const declarationsOf = (api, platform) => {
40
+ const layers = new Map();
41
+ HttpApi.reflect(api, {
42
+ onGroup() { },
43
+ onEndpoint({ middleware }) {
44
+ for (const key of middleware) {
45
+ const runtime = declarationOf(key);
46
+ if (runtime !== undefined && !layers.has(key.key))
47
+ layers.set(key.key, declarationLayer(key, runtime));
48
+ }
49
+ },
50
+ });
51
+ return Layer.mergeAll(Layer.empty, ...layers.values()).pipe(Layer.provide(platform.resources === undefined ? RuntimeResources.layer : Layer.succeed(RuntimeResources, platform.resources)));
52
+ };
53
+ export const workflow = (options) => {
54
+ const manifest = makeManifest(options.api);
55
+ const handlers = options.handlers.pipe(Layer.provide(declarationsOf(options.api, options)));
56
+ const appLayer = Layer.mergeAll(PlatformRoutes, HttpApiBuilder.layer(options.api).pipe(Layer.provide(handlers), Layer.provide(EventRequestMiddleware)), UnmatchedRequestMiddleware).pipe(Layer.provide(HttpServer.layerServices), Layer.provide(InMemoryHttpPlatform), Layer.provideMerge(platformLayer(options)));
57
+ // Legacy Hono routing: exact case, no trailing- or duplicate-slash folding, unbounded parameters.
58
+ const web = HttpRouter.toWebHandler(appLayer, {
59
+ disableLogger: true,
60
+ routerConfig: {
61
+ caseSensitive: true,
62
+ ignoreTrailingSlash: false,
63
+ ignoreDuplicateSlashes: false,
64
+ maxParamLength: Number.POSITIVE_INFINITY,
65
+ },
66
+ });
67
+ // SAFETY: WorkflowOptions accepts a complete handler layer whose only request service is Invocation.
68
+ const handler = web.handler;
69
+ return Object.freeze({
70
+ api: options.api,
71
+ manifest,
72
+ fetch: (request, invocation) => {
73
+ stripPlatformHeaders(request);
74
+ return handler(request, Context.make(Invocation, invocation));
75
+ },
76
+ dispose: web.dispose,
77
+ withPlatform: (platform) => workflow({ ...options, ...platform }),
78
+ });
79
+ };
80
+ //# sourceMappingURL=Workflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Workflow.js","sourceRoot":"","sources":["../src/Workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACjF,OAAO,EAAE,IAAI,EAAmB,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACvH,OAAO,EAAE,OAAO,EAAE,cAAc,EAAqB,MAAM,yBAAyB,CAAC;AAGrF,OAAO,EAAE,eAAe,EAAsB,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAuB,gBAAgB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAAuB,MAAM,uBAAuB,CAAC;AAE9E;;;;;;GAMG;AACH,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAEhH,MAAM,oBAAoB,GAAG,KAAK,CAAC,QAAQ,CAC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AC,QAAQ,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,QAAQ,EAAE,CAAC;KACpF,CAAC,CAAC;AACL,CAAC,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bun
2
+ export declare const runCli: (arguments_: ReadonlyArray<string>) => Promise<void>;
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAgeA,eAAO,MAAM,MAAM,eAAsB,aAAa,CAAC,MAAM,CAAC,KAAG,OAAO,CAAC,IAAI,CAK5E,CAAC"}