@webiny/api-core 6.6.0-alpha.3 → 6.6.0-alpha.4

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.
@@ -22,13 +22,14 @@ export interface ITaskOutput {
22
22
  * wraps every task; without this it has nothing to branch on but a hardcoded list of ids, which
23
23
  * means editing the decorator every time a task is added.
24
24
  *
25
- * This is {@link ITaskMetadata}: identity and policy, no behaviour. The object passed at runtime is
26
- * the resolved task, so `run` is physically present; naming the metadata type here stops the obvious
27
- * mistake of a handler calling `params.definition.run(...)` and recursing forever.
25
+ * This is {@link ITaskMetadata}: identity and policy, no behaviour and no handler pointer. The
26
+ * object passed at runtime is the resolved task, so `run` is physically present; naming the metadata
27
+ * type here stops the obvious mistake of a handler calling `params.definition.run(...)` and
28
+ * recursing forever.
28
29
  *
29
30
  * Only the fields declared here arrive. A field a project adds to its own definition class is
30
- * currently dropped, because `RunnableTaskDecorator` and `SelfCleaningTaskDecorator` are fixed
31
- * pass-throughs that expose a known set of getters and nothing else. Making them forward unknown
31
+ * currently dropped, because `TaskDefinitionDefaultsDecorator` is a fixed pass-through that
32
+ * exposes a known set of getters and nothing else. Making them forward unknown
32
33
  * properties would turn a definition into a place to declare policy (a rate limit, a set of tags)
33
34
  * that a decorator acts on; `taskDefinitionInParams.test.ts` pins the current behaviour so that
34
35
  * change announces itself.
@@ -99,7 +100,7 @@ export type ITaskLifecycleHook<I extends ITaskInput = ITaskInput, O extends ITas
99
100
  * What a task IS: identity and runtime policy, with no behaviour and no dependencies.
100
101
  *
101
102
  * Listing tasks, resolving one by id, and applying defaults all need only this. Keeping it free of
102
- * dependencies is the whole point — `GetTaskDefinitionUseCase` builds every registered definition
103
+ * dependencies is the whole point — `GetRunnableTaskDefinitionUseCase` builds every registered definition
103
104
  * to find one by id, so anything expensive here is paid 24 times per lookup.
104
105
  */
105
106
  export interface ITaskMetadata {
@@ -140,22 +141,14 @@ export interface ITaskHandler<I extends ITaskInput = ITaskInput, O extends ITask
140
141
  createInputValidation?(params: ITaskCreateInputValidationParams): GenericRecord<keyof I, zod.Schema> | zod.Schema;
141
142
  }
142
143
  /**
143
- * Core TaskDefinition - minimal interface
144
+ * What you register: a task's {@link ITaskMetadata} plus the class that does the work.
144
145
  *
145
- * TRANSITIONAL SHAPE. A definition supplies its behaviour in one of two ways:
146
- *
147
- * - the new way: `handler` names a {@link ITaskHandler} class, which the runner builds only for the
148
- * task it is about to run;
149
- * - the old way: the definition implements `run()` and the hooks itself, which forces every
150
- * definition (and every dependency it injects) to be built just to look one up by id.
151
- *
152
- * `run` is optional ONLY to let both shapes coexist while packages migrate. Once every definition
153
- * carries a `handler`, this interface becomes `ITaskMetadata & { handler }` and the optionality
154
- * goes away. Exactly one of `run` or `handler` must be present; `GetTaskDefinitionUseCase` fails
155
- * with {@link TaskDefinitionNotRunnableError} if neither is.
146
+ * The definition takes no dependencies of its own, so `GetRunnableTaskDefinitionUseCase` can build every
147
+ * registered one to find a task by id without constructing anything expensive. Only the winner's
148
+ * `handler` gets built.
156
149
  */
157
- export interface ITaskDefinition<I extends ITaskInput = ITaskInput, O extends ITaskOutput = ITaskOutput> extends ITaskMetadata, Partial<ITaskHandler<I, O>> {
158
- handler?: Constructor<ITaskHandler<I, O>>;
150
+ export interface ITaskDefinition<I extends ITaskInput = ITaskInput, O extends ITaskOutput = ITaskOutput> extends ITaskMetadata {
151
+ handler: Constructor<ITaskHandler<I, O>>;
159
152
  }
160
153
  export interface ITaskCreateInputValidationParams {
161
154
  validator: typeof zod;
@@ -1 +1 @@
1
- {"version":3,"file":"features/task/TaskDefinition/abstractions.js","sources":["../../../../src/features/task/TaskDefinition/abstractions.ts"],"sourcesContent":["import zod from \"zod\";\nimport type { Constructor } from \"@webiny/di\";\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types\";\nimport type { ITask } from \"~/features/task/TaskService/index.js\";\nimport { TaskController } from \"~/features/task/TaskController/index.js\";\n\nexport type ITaskInput = GenericRecord;\n\nexport interface IResponseError {\n message: string;\n code?: string | null;\n data?: GenericRecord | null;\n stack?: string;\n}\n\nexport interface ITaskOutput {\n error?: IResponseError;\n [key: string]: any;\n}\n\n/**\n * The task's own definition, minus its behaviour.\n *\n * Handed to `run()` and to every lifecycle hook so a decorator can tell which task it is wrapping\n * and act on the definition's own fields. A decorator is registered against the abstraction, so it\n * wraps every task; without this it has nothing to branch on but a hardcoded list of ids, which\n * means editing the decorator every time a task is added.\n *\n * This is {@link ITaskMetadata}: identity and policy, no behaviour. The object passed at runtime is\n * the resolved task, so `run` is physically present; naming the metadata type here stops the obvious\n * mistake of a handler calling `params.definition.run(...)` and recursing forever.\n *\n * Only the fields declared here arrive. A field a project adds to its own definition class is\n * currently dropped, because `RunnableTaskDecorator` and `SelfCleaningTaskDecorator` are fixed\n * pass-throughs that expose a known set of getters and nothing else. Making them forward unknown\n * properties would turn a definition into a place to declare policy (a rate limit, a set of tags)\n * that a decorator acts on; `taskDefinitionInParams.test.ts` pins the current behaviour so that\n * change announces itself.\n */\nexport type ITaskDefinitionInfo = ITaskMetadata;\n\n/**\n * Task run params - the input data, plus the definition being run\n * All runtime dependencies come from TaskController (injected separately)\n */\nexport interface ITaskRunParams<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n> {\n input: I;\n controller: TaskController.Interface<I, O>;\n definition: ITaskDefinitionInfo;\n}\n\n/**\n * Data for creating a new task\n */\nexport interface ITaskCreateData<I = ITaskInput> {\n definitionId: string;\n name: string;\n input: I;\n parentId?: string;\n}\n\n/**\n * Parameters for onBeforeTrigger lifecycle hook\n */\nexport interface ITaskBeforeTriggerParams<I = ITaskInput> {\n data: ITaskCreateData<I>;\n definition: ITaskDefinitionInfo;\n}\n\n/**\n * Task result status enum\n */\nexport enum TaskResultStatus {\n DONE = \"done\",\n CONTINUE = \"continue\",\n ERROR = \"error\",\n ABORTED = \"aborted\"\n}\n\n/**\n * Specific result types\n */\nexport interface ITaskResultDone<O extends ITaskOutput = ITaskOutput> {\n status: TaskResultStatus.DONE;\n message?: string;\n output?: O;\n}\n\nexport interface ITaskResultContinue<I = ITaskInput> {\n status: TaskResultStatus.CONTINUE;\n input: I;\n wait?: number; // seconds to wait before next iteration\n}\n\nexport interface ITaskResultError {\n status: TaskResultStatus.ERROR;\n error: IResponseError;\n}\n\nexport interface ITaskResultAborted {\n status: TaskResultStatus.ABORTED;\n}\n\nexport type ITaskResult<I = ITaskInput, O extends ITaskOutput = ITaskOutput> =\n | ITaskResultDone<O>\n | ITaskResultContinue<I>\n | ITaskResultError\n | ITaskResultAborted;\n\nexport type ISelfCleanupEvent = \"onSuccess\" | \"onError\" | \"onAbort\";\n\nexport type ISelfCleanup = \"always\" | \"never\" | ISelfCleanupEvent | ISelfCleanupEvent[];\n\nexport type ITaskLifecycleHook<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n> = {\n task: ITask<I, O>;\n definition: ITaskDefinitionInfo;\n};\n\n/**\n * What a task IS: identity and runtime policy, with no behaviour and no dependencies.\n *\n * Listing tasks, resolving one by id, and applying defaults all need only this. Keeping it free of\n * dependencies is the whole point — `GetTaskDefinitionUseCase` builds every registered definition\n * to find one by id, so anything expensive here is paid 24 times per lookup.\n */\nexport interface ITaskMetadata {\n id: string;\n title: string;\n description?: string;\n maxIterations?: number;\n databaseLogs?: boolean;\n isPrivate?: boolean;\n selfCleanup?: ISelfCleanup;\n}\n\n/**\n * What a task DOES. This is the half that carries dependencies (a CMS context, an OpenSearch\n * client), so it is built only for the task actually being run.\n *\n * The lifecycle hooks live here rather than on {@link ITaskMetadata} because they need the same\n * dependencies `run()` does — see `MockDataManagerTask`, whose `onError` and `onAbort` both use the\n * OpenSearch client injected for `run()`.\n */\nexport interface ITaskHandler<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n> {\n /**\n * Core run method - receives ONLY input params\n * All runtime dependencies (logging, state management, etc.) come from TaskController\n */\n run(params: ITaskRunParams<I, O>): Promise<ITaskResult<I, O>>;\n\n /**\n * Optional lifecycle hooks - receive task data, no context.\n */\n onBeforeTrigger?(params: ITaskBeforeTriggerParams<I>): Promise<void>;\n onDone?(params: ITaskLifecycleHook<I, O>): Promise<void>;\n onError?(params: ITaskLifecycleHook<I, O>): Promise<void>;\n onAbort?(params: ITaskLifecycleHook<I, O>): Promise<void>;\n onMaxIterations?(params: ITaskLifecycleHook<I, O>): Promise<void>;\n /**\n * Create a validation schema for the task input.\n * This will be used to validate the input before the task is triggered.\n */\n createInputValidation?(\n params: ITaskCreateInputValidationParams\n ): GenericRecord<keyof I, zod.Schema> | zod.Schema;\n}\n\n/**\n * Core TaskDefinition - minimal interface\n *\n * TRANSITIONAL SHAPE. A definition supplies its behaviour in one of two ways:\n *\n * - the new way: `handler` names a {@link ITaskHandler} class, which the runner builds only for the\n * task it is about to run;\n * - the old way: the definition implements `run()` and the hooks itself, which forces every\n * definition (and every dependency it injects) to be built just to look one up by id.\n *\n * `run` is optional ONLY to let both shapes coexist while packages migrate. Once every definition\n * carries a `handler`, this interface becomes `ITaskMetadata & { handler }` and the optionality\n * goes away. Exactly one of `run` or `handler` must be present; `GetTaskDefinitionUseCase` fails\n * with {@link TaskDefinitionNotRunnableError} if neither is.\n */\nexport interface ITaskDefinition<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n>\n extends ITaskMetadata, Partial<ITaskHandler<I, O>> {\n handler?: Constructor<ITaskHandler<I, O>>;\n}\n\nexport interface ITaskCreateInputValidationParams {\n validator: typeof zod;\n}\n\n/** Define a long-running background task with lifecycle hooks. */\nexport const TaskDefinition = createAbstraction<ITaskDefinition>(\"TaskDefinition\");\n\n/**\n * The behaviour half of a task, resolved on demand by the runner via\n * `container.resolveImplementation(definition.handler)`. Registered implementations are NOT\n * registered against this abstraction — the definition points at the class directly, exactly as\n * `HttpRouteDefinition` points at its `HttpRouteHandler`.\n */\nexport const TaskHandler = createAbstraction<ITaskHandler>(\"TaskHandler\");\n\n/**\n * IRunnableTaskDefinition represents a TaskDefinition after decoration/processing.\n * All optional runtime properties are guaranteed to have values (with defaults applied).\n * Used internally by the task runner to ensure consistent behavior.\n */\nexport interface IRunnableTaskDefinition<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n>\n extends ITaskMetadata, ITaskHandler<I, O> {\n // Override optional properties to be required with guaranteed values\n isPrivate: boolean;\n databaseLogs: boolean;\n maxIterations: number;\n}\n\nexport namespace TaskHandler {\n export type Interface<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskHandler<I, O>;\n\n export type RunParams<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskRunParams<I, O>;\n\n export type Result<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskResult<I, O>;\n\n export type LifecycleHookParams<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskLifecycleHook<I, O>;\n}\n\nexport namespace TaskDefinition {\n export type Interface<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskDefinition<I, O>;\n\n export type Metadata = ITaskMetadata;\n\n export type Handler<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskHandler<I, O>;\n\n export type TaskInput = ITaskInput;\n\n export type TaskOutput = ITaskOutput;\n\n export type Runnable<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = IRunnableTaskDefinition<I, O>;\n\n export type RunParams<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskRunParams<I, O>;\n\n export type Result<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskResult<I, O>;\n\n export type Task<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITask<I, O>;\n\n export type ResultDone<O extends ITaskOutput = ITaskOutput> = ITaskResultDone<O>;\n export type ResultContinue<I = ITaskInput> = ITaskResultContinue<I>;\n export type ResultError = ITaskResultError;\n export type ResultAborted = ITaskResultAborted;\n export type CreateInputValidationParams = ITaskCreateInputValidationParams;\n export type TaskCreateData<I = ITaskInput> = ITaskCreateData<I>;\n export type BeforeTriggerParams<I = ITaskInput> = ITaskBeforeTriggerParams<I>;\n export type LifecycleHookParams<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskLifecycleHook<I, O>;\n\n export type Info = ITaskDefinitionInfo;\n\n export type SelfCleanupEvent = ISelfCleanupEvent;\n export type SelfCleanup = ISelfCleanup;\n}\n"],"names":["TaskResultStatus","TaskDefinition","createAbstraction","TaskHandler"],"mappings":";AA4EO,IAAKA,gCAAgBA,WAAAA,GAAAA,SAAhBA,gBAAgB;;;;;WAAhBA;;AAiIL,MAAMC,iBAAiBC,kBAAmC;AAQ1D,MAAMC,cAAcD,kBAAgC"}
1
+ {"version":3,"file":"features/task/TaskDefinition/abstractions.js","sources":["../../../../src/features/task/TaskDefinition/abstractions.ts"],"sourcesContent":["import zod from \"zod\";\nimport type { Constructor } from \"@webiny/di\";\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types\";\nimport type { ITask } from \"~/features/task/TaskService/index.js\";\nimport { TaskController } from \"~/features/task/TaskController/index.js\";\n\nexport type ITaskInput = GenericRecord;\n\nexport interface IResponseError {\n message: string;\n code?: string | null;\n data?: GenericRecord | null;\n stack?: string;\n}\n\nexport interface ITaskOutput {\n error?: IResponseError;\n [key: string]: any;\n}\n\n/**\n * The task's own definition, minus its behaviour.\n *\n * Handed to `run()` and to every lifecycle hook so a decorator can tell which task it is wrapping\n * and act on the definition's own fields. A decorator is registered against the abstraction, so it\n * wraps every task; without this it has nothing to branch on but a hardcoded list of ids, which\n * means editing the decorator every time a task is added.\n *\n * This is {@link ITaskMetadata}: identity and policy, no behaviour and no handler pointer. The\n * object passed at runtime is the resolved task, so `run` is physically present; naming the metadata\n * type here stops the obvious mistake of a handler calling `params.definition.run(...)` and\n * recursing forever.\n *\n * Only the fields declared here arrive. A field a project adds to its own definition class is\n * currently dropped, because `TaskDefinitionDefaultsDecorator` is a fixed pass-through that\n * exposes a known set of getters and nothing else. Making them forward unknown\n * properties would turn a definition into a place to declare policy (a rate limit, a set of tags)\n * that a decorator acts on; `taskDefinitionInParams.test.ts` pins the current behaviour so that\n * change announces itself.\n */\nexport type ITaskDefinitionInfo = ITaskMetadata;\n\n/**\n * Task run params - the input data, plus the definition being run\n * All runtime dependencies come from TaskController (injected separately)\n */\nexport interface ITaskRunParams<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n> {\n input: I;\n controller: TaskController.Interface<I, O>;\n definition: ITaskDefinitionInfo;\n}\n\n/**\n * Data for creating a new task\n */\nexport interface ITaskCreateData<I = ITaskInput> {\n definitionId: string;\n name: string;\n input: I;\n parentId?: string;\n}\n\n/**\n * Parameters for onBeforeTrigger lifecycle hook\n */\nexport interface ITaskBeforeTriggerParams<I = ITaskInput> {\n data: ITaskCreateData<I>;\n definition: ITaskDefinitionInfo;\n}\n\n/**\n * Task result status enum\n */\nexport enum TaskResultStatus {\n DONE = \"done\",\n CONTINUE = \"continue\",\n ERROR = \"error\",\n ABORTED = \"aborted\"\n}\n\n/**\n * Specific result types\n */\nexport interface ITaskResultDone<O extends ITaskOutput = ITaskOutput> {\n status: TaskResultStatus.DONE;\n message?: string;\n output?: O;\n}\n\nexport interface ITaskResultContinue<I = ITaskInput> {\n status: TaskResultStatus.CONTINUE;\n input: I;\n wait?: number; // seconds to wait before next iteration\n}\n\nexport interface ITaskResultError {\n status: TaskResultStatus.ERROR;\n error: IResponseError;\n}\n\nexport interface ITaskResultAborted {\n status: TaskResultStatus.ABORTED;\n}\n\nexport type ITaskResult<I = ITaskInput, O extends ITaskOutput = ITaskOutput> =\n | ITaskResultDone<O>\n | ITaskResultContinue<I>\n | ITaskResultError\n | ITaskResultAborted;\n\nexport type ISelfCleanupEvent = \"onSuccess\" | \"onError\" | \"onAbort\";\n\nexport type ISelfCleanup = \"always\" | \"never\" | ISelfCleanupEvent | ISelfCleanupEvent[];\n\nexport type ITaskLifecycleHook<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n> = {\n task: ITask<I, O>;\n definition: ITaskDefinitionInfo;\n};\n\n/**\n * What a task IS: identity and runtime policy, with no behaviour and no dependencies.\n *\n * Listing tasks, resolving one by id, and applying defaults all need only this. Keeping it free of\n * dependencies is the whole point — `GetRunnableTaskDefinitionUseCase` builds every registered definition\n * to find one by id, so anything expensive here is paid 24 times per lookup.\n */\nexport interface ITaskMetadata {\n id: string;\n title: string;\n description?: string;\n maxIterations?: number;\n databaseLogs?: boolean;\n isPrivate?: boolean;\n selfCleanup?: ISelfCleanup;\n}\n\n/**\n * What a task DOES. This is the half that carries dependencies (a CMS context, an OpenSearch\n * client), so it is built only for the task actually being run.\n *\n * The lifecycle hooks live here rather than on {@link ITaskMetadata} because they need the same\n * dependencies `run()` does — see `MockDataManagerTask`, whose `onError` and `onAbort` both use the\n * OpenSearch client injected for `run()`.\n */\nexport interface ITaskHandler<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n> {\n /**\n * Core run method - receives ONLY input params\n * All runtime dependencies (logging, state management, etc.) come from TaskController\n */\n run(params: ITaskRunParams<I, O>): Promise<ITaskResult<I, O>>;\n\n /**\n * Optional lifecycle hooks - receive task data, no context.\n */\n onBeforeTrigger?(params: ITaskBeforeTriggerParams<I>): Promise<void>;\n onDone?(params: ITaskLifecycleHook<I, O>): Promise<void>;\n onError?(params: ITaskLifecycleHook<I, O>): Promise<void>;\n onAbort?(params: ITaskLifecycleHook<I, O>): Promise<void>;\n onMaxIterations?(params: ITaskLifecycleHook<I, O>): Promise<void>;\n /**\n * Create a validation schema for the task input.\n * This will be used to validate the input before the task is triggered.\n */\n createInputValidation?(\n params: ITaskCreateInputValidationParams\n ): GenericRecord<keyof I, zod.Schema> | zod.Schema;\n}\n\n/**\n * What you register: a task's {@link ITaskMetadata} plus the class that does the work.\n *\n * The definition takes no dependencies of its own, so `GetRunnableTaskDefinitionUseCase` can build every\n * registered one to find a task by id without constructing anything expensive. Only the winner's\n * `handler` gets built.\n */\nexport interface ITaskDefinition<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n> extends ITaskMetadata {\n handler: Constructor<ITaskHandler<I, O>>;\n}\n\nexport interface ITaskCreateInputValidationParams {\n validator: typeof zod;\n}\n\n/** Define a long-running background task with lifecycle hooks. */\nexport const TaskDefinition = createAbstraction<ITaskDefinition>(\"TaskDefinition\");\n\n/**\n * The behaviour half of a task, resolved on demand by the runner via\n * `container.resolveImplementation(definition.handler)`. Registered implementations are NOT\n * registered against this abstraction — the definition points at the class directly, exactly as\n * `HttpRouteDefinition` points at its `HttpRouteHandler`.\n */\nexport const TaskHandler = createAbstraction<ITaskHandler>(\"TaskHandler\");\n\n/**\n * IRunnableTaskDefinition represents a TaskDefinition after decoration/processing.\n * All optional runtime properties are guaranteed to have values (with defaults applied).\n * Used internally by the task runner to ensure consistent behavior.\n */\nexport interface IRunnableTaskDefinition<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n>\n extends ITaskMetadata, ITaskHandler<I, O> {\n // Override optional properties to be required with guaranteed values\n isPrivate: boolean;\n databaseLogs: boolean;\n maxIterations: number;\n}\n\nexport namespace TaskHandler {\n export type Interface<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskHandler<I, O>;\n\n export type RunParams<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskRunParams<I, O>;\n\n export type Result<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskResult<I, O>;\n\n export type LifecycleHookParams<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskLifecycleHook<I, O>;\n}\n\nexport namespace TaskDefinition {\n export type Interface<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskDefinition<I, O>;\n\n export type Metadata = ITaskMetadata;\n\n export type Handler<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskHandler<I, O>;\n\n export type TaskInput = ITaskInput;\n\n export type TaskOutput = ITaskOutput;\n\n export type Runnable<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = IRunnableTaskDefinition<I, O>;\n\n export type RunParams<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskRunParams<I, O>;\n\n export type Result<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskResult<I, O>;\n\n export type Task<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITask<I, O>;\n\n export type ResultDone<O extends ITaskOutput = ITaskOutput> = ITaskResultDone<O>;\n export type ResultContinue<I = ITaskInput> = ITaskResultContinue<I>;\n export type ResultError = ITaskResultError;\n export type ResultAborted = ITaskResultAborted;\n export type CreateInputValidationParams = ITaskCreateInputValidationParams;\n export type TaskCreateData<I = ITaskInput> = ITaskCreateData<I>;\n export type BeforeTriggerParams<I = ITaskInput> = ITaskBeforeTriggerParams<I>;\n export type LifecycleHookParams<\n I extends ITaskInput = ITaskInput,\n O extends ITaskOutput = ITaskOutput\n > = ITaskLifecycleHook<I, O>;\n\n export type Info = ITaskDefinitionInfo;\n\n export type SelfCleanupEvent = ISelfCleanupEvent;\n export type SelfCleanup = ISelfCleanup;\n}\n"],"names":["TaskResultStatus","TaskDefinition","createAbstraction","TaskHandler"],"mappings":";AA6EO,IAAKA,gCAAgBA,WAAAA,GAAAA,SAAhBA,gBAAgB;;;;;WAAhBA;;AAwHL,MAAMC,iBAAiBC,kBAAmC;AAQ1D,MAAMC,cAAcD,kBAAgC"}
@@ -1 +1 @@
1
- {"version":3,"file":"features/wcp/WcpLicenseLoader.js","sources":["../../../src/features/wcp/WcpLicenseLoader.ts"],"sourcesContent":["import { getWcpProjectLicense, NullLicense, License } from \"@webiny/wcp\";\nimport type { DecryptedWcpProjectLicense, ILicense } from \"@webiny/wcp/types.js\";\nimport type { CachedWcpProjectLicense } from \"~/features/wcp/WcpContext/types.js\";\nimport { getWcpProjectLicenseCacheKey } from \"~/features/wcp/WcpContext/utils.js\";\nimport { resolveWcpProjectEnvironment } from \"~/features/wcp/resolveWcpProjectEnvironment.js\";\n\n/**\n * Loads and process-caches the WCP project license. Static because the cache is process-global (one\n * license per deployment): the pre-register refresh in `registerApiRequestStack` calls `load()` to\n * populate it, and `WcpLicenseProvider` / register-time feature-flag gates read it synchronously via\n * `getCached()`. Not DI — it must be usable before any container exists (before register).\n */\nexport class WcpLicenseLoader {\n private static readonly wcpProjectEnvironment = resolveWcpProjectEnvironment();\n\n private static cached: CachedWcpProjectLicense = {\n cacheKey: null,\n project: null,\n license: new NullLicense()\n };\n\n // In-flight fetch, memoized so concurrent cache-miss callers coalesce onto a single WCP request\n // (self-hosted runs many requests in one process; we never want two license fetches at once).\n private static inflight: Promise<ILicense> | null = null;\n\n /**\n * Synchronously read the currently cached license. `load()` must have been awaited at least once\n * this request (the pre-register refresh does this), so this reflects the live license — letting\n * register()-time feature-flag checks read it synchronously.\n */\n static getCached(): ILicense {\n return WcpLicenseLoader.cached.license;\n }\n\n /**\n * Seed the cache with an already-resolved license (tests pass a pre-built one). Marks it fresh so\n * a subsequent `load()` returns it without a fetch. This is how `WcpLicenseProviderImpl` installs\n * an initial license.\n */\n static seed(license: ILicense): void {\n WcpLicenseLoader.cached.license = license;\n WcpLicenseLoader.cached.cacheKey = getWcpProjectLicenseCacheKey();\n }\n\n static async load(testProjectLicense?: DecryptedWcpProjectLicense): Promise<ILicense> {\n const cached = WcpLicenseLoader.cached;\n\n if (testProjectLicense) {\n cached.license = License.fromLicenseDto(testProjectLicense);\n return cached.license;\n }\n\n const env = WcpLicenseLoader.wcpProjectEnvironment;\n if (!env) {\n return cached.license;\n }\n\n const currentCacheKey = getWcpProjectLicenseCacheKey();\n if (cached.cacheKey === currentCacheKey) {\n return cached.license;\n }\n\n // Cache miss (first load or the ~5-min key rotated). Coalesce concurrent callers onto one fetch.\n if (WcpLicenseLoader.inflight) {\n return WcpLicenseLoader.inflight;\n }\n\n WcpLicenseLoader.inflight = (async () => {\n // Pull the project license from the WCP API.\n const decryptedLicenseDto = await getWcpProjectLicense({\n orgId: env.org.id,\n projectId: env.project.id,\n projectEnvironmentApiKey: env.apiKey\n });\n\n if (decryptedLicenseDto) {\n cached.project = {\n orgId: decryptedLicenseDto.orgId,\n projectId: decryptedLicenseDto.projectId,\n package: decryptedLicenseDto.package\n };\n }\n\n cached.license = License.fromLicenseDto(decryptedLicenseDto);\n // Mark fresh only after a successful fetch — a throw leaves the key unset so the next call retries.\n cached.cacheKey = currentCacheKey;\n return cached.license;\n })().finally(() => {\n WcpLicenseLoader.inflight = null;\n });\n\n return WcpLicenseLoader.inflight;\n }\n}\n"],"names":["WcpLicenseLoader","resolveWcpProjectEnvironment","NullLicense","license","getWcpProjectLicenseCacheKey","testProjectLicense","cached","License","env","currentCacheKey","decryptedLicenseDto","getWcpProjectLicense"],"mappings":";;;AAYO,MAAMA;;aACe,qBAAqB,GAAGC;;;aAEjC,MAAM,GAA4B;YAC7C,UAAU;YACV,SAAS;YACT,SAAS,IAAIC;QACjB;;;aAIe,QAAQ,GAA6B;;IAOpD,OAAO,YAAsB;QACzB,OAAOF,iBAAiB,MAAM,CAAC,OAAO;IAC1C;IAOA,OAAO,KAAKG,OAAiB,EAAQ;QACjCH,iBAAiB,MAAM,CAAC,OAAO,GAAGG;QAClCH,iBAAiB,MAAM,CAAC,QAAQ,GAAGI;IACvC;IAEA,aAAa,KAAKC,kBAA+C,EAAqB;QAClF,MAAMC,SAASN,iBAAiB,MAAM;QAEtC,IAAIK,oBAAoB;YACpBC,OAAO,OAAO,GAAGC,QAAQ,cAAc,CAACF;YACxC,OAAOC,OAAO,OAAO;QACzB;QAEA,MAAME,MAAMR,iBAAiB,qBAAqB;QAClD,IAAI,CAACQ,KACD,OAAOF,OAAO,OAAO;QAGzB,MAAMG,kBAAkBL;QACxB,IAAIE,OAAO,QAAQ,KAAKG,iBACpB,OAAOH,OAAO,OAAO;QAIzB,IAAIN,iBAAiB,QAAQ,EACzB,OAAOA,iBAAiB,QAAQ;QAGpCA,iBAAiB,QAAQ,GAAI;YAEzB,MAAMU,sBAAsB,MAAMC,qBAAqB;gBACnD,OAAOH,IAAI,GAAG,CAAC,EAAE;gBACjB,WAAWA,IAAI,OAAO,CAAC,EAAE;gBACzB,0BAA0BA,IAAI,MAAM;YACxC;YAEA,IAAIE,qBACAJ,OAAO,OAAO,GAAG;gBACb,OAAOI,oBAAoB,KAAK;gBAChC,WAAWA,oBAAoB,SAAS;gBACxC,SAASA,oBAAoB,OAAO;YACxC;YAGJJ,OAAO,OAAO,GAAGC,QAAQ,cAAc,CAACG;YAExCJ,OAAO,QAAQ,GAAGG;YAClB,OAAOH,OAAO,OAAO;QACzB,KAAK,OAAO,CAAC;YACTN,iBAAiB,QAAQ,GAAG;QAChC;QAEA,OAAOA,iBAAiB,QAAQ;IACpC;AACJ"}
1
+ {"version":3,"file":"features/wcp/WcpLicenseLoader.js","sources":["../../../src/features/wcp/WcpLicenseLoader.ts"],"sourcesContent":["import { getWcpProjectLicense, NullLicense, License } from \"@webiny/wcp\";\nimport type { DecryptedWcpProjectLicense, ILicense } from \"@webiny/wcp/types.js\";\nimport type { CachedWcpProjectLicense } from \"~/features/wcp/WcpContext/types.js\";\nimport { getWcpProjectLicenseCacheKey } from \"~/features/wcp/WcpContext/utils.js\";\nimport { resolveWcpProjectEnvironment } from \"~/features/wcp/resolveWcpProjectEnvironment.js\";\n\n/**\n * Loads and process-caches the WCP project license. Static because the cache is process-global (one\n * license per deployment): the pre-register refresh in `registerApiRequestStack` calls `load()` to\n * populate it, and `WcpLicenseProvider` / register-time feature-flag gates read it synchronously via\n * `getCached()`. Not DI — it must be usable before any container exists (before register).\n */\nexport class WcpLicenseLoader {\n private static readonly wcpProjectEnvironment = resolveWcpProjectEnvironment();\n\n private static cached: CachedWcpProjectLicense = {\n cacheKey: null,\n project: null,\n license: new NullLicense()\n };\n\n // In-flight fetch, memoized so concurrent cache-miss callers coalesce onto a single WCP request\n // (standalone runs many requests in one process; we never want two license fetches at once).\n private static inflight: Promise<ILicense> | null = null;\n\n /**\n * Synchronously read the currently cached license. `load()` must have been awaited at least once\n * this request (the pre-register refresh does this), so this reflects the live license — letting\n * register()-time feature-flag checks read it synchronously.\n */\n static getCached(): ILicense {\n return WcpLicenseLoader.cached.license;\n }\n\n /**\n * Seed the cache with an already-resolved license (tests pass a pre-built one). Marks it fresh so\n * a subsequent `load()` returns it without a fetch. This is how `WcpLicenseProviderImpl` installs\n * an initial license.\n */\n static seed(license: ILicense): void {\n WcpLicenseLoader.cached.license = license;\n WcpLicenseLoader.cached.cacheKey = getWcpProjectLicenseCacheKey();\n }\n\n static async load(testProjectLicense?: DecryptedWcpProjectLicense): Promise<ILicense> {\n const cached = WcpLicenseLoader.cached;\n\n if (testProjectLicense) {\n cached.license = License.fromLicenseDto(testProjectLicense);\n return cached.license;\n }\n\n const env = WcpLicenseLoader.wcpProjectEnvironment;\n if (!env) {\n return cached.license;\n }\n\n const currentCacheKey = getWcpProjectLicenseCacheKey();\n if (cached.cacheKey === currentCacheKey) {\n return cached.license;\n }\n\n // Cache miss (first load or the ~5-min key rotated). Coalesce concurrent callers onto one fetch.\n if (WcpLicenseLoader.inflight) {\n return WcpLicenseLoader.inflight;\n }\n\n WcpLicenseLoader.inflight = (async () => {\n // Pull the project license from the WCP API.\n const decryptedLicenseDto = await getWcpProjectLicense({\n orgId: env.org.id,\n projectId: env.project.id,\n projectEnvironmentApiKey: env.apiKey\n });\n\n if (decryptedLicenseDto) {\n cached.project = {\n orgId: decryptedLicenseDto.orgId,\n projectId: decryptedLicenseDto.projectId,\n package: decryptedLicenseDto.package\n };\n }\n\n cached.license = License.fromLicenseDto(decryptedLicenseDto);\n // Mark fresh only after a successful fetch — a throw leaves the key unset so the next call retries.\n cached.cacheKey = currentCacheKey;\n return cached.license;\n })().finally(() => {\n WcpLicenseLoader.inflight = null;\n });\n\n return WcpLicenseLoader.inflight;\n }\n}\n"],"names":["WcpLicenseLoader","resolveWcpProjectEnvironment","NullLicense","license","getWcpProjectLicenseCacheKey","testProjectLicense","cached","License","env","currentCacheKey","decryptedLicenseDto","getWcpProjectLicense"],"mappings":";;;AAYO,MAAMA;;aACe,qBAAqB,GAAGC;;;aAEjC,MAAM,GAA4B;YAC7C,UAAU;YACV,SAAS;YACT,SAAS,IAAIC;QACjB;;;aAIe,QAAQ,GAA6B;;IAOpD,OAAO,YAAsB;QACzB,OAAOF,iBAAiB,MAAM,CAAC,OAAO;IAC1C;IAOA,OAAO,KAAKG,OAAiB,EAAQ;QACjCH,iBAAiB,MAAM,CAAC,OAAO,GAAGG;QAClCH,iBAAiB,MAAM,CAAC,QAAQ,GAAGI;IACvC;IAEA,aAAa,KAAKC,kBAA+C,EAAqB;QAClF,MAAMC,SAASN,iBAAiB,MAAM;QAEtC,IAAIK,oBAAoB;YACpBC,OAAO,OAAO,GAAGC,QAAQ,cAAc,CAACF;YACxC,OAAOC,OAAO,OAAO;QACzB;QAEA,MAAME,MAAMR,iBAAiB,qBAAqB;QAClD,IAAI,CAACQ,KACD,OAAOF,OAAO,OAAO;QAGzB,MAAMG,kBAAkBL;QACxB,IAAIE,OAAO,QAAQ,KAAKG,iBACpB,OAAOH,OAAO,OAAO;QAIzB,IAAIN,iBAAiB,QAAQ,EACzB,OAAOA,iBAAiB,QAAQ;QAGpCA,iBAAiB,QAAQ,GAAI;YAEzB,MAAMU,sBAAsB,MAAMC,qBAAqB;gBACnD,OAAOH,IAAI,GAAG,CAAC,EAAE;gBACjB,WAAWA,IAAI,OAAO,CAAC,EAAE;gBACzB,0BAA0BA,IAAI,MAAM;YACxC;YAEA,IAAIE,qBACAJ,OAAO,OAAO,GAAG;gBACb,OAAOI,oBAAoB,KAAK;gBAChC,WAAWA,oBAAoB,SAAS;gBACxC,SAASA,oBAAoB,OAAO;YACxC;YAGJJ,OAAO,OAAO,GAAGC,QAAQ,cAAc,CAACG;YAExCJ,OAAO,QAAQ,GAAGG;YAClB,OAAOH,OAAO,OAAO;QACzB,KAAK,OAAO,CAAC;YACTN,iBAAiB,QAAQ,GAAG;QAChC;QAEA,OAAOA,iBAAiB,QAAQ;IACpC;AACJ"}
@@ -2,7 +2,7 @@ import type { WcpProjectEnvironment } from "@webiny/wcp/types.js";
2
2
  /**
3
3
  * Resolve the WCP project environment used to fetch the license. Prefer the CLI-computed
4
4
  * WCP_PROJECT_ENVIRONMENT blob (set by `applyWcpEnvVars` during `webiny serve` and the AWS deploy).
5
- * When it's absent — a CLI-less self-hosted deploy that boots the built handler directly (e.g.
5
+ * When it's absent — a CLI-less standalone deploy that boots the built handler directly (e.g.
6
6
  * `node start.mjs`) — derive the same org, project and api key straight from the runtime env, so a
7
7
  * fresh license can still be fetched.
8
8
  */
@@ -1 +1 @@
1
- {"version":3,"file":"features/wcp/resolveWcpProjectEnvironment.js","sources":["../../../src/features/wcp/resolveWcpProjectEnvironment.ts"],"sourcesContent":["import { getWcpProjectEnvironment } from \"@webiny/wcp\";\nimport type { WcpProjectEnvironment } from \"@webiny/wcp/types.js\";\n\n/**\n * Resolve the WCP project environment used to fetch the license. Prefer the CLI-computed\n * WCP_PROJECT_ENVIRONMENT blob (set by `applyWcpEnvVars` during `webiny serve` and the AWS deploy).\n * When it's absent — a CLI-less self-hosted deploy that boots the built handler directly (e.g.\n * `node start.mjs`) — derive the same org, project and api key straight from the runtime env, so a\n * fresh license can still be fetched.\n */\nexport function resolveWcpProjectEnvironment(): WcpProjectEnvironment | null {\n const fromBlob = getWcpProjectEnvironment();\n if (fromBlob) {\n return fromBlob;\n }\n\n const projectId = process.env.WEBINY_PROJECT_ID || process.env.WCP_PROJECT_ID;\n const apiKey =\n process.env.WEBINY_PROJECT_API_KEY || process.env.WCP_PROJECT_ENVIRONMENT_API_KEY;\n if (!projectId || !apiKey) {\n return null;\n }\n\n // WEBINY_PROJECT_ID has an \"orgId/projectId\" shape.\n const [orgId, project] = projectId.split(\"/\");\n if (!orgId || !project) {\n return null;\n }\n\n // `id` is intentionally empty. The WCP backend identifies the specific project environment\n // from the api key (sent as the request's authorization header); the license fetch only uses\n // org/project (URL path) + apiKey (auth), never the environment id. So there's nothing to fill.\n return { id: \"\", apiKey, org: { id: orgId }, project: { id: project } };\n}\n"],"names":["resolveWcpProjectEnvironment","fromBlob","getWcpProjectEnvironment","projectId","process","apiKey","orgId","project"],"mappings":";AAUO,SAASA;IACZ,MAAMC,WAAWC;IACjB,IAAID,UACA,OAAOA;IAGX,MAAME,YAAYC,QAAQ,GAAG,CAAC,iBAAiB,IAAIA,QAAQ,GAAG,CAAC,cAAc;IAC7E,MAAMC,SACFD,QAAQ,GAAG,CAAC,sBAAsB,IAAIA,QAAQ,GAAG,CAAC,+BAA+B;IACrF,IAAI,CAACD,aAAa,CAACE,QACf,OAAO;IAIX,MAAM,CAACC,OAAOC,QAAQ,GAAGJ,UAAU,KAAK,CAAC;IACzC,IAAI,CAACG,SAAS,CAACC,SACX,OAAO;IAMX,OAAO;QAAE,IAAI;QAAIF;QAAQ,KAAK;YAAE,IAAIC;QAAM;QAAG,SAAS;YAAE,IAAIC;QAAQ;IAAE;AAC1E"}
1
+ {"version":3,"file":"features/wcp/resolveWcpProjectEnvironment.js","sources":["../../../src/features/wcp/resolveWcpProjectEnvironment.ts"],"sourcesContent":["import { getWcpProjectEnvironment } from \"@webiny/wcp\";\nimport type { WcpProjectEnvironment } from \"@webiny/wcp/types.js\";\n\n/**\n * Resolve the WCP project environment used to fetch the license. Prefer the CLI-computed\n * WCP_PROJECT_ENVIRONMENT blob (set by `applyWcpEnvVars` during `webiny serve` and the AWS deploy).\n * When it's absent — a CLI-less standalone deploy that boots the built handler directly (e.g.\n * `node start.mjs`) — derive the same org, project and api key straight from the runtime env, so a\n * fresh license can still be fetched.\n */\nexport function resolveWcpProjectEnvironment(): WcpProjectEnvironment | null {\n const fromBlob = getWcpProjectEnvironment();\n if (fromBlob) {\n return fromBlob;\n }\n\n const projectId = process.env.WEBINY_PROJECT_ID || process.env.WCP_PROJECT_ID;\n const apiKey =\n process.env.WEBINY_PROJECT_API_KEY || process.env.WCP_PROJECT_ENVIRONMENT_API_KEY;\n if (!projectId || !apiKey) {\n return null;\n }\n\n // WEBINY_PROJECT_ID has an \"orgId/projectId\" shape.\n const [orgId, project] = projectId.split(\"/\");\n if (!orgId || !project) {\n return null;\n }\n\n // `id` is intentionally empty. The WCP backend identifies the specific project environment\n // from the api key (sent as the request's authorization header); the license fetch only uses\n // org/project (URL path) + apiKey (auth), never the environment id. So there's nothing to fill.\n return { id: \"\", apiKey, org: { id: orgId }, project: { id: project } };\n}\n"],"names":["resolveWcpProjectEnvironment","fromBlob","getWcpProjectEnvironment","projectId","process","apiKey","orgId","project"],"mappings":";AAUO,SAASA;IACZ,MAAMC,WAAWC;IACjB,IAAID,UACA,OAAOA;IAGX,MAAME,YAAYC,QAAQ,GAAG,CAAC,iBAAiB,IAAIA,QAAQ,GAAG,CAAC,cAAc;IAC7E,MAAMC,SACFD,QAAQ,GAAG,CAAC,sBAAsB,IAAIA,QAAQ,GAAG,CAAC,+BAA+B;IACrF,IAAI,CAACD,aAAa,CAACE,QACf,OAAO;IAIX,MAAM,CAACC,OAAOC,QAAQ,GAAGJ,UAAU,KAAK,CAAC;IACzC,IAAI,CAACG,SAAS,CAACC,SACX,OAAO;IAMX,OAAO;QAAE,IAAI;QAAIF;QAAQ,KAAK;YAAE,IAAIC;QAAM;QAAG,SAAS;YAAE,IAAIC;QAAQ;IAAE;AAC1E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-core",
3
- "version": "6.6.0-alpha.3",
3
+ "version": "6.6.0-alpha.4",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,16 +16,16 @@
16
16
  "dependencies": {
17
17
  "@ai-sdk/anthropic": "4.0.40",
18
18
  "@ai-sdk/openai": "4.0.45",
19
- "@webiny/api": "6.6.0-alpha.3",
20
- "@webiny/api-graphql": "6.6.0-alpha.3",
19
+ "@webiny/api": "6.6.0-alpha.4",
20
+ "@webiny/api-graphql": "6.6.0-alpha.4",
21
21
  "@webiny/di": "1.1.0",
22
- "@webiny/error": "6.6.0-alpha.3",
23
- "@webiny/event-handler-core": "6.6.0-alpha.3",
24
- "@webiny/feature": "6.6.0-alpha.3",
25
- "@webiny/feature-flags": "6.6.0-alpha.3",
26
- "@webiny/handler": "6.6.0-alpha.3",
27
- "@webiny/utils": "6.6.0-alpha.3",
28
- "@webiny/wcp": "6.6.0-alpha.3",
22
+ "@webiny/error": "6.6.0-alpha.4",
23
+ "@webiny/event-handler-core": "6.6.0-alpha.4",
24
+ "@webiny/feature": "6.6.0-alpha.4",
25
+ "@webiny/feature-flags": "6.6.0-alpha.4",
26
+ "@webiny/handler": "6.6.0-alpha.4",
27
+ "@webiny/utils": "6.6.0-alpha.4",
28
+ "@webiny/wcp": "6.6.0-alpha.4",
29
29
  "ai": "7.0.73",
30
30
  "dataloader": "2.2.3",
31
31
  "graphql": "16.14.2",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/jsonwebtoken": "9.0.10",
43
- "@webiny/build-tools": "6.6.0-alpha.3",
43
+ "@webiny/build-tools": "6.6.0-alpha.4",
44
44
  "rimraf": "6.1.3",
45
45
  "typescript": "7.0.2",
46
46
  "vitest": "4.1.11"