Skip to content

Commit a5cc2fc

Browse files
committed
Finish renaming jwt -> publicAccessToken and automatically give the JWT read access to the tags when using trigger
1 parent 63b9941 commit a5cc2fc

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,4 +628,4 @@
628628
"main": "./dist/commonjs/index.js",
629629
"types": "./dist/commonjs/index.d.ts",
630630
"module": "./dist/esm/index.js"
631-
}
631+
}

packages/core/src/v3/apiClient/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ export type TriggerOptions = {
6969
};
7070

7171
export type TriggerRequestOptions = ZodFetchOptions & {
72-
jwt?: TriggerJwtOptions;
72+
publicAccessToken?: TriggerJwtOptions;
7373
};
7474

7575
export type TriggerApiRequestOptions = ApiRequestOptions & {
76-
jwt?: TriggerJwtOptions;
76+
publicAccessToken?: TriggerJwtOptions;
7777
};
7878

7979
const DEFAULT_ZOD_FETCH_OPTIONS: ZodFetchOptions = {
@@ -189,9 +189,11 @@ export class ApiClient {
189189
secretKey: this.accessToken,
190190
payload: {
191191
...claims,
192-
scopes: [`read:runs:${data.id}`],
192+
scopes: [`read:runs:${data.id}`].concat(
193+
body.options?.tags ? Array.from(body.options?.tags).map((t) => `read:tags:${t}`) : []
194+
),
193195
},
194-
expirationTime: requestOptions?.jwt?.expirationTime ?? "1h",
196+
expirationTime: requestOptions?.publicAccessToken?.expirationTime ?? "1h",
195197
});
196198

197199
return {
@@ -230,7 +232,7 @@ export class ApiClient {
230232
...claims,
231233
scopes: [`read:batch:${data.batchId}`],
232234
},
233-
expirationTime: requestOptions?.jwt?.expirationTime ?? "1h",
235+
expirationTime: requestOptions?.publicAccessToken?.expirationTime ?? "1h",
234236
});
235237

236238
return {

packages/react-hooks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@
7474
"main": "./dist/commonjs/index.js",
7575
"types": "./dist/commonjs/index.d.ts",
7676
"module": "./dist/esm/index.js"
77-
}
77+
}

references/v3-catalog/src/clientUsage.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
import { runs, tasks, auth, AnyTask, Task } from "@trigger.dev/sdk/v3";
1+
import { auth, runs, tasks } from "@trigger.dev/sdk/v3";
22
import type { task1, task2 } from "./trigger/taskTypes.js";
3+
import { randomUUID } from "crypto";
34

45
async function main() {
6+
const userId = randomUUID();
7+
58
const anyHandle = await tasks.trigger<typeof task1>(
69
"types/task-1",
710
{
811
foo: "baz",
912
},
1013
{
11-
tags: ["user:1234"],
14+
tags: [`user:${userId}`],
15+
},
16+
{
17+
publicAccessToken: {
18+
expirationTime: "24hr",
19+
},
1220
}
1321
);
1422

15-
const jwt = await auth.createPublicToken({ scopes: { read: { tags: "user:1234" } } });
16-
17-
console.log("Generated JWT:", jwt);
23+
console.log("Auto JWT", anyHandle.publicAccessToken);
1824

19-
await auth.withAuth({ accessToken: jwt }, async () => {
20-
const subscription = runs.subscribeToRunsWithTag<typeof task1 | typeof task2>("user:1234");
25+
await auth.withAuth({ accessToken: anyHandle.publicAccessToken }, async () => {
26+
const subscription = runs.subscribeToRunsWithTag<typeof task1 | typeof task2>(`user:${userId}`);
2127

2228
for await (const run of subscription) {
2329
switch (run.taskIdentifier) {

0 commit comments

Comments
 (0)