wirejs-deploy-amplify-basic 0.0.104-realtime → 0.0.106-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.
@@ -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.72-realtime"
6
+ "wirejs-resources": "^0.1.74-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<void>;
11
+ publish(channel: string, data: T | T[]): Promise<any>;
12
12
  getStream(channel: string): Promise<any>;
13
13
  }
@@ -54,51 +54,62 @@ export class RealtimeService extends Resource {
54
54
  }
55
55
  async publish(channel, data) {
56
56
  this.#validateChannelName(channel);
57
- console.log('Publishing to channels:', channel);
57
+ console.log('Publishing to channel:', channel);
58
58
  const events = Array.isArray(data) ? data : [data];
59
59
  // AppSync allows batches of no more than 5. Hence, if we have more than 5,
60
60
  // we need to perform batching on our end.
61
61
  if (events.length > 5) {
62
+ console.log(`More than 5 events received. Batching...`);
63
+ let results = [];
62
64
  let i = 0;
63
65
  while (i < events.length) {
64
66
  const batch = events.slice(i, i + 5);
65
- await this.publish(channel, batch);
67
+ results.push(await this.publish(channel, batch));
66
68
  i += 5;
67
69
  }
68
- return;
70
+ return results;
69
71
  }
70
72
  // TODO: Utility for making SigV4 requests a little more concise.
71
73
  const credentials = await defaultProvider()();
72
- const signer = new SignatureV4({
74
+ const signerConfig = {
73
75
  service: 'appsync',
74
76
  region: process.env.AWS_REGION || 'us-east-1',
75
77
  credentials,
76
78
  sha256: Sha256,
77
- });
79
+ };
80
+ console.log('Signer config:', signerConfig);
81
+ const signer = new SignatureV4(signerConfig);
78
82
  const request = new HttpRequest({
79
83
  method: 'POST',
80
- protocol: 'https:',
81
- // hostname: `${process.env.REALTIME_DOMAIN}.appsync-api.${process.env.AWS_REGION}.amazonaws.com`,
82
84
  hostname: process.env.REALTIME_HTTP_DOMAIN,
83
85
  path: '/event',
84
86
  headers: {
85
- 'Content-Type': 'application/json',
87
+ accept: 'application/json, text/javascript',
88
+ 'content-encoding': 'amz-1.0',
89
+ 'content-type': 'application/json; charset=UTF-8',
86
90
  'x-amz-date': new Date().toISOString(),
91
+ host: process.env.REALTIME_HTTP_DOMAIN,
87
92
  },
88
93
  body: JSON.stringify({
94
+ id: crypto.randomUUID(),
89
95
  channel: `${this.#namespace}/${channel}`,
90
96
  events: events.map(event => JSON.stringify(event))
91
97
  }),
92
98
  });
99
+ console.log('Signing request:', request);
93
100
  const signedRequest = await signer.sign(request);
94
101
  const response = await fetch(`https://${signedRequest.hostname}${signedRequest.path}`, {
95
102
  method: signedRequest.method,
96
103
  headers: signedRequest.headers,
97
104
  body: signedRequest.body,
98
105
  });
106
+ console.log('Response status:', response.status);
99
107
  if (!response.ok) {
100
108
  throw new Error(`Failed to publish to channel: ${response.statusText}`);
101
109
  }
110
+ const result = await response.json();
111
+ console.log('Response from publish:', result);
112
+ return result;
102
113
  }
103
114
  async getStream(channel) {
104
115
  this.#validateChannelName(channel);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirejs-deploy-amplify-basic",
3
- "version": "0.0.104-realtime",
3
+ "version": "0.0.106-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.72-realtime"
44
+ "wirejs-resources": "^0.1.74-realtime"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@aws-amplify/backend": "^1.14.0",