ts-glitter 21.5.2 → 21.5.4

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.
Files changed (89) hide show
  1. package/lowcode/Entry.js +1 -1
  2. package/lowcode/Entry.ts +1 -1
  3. package/lowcode/cms-plugin/account-info.js +79 -67
  4. package/lowcode/cms-plugin/account-info.ts +327 -311
  5. package/lowcode/cms-plugin/information/information-module.ts +3 -1
  6. package/lowcode/cms-plugin/list-header-option.js +1 -0
  7. package/lowcode/cms-plugin/list-header-option.ts +1 -0
  8. package/lowcode/cms-plugin/shopping-information.js +468 -0
  9. package/lowcode/cms-plugin/shopping-information.ts +557 -0
  10. package/lowcode/cms-plugin/shopping-market-shopee.js +283 -231
  11. package/lowcode/cms-plugin/shopping-market-shopee.ts +401 -361
  12. package/lowcode/cms-plugin/shopping-order-manager.js +16 -4
  13. package/lowcode/cms-plugin/shopping-order-manager.ts +18 -3
  14. package/lowcode/glitter-base/global/language.js +4 -1
  15. package/lowcode/glitter-base/global/language.ts +4 -2
  16. package/lowcode/glitter-base/route/shopee.js +48 -11
  17. package/lowcode/glitter-base/route/shopee.ts +119 -80
  18. package/lowcode/glitterBundle/plugins/html-render.js +121 -90
  19. package/lowcode/glitterBundle/plugins/html-render.ts +367 -318
  20. package/lowcode/modules/image-library.js +2 -3
  21. package/lowcode/modules/image-library.ts +21 -7
  22. package/lowcode/public-components/checkout/index.js +90 -41
  23. package/lowcode/public-components/checkout/index.ts +101 -49
  24. package/lowcode/public-components/footer/footer-initial.js +11 -2
  25. package/lowcode/public-components/footer/footer-initial.ts +29 -18
  26. package/lowcode/public-components/headers/header-class.js +47 -35
  27. package/lowcode/public-components/headers/header-class.ts +54 -38
  28. package/lowcode/public-components/headers/sy-02.js +1 -1
  29. package/lowcode/public-components/headers/sy-02.ts +1 -1
  30. package/lowcode/public-components/headers/sy-03.js +1 -1
  31. package/lowcode/public-components/headers/sy-03.ts +1 -1
  32. package/lowcode/public-components/headers/sy-04.js +1 -1
  33. package/lowcode/public-components/headers/sy-04.ts +1 -1
  34. package/lowcode/public-components/headers/sy-05.js +1 -2
  35. package/lowcode/public-components/headers/sy-05.ts +1 -1
  36. package/lowcode/public-components/layout-plugin/social-links-01.js +122 -3
  37. package/lowcode/public-components/layout-plugin/social-links-01.ts +135 -10
  38. package/lowcode/public-components/product/pd-card-01.js +23 -14
  39. package/lowcode/public-components/product/pd-card-01.ts +25 -14
  40. package/lowcode/public-components/product/pd-card-02.js +23 -16
  41. package/lowcode/public-components/product/pd-card-02.ts +25 -16
  42. package/lowcode/public-components/product/pd-card-03.js +25 -16
  43. package/lowcode/public-components/product/pd-card-03.ts +27 -16
  44. package/lowcode/public-components/product/pd-class.js +1 -1
  45. package/lowcode/public-components/product/pd-class.ts +1 -1
  46. package/lowcode/public-components/terms-related/index.js +13 -2
  47. package/lowcode/public-components/terms-related/index.ts +15 -2
  48. package/lowcode/public-components/user-manager/um-class.js +490 -501
  49. package/lowcode/public-components/user-manager/um-class.ts +872 -882
  50. package/lowcode/public-components/user-manager/um-info.js +41 -40
  51. package/lowcode/public-components/user-manager/um-info.ts +54 -56
  52. package/lowcode/public-components/user-manager/um-login.js +10 -13
  53. package/lowcode/public-components/user-manager/um-login.ts +15 -23
  54. package/lowcode/public-components/user-manager/um-orderlist.js +60 -51
  55. package/lowcode/public-components/user-manager/um-orderlist.ts +289 -275
  56. package/lowcode/public-components/user-manager/um-rebate.js +104 -82
  57. package/lowcode/public-components/user-manager/um-rebate.ts +294 -267
  58. package/lowcode/public-components/user-manager/um-receive.js +582 -0
  59. package/lowcode/public-components/user-manager/um-receive.ts +599 -0
  60. package/lowcode/public-components/user-manager/um-wishlist.js +72 -68
  61. package/lowcode/public-components/user-manager/um-wishlist.ts +240 -230
  62. package/package.json +1 -1
  63. package/src/api-public/controllers/shopee.js +17 -0
  64. package/src/api-public/controllers/shopee.js.map +1 -1
  65. package/src/api-public/controllers/shopee.ts +32 -0
  66. package/src/api-public/services/monitor.d.ts +1 -0
  67. package/src/api-public/services/post.js +17 -7
  68. package/src/api-public/services/post.js.map +1 -1
  69. package/src/api-public/services/rebate.js +2 -11
  70. package/src/api-public/services/rebate.js.map +1 -1
  71. package/src/api-public/services/rebate.ts +5 -12
  72. package/src/api-public/services/shopee.d.ts +23 -2
  73. package/src/api-public/services/shopee.js +230 -111
  74. package/src/api-public/services/shopee.js.map +1 -1
  75. package/src/api-public/services/shopee.ts +1012 -838
  76. package/src/api-public/services/user.js +2 -2
  77. package/src/api-public/services/user.js.map +1 -1
  78. package/src/api-public/services/user.ts +3 -3
  79. package/src/index.js +17 -7
  80. package/src/index.js.map +1 -1
  81. package/src/modules/tool.d.ts +4 -4
  82. package/src/modules/tool.js +2 -1
  83. package/src/modules/tool.js.map +1 -1
  84. package/src/services/backend-service.js +17 -7
  85. package/src/services/backend-service.js.map +1 -1
  86. package/src/services/template.d.ts +1 -1
  87. package/src/services/template.js +24 -18
  88. package/src/services/template.js.map +1 -1
  89. package/src/services/template.ts +34 -37
@@ -86,23 +86,26 @@ class Shopee {
86
86
  return `${Shopee.path}${api_path}?partner_id=${partner_id}&timestamp=${timestamp}&sign=${sign}`;
87
87
  }
88
88
  cryptoSign(partner_id, api_path, timestamp, access_token, shop_id) {
89
- const baseString = `${partner_id}${api_path}${timestamp}${access_token !== null && access_token !== void 0 ? access_token : ""}${shop_id !== null && shop_id !== void 0 ? shop_id : ""}`;
89
+ const baseString = `${partner_id}${api_path}${timestamp}${access_token !== null && access_token !== void 0 ? access_token : ''}${shop_id !== null && shop_id !== void 0 ? shop_id : ''}`;
90
90
  const partner_key = Shopee.partner_key;
91
- return crypto_1.default.createHmac('sha256', partner_key !== null && partner_key !== void 0 ? partner_key : "").update(baseString).digest('hex');
91
+ return crypto_1.default
92
+ .createHmac('sha256', partner_key !== null && partner_key !== void 0 ? partner_key : '')
93
+ .update(baseString)
94
+ .digest('hex');
92
95
  }
93
96
  generateAuth(redirectUrl) {
94
97
  const partner_id = Shopee.partner_id;
95
- const api_path = "/api/v2/shop/auth_partner";
98
+ const api_path = '/api/v2/shop/auth_partner';
96
99
  const timestamp = Math.floor(Date.now() / 1000);
97
100
  const baseString = `${partner_id}${api_path}${timestamp}`;
98
- const signature = this.cryptoSign(partner_id !== null && partner_id !== void 0 ? partner_id : "", api_path, timestamp);
101
+ const signature = this.cryptoSign(partner_id !== null && partner_id !== void 0 ? partner_id : '', api_path, timestamp);
99
102
  return `${Shopee.path}${api_path}?partner_id=${partner_id}&timestamp=${timestamp}&redirect=${redirectUrl}&sign=${signature}`;
100
103
  }
101
104
  async getToken(code, shop_id) {
102
105
  var _a;
103
106
  const timestamp = Math.floor(Date.now() / 1000);
104
- const partner_id = (_a = Shopee.partner_id) !== null && _a !== void 0 ? _a : "";
105
- const api_path = "/api/v2/auth/token/get";
107
+ const partner_id = (_a = Shopee.partner_id) !== null && _a !== void 0 ? _a : '';
108
+ const api_path = '/api/v2/auth/token/get';
106
109
  const config = {
107
110
  method: 'post',
108
111
  url: this.generateUrl(partner_id, api_path, timestamp),
@@ -113,29 +116,30 @@ class Shopee {
113
116
  code: code,
114
117
  partner_id: parseInt(partner_id, 10),
115
118
  shop_id: parseInt(shop_id),
116
- })
119
+ }),
117
120
  };
118
121
  try {
119
122
  const response = await (0, axios_1.default)(config);
120
- const data = (await database_js_1.default.execute(`select *
121
- from \`${config_js_1.saasConfig.SAAS_NAME}\`.private_config
122
- where \`app_name\` = '${this.app}'
123
- and \`key\` = 'shopee_access_token'
124
- `, []));
123
+ const data = await database_js_1.default.execute(`select *
124
+ from \`${config_js_1.saasConfig.SAAS_NAME}\`.private_config
125
+ where \`app_name\` = '${this.app}'
126
+ and \`key\` = 'shopee_access_token'
127
+ `, []);
125
128
  let passData = Object.assign(Object.assign({}, response.data), { expires_at: new Date(Date.now() + 14373 * 1000).toISOString(), created_at: new Date().toISOString(), shop_id: shop_id });
126
129
  if (data.length == 0) {
127
130
  await database_js_1.default.execute(`
128
- INSERT INTO \`${config_js_1.saasConfig.SAAS_NAME}\`.private_config (\`app_name\`, \`key\`, \`value\`, \`updated_at\`)
129
- VALUES (?, ?, ?, ?);
130
- `, [this.app, "shopee_access_token", passData, new Date()]);
131
+ INSERT INTO \`${config_js_1.saasConfig.SAAS_NAME}\`.private_config (\`app_name\`, \`key\`, \`value\`, \`updated_at\`)
132
+ VALUES (?, ?, ?, ?);
133
+ `, [this.app, 'shopee_access_token', passData, new Date()]);
131
134
  }
132
135
  else {
133
136
  await database_js_1.default.execute(`
134
- UPDATE \`${config_js_1.saasConfig.SAAS_NAME}\`.\`private_config\`
135
- SET \`value\` = ? , updated_at=?
136
- where \`app_name\` = '${this.app}'
137
- and \`key\` = 'shopee_access_token'
138
- `, [passData, new Date()]);
137
+ UPDATE \`${config_js_1.saasConfig.SAAS_NAME}\`.\`private_config\`
138
+ SET \`value\` = ?,
139
+ updated_at=?
140
+ where \`app_name\` = '${this.app}'
141
+ and \`key\` = 'shopee_access_token'
142
+ `, [passData, new Date()]);
139
143
  }
140
144
  }
141
145
  catch (error) {
@@ -150,14 +154,14 @@ class Shopee {
150
154
  async getItemList(start, end, index = 0) {
151
155
  var _a;
152
156
  const timestamp = Math.floor(Date.now() / 1000);
153
- const partner_id = (_a = Shopee.partner_id) !== null && _a !== void 0 ? _a : "";
154
- const api_path = "/api/v2/product/get_item_list";
157
+ const partner_id = (_a = Shopee.partner_id) !== null && _a !== void 0 ? _a : '';
158
+ const api_path = '/api/v2/product/get_item_list';
155
159
  await this.fetchShopeeAccessToken();
156
- const data = (await database_js_1.default.execute(`select *
157
- from \`${config_js_1.saasConfig.SAAS_NAME}\`.private_config
158
- where \`app_name\` = '${this.app}'
159
- and \`key\` = 'shopee_access_token'
160
- `, []));
160
+ const data = await database_js_1.default.execute(`select *
161
+ from \`${config_js_1.saasConfig.SAAS_NAME}\`.private_config
162
+ where \`app_name\` = '${this.app}'
163
+ and \`key\` = 'shopee_access_token'
164
+ `, []);
161
165
  const config = {
162
166
  method: 'get',
163
167
  url: this.generateShopUrl(partner_id, api_path, timestamp, data[0].value.access_token, parseInt(data[0].value.shop_id)),
@@ -179,17 +183,26 @@ class Shopee {
179
183
  const response = await (0, axios_1.default)(config);
180
184
  if (response.data.error.length > 0) {
181
185
  return {
182
- type: "error",
183
- message: response.data.error
186
+ type: 'error',
187
+ message: response.data.error,
188
+ };
189
+ }
190
+ console.log("response -- ", response);
191
+ if (response.data.response.total_count == 0) {
192
+ return {
193
+ type: 'success',
194
+ data: response.data.response,
195
+ message: '該時間區間查無商品',
184
196
  };
185
197
  }
186
198
  const itemList = response.data.response.item;
187
199
  const productData = await Promise.all(itemList.map(async (item, index) => {
200
+ console.log('here -- OK');
188
201
  try {
189
- const pd_data = (await database_js_1.default.query(`SELECT count(1)
190
- FROM ${this.app}.t_manager_post
191
- WHERE (content ->>'$.type'='product')
192
- AND (content ->>'$.shopee_id' = ${item.item_id});`, []));
202
+ const pd_data = await database_js_1.default.query(`SELECT count(1)
203
+ FROM ${this.app}.t_manager_post
204
+ WHERE (content ->>'$.type'='product')
205
+ AND (content ->>'$.shopee_id' = ${item.item_id});`, []);
193
206
  if (pd_data[0]['count(1)'] > 0) {
194
207
  return null;
195
208
  }
@@ -202,7 +215,7 @@ class Shopee {
202
215
  }
203
216
  }));
204
217
  const temp = {};
205
- temp.data = productData.reverse().filter((dd) => {
218
+ temp.data = productData.reverse().filter(dd => {
206
219
  return dd;
207
220
  });
208
221
  temp.collection = [];
@@ -213,24 +226,24 @@ class Shopee {
213
226
  }
214
227
  return {
215
228
  data: temp.data,
216
- message: '匯入OK'
229
+ message: '匯入OK',
217
230
  };
218
231
  }
219
232
  catch (error) {
220
233
  console.error(error);
221
234
  return {
222
- type: "error",
235
+ type: 'error',
223
236
  data: temp.data,
224
- message: '產品匯入資料庫失敗'
237
+ message: '產品匯入資料庫失敗',
225
238
  };
226
239
  }
227
240
  }
228
241
  catch (error) {
229
242
  if (axios_1.default.isAxiosError(error) && error.response) {
230
- console.log("Try get_item_list error");
243
+ console.log('Try get_item_list error');
231
244
  console.error('Error Response:', error.response.data);
232
245
  return {
233
- type: "error",
246
+ type: 'error',
234
247
  error: error.response.data.error,
235
248
  message: error.response.data.message,
236
249
  };
@@ -250,8 +263,8 @@ class Shopee {
250
263
  async function getModel(postMD) {
251
264
  var _a;
252
265
  const timestamp = Math.floor(Date.now() / 1000);
253
- const partner_id = (_a = Shopee.partner_id) !== null && _a !== void 0 ? _a : "";
254
- const api_path = "/api/v2/product/get_model_list";
266
+ const partner_id = (_a = Shopee.partner_id) !== null && _a !== void 0 ? _a : '';
267
+ const api_path = '/api/v2/product/get_model_list';
255
268
  const config = {
256
269
  method: 'get',
257
270
  url: that.generateShopUrl(partner_id, api_path, timestamp, token.access_token, parseInt(token.shop_id)),
@@ -261,7 +274,7 @@ class Shopee {
261
274
  params: {
262
275
  shop_id: parseInt(token.shop_id),
263
276
  access_token: token.access_token,
264
- item_id: id
277
+ item_id: id,
265
278
  },
266
279
  };
267
280
  try {
@@ -273,13 +286,13 @@ class Shopee {
273
286
  let temp = {
274
287
  title: dd.name,
275
288
  option: [],
276
- language_title: {}
289
+ language_title: {},
277
290
  };
278
291
  dd.option_list.map((option) => {
279
292
  temp.option.push({
280
293
  title: option.option,
281
294
  expand: false,
282
- language_title: {}
295
+ language_title: {},
283
296
  });
284
297
  });
285
298
  return temp;
@@ -299,30 +312,30 @@ class Shopee {
299
312
  weight: 0,
300
313
  shipment_type: 'none',
301
314
  sku: data.model_sku,
302
- barcode: "",
315
+ barcode: '',
303
316
  stock: data.stock_info_v2.summary_info.total_available_stock,
304
317
  stockList: {},
305
- preview_image: "",
306
- show_understocking: "true",
307
- type: "product",
318
+ preview_image: '',
319
+ show_understocking: 'true',
320
+ type: 'product',
308
321
  };
309
- if (!(option && option.skip_image_load) && (((_a = data === null || data === void 0 ? void 0 : data.image) === null || _a === void 0 ? void 0 : _a.image_url_list.length) > 0)) {
322
+ if (!(option && option.skip_image_load) && ((_a = data === null || data === void 0 ? void 0 : data.image) === null || _a === void 0 ? void 0 : _a.image_url_list.length) > 0) {
310
323
  try {
311
324
  const imageUrl = data.image.image_url_list[0];
312
325
  if (imageUrl) {
313
326
  const buffer = await that.downloadImage(imageUrl);
314
- const fileExtension = "jpg";
327
+ const fileExtension = 'jpg';
315
328
  const fileName = `shopee/${postMD.title}/${new Date().getTime()}_0.${fileExtension}`;
316
329
  newVariants.preview_image = await that.uploadFile(fileName, buffer);
317
330
  }
318
331
  else {
319
332
  console.warn('圖片 URL 列表為空,無法處理');
320
- newVariants.preview_image = "";
333
+ newVariants.preview_image = '';
321
334
  }
322
335
  }
323
336
  catch (error) {
324
337
  console.error('下載或上傳失敗:', error);
325
- newVariants.preview_image = "";
338
+ newVariants.preview_image = '';
326
339
  }
327
340
  }
328
341
  newVariants.shopee_model_id = data.model_id;
@@ -340,8 +353,8 @@ class Shopee {
340
353
  }
341
354
  }
342
355
  const timestamp = Math.floor(Date.now() / 1000);
343
- const partner_id = (_a = Shopee.partner_id) !== null && _a !== void 0 ? _a : "";
344
- const api_path = "/api/v2/product/get_item_base_info";
356
+ const partner_id = (_a = Shopee.partner_id) !== null && _a !== void 0 ? _a : '';
357
+ const api_path = '/api/v2/product/get_item_base_info';
345
358
  const config = {
346
359
  method: 'get',
347
360
  url: this.generateShopUrl(partner_id, api_path, timestamp, token.access_token, parseInt(token.shop_id)),
@@ -351,7 +364,7 @@ class Shopee {
351
364
  params: {
352
365
  shop_id: parseInt(token.shop_id),
353
366
  access_token: token.access_token,
354
- item_id_list: id
367
+ item_id_list: id,
355
368
  },
356
369
  };
357
370
  try {
@@ -360,12 +373,11 @@ class Shopee {
360
373
  let origData = {};
361
374
  try {
362
375
  origData = await database_js_1.default.query(`SELECT *
363
- FROM \`${this.app}\`.t_manager_post
364
- WHERE (content ->>'$.type'='product')
365
- AND (content ->>'$.shopee_id' = ?);`, [id]);
366
- }
367
- catch (e) {
376
+ FROM \`${this.app}\`.t_manager_post
377
+ WHERE (content ->>'$.type'='product')
378
+ AND (content ->>'$.shopee_id' = ?);`, [id]);
368
379
  }
380
+ catch (e) { }
369
381
  let postMD;
370
382
  postMD = this.getInitial({});
371
383
  if (origData.length > 0) {
@@ -378,7 +390,7 @@ class Shopee {
378
390
  if (item1.field_type == 'image' && !(option && option.skip_image_load)) {
379
391
  try {
380
392
  const buffer = await this.downloadImage(item1.image_info.image_url);
381
- const fileExtension = "jpg";
393
+ const fileExtension = 'jpg';
382
394
  const fileName = `shopee/${postMD.title}/${new Date().getTime()}_${item1.image_info.image_id}.${fileExtension}`;
383
395
  item1.image_info.s3 = await this.uploadFile(fileName, buffer);
384
396
  }
@@ -392,13 +404,12 @@ class Shopee {
392
404
  if (item.description_info && item.description_info.extended_description) {
393
405
  item.description_info.extended_description.field_list.map((item) => {
394
406
  if (item.field_type == 'image' && !(option && option.skip_image_load)) {
395
- temp += html `
396
- <div style="white-space: pre-wrap;"><img src="${item.image_info.s3}"
397
- alt='${item.image_info.image_id}'></div>`;
407
+ temp += html ` <div style="white-space: pre-wrap;">
408
+ <img src="${item.image_info.s3}" alt="${item.image_info.image_id}" />
409
+ </div>`;
398
410
  }
399
411
  else if (item.field_type == 'text') {
400
- temp += html `
401
- <div style="white-space: pre-wrap;">${item.text}</div>`;
412
+ temp += html ` <div style="white-space: pre-wrap;">${item.text}</div>`;
402
413
  }
403
414
  });
404
415
  }
@@ -416,13 +427,13 @@ class Shopee {
416
427
  v_height: item.dimension.package_height,
417
428
  weight: item.weight,
418
429
  shipment_type: 'none',
419
- sku: "",
420
- barcode: "",
430
+ sku: '',
431
+ barcode: '',
421
432
  stock: item.stock_info_v2.summary_info.total_available_stock,
422
433
  stockList: {},
423
- preview_image: "",
424
- show_understocking: "true",
425
- type: "product",
434
+ preview_image: '',
435
+ show_understocking: 'true',
436
+ type: 'product',
426
437
  };
427
438
  postMD.variants = [];
428
439
  postMD.variants.push(newVariants);
@@ -434,7 +445,7 @@ class Shopee {
434
445
  postMD.preview_image = await Promise.all(item.image.image_url_list.map(async (imageUrl, index) => {
435
446
  try {
436
447
  const buffer = await this.downloadImage(imageUrl);
437
- const fileExtension = "jpg";
448
+ const fileExtension = 'jpg';
438
449
  const fileName = `shopee/${postMD.title}/${new Date().getTime()}_${index}.${fileExtension}`;
439
450
  const uploadedData = await this.uploadFile(fileName, buffer);
440
451
  return uploadedData;
@@ -470,11 +481,11 @@ class Shopee {
470
481
  return;
471
482
  }
472
483
  let basicData = {
473
- "item_id": obj.product.content.shopee_id,
474
- "stock_list": []
484
+ item_id: obj.product.content.shopee_id,
485
+ stock_list: [],
475
486
  };
476
- const partner_id = (_a = Shopee.partner_id) !== null && _a !== void 0 ? _a : "";
477
- const api_path = "/api/v2/product/get_model_list";
487
+ const partner_id = (_a = Shopee.partner_id) !== null && _a !== void 0 ? _a : '';
488
+ const api_path = '/api/v2/product/get_model_list';
478
489
  const timestamp = Math.floor(Date.now() / 1000);
479
490
  const config = {
480
491
  method: 'get',
@@ -485,7 +496,7 @@ class Shopee {
485
496
  params: {
486
497
  shop_id: parseInt(obj.shop_id),
487
498
  access_token: obj.access_token,
488
- item_id: obj.product.content.shopee_id
499
+ item_id: obj.product.content.shopee_id,
489
500
  },
490
501
  };
491
502
  try {
@@ -495,14 +506,16 @@ class Shopee {
495
506
  }
496
507
  obj.product.content.variants.map((variant) => {
497
508
  let basicStock = {
498
- "model_id": 0,
499
- "seller_stock": [
509
+ model_id: 0,
510
+ seller_stock: [
500
511
  {
501
- "stock": 0
502
- }
503
- ]
512
+ stock: 0,
513
+ },
514
+ ],
504
515
  };
505
- let findModel = response.data.response.model.find((item) => { return item.model_name == variant.spec.join(','); });
516
+ let findModel = response.data.response.model.find((item) => {
517
+ return item.model_name == variant.spec.join(',');
518
+ });
506
519
  console.log(`findModel===>`, findModel);
507
520
  if (findModel || response.data.response.model.length == 0) {
508
521
  basicStock.model_id = (findModel && findModel.model_id) || 0;
@@ -512,7 +525,7 @@ class Shopee {
512
525
  });
513
526
  const updateConfig = {
514
527
  method: 'post',
515
- url: this.generateShopUrl(partner_id, "/api/v2/product/update_stock", timestamp, obj.access_token, parseInt(obj.shop_id)),
528
+ url: this.generateShopUrl(partner_id, '/api/v2/product/update_stock', timestamp, obj.access_token, parseInt(obj.shop_id)),
516
529
  params: {
517
530
  shop_id: parseInt(obj.shop_id),
518
531
  access_token: obj.access_token,
@@ -520,7 +533,7 @@ class Shopee {
520
533
  headers: {
521
534
  'Content-Type': 'application/json',
522
535
  },
523
- data: JSON.stringify(basicData)
536
+ data: JSON.stringify(basicData),
524
537
  };
525
538
  try {
526
539
  const response = await (0, axios_1.default)(updateConfig);
@@ -550,9 +563,9 @@ class Shopee {
550
563
  let origData = {};
551
564
  try {
552
565
  origData = await database_js_1.default.query(`SELECT *
553
- FROM \`${this.app}\`.t_manager_post
554
- WHERE (content ->>'$.type'='product')
555
- AND (content ->>'$.shopee_id' IS NOT NULL AND content ->>'$.shopee_id' <> '')`, []);
566
+ FROM \`${this.app}\`.t_manager_post
567
+ WHERE (content ->>'$.type'='product')
568
+ AND (content ->>'$.shopee_id' IS NOT NULL AND content ->>'$.shopee_id' <> '')`, []);
556
569
  let temp = await this.fetchShopeeAccessToken();
557
570
  return Promise.all(origData.map((product) => new Promise((resolve, reject) => {
558
571
  try {
@@ -562,36 +575,37 @@ class Shopee {
562
575
  resolve();
563
576
  },
564
577
  access_token: temp.access_token,
565
- shop_id: temp.shop_id
578
+ shop_id: temp.shop_id,
566
579
  });
567
580
  }
568
581
  catch (e) {
569
582
  reject(e);
570
583
  }
571
- }))).then(() => {
572
- console.log("所有產品的庫存同步完成!");
584
+ })))
585
+ .then(() => {
586
+ console.log('所有產品的庫存同步完成!');
573
587
  return {
574
- result: "OK",
588
+ result: 'OK',
575
589
  };
576
- }).catch((error) => {
577
- console.error("同步庫存時發生錯誤:", error);
590
+ })
591
+ .catch(error => {
592
+ console.error('同步庫存時發生錯誤:', error);
578
593
  });
579
594
  }
580
- catch (e) {
581
- }
595
+ catch (e) { }
582
596
  }
583
597
  async fetchShopeeAccessToken() {
584
598
  try {
585
- const sqlData = await database_js_1.default.execute(`SELECT *
586
- FROM \`${config_js_1.saasConfig.SAAS_NAME}\`.private_config
587
- WHERE \`app_name\` = '${this.app}'
588
- AND \`key\` = 'shopee_access_token'`, []);
599
+ const sqlData = await database_js_1.default.execute(`SELECT *
600
+ FROM \`${config_js_1.saasConfig.SAAS_NAME}\`.private_config
601
+ WHERE \`app_name\` = '${this.app}'
602
+ AND \`key\` = 'shopee_access_token'`, []);
589
603
  const obj = {};
590
604
  obj.accessToken = sqlData;
591
- if (new Date().getTime() >= (new Date(sqlData[0].updated_at).getTime() + (3.9 * 3600 * 1000))) {
605
+ if (new Date().getTime() >= new Date(sqlData[0].updated_at).getTime() + 3.9 * 3600 * 1000) {
592
606
  console.log(`確認要刷新token`);
593
607
  const partner_id = Shopee.partner_id;
594
- const api_path = "/api/v2/auth/access_token/get";
608
+ const api_path = '/api/v2/auth/access_token/get';
595
609
  const timestamp = Math.floor(Date.now() / 1000);
596
610
  const config = {
597
611
  method: 'post',
@@ -602,26 +616,27 @@ class Shopee {
602
616
  data: JSON.stringify({
603
617
  shop_id: parseInt(obj.accessToken[0].value.shop_id),
604
618
  refresh_token: obj.accessToken[0].value.refresh_token,
605
- partner_id: parseInt(partner_id)
619
+ partner_id: parseInt(partner_id),
606
620
  }),
607
621
  };
608
622
  try {
609
623
  const response = await (0, axios_1.default)(config);
610
624
  try {
611
625
  await database_js_1.default.execute(`
612
- UPDATE \`${config_js_1.saasConfig.SAAS_NAME}\`.\`private_config\`
613
- SET \`value\` = ? , updated_at = ?
614
- where \`app_name\` = '${this.app}'
615
- and \`key\` = 'shopee_access_token'
616
- `, [response.data, new Date()]);
626
+ UPDATE \`${config_js_1.saasConfig.SAAS_NAME}\`.\`private_config\`
627
+ SET \`value\` = ?,
628
+ updated_at = ?
629
+ where \`app_name\` = '${this.app}'
630
+ and \`key\` = 'shopee_access_token'
631
+ `, [response.data, new Date()]);
617
632
  return response.data;
618
633
  }
619
634
  catch (e) {
620
- console.error("refresh private_config shopee_access_token error : ", e.data);
635
+ console.error('refresh private_config shopee_access_token error : ', e.data);
621
636
  }
622
637
  }
623
638
  catch (e) {
624
- console.error("Shopee access token API request failed:", e);
639
+ console.error('Shopee access token API request failed:', e);
625
640
  }
626
641
  }
627
642
  else {
@@ -629,7 +644,111 @@ class Shopee {
629
644
  }
630
645
  }
631
646
  catch (e) {
632
- console.error("Database query for Shopee access token failed:", e);
647
+ console.error('Database query for Shopee access token failed:', e);
648
+ }
649
+ }
650
+ async getOrderList(start, end, index = 0) {
651
+ var _a;
652
+ const timestamp = Math.floor(Date.now() / 1000);
653
+ const partner_id = (_a = Shopee.partner_id) !== null && _a !== void 0 ? _a : '';
654
+ const api_path = '/api/v2/order/get_order_list';
655
+ await this.fetchShopeeAccessToken();
656
+ console.log();
657
+ const data = await database_js_1.default.execute(`select *
658
+ from \`${config_js_1.saasConfig.SAAS_NAME}\`.private_config
659
+ where \`app_name\` = '${this.app}'
660
+ and \`key\` = 'shopee_access_token'
661
+ `, []);
662
+ const config = {
663
+ method: 'get',
664
+ url: this.generateShopUrl(partner_id, api_path, timestamp, data[0].value.access_token, parseInt(data[0].value.shop_id)),
665
+ headers: {
666
+ 'Content-Type': 'application/json',
667
+ },
668
+ params: {
669
+ shop_id: parseInt(data[0].value.shop_id),
670
+ access_token: data[0].value.access_token,
671
+ offset: index || 0,
672
+ page_size: 10,
673
+ update_time_from: start,
674
+ update_time_to: Math.floor(Date.now() / 1000),
675
+ item_status: ['NORMAL', 'BANNED', 'UNLIST'],
676
+ },
677
+ paramsSerializer: (params) => qs_1.default.stringify(params, { arrayFormat: 'repeat' }),
678
+ };
679
+ try {
680
+ const response = await (0, axios_1.default)(config);
681
+ if (response.data.error.length > 0) {
682
+ return {
683
+ type: 'error',
684
+ message: response.data.error,
685
+ };
686
+ }
687
+ console.log("order response -- ", response.data);
688
+ if (response.data.response.total_count == 0) {
689
+ return {
690
+ type: 'success',
691
+ data: response.data.response,
692
+ message: '該時間區間查無商品',
693
+ };
694
+ }
695
+ return;
696
+ const itemList = response.data.response.item;
697
+ const productData = await Promise.all(itemList.map(async (item, index) => {
698
+ console.log('here -- OK');
699
+ try {
700
+ const pd_data = await database_js_1.default.query(`SELECT count(1)
701
+ FROM ${this.app}.t_manager_post
702
+ WHERE (content ->>'$.type'='product')
703
+ AND (content ->>'$.shopee_id' = ${item.item_id});`, []);
704
+ if (pd_data[0]['count(1)'] > 0) {
705
+ return null;
706
+ }
707
+ else {
708
+ return await this.getProductDetail(item.item_id);
709
+ }
710
+ }
711
+ catch (error) {
712
+ return null;
713
+ }
714
+ }));
715
+ const temp = {};
716
+ temp.data = productData.reverse().filter(dd => {
717
+ return dd;
718
+ });
719
+ temp.collection = [];
720
+ try {
721
+ await new shopping_js_1.Shopping(this.app, this.token).postMulProduct(temp);
722
+ if (response.data.response.has_next_page) {
723
+ await this.getItemList(start, end, response.data.response.next_offset);
724
+ }
725
+ return {
726
+ data: temp.data,
727
+ message: '匯入OK',
728
+ };
729
+ }
730
+ catch (error) {
731
+ console.error(error);
732
+ return {
733
+ type: 'error',
734
+ data: temp.data,
735
+ message: '產品匯入資料庫失敗',
736
+ };
737
+ }
738
+ }
739
+ catch (error) {
740
+ if (axios_1.default.isAxiosError(error) && error.response) {
741
+ console.log('Try get_item_list error');
742
+ console.error('Error Response:', error.response.data);
743
+ return {
744
+ type: 'error',
745
+ error: error.response.data.error,
746
+ message: error.response.data.message,
747
+ };
748
+ }
749
+ else {
750
+ console.error('Unexpected Error:', error.message);
751
+ }
633
752
  }
634
753
  }
635
754
  getInitial(obj) {