@commercengine/pos 0.1.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -34
- package/dist/index.d.ts +3779 -129
- package/dist/index.js +1510 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -395,6 +395,15 @@ var BaseAPIClient = class {
|
|
|
395
395
|
getDefaultHeaders() {
|
|
396
396
|
return this.config.defaultHeaders;
|
|
397
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Add middleware to the client
|
|
400
|
+
* This allows SDK extensions to add custom middleware like authentication
|
|
401
|
+
*
|
|
402
|
+
* @param middleware - Middleware to add to the client
|
|
403
|
+
*/
|
|
404
|
+
use(middleware) {
|
|
405
|
+
this.client.use(middleware);
|
|
406
|
+
}
|
|
398
407
|
};
|
|
399
408
|
/**
|
|
400
409
|
* Generic URL utility functions for any SDK
|
|
@@ -982,6 +991,20 @@ var PosAPIClient = class PosAPIClient extends BaseAPIClient {
|
|
|
982
991
|
console.warn("Failed to initialize tokens in storage:", error);
|
|
983
992
|
}
|
|
984
993
|
}
|
|
994
|
+
/**
|
|
995
|
+
* Get client typed for storefront POS operations (paths schema)
|
|
996
|
+
* This provides proper typing for storefront POS endpoints
|
|
997
|
+
*/
|
|
998
|
+
get storefrontClient() {
|
|
999
|
+
return this.client;
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Get client typed for admin POS operations (AdminPaths schema)
|
|
1003
|
+
* This provides proper typing for admin POS endpoints
|
|
1004
|
+
*/
|
|
1005
|
+
get adminClient() {
|
|
1006
|
+
return this.client;
|
|
1007
|
+
}
|
|
985
1008
|
};
|
|
986
1009
|
|
|
987
1010
|
//#endregion
|
|
@@ -992,41 +1015,97 @@ var PosAPIClient = class PosAPIClient extends BaseAPIClient {
|
|
|
992
1015
|
*/
|
|
993
1016
|
var PosClient = class extends PosAPIClient {
|
|
994
1017
|
/**
|
|
995
|
-
* Login with email address
|
|
996
|
-
* @param body - Login credentials containing
|
|
1018
|
+
* Login with email address
|
|
1019
|
+
* @param body - Login credentials containing location ID and email
|
|
997
1020
|
* @returns Promise with OTP token and action
|
|
1021
|
+
* @example
|
|
1022
|
+
* ```typescript
|
|
1023
|
+
* const { data, error } = await pos.loginWithEmail({
|
|
1024
|
+
* location_id: "pos-location-123",
|
|
1025
|
+
* email: "staff@example.com"
|
|
1026
|
+
* });
|
|
1027
|
+
*
|
|
1028
|
+
* if (error) {
|
|
1029
|
+
* console.error("Login failed:", error.message);
|
|
1030
|
+
* } else {
|
|
1031
|
+
* console.log("OTP sent:", data.otp_token);
|
|
1032
|
+
* console.log("Action:", data.otp_action);
|
|
1033
|
+
* // Use the otp_token to verify OTP
|
|
1034
|
+
* }
|
|
1035
|
+
* ```
|
|
998
1036
|
*/
|
|
999
1037
|
async loginWithEmail(body) {
|
|
1000
1038
|
return this.executeRequest(() => this.client.POST("/pos/auth/login/email", { body }));
|
|
1001
1039
|
}
|
|
1002
1040
|
/**
|
|
1003
|
-
* Login with phone number
|
|
1004
|
-
* @param body - Login credentials containing
|
|
1041
|
+
* Login with phone number
|
|
1042
|
+
* @param body - Login credentials containing location ID and phone
|
|
1005
1043
|
* @returns Promise with OTP token and action
|
|
1044
|
+
* @example
|
|
1045
|
+
* ```typescript
|
|
1046
|
+
* const { data, error } = await pos.loginWithPhone({
|
|
1047
|
+
* location_id: "pos-location-123",
|
|
1048
|
+
* phone: "234567890",
|
|
1049
|
+
* country_code: "+91" // default is +91
|
|
1050
|
+
* });
|
|
1051
|
+
*
|
|
1052
|
+
* if (error) {
|
|
1053
|
+
* console.error("Login failed:", error.message);
|
|
1054
|
+
* } else {
|
|
1055
|
+
* console.log("OTP sent:", data.otp_token);
|
|
1056
|
+
* console.log("Action:", data.otp_action);
|
|
1057
|
+
* // Use the otp_token to verify OTP
|
|
1058
|
+
* }
|
|
1059
|
+
* ```
|
|
1006
1060
|
*/
|
|
1007
1061
|
async loginWithPhone(body) {
|
|
1008
1062
|
return this.executeRequest(() => this.client.POST("/pos/auth/login/phone", { body }));
|
|
1009
1063
|
}
|
|
1010
1064
|
/**
|
|
1011
|
-
* Login with WhatsApp
|
|
1012
|
-
* @param body - Login credentials containing
|
|
1065
|
+
* Login with WhatsApp
|
|
1066
|
+
* @param body - Login credentials containing location ID and phone
|
|
1013
1067
|
* @returns Promise with OTP token and action
|
|
1068
|
+
* @example
|
|
1069
|
+
* ```typescript
|
|
1070
|
+
* const { data, error } = await pos.loginWithWhatsapp({
|
|
1071
|
+
* location_id: "pos-location-123",
|
|
1072
|
+
* phone: "234567890",
|
|
1073
|
+
* country_code: "+91" // default is +91
|
|
1074
|
+
* });
|
|
1075
|
+
*
|
|
1076
|
+
* if (error) {
|
|
1077
|
+
* console.error("WhatsApp login failed:", error.message);
|
|
1078
|
+
* } else {
|
|
1079
|
+
* console.log("WhatsApp OTP sent:", data.otp_token);
|
|
1080
|
+
* console.log("Action:", data.otp_action);
|
|
1081
|
+
* // Use the otp_token to verify OTP
|
|
1082
|
+
* }
|
|
1083
|
+
* ```
|
|
1014
1084
|
*/
|
|
1015
1085
|
async loginWithWhatsapp(body) {
|
|
1016
1086
|
return this.executeRequest(() => this.client.POST("/pos/auth/login/whatsapp", { body }));
|
|
1017
1087
|
}
|
|
1018
1088
|
/**
|
|
1019
|
-
*
|
|
1020
|
-
* @param body - Pairing code received via phone/email
|
|
1021
|
-
* @returns Promise with device information
|
|
1022
|
-
*/
|
|
1023
|
-
async pairDevice(body) {
|
|
1024
|
-
return this.executeRequest(() => this.client.POST("/pos/auth/pair-device", { body }));
|
|
1025
|
-
}
|
|
1026
|
-
/**
|
|
1027
|
-
* Verify OTP for POS login
|
|
1089
|
+
* Verify OTP
|
|
1028
1090
|
* @param body - OTP verification data
|
|
1029
1091
|
* @returns Promise with user info and tokens
|
|
1092
|
+
* @example
|
|
1093
|
+
* ```typescript
|
|
1094
|
+
* const { data, error } = await pos.verifyOtp({
|
|
1095
|
+
* otp_token: "otp-token-from-login",
|
|
1096
|
+
* otp: "123456",
|
|
1097
|
+
* otp_action: "login"
|
|
1098
|
+
* });
|
|
1099
|
+
*
|
|
1100
|
+
* if (error) {
|
|
1101
|
+
* console.error("OTP verification failed:", error.message);
|
|
1102
|
+
* } else {
|
|
1103
|
+
* console.log("Login successful:", data.user);
|
|
1104
|
+
* console.log("Access token:", data.access_token);
|
|
1105
|
+
* console.log("Refresh token:", data.refresh_token);
|
|
1106
|
+
* // Tokens are automatically stored by the SDK
|
|
1107
|
+
* }
|
|
1108
|
+
* ```
|
|
1030
1109
|
*/
|
|
1031
1110
|
async verifyOtp(body) {
|
|
1032
1111
|
return this.executeRequest(() => this.client.POST("/pos/auth/verify-otp", { body }));
|
|
@@ -1035,21 +1114,169 @@ var PosClient = class extends PosAPIClient {
|
|
|
1035
1114
|
* Refresh POS access token
|
|
1036
1115
|
* @param body - Refresh token data
|
|
1037
1116
|
* @returns Promise with new tokens
|
|
1117
|
+
* @example
|
|
1118
|
+
* ```typescript
|
|
1119
|
+
* const { data, error } = await pos.refreshAccessToken({
|
|
1120
|
+
* refresh_token: "refresh-token-here"
|
|
1121
|
+
* });
|
|
1122
|
+
*
|
|
1123
|
+
* if (error) {
|
|
1124
|
+
* console.error("Token refresh failed:", error.message);
|
|
1125
|
+
* } else {
|
|
1126
|
+
* console.log("New access token:", data.access_token);
|
|
1127
|
+
* console.log("New refresh token:", data.refresh_token);
|
|
1128
|
+
* // New tokens are automatically stored by the SDK
|
|
1129
|
+
* }
|
|
1130
|
+
* ```
|
|
1038
1131
|
*/
|
|
1039
1132
|
async refreshAccessToken(body) {
|
|
1040
1133
|
return this.executeRequest(() => this.client.POST("/pos/auth/refresh-token", { body }));
|
|
1041
1134
|
}
|
|
1042
1135
|
/**
|
|
1043
|
-
* Logout
|
|
1136
|
+
* Logout
|
|
1044
1137
|
* @returns Promise with logout confirmation
|
|
1138
|
+
* @example
|
|
1139
|
+
* ```typescript
|
|
1140
|
+
* const { data, error } = await pos.logout();
|
|
1141
|
+
*
|
|
1142
|
+
* if (error) {
|
|
1143
|
+
* console.error("Logout failed:", error.message);
|
|
1144
|
+
* } else {
|
|
1145
|
+
* console.log("Logout message:", data.message);
|
|
1146
|
+
* console.log("Success:", data.success);
|
|
1147
|
+
* // Tokens are automatically cleared by the SDK
|
|
1148
|
+
* }
|
|
1149
|
+
* ```
|
|
1045
1150
|
*/
|
|
1046
1151
|
async logout() {
|
|
1047
1152
|
return this.executeRequest(() => this.client.POST("/pos/auth/logout"));
|
|
1048
1153
|
}
|
|
1049
1154
|
/**
|
|
1155
|
+
* List store locations
|
|
1156
|
+
* @returns Promise with list of locations
|
|
1157
|
+
* @example
|
|
1158
|
+
* ```typescript
|
|
1159
|
+
* const { data, error } = await pos.listLocations();
|
|
1160
|
+
* if (error) {
|
|
1161
|
+
* console.error("Failed to list locations:", error.message);
|
|
1162
|
+
* } else {
|
|
1163
|
+
* console.log("Locations:", data.locations);
|
|
1164
|
+
* }
|
|
1165
|
+
* ```
|
|
1166
|
+
*/
|
|
1167
|
+
async listLocations() {
|
|
1168
|
+
return this.executeRequest(() => this.client.GET("/pos/locations"));
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* List devices
|
|
1172
|
+
* @returns Promise with list of devices
|
|
1173
|
+
* @example
|
|
1174
|
+
* ```typescript
|
|
1175
|
+
* const { data, error } = await pos.listDevices();
|
|
1176
|
+
* if (error) {
|
|
1177
|
+
* console.error("Failed to list devices:", error.message);
|
|
1178
|
+
* } else {
|
|
1179
|
+
* console.log("Devices:", data.devices);
|
|
1180
|
+
* }
|
|
1181
|
+
* ```
|
|
1182
|
+
*/
|
|
1183
|
+
async listDevices() {
|
|
1184
|
+
return this.executeRequest(() => this.client.GET("/pos/devices"));
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* Pair POS device with pairing code
|
|
1188
|
+
* @param body - Pairing code received via phone/email
|
|
1189
|
+
* @returns Promise with device information
|
|
1190
|
+
* @example
|
|
1191
|
+
* ```typescript
|
|
1192
|
+
* const { data, error } = await pos.pairDevice({
|
|
1193
|
+
* pairing_code: "ABC123"
|
|
1194
|
+
* });
|
|
1195
|
+
*
|
|
1196
|
+
* if (error) {
|
|
1197
|
+
* console.error("Device pairing failed:", error.message);
|
|
1198
|
+
* } else {
|
|
1199
|
+
* console.log("Device paired:", data.device.id);
|
|
1200
|
+
* console.log("Device name:", data.device.name);
|
|
1201
|
+
* // Store device_id for future use
|
|
1202
|
+
* }
|
|
1203
|
+
* ```
|
|
1204
|
+
*/
|
|
1205
|
+
async pairDevice(body) {
|
|
1206
|
+
return this.executeRequest(() => this.client.POST("/pos/auth/pair-device", { body }));
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Unclaim POS device - Unlinks a device from the user session
|
|
1210
|
+
* @param pathParams - Device ID
|
|
1211
|
+
* @returns Promise with unclaim confirmation
|
|
1212
|
+
* @example
|
|
1213
|
+
* ```typescript
|
|
1214
|
+
* const { data, error } = await pos.unclaimDevice({
|
|
1215
|
+
* id: "01H9DEVICE12345ABCDE"
|
|
1216
|
+
* });
|
|
1217
|
+
*
|
|
1218
|
+
* if (error) {
|
|
1219
|
+
* console.error("Failed to unclaim device:", error.message);
|
|
1220
|
+
* } else {
|
|
1221
|
+
* console.log("Device unclaimed:", data.message);
|
|
1222
|
+
* }
|
|
1223
|
+
* ```
|
|
1224
|
+
*/
|
|
1225
|
+
async unclaimDevice(pathParams) {
|
|
1226
|
+
return this.executeRequest(() => this.client.POST("/pos/devices/{id}/unclaim", { params: { path: pathParams } }));
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* Claim POS device - Links a device to the user session
|
|
1230
|
+
* @param pathParams - Device ID
|
|
1231
|
+
* @returns Promise with claim confirmation
|
|
1232
|
+
* @example
|
|
1233
|
+
* ```typescript
|
|
1234
|
+
* const { data, error } = await pos.claimDevice({
|
|
1235
|
+
* id: "01H9DEVICE12345ABCDE"
|
|
1236
|
+
* });
|
|
1237
|
+
*
|
|
1238
|
+
* if (error) {
|
|
1239
|
+
* console.error("Failed to claim device:", error.message);
|
|
1240
|
+
* } else {
|
|
1241
|
+
* console.log("Device claimed:", data.message);
|
|
1242
|
+
* }
|
|
1243
|
+
* ```
|
|
1244
|
+
*/
|
|
1245
|
+
async claimDevice(pathParams) {
|
|
1246
|
+
return this.executeRequest(() => this.client.POST("/pos/devices/{id}/claim", { params: { path: pathParams } }));
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1050
1249
|
* Create a new cart
|
|
1051
1250
|
* @param body - Cart creation data with items
|
|
1052
1251
|
* @returns Promise with created cart
|
|
1252
|
+
* @example
|
|
1253
|
+
* ```typescript
|
|
1254
|
+
* const { data, error } = await pos.createCart({
|
|
1255
|
+
* items: [
|
|
1256
|
+
* {
|
|
1257
|
+
* product_id: "01H9XYZ12345ABCDE",
|
|
1258
|
+
* variant_id: null,
|
|
1259
|
+
* quantity: 2
|
|
1260
|
+
* },
|
|
1261
|
+
* {
|
|
1262
|
+
* product_id: "01H9ABC67890FGHIJ",
|
|
1263
|
+
* variant_id: "01H9XYZ67890KLMNO",
|
|
1264
|
+
* quantity: 1
|
|
1265
|
+
* }
|
|
1266
|
+
* ],
|
|
1267
|
+
* metadata: {
|
|
1268
|
+
* "source": "pos-terminal-1",
|
|
1269
|
+
* "staff_id": "staff-123"
|
|
1270
|
+
* }
|
|
1271
|
+
* });
|
|
1272
|
+
*
|
|
1273
|
+
* if (error) {
|
|
1274
|
+
* console.error("Failed to create cart:", error.message);
|
|
1275
|
+
* } else {
|
|
1276
|
+
* console.log("Cart created:", data.cart.id);
|
|
1277
|
+
* console.log("Cart total:", data.cart.grand_total);
|
|
1278
|
+
* }
|
|
1279
|
+
* ```
|
|
1053
1280
|
*/
|
|
1054
1281
|
async createCart(body) {
|
|
1055
1282
|
return this.executeRequest(() => this.client.POST("/pos/carts", { body }));
|
|
@@ -1058,6 +1285,20 @@ var PosClient = class extends PosAPIClient {
|
|
|
1058
1285
|
* Get cart details
|
|
1059
1286
|
* @param pathParams - Cart ID
|
|
1060
1287
|
* @returns Promise with cart details
|
|
1288
|
+
* @example
|
|
1289
|
+
* ```typescript
|
|
1290
|
+
* const { data, error } = await pos.getCart({
|
|
1291
|
+
* id: "01H9CART12345ABCDE"
|
|
1292
|
+
* });
|
|
1293
|
+
*
|
|
1294
|
+
* if (error) {
|
|
1295
|
+
* console.error("Failed to get cart:", error.message);
|
|
1296
|
+
* } else {
|
|
1297
|
+
* const cart = data.cart;
|
|
1298
|
+
* console.log("Cart total:", cart.grand_total);
|
|
1299
|
+
* console.log("Items count:", cart.cart_items.length);
|
|
1300
|
+
* }
|
|
1301
|
+
* ```
|
|
1061
1302
|
*/
|
|
1062
1303
|
async getCart(pathParams) {
|
|
1063
1304
|
return this.executeRequest(() => this.client.GET("/pos/carts/{id}", { params: { path: pathParams } }));
|
|
@@ -1066,6 +1307,18 @@ var PosClient = class extends PosAPIClient {
|
|
|
1066
1307
|
* Delete cart (remove all items)
|
|
1067
1308
|
* @param pathParams - Cart ID
|
|
1068
1309
|
* @returns Promise with deletion confirmation
|
|
1310
|
+
* @example
|
|
1311
|
+
* ```typescript
|
|
1312
|
+
* const { data, error } = await pos.deleteCart({
|
|
1313
|
+
* id: "01H9CART12345ABCDE"
|
|
1314
|
+
* });
|
|
1315
|
+
*
|
|
1316
|
+
* if (error) {
|
|
1317
|
+
* console.error("Failed to delete cart:", error.message);
|
|
1318
|
+
* } else {
|
|
1319
|
+
* console.log("Cart deleted:", data.message);
|
|
1320
|
+
* }
|
|
1321
|
+
* ```
|
|
1069
1322
|
*/
|
|
1070
1323
|
async deleteCart(pathParams) {
|
|
1071
1324
|
return this.executeRequest(() => this.client.DELETE("/pos/carts/{id}", { params: { path: pathParams } }));
|
|
@@ -1075,6 +1328,34 @@ var PosClient = class extends PosAPIClient {
|
|
|
1075
1328
|
* @param pathParams - Cart ID
|
|
1076
1329
|
* @param body - Item update data
|
|
1077
1330
|
* @returns Promise with updated cart
|
|
1331
|
+
* @example
|
|
1332
|
+
* ```typescript
|
|
1333
|
+
* // Add item to cart
|
|
1334
|
+
* const { data, error } = await pos.updateCart(
|
|
1335
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1336
|
+
* {
|
|
1337
|
+
* product_id: "01H9XYZ12345ABCDE",
|
|
1338
|
+
* variant_id: null,
|
|
1339
|
+
* quantity: 3
|
|
1340
|
+
* }
|
|
1341
|
+
* );
|
|
1342
|
+
*
|
|
1343
|
+
* if (error) {
|
|
1344
|
+
* console.error("Failed to update cart:", error.message);
|
|
1345
|
+
* } else {
|
|
1346
|
+
* console.log("Cart updated:", data.cart.cart_items.length);
|
|
1347
|
+
* }
|
|
1348
|
+
*
|
|
1349
|
+
* // Remove item from cart (set quantity to 0)
|
|
1350
|
+
* const { data: removeData, error: removeError } = await pos.updateCart(
|
|
1351
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1352
|
+
* {
|
|
1353
|
+
* product_id: "01H9XYZ12345ABCDE",
|
|
1354
|
+
* variant_id: null,
|
|
1355
|
+
* quantity: 0
|
|
1356
|
+
* }
|
|
1357
|
+
* );
|
|
1358
|
+
* ```
|
|
1078
1359
|
*/
|
|
1079
1360
|
async updateCart(pathParams, body) {
|
|
1080
1361
|
return this.executeRequest(() => this.client.POST("/pos/carts/{id}/items", {
|
|
@@ -1087,6 +1368,62 @@ var PosClient = class extends PosAPIClient {
|
|
|
1087
1368
|
* @param pathParams - Cart ID
|
|
1088
1369
|
* @param body - Address data (registered user IDs or guest addresses)
|
|
1089
1370
|
* @returns Promise with updated cart
|
|
1371
|
+
* @example
|
|
1372
|
+
* ```typescript
|
|
1373
|
+
* // For registered users with saved addresses
|
|
1374
|
+
* const { data, error } = await pos.createCartAddress(
|
|
1375
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1376
|
+
* {
|
|
1377
|
+
* billing_address_id: "01H9ADDR12345BILL",
|
|
1378
|
+
* shipping_address_id: "01H9ADDR12345SHIP"
|
|
1379
|
+
* }
|
|
1380
|
+
* );
|
|
1381
|
+
*
|
|
1382
|
+
* if (error) {
|
|
1383
|
+
* console.error("Failed to update cart address:", error.message);
|
|
1384
|
+
* } else {
|
|
1385
|
+
* console.log("Addresses updated:", data.message);
|
|
1386
|
+
* }
|
|
1387
|
+
*
|
|
1388
|
+
* // For guest checkout with new addresses
|
|
1389
|
+
* const { data: guestData, error: guestError } = await pos.createCartAddress(
|
|
1390
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1391
|
+
* {
|
|
1392
|
+
* billing_address: {
|
|
1393
|
+
* first_name: "John",
|
|
1394
|
+
* last_name: "Doe",
|
|
1395
|
+
* email: "john@example.com",
|
|
1396
|
+
* phone: "9876543210",
|
|
1397
|
+
* country_code: "+91",
|
|
1398
|
+
* address_line1: "123 Main Street",
|
|
1399
|
+
* address_line2: "Apt 4B",
|
|
1400
|
+
* city: "Mumbai",
|
|
1401
|
+
* state: "Maharashtra",
|
|
1402
|
+
* pincode: "400001",
|
|
1403
|
+
* country: "India",
|
|
1404
|
+
* landmark: "Near Station",
|
|
1405
|
+
* tax_identification_number: null,
|
|
1406
|
+
* business_name: null
|
|
1407
|
+
* },
|
|
1408
|
+
* shipping_address: {
|
|
1409
|
+
* first_name: "John",
|
|
1410
|
+
* last_name: "Doe",
|
|
1411
|
+
* email: "john@example.com",
|
|
1412
|
+
* phone: "9876543210",
|
|
1413
|
+
* country_code: "+91",
|
|
1414
|
+
* address_line1: "456 Oak Avenue",
|
|
1415
|
+
* address_line2: null,
|
|
1416
|
+
* city: "Pune",
|
|
1417
|
+
* state: "Maharashtra",
|
|
1418
|
+
* pincode: "411001",
|
|
1419
|
+
* country: "India",
|
|
1420
|
+
* landmark: "Near Mall",
|
|
1421
|
+
* tax_identification_number: null,
|
|
1422
|
+
* business_name: null
|
|
1423
|
+
* }
|
|
1424
|
+
* }
|
|
1425
|
+
* );
|
|
1426
|
+
* ```
|
|
1090
1427
|
*/
|
|
1091
1428
|
async createCartAddress(pathParams, body) {
|
|
1092
1429
|
return this.executeRequest(() => this.client.POST("/pos/carts/{id}/address", {
|
|
@@ -1098,6 +1435,26 @@ var PosClient = class extends PosAPIClient {
|
|
|
1098
1435
|
* List all available coupons
|
|
1099
1436
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1100
1437
|
* @returns Promise with available coupons
|
|
1438
|
+
* @example
|
|
1439
|
+
* ```typescript
|
|
1440
|
+
* // Get all available coupons
|
|
1441
|
+
* const { data, error } = await pos.listCoupons();
|
|
1442
|
+
*
|
|
1443
|
+
* if (error) {
|
|
1444
|
+
* console.error("Failed to get available coupons:", error.message);
|
|
1445
|
+
* } else {
|
|
1446
|
+
* const coupons = data.coupons || [];
|
|
1447
|
+
* console.log("Available coupons:", coupons.length);
|
|
1448
|
+
* coupons.forEach(coupon => {
|
|
1449
|
+
* console.log("Coupon:", coupon.code, "Discount:", coupon.discount_amount);
|
|
1450
|
+
* });
|
|
1451
|
+
* }
|
|
1452
|
+
*
|
|
1453
|
+
* // Override customer group ID for this specific request
|
|
1454
|
+
* const { data: overrideData, error: overrideError } = await pos.listCoupons({
|
|
1455
|
+
* "x-customer-group-id": "01H9GROUP12345ABC" // Override default SDK config
|
|
1456
|
+
* });
|
|
1457
|
+
* ```
|
|
1101
1458
|
*/
|
|
1102
1459
|
async listCoupons(headers) {
|
|
1103
1460
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1107,6 +1464,26 @@ var PosClient = class extends PosAPIClient {
|
|
|
1107
1464
|
* List all available promotions
|
|
1108
1465
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1109
1466
|
* @returns Promise with available promotions
|
|
1467
|
+
* @example
|
|
1468
|
+
* ```typescript
|
|
1469
|
+
* // Get all available promotions
|
|
1470
|
+
* const { data, error } = await pos.listPromotions();
|
|
1471
|
+
*
|
|
1472
|
+
* if (error) {
|
|
1473
|
+
* console.error("Failed to get available promotions:", error.message);
|
|
1474
|
+
* } else {
|
|
1475
|
+
* const promotions = data.promotions || [];
|
|
1476
|
+
* console.log("Available promotions:", promotions.length);
|
|
1477
|
+
* promotions.forEach(promotion => {
|
|
1478
|
+
* console.log("Promotion:", promotion.name, "Type:", promotion.promotion_type);
|
|
1479
|
+
* });
|
|
1480
|
+
* }
|
|
1481
|
+
*
|
|
1482
|
+
* // Override customer group ID for this specific request
|
|
1483
|
+
* const { data: overrideData, error: overrideError } = await pos.listPromotions({
|
|
1484
|
+
* "x-customer-group-id": "01H9GROUP12345ABC" // Override default SDK config
|
|
1485
|
+
* });
|
|
1486
|
+
* ```
|
|
1110
1487
|
*/
|
|
1111
1488
|
async listPromotions(headers) {
|
|
1112
1489
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1117,6 +1494,20 @@ var PosClient = class extends PosAPIClient {
|
|
|
1117
1494
|
* @param pathParams - Cart ID
|
|
1118
1495
|
* @param body - Coupon code
|
|
1119
1496
|
* @returns Promise with updated cart
|
|
1497
|
+
* @example
|
|
1498
|
+
* ```typescript
|
|
1499
|
+
* const { data, error } = await pos.applyCoupon(
|
|
1500
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1501
|
+
* { coupon_code: "FLAT100OFF" }
|
|
1502
|
+
* );
|
|
1503
|
+
*
|
|
1504
|
+
* if (error) {
|
|
1505
|
+
* console.error("Failed to apply coupon:", error.message);
|
|
1506
|
+
* } else {
|
|
1507
|
+
* console.log("Coupon applied, new total:", data.cart.grand_total);
|
|
1508
|
+
* console.log("Discount amount:", data.cart.coupon_discount_amount);
|
|
1509
|
+
* }
|
|
1510
|
+
* ```
|
|
1120
1511
|
*/
|
|
1121
1512
|
async applyCoupon(pathParams, body) {
|
|
1122
1513
|
return this.executeRequest(() => this.client.POST("/pos/carts/{id}/coupon", {
|
|
@@ -1128,6 +1519,18 @@ var PosClient = class extends PosAPIClient {
|
|
|
1128
1519
|
* Remove coupon from cart
|
|
1129
1520
|
* @param pathParams - Cart ID
|
|
1130
1521
|
* @returns Promise with updated cart
|
|
1522
|
+
* @example
|
|
1523
|
+
* ```typescript
|
|
1524
|
+
* const { data, error } = await pos.removeCoupon({
|
|
1525
|
+
* id: "01H9CART12345ABCDE"
|
|
1526
|
+
* });
|
|
1527
|
+
*
|
|
1528
|
+
* if (error) {
|
|
1529
|
+
* console.error("Failed to remove coupon:", error.message);
|
|
1530
|
+
* } else {
|
|
1531
|
+
* console.log("Coupon removed, new total:", data.cart.grand_total);
|
|
1532
|
+
* }
|
|
1533
|
+
* ```
|
|
1131
1534
|
*/
|
|
1132
1535
|
async removeCoupon(pathParams) {
|
|
1133
1536
|
return this.executeRequest(() => this.client.DELETE("/pos/carts/{id}/coupon", { params: { path: pathParams } }));
|
|
@@ -1136,6 +1539,29 @@ var PosClient = class extends PosAPIClient {
|
|
|
1136
1539
|
* Evaluate applicable/inapplicable coupons for cart
|
|
1137
1540
|
* @param pathParams - Cart ID
|
|
1138
1541
|
* @returns Promise with coupon evaluation results
|
|
1542
|
+
* @example
|
|
1543
|
+
* ```typescript
|
|
1544
|
+
* const { data, error } = await pos.evaluateCoupons({
|
|
1545
|
+
* id: "01H9CART12345ABCDE"
|
|
1546
|
+
* });
|
|
1547
|
+
*
|
|
1548
|
+
* if (error) {
|
|
1549
|
+
* console.error("Failed to evaluate coupons:", error.message);
|
|
1550
|
+
* } else {
|
|
1551
|
+
* const applicable = data.applicable_coupons || [];
|
|
1552
|
+
* const inapplicable = data.inapplicable_coupons || [];
|
|
1553
|
+
*
|
|
1554
|
+
* console.log("Applicable coupons:", applicable.length);
|
|
1555
|
+
* applicable.forEach(coupon => {
|
|
1556
|
+
* console.log(`- ${coupon.code}: Save $${coupon.estimated_discount}`);
|
|
1557
|
+
* });
|
|
1558
|
+
*
|
|
1559
|
+
* console.log("Inapplicable coupons:", inapplicable.length);
|
|
1560
|
+
* inapplicable.forEach(coupon => {
|
|
1561
|
+
* console.log(`- ${coupon.code}: ${coupon.reason}`);
|
|
1562
|
+
* });
|
|
1563
|
+
* }
|
|
1564
|
+
* ```
|
|
1139
1565
|
*/
|
|
1140
1566
|
async evaluateCoupons(pathParams) {
|
|
1141
1567
|
return this.executeRequest(() => this.client.GET("/pos/carts/{id}/evaluate-coupons", { params: { path: pathParams } }));
|
|
@@ -1144,6 +1570,29 @@ var PosClient = class extends PosAPIClient {
|
|
|
1144
1570
|
* Evaluate applicable/inapplicable promotions for cart
|
|
1145
1571
|
* @param pathParams - Cart ID
|
|
1146
1572
|
* @returns Promise with promotion evaluation results
|
|
1573
|
+
* @example
|
|
1574
|
+
* ```typescript
|
|
1575
|
+
* const { data, error } = await pos.evaluatePromotions({
|
|
1576
|
+
* id: "01H9CART12345ABCDE"
|
|
1577
|
+
* });
|
|
1578
|
+
*
|
|
1579
|
+
* if (error) {
|
|
1580
|
+
* console.error("Failed to evaluate promotions:", error.message);
|
|
1581
|
+
* } else {
|
|
1582
|
+
* const applicable = data.applicable_promotions || [];
|
|
1583
|
+
* const inapplicable = data.inapplicable_promotions || [];
|
|
1584
|
+
*
|
|
1585
|
+
* console.log("Applicable promotions:", applicable.length);
|
|
1586
|
+
* applicable.forEach(promo => {
|
|
1587
|
+
* console.log(`- ${promo.name}: ${promo.savings_message}`);
|
|
1588
|
+
* });
|
|
1589
|
+
*
|
|
1590
|
+
* console.log("Inapplicable promotions:", inapplicable.length);
|
|
1591
|
+
* inapplicable.forEach(promo => {
|
|
1592
|
+
* console.log(`- ${promo.name}: ${promo.reason}`);
|
|
1593
|
+
* });
|
|
1594
|
+
* }
|
|
1595
|
+
* ```
|
|
1147
1596
|
*/
|
|
1148
1597
|
async evaluatePromotions(pathParams) {
|
|
1149
1598
|
return this.executeRequest(() => this.client.GET("/pos/carts/{id}/evaluate-promotions", { params: { path: pathParams } }));
|
|
@@ -1153,6 +1602,20 @@ var PosClient = class extends PosAPIClient {
|
|
|
1153
1602
|
* @param pathParams - Cart ID
|
|
1154
1603
|
* @param body - Credit balance amount to use
|
|
1155
1604
|
* @returns Promise with updated cart
|
|
1605
|
+
* @example
|
|
1606
|
+
* ```typescript
|
|
1607
|
+
* const { data, error } = await pos.redeemCreditBalance(
|
|
1608
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1609
|
+
* { credit_balance_used: 250.00 }
|
|
1610
|
+
* );
|
|
1611
|
+
*
|
|
1612
|
+
* if (error) {
|
|
1613
|
+
* console.error("Failed to redeem credit balance:", error.message);
|
|
1614
|
+
* } else {
|
|
1615
|
+
* console.log("Credit applied, new total:", data.cart.grand_total);
|
|
1616
|
+
* console.log("Credit used:", data.cart.credit_balance_used);
|
|
1617
|
+
* }
|
|
1618
|
+
* ```
|
|
1156
1619
|
*/
|
|
1157
1620
|
async redeemCreditBalance(pathParams, body) {
|
|
1158
1621
|
return this.executeRequest(() => this.client.POST("/pos/carts/{id}/credit-balance", {
|
|
@@ -1164,6 +1627,18 @@ var PosClient = class extends PosAPIClient {
|
|
|
1164
1627
|
* Remove credit balance from cart
|
|
1165
1628
|
* @param pathParams - Cart ID
|
|
1166
1629
|
* @returns Promise with updated cart
|
|
1630
|
+
* @example
|
|
1631
|
+
* ```typescript
|
|
1632
|
+
* const { data, error } = await pos.removeCreditBalance({
|
|
1633
|
+
* id: "01H9CART12345ABCDE"
|
|
1634
|
+
* });
|
|
1635
|
+
*
|
|
1636
|
+
* if (error) {
|
|
1637
|
+
* console.error("Failed to remove credit balance:", error.message);
|
|
1638
|
+
* } else {
|
|
1639
|
+
* console.log("Credit balance removed, new total:", data.cart.grand_total);
|
|
1640
|
+
* }
|
|
1641
|
+
* ```
|
|
1167
1642
|
*/
|
|
1168
1643
|
async removeCreditBalance(pathParams) {
|
|
1169
1644
|
return this.executeRequest(() => this.client.DELETE("/pos/carts/{id}/credit-balance", { params: { path: pathParams } }));
|
|
@@ -1173,6 +1648,20 @@ var PosClient = class extends PosAPIClient {
|
|
|
1173
1648
|
* @param pathParams - Cart ID
|
|
1174
1649
|
* @param body - Loyalty points to redeem
|
|
1175
1650
|
* @returns Promise with updated cart
|
|
1651
|
+
* @example
|
|
1652
|
+
* ```typescript
|
|
1653
|
+
* const { data, error } = await pos.redeemLoyaltyPoints(
|
|
1654
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1655
|
+
* { loyalty_point_redeemed: 500 }
|
|
1656
|
+
* );
|
|
1657
|
+
*
|
|
1658
|
+
* if (error) {
|
|
1659
|
+
* console.error("Failed to redeem loyalty points:", error.message);
|
|
1660
|
+
* } else {
|
|
1661
|
+
* console.log("Points redeemed, new total:", data.cart.grand_total);
|
|
1662
|
+
* console.log("Points redeemed:", data.cart.loyalty_points_redeemed);
|
|
1663
|
+
* }
|
|
1664
|
+
* ```
|
|
1176
1665
|
*/
|
|
1177
1666
|
async redeemLoyaltyPoints(pathParams, body) {
|
|
1178
1667
|
return this.executeRequest(() => this.client.POST("/pos/carts/{id}/loyalty-points", {
|
|
@@ -1184,6 +1673,18 @@ var PosClient = class extends PosAPIClient {
|
|
|
1184
1673
|
* Remove loyalty points from cart
|
|
1185
1674
|
* @param pathParams - Cart ID
|
|
1186
1675
|
* @returns Promise with updated cart
|
|
1676
|
+
* @example
|
|
1677
|
+
* ```typescript
|
|
1678
|
+
* const { data, error } = await pos.removeLoyaltyPoints({
|
|
1679
|
+
* id: "01H9CART12345ABCDE"
|
|
1680
|
+
* });
|
|
1681
|
+
*
|
|
1682
|
+
* if (error) {
|
|
1683
|
+
* console.error("Failed to remove loyalty points:", error.message);
|
|
1684
|
+
* } else {
|
|
1685
|
+
* console.log("Loyalty points removed, new total:", data.cart.grand_total);
|
|
1686
|
+
* }
|
|
1687
|
+
* ```
|
|
1187
1688
|
*/
|
|
1188
1689
|
async removeLoyaltyPoints(pathParams) {
|
|
1189
1690
|
return this.executeRequest(() => this.client.DELETE("/pos/carts/{id}/loyalty-points", { params: { path: pathParams } }));
|
|
@@ -1193,6 +1694,23 @@ var PosClient = class extends PosAPIClient {
|
|
|
1193
1694
|
* @param pathParams - Cart ID
|
|
1194
1695
|
* @param body - Fulfillment preference data
|
|
1195
1696
|
* @returns Promise with confirmation
|
|
1697
|
+
* @example
|
|
1698
|
+
* ```typescript
|
|
1699
|
+
* const { data, error } = await pos.updateFulfillmentPreference(
|
|
1700
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1701
|
+
* {
|
|
1702
|
+
* fulfillment_type: "delivery",
|
|
1703
|
+
* delivery_address_id: "01H9ADDR12345ABCDE"
|
|
1704
|
+
* }
|
|
1705
|
+
* );
|
|
1706
|
+
*
|
|
1707
|
+
* if (error) {
|
|
1708
|
+
* console.error("Failed to update fulfillment preference:", error.message);
|
|
1709
|
+
* } else {
|
|
1710
|
+
* console.log("Fulfillment preference updated:", data.message);
|
|
1711
|
+
* console.log("Success:", data.success);
|
|
1712
|
+
* }
|
|
1713
|
+
* ```
|
|
1196
1714
|
*/
|
|
1197
1715
|
async updateFulfillmentPreference(pathParams, body) {
|
|
1198
1716
|
return this.executeRequest(() => this.client.POST("/pos/carts/{id}/fulfillment-preference", {
|
|
@@ -1204,6 +1722,28 @@ var PosClient = class extends PosAPIClient {
|
|
|
1204
1722
|
* Get fulfillment options for cart
|
|
1205
1723
|
* @param body - Cart data for fulfillment calculation
|
|
1206
1724
|
* @returns Promise with fulfillment options
|
|
1725
|
+
* @example
|
|
1726
|
+
* ```typescript
|
|
1727
|
+
* const { data, error } = await pos.getFulfillmentOptions({
|
|
1728
|
+
* cart_id: "01H9CART12345ABCDE",
|
|
1729
|
+
* delivery_address: {
|
|
1730
|
+
* street: "123 Main St",
|
|
1731
|
+
* city: "New York",
|
|
1732
|
+
* state: "NY",
|
|
1733
|
+
* zip_code: "10001",
|
|
1734
|
+
* country: "US"
|
|
1735
|
+
* }
|
|
1736
|
+
* });
|
|
1737
|
+
*
|
|
1738
|
+
* if (error) {
|
|
1739
|
+
* console.error("Failed to get fulfillment options:", error.message);
|
|
1740
|
+
* } else {
|
|
1741
|
+
* console.log("Available fulfillment options:", data.options.length);
|
|
1742
|
+
* data.options.forEach(option => {
|
|
1743
|
+
* console.log(`${option.type}: ${option.name} - $${option.cost}`);
|
|
1744
|
+
* });
|
|
1745
|
+
* }
|
|
1746
|
+
* ```
|
|
1207
1747
|
*/
|
|
1208
1748
|
async getFulfillmentOptions(body) {
|
|
1209
1749
|
return this.executeRequest(() => this.client.POST("/pos/fulfillment-options", { body }));
|
|
@@ -1213,6 +1753,24 @@ var PosClient = class extends PosAPIClient {
|
|
|
1213
1753
|
* @param pathParams - Cart ID
|
|
1214
1754
|
* @param body - Customer update data
|
|
1215
1755
|
* @returns Promise with updated cart
|
|
1756
|
+
* @example
|
|
1757
|
+
* ```typescript
|
|
1758
|
+
* const { data, error } = await pos.updateCartCustomer(
|
|
1759
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1760
|
+
* {
|
|
1761
|
+
* customer_id: "01H9CUST12345ABCDE",
|
|
1762
|
+
* customer_group_id: "01H9GROUP12345ABCDE"
|
|
1763
|
+
* }
|
|
1764
|
+
* );
|
|
1765
|
+
*
|
|
1766
|
+
* if (error) {
|
|
1767
|
+
* console.error("Failed to update cart customer:", error.message);
|
|
1768
|
+
* } else {
|
|
1769
|
+
* console.log("Cart customer updated:", data.cart.id);
|
|
1770
|
+
* console.log("Customer ID:", data.cart.customer_id);
|
|
1771
|
+
* console.log("Customer group:", data.cart.customer_group_id);
|
|
1772
|
+
* }
|
|
1773
|
+
* ```
|
|
1216
1774
|
*/
|
|
1217
1775
|
async updateCartCustomer(pathParams, body) {
|
|
1218
1776
|
return this.executeRequest(() => this.client.POST("/pos/carts/{id}/update-customer", {
|
|
@@ -1224,14 +1782,85 @@ var PosClient = class extends PosAPIClient {
|
|
|
1224
1782
|
* Create order from cart
|
|
1225
1783
|
* @param body - Order creation data
|
|
1226
1784
|
* @returns Promise with created order
|
|
1785
|
+
* @example
|
|
1786
|
+
* ```typescript
|
|
1787
|
+
* const { data, error } = await pos.createOrder({
|
|
1788
|
+
* cart_id: "01H9CART12345ABCDE"
|
|
1789
|
+
* });
|
|
1790
|
+
*
|
|
1791
|
+
* if (error) {
|
|
1792
|
+
* console.error("Failed to create order:", error.message);
|
|
1793
|
+
* } else {
|
|
1794
|
+
* console.log("Order created:", data.order.id);
|
|
1795
|
+
* console.log("Payment required:", data.payment_required);
|
|
1796
|
+
* }
|
|
1797
|
+
* ```
|
|
1227
1798
|
*/
|
|
1228
1799
|
async createOrder(body) {
|
|
1229
|
-
return this.executeRequest(() => this.
|
|
1800
|
+
return this.executeRequest(() => this.storefrontClient.POST("/pos/orders", { body }));
|
|
1801
|
+
}
|
|
1802
|
+
/**
|
|
1803
|
+
* List payment options
|
|
1804
|
+
* @returns Promise with list of payment options
|
|
1805
|
+
* @example
|
|
1806
|
+
* ```typescript
|
|
1807
|
+
* const { data, error } = await pos.listPaymentOptions();
|
|
1808
|
+
*
|
|
1809
|
+
* if (error) {
|
|
1810
|
+
* console.error("Failed to list payment options:", error.message);
|
|
1811
|
+
* } else {
|
|
1812
|
+
* console.log("Payment options:", data.payment_options);
|
|
1813
|
+
* }
|
|
1814
|
+
* ```
|
|
1815
|
+
*/
|
|
1816
|
+
async listPaymentOptions() {
|
|
1817
|
+
return this.executeRequest(() => this.client.GET("/pos/payments/payment-options"));
|
|
1818
|
+
}
|
|
1819
|
+
/**
|
|
1820
|
+
* Get payment status
|
|
1821
|
+
* @param pathParams - Order number
|
|
1822
|
+
* @returns Promise with payment status
|
|
1823
|
+
* @example
|
|
1824
|
+
* ```typescript
|
|
1825
|
+
* const { data, error } = await pos.getPaymentStatus({ order_number: "1234567890" });
|
|
1826
|
+
*
|
|
1827
|
+
* if (error) {
|
|
1828
|
+
* console.error("Failed to get payment status:", error.message);
|
|
1829
|
+
* } else {
|
|
1830
|
+
* console.log("Payment status:", data.status);
|
|
1831
|
+
* console.log("Amount paid:", data.amount_paid);
|
|
1832
|
+
* console.log("Amount unpaid:", data.amount_unpaid);
|
|
1833
|
+
* console.log("Retry available:", data.is_retry_available);
|
|
1834
|
+
* }
|
|
1835
|
+
* ```
|
|
1836
|
+
*/
|
|
1837
|
+
async getPaymentStatus(pathParams) {
|
|
1838
|
+
return this.executeRequest(() => this.client.GET("/pos/orders/{order_number}/payment-status", { params: { path: pathParams } }));
|
|
1230
1839
|
}
|
|
1231
1840
|
/**
|
|
1232
1841
|
* List all categories
|
|
1233
1842
|
* @param query - Optional query parameters for filtering categories
|
|
1234
1843
|
* @returns Promise with list of categories
|
|
1844
|
+
* @example
|
|
1845
|
+
* ```typescript
|
|
1846
|
+
* // Basic category listing
|
|
1847
|
+
* const { data, error } = await pos.listCategories();
|
|
1848
|
+
*
|
|
1849
|
+
* if (error) {
|
|
1850
|
+
* console.error("Failed to list categories:", error.message);
|
|
1851
|
+
* } else {
|
|
1852
|
+
* console.log("Categories found:", data.categories?.length || 0);
|
|
1853
|
+
* data.categories?.forEach(category => {
|
|
1854
|
+
* console.log(`Category: ${category.name} - ${category.description}`);
|
|
1855
|
+
* });
|
|
1856
|
+
* }
|
|
1857
|
+
*
|
|
1858
|
+
* // With pagination
|
|
1859
|
+
* const { data: catData, error: catError } = await pos.listCategories({
|
|
1860
|
+
* page: 1,
|
|
1861
|
+
* limit: 10
|
|
1862
|
+
* });
|
|
1863
|
+
* ```
|
|
1235
1864
|
*/
|
|
1236
1865
|
async listCategories(query) {
|
|
1237
1866
|
return this.executeRequest(() => this.client.GET("/pos/catalog/categories", { params: { query } }));
|
|
@@ -1241,6 +1870,42 @@ var PosClient = class extends PosAPIClient {
|
|
|
1241
1870
|
* @param query - Optional query parameters for filtering products
|
|
1242
1871
|
* @param headers - Optional header parameters
|
|
1243
1872
|
* @returns Promise with list of products
|
|
1873
|
+
* @example
|
|
1874
|
+
* ```typescript
|
|
1875
|
+
* // Basic product listing
|
|
1876
|
+
* const { data, error } = await pos.listProducts();
|
|
1877
|
+
*
|
|
1878
|
+
* if (error) {
|
|
1879
|
+
* console.error("Failed to list products:", error.message);
|
|
1880
|
+
* } else {
|
|
1881
|
+
* console.log("Products found:", data.products?.length || 0);
|
|
1882
|
+
* console.log("Pagination:", data.pagination);
|
|
1883
|
+
* data.products?.forEach(product => {
|
|
1884
|
+
* console.log(`Product: ${product.name} - $${product.price}`);
|
|
1885
|
+
* });
|
|
1886
|
+
* }
|
|
1887
|
+
*
|
|
1888
|
+
* // With filtering and pagination
|
|
1889
|
+
* const { data: filteredData, error: filteredError } = await pos.listProducts({
|
|
1890
|
+
* page: 1,
|
|
1891
|
+
* limit: 20,
|
|
1892
|
+
* sort_by: JSON.stringify({ "created_at": "desc" }),
|
|
1893
|
+
* category_slug: ["electronics", "smartphones"]
|
|
1894
|
+
* });
|
|
1895
|
+
*
|
|
1896
|
+
* // Override customer group ID for this specific request
|
|
1897
|
+
* const { data: overrideData, error: overrideError } = await pos.listProducts(
|
|
1898
|
+
* {
|
|
1899
|
+
* page: 1,
|
|
1900
|
+
* limit: 20,
|
|
1901
|
+
* sort_by: JSON.stringify({ "created_at": "desc" }),
|
|
1902
|
+
* category_slug: ["electronics", "smartphones"]
|
|
1903
|
+
* },
|
|
1904
|
+
* {
|
|
1905
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1906
|
+
* }
|
|
1907
|
+
* );
|
|
1908
|
+
* ```
|
|
1244
1909
|
*/
|
|
1245
1910
|
async listProducts(query, headers) {
|
|
1246
1911
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1254,6 +1919,43 @@ var PosClient = class extends PosAPIClient {
|
|
|
1254
1919
|
* @param query - Query parameters with product IDs for cross-sell recommendations
|
|
1255
1920
|
* @param headers - Optional header parameters
|
|
1256
1921
|
* @returns Promise with cross-sell products
|
|
1922
|
+
* @example
|
|
1923
|
+
* ```typescript
|
|
1924
|
+
* // Basic usage - get cross-sell products for cart items
|
|
1925
|
+
* const { data, error } = await pos.listCrosssellProducts({
|
|
1926
|
+
* product_ids: ["prod_01H9XYZ12345ABCDE", "prod_01H9ABC67890FGHIJ"]
|
|
1927
|
+
* });
|
|
1928
|
+
*
|
|
1929
|
+
* // Advanced usage with pagination and custom sorting
|
|
1930
|
+
* const { data, error } = await pos.listCrosssellProducts({
|
|
1931
|
+
* product_ids: ["prod_01H9XYZ12345ABCDE"],
|
|
1932
|
+
* page: 1,
|
|
1933
|
+
* limit: 10,
|
|
1934
|
+
* sort_by: '{"price":"asc"}'
|
|
1935
|
+
* });
|
|
1936
|
+
*
|
|
1937
|
+
* // Override customer group ID for this specific request
|
|
1938
|
+
* const { data, error } = await pos.listCrosssellProducts(
|
|
1939
|
+
* {
|
|
1940
|
+
* product_ids: ["prod_01H9XYZ12345ABCDE"],
|
|
1941
|
+
* page: 1,
|
|
1942
|
+
* limit: 10
|
|
1943
|
+
* },
|
|
1944
|
+
* {
|
|
1945
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1946
|
+
* }
|
|
1947
|
+
* );
|
|
1948
|
+
*
|
|
1949
|
+
* if (error) {
|
|
1950
|
+
* console.error("Failed to get cross-sell products:", error.message);
|
|
1951
|
+
* } else {
|
|
1952
|
+
* console.log("Cross-sell products found:", data.products.length);
|
|
1953
|
+
* console.log("Pagination:", data.pagination);
|
|
1954
|
+
* data.products.forEach(product => {
|
|
1955
|
+
* console.log(`Product: ${product.name} - ${product.price}`);
|
|
1956
|
+
* });
|
|
1957
|
+
* }
|
|
1958
|
+
* ```
|
|
1257
1959
|
*/
|
|
1258
1960
|
async listCrosssellProducts(query, headers) {
|
|
1259
1961
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1267,6 +1969,41 @@ var PosClient = class extends PosAPIClient {
|
|
|
1267
1969
|
* @param body - Search criteria and parameters
|
|
1268
1970
|
* @param headers - Optional header parameters
|
|
1269
1971
|
* @returns Promise with search results
|
|
1972
|
+
* @example
|
|
1973
|
+
* ```typescript
|
|
1974
|
+
* const { data, error } = await pos.searchProducts({
|
|
1975
|
+
* query: "smartphone",
|
|
1976
|
+
* filters: {
|
|
1977
|
+
* category: ["electronics", "mobile"],
|
|
1978
|
+
* price_range: { min: 100, max: 1000 },
|
|
1979
|
+
* brand: ["Apple", "Samsung"] // facet names depend on product configuration
|
|
1980
|
+
* },
|
|
1981
|
+
* page: 1,
|
|
1982
|
+
* limit: 20
|
|
1983
|
+
* });
|
|
1984
|
+
*
|
|
1985
|
+
* if (error) {
|
|
1986
|
+
* console.error("Failed to search products:", error.message);
|
|
1987
|
+
* } else {
|
|
1988
|
+
* console.log("Search results:", data.skus?.length || 0, "products found");
|
|
1989
|
+
* console.log("Facet distribution:", data.facet_distribution);
|
|
1990
|
+
* console.log("Price range:", data.facet_stats.price_range);
|
|
1991
|
+
* data.skus?.forEach(sku => {
|
|
1992
|
+
* console.log(`Found: ${sku.name} - ${sku.price}`);
|
|
1993
|
+
* });
|
|
1994
|
+
* }
|
|
1995
|
+
*
|
|
1996
|
+
* // Override customer group ID for this specific request
|
|
1997
|
+
* const { data: overrideData, error: overrideError } = await pos.searchProducts(
|
|
1998
|
+
* {
|
|
1999
|
+
* query: "laptop",
|
|
2000
|
+
* filters: { category: ["computers"] }
|
|
2001
|
+
* },
|
|
2002
|
+
* {
|
|
2003
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
2004
|
+
* }
|
|
2005
|
+
* );
|
|
2006
|
+
* ```
|
|
1270
2007
|
*/
|
|
1271
2008
|
async searchProducts(body, headers) {
|
|
1272
2009
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1280,6 +2017,43 @@ var PosClient = class extends PosAPIClient {
|
|
|
1280
2017
|
* @param query - Query parameters with product ID for similarity recommendations
|
|
1281
2018
|
* @param headers - Optional header parameters
|
|
1282
2019
|
* @returns Promise with similar products
|
|
2020
|
+
* @example
|
|
2021
|
+
* ```typescript
|
|
2022
|
+
* // Basic usage - get similar products for a specific product
|
|
2023
|
+
* const { data, error } = await pos.listSimilarProducts({
|
|
2024
|
+
* product_id: "prod_01H9XYZ12345ABCDE"
|
|
2025
|
+
* });
|
|
2026
|
+
*
|
|
2027
|
+
* // Advanced usage with pagination and custom sorting
|
|
2028
|
+
* const { data, error } = await pos.listSimilarProducts({
|
|
2029
|
+
* product_id: "prod_01H9XYZ12345ABCDE",
|
|
2030
|
+
* page: 1,
|
|
2031
|
+
* limit: 20,
|
|
2032
|
+
* sort_by: '{"relevance":"desc"}'
|
|
2033
|
+
* });
|
|
2034
|
+
*
|
|
2035
|
+
* // Override customer group ID for this specific request
|
|
2036
|
+
* const { data, error } = await pos.listSimilarProducts(
|
|
2037
|
+
* {
|
|
2038
|
+
* product_id: "prod_01H9XYZ12345ABCDE",
|
|
2039
|
+
* page: 1,
|
|
2040
|
+
* limit: 20
|
|
2041
|
+
* },
|
|
2042
|
+
* {
|
|
2043
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
2044
|
+
* }
|
|
2045
|
+
* );
|
|
2046
|
+
*
|
|
2047
|
+
* if (error) {
|
|
2048
|
+
* console.error("Failed to get similar products:", error.message);
|
|
2049
|
+
* } else {
|
|
2050
|
+
* console.log("Similar products found:", data.products.length);
|
|
2051
|
+
* console.log("Pagination:", data.pagination);
|
|
2052
|
+
* data.products.forEach(product => {
|
|
2053
|
+
* console.log(`Similar: ${product.name} - ${product.price}`);
|
|
2054
|
+
* });
|
|
2055
|
+
* }
|
|
2056
|
+
* ```
|
|
1283
2057
|
*/
|
|
1284
2058
|
async listSimilarProducts(query, headers) {
|
|
1285
2059
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1293,6 +2067,43 @@ var PosClient = class extends PosAPIClient {
|
|
|
1293
2067
|
* @param query - Query parameters with product IDs for up-sell recommendations
|
|
1294
2068
|
* @param headers - Optional header parameters
|
|
1295
2069
|
* @returns Promise with up-sell products
|
|
2070
|
+
* @example
|
|
2071
|
+
* ```typescript
|
|
2072
|
+
* // Basic usage - get up-sell products for cart items
|
|
2073
|
+
* const { data, error } = await pos.listUpsellProducts({
|
|
2074
|
+
* product_ids: ["prod_01H9XYZ12345ABCDE"]
|
|
2075
|
+
* });
|
|
2076
|
+
*
|
|
2077
|
+
* // Advanced usage with pagination and custom sorting
|
|
2078
|
+
* const { data, error } = await pos.listUpsellProducts({
|
|
2079
|
+
* product_ids: ["prod_01H9XYZ12345ABCDE"],
|
|
2080
|
+
* page: 1,
|
|
2081
|
+
* limit: 15,
|
|
2082
|
+
* sort_by: '{"relevance":"desc"}'
|
|
2083
|
+
* });
|
|
2084
|
+
*
|
|
2085
|
+
* // Override customer group ID for this specific request
|
|
2086
|
+
* const { data, error } = await pos.listUpsellProducts(
|
|
2087
|
+
* {
|
|
2088
|
+
* product_ids: ["prod_01H9XYZ12345ABCDE"],
|
|
2089
|
+
* page: 1,
|
|
2090
|
+
* limit: 15
|
|
2091
|
+
* },
|
|
2092
|
+
* {
|
|
2093
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
2094
|
+
* }
|
|
2095
|
+
* );
|
|
2096
|
+
*
|
|
2097
|
+
* if (error) {
|
|
2098
|
+
* console.error("Failed to get up-sell products:", error.message);
|
|
2099
|
+
* } else {
|
|
2100
|
+
* console.log("Up-sell products found:", data.products.length);
|
|
2101
|
+
* console.log("Pagination:", data.pagination);
|
|
2102
|
+
* data.products.forEach(product => {
|
|
2103
|
+
* console.log(`Up-sell: ${product.name} - ${product.price}`);
|
|
2104
|
+
* });
|
|
2105
|
+
* }
|
|
2106
|
+
* ```
|
|
1296
2107
|
*/
|
|
1297
2108
|
async listUpsellProducts(query, headers) {
|
|
1298
2109
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1306,6 +2117,34 @@ var PosClient = class extends PosAPIClient {
|
|
|
1306
2117
|
* @param pathParams - Product ID or slug
|
|
1307
2118
|
* @param headers - Optional header parameters
|
|
1308
2119
|
* @returns Promise with product details
|
|
2120
|
+
* @example
|
|
2121
|
+
* ```typescript
|
|
2122
|
+
* // Get product by ID
|
|
2123
|
+
* const { data, error } = await pos.getProductDetail(
|
|
2124
|
+
* { product_id_or_slug: "prod_123" }
|
|
2125
|
+
* );
|
|
2126
|
+
*
|
|
2127
|
+
* if (error) {
|
|
2128
|
+
* console.error("Failed to get product details:", error.message);
|
|
2129
|
+
* } else {
|
|
2130
|
+
* console.log("Product:", data.product.name);
|
|
2131
|
+
* console.log("Price:", data.product.price);
|
|
2132
|
+
* console.log("Description:", data.product.description);
|
|
2133
|
+
* }
|
|
2134
|
+
*
|
|
2135
|
+
* // Get product by slug
|
|
2136
|
+
* const { data: slugData, error: slugError } = await pos.getProductDetail({
|
|
2137
|
+
* product_id_or_slug: "detox-candy"
|
|
2138
|
+
* });
|
|
2139
|
+
*
|
|
2140
|
+
* // Override customer group ID for this specific request
|
|
2141
|
+
* const { data: overrideData, error: overrideError } = await pos.getProductDetail(
|
|
2142
|
+
* { product_id_or_slug: "detox-candy" },
|
|
2143
|
+
* {
|
|
2144
|
+
* "x-customer-group-id": "premium_customers" // Override default SDK config
|
|
2145
|
+
* }
|
|
2146
|
+
* );
|
|
2147
|
+
* ```
|
|
1309
2148
|
*/
|
|
1310
2149
|
async getProductDetail(pathParams, headers) {
|
|
1311
2150
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1319,6 +2158,31 @@ var PosClient = class extends PosAPIClient {
|
|
|
1319
2158
|
* @param pathParams - Product ID
|
|
1320
2159
|
* @param query - Optional query parameters for filtering reviews
|
|
1321
2160
|
* @returns Promise with product reviews
|
|
2161
|
+
* @example
|
|
2162
|
+
* ```typescript
|
|
2163
|
+
* const { data, error } = await pos.listProductReviews(
|
|
2164
|
+
* { product_id: "prod_123" }
|
|
2165
|
+
* );
|
|
2166
|
+
*
|
|
2167
|
+
* if (error) {
|
|
2168
|
+
* console.error("Failed to list product reviews:", error.message);
|
|
2169
|
+
* } else {
|
|
2170
|
+
* console.log("Reviews found:", data.reviews?.length || 0);
|
|
2171
|
+
* data.reviews?.forEach(review => {
|
|
2172
|
+
* console.log(`Review by ${review.customer_name}: ${review.rating}/5`);
|
|
2173
|
+
* console.log("Comment:", review.comment);
|
|
2174
|
+
* });
|
|
2175
|
+
* }
|
|
2176
|
+
*
|
|
2177
|
+
* // With pagination
|
|
2178
|
+
* const { data: reviewData, error: reviewError } = await pos.listProductReviews(
|
|
2179
|
+
* { product_id: "prod_123" },
|
|
2180
|
+
* {
|
|
2181
|
+
* page: 1,
|
|
2182
|
+
* limit: 5
|
|
2183
|
+
* }
|
|
2184
|
+
* );
|
|
2185
|
+
* ```
|
|
1322
2186
|
*/
|
|
1323
2187
|
async listProductReviews(pathParams, query) {
|
|
1324
2188
|
return this.executeRequest(() => this.client.GET("/pos/catalog/products/{product_id}/reviews", { params: {
|
|
@@ -1331,6 +2195,29 @@ var PosClient = class extends PosAPIClient {
|
|
|
1331
2195
|
* @param pathParams - Product ID
|
|
1332
2196
|
* @param headers - Optional header parameters
|
|
1333
2197
|
* @returns Promise with product variants
|
|
2198
|
+
* @example
|
|
2199
|
+
* ```typescript
|
|
2200
|
+
* const { data, error } = await pos.listProductVariants(
|
|
2201
|
+
* { product_id: "prod_123" }
|
|
2202
|
+
* );
|
|
2203
|
+
*
|
|
2204
|
+
* if (error) {
|
|
2205
|
+
* console.error("Failed to list product variants:", error.message);
|
|
2206
|
+
* } else {
|
|
2207
|
+
* console.log("Variants found:", data.variants?.length || 0);
|
|
2208
|
+
* data.variants?.forEach(variant => {
|
|
2209
|
+
* console.log(`Variant: ${variant.name} - SKU: ${variant.sku} - Price: ${variant.price}`);
|
|
2210
|
+
* });
|
|
2211
|
+
* }
|
|
2212
|
+
*
|
|
2213
|
+
* // Override customer group ID for this specific request
|
|
2214
|
+
* const { data: overrideData, error: overrideError } = await pos.listProductVariants(
|
|
2215
|
+
* { product_id: "prod_123" },
|
|
2216
|
+
* {
|
|
2217
|
+
* "x-customer-group-id": "wholesale_customers" // Override default SDK config
|
|
2218
|
+
* }
|
|
2219
|
+
* );
|
|
2220
|
+
* ```
|
|
1334
2221
|
*/
|
|
1335
2222
|
async listProductVariants(pathParams, headers) {
|
|
1336
2223
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1344,6 +2231,35 @@ var PosClient = class extends PosAPIClient {
|
|
|
1344
2231
|
* @param pathParams - Product ID and variant ID
|
|
1345
2232
|
* @param headers - Optional header parameters
|
|
1346
2233
|
* @returns Promise with variant details
|
|
2234
|
+
* @example
|
|
2235
|
+
* ```typescript
|
|
2236
|
+
* const { data, error } = await pos.getVariantDetail(
|
|
2237
|
+
* {
|
|
2238
|
+
* product_id: "prod_123",
|
|
2239
|
+
* variant_id: "var_456"
|
|
2240
|
+
* }
|
|
2241
|
+
* );
|
|
2242
|
+
*
|
|
2243
|
+
* if (error) {
|
|
2244
|
+
* console.error("Failed to get variant details:", error.message);
|
|
2245
|
+
* } else {
|
|
2246
|
+
* console.log("Variant:", data.variant.name);
|
|
2247
|
+
* console.log("SKU:", data.variant.sku);
|
|
2248
|
+
* console.log("Price:", data.variant.price);
|
|
2249
|
+
* console.log("Stock:", data.variant.stock);
|
|
2250
|
+
* }
|
|
2251
|
+
*
|
|
2252
|
+
* // Override customer group ID for this specific request
|
|
2253
|
+
* const { data: overrideData, error: overrideError } = await pos.getVariantDetail(
|
|
2254
|
+
* {
|
|
2255
|
+
* product_id: "prod_123",
|
|
2256
|
+
* variant_id: "var_456"
|
|
2257
|
+
* },
|
|
2258
|
+
* {
|
|
2259
|
+
* "x-customer-group-id": "wholesale_customers" // Override default SDK config
|
|
2260
|
+
* }
|
|
2261
|
+
* );
|
|
2262
|
+
* ```
|
|
1347
2263
|
*/
|
|
1348
2264
|
async getVariantDetail(pathParams, headers) {
|
|
1349
2265
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1357,6 +2273,38 @@ var PosClient = class extends PosAPIClient {
|
|
|
1357
2273
|
* @param query - Optional query parameters for filtering SKUs
|
|
1358
2274
|
* @param headers - Optional header parameters
|
|
1359
2275
|
* @returns Promise with list of SKUs
|
|
2276
|
+
* @example
|
|
2277
|
+
* ```typescript
|
|
2278
|
+
* // Basic SKU listing
|
|
2279
|
+
* const { data, error } = await pos.listSkus();
|
|
2280
|
+
*
|
|
2281
|
+
* if (error) {
|
|
2282
|
+
* console.error("Failed to list SKUs:", error.message);
|
|
2283
|
+
* } else {
|
|
2284
|
+
* console.log("SKUs found:", data.skus?.length || 0);
|
|
2285
|
+
* console.log("Pagination:", data.pagination);
|
|
2286
|
+
* data.skus?.forEach(sku => {
|
|
2287
|
+
* console.log(`SKU: ${sku.sku} - Price: ${sku.price}`);
|
|
2288
|
+
* });
|
|
2289
|
+
* }
|
|
2290
|
+
*
|
|
2291
|
+
* // With pagination
|
|
2292
|
+
* const { data: skuData, error: skuError } = await pos.listSkus({
|
|
2293
|
+
* page: 1,
|
|
2294
|
+
* limit: 50
|
|
2295
|
+
* });
|
|
2296
|
+
*
|
|
2297
|
+
* // Override customer group ID for this specific request
|
|
2298
|
+
* const { data: overrideData, error: overrideError } = await pos.listSkus(
|
|
2299
|
+
* {
|
|
2300
|
+
* page: 1,
|
|
2301
|
+
* limit: 50
|
|
2302
|
+
* },
|
|
2303
|
+
* {
|
|
2304
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
2305
|
+
* }
|
|
2306
|
+
* );
|
|
2307
|
+
* ```
|
|
1360
2308
|
*/
|
|
1361
2309
|
async listSkus(query, headers) {
|
|
1362
2310
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1365,6 +2313,551 @@ var PosClient = class extends PosAPIClient {
|
|
|
1365
2313
|
header: mergedHeaders
|
|
1366
2314
|
} }));
|
|
1367
2315
|
}
|
|
2316
|
+
/**
|
|
2317
|
+
* List all inventories (Admin)
|
|
2318
|
+
* @param query - Optional query parameters for filtering inventories
|
|
2319
|
+
* @returns Promise with list of inventories
|
|
2320
|
+
* @example
|
|
2321
|
+
* ```typescript
|
|
2322
|
+
* // Basic inventory listing
|
|
2323
|
+
* const { data, error } = await pos.listInventories();
|
|
2324
|
+
*
|
|
2325
|
+
* if (error) {
|
|
2326
|
+
* console.error("Failed to list inventories:", error.message);
|
|
2327
|
+
* } else {
|
|
2328
|
+
* console.log("Inventories found:", data.content?.inventories?.length || 0);
|
|
2329
|
+
* data.content?.inventories?.forEach(inventory => {
|
|
2330
|
+
* console.log(`Product: ${inventory.product_name} - Stock: ${inventory.stock_quantity}`);
|
|
2331
|
+
* });
|
|
2332
|
+
* }
|
|
2333
|
+
*
|
|
2334
|
+
* // With pagination and filters
|
|
2335
|
+
* const { data: filteredData, error: filteredError } = await pos.listInventories({
|
|
2336
|
+
* page: 1,
|
|
2337
|
+
* limit: 20,
|
|
2338
|
+
* sort_by: JSON.stringify({ "stock_quantity": "desc" }),
|
|
2339
|
+
* filters: JSON.stringify({ "product_name": "smartphone" })
|
|
2340
|
+
* });
|
|
2341
|
+
* ```
|
|
2342
|
+
*/
|
|
2343
|
+
async listInventories(query) {
|
|
2344
|
+
return this.executeRequest(() => this.client.GET("/pos/catalog/inventories", { params: { query } }));
|
|
2345
|
+
}
|
|
2346
|
+
/**
|
|
2347
|
+
* List all inventory activities (Admin)
|
|
2348
|
+
* @param query - Optional query parameters for filtering inventory activities
|
|
2349
|
+
* @returns Promise with list of inventory activities
|
|
2350
|
+
* @example
|
|
2351
|
+
* ```typescript
|
|
2352
|
+
* // Basic inventory activities listing
|
|
2353
|
+
* const { data, error } = await pos.listInventoryActivities();
|
|
2354
|
+
*
|
|
2355
|
+
* if (error) {
|
|
2356
|
+
* console.error("Failed to list inventory activities:", error.message);
|
|
2357
|
+
* } else {
|
|
2358
|
+
* console.log("Activities found:", data.content?.activities?.length || 0);
|
|
2359
|
+
* data.content?.activities?.forEach(activity => {
|
|
2360
|
+
* console.log(`Activity: ${activity.activity_type} - Product: ${activity.product_name} - Quantity: ${activity.quantity}`);
|
|
2361
|
+
* });
|
|
2362
|
+
* }
|
|
2363
|
+
*
|
|
2364
|
+
* // With pagination and filters
|
|
2365
|
+
* const { data: filteredData, error: filteredError } = await pos.listInventoryActivities({
|
|
2366
|
+
* page: 1,
|
|
2367
|
+
* limit: 50,
|
|
2368
|
+
* sort_by: JSON.stringify({ "created_at": "desc" }),
|
|
2369
|
+
* filters: JSON.stringify({ "activity_type": "add" })
|
|
2370
|
+
* });
|
|
2371
|
+
* ```
|
|
2372
|
+
*/
|
|
2373
|
+
async listInventoryActivities(query) {
|
|
2374
|
+
return this.executeRequest(() => this.client.GET("/pos/catalog/inventories/activites", { params: { query } }));
|
|
2375
|
+
}
|
|
2376
|
+
/**
|
|
2377
|
+
* Get inventory detail (Admin)
|
|
2378
|
+
* @param query - Query parameters with product/variant information
|
|
2379
|
+
* @returns Promise with inventory details
|
|
2380
|
+
* @example
|
|
2381
|
+
* ```typescript
|
|
2382
|
+
* // Get inventory detail for a product
|
|
2383
|
+
* const { data, error } = await pos.getInventoryDetail({
|
|
2384
|
+
* product_id: "01H9XYZ12345ABCDE"
|
|
2385
|
+
* });
|
|
2386
|
+
*
|
|
2387
|
+
* if (error) {
|
|
2388
|
+
* console.error("Failed to get inventory detail:", error.message);
|
|
2389
|
+
* } else {
|
|
2390
|
+
* const inventory = data.content?.inventory;
|
|
2391
|
+
* console.log(`Product: ${inventory?.product_name}`);
|
|
2392
|
+
* console.log(`Stock: ${inventory?.stock_quantity}`);
|
|
2393
|
+
* console.log(`Warehouse details:`, inventory?.details);
|
|
2394
|
+
* }
|
|
2395
|
+
*
|
|
2396
|
+
* // Get inventory detail for a product variant
|
|
2397
|
+
* const { data: variantData, error: variantError } = await pos.getInventoryDetail({
|
|
2398
|
+
* product_id: "01H9XYZ12345ABCDE",
|
|
2399
|
+
* variant_id: "01H9ABC67890FGHIJ"
|
|
2400
|
+
* });
|
|
2401
|
+
*
|
|
2402
|
+
* // Get inventory detail for a specific lot/batch
|
|
2403
|
+
* const { data: batchData, error: batchError } = await pos.getInventoryDetail({
|
|
2404
|
+
* product_id: "01H9XYZ12345ABCDE",
|
|
2405
|
+
* lot_batch: "BATCH001"
|
|
2406
|
+
* });
|
|
2407
|
+
* ```
|
|
2408
|
+
*/
|
|
2409
|
+
async getInventoryDetail(query) {
|
|
2410
|
+
return this.executeRequest(() => this.client.GET("/pos/catalog/inventories/detail", { params: { query } }));
|
|
2411
|
+
}
|
|
2412
|
+
/**
|
|
2413
|
+
* List all customers (Admin)
|
|
2414
|
+
* @param query - Optional query parameters for filtering customers
|
|
2415
|
+
* @returns Promise with list of customers
|
|
2416
|
+
* @example
|
|
2417
|
+
* ```typescript
|
|
2418
|
+
* // Basic customer listing
|
|
2419
|
+
* const { data, error } = await pos.getCustomers();
|
|
2420
|
+
*
|
|
2421
|
+
* if (error) {
|
|
2422
|
+
* console.error("Failed to list customers:", error.message);
|
|
2423
|
+
* } else {
|
|
2424
|
+
* console.log("Customers found:", data.content?.customers?.length || 0);
|
|
2425
|
+
* console.log("Pagination:", data.content?.pagination);
|
|
2426
|
+
* data.content?.customers?.forEach(customer => {
|
|
2427
|
+
* console.log(`Customer: ${customer.full_name} - Email: ${customer.email}`);
|
|
2428
|
+
* });
|
|
2429
|
+
* }
|
|
2430
|
+
*
|
|
2431
|
+
* // With search and pagination
|
|
2432
|
+
* const { data: searchData, error: searchError } = await pos.getCustomers({
|
|
2433
|
+
* page: 1,
|
|
2434
|
+
* limit: 20,
|
|
2435
|
+
* search: "john@example.com",
|
|
2436
|
+
* sort_by: JSON.stringify({ "created_at": "desc" })
|
|
2437
|
+
* });
|
|
2438
|
+
* ```
|
|
2439
|
+
*/
|
|
2440
|
+
async getCustomers(query) {
|
|
2441
|
+
return this.executeRequest(() => this.client.GET("/pos/customers", { params: { query } }));
|
|
2442
|
+
}
|
|
2443
|
+
/**
|
|
2444
|
+
* Get customer details (Admin)
|
|
2445
|
+
* @param pathParams - Customer ID
|
|
2446
|
+
* @returns Promise with customer details
|
|
2447
|
+
* @example
|
|
2448
|
+
* ```typescript
|
|
2449
|
+
* const { data, error } = await pos.getCustomer({
|
|
2450
|
+
* id: "01H9CUST12345ABCDE"
|
|
2451
|
+
* });
|
|
2452
|
+
*
|
|
2453
|
+
* if (error) {
|
|
2454
|
+
* console.error("Failed to get customer:", error.message);
|
|
2455
|
+
* } else {
|
|
2456
|
+
* const customer = data.content?.customer;
|
|
2457
|
+
* console.log(`Customer: ${customer?.full_name}`);
|
|
2458
|
+
* console.log(`Email: ${customer?.email}`);
|
|
2459
|
+
* console.log(`Phone: ${customer?.phone}`);
|
|
2460
|
+
* console.log(`Loyalty points: ${customer?.loyalty?.points_balance}`);
|
|
2461
|
+
* console.log(`Total spent: ${customer?.loyalty?.lifetime_spent}`);
|
|
2462
|
+
* }
|
|
2463
|
+
* ```
|
|
2464
|
+
*/
|
|
2465
|
+
async getCustomer(pathParams) {
|
|
2466
|
+
return this.executeRequest(() => this.client.GET("/pos/customers/{id}", { params: { path: pathParams } }));
|
|
2467
|
+
}
|
|
2468
|
+
/**
|
|
2469
|
+
* List all orders (Admin)
|
|
2470
|
+
* @param query - Optional query parameters for filtering orders
|
|
2471
|
+
* @returns Promise with list of orders
|
|
2472
|
+
* @example
|
|
2473
|
+
* ```typescript
|
|
2474
|
+
* // Basic order listing
|
|
2475
|
+
* const { data, error } = await pos.listOrders();
|
|
2476
|
+
*
|
|
2477
|
+
* if (error) {
|
|
2478
|
+
* console.error("Failed to list orders:", error.message);
|
|
2479
|
+
* } else {
|
|
2480
|
+
* console.log("Orders found:", data.content?.orders?.length || 0);
|
|
2481
|
+
* console.log("Pagination:", data.content?.pagination);
|
|
2482
|
+
* data.content?.orders?.forEach(order => {
|
|
2483
|
+
* console.log(`Order: ${order.order_number} - Status: ${order.status} - Total: ${order.grand_total}`);
|
|
2484
|
+
* });
|
|
2485
|
+
* }
|
|
2486
|
+
*
|
|
2487
|
+
* // With filters and pagination
|
|
2488
|
+
* const { data: filteredData, error: filteredError } = await pos.listOrders({
|
|
2489
|
+
* page: 1,
|
|
2490
|
+
* limit: 50,
|
|
2491
|
+
* search: "ORD-2024",
|
|
2492
|
+
* filters: JSON.stringify({ "status": "delivered", "payment_status": "success" }),
|
|
2493
|
+
* sort_by: JSON.stringify({ "order_date": "desc" })
|
|
2494
|
+
* });
|
|
2495
|
+
* ```
|
|
2496
|
+
*/
|
|
2497
|
+
async listOrders(query) {
|
|
2498
|
+
return this.executeRequest(() => this.adminClient.GET("/pos/orders", { params: { query } }));
|
|
2499
|
+
}
|
|
2500
|
+
/**
|
|
2501
|
+
* Get order details (Admin)
|
|
2502
|
+
* @param pathParams - Order number
|
|
2503
|
+
* @returns Promise with order details
|
|
2504
|
+
* @example
|
|
2505
|
+
* ```typescript
|
|
2506
|
+
* const { data, error } = await pos.getOrderDetail({
|
|
2507
|
+
* order_number: "ORD-2024-001234"
|
|
2508
|
+
* });
|
|
2509
|
+
*
|
|
2510
|
+
* if (error) {
|
|
2511
|
+
* console.error("Failed to get order:", error.message);
|
|
2512
|
+
* } else {
|
|
2513
|
+
* const order = data.content?.order;
|
|
2514
|
+
* console.log(`Order: ${order?.order_number}`);
|
|
2515
|
+
* console.log(`Status: ${order?.status}`);
|
|
2516
|
+
* console.log(`Payment Status: ${order?.payment_status}`);
|
|
2517
|
+
* console.log(`Total: ${order?.grand_total}`);
|
|
2518
|
+
* console.log(`Items:`, order?.order_items);
|
|
2519
|
+
* console.log(`Billing Address:`, order?.billing_address);
|
|
2520
|
+
* console.log(`Payments:`, order?.payments);
|
|
2521
|
+
* }
|
|
2522
|
+
* ```
|
|
2523
|
+
*/
|
|
2524
|
+
async getOrderDetail(pathParams) {
|
|
2525
|
+
return this.executeRequest(() => this.client.GET("/pos/orders/{order_number}", { params: { path: pathParams } }));
|
|
2526
|
+
}
|
|
2527
|
+
/**
|
|
2528
|
+
* List order activity (Admin)
|
|
2529
|
+
* @param pathParams - Order number
|
|
2530
|
+
* @returns Promise with order activities
|
|
2531
|
+
* @example
|
|
2532
|
+
* ```typescript
|
|
2533
|
+
* const { data, error } = await pos.listOrderActivity({
|
|
2534
|
+
* order_number: "ORD-2024-001234"
|
|
2535
|
+
* });
|
|
2536
|
+
*
|
|
2537
|
+
* if (error) {
|
|
2538
|
+
* console.error("Failed to get order activity:", error.message);
|
|
2539
|
+
* } else {
|
|
2540
|
+
* console.log("Activities found:", data.content?.activity?.length || 0);
|
|
2541
|
+
* data.content?.activity?.forEach(activity => {
|
|
2542
|
+
* console.log(`${activity.created_at}: ${activity.activity_type} - ${activity.comment}`);
|
|
2543
|
+
* console.log(`By: ${activity.user_name} (${activity.user_type})`);
|
|
2544
|
+
* });
|
|
2545
|
+
* }
|
|
2546
|
+
* ```
|
|
2547
|
+
*/
|
|
2548
|
+
async listOrderActivity(pathParams) {
|
|
2549
|
+
return this.executeRequest(() => this.client.GET("/pos/orders/{order_number}/activity", { params: { path: pathParams } }));
|
|
2550
|
+
}
|
|
2551
|
+
/**
|
|
2552
|
+
* Get order invoice (Admin)
|
|
2553
|
+
* @param pathParams - Order number
|
|
2554
|
+
* @param query - Optional format parameter
|
|
2555
|
+
* @returns Promise with order invoice
|
|
2556
|
+
* @example
|
|
2557
|
+
* ```typescript
|
|
2558
|
+
* // Get invoice as JSON
|
|
2559
|
+
* const { data, error } = await pos.getOrderInvoice(
|
|
2560
|
+
* { order_number: "ORD-2024-001234" },
|
|
2561
|
+
* { format: "json" }
|
|
2562
|
+
* );
|
|
2563
|
+
*
|
|
2564
|
+
* if (error) {
|
|
2565
|
+
* console.error("Failed to get order invoice:", error.message);
|
|
2566
|
+
* } else {
|
|
2567
|
+
* data.content?.invoices?.forEach(invoice => {
|
|
2568
|
+
* console.log(`Invoice: ${invoice.invoice_number}`);
|
|
2569
|
+
* console.log(`Date: ${invoice.invoice_date}`);
|
|
2570
|
+
* console.log(`Total: ${invoice.grand_total}`);
|
|
2571
|
+
* console.log(`Items:`, invoice.items);
|
|
2572
|
+
* });
|
|
2573
|
+
* }
|
|
2574
|
+
*
|
|
2575
|
+
* // Get invoice as PDF
|
|
2576
|
+
* const { data: pdfData, error: pdfError } = await pos.getOrderInvoice(
|
|
2577
|
+
* { order_number: "ORD-2024-001234" },
|
|
2578
|
+
* { format: "pdf" }
|
|
2579
|
+
* );
|
|
2580
|
+
* ```
|
|
2581
|
+
*/
|
|
2582
|
+
async getOrderInvoice(pathParams, query) {
|
|
2583
|
+
return this.executeRequest(() => this.client.GET("/pos/orders/{order_number}/invoice", { params: {
|
|
2584
|
+
path: pathParams,
|
|
2585
|
+
query
|
|
2586
|
+
} }));
|
|
2587
|
+
}
|
|
2588
|
+
/**
|
|
2589
|
+
* Get order receipt (Admin)
|
|
2590
|
+
* @param pathParams - Order number
|
|
2591
|
+
* @param query - Optional format parameter
|
|
2592
|
+
* @returns Promise with order receipt
|
|
2593
|
+
* @example
|
|
2594
|
+
* ```typescript
|
|
2595
|
+
* // Get receipt as JSON
|
|
2596
|
+
* const { data, error } = await pos.getOrderReceipt(
|
|
2597
|
+
* { order_number: "ORD-2024-001234" },
|
|
2598
|
+
* { format: "json" }
|
|
2599
|
+
* );
|
|
2600
|
+
*
|
|
2601
|
+
* if (error) {
|
|
2602
|
+
* console.error("Failed to get order receipt:", error.message);
|
|
2603
|
+
* } else {
|
|
2604
|
+
* const receipt = data.content?.order_receipt;
|
|
2605
|
+
* console.log(`Order: ${receipt?.order_number}`);
|
|
2606
|
+
* console.log(`Date: ${receipt?.order_date}`);
|
|
2607
|
+
* console.log(`Total: ${receipt?.grand_total}`);
|
|
2608
|
+
* console.log(`Items:`, receipt?.order_items);
|
|
2609
|
+
* console.log(`Payments:`, receipt?.payments);
|
|
2610
|
+
* }
|
|
2611
|
+
*
|
|
2612
|
+
* // Get receipt as PDF
|
|
2613
|
+
* const { data: pdfData, error: pdfError } = await pos.getOrderReceipt(
|
|
2614
|
+
* { order_number: "ORD-2024-001234" },
|
|
2615
|
+
* { format: "pdf" }
|
|
2616
|
+
* );
|
|
2617
|
+
* ```
|
|
2618
|
+
*/
|
|
2619
|
+
async getOrderReceipt(pathParams, query) {
|
|
2620
|
+
return this.executeRequest(() => this.client.GET("/pos/orders/{order_number}/receipt", { params: {
|
|
2621
|
+
path: pathParams,
|
|
2622
|
+
query
|
|
2623
|
+
} }));
|
|
2624
|
+
}
|
|
2625
|
+
/**
|
|
2626
|
+
* Get order shipments (Admin)
|
|
2627
|
+
* @param pathParams - Order number
|
|
2628
|
+
* @returns Promise with order shipments
|
|
2629
|
+
* @example
|
|
2630
|
+
* ```typescript
|
|
2631
|
+
* const { data, error } = await pos.getOrderShipments({
|
|
2632
|
+
* order_number: "ORD-2024-001234"
|
|
2633
|
+
* });
|
|
2634
|
+
*
|
|
2635
|
+
* if (error) {
|
|
2636
|
+
* console.error("Failed to get order shipments:", error.message);
|
|
2637
|
+
* } else {
|
|
2638
|
+
* const shipment = data.content?.shipment;
|
|
2639
|
+
* console.log(`Order: ${shipment?.order_number}`);
|
|
2640
|
+
* console.log(`Order Status: ${shipment?.order_status}`);
|
|
2641
|
+
* console.log(`Payment Status: ${shipment?.payment_status}`);
|
|
2642
|
+
* console.log(`Customer: ${shipment?.customer_name}`);
|
|
2643
|
+
* console.log(`Shipments:`, shipment?.shipments);
|
|
2644
|
+
* console.log(`Allowed Actions:`, shipment?.allowed_actions);
|
|
2645
|
+
* }
|
|
2646
|
+
* ```
|
|
2647
|
+
*/
|
|
2648
|
+
async getOrderShipments(pathParams) {
|
|
2649
|
+
return this.executeRequest(() => this.client.GET("/pos/orders/{order_number}/shipments", { params: { path: pathParams } }));
|
|
2650
|
+
}
|
|
2651
|
+
/**
|
|
2652
|
+
* List all shipments (Admin)
|
|
2653
|
+
* @param query - Optional query parameters for filtering shipments
|
|
2654
|
+
* @returns Promise with list of shipments
|
|
2655
|
+
* @example
|
|
2656
|
+
* ```typescript
|
|
2657
|
+
* // Basic shipment listing
|
|
2658
|
+
* const { data, error } = await pos.listShipments();
|
|
2659
|
+
*
|
|
2660
|
+
* if (error) {
|
|
2661
|
+
* console.error("Failed to list shipments:", error.message);
|
|
2662
|
+
* } else {
|
|
2663
|
+
* console.log("Shipments found:", data.content?.shipments?.length || 0);
|
|
2664
|
+
* console.log("Pagination:", data.content?.pagination);
|
|
2665
|
+
* data.content?.shipments?.forEach(shipment => {
|
|
2666
|
+
* console.log(`Shipment: ${shipment.shipment_number} - Status: ${shipment.status}`);
|
|
2667
|
+
* console.log(`Order: ${shipment.order_number} - AWB: ${shipment.awb_no}`);
|
|
2668
|
+
* });
|
|
2669
|
+
* }
|
|
2670
|
+
*
|
|
2671
|
+
* // With filters and search
|
|
2672
|
+
* const { data: filteredData, error: filteredError } = await pos.listShipments({
|
|
2673
|
+
* page: 1,
|
|
2674
|
+
* limit: 25,
|
|
2675
|
+
* search: "SHIP-2024",
|
|
2676
|
+
* filters: JSON.stringify({ "status": "shipped" }),
|
|
2677
|
+
* sort_by: JSON.stringify({ "shipped_date": "desc" })
|
|
2678
|
+
* });
|
|
2679
|
+
* ```
|
|
2680
|
+
*/
|
|
2681
|
+
async listShipments(query) {
|
|
2682
|
+
return this.executeRequest(() => this.client.GET("/pos/shipping/shipments", { params: { query } }));
|
|
2683
|
+
}
|
|
2684
|
+
/**
|
|
2685
|
+
* Check inventory for order (Admin)
|
|
2686
|
+
* @param pathParams - Order number
|
|
2687
|
+
* @returns Promise with inventory check results
|
|
2688
|
+
* @example
|
|
2689
|
+
* ```typescript
|
|
2690
|
+
* const { data, error } = await pos.checkInventory({
|
|
2691
|
+
* order_number: "ORD-2024-001234"
|
|
2692
|
+
* });
|
|
2693
|
+
*
|
|
2694
|
+
* if (error) {
|
|
2695
|
+
* console.error("Failed to check inventory:", error.message);
|
|
2696
|
+
* } else {
|
|
2697
|
+
* const inventory = data.content;
|
|
2698
|
+
* console.log(`Inventory Status: ${inventory?.inventory_status}`);
|
|
2699
|
+
* console.log(`Shipment Items:`, inventory?.shipment_items);
|
|
2700
|
+
* console.log(`Recommended Warehouses:`, inventory?.recommended_warehouses);
|
|
2701
|
+
* console.log(`Inventory Detail:`, inventory?.inventory_detail);
|
|
2702
|
+
* console.log(`Allowed Actions:`, inventory?.allowed_action);
|
|
2703
|
+
* }
|
|
2704
|
+
* ```
|
|
2705
|
+
*/
|
|
2706
|
+
async checkInventory(pathParams) {
|
|
2707
|
+
return this.executeRequest(() => this.client.GET("/pos/shipping/shipments/{order_number}/check-inventory", { params: { path: pathParams } }));
|
|
2708
|
+
}
|
|
2709
|
+
/**
|
|
2710
|
+
* Refund shortfall for order (Admin)
|
|
2711
|
+
* @param pathParams - Order number
|
|
2712
|
+
* @param body - Refund details
|
|
2713
|
+
* @returns Promise with refund confirmation
|
|
2714
|
+
* @example
|
|
2715
|
+
* ```typescript
|
|
2716
|
+
* const { data, error } = await pos.refundShortfall(
|
|
2717
|
+
* { order_number: "ORD-2024-001234" },
|
|
2718
|
+
* {
|
|
2719
|
+
* items: [
|
|
2720
|
+
* {
|
|
2721
|
+
* sku: "SKU-123",
|
|
2722
|
+
* quantity: 2,
|
|
2723
|
+
* free_quantity: 0
|
|
2724
|
+
* }
|
|
2725
|
+
* ],
|
|
2726
|
+
* payment_method: "original-payment-mode"
|
|
2727
|
+
* }
|
|
2728
|
+
* );
|
|
2729
|
+
*
|
|
2730
|
+
* if (error) {
|
|
2731
|
+
* console.error("Failed to process refund:", error.message);
|
|
2732
|
+
* } else {
|
|
2733
|
+
* console.log("Refund processed:", data.message);
|
|
2734
|
+
* console.log("Success:", data.success);
|
|
2735
|
+
* }
|
|
2736
|
+
*
|
|
2737
|
+
* // Refund to bank transfer
|
|
2738
|
+
* const { data: bankData, error: bankError } = await pos.refundShortfall(
|
|
2739
|
+
* { order_number: "ORD-2024-001234" },
|
|
2740
|
+
* {
|
|
2741
|
+
* items: [{ sku: "SKU-123", quantity: 1 }],
|
|
2742
|
+
* payment_method: "bank-transfer",
|
|
2743
|
+
* bank_account_id: "BANK_ACC_123"
|
|
2744
|
+
* }
|
|
2745
|
+
* );
|
|
2746
|
+
* ```
|
|
2747
|
+
*/
|
|
2748
|
+
async refundShortfall(pathParams, body) {
|
|
2749
|
+
return this.executeRequest(() => this.client.POST("/pos/shipping/shipments/{order_number}/refund-shortfall", {
|
|
2750
|
+
params: { path: pathParams },
|
|
2751
|
+
body
|
|
2752
|
+
}));
|
|
2753
|
+
}
|
|
2754
|
+
/**
|
|
2755
|
+
* Get shipment details (Admin)
|
|
2756
|
+
* @param pathParams - Shipment reference number
|
|
2757
|
+
* @returns Promise with shipment details
|
|
2758
|
+
* @example
|
|
2759
|
+
* ```typescript
|
|
2760
|
+
* const { data, error } = await pos.getShipment({
|
|
2761
|
+
* reference_number: "SHIP-2024-001234"
|
|
2762
|
+
* });
|
|
2763
|
+
*
|
|
2764
|
+
* if (error) {
|
|
2765
|
+
* console.error("Failed to get shipment:", error.message);
|
|
2766
|
+
* } else {
|
|
2767
|
+
* const shipment = data.content?.shipment;
|
|
2768
|
+
* console.log(`Order: ${shipment?.order_number}`);
|
|
2769
|
+
* console.log(`Shipments:`, shipment?.shipments);
|
|
2770
|
+
* shipment?.shipments?.forEach(s => {
|
|
2771
|
+
* console.log(` Shipment: ${s.shipment_number} - Status: ${s.status}`);
|
|
2772
|
+
* console.log(` AWB: ${s.awb_no} - Courier: ${s.courier_company_name}`);
|
|
2773
|
+
* console.log(` Items:`, s.shipment_items);
|
|
2774
|
+
* });
|
|
2775
|
+
* }
|
|
2776
|
+
* ```
|
|
2777
|
+
*/
|
|
2778
|
+
async getShipment(pathParams) {
|
|
2779
|
+
return this.executeRequest(() => this.client.GET("/pos/shipping/shipments/{reference_number}", { params: { path: pathParams } }));
|
|
2780
|
+
}
|
|
2781
|
+
/**
|
|
2782
|
+
* Get shipment invoice (Admin)
|
|
2783
|
+
* @param pathParams - Shipment reference number
|
|
2784
|
+
* @param query - Optional format parameter
|
|
2785
|
+
* @returns Promise with shipment invoice
|
|
2786
|
+
* @example
|
|
2787
|
+
* ```typescript
|
|
2788
|
+
* // Get shipment invoice as JSON
|
|
2789
|
+
* const { data, error } = await pos.getShipmentInvoice(
|
|
2790
|
+
* { reference_number: "SHIP-2024-001234" },
|
|
2791
|
+
* { format: "json" }
|
|
2792
|
+
* );
|
|
2793
|
+
*
|
|
2794
|
+
* if (error) {
|
|
2795
|
+
* console.error("Failed to get shipment invoice:", error.message);
|
|
2796
|
+
* } else {
|
|
2797
|
+
* const invoice = data.content?.invoice;
|
|
2798
|
+
* console.log(`Invoice: ${invoice?.invoice_number}`);
|
|
2799
|
+
* console.log(`Date: ${invoice?.invoice_date}`);
|
|
2800
|
+
* console.log(`Total: ${invoice?.grand_total}`);
|
|
2801
|
+
* console.log(`Items:`, invoice?.items);
|
|
2802
|
+
* }
|
|
2803
|
+
*
|
|
2804
|
+
* // Get shipment invoice as PDF
|
|
2805
|
+
* const { data: pdfData, error: pdfError } = await pos.getShipmentInvoice(
|
|
2806
|
+
* { reference_number: "SHIP-2024-001234" },
|
|
2807
|
+
* { format: "pdf" }
|
|
2808
|
+
* );
|
|
2809
|
+
* ```
|
|
2810
|
+
*/
|
|
2811
|
+
async getShipmentInvoice(pathParams, query) {
|
|
2812
|
+
return this.executeRequest(() => this.client.GET("/pos/shipping/shipments/{reference_number}/invoice", { params: {
|
|
2813
|
+
path: pathParams,
|
|
2814
|
+
query
|
|
2815
|
+
} }));
|
|
2816
|
+
}
|
|
2817
|
+
/**
|
|
2818
|
+
* Update shipment details (Admin)
|
|
2819
|
+
* @param pathParams - Shipment reference number
|
|
2820
|
+
* @param body - Shipment update data
|
|
2821
|
+
* @returns Promise with updated shipment
|
|
2822
|
+
* @example
|
|
2823
|
+
* ```typescript
|
|
2824
|
+
* const { data, error } = await pos.updateShipment(
|
|
2825
|
+
* { reference_number: "SHIP-2024-001234" },
|
|
2826
|
+
* {
|
|
2827
|
+
* status: "shipped",
|
|
2828
|
+
* awb_no: "AWB123456789",
|
|
2829
|
+
* courier_company_name: "BlueDart",
|
|
2830
|
+
* shipping_label_url: "https://example.com/label.pdf",
|
|
2831
|
+
* tracking_url: "https://tracking.example.com/AWB123456789",
|
|
2832
|
+
* eta_delivery: "2024-01-15T10:00:00Z",
|
|
2833
|
+
* shipped_date: "2024-01-10T14:30:00Z"
|
|
2834
|
+
* }
|
|
2835
|
+
* );
|
|
2836
|
+
*
|
|
2837
|
+
* if (error) {
|
|
2838
|
+
* console.error("Failed to update shipment:", error.message);
|
|
2839
|
+
* } else {
|
|
2840
|
+
* console.log("Shipment updated successfully:", data.message);
|
|
2841
|
+
* const shipment = data.content?.shipment;
|
|
2842
|
+
* console.log(`Updated shipment status:`, shipment?.shipments?.[0]?.status);
|
|
2843
|
+
* }
|
|
2844
|
+
*
|
|
2845
|
+
* // Update delivery status
|
|
2846
|
+
* const { data: deliveryData, error: deliveryError } = await pos.updateShipment(
|
|
2847
|
+
* { reference_number: "SHIP-2024-001234" },
|
|
2848
|
+
* {
|
|
2849
|
+
* status: "delivered",
|
|
2850
|
+
* delivered_date: "2024-01-15T16:45:00Z"
|
|
2851
|
+
* }
|
|
2852
|
+
* );
|
|
2853
|
+
* ```
|
|
2854
|
+
*/
|
|
2855
|
+
async updateShipment(pathParams, body) {
|
|
2856
|
+
return this.executeRequest(() => this.client.PUT("/pos/shipping/shipments/{reference_number}/manual-update", {
|
|
2857
|
+
params: { path: pathParams },
|
|
2858
|
+
body
|
|
2859
|
+
}));
|
|
2860
|
+
}
|
|
1368
2861
|
};
|
|
1369
2862
|
|
|
1370
2863
|
//#endregion
|