@sylphx/sdk 0.3.7 → 0.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/dist/index.d.cts +938 -140
- package/dist/index.d.ts +938 -140
- package/dist/index.js +810 -267
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +791 -269
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs/index.js +44 -20
- package/dist/nextjs/index.js.map +1 -1
- package/dist/nextjs/index.mjs +44 -20
- package/dist/nextjs/index.mjs.map +1 -1
- package/dist/react/index.d.cts +389 -32
- package/dist/react/index.d.ts +389 -32
- package/dist/react/index.js +1610 -1285
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +1284 -963
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.d.cts +355 -18
- package/dist/server/index.d.ts +355 -18
- package/dist/server/index.js +559 -22
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +555 -22
- package/dist/server/index.mjs.map +1 -1
- package/dist/web-analytics.js.map +1 -1
- package/dist/web-analytics.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/web-analytics.d.cts +0 -90
- package/dist/web-analytics.d.ts +0 -90
package/dist/index.d.ts
CHANGED
|
@@ -1,140 +1,170 @@
|
|
|
1
1
|
import * as openapi_fetch from 'openapi-fetch';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* SDK
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* This is
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
4
|
+
* Sylphx Connection URL Parser — SDK Self-Contained Copy
|
|
5
|
+
*
|
|
6
|
+
* Implements the canonical connection string format defined in ADR-055 §5.
|
|
7
|
+
* This is a self-contained copy for SDK package independence (no app imports).
|
|
8
|
+
*
|
|
9
|
+
* Format:
|
|
10
|
+
* sylphx://{credential}@{slug}.{domain}[:port][/v{version}]
|
|
11
|
+
*
|
|
12
|
+
* Examples:
|
|
13
|
+
* sylphx://pk_prod_f19e5cdc3cc54f7ff81bdc26ec5bfbad@bold-river-a1b2c3.sylphx.com
|
|
14
|
+
* sylphx://sk_prod_5120bfeb5120bfeb5120bfeb5120bfeb@bold-river-a1b2c3.sylphx.com/v1
|
|
15
|
+
* sylphx://pk_dev_abc12345abc12345abc12345abc12345@calm-peak-z9x4d5.sylphx.dev
|
|
16
|
+
*
|
|
17
|
+
* Invariants:
|
|
18
|
+
* - Protocol is always `sylphx:` (no exceptions)
|
|
19
|
+
* - Credential matches `(pk|sk)_(dev|stg|prod|prev)_[a-f0-9]{32,64}`
|
|
20
|
+
* - Host's first DNS label is the resource slug (validated by slug regex)
|
|
21
|
+
* - `apiBaseUrl` is always HTTPS, with `/v{version}` appended (default `v1`)
|
|
22
|
+
*
|
|
23
|
+
* Parsing uses the WHATWG `URL` constructor — custom regex parsing is banned
|
|
24
|
+
* because it is notoriously brittle (ADR-055 §5.3).
|
|
25
|
+
*/
|
|
26
|
+
type ConnectionCredentialType = 'pk' | 'sk';
|
|
27
|
+
type ConnectionEnv = 'dev' | 'stg' | 'prod' | 'prev';
|
|
28
|
+
interface ParsedConnectionUrl {
|
|
29
|
+
/** Full credential string, e.g. `pk_prod_f19e...` */
|
|
30
|
+
readonly credential: string;
|
|
31
|
+
/** Credential kind — `pk` (publishable) or `sk` (secret) */
|
|
32
|
+
readonly credentialType: ConnectionCredentialType;
|
|
33
|
+
/** Target environment encoded in the credential */
|
|
34
|
+
readonly env: ConnectionEnv;
|
|
35
|
+
/** First DNS label of the host — the resource slug (e.g. `bold-river-a1b2c3`) */
|
|
36
|
+
readonly slug: string;
|
|
37
|
+
/** Full host including port when present (e.g. `bold-river-a1b2c3.sylphx.com`) */
|
|
38
|
+
readonly host: string;
|
|
39
|
+
/** Ready-to-use SDK base URL, always HTTPS (e.g. `https://bold-river-a1b2c3.sylphx.com/v1`) */
|
|
40
|
+
readonly apiBaseUrl: string;
|
|
41
|
+
}
|
|
42
|
+
declare class InvalidConnectionUrlError extends Error {
|
|
43
|
+
readonly code: "INVALID_CONNECTION_URL";
|
|
44
|
+
constructor(message: string);
|
|
27
45
|
}
|
|
46
|
+
|
|
28
47
|
/**
|
|
29
|
-
*
|
|
48
|
+
* SDK Configuration — ADR-055 Connection URL API
|
|
49
|
+
*
|
|
50
|
+
* v0.5.0: The primary entry point is `createClient(url)` which accepts
|
|
51
|
+
* a `sylphx://` connection URL. The old `createConfig({ ref, publicKey })`
|
|
52
|
+
* API is removed.
|
|
30
53
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { createClient } from '@sylphx/sdk'
|
|
34
57
|
*
|
|
35
|
-
*
|
|
58
|
+
* const sylphx = createClient(process.env.SYLPHX_URL!)
|
|
59
|
+
* // Parses: sylphx://pk_prod_{hex}@bold-river-a1b2c3.sylphx.com
|
|
60
|
+
* ```
|
|
36
61
|
*/
|
|
37
|
-
|
|
62
|
+
|
|
38
63
|
/**
|
|
39
|
-
* SDK Configuration
|
|
64
|
+
* SDK Configuration object — immutable, frozen.
|
|
40
65
|
*
|
|
41
|
-
*
|
|
42
|
-
* `track()`, `signIn()`,
|
|
43
|
-
*
|
|
44
|
-
* ## Config Type Hierarchy
|
|
45
|
-
*
|
|
46
|
-
* - `SylphxConfig` (this) — Pure functions, server or client
|
|
47
|
-
* - `SylphxClientConfig` — React hooks return value (appId, platformUrl only)
|
|
48
|
-
* - `SylphxProviderProps` — React provider component props
|
|
49
|
-
* - `SylphxMiddlewareConfig` — Next.js middleware options
|
|
50
|
-
*
|
|
51
|
-
* @example Server-side usage
|
|
52
|
-
* ```ts
|
|
53
|
-
* import { createConfig, track } from '@sylphx/sdk'
|
|
54
|
-
*
|
|
55
|
-
* const config = createConfig({ secretKey: process.env.SYLPHX_SECRET_KEY! })
|
|
56
|
-
* await track(config, { event: 'purchase', properties: { amount: 99 } })
|
|
57
|
-
* ```
|
|
66
|
+
* Created by `createClient()` or `createServerClient()`.
|
|
67
|
+
* Passed to all pure SDK functions (`track()`, `signIn()`, etc.).
|
|
58
68
|
*/
|
|
59
69
|
interface SylphxConfig {
|
|
70
|
+
/** The credential string (pk_* or sk_*) */
|
|
71
|
+
readonly credential: string;
|
|
72
|
+
/** Credential type: 'pk' (publishable) or 'sk' (secret) */
|
|
73
|
+
readonly credentialType: 'pk' | 'sk';
|
|
74
|
+
/** Target environment: dev, stg, prod, or prev */
|
|
75
|
+
readonly env: 'dev' | 'stg' | 'prod' | 'prev';
|
|
76
|
+
/** Resource slug (first DNS label), e.g. 'bold-river-a1b2c3' */
|
|
77
|
+
readonly slug: string;
|
|
78
|
+
/** Pre-computed API base URL, e.g. 'https://bold-river-a1b2c3.sylphx.com/v1' */
|
|
79
|
+
readonly baseUrl: string;
|
|
80
|
+
/** Optional access token for authenticated requests */
|
|
81
|
+
readonly accessToken?: string;
|
|
60
82
|
/**
|
|
61
|
-
* Secret key
|
|
62
|
-
*
|
|
63
|
-
* Get from Platform Console → Apps → Your App → Environments.
|
|
83
|
+
* Secret key — populated when credentialType is 'sk'.
|
|
84
|
+
* Backward-compatible alias for `credential` when credential is sk_*.
|
|
64
85
|
*/
|
|
65
86
|
readonly secretKey?: string;
|
|
66
87
|
/**
|
|
67
|
-
* Publishable key
|
|
68
|
-
*
|
|
69
|
-
* Get from Platform Console → Apps → Your App → Environments.
|
|
88
|
+
* Publishable key — populated when credentialType is 'pk'.
|
|
89
|
+
* Backward-compatible alias for `credential` when credential is pk_*.
|
|
70
90
|
*/
|
|
71
91
|
readonly publicKey?: string;
|
|
72
92
|
/**
|
|
73
|
-
*
|
|
74
|
-
* Extracted from the key automatically (ADR-021).
|
|
75
|
-
* The SDK targets: https://{ref}.api.sylphx.com/v1
|
|
93
|
+
* @deprecated Use `slug`. Backward-compatible alias.
|
|
76
94
|
*/
|
|
77
95
|
readonly ref: string;
|
|
78
|
-
/**
|
|
79
|
-
* Pre-computed base URL: https://{ref}.api.sylphx.com/v1
|
|
80
|
-
* Derived from the embedded ref in the key.
|
|
81
|
-
*/
|
|
82
|
-
readonly baseUrl: string;
|
|
83
|
-
/** Optional: Current access token for authenticated requests */
|
|
84
|
-
readonly accessToken?: string;
|
|
85
96
|
}
|
|
86
97
|
/**
|
|
87
|
-
*
|
|
98
|
+
* Explicit components input — alternative to connection URL string.
|
|
88
99
|
*
|
|
89
|
-
*
|
|
90
|
-
* The project ref is extracted automatically from the key.
|
|
100
|
+
* For multi-tenant apps or cases where components are stored separately.
|
|
91
101
|
*/
|
|
92
|
-
interface
|
|
93
|
-
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
* env var: NEXT_PUBLIC_SYLPHX_KEY
|
|
97
|
-
*/
|
|
102
|
+
interface SylphxClientInput {
|
|
103
|
+
/** Resource slug, e.g. 'bold-river-a1b2c3' */
|
|
104
|
+
slug?: string;
|
|
105
|
+
/** Publishable key (pk_*) — client-safe */
|
|
98
106
|
publicKey?: string;
|
|
99
|
-
/**
|
|
100
|
-
* Secret key (sk_*) — server-side only.
|
|
101
|
-
* Format: sk_{env}_{ref}_{64hex}
|
|
102
|
-
* env var: SYLPHX_SECRET_KEY
|
|
103
|
-
*/
|
|
107
|
+
/** Secret key (sk_*) — server-side only */
|
|
104
108
|
secretKey?: string;
|
|
109
|
+
/** Optional access token */
|
|
110
|
+
accessToken?: string;
|
|
111
|
+
/** API domain override (default: sylphx.com) */
|
|
112
|
+
domain?: string;
|
|
105
113
|
/**
|
|
106
|
-
* @deprecated Use
|
|
107
|
-
* Still accepted for backward compatibility; overridden by key-embedded ref.
|
|
114
|
+
* @deprecated Use `slug`. Accepted for backward compatibility during migration.
|
|
108
115
|
*/
|
|
109
116
|
ref?: string;
|
|
110
|
-
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated Use `domain`. Accepted for backward compatibility during migration.
|
|
119
|
+
*/
|
|
120
|
+
platformUrl?: string;
|
|
111
121
|
}
|
|
112
122
|
/**
|
|
113
|
-
* Create a Sylphx
|
|
123
|
+
* Create a Sylphx client from a connection URL or explicit components.
|
|
114
124
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
125
|
+
* This is the primary SDK entry point for client-side (browser) usage.
|
|
126
|
+
* Accepts a `sylphx://` connection URL or an explicit components object.
|
|
117
127
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
128
|
+
* @example Connection URL (recommended)
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const sylphx = createClient(process.env.NEXT_PUBLIC_SYLPHX_URL!)
|
|
131
|
+
* // Parses: sylphx://pk_prod_{hex}@bold-river-a1b2c3.sylphx.com
|
|
132
|
+
* ```
|
|
120
133
|
*
|
|
121
|
-
* @example
|
|
134
|
+
* @example Explicit components
|
|
122
135
|
* ```typescript
|
|
123
|
-
* const
|
|
124
|
-
*
|
|
136
|
+
* const sylphx = createClient({
|
|
137
|
+
* slug: 'bold-river-a1b2c3',
|
|
138
|
+
* publicKey: 'pk_prod_f19e...',
|
|
125
139
|
* })
|
|
126
140
|
* ```
|
|
141
|
+
*/
|
|
142
|
+
declare function createClient(input: string | SylphxClientInput): SylphxConfig;
|
|
143
|
+
/**
|
|
144
|
+
* Create a Sylphx server client from a connection URL or explicit components.
|
|
127
145
|
*
|
|
128
|
-
*
|
|
146
|
+
* Equivalent to `createClient()` but validates that a secret key (sk_*) is provided.
|
|
147
|
+
* Use this for server-side operations that require elevated permissions.
|
|
148
|
+
*
|
|
149
|
+
* @example Connection URL (recommended)
|
|
129
150
|
* ```typescript
|
|
130
|
-
* const
|
|
131
|
-
*
|
|
151
|
+
* const sylphx = createServerClient(process.env.SYLPHX_SECRET_URL!)
|
|
152
|
+
* // Parses: sylphx://sk_prod_{hex}@bold-river-a1b2c3.sylphx.com
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @example Explicit components
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const sylphx = createServerClient({
|
|
158
|
+
* slug: 'bold-river-a1b2c3',
|
|
159
|
+
* secretKey: 'sk_prod_5120...',
|
|
132
160
|
* })
|
|
133
161
|
* ```
|
|
134
162
|
*/
|
|
135
|
-
declare function
|
|
163
|
+
declare function createServerClient(input: string | SylphxClientInput): SylphxConfig;
|
|
136
164
|
/**
|
|
137
|
-
* Create a new config with an updated access token
|
|
165
|
+
* Create a new config with an updated access token.
|
|
166
|
+
*
|
|
167
|
+
* Returns a new frozen config — does not mutate the original.
|
|
138
168
|
*
|
|
139
169
|
* @example
|
|
140
170
|
* ```typescript
|
|
@@ -142,6 +172,15 @@ declare function createConfig(input: SylphxConfigInput): SylphxConfig;
|
|
|
142
172
|
* ```
|
|
143
173
|
*/
|
|
144
174
|
declare function withToken(config: SylphxConfig, accessToken: string): SylphxConfig;
|
|
175
|
+
/**
|
|
176
|
+
* @deprecated Use `createClient()` or `createServerClient()` instead.
|
|
177
|
+
* This function is kept temporarily for migration but will be removed.
|
|
178
|
+
*/
|
|
179
|
+
type SylphxConfigInput = string | SylphxClientInput;
|
|
180
|
+
/**
|
|
181
|
+
* @deprecated Use `createClient()` instead. See ADR-055.
|
|
182
|
+
*/
|
|
183
|
+
declare const createConfig: typeof createClient;
|
|
145
184
|
|
|
146
185
|
/**
|
|
147
186
|
* SDK Debug Mode
|
|
@@ -19946,6 +19985,16 @@ declare class SylphxError extends Error {
|
|
|
19946
19985
|
static isRateLimited(err: unknown): err is SylphxError & {
|
|
19947
19986
|
code: 'TOO_MANY_REQUESTS';
|
|
19948
19987
|
};
|
|
19988
|
+
/**
|
|
19989
|
+
* Check if error is an account lockout error (too many failed login attempts).
|
|
19990
|
+
* When true, `error.data?.lockoutUntil` contains the ISO 8601 timestamp when the lockout expires.
|
|
19991
|
+
*/
|
|
19992
|
+
static isAccountLocked(err: unknown): err is SylphxError & {
|
|
19993
|
+
code: 'TOO_MANY_REQUESTS';
|
|
19994
|
+
data: {
|
|
19995
|
+
lockoutUntil: string | null;
|
|
19996
|
+
};
|
|
19997
|
+
};
|
|
19949
19998
|
/**
|
|
19950
19999
|
* Check if error is a quota exceeded error (plan limit reached)
|
|
19951
20000
|
*/
|
|
@@ -21352,11 +21401,16 @@ interface RegisterInput {
|
|
|
21352
21401
|
invitationToken?: string;
|
|
21353
21402
|
}
|
|
21354
21403
|
/**
|
|
21355
|
-
* Org context claims present in org-scoped tokens.
|
|
21404
|
+
* Org context claims present in org-scoped tokens (after switch-org).
|
|
21405
|
+
*
|
|
21406
|
+
* The JWT carries the role key only. Permissions are resolved server-side
|
|
21407
|
+
* via Redis-cached role→permissions lookup (WorkOS pattern). This keeps
|
|
21408
|
+
* tokens small and ensures permission changes take effect without token refresh.
|
|
21356
21409
|
*/
|
|
21357
21410
|
interface OrgTokenPayload {
|
|
21358
21411
|
org_id: string;
|
|
21359
21412
|
org_slug: string;
|
|
21413
|
+
/** RBAC role key (e.g. "hr_manager", "admin"). Permissions resolved server-side. */
|
|
21360
21414
|
org_role: string;
|
|
21361
21415
|
}
|
|
21362
21416
|
/**
|
|
@@ -22309,6 +22363,32 @@ type NativeStepContext = {
|
|
|
22309
22363
|
* @param duration Human-readable duration: '5s', '30m', '2h', '1d'.
|
|
22310
22364
|
*/
|
|
22311
22365
|
sleep(name: string, duration: string): Promise<void>;
|
|
22366
|
+
/**
|
|
22367
|
+
* Pause execution until a named event is published via TriggersClient.publishEvent().
|
|
22368
|
+
*
|
|
22369
|
+
* On first encounter: signals the platform to wait for the event; stops execution.
|
|
22370
|
+
* After the event arrives: returns the event payload.
|
|
22371
|
+
* If timeout expires before event arrives: returns null.
|
|
22372
|
+
*
|
|
22373
|
+
* @param name Step identifier (must be unique within the handler).
|
|
22374
|
+
* @param eventName The event name to listen for (e.g. 'user.approved').
|
|
22375
|
+
* @param options Optional timeout ('24h', '7d') and payload filter.
|
|
22376
|
+
*
|
|
22377
|
+
* @example Human-in-the-loop approval
|
|
22378
|
+
* ```typescript
|
|
22379
|
+
* const approval = await step.waitForEvent<{ approvedBy: string }>(
|
|
22380
|
+
* 'wait-approval',
|
|
22381
|
+
* 'order.approved',
|
|
22382
|
+
* { timeout: '48h', filter: { orderId: payload.orderId } },
|
|
22383
|
+
* )
|
|
22384
|
+
* if (!approval) throw new Error('Approval timed out')
|
|
22385
|
+
* await notifyCustomer(approval.approvedBy)
|
|
22386
|
+
* ```
|
|
22387
|
+
*/
|
|
22388
|
+
waitForEvent<T = unknown>(name: string, eventName: string, options?: {
|
|
22389
|
+
timeout?: string;
|
|
22390
|
+
filter?: Record<string, unknown>;
|
|
22391
|
+
}): Promise<T | null>;
|
|
22312
22392
|
};
|
|
22313
22393
|
/**
|
|
22314
22394
|
* A named task definition registered with sylphx.tasks.define().
|
|
@@ -22401,9 +22481,9 @@ declare class StepSleepSignal {
|
|
|
22401
22481
|
* Build the step proxy for a single handler invocation.
|
|
22402
22482
|
*
|
|
22403
22483
|
* @param completedSteps Map of stepName → cached result
|
|
22404
|
-
* @param resolvedWaits
|
|
22484
|
+
* @param resolvedWaits Map of stepName → wait result (sleep = undefined, event = event payload)
|
|
22405
22485
|
*/
|
|
22406
|
-
declare function createStepContext(completedSteps: Map<string, unknown>, resolvedWaits:
|
|
22486
|
+
declare function createStepContext(completedSteps: Map<string, unknown>, resolvedWaits: Map<string, unknown>): NativeStepContext;
|
|
22407
22487
|
/**
|
|
22408
22488
|
* Constant-time HMAC-SHA256 signature verification.
|
|
22409
22489
|
* Accepts both raw hex and 'sha256={hex}' formats.
|
|
@@ -23788,6 +23868,350 @@ declare function canManageSettings(membership: OrganizationMembership | null): b
|
|
|
23788
23868
|
*/
|
|
23789
23869
|
declare function canDeleteOrganization(membership: OrganizationMembership | null): boolean;
|
|
23790
23870
|
|
|
23871
|
+
/**
|
|
23872
|
+
* Permission Functions
|
|
23873
|
+
*
|
|
23874
|
+
* Pure functions for permission management — no hidden state.
|
|
23875
|
+
* Each function takes config as the first parameter.
|
|
23876
|
+
*
|
|
23877
|
+
* Uses REST API at /permissions/* for project-scoped operations.
|
|
23878
|
+
* Uses REST API at /orgs/{orgId}/members/{memberId}/permissions for member checks.
|
|
23879
|
+
*
|
|
23880
|
+
* Types are self-contained (not dependent on generated OpenAPI spec) because
|
|
23881
|
+
* the RBAC routes were added after the last spec generation.
|
|
23882
|
+
*/
|
|
23883
|
+
|
|
23884
|
+
/**
|
|
23885
|
+
* A permission definition within a project.
|
|
23886
|
+
*
|
|
23887
|
+
* Permissions are the atomic building blocks of RBAC roles.
|
|
23888
|
+
* They use colon-separated keys (e.g. "org:members:read", "payroll:approve").
|
|
23889
|
+
*/
|
|
23890
|
+
interface Permission {
|
|
23891
|
+
/** Prefixed permission ID (e.g. "perm_xxx") */
|
|
23892
|
+
id: string;
|
|
23893
|
+
/** Unique key within the project (e.g. "org:members:read") */
|
|
23894
|
+
key: string;
|
|
23895
|
+
/** Human-readable name */
|
|
23896
|
+
name: string;
|
|
23897
|
+
/** Optional description */
|
|
23898
|
+
description: string | null;
|
|
23899
|
+
/** Whether this is a system-defined permission (immutable) */
|
|
23900
|
+
isSystem: boolean;
|
|
23901
|
+
/** ISO 8601 creation timestamp */
|
|
23902
|
+
createdAt: string;
|
|
23903
|
+
}
|
|
23904
|
+
/**
|
|
23905
|
+
* Input for creating a custom permission.
|
|
23906
|
+
*/
|
|
23907
|
+
interface CreatePermissionInput {
|
|
23908
|
+
/** Unique key — colon-separated lowercase segments (e.g. "org:leave:approve") */
|
|
23909
|
+
key: string;
|
|
23910
|
+
/** Human-readable name */
|
|
23911
|
+
name: string;
|
|
23912
|
+
/** Optional description */
|
|
23913
|
+
description?: string;
|
|
23914
|
+
}
|
|
23915
|
+
/**
|
|
23916
|
+
* Resolved permissions for a member, including their assigned role.
|
|
23917
|
+
*/
|
|
23918
|
+
interface MemberPermissionsResult {
|
|
23919
|
+
/** Prefixed user ID of the member */
|
|
23920
|
+
memberId: string;
|
|
23921
|
+
/** Assigned role (null if no role assigned) */
|
|
23922
|
+
role: {
|
|
23923
|
+
key: string;
|
|
23924
|
+
name: string;
|
|
23925
|
+
} | null;
|
|
23926
|
+
/** Flattened, deduplicated permission keys from all assigned roles */
|
|
23927
|
+
permissions: string[];
|
|
23928
|
+
}
|
|
23929
|
+
/**
|
|
23930
|
+
* List all permissions for the current project.
|
|
23931
|
+
*
|
|
23932
|
+
* Returns both system-defined and custom permissions.
|
|
23933
|
+
* Requires a secret key (server-side only).
|
|
23934
|
+
*
|
|
23935
|
+
* @example
|
|
23936
|
+
* ```typescript
|
|
23937
|
+
* const { permissions } = await listPermissions(config)
|
|
23938
|
+
* console.log(permissions.map(p => p.key))
|
|
23939
|
+
* // ['org:members:read', 'org:members:manage', 'payroll:view', ...]
|
|
23940
|
+
* ```
|
|
23941
|
+
*/
|
|
23942
|
+
declare function listPermissions(config: SylphxConfig): Promise<{
|
|
23943
|
+
permissions: Permission[];
|
|
23944
|
+
}>;
|
|
23945
|
+
/**
|
|
23946
|
+
* Create a custom permission for the project.
|
|
23947
|
+
*
|
|
23948
|
+
* Permission keys must be colon-separated lowercase segments
|
|
23949
|
+
* (e.g. "org:leave:approve", "payroll:run").
|
|
23950
|
+
* Requires a secret key (server-side only).
|
|
23951
|
+
*
|
|
23952
|
+
* @example
|
|
23953
|
+
* ```typescript
|
|
23954
|
+
* const { permission } = await createPermission(config, {
|
|
23955
|
+
* key: 'payroll:approve',
|
|
23956
|
+
* name: 'Approve Payroll',
|
|
23957
|
+
* description: 'Can approve payroll runs for the organization',
|
|
23958
|
+
* })
|
|
23959
|
+
* ```
|
|
23960
|
+
*/
|
|
23961
|
+
declare function createPermission(config: SylphxConfig, input: CreatePermissionInput): Promise<{
|
|
23962
|
+
permission: Permission;
|
|
23963
|
+
}>;
|
|
23964
|
+
/**
|
|
23965
|
+
* Delete a custom permission by key.
|
|
23966
|
+
*
|
|
23967
|
+
* System permissions cannot be deleted.
|
|
23968
|
+
* Role-permission assignments are removed automatically via cascading delete.
|
|
23969
|
+
* Requires a secret key (server-side only).
|
|
23970
|
+
*
|
|
23971
|
+
* @example
|
|
23972
|
+
* ```typescript
|
|
23973
|
+
* const { success } = await deletePermission(config, 'payroll:approve')
|
|
23974
|
+
* ```
|
|
23975
|
+
*/
|
|
23976
|
+
declare function deletePermission(config: SylphxConfig, permissionKey: string): Promise<{
|
|
23977
|
+
success: boolean;
|
|
23978
|
+
}>;
|
|
23979
|
+
/**
|
|
23980
|
+
* Get a member's resolved permissions within an organization.
|
|
23981
|
+
*
|
|
23982
|
+
* Returns the flattened, deduplicated set of permission keys from all
|
|
23983
|
+
* roles assigned to the member. Also returns their current role info.
|
|
23984
|
+
* Requires the caller to be a member of the same organization.
|
|
23985
|
+
*
|
|
23986
|
+
* @example
|
|
23987
|
+
* ```typescript
|
|
23988
|
+
* const result = await getMemberPermissions(config, 'my-org', 'usr_abc123')
|
|
23989
|
+
* console.log(result.permissions)
|
|
23990
|
+
* // ['org:members:read', 'payroll:view', 'payroll:approve']
|
|
23991
|
+
* console.log(result.role)
|
|
23992
|
+
* // { key: 'hr_manager', name: 'HR Manager' }
|
|
23993
|
+
* ```
|
|
23994
|
+
*/
|
|
23995
|
+
declare function getMemberPermissions(config: SylphxConfig, orgIdOrSlug: string, memberId: string): Promise<MemberPermissionsResult>;
|
|
23996
|
+
/**
|
|
23997
|
+
* Check if a permission set includes a specific permission.
|
|
23998
|
+
*
|
|
23999
|
+
* Pure function — no API call. Use with permissions from JWT claims
|
|
24000
|
+
* (org_permissions) or from getMemberPermissions().
|
|
24001
|
+
*
|
|
24002
|
+
* @example
|
|
24003
|
+
* ```typescript
|
|
24004
|
+
* const permissions = ['org:members:read', 'payroll:view']
|
|
24005
|
+
* hasPermission(permissions, 'payroll:view') // true
|
|
24006
|
+
* hasPermission(permissions, 'payroll:approve') // false
|
|
24007
|
+
* ```
|
|
24008
|
+
*/
|
|
24009
|
+
declare function hasPermission(permissions: string[], required: string): boolean;
|
|
24010
|
+
/**
|
|
24011
|
+
* Check if a permission set includes ANY of the required permissions.
|
|
24012
|
+
*
|
|
24013
|
+
* Pure function — no API call. Returns true if at least one of the
|
|
24014
|
+
* required permissions is present.
|
|
24015
|
+
*
|
|
24016
|
+
* @example
|
|
24017
|
+
* ```typescript
|
|
24018
|
+
* const permissions = ['org:members:read', 'payroll:view']
|
|
24019
|
+
* hasAnyPermission(permissions, ['payroll:view', 'payroll:approve']) // true
|
|
24020
|
+
* hasAnyPermission(permissions, ['admin:full', 'super:admin']) // false
|
|
24021
|
+
* ```
|
|
24022
|
+
*/
|
|
24023
|
+
declare function hasAnyPermission(permissions: string[], required: string[]): boolean;
|
|
24024
|
+
/**
|
|
24025
|
+
* Check if a permission set includes ALL of the required permissions.
|
|
24026
|
+
*
|
|
24027
|
+
* Pure function — no API call. Returns true only if every required
|
|
24028
|
+
* permission is present.
|
|
24029
|
+
*
|
|
24030
|
+
* @example
|
|
24031
|
+
* ```typescript
|
|
24032
|
+
* const permissions = ['org:members:read', 'payroll:view', 'payroll:approve']
|
|
24033
|
+
* hasAllPermissions(permissions, ['payroll:view', 'payroll:approve']) // true
|
|
24034
|
+
* hasAllPermissions(permissions, ['payroll:view', 'admin:full']) // false
|
|
24035
|
+
* ```
|
|
24036
|
+
*/
|
|
24037
|
+
declare function hasAllPermissions(permissions: string[], required: string[]): boolean;
|
|
24038
|
+
|
|
24039
|
+
/**
|
|
24040
|
+
* Role Functions
|
|
24041
|
+
*
|
|
24042
|
+
* Pure functions for role management — no hidden state.
|
|
24043
|
+
* Each function takes config as the first parameter.
|
|
24044
|
+
*
|
|
24045
|
+
* Uses REST API at /roles/* for project-scoped operations.
|
|
24046
|
+
* Uses REST API at /orgs/{orgId}/members/{memberId}/assign-role for assignment.
|
|
24047
|
+
*
|
|
24048
|
+
* Types are self-contained (not dependent on generated OpenAPI spec) because
|
|
24049
|
+
* the RBAC routes were added after the last spec generation.
|
|
24050
|
+
*/
|
|
24051
|
+
|
|
24052
|
+
/**
|
|
24053
|
+
* A role definition within a project.
|
|
24054
|
+
*
|
|
24055
|
+
* Roles bundle permissions into named groups that can be assigned to
|
|
24056
|
+
* organization members (e.g. "HR Manager", "Payroll Admin").
|
|
24057
|
+
*/
|
|
24058
|
+
interface Role {
|
|
24059
|
+
/** Prefixed role ID (e.g. "role_xxx") */
|
|
24060
|
+
id: string;
|
|
24061
|
+
/** Unique key within the project (e.g. "hr_manager") */
|
|
24062
|
+
key: string;
|
|
24063
|
+
/** Human-readable name */
|
|
24064
|
+
name: string;
|
|
24065
|
+
/** Optional description */
|
|
24066
|
+
description: string | null;
|
|
24067
|
+
/** Whether this is a system-defined role (metadata immutable) */
|
|
24068
|
+
isSystem: boolean;
|
|
24069
|
+
/** Whether this role is automatically assigned to new org members */
|
|
24070
|
+
isDefault: boolean;
|
|
24071
|
+
/** Display order (lower = higher priority) */
|
|
24072
|
+
sortOrder: number;
|
|
24073
|
+
/** Permission keys assigned to this role */
|
|
24074
|
+
permissions: string[];
|
|
24075
|
+
/** ISO 8601 creation timestamp */
|
|
24076
|
+
createdAt: string;
|
|
24077
|
+
/** ISO 8601 update timestamp (present on roles route response) */
|
|
24078
|
+
updatedAt?: string;
|
|
24079
|
+
}
|
|
24080
|
+
/**
|
|
24081
|
+
* Input for creating a custom role.
|
|
24082
|
+
*/
|
|
24083
|
+
interface CreateRoleInput {
|
|
24084
|
+
/** Unique key — lowercase alphanumeric with underscores (e.g. "hr_manager") */
|
|
24085
|
+
key: string;
|
|
24086
|
+
/** Human-readable name */
|
|
24087
|
+
name: string;
|
|
24088
|
+
/** Optional description */
|
|
24089
|
+
description?: string;
|
|
24090
|
+
/** Permission keys to assign to this role */
|
|
24091
|
+
permissions?: string[];
|
|
24092
|
+
/** Whether to auto-assign to new org members */
|
|
24093
|
+
isDefault?: boolean;
|
|
24094
|
+
/** Display order (lower = higher priority) */
|
|
24095
|
+
sortOrder?: number;
|
|
24096
|
+
}
|
|
24097
|
+
/**
|
|
24098
|
+
* Input for updating an existing role.
|
|
24099
|
+
*
|
|
24100
|
+
* System role metadata (name, description) is immutable, but their
|
|
24101
|
+
* permissions can be changed.
|
|
24102
|
+
*/
|
|
24103
|
+
interface UpdateRoleInput {
|
|
24104
|
+
/** Human-readable name (ignored for system roles) */
|
|
24105
|
+
name?: string;
|
|
24106
|
+
/** Description (ignored for system roles) */
|
|
24107
|
+
description?: string | null;
|
|
24108
|
+
/** Permission keys to assign (replaces existing) */
|
|
24109
|
+
permissions?: string[];
|
|
24110
|
+
/** Whether to auto-assign to new org members */
|
|
24111
|
+
isDefault?: boolean;
|
|
24112
|
+
/** Display order */
|
|
24113
|
+
sortOrder?: number;
|
|
24114
|
+
}
|
|
24115
|
+
/**
|
|
24116
|
+
* List all roles for the current project.
|
|
24117
|
+
*
|
|
24118
|
+
* Returns both system-defined and custom roles, each with their
|
|
24119
|
+
* assigned permission keys. Requires a secret key (server-side only).
|
|
24120
|
+
*
|
|
24121
|
+
* @example
|
|
24122
|
+
* ```typescript
|
|
24123
|
+
* const { roles } = await listRoles(config)
|
|
24124
|
+
* for (const role of roles) {
|
|
24125
|
+
* console.log(`${role.name}: ${role.permissions.join(', ')}`)
|
|
24126
|
+
* }
|
|
24127
|
+
* ```
|
|
24128
|
+
*/
|
|
24129
|
+
declare function listRoles(config: SylphxConfig): Promise<{
|
|
24130
|
+
roles: Role[];
|
|
24131
|
+
}>;
|
|
24132
|
+
/**
|
|
24133
|
+
* Get a single role by key, including its assigned permission keys.
|
|
24134
|
+
*
|
|
24135
|
+
* Requires a secret key (server-side only).
|
|
24136
|
+
*
|
|
24137
|
+
* @example
|
|
24138
|
+
* ```typescript
|
|
24139
|
+
* const { role } = await getRole(config, 'hr_manager')
|
|
24140
|
+
* console.log(role.permissions)
|
|
24141
|
+
* // ['org:members:read', 'payroll:view', 'payroll:approve']
|
|
24142
|
+
* ```
|
|
24143
|
+
*/
|
|
24144
|
+
declare function getRole(config: SylphxConfig, roleKey: string): Promise<{
|
|
24145
|
+
role: Role;
|
|
24146
|
+
}>;
|
|
24147
|
+
/**
|
|
24148
|
+
* Create a custom role with optional permission assignments.
|
|
24149
|
+
*
|
|
24150
|
+
* Role keys must be lowercase alphanumeric with underscores
|
|
24151
|
+
* (e.g. "hr_manager", "payroll_admin").
|
|
24152
|
+
* Requires a secret key (server-side only).
|
|
24153
|
+
*
|
|
24154
|
+
* @example
|
|
24155
|
+
* ```typescript
|
|
24156
|
+
* const { role } = await createRole(config, {
|
|
24157
|
+
* key: 'hr_manager',
|
|
24158
|
+
* name: 'HR Manager',
|
|
24159
|
+
* description: 'Can manage employees and approve leave',
|
|
24160
|
+
* permissions: ['org:members:read', 'leave:approve', 'payroll:view'],
|
|
24161
|
+
* })
|
|
24162
|
+
* ```
|
|
24163
|
+
*/
|
|
24164
|
+
declare function createRole(config: SylphxConfig, input: CreateRoleInput): Promise<{
|
|
24165
|
+
role: Role;
|
|
24166
|
+
}>;
|
|
24167
|
+
/**
|
|
24168
|
+
* Update a role's metadata and/or permission assignments.
|
|
24169
|
+
*
|
|
24170
|
+
* System role metadata (name, description) is immutable, but their
|
|
24171
|
+
* permissions can be changed. Passing `permissions` replaces the
|
|
24172
|
+
* entire permission set for the role.
|
|
24173
|
+
* Requires a secret key (server-side only).
|
|
24174
|
+
*
|
|
24175
|
+
* @example
|
|
24176
|
+
* ```typescript
|
|
24177
|
+
* const { role } = await updateRole(config, 'hr_manager', {
|
|
24178
|
+
* permissions: ['org:members:read', 'org:members:manage', 'leave:approve'],
|
|
24179
|
+
* })
|
|
24180
|
+
* ```
|
|
24181
|
+
*/
|
|
24182
|
+
declare function updateRole(config: SylphxConfig, roleKey: string, input: UpdateRoleInput): Promise<{
|
|
24183
|
+
role: Role;
|
|
24184
|
+
}>;
|
|
24185
|
+
/**
|
|
24186
|
+
* Delete a custom role by key.
|
|
24187
|
+
*
|
|
24188
|
+
* System roles cannot be deleted. Roles with active member assignments
|
|
24189
|
+
* cannot be deleted — reassign members first.
|
|
24190
|
+
* Requires a secret key (server-side only).
|
|
24191
|
+
*
|
|
24192
|
+
* @example
|
|
24193
|
+
* ```typescript
|
|
24194
|
+
* const { success } = await deleteRole(config, 'hr_manager')
|
|
24195
|
+
* ```
|
|
24196
|
+
*/
|
|
24197
|
+
declare function deleteRole(config: SylphxConfig, roleKey: string): Promise<{
|
|
24198
|
+
success: boolean;
|
|
24199
|
+
}>;
|
|
24200
|
+
/**
|
|
24201
|
+
* Assign an RBAC role to an organization member.
|
|
24202
|
+
*
|
|
24203
|
+
* Replaces any existing role assignment (single-role mode).
|
|
24204
|
+
* Requires admin access to the organization.
|
|
24205
|
+
*
|
|
24206
|
+
* @example
|
|
24207
|
+
* ```typescript
|
|
24208
|
+
* const { success } = await assignMemberRole(config, 'my-org', 'usr_abc123', 'hr_manager')
|
|
24209
|
+
* ```
|
|
24210
|
+
*/
|
|
24211
|
+
declare function assignMemberRole(config: SylphxConfig, orgIdOrSlug: string, memberId: string, roleKey: string): Promise<{
|
|
24212
|
+
success: boolean;
|
|
24213
|
+
}>;
|
|
24214
|
+
|
|
23791
24215
|
/**
|
|
23792
24216
|
* Secrets SDK
|
|
23793
24217
|
*
|
|
@@ -25330,6 +25754,21 @@ interface SandboxOptions {
|
|
|
25330
25754
|
};
|
|
25331
25755
|
/** Environment variables injected into the sandbox container */
|
|
25332
25756
|
env?: Record<string, string>;
|
|
25757
|
+
/**
|
|
25758
|
+
* Shared volume mounts from org-level managed volumes.
|
|
25759
|
+
* Requires ReadWriteMany volumes (CephFS). Multiple sandboxes can mount
|
|
25760
|
+
* the same volume for shared filesystem access.
|
|
25761
|
+
*/
|
|
25762
|
+
volumeMounts?: Array<{
|
|
25763
|
+
/** Volume resource ID (from `sylphx volumes list`) */
|
|
25764
|
+
volumeId: string;
|
|
25765
|
+
/** Absolute path inside the container (e.g. "/shared") */
|
|
25766
|
+
mountPath: string;
|
|
25767
|
+
/** Optional sub-path within the volume */
|
|
25768
|
+
subPath?: string;
|
|
25769
|
+
/** Read-only mount (default: false) */
|
|
25770
|
+
readOnly?: boolean;
|
|
25771
|
+
}>;
|
|
25333
25772
|
}
|
|
25334
25773
|
/** SSE event emitted by sandbox.exec() */
|
|
25335
25774
|
type ExecEvent = {
|
|
@@ -25368,6 +25807,75 @@ interface ExecOptions {
|
|
|
25368
25807
|
timeout?: number;
|
|
25369
25808
|
stdin?: string;
|
|
25370
25809
|
}
|
|
25810
|
+
interface ProcessStartOptions {
|
|
25811
|
+
/** Command + args (e.g. ['npm', 'install']) */
|
|
25812
|
+
command: string[];
|
|
25813
|
+
/** Working directory */
|
|
25814
|
+
cwd?: string;
|
|
25815
|
+
/** Environment variables */
|
|
25816
|
+
env?: Record<string, string>;
|
|
25817
|
+
/** Hard timeout in seconds (0 = no timeout) */
|
|
25818
|
+
timeoutSeconds?: number;
|
|
25819
|
+
/** Open stdin pipe for writing */
|
|
25820
|
+
stdin?: boolean;
|
|
25821
|
+
}
|
|
25822
|
+
interface ProcessInfo {
|
|
25823
|
+
id: string;
|
|
25824
|
+
pid: number;
|
|
25825
|
+
command: string[];
|
|
25826
|
+
cwd: string;
|
|
25827
|
+
status: 'running' | 'exited' | 'killed' | 'timeout';
|
|
25828
|
+
exitCode: number | null;
|
|
25829
|
+
signal: string | null;
|
|
25830
|
+
startedAt: string;
|
|
25831
|
+
exitedAt: string | null;
|
|
25832
|
+
durationMs: number | null;
|
|
25833
|
+
stdout: string;
|
|
25834
|
+
stderr: string;
|
|
25835
|
+
}
|
|
25836
|
+
interface ProcessSummary {
|
|
25837
|
+
id: string;
|
|
25838
|
+
pid: number;
|
|
25839
|
+
command: string[];
|
|
25840
|
+
status: 'running' | 'exited' | 'killed' | 'timeout';
|
|
25841
|
+
exitCode: number | null;
|
|
25842
|
+
startedAt: string;
|
|
25843
|
+
exitedAt: string | null;
|
|
25844
|
+
durationMs: number | null;
|
|
25845
|
+
}
|
|
25846
|
+
/** SSE event from a process stream */
|
|
25847
|
+
type ProcessEvent = {
|
|
25848
|
+
type: 'stdout';
|
|
25849
|
+
pid: number;
|
|
25850
|
+
data: string;
|
|
25851
|
+
} | {
|
|
25852
|
+
type: 'stderr';
|
|
25853
|
+
pid: number;
|
|
25854
|
+
data: string;
|
|
25855
|
+
} | {
|
|
25856
|
+
type: 'exit';
|
|
25857
|
+
pid: number;
|
|
25858
|
+
exitCode: number;
|
|
25859
|
+
};
|
|
25860
|
+
interface WatchOptions {
|
|
25861
|
+
/** Path to watch (relative to /workspace or absolute) */
|
|
25862
|
+
path: string;
|
|
25863
|
+
/** Watch subdirectories recursively (default: true) */
|
|
25864
|
+
recursive?: boolean;
|
|
25865
|
+
/** Additional patterns to ignore */
|
|
25866
|
+
ignore?: string[];
|
|
25867
|
+
}
|
|
25868
|
+
interface WatchEntry {
|
|
25869
|
+
path: string;
|
|
25870
|
+
recursive: boolean;
|
|
25871
|
+
createdAt: string;
|
|
25872
|
+
}
|
|
25873
|
+
/** File change event delivered via SSE /events stream */
|
|
25874
|
+
interface FileEvent {
|
|
25875
|
+
type: 'file';
|
|
25876
|
+
path: string;
|
|
25877
|
+
event: 'created' | 'modified' | 'deleted';
|
|
25878
|
+
}
|
|
25371
25879
|
interface SandboxRecord {
|
|
25372
25880
|
id: string;
|
|
25373
25881
|
status: 'starting' | 'running' | 'idle' | 'terminated' | 'error';
|
|
@@ -25397,6 +25905,46 @@ declare class SandboxFiles {
|
|
|
25397
25905
|
/** List files in a directory. */
|
|
25398
25906
|
list(path?: string): Promise<string[]>;
|
|
25399
25907
|
}
|
|
25908
|
+
declare class SandboxProcesses {
|
|
25909
|
+
private readonly endpoint;
|
|
25910
|
+
private readonly token;
|
|
25911
|
+
constructor(endpoint: string, token: string);
|
|
25912
|
+
private authHeader;
|
|
25913
|
+
/** Spawn a new tracked process. Returns processId + pid immediately. */
|
|
25914
|
+
start(opts: ProcessStartOptions): Promise<{
|
|
25915
|
+
id: string;
|
|
25916
|
+
pid: number;
|
|
25917
|
+
}>;
|
|
25918
|
+
/** List all tracked processes. */
|
|
25919
|
+
list(): Promise<ProcessSummary[]>;
|
|
25920
|
+
/** Get full process info including buffered output. */
|
|
25921
|
+
get(processId: string): Promise<ProcessInfo>;
|
|
25922
|
+
/** Send a signal to a process. */
|
|
25923
|
+
kill(processId: string, signal?: string): Promise<void>;
|
|
25924
|
+
/** Write to process stdin. */
|
|
25925
|
+
writeStdin(processId: string, data: string): Promise<void>;
|
|
25926
|
+
/**
|
|
25927
|
+
* Wait for a process to complete and return its final info.
|
|
25928
|
+
* Polls every 500ms until status is no longer 'running'.
|
|
25929
|
+
*
|
|
25930
|
+
* For real-time output, use stream() instead.
|
|
25931
|
+
*/
|
|
25932
|
+
wait(processId: string, timeoutMs?: number): Promise<ProcessInfo>;
|
|
25933
|
+
/** Stream process output as async iterable SSE events. */
|
|
25934
|
+
stream(processId: string): AsyncGenerator<ProcessEvent>;
|
|
25935
|
+
}
|
|
25936
|
+
declare class SandboxWatch {
|
|
25937
|
+
private readonly endpoint;
|
|
25938
|
+
private readonly token;
|
|
25939
|
+
constructor(endpoint: string, token: string);
|
|
25940
|
+
private authHeader;
|
|
25941
|
+
/** Start watching a path. Events delivered via sandbox.events() SSE stream. */
|
|
25942
|
+
add(opts: WatchOptions): Promise<WatchEntry>;
|
|
25943
|
+
/** List active watches. */
|
|
25944
|
+
list(): Promise<WatchEntry[]>;
|
|
25945
|
+
/** Stop watching a path. */
|
|
25946
|
+
remove(path: string): Promise<void>;
|
|
25947
|
+
}
|
|
25400
25948
|
declare class SandboxClient {
|
|
25401
25949
|
readonly id: string;
|
|
25402
25950
|
private readonly config;
|
|
@@ -25406,6 +25954,10 @@ declare class SandboxClient {
|
|
|
25406
25954
|
readonly token: string | null;
|
|
25407
25955
|
/** File operations (direct to exec-server) */
|
|
25408
25956
|
readonly files: SandboxFiles | null;
|
|
25957
|
+
/** Concurrent process management (direct to exec-server) */
|
|
25958
|
+
readonly processes: SandboxProcesses | null;
|
|
25959
|
+
/** Filesystem watch management (direct to exec-server) */
|
|
25960
|
+
readonly watch: SandboxWatch | null;
|
|
25409
25961
|
private constructor();
|
|
25410
25962
|
/**
|
|
25411
25963
|
* Create a new sandbox.
|
|
@@ -25423,10 +25975,21 @@ declare class SandboxClient {
|
|
|
25423
25975
|
getStatus(): Promise<SandboxRecord>;
|
|
25424
25976
|
terminate(): Promise<void>;
|
|
25425
25977
|
/**
|
|
25426
|
-
* Execute a command and stream output as async iterable events.
|
|
25978
|
+
* Execute a command and stream output as async iterable SSE events.
|
|
25979
|
+
*
|
|
25980
|
+
* **Stateless mode**: each exec() call runs in an isolated bash invocation.
|
|
25981
|
+
* Shell state (CWD changes, exported env vars, functions) is NOT preserved
|
|
25982
|
+
* between calls.
|
|
25427
25983
|
*
|
|
25428
|
-
*
|
|
25429
|
-
*
|
|
25984
|
+
* For state-preserving execution (CWD, env), use `run()` which runs in the
|
|
25985
|
+
* persistent active shell and returns the result once complete.
|
|
25986
|
+
*
|
|
25987
|
+
* For streaming + state-preserving (advanced), combine `sandbox.events()` with `run()`:
|
|
25988
|
+
* ```typescript
|
|
25989
|
+
* const eventStream = sandbox.events({ type: 'stdout' })
|
|
25990
|
+
* sandbox.run(['npm', 'install']) // don't await yet
|
|
25991
|
+
* for await (const ev of eventStream) { ... }
|
|
25992
|
+
* ```
|
|
25430
25993
|
*
|
|
25431
25994
|
* @example
|
|
25432
25995
|
* ```typescript
|
|
@@ -25444,6 +26007,24 @@ declare class SandboxClient {
|
|
|
25444
26007
|
* For long-running commands, prefer exec() to stream output incrementally.
|
|
25445
26008
|
*/
|
|
25446
26009
|
run(command: string[], options?: ExecOptions): Promise<ExecResult>;
|
|
26010
|
+
/**
|
|
26011
|
+
* Subscribe to the unified event stream (SSE).
|
|
26012
|
+
*
|
|
26013
|
+
* Receives all sandbox events: stdout, stderr, exit, port, file, shell, resource.
|
|
26014
|
+
* Filter by type/pid/shellId using query params.
|
|
26015
|
+
*
|
|
26016
|
+
* @example
|
|
26017
|
+
* ```typescript
|
|
26018
|
+
* for await (const event of sandbox.events({ type: 'file' })) {
|
|
26019
|
+
* console.log('File changed:', event.path, event.event)
|
|
26020
|
+
* }
|
|
26021
|
+
* ```
|
|
26022
|
+
*/
|
|
26023
|
+
events(filter?: {
|
|
26024
|
+
type?: 'stdout' | 'stderr' | 'exit' | 'port' | 'file' | 'shell' | 'resource';
|
|
26025
|
+
pid?: number;
|
|
26026
|
+
shellId?: string;
|
|
26027
|
+
}): AsyncGenerator<Record<string, unknown>>;
|
|
25447
26028
|
/**
|
|
25448
26029
|
* Open an interactive PTY session (WebSocket).
|
|
25449
26030
|
*
|
|
@@ -25463,11 +26044,11 @@ declare class SandboxClient {
|
|
|
25463
26044
|
}
|
|
25464
26045
|
|
|
25465
26046
|
/**
|
|
25466
|
-
*
|
|
26047
|
+
* Runs Client (ADR-040, formerly Workers)
|
|
25467
26048
|
*
|
|
25468
26049
|
* Fire-and-forget batch compute API (Modal-style run-to-completion jobs).
|
|
25469
26050
|
*
|
|
25470
|
-
*
|
|
26051
|
+
* Runs are ephemeral K8s Jobs that run to completion. Use them for:
|
|
25471
26052
|
* - ML training folds (walk-forward cross-validation)
|
|
25472
26053
|
* - Data processing pipelines
|
|
25473
26054
|
* - Batch inference
|
|
@@ -25477,11 +26058,11 @@ declare class SandboxClient {
|
|
|
25477
26058
|
*
|
|
25478
26059
|
* ### Single worker
|
|
25479
26060
|
* ```typescript
|
|
25480
|
-
* import { createConfig,
|
|
26061
|
+
* import { createConfig, RunsClient } from '@sylphx/sdk'
|
|
25481
26062
|
*
|
|
25482
26063
|
* const config = createConfig({ secretKey: process.env.SYLPHX_SECRET_KEY!, ref: 'my-project' })
|
|
25483
26064
|
*
|
|
25484
|
-
* const
|
|
26065
|
+
* const run = await RunsClient.create(config, {
|
|
25485
26066
|
* image: 'registry.sylphx.com/sylphx/my-trainer:abc123',
|
|
25486
26067
|
* command: ['python', 'train.py', '--fold', '0'],
|
|
25487
26068
|
* resources: { requests: { cpu: '4', memory: '8Gi' } },
|
|
@@ -25497,7 +26078,7 @@ declare class SandboxClient {
|
|
|
25497
26078
|
* ```typescript
|
|
25498
26079
|
* const workers = await Promise.all(
|
|
25499
26080
|
* folds.map((fold) =>
|
|
25500
|
-
*
|
|
26081
|
+
* RunsClient.create(config, {
|
|
25501
26082
|
* image: 'registry.sylphx.com/sylphx/trainer:abc123',
|
|
25502
26083
|
* command: ['python', 'train.py', '--fold', String(fold.id)],
|
|
25503
26084
|
* env: { FOLD_ID: String(fold.id), DATABASE_URL: process.env.DATABASE_URL! },
|
|
@@ -25525,8 +26106,8 @@ declare class SandboxClient {
|
|
|
25525
26106
|
* @module
|
|
25526
26107
|
*/
|
|
25527
26108
|
|
|
25528
|
-
type
|
|
25529
|
-
interface
|
|
26109
|
+
type RunStatus = 'pending' | 'running' | 'succeeded' | 'failed' | 'cancelled' | 'timeout';
|
|
26110
|
+
interface RunVolumeMount {
|
|
25530
26111
|
/** UUID of the volumeResource to mount (must belong to this org) */
|
|
25531
26112
|
volumeId: string;
|
|
25532
26113
|
/** Absolute mount path inside the container (e.g. '/cache') */
|
|
@@ -25536,7 +26117,7 @@ interface WorkerVolumeMount {
|
|
|
25536
26117
|
/** Mount as read-only (default: false) */
|
|
25537
26118
|
readOnly?: boolean;
|
|
25538
26119
|
}
|
|
25539
|
-
interface
|
|
26120
|
+
interface RunResourceSpec {
|
|
25540
26121
|
requests?: {
|
|
25541
26122
|
/** CPU request (e.g. '500m', '2', '4') */
|
|
25542
26123
|
cpu?: string;
|
|
@@ -25550,7 +26131,7 @@ interface WorkerResourceSpec {
|
|
|
25550
26131
|
memory?: string;
|
|
25551
26132
|
};
|
|
25552
26133
|
}
|
|
25553
|
-
interface
|
|
26134
|
+
interface CreateRunOptions {
|
|
25554
26135
|
/**
|
|
25555
26136
|
* Docker image to run (must be from registry.sylphx.com).
|
|
25556
26137
|
*
|
|
@@ -25573,7 +26154,7 @@ interface RunWorkerOptions {
|
|
|
25573
26154
|
* CPU/memory resource spec.
|
|
25574
26155
|
* Defaults: { requests: { cpu: '500m', memory: '512Mi' }, limits: { cpu: '2', memory: '2Gi' } }
|
|
25575
26156
|
*/
|
|
25576
|
-
resources?:
|
|
26157
|
+
resources?: RunResourceSpec;
|
|
25577
26158
|
/**
|
|
25578
26159
|
* Hard timeout in seconds (default: 3600 = 1 hour, max: 86400 = 24 hours).
|
|
25579
26160
|
* K8s terminates the Job when the deadline is reached (status: 'timeout').
|
|
@@ -25583,13 +26164,13 @@ interface RunWorkerOptions {
|
|
|
25583
26164
|
* Volume mounts from org-level volumeResources.
|
|
25584
26165
|
* ReadWriteMany volumes (rook-cephfs) allow concurrent access by multiple parallel workers.
|
|
25585
26166
|
*/
|
|
25586
|
-
volumeMounts?:
|
|
26167
|
+
volumeMounts?: RunVolumeMount[];
|
|
25587
26168
|
}
|
|
25588
|
-
interface
|
|
26169
|
+
interface Run {
|
|
25589
26170
|
/** Worker run ID (e.g. 'worker_Vh3kJ9mNpQ2wXsL1') */
|
|
25590
26171
|
id: string;
|
|
25591
26172
|
/** Current lifecycle status */
|
|
25592
|
-
status:
|
|
26173
|
+
status: RunStatus;
|
|
25593
26174
|
/** Docker image */
|
|
25594
26175
|
image: string;
|
|
25595
26176
|
/** Command being executed */
|
|
@@ -25597,11 +26178,11 @@ interface WorkerRun {
|
|
|
25597
26178
|
/** Environment variables */
|
|
25598
26179
|
env: Record<string, string> | null;
|
|
25599
26180
|
/** Resource spec */
|
|
25600
|
-
resources:
|
|
26181
|
+
resources: RunResourceSpec | null;
|
|
25601
26182
|
/** Hard timeout in seconds */
|
|
25602
26183
|
timeoutSeconds: number;
|
|
25603
26184
|
/** Volume mounts */
|
|
25604
|
-
volumeMounts:
|
|
26185
|
+
volumeMounts: RunVolumeMount[] | null;
|
|
25605
26186
|
/** Exit code (only when succeeded or failed) */
|
|
25606
26187
|
exitCode: number | null;
|
|
25607
26188
|
/** Captured stdout (up to 1 MiB) */
|
|
@@ -25621,11 +26202,11 @@ interface WorkerRun {
|
|
|
25621
26202
|
/** Last update timestamp */
|
|
25622
26203
|
updatedAt: string;
|
|
25623
26204
|
}
|
|
25624
|
-
interface
|
|
26205
|
+
interface RunResult {
|
|
25625
26206
|
/** Exit code (0 = success) */
|
|
25626
26207
|
exitCode: number | null;
|
|
25627
26208
|
/** Status at completion */
|
|
25628
|
-
status:
|
|
26209
|
+
status: RunStatus;
|
|
25629
26210
|
/** Captured stdout */
|
|
25630
26211
|
stdout: string | null;
|
|
25631
26212
|
/** Captured stderr */
|
|
@@ -25635,7 +26216,7 @@ interface WorkerResult {
|
|
|
25635
26216
|
/** Wall-clock duration in milliseconds */
|
|
25636
26217
|
durationMs: number | null;
|
|
25637
26218
|
}
|
|
25638
|
-
interface
|
|
26219
|
+
interface RunLogsResult {
|
|
25639
26220
|
/** Captured stdout (up to 1 MiB) */
|
|
25640
26221
|
stdout: string;
|
|
25641
26222
|
/** Captured stderr (up to 1 MiB) */
|
|
@@ -25643,14 +26224,14 @@ interface WorkerLogsResult {
|
|
|
25643
26224
|
/** Whether logs are still being captured (worker is running) */
|
|
25644
26225
|
live: boolean;
|
|
25645
26226
|
}
|
|
25646
|
-
interface
|
|
26227
|
+
interface ListRunsOptions {
|
|
25647
26228
|
/** Filter by status */
|
|
25648
|
-
status?:
|
|
26229
|
+
status?: RunStatus;
|
|
25649
26230
|
}
|
|
25650
26231
|
/** OpenAI/Stripe-style list response */
|
|
25651
|
-
interface
|
|
26232
|
+
interface ListRunsResult {
|
|
25652
26233
|
object: 'list';
|
|
25653
|
-
data:
|
|
26234
|
+
data: Run[];
|
|
25654
26235
|
/** True if there are more results (limit was hit) */
|
|
25655
26236
|
has_more: boolean;
|
|
25656
26237
|
}
|
|
@@ -25658,20 +26239,20 @@ interface ListWorkersResult {
|
|
|
25658
26239
|
* Handle to a running (or completed) worker.
|
|
25659
26240
|
* Use `.wait()` to poll until completion, `.logs()` to stream logs, `.cancel()` to abort.
|
|
25660
26241
|
*/
|
|
25661
|
-
declare class
|
|
26242
|
+
declare class RunHandle {
|
|
25662
26243
|
readonly id: string;
|
|
25663
26244
|
private readonly config;
|
|
25664
26245
|
constructor(id: string, config: SylphxConfig);
|
|
25665
26246
|
/**
|
|
25666
26247
|
* Get the current status of this worker.
|
|
25667
26248
|
*/
|
|
25668
|
-
status(): Promise<
|
|
26249
|
+
status(): Promise<Run>;
|
|
25669
26250
|
/**
|
|
25670
26251
|
* Poll the worker until it reaches a terminal state (succeeded, failed, cancelled, timeout).
|
|
25671
26252
|
*
|
|
25672
26253
|
* @param options.pollIntervalMs - How often to poll in ms (default: 3000)
|
|
25673
26254
|
* @param options.timeoutMs - Max time to wait before throwing (default: 7_200_000 = 2h)
|
|
25674
|
-
* @returns
|
|
26255
|
+
* @returns RunResult with exit code, status, stdout/stderr
|
|
25675
26256
|
* @throws Error if waitTimeout is exceeded
|
|
25676
26257
|
*
|
|
25677
26258
|
* @example
|
|
@@ -25685,7 +26266,7 @@ declare class WorkerHandle {
|
|
|
25685
26266
|
wait(options?: {
|
|
25686
26267
|
pollIntervalMs?: number;
|
|
25687
26268
|
timeoutMs?: number;
|
|
25688
|
-
}): Promise<
|
|
26269
|
+
}): Promise<RunResult>;
|
|
25689
26270
|
/**
|
|
25690
26271
|
* Fetch captured logs for this worker.
|
|
25691
26272
|
*
|
|
@@ -25699,7 +26280,7 @@ declare class WorkerHandle {
|
|
|
25699
26280
|
* if (live) console.log('(worker still running, logs may be incomplete)')
|
|
25700
26281
|
* ```
|
|
25701
26282
|
*/
|
|
25702
|
-
logs(): Promise<
|
|
26283
|
+
logs(): Promise<RunLogsResult>;
|
|
25703
26284
|
/**
|
|
25704
26285
|
* Cancel this worker.
|
|
25705
26286
|
*
|
|
@@ -25717,13 +26298,75 @@ declare class WorkerHandle {
|
|
|
25717
26298
|
* const config = createConfig({ secretKey: process.env.SYLPHX_SECRET_KEY!, ref: 'my-project' })
|
|
25718
26299
|
*
|
|
25719
26300
|
* // Run a worker and wait for completion
|
|
25720
|
-
* const result = await
|
|
26301
|
+
* const result = await RunsClient.create(config, { ... }).then(w => w.wait())
|
|
25721
26302
|
*
|
|
25722
26303
|
* // Run N workers in parallel, wait for all
|
|
25723
|
-
* const handles = await Promise.all(folds.map(fold =>
|
|
26304
|
+
* const handles = await Promise.all(folds.map(fold => RunsClient.create(config, { ... })))
|
|
25724
26305
|
* const results = await Promise.all(handles.map(h => h.wait()))
|
|
25725
26306
|
* ```
|
|
25726
26307
|
*/
|
|
26308
|
+
declare const RunsClient: {
|
|
26309
|
+
/**
|
|
26310
|
+
* Spawn a new worker (K8s Job) and return a handle.
|
|
26311
|
+
*
|
|
26312
|
+
* The Job is created immediately and starts pulling the image.
|
|
26313
|
+
* Use the returned handle to `.wait()` for completion or `.cancel()`.
|
|
26314
|
+
*
|
|
26315
|
+
* @example
|
|
26316
|
+
* ```typescript
|
|
26317
|
+
* const run = await RunsClient.create(config, {
|
|
26318
|
+
* image: 'registry.sylphx.com/sylphx/trainer:abc123',
|
|
26319
|
+
* command: ['python', 'train.py', '--fold', '3'],
|
|
26320
|
+
* resources: { requests: { cpu: '4', memory: '16Gi' } },
|
|
26321
|
+
* volumeMounts: [{ volumeId: cacheVolumeId, mountPath: '/cache' }],
|
|
26322
|
+
* })
|
|
26323
|
+
* const result = await worker.wait()
|
|
26324
|
+
* ```
|
|
26325
|
+
*/
|
|
26326
|
+
run(config: SylphxConfig, options: CreateRunOptions): Promise<RunHandle>;
|
|
26327
|
+
/**
|
|
26328
|
+
* Get a RunHandle for an existing run by ID.
|
|
26329
|
+
*
|
|
26330
|
+
* Useful for resuming monitoring across requests.
|
|
26331
|
+
*
|
|
26332
|
+
* @example
|
|
26333
|
+
* ```typescript
|
|
26334
|
+
* // Store the worker ID, retrieve later
|
|
26335
|
+
* const handle = RunsClient.fromId(config, storedWorkerId)
|
|
26336
|
+
* const result = await handle.wait()
|
|
26337
|
+
* ```
|
|
26338
|
+
*/
|
|
26339
|
+
fromId(config: SylphxConfig, workerId: string): RunHandle;
|
|
26340
|
+
/**
|
|
26341
|
+
* List worker runs for this environment.
|
|
26342
|
+
*
|
|
26343
|
+
* @example
|
|
26344
|
+
* ```typescript
|
|
26345
|
+
* const { workers } = await RunsClient.list(config, { status: 'running' })
|
|
26346
|
+
* console.log(`${workers.length} workers currently running`)
|
|
26347
|
+
* ```
|
|
26348
|
+
*/
|
|
26349
|
+
list(config: SylphxConfig, options?: ListRunsOptions): Promise<ListRunsResult>;
|
|
26350
|
+
/**
|
|
26351
|
+
* Spawn a worker and wait for it to complete in one call.
|
|
26352
|
+
*
|
|
26353
|
+
* Equivalent to `(await RunsClient.create(config, options)).wait(waitOptions)`.
|
|
26354
|
+
*
|
|
26355
|
+
* @example
|
|
26356
|
+
* ```typescript
|
|
26357
|
+
* const result = await RunsClient.runAndWait(config, {
|
|
26358
|
+
* image: 'registry.sylphx.com/sylphx/process:abc',
|
|
26359
|
+
* command: ['node', 'dist/process.js'],
|
|
26360
|
+
* })
|
|
26361
|
+
* if (result.exitCode !== 0) throw new Error(result.errorMessage ?? 'worker failed')
|
|
26362
|
+
* ```
|
|
26363
|
+
*/
|
|
26364
|
+
runAndWait(config: SylphxConfig, options: CreateRunOptions, waitOptions?: {
|
|
26365
|
+
pollIntervalMs?: number;
|
|
26366
|
+
timeoutMs?: number;
|
|
26367
|
+
}): Promise<RunResult>;
|
|
26368
|
+
};
|
|
26369
|
+
/** @deprecated Use RunsClient */
|
|
25727
26370
|
declare const WorkersClient: {
|
|
25728
26371
|
/**
|
|
25729
26372
|
* Spawn a new worker (K8s Job) and return a handle.
|
|
@@ -25733,7 +26376,7 @@ declare const WorkersClient: {
|
|
|
25733
26376
|
*
|
|
25734
26377
|
* @example
|
|
25735
26378
|
* ```typescript
|
|
25736
|
-
* const
|
|
26379
|
+
* const run = await RunsClient.create(config, {
|
|
25737
26380
|
* image: 'registry.sylphx.com/sylphx/trainer:abc123',
|
|
25738
26381
|
* command: ['python', 'train.py', '--fold', '3'],
|
|
25739
26382
|
* resources: { requests: { cpu: '4', memory: '16Gi' } },
|
|
@@ -25742,48 +26385,203 @@ declare const WorkersClient: {
|
|
|
25742
26385
|
* const result = await worker.wait()
|
|
25743
26386
|
* ```
|
|
25744
26387
|
*/
|
|
25745
|
-
run(config: SylphxConfig, options:
|
|
26388
|
+
run(config: SylphxConfig, options: CreateRunOptions): Promise<RunHandle>;
|
|
25746
26389
|
/**
|
|
25747
|
-
* Get a
|
|
26390
|
+
* Get a RunHandle for an existing run by ID.
|
|
25748
26391
|
*
|
|
25749
26392
|
* Useful for resuming monitoring across requests.
|
|
25750
26393
|
*
|
|
25751
26394
|
* @example
|
|
25752
26395
|
* ```typescript
|
|
25753
26396
|
* // Store the worker ID, retrieve later
|
|
25754
|
-
* const handle =
|
|
26397
|
+
* const handle = RunsClient.fromId(config, storedWorkerId)
|
|
25755
26398
|
* const result = await handle.wait()
|
|
25756
26399
|
* ```
|
|
25757
26400
|
*/
|
|
25758
|
-
fromId(config: SylphxConfig, workerId: string):
|
|
26401
|
+
fromId(config: SylphxConfig, workerId: string): RunHandle;
|
|
25759
26402
|
/**
|
|
25760
26403
|
* List worker runs for this environment.
|
|
25761
26404
|
*
|
|
25762
26405
|
* @example
|
|
25763
26406
|
* ```typescript
|
|
25764
|
-
* const { workers } = await
|
|
26407
|
+
* const { workers } = await RunsClient.list(config, { status: 'running' })
|
|
25765
26408
|
* console.log(`${workers.length} workers currently running`)
|
|
25766
26409
|
* ```
|
|
25767
26410
|
*/
|
|
25768
|
-
list(config: SylphxConfig, options?:
|
|
26411
|
+
list(config: SylphxConfig, options?: ListRunsOptions): Promise<ListRunsResult>;
|
|
25769
26412
|
/**
|
|
25770
26413
|
* Spawn a worker and wait for it to complete in one call.
|
|
25771
26414
|
*
|
|
25772
|
-
* Equivalent to `(await
|
|
26415
|
+
* Equivalent to `(await RunsClient.create(config, options)).wait(waitOptions)`.
|
|
25773
26416
|
*
|
|
25774
26417
|
* @example
|
|
25775
26418
|
* ```typescript
|
|
25776
|
-
* const result = await
|
|
26419
|
+
* const result = await RunsClient.runAndWait(config, {
|
|
25777
26420
|
* image: 'registry.sylphx.com/sylphx/process:abc',
|
|
25778
26421
|
* command: ['node', 'dist/process.js'],
|
|
25779
26422
|
* })
|
|
25780
26423
|
* if (result.exitCode !== 0) throw new Error(result.errorMessage ?? 'worker failed')
|
|
25781
26424
|
* ```
|
|
25782
26425
|
*/
|
|
25783
|
-
runAndWait(config: SylphxConfig, options:
|
|
26426
|
+
runAndWait(config: SylphxConfig, options: CreateRunOptions, waitOptions?: {
|
|
25784
26427
|
pollIntervalMs?: number;
|
|
25785
26428
|
timeoutMs?: number;
|
|
25786
|
-
}): Promise<
|
|
26429
|
+
}): Promise<RunResult>;
|
|
25787
26430
|
};
|
|
25788
26431
|
|
|
25789
|
-
|
|
26432
|
+
/**
|
|
26433
|
+
* Triggers Client (ADR-040)
|
|
26434
|
+
*
|
|
26435
|
+
* Unified scheduling + event dispatch API.
|
|
26436
|
+
* Create cron schedules and event triggers that dispatch to Tasks, Runs, or HTTP URLs.
|
|
26437
|
+
*
|
|
26438
|
+
* ## Usage
|
|
26439
|
+
*
|
|
26440
|
+
* ### Cron → Task
|
|
26441
|
+
* ```typescript
|
|
26442
|
+
* import { createConfig, TriggersClient } from '@sylphx/sdk'
|
|
26443
|
+
* const config = createConfig({ secretKey: process.env.SYLPHX_SECRET_KEY!, ref: 'my-project' })
|
|
26444
|
+
*
|
|
26445
|
+
* const trigger = await TriggersClient.create(config, {
|
|
26446
|
+
* name: 'daily-cleanup',
|
|
26447
|
+
* source: { type: 'cron', expression: '0 2 * * *' },
|
|
26448
|
+
* target: { type: 'task', taskName: 'daily-cleanup' },
|
|
26449
|
+
* })
|
|
26450
|
+
* ```
|
|
26451
|
+
*
|
|
26452
|
+
* ### Event → Task (fires when event is published via publishEvent)
|
|
26453
|
+
* ```typescript
|
|
26454
|
+
* const trigger = await TriggersClient.create(config, {
|
|
26455
|
+
* name: 'welcome-email-on-signup',
|
|
26456
|
+
* source: { type: 'event', eventName: 'user.signup' },
|
|
26457
|
+
* target: { type: 'task', taskName: 'send-welcome-email' },
|
|
26458
|
+
* })
|
|
26459
|
+
* // Publish from your app:
|
|
26460
|
+
* await TriggersClient.publishEvent(config, 'user.signup', { userId: '123' })
|
|
26461
|
+
* ```
|
|
26462
|
+
*
|
|
26463
|
+
* ### Cron → HTTP URL (any language, no code required)
|
|
26464
|
+
* ```typescript
|
|
26465
|
+
* const trigger = await TriggersClient.create(config, {
|
|
26466
|
+
* name: 'nightly-backup',
|
|
26467
|
+
* source: { type: 'cron', expression: '0 3 * * *' },
|
|
26468
|
+
* target: { type: 'http', url: 'https://myapp.com/api/backup', payload: { type: 'full' } },
|
|
26469
|
+
* })
|
|
26470
|
+
* ```
|
|
26471
|
+
*/
|
|
26472
|
+
|
|
26473
|
+
type TriggerTargetType = 'task' | 'run' | 'http';
|
|
26474
|
+
type TriggerSourceType = 'cron' | 'event';
|
|
26475
|
+
type TriggerStatus = 'active' | 'paused' | 'deleted';
|
|
26476
|
+
interface TaskTarget {
|
|
26477
|
+
type: 'task';
|
|
26478
|
+
taskName: string;
|
|
26479
|
+
handlerPath?: string;
|
|
26480
|
+
payload?: Record<string, unknown>;
|
|
26481
|
+
}
|
|
26482
|
+
interface HttpTarget {
|
|
26483
|
+
type: 'http';
|
|
26484
|
+
url: string;
|
|
26485
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
26486
|
+
headers?: Record<string, string>;
|
|
26487
|
+
payload?: Record<string, unknown>;
|
|
26488
|
+
}
|
|
26489
|
+
interface RunTarget {
|
|
26490
|
+
type: 'run';
|
|
26491
|
+
image: string;
|
|
26492
|
+
command: string[];
|
|
26493
|
+
resources?: {
|
|
26494
|
+
cpu?: string;
|
|
26495
|
+
memory?: string;
|
|
26496
|
+
};
|
|
26497
|
+
}
|
|
26498
|
+
type TriggerTarget = TaskTarget | HttpTarget | RunTarget;
|
|
26499
|
+
interface CronSource {
|
|
26500
|
+
type: 'cron';
|
|
26501
|
+
expression: string;
|
|
26502
|
+
}
|
|
26503
|
+
interface EventSource {
|
|
26504
|
+
type: 'event';
|
|
26505
|
+
/** The event name to listen for. e.g. 'user.signup', 'order.paid' */
|
|
26506
|
+
eventName: string;
|
|
26507
|
+
}
|
|
26508
|
+
type TriggerSource = CronSource | EventSource;
|
|
26509
|
+
interface CreateTriggerOptions {
|
|
26510
|
+
name?: string;
|
|
26511
|
+
source: TriggerSource;
|
|
26512
|
+
target: TriggerTarget;
|
|
26513
|
+
paused?: boolean;
|
|
26514
|
+
/** Idempotency key — prevents duplicate trigger creation per project+environment */
|
|
26515
|
+
idempotencyKey?: string;
|
|
26516
|
+
}
|
|
26517
|
+
interface UpdateTriggerOptions {
|
|
26518
|
+
name?: string;
|
|
26519
|
+
source?: TriggerSource;
|
|
26520
|
+
paused?: boolean;
|
|
26521
|
+
}
|
|
26522
|
+
interface Trigger {
|
|
26523
|
+
id: string;
|
|
26524
|
+
name: string;
|
|
26525
|
+
targetType: TriggerTargetType;
|
|
26526
|
+
sourceType: TriggerSourceType;
|
|
26527
|
+
cronExpression: string | null;
|
|
26528
|
+
eventName: string | null;
|
|
26529
|
+
handlerPath: string | null;
|
|
26530
|
+
callbackUrl: string | null;
|
|
26531
|
+
payload: unknown;
|
|
26532
|
+
status: TriggerStatus;
|
|
26533
|
+
nextRunAt: string | null;
|
|
26534
|
+
lastRunAt: string | null;
|
|
26535
|
+
createdAt: string;
|
|
26536
|
+
updatedAt: string;
|
|
26537
|
+
}
|
|
26538
|
+
interface ListTriggersResult {
|
|
26539
|
+
triggers: Trigger[];
|
|
26540
|
+
}
|
|
26541
|
+
interface PublishEventResult {
|
|
26542
|
+
dispatched: number;
|
|
26543
|
+
eventName: string;
|
|
26544
|
+
}
|
|
26545
|
+
declare class TriggersClient {
|
|
26546
|
+
/** Create a new trigger (cron or event source, task/run/http target) */
|
|
26547
|
+
static create(config: SylphxConfig, options: CreateTriggerOptions): Promise<Trigger>;
|
|
26548
|
+
/** List all triggers for the project */
|
|
26549
|
+
static list(config: SylphxConfig): Promise<ListTriggersResult>;
|
|
26550
|
+
/** Get a trigger by ID */
|
|
26551
|
+
static get(config: SylphxConfig, triggerId: string): Promise<Trigger>;
|
|
26552
|
+
/** Update a trigger */
|
|
26553
|
+
static update(config: SylphxConfig, triggerId: string, options: UpdateTriggerOptions): Promise<Trigger>;
|
|
26554
|
+
/** Delete a trigger */
|
|
26555
|
+
static delete(config: SylphxConfig, triggerId: string): Promise<{
|
|
26556
|
+
success: boolean;
|
|
26557
|
+
}>;
|
|
26558
|
+
/** Pause a trigger */
|
|
26559
|
+
static pause(config: SylphxConfig, triggerId: string): Promise<Trigger>;
|
|
26560
|
+
/** Resume a paused trigger */
|
|
26561
|
+
static resume(config: SylphxConfig, triggerId: string): Promise<Trigger>;
|
|
26562
|
+
/** Fire a trigger immediately (one-shot, regardless of schedule) */
|
|
26563
|
+
static fire(config: SylphxConfig, triggerId: string): Promise<{
|
|
26564
|
+
success: boolean;
|
|
26565
|
+
message: string;
|
|
26566
|
+
}>;
|
|
26567
|
+
/**
|
|
26568
|
+
* Publish an event — dispatches all active event triggers matching the event name.
|
|
26569
|
+
*
|
|
26570
|
+
* @example
|
|
26571
|
+
* ```typescript
|
|
26572
|
+
* await TriggersClient.publishEvent(config, 'user.signup', { userId: '123', plan: 'pro' })
|
|
26573
|
+
* ```
|
|
26574
|
+
*/
|
|
26575
|
+
/**
|
|
26576
|
+
* Publish an event — dispatches all active event triggers matching the event name.
|
|
26577
|
+
* Endpoint: POST /triggers/events
|
|
26578
|
+
*
|
|
26579
|
+
* @example
|
|
26580
|
+
* ```typescript
|
|
26581
|
+
* await TriggersClient.publishEvent(config, 'user.signup', { userId: '123', plan: 'pro' })
|
|
26582
|
+
* ```
|
|
26583
|
+
*/
|
|
26584
|
+
static publishEvent(config: SylphxConfig, eventName: string, payload?: Record<string, unknown>): Promise<PublishEventResult>;
|
|
26585
|
+
}
|
|
26586
|
+
|
|
26587
|
+
export { ACHIEVEMENT_TIER_CONFIG, type AIListModelsOptions, type AIListModelsResponse, type AIMessage, type AIMessageRole, type AIModel, type AIModelInfo, type AIModelsResponse, type AIProvider, type AIRateLimitInfo, type AIRateLimitResponse, type AIRequestType, type AIStreamChunk, type AITool, type AIToolCall, type AIUsageResponse, type AIUsageStats, type AccessTokenPayload, type AchievementCategory, type AchievementCriteria, type AchievementCriterion, type AchievementDefinition, type AchievementTier, type AchievementType, type AchievementUnlockEvent, type AdminUser, AuthenticationError, AuthorizationError, type BalanceResponse, type BatchEvent, type BatchIndexInput, type BatchIndexResult, type Breadcrumb, type BuildLog, type BuildLogHistoryResponse, type CaptureExceptionRequest, type CaptureMessageRequest, type ChatCompletionInput, type ChatCompletionResponse, type ChatInput, type ChatMessage, type ChatResult, type ChatStreamChunk, type CheckoutRequest, type CheckoutResponse, type CircuitBreakerConfig, CircuitBreakerOpenError, type CircuitState, type CommandResult, type ConsentCategory, type ConsentHistoryEntry, type ConsentHistoryResult, type ConsentPurposeDefaults, type ConsentType, type ContentPart, type CreateOrgInput, type CreatePermissionInput, type CreateRoleInput, type CreateRunOptions, type CreateTriggerOptions, type CriteriaOperator, type CronInput, type CronSchedule, type CronSource, type DatabaseConnectionInfo, type DatabaseStatus, type DatabaseStatusInfo, type DebugCategory, type DeduplicationConfig, type DeleteDocumentInput, type DeployHistoryResponse, type DeployInfo, type DeployStatus, type DynamicRestClient, ERROR_CODE_STATUS, type EmbedInput, type EmbedResult, type EmbeddingInput, type EmbeddingResponse, type LeaderboardEntry as EngagementLeaderboardEntry, type LeaderboardResult as EngagementLeaderboardResult, type EnvVar, type ErrorCode, type ErrorResponse, type EventSource, type ExceptionFrame, type ExceptionValue, type ExecEvent, type ExecOptions, type ExecResult, type FacetsResponse, type FileEvent, type FileInfo, type FileUploadOptions, type FlagContext, type FlagResult, type GetConsentHistoryInput, type GetConsentsInput, type GetFacetsInput, type GetSecretInput, type GetSecretResult, type GetSecretsInput, type GetSecretsResult, type HttpTarget, type IdentifyInput, type IndexDocumentInput, type IndexDocumentResult, InvalidConnectionUrlError, type InviteMemberInput, type InviteUserRequest, type InviteUserResponse, type KvExpireRequest, type KvHgetRequest, type KvHgetallRequest, type KvHsetRequest, type KvIncrRequest, type KvLpushRequest, type KvLrangeRequest, type KvMgetRequest, type KvMsetRequest, type KvRateLimitRequest, type KvRateLimitResult, type KvScanOptions, type KvScanResult, type KvSetOptions, type KvSetRequest, type KvZMember, type KvZaddRequest, type KvZrangeRequest, type LeaderboardAggregation, type LeaderboardDefinition, type LeaderboardEntry$1 as LeaderboardEntry, type LeaderboardOptions, type LeaderboardQueryOptions, type LeaderboardResetPeriod, type LeaderboardResult$1 as LeaderboardResult, type LeaderboardSortDirection, type LinkAnonymousConsentsInput, type ListRunsOptions, type ListRunsResult, type ListScheduledEmailsOptions, type ListSecretKeysInput, type ListTriggersResult, type ListUsersOptions, type ListUsersResult, type LoginHistoryEntry, type LoginRequest, type LoginResponse, type MeResponse, type MemberPermissionsResult, type MonitoringResponse, type MonitoringSeverity, type NativeStepContext, type NativeTaskDefinition, type TaskRunStatus as NativeTaskRunStatus, NetworkError, NotFoundError, type OrgRole, type OrgTokenPayload, type Organization, type OrganizationInvitation, type OrganizationMember, type OrganizationMembership, type PageInput, type PaginatedResponse, type PaginationInput, type ParsedConnectionUrl, type Permission, type Plan, type PortalRequest, type PortalResponse, type ProcessEvent, type ProcessInfo, type ProcessStartOptions, type ProcessSummary, type PublishEventResult, type PushNotification, type PushNotificationPayload, type PushServiceWorkerConfig, type PushSubscription, RETRYABLE_CODES, RateLimitError, type RealtimeEmitRequest, type RealtimeEmitResponse, type RealtimeHistoryRequest, type RealtimeHistoryResponse, type RecordActivityInput, type RecordActivityResult, type RedeemReferralInput, type RedeemResult, type ReferralCode, type ReferralStats, type RegisterInput, type RegisterRequest, type RegisterResponse, type RestClient, type RestClientConfig, type RestDynamicConfig, type paths as RestPaths, type RetryConfig, type RevokeTokenOptions, type Role, type RollbackDeployRequest, type Run, RunHandle, type RunLogsResult, type RunResourceSpec, type RunResult, type RunStatus, type RunTarget, type RunVolumeMount, type CreateRunOptions as RunWorkerOptions, RunsClient, SandboxClient, type SandboxFile, SandboxFiles, type SandboxOptions, SandboxProcesses, type SandboxRecord, SandboxWatch, type ScheduleEmailOptions, type ScheduledEmail, type ScheduledEmailStats, type ScheduledEmailsResult, type SearchInput, type SearchResponse, type SearchResultItem, type SearchStatsResult, type SearchType, type SecretKeyInfo, type SecuritySettings, type SendEmailOptions, type SendResult, type SendTemplatedEmailOptions, type SendToUserOptions, type SessionResult, type SetConsentsInput, type SetEnvVarRequest, type SignedUrlOptions, type SignedUrlResult, StepCompleteSignal, StepSleepSignal, type StreakDefinition, type StreakFrequency, type StreakState, type StreamMessage, type SubmitScoreInput, type SubmitScoreResult, type Subscription, type SuccessResponse, type SylphxClientInput, type SylphxConfig, type SylphxConfigInput, SylphxError, type SylphxErrorCode, type SylphxErrorOptions, type TaskInput, type TaskResult, type TaskStatus, type TaskTarget, type TextCompletionInput, type TextCompletionResponse, TimeoutError, type TokenIntrospectionResult, type TokenResponse, type Tool, type ToolCall, type TrackClickInput, type TrackInput, type Trigger, type TriggerDeployRequest, type TriggerSource, type TriggerSourceType, type TriggerStatus, type TriggerTarget, type TriggerTargetType, TriggersClient, type TwoFactorVerifyRequest, type UpdateOrgInput, type UpdateRoleInput, type UpdateTriggerOptions, type UploadProgressEvent, type UploadResult, type UpsertDocumentInput, type UpsertDocumentResult, type UsageResponse, type User, type UserAchievement, type UserConsent, type UserProfile, ValidationError, type VisionInput, type WatchEntry, type WatchOptions, type WebhookConfig, type WebhookConfigUpdate, type WebhookDeliveriesResult, type WebhookDelivery, type WebhookStats, RunHandle as WorkerHandle, type RunLogsResult as WorkerLogsResult, type RunResourceSpec as WorkerResourceSpec, type RunResult as WorkerResult, type Run as WorkerRun, type RunStatus as WorkerStatus, type RunVolumeMount as WorkerVolumeMount, WorkersClient, acceptAllConsents, acceptOrganizationInvitation, assignMemberRole, batchIndex, canDeleteOrganization, canManageMembers, canManageSettings, cancelScheduledEmail, cancelTask, captureException, captureExceptionRaw, captureMessage, chat, chatStream, checkFlag, complete, createCheckout, createClient, createConfig, createCron, createDynamicRestClient, createOrganization, createPermission, createPortalSession, createRestClient, createRole, createServerClient, createServiceWorkerScript, createStepContext, createTasksHandler, createTracker, debugError, debugLog, debugTimer, debugWarn, declineOptionalConsents, deleteCron, deleteDocument, deleteEnvVar, deleteFile, deleteOrganization, deletePermission, deleteRole, deleteUser, disableDebug, embed, enableDebug, exponentialBackoff, extendedSignUp, forgotPassword, generateAnonymousId, getAchievement, getAchievementPoints, getAchievements, getAllFlags, getAllSecrets, getAllStreaks, getBillingBalance, getBillingUsage, getBuildLogHistory, getCircuitBreakerState, getConsentHistory, getConsentTypes, getDatabaseConnectionString, getDatabaseStatus, getDebugMode, getDeployHistory, getDeployStatus, getErrorCode, getErrorMessage, getFacets, getFileInfo, getFileUrl, getFlagPayload, getFlags, getLeaderboard, getMemberPermissions, getMyReferralCode, getOrganization, getOrganizationInvitations, getOrganizationMembers, getOrganizations, getPlans, getPushPreferences, getRealtimeHistory, getReferralLeaderboard, getReferralStats, getRestErrorMessage, getRole, getScheduledEmail, getScheduledEmailStats, getSearchStats, getSecret, getSecrets, getSession, getSignedUrl, getStreak, getSubscription, getTask, getUser, getUserByEmail, getUserConsents, getUserLeaderboardRank, getVariant, getWebhookConfig, getWebhookDeliveries, getWebhookDelivery, getWebhookStats, hasAllPermissions, hasAnyPermission, hasConsent, hasError, hasPermission, hasRole, hasSecret, identify, incrementAchievementProgress, indexDocument, initPushServiceWorker, installGlobalDebugHelpers, introspectToken, inviteOrganizationMember, inviteUser, isEmailConfigured, isEnabled, isRetryableError, isSylphxError, kvDelete, kvExists, kvExpire, kvGet, kvGetJSON, kvHget, kvHgetall, kvHset, kvIncr, kvLpush, kvLrange, kvMget, kvMset, kvRateLimit, kvScan, kvSet, kvSetJSON, kvZadd, kvZrange, leaveOrganization, linkAnonymousConsents, listEnvVars, listPermissions, listRoles, listScheduledEmails, listSecretKeys, listTasks, listUsers, page, pauseCron, realtimeEmit, recordStreakActivity, recoverStreak, redeemReferralCode, refreshToken, regenerateReferralCode, registerPush, registerPushServiceWorker, removeOrganizationMember, replayWebhookDelivery, rescheduleEmail, resetCircuitBreaker, resetDebugModeCache, resetPassword, resumeCron, revokeAllTokens, revokeOrganizationInvitation, revokeToken, rollbackDeploy, scheduleEmail, scheduleTask, search, sendEmail, sendEmailToUser, sendPush, sendTemplatedEmail, setConsents, setEnvVar, signIn, signOut, signUp, streamToString, submitScore, suspendUser, switchOrg, toSylphxError, track, trackBatch, trackClick, triggerDeploy, unlockAchievement, unregisterPush, updateOrganization, updateOrganizationMemberRole, updatePushPreferences, updateRole, updateUser, updateUserMetadata, updateWebhookConfig, uploadAvatar, uploadFile, upsertDocument, verifyEmail, verifySignature as verifyTaskSignature, verifyTwoFactor, withToken };
|