sst 3.4.24 → 3.4.26

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.
@@ -0,0 +1,185 @@
1
+ import { AwsOptions } from "./client.js";
2
+ /**
3
+ * The `task` client SDK is available through the following.
4
+ *
5
+ * @example
6
+ * ```js title="src/app.ts"
7
+ * import { task } from "sst/aws/task";
8
+ * ```
9
+ */
10
+ export declare namespace task {
11
+ /**
12
+ * The link data for the task.
13
+ *
14
+ * @example
15
+ * For example, let's say you have a task.
16
+ *
17
+ * ```js title="sst.config.ts"
18
+ * cluster.addTask("MyTask");
19
+ * ```
20
+ *
21
+ * `Resource.MyTask` will have all the link data.
22
+ *
23
+ * ```js title="src/app.ts"
24
+ * import { Resource } from "sst";
25
+ *
26
+ * console.log(Resource.MyTask);
27
+ * ```
28
+ */
29
+ export interface Resource {
30
+ /**
31
+ * The ARN of the cluster.
32
+ */
33
+ cluster: string;
34
+ /**
35
+ * The ARN of the task definition.
36
+ */
37
+ taskDefinition: string;
38
+ /**
39
+ * The subnets to use for the task.
40
+ */
41
+ subnets: string[];
42
+ /**
43
+ * The security groups to use for the task.
44
+ */
45
+ securityGroups: string[];
46
+ /**
47
+ * Whether to assign a public IP address to the task.
48
+ */
49
+ assignPublicIp: boolean;
50
+ /**
51
+ * The names of the containers in the task.
52
+ */
53
+ containers: string[];
54
+ }
55
+ export interface Options {
56
+ /**
57
+ * Configure the AWS client.
58
+ */
59
+ aws?: AwsOptions;
60
+ }
61
+ interface Task {
62
+ /**
63
+ * The ARN of the task.
64
+ */
65
+ arn: string;
66
+ /**
67
+ * The status of the task.
68
+ */
69
+ status: string;
70
+ }
71
+ export interface DescribeResponse extends Task {
72
+ /**
73
+ * The raw response from the AWS ECS DescribeTasks API.
74
+ * @see [@aws-sdk/client-ecs.DescribeTasksResponse](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ecs/Interface/DescribeTasksResponse/)
75
+ */
76
+ response: any;
77
+ }
78
+ export interface RunResponse extends Task {
79
+ /**
80
+ * The raw response from the AWS ECS RunTask API.
81
+ * @see [@aws-sdk/client-ecs.RunTaskResponse](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ecs/Interface/RunTaskResponse/)
82
+ */
83
+ response: any;
84
+ }
85
+ export interface StopResponse extends Task {
86
+ /**
87
+ * The raw response from the AWS ECS StopTask API.
88
+ * @see [@aws-sdk/client-ecs.StopTaskResponse](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ecs/Interface/StopTaskResponse/)
89
+ */
90
+ response: any;
91
+ }
92
+ /**
93
+ * Gets the details of a task. Tasks stopped longer than 1 hour are not returned.
94
+ * @example
95
+ * For example, let's say you have started task.
96
+ *
97
+ * ```js title="src/app.ts"
98
+ * import { Resource } from "sst";
99
+ * import { task } from "sst/aws/task";
100
+ *
101
+ * const runRet = await task.run(Resource.MyTask);
102
+ * const taskArn = runRet.tasks[0].taskArn;
103
+ * ```
104
+ *
105
+ * You can get the details of the task with the following.
106
+ *
107
+ * ```js title="src/app.ts"
108
+ * const describeRet = await task.describe(Resource.MyTask, taskArn);
109
+ * ```
110
+ */
111
+ export function describe(resource: Resource, task: string, options?: Options): Promise<DescribeResponse>;
112
+ /**
113
+ * Runs a task.
114
+ *
115
+ * @example
116
+ *
117
+ * For example, let's say you have a task.
118
+ *
119
+ * ```js title="sst.config.ts"
120
+ * cluster.addTask("MyTask");
121
+ * ```
122
+ *
123
+ * You can run it in your application with the following.
124
+ *
125
+ * ```js title="src/app.ts"
126
+ * import { Resource } from "sst";
127
+ * import { task } from "sst/aws/task";
128
+ *
129
+ * const runRet = await task.run(Resource.MyTask);
130
+ * const taskArn = runRet.tasks[0].taskArn;
131
+ * ```
132
+ *
133
+ * `taskArn` is the ARN of the task. You can pass it to the `describe` function to get
134
+ * the status of the task; or to the `stop` function to stop the task.
135
+ *
136
+ * You can also pass in environment variables to the task.
137
+ *
138
+ * ```js title="src/app.ts"
139
+ * await task.run(Resource.MyTask, {
140
+ * MY_ENV_VAR: "my-value",
141
+ * });
142
+ * ```
143
+ */
144
+ export function run(resource: Resource, environment?: Record<string, string>, options?: {
145
+ aws?: AwsOptions;
146
+ }): Promise<RunResponse>;
147
+ /**
148
+ * Stops a task.
149
+ *
150
+ * @example
151
+ *
152
+ * For example, let's say you have started a task.
153
+ *
154
+ * ```js title="src/app.ts"
155
+ * import { Resource } from "sst";
156
+ * import { task } from "sst/aws/task";
157
+ *
158
+ * const runRet = await task.run(Resource.MyTask);
159
+ * const taskArn = runRet.tasks[0].taskArn;
160
+ * ```
161
+ *
162
+ * You can stop the task with the following.
163
+ *
164
+ * ```js title="src/app.ts"
165
+ * const stopRet = await task.stop(Resource.MyTask, taskArn);
166
+ *
167
+ * // check if the task is stopped
168
+ * console.log(stopRet.task?.lastStatus);
169
+ * ```
170
+ */
171
+ export function stop(resource: Resource, task: string, options?: Options): Promise<StopResponse>;
172
+ export class DescribeError extends Error {
173
+ readonly response: Response;
174
+ constructor(response: Response);
175
+ }
176
+ export class RunError extends Error {
177
+ readonly response: Response;
178
+ constructor(response: Response);
179
+ }
180
+ export class StopError extends Error {
181
+ readonly response: Response;
182
+ constructor(response: Response);
183
+ }
184
+ export {};
185
+ }
@@ -0,0 +1,217 @@
1
+ import { client } from "./client.js";
2
+ /**
3
+ * The `task` client SDK is available through the following.
4
+ *
5
+ * @example
6
+ * ```js title="src/app.ts"
7
+ * import { task } from "sst/aws/task";
8
+ * ```
9
+ */
10
+ export var task;
11
+ (function (task_1) {
12
+ function url(region, options) {
13
+ if (options?.region)
14
+ region = options.region;
15
+ return `https://ecs.${region}.amazonaws.com/`;
16
+ }
17
+ /**
18
+ * Gets the details of a task. Tasks stopped longer than 1 hour are not returned.
19
+ * @example
20
+ * For example, let's say you have started task.
21
+ *
22
+ * ```js title="src/app.ts"
23
+ * import { Resource } from "sst";
24
+ * import { task } from "sst/aws/task";
25
+ *
26
+ * const runRet = await task.run(Resource.MyTask);
27
+ * const taskArn = runRet.tasks[0].taskArn;
28
+ * ```
29
+ *
30
+ * You can get the details of the task with the following.
31
+ *
32
+ * ```js title="src/app.ts"
33
+ * const describeRet = await task.describe(Resource.MyTask, taskArn);
34
+ * ```
35
+ */
36
+ async function describe(resource, task, options) {
37
+ const c = await client();
38
+ const u = url(c.region, options?.aws);
39
+ const res = await c.fetch(u, {
40
+ method: "POST",
41
+ aws: options?.aws,
42
+ headers: {
43
+ "X-Amz-Target": "AmazonEC2ContainerServiceV20141113.DescribeTasks",
44
+ "Content-Type": "application/x-amz-json-1.1",
45
+ },
46
+ body: JSON.stringify({
47
+ cluster: resource.cluster,
48
+ tasks: [task],
49
+ }),
50
+ });
51
+ if (!res.ok)
52
+ throw new DescribeError(res);
53
+ const data = (await res.json());
54
+ if (!data.tasks?.length)
55
+ throw new DescribeError(res);
56
+ return {
57
+ arn: data.tasks[0].taskArn,
58
+ status: data.tasks[0].lastStatus,
59
+ response: data,
60
+ };
61
+ }
62
+ task_1.describe = describe;
63
+ /**
64
+ * Runs a task.
65
+ *
66
+ * @example
67
+ *
68
+ * For example, let's say you have a task.
69
+ *
70
+ * ```js title="sst.config.ts"
71
+ * cluster.addTask("MyTask");
72
+ * ```
73
+ *
74
+ * You can run it in your application with the following.
75
+ *
76
+ * ```js title="src/app.ts"
77
+ * import { Resource } from "sst";
78
+ * import { task } from "sst/aws/task";
79
+ *
80
+ * const runRet = await task.run(Resource.MyTask);
81
+ * const taskArn = runRet.tasks[0].taskArn;
82
+ * ```
83
+ *
84
+ * `taskArn` is the ARN of the task. You can pass it to the `describe` function to get
85
+ * the status of the task; or to the `stop` function to stop the task.
86
+ *
87
+ * You can also pass in environment variables to the task.
88
+ *
89
+ * ```js title="src/app.ts"
90
+ * await task.run(Resource.MyTask, {
91
+ * MY_ENV_VAR: "my-value",
92
+ * });
93
+ * ```
94
+ */
95
+ async function run(resource, environment, options) {
96
+ const c = await client();
97
+ const u = url(c.region, options?.aws);
98
+ const res = await c.fetch(u, {
99
+ method: "POST",
100
+ aws: options?.aws,
101
+ headers: {
102
+ "X-Amz-Target": "AmazonEC2ContainerServiceV20141113.RunTask",
103
+ "Content-Type": "application/x-amz-json-1.1",
104
+ },
105
+ body: JSON.stringify({
106
+ cluster: resource.cluster,
107
+ launchType: "FARGATE",
108
+ taskDefinition: resource.taskDefinition,
109
+ networkConfiguration: {
110
+ awsvpcConfiguration: {
111
+ subnets: resource.subnets,
112
+ securityGroups: resource.securityGroups,
113
+ assignPublicIp: resource.assignPublicIp ? "ENABLED" : "DISABLED",
114
+ },
115
+ },
116
+ overrides: {
117
+ containerOverrides: resource.containers.map((name) => ({
118
+ name,
119
+ environment: Object.entries(environment ?? {}).map(([key, value]) => ({
120
+ name: key,
121
+ value,
122
+ })),
123
+ })),
124
+ },
125
+ }),
126
+ });
127
+ if (!res.ok)
128
+ throw new RunError(res);
129
+ const data = (await res.json());
130
+ if (!data.tasks?.length)
131
+ throw new RunError(res);
132
+ return {
133
+ arn: data.tasks[0].taskArn,
134
+ status: data.tasks[0].lastStatus,
135
+ response: data,
136
+ };
137
+ }
138
+ task_1.run = run;
139
+ /**
140
+ * Stops a task.
141
+ *
142
+ * @example
143
+ *
144
+ * For example, let's say you have started a task.
145
+ *
146
+ * ```js title="src/app.ts"
147
+ * import { Resource } from "sst";
148
+ * import { task } from "sst/aws/task";
149
+ *
150
+ * const runRet = await task.run(Resource.MyTask);
151
+ * const taskArn = runRet.tasks[0].taskArn;
152
+ * ```
153
+ *
154
+ * You can stop the task with the following.
155
+ *
156
+ * ```js title="src/app.ts"
157
+ * const stopRet = await task.stop(Resource.MyTask, taskArn);
158
+ *
159
+ * // check if the task is stopped
160
+ * console.log(stopRet.task?.lastStatus);
161
+ * ```
162
+ */
163
+ async function stop(resource, task, options) {
164
+ const c = await client();
165
+ const u = url(c.region, options?.aws);
166
+ const res = await c.fetch(u, {
167
+ method: "POST",
168
+ aws: options?.aws,
169
+ headers: {
170
+ "X-Amz-Target": "AmazonEC2ContainerServiceV20141113.StopTask",
171
+ "Content-Type": "application/x-amz-json-1.1",
172
+ },
173
+ body: JSON.stringify({
174
+ cluster: resource.cluster,
175
+ task,
176
+ }),
177
+ });
178
+ if (!res.ok)
179
+ throw new StopError(res);
180
+ const data = (await res.json());
181
+ if (!data.task)
182
+ throw new StopError(res);
183
+ return {
184
+ arn: data.task.taskArn,
185
+ status: data.task.lastStatus,
186
+ response: data,
187
+ };
188
+ }
189
+ task_1.stop = stop;
190
+ class DescribeError extends Error {
191
+ response;
192
+ constructor(response) {
193
+ super("Failed to describe task");
194
+ this.response = response;
195
+ console.log(response);
196
+ }
197
+ }
198
+ task_1.DescribeError = DescribeError;
199
+ class RunError extends Error {
200
+ response;
201
+ constructor(response) {
202
+ super("Failed to run task");
203
+ this.response = response;
204
+ console.log(response);
205
+ }
206
+ }
207
+ task_1.RunError = RunError;
208
+ class StopError extends Error {
209
+ response;
210
+ constructor(response) {
211
+ super("Failed to stop task");
212
+ this.response = response;
213
+ console.log(response);
214
+ }
215
+ }
216
+ task_1.StopError = StopError;
217
+ })(task || (task = {}));
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "sst",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
- "version": "3.4.24",
6
+ "version": "3.4.26",
7
7
  "main": "./dist/index.js",
8
8
  "exports": {
9
9
  ".": "./dist/index.js",
@@ -46,11 +46,11 @@
46
46
  }
47
47
  },
48
48
  "optionalDependencies": {
49
- "sst-linux-x86": "3.4.24",
50
- "sst-linux-x64": "3.4.24",
51
- "sst-linux-arm64": "3.4.24",
52
- "sst-darwin-x64": "3.4.24",
53
- "sst-darwin-arm64": "3.4.24"
49
+ "sst-linux-x64": "3.4.26",
50
+ "sst-linux-x86": "3.4.26",
51
+ "sst-linux-arm64": "3.4.26",
52
+ "sst-darwin-x64": "3.4.26",
53
+ "sst-darwin-arm64": "3.4.26"
54
54
  },
55
55
  "dependencies": {
56
56
  "aws4fetch": "^1.0.18",