@tailor-platform/sdk 1.74.1 → 1.75.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 (52) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/application-BJKNlv8c.mjs +3 -0
  3. package/dist/{application-BsH6tkZC.mjs → application-DYshsH-K.mjs} +20 -8
  4. package/dist/application-DYshsH-K.mjs.map +1 -0
  5. package/dist/brand-Eo4pLXPJ.mjs.map +1 -1
  6. package/dist/cli/commands/deploy/workflow-execution-policy.d.mts +1 -0
  7. package/dist/cli/index.mjs +4 -4
  8. package/dist/cli/lib.mjs +2 -2
  9. package/dist/completion/zsh-worker.zsh +9 -9
  10. package/dist/configure/config/types.d.mts +3 -1
  11. package/dist/configure/index.d.mts +3 -1
  12. package/dist/configure/index.mjs +111 -3
  13. package/dist/configure/index.mjs.map +1 -1
  14. package/dist/configure/services/index.d.mts +3 -1
  15. package/dist/configure/services/workflow/execution-policy.d.mts +71 -0
  16. package/dist/configure/services/workflow/execution-policy.types.d.mts +104 -0
  17. package/dist/configure/services/workflow/index.d.mts +3 -1
  18. package/dist/configure/services/workflow/job.d.mts +7 -3
  19. package/dist/{globals-B8XX5TRB.mjs → globals-CcU1ONiK.mjs} +2 -2
  20. package/dist/globals-CcU1ONiK.mjs.map +1 -0
  21. package/dist/{job-CtU73PGa.mjs → job-D-PbD1P3.mjs} +5 -3
  22. package/dist/job-D-PbD1P3.mjs.map +1 -0
  23. package/dist/{registry-BozuxbPp.mjs → registry-NfSW0BRo.mjs} +4 -3
  24. package/dist/registry-NfSW0BRo.mjs.map +1 -0
  25. package/dist/runtime/globals.d.mts +1 -1
  26. package/dist/runtime/index.d.mts +1 -1
  27. package/dist/runtime/workflow.d.mts +22 -3
  28. package/dist/{runtime-DV1EnfMs.mjs → runtime-CJ5usBOu.mjs} +230 -6
  29. package/dist/runtime-CJ5usBOu.mjs.map +1 -0
  30. package/dist/{service_pb-CIrhGwHk.mjs → service_pb-4unFyubn.mjs} +16 -6
  31. package/dist/{service_pb-CIrhGwHk.mjs.map → service_pb-4unFyubn.mjs.map} +1 -1
  32. package/dist/{service_pb-DjwIn4jO.mjs → service_pb-D-PXRoMg.mjs} +1 -1
  33. package/dist/tailor-proto/src/tailor/v1/service_pb.d.mts +1 -1
  34. package/dist/tailor-proto/src/tailor/v1/workflow_pb.d.mts +29 -9
  35. package/dist/tailor-proto/src/tailor/v1/workflow_resource_pb.d.mts +35 -1
  36. package/dist/utils/test/index.mjs +1 -1
  37. package/dist/utils/test/index.mjs.map +1 -1
  38. package/dist/vitest/environment.mjs +1 -1
  39. package/dist/vitest/index.mjs +15 -12
  40. package/dist/vitest/index.mjs.map +1 -1
  41. package/dist/vitest/mocks/workflow.d.mts +5 -3
  42. package/dist/vitest/setup.mjs +1 -1
  43. package/dist/workflow-DSwnYPPP.mjs.map +1 -1
  44. package/docs/configuration.md +24 -0
  45. package/docs/services/workflow.md +78 -0
  46. package/package.json +1 -1
  47. package/dist/application-BsH6tkZC.mjs.map +0 -1
  48. package/dist/application-CSUhZMb5.mjs +0 -3
  49. package/dist/globals-B8XX5TRB.mjs.map +0 -1
  50. package/dist/job-CtU73PGa.mjs.map +0 -1
  51. package/dist/registry-BozuxbPp.mjs.map +0 -1
  52. package/dist/runtime-DV1EnfMs.mjs.map +0 -1
@@ -351,6 +351,84 @@ export default createWorkflow({
351
351
  });
352
352
  ```
353
353
 
354
+ ## Execution Policies
355
+
356
+ Execution policies apply a per-key concurrency cap to workflow job function dispatches. Declare them at the workspace level and pass a matching key when triggering a job; the platform serializes dispatches that resolve to the same key and suspends any that would exceed the cap until slots free up.
357
+
358
+ ### Declaring Policies
359
+
360
+ Use `defineWorkflowExecutionPolicies` with a builder callback. Property names supply the workspace-unique name and default key prefix verbatim, matching the mental model of `defineWaitPoints`. Override `name` or `key` in the body when the property identifier is not valid execution policy grammar or the key prefix needs to differ. Set `matchType: "prefix"` to register the prefix as a wildcard that matches every dispatch key starting with it (the default, `"exact"`, matches only a dispatch key equal to it).
361
+
362
+ ```typescript
363
+ import { defineWorkflowExecutionPolicies } from "@tailor-platform/sdk";
364
+
365
+ export const executionPolicies = defineWorkflowExecutionPolicies((define) => ({
366
+ /** Shared cap across every "premium" worker dispatch. */
367
+ premium: define({ concurrencyPolicy: { maxConcurrentExecutions: 5 } }),
368
+ /** Per-tenant cap: one pool per resolved tenant key. */
369
+ tenantApi: define({
370
+ name: "tenant-api",
371
+ matchType: "prefix",
372
+ concurrencyPolicy: { maxConcurrentExecutions: 3 },
373
+ }),
374
+ }));
375
+ ```
376
+
377
+ For a single policy, use `defineWorkflowExecutionPolicy(name, def?)`; the key prefix defaults to `name` when `key` is omitted.
378
+
379
+ `concurrencyPolicy` is optional; when omitted, the policy registers the key as valid without a user-defined limit (platform safety nets still apply).
380
+
381
+ Register the policies on your config so the SDK creates them on the workspace during deploy:
382
+
383
+ ```typescript
384
+ // tailor.config.ts
385
+ import { defineConfig } from "@tailor-platform/sdk";
386
+ import { executionPolicies } from "./workflows/policies";
387
+
388
+ export default defineConfig({
389
+ workflow: {
390
+ files: ["workflows/**/*.ts"],
391
+ executionPolicies,
392
+ },
393
+ });
394
+ ```
395
+
396
+ ### Key Grammar
397
+
398
+ `key` accepts `[a-z0-9_:.-]` and must start with `[a-z0-9]`. An exact key must also end with `[a-z0-9]`; a wildcard prefix (`matchType: "prefix"`) may end with any of those characters, since the platform appends a trailing `*` after it. The platform-registered key — including that trailing `*` when wildcarded — is 2 to 64 characters long, so a wildcard prefix must be at most 63 characters. `foo:bar` is a valid exact key; `tenant-api` with `matchType: "prefix"` registers `tenant-api*` as a wildcard prefix.
399
+
400
+ An exact-key policy applies to dispatches whose runtime key equals the policy key. A wildcard policy applies to every dispatch whose runtime key begins with the prefix; each concrete resolved key gets its own independent pool of the declared size (a `cap = 3` wildcard yields three concurrent dispatches per resolved key, not three across every match). The longest matching prefix wins when a dispatch could match more than one wildcard.
401
+
402
+ ### Referencing a Policy from a Workflow
403
+
404
+ Pass the runtime key through the `executionPolicyKey` option on `job.trigger()` or `tailor.workflow.triggerJobFunction()`. For exact-key policies, use `<policy>.key` directly — it's typed so only a value that came from a declared policy can be passed. For wildcard policies (`matchType: "prefix"`), there is no `<policy>.key` — call `<policy>.keyFor(suffix)` to build the concrete key. `keyFor` joins the prefix and suffix with `.` by default; override it with `separator` — the second argument to `defineWorkflowExecutionPolicies` (applies to every policy in the group), or a `def` field on a single `defineWorkflowExecutionPolicy`.
405
+
406
+ ```typescript
407
+ import { createWorkflowJob } from "@tailor-platform/sdk";
408
+ import { executionPolicies } from "./policies";
409
+ import { sendNotification } from "./jobs/send-notification";
410
+ import { fetchTenant } from "./jobs/fetch-tenant";
411
+
412
+ export const mainJob = createWorkflowJob({
413
+ name: "main-job",
414
+ body: async (input: { tenantId: string }) => {
415
+ // Exact key policy: pass .key directly.
416
+ await sendNotification.trigger(
417
+ { message: "Order processed" },
418
+ { executionPolicyKey: executionPolicies.premium.key },
419
+ );
420
+
421
+ // Wildcard policy: build the concrete key with keyFor().
422
+ await fetchTenant.trigger(
423
+ { tenantId: input.tenantId },
424
+ { executionPolicyKey: executionPolicies.tenantApi.keyFor(input.tenantId) },
425
+ );
426
+ },
427
+ });
428
+ ```
429
+
430
+ The same `executionPolicyKey` option is available on `tailor.workflow.triggerJobFunction(name, args, options)` for jobs invoked by name.
431
+
354
432
  ## Triggering a Workflow from a Resolver
355
433
 
356
434
  You can start a workflow execution from a resolver using `workflow.trigger()`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tailor-platform/sdk",
3
- "version": "1.74.1",
3
+ "version": "1.75.0",
4
4
  "description": "Tailor Platform SDK - The SDK to work with Tailor Platform",
5
5
  "license": "MIT",
6
6
  "repository": {