@15gifts/sdk 0.3.0 → 0.4.0

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
@@ -1,4 +1,5 @@
1
- import { Client as Client$1 } from 'openapi-fetch';
1
+ import * as openapi_fetch from 'openapi-fetch';
2
+ import { Client as Client$1, Middleware } from 'openapi-fetch';
2
3
 
3
4
  /**
4
5
  * This file was auto-generated by openapi-typescript.
@@ -469,7 +470,7 @@ interface operations {
469
470
  [name: string]: unknown;
470
471
  };
471
472
  content: {
472
- 'application/json': components['schemas']['ConversationResponseMessageChunk'] | components['schemas']['ConversationResponseDebugChunk'];
473
+ 'application/json': (components['schemas']['ConversationResponseMessageChunk'] | components['schemas']['ConversationResponseDebugChunk'])[];
473
474
  };
474
475
  };
475
476
  /** @description Validation Error */
@@ -553,7 +554,7 @@ interface operations {
553
554
  * Do not make direct changes to the file.
554
555
  */
555
556
  interface paths {
556
- '/api/config/v2/{customerId}': {
557
+ '/api/tracking/identity/v1': {
557
558
  parameters: {
558
559
  query?: never;
559
560
  header?: never;
@@ -563,33 +564,27 @@ interface paths {
563
564
  get?: never;
564
565
  put?: never;
565
566
  /**
566
- * Get front-end configuration
567
- * @description Get front-end configuration for the partner identified by the given ID
567
+ * Generate tracking identifiers
568
+ * @deprecated
569
+ * @description Generate tracking identifiers for a user
568
570
  */
569
571
  post: {
570
572
  parameters: {
571
573
  query?: never;
572
574
  header?: never;
573
- path: {
574
- /** @description Customer ID */
575
- customerId: string;
576
- };
575
+ path?: never;
577
576
  cookie?: never;
578
577
  };
579
- /** @description Product Expert user feedback */
578
+ /** @description Generate tracking identifiers for a user */
580
579
  requestBody: {
581
580
  content: {
582
581
  'application/json': {
583
- /**
584
- * Format: uri
585
- * @description URL of the page where the product-expert will be shown
586
- * @example https://www.example.com/telco/
587
- */
588
- url: string;
582
+ /** @description Customer ID */
583
+ customerId: string;
589
584
  /** @description User ID */
590
- userId?: string;
585
+ createUserId?: boolean;
591
586
  /** @description Session ID */
592
- sessionId: string;
587
+ createSessionId?: boolean;
593
588
  };
594
589
  };
595
590
  };
@@ -601,126 +596,13 @@ interface paths {
601
596
  };
602
597
  content: {
603
598
  'application/json': {
604
- frontend: {
605
- customer: {
606
- id: string;
607
- displayName: string;
608
- domain?: string;
609
- };
610
- engage: {
611
- text: string;
612
- /** @enum {string} */
613
- type: 'floating' | 'embedded' | 'embedded-fullwidth';
614
- };
615
- styles: {
616
- primaryColor: string;
617
- hoverColor: string;
618
- textColor: string;
619
- };
620
- };
621
- show: boolean;
622
- features?: string[];
623
- metadata: {
624
- customerVersion: string;
625
- customerRevision: string;
626
- productVersion: string;
627
- productRevision: string;
628
- };
599
+ /** @description User ID */
600
+ userId?: string;
601
+ /** @description Session ID */
602
+ sessionId?: string;
629
603
  };
630
604
  };
631
605
  };
632
- /** @description Default Response */
633
- 404: {
634
- headers: {
635
- [name: string]: unknown;
636
- };
637
- content?: never;
638
- };
639
- };
640
- };
641
- delete?: never;
642
- options?: never;
643
- head?: never;
644
- patch?: never;
645
- trace?: never;
646
- };
647
- '/api/feedback/v1': {
648
- parameters: {
649
- query?: never;
650
- header?: never;
651
- path?: never;
652
- cookie?: never;
653
- };
654
- get?: never;
655
- put?: never;
656
- /**
657
- * Submit user feedback
658
- * @description Submit user feedback
659
- */
660
- post: {
661
- parameters: {
662
- query?: never;
663
- header?: never;
664
- path?: never;
665
- cookie?: never;
666
- };
667
- /** @description Product Expert user feedback */
668
- requestBody: {
669
- content: {
670
- /** @example {
671
- * "customerId": "oclet",
672
- * "userId": "163a692e-8ee2-623f-9927-0bb563b19853",
673
- * "sessionId": "2f6863a9-2833-5521-a45d-359dcdfd154a",
674
- * "conversationId": "386d85d7-9daa-8a87-85d4-3f93c990b292",
675
- * "url": "https://www.example.com/telco/",
676
- * "deviceType": "desktop",
677
- * "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
678
- * "rating": 4,
679
- * "ratingText": "excellent"
680
- * } */
681
- 'application/json': {
682
- /** @description Customer ID */
683
- customerId: string;
684
- /** @description User ID */
685
- userId?: string;
686
- /** @description Session ID */
687
- sessionId: string;
688
- /** @description Conversation ID */
689
- conversationId?: string;
690
- /** @description URL */
691
- url?: string;
692
- /**
693
- * @description Device Type
694
- * @enum {string}
695
- */
696
- deviceType?: 'desktop' | 'mobile' | 'tablet';
697
- /** @description User Agent */
698
- userAgent?: string;
699
- /** @description Conversation Rating */
700
- rating: number;
701
- /**
702
- * @description Conversation Rating
703
- * @enum {string}
704
- */
705
- ratingText: 'poor' | 'fair' | 'good' | 'excellent';
706
- };
707
- };
708
- };
709
- responses: {
710
- /** @description Successful response */
711
- 204: {
712
- headers: {
713
- [name: string]: unknown;
714
- };
715
- content?: never;
716
- };
717
- /** @description Default Response */
718
- 404: {
719
- headers: {
720
- [name: string]: unknown;
721
- };
722
- content?: never;
723
- };
724
606
  };
725
607
  };
726
608
  delete?: never;
@@ -729,7 +611,7 @@ interface paths {
729
611
  patch?: never;
730
612
  trace?: never;
731
613
  };
732
- '/api/tracking/identity/v1': {
614
+ '/api/tracking/identity/v2': {
733
615
  parameters: {
734
616
  query?: never;
735
617
  header?: never;
@@ -755,10 +637,10 @@ interface paths {
755
637
  'application/json': {
756
638
  /** @description Customer ID */
757
639
  customerId: string;
758
- /** @description User ID */
759
- createUserId?: boolean;
760
640
  /** @description Session ID */
761
- createSessionId?: boolean;
641
+ sessionId?: string;
642
+ /** @description User ID */
643
+ userId?: string;
762
644
  };
763
645
  };
764
646
  };
@@ -770,10 +652,12 @@ interface paths {
770
652
  };
771
653
  content: {
772
654
  'application/json': {
773
- /** @description User ID */
774
- userId?: string;
775
655
  /** @description Session ID */
776
- sessionId?: string;
656
+ sessionId: string;
657
+ /** @description User ID */
658
+ userId: string;
659
+ /** @description JSON Web Token (JWT) */
660
+ token: string;
777
661
  };
778
662
  };
779
663
  };
@@ -796,6 +680,7 @@ interface paths {
796
680
  put?: never;
797
681
  /**
798
682
  * Submit sales tracking data
683
+ * @deprecated
799
684
  * @description Submit sales tracking data
800
685
  */
801
686
  post: {
@@ -898,6 +783,111 @@ interface paths {
898
783
  patch?: never;
899
784
  trace?: never;
900
785
  };
786
+ '/api/tracking/sales/v2': {
787
+ parameters: {
788
+ query?: never;
789
+ header?: never;
790
+ path?: never;
791
+ cookie?: never;
792
+ };
793
+ get?: never;
794
+ put?: never;
795
+ /**
796
+ * Submit sales tracking data
797
+ * @description Submit sales tracking data
798
+ */
799
+ post: {
800
+ parameters: {
801
+ query?: never;
802
+ header?: never;
803
+ path?: never;
804
+ cookie?: never;
805
+ };
806
+ /** @description Sales tracking event data */
807
+ requestBody: {
808
+ content: {
809
+ /** @example {
810
+ * "conversationId": "386d85d7-9daa-8a87-85d4-3f93c990b292",
811
+ * "currency": "GBP",
812
+ * "items": [
813
+ * {
814
+ * "name": "Product 1",
815
+ * "productRef": "1260449",
816
+ * "quantity": 1,
817
+ * "recurring": 10
818
+ * },
819
+ * {
820
+ * "name": "Product 2",
821
+ * "price": 50,
822
+ * "productRef": "fe-56-sd2458",
823
+ * "quantity": 2
824
+ * }
825
+ * ],
826
+ * "saleRef": "34596872",
827
+ * "totalPrice": 100,
828
+ * "totalRecurring": 10
829
+ * } */
830
+ 'application/json': {
831
+ /** @description Conversation ID */
832
+ conversationId?: string;
833
+ /** @description Contract Length */
834
+ contractLength?: number;
835
+ /** @description Currency Code */
836
+ currency: string;
837
+ /**
838
+ * @description Device Type
839
+ * @enum {string}
840
+ */
841
+ deviceType?: 'desktop' | 'mobile' | 'tablet';
842
+ /** @description Event data */
843
+ items?: {
844
+ /** @description Product Name */
845
+ name?: string;
846
+ /** @description Price */
847
+ price?: number;
848
+ /** @description Product Reference */
849
+ productRef?: string;
850
+ /** @description Quantity */
851
+ quantity?: number;
852
+ /** @description Recurring Price */
853
+ recurring?: number;
854
+ }[];
855
+ /** @description Sale Reference */
856
+ saleRef: string;
857
+ /** @description Total Price */
858
+ totalPrice: number;
859
+ /** @description Total Recurring Price */
860
+ totalRecurring?: number;
861
+ /** @description URL */
862
+ url?: string;
863
+ /** @description User Agent */
864
+ userAgent?: string;
865
+ };
866
+ };
867
+ };
868
+ responses: {
869
+ /** @description Successful response */
870
+ 204: {
871
+ headers: {
872
+ [name: string]: unknown;
873
+ };
874
+ content?: never;
875
+ };
876
+ /** @description Default Response */
877
+ 404: {
878
+ headers: {
879
+ [name: string]: unknown;
880
+ };
881
+ content?: never;
882
+ };
883
+ };
884
+ };
885
+ delete?: never;
886
+ options?: never;
887
+ head?: never;
888
+ patch?: never;
889
+ trace?: never;
890
+ };
901
891
  '/api/tracking/user/v1': {
902
892
  parameters: {
903
893
  query?: never;
@@ -909,6 +899,7 @@ interface paths {
909
899
  put?: never;
910
900
  /**
911
901
  * Submit user tracking data
902
+ * @deprecated
912
903
  * @description Submit user tracking data
913
904
  */
914
905
  post: {
@@ -952,7 +943,83 @@ interface paths {
952
943
  deviceType?: 'desktop' | 'mobile' | 'tablet';
953
944
  /** @description User Agent */
954
945
  userAgent?: string;
955
- additionalProperties?: Record<string, never>;
946
+ additionalProperties?: {
947
+ [key: string]: string | number | boolean;
948
+ };
949
+ };
950
+ };
951
+ };
952
+ responses: {
953
+ /** @description Successful response */
954
+ 204: {
955
+ headers: {
956
+ [name: string]: unknown;
957
+ };
958
+ content?: never;
959
+ };
960
+ /** @description Default Response */
961
+ 404: {
962
+ headers: {
963
+ [name: string]: unknown;
964
+ };
965
+ content?: never;
966
+ };
967
+ };
968
+ };
969
+ delete?: never;
970
+ options?: never;
971
+ head?: never;
972
+ patch?: never;
973
+ trace?: never;
974
+ };
975
+ '/api/tracking/user/v2': {
976
+ parameters: {
977
+ query?: never;
978
+ header?: never;
979
+ path?: never;
980
+ cookie?: never;
981
+ };
982
+ get?: never;
983
+ put?: never;
984
+ /**
985
+ * Submit user tracking data
986
+ * @description Submit user tracking data
987
+ */
988
+ post: {
989
+ parameters: {
990
+ query?: never;
991
+ header?: never;
992
+ path?: never;
993
+ cookie?: never;
994
+ };
995
+ /** @description User tracking event data */
996
+ requestBody: {
997
+ content: {
998
+ /** @example {
999
+ * "conversationId": "386d85d7-9daa-8a87-85d4-3f93c990b292",
1000
+ * "eventName": "tab-shown",
1001
+ * "url": "https://www.example.com/telco/"
1002
+ * } */
1003
+ 'application/json': {
1004
+ additionalProperties?: {
1005
+ [key: string]: boolean | number | string;
1006
+ };
1007
+ /** @description Conversation ID */
1008
+ conversationId?: string;
1009
+ /**
1010
+ * @description Device Type
1011
+ * @enum {string}
1012
+ */
1013
+ deviceType?: 'desktop' | 'mobile' | 'tablet';
1014
+ /**
1015
+ * @description Event Name
1016
+ * @enum {string}
1017
+ */
1018
+ eventName: 'welcome_screen-shown' | 'tab-shown' | 'feedback_submit-clicked' | 'page-shown' | 'tool-closed' | 'user_message-submitted' | 'assistant_message-submitted' | 'feedback-shown' | 'feedback_skip-clicked' | 'sale-completed' | 'tab-clicked' | 'tool_close-clicked' | 'woo_assistant_message-submitted' | 'woo_user_message-submitted' | 'woo_reaction-submitted';
1019
+ /** @description URL */
1020
+ url?: string;
1021
+ /** @description User Agent */
1022
+ userAgent?: string;
956
1023
  };
957
1024
  };
958
1025
  };
@@ -986,14 +1053,9 @@ interface paths {
986
1053
  * We don't use them directly, or export them here because of how they appear in the documentation site.
987
1054
  */
988
1055
  type ApiConversationRequest = components['schemas']['ConversationRequest'];
989
- type ApiMessage = components['schemas']['ConversationResponseMessageChunk'];
990
1056
  type ApiDebug = components['schemas']['ConversationResponseDebugChunk'];
991
- type ApiTrackingEvent = paths['/api/tracking/user/v1']['post']['requestBody']['content']['application/json'];
992
- /**
993
- * The request to the conversation API.
994
- */
995
- interface ConversationApiRequest extends ApiConversationRequest {
996
- }
1057
+ type ApiMessage = components['schemas']['ConversationResponseMessageChunk'];
1058
+ type ApiTrackingUserRequest = paths['/api/tracking/user/v2']['post']['requestBody']['content']['application/json'];
997
1059
  /**
998
1060
  * Configuration options for initializing the client.
999
1061
  */
@@ -1006,7 +1068,7 @@ interface Config {
1006
1068
  * Optional fetch function to use for making HTTP requests.
1007
1069
  * If not provided, the default `fetch` implementation will be used.
1008
1070
  */
1009
- fetch?: ((input: Request) => Promise<Response>) | undefined;
1071
+ fetch?: (input: Request) => Promise<Response>;
1010
1072
  /**
1011
1073
  * The base URL for the conversation API.
1012
1074
  */
@@ -1036,24 +1098,24 @@ interface Identity {
1036
1098
  /**
1037
1099
  * The customer ID.
1038
1100
  */
1039
- customerId: ConversationApiRequest['customerId'];
1101
+ customerId: Config['customerId'];
1040
1102
  /**
1041
1103
  * The conversation ID.
1042
1104
  */
1043
- conversationId: ConversationApiRequest['conversationId'];
1105
+ conversationId?: string;
1044
1106
  /**
1045
1107
  * The session ID associated with the user.
1046
1108
  */
1047
- sessionId: ConversationApiRequest['sessionId'];
1109
+ sessionId?: string;
1048
1110
  /**
1049
1111
  * The user ID.
1050
1112
  */
1051
- userId: ConversationApiRequest['userId'];
1113
+ userId?: string;
1052
1114
  }
1053
1115
  /**
1054
1116
  * Message within a conversation.
1055
1117
  */
1056
- interface Message {
1118
+ interface Message extends ApiMessage {
1057
1119
  /**
1058
1120
  * The conversation ID to which the message belongs.
1059
1121
  */
@@ -1081,7 +1143,12 @@ interface DebugResponse {
1081
1143
  */
1082
1144
  type: ApiDebug['type'];
1083
1145
  }
1084
- interface TrackingEvent extends ApiTrackingEvent {
1146
+ /**
1147
+ * The request to the conversation API.
1148
+ */
1149
+ interface ConversationApiRequest extends ApiConversationRequest {
1150
+ }
1151
+ interface TrackingEvent extends ApiTrackingUserRequest {
1085
1152
  }
1086
1153
 
1087
1154
  /**
@@ -1114,9 +1181,10 @@ declare class Client {
1114
1181
  */
1115
1182
  constructor({ customerId, fetch, conversationUrl, frontendUrl }: Config);
1116
1183
  /**
1117
- * Creates a new identity for the user by generating a session ID and user ID if they don't exist.
1184
+ * Creates a new identity for the user by generating a session ID and user ID if they don't exist, and sets the access token for future API calls.
1185
+ * Ends the current conversation if a conversation ID is present before sending a request to update identity.
1118
1186
  *
1119
- * @returns A promise that resolves once the identity is created.
1187
+ * @returns A promise that resolves once the identity is created and the access token is set.
1120
1188
  *
1121
1189
  * @example
1122
1190
  * ```ts
@@ -1139,12 +1207,12 @@ declare class Client {
1139
1207
  * Sends a message in the conversation, optionally with an opening message.
1140
1208
  *
1141
1209
  * @param options - An object containing the opening message and the user message.
1142
- * @returns A promise that resolves to a message or a debug record.
1210
+ * @returns A promise that resolves to an array of messages or debug records.
1143
1211
  * If the message is a debug record, it will throw an error.
1144
1212
  *
1145
1213
  * @example
1146
1214
  * ```ts
1147
- * const newMessage = await client.sendMessage({
1215
+ * const newMessages = await client.sendMessage({
1148
1216
  * openingMessage: 'Hello! How can I help you?',
1149
1217
  * userMessage: 'How can I get support?',
1150
1218
  * })
@@ -1159,7 +1227,7 @@ declare class Client {
1159
1227
  sendMessage({ openingMessage, userMessage, }: {
1160
1228
  openingMessage?: ConversationApiRequest['openingMessage'];
1161
1229
  userMessage: ConversationApiRequest['userMessage'];
1162
- }): Promise<Message | undefined>;
1230
+ }): Promise<Message[] | undefined>;
1163
1231
  /**
1164
1232
  * Sends an event to the tracking API, with the required properties already set.
1165
1233
  *
@@ -1172,15 +1240,50 @@ declare class Client {
1172
1240
  * await client.trackEvent('tab-shown')
1173
1241
  * ```
1174
1242
  */
1175
- trackEvent(eventName: TrackingEvent['eventName'], properties?: TrackingEvent['additionalProperties']): Promise<{
1176
- data?: undefined;
1177
- error?: undefined;
1178
- response: Response;
1179
- }>;
1243
+ trackEvent(eventName: TrackingEvent['eventName'], properties?: TrackingEvent['additionalProperties']): Promise<openapi_fetch.FetchResponse<{
1244
+ parameters: {
1245
+ query?: never;
1246
+ header?: never;
1247
+ path?: never;
1248
+ cookie?: never;
1249
+ };
1250
+ requestBody: {
1251
+ content: {
1252
+ "application/json": {
1253
+ additionalProperties?: {
1254
+ [key: string]: boolean | number | string;
1255
+ };
1256
+ conversationId?: string;
1257
+ deviceType?: "desktop" | "mobile" | "tablet";
1258
+ eventName: "welcome_screen-shown" | "tab-shown" | "feedback_submit-clicked" | "page-shown" | "tool-closed" | "user_message-submitted" | "assistant_message-submitted" | "feedback-shown" | "feedback_skip-clicked" | "sale-completed" | "tab-clicked" | "tool_close-clicked" | "woo_assistant_message-submitted" | "woo_user_message-submitted" | "woo_reaction-submitted";
1259
+ url?: string;
1260
+ userAgent?: string;
1261
+ };
1262
+ };
1263
+ };
1264
+ responses: {
1265
+ 204: {
1266
+ headers: {
1267
+ [name: string]: unknown;
1268
+ };
1269
+ content?: never;
1270
+ };
1271
+ 404: {
1272
+ headers: {
1273
+ [name: string]: unknown;
1274
+ };
1275
+ content?: never;
1276
+ };
1277
+ };
1278
+ }, {
1279
+ body: TrackingEvent;
1280
+ }, `${string}/${string}`>>;
1180
1281
  }
1181
1282
 
1182
1283
  /**
1183
1284
  * The key used to store the conversation ID in `sessionStorage`.
1285
+ *
1286
+ * @ignore
1184
1287
  */
1185
1288
  declare const CONVERSATION_ID = "__15gifts_conversation_id";
1186
1289
  /**
@@ -1227,6 +1330,8 @@ declare const setConversationId: (conversationId: string) => void;
1227
1330
 
1228
1331
  /**
1229
1332
  * The key used to store the session ID in `sessionStorage`.
1333
+ *
1334
+ * @ignore
1230
1335
  */
1231
1336
  declare const SESSION_ID = "__15gifts_session_id";
1232
1337
  /**
@@ -1261,11 +1366,15 @@ declare const setSessionId: (sessionId: string) => void;
1261
1366
 
1262
1367
  /**
1263
1368
  * The key used to store the user ID in `localStorage`.
1369
+ *
1370
+ * @ignore
1264
1371
  */
1265
1372
  declare const USER_ID = "__15gifts_user_id";
1266
1373
  /**
1267
1374
  * Time-to-live (TTL) for the user ID in milliseconds.
1268
1375
  * Set to 30 days.
1376
+ *
1377
+ * @ignore
1269
1378
  */
1270
1379
  declare const TTL: number;
1271
1380
  /**
@@ -1298,4 +1407,19 @@ declare const getUserId: () => string | null;
1298
1407
  */
1299
1408
  declare const setUserId: (userId: string) => void;
1300
1409
 
1301
- export { CONVERSATION_ID, Client, type Config, type ConversationApiRequest, type DebugResponse, type Endpoint, type Identity, type Message, SESSION_ID, TTL, type TrackingEvent, USER_ID, deleteConversationId, getConversationId, getSessionId, getUserId, setConversationId, setSessionId, setUserId };
1410
+ /**
1411
+ * Middleware for adding an `Authorization` header to requests.
1412
+ *
1413
+ * @param accessToken - The token to be included in the `Authorization` header.
1414
+ * @returns A middleware object that attaches the access token to the request headers.
1415
+ *
1416
+ * @example
1417
+ * ```ts
1418
+ * import { authMiddleware } from '@15gifts/sdk';
1419
+ *
1420
+ * this.endpoint.conversation.use(authMiddleware(accessToken))
1421
+ * ```
1422
+ */
1423
+ declare const authMiddleware: (accessToken: string) => Middleware;
1424
+
1425
+ export { CONVERSATION_ID, Client, type Config, type ConversationApiRequest, type DebugResponse, type Endpoint, type Identity, type Message, SESSION_ID, TTL, type TrackingEvent, USER_ID, authMiddleware, deleteConversationId, getConversationId, getSessionId, getUserId, setConversationId, setSessionId, setUserId };