sst 3.0.33 → 3.0.36

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/aws/bus.js CHANGED
@@ -2,8 +2,9 @@ import { client } from "../aws/client.js";
2
2
  import { Resource } from "../resource.js";
3
3
  export var bus;
4
4
  (function (bus) {
5
- function url(options) {
6
- const region = options?.region || client.region;
5
+ function url(region, options) {
6
+ if (options?.region)
7
+ region = options.region;
7
8
  return `https://events.${region}.amazonaws.com/`;
8
9
  }
9
10
  function subscriber(_events, cb) {
@@ -22,7 +23,8 @@ export var bus;
22
23
  * */
23
24
  bus.handler = subscriber;
24
25
  async function publish(name, def, properties, options) {
25
- const u = url(options?.aws);
26
+ const c = await client();
27
+ const u = url(c.region, options?.aws);
26
28
  const evt = typeof def === "string"
27
29
  ? {
28
30
  type: def,
@@ -30,7 +32,7 @@ export var bus;
30
32
  metadata: options?.metadata || {},
31
33
  }
32
34
  : await def.create(properties, options?.metadata);
33
- const res = await client.fetch(u, {
35
+ const res = await c.fetch(u, {
34
36
  method: "POST",
35
37
  aws: options?.aws,
36
38
  headers: {
@@ -1,3 +1,3 @@
1
1
  import { AwsClient } from "aws4fetch";
2
- export declare const client: AwsClient;
2
+ export declare function client(): Promise<AwsClient>;
3
3
  export type AwsOptions = Exclude<Parameters<AwsClient["fetch"]>[1], null | undefined>["aws"];
@@ -1,7 +1,35 @@
1
1
  import { AwsClient } from "aws4fetch";
2
- export const client = new AwsClient({
3
- accessKeyId: process.env.AWS_ACCESS_KEY_ID,
4
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
5
- sessionToken: process.env.AWS_SESSION_TOKEN,
6
- region: process.env.AWS_REGION,
7
- });
2
+ let cachedCredentials = null;
3
+ async function getCredentials(url) {
4
+ if (cachedCredentials) {
5
+ const currentTime = new Date();
6
+ const fiveMinutesFromNow = new Date(currentTime.getTime() + 5 * 60000);
7
+ const expirationTime = new Date(cachedCredentials.Expiration);
8
+ if (expirationTime > fiveMinutesFromNow) {
9
+ return cachedCredentials;
10
+ }
11
+ }
12
+ const credentials = (await fetch(url).then((res) => res.json()));
13
+ cachedCredentials = credentials;
14
+ return credentials;
15
+ }
16
+ export async function client() {
17
+ if (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY) {
18
+ return new AwsClient({
19
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID,
20
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
21
+ sessionToken: process.env.AWS_SESSION_TOKEN,
22
+ region: process.env.AWS_REGION,
23
+ });
24
+ }
25
+ if (process.env.ECS_CONTAINER_METADATA_URI_V4) {
26
+ const credentials = await getCredentials(process.env.ECS_CONTAINER_METADATA_URI_V4 + "/credentials");
27
+ return new AwsClient({
28
+ accessKeyId: credentials.AccessKeyId,
29
+ secretAccessKey: credentials.SecretAccessKey,
30
+ sessionToken: credentials.Token,
31
+ region: process.env.AWS_REGION,
32
+ });
33
+ }
34
+ throw new Error("No AWS credentials found");
35
+ }
@@ -1,4 +1,4 @@
1
- import { IoTCustomAuthorizerHandler } from "aws-lambda";
1
+ import { Context, IoTCustomAuthorizerEvent } from "aws-lambda";
2
2
  export declare namespace realtime {
3
3
  interface AuthResult {
4
4
  /**
@@ -57,5 +57,22 @@ export declare namespace realtime {
57
57
  * });
58
58
  * ```
59
59
  */
60
- function authorizer(input: (token: string) => Promise<AuthResult>): IoTCustomAuthorizerHandler;
60
+ function authorizer(input: (token: string) => Promise<AuthResult>): (evt: IoTCustomAuthorizerEvent, context: Context) => Promise<{
61
+ isAuthenticated: boolean;
62
+ principalId: string;
63
+ disconnectAfterInSeconds: number;
64
+ refreshAfterInSeconds: number;
65
+ policyDocuments: {
66
+ Version: string;
67
+ Statement: ({
68
+ Action: string;
69
+ Effect: string;
70
+ Resource: string;
71
+ } | {
72
+ Action: string;
73
+ Effect: string;
74
+ Resource: string[];
75
+ })[];
76
+ }[];
77
+ }>;
61
78
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "sst",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
- "version": "3.0.33",
6
+ "version": "3.0.36",
7
7
  "main": "./dist/index.js",
8
8
  "exports": {
9
9
  ".": "./dist/index.js",