iframe-pubsub 1.0.15 → 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
@@ -156,12 +156,14 @@ var Client = class {
156
156
  *
157
157
  * @param pageId The ID of the page or component to register to.
158
158
  */
159
- constructor(pageId) {
159
+ constructor(pageId, targetAIChatClientId = "aichat" /* AI_CHAT_CLIENT_ID */) {
160
+ __publicField(this, "targetAIChatClientId");
160
161
  __publicField(this, "pageId");
161
162
  __publicField(this, "callback");
162
163
  __publicField(this, "pubsub");
163
164
  __publicField(this, "isIframe");
164
165
  __publicField(this, "boundHandleMessage");
166
+ this.targetAIChatClientId = targetAIChatClientId;
165
167
  this.pageId = pageId;
166
168
  this.pubsub = PubSub.getInstance();
167
169
  this.isIframe = window !== window.parent;
@@ -199,7 +201,7 @@ var Client = class {
199
201
  throw new Error("You are not allowed to clean up aichat from iframe.");
200
202
  }
201
203
  window.removeEventListener("message", this.boundHandleMessage);
202
- return this.pubsub.unregister("aichat" /* AI_CHAT_CLIENT_ID */);
204
+ return this.pubsub.unregister(this.targetAIChatClientId);
203
205
  }
204
206
  /**
205
207
  * Listen for messages from the parent page with a callback.
@@ -338,16 +340,14 @@ var AIChatClient = class extends Client {
338
340
  *
339
341
  * @param pageId The ID of the page or component to register to.
340
342
  */
341
- constructor(pageId) {
342
- super(pageId);
343
+ constructor(pageId, targetAIChatClientId = "aichat" /* AI_CHAT_CLIENT_ID */) {
344
+ super(pageId, targetAIChatClientId);
343
345
  }
344
346
  sendAIChatPubsubMethod(methodName, arg) {
345
347
  this.sendMessage(
346
- "aichat" /* AI_CHAT_CLIENT_ID */,
347
- // This name is hardcode, do not change it
348
+ this.targetAIChatClientId,
348
349
  {
349
350
  type: "pubsub" /* AI_CHAT_INTERNAL_COMM_TYPE */,
350
- // This name is hardcode, do not change it
351
351
  methodName,
352
352
  arg
353
353
  }
@@ -407,7 +407,7 @@ var AIChatClient = class extends Client {
407
407
  * @param message The message to show.
408
408
  */
409
409
  showChatMessage(message) {
410
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
410
+ this.sendMessage(this.targetAIChatClientId, {
411
411
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
412
412
  name: "showChatMessage" /* SHOW_CHAT_MESSAGE */,
413
413
  parameters: {
@@ -421,7 +421,7 @@ var AIChatClient = class extends Client {
421
421
  * @param message The error message to show.
422
422
  */
423
423
  showErrorMessage(message) {
424
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
424
+ this.sendMessage(this.targetAIChatClientId, {
425
425
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
426
426
  name: "showErrorMessage" /* SHOW_ERROR_MESSAGE */,
427
427
  parameters: {
@@ -435,7 +435,7 @@ var AIChatClient = class extends Client {
435
435
  * @param action The action to confirm.
436
436
  */
437
437
  confirmAction(action) {
438
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
438
+ this.sendMessage(this.targetAIChatClientId, {
439
439
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
440
440
  name: "confirmAction" /* CONFIRM_ACTION */,
441
441
  parameters: {
@@ -449,7 +449,7 @@ var AIChatClient = class extends Client {
449
449
  * @param options The options to show.
450
450
  */
451
451
  showOptions(options) {
452
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
452
+ this.sendMessage(this.targetAIChatClientId, {
453
453
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
454
454
  name: "showOptions" /* SHOW_OPTIONS */,
455
455
  parameters: {
@@ -463,7 +463,7 @@ var AIChatClient = class extends Client {
463
463
  * @param prompt The prompt to send.
464
464
  */
465
465
  sendChatPrompt(prompt) {
466
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
466
+ this.sendMessage(this.targetAIChatClientId, {
467
467
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
468
468
  name: "sendChatPrompt" /* SEND_CHAT_PROMPT */,
469
469
  parameters: {
@@ -475,7 +475,7 @@ var AIChatClient = class extends Client {
475
475
  * Show an unknown error message in the AI Chat component.
476
476
  */
477
477
  showComingSoon() {
478
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
478
+ this.sendMessage(this.targetAIChatClientId, {
479
479
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
480
480
  name: "showComingSoon" /* SHOW_COMING_SOON */,
481
481
  parameters: {
package/dist/index.mjs CHANGED
@@ -129,12 +129,14 @@ var Client = class {
129
129
  *
130
130
  * @param pageId The ID of the page or component to register to.
131
131
  */
132
- constructor(pageId) {
132
+ constructor(pageId, targetAIChatClientId = "aichat" /* AI_CHAT_CLIENT_ID */) {
133
+ __publicField(this, "targetAIChatClientId");
133
134
  __publicField(this, "pageId");
134
135
  __publicField(this, "callback");
135
136
  __publicField(this, "pubsub");
136
137
  __publicField(this, "isIframe");
137
138
  __publicField(this, "boundHandleMessage");
139
+ this.targetAIChatClientId = targetAIChatClientId;
138
140
  this.pageId = pageId;
139
141
  this.pubsub = PubSub.getInstance();
140
142
  this.isIframe = window !== window.parent;
@@ -172,7 +174,7 @@ var Client = class {
172
174
  throw new Error("You are not allowed to clean up aichat from iframe.");
173
175
  }
174
176
  window.removeEventListener("message", this.boundHandleMessage);
175
- return this.pubsub.unregister("aichat" /* AI_CHAT_CLIENT_ID */);
177
+ return this.pubsub.unregister(this.targetAIChatClientId);
176
178
  }
177
179
  /**
178
180
  * Listen for messages from the parent page with a callback.
@@ -311,16 +313,14 @@ var AIChatClient = class extends Client {
311
313
  *
312
314
  * @param pageId The ID of the page or component to register to.
313
315
  */
314
- constructor(pageId) {
315
- super(pageId);
316
+ constructor(pageId, targetAIChatClientId = "aichat" /* AI_CHAT_CLIENT_ID */) {
317
+ super(pageId, targetAIChatClientId);
316
318
  }
317
319
  sendAIChatPubsubMethod(methodName, arg) {
318
320
  this.sendMessage(
319
- "aichat" /* AI_CHAT_CLIENT_ID */,
320
- // This name is hardcode, do not change it
321
+ this.targetAIChatClientId,
321
322
  {
322
323
  type: "pubsub" /* AI_CHAT_INTERNAL_COMM_TYPE */,
323
- // This name is hardcode, do not change it
324
324
  methodName,
325
325
  arg
326
326
  }
@@ -380,7 +380,7 @@ var AIChatClient = class extends Client {
380
380
  * @param message The message to show.
381
381
  */
382
382
  showChatMessage(message) {
383
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
383
+ this.sendMessage(this.targetAIChatClientId, {
384
384
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
385
385
  name: "showChatMessage" /* SHOW_CHAT_MESSAGE */,
386
386
  parameters: {
@@ -394,7 +394,7 @@ var AIChatClient = class extends Client {
394
394
  * @param message The error message to show.
395
395
  */
396
396
  showErrorMessage(message) {
397
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
397
+ this.sendMessage(this.targetAIChatClientId, {
398
398
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
399
399
  name: "showErrorMessage" /* SHOW_ERROR_MESSAGE */,
400
400
  parameters: {
@@ -408,7 +408,7 @@ var AIChatClient = class extends Client {
408
408
  * @param action The action to confirm.
409
409
  */
410
410
  confirmAction(action) {
411
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
411
+ this.sendMessage(this.targetAIChatClientId, {
412
412
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
413
413
  name: "confirmAction" /* CONFIRM_ACTION */,
414
414
  parameters: {
@@ -422,7 +422,7 @@ var AIChatClient = class extends Client {
422
422
  * @param options The options to show.
423
423
  */
424
424
  showOptions(options) {
425
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
425
+ this.sendMessage(this.targetAIChatClientId, {
426
426
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
427
427
  name: "showOptions" /* SHOW_OPTIONS */,
428
428
  parameters: {
@@ -436,7 +436,7 @@ var AIChatClient = class extends Client {
436
436
  * @param prompt The prompt to send.
437
437
  */
438
438
  sendChatPrompt(prompt) {
439
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
439
+ this.sendMessage(this.targetAIChatClientId, {
440
440
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
441
441
  name: "sendChatPrompt" /* SEND_CHAT_PROMPT */,
442
442
  parameters: {
@@ -448,7 +448,7 @@ var AIChatClient = class extends Client {
448
448
  * Show an unknown error message in the AI Chat component.
449
449
  */
450
450
  showComingSoon() {
451
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
451
+ this.sendMessage(this.targetAIChatClientId, {
452
452
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
453
453
  name: "showComingSoon" /* SHOW_COMING_SOON */,
454
454
  parameters: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iframe-pubsub",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "A PubSub library for iframe communication.",
5
5
  "author": "Lap Tran",
6
6
  "license": "ISC",