@trigger.dev/sdk 0.0.0-prerelease-20241003205750 → 0.0.0-prerelease-20241119135607
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/README.md +32 -1
- package/dist/commonjs/triggers/invokeTrigger.d.ts +1 -1
- package/dist/commonjs/types.d.ts +4 -4
- package/dist/commonjs/v3/auth.d.ts +104 -0
- package/dist/commonjs/v3/auth.js +102 -0
- package/dist/commonjs/v3/auth.js.map +1 -0
- package/dist/commonjs/v3/idempotencyKeys.d.ts +2 -46
- package/dist/commonjs/v3/idempotencyKeys.js +1 -69
- package/dist/commonjs/v3/idempotencyKeys.js.map +1 -1
- package/dist/commonjs/v3/index.d.ts +4 -19
- package/dist/commonjs/v3/index.js +18 -35
- package/dist/commonjs/v3/index.js.map +1 -1
- package/dist/commonjs/v3/metadata.d.ts +75 -12
- package/dist/commonjs/v3/metadata.js +93 -53
- package/dist/commonjs/v3/metadata.js.map +1 -1
- package/dist/commonjs/v3/runs.d.ts +49 -772
- package/dist/commonjs/v3/runs.js +12 -1
- package/dist/commonjs/v3/runs.js.map +1 -1
- package/dist/commonjs/v3/shared.d.ts +10 -380
- package/dist/commonjs/v3/shared.js +125 -68
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/v3/tasks.d.ts +6 -5
- package/dist/commonjs/v3/tasks.js +4 -5
- package/dist/commonjs/v3/tasks.js.map +1 -1
- package/dist/commonjs/v3/tracer.d.ts +1 -1
- package/dist/commonjs/v3/tracer.js +2 -2
- package/dist/commonjs/v3/tracer.js.map +1 -1
- package/dist/commonjs/v3/waitUntil.d.ts +9 -0
- package/dist/commonjs/v3/waitUntil.js +16 -0
- package/dist/commonjs/v3/waitUntil.js.map +1 -0
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/auth.d.ts +104 -0
- package/dist/esm/v3/auth.js +98 -0
- package/dist/esm/v3/auth.js.map +1 -0
- package/dist/esm/v3/idempotencyKeys.d.ts +2 -46
- package/dist/esm/v3/idempotencyKeys.js +1 -68
- package/dist/esm/v3/idempotencyKeys.js.map +1 -1
- package/dist/esm/v3/index-browser.d.mts +2 -0
- package/dist/esm/v3/index-browser.mjs +3 -0
- package/dist/esm/v3/index-browser.mjs.map +1 -0
- package/dist/esm/v3/index.d.ts +4 -19
- package/dist/esm/v3/index.js +4 -22
- package/dist/esm/v3/index.js.map +1 -1
- package/dist/esm/v3/metadata.d.ts +75 -12
- package/dist/esm/v3/metadata.js +94 -54
- package/dist/esm/v3/metadata.js.map +1 -1
- package/dist/esm/v3/runs.d.ts +64 -787
- package/dist/esm/v3/runs.js +12 -1
- package/dist/esm/v3/runs.js.map +1 -1
- package/dist/esm/v3/shared.d.ts +10 -380
- package/dist/esm/v3/shared.js +121 -65
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/v3/tasks.d.ts +6 -5
- package/dist/esm/v3/tasks.js +4 -4
- package/dist/esm/v3/tasks.js.map +1 -1
- package/dist/esm/v3/tracer.d.ts +1 -1
- package/dist/esm/v3/tracer.js +1 -1
- package/dist/esm/v3/tracer.js.map +1 -1
- package/dist/esm/v3/waitUntil.d.ts +9 -0
- package/dist/esm/v3/waitUntil.js +13 -0
- package/dist/esm/v3/waitUntil.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://imagedelivery.net/3TbraffuDZ4aEf8KWOmI_w/a45d1fa2-0ae8-4a39-4409-f4f934bfae00/public">
|
|
4
|
+
<source media="(prefers-color-scheme: light)" srcset="https://imagedelivery.net/3TbraffuDZ4aEf8KWOmI_w/3f5ad4c1-c4c8-4277-b622-290e7f37bd00/public">
|
|
5
|
+
<img alt="Trigger.dev logo" src="https://imagedelivery.net/3TbraffuDZ4aEf8KWOmI_w/a45d1fa2-0ae8-4a39-4409-f4f934bfae00/public">
|
|
6
|
+
</picture>
|
|
7
|
+
|
|
8
|
+
### Open source background jobs with no timeouts
|
|
9
|
+
|
|
10
|
+
[Discord](https://trigger.dev/discord) | [Website](https://trigger.dev) | [Issues](https://github.com/triggerdotdev/trigger.dev/issues) | [Docs](https://trigger.dev/docs)
|
|
11
|
+
|
|
12
|
+
[](https://twitter.com/triggerdotdev)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
1
16
|
# Official TypeScript SDK for Trigger.dev
|
|
2
17
|
|
|
3
|
-
|
|
18
|
+
The Trigger.dev SDK is a TypeScript/JavaScript library that allows you to define and trigger tasks in your project.
|
|
19
|
+
|
|
20
|
+
## About
|
|
21
|
+
|
|
22
|
+
Trigger.dev is an open source platform and SDK which allows you to create long-running background jobs. Write normal async code, deploy, and never hit a timeout.
|
|
23
|
+
|
|
24
|
+
## Getting started
|
|
25
|
+
|
|
26
|
+
The quickest way to get started is to create an account in our [web app](https://cloud.trigger.dev), create a new project and follow the instructions in the onboarding. Build and deploy your first task in minutes.
|
|
27
|
+
|
|
28
|
+
## SDK usage
|
|
29
|
+
|
|
30
|
+
For more information on our SDK, refer to our [docs](https://trigger.dev/docs/introduction).
|
|
31
|
+
|
|
32
|
+
## Support
|
|
33
|
+
|
|
34
|
+
If you have any questions, please reach out to us on [Discord](https://trigger.dev/discord) and we'll be happy to help.
|
package/dist/commonjs/types.d.ts
CHANGED
|
@@ -116,13 +116,13 @@ export declare const EventSpecificationExampleSchema: z.ZodObject<{
|
|
|
116
116
|
icon: z.ZodOptional<z.ZodString>;
|
|
117
117
|
payload: z.ZodAny;
|
|
118
118
|
}, "strip", z.ZodTypeAny, {
|
|
119
|
-
name: string;
|
|
120
119
|
id: string;
|
|
120
|
+
name: string;
|
|
121
121
|
icon?: string | undefined;
|
|
122
122
|
payload?: any;
|
|
123
123
|
}, {
|
|
124
|
-
name: string;
|
|
125
124
|
id: string;
|
|
125
|
+
name: string;
|
|
126
126
|
icon?: string | undefined;
|
|
127
127
|
payload?: any;
|
|
128
128
|
}>;
|
|
@@ -181,17 +181,17 @@ export declare function waitForEventSchema(schema: z.ZodTypeAny): z.ZodObject<{
|
|
|
181
181
|
context: z.ZodOptional<z.ZodAny>;
|
|
182
182
|
accountId: z.ZodOptional<z.ZodString>;
|
|
183
183
|
}, "strip", z.ZodTypeAny, {
|
|
184
|
+
id: string;
|
|
184
185
|
name: string;
|
|
185
186
|
source: string;
|
|
186
|
-
id: string;
|
|
187
187
|
timestamp: Date;
|
|
188
188
|
payload?: any;
|
|
189
189
|
context?: any;
|
|
190
190
|
accountId?: string | undefined;
|
|
191
191
|
}, {
|
|
192
|
+
id: string;
|
|
192
193
|
name: string;
|
|
193
194
|
source: string;
|
|
194
|
-
id: string;
|
|
195
195
|
timestamp: Date;
|
|
196
196
|
payload?: any;
|
|
197
197
|
context?: any;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { type ApiClientConfiguration } from "@trigger.dev/core/v3";
|
|
2
|
+
/**
|
|
3
|
+
* Register the global API client configuration. Alternatively, you can set the `TRIGGER_SECRET_KEY` and `TRIGGER_API_URL` environment variables.
|
|
4
|
+
* @param options The API client configuration.
|
|
5
|
+
* @param options.baseURL The base URL of the Trigger API. (default: `https://api.trigger.dev`)
|
|
6
|
+
* @param options.accessToken The accessToken to authenticate with the Trigger API. (default: `process.env.TRIGGER_SECRET_KEY`) This can be found in your Trigger.dev project "API Keys" settings.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { configure } from "@trigger.dev/sdk/v3";
|
|
12
|
+
*
|
|
13
|
+
* configure({
|
|
14
|
+
* baseURL: "https://api.trigger.dev",
|
|
15
|
+
* accessToken: "tr_dev_1234567890"
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function configure(options: ApiClientConfiguration): void;
|
|
20
|
+
export declare const auth: {
|
|
21
|
+
configure: typeof configure;
|
|
22
|
+
createPublicToken: typeof createPublicToken;
|
|
23
|
+
withAuth: typeof withAuth;
|
|
24
|
+
};
|
|
25
|
+
type PublicTokenPermissionAction = "read" | "write";
|
|
26
|
+
type PublicTokenPermissionProperties = {
|
|
27
|
+
/**
|
|
28
|
+
* Grant access to specific tasks
|
|
29
|
+
*/
|
|
30
|
+
tasks?: string | string[];
|
|
31
|
+
/**
|
|
32
|
+
* Grant access to specific run tags
|
|
33
|
+
*/
|
|
34
|
+
tags?: string | string[];
|
|
35
|
+
/**
|
|
36
|
+
* Grant access to specific runs
|
|
37
|
+
*/
|
|
38
|
+
runs?: string | string[] | true;
|
|
39
|
+
/**
|
|
40
|
+
* Grant access to specific batch runs
|
|
41
|
+
*/
|
|
42
|
+
batch?: string | string[];
|
|
43
|
+
};
|
|
44
|
+
export type PublicTokenPermissions = {
|
|
45
|
+
[key in PublicTokenPermissionAction]?: PublicTokenPermissionProperties;
|
|
46
|
+
};
|
|
47
|
+
export type CreatePublicTokenOptions = {
|
|
48
|
+
/**
|
|
49
|
+
* A collection of permission scopes to be granted to the token.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
*
|
|
53
|
+
* ```typescript
|
|
54
|
+
* scopes: {
|
|
55
|
+
* read: {
|
|
56
|
+
* tags: ["file:1234"]
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
scopes?: PublicTokenPermissions;
|
|
62
|
+
/**
|
|
63
|
+
* The expiration time for the token. This can be a number representing the time in milliseconds, a `Date` object, or a string.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
*
|
|
67
|
+
* ```typescript
|
|
68
|
+
* expirationTime: "1h"
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
expirationTime?: number | Date | string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Creates a public token using the provided options.
|
|
75
|
+
*
|
|
76
|
+
* @param options - Optional parameters for creating the public token.
|
|
77
|
+
* @param options.scopes - An array of permission scopes to be included in the token.
|
|
78
|
+
* @param options.expirationTime - The expiration time for the token.
|
|
79
|
+
* @returns A promise that resolves to a string representing the generated public token.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
*
|
|
83
|
+
* ```typescript
|
|
84
|
+
* import { auth } from "@trigger.dev/sdk/v3";
|
|
85
|
+
*
|
|
86
|
+
* const publicToken = await auth.createPublicToken({
|
|
87
|
+
* scopes: {
|
|
88
|
+
* read: {
|
|
89
|
+
* tags: ["file:1234"]
|
|
90
|
+
* }
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare function createPublicToken(options?: CreatePublicTokenOptions): Promise<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Executes a provided asynchronous function with a specified API client configuration.
|
|
97
|
+
*
|
|
98
|
+
* @template R - The type of the asynchronous function to be executed.
|
|
99
|
+
* @param {ApiClientConfiguration} config - The configuration for the API client.
|
|
100
|
+
* @param {R} fn - The asynchronous function to be executed.
|
|
101
|
+
* @returns {Promise<ReturnType<R>>} A promise that resolves to the return type of the provided function.
|
|
102
|
+
*/
|
|
103
|
+
declare function withAuth<R extends (...args: any[]) => Promise<any>>(config: ApiClientConfiguration, fn: R): Promise<ReturnType<R>>;
|
|
104
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.auth = void 0;
|
|
4
|
+
exports.configure = configure;
|
|
5
|
+
const v3_1 = require("@trigger.dev/core/v3");
|
|
6
|
+
const v3_2 = require("@trigger.dev/core/v3");
|
|
7
|
+
/**
|
|
8
|
+
* Register the global API client configuration. Alternatively, you can set the `TRIGGER_SECRET_KEY` and `TRIGGER_API_URL` environment variables.
|
|
9
|
+
* @param options The API client configuration.
|
|
10
|
+
* @param options.baseURL The base URL of the Trigger API. (default: `https://api.trigger.dev`)
|
|
11
|
+
* @param options.accessToken The accessToken to authenticate with the Trigger API. (default: `process.env.TRIGGER_SECRET_KEY`) This can be found in your Trigger.dev project "API Keys" settings.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { configure } from "@trigger.dev/sdk/v3";
|
|
17
|
+
*
|
|
18
|
+
* configure({
|
|
19
|
+
* baseURL: "https://api.trigger.dev",
|
|
20
|
+
* accessToken: "tr_dev_1234567890"
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function configure(options) {
|
|
25
|
+
v3_1.apiClientManager.setGlobalAPIClientConfiguration(options);
|
|
26
|
+
}
|
|
27
|
+
exports.auth = {
|
|
28
|
+
configure,
|
|
29
|
+
createPublicToken,
|
|
30
|
+
withAuth,
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Creates a public token using the provided options.
|
|
34
|
+
*
|
|
35
|
+
* @param options - Optional parameters for creating the public token.
|
|
36
|
+
* @param options.scopes - An array of permission scopes to be included in the token.
|
|
37
|
+
* @param options.expirationTime - The expiration time for the token.
|
|
38
|
+
* @returns A promise that resolves to a string representing the generated public token.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
*
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import { auth } from "@trigger.dev/sdk/v3";
|
|
44
|
+
*
|
|
45
|
+
* const publicToken = await auth.createPublicToken({
|
|
46
|
+
* scopes: {
|
|
47
|
+
* read: {
|
|
48
|
+
* tags: ["file:1234"]
|
|
49
|
+
* }
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
async function createPublicToken(options) {
|
|
54
|
+
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
55
|
+
const claims = await apiClient.generateJWTClaims();
|
|
56
|
+
return await (0, v3_2.generateJWT)({
|
|
57
|
+
secretKey: apiClient.accessToken,
|
|
58
|
+
payload: {
|
|
59
|
+
...claims,
|
|
60
|
+
scopes: options?.scopes ? flattenScopes(options.scopes) : undefined,
|
|
61
|
+
},
|
|
62
|
+
expirationTime: options?.expirationTime,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Executes a provided asynchronous function with a specified API client configuration.
|
|
67
|
+
*
|
|
68
|
+
* @template R - The type of the asynchronous function to be executed.
|
|
69
|
+
* @param {ApiClientConfiguration} config - The configuration for the API client.
|
|
70
|
+
* @param {R} fn - The asynchronous function to be executed.
|
|
71
|
+
* @returns {Promise<ReturnType<R>>} A promise that resolves to the return type of the provided function.
|
|
72
|
+
*/
|
|
73
|
+
async function withAuth(config, fn) {
|
|
74
|
+
return v3_1.apiClientManager.runWithConfig(config, fn);
|
|
75
|
+
}
|
|
76
|
+
function flattenScopes(permissions) {
|
|
77
|
+
const flattenedPermissions = [];
|
|
78
|
+
for (const [action, properties] of Object.entries(permissions)) {
|
|
79
|
+
if (properties) {
|
|
80
|
+
if (typeof properties === "boolean" && properties) {
|
|
81
|
+
flattenedPermissions.push(action);
|
|
82
|
+
}
|
|
83
|
+
else if (typeof properties === "object") {
|
|
84
|
+
for (const [property, value] of Object.entries(properties)) {
|
|
85
|
+
if (Array.isArray(value)) {
|
|
86
|
+
for (const item of value) {
|
|
87
|
+
flattenedPermissions.push(`${action}:${property}:${item}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else if (typeof value === "string") {
|
|
91
|
+
flattenedPermissions.push(`${action}:${property}:${value}`);
|
|
92
|
+
}
|
|
93
|
+
else if (typeof value === "boolean" && value) {
|
|
94
|
+
flattenedPermissions.push(`${action}:${property}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return flattenedPermissions;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/v3/auth.ts"],"names":[],"mappings":";;;AAoBA,8BAEC;AAtBD,6CAAqF;AACrF,6CAA2E;AAE3E;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,SAAS,CAAC,OAA+B;IACvD,qBAAgB,CAAC,+BAA+B,CAAC,OAAO,CAAC,CAAC;AAC5D,CAAC;AAEY,QAAA,IAAI,GAAG;IAClB,SAAS;IACT,iBAAiB;IACjB,QAAQ;CACT,CAAC;AA0DF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,KAAK,UAAU,iBAAiB,CAAC,OAAkC;IACjE,MAAM,SAAS,GAAG,qBAAgB,CAAC,aAAa,EAAE,CAAC;IAEnD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,iBAAiB,EAAE,CAAC;IAEnD,OAAO,MAAM,IAAA,gBAAoB,EAAC;QAChC,SAAS,EAAE,SAAS,CAAC,WAAW;QAChC,OAAO,EAAE;YACP,GAAG,MAAM;YACT,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;SACpE;QACD,cAAc,EAAE,OAAO,EAAE,cAAc;KACxC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,QAAQ,CACrB,MAA8B,EAC9B,EAAK;IAEL,OAAO,qBAAgB,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,aAAa,CAAC,WAAmC;IACxD,MAAM,oBAAoB,GAAa,EAAE,CAAC;IAE1C,KAAK,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/D,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,OAAO,UAAU,KAAK,SAAS,IAAI,UAAU,EAAE,CAAC;gBAClD,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACpC,CAAC;iBAAM,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;gBAC1C,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;oBAC3D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;wBACzB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;4BACzB,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC;wBAC7D,CAAC;oBACH,CAAC;yBAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;wBACrC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC,CAAC;oBAC9D,CAAC;yBAAM,IAAI,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,EAAE,CAAC;wBAC/C,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,QAAQ,EAAE,CAAC,CAAC;oBACrD,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,oBAAoB,CAAC;AAC9B,CAAC"}
|
|
@@ -1,49 +1,5 @@
|
|
|
1
|
+
import { createIdempotencyKey, type IdempotencyKey } from "@trigger.dev/core/v3";
|
|
1
2
|
export declare const idempotencyKeys: {
|
|
2
3
|
create: typeof createIdempotencyKey;
|
|
3
4
|
};
|
|
4
|
-
|
|
5
|
-
type Brand<B> = {
|
|
6
|
-
[__brand]: B;
|
|
7
|
-
};
|
|
8
|
-
type Branded<T, B> = T & Brand<B>;
|
|
9
|
-
export type IdempotencyKey = Branded<string, "IdempotencyKey">;
|
|
10
|
-
export declare function isIdempotencyKey(value: string | string[] | IdempotencyKey): value is IdempotencyKey;
|
|
11
|
-
/**
|
|
12
|
-
* Creates a deterministic idempotency key based on the provided key material.
|
|
13
|
-
*
|
|
14
|
-
* If running inside a task, the task run ID is automatically included in the key material, giving you a unique key per task run.
|
|
15
|
-
* This ensures that a given child task is only triggered once per task run, even if the parent task is retried.
|
|
16
|
-
*
|
|
17
|
-
* @param {string | string[]} key The key material to create the idempotency key from.
|
|
18
|
-
* @param {object} [options] Additional options.
|
|
19
|
-
* @param {"run" | "attempt" | "global"} [options.scope="run"] The scope of the idempotency key.
|
|
20
|
-
*
|
|
21
|
-
* @returns {Promise<IdempotencyKey>} The idempotency key as a branded string.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
*
|
|
25
|
-
* ```typescript
|
|
26
|
-
* import { idempotencyKeys, task } from "@trigger.dev/sdk/v3";
|
|
27
|
-
*
|
|
28
|
-
* export const myTask = task({
|
|
29
|
-
* id: "my-task",
|
|
30
|
-
* run: async (payload: any) => {
|
|
31
|
-
* const idempotencyKey = await idempotencyKeys.create("my-task-key");
|
|
32
|
-
*
|
|
33
|
-
* // Use the idempotency key when triggering child tasks
|
|
34
|
-
* await childTask.triggerAndWait(payload, { idempotencyKey });
|
|
35
|
-
* }
|
|
36
|
-
* });
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* You can also use the `scope` parameter to create a key that is unique per task run, task run attempts (retries of the same run), or globally:
|
|
40
|
-
*
|
|
41
|
-
* ```typescript
|
|
42
|
-
* await idempotencyKeys.create("my-task-key", { scope: "attempt" }); // Creates a key that is unique per task run attempt
|
|
43
|
-
* await idempotencyKeys.create("my-task-key", { scope: "global" }); // Skips including the task run ID
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
declare function createIdempotencyKey(key: string | string[], options?: {
|
|
47
|
-
scope?: "run" | "attempt" | "global";
|
|
48
|
-
}): Promise<IdempotencyKey>;
|
|
49
|
-
export {};
|
|
5
|
+
export type { IdempotencyKey };
|
|
@@ -1,76 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.idempotencyKeys = void 0;
|
|
4
|
-
exports.isIdempotencyKey = isIdempotencyKey;
|
|
5
4
|
const v3_1 = require("@trigger.dev/core/v3");
|
|
6
5
|
exports.idempotencyKeys = {
|
|
7
|
-
create: createIdempotencyKey,
|
|
6
|
+
create: v3_1.createIdempotencyKey,
|
|
8
7
|
};
|
|
9
|
-
function isIdempotencyKey(value) {
|
|
10
|
-
// Cannot check the brand at runtime because it doesn't exist (it's a TypeScript-only construct)
|
|
11
|
-
return typeof value === "string" && value.length === 64;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Creates a deterministic idempotency key based on the provided key material.
|
|
15
|
-
*
|
|
16
|
-
* If running inside a task, the task run ID is automatically included in the key material, giving you a unique key per task run.
|
|
17
|
-
* This ensures that a given child task is only triggered once per task run, even if the parent task is retried.
|
|
18
|
-
*
|
|
19
|
-
* @param {string | string[]} key The key material to create the idempotency key from.
|
|
20
|
-
* @param {object} [options] Additional options.
|
|
21
|
-
* @param {"run" | "attempt" | "global"} [options.scope="run"] The scope of the idempotency key.
|
|
22
|
-
*
|
|
23
|
-
* @returns {Promise<IdempotencyKey>} The idempotency key as a branded string.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
*
|
|
27
|
-
* ```typescript
|
|
28
|
-
* import { idempotencyKeys, task } from "@trigger.dev/sdk/v3";
|
|
29
|
-
*
|
|
30
|
-
* export const myTask = task({
|
|
31
|
-
* id: "my-task",
|
|
32
|
-
* run: async (payload: any) => {
|
|
33
|
-
* const idempotencyKey = await idempotencyKeys.create("my-task-key");
|
|
34
|
-
*
|
|
35
|
-
* // Use the idempotency key when triggering child tasks
|
|
36
|
-
* await childTask.triggerAndWait(payload, { idempotencyKey });
|
|
37
|
-
* }
|
|
38
|
-
* });
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* You can also use the `scope` parameter to create a key that is unique per task run, task run attempts (retries of the same run), or globally:
|
|
42
|
-
*
|
|
43
|
-
* ```typescript
|
|
44
|
-
* await idempotencyKeys.create("my-task-key", { scope: "attempt" }); // Creates a key that is unique per task run attempt
|
|
45
|
-
* await idempotencyKeys.create("my-task-key", { scope: "global" }); // Skips including the task run ID
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
async function createIdempotencyKey(key, options) {
|
|
49
|
-
const idempotencyKey = await generateIdempotencyKey([...(Array.isArray(key) ? key : [key])].concat(injectScope(options?.scope ?? "run")));
|
|
50
|
-
return idempotencyKey;
|
|
51
|
-
}
|
|
52
|
-
function injectScope(scope) {
|
|
53
|
-
switch (scope) {
|
|
54
|
-
case "run": {
|
|
55
|
-
if (v3_1.taskContext?.ctx) {
|
|
56
|
-
return [v3_1.taskContext.ctx.run.id];
|
|
57
|
-
}
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
case "attempt": {
|
|
61
|
-
if (v3_1.taskContext?.ctx) {
|
|
62
|
-
return [v3_1.taskContext.ctx.attempt.id];
|
|
63
|
-
}
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return [];
|
|
68
|
-
}
|
|
69
|
-
async function generateIdempotencyKey(keyMaterial) {
|
|
70
|
-
const hash = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(keyMaterial.join("-")));
|
|
71
|
-
// Return a hex string, using cross-runtime compatible methods
|
|
72
|
-
return Array.from(new Uint8Array(hash))
|
|
73
|
-
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
74
|
-
.join("");
|
|
75
|
-
}
|
|
76
8
|
//# sourceMappingURL=idempotencyKeys.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idempotencyKeys.js","sourceRoot":"","sources":["../../../src/v3/idempotencyKeys.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"idempotencyKeys.js","sourceRoot":"","sources":["../../../src/v3/idempotencyKeys.ts"],"names":[],"mappings":";;;AAAA,6CAAiF;AAEpE,QAAA,eAAe,GAAG;IAC7B,MAAM,EAAE,yBAAoB;CAC7B,CAAC"}
|
|
@@ -4,35 +4,20 @@ export { retry, type RetryOptions } from "./retry.js";
|
|
|
4
4
|
export { queue } from "./shared.js";
|
|
5
5
|
export * from "./tasks.js";
|
|
6
6
|
export * from "./wait.js";
|
|
7
|
+
export * from "./waitUntil.js";
|
|
7
8
|
export * from "./usage.js";
|
|
8
9
|
export * from "./idempotencyKeys.js";
|
|
9
10
|
export * from "./tags.js";
|
|
10
11
|
export * from "./metadata.js";
|
|
11
12
|
export * from "./timeout.js";
|
|
13
|
+
export * from "./waitUntil.js";
|
|
12
14
|
export type { Context };
|
|
13
15
|
import type { Context } from "./shared.js";
|
|
14
16
|
import type { ApiClientConfiguration } from "@trigger.dev/core/v3";
|
|
15
17
|
export type { ApiClientConfiguration };
|
|
16
18
|
export { ApiError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError, AbortTaskRunError, logger, type LogLevel, } from "@trigger.dev/core/v3";
|
|
17
|
-
export { runs } from "./runs.js";
|
|
19
|
+
export { runs, type RunShape, type AnyRunShape, type TaskRunShape, type RealtimeRun, type RetrieveRunResult, type AnyRetrieveRunResult, } from "./runs.js";
|
|
18
20
|
export * as schedules from "./schedules/index.js";
|
|
19
21
|
export * as envvars from "./envvars.js";
|
|
20
22
|
export type { ImportEnvironmentVariablesParams } from "./envvars.js";
|
|
21
|
-
|
|
22
|
-
* Register the global API client configuration. Alternatively, you can set the `TRIGGER_SECRET_KEY` and `TRIGGER_API_URL` environment variables.
|
|
23
|
-
* @param options The API client configuration.
|
|
24
|
-
* @param options.baseURL The base URL of the Trigger API. (default: `https://api.trigger.dev`)
|
|
25
|
-
* @param options.secretKey The secret key to authenticate with the Trigger API. (default: `process.env.TRIGGER_SECRET_KEY`) This can be found in your Trigger.dev project "API Keys" settings.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
*
|
|
29
|
-
* ```typescript
|
|
30
|
-
* import { configure } from "@trigger.dev/sdk/v3";
|
|
31
|
-
*
|
|
32
|
-
* configure({
|
|
33
|
-
* baseURL: "https://api.trigger.dev",
|
|
34
|
-
* secretKey: "tr_dev_1234567890"
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare function configure(options: ApiClientConfiguration): void;
|
|
23
|
+
export { configure, auth } from "./auth.js";
|
|
@@ -26,8 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.envvars = exports.schedules = exports.runs = exports.logger = exports.AbortTaskRunError = exports.UnprocessableEntityError = exports.RateLimitError = exports.PermissionDeniedError = exports.NotFoundError = exports.InternalServerError = exports.ConflictError = exports.BadRequestError = exports.AuthenticationError = exports.ApiError = exports.queue = exports.retry = void 0;
|
|
30
|
-
exports.configure = configure;
|
|
29
|
+
exports.auth = exports.configure = exports.envvars = exports.schedules = exports.runs = exports.logger = exports.AbortTaskRunError = exports.UnprocessableEntityError = exports.RateLimitError = exports.PermissionDeniedError = exports.NotFoundError = exports.InternalServerError = exports.ConflictError = exports.BadRequestError = exports.AuthenticationError = exports.ApiError = exports.queue = exports.retry = void 0;
|
|
31
30
|
__exportStar(require("./cache.js"), exports);
|
|
32
31
|
__exportStar(require("./config.js"), exports);
|
|
33
32
|
var retry_js_1 = require("./retry.js");
|
|
@@ -36,46 +35,30 @@ var shared_js_1 = require("./shared.js");
|
|
|
36
35
|
Object.defineProperty(exports, "queue", { enumerable: true, get: function () { return shared_js_1.queue; } });
|
|
37
36
|
__exportStar(require("./tasks.js"), exports);
|
|
38
37
|
__exportStar(require("./wait.js"), exports);
|
|
38
|
+
__exportStar(require("./waitUntil.js"), exports);
|
|
39
39
|
__exportStar(require("./usage.js"), exports);
|
|
40
40
|
__exportStar(require("./idempotencyKeys.js"), exports);
|
|
41
41
|
__exportStar(require("./tags.js"), exports);
|
|
42
42
|
__exportStar(require("./metadata.js"), exports);
|
|
43
43
|
__exportStar(require("./timeout.js"), exports);
|
|
44
|
-
|
|
45
|
-
var
|
|
46
|
-
Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return
|
|
47
|
-
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return
|
|
48
|
-
Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return
|
|
49
|
-
Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return
|
|
50
|
-
Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return
|
|
51
|
-
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return
|
|
52
|
-
Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get: function () { return
|
|
53
|
-
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return
|
|
54
|
-
Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return
|
|
55
|
-
Object.defineProperty(exports, "AbortTaskRunError", { enumerable: true, get: function () { return
|
|
56
|
-
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return
|
|
44
|
+
__exportStar(require("./waitUntil.js"), exports);
|
|
45
|
+
var v3_1 = require("@trigger.dev/core/v3");
|
|
46
|
+
Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return v3_1.ApiError; } });
|
|
47
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return v3_1.AuthenticationError; } });
|
|
48
|
+
Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return v3_1.BadRequestError; } });
|
|
49
|
+
Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return v3_1.ConflictError; } });
|
|
50
|
+
Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return v3_1.InternalServerError; } });
|
|
51
|
+
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return v3_1.NotFoundError; } });
|
|
52
|
+
Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get: function () { return v3_1.PermissionDeniedError; } });
|
|
53
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return v3_1.RateLimitError; } });
|
|
54
|
+
Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return v3_1.UnprocessableEntityError; } });
|
|
55
|
+
Object.defineProperty(exports, "AbortTaskRunError", { enumerable: true, get: function () { return v3_1.AbortTaskRunError; } });
|
|
56
|
+
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return v3_1.logger; } });
|
|
57
57
|
var runs_js_1 = require("./runs.js");
|
|
58
58
|
Object.defineProperty(exports, "runs", { enumerable: true, get: function () { return runs_js_1.runs; } });
|
|
59
59
|
exports.schedules = __importStar(require("./schedules/index.js"));
|
|
60
60
|
exports.envvars = __importStar(require("./envvars.js"));
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
* @param options.baseURL The base URL of the Trigger API. (default: `https://api.trigger.dev`)
|
|
65
|
-
* @param options.secretKey The secret key to authenticate with the Trigger API. (default: `process.env.TRIGGER_SECRET_KEY`) This can be found in your Trigger.dev project "API Keys" settings.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
*
|
|
69
|
-
* ```typescript
|
|
70
|
-
* import { configure } from "@trigger.dev/sdk/v3";
|
|
71
|
-
*
|
|
72
|
-
* configure({
|
|
73
|
-
* baseURL: "https://api.trigger.dev",
|
|
74
|
-
* secretKey: "tr_dev_1234567890"
|
|
75
|
-
* });
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
function configure(options) {
|
|
79
|
-
v3_1.apiClientManager.setGlobalAPIClientConfiguration(options);
|
|
80
|
-
}
|
|
61
|
+
var auth_js_1 = require("./auth.js");
|
|
62
|
+
Object.defineProperty(exports, "configure", { enumerable: true, get: function () { return auth_js_1.configure; } });
|
|
63
|
+
Object.defineProperty(exports, "auth", { enumerable: true, get: function () { return auth_js_1.auth; } });
|
|
81
64
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,8CAA4B;AAC5B,uCAAsD;AAA7C,iGAAA,KAAK,OAAA;AACd,yCAAoC;AAA3B,kGAAA,KAAK,OAAA;AACd,6CAA2B;AAC3B,4CAA0B;AAC1B,iDAA+B;AAC/B,6CAA2B;AAC3B,uDAAqC;AACrC,4CAA0B;AAC1B,gDAA8B;AAC9B,+CAA6B;AAC7B,iDAA+B;AAS/B,2CAa8B;AAZ5B,8FAAA,QAAQ,OAAA;AACR,yGAAA,mBAAmB,OAAA;AACnB,qGAAA,eAAe,OAAA;AACf,mGAAA,aAAa,OAAA;AACb,yGAAA,mBAAmB,OAAA;AACnB,mGAAA,aAAa,OAAA;AACb,2GAAA,qBAAqB,OAAA;AACrB,oGAAA,cAAc,OAAA;AACd,8GAAA,wBAAwB,OAAA;AACxB,uGAAA,iBAAiB,OAAA;AACjB,4FAAA,MAAM,OAAA;AAIR,qCAQmB;AAPjB,+FAAA,IAAI,OAAA;AAQN,kEAAkD;AAClD,wDAAwC;AAGxC,qCAA4C;AAAnC,oGAAA,SAAS,OAAA;AAAE,+FAAA,IAAI,OAAA"}
|