-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(sdk,core): add TriggerClient for per-instance SDK configuration #3683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ericallam
wants to merge
8
commits into
main
Choose a base branch
from
feat/trigger-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fd7bec7
feat(sdk,core): add TriggerClient for per-instance SDK configuration
ericallam 8c6c8c5
fix(core,sdk): keep sdkScope out of the browser import graph
ericallam 768ce08
fix(core,sdk): add typesVersions entry for v3/sdk-scope-storage + mov…
ericallam 90a3e04
fix(core): preserve storage-node side effect + env fallback for inher…
ericallam 8a8fb97
feat(core,sdk): TriggerClient falls back to env vars at construction
ericallam e1ca02e
fix(sdk): drop triggerAndSubscribe from TriggerClient surface
ericallam 53162a6
chore(changeset): trim TriggerClient changeset to sdk-only patch
ericallam de3b063
fix(core): compose nested withAuth by merging from enclosing scope
ericallam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --- | ||
| "@trigger.dev/sdk": patch | ||
| --- | ||
|
|
||
| Add `TriggerClient` for running multiple SDK clients side-by-side, each with its own auth, preview branch, and baseURL. Useful when a single process needs to trigger tasks or read runs across multiple projects, environments, or preview branches without mutating shared global state. | ||
|
|
||
| ```ts | ||
| import { TriggerClient } from "@trigger.dev/sdk"; | ||
|
|
||
| const prod = new TriggerClient({ accessToken: process.env.TRIGGER_PROD_KEY }); | ||
| const preview = new TriggerClient({ | ||
| accessToken: process.env.TRIGGER_PREVIEW_KEY, | ||
| previewBranch: "signup-flow", | ||
| }); | ||
|
|
||
| await prod.tasks.trigger("send-email", payload); | ||
| await preview.runs.list({ status: ["COMPLETED"] }); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { sdkScope, type SdkScope } from "./sdkScope/index.js"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import type { SdkScope, SdkScopeStorage } from "./types.js"; | ||
|
|
||
| export type { SdkScope, SdkScopeStorage } from "./types.js"; | ||
|
|
||
| let installedStorage: SdkScopeStorage | undefined; | ||
|
|
||
| export function _installSdkScopeStorage(storage: SdkScopeStorage): void { | ||
| installedStorage = storage; | ||
| } | ||
|
|
||
| export const sdkScope = { | ||
| hasStorage(): boolean { | ||
| return installedStorage !== undefined; | ||
| }, | ||
| getStore(): SdkScope | undefined { | ||
| return installedStorage?.getStore(); | ||
| }, | ||
| withScope<R>(scope: SdkScope, fn: () => R): R { | ||
| return installedStorage ? installedStorage.run(scope, fn) : fn(); | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { AsyncLocalStorage } from "node:async_hooks"; | ||
| import { _installSdkScopeStorage } from "./index.js"; | ||
| import type { SdkScope } from "./types.js"; | ||
|
|
||
| const als = new AsyncLocalStorage<SdkScope>(); | ||
|
|
||
| _installSdkScopeStorage({ | ||
| getStore: () => als.getStore(), | ||
| run: (scope, fn) => als.run(scope, fn), | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import type { ApiClientConfiguration } from "../apiClientManager/types.js"; | ||
|
|
||
| export type SdkScope = { | ||
| apiClientConfig: ApiClientConfiguration; | ||
| inheritContext: boolean; | ||
| }; | ||
|
|
||
| export type SdkScopeStorage = { | ||
| getStore(): SdkScope | undefined; | ||
| run<R>(scope: SdkScope, fn: () => R): R; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| "directory": "packages/trigger-sdk" | ||
| }, | ||
| "type": "module", | ||
| "sideEffects": false, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.