wirejs-deploy-amplify-basic 0.0.98-realtime → 0.0.99-realtime

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.
@@ -141,6 +141,7 @@ if (generated.some(isRealtimeService)) {
141
141
  appId: APP_ID!,
142
142
  branchId: BRANCH_ID,
143
143
  publisher: backend.api,
144
+ bucket: bucket.bucketName,
144
145
  namespaces: generated
145
146
  .filter(isRealtimeService)
146
147
  .map(r => r.options.namespace),
@@ -22,12 +22,15 @@ type AuthorizationResult = {
22
22
  ttlOverride?: number;
23
23
  };
24
24
 
25
- let secrets: Record<string, Promise<string> | undefined> = {};
25
+ let secret: Promise<string> | undefined = undefined;
26
26
  async function getSecret(ns: string): Promise<any> {
27
- if (!secrets[ns]) {
28
- secrets[ns] = new Promise(async (resolve, reject) => {
27
+ if (!secret) {
28
+ secret = new Promise(async (resolve, reject) => {
29
29
  try {
30
- const secret = new Secret(ns, process.env.SECRET_ID!)
30
+ const secret = new Secret(
31
+ process.env.SECRET_SCOPE!,
32
+ process.env.SECRET_ID!
33
+ )
31
34
  resolve(await secret.read());
32
35
  } catch (error) {
33
36
  console.error('Error reading secret:', error);
@@ -35,7 +38,7 @@ async function getSecret(ns: string): Promise<any> {
35
38
  }
36
39
  });
37
40
  }
38
- return secrets[ns];
41
+ return secret;
39
42
  }
40
43
 
41
44
  export const handler = async (event: AuthorizationRequest): Promise<AuthorizationResult> => {
@@ -24,6 +24,7 @@ export class RealtimeService extends Construct {
24
24
  lambda: IFunction;
25
25
  }
26
26
  };
27
+ bucket: string; // needed for `Secret`, which currently uses the common S3 bucket
27
28
  namespaces: string[];
28
29
  }) {
29
30
  super(scope, id);
@@ -38,9 +39,11 @@ export class RealtimeService extends Construct {
38
39
  entry: path.join(__dirname, 'authorizer-lambda.ts'),
39
40
  timeout: Duration.seconds(30),
40
41
  environment: {
41
- // must match wirejs-deploy-amplify-basic/wirejs-resources-overrides/services/realtime.ts:SECRET_ID
42
- // TODO: find a common place to define this, or just pass it through
43
- // in `addResource()`. (Redundant across `RealtimeService` instances.)
42
+ // global storage bucket currently used by `Secret` resource
43
+ BUCKET: props.bucket,
44
+
45
+ // NOTE: These MUST equal those defined in RealtimeService resource.
46
+ SECRET_SCOPE: 'wirejs-global',
44
47
  SECRET_ID: 'realtime-secret',
45
48
  }
46
49
  });
@@ -3,6 +3,6 @@
3
3
  "dependencies": {
4
4
  "jsdom": "^25.0.1",
5
5
  "wirejs-dom": "^1.0.41",
6
- "wirejs-resources": "^0.1.66-realtime"
6
+ "wirejs-resources": "^0.1.67-realtime"
7
7
  }
8
8
  }
@@ -56,7 +56,7 @@ async function callApi(INTERNAL_API_URL, method, ...args) {
56
56
  if (typeof value === 'object' && value.__wjstype === 'realtime') {
57
57
  return {
58
58
  subscribe(subscriber) {
59
- rt.subscribe(value.url, value.channel, value.token, subscriber);
59
+ rt.subscribe(value.url, value.channel, value.token, value.authHost, subscriber);
60
60
  return () => {
61
61
  rt.unsubscribe(value.url, value.channel, subscriber);
62
62
  };
@@ -7,5 +7,5 @@ export type ChannelEvent<T = any> = {
7
7
  id: string;
8
8
  event: any;
9
9
  };
10
- export declare function subscribe(url: string, channel: string, token: string, subscriber: Subscriber): void;
10
+ export declare function subscribe(url: string, channel: string, token: string, authHost: string, subscriber: Subscriber): void;
11
11
  export declare function unsubscribe(url: string, channel: string, subscriber: Subscriber): void;
@@ -33,11 +33,11 @@ function getAuthProtocol(authorization) {
33
33
  const header = getBase64URLEncoded(authorization);
34
34
  return `header-${header}`;
35
35
  }
36
- export function subscribe(url, channel, token, subscriber) {
36
+ export function subscribe(url, channel, token, authHost, subscriber) {
37
37
  const fullChannelName = `${url}#${channel}`;
38
38
  const authorization = {
39
39
  Authorization: token,
40
- host: new URL(url).host,
40
+ host: authHost,
41
41
  };
42
42
  if (!connections.has(url)) {
43
43
  const ws = new WebSocket(url, [
@@ -1,5 +1,6 @@
1
1
  import { Resource } from 'wirejs-resources';
2
- export declare const SECRET_ID = "realtime-secret";
2
+ export declare const REALTIME_SECRET_SCOPE = "wirejs-global";
3
+ export declare const REALTIME_SECRET_ID = "realtime-secret";
3
4
  export declare class RealtimeService<T = any> extends Resource {
4
5
  #private;
5
6
  constructor(scope: Resource | string, id: string);
@@ -5,17 +5,28 @@ import { HttpRequest } from '@aws-sdk/protocol-http';
5
5
  import { defaultProvider } from '@aws-sdk/credential-provider-node';
6
6
  import { Sha256 } from '@aws-crypto/sha256-js';
7
7
  import { addResource } from '../resource-collector.js';
8
- export const SECRET_ID = 'realtime-secret';
8
+ export const REALTIME_SECRET_SCOPE = 'wirejs-global';
9
+ export const REALTIME_SECRET_ID = 'realtime-secret';
10
+ let secret = undefined;
11
+ function createSecret() {
12
+ if (!secret) {
13
+ secret = new Secret(REALTIME_SECRET_SCOPE, REALTIME_SECRET_ID);
14
+ }
15
+ return secret;
16
+ }
9
17
  export class RealtimeService extends Resource {
10
18
  #secret;
11
19
  #namespace;
12
20
  constructor(scope, id) {
13
21
  super(scope, id);
14
- this.#secret = new Secret(this, SECRET_ID);
22
+ this.#secret = createSecret();
15
23
  this.#namespace = this.absoluteId
16
24
  .replace(/[^a-zA-Z0-9]/g, '-')
17
25
  .slice(0, 50);
18
- addResource('RealtimeService', { namespace: this.#namespace });
26
+ addResource('RealtimeService', {
27
+ absoluteId: this.absoluteId,
28
+ namespace: this.#namespace,
29
+ });
19
30
  }
20
31
  /**
21
32
  * Ensures channel name will be supported by known, major cloud provers using
@@ -105,7 +116,8 @@ export class RealtimeService extends Resource {
105
116
  __wjstype: 'realtime',
106
117
  url: this.address,
107
118
  channel: `${this.#namespace}/${channel}`,
108
- token: jwt
119
+ token: jwt,
120
+ authHost: process.env.REALTIME_HTTP_DOMAIN,
109
121
  };
110
122
  }
111
123
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirejs-deploy-amplify-basic",
3
- "version": "0.0.98-realtime",
3
+ "version": "0.0.99-realtime",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  "recursive-copy": "^2.0.14",
42
42
  "rimraf": "^6.0.1",
43
43
  "wirejs-dom": "^1.0.41",
44
- "wirejs-resources": "^0.1.66-realtime"
44
+ "wirejs-resources": "^0.1.67-realtime"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@aws-amplify/backend": "^1.14.0",