@15gifts/sdk 0.6.0 → 0.6.2
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 +11 -257
- package/dist/index.d.ts +11 -257
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -3
package/dist/index.d.mts
CHANGED
|
@@ -1069,63 +1069,6 @@ interface operations {
|
|
|
1069
1069
|
* Do not make direct changes to the file.
|
|
1070
1070
|
*/
|
|
1071
1071
|
interface paths {
|
|
1072
|
-
'/api/tracking/identity/v1': {
|
|
1073
|
-
parameters: {
|
|
1074
|
-
query?: never;
|
|
1075
|
-
header?: never;
|
|
1076
|
-
path?: never;
|
|
1077
|
-
cookie?: never;
|
|
1078
|
-
};
|
|
1079
|
-
get?: never;
|
|
1080
|
-
put?: never;
|
|
1081
|
-
/**
|
|
1082
|
-
* Generate tracking identifiers
|
|
1083
|
-
* @deprecated
|
|
1084
|
-
* @description Generate tracking identifiers for a user
|
|
1085
|
-
*/
|
|
1086
|
-
post: {
|
|
1087
|
-
parameters: {
|
|
1088
|
-
query?: never;
|
|
1089
|
-
header?: never;
|
|
1090
|
-
path?: never;
|
|
1091
|
-
cookie?: never;
|
|
1092
|
-
};
|
|
1093
|
-
/** @description Generate tracking identifiers for a user */
|
|
1094
|
-
requestBody: {
|
|
1095
|
-
content: {
|
|
1096
|
-
'application/json': {
|
|
1097
|
-
/** @description Customer ID */
|
|
1098
|
-
customerId: string;
|
|
1099
|
-
/** @description User ID */
|
|
1100
|
-
createUserId?: boolean;
|
|
1101
|
-
/** @description Session ID */
|
|
1102
|
-
createSessionId?: boolean;
|
|
1103
|
-
};
|
|
1104
|
-
};
|
|
1105
|
-
};
|
|
1106
|
-
responses: {
|
|
1107
|
-
/** @description Successful response */
|
|
1108
|
-
200: {
|
|
1109
|
-
headers: {
|
|
1110
|
-
[name: string]: unknown;
|
|
1111
|
-
};
|
|
1112
|
-
content: {
|
|
1113
|
-
'application/json': {
|
|
1114
|
-
/** @description User ID */
|
|
1115
|
-
userId?: string;
|
|
1116
|
-
/** @description Session ID */
|
|
1117
|
-
sessionId?: string;
|
|
1118
|
-
};
|
|
1119
|
-
};
|
|
1120
|
-
};
|
|
1121
|
-
};
|
|
1122
|
-
};
|
|
1123
|
-
delete?: never;
|
|
1124
|
-
options?: never;
|
|
1125
|
-
head?: never;
|
|
1126
|
-
patch?: never;
|
|
1127
|
-
trace?: never;
|
|
1128
|
-
};
|
|
1129
1072
|
'/api/tracking/identity/v2': {
|
|
1130
1073
|
parameters: {
|
|
1131
1074
|
query?: never;
|
|
@@ -1167,6 +1110,8 @@ interface paths {
|
|
|
1167
1110
|
};
|
|
1168
1111
|
content: {
|
|
1169
1112
|
'application/json': {
|
|
1113
|
+
/** @description Pageview ID */
|
|
1114
|
+
pageviewId: string;
|
|
1170
1115
|
/** @description Session ID */
|
|
1171
1116
|
sessionId: string;
|
|
1172
1117
|
/** @description User ID */
|
|
@@ -1184,120 +1129,6 @@ interface paths {
|
|
|
1184
1129
|
patch?: never;
|
|
1185
1130
|
trace?: never;
|
|
1186
1131
|
};
|
|
1187
|
-
'/api/tracking/sales/v1': {
|
|
1188
|
-
parameters: {
|
|
1189
|
-
query?: never;
|
|
1190
|
-
header?: never;
|
|
1191
|
-
path?: never;
|
|
1192
|
-
cookie?: never;
|
|
1193
|
-
};
|
|
1194
|
-
get?: never;
|
|
1195
|
-
put?: never;
|
|
1196
|
-
/**
|
|
1197
|
-
* Submit sales tracking data
|
|
1198
|
-
* @deprecated
|
|
1199
|
-
* @description Submit sales tracking data
|
|
1200
|
-
*/
|
|
1201
|
-
post: {
|
|
1202
|
-
parameters: {
|
|
1203
|
-
query?: never;
|
|
1204
|
-
header?: never;
|
|
1205
|
-
path?: never;
|
|
1206
|
-
cookie?: never;
|
|
1207
|
-
};
|
|
1208
|
-
/** @description Sales tracking event data */
|
|
1209
|
-
requestBody: {
|
|
1210
|
-
content: {
|
|
1211
|
-
/** @example {
|
|
1212
|
-
* "customerId": "oclet",
|
|
1213
|
-
* "userId": "163a692e-8ee2-623f-9927-0bb563b19853",
|
|
1214
|
-
* "sessionId": "2f6863a9-2833-5521-a45d-359dcdfd154a",
|
|
1215
|
-
* "saleRef": "34596872",
|
|
1216
|
-
* "currency": "GBP",
|
|
1217
|
-
* "totalPrice": 100,
|
|
1218
|
-
* "totalRecurring": 10,
|
|
1219
|
-
* "items": [
|
|
1220
|
-
* {
|
|
1221
|
-
* "productRef": "1260449",
|
|
1222
|
-
* "name": "Product 1",
|
|
1223
|
-
* "quantity": 1,
|
|
1224
|
-
* "recurring": 10
|
|
1225
|
-
* },
|
|
1226
|
-
* {
|
|
1227
|
-
* "productRef": "fe-56-sd2458",
|
|
1228
|
-
* "name": "Product 2",
|
|
1229
|
-
* "quantity": 2,
|
|
1230
|
-
* "price": 50
|
|
1231
|
-
* }
|
|
1232
|
-
* ]
|
|
1233
|
-
* } */
|
|
1234
|
-
'application/json': {
|
|
1235
|
-
/** @description Customer ID */
|
|
1236
|
-
customerId: string;
|
|
1237
|
-
/** @description User ID */
|
|
1238
|
-
userId?: string;
|
|
1239
|
-
/** @description Session ID */
|
|
1240
|
-
sessionId: string;
|
|
1241
|
-
/** @description Conversation ID */
|
|
1242
|
-
conversationId?: string;
|
|
1243
|
-
/** @description URL */
|
|
1244
|
-
url?: string;
|
|
1245
|
-
/**
|
|
1246
|
-
* @description Device Type
|
|
1247
|
-
* @enum {string}
|
|
1248
|
-
*/
|
|
1249
|
-
deviceType?: 'desktop' | 'mobile' | 'tablet';
|
|
1250
|
-
/** @description User Agent */
|
|
1251
|
-
userAgent?: string;
|
|
1252
|
-
/** @description Sale Reference */
|
|
1253
|
-
saleRef: string;
|
|
1254
|
-
/** @description Currency Code */
|
|
1255
|
-
currency: string;
|
|
1256
|
-
/** @description Total Price */
|
|
1257
|
-
totalPrice: number;
|
|
1258
|
-
/** @description Total Recurring Price */
|
|
1259
|
-
totalRecurring?: number;
|
|
1260
|
-
/** @description Contract Length */
|
|
1261
|
-
contractLength?: number;
|
|
1262
|
-
/** @description Event data */
|
|
1263
|
-
items?: {
|
|
1264
|
-
/** @description Product Reference */
|
|
1265
|
-
productRef?: string;
|
|
1266
|
-
/** @description Product Name */
|
|
1267
|
-
name?: string;
|
|
1268
|
-
/** @description Quantity */
|
|
1269
|
-
quantity?: number;
|
|
1270
|
-
/** @description Price */
|
|
1271
|
-
price?: number;
|
|
1272
|
-
/** @description Recurring Price */
|
|
1273
|
-
recurring?: number;
|
|
1274
|
-
}[];
|
|
1275
|
-
};
|
|
1276
|
-
};
|
|
1277
|
-
};
|
|
1278
|
-
responses: {
|
|
1279
|
-
/** @description Successful response */
|
|
1280
|
-
204: {
|
|
1281
|
-
headers: {
|
|
1282
|
-
[name: string]: unknown;
|
|
1283
|
-
};
|
|
1284
|
-
content?: never;
|
|
1285
|
-
};
|
|
1286
|
-
/** @description Default Response */
|
|
1287
|
-
404: {
|
|
1288
|
-
headers: {
|
|
1289
|
-
[name: string]: unknown;
|
|
1290
|
-
};
|
|
1291
|
-
content?: never;
|
|
1292
|
-
};
|
|
1293
|
-
};
|
|
1294
|
-
};
|
|
1295
|
-
delete?: never;
|
|
1296
|
-
options?: never;
|
|
1297
|
-
head?: never;
|
|
1298
|
-
patch?: never;
|
|
1299
|
-
trace?: never;
|
|
1300
|
-
};
|
|
1301
1132
|
'/api/tracking/sales/v2': {
|
|
1302
1133
|
parameters: {
|
|
1303
1134
|
query?: never;
|
|
@@ -1403,90 +1234,6 @@ interface paths {
|
|
|
1403
1234
|
patch?: never;
|
|
1404
1235
|
trace?: never;
|
|
1405
1236
|
};
|
|
1406
|
-
'/api/tracking/user/v1': {
|
|
1407
|
-
parameters: {
|
|
1408
|
-
query?: never;
|
|
1409
|
-
header?: never;
|
|
1410
|
-
path?: never;
|
|
1411
|
-
cookie?: never;
|
|
1412
|
-
};
|
|
1413
|
-
get?: never;
|
|
1414
|
-
put?: never;
|
|
1415
|
-
/**
|
|
1416
|
-
* Submit user tracking data
|
|
1417
|
-
* @deprecated
|
|
1418
|
-
* @description Submit user tracking data
|
|
1419
|
-
*/
|
|
1420
|
-
post: {
|
|
1421
|
-
parameters: {
|
|
1422
|
-
query?: never;
|
|
1423
|
-
header?: never;
|
|
1424
|
-
path?: never;
|
|
1425
|
-
cookie?: never;
|
|
1426
|
-
};
|
|
1427
|
-
/** @description User tracking event data */
|
|
1428
|
-
requestBody: {
|
|
1429
|
-
content: {
|
|
1430
|
-
/** @example {
|
|
1431
|
-
* "eventName": "tab-shown",
|
|
1432
|
-
* "customerId": "oclet",
|
|
1433
|
-
* "userId": "163a692e-8ee2-623f-9927-0bb563b19853",
|
|
1434
|
-
* "sessionId": "2f6863a9-2833-5521-a45d-359dcdfd154a",
|
|
1435
|
-
* "conversationId": "386d85d7-9daa-8a87-85d4-3f93c990b292",
|
|
1436
|
-
* "url": "https://www.example.com/telco/"
|
|
1437
|
-
* } */
|
|
1438
|
-
'application/json': {
|
|
1439
|
-
/**
|
|
1440
|
-
* @description Event Name
|
|
1441
|
-
* @enum {string}
|
|
1442
|
-
*/
|
|
1443
|
-
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';
|
|
1444
|
-
/** @description Customer ID */
|
|
1445
|
-
customerId: string;
|
|
1446
|
-
/** @description User ID */
|
|
1447
|
-
userId?: string;
|
|
1448
|
-
/** @description Session ID */
|
|
1449
|
-
sessionId: string;
|
|
1450
|
-
/** @description Conversation ID */
|
|
1451
|
-
conversationId?: string;
|
|
1452
|
-
/** @description URL */
|
|
1453
|
-
url?: string;
|
|
1454
|
-
/**
|
|
1455
|
-
* @description Device Type
|
|
1456
|
-
* @enum {string}
|
|
1457
|
-
*/
|
|
1458
|
-
deviceType?: 'desktop' | 'mobile' | 'tablet';
|
|
1459
|
-
/** @description User Agent */
|
|
1460
|
-
userAgent?: string;
|
|
1461
|
-
additionalProperties?: {
|
|
1462
|
-
[key: string]: string | number | boolean;
|
|
1463
|
-
};
|
|
1464
|
-
};
|
|
1465
|
-
};
|
|
1466
|
-
};
|
|
1467
|
-
responses: {
|
|
1468
|
-
/** @description Successful response */
|
|
1469
|
-
204: {
|
|
1470
|
-
headers: {
|
|
1471
|
-
[name: string]: unknown;
|
|
1472
|
-
};
|
|
1473
|
-
content?: never;
|
|
1474
|
-
};
|
|
1475
|
-
/** @description Default Response */
|
|
1476
|
-
404: {
|
|
1477
|
-
headers: {
|
|
1478
|
-
[name: string]: unknown;
|
|
1479
|
-
};
|
|
1480
|
-
content?: never;
|
|
1481
|
-
};
|
|
1482
|
-
};
|
|
1483
|
-
};
|
|
1484
|
-
delete?: never;
|
|
1485
|
-
options?: never;
|
|
1486
|
-
head?: never;
|
|
1487
|
-
patch?: never;
|
|
1488
|
-
trace?: never;
|
|
1489
|
-
};
|
|
1490
1237
|
'/api/tracking/user/v2': {
|
|
1491
1238
|
parameters: {
|
|
1492
1239
|
query?: never;
|
|
@@ -1530,7 +1277,9 @@ interface paths {
|
|
|
1530
1277
|
* @description Event Name
|
|
1531
1278
|
* @enum {string}
|
|
1532
1279
|
*/
|
|
1533
|
-
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' | '
|
|
1280
|
+
eventName: 'welcome_screen-shown' | 'tab-shown' | 'feedback_submit-clicked' | 'page-shown' | 'tool-closed' | 'user_message-submitted' | 'user_message-submitted message' | 'user_message-submitted single_select' | 'user_message-submitted multi_select' | 'assistant_message-submitted' | 'assistant_message-submitted recommendation' | 'assistant_message-submitted message' | 'assistant_message-submitted single_select' | 'assistant_message-submitted multi_select' | 'assistant_message-submitted exit_to_chat' | 'assistant_message-submitted exit_to_purchase' | 'feedback-shown' | 'feedback_skip-clicked' | 'sale-completed' | 'tab-clicked' | 'tool_close-clicked' | 'exit_to_purchase-completed' | 'exit_to_chat-completed';
|
|
1281
|
+
/** @description Pageview ID */
|
|
1282
|
+
pageviewId?: string;
|
|
1534
1283
|
/** @description URL */
|
|
1535
1284
|
url?: string;
|
|
1536
1285
|
/** @description User Agent */
|
|
@@ -1624,6 +1373,10 @@ interface Identity {
|
|
|
1624
1373
|
* The conversation ID.
|
|
1625
1374
|
*/
|
|
1626
1375
|
conversationId?: string;
|
|
1376
|
+
/**
|
|
1377
|
+
* The pageview ID.
|
|
1378
|
+
*/
|
|
1379
|
+
pageviewId?: string;
|
|
1627
1380
|
/**
|
|
1628
1381
|
* The session ID associated with the user.
|
|
1629
1382
|
*/
|
|
@@ -1789,7 +1542,8 @@ declare class Client {
|
|
|
1789
1542
|
};
|
|
1790
1543
|
conversationId?: string;
|
|
1791
1544
|
deviceType?: "desktop" | "mobile" | "tablet";
|
|
1792
|
-
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" | "
|
|
1545
|
+
eventName: "welcome_screen-shown" | "tab-shown" | "feedback_submit-clicked" | "page-shown" | "tool-closed" | "user_message-submitted" | "user_message-submitted message" | "user_message-submitted single_select" | "user_message-submitted multi_select" | "assistant_message-submitted" | "assistant_message-submitted recommendation" | "assistant_message-submitted message" | "assistant_message-submitted single_select" | "assistant_message-submitted multi_select" | "assistant_message-submitted exit_to_chat" | "assistant_message-submitted exit_to_purchase" | "feedback-shown" | "feedback_skip-clicked" | "sale-completed" | "tab-clicked" | "tool_close-clicked" | "exit_to_purchase-completed" | "exit_to_chat-completed";
|
|
1546
|
+
pageviewId?: string;
|
|
1793
1547
|
url?: string;
|
|
1794
1548
|
userAgent?: string;
|
|
1795
1549
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1069,63 +1069,6 @@ interface operations {
|
|
|
1069
1069
|
* Do not make direct changes to the file.
|
|
1070
1070
|
*/
|
|
1071
1071
|
interface paths {
|
|
1072
|
-
'/api/tracking/identity/v1': {
|
|
1073
|
-
parameters: {
|
|
1074
|
-
query?: never;
|
|
1075
|
-
header?: never;
|
|
1076
|
-
path?: never;
|
|
1077
|
-
cookie?: never;
|
|
1078
|
-
};
|
|
1079
|
-
get?: never;
|
|
1080
|
-
put?: never;
|
|
1081
|
-
/**
|
|
1082
|
-
* Generate tracking identifiers
|
|
1083
|
-
* @deprecated
|
|
1084
|
-
* @description Generate tracking identifiers for a user
|
|
1085
|
-
*/
|
|
1086
|
-
post: {
|
|
1087
|
-
parameters: {
|
|
1088
|
-
query?: never;
|
|
1089
|
-
header?: never;
|
|
1090
|
-
path?: never;
|
|
1091
|
-
cookie?: never;
|
|
1092
|
-
};
|
|
1093
|
-
/** @description Generate tracking identifiers for a user */
|
|
1094
|
-
requestBody: {
|
|
1095
|
-
content: {
|
|
1096
|
-
'application/json': {
|
|
1097
|
-
/** @description Customer ID */
|
|
1098
|
-
customerId: string;
|
|
1099
|
-
/** @description User ID */
|
|
1100
|
-
createUserId?: boolean;
|
|
1101
|
-
/** @description Session ID */
|
|
1102
|
-
createSessionId?: boolean;
|
|
1103
|
-
};
|
|
1104
|
-
};
|
|
1105
|
-
};
|
|
1106
|
-
responses: {
|
|
1107
|
-
/** @description Successful response */
|
|
1108
|
-
200: {
|
|
1109
|
-
headers: {
|
|
1110
|
-
[name: string]: unknown;
|
|
1111
|
-
};
|
|
1112
|
-
content: {
|
|
1113
|
-
'application/json': {
|
|
1114
|
-
/** @description User ID */
|
|
1115
|
-
userId?: string;
|
|
1116
|
-
/** @description Session ID */
|
|
1117
|
-
sessionId?: string;
|
|
1118
|
-
};
|
|
1119
|
-
};
|
|
1120
|
-
};
|
|
1121
|
-
};
|
|
1122
|
-
};
|
|
1123
|
-
delete?: never;
|
|
1124
|
-
options?: never;
|
|
1125
|
-
head?: never;
|
|
1126
|
-
patch?: never;
|
|
1127
|
-
trace?: never;
|
|
1128
|
-
};
|
|
1129
1072
|
'/api/tracking/identity/v2': {
|
|
1130
1073
|
parameters: {
|
|
1131
1074
|
query?: never;
|
|
@@ -1167,6 +1110,8 @@ interface paths {
|
|
|
1167
1110
|
};
|
|
1168
1111
|
content: {
|
|
1169
1112
|
'application/json': {
|
|
1113
|
+
/** @description Pageview ID */
|
|
1114
|
+
pageviewId: string;
|
|
1170
1115
|
/** @description Session ID */
|
|
1171
1116
|
sessionId: string;
|
|
1172
1117
|
/** @description User ID */
|
|
@@ -1184,120 +1129,6 @@ interface paths {
|
|
|
1184
1129
|
patch?: never;
|
|
1185
1130
|
trace?: never;
|
|
1186
1131
|
};
|
|
1187
|
-
'/api/tracking/sales/v1': {
|
|
1188
|
-
parameters: {
|
|
1189
|
-
query?: never;
|
|
1190
|
-
header?: never;
|
|
1191
|
-
path?: never;
|
|
1192
|
-
cookie?: never;
|
|
1193
|
-
};
|
|
1194
|
-
get?: never;
|
|
1195
|
-
put?: never;
|
|
1196
|
-
/**
|
|
1197
|
-
* Submit sales tracking data
|
|
1198
|
-
* @deprecated
|
|
1199
|
-
* @description Submit sales tracking data
|
|
1200
|
-
*/
|
|
1201
|
-
post: {
|
|
1202
|
-
parameters: {
|
|
1203
|
-
query?: never;
|
|
1204
|
-
header?: never;
|
|
1205
|
-
path?: never;
|
|
1206
|
-
cookie?: never;
|
|
1207
|
-
};
|
|
1208
|
-
/** @description Sales tracking event data */
|
|
1209
|
-
requestBody: {
|
|
1210
|
-
content: {
|
|
1211
|
-
/** @example {
|
|
1212
|
-
* "customerId": "oclet",
|
|
1213
|
-
* "userId": "163a692e-8ee2-623f-9927-0bb563b19853",
|
|
1214
|
-
* "sessionId": "2f6863a9-2833-5521-a45d-359dcdfd154a",
|
|
1215
|
-
* "saleRef": "34596872",
|
|
1216
|
-
* "currency": "GBP",
|
|
1217
|
-
* "totalPrice": 100,
|
|
1218
|
-
* "totalRecurring": 10,
|
|
1219
|
-
* "items": [
|
|
1220
|
-
* {
|
|
1221
|
-
* "productRef": "1260449",
|
|
1222
|
-
* "name": "Product 1",
|
|
1223
|
-
* "quantity": 1,
|
|
1224
|
-
* "recurring": 10
|
|
1225
|
-
* },
|
|
1226
|
-
* {
|
|
1227
|
-
* "productRef": "fe-56-sd2458",
|
|
1228
|
-
* "name": "Product 2",
|
|
1229
|
-
* "quantity": 2,
|
|
1230
|
-
* "price": 50
|
|
1231
|
-
* }
|
|
1232
|
-
* ]
|
|
1233
|
-
* } */
|
|
1234
|
-
'application/json': {
|
|
1235
|
-
/** @description Customer ID */
|
|
1236
|
-
customerId: string;
|
|
1237
|
-
/** @description User ID */
|
|
1238
|
-
userId?: string;
|
|
1239
|
-
/** @description Session ID */
|
|
1240
|
-
sessionId: string;
|
|
1241
|
-
/** @description Conversation ID */
|
|
1242
|
-
conversationId?: string;
|
|
1243
|
-
/** @description URL */
|
|
1244
|
-
url?: string;
|
|
1245
|
-
/**
|
|
1246
|
-
* @description Device Type
|
|
1247
|
-
* @enum {string}
|
|
1248
|
-
*/
|
|
1249
|
-
deviceType?: 'desktop' | 'mobile' | 'tablet';
|
|
1250
|
-
/** @description User Agent */
|
|
1251
|
-
userAgent?: string;
|
|
1252
|
-
/** @description Sale Reference */
|
|
1253
|
-
saleRef: string;
|
|
1254
|
-
/** @description Currency Code */
|
|
1255
|
-
currency: string;
|
|
1256
|
-
/** @description Total Price */
|
|
1257
|
-
totalPrice: number;
|
|
1258
|
-
/** @description Total Recurring Price */
|
|
1259
|
-
totalRecurring?: number;
|
|
1260
|
-
/** @description Contract Length */
|
|
1261
|
-
contractLength?: number;
|
|
1262
|
-
/** @description Event data */
|
|
1263
|
-
items?: {
|
|
1264
|
-
/** @description Product Reference */
|
|
1265
|
-
productRef?: string;
|
|
1266
|
-
/** @description Product Name */
|
|
1267
|
-
name?: string;
|
|
1268
|
-
/** @description Quantity */
|
|
1269
|
-
quantity?: number;
|
|
1270
|
-
/** @description Price */
|
|
1271
|
-
price?: number;
|
|
1272
|
-
/** @description Recurring Price */
|
|
1273
|
-
recurring?: number;
|
|
1274
|
-
}[];
|
|
1275
|
-
};
|
|
1276
|
-
};
|
|
1277
|
-
};
|
|
1278
|
-
responses: {
|
|
1279
|
-
/** @description Successful response */
|
|
1280
|
-
204: {
|
|
1281
|
-
headers: {
|
|
1282
|
-
[name: string]: unknown;
|
|
1283
|
-
};
|
|
1284
|
-
content?: never;
|
|
1285
|
-
};
|
|
1286
|
-
/** @description Default Response */
|
|
1287
|
-
404: {
|
|
1288
|
-
headers: {
|
|
1289
|
-
[name: string]: unknown;
|
|
1290
|
-
};
|
|
1291
|
-
content?: never;
|
|
1292
|
-
};
|
|
1293
|
-
};
|
|
1294
|
-
};
|
|
1295
|
-
delete?: never;
|
|
1296
|
-
options?: never;
|
|
1297
|
-
head?: never;
|
|
1298
|
-
patch?: never;
|
|
1299
|
-
trace?: never;
|
|
1300
|
-
};
|
|
1301
1132
|
'/api/tracking/sales/v2': {
|
|
1302
1133
|
parameters: {
|
|
1303
1134
|
query?: never;
|
|
@@ -1403,90 +1234,6 @@ interface paths {
|
|
|
1403
1234
|
patch?: never;
|
|
1404
1235
|
trace?: never;
|
|
1405
1236
|
};
|
|
1406
|
-
'/api/tracking/user/v1': {
|
|
1407
|
-
parameters: {
|
|
1408
|
-
query?: never;
|
|
1409
|
-
header?: never;
|
|
1410
|
-
path?: never;
|
|
1411
|
-
cookie?: never;
|
|
1412
|
-
};
|
|
1413
|
-
get?: never;
|
|
1414
|
-
put?: never;
|
|
1415
|
-
/**
|
|
1416
|
-
* Submit user tracking data
|
|
1417
|
-
* @deprecated
|
|
1418
|
-
* @description Submit user tracking data
|
|
1419
|
-
*/
|
|
1420
|
-
post: {
|
|
1421
|
-
parameters: {
|
|
1422
|
-
query?: never;
|
|
1423
|
-
header?: never;
|
|
1424
|
-
path?: never;
|
|
1425
|
-
cookie?: never;
|
|
1426
|
-
};
|
|
1427
|
-
/** @description User tracking event data */
|
|
1428
|
-
requestBody: {
|
|
1429
|
-
content: {
|
|
1430
|
-
/** @example {
|
|
1431
|
-
* "eventName": "tab-shown",
|
|
1432
|
-
* "customerId": "oclet",
|
|
1433
|
-
* "userId": "163a692e-8ee2-623f-9927-0bb563b19853",
|
|
1434
|
-
* "sessionId": "2f6863a9-2833-5521-a45d-359dcdfd154a",
|
|
1435
|
-
* "conversationId": "386d85d7-9daa-8a87-85d4-3f93c990b292",
|
|
1436
|
-
* "url": "https://www.example.com/telco/"
|
|
1437
|
-
* } */
|
|
1438
|
-
'application/json': {
|
|
1439
|
-
/**
|
|
1440
|
-
* @description Event Name
|
|
1441
|
-
* @enum {string}
|
|
1442
|
-
*/
|
|
1443
|
-
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';
|
|
1444
|
-
/** @description Customer ID */
|
|
1445
|
-
customerId: string;
|
|
1446
|
-
/** @description User ID */
|
|
1447
|
-
userId?: string;
|
|
1448
|
-
/** @description Session ID */
|
|
1449
|
-
sessionId: string;
|
|
1450
|
-
/** @description Conversation ID */
|
|
1451
|
-
conversationId?: string;
|
|
1452
|
-
/** @description URL */
|
|
1453
|
-
url?: string;
|
|
1454
|
-
/**
|
|
1455
|
-
* @description Device Type
|
|
1456
|
-
* @enum {string}
|
|
1457
|
-
*/
|
|
1458
|
-
deviceType?: 'desktop' | 'mobile' | 'tablet';
|
|
1459
|
-
/** @description User Agent */
|
|
1460
|
-
userAgent?: string;
|
|
1461
|
-
additionalProperties?: {
|
|
1462
|
-
[key: string]: string | number | boolean;
|
|
1463
|
-
};
|
|
1464
|
-
};
|
|
1465
|
-
};
|
|
1466
|
-
};
|
|
1467
|
-
responses: {
|
|
1468
|
-
/** @description Successful response */
|
|
1469
|
-
204: {
|
|
1470
|
-
headers: {
|
|
1471
|
-
[name: string]: unknown;
|
|
1472
|
-
};
|
|
1473
|
-
content?: never;
|
|
1474
|
-
};
|
|
1475
|
-
/** @description Default Response */
|
|
1476
|
-
404: {
|
|
1477
|
-
headers: {
|
|
1478
|
-
[name: string]: unknown;
|
|
1479
|
-
};
|
|
1480
|
-
content?: never;
|
|
1481
|
-
};
|
|
1482
|
-
};
|
|
1483
|
-
};
|
|
1484
|
-
delete?: never;
|
|
1485
|
-
options?: never;
|
|
1486
|
-
head?: never;
|
|
1487
|
-
patch?: never;
|
|
1488
|
-
trace?: never;
|
|
1489
|
-
};
|
|
1490
1237
|
'/api/tracking/user/v2': {
|
|
1491
1238
|
parameters: {
|
|
1492
1239
|
query?: never;
|
|
@@ -1530,7 +1277,9 @@ interface paths {
|
|
|
1530
1277
|
* @description Event Name
|
|
1531
1278
|
* @enum {string}
|
|
1532
1279
|
*/
|
|
1533
|
-
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' | '
|
|
1280
|
+
eventName: 'welcome_screen-shown' | 'tab-shown' | 'feedback_submit-clicked' | 'page-shown' | 'tool-closed' | 'user_message-submitted' | 'user_message-submitted message' | 'user_message-submitted single_select' | 'user_message-submitted multi_select' | 'assistant_message-submitted' | 'assistant_message-submitted recommendation' | 'assistant_message-submitted message' | 'assistant_message-submitted single_select' | 'assistant_message-submitted multi_select' | 'assistant_message-submitted exit_to_chat' | 'assistant_message-submitted exit_to_purchase' | 'feedback-shown' | 'feedback_skip-clicked' | 'sale-completed' | 'tab-clicked' | 'tool_close-clicked' | 'exit_to_purchase-completed' | 'exit_to_chat-completed';
|
|
1281
|
+
/** @description Pageview ID */
|
|
1282
|
+
pageviewId?: string;
|
|
1534
1283
|
/** @description URL */
|
|
1535
1284
|
url?: string;
|
|
1536
1285
|
/** @description User Agent */
|
|
@@ -1624,6 +1373,10 @@ interface Identity {
|
|
|
1624
1373
|
* The conversation ID.
|
|
1625
1374
|
*/
|
|
1626
1375
|
conversationId?: string;
|
|
1376
|
+
/**
|
|
1377
|
+
* The pageview ID.
|
|
1378
|
+
*/
|
|
1379
|
+
pageviewId?: string;
|
|
1627
1380
|
/**
|
|
1628
1381
|
* The session ID associated with the user.
|
|
1629
1382
|
*/
|
|
@@ -1789,7 +1542,8 @@ declare class Client {
|
|
|
1789
1542
|
};
|
|
1790
1543
|
conversationId?: string;
|
|
1791
1544
|
deviceType?: "desktop" | "mobile" | "tablet";
|
|
1792
|
-
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" | "
|
|
1545
|
+
eventName: "welcome_screen-shown" | "tab-shown" | "feedback_submit-clicked" | "page-shown" | "tool-closed" | "user_message-submitted" | "user_message-submitted message" | "user_message-submitted single_select" | "user_message-submitted multi_select" | "assistant_message-submitted" | "assistant_message-submitted recommendation" | "assistant_message-submitted message" | "assistant_message-submitted single_select" | "assistant_message-submitted multi_select" | "assistant_message-submitted exit_to_chat" | "assistant_message-submitted exit_to_purchase" | "feedback-shown" | "feedback_skip-clicked" | "sale-completed" | "tab-clicked" | "tool_close-clicked" | "exit_to_purchase-completed" | "exit_to_chat-completed";
|
|
1546
|
+
pageviewId?: string;
|
|
1793
1547
|
url?: string;
|
|
1794
1548
|
userAgent?: string;
|
|
1795
1549
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var b=Object.create;var a=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var s in e)a(t,s,{get:e[s],enumerable:!0})},w=(t,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of _(e))!D.call(t,i)&&i!==s&&a(t,i,{get:()=>e[i],enumerable:!(n=O(e,i))||n.enumerable});return t};var N=(t,e,s)=>(s=t!=null?b(T(t)):{},w(e||!t||!t.__esModule?a(s,"default",{value:t,enumerable:!0}):s,t)),k=t=>w(a({},"__esModule",{value:!0}),t);var W={};P(W,{CONVERSATION_ID:()=>d,Client:()=>E,SESSION_ID:()=>v,TTL:()=>M,USER_ID:()=>y,authMiddleware:()=>p,deleteConversationId:()=>g,getConversationId:()=>I,getSessionId:()=>f,getUserId:()=>h,setConversationId:()=>c,setSessionId:()=>m,setUserId:()=>x});module.exports=k(W);var S=N(require("openapi-fetch"));var d="__15gifts_conversation_id",g=()=>sessionStorage.removeItem(d),I=()=>sessionStorage.getItem(d),c=t=>sessionStorage.setItem(d,t);var v="__15gifts_session_id",f=()=>sessionStorage.getItem(v),m=t=>sessionStorage.setItem(v,t);var A=t=>{let e=localStorage.getItem(t);if(!e)return null;let s=JSON.parse(e);return Date.now()>s.expires?(localStorage.removeItem(t),null):s.value},u=A;var R=(t,e,s)=>{let n={expires:Date.now()+s,value:e};localStorage.setItem(t,JSON.stringify(n))},l=R;var y="__15gifts_user_id",M=1e3*60*60*24*30,h=()=>u(y),x=t=>l(y,t,M);var U=t=>({onRequest:async({request:e})=>(e.headers.set("Authorization",`Bearer ${t}`),e)}),p=U;var C="0.6.2";var E=class{endpoint;identity;constructor({customerId:e,fetch:s,conversationUrl:n,frontendUrl:i}){let o={"X-SDK-VERSION":C};this.endpoint={conversation:(0,S.default)({baseUrl:n,fetch:s,headers:o}),frontend:(0,S.default)({baseUrl:i,fetch:s,headers:o})},this.identity={customerId:e,conversationId:I()??void 0,sessionId:f()??void 0,userId:h()??void 0}}async createIdentity(){let{customerId:e,pageviewId:s,sessionId:n,userId:i}=this.identity,{data:o}=await this.endpoint.frontend.POST("/api/tracking/identity/v2",{body:{customerId:e,sessionId:n,userId:i}});o&&(s||(this.identity.pageviewId=o.pageviewId),n||(this.identity.sessionId=o.sessionId,m(o.sessionId)),i||(this.identity.userId=o.userId,x(o.userId)),Object.values(this.endpoint).forEach(r=>{r.use(p(o.token))}))}endConversation(){g(),this.identity.conversationId=void 0}async startConversation(e){this.endConversation();let s={availableProductIds:[],...e},{data:n}=await this.endpoint.conversation.POST("/api/conversation/v3",{body:{type:"START_CONVERSATION",conversationContext:s}}),[i,o]=n,r=i.conversationId;if(!r)throw new Error("Conversation ID not received");return c(r),this.identity.conversationId=r,o}async sendMessage({userMessage:e}){let{data:s}=await this.endpoint.conversation.POST("/api/conversation/v3",{body:{conversationId:this.identity.conversationId,userMessage:e,type:"MESSAGE"}});if(!s)return;let n=s.filter(r=>r.type==="DEBUG");n.length&&console.info("Debug messages:",n);let i=s.find(r=>r.type==="CONVERSATION_ID")?.conversationId;return i&&(c(i),this.identity.conversationId=i),s.filter(r=>r.type!=="CONVERSATION_ID"&&r.type!=="DEBUG")}async trackEvent(e,s){let n={additionalProperties:s,conversationId:this.identity.conversationId,deviceType:void 0,eventName:e,pageviewId:this.identity.pageviewId,url:window.location.href,userAgent:window.navigator.userAgent};return this.endpoint.frontend.POST("/api/tracking/user/v2",{body:n})}};0&&(module.exports={CONVERSATION_ID,Client,SESSION_ID,TTL,USER_ID,authMiddleware,deleteConversationId,getConversationId,getSessionId,getUserId,setConversationId,setSessionId,setUserId});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/identity/conversationId.ts","../src/identity/sessionId.ts","../src/utils/getItemWithExpiry.ts","../src/utils/setItemWithExpiry.ts","../src/identity/userId.ts","../src/middlewares/auth.ts","../package.json"],"sourcesContent":["export * from './client'\nexport * from './identity'\nexport * from './middlewares'\nexport * from './types'\n","import createClient from 'openapi-fetch'\n\nimport {\n deleteConversationId,\n getConversationId,\n getSessionId,\n getUserId,\n setConversationId,\n setSessionId,\n setUserId,\n} from './identity'\nimport { authMiddleware } from './middlewares'\nimport type { paths as conversationPaths } from './schemas/conversation'\nimport type { paths as frontendPaths } from './schemas/frontend'\nimport type {\n BasicMessage,\n Config,\n ConversationIdMessage,\n DebugMessage,\n Endpoint,\n Identity,\n Message,\n TrackingEvent,\n} from './types'\nimport { version } from '../package.json'\n\n/**\n * The `Client` class provides methods to manage 15gifts API.\n */\nexport class Client {\n /**\n * This can be used to interact with the APIs directly. It is recommended to use the [helper methods](/sdk/sdk-reference/classes/client/#methods) provided by the `Client` class instead.\n *\n * @example\n * ```ts\n * const client = new Client({ customerId: 'YOUR_CUSTOMER_ID' })\n * const { data } = await client.endpoint.conversation.POST('/api/conversation/v2')\n * ```\n */\n endpoint: Endpoint\n\n /**\n * The identity information.\n */\n identity: Identity\n\n /**\n * Creates a new instance of the `Client` class.\n *\n * @param config - Configuration options for initializing the client.\n *\n * @example\n * ```ts\n * const client = new Client({ customerId: 'YOUR_CUSTOMER_ID' })\n * ```\n */\n constructor({ customerId, fetch, conversationUrl, frontendUrl }: Config) {\n const headers = {\n 'X-SDK-VERSION': version,\n }\n\n this.endpoint = {\n conversation: createClient<conversationPaths>({ baseUrl: conversationUrl, fetch, headers }),\n frontend: createClient<frontendPaths>({ baseUrl: frontendUrl, fetch, headers }),\n }\n this.identity = {\n customerId,\n conversationId: getConversationId() ?? undefined,\n sessionId: getSessionId() ?? undefined,\n userId: getUserId() ?? undefined,\n }\n }\n\n /**\n * 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.\n * Ends the current conversation if a conversation ID is present before sending a request to update identity.\n *\n * @returns A promise that resolves once the identity is created and the access token is set.\n *\n * @example\n * ```ts\n * await client.createIdentity()\n * console.log('Identity created:', client.identity)\n * ```\n */\n async createIdentity(): Promise<void> {\n const { customerId, sessionId, userId } = this.identity\n\n const { data } = await this.endpoint.frontend.POST('/api/tracking/identity/v2', {\n body: {\n customerId,\n sessionId,\n userId,\n },\n })\n\n if (data) {\n if (!sessionId) {\n this.identity.sessionId = data.sessionId\n setSessionId(data.sessionId)\n }\n if (!userId) {\n this.identity.userId = data.userId\n setUserId(data.userId)\n }\n\n Object.values(this.endpoint).forEach((endpont) => {\n endpont.use(authMiddleware(data.token))\n })\n }\n }\n\n /**\n * Ends the current conversation by deleting the conversation ID.\n *\n * @example\n * ```ts\n * client.endConversation()\n * console.log('Conversation ended')\n * ```\n */\n endConversation(): void {\n deleteConversationId()\n this.identity.conversationId = undefined\n }\n\n /**\n * Clears the existing conversation ID, then generates a new one and returns the opening message.\n *\n * @param context - Optional context to customize the conversation. It can include:\n * @param context.eligibleProducts An array of eligible product IDs.\n * @param context.productOverrides Overrides for product details.\n *\n *\n * @returns A promise that resolves to the opening message.\n *\n * @example\n * ##### Basic usage\n * ```ts\n * const openingMessage = await client.startConversation()\n * console.log('Opening message:', openingMessage)\n * ```\n *\n * ##### With context\n * ```ts\n * const openingMessage = await client.startConversation({ eligibleProducts: ['product-1', 'product-2'], productOverrides: { 'product-1': { price: 40 } })\n * console.log('Opening message:', openingMessage)\n * ```\n */\n async startConversation(context?: {\n eligibleProducts?: string[]\n productOverrides?: Record<string, { price: number; minSpeed?: number; maxSpeed?: number }>\n }): Promise<BasicMessage | undefined> {\n this.endConversation()\n\n const conversationContext = {\n availableProductIds: [],\n ...context,\n }\n\n const { data } = await this.endpoint.conversation.POST(`/api/conversation/v3`, {\n body: {\n type: 'START_CONVERSATION',\n conversationContext,\n },\n })\n\n const [conversationIdMessage, openingMessage] = data as [ConversationIdMessage, BasicMessage]\n\n const conversationId = conversationIdMessage.conversationId\n if (!conversationId) {\n throw new Error('Conversation ID not received')\n }\n\n setConversationId(conversationId)\n this.identity.conversationId = conversationId\n\n return openingMessage\n }\n\n /**\n * Sends a message in the conversation.\n *\n * @param options - An object containing the user message.\n * @returns A promise that resolves to an array of messages\n *\n * @example\n * ```ts\n * const newMessages = await client.sendMessage({\n * userMessage: 'How can I get support?',\n * })\n *\n * if (newMessages) {\n * console.log('Received messages:', newMessages)\n * } else {\n * console.log('No message received')\n * }\n * ```\n */\n async sendMessage({\n userMessage,\n }: {\n userMessage: string\n }): Promise<Exclude<Message, ConversationIdMessage | DebugMessage>[] | undefined> {\n const { data } = await this.endpoint.conversation.POST('/api/conversation/v3', {\n body: {\n conversationId: this.identity.conversationId,\n userMessage,\n type: 'MESSAGE',\n },\n })\n\n if (!data) return undefined\n\n // Log debug messages\n // These will only be in the response when used in internal testing\n const debugMessages = data.filter((message) => message.type === 'DEBUG')\n if (debugMessages.length) {\n console.info('Debug messages:', debugMessages)\n }\n\n // When a request does not contain a conversation ID, the API will return a new conversation ID as the first message\n const conversationId = data.find((message) => message.type === 'CONVERSATION_ID')?.conversationId\n if (conversationId) {\n setConversationId(conversationId)\n this.identity.conversationId = conversationId\n }\n\n const messages = data.filter((message) => message.type !== 'CONVERSATION_ID' && message.type !== 'DEBUG')\n return messages\n }\n\n /**\n * Sends an event to the tracking API, with the required properties already set.\n *\n * @param eventName - The name of the event to track.\n * @param properties - Additional properties to include in the event.\n * @returns A promise that resolves once the event is tracked.\n *\n * @example\n * ```ts\n * await client.trackEvent('tab-shown')\n * ```\n */\n async trackEvent(eventName: TrackingEvent['eventName'], properties?: TrackingEvent['additionalProperties']) {\n const body: TrackingEvent = {\n additionalProperties: properties,\n conversationId: this.identity.conversationId,\n deviceType: undefined,\n eventName,\n url: window.location.href,\n userAgent: window.navigator.userAgent,\n }\n\n return this.endpoint.frontend.POST('/api/tracking/user/v2', {\n body,\n })\n }\n}\n","/**\n * The key used to store the conversation ID in `sessionStorage`.\n *\n * @ignore\n */\nexport const CONVERSATION_ID = '__15gifts_conversation_id'\n\n/**\n * Deletes the conversation ID from `sessionStorage`.\n *\n * @example\n * ```ts\n * import { deleteConversationId } from '@15gifts/sdk'\n *\n * deleteConversationId()\n * // The conversation ID will be removed.\n * ```\n */\nexport const deleteConversationId = () => sessionStorage.removeItem(CONVERSATION_ID)\n\n/**\n * Retrieves the conversation ID from `sessionStorage`.\n *\n * @example\n * ```ts\n * import { getConversationId } from '@15gifts/sdk'\n *\n * const conversationId = getConversationId()\n *\n * if (conversationId) {\n * console.log(`Conversation ID: ${conversationId}`)\n * } else {\n * console.log('No conversation ID found.')\n * }\n * ```\n */\nexport const getConversationId = () => sessionStorage.getItem(CONVERSATION_ID)\n\n/**\n * Stores the given conversation ID in `sessionStorage`.\n *\n * @example\n * ```ts\n * import { setConversationId } from '@15gifts/sdk'\n *\n * setConversationId('ca0ab4ce-f697-41cc-8d0c-081762aace9b')\n * // The conversation ID 'ca0ab4ce-f697-41cc-8d0c-081762aace9b' will be stored.\n * ```\n */\nexport const setConversationId = (conversationId: string) => sessionStorage.setItem(CONVERSATION_ID, conversationId)\n","/**\n * The key used to store the session ID in `sessionStorage`.\n *\n * @ignore\n */\nexport const SESSION_ID = '__15gifts_session_id'\n\n/**\n * Retrieves the session ID from `sessionStorage`.\n *\n * @example\n * ```ts\n * import { getSessionId } from '@15gifts/sdk'\n *\n * const sessionId = getSessionId()\n *\n * if (sessionId) {\n * console.log(`Session ID: ${sessionId}`)\n * } else {\n * console.log('No session ID found.')\n * }\n * ```\n */\nexport const getSessionId = () => sessionStorage.getItem(SESSION_ID)\n\n/**\n * Stores the given session ID in `sessionStorage`.\n *\n * @example\n * ```ts\n * import { setSessionId } from '@15gifts/sdk'\n *\n * setSessionId('20b2bff6-64a0-4101-bed9-ff545326584a')\n * // The session ID '20b2bff6-64a0-4101-bed9-ff545326584a' will be stored.\n * ```\n */\nexport const setSessionId = (sessionId: string) => sessionStorage.setItem(SESSION_ID, sessionId)\n","const getItemWithExpiry = (key: string) => {\n const itemString = localStorage.getItem(key)\n\n if (!itemString) return null\n\n const item = JSON.parse(itemString) as { expires: number; value: string }\n\n if (Date.now() > item.expires) {\n localStorage.removeItem(key)\n\n return null\n }\n\n return item.value\n}\n\nexport default getItemWithExpiry\n","const setItemWithExpiry = (key: string, value: string, ttl: number) => {\n const item = {\n expires: Date.now() + ttl,\n value,\n }\n\n localStorage.setItem(key, JSON.stringify(item))\n}\n\nexport default setItemWithExpiry\n","import { getItemWithExpiry, setItemWithExpiry } from '../utils'\n\n/**\n * The key used to store the user ID in `localStorage`.\n *\n * @ignore\n */\nexport const USER_ID = '__15gifts_user_id'\n\n/**\n * Time-to-live (TTL) for the user ID in milliseconds.\n * Set to 30 days.\n *\n * @ignore\n */\nexport const TTL = 1000 * 60 * 60 * 24 * 30 // 30 days\n\n/**\n * Retrieves the user ID from `localStorage`.\n *\n * @example\n * ```ts\n * import { getUserId } from '@15gifts/sdk'\n *\n * const userId = getUserId()\n *\n * if (userId) {\n * console.log(`User ID: ${userId}`)\n * } else {\n * console.log('No user ID found.')\n * }\n * ```\n */\nexport const getUserId = () => getItemWithExpiry(USER_ID)\n\n/**\n * Stores the given user ID in `localStorage`.\n *\n * @example\n * ```ts\n * import { setUserId } from '@15gifts/sdk'\n *\n * setUserId('5b77656c-ea4c-492f-82bf-7129297c5873')\n * // The user ID '5b77656c-ea4c-492f-82bf-7129297c5873' will be stored with a 30-day expiry.\n * ```\n */\nexport const setUserId = (userId: string) => setItemWithExpiry(USER_ID, userId, TTL)\n","import type { Middleware } from 'openapi-fetch'\n\n/**\n * Middleware for adding an `Authorization` header to requests.\n *\n * @param accessToken - The token to be included in the `Authorization` header.\n * @returns A middleware object that attaches the access token to the request headers.\n *\n * @example\n * ```ts\n * import { authMiddleware } from '@15gifts/sdk';\n *\n * this.endpoint.conversation.use(authMiddleware(accessToken))\n * ```\n */\nconst authMiddleware = (accessToken: string): Middleware => ({\n onRequest: async ({ request }) => {\n request.headers.set('Authorization', `Bearer ${accessToken}`)\n\n return request\n },\n})\n\nexport default authMiddleware\n","{\n \"name\": \"@15gifts/sdk\",\n \"version\": \"0.6.0\",\n \"files\": [\n \"dist\"\n ],\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"scripts\": {\n \"build\": \"tsup\",\n \"coverage\": \"vitest run --coverage\",\n \"dev\": \"tsup --watch\",\n \"format\": \"prettier . --write\",\n \"generate\": \"npx openapi-typescript\",\n \"lint\": \"eslint .\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"typecheck\": \"tsc\"\n },\n \"dependencies\": {\n \"openapi-fetch\": \"^0.13.3\"\n },\n \"devDependencies\": {\n \"openapi-typescript\": \"^7.4.4\",\n \"tsup\": \"^8.3.5\",\n \"eslint-config-custom\": \"^0.1.0\"\n },\n \"sideEffects\": false,\n \"prettier\": \"prettier-config-custom\"\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,WAAAC,EAAA,eAAAC,EAAA,QAAAC,EAAA,YAAAC,EAAA,mBAAAC,EAAA,yBAAAC,EAAA,sBAAAC,EAAA,iBAAAC,EAAA,cAAAC,EAAA,sBAAAC,EAAA,iBAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAf,GCAA,IAAAgB,EAAyB,4BCKlB,IAAMC,EAAkB,4BAalBC,EAAuB,IAAM,eAAe,WAAWD,CAAe,EAkBtEE,EAAoB,IAAM,eAAe,QAAQF,CAAe,EAahEG,EAAqBC,GAA2B,eAAe,QAAQJ,EAAiBI,CAAc,EC5C5G,IAAMC,EAAa,uBAkBbC,EAAe,IAAM,eAAe,QAAQD,CAAU,EAatDE,EAAgBC,GAAsB,eAAe,QAAQH,EAAYG,CAAS,ECpC/F,IAAMC,EAAqBC,GAAgB,CACzC,IAAMC,EAAa,aAAa,QAAQD,CAAG,EAE3C,GAAI,CAACC,EAAY,OAAO,KAExB,IAAMC,EAAO,KAAK,MAA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BD,CAAc,EAChC,KAAK,SAAS,eAAiBA,GAGhBV,EAAK,OAAQc,GAAYA,EAAQ,OAAS,mBAAqBA,EAAQ,OAAS,OAAO,CAE1G,CAcA,MAAM,WAAWC,EAAuCC,EAAoD,CAC1G,IAAMC,EAAsB,CAC1B,qBAAsBD,EACtB,eAAgB,KAAK,SAAS,eAC9B,WAAY,OACZ,UAAAD,EACA,IAAK,OAAO,SAAS,KACrB,UAAW,OAAO,UAAU,SAC9B,EAEA,OAAO,KAAK,SAAS,SAAS,KAAK,wBAAyB,CAC1D,KAAAE,CACF,CAAC,CACH,CACF","names":["index_exports","__export","CONVERSATION_ID","Client","SESSION_ID","TTL","USER_ID","auth_default","deleteConversationId","getConversationId","getSessionId","getUserId","setConversationId","setSessionId","setUserId","__toCommonJS","import_openapi_fetch","CONVERSATION_ID","deleteConversationId","getConversationId","setConversationId","conversationId","SESSION_ID","getSessionId","setSessionId","sessionId","getItemWithExpiry","key","itemString","item","getItemWithExpiry_default","setItemWithExpiry","key","value","ttl","item","setItemWithExpiry_default","USER_ID","TTL","getUserId","getItemWithExpiry_default","setUserId","userId","setItemWithExpiry_default","authMiddleware","accessToken","request","auth_default","version","Client","customerId","fetch","conversationUrl","frontendUrl","headers","version","createClient","getConversationId","getSessionId","getUserId","sessionId","userId","data","setSessionId","setUserId","endpont","auth_default","deleteConversationId","context","conversationContext","conversationIdMessage","openingMessage","conversationId","setConversationId","userMessage","debugMessages","message","eventName","properties","body"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/identity/conversationId.ts","../src/identity/sessionId.ts","../src/utils/getItemWithExpiry.ts","../src/utils/setItemWithExpiry.ts","../src/identity/userId.ts","../src/middlewares/auth.ts","../package.json"],"sourcesContent":["export * from './client'\nexport * from './identity'\nexport * from './middlewares'\nexport * from './types'\n","import createClient from 'openapi-fetch'\n\nimport {\n deleteConversationId,\n getConversationId,\n getSessionId,\n getUserId,\n setConversationId,\n setSessionId,\n setUserId,\n} from './identity'\nimport { authMiddleware } from './middlewares'\nimport type { paths as conversationPaths } from './schemas/conversation'\nimport type { paths as frontendPaths } from './schemas/frontend'\nimport type {\n BasicMessage,\n Config,\n ConversationIdMessage,\n DebugMessage,\n Endpoint,\n Identity,\n Message,\n TrackingEvent,\n} from './types'\nimport { version } from '../package.json'\n\n/**\n * The `Client` class provides methods to manage 15gifts API.\n */\nexport class Client {\n /**\n * This can be used to interact with the APIs directly. It is recommended to use the [helper methods](/sdk/sdk-reference/classes/client/#methods) provided by the `Client` class instead.\n *\n * @example\n * ```ts\n * const client = new Client({ customerId: 'YOUR_CUSTOMER_ID' })\n * const { data } = await client.endpoint.conversation.POST('/api/conversation/v2')\n * ```\n */\n endpoint: Endpoint\n\n /**\n * The identity information.\n */\n identity: Identity\n\n /**\n * Creates a new instance of the `Client` class.\n *\n * @param config - Configuration options for initializing the client.\n *\n * @example\n * ```ts\n * const client = new Client({ customerId: 'YOUR_CUSTOMER_ID' })\n * ```\n */\n constructor({ customerId, fetch, conversationUrl, frontendUrl }: Config) {\n const headers = {\n 'X-SDK-VERSION': version,\n }\n\n this.endpoint = {\n conversation: createClient<conversationPaths>({ baseUrl: conversationUrl, fetch, headers }),\n frontend: createClient<frontendPaths>({ baseUrl: frontendUrl, fetch, headers }),\n }\n this.identity = {\n customerId,\n conversationId: getConversationId() ?? undefined,\n sessionId: getSessionId() ?? undefined,\n userId: getUserId() ?? undefined,\n }\n }\n\n /**\n * 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.\n * Ends the current conversation if a conversation ID is present before sending a request to update identity.\n *\n * @returns A promise that resolves once the identity is created and the access token is set.\n *\n * @example\n * ```ts\n * await client.createIdentity()\n * console.log('Identity created:', client.identity)\n * ```\n */\n async createIdentity(): Promise<void> {\n const { customerId, pageviewId, sessionId, userId } = this.identity\n\n const { data } = await this.endpoint.frontend.POST('/api/tracking/identity/v2', {\n body: {\n customerId,\n sessionId,\n userId,\n },\n })\n\n if (data) {\n if (!pageviewId) {\n this.identity.pageviewId = data.pageviewId\n }\n if (!sessionId) {\n this.identity.sessionId = data.sessionId\n setSessionId(data.sessionId)\n }\n if (!userId) {\n this.identity.userId = data.userId\n setUserId(data.userId)\n }\n\n Object.values(this.endpoint).forEach((endpont) => {\n endpont.use(authMiddleware(data.token))\n })\n }\n }\n\n /**\n * Ends the current conversation by deleting the conversation ID.\n *\n * @example\n * ```ts\n * client.endConversation()\n * console.log('Conversation ended')\n * ```\n */\n endConversation(): void {\n deleteConversationId()\n this.identity.conversationId = undefined\n }\n\n /**\n * Clears the existing conversation ID, then generates a new one and returns the opening message.\n *\n * @param context - Optional context to customize the conversation. It can include:\n * @param context.eligibleProducts An array of eligible product IDs.\n * @param context.productOverrides Overrides for product details.\n *\n *\n * @returns A promise that resolves to the opening message.\n *\n * @example\n * ##### Basic usage\n * ```ts\n * const openingMessage = await client.startConversation()\n * console.log('Opening message:', openingMessage)\n * ```\n *\n * ##### With context\n * ```ts\n * const openingMessage = await client.startConversation({ eligibleProducts: ['product-1', 'product-2'], productOverrides: { 'product-1': { price: 40 } })\n * console.log('Opening message:', openingMessage)\n * ```\n */\n async startConversation(context?: {\n eligibleProducts?: string[]\n productOverrides?: Record<string, { price: number; minSpeed?: number; maxSpeed?: number }>\n }): Promise<BasicMessage | undefined> {\n this.endConversation()\n\n const conversationContext = {\n availableProductIds: [],\n ...context,\n }\n\n const { data } = await this.endpoint.conversation.POST(`/api/conversation/v3`, {\n body: {\n type: 'START_CONVERSATION',\n conversationContext,\n },\n })\n\n const [conversationIdMessage, openingMessage] = data as [ConversationIdMessage, BasicMessage]\n\n const conversationId = conversationIdMessage.conversationId\n if (!conversationId) {\n throw new Error('Conversation ID not received')\n }\n\n setConversationId(conversationId)\n this.identity.conversationId = conversationId\n\n return openingMessage\n }\n\n /**\n * Sends a message in the conversation.\n *\n * @param options - An object containing the user message.\n * @returns A promise that resolves to an array of messages\n *\n * @example\n * ```ts\n * const newMessages = await client.sendMessage({\n * userMessage: 'How can I get support?',\n * })\n *\n * if (newMessages) {\n * console.log('Received messages:', newMessages)\n * } else {\n * console.log('No message received')\n * }\n * ```\n */\n async sendMessage({\n userMessage,\n }: {\n userMessage: string\n }): Promise<Exclude<Message, ConversationIdMessage | DebugMessage>[] | undefined> {\n const { data } = await this.endpoint.conversation.POST('/api/conversation/v3', {\n body: {\n conversationId: this.identity.conversationId,\n userMessage,\n type: 'MESSAGE',\n },\n })\n\n if (!data) return undefined\n\n // Log debug messages\n // These will only be in the response when used in internal testing\n const debugMessages = data.filter((message) => message.type === 'DEBUG')\n if (debugMessages.length) {\n console.info('Debug messages:', debugMessages)\n }\n\n // When a request does not contain a conversation ID, the API will return a new conversation ID as the first message\n const conversationId = data.find((message) => message.type === 'CONVERSATION_ID')?.conversationId\n if (conversationId) {\n setConversationId(conversationId)\n this.identity.conversationId = conversationId\n }\n\n const messages = data.filter((message) => message.type !== 'CONVERSATION_ID' && message.type !== 'DEBUG')\n return messages\n }\n\n /**\n * Sends an event to the tracking API, with the required properties already set.\n *\n * @param eventName - The name of the event to track.\n * @param properties - Additional properties to include in the event.\n * @returns A promise that resolves once the event is tracked.\n *\n * @example\n * ```ts\n * await client.trackEvent('tab-shown')\n * ```\n */\n async trackEvent(eventName: TrackingEvent['eventName'], properties?: TrackingEvent['additionalProperties']) {\n const body: TrackingEvent = {\n additionalProperties: properties,\n conversationId: this.identity.conversationId,\n deviceType: undefined,\n eventName,\n pageviewId: this.identity.pageviewId,\n url: window.location.href,\n userAgent: window.navigator.userAgent,\n }\n\n return this.endpoint.frontend.POST('/api/tracking/user/v2', {\n body,\n })\n }\n}\n","/**\n * The key used to store the conversation ID in `sessionStorage`.\n *\n * @ignore\n */\nexport const CONVERSATION_ID = '__15gifts_conversation_id'\n\n/**\n * Deletes the conversation ID from `sessionStorage`.\n *\n * @example\n * ```ts\n * import { deleteConversationId } from '@15gifts/sdk'\n *\n * deleteConversationId()\n * // The conversation ID will be removed.\n * ```\n */\nexport const deleteConversationId = () => sessionStorage.removeItem(CONVERSATION_ID)\n\n/**\n * Retrieves the conversation ID from `sessionStorage`.\n *\n * @example\n * ```ts\n * import { getConversationId } from '@15gifts/sdk'\n *\n * const conversationId = getConversationId()\n *\n * if (conversationId) {\n * console.log(`Conversation ID: ${conversationId}`)\n * } else {\n * console.log('No conversation ID found.')\n * }\n * ```\n */\nexport const getConversationId = () => sessionStorage.getItem(CONVERSATION_ID)\n\n/**\n * Stores the given conversation ID in `sessionStorage`.\n *\n * @example\n * ```ts\n * import { setConversationId } from '@15gifts/sdk'\n *\n * setConversationId('ca0ab4ce-f697-41cc-8d0c-081762aace9b')\n * // The conversation ID 'ca0ab4ce-f697-41cc-8d0c-081762aace9b' will be stored.\n * ```\n */\nexport const setConversationId = (conversationId: string) => sessionStorage.setItem(CONVERSATION_ID, conversationId)\n","/**\n * The key used to store the session ID in `sessionStorage`.\n *\n * @ignore\n */\nexport const SESSION_ID = '__15gifts_session_id'\n\n/**\n * Retrieves the session ID from `sessionStorage`.\n *\n * @example\n * ```ts\n * import { getSessionId } from '@15gifts/sdk'\n *\n * const sessionId = getSessionId()\n *\n * if (sessionId) {\n * console.log(`Session ID: ${sessionId}`)\n * } else {\n * console.log('No session ID found.')\n * }\n * ```\n */\nexport const getSessionId = () => sessionStorage.getItem(SESSION_ID)\n\n/**\n * Stores the given session ID in `sessionStorage`.\n *\n * @example\n * ```ts\n * import { setSessionId } from '@15gifts/sdk'\n *\n * setSessionId('20b2bff6-64a0-4101-bed9-ff545326584a')\n * // The session ID '20b2bff6-64a0-4101-bed9-ff545326584a' will be stored.\n * ```\n */\nexport const setSessionId = (sessionId: string) => sessionStorage.setItem(SESSION_ID, sessionId)\n","const getItemWithExpiry = (key: string) => {\n const itemString = localStorage.getItem(key)\n\n if (!itemString) return null\n\n const item = JSON.parse(itemString) as { expires: number; value: string }\n\n if (Date.now() > item.expires) {\n localStorage.removeItem(key)\n\n return null\n }\n\n return item.value\n}\n\nexport default getItemWithExpiry\n","const setItemWithExpiry = (key: string, value: string, ttl: number) => {\n const item = {\n expires: Date.now() + ttl,\n value,\n }\n\n localStorage.setItem(key, JSON.stringify(item))\n}\n\nexport default setItemWithExpiry\n","import { getItemWithExpiry, setItemWithExpiry } from '../utils'\n\n/**\n * The key used to store the user ID in `localStorage`.\n *\n * @ignore\n */\nexport const USER_ID = '__15gifts_user_id'\n\n/**\n * Time-to-live (TTL) for the user ID in milliseconds.\n * Set to 30 days.\n *\n * @ignore\n */\nexport const TTL = 1000 * 60 * 60 * 24 * 30 // 30 days\n\n/**\n * Retrieves the user ID from `localStorage`.\n *\n * @example\n * ```ts\n * import { getUserId } from '@15gifts/sdk'\n *\n * const userId = getUserId()\n *\n * if (userId) {\n * console.log(`User ID: ${userId}`)\n * } else {\n * console.log('No user ID found.')\n * }\n * ```\n */\nexport const getUserId = () => getItemWithExpiry(USER_ID)\n\n/**\n * Stores the given user ID in `localStorage`.\n *\n * @example\n * ```ts\n * import { setUserId } from '@15gifts/sdk'\n *\n * setUserId('5b77656c-ea4c-492f-82bf-7129297c5873')\n * // The user ID '5b77656c-ea4c-492f-82bf-7129297c5873' will be stored with a 30-day expiry.\n * ```\n */\nexport const setUserId = (userId: string) => setItemWithExpiry(USER_ID, userId, TTL)\n","import type { Middleware } from 'openapi-fetch'\n\n/**\n * Middleware for adding an `Authorization` header to requests.\n *\n * @param accessToken - The token to be included in the `Authorization` header.\n * @returns A middleware object that attaches the access token to the request headers.\n *\n * @example\n * ```ts\n * import { authMiddleware } from '@15gifts/sdk';\n *\n * this.endpoint.conversation.use(authMiddleware(accessToken))\n * ```\n */\nconst authMiddleware = (accessToken: string): Middleware => ({\n onRequest: async ({ request }) => {\n request.headers.set('Authorization', `Bearer ${accessToken}`)\n\n return request\n },\n})\n\nexport default authMiddleware\n","{\n \"name\": \"@15gifts/sdk\",\n \"version\": \"0.6.2\",\n \"files\": [\n \"dist\"\n ],\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"scripts\": {\n \"build\": \"tsup\",\n \"coverage\": \"vitest run --coverage\",\n \"dev\": \"tsup --watch\",\n \"format\": \"prettier . --write\",\n \"generate\": \"npx openapi-typescript\",\n \"lint\": \"eslint .\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"typecheck\": \"tsc\"\n },\n \"dependencies\": {\n \"openapi-fetch\": \"^0.13.3\"\n },\n \"devDependencies\": {\n \"openapi-typescript\": \"^7.4.4\",\n \"tsup\": \"^8.3.5\"\n },\n \"sideEffects\": false,\n \"prettier\": \"prettier-config-custom\"\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,WAAAC,EAAA,eAAAC,EAAA,QAAAC,EAAA,YAAAC,EAAA,mBAAAC,EAAA,yBAAAC,EAAA,sBAAAC,EAAA,iBAAAC,EAAA,cAAAC,EAAA,sBAAAC,EAAA,iBAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAf,GCAA,IAAAgB,EAAyB,4BCKlB,IAAMC,EAAkB,4BAalBC,EAAuB,IAAM,eAAe,WAAWD,CAAe,EAkBtEE,EAAoB,IAAM,eAAe,QAAQF,CAAe,EAahEG,EAAqBC,GAA2B,eAAe,QAAQJ,EAAiBI,CAAc,EC5C5G,IAAMC,EAAa,uBAkBbC,EAAe,IAAM,eAAe,QAAQD,CAAU,EAatDE,EAAgBC,GAAsB,eAAe,QAAQH,EAAYG,CAAS,ECpC/F,IAAMC,EAAqBC,GAAgB,CACzC,IAAMC,EAAa,aAAa,QAAQD,CAAG,EAE3C,GAAI,CAACC,EAAY,OAAO,KAExB,IAAMC,EAAO,KAAK,MAAMD,CAAU,EAElC,OAAI,KAAK,IAAI,EAAIC,EAAK,SACpB,aAAa,WAAWF,CAAG,EAEpB,MAGFE,EAAK,KACd,EAEOC,EAAQJ,EChBf,IAAMK,EAAoB,CAACC,EAAaC,EAAeC,IAAgB,CACrE,IAAMC,EAAO,CACX,QAAS,KAA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oD,CAC1G,IAAMC,EAAsB,CAC1B,qBAAsBD,EACtB,eAAgB,KAAK,SAAS,eAC9B,WAAY,OACZ,UAAAD,EACA,WAAY,KAAK,SAAS,WAC1B,IAAK,OAAO,SAAS,KACrB,UAAW,OAAO,UAAU,SAC9B,EAEA,OAAO,KAAK,SAAS,SAAS,KAAK,wBAAyB,CAC1D,KAAAE,CACF,CAAC,CACH,CACF","names":["index_exports","__export","CONVERSATION_ID","Client","SESSION_ID","TTL","USER_ID","auth_default","deleteConversationId","getConversationId","getSessionId","getUserId","setConversationId","setSessionId","setUserId","__toCommonJS","import_openapi_fetch","CONVERSATION_ID","deleteConversationId","getConversationId","setConversationId","conversationId","SESSION_ID","getSessionId","setSessionId","sessionId","getItemWithExpiry","key","itemString","item","getItemWithExpiry_default","setItemWithExpiry","key","value","ttl","item","setItemWithExpiry_default","USER_ID","TTL","getUserId","getItemWithExpiry_default","setUserId","userId","setItemWithExpiry_default","authMiddleware","accessToken","request","auth_default","version","Client","customerId","fetch","conversationUrl","frontendUrl","headers","version","createClient","getConversationId","getSessionId","getUserId","pageviewId","sessionId","userId","data","setSessionId","setUserId","endpont","auth_default","deleteConversationId","context","conversationContext","conversationIdMessage","openingMessage","conversationId","setConversationId","userMessage","debugMessages","message","eventName","properties","body"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import S from"openapi-fetch";var a="__15gifts_conversation_id",I=()=>sessionStorage.removeItem(a),
|
|
1
|
+
import S from"openapi-fetch";var a="__15gifts_conversation_id",I=()=>sessionStorage.removeItem(a),v=()=>sessionStorage.getItem(a),d=s=>sessionStorage.setItem(a,s);var f="__15gifts_session_id",m=()=>sessionStorage.getItem(f),u=s=>sessionStorage.setItem(f,s);var w=s=>{let t=localStorage.getItem(s);if(!t)return null;let e=JSON.parse(t);return Date.now()>e.expires?(localStorage.removeItem(s),null):e.value},c=w;var M=(s,t,e)=>{let n={expires:Date.now()+e,value:t};localStorage.setItem(s,JSON.stringify(n))},p=M;var l="__15gifts_user_id",C=1e3*60*60*24*30,y=()=>c(l),h=s=>p(l,s,C);var b=s=>({onRequest:async({request:t})=>(t.headers.set("Authorization",`Bearer ${s}`),t)}),g=b;var x="0.6.2";var E=class{endpoint;identity;constructor({customerId:t,fetch:e,conversationUrl:n,frontendUrl:r}){let i={"X-SDK-VERSION":x};this.endpoint={conversation:S({baseUrl:n,fetch:e,headers:i}),frontend:S({baseUrl:r,fetch:e,headers:i})},this.identity={customerId:t,conversationId:v()??void 0,sessionId:m()??void 0,userId:y()??void 0}}async createIdentity(){let{customerId:t,pageviewId:e,sessionId:n,userId:r}=this.identity,{data:i}=await this.endpoint.frontend.POST("/api/tracking/identity/v2",{body:{customerId:t,sessionId:n,userId:r}});i&&(e||(this.identity.pageviewId=i.pageviewId),n||(this.identity.sessionId=i.sessionId,u(i.sessionId)),r||(this.identity.userId=i.userId,h(i.userId)),Object.values(this.endpoint).forEach(o=>{o.use(g(i.token))}))}endConversation(){I(),this.identity.conversationId=void 0}async startConversation(t){this.endConversation();let e={availableProductIds:[],...t},{data:n}=await this.endpoint.conversation.POST("/api/conversation/v3",{body:{type:"START_CONVERSATION",conversationContext:e}}),[r,i]=n,o=r.conversationId;if(!o)throw new Error("Conversation ID not received");return d(o),this.identity.conversationId=o,i}async sendMessage({userMessage:t}){let{data:e}=await this.endpoint.conversation.POST("/api/conversation/v3",{body:{conversationId:this.identity.conversationId,userMessage:t,type:"MESSAGE"}});if(!e)return;let n=e.filter(o=>o.type==="DEBUG");n.length&&console.info("Debug messages:",n);let r=e.find(o=>o.type==="CONVERSATION_ID")?.conversationId;return r&&(d(r),this.identity.conversationId=r),e.filter(o=>o.type!=="CONVERSATION_ID"&&o.type!=="DEBUG")}async trackEvent(t,e){let n={additionalProperties:e,conversationId:this.identity.conversationId,deviceType:void 0,eventName:t,pageviewId:this.identity.pageviewId,url:window.location.href,userAgent:window.navigator.userAgent};return this.endpoint.frontend.POST("/api/tracking/user/v2",{body:n})}};export{a as CONVERSATION_ID,E as Client,f as SESSION_ID,C as TTL,l as USER_ID,g as authMiddleware,I as deleteConversationId,v as getConversationId,m as getSessionId,y as getUserId,d as setConversationId,u as setSessionId,h as setUserId};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/identity/conversationId.ts","../src/identity/sessionId.ts","../src/utils/getItemWithExpiry.ts","../src/utils/setItemWithExpiry.ts","../src/identity/userId.ts","../src/middlewares/auth.ts","../package.json"],"sourcesContent":["import createClient from 'openapi-fetch'\n\nimport {\n deleteConversationId,\n getConversationId,\n getSessionId,\n getUserId,\n setConversationId,\n setSessionId,\n setUserId,\n} from './identity'\nimport { authMiddleware } from './middlewares'\nimport type { paths as conversationPaths } from './schemas/conversation'\nimport type { paths as frontendPaths } from './schemas/frontend'\nimport type {\n BasicMessage,\n Config,\n ConversationIdMessage,\n DebugMessage,\n Endpoint,\n Identity,\n Message,\n TrackingEvent,\n} from './types'\nimport { version } from '../package.json'\n\n/**\n * The `Client` class provides methods to manage 15gifts API.\n */\nexport class Client {\n /**\n * This can be used to interact with the APIs directly. It is recommended to use the [helper methods](/sdk/sdk-reference/classes/client/#methods) provided by the `Client` class instead.\n *\n * @example\n * ```ts\n * const client = new Client({ customerId: 'YOUR_CUSTOMER_ID' })\n * const { data } = await client.endpoint.conversation.POST('/api/conversation/v2')\n * ```\n */\n endpoint: Endpoint\n\n /**\n * The identity information.\n */\n identity: Identity\n\n /**\n * Creates a new instance of the `Client` class.\n *\n * @param config - Configuration options for initializing the client.\n *\n * @example\n * ```ts\n * const client = new Client({ customerId: 'YOUR_CUSTOMER_ID' })\n * ```\n */\n constructor({ customerId, fetch, conversationUrl, frontendUrl }: Config) {\n const headers = {\n 'X-SDK-VERSION': version,\n }\n\n this.endpoint = {\n conversation: createClient<conversationPaths>({ baseUrl: conversationUrl, fetch, headers }),\n frontend: createClient<frontendPaths>({ baseUrl: frontendUrl, fetch, headers }),\n }\n this.identity = {\n customerId,\n conversationId: getConversationId() ?? undefined,\n sessionId: getSessionId() ?? undefined,\n userId: getUserId() ?? undefined,\n }\n }\n\n /**\n * 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.\n * Ends the current conversation if a conversation ID is present before sending a request to update identity.\n *\n * @returns A promise that resolves once the identity is created and the access token is set.\n *\n * @example\n * ```ts\n * await client.createIdentity()\n * console.log('Identity created:', client.identity)\n * ```\n */\n async createIdentity(): Promise<void> {\n const { customerId, sessionId, userId } = this.identity\n\n const { data } = await this.endpoint.frontend.POST('/api/tracking/identity/v2', {\n body: {\n customerId,\n sessionId,\n userId,\n },\n })\n\n if (data) {\n if (!sessionId) {\n this.identity.sessionId = data.sessionId\n setSessionId(data.sessionId)\n }\n if (!userId) {\n this.identity.userId = data.userId\n setUserId(data.userId)\n }\n\n Object.values(this.endpoint).forEach((endpont) => {\n endpont.use(authMiddleware(data.token))\n })\n }\n }\n\n /**\n * Ends the current conversation by deleting the conversation ID.\n *\n * @example\n * ```ts\n * client.endConversation()\n * console.log('Conversation ended')\n * ```\n */\n endConversation(): void {\n deleteConversationId()\n this.identity.conversationId = undefined\n }\n\n /**\n * Clears the existing conversation ID, then generates a new one and returns the opening message.\n *\n * @param context - Optional context to customize the conversation. It can include:\n * @param context.eligibleProducts An array of eligible product IDs.\n * @param context.productOverrides Overrides for product details.\n *\n *\n * @returns A promise that resolves to the opening message.\n *\n * @example\n * ##### Basic usage\n * ```ts\n * const openingMessage = await client.startConversation()\n * console.log('Opening message:', openingMessage)\n * ```\n *\n * ##### With context\n * ```ts\n * const openingMessage = await client.startConversation({ eligibleProducts: ['product-1', 'product-2'], productOverrides: { 'product-1': { price: 40 } })\n * console.log('Opening message:', openingMessage)\n * ```\n */\n async startConversation(context?: {\n eligibleProducts?: string[]\n productOverrides?: Record<string, { price: number; minSpeed?: number; maxSpeed?: number }>\n }): Promise<BasicMessage | undefined> {\n this.endConversation()\n\n const conversationContext = {\n availableProductIds: [],\n ...context,\n }\n\n const { data } = await this.endpoint.conversation.POST(`/api/conversation/v3`, {\n body: {\n type: 'START_CONVERSATION',\n conversationContext,\n },\n })\n\n const [conversationIdMessage, openingMessage] = data as [ConversationIdMessage, BasicMessage]\n\n const conversationId = conversationIdMessage.conversationId\n if (!conversationId) {\n throw new Error('Conversation ID not received')\n }\n\n setConversationId(conversationId)\n this.identity.conversationId = conversationId\n\n return openingMessage\n }\n\n /**\n * Sends a message in the conversation.\n *\n * @param options - An object containing the user message.\n * @returns A promise that resolves to an array of messages\n *\n * @example\n * ```ts\n * const newMessages = await client.sendMessage({\n * userMessage: 'How can I get support?',\n * })\n *\n * if (newMessages) {\n * console.log('Received messages:', newMessages)\n * } else {\n * console.log('No message received')\n * }\n * ```\n */\n async sendMessage({\n userMessage,\n }: {\n userMessage: string\n }): Promise<Exclude<Message, ConversationIdMessage | DebugMessage>[] | undefined> {\n const { data } = await this.endpoint.conversation.POST('/api/conversation/v3', {\n body: {\n conversationId: this.identity.conversationId,\n userMessage,\n type: 'MESSAGE',\n },\n })\n\n if (!data) return undefined\n\n // Log debug messages\n // These will only be in the response when used in internal testing\n const debugMessages = data.filter((message) => message.type === 'DEBUG')\n if (debugMessages.length) {\n console.info('Debug messages:', debugMessages)\n }\n\n // When a request does not contain a conversation ID, the API will return a new conversation ID as the first message\n const conversationId = data.find((message) => message.type === 'CONVERSATION_ID')?.conversationId\n if (conversationId) {\n setConversationId(conversationId)\n this.identity.conversationId = conversationId\n }\n\n const messages = data.filter((message) => message.type !== 'CONVERSATION_ID' && message.type !== 'DEBUG')\n return messages\n }\n\n /**\n * Sends an event to the tracking API, with the required properties already set.\n *\n * @param eventName - The name of the event to track.\n * @param properties - Additional properties to include in the event.\n * @returns A promise that resolves once the event is tracked.\n *\n * @example\n * ```ts\n * await client.trackEvent('tab-shown')\n * ```\n */\n async trackEvent(eventName: TrackingEvent['eventName'], properties?: TrackingEvent['additionalProperties']) {\n const body: TrackingEvent = {\n additionalProperties: properties,\n conversationId: this.identity.conversationId,\n deviceType: undefined,\n eventName,\n url: window.location.href,\n userAgent: window.navigator.userAgent,\n }\n\n return this.endpoint.frontend.POST('/api/tracking/user/v2', {\n body,\n })\n }\n}\n","/**\n * The key used to store the conversation ID in `sessionStorage`.\n *\n * @ignore\n */\nexport const CONVERSATION_ID = '__15gifts_conversation_id'\n\n/**\n * Deletes the conversation ID from `sessionStorage`.\n *\n * @example\n * ```ts\n * import { deleteConversationId } from '@15gifts/sdk'\n *\n * deleteConversationId()\n * // The conversation ID will be removed.\n * ```\n */\nexport const deleteConversationId = () => sessionStorage.removeItem(CONVERSATION_ID)\n\n/**\n * Retrieves the conversation ID from `sessionStorage`.\n *\n * @example\n * ```ts\n * import { getConversationId } from '@15gifts/sdk'\n *\n * const conversationId = getConversationId()\n *\n * if (conversationId) {\n * console.log(`Conversation ID: ${conversationId}`)\n * } else {\n * console.log('No conversation ID found.')\n * }\n * ```\n */\nexport const getConversationId = () => sessionStorage.getItem(CONVERSATION_ID)\n\n/**\n * Stores the given conversation ID in `sessionStorage`.\n *\n * @example\n * ```ts\n * import { setConversationId } from '@15gifts/sdk'\n *\n * setConversationId('ca0ab4ce-f697-41cc-8d0c-081762aace9b')\n * // The conversation ID 'ca0ab4ce-f697-41cc-8d0c-081762aace9b' will be stored.\n * ```\n */\nexport const setConversationId = (conversationId: string) => sessionStorage.setItem(CONVERSATION_ID, conversationId)\n","/**\n * The key used to store the session ID in `sessionStorage`.\n *\n * @ignore\n */\nexport const SESSION_ID = '__15gifts_session_id'\n\n/**\n * Retrieves the session ID from `sessionStorage`.\n *\n * @example\n * ```ts\n * import { getSessionId } from '@15gifts/sdk'\n *\n * const sessionId = getSessionId()\n *\n * if (sessionId) {\n * console.log(`Session ID: ${sessionId}`)\n * } else {\n * console.log('No session ID found.')\n * }\n * ```\n */\nexport const getSessionId = () => sessionStorage.getItem(SESSION_ID)\n\n/**\n * Stores the given session ID in `sessionStorage`.\n *\n * @example\n * ```ts\n * import { setSessionId } from '@15gifts/sdk'\n *\n * setSessionId('20b2bff6-64a0-4101-bed9-ff545326584a')\n * // The session ID '20b2bff6-64a0-4101-bed9-ff545326584a' will be stored.\n * ```\n */\nexport const setSessionId = (sessionId: string) => sessionStorage.setItem(SESSION_ID, sessionId)\n","const getItemWithExpiry = (key: string) => {\n const itemString = localStorage.getItem(key)\n\n if (!itemString) return null\n\n const item = JSON.parse(itemString) as { expires: number; value: string }\n\n if (Date.now() > item.expires) {\n localStorage.removeItem(key)\n\n return null\n }\n\n return item.value\n}\n\nexport default getItemWithExpiry\n","const setItemWithExpiry = (key: string, value: string, ttl: number) => {\n const item = {\n expires: Date.now() + ttl,\n value,\n }\n\n localStorage.setItem(key, JSON.stringify(item))\n}\n\nexport default setItemWithExpiry\n","import { getItemWithExpiry, setItemWithExpiry } from '../utils'\n\n/**\n * The key used to store the user ID in `localStorage`.\n *\n * @ignore\n */\nexport const USER_ID = '__15gifts_user_id'\n\n/**\n * Time-to-live (TTL) for the user ID in milliseconds.\n * Set to 30 days.\n *\n * @ignore\n */\nexport const TTL = 1000 * 60 * 60 * 24 * 30 // 30 days\n\n/**\n * Retrieves the user ID from `localStorage`.\n *\n * @example\n * ```ts\n * import { getUserId } from '@15gifts/sdk'\n *\n * const userId = getUserId()\n *\n * if (userId) {\n * console.log(`User ID: ${userId}`)\n * } else {\n * console.log('No user ID found.')\n * }\n * ```\n */\nexport const getUserId = () => getItemWithExpiry(USER_ID)\n\n/**\n * Stores the given user ID in `localStorage`.\n *\n * @example\n * ```ts\n * import { setUserId } from '@15gifts/sdk'\n *\n * setUserId('5b77656c-ea4c-492f-82bf-7129297c5873')\n * // The user ID '5b77656c-ea4c-492f-82bf-7129297c5873' will be stored with a 30-day expiry.\n * ```\n */\nexport const setUserId = (userId: string) => setItemWithExpiry(USER_ID, userId, TTL)\n","import type { Middleware } from 'openapi-fetch'\n\n/**\n * Middleware for adding an `Authorization` header to requests.\n *\n * @param accessToken - The token to be included in the `Authorization` header.\n * @returns A middleware object that attaches the access token to the request headers.\n *\n * @example\n * ```ts\n * import { authMiddleware } from '@15gifts/sdk';\n *\n * this.endpoint.conversation.use(authMiddleware(accessToken))\n * ```\n */\nconst authMiddleware = (accessToken: string): Middleware => ({\n onRequest: async ({ request }) => {\n request.headers.set('Authorization', `Bearer ${accessToken}`)\n\n return request\n },\n})\n\nexport default authMiddleware\n","{\n \"name\": \"@15gifts/sdk\",\n \"version\": \"0.6.0\",\n \"files\": [\n \"dist\"\n ],\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"scripts\": {\n \"build\": \"tsup\",\n \"coverage\": \"vitest run --coverage\",\n \"dev\": \"tsup --watch\",\n \"format\": \"prettier . --write\",\n \"generate\": \"npx openapi-typescript\",\n \"lint\": \"eslint .\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"typecheck\": \"tsc\"\n },\n \"dependencies\": {\n \"openapi-fetch\": \"^0.13.3\"\n },\n \"devDependencies\": {\n \"openapi-typescript\": \"^7.4.4\",\n \"tsup\": \"^8.3.5\",\n \"eslint-config-custom\": \"^0.1.0\"\n },\n \"sideEffects\": false,\n \"prettier\": \"prettier-config-custom\"\n}\n"],"mappings":"AAAA,OAAOA,MAAkB,gBCKlB,IAAMC,EAAkB,4BAalBC,EAAuB,IAAM,eAAe,WAAWD,CAAe,EAkBtEE,EAAoB,IAAM,eAAe,QAAQF,CAAe,EAahEG,EAAqBC,GAA2B,eAAe,QAAQJ,EAAiBI,CAAc,EC5C5G,IAAMC,EAAa,uBAkBbC,EAAe,IAAM,eAAe,QAAQD,CAAU,EAatDE,EAAgBC,GAAsB,eAAe,QAAQH,EAAYG,CAAS,ECpC/F,IAAMC,EAAqBC,GAAgB,CACzC,IAAMC,EAAa,aAAa,QAAQD,CAAG,EAE3C,GAAI,CAACC,EAAY,OAAO,KAExB,IAAMC,EAAO,KAAK,MA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ChC,KAAK,SAAS,eAAiBA,GAGhBV,EAAK,OAAQc,GAAYA,EAAQ,OAAS,mBAAqBA,EAAQ,OAAS,OAAO,CAE1G,CAcA,MAAM,WAAWC,EAAuCC,EAAoD,CAC1G,IAAMC,EAAsB,CAC1B,qBAAsBD,EACtB,eAAgB,KAAK,SAAS,eAC9B,WAAY,OACZ,UAAAD,EACA,IAAK,OAAO,SAAS,KACrB,UAAW,OAAO,UAAU,SAC9B,EAEA,OAAO,KAAK,SAAS,SAAS,KAAK,wBAAyB,CAC1D,KAAAE,CACF,CAAC,CACH,CACF","names":["createClient","CONVERSATION_ID","deleteConversationId","getConversationId","setConversationId","conversationId","SESSION_ID","getSessionId","setSessionId","sessionId","getItemWithExpiry","key","itemString","item","getItemWithExpiry_default","setItemWithExpiry","key","value","ttl","item","setItemWithExpiry_default","USER_ID","TTL","getUserId","getItemWithExpiry_default","setUserId","userId","setItemWithExpiry_default","authMiddleware","accessToken","request","auth_default","version","Client","customerId","fetch","conversationUrl","frontendUrl","headers","version","createClient","getConversationId","getSessionId","getUserId","sessionId","userId","data","setSessionId","setUserId","endpont","auth_default","deleteConversationId","context","conversationContext","conversationIdMessage","openingMessage","conversationId","setConversationId","userMessage","debugMessages","message","eventName","properties","body"]}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/identity/conversationId.ts","../src/identity/sessionId.ts","../src/utils/getItemWithExpiry.ts","../src/utils/setItemWithExpiry.ts","../src/identity/userId.ts","../src/middlewares/auth.ts","../package.json"],"sourcesContent":["import createClient from 'openapi-fetch'\n\nimport {\n deleteConversationId,\n getConversationId,\n getSessionId,\n getUserId,\n setConversationId,\n setSessionId,\n setUserId,\n} from './identity'\nimport { authMiddleware } from './middlewares'\nimport type { paths as conversationPaths } from './schemas/conversation'\nimport type { paths as frontendPaths } from './schemas/frontend'\nimport type {\n BasicMessage,\n Config,\n ConversationIdMessage,\n DebugMessage,\n Endpoint,\n Identity,\n Message,\n TrackingEvent,\n} from './types'\nimport { version } from '../package.json'\n\n/**\n * The `Client` class provides methods to manage 15gifts API.\n */\nexport class Client {\n /**\n * This can be used to interact with the APIs directly. It is recommended to use the [helper methods](/sdk/sdk-reference/classes/client/#methods) provided by the `Client` class instead.\n *\n * @example\n * ```ts\n * const client = new Client({ customerId: 'YOUR_CUSTOMER_ID' })\n * const { data } = await client.endpoint.conversation.POST('/api/conversation/v2')\n * ```\n */\n endpoint: Endpoint\n\n /**\n * The identity information.\n */\n identity: Identity\n\n /**\n * Creates a new instance of the `Client` class.\n *\n * @param config - Configuration options for initializing the client.\n *\n * @example\n * ```ts\n * const client = new Client({ customerId: 'YOUR_CUSTOMER_ID' })\n * ```\n */\n constructor({ customerId, fetch, conversationUrl, frontendUrl }: Config) {\n const headers = {\n 'X-SDK-VERSION': version,\n }\n\n this.endpoint = {\n conversation: createClient<conversationPaths>({ baseUrl: conversationUrl, fetch, headers }),\n frontend: createClient<frontendPaths>({ baseUrl: frontendUrl, fetch, headers }),\n }\n this.identity = {\n customerId,\n conversationId: getConversationId() ?? undefined,\n sessionId: getSessionId() ?? undefined,\n userId: getUserId() ?? undefined,\n }\n }\n\n /**\n * 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.\n * Ends the current conversation if a conversation ID is present before sending a request to update identity.\n *\n * @returns A promise that resolves once the identity is created and the access token is set.\n *\n * @example\n * ```ts\n * await client.createIdentity()\n * console.log('Identity created:', client.identity)\n * ```\n */\n async createIdentity(): Promise<void> {\n const { customerId, pageviewId, sessionId, userId } = this.identity\n\n const { data } = await this.endpoint.frontend.POST('/api/tracking/identity/v2', {\n body: {\n customerId,\n sessionId,\n userId,\n },\n })\n\n if (data) {\n if (!pageviewId) {\n this.identity.pageviewId = data.pageviewId\n }\n if (!sessionId) {\n this.identity.sessionId = data.sessionId\n setSessionId(data.sessionId)\n }\n if (!userId) {\n this.identity.userId = data.userId\n setUserId(data.userId)\n }\n\n Object.values(this.endpoint).forEach((endpont) => {\n endpont.use(authMiddleware(data.token))\n })\n }\n }\n\n /**\n * Ends the current conversation by deleting the conversation ID.\n *\n * @example\n * ```ts\n * client.endConversation()\n * console.log('Conversation ended')\n * ```\n */\n endConversation(): void {\n deleteConversationId()\n this.identity.conversationId = undefined\n }\n\n /**\n * Clears the existing conversation ID, then generates a new one and returns the opening message.\n *\n * @param context - Optional context to customize the conversation. It can include:\n * @param context.eligibleProducts An array of eligible product IDs.\n * @param context.productOverrides Overrides for product details.\n *\n *\n * @returns A promise that resolves to the opening message.\n *\n * @example\n * ##### Basic usage\n * ```ts\n * const openingMessage = await client.startConversation()\n * console.log('Opening message:', openingMessage)\n * ```\n *\n * ##### With context\n * ```ts\n * const openingMessage = await client.startConversation({ eligibleProducts: ['product-1', 'product-2'], productOverrides: { 'product-1': { price: 40 } })\n * console.log('Opening message:', openingMessage)\n * ```\n */\n async startConversation(context?: {\n eligibleProducts?: string[]\n productOverrides?: Record<string, { price: number; minSpeed?: number; maxSpeed?: number }>\n }): Promise<BasicMessage | undefined> {\n this.endConversation()\n\n const conversationContext = {\n availableProductIds: [],\n ...context,\n }\n\n const { data } = await this.endpoint.conversation.POST(`/api/conversation/v3`, {\n body: {\n type: 'START_CONVERSATION',\n conversationContext,\n },\n })\n\n const [conversationIdMessage, openingMessage] = data as [ConversationIdMessage, BasicMessage]\n\n const conversationId = conversationIdMessage.conversationId\n if (!conversationId) {\n throw new Error('Conversation ID not received')\n }\n\n setConversationId(conversationId)\n this.identity.conversationId = conversationId\n\n return openingMessage\n }\n\n /**\n * Sends a message in the conversation.\n *\n * @param options - An object containing the user message.\n * @returns A promise that resolves to an array of messages\n *\n * @example\n * ```ts\n * const newMessages = await client.sendMessage({\n * userMessage: 'How can I get support?',\n * })\n *\n * if (newMessages) {\n * console.log('Received messages:', newMessages)\n * } else {\n * console.log('No message received')\n * }\n * ```\n */\n async sendMessage({\n userMessage,\n }: {\n userMessage: string\n }): Promise<Exclude<Message, ConversationIdMessage | DebugMessage>[] | undefined> {\n const { data } = await this.endpoint.conversation.POST('/api/conversation/v3', {\n body: {\n conversationId: this.identity.conversationId,\n userMessage,\n type: 'MESSAGE',\n },\n })\n\n if (!data) return undefined\n\n // Log debug messages\n // These will only be in the response when used in internal testing\n const debugMessages = data.filter((message) => message.type === 'DEBUG')\n if (debugMessages.length) {\n console.info('Debug messages:', debugMessages)\n }\n\n // When a request does not contain a conversation ID, the API will return a new conversation ID as the first message\n const conversationId = data.find((message) => message.type === 'CONVERSATION_ID')?.conversationId\n if (conversationId) {\n setConversationId(conversationId)\n this.identity.conversationId = conversationId\n }\n\n const messages = data.filter((message) => message.type !== 'CONVERSATION_ID' && message.type !== 'DEBUG')\n return messages\n }\n\n /**\n * Sends an event to the tracking API, with the required properties already set.\n *\n * @param eventName - The name of the event to track.\n * @param properties - Additional properties to include in the event.\n * @returns A promise that resolves once the event is tracked.\n *\n * @example\n * ```ts\n * await client.trackEvent('tab-shown')\n * ```\n */\n async trackEvent(eventName: TrackingEvent['eventName'], properties?: TrackingEvent['additionalProperties']) {\n const body: TrackingEvent = {\n additionalProperties: properties,\n conversationId: this.identity.conversationId,\n deviceType: undefined,\n eventName,\n pageviewId: this.identity.pageviewId,\n url: window.location.href,\n userAgent: window.navigator.userAgent,\n }\n\n return this.endpoint.frontend.POST('/api/tracking/user/v2', {\n body,\n })\n }\n}\n","/**\n * The key used to store the conversation ID in `sessionStorage`.\n *\n * @ignore\n */\nexport const CONVERSATION_ID = '__15gifts_conversation_id'\n\n/**\n * Deletes the conversation ID from `sessionStorage`.\n *\n * @example\n * ```ts\n * import { deleteConversationId } from '@15gifts/sdk'\n *\n * deleteConversationId()\n * // The conversation ID will be removed.\n * ```\n */\nexport const deleteConversationId = () => sessionStorage.removeItem(CONVERSATION_ID)\n\n/**\n * Retrieves the conversation ID from `sessionStorage`.\n *\n * @example\n * ```ts\n * import { getConversationId } from '@15gifts/sdk'\n *\n * const conversationId = getConversationId()\n *\n * if (conversationId) {\n * console.log(`Conversation ID: ${conversationId}`)\n * } else {\n * console.log('No conversation ID found.')\n * }\n * ```\n */\nexport const getConversationId = () => sessionStorage.getItem(CONVERSATION_ID)\n\n/**\n * Stores the given conversation ID in `sessionStorage`.\n *\n * @example\n * ```ts\n * import { setConversationId } from '@15gifts/sdk'\n *\n * setConversationId('ca0ab4ce-f697-41cc-8d0c-081762aace9b')\n * // The conversation ID 'ca0ab4ce-f697-41cc-8d0c-081762aace9b' will be stored.\n * ```\n */\nexport const setConversationId = (conversationId: string) => sessionStorage.setItem(CONVERSATION_ID, conversationId)\n","/**\n * The key used to store the session ID in `sessionStorage`.\n *\n * @ignore\n */\nexport const SESSION_ID = '__15gifts_session_id'\n\n/**\n * Retrieves the session ID from `sessionStorage`.\n *\n * @example\n * ```ts\n * import { getSessionId } from '@15gifts/sdk'\n *\n * const sessionId = getSessionId()\n *\n * if (sessionId) {\n * console.log(`Session ID: ${sessionId}`)\n * } else {\n * console.log('No session ID found.')\n * }\n * ```\n */\nexport const getSessionId = () => sessionStorage.getItem(SESSION_ID)\n\n/**\n * Stores the given session ID in `sessionStorage`.\n *\n * @example\n * ```ts\n * import { setSessionId } from '@15gifts/sdk'\n *\n * setSessionId('20b2bff6-64a0-4101-bed9-ff545326584a')\n * // The session ID '20b2bff6-64a0-4101-bed9-ff545326584a' will be stored.\n * ```\n */\nexport const setSessionId = (sessionId: string) => sessionStorage.setItem(SESSION_ID, sessionId)\n","const getItemWithExpiry = (key: string) => {\n const itemString = localStorage.getItem(key)\n\n if (!itemString) return null\n\n const item = JSON.parse(itemString) as { expires: number; value: string }\n\n if (Date.now() > item.expires) {\n localStorage.removeItem(key)\n\n return null\n }\n\n return item.value\n}\n\nexport default getItemWithExpiry\n","const setItemWithExpiry = (key: string, value: string, ttl: number) => {\n const item = {\n expires: Date.now() + ttl,\n value,\n }\n\n localStorage.setItem(key, JSON.stringify(item))\n}\n\nexport default setItemWithExpiry\n","import { getItemWithExpiry, setItemWithExpiry } from '../utils'\n\n/**\n * The key used to store the user ID in `localStorage`.\n *\n * @ignore\n */\nexport const USER_ID = '__15gifts_user_id'\n\n/**\n * Time-to-live (TTL) for the user ID in milliseconds.\n * Set to 30 days.\n *\n * @ignore\n */\nexport const TTL = 1000 * 60 * 60 * 24 * 30 // 30 days\n\n/**\n * Retrieves the user ID from `localStorage`.\n *\n * @example\n * ```ts\n * import { getUserId } from '@15gifts/sdk'\n *\n * const userId = getUserId()\n *\n * if (userId) {\n * console.log(`User ID: ${userId}`)\n * } else {\n * console.log('No user ID found.')\n * }\n * ```\n */\nexport const getUserId = () => getItemWithExpiry(USER_ID)\n\n/**\n * Stores the given user ID in `localStorage`.\n *\n * @example\n * ```ts\n * import { setUserId } from '@15gifts/sdk'\n *\n * setUserId('5b77656c-ea4c-492f-82bf-7129297c5873')\n * // The user ID '5b77656c-ea4c-492f-82bf-7129297c5873' will be stored with a 30-day expiry.\n * ```\n */\nexport const setUserId = (userId: string) => setItemWithExpiry(USER_ID, userId, TTL)\n","import type { Middleware } from 'openapi-fetch'\n\n/**\n * Middleware for adding an `Authorization` header to requests.\n *\n * @param accessToken - The token to be included in the `Authorization` header.\n * @returns A middleware object that attaches the access token to the request headers.\n *\n * @example\n * ```ts\n * import { authMiddleware } from '@15gifts/sdk';\n *\n * this.endpoint.conversation.use(authMiddleware(accessToken))\n * ```\n */\nconst authMiddleware = (accessToken: string): Middleware => ({\n onRequest: async ({ request }) => {\n request.headers.set('Authorization', `Bearer ${accessToken}`)\n\n return request\n },\n})\n\nexport default authMiddleware\n","{\n \"name\": \"@15gifts/sdk\",\n \"version\": \"0.6.2\",\n \"files\": [\n \"dist\"\n ],\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"scripts\": {\n \"build\": \"tsup\",\n \"coverage\": \"vitest run --coverage\",\n \"dev\": \"tsup --watch\",\n \"format\": \"prettier . --write\",\n \"generate\": \"npx openapi-typescript\",\n \"lint\": \"eslint .\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"typecheck\": \"tsc\"\n },\n \"dependencies\": {\n \"openapi-fetch\": \"^0.13.3\"\n },\n \"devDependencies\": {\n \"openapi-typescript\": \"^7.4.4\",\n \"tsup\": \"^8.3.5\"\n },\n \"sideEffects\": false,\n \"prettier\": \"prettier-config-custom\"\n}\n"],"mappings":"AAAA,OAAOA,MAAkB,gBCKlB,IAAMC,EAAkB,4BAalBC,EAAuB,IAAM,eAAe,WAAWD,CAAe,EAkBtEE,EAAoB,IAAM,eAAe,QAAQF,CAAe,EAahEG,EAAqBC,GAA2B,eAAe,QAAQJ,EAAiBI,CAAc,EC5C5G,IAAMC,EAAa,uBAkBbC,EAAe,IAAM,eAAe,QAAQD,CAAU,EAatDE,EAAgBC,GAAsB,eAAe,QAAQH,EAAYG,CAAS,ECpC/F,IAAMC,EAAqBC,GAAgB,CACzC,IAAMC,EAAa,aAAa,QAAQD,CAAG,EAE3C,GAAI,CAACC,EAAY,OAAO,KAExB,IAAMC,EAAO,KAAK,MAAMD,CAAU,EAElC,OAAI,KAAK,IAAI,EAAIC,EAAK,SACpB,aAAa,WAAWF,CAAG,EAEpB,MAGFE,EAAK,KACd,EAEOC,EAAQJ,EChBf,IAAMK,EAAoB,CAACC,EAAaC,EAAeC,IAAgB,CACrE,IAAMC,EAAO,CACX,QAAS,KAAK,IAAI,EAAID,EACtB,MAAAD,CACF,EAEA,aAAa,QAAQD,EAAK,KAAK,UAAUG,CAAI,CAAC,CAChD,EAEOC,EAAQL,ECFR,IAAMM,EAAU,oBAQVC,EAAM,IAAO,GAAK,GAAK,GAAK,GAkB5BC,EAAY,IAAMC,EAAkBH,CAAO,EAa3CI,EAAaC,GAAmBC,EAAkBN,EAASK,EAAQJ,CAAG,EC/BnF,IAAMM,EAAkBC,IAAqC,CAC3D,UAAW,MAAO,CAAE,QAAAC,CAAQ,KAC1BA,EAAQ,QAAQ,IAAI,gBAAiB,UAAUD,CAAW,EAAE,EAErDC,EAEX,GAEOC,EAAQH,ECrBb,IAAAI,EAAW,QP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,KAAM,qBACN,oBAAAO,CACF,CACF,CAAC,EAEK,CAACC,EAAuBC,CAAc,EAAIT,EAE1CU,EAAiBF,EAAsB,eAC7C,GAAI,CAACE,EACH,MAAM,IAAI,MAAM,8BAA8B,EAGhD,OAAAC,EAAkBD,CAAc,EAChC,KAAK,SAAS,eAAiBA,EAExBD,CACT,CAqBA,MAAM,YAAY,CAChB,YAAAG,CACF,EAEkF,CAChF,GAAM,CAAE,KAAAZ,CAAK,EAAI,MAAM,KAAK,SAAS,aAAa,KAAK,uBAAwB,CAC7E,KAAM,CACJ,eAAgB,KAAK,SAAS,eAC9B,YAAAY,EACA,KAAM,SACR,CACF,CAAC,EAED,GAAI,CAACZ,EAAM,OAIX,IAAMa,EAAgBb,EAAK,OAAQc,GAAYA,EAAQ,OAAS,OAAO,EACnED,EAAc,QAChB,QAAQ,KAAK,kBAAmBA,CAAa,EAI/C,IAAMH,EAAiBV,EAAK,KAAMc,GAAYA,EAAQ,OAAS,iBAAiB,GAAG,eACnF,OAAIJ,IACFC,EAAkBD,CAAc,EAChC,KAAK,SAAS,eAAiBA,GAGhBV,EAAK,OAAQc,GAAYA,EAAQ,OAAS,mBAAqBA,EAAQ,OAAS,OAAO,CAE1G,CAcA,MAAM,WAAWC,EAAuCC,EAAoD,CAC1G,IAAMC,EAAsB,CAC1B,qBAAsBD,EACtB,eAAgB,KAAK,SAAS,eAC9B,WAAY,OACZ,UAAAD,EACA,WAAY,KAAK,SAAS,WAC1B,IAAK,OAAO,SAAS,KACrB,UAAW,OAAO,UAAU,SAC9B,EAEA,OAAO,KAAK,SAAS,SAAS,KAAK,wBAAyB,CAC1D,KAAAE,CACF,CAAC,CACH,CACF","names":["createClient","CONVERSATION_ID","deleteConversationId","getConversationId","setConversationId","conversationId","SESSION_ID","getSessionId","setSessionId","sessionId","getItemWithExpiry","key","itemString","item","getItemWithExpiry_default","setItemWithExpiry","key","value","ttl","item","setItemWithExpiry_default","USER_ID","TTL","getUserId","getItemWithExpiry_default","setUserId","userId","setItemWithExpiry_default","authMiddleware","accessToken","request","auth_default","version","Client","customerId","fetch","conversationUrl","frontendUrl","headers","version","createClient","getConversationId","getSessionId","getUserId","pageviewId","sessionId","userId","data","setSessionId","setUserId","endpont","auth_default","deleteConversationId","context","conversationContext","conversationIdMessage","openingMessage","conversationId","setConversationId","userMessage","debugMessages","message","eventName","properties","body"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@15gifts/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist"
|
|
6
6
|
],
|
|
@@ -23,8 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"openapi-typescript": "^7.4.4",
|
|
26
|
-
"tsup": "^8.3.5"
|
|
27
|
-
"eslint-config-custom": "^0.1.0"
|
|
26
|
+
"tsup": "^8.3.5"
|
|
28
27
|
},
|
|
29
28
|
"sideEffects": false,
|
|
30
29
|
"prettier": "prettier-config-custom"
|