wirejs-deploy-amplify-basic 0.0.106-realtime → 0.0.107-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.
@@ -51,7 +51,11 @@ export const handler = async (event: AuthorizationRequest): Promise<Authorizatio
51
51
  * 4. Must be for the correct channel
52
52
  */
53
53
  try {
54
- console.log('Authorization event:', JSON.stringify(event, null, 2));
54
+ console.log(
55
+ 'Authorization request:',
56
+ event.requestContext.operation,
57
+ event.requestContext.channel
58
+ );
55
59
 
56
60
  if (event.requestContext.operation === 'EVENT_PUBLISH') {
57
61
  throw new Error('Publish not permitted');
@@ -66,10 +70,15 @@ export const handler = async (event: AuthorizationRequest): Promise<Authorizatio
66
70
  new TextEncoder().encode(await getSecret(event.requestContext.channelNamespaceName))
67
71
  );
68
72
 
69
- if (event.requestContext.channel && decoded.payload.channel !== event.requestContext.channel) {
70
- throw new Error(`Channel mismatch: expected ${event.requestContext.channel}, got ${decoded.payload.channel}`);
73
+ // channel from context gets prefixed with a slash
74
+ if (event.requestContext.channel
75
+ && `/${decoded.payload.channel}` !== event.requestContext.channel
76
+ ) {
77
+ throw new Error(`Channel mismatch: Token is for "/${decoded.payload.channel}", authorization request is for "${event.requestContext.channel}".`);
71
78
  }
72
79
 
80
+ console.log('Authorized.');
81
+
73
82
  // Default TTL from AppSync is 5 minutes according to construct docstring.
74
83
  return {
75
84
  isAuthorized: true,
@@ -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.74-realtime"
6
+ "wirejs-resources": "^0.1.75-realtime"
7
7
  }
8
8
  }
@@ -8,6 +8,6 @@ export declare class RealtimeService<T = any> extends Resource {
8
8
  * The address the client will need to connect to.
9
9
  */
10
10
  get address(): string;
11
- publish(channel: string, data: T | T[]): Promise<any>;
11
+ publish(channel: string, events: T[]): Promise<any>;
12
12
  getStream(channel: string): Promise<any>;
13
13
  }
@@ -52,14 +52,13 @@ export class RealtimeService extends Resource {
52
52
  get address() {
53
53
  return `wss://${process.env.REALTIME_WS_DOMAIN}/event/realtime`;
54
54
  }
55
- async publish(channel, data) {
55
+ async publish(channel, events) {
56
56
  this.#validateChannelName(channel);
57
- console.log('Publishing to channel:', channel);
58
- const events = Array.isArray(data) ? data : [data];
57
+ console.log('Attempting to publish to channel:', channel);
59
58
  // AppSync allows batches of no more than 5. Hence, if we have more than 5,
60
59
  // we need to perform batching on our end.
61
60
  if (events.length > 5) {
62
- console.log(`More than 5 events received. Batching...`);
61
+ // console.log(`More than 5 events received. Batching...`);
63
62
  let results = [];
64
63
  let i = 0;
65
64
  while (i < events.length) {
@@ -71,14 +70,13 @@ export class RealtimeService extends Resource {
71
70
  }
72
71
  // TODO: Utility for making SigV4 requests a little more concise.
73
72
  const credentials = await defaultProvider()();
74
- const signerConfig = {
73
+ ;
74
+ const signer = new SignatureV4({
75
75
  service: 'appsync',
76
76
  region: process.env.AWS_REGION || 'us-east-1',
77
77
  credentials,
78
78
  sha256: Sha256,
79
- };
80
- console.log('Signer config:', signerConfig);
81
- const signer = new SignatureV4(signerConfig);
79
+ });
82
80
  const request = new HttpRequest({
83
81
  method: 'POST',
84
82
  hostname: process.env.REALTIME_HTTP_DOMAIN,
@@ -96,25 +94,22 @@ export class RealtimeService extends Resource {
96
94
  events: events.map(event => JSON.stringify(event))
97
95
  }),
98
96
  });
99
- console.log('Signing request:', request);
100
97
  const signedRequest = await signer.sign(request);
101
98
  const response = await fetch(`https://${signedRequest.hostname}${signedRequest.path}`, {
102
99
  method: signedRequest.method,
103
100
  headers: signedRequest.headers,
104
101
  body: signedRequest.body,
105
102
  });
106
- console.log('Response status:', response.status);
103
+ console.log(`AppSync response status:`, response.status);
107
104
  if (!response.ok) {
108
105
  throw new Error(`Failed to publish to channel: ${response.statusText}`);
109
106
  }
110
- const result = await response.json();
111
- console.log('Response from publish:', result);
112
- return result;
107
+ return response.json();
113
108
  }
114
109
  async getStream(channel) {
115
110
  this.#validateChannelName(channel);
116
111
  const channelString = `${this.#namespace}/${channel}`;
117
- const payload = { channel: `/${channelString}` };
112
+ const payload = { channel: channelString };
118
113
  const jwt = await new jose.SignJWT(payload)
119
114
  .setProtectedHeader({ alg: 'HS256' })
120
115
  .setIssuedAt()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirejs-deploy-amplify-basic",
3
- "version": "0.0.106-realtime",
3
+ "version": "0.0.107-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.74-realtime"
44
+ "wirejs-resources": "^0.1.75-realtime"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@aws-amplify/backend": "^1.14.0",