@15gifts/sdk 0.16.5 → 0.16.6

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.ts CHANGED
@@ -43,6 +43,7 @@ interface components {
43
43
  /**
44
44
  * Conversationid
45
45
  * @description Unique identifier for the conversation. This will be generated once, at the start of a conversation.
46
+ * @example 123e4567-e89b-12d3-a456-426614174000
46
47
  */
47
48
  conversationId?: string | null;
48
49
  };
@@ -60,6 +61,7 @@ interface components {
60
61
  /**
61
62
  * Fallbackmessage
62
63
  * @description What should a client render if they do not have a native renderer for this message type?
64
+ * @example Your options are a, b or c
63
65
  */
64
66
  fallbackMessage: string;
65
67
  /**
@@ -69,6 +71,12 @@ interface components {
69
71
  conversationSummary: string;
70
72
  /** @description Why have we been exited to chat? */
71
73
  reason: components['schemas']['ExitToHumanReason'];
74
+ /**
75
+ * Recommendations
76
+ * @description A list of recommendations the user received from the recommender.
77
+ * @default []
78
+ */
79
+ recommendations: components['schemas']['RecommendationV2'][];
72
80
  };
73
81
  /**
74
82
  * AssistantExitToPhoneMessage
@@ -84,6 +92,7 @@ interface components {
84
92
  /**
85
93
  * Fallbackmessage
86
94
  * @description What should a client render if they do not have a native renderer for this message type?
95
+ * @example Your options are a, b or c
87
96
  */
88
97
  fallbackMessage: string;
89
98
  /** @description Why have we been exited to phone? */
@@ -115,6 +124,7 @@ interface components {
115
124
  /**
116
125
  * Fallbackmessage
117
126
  * @description What should a client render if they do not have a native renderer for this message type?
127
+ * @example Your options are a, b or c
118
128
  */
119
129
  fallbackMessage: string;
120
130
  /** Recommendationidforexit */
@@ -148,6 +158,7 @@ interface components {
148
158
  /**
149
159
  * Fallbackmessage
150
160
  * @description What should a client render if they do not have a native renderer for this message type?
161
+ * @example Your options are a, b or c
151
162
  */
152
163
  fallbackMessage: string;
153
164
  /** Recommendationidforexit */
@@ -181,6 +192,7 @@ interface components {
181
192
  /**
182
193
  * Fallbackmessage
183
194
  * @description What should a client render if they do not have a native renderer for this message type?
195
+ * @example Your options are a, b or c
184
196
  */
185
197
  fallbackMessage: string;
186
198
  /**
@@ -208,6 +220,7 @@ interface components {
208
220
  /**
209
221
  * Fallbackmessage
210
222
  * @description What should a client render if they do not have a native renderer for this message type?
223
+ * @example Your options are a, b or c
211
224
  */
212
225
  fallbackMessage: string;
213
226
  /** Recommendations */
@@ -227,6 +240,7 @@ interface components {
227
240
  /**
228
241
  * Fallbackmessage
229
242
  * @description What should a client render if they do not have a native renderer for this message type?
243
+ * @example Your options are a, b or c
230
244
  */
231
245
  fallbackMessage: string;
232
246
  /** Recommendations */
@@ -248,6 +262,7 @@ interface components {
248
262
  /**
249
263
  * Fallbackmessage
250
264
  * @description What should a client render if they do not have a native renderer for this message type?
265
+ * @example Your options are a, b or c
251
266
  */
252
267
  fallbackMessage: string;
253
268
  /**
@@ -275,6 +290,7 @@ interface components {
275
290
  /**
276
291
  * Message
277
292
  * @description Message for the conversation.
293
+ * @example Hello, how can I help you today?
278
294
  */
279
295
  message: string;
280
296
  };
@@ -345,21 +361,43 @@ interface components {
345
361
  /**
346
362
  * Eligibleproducts
347
363
  * @description What product IDs is the user eligible for?
364
+ * @example [
365
+ * "12345"
366
+ * ]
348
367
  */
349
368
  eligibleProducts?: string[] | null;
350
369
  /**
351
370
  * Eligiblebundles
352
371
  * @description What bundle IDs is the user eligible for?
372
+ * @example [
373
+ * "12345"
374
+ * ]
353
375
  */
354
376
  eligibleBundles?: string[] | null;
355
377
  /**
356
378
  * Eligibleoffers
357
379
  * @description What offer IDs is the user eligible for?
380
+ * @example [
381
+ * "PROMO1234"
382
+ * ]
358
383
  */
359
384
  eligibleOffers?: string[] | null;
360
385
  /**
361
386
  * Productoverrides
362
387
  * @description The fields to override in the product specs as based on eligibility
388
+ * @example {
389
+ * "INTERNET": {
390
+ * "specifications": {
391
+ * "connectionSpeeds": {
392
+ * "averageDownloadSpeed": {
393
+ * "@type": "AverageDownloadSpeed",
394
+ * "unitText": "Mbps",
395
+ * "value": 100
396
+ * }
397
+ * }
398
+ * }
399
+ * }
400
+ * }
363
401
  */
364
402
  productOverrides?: {
365
403
  [key: string]: {
@@ -369,6 +407,21 @@ interface components {
369
407
  /**
370
408
  * Bundleoverrides
371
409
  * @description The fields to override in the product specs as based on eligibility
410
+ * @example {
411
+ * "BUNDLEDISCOUNT": {
412
+ * "prices": {
413
+ * "@type": "Standard",
414
+ * "description": "$17.50 per month for 12 months",
415
+ * "monthlyCost": 17.5,
416
+ * "parts": [
417
+ * {
418
+ * "@type": "MonthlyPricePart",
419
+ * "value": 17.5
420
+ * }
421
+ * ]
422
+ * }
423
+ * }
424
+ * }
372
425
  */
373
426
  bundleOverrides?: {
374
427
  [key: string]: {
@@ -378,6 +431,14 @@ interface components {
378
431
  /**
379
432
  * Offeroverrides
380
433
  * @description The fields to override in the offer specs as based on eligibility
434
+ * @example {
435
+ * "PROMO1234": {
436
+ * "discount": {
437
+ * "description": "Big Summer Blowout (20% off)",
438
+ * "value": 20
439
+ * }
440
+ * }
441
+ * }
381
442
  */
382
443
  offerOverrides?: {
383
444
  [key: string]: {
@@ -435,6 +496,11 @@ interface components {
435
496
  * @description Description of the offer from the feed data
436
497
  */
437
498
  description?: string | null;
499
+ /**
500
+ * Type
501
+ * @description The type of the offer
502
+ */
503
+ type?: string | null;
438
504
  };
439
505
  /** Product */
440
506
  Product: {
@@ -608,16 +674,22 @@ interface components {
608
674
  * Conversationid
609
675
  * Format: uuid
610
676
  * @description The conversation id
677
+ * @example 15630a82-0e3d-4d1b-ab7d-fb7481a7a344
611
678
  */
612
679
  conversationId: string;
613
680
  /**
614
681
  * Usermessage
615
682
  * @description The user message
683
+ * @example Hello
616
684
  */
617
685
  userMessage?: string | null;
618
686
  /**
619
687
  * Options
620
688
  * @description Which select options were picked?
689
+ * @example [
690
+ * "12345",
691
+ * "67890"
692
+ * ]
621
693
  */
622
694
  options: string[];
623
695
  };
@@ -636,16 +708,19 @@ interface components {
636
708
  * Conversationid
637
709
  * Format: uuid
638
710
  * @description The conversation id
711
+ * @example 15630a82-0e3d-4d1b-ab7d-fb7481a7a344
639
712
  */
640
713
  conversationId: string;
641
714
  /**
642
715
  * Usermessage
643
716
  * @description The user message
717
+ * @example Hello
644
718
  */
645
719
  userMessage?: string | null;
646
720
  /**
647
721
  * Option
648
722
  * @description Which select option was picked?
723
+ * @example 12345
649
724
  */
650
725
  option?: string | null;
651
726
  };
@@ -662,6 +737,11 @@ interface components {
662
737
  type: 'START_CONVERSATION';
663
738
  /** @description Context information we'll be getting with the request */
664
739
  conversationContext: components['schemas']['ConversationContext'];
740
+ /**
741
+ * Openingusermessage
742
+ * @description An optional opening message sent by the user as the very first message, for things such as UI chips in the frontend to prepopulate the conversation
743
+ */
744
+ openingUserMessage?: components['schemas']['UserTextMessage'] | components['schemas']['UserSingleSelectMessage'] | components['schemas']['UserMultiSelectMessage'] | null;
665
745
  };
666
746
  /**
667
747
  * UserTextMessage
@@ -678,11 +758,13 @@ interface components {
678
758
  * Conversationid
679
759
  * Format: uuid
680
760
  * @description The conversation id
761
+ * @example 15630a82-0e3d-4d1b-ab7d-fb7481a7a344
681
762
  */
682
763
  conversationId: string;
683
764
  /**
684
765
  * Usermessage
685
766
  * @description The user message
767
+ * @example Hello
686
768
  */
687
769
  userMessage: string;
688
770
  };
@@ -742,6 +824,13 @@ interface operations {
742
824
  [name: string]: unknown;
743
825
  };
744
826
  content: {
827
+ /**
828
+ * @example {
829
+ * "code": "ERROR_UNHANDLED",
830
+ * "message": "An error occurred",
831
+ * "detail": "Unauthorized access"
832
+ * }
833
+ */
745
834
  'application/json': unknown;
746
835
  };
747
836
  };
@@ -751,6 +840,13 @@ interface operations {
751
840
  [name: string]: unknown;
752
841
  };
753
842
  content: {
843
+ /**
844
+ * @example {
845
+ * "code": "ERROR_UNHANDLED",
846
+ * "message": "An error occurred",
847
+ * "detail": "Access forbidden"
848
+ * }
849
+ */
754
850
  'application/json': unknown;
755
851
  };
756
852
  };
@@ -760,6 +856,13 @@ interface operations {
760
856
  [name: string]: unknown;
761
857
  };
762
858
  content: {
859
+ /**
860
+ * @example {
861
+ * "code": "ERROR_UNHANDLED",
862
+ * "message": "An error occurred",
863
+ * "detail": "Customer 1234 not found"
864
+ * }
865
+ */
763
866
  'application/json': unknown;
764
867
  };
765
868
  };
@@ -769,6 +872,20 @@ interface operations {
769
872
  [name: string]: unknown;
770
873
  };
771
874
  content: {
875
+ /**
876
+ * @example {
877
+ * "code": "ERROR_UNHANDLED",
878
+ * "message": "An error occurred",
879
+ * "detail": {
880
+ * "loc": [
881
+ * "string",
882
+ * 0
883
+ * ],
884
+ * "msg": "string",
885
+ * "type": "string"
886
+ * }
887
+ * }
888
+ */
772
889
  'application/json': unknown;
773
890
  };
774
891
  };
@@ -849,6 +966,14 @@ interface paths {
849
966
  [name: string]: unknown;
850
967
  };
851
968
  content: {
969
+ /**
970
+ * @example {
971
+ * "pageviewId": "3c06dccf-06cb-4ffe-a3c2-863f76dcc765",
972
+ * "sessionId": "2f6863a9-2833-5521-a45d-359dcdfd154a",
973
+ * "userId": "163a692e-8ee2-623f-9927-0bb563b19853",
974
+ * "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
975
+ * }
976
+ */
852
977
  'application/json': {
853
978
  /**
854
979
  * @description A 36 character hash, 5 segments, separated by dashes that uniquely identifies a page view (page-shown event)
@@ -901,7 +1026,8 @@ interface paths {
901
1026
  /** @description User tracking event data */
902
1027
  requestBody: {
903
1028
  content: {
904
- /** @example {
1029
+ /**
1030
+ * @example {
905
1031
  * "conversationId": "386d85d7-9daa-8a87-85d4-3f93c990b292",
906
1032
  * "eventName": "entry_point-shown",
907
1033
  * "pageviewId": "3c06dccf-06cb-4ffe-a3c2-863f76dcc765",
@@ -910,73 +1036,85 @@ interface paths {
910
1036
  * "screenWidth": 390,
911
1037
  * "url": "https://www.example.com/telco/",
912
1038
  * "userAgent": "Mozilla/5.0 (Linux; Android 11; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36"
913
- * } */
1039
+ * }
1040
+ */
914
1041
  'application/json': {
915
1042
  additionalProperties?: {
916
- /** @description A 36 character alphanumeric hash that uniquely identifies a user.
1043
+ /**
1044
+ * @description A 36 character alphanumeric hash that uniquely identifies a user.
917
1045
  *
918
1046
  *
919
1047
  * This should match the UUID V4 as specified in RFC 9652:
920
1048
  * https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-4
921
1049
  *
922
- * e.g f81d4fae-7dec-41d0-a765-00a0c91e6bf6 */
1050
+ * e.g f81d4fae-7dec-41d0-a765-00a0c91e6bf6
1051
+ */
923
1052
  user_id?: string;
924
1053
  /** @description A timestamp describing the time the event occurred. This should conform to ISO 8601 standards and be in UTC. Example: "2024-07-17T10:11:16.591Z" */
925
1054
  event_at?: string;
926
1055
  /** @description The page url at the time the event is fired */
927
1056
  url?: string;
928
- /** @description What web browser the user is using e.g. chrome/firefox/safari etc. */
1057
+ /** @description What web browser the user is using e.g. chrome/firefox/safari etc. */
929
1058
  browser?: string;
930
1059
  /** @description The customer that the event occurred on */
931
1060
  customer_id?: string;
932
1061
  /** @description The user agent string e.g. "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" */
933
1062
  user_agent?: string;
934
- /** @description A 36 character alphanumeric hash that uniquely identifies a tracking event
1063
+ /**
1064
+ * @description A 36 character alphanumeric hash that uniquely identifies a tracking event
935
1065
  *
936
1066
  * This should match the UUID V4 as specified in RFC 9652:
937
1067
  * https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-4
938
1068
  *
939
- * e.g f81d4fae-7dec-41d0-a765-00a0c91e6bf6 */
1069
+ * e.g f81d4fae-7dec-41d0-a765-00a0c91e6bf6
1070
+ */
940
1071
  event_id?: string;
941
1072
  /** @description The name of an event */
942
1073
  event_name?: string;
943
- /** @description A 36 character alphanumeric hash that uniquely identifies a page view (page-shown event)
1074
+ /**
1075
+ * @description A 36 character alphanumeric hash that uniquely identifies a page view (page-shown event)
944
1076
  *
945
1077
  * This should match the UUID V4 as specified in RFC 9652:
946
1078
  * https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-4
947
1079
  *
948
- * e.g f81d4fae-7dec-41d0-a765-00a0c91e6bf6 */
1080
+ * e.g f81d4fae-7dec-41d0-a765-00a0c91e6bf6
1081
+ */
949
1082
  pageview_id?: string;
950
1083
  /** @description A unique user id native to our customers web analytics platforms (adobe, google analytics etc). Helps us & our customers align our data with what customers see in their platforms. */
951
1084
  web_analytics_platform_user_id?: string | null;
952
- /** @description A 36 character alphanumeric hash that uniquely identifies a session.
1085
+ /**
1086
+ * @description A 36 character alphanumeric hash that uniquely identifies a session.
953
1087
  *
954
1088
  *
955
1089
  * This should match the UUID V4 as specified in RFC 9652:
956
1090
  * https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-4
957
1091
  *
958
1092
  * e.g f81d4fae-7dec-41d0-a765-00a0c91e6bf6
959
- * */
1093
+ */
960
1094
  browser_session_id?: string | null;
961
1095
  /** @description The device screen width in pixels - window.screen.width in JS. This is a user level property that should never change. */
962
1096
  screen_width?: number;
963
1097
  /** @description The device screen height in pixels - window.screen.height in JS. This is a user level property that should never change. */
964
1098
  screen_height?: number;
965
- /** @description The size of the device's screen, based off the actual user experience it will generate, assuming the browser window takes up the whole screen.
1099
+ /**
1100
+ * @description The size of the device's screen, based off the actual user experience it will generate, assuming the browser window takes up the whole screen.
966
1101
  *
967
1102
  * Based off https://15gifts.atlassian.net/wiki/spaces/AI/pages/3981443139/Breakpoints+for+mobile+desktop
968
1103
  *
969
1104
  * screen_width <= 480px = 'mobile'
970
- * screen_width > 480px = 'large' */
1105
+ * screen_width > 480px = 'large'
1106
+ */
971
1107
  screen_size?: string;
972
1108
  /** @description The type of entry point the event refers to, e.g. engagement_button (previously named tab), engagement popup (previously named engagement bubble) etc */
973
1109
  entry_point_type?: string;
974
- /** @description A 36 character alphanumeric hash that uniquely identifies a conversation.
1110
+ /**
1111
+ * @description A 36 character alphanumeric hash that uniquely identifies a conversation.
975
1112
  *
976
1113
  * This should match the UUID V4 as specified in RFC 9652:
977
1114
  * https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-4
978
1115
  *
979
- * e.g f81d4fae-7dec-41d0-a765-00a0c91e6bf6 */
1116
+ * e.g f81d4fae-7dec-41d0-a765-00a0c91e6bf6
1117
+ */
980
1118
  conversation_id?: string;
981
1119
  /** @description The name of the system/service that the event originates from */
982
1120
  service?: string;
@@ -994,14 +1132,15 @@ interface paths {
994
1132
  tool_ui_closed_reason?: string;
995
1133
  /** @description Specifies whether the click on the entry point was a positive or negative CTA. Positive would be expected to open the tool ui, negative would be expected to close the entry point. */
996
1134
  entry_point_click_type?: string | null;
997
- /** @description Describes what exactly was clicked on an entry point that lead to the tool opening.
1135
+ /**
1136
+ * @description Describes what exactly was clicked on an entry point that lead to the tool opening.
998
1137
  *
999
1138
  * Value should be one of the following:
1000
1139
  *
1001
1140
  * 'main_cta' if the standard sparkles cta is clicked
1002
1141
  * 'keyword_box' - if it's the freetext box that's clicked
1003
1142
  * 'prompt_chip_{promptchiptext}' - if an example prompt is clicked e.g. 'prompt_chip_what_speed_is_best_for_my_devices' - we'll revise this tracking post fake door test if prompt chips become more permanent
1004
- * */
1143
+ */
1005
1144
  entry_point_click_element?: string;
1006
1145
  /** @description A list of ids that each correspond to their own recommendation, with all recs in the list being 'exit to purchase-able' or 'exit to chat-able' */
1007
1146
  recommendation_ids_for_exit?: unknown[];
@@ -1015,27 +1154,26 @@ interface paths {
1015
1154
  experiment_variation_name?: string;
1016
1155
  /** @description Describes the reason the entry point was closed. When the value is 'customer_triggered' it's because it's been programmatically closed by the customer (by running window.axiom.integrations.hide()). When it's 'user_close_click' it's because the actual end user has closed it manually by clicking. */
1017
1156
  entry_point_closed_reason?: string;
1018
- /** @description A categorical property to denote which party was responsible for suppression. This is useful for accurately calculating control conversion rates, it allows us to count how many users were suppressed before humara loading, and how many were put in a control group.
1019
- * */
1157
+ /** @description A categorical property to denote which party was responsible for suppression. This is useful for accurately calculating control conversion rates, it allows us to count how many users were suppressed before humara loading, and how many were put in a control group. */
1020
1158
  suppressed_by?: unknown[];
1021
- /** @description A categorical property that describes the reason for the suppression. When the value is 'customer_triggered' it's because it's been programmatically closed by the customer (by running window.axiom.integrations.hide())
1022
- * */
1159
+ /** @description A categorical property that describes the reason for the suppression. When the value is 'customer_triggered' it's because it's been programmatically closed by the customer (by running window.axiom.integrations.hide()) */
1023
1160
  suppressed_reason?: unknown[];
1024
1161
  /** @description The type of destination the user will be sent to as a result of exiting to chat. E.g 'phone','chat','email' etc */
1025
1162
  exit_destination_type?: string;
1026
1163
  /** @description Describes whether a user clicked the thumbs up ('positive') or thumbs down ('negative') on the rec card */
1027
1164
  rec_card_feedback_sentiment?: string;
1028
- /** @description A 32 character alphanumeric hash that uniquely identifies a single rec in a recommendation set.
1165
+ /**
1166
+ * @description A 32 character alphanumeric hash that uniquely identifies a single rec in a recommendation set.
1029
1167
  *
1030
1168
  * This should match the UUID V4 as specified in RFC 9652:
1031
1169
  * https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-4
1032
1170
  *
1033
- * e.g f81d4fae-7dec-41d0-a765-00a0c91e6bf6 */
1171
+ * e.g f81d4fae-7dec-41d0-a765-00a0c91e6bf6
1172
+ */
1034
1173
  recommendation_id?: string;
1035
- /** @description List of objects that represents the options for single & multiselect questions. */
1174
+ /** @description List of objects that represents the options for single & multiselect questions. */
1036
1175
  message_select_options?: unknown[];
1037
- /** @description The text that was visible to the user on the CTA button
1038
- * */
1176
+ /** @description The text that was visible to the user on the CTA button */
1039
1177
  button_text?: string;
1040
1178
  };
1041
1179
  /**
@@ -1326,6 +1464,7 @@ declare class Client {
1326
1464
  fallbackMessage: string;
1327
1465
  conversationSummary: string;
1328
1466
  reason: components["schemas"]["ExitToHumanReason"];
1467
+ recommendations: components["schemas"]["RecommendationV2"][];
1329
1468
  } | {
1330
1469
  type: "EXIT_TO_PHONE";
1331
1470
  fallbackMessage: string;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var V=Object.create;var c=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var j=(e,t)=>{for(var s in t)c(e,s,{get:t[s],enumerable:!0})},R=(e,t,s,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of b(t))!W.call(e,n)&&n!==s&&c(e,n,{get:()=>t[n],enumerable:!(o=N(t,n))||o.enumerable});return e};var q=(e,t,s)=>(s=e!=null?V(D(e)):{},R(t||!e||!e.__esModule?c(s,"default",{value:e,enumerable:!0}):s,e)),$=e=>R(c({},"__esModule",{value:!0}),e);var H={};j(H,{CONVERSATION_ID:()=>p,Client:()=>O,JWT_TOKEN:()=>m,SDKError:()=>i,SESSION_ID:()=>x,TTL:()=>U,USER_ID:()=>E,authMiddleware:()=>d,deleteConversationId:()=>u,errorMiddleware:()=>l,getConversationId:()=>v,getSessionId:()=>y,getToken:()=>A,getUserId:()=>C,headerMiddleware:()=>h,isTokenExpired:()=>_,setConversationId:()=>I,setSessionId:()=>M,setToken:()=>T,setUserId:()=>g});module.exports=$(H);var P=q(require("openapi-fetch"));var p="__15gifts_conversation_id",u=()=>sessionStorage.removeItem(p),v=()=>sessionStorage.getItem(p),I=e=>sessionStorage.setItem(p,e);var x="__15gifts_session_id",y=()=>sessionStorage.getItem(x),M=e=>sessionStorage.setItem(x,e);var B=e=>{let t=localStorage.getItem(e);if(!t)return null;let s=JSON.parse(t);return Date.now()>s.expires?(localStorage.removeItem(e),null):s.value},w=B;var F=(e,t,s)=>{let o={expires:Date.now()+s,value:t};localStorage.setItem(e,JSON.stringify(o))},S=F;var J=1e3*60*60*24,E="__15gifts_user_id",U=J*30,C=()=>{let e=w(E);return e&&g(e),e},g=e=>S(E,e,U);var m="__15gifts_identity_token",_=e=>{try{let[,t]=e.split(".");if(!t)throw new Error("Invalid token payload");let s=JSON.parse(atob(t));return s.exp&&Date.now()/1e3>s.exp}catch(t){return console.error("Invalid token format",t),!0}},A=()=>{let e=localStorage.getItem(m);return!e||_(e)?(localStorage.removeItem(m),null):e},T=e=>localStorage.setItem(m,e);var K=e=>({onRequest:async({request:t})=>{if(t.url.includes("/identity/"))return t;if(!e)throw new Error("Access token is required for authentication.");return t.headers.set("Authorization",`Bearer ${e}`),t}}),d=K;var X={onResponse:async({response:e})=>{if(!e.ok){let t=await e.json();throw new Error(t.message)}return e}},l=X;var z=(e,t)=>({onRequest:async({request:s})=>(e.pageviewId&&s.headers.set("X-PAGEVIEW-ID",e.pageviewId),t&&s.headers.set("X-PAGE-URL",t),s)}),h=z;var f="0.16.5";var i=class e extends Error{sdkVersion;cause;constructor(t,{cause:s}={}){super(t),this.name="SDKError",this.cause=s,this.sdkVersion=f,Object.setPrototypeOf(this,e.prototype)}};var O=class{endpoint;identity;constructor(t){let{conversationUrl:s,customerId:o,fetch:n,frontendUrl:r,headers:a}=t,k={...a,"X-SDK-VERSION":f};this.endpoint={conversation:(0,P.default)({baseUrl:s,fetch:n,headers:k,credentials:"include"}),frontend:(0,P.default)({baseUrl:r,fetch:n,headers:k})},this.identity={customerId:o,conversationId:v()??void 0,sessionId:y()??void 0,userId:C()??void 0},this.endpoint.conversation.use(l),this.endpoint.conversation.use(h(this.identity,window.location.href))}async createIdentity(){let{customerId:t,sessionId:s,userId:o}=this.identity;try{let{data:n}=await this.endpoint.frontend.POST("/api/tracking/identity/v2",{body:{customerId:t,sessionId:s,userId:o,url:window.location.href,userAgent:window.navigator.userAgent}});if(!n)throw new i("No data received from identity API");this.identity.pageviewId=n.pageviewId,s||(this.identity.sessionId=n.sessionId,M(n.sessionId)),o||(this.identity.userId=n.userId,g(n.userId)),T(n.token),Object.values(this.endpoint).forEach(r=>{r.use(d(n.token))})}catch(n){throw Object.values(this.endpoint).forEach(r=>{r.use(d())}),new i("Failed to create identity",{cause:n})}}endConversation(){u(),this.identity.conversationId=void 0}async startConversation(t){this.endConversation();let s={...t},{data:o}=await this.endpoint.conversation.POST("/api/conversation/v3",{body:{type:"START_CONVERSATION",conversationContext:s}});if(!o)throw new i("No data received from Conversation API");let[n,...r]=o,a=n.conversationId;if(!a)throw new i("Conversation ID not received in API response");return I(a),this.identity.conversationId=a,r}async sendMessage(t){let s=this.identity.conversationId;if(!s)throw new i("Conversation ID not set");let{data:o}=await this.endpoint.conversation.POST("/api/conversation/v3",{body:{conversationId:s,...t}});if(!o)throw new i("No data received from conversation API");return o.filter(n=>n.type!=="CONVERSATION_ID")}async trackEvent(t,s){let o={additionalProperties:s,conversationId:this.identity.conversationId,eventName:t,pageviewId:this.identity.pageviewId??"unknown",screenWidth:window.screen.width,screenHeight:window.screen.height,screenSize:window.screen.width<=480?"mobile":"large",url:window.location.href,userAgent:window.navigator.userAgent};return this.endpoint.frontend.POST("/api/tracking/user/v2",{body:o})}getIdentity(){return this.identity}getIdentityToken(){return A()}};0&&(module.exports={CONVERSATION_ID,Client,JWT_TOKEN,SDKError,SESSION_ID,TTL,USER_ID,authMiddleware,deleteConversationId,errorMiddleware,getConversationId,getSessionId,getToken,getUserId,headerMiddleware,isTokenExpired,setConversationId,setSessionId,setToken,setUserId});
1
+ "use strict";var V=Object.create;var c=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var j=(e,t)=>{for(var s in t)c(e,s,{get:t[s],enumerable:!0})},R=(e,t,s,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of b(t))!W.call(e,n)&&n!==s&&c(e,n,{get:()=>t[n],enumerable:!(o=N(t,n))||o.enumerable});return e};var q=(e,t,s)=>(s=e!=null?V(D(e)):{},R(t||!e||!e.__esModule?c(s,"default",{value:e,enumerable:!0}):s,e)),$=e=>R(c({},"__esModule",{value:!0}),e);var H={};j(H,{CONVERSATION_ID:()=>p,Client:()=>O,JWT_TOKEN:()=>m,SDKError:()=>i,SESSION_ID:()=>x,TTL:()=>U,USER_ID:()=>E,authMiddleware:()=>d,deleteConversationId:()=>u,errorMiddleware:()=>l,getConversationId:()=>v,getSessionId:()=>y,getToken:()=>A,getUserId:()=>C,headerMiddleware:()=>h,isTokenExpired:()=>_,setConversationId:()=>I,setSessionId:()=>M,setToken:()=>T,setUserId:()=>g});module.exports=$(H);var P=q(require("openapi-fetch"));var p="__15gifts_conversation_id",u=()=>sessionStorage.removeItem(p),v=()=>sessionStorage.getItem(p),I=e=>sessionStorage.setItem(p,e);var x="__15gifts_session_id",y=()=>sessionStorage.getItem(x),M=e=>sessionStorage.setItem(x,e);var B=e=>{let t=localStorage.getItem(e);if(!t)return null;let s=JSON.parse(t);return Date.now()>s.expires?(localStorage.removeItem(e),null):s.value},w=B;var F=(e,t,s)=>{let o={expires:Date.now()+s,value:t};localStorage.setItem(e,JSON.stringify(o))},S=F;var J=1e3*60*60*24,E="__15gifts_user_id",U=J*30,C=()=>{let e=w(E);return e&&g(e),e},g=e=>S(E,e,U);var m="__15gifts_identity_token",_=e=>{try{let[,t]=e.split(".");if(!t)throw new Error("Invalid token payload");let s=JSON.parse(atob(t));return s.exp&&Date.now()/1e3>s.exp}catch(t){return console.error("Invalid token format",t),!0}},A=()=>{let e=localStorage.getItem(m);return!e||_(e)?(localStorage.removeItem(m),null):e},T=e=>localStorage.setItem(m,e);var K=e=>({onRequest:async({request:t})=>{if(t.url.includes("/identity/"))return t;if(!e)throw new Error("Access token is required for authentication.");return t.headers.set("Authorization",`Bearer ${e}`),t}}),d=K;var X={onResponse:async({response:e})=>{if(!e.ok){let t=await e.json();throw new Error(t.message)}return e}},l=X;var z=(e,t)=>({onRequest:async({request:s})=>(e.pageviewId&&s.headers.set("X-PAGEVIEW-ID",e.pageviewId),t&&s.headers.set("X-PAGE-URL",t),s)}),h=z;var f="0.16.6";var i=class e extends Error{sdkVersion;cause;constructor(t,{cause:s}={}){super(t),this.name="SDKError",this.cause=s,this.sdkVersion=f,Object.setPrototypeOf(this,e.prototype)}};var O=class{endpoint;identity;constructor(t){let{conversationUrl:s,customerId:o,fetch:n,frontendUrl:r,headers:a}=t,k={...a,"X-SDK-VERSION":f};this.endpoint={conversation:(0,P.default)({baseUrl:s,fetch:n,headers:k,credentials:"include"}),frontend:(0,P.default)({baseUrl:r,fetch:n,headers:k})},this.identity={customerId:o,conversationId:v()??void 0,sessionId:y()??void 0,userId:C()??void 0},this.endpoint.conversation.use(l),this.endpoint.conversation.use(h(this.identity,window.location.href))}async createIdentity(){let{customerId:t,sessionId:s,userId:o}=this.identity;try{let{data:n}=await this.endpoint.frontend.POST("/api/tracking/identity/v2",{body:{customerId:t,sessionId:s,userId:o,url:window.location.href,userAgent:window.navigator.userAgent}});if(!n)throw new i("No data received from identity API");this.identity.pageviewId=n.pageviewId,s||(this.identity.sessionId=n.sessionId,M(n.sessionId)),o||(this.identity.userId=n.userId,g(n.userId)),T(n.token),Object.values(this.endpoint).forEach(r=>{r.use(d(n.token))})}catch(n){throw Object.values(this.endpoint).forEach(r=>{r.use(d())}),new i("Failed to create identity",{cause:n})}}endConversation(){u(),this.identity.conversationId=void 0}async startConversation(t){this.endConversation();let s={...t},{data:o}=await this.endpoint.conversation.POST("/api/conversation/v3",{body:{type:"START_CONVERSATION",conversationContext:s}});if(!o)throw new i("No data received from Conversation API");let[n,...r]=o,a=n.conversationId;if(!a)throw new i("Conversation ID not received in API response");return I(a),this.identity.conversationId=a,r}async sendMessage(t){let s=this.identity.conversationId;if(!s)throw new i("Conversation ID not set");let{data:o}=await this.endpoint.conversation.POST("/api/conversation/v3",{body:{conversationId:s,...t}});if(!o)throw new i("No data received from conversation API");return o.filter(n=>n.type!=="CONVERSATION_ID")}async trackEvent(t,s){let o={additionalProperties:s,conversationId:this.identity.conversationId,eventName:t,pageviewId:this.identity.pageviewId??"unknown",screenWidth:window.screen.width,screenHeight:window.screen.height,screenSize:window.screen.width<=480?"mobile":"large",url:window.location.href,userAgent:window.navigator.userAgent};return this.endpoint.frontend.POST("/api/tracking/user/v2",{body:o})}getIdentity(){return this.identity}getIdentityToken(){return A()}};0&&(module.exports={CONVERSATION_ID,Client,JWT_TOKEN,SDKError,SESSION_ID,TTL,USER_ID,authMiddleware,deleteConversationId,errorMiddleware,getConversationId,getSessionId,getToken,getUserId,headerMiddleware,isTokenExpired,setConversationId,setSessionId,setToken,setUserId});
2
2
  //# sourceMappingURL=index.js.map