iframe-pubsub 1.0.14 → 1.0.16

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.mts CHANGED
@@ -23,6 +23,7 @@ interface IRegistrationMessage {
23
23
  type MessageCallback = (message: IMessage) => void | Promise<void>;
24
24
 
25
25
  declare class Client {
26
+ protected targetAIChatClientId: string;
26
27
  private pageId;
27
28
  private callback?;
28
29
  private pubsub;
@@ -33,7 +34,7 @@ declare class Client {
33
34
  *
34
35
  * @param pageId The ID of the page or component to register to.
35
36
  */
36
- constructor(pageId: string);
37
+ constructor(pageId: string, targetAIChatClientId?: string);
37
38
  /**
38
39
  * Unregister the client from the pubsub.
39
40
  */
@@ -104,7 +105,7 @@ declare class AIChatClient extends Client {
104
105
  *
105
106
  * @param pageId The ID of the page or component to register to.
106
107
  */
107
- constructor(pageId: string);
108
+ constructor(pageId: string, targetAIChatClientId?: string);
108
109
  private sendAIChatPubsubMethod;
109
110
  /**
110
111
  * Set the parent name then the AI Chat can know who should it communicate with.
package/dist/index.d.ts CHANGED
@@ -23,6 +23,7 @@ interface IRegistrationMessage {
23
23
  type MessageCallback = (message: IMessage) => void | Promise<void>;
24
24
 
25
25
  declare class Client {
26
+ protected targetAIChatClientId: string;
26
27
  private pageId;
27
28
  private callback?;
28
29
  private pubsub;
@@ -33,7 +34,7 @@ declare class Client {
33
34
  *
34
35
  * @param pageId The ID of the page or component to register to.
35
36
  */
36
- constructor(pageId: string);
37
+ constructor(pageId: string, targetAIChatClientId?: string);
37
38
  /**
38
39
  * Unregister the client from the pubsub.
39
40
  */
@@ -104,7 +105,7 @@ declare class AIChatClient extends Client {
104
105
  *
105
106
  * @param pageId The ID of the page or component to register to.
106
107
  */
107
- constructor(pageId: string);
108
+ constructor(pageId: string, targetAIChatClientId?: string);
108
109
  private sendAIChatPubsubMethod;
109
110
  /**
110
111
  * Set the parent name then the AI Chat can know who should it communicate with.
package/dist/index.js CHANGED
@@ -38,9 +38,6 @@ var _PubSub = class _PubSub {
38
38
  this.subscribers = /* @__PURE__ */ new Map();
39
39
  this.boundHandleMessage = this.handleMessage.bind(this);
40
40
  window.addEventListener("message", this.boundHandleMessage);
41
- window.addEventListener("message", (event) => {
42
- console.info("I am still live: ", event);
43
- });
44
41
  }
45
42
  static getInstance() {
46
43
  if (!_PubSub.instance) {
@@ -101,7 +98,6 @@ var _PubSub = class _PubSub {
101
98
  }
102
99
  }
103
100
  handleMessage(event) {
104
- console.log("Pubsub Received message:", event);
105
101
  const data = event.data;
106
102
  const source = event.source;
107
103
  if (data?.type === "REGISTER") {
@@ -160,12 +156,14 @@ var Client = class {
160
156
  *
161
157
  * @param pageId The ID of the page or component to register to.
162
158
  */
163
- constructor(pageId) {
159
+ constructor(pageId, targetAIChatClientId = "aichat" /* AI_CHAT_CLIENT_ID */) {
160
+ __publicField(this, "targetAIChatClientId");
164
161
  __publicField(this, "pageId");
165
162
  __publicField(this, "callback");
166
163
  __publicField(this, "pubsub");
167
164
  __publicField(this, "isIframe");
168
165
  __publicField(this, "boundHandleMessage");
166
+ this.targetAIChatClientId = targetAIChatClientId;
169
167
  this.pageId = pageId;
170
168
  this.pubsub = PubSub.getInstance();
171
169
  this.isIframe = window !== window.parent;
@@ -203,7 +201,7 @@ var Client = class {
203
201
  throw new Error("You are not allowed to clean up aichat from iframe.");
204
202
  }
205
203
  window.removeEventListener("message", this.boundHandleMessage);
206
- return this.pubsub.unregister("aichat" /* AI_CHAT_CLIENT_ID */);
204
+ return this.pubsub.unregister(this.targetAIChatClientId);
207
205
  }
208
206
  /**
209
207
  * Listen for messages from the parent page with a callback.
@@ -211,7 +209,6 @@ var Client = class {
211
209
  * @param callback The callback function to register.
212
210
  */
213
211
  onMessage(callback) {
214
- console.info("Register new onMessage callback for", this.pageId, callback);
215
212
  this.callback = callback;
216
213
  }
217
214
  /**
@@ -298,7 +295,6 @@ var Client = class {
298
295
  });
299
296
  }
300
297
  handleMessage(event) {
301
- console.log("Client Received message:", event);
302
298
  let message;
303
299
  if (event.data) {
304
300
  const evt = event;
@@ -344,16 +340,14 @@ var AIChatClient = class extends Client {
344
340
  *
345
341
  * @param pageId The ID of the page or component to register to.
346
342
  */
347
- constructor(pageId) {
348
- super(pageId);
343
+ constructor(pageId, targetAIChatClientId = "aichat" /* AI_CHAT_CLIENT_ID */) {
344
+ super(pageId, targetAIChatClientId);
349
345
  }
350
346
  sendAIChatPubsubMethod(methodName, arg) {
351
347
  this.sendMessage(
352
- "aichat" /* AI_CHAT_CLIENT_ID */,
353
- // This name is hardcode, do not change it
348
+ this.targetAIChatClientId,
354
349
  {
355
350
  type: "pubsub" /* AI_CHAT_INTERNAL_COMM_TYPE */,
356
- // This name is hardcode, do not change it
357
351
  methodName,
358
352
  arg
359
353
  }
@@ -413,7 +407,7 @@ var AIChatClient = class extends Client {
413
407
  * @param message The message to show.
414
408
  */
415
409
  showChatMessage(message) {
416
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
410
+ this.sendMessage(this.targetAIChatClientId, {
417
411
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
418
412
  name: "showChatMessage" /* SHOW_CHAT_MESSAGE */,
419
413
  parameters: {
@@ -427,7 +421,7 @@ var AIChatClient = class extends Client {
427
421
  * @param message The error message to show.
428
422
  */
429
423
  showErrorMessage(message) {
430
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
424
+ this.sendMessage(this.targetAIChatClientId, {
431
425
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
432
426
  name: "showErrorMessage" /* SHOW_ERROR_MESSAGE */,
433
427
  parameters: {
@@ -441,7 +435,7 @@ var AIChatClient = class extends Client {
441
435
  * @param action The action to confirm.
442
436
  */
443
437
  confirmAction(action) {
444
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
438
+ this.sendMessage(this.targetAIChatClientId, {
445
439
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
446
440
  name: "confirmAction" /* CONFIRM_ACTION */,
447
441
  parameters: {
@@ -455,7 +449,7 @@ var AIChatClient = class extends Client {
455
449
  * @param options The options to show.
456
450
  */
457
451
  showOptions(options) {
458
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
452
+ this.sendMessage(this.targetAIChatClientId, {
459
453
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
460
454
  name: "showOptions" /* SHOW_OPTIONS */,
461
455
  parameters: {
@@ -469,7 +463,7 @@ var AIChatClient = class extends Client {
469
463
  * @param prompt The prompt to send.
470
464
  */
471
465
  sendChatPrompt(prompt) {
472
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
466
+ this.sendMessage(this.targetAIChatClientId, {
473
467
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
474
468
  name: "sendChatPrompt" /* SEND_CHAT_PROMPT */,
475
469
  parameters: {
@@ -481,7 +475,7 @@ var AIChatClient = class extends Client {
481
475
  * Show an unknown error message in the AI Chat component.
482
476
  */
483
477
  showComingSoon() {
484
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
478
+ this.sendMessage(this.targetAIChatClientId, {
485
479
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
486
480
  name: "showComingSoon" /* SHOW_COMING_SOON */,
487
481
  parameters: {
package/dist/index.mjs CHANGED
@@ -11,9 +11,6 @@ var _PubSub = class _PubSub {
11
11
  this.subscribers = /* @__PURE__ */ new Map();
12
12
  this.boundHandleMessage = this.handleMessage.bind(this);
13
13
  window.addEventListener("message", this.boundHandleMessage);
14
- window.addEventListener("message", (event) => {
15
- console.info("I am still live: ", event);
16
- });
17
14
  }
18
15
  static getInstance() {
19
16
  if (!_PubSub.instance) {
@@ -74,7 +71,6 @@ var _PubSub = class _PubSub {
74
71
  }
75
72
  }
76
73
  handleMessage(event) {
77
- console.log("Pubsub Received message:", event);
78
74
  const data = event.data;
79
75
  const source = event.source;
80
76
  if (data?.type === "REGISTER") {
@@ -133,12 +129,14 @@ var Client = class {
133
129
  *
134
130
  * @param pageId The ID of the page or component to register to.
135
131
  */
136
- constructor(pageId) {
132
+ constructor(pageId, targetAIChatClientId = "aichat" /* AI_CHAT_CLIENT_ID */) {
133
+ __publicField(this, "targetAIChatClientId");
137
134
  __publicField(this, "pageId");
138
135
  __publicField(this, "callback");
139
136
  __publicField(this, "pubsub");
140
137
  __publicField(this, "isIframe");
141
138
  __publicField(this, "boundHandleMessage");
139
+ this.targetAIChatClientId = targetAIChatClientId;
142
140
  this.pageId = pageId;
143
141
  this.pubsub = PubSub.getInstance();
144
142
  this.isIframe = window !== window.parent;
@@ -176,7 +174,7 @@ var Client = class {
176
174
  throw new Error("You are not allowed to clean up aichat from iframe.");
177
175
  }
178
176
  window.removeEventListener("message", this.boundHandleMessage);
179
- return this.pubsub.unregister("aichat" /* AI_CHAT_CLIENT_ID */);
177
+ return this.pubsub.unregister(this.targetAIChatClientId);
180
178
  }
181
179
  /**
182
180
  * Listen for messages from the parent page with a callback.
@@ -184,7 +182,6 @@ var Client = class {
184
182
  * @param callback The callback function to register.
185
183
  */
186
184
  onMessage(callback) {
187
- console.info("Register new onMessage callback for", this.pageId, callback);
188
185
  this.callback = callback;
189
186
  }
190
187
  /**
@@ -271,7 +268,6 @@ var Client = class {
271
268
  });
272
269
  }
273
270
  handleMessage(event) {
274
- console.log("Client Received message:", event);
275
271
  let message;
276
272
  if (event.data) {
277
273
  const evt = event;
@@ -317,16 +313,14 @@ var AIChatClient = class extends Client {
317
313
  *
318
314
  * @param pageId The ID of the page or component to register to.
319
315
  */
320
- constructor(pageId) {
321
- super(pageId);
316
+ constructor(pageId, targetAIChatClientId = "aichat" /* AI_CHAT_CLIENT_ID */) {
317
+ super(pageId, targetAIChatClientId);
322
318
  }
323
319
  sendAIChatPubsubMethod(methodName, arg) {
324
320
  this.sendMessage(
325
- "aichat" /* AI_CHAT_CLIENT_ID */,
326
- // This name is hardcode, do not change it
321
+ this.targetAIChatClientId,
327
322
  {
328
323
  type: "pubsub" /* AI_CHAT_INTERNAL_COMM_TYPE */,
329
- // This name is hardcode, do not change it
330
324
  methodName,
331
325
  arg
332
326
  }
@@ -386,7 +380,7 @@ var AIChatClient = class extends Client {
386
380
  * @param message The message to show.
387
381
  */
388
382
  showChatMessage(message) {
389
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
383
+ this.sendMessage(this.targetAIChatClientId, {
390
384
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
391
385
  name: "showChatMessage" /* SHOW_CHAT_MESSAGE */,
392
386
  parameters: {
@@ -400,7 +394,7 @@ var AIChatClient = class extends Client {
400
394
  * @param message The error message to show.
401
395
  */
402
396
  showErrorMessage(message) {
403
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
397
+ this.sendMessage(this.targetAIChatClientId, {
404
398
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
405
399
  name: "showErrorMessage" /* SHOW_ERROR_MESSAGE */,
406
400
  parameters: {
@@ -414,7 +408,7 @@ var AIChatClient = class extends Client {
414
408
  * @param action The action to confirm.
415
409
  */
416
410
  confirmAction(action) {
417
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
411
+ this.sendMessage(this.targetAIChatClientId, {
418
412
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
419
413
  name: "confirmAction" /* CONFIRM_ACTION */,
420
414
  parameters: {
@@ -428,7 +422,7 @@ var AIChatClient = class extends Client {
428
422
  * @param options The options to show.
429
423
  */
430
424
  showOptions(options) {
431
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
425
+ this.sendMessage(this.targetAIChatClientId, {
432
426
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
433
427
  name: "showOptions" /* SHOW_OPTIONS */,
434
428
  parameters: {
@@ -442,7 +436,7 @@ var AIChatClient = class extends Client {
442
436
  * @param prompt The prompt to send.
443
437
  */
444
438
  sendChatPrompt(prompt) {
445
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
439
+ this.sendMessage(this.targetAIChatClientId, {
446
440
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
447
441
  name: "sendChatPrompt" /* SEND_CHAT_PROMPT */,
448
442
  parameters: {
@@ -454,7 +448,7 @@ var AIChatClient = class extends Client {
454
448
  * Show an unknown error message in the AI Chat component.
455
449
  */
456
450
  showComingSoon() {
457
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
451
+ this.sendMessage(this.targetAIChatClientId, {
458
452
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
459
453
  name: "showComingSoon" /* SHOW_COMING_SOON */,
460
454
  parameters: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iframe-pubsub",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "A PubSub library for iframe communication.",
5
5
  "author": "Lap Tran",
6
6
  "license": "ISC",