@tailor-platform/sdk 1.4.2 → 1.5.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.
- package/CHANGELOG.md +34 -0
- package/dist/auth-CZPUwA1p.mjs +801 -0
- package/dist/auth-CZPUwA1p.mjs.map +1 -0
- package/dist/cli/index.mjs +3 -2
- package/dist/cli/index.mjs.map +1 -1
- package/dist/cli/lib.d.mts +7 -8
- package/dist/cli/lib.mjs +3 -2
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/configure/index.d.mts +3 -3
- package/dist/configure/index.mjs +29 -5
- package/dist/configure/index.mjs.map +1 -1
- package/dist/{types-BWzDv7TK.d.mts → index-D40SiXpf.d.mts} +897 -865
- package/dist/{index-lDsl6VDv.d.mts → index-bRPODqag.d.mts} +45 -3
- package/dist/{jiti-31_Wx1yz.mjs → jiti-BUw4tcVQ.mjs} +1 -1
- package/dist/{jiti-31_Wx1yz.mjs.map → jiti-BUw4tcVQ.mjs.map} +1 -1
- package/dist/job-CX4l7Myn.mjs +28 -0
- package/dist/job-CX4l7Myn.mjs.map +1 -0
- package/dist/{list-QT92XcP3.mjs → list-Dr8070QZ.mjs} +1567 -1562
- package/dist/list-Dr8070QZ.mjs.map +1 -0
- package/dist/{src-Bhwd-tei.mjs → src-Bu0051gO.mjs} +1 -1
- package/dist/{src-Bhwd-tei.mjs.map → src-Bu0051gO.mjs.map} +1 -1
- package/dist/utils/test/index.d.mts +4 -3
- package/dist/utils/test/index.mjs +3 -1
- package/dist/utils/test/index.mjs.map +1 -1
- package/docs/services/auth.md +35 -1
- package/docs/testing.md +81 -0
- package/package.json +1 -1
- package/dist/config-CBpYlVa-.mjs +0 -664
- package/dist/config-CBpYlVa-.mjs.map +0 -1
- package/dist/list-QT92XcP3.mjs.map +0 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/configure/services/workflow/job.ts
|
|
2
|
+
/**
|
|
3
|
+
* Symbol used to brand WorkflowJob objects created by createWorkflowJob.
|
|
4
|
+
* This enables reliable runtime detection of workflow jobs regardless of
|
|
5
|
+
* how they were imported or assigned (variable reassignment, destructuring, etc.)
|
|
6
|
+
*/
|
|
7
|
+
const WORKFLOW_JOB_BRAND = Symbol.for("tailor:workflow-job");
|
|
8
|
+
/**
|
|
9
|
+
* Environment variable key for workflow testing.
|
|
10
|
+
* Contains JSON-serialized TailorEnv object.
|
|
11
|
+
*/
|
|
12
|
+
const WORKFLOW_TEST_ENV_KEY = "TAILOR_TEST_WORKFLOW_ENV";
|
|
13
|
+
const createWorkflowJob = (config) => {
|
|
14
|
+
return {
|
|
15
|
+
[WORKFLOW_JOB_BRAND]: true,
|
|
16
|
+
name: config.name,
|
|
17
|
+
trigger: async (args) => {
|
|
18
|
+
const env = JSON.parse(process.env[WORKFLOW_TEST_ENV_KEY] || "{}");
|
|
19
|
+
const result = await config.body(args, { env });
|
|
20
|
+
return result ? JSON.parse(JSON.stringify(result)) : result;
|
|
21
|
+
},
|
|
22
|
+
body: config.body
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { WORKFLOW_TEST_ENV_KEY as n, createWorkflowJob as r, WORKFLOW_JOB_BRAND as t };
|
|
28
|
+
//# sourceMappingURL=job-CX4l7Myn.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-CX4l7Myn.mjs","names":[],"sources":["../src/configure/services/workflow/job.ts"],"sourcesContent":["import type { TailorEnv } from \"@/configure/types/env\";\nimport type { JsonCompatible } from \"@/configure/types/helpers\";\nimport type { Jsonifiable, Jsonify, JsonPrimitive } from \"type-fest\";\n\n/**\n * Symbol used to brand WorkflowJob objects created by createWorkflowJob.\n * This enables reliable runtime detection of workflow jobs regardless of\n * how they were imported or assigned (variable reassignment, destructuring, etc.)\n */\nexport const WORKFLOW_JOB_BRAND = Symbol.for(\"tailor:workflow-job\");\n\n/**\n * Context object passed as the second argument to workflow job body functions.\n */\nexport type WorkflowJobContext = {\n env: TailorEnv;\n};\n\n/**\n * Allowed output types for workflow job body functions.\n * Includes Jsonifiable (JSON-serializable values including objects with toJSON like Date),\n * undefined, and void.\n */\nexport type WorkflowJobOutput = Jsonifiable | undefined | void;\n\n/**\n * Convert output type to what trigger returns after JSON serialization.\n * - Jsonifiable values are converted via Jsonify (Date -> string, etc.)\n * - undefined remains undefined\n * - void becomes void\n */\ntype JsonifyOutput<T> = T extends Jsonifiable ? Jsonify<T> : T;\n\n/**\n * Input type constraint for workflow jobs.\n * Accepts any type that is JSON-compatible (primitives, arrays, objects with JSON-compatible values).\n * Excludes objects with toJSON method (like Date) since they won't be serialized in input.\n */\nexport type WorkflowJobInput = undefined | JsonCompatible<unknown>;\n\n/**\n * WorkflowJob represents a job that can be triggered in a workflow.\n *\n * Type constraints:\n * - Input: Must be JSON-compatible (no Date/toJSON objects) or undefined. Interfaces are allowed.\n * - Output: Must be Jsonifiable, undefined, or void\n * - Trigger returns Jsonify<Output> (Date becomes string after JSON.stringify)\n */\nexport interface WorkflowJob<Name extends string = string, Input = undefined, Output = undefined> {\n readonly [WORKFLOW_JOB_BRAND]?: true;\n name: Name;\n /**\n * Trigger this job with the given input.\n * At runtime, this is a placeholder that calls the body function.\n * During bundling, calls to .trigger() are transformed to\n * tailor.workflow.triggerJobFunction(\"<job-name>\", args).\n *\n * Returns Jsonify<Output> because the value passes through JSON.stringify.\n */\n trigger: [Input] extends [undefined]\n ? () => Promise<JsonifyOutput<Awaited<Output>>>\n : (input: Input) => Promise<JsonifyOutput<Awaited<Output>>>;\n body: (input: Input, context: WorkflowJobContext) => Output | Promise<Output>;\n}\n\n/**\n * Helper type to check if all property types are valid.\n * Uses -? to remove optional modifiers so all properties are treated uniformly.\n */\ntype AllPropertiesValid<T> = {\n [K in keyof T]-?: IsValidInput<T[K]> extends true ? true : false;\n}[keyof T] extends true\n ? true\n : false;\n\n/**\n * Check if a type contains any non-JSON-compatible values.\n * Returns `true` if the type is valid for input, `false` otherwise.\n *\n * Accepts:\n * - JSON primitives (string, number, boolean, null)\n * - undefined\n * - Optional primitives (e.g., string | undefined)\n * - Arrays of valid types\n * - Objects with valid field types\n *\n * Rejects:\n * - Objects with toJSON methods (like Date)\n * - Other non-JSON-serializable types\n */\ntype IsValidInput<T> = T extends undefined\n ? true\n : T extends JsonPrimitive\n ? true\n : T extends readonly (infer U)[]\n ? IsValidInput<U>\n : T extends object\n ? T extends { toJSON: () => unknown }\n ? false\n : AllPropertiesValid<T>\n : false;\n\n/**\n * Helper type to check if all property types are valid for output.\n * Uses -? to remove optional modifiers so all properties are treated uniformly.\n */\ntype AllPropertiesValidOutput<T> = {\n [K in keyof T]-?: IsValidOutput<T[K]> extends true ? true : false;\n}[keyof T] extends true\n ? true\n : false;\n\n/**\n * Check if a type is valid for output.\n * Returns `true` if the type is valid, `false` otherwise.\n *\n * Accepts:\n * - JSON primitives (string, number, boolean, null)\n * - undefined and void\n * - Optional primitives (e.g., string | undefined)\n * - Jsonifiable types (Date, objects with toJSON)\n * - Arrays of valid types\n * - Objects with valid field types\n */\ntype IsValidOutput<T> = T extends undefined | void\n ? true\n : T extends JsonPrimitive\n ? true\n : T extends readonly (infer U)[]\n ? IsValidOutput<U>\n : T extends object\n ? AllPropertiesValidOutput<T>\n : false;\n\n/**\n * Body function type with conditional constraint.\n * If input contains invalid types (like Date), the body type becomes `never` to cause an error.\n */\ntype WorkflowJobBody<I, O> =\n IsValidInput<I> extends true\n ? IsValidOutput<O> extends true\n ? (input: I, context: WorkflowJobContext) => O | Promise<O>\n : never\n : never;\n\n/**\n * Environment variable key for workflow testing.\n * Contains JSON-serialized TailorEnv object.\n */\nexport const WORKFLOW_TEST_ENV_KEY = \"TAILOR_TEST_WORKFLOW_ENV\";\n\nexport const createWorkflowJob = <const Name extends string, I = undefined, O = undefined>(config: {\n readonly name: Name;\n readonly body: WorkflowJobBody<I, O>;\n}): WorkflowJob<Name, I, Awaited<O>> => {\n return {\n [WORKFLOW_JOB_BRAND]: true,\n name: config.name,\n // JSON.parse(JSON.stringify(...)) ensures the return value matches Jsonify<Output> type.\n // This converts Date objects to strings, matching actual runtime behavior.\n // In production, bundler transforms .trigger() calls to tailor.workflow.triggerJobFunction().\n trigger: async (args?: unknown) => {\n const env: TailorEnv = JSON.parse(process.env[WORKFLOW_TEST_ENV_KEY] || \"{}\");\n const result = await config.body(args as I, { env });\n return result ? JSON.parse(JSON.stringify(result)) : result;\n },\n body: config.body,\n } as WorkflowJob<Name, I, Awaited<O>>;\n};\n"],"mappings":";;;;;;AASA,MAAa,qBAAqB,OAAO,IAAI,sBAAsB;;;;;AA4InE,MAAa,wBAAwB;AAErC,MAAa,qBAA8E,WAGnD;AACtC,QAAO;GACJ,qBAAqB;EACtB,MAAM,OAAO;EAIb,SAAS,OAAO,SAAmB;GACjC,MAAM,MAAiB,KAAK,MAAM,QAAQ,IAAI,0BAA0B,KAAK;GAC7E,MAAM,SAAS,MAAM,OAAO,KAAK,MAAW,EAAE,KAAK,CAAC;AACpD,UAAO,SAAS,KAAK,MAAM,KAAK,UAAU,OAAO,CAAC,GAAG;;EAEvD,MAAM,OAAO;EACd"}
|