sst 4.12.1 → 4.12.3

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.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export * from "./realtime/index.js";
2
- export * from "./resource/index.js";
2
+ export { Resource } from "./resource/index.js";
3
3
  export * from "./vector/index.js";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./realtime/index.js";
2
- export * from "./resource/index.js";
2
+ export { Resource } from "./resource/index.js";
3
3
  export * from "./vector/index.js";
4
4
  import { format } from "util";
5
5
  if (process.env?.ECS_CONTAINER_METADATA_URI_V4 &&
@@ -1,4 +1,5 @@
1
- import { Resource } from "./shared.js";
2
- export declare function fromCloudflareEnv(input: any): void;
1
+ import type { Resource as BaseResource } from "./node.js";
3
2
  export declare function wrapCloudflareHandler(handler: any): any;
4
- export { Resource };
3
+ export interface Resource extends BaseResource {
4
+ }
5
+ export declare const Resource: Resource;
@@ -1,8 +1,7 @@
1
1
  import { env } from "cloudflare:workers";
2
- import { loadFromCloudflareEnv, Resource } from "./shared.js";
3
- loadFromCloudflareEnv(env);
4
- export function fromCloudflareEnv(input) {
5
- loadFromCloudflareEnv(input);
2
+ import { createResource, loadResourceEnvironment } from "./shared.js";
3
+ function loadCloudflareResources() {
4
+ loadResourceEnvironment(env);
6
5
  }
7
6
  export function wrapCloudflareHandler(handler) {
8
7
  if (handler == null) {
@@ -11,14 +10,14 @@ export function wrapCloudflareHandler(handler) {
11
10
  if (typeof handler === "function" && handler.hasOwnProperty("prototype")) {
12
11
  return class extends handler {
13
12
  constructor(ctx, env) {
14
- loadFromCloudflareEnv(env);
13
+ loadResourceEnvironment(env);
15
14
  super(ctx, env);
16
15
  }
17
16
  };
18
17
  }
19
18
  function wrap(fn) {
20
19
  return function (req, env, ...rest) {
21
- loadFromCloudflareEnv(env);
20
+ loadResourceEnvironment(env);
22
21
  return fn(req, env, ...rest);
23
22
  };
24
23
  }
@@ -28,4 +27,4 @@ export function wrapCloudflareHandler(handler) {
28
27
  }
29
28
  return result;
30
29
  }
31
- export { Resource };
30
+ export const Resource = createResource(loadCloudflareResources);
@@ -1,2 +1,4 @@
1
- import { Resource } from "./shared.js";
2
- export { Resource };
1
+ import type { Resource as BaseResource } from "./shared.js";
2
+ export interface Resource extends BaseResource {
3
+ }
4
+ export declare const Resource: Resource;
@@ -1,33 +1,38 @@
1
1
  import crypto from "crypto";
2
2
  import { readFileSync } from "fs";
3
3
  import { env } from "process";
4
- import { loadResourceData, loadResourceEnvironment, Resource, } from "./shared.js";
5
- const environment = {
6
- ...env,
7
- ...globalThis.process?.env,
8
- };
9
- loadResourceEnvironment(environment);
10
- if (environment.SST_RESOURCES_JSON) {
11
- try {
12
- loadResourceData(JSON.parse(environment.SST_RESOURCES_JSON));
4
+ import { createResource, loadResourceData, loadResourceEnvironment, } from "./shared.js";
5
+ const state = globalThis;
6
+ function loadNodeResources() {
7
+ const environment = {
8
+ ...env,
9
+ ...globalThis.process?.env,
10
+ };
11
+ loadResourceEnvironment(environment);
12
+ if (environment.SST_RESOURCES_JSON) {
13
+ try {
14
+ loadResourceData(JSON.parse(environment.SST_RESOURCES_JSON));
15
+ }
16
+ catch (error) {
17
+ console.error("Failed to parse SST_RESOURCES_JSON:", error);
18
+ }
13
19
  }
14
- catch (error) {
15
- console.error("Failed to parse SST_RESOURCES_JSON:", error);
20
+ if (environment.SST_KEY_FILE &&
21
+ environment.SST_KEY &&
22
+ !state.SST_KEY_FILE_DATA) {
23
+ const key = Buffer.from(environment.SST_KEY, "base64");
24
+ const encryptedData = readFileSync(environment.SST_KEY_FILE);
25
+ const nonce = Buffer.alloc(12, 0);
26
+ const decipher = crypto.createDecipheriv("aes-256-gcm", key, nonce);
27
+ const authTag = encryptedData.subarray(-16);
28
+ const actualCiphertext = encryptedData.subarray(0, -16);
29
+ decipher.setAuthTag(authTag);
30
+ let decrypted = decipher.update(actualCiphertext);
31
+ decrypted = Buffer.concat([decrypted, decipher.final()]);
32
+ loadResourceData(JSON.parse(decrypted.toString()));
33
+ }
34
+ if (state.SST_KEY_FILE_DATA) {
35
+ loadResourceData(state.SST_KEY_FILE_DATA);
16
36
  }
17
37
  }
18
- if (environment.SST_KEY_FILE && environment.SST_KEY && !globalThis.SST_KEY_FILE_DATA) {
19
- const key = Buffer.from(environment.SST_KEY, "base64");
20
- const encryptedData = readFileSync(environment.SST_KEY_FILE);
21
- const nonce = Buffer.alloc(12, 0);
22
- const decipher = crypto.createDecipheriv("aes-256-gcm", key, nonce);
23
- const authTag = encryptedData.subarray(-16);
24
- const actualCiphertext = encryptedData.subarray(0, -16);
25
- decipher.setAuthTag(authTag);
26
- let decrypted = decipher.update(actualCiphertext);
27
- decrypted = Buffer.concat([decrypted, decipher.final()]);
28
- loadResourceData(JSON.parse(decrypted.toString()));
29
- }
30
- if (globalThis.SST_KEY_FILE_DATA) {
31
- loadResourceData(globalThis.SST_KEY_FILE_DATA);
32
- }
33
- export { Resource };
38
+ export const Resource = createResource(loadNodeResources);
@@ -6,5 +6,4 @@ export interface Resource {
6
6
  }
7
7
  export declare function loadResourceEnvironment(input?: Record<string, any>): void;
8
8
  export declare function loadResourceData(input?: Record<string, any>): void;
9
- export declare function loadFromCloudflareEnv(input: any): void;
10
- export declare const Resource: Resource;
9
+ export declare function createResource<T extends Resource>(load: () => void): T;
@@ -5,46 +5,58 @@ const raw = (state.__SST_RESOURCE_RAW__ ??= {
5
5
  });
6
6
  const environment = (state.__SST_RESOURCE_ENVIRONMENT__ ??= {});
7
7
  export function loadResourceEnvironment(input) {
8
- for (const [key, value] of Object.entries(input ?? {})) {
8
+ for (let [key, value] of Object.entries(input ?? {})) {
9
9
  if (typeof value === "string") {
10
10
  environment[key] = value;
11
- }
12
- if (!key.startsWith("SST_RESOURCE_") || !value) {
11
+ if (!key.startsWith("SST_RESOURCE_") || !value) {
12
+ continue;
13
+ }
14
+ raw[key.slice("SST_RESOURCE_".length)] = JSON.parse(value);
13
15
  continue;
14
16
  }
15
- raw[key.slice("SST_RESOURCE_".length)] = JSON.parse(value);
17
+ raw[key] = value;
16
18
  }
17
19
  }
18
20
  export function loadResourceData(input) {
19
21
  Object.assign(raw, input ?? {});
20
22
  }
21
- export function loadFromCloudflareEnv(input) {
22
- for (let [key, value] of Object.entries(input)) {
23
- if (typeof value === "string") {
24
- environment[key] = value;
25
- try {
26
- value = JSON.parse(value);
23
+ export function createResource(load) {
24
+ let loaded = false;
25
+ const loadData = () => {
26
+ if (loaded)
27
+ return;
28
+ load();
29
+ loaded = true;
30
+ };
31
+ return new Proxy(raw, {
32
+ get(_target, prop) {
33
+ loadData();
34
+ if (prop in raw) {
35
+ return raw[prop];
27
36
  }
28
- catch { }
29
- }
30
- raw[key] = value;
31
- if (key.startsWith("SST_RESOURCE_")) {
32
- raw[key.replace("SST_RESOURCE_", "")] = value;
33
- }
34
- }
37
+ if (typeof prop !== "string") {
38
+ return undefined;
39
+ }
40
+ if (!environment.SST_RESOURCE_App && !raw.App) {
41
+ throw new Error("It does not look like SST links are active. If this is in local development and you are not starting this process through the multiplexer, wrap your command with `sst dev -- <command>`");
42
+ }
43
+ let msg = `"${prop}" is not linked in your sst.config.ts`;
44
+ if (environment.AWS_LAMBDA_FUNCTION_NAME) {
45
+ msg += ` to ${environment.AWS_LAMBDA_FUNCTION_NAME}`;
46
+ }
47
+ throw new Error(msg);
48
+ },
49
+ has(_target, prop) {
50
+ loadData();
51
+ return prop in raw;
52
+ },
53
+ ownKeys() {
54
+ loadData();
55
+ return Reflect.ownKeys(raw);
56
+ },
57
+ getOwnPropertyDescriptor(_target, prop) {
58
+ loadData();
59
+ return Object.getOwnPropertyDescriptor(raw, prop);
60
+ },
61
+ });
35
62
  }
36
- export const Resource = new Proxy(raw, {
37
- get(_target, prop) {
38
- if (prop in raw) {
39
- return raw[prop];
40
- }
41
- if (!environment.SST_RESOURCE_App) {
42
- throw new Error("It does not look like SST links are active. If this is in local development and you are not starting this process through the multiplexer, wrap your command with `sst dev -- <command>`");
43
- }
44
- let msg = `"${prop}" is not linked in your sst.config.ts`;
45
- if (environment.AWS_LAMBDA_FUNCTION_NAME) {
46
- msg += ` to ${environment.AWS_LAMBDA_FUNCTION_NAME}`;
47
- }
48
- throw new Error(msg);
49
- },
50
- });
package/package.json CHANGED
@@ -2,11 +2,8 @@
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "sst",
4
4
  "type": "module",
5
- "sideEffects": [
6
- "./dist/resource/node.js",
7
- "./dist/resource/cloudflare.js"
8
- ],
9
- "version": "4.12.1",
5
+ "sideEffects": false,
6
+ "version": "4.12.3",
10
7
  "main": "./dist/index.js",
11
8
  "repository": {
12
9
  "type": "git",
@@ -58,14 +55,14 @@
58
55
  "sst": "./bin/sst.mjs"
59
56
  },
60
57
  "optionalDependencies": {
61
- "sst-linux-x64": "4.12.1",
62
- "sst-linux-x86": "4.12.1",
63
- "sst-darwin-x64": "4.12.1",
64
- "sst-linux-arm64": "4.12.1",
65
- "sst-darwin-arm64": "4.12.1",
66
- "sst-win32-x64": "4.12.1",
67
- "sst-win32-x86": "4.12.1",
68
- "sst-win32-arm64": "4.12.1"
58
+ "sst-linux-x64": "4.12.3",
59
+ "sst-linux-x86": "4.12.3",
60
+ "sst-darwin-x64": "4.12.3",
61
+ "sst-linux-arm64": "4.12.3",
62
+ "sst-darwin-arm64": "4.12.3",
63
+ "sst-win32-x64": "4.12.3",
64
+ "sst-win32-x86": "4.12.3",
65
+ "sst-win32-arm64": "4.12.3"
69
66
  },
70
67
  "dependencies": {
71
68
  "@aws/durable-execution-sdk-js": "1.0.2",