@sst-community/sst 0.0.0-placeholder.0 → 4.17.2
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 +86 -0
- package/bin/sst.mjs +33 -0
- package/dist/auth/adapter/adapter.d.ts +23 -0
- package/dist/auth/adapter/adapter.js +4 -0
- package/dist/auth/adapter/apple.d.ts +5 -0
- package/dist/auth/adapter/apple.js +22 -0
- package/dist/auth/adapter/code.d.ts +7 -0
- package/dist/auth/adapter/code.js +47 -0
- package/dist/auth/adapter/facebook.d.ts +5 -0
- package/dist/auth/adapter/facebook.js +27 -0
- package/dist/auth/adapter/github.d.ts +7 -0
- package/dist/auth/adapter/github.js +15 -0
- package/dist/auth/adapter/google.d.ts +17 -0
- package/dist/auth/adapter/google.js +22 -0
- package/dist/auth/adapter/index.d.ts +11 -0
- package/dist/auth/adapter/index.js +10 -0
- package/dist/auth/adapter/link.d.ts +5 -0
- package/dist/auth/adapter/link.js +27 -0
- package/dist/auth/adapter/microsoft.d.ts +11 -0
- package/dist/auth/adapter/microsoft.js +16 -0
- package/dist/auth/adapter/oauth.d.ts +33 -0
- package/dist/auth/adapter/oauth.js +82 -0
- package/dist/auth/adapter/oidc.d.ts +19 -0
- package/dist/auth/adapter/oidc.js +48 -0
- package/dist/auth/adapter/spotify.d.ts +12 -0
- package/dist/auth/adapter/spotify.js +22 -0
- package/dist/auth/example/bun.d.ts +2 -0
- package/dist/auth/example/bun.js +46 -0
- package/dist/auth/handler.d.ts +57 -0
- package/dist/auth/handler.js +206 -0
- package/dist/auth/index.d.ts +10 -0
- package/dist/auth/index.js +10 -0
- package/dist/auth/session.d.ts +25 -0
- package/dist/auth/session.js +28 -0
- package/dist/aws/auth.d.ts +9 -0
- package/dist/aws/auth.js +12 -0
- package/dist/aws/bus.d.ts +28 -0
- package/dist/aws/bus.js +66 -0
- package/dist/aws/client.d.ts +8 -0
- package/dist/aws/client.js +54 -0
- package/dist/aws/realtime.d.ts +118 -0
- package/dist/aws/realtime.js +83 -0
- package/dist/aws/task.d.ts +228 -0
- package/dist/aws/task.js +232 -0
- package/dist/aws/workflow.d.ts +324 -0
- package/dist/aws/workflow.js +504 -0
- package/dist/event/index.d.ts +72 -0
- package/dist/event/index.js +35 -0
- package/dist/event/validator.d.ts +4 -0
- package/dist/event/validator.js +11 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +17 -0
- package/dist/realtime/index.d.ts +25 -0
- package/dist/realtime/index.js +24 -0
- package/dist/resource/cloudflare.d.ts +5 -0
- package/dist/resource/cloudflare.js +30 -0
- package/dist/resource/index.d.ts +1 -0
- package/dist/resource/index.js +1 -0
- package/dist/resource/node.d.ts +4 -0
- package/dist/resource/node.js +38 -0
- package/dist/resource/shared.d.ts +9 -0
- package/dist/resource/shared.js +62 -0
- package/dist/resource.d.ts +1 -0
- package/dist/resource.js +1 -0
- package/dist/util/prettify.d.ts +3 -0
- package/dist/util/prettify.js +1 -0
- package/dist/vector/index.d.ts +247 -0
- package/dist/vector/index.js +107 -0
- package/package.json +73 -1
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import * as durable from "@aws/durable-execution-sdk-js";
|
|
2
|
+
import { type AwsOptions } from "./client.js";
|
|
3
|
+
/**
|
|
4
|
+
* The `workflow` SDK is a thin wrapper around the
|
|
5
|
+
* [`@aws/durable-execution-sdk-js`](https://www.npmjs.com/package/@aws/durable-execution-sdk-js)
|
|
6
|
+
* package and the AWS Lambda durable execution APIs.
|
|
7
|
+
*
|
|
8
|
+
* SST also adds a few helpers on top, including `ctx.stepWithRollback()`,
|
|
9
|
+
* `ctx.rollbackAll()`, and `ctx.waitUntil()`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts title="src/workflow.ts"
|
|
13
|
+
* import { workflow } from "sst/aws/workflow";
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* Use `stepWithRollback()` and `rollbackAll()` to register compensating actions.
|
|
18
|
+
*
|
|
19
|
+
* ```ts title="src/workflow.ts"
|
|
20
|
+
* import { workflow } from "sst/aws/workflow";
|
|
21
|
+
*
|
|
22
|
+
* export const handler = workflow.handler(async (_event, ctx) => {
|
|
23
|
+
* try {
|
|
24
|
+
* const order = await ctx.stepWithRollback("create-order", {
|
|
25
|
+
* run: async () => ({ orderId: "order_123" }),
|
|
26
|
+
* undo: async (error, result) => {
|
|
27
|
+
* await fetch(`https://example.com/orders/${result.orderId}`, {
|
|
28
|
+
* method: "DELETE",
|
|
29
|
+
* });
|
|
30
|
+
* },
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* await ctx.step("charge-card", async () => {
|
|
34
|
+
* throw new Error("Card declined");
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* return order;
|
|
38
|
+
* } catch (error) {
|
|
39
|
+
* await ctx.rollbackAll(error);
|
|
40
|
+
* throw error;
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* Use `waitUntil()` when you already know the exact time the workflow should resume.
|
|
47
|
+
*
|
|
48
|
+
* ```ts title="src/workflow.ts"
|
|
49
|
+
* import { workflow } from "sst/aws/workflow";
|
|
50
|
+
*
|
|
51
|
+
* export const handler = workflow.handler(
|
|
52
|
+
* async (_event, ctx) => {
|
|
53
|
+
* const resumeAt = new Date();
|
|
54
|
+
* resumeAt.setMinutes(resumeAt.getMinutes() + 10);
|
|
55
|
+
*
|
|
56
|
+
* await ctx.waitUntil("wait-for-follow-up", resumeAt);
|
|
57
|
+
*
|
|
58
|
+
* return ctx.step("send-follow-up", async () => {
|
|
59
|
+
* return { delivered: true };
|
|
60
|
+
* });
|
|
61
|
+
* },
|
|
62
|
+
* );
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare namespace workflow {
|
|
66
|
+
interface Context<TLogger extends durable.DurableLogger = durable.DurableLogger> extends durable.DurableContext<TLogger> {
|
|
67
|
+
/**
|
|
68
|
+
* Execute a durable step and register a compensating rollback step if it succeeds.
|
|
69
|
+
* If `run` throws, nothing is added to the rollback stack for that step.
|
|
70
|
+
*/
|
|
71
|
+
stepWithRollback<TOutput>(name: string, handler: StepWithRollbackHandler<TOutput, TLogger>, config?: StepConfig<TOutput>): durable.DurablePromise<TOutput>;
|
|
72
|
+
/**
|
|
73
|
+
* Wait until the provided time. Delays are rounded up to the nearest second.
|
|
74
|
+
*/
|
|
75
|
+
waitUntil(name: string, until: Date): durable.DurablePromise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Execute all registered rollback steps in reverse order.
|
|
78
|
+
*/
|
|
79
|
+
rollbackAll(error: unknown): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
type Handler<TEvent = any, TResult = any, TLogger extends durable.DurableLogger = durable.DurableLogger> = (event: TEvent, context: Context<TLogger>) => Promise<TResult>;
|
|
82
|
+
type Config = durable.DurableExecutionConfig;
|
|
83
|
+
type Duration = durable.Duration;
|
|
84
|
+
type StepConfig<TOutput = any> = durable.StepConfig<TOutput>;
|
|
85
|
+
type ExecutionStatus = "RUNNING" | "SUCCEEDED" | "FAILED" | "TIMED_OUT" | "STOPPED";
|
|
86
|
+
interface Resource {
|
|
87
|
+
/**
|
|
88
|
+
* The name of the workflow function.
|
|
89
|
+
*/
|
|
90
|
+
name: string;
|
|
91
|
+
/**
|
|
92
|
+
* The version or alias qualifier to invoke.
|
|
93
|
+
*
|
|
94
|
+
* Linked `sst.aws.Workflow` resources include this automatically.
|
|
95
|
+
*/
|
|
96
|
+
qualifier: string;
|
|
97
|
+
}
|
|
98
|
+
interface Options {
|
|
99
|
+
/**
|
|
100
|
+
* Configure the options for the [aws4fetch](https://github.com/mhart/aws4fetch)
|
|
101
|
+
* [`AWSClient`](https://github.com/mhart/aws4fetch?tab=readme-ov-file#new-awsclientoptions) used internally by the SDK.
|
|
102
|
+
*/
|
|
103
|
+
aws?: AwsOptions;
|
|
104
|
+
}
|
|
105
|
+
interface StartResponse {
|
|
106
|
+
/**
|
|
107
|
+
* The ARN of the durable execution.
|
|
108
|
+
*/
|
|
109
|
+
arn?: string;
|
|
110
|
+
/**
|
|
111
|
+
* The HTTP status code from Lambda.
|
|
112
|
+
*/
|
|
113
|
+
statusCode: number;
|
|
114
|
+
/**
|
|
115
|
+
* The function version that was executed.
|
|
116
|
+
*/
|
|
117
|
+
version?: string;
|
|
118
|
+
}
|
|
119
|
+
interface Execution {
|
|
120
|
+
/**
|
|
121
|
+
* The ARN of the durable execution.
|
|
122
|
+
*/
|
|
123
|
+
arn: string;
|
|
124
|
+
/**
|
|
125
|
+
* The durable execution name.
|
|
126
|
+
*/
|
|
127
|
+
name: string;
|
|
128
|
+
/**
|
|
129
|
+
* The ARN of the workflow function.
|
|
130
|
+
*/
|
|
131
|
+
functionArn: string;
|
|
132
|
+
/**
|
|
133
|
+
* The current execution status.
|
|
134
|
+
*/
|
|
135
|
+
status: ExecutionStatus;
|
|
136
|
+
/**
|
|
137
|
+
* When the execution started.
|
|
138
|
+
*/
|
|
139
|
+
createdAt: Date;
|
|
140
|
+
/**
|
|
141
|
+
* When the execution ended, if it has finished.
|
|
142
|
+
*/
|
|
143
|
+
endedAt?: Date;
|
|
144
|
+
}
|
|
145
|
+
interface ListResponse {
|
|
146
|
+
/**
|
|
147
|
+
* The matching executions.
|
|
148
|
+
*/
|
|
149
|
+
executions: Execution[];
|
|
150
|
+
}
|
|
151
|
+
interface DescribeResponse extends Execution {
|
|
152
|
+
/**
|
|
153
|
+
* The version that started the execution.
|
|
154
|
+
*/
|
|
155
|
+
version?: string;
|
|
156
|
+
}
|
|
157
|
+
interface StopResponse {
|
|
158
|
+
/**
|
|
159
|
+
* The ARN of the durable execution.
|
|
160
|
+
*/
|
|
161
|
+
arn: string;
|
|
162
|
+
/**
|
|
163
|
+
* The execution status after the stop call.
|
|
164
|
+
*/
|
|
165
|
+
status: "STOPPED";
|
|
166
|
+
/**
|
|
167
|
+
* When the execution was stopped.
|
|
168
|
+
*/
|
|
169
|
+
stoppedAt?: Date;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Create a durable workflow handler.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts title="src/workflow.ts"
|
|
176
|
+
* import { workflow } from "sst/aws/workflow";
|
|
177
|
+
*
|
|
178
|
+
* export const handler = workflow.handler(
|
|
179
|
+
* async (_event, ctx) => {
|
|
180
|
+
* const user = await ctx.step("load-user", async () => {
|
|
181
|
+
* return { id: "user_123", email: "alice@example.com" };
|
|
182
|
+
* });
|
|
183
|
+
*
|
|
184
|
+
* await ctx.wait("pause-before-email", "1 minute");
|
|
185
|
+
*
|
|
186
|
+
* return ctx.step("send-email", async () => {
|
|
187
|
+
* return { sent: true, userId: user.id };
|
|
188
|
+
* });
|
|
189
|
+
* },
|
|
190
|
+
* );
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
function handler<TEvent = any, TResult = any, TLogger extends durable.DurableLogger = durable.DurableLogger>(input: Handler<TEvent, TResult, TLogger>, config?: Config): durable.DurableLambdaHandler;
|
|
194
|
+
/**
|
|
195
|
+
* Start a new workflow execution.
|
|
196
|
+
*
|
|
197
|
+
* This is the equivalent to calling
|
|
198
|
+
* [`Invoke`](https://docs.aws.amazon.com/lambda/latest/api/API_Invoke.html)
|
|
199
|
+
* for a durable Lambda function, using the durable invocation flow described in
|
|
200
|
+
* [Invoking durable Lambda functions](https://docs.aws.amazon.com/lambda/latest/dg/durable-invoking.html).
|
|
201
|
+
*/
|
|
202
|
+
function start<TPayload = unknown>(resource: Resource, input: StartInput<TPayload>, options?: Options): Promise<StartResponse>;
|
|
203
|
+
/**
|
|
204
|
+
* List workflow executions.
|
|
205
|
+
*
|
|
206
|
+
* The SDK returns only the first page of results.
|
|
207
|
+
*/
|
|
208
|
+
function list(resource: Resource, query: ListQuery, options?: Options): Promise<ListResponse>;
|
|
209
|
+
/**
|
|
210
|
+
* Get the details for a single workflow execution.
|
|
211
|
+
*/
|
|
212
|
+
function describe(arn: string, options?: Options): Promise<DescribeResponse>;
|
|
213
|
+
/**
|
|
214
|
+
* Stop a running workflow execution.
|
|
215
|
+
*/
|
|
216
|
+
function stop(arn: string, input?: StopInput, options?: Options): Promise<StopResponse>;
|
|
217
|
+
/**
|
|
218
|
+
* Send a successful result for a pending workflow callback.
|
|
219
|
+
*
|
|
220
|
+
* This is the equivalent to calling
|
|
221
|
+
* [`SendDurableExecutionCallbackSuccess`](https://docs.aws.amazon.com/lambda/latest/api/API_SendDurableExecutionCallbackSuccess.html).
|
|
222
|
+
*/
|
|
223
|
+
function succeed<TPayload = unknown>(token: string, input?: SucceedInput<TPayload>, options?: Options): Promise<void>;
|
|
224
|
+
/**
|
|
225
|
+
* Send a failure result for a pending workflow callback.
|
|
226
|
+
*
|
|
227
|
+
* This is the equivalent to calling
|
|
228
|
+
* [`SendDurableExecutionCallbackFailure`](https://docs.aws.amazon.com/lambda/latest/api/API_SendDurableExecutionCallbackFailure.html).
|
|
229
|
+
*/
|
|
230
|
+
function fail(token: string, input: FailInput, options?: Options): Promise<void>;
|
|
231
|
+
/**
|
|
232
|
+
* Send a heartbeat for a pending workflow callback.
|
|
233
|
+
*
|
|
234
|
+
* This is useful when the external system handling the callback is still doing
|
|
235
|
+
* work and needs to prevent the callback from timing out.
|
|
236
|
+
*
|
|
237
|
+
* This is the equivalent to calling
|
|
238
|
+
* [`SendDurableExecutionCallbackHeartbeat`](https://docs.aws.amazon.com/lambda/latest/api/API_SendDurableExecutionCallbackHeartbeat.html).
|
|
239
|
+
*/
|
|
240
|
+
function heartbeat(token: string, options?: Options): Promise<void>;
|
|
241
|
+
class StartError extends Error {
|
|
242
|
+
readonly response: Response;
|
|
243
|
+
constructor(response: Response);
|
|
244
|
+
}
|
|
245
|
+
class ListError extends Error {
|
|
246
|
+
readonly response: Response;
|
|
247
|
+
constructor(response: Response);
|
|
248
|
+
}
|
|
249
|
+
class DescribeError extends Error {
|
|
250
|
+
readonly response: Response;
|
|
251
|
+
constructor(response: Response);
|
|
252
|
+
}
|
|
253
|
+
class StopError extends Error {
|
|
254
|
+
readonly response: Response;
|
|
255
|
+
constructor(response: Response);
|
|
256
|
+
}
|
|
257
|
+
class SucceedError extends Error {
|
|
258
|
+
readonly response: Response;
|
|
259
|
+
constructor(response: Response);
|
|
260
|
+
}
|
|
261
|
+
class FailError extends Error {
|
|
262
|
+
readonly response: Response;
|
|
263
|
+
constructor(response: Response);
|
|
264
|
+
}
|
|
265
|
+
class HeartbeatError extends Error {
|
|
266
|
+
readonly response: Response;
|
|
267
|
+
constructor(response: Response);
|
|
268
|
+
}
|
|
269
|
+
class RollbackError extends Error {
|
|
270
|
+
readonly stepName: string;
|
|
271
|
+
readonly originalError: unknown;
|
|
272
|
+
readonly undoError: unknown;
|
|
273
|
+
constructor(stepName: string, originalError: unknown, undoError: unknown);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
interface StepWithRollbackHandler<TOutput = any, TLogger extends durable.DurableLogger = durable.DurableLogger> {
|
|
277
|
+
/**
|
|
278
|
+
* The durable step to execute.
|
|
279
|
+
*/
|
|
280
|
+
run: durable.StepFunc<TOutput, TLogger>;
|
|
281
|
+
/**
|
|
282
|
+
* Called during rollback with the original error, the step result, and step context.
|
|
283
|
+
*/
|
|
284
|
+
undo: (error: unknown, value: TOutput, context: Parameters<durable.StepFunc<void, TLogger>>[0]) => Promise<void>;
|
|
285
|
+
}
|
|
286
|
+
interface StartInput<TPayload = unknown> {
|
|
287
|
+
/**
|
|
288
|
+
* The unique name for this workflow execution.
|
|
289
|
+
*/
|
|
290
|
+
name: string;
|
|
291
|
+
/**
|
|
292
|
+
* The event payload passed to the workflow handler.
|
|
293
|
+
*/
|
|
294
|
+
payload?: TPayload;
|
|
295
|
+
}
|
|
296
|
+
interface SucceedInput<TPayload = unknown> {
|
|
297
|
+
/**
|
|
298
|
+
* The payload to resolve the callback with.
|
|
299
|
+
*/
|
|
300
|
+
payload?: TPayload;
|
|
301
|
+
}
|
|
302
|
+
interface FailInput {
|
|
303
|
+
/**
|
|
304
|
+
* The error to reject the callback with. Supports an `Error`, a string,
|
|
305
|
+
* or an object with camelCase fields like `message`, `type`, `data`, and `stack`.
|
|
306
|
+
*/
|
|
307
|
+
error: unknown;
|
|
308
|
+
}
|
|
309
|
+
interface StopInput {
|
|
310
|
+
/**
|
|
311
|
+
* The error to reject the callback with. Supports an `Error`, a string,
|
|
312
|
+
* or an object with camelCase fields like `message`, `type`, `data`, and `stack`.
|
|
313
|
+
*/
|
|
314
|
+
error?: unknown;
|
|
315
|
+
}
|
|
316
|
+
interface ListQuery {
|
|
317
|
+
status?: workflow.ExecutionStatus;
|
|
318
|
+
createdAt?: {
|
|
319
|
+
from?: Date;
|
|
320
|
+
to?: Date;
|
|
321
|
+
order?: "asc" | "desc";
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
export {};
|