iframe-pubsub 1.0.15 → 1.0.17

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
  */
@@ -87,6 +88,7 @@ declare enum AIChatNameEnum {
87
88
  SET_USER_ID = "setUserId",
88
89
  SET_CUSTOM_HEADERS = "setCustomHeaders",
89
90
  SET_CUSTOM_PAYLOAD = "setCustomPayload",
91
+ SET_METADATA = "setMetadata",
90
92
  SET_SUGGESTIONS = "setSuggestions",
91
93
  SHOW_SUGGESTIONS = "showSuggestions",
92
94
  SHOW_CHAT_MESSAGE = "showChatMessage",
@@ -104,7 +106,7 @@ declare class AIChatClient extends Client {
104
106
  *
105
107
  * @param pageId The ID of the page or component to register to.
106
108
  */
107
- constructor(pageId: string);
109
+ constructor(pageId: string, targetAIChatClientId?: string);
108
110
  private sendAIChatPubsubMethod;
109
111
  /**
110
112
  * Set the parent name then the AI Chat can know who should it communicate with.
@@ -136,6 +138,11 @@ declare class AIChatClient extends Client {
136
138
  * @param suggestions The suggestions to set.
137
139
  */
138
140
  setSuggestions(suggestions: any[]): void;
141
+ /**
142
+ * Product metadata for the AI Chat component.
143
+ * @param metadata JSON object containing metadata for the AI Chat component.
144
+ */
145
+ setMetadata(metadata: any): void;
139
146
  /**
140
147
  * Show suggestions in the AI Chat component.
141
148
  *
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
  */
@@ -87,6 +88,7 @@ declare enum AIChatNameEnum {
87
88
  SET_USER_ID = "setUserId",
88
89
  SET_CUSTOM_HEADERS = "setCustomHeaders",
89
90
  SET_CUSTOM_PAYLOAD = "setCustomPayload",
91
+ SET_METADATA = "setMetadata",
90
92
  SET_SUGGESTIONS = "setSuggestions",
91
93
  SHOW_SUGGESTIONS = "showSuggestions",
92
94
  SHOW_CHAT_MESSAGE = "showChatMessage",
@@ -104,7 +106,7 @@ declare class AIChatClient extends Client {
104
106
  *
105
107
  * @param pageId The ID of the page or component to register to.
106
108
  */
107
- constructor(pageId: string);
109
+ constructor(pageId: string, targetAIChatClientId?: string);
108
110
  private sendAIChatPubsubMethod;
109
111
  /**
110
112
  * Set the parent name then the AI Chat can know who should it communicate with.
@@ -136,6 +138,11 @@ declare class AIChatClient extends Client {
136
138
  * @param suggestions The suggestions to set.
137
139
  */
138
140
  setSuggestions(suggestions: any[]): void;
141
+ /**
142
+ * Product metadata for the AI Chat component.
143
+ * @param metadata JSON object containing metadata for the AI Chat component.
144
+ */
145
+ setMetadata(metadata: any): void;
139
146
  /**
140
147
  * Show suggestions in the AI Chat component.
141
148
  *
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.
@@ -320,6 +322,7 @@ var AIChatNameEnum = /* @__PURE__ */ ((AIChatNameEnum2) => {
320
322
  AIChatNameEnum2["SET_USER_ID"] = "setUserId";
321
323
  AIChatNameEnum2["SET_CUSTOM_HEADERS"] = "setCustomHeaders";
322
324
  AIChatNameEnum2["SET_CUSTOM_PAYLOAD"] = "setCustomPayload";
325
+ AIChatNameEnum2["SET_METADATA"] = "setMetadata";
323
326
  AIChatNameEnum2["SET_SUGGESTIONS"] = "setSuggestions";
324
327
  AIChatNameEnum2["SHOW_SUGGESTIONS"] = "showSuggestions";
325
328
  AIChatNameEnum2["SHOW_CHAT_MESSAGE"] = "showChatMessage";
@@ -338,16 +341,14 @@ var AIChatClient = class extends Client {
338
341
  *
339
342
  * @param pageId The ID of the page or component to register to.
340
343
  */
341
- constructor(pageId) {
342
- super(pageId);
344
+ constructor(pageId, targetAIChatClientId = "aichat" /* AI_CHAT_CLIENT_ID */) {
345
+ super(pageId, targetAIChatClientId);
343
346
  }
344
347
  sendAIChatPubsubMethod(methodName, arg) {
345
348
  this.sendMessage(
346
- "aichat" /* AI_CHAT_CLIENT_ID */,
347
- // This name is hardcode, do not change it
349
+ this.targetAIChatClientId,
348
350
  {
349
351
  type: "pubsub" /* AI_CHAT_INTERNAL_COMM_TYPE */,
350
- // This name is hardcode, do not change it
351
352
  methodName,
352
353
  arg
353
354
  }
@@ -393,6 +394,13 @@ var AIChatClient = class extends Client {
393
394
  setSuggestions(suggestions) {
394
395
  this.sendAIChatPubsubMethod("setSuggestions" /* SET_SUGGESTIONS */, suggestions);
395
396
  }
397
+ /**
398
+ * Product metadata for the AI Chat component.
399
+ * @param metadata JSON object containing metadata for the AI Chat component.
400
+ */
401
+ setMetadata(metadata) {
402
+ this.sendAIChatPubsubMethod("setMetadata" /* SET_METADATA */, metadata);
403
+ }
396
404
  /**
397
405
  * Show suggestions in the AI Chat component.
398
406
  *
@@ -407,7 +415,7 @@ var AIChatClient = class extends Client {
407
415
  * @param message The message to show.
408
416
  */
409
417
  showChatMessage(message) {
410
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
418
+ this.sendMessage(this.targetAIChatClientId, {
411
419
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
412
420
  name: "showChatMessage" /* SHOW_CHAT_MESSAGE */,
413
421
  parameters: {
@@ -421,7 +429,7 @@ var AIChatClient = class extends Client {
421
429
  * @param message The error message to show.
422
430
  */
423
431
  showErrorMessage(message) {
424
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
432
+ this.sendMessage(this.targetAIChatClientId, {
425
433
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
426
434
  name: "showErrorMessage" /* SHOW_ERROR_MESSAGE */,
427
435
  parameters: {
@@ -435,7 +443,7 @@ var AIChatClient = class extends Client {
435
443
  * @param action The action to confirm.
436
444
  */
437
445
  confirmAction(action) {
438
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
446
+ this.sendMessage(this.targetAIChatClientId, {
439
447
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
440
448
  name: "confirmAction" /* CONFIRM_ACTION */,
441
449
  parameters: {
@@ -449,7 +457,7 @@ var AIChatClient = class extends Client {
449
457
  * @param options The options to show.
450
458
  */
451
459
  showOptions(options) {
452
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
460
+ this.sendMessage(this.targetAIChatClientId, {
453
461
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
454
462
  name: "showOptions" /* SHOW_OPTIONS */,
455
463
  parameters: {
@@ -463,7 +471,7 @@ var AIChatClient = class extends Client {
463
471
  * @param prompt The prompt to send.
464
472
  */
465
473
  sendChatPrompt(prompt) {
466
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
474
+ this.sendMessage(this.targetAIChatClientId, {
467
475
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
468
476
  name: "sendChatPrompt" /* SEND_CHAT_PROMPT */,
469
477
  parameters: {
@@ -475,7 +483,7 @@ var AIChatClient = class extends Client {
475
483
  * Show an unknown error message in the AI Chat component.
476
484
  */
477
485
  showComingSoon() {
478
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
486
+ this.sendMessage(this.targetAIChatClientId, {
479
487
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
480
488
  name: "showComingSoon" /* SHOW_COMING_SOON */,
481
489
  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.
@@ -293,6 +295,7 @@ var AIChatNameEnum = /* @__PURE__ */ ((AIChatNameEnum2) => {
293
295
  AIChatNameEnum2["SET_USER_ID"] = "setUserId";
294
296
  AIChatNameEnum2["SET_CUSTOM_HEADERS"] = "setCustomHeaders";
295
297
  AIChatNameEnum2["SET_CUSTOM_PAYLOAD"] = "setCustomPayload";
298
+ AIChatNameEnum2["SET_METADATA"] = "setMetadata";
296
299
  AIChatNameEnum2["SET_SUGGESTIONS"] = "setSuggestions";
297
300
  AIChatNameEnum2["SHOW_SUGGESTIONS"] = "showSuggestions";
298
301
  AIChatNameEnum2["SHOW_CHAT_MESSAGE"] = "showChatMessage";
@@ -311,16 +314,14 @@ var AIChatClient = class extends Client {
311
314
  *
312
315
  * @param pageId The ID of the page or component to register to.
313
316
  */
314
- constructor(pageId) {
315
- super(pageId);
317
+ constructor(pageId, targetAIChatClientId = "aichat" /* AI_CHAT_CLIENT_ID */) {
318
+ super(pageId, targetAIChatClientId);
316
319
  }
317
320
  sendAIChatPubsubMethod(methodName, arg) {
318
321
  this.sendMessage(
319
- "aichat" /* AI_CHAT_CLIENT_ID */,
320
- // This name is hardcode, do not change it
322
+ this.targetAIChatClientId,
321
323
  {
322
324
  type: "pubsub" /* AI_CHAT_INTERNAL_COMM_TYPE */,
323
- // This name is hardcode, do not change it
324
325
  methodName,
325
326
  arg
326
327
  }
@@ -366,6 +367,13 @@ var AIChatClient = class extends Client {
366
367
  setSuggestions(suggestions) {
367
368
  this.sendAIChatPubsubMethod("setSuggestions" /* SET_SUGGESTIONS */, suggestions);
368
369
  }
370
+ /**
371
+ * Product metadata for the AI Chat component.
372
+ * @param metadata JSON object containing metadata for the AI Chat component.
373
+ */
374
+ setMetadata(metadata) {
375
+ this.sendAIChatPubsubMethod("setMetadata" /* SET_METADATA */, metadata);
376
+ }
369
377
  /**
370
378
  * Show suggestions in the AI Chat component.
371
379
  *
@@ -380,7 +388,7 @@ var AIChatClient = class extends Client {
380
388
  * @param message The message to show.
381
389
  */
382
390
  showChatMessage(message) {
383
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
391
+ this.sendMessage(this.targetAIChatClientId, {
384
392
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
385
393
  name: "showChatMessage" /* SHOW_CHAT_MESSAGE */,
386
394
  parameters: {
@@ -394,7 +402,7 @@ var AIChatClient = class extends Client {
394
402
  * @param message The error message to show.
395
403
  */
396
404
  showErrorMessage(message) {
397
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
405
+ this.sendMessage(this.targetAIChatClientId, {
398
406
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
399
407
  name: "showErrorMessage" /* SHOW_ERROR_MESSAGE */,
400
408
  parameters: {
@@ -408,7 +416,7 @@ var AIChatClient = class extends Client {
408
416
  * @param action The action to confirm.
409
417
  */
410
418
  confirmAction(action) {
411
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
419
+ this.sendMessage(this.targetAIChatClientId, {
412
420
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
413
421
  name: "confirmAction" /* CONFIRM_ACTION */,
414
422
  parameters: {
@@ -422,7 +430,7 @@ var AIChatClient = class extends Client {
422
430
  * @param options The options to show.
423
431
  */
424
432
  showOptions(options) {
425
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
433
+ this.sendMessage(this.targetAIChatClientId, {
426
434
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
427
435
  name: "showOptions" /* SHOW_OPTIONS */,
428
436
  parameters: {
@@ -436,7 +444,7 @@ var AIChatClient = class extends Client {
436
444
  * @param prompt The prompt to send.
437
445
  */
438
446
  sendChatPrompt(prompt) {
439
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
447
+ this.sendMessage(this.targetAIChatClientId, {
440
448
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
441
449
  name: "sendChatPrompt" /* SEND_CHAT_PROMPT */,
442
450
  parameters: {
@@ -448,7 +456,7 @@ var AIChatClient = class extends Client {
448
456
  * Show an unknown error message in the AI Chat component.
449
457
  */
450
458
  showComingSoon() {
451
- this.sendMessage("aichat" /* AI_CHAT_CLIENT_ID */, {
459
+ this.sendMessage(this.targetAIChatClientId, {
452
460
  type: "aichat" /* AI_CHAT_CLIENT_ID */,
453
461
  name: "showComingSoon" /* SHOW_COMING_SOON */,
454
462
  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.17",
4
4
  "description": "A PubSub library for iframe communication.",
5
5
  "author": "Lap Tran",
6
6
  "license": "ISC",