@tailor-platform/create-sdk 1.17.0 → 1.18.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 +8 -0
- package/package.json +1 -1
- package/templates/hello-world/package.json +1 -5
- package/templates/hello-world/tailor.config.ts +5 -5
- package/templates/inventory-management/package.json +1 -5
- package/templates/inventory-management/tailor.config.ts +5 -5
- package/templates/multi-application/package.json +1 -1
- package/templates/testing/package.json +1 -5
- package/templates/testing/src/resolver/wrapTailordb.ts +1 -1
- package/templates/testing/src/workflow/simple.test.ts +56 -5
- package/templates/testing/src/workflow/simple.ts +7 -0
- package/templates/testing/src/workflow/trigger.test.ts +44 -7
- package/templates/testing/src/workflow/wrapTailordb.ts +1 -1
- package/templates/testing/tailor.config.ts +3 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @tailor-platform/create-sdk
|
|
2
2
|
|
|
3
|
+
## 1.18.0
|
|
4
|
+
|
|
5
|
+
## 1.17.1
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- [#627](https://github.com/tailor-platform/sdk/pull/627) [`b75a0cd`](https://github.com/tailor-platform/sdk/commit/b75a0cd124a707befaaf77b5da0dafe8835b7263) Thanks [@toiroakr](https://github.com/toiroakr)! - Remove redundant kysely and @tailor-platform/function-kysely-tailordb dependencies from create-sdk templates, as these are already provided through @tailor-platform/sdk
|
|
10
|
+
|
|
3
11
|
## 1.17.0
|
|
4
12
|
|
|
5
13
|
## 1.16.0
|
package/package.json
CHANGED
|
@@ -11,13 +11,9 @@
|
|
|
11
11
|
"lint:fix": "oxlint --type-aware --fix . && eslint --cache --fix .",
|
|
12
12
|
"typecheck": "tsc --noEmit"
|
|
13
13
|
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"@tailor-platform/function-kysely-tailordb": "0.1.3",
|
|
16
|
-
"kysely": "0.28.10"
|
|
17
|
-
},
|
|
18
14
|
"devDependencies": {
|
|
19
15
|
"@eslint/js": "9.39.2",
|
|
20
|
-
"@tailor-platform/sdk": "1.
|
|
16
|
+
"@tailor-platform/sdk": "1.18.0",
|
|
21
17
|
"@types/node": "24.10.9",
|
|
22
18
|
"eslint": "9.39.2",
|
|
23
19
|
"eslint-plugin-oxlint": "1.39.0",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { defineConfig,
|
|
1
|
+
import { defineConfig, definePlugins } from "@tailor-platform/sdk";
|
|
2
|
+
import { kyselyTypePlugin } from "@tailor-platform/sdk/plugin/kysely-type";
|
|
2
3
|
|
|
3
4
|
export default defineConfig({
|
|
4
5
|
name: "hello-world",
|
|
@@ -6,7 +7,6 @@ export default defineConfig({
|
|
|
6
7
|
resolver: { "main-resolver": { files: [`./src/resolvers/**/*.ts`] } },
|
|
7
8
|
});
|
|
8
9
|
|
|
9
|
-
export const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
]);
|
|
10
|
+
export const plugins = definePlugins(
|
|
11
|
+
kyselyTypePlugin({ distPath: `./src/generated/kysely-tailordb.ts` }),
|
|
12
|
+
);
|
|
@@ -11,14 +11,10 @@
|
|
|
11
11
|
"lint:fix": "oxlint --type-aware --fix . && eslint --cache --fix .",
|
|
12
12
|
"typecheck": "tsc --noEmit"
|
|
13
13
|
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"@tailor-platform/function-kysely-tailordb": "0.1.3",
|
|
16
|
-
"kysely": "0.28.10"
|
|
17
|
-
},
|
|
18
14
|
"devDependencies": {
|
|
19
15
|
"@eslint/js": "9.39.2",
|
|
20
16
|
"@tailor-platform/function-types": "0.8.0",
|
|
21
|
-
"@tailor-platform/sdk": "1.
|
|
17
|
+
"@tailor-platform/sdk": "1.18.0",
|
|
22
18
|
"@types/node": "24.10.9",
|
|
23
19
|
"eslint": "9.39.2",
|
|
24
20
|
"eslint-plugin-oxlint": "1.39.0",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { defineAuth, defineConfig,
|
|
1
|
+
import { defineAuth, defineConfig, definePlugins } from "@tailor-platform/sdk";
|
|
2
|
+
import { kyselyTypePlugin } from "@tailor-platform/sdk/plugin/kysely-type";
|
|
2
3
|
import { user } from "./src/db/user";
|
|
3
4
|
|
|
4
5
|
export default defineConfig({
|
|
@@ -25,7 +26,6 @@ export default defineConfig({
|
|
|
25
26
|
executor: { files: ["./src/executor/*.ts"] },
|
|
26
27
|
});
|
|
27
28
|
|
|
28
|
-
export const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
]);
|
|
29
|
+
export const plugins = definePlugins(
|
|
30
|
+
kyselyTypePlugin({ distPath: `./src/generated/kysely-tailordb.ts` }),
|
|
31
|
+
);
|
|
@@ -14,14 +14,10 @@
|
|
|
14
14
|
"lint:fix": "oxlint --type-aware --fix . && eslint --cache --fix .",
|
|
15
15
|
"typecheck": "tsc --noEmit"
|
|
16
16
|
},
|
|
17
|
-
"dependencies": {
|
|
18
|
-
"@tailor-platform/function-kysely-tailordb": "0.1.3",
|
|
19
|
-
"kysely": "0.28.10"
|
|
20
|
-
},
|
|
21
17
|
"devDependencies": {
|
|
22
18
|
"@eslint/js": "9.39.2",
|
|
23
19
|
"@tailor-platform/function-types": "0.8.0",
|
|
24
|
-
"@tailor-platform/sdk": "1.
|
|
20
|
+
"@tailor-platform/sdk": "1.18.0",
|
|
25
21
|
"@types/node": "24.10.9",
|
|
26
22
|
"eslint": "9.39.2",
|
|
27
23
|
"eslint-plugin-oxlint": "1.39.0",
|
|
@@ -1,22 +1,41 @@
|
|
|
1
|
+
import { unauthenticatedTailorUser } from "@tailor-platform/sdk/test";
|
|
1
2
|
import { describe, expect, test, vi } from "vitest";
|
|
2
|
-
import { addNumbers, multiplyNumbers, calculate } from "./simple";
|
|
3
|
+
import { addNumbers, multiplyNumbers, calculate, getUserInfo } from "./simple";
|
|
3
4
|
|
|
4
5
|
describe("workflow jobs", () => {
|
|
5
6
|
describe("addNumbers job", () => {
|
|
6
7
|
test("adds two numbers", () => {
|
|
7
|
-
const result = addNumbers.body(
|
|
8
|
+
const result = addNumbers.body(
|
|
9
|
+
{ a: 2, b: 3 },
|
|
10
|
+
{
|
|
11
|
+
env: {},
|
|
12
|
+
user: unauthenticatedTailorUser,
|
|
13
|
+
},
|
|
14
|
+
);
|
|
8
15
|
expect(result).toBe(5);
|
|
9
16
|
});
|
|
10
17
|
|
|
11
18
|
test("handles negative numbers", () => {
|
|
12
|
-
const result = addNumbers.body(
|
|
19
|
+
const result = addNumbers.body(
|
|
20
|
+
{ a: -5, b: 3 },
|
|
21
|
+
{
|
|
22
|
+
env: {},
|
|
23
|
+
user: unauthenticatedTailorUser,
|
|
24
|
+
},
|
|
25
|
+
);
|
|
13
26
|
expect(result).toBe(-2);
|
|
14
27
|
});
|
|
15
28
|
});
|
|
16
29
|
|
|
17
30
|
describe("multiplyNumbers job", () => {
|
|
18
31
|
test("multiplies two numbers", () => {
|
|
19
|
-
const result = multiplyNumbers.body(
|
|
32
|
+
const result = multiplyNumbers.body(
|
|
33
|
+
{ x: 4, y: 5 },
|
|
34
|
+
{
|
|
35
|
+
env: {},
|
|
36
|
+
user: unauthenticatedTailorUser,
|
|
37
|
+
},
|
|
38
|
+
);
|
|
20
39
|
expect(result).toBe(20);
|
|
21
40
|
});
|
|
22
41
|
});
|
|
@@ -27,11 +46,43 @@ describe("workflow jobs", () => {
|
|
|
27
46
|
vi.spyOn(addNumbers, "trigger").mockResolvedValue(5); // 2 + 3 = 5
|
|
28
47
|
vi.spyOn(multiplyNumbers, "trigger").mockResolvedValue(10); // 5 * 2 = 10
|
|
29
48
|
|
|
30
|
-
const result = await calculate.body(
|
|
49
|
+
const result = await calculate.body(
|
|
50
|
+
{ a: 2, b: 3 },
|
|
51
|
+
{
|
|
52
|
+
env: {},
|
|
53
|
+
user: unauthenticatedTailorUser,
|
|
54
|
+
},
|
|
55
|
+
);
|
|
31
56
|
|
|
32
57
|
expect(addNumbers.trigger).toHaveBeenCalledWith({ a: 2, b: 3 });
|
|
33
58
|
expect(multiplyNumbers.trigger).toHaveBeenCalledWith({ x: 5, y: 2 });
|
|
34
59
|
expect(result).toBe(10);
|
|
35
60
|
});
|
|
36
61
|
});
|
|
62
|
+
|
|
63
|
+
describe("getUserInfo job", () => {
|
|
64
|
+
test("returns user info from context", () => {
|
|
65
|
+
const result = getUserInfo.body(undefined, {
|
|
66
|
+
env: {},
|
|
67
|
+
user: unauthenticatedTailorUser,
|
|
68
|
+
});
|
|
69
|
+
expect(result).toEqual({
|
|
70
|
+
userId: unauthenticatedTailorUser.id,
|
|
71
|
+
workspaceId: unauthenticatedTailorUser.workspaceId,
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("returns custom user info", () => {
|
|
76
|
+
const customUser = {
|
|
77
|
+
...unauthenticatedTailorUser,
|
|
78
|
+
id: "user-123",
|
|
79
|
+
workspaceId: "ws-456",
|
|
80
|
+
};
|
|
81
|
+
const result = getUserInfo.body(undefined, {
|
|
82
|
+
env: {},
|
|
83
|
+
user: customUser,
|
|
84
|
+
});
|
|
85
|
+
expect(result).toEqual({ userId: "user-123", workspaceId: "ws-456" });
|
|
86
|
+
});
|
|
87
|
+
});
|
|
37
88
|
});
|
|
@@ -23,6 +23,13 @@ export const calculate = createWorkflowJob({
|
|
|
23
23
|
},
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
+
export const getUserInfo = createWorkflowJob({
|
|
27
|
+
name: "get-user-info",
|
|
28
|
+
body: (_input: undefined, { user }) => {
|
|
29
|
+
return { userId: user.id, workspaceId: user.workspaceId };
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
26
33
|
export default createWorkflow({
|
|
27
34
|
name: "simple-calculation",
|
|
28
35
|
mainJob: calculate,
|
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
* This test file demonstrates how to test workflows using the .trigger() method.
|
|
3
3
|
*
|
|
4
4
|
* Key features:
|
|
5
|
-
* - Use vi.stubEnv() with WORKFLOW_TEST_ENV_KEY to set environment variables
|
|
5
|
+
* - Use vi.stubEnv() with WORKFLOW_TEST_ENV_KEY / WORKFLOW_TEST_USER_KEY to set environment variables
|
|
6
6
|
* - Use vi.spyOn() to mock dependent jobs
|
|
7
7
|
* - Call .trigger() on jobs/workflows directly
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
WORKFLOW_TEST_ENV_KEY,
|
|
11
|
+
WORKFLOW_TEST_USER_KEY,
|
|
12
|
+
unauthenticatedTailorUser,
|
|
13
|
+
} from "@tailor-platform/sdk/test";
|
|
10
14
|
import { afterEach, describe, expect, test, vi } from "vitest";
|
|
11
|
-
import workflow, { addNumbers, calculate, multiplyNumbers } from "./simple";
|
|
15
|
+
import workflow, { addNumbers, calculate, getUserInfo, multiplyNumbers } from "./simple";
|
|
12
16
|
|
|
13
17
|
describe("workflow trigger tests", () => {
|
|
14
18
|
afterEach(() => {
|
|
@@ -18,12 +22,24 @@ describe("workflow trigger tests", () => {
|
|
|
18
22
|
|
|
19
23
|
describe("unit tests with .body()", () => {
|
|
20
24
|
test("addNumbers.body() adds two numbers", () => {
|
|
21
|
-
const result = addNumbers.body(
|
|
25
|
+
const result = addNumbers.body(
|
|
26
|
+
{ a: 2, b: 3 },
|
|
27
|
+
{
|
|
28
|
+
env: {},
|
|
29
|
+
user: unauthenticatedTailorUser,
|
|
30
|
+
},
|
|
31
|
+
);
|
|
22
32
|
expect(result).toBe(5);
|
|
23
33
|
});
|
|
24
34
|
|
|
25
35
|
test("multiplyNumbers.body() multiplies two numbers", () => {
|
|
26
|
-
const result = multiplyNumbers.body(
|
|
36
|
+
const result = multiplyNumbers.body(
|
|
37
|
+
{ x: 4, y: 5 },
|
|
38
|
+
{
|
|
39
|
+
env: {},
|
|
40
|
+
user: unauthenticatedTailorUser,
|
|
41
|
+
},
|
|
42
|
+
);
|
|
27
43
|
expect(result).toBe(20);
|
|
28
44
|
});
|
|
29
45
|
|
|
@@ -32,7 +48,13 @@ describe("workflow trigger tests", () => {
|
|
|
32
48
|
vi.spyOn(addNumbers, "trigger").mockResolvedValue(5);
|
|
33
49
|
vi.spyOn(multiplyNumbers, "trigger").mockResolvedValue(10);
|
|
34
50
|
|
|
35
|
-
const result = await calculate.body(
|
|
51
|
+
const result = await calculate.body(
|
|
52
|
+
{ a: 2, b: 3 },
|
|
53
|
+
{
|
|
54
|
+
env: {},
|
|
55
|
+
user: unauthenticatedTailorUser,
|
|
56
|
+
},
|
|
57
|
+
);
|
|
36
58
|
|
|
37
59
|
expect(addNumbers.trigger).toHaveBeenCalledWith({ a: 2, b: 3 });
|
|
38
60
|
expect(multiplyNumbers.trigger).toHaveBeenCalledWith({ x: 5, y: 2 });
|
|
@@ -46,7 +68,13 @@ describe("workflow trigger tests", () => {
|
|
|
46
68
|
vi.spyOn(addNumbers, "trigger").mockResolvedValue(7);
|
|
47
69
|
vi.spyOn(multiplyNumbers, "trigger").mockResolvedValue(21);
|
|
48
70
|
|
|
49
|
-
const result = await workflow.mainJob.body(
|
|
71
|
+
const result = await workflow.mainJob.body(
|
|
72
|
+
{ a: 3, b: 4 },
|
|
73
|
+
{
|
|
74
|
+
env: {},
|
|
75
|
+
user: unauthenticatedTailorUser,
|
|
76
|
+
},
|
|
77
|
+
);
|
|
50
78
|
|
|
51
79
|
expect(addNumbers.trigger).toHaveBeenCalledWith({ a: 3, b: 4 });
|
|
52
80
|
expect(multiplyNumbers.trigger).toHaveBeenCalledWith({ x: 7, y: 3 });
|
|
@@ -63,5 +91,14 @@ describe("workflow trigger tests", () => {
|
|
|
63
91
|
// (3 + 4) * 3 = 21
|
|
64
92
|
expect(result).toBe(21);
|
|
65
93
|
});
|
|
94
|
+
|
|
95
|
+
test("getUserInfo.trigger() uses mocked user", async () => {
|
|
96
|
+
// stubEnv with WORKFLOW_TEST_USER_KEY to inject a custom user into .trigger() calls
|
|
97
|
+
const customUser = { ...unauthenticatedTailorUser, id: "user-abc", workspaceId: "ws-xyz" };
|
|
98
|
+
vi.stubEnv(WORKFLOW_TEST_USER_KEY, JSON.stringify(customUser));
|
|
99
|
+
|
|
100
|
+
const result = await getUserInfo.trigger();
|
|
101
|
+
expect(result).toEqual({ userId: "user-abc", workspaceId: "ws-xyz" });
|
|
102
|
+
});
|
|
66
103
|
});
|
|
67
104
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createWorkflowJob, createWorkflow } from "@tailor-platform/sdk";
|
|
2
|
-
import type { Selectable } from "kysely";
|
|
2
|
+
import type { Selectable } from "@tailor-platform/sdk/kysely";
|
|
3
3
|
import { getDB, type DB, type Namespace } from "../generated/db";
|
|
4
4
|
|
|
5
5
|
type User = Selectable<Namespace["main-db"]["User"]>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { defineAuth, defineConfig,
|
|
1
|
+
import { defineAuth, defineConfig, definePlugins, t } from "@tailor-platform/sdk";
|
|
2
|
+
import { kyselyTypePlugin } from "@tailor-platform/sdk/plugin/kysely-type";
|
|
2
3
|
|
|
3
4
|
export default defineConfig({
|
|
4
5
|
name: "testing",
|
|
@@ -19,7 +20,4 @@ export default defineConfig({
|
|
|
19
20
|
workflow: { files: ["./src/workflow/*.ts"] },
|
|
20
21
|
});
|
|
21
22
|
|
|
22
|
-
export const
|
|
23
|
-
"@tailor-platform/kysely-type",
|
|
24
|
-
{ distPath: "./src/generated/db.ts" },
|
|
25
|
-
]);
|
|
23
|
+
export const plugins = definePlugins(kyselyTypePlugin({ distPath: "./src/generated/db.ts" }));
|