sst 2.38.7 → 2.38.8

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.
@@ -2,7 +2,7 @@ import { Construct, IConstruct } from "constructs";
2
2
  import { Role } from "aws-cdk-lib/aws-iam";
3
3
  import { IVersion, IFunction as CdkIFunction } from "aws-cdk-lib/aws-lambda";
4
4
  import { SSTConstruct } from "./Construct.js";
5
- import { NodeJSProps } from "./Function.js";
5
+ import { NodeJSProps, FunctionCopyFilesProps } from "./Function.js";
6
6
  import { Size } from "./util/size.js";
7
7
  import { Duration } from "./util/duration.js";
8
8
  import { Permissions } from "./util/permission.js";
@@ -16,6 +16,7 @@ export interface EdgeFunctionProps {
16
16
  environment?: Record<string, string>;
17
17
  bind?: SSTConstruct[];
18
18
  nodejs?: NodeJSProps;
19
+ copyFiles?: FunctionCopyFilesProps[];
19
20
  scopeOverride?: IConstruct;
20
21
  }
21
22
  export declare class EdgeFunction extends Construct {
@@ -12,7 +12,7 @@ import { Lazy, Duration as CdkDuration, CustomResource, } from "aws-cdk-lib/core
12
12
  import { useProject } from "../project.js";
13
13
  import { useRuntimeHandlers } from "../runtime/handlers.js";
14
14
  import { Stack } from "./Stack.js";
15
- import { useFunctions } from "./Function.js";
15
+ import { useFunctions, } from "./Function.js";
16
16
  import { bindEnvironment, bindPermissions, getReferencedSecrets, } from "./util/functionBinding.js";
17
17
  import { toCdkSize } from "./util/size.js";
18
18
  import { toCdkDuration } from "./util/duration.js";
@@ -43,10 +43,10 @@ export class EdgeFunction extends Construct {
43
43
  // them.
44
44
  this.scope = props.scopeOverride || this;
45
45
  this.props = {
46
- ...props,
47
46
  runtime: "nodejs18.x",
48
47
  timeout: 10,
49
48
  memorySize: 1024,
49
+ ...props,
50
50
  environment: props.environment || {},
51
51
  permissions: props.permissions || [],
52
52
  };
@@ -96,7 +96,7 @@ export class EdgeFunction extends Construct {
96
96
  }));
97
97
  }
98
98
  async buildAssetFromHandler() {
99
- const { nodejs } = this.props;
99
+ const { nodejs, copyFiles } = this.props;
100
100
  useFunctions().add(this.node.addr, {
101
101
  ...this.props,
102
102
  architecture: "x86_64",
@@ -107,6 +107,7 @@ export class EdgeFunction extends Construct {
107
107
  nodejs?.banner || "",
108
108
  ].join("\n"),
109
109
  },
110
+ copyFiles,
110
111
  });
111
112
  // Build function
112
113
  const result = await useRuntimeHandlers().build(this.node.addr, "deploy");
@@ -1,5 +1,6 @@
1
1
  import { Construct } from "constructs";
2
2
  import { Function as CdkFunction } from "aws-cdk-lib/aws-lambda";
3
+ import { Project } from "aws-cdk-lib/aws-codebuild";
3
4
  import { RetentionDays } from "aws-cdk-lib/aws-logs";
4
5
  import { SSTConstruct } from "./Construct.js";
5
6
  import { NodeJSProps, FunctionCopyFilesProps } from "./Function.js";
@@ -321,6 +322,9 @@ export declare class Job extends Construct implements SSTConstruct {
321
322
  * ```
322
323
  */
323
324
  addEnvironment(name: string, value: string): void;
325
+ get cdk(): {
326
+ codeBuildProject: Project;
327
+ };
324
328
  private createCodeBuildJob;
325
329
  private createLiveDevJob;
326
330
  private createLogRetention;
package/constructs/Job.js CHANGED
@@ -135,6 +135,11 @@ export class Job extends Construct {
135
135
  this.liveDevJob?.addEnvironment(name, value);
136
136
  this.addEnvironmentForCodeBuild(name, value);
137
137
  }
138
+ get cdk() {
139
+ return {
140
+ codeBuildProject: this.job,
141
+ };
142
+ }
138
143
  createCodeBuildJob() {
139
144
  const { cdk, runtime, handler, memorySize, timeout, container } = this.props;
140
145
  const app = this.node.root;
@@ -411,6 +411,7 @@ function handler(event) {
411
411
  ...environment,
412
412
  ...props.environment,
413
413
  },
414
+ ...cdk?.server,
414
415
  });
415
416
  bucket.grantReadWrite(fn.role);
416
417
  functions[name] = fn;
package/iot.js CHANGED
@@ -100,6 +100,7 @@ export const useIOT = lazy(async () => {
100
100
  secretKey: creds.secretAccessKey,
101
101
  sessionToken: creds.sessionToken,
102
102
  reconnectPeriod: 1,
103
+ keepalive: 60,
103
104
  });
104
105
  const PREFIX = `/sst/${project.config.name}/${project.config.stage}`;
105
106
  device.subscribe(`${PREFIX}/events`, { qos: 1 });
@@ -3,7 +3,7 @@ export interface EventBusResources {
3
3
  export declare const EventBus: EventBusResources;
4
4
  import { PutEventsCommandOutput } from "@aws-sdk/client-eventbridge";
5
5
  import { EventBridgeEvent } from "aws-lambda";
6
- import { ZodAny, ZodObject, ZodRawShape, z } from "zod";
6
+ import { ZodObject, ZodSchema, z } from "zod";
7
7
  /**
8
8
  * PutEventsCommandOutput is used in return type of createEvent, in case the consumer of SST builds
9
9
  * their project with declaration files, this is not portable. In order to allow TS to generate a
@@ -12,34 +12,60 @@ import { ZodAny, ZodObject, ZodRawShape, z } from "zod";
12
12
  * More information here: https://github.com/microsoft/TypeScript/issues/47663#issuecomment-1519138189
13
13
  */
14
14
  export { PutEventsCommandOutput };
15
- export declare function createEventBuilder<Bus extends keyof typeof EventBus, MetadataShape extends ZodRawShape | undefined, MetadataFunction extends () => any>(props: {
15
+ export declare function createEventBuilder<Bus extends keyof typeof EventBus, MetadataFunction extends () => any, Validator extends (schema: any) => (input: any) => any, MetadataSchema extends Parameters<Validator>[0]>(input: {
16
16
  bus: Bus;
17
- metadata?: MetadataShape;
17
+ metadata?: MetadataSchema;
18
18
  metadataFn?: MetadataFunction;
19
- }): <Type extends string, Shape extends ZodRawShape, Properties = z.objectOutputType<Shape, ZodAny, "strip">>(type: Type, properties: Shape) => {
20
- publish: undefined extends MetadataShape ? (properties: Properties) => Promise<PutEventsCommandOutput> : (properties: Properties, metadata: z.infer<ZodObject<Exclude<MetadataShape, undefined>, "strip", ZodAny>>) => Promise<void>;
19
+ validator: Validator;
20
+ }): <Type extends string, Schema extends Parameters<Validator>[0]>(type: Type, schema: Schema) => {
21
+ publish: undefined extends MetadataSchema ? (properties: inferParser<Schema>["in"]) => Promise<PutEventsCommandOutput> : (properties: inferParser<Schema>["in"], metadata: inferParser<MetadataSchema>["in"]) => Promise<void>;
21
22
  type: Type;
22
- shape: {
23
- metadata: Parameters<undefined extends MetadataShape ? (properties: Properties) => Promise<PutEventsCommandOutput> : (properties: Properties, metadata: z.infer<ZodObject<Exclude<MetadataShape, undefined>, "strip", ZodAny>>) => Promise<void>>[1];
24
- properties: Properties;
25
- metadataFn: ReturnType<MetadataFunction>;
23
+ $input: inferParser<Schema>["in"];
24
+ $output: inferParser<Schema>["out"];
25
+ $metadata: ReturnType<MetadataFunction>;
26
+ };
27
+ export declare function ZodValidator<Schema extends ZodSchema>(schema: Schema): (input: z.input<Schema>) => z.output<Schema>;
28
+ export type ParserZodEsque<TInput, TParsedInput> = {
29
+ _input: TInput;
30
+ _output: TParsedInput;
31
+ };
32
+ export type ParserValibotEsque<TInput, TParsedInput> = {
33
+ _types?: {
34
+ input: TInput;
35
+ output: TParsedInput;
26
36
  };
27
37
  };
38
+ export type ParserMyZodEsque<TInput> = {
39
+ parse: (input: any) => TInput;
40
+ };
41
+ export type ParserSuperstructEsque<TInput> = {
42
+ create: (input: unknown) => TInput;
43
+ };
44
+ export type ParserCustomValidatorEsque<TInput> = (input: unknown) => Promise<TInput> | TInput;
45
+ export type ParserYupEsque<TInput> = {
46
+ validateSync: (input: unknown) => TInput;
47
+ };
48
+ export type ParserScaleEsque<TInput> = {
49
+ assert(value: unknown): asserts value is TInput;
50
+ };
51
+ export type ParserWithoutInput<TInput> = ParserCustomValidatorEsque<TInput> | ParserMyZodEsque<TInput> | ParserScaleEsque<TInput> | ParserSuperstructEsque<TInput> | ParserYupEsque<TInput>;
52
+ export type ParserWithInputOutput<TInput, TParsedInput> = ParserZodEsque<TInput, TParsedInput> | ParserValibotEsque<TInput, TParsedInput>;
53
+ export type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
54
+ export type inferParser<TParser extends Parser> = TParser extends ParserWithInputOutput<infer $TIn, infer $TOut> ? {
55
+ in: $TIn;
56
+ out: $TOut;
57
+ } : TParser extends ParserWithoutInput<infer $InOut> ? {
58
+ in: $InOut;
59
+ out: $InOut;
60
+ } : never;
28
61
  export type inferEvent<T extends {
29
62
  shape: ZodObject<any>;
30
63
  }> = z.infer<T["shape"]>;
31
- type Event = {
32
- type: string;
33
- shape: {
34
- properties: any;
35
- metadata: any;
36
- metadataFn: any;
37
- };
38
- };
39
- export type EventPayload<E extends Event> = {
64
+ type Event = ReturnType<ReturnType<typeof createEventBuilder>>;
65
+ type EventPayload<E extends Event> = {
40
66
  type: E["type"];
41
- properties: E["shape"]["properties"];
42
- metadata: undefined extends E["shape"]["metadata"] ? E["shape"]["metadataFn"] : E["shape"]["metadata"];
67
+ properties: E["$output"];
68
+ metadata: E["$metadata"];
43
69
  attempts: number;
44
70
  };
45
71
  export declare function EventHandler<Events extends Event>(_events: Events | Events[], cb: (evt: {
@@ -2,17 +2,15 @@ import { createProxy } from "../util/index.js";
2
2
  export const EventBus =
3
3
  /* @__PURE__ */ createProxy("EventBus");
4
4
  import { EventBridgeClient, PutEventsCommand, } from "@aws-sdk/client-eventbridge";
5
- import { z } from "zod";
6
5
  import { useLoader } from "../util/loader.js";
7
6
  import { Config } from "../config/index.js";
8
- const client = new EventBridgeClient({});
9
- export function createEventBuilder(props) {
10
- return function createEvent(type, properties) {
11
- const propertiesSchema = z.object(properties);
12
- const metadataSchema = props.metadata
13
- ? z.object(props.metadata)
14
- : undefined;
15
- const publish = async (properties, metadata) => {
7
+ export function createEventBuilder(input) {
8
+ const client = new EventBridgeClient({});
9
+ const validator = input.validator;
10
+ const metadataValidator = input.metadata ? validator(input.metadata) : null;
11
+ return function event(type, schema) {
12
+ const validate = validator(schema);
13
+ async function publish(properties, metadata) {
16
14
  const result = await useLoader("sst.bus.publish", async (input) => {
17
15
  const size = 10;
18
16
  const promises = [];
@@ -39,31 +37,34 @@ export function createEventBuilder(props) {
39
37
  // @ts-expect-error
40
38
  Source: Config.APP,
41
39
  Detail: JSON.stringify({
42
- properties: propertiesSchema.parse(properties),
40
+ properties: validate(properties),
43
41
  metadata: (() => {
44
- if (metadataSchema) {
45
- return metadataSchema.parse(metadata);
42
+ if (metadataValidator) {
43
+ return metadataValidator(metadata);
46
44
  }
47
- if (props.metadataFn) {
48
- return props.metadataFn();
45
+ if (input.metadataFn) {
46
+ return input.metadataFn();
49
47
  }
50
48
  })(),
51
49
  }),
52
50
  DetailType: type,
53
51
  });
54
52
  return result;
55
- };
53
+ }
56
54
  return {
57
55
  publish: publish,
58
56
  type,
59
- shape: {
60
- metadata: {},
61
- properties: {},
62
- metadataFn: {},
63
- },
57
+ $input: {},
58
+ $output: {},
59
+ $metadata: {},
64
60
  };
65
61
  };
66
62
  }
63
+ export function ZodValidator(schema) {
64
+ return (input) => {
65
+ return schema.parse(input);
66
+ };
67
+ }
67
68
  export function EventHandler(_events, cb) {
68
69
  return async (event) => {
69
70
  await cb({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.38.7",
4
+ "version": "2.38.8",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },
@@ -120,7 +120,7 @@
120
120
  "@types/ws": "^8.5.3",
121
121
  "@types/yargs": "^17.0.13",
122
122
  "archiver": "^5.3.1",
123
- "astro-sst": "2.38.7",
123
+ "astro-sst": "2.38.8",
124
124
  "async": "^3.2.4",
125
125
  "tsx": "^3.12.1",
126
126
  "typescript": "^5.2.2",
@@ -206,23 +206,26 @@ export const useNodeHandler = () => {
206
206
  await fs.writeFile(path.join(input.out, "package.json"), JSON.stringify({
207
207
  dependencies: Object.fromEntries(installPackages.map((x) => [x, json.dependencies?.[x] || "*"])),
208
208
  }));
209
- const cmd = ["npm install"];
209
+ const cmd = [
210
+ "npm install",
211
+ "--platform=linux",
212
+ "--omit=dev",
213
+ "--no-optional",
214
+ input.props.architecture === "arm_64"
215
+ ? "--arch=arm64"
216
+ : "--arch=x64",
217
+ ];
210
218
  if (installPackages.includes("sharp")) {
211
219
  /**
212
220
  * TODO: This is a workaround for issues that sharp v0.33.0 has
213
221
  * with cross platform builds. This can be removed once sharp
214
222
  * releases a new version with the fix.
215
223
  */
216
- cmd.push("--platform=linux", "--omit=dev", "--no-optional", input.props.architecture === "arm_64"
217
- ? "--arch=arm64"
218
- : "--arch=x64", "--force sharp@0.32.6");
224
+ cmd.push("--force sharp@0.32.6");
219
225
  /**
220
226
  * Once the above issue is resolved, the code below can be used.
221
227
  */
222
228
  // cmd.push(
223
- // "--platform=linux",
224
- // "--omit=dev",
225
- // "--no-optional",
226
229
  // ...input.props.architecture === "arm_64"
227
230
  // ? ["--arch=arm64", "--force @img/sharp-linux-arm64"]
228
231
  // : ["--arch=x64", "--force @img/sharp-linux-x64"],