@congminh1254/shopee-sdk 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +85 -0
  3. package/lib/errors.d.ts +8 -0
  4. package/lib/errors.js +15 -0
  5. package/lib/errors.js.map +1 -0
  6. package/lib/fetch.d.ts +5 -0
  7. package/lib/fetch.js +105 -0
  8. package/lib/fetch.js.map +1 -0
  9. package/lib/managers/ads.manager.d.ts +53 -0
  10. package/lib/managers/ads.manager.js +74 -0
  11. package/lib/managers/ads.manager.js.map +1 -0
  12. package/lib/managers/auth.manager.d.ts +9 -0
  13. package/lib/managers/auth.manager.js +58 -0
  14. package/lib/managers/auth.manager.js.map +1 -0
  15. package/lib/managers/base.manager.d.ts +5 -0
  16. package/lib/managers/base.manager.js +7 -0
  17. package/lib/managers/base.manager.js.map +1 -0
  18. package/lib/managers/index.d.ts +10 -0
  19. package/lib/managers/index.js +11 -0
  20. package/lib/managers/index.js.map +1 -0
  21. package/lib/managers/logistics.manager.d.ts +33 -0
  22. package/lib/managers/logistics.manager.js +42 -0
  23. package/lib/managers/logistics.manager.js.map +1 -0
  24. package/lib/managers/order.manager.d.ts +105 -0
  25. package/lib/managers/order.manager.js +173 -0
  26. package/lib/managers/order.manager.js.map +1 -0
  27. package/lib/managers/payment.manager.d.ts +30 -0
  28. package/lib/managers/payment.manager.js +39 -0
  29. package/lib/managers/payment.manager.js.map +1 -0
  30. package/lib/managers/product.manager.d.ts +114 -0
  31. package/lib/managers/product.manager.js +147 -0
  32. package/lib/managers/product.manager.js.map +1 -0
  33. package/lib/managers/public.manager.d.ts +9 -0
  34. package/lib/managers/public.manager.js +34 -0
  35. package/lib/managers/public.manager.js.map +1 -0
  36. package/lib/managers/push.manager.d.ts +36 -0
  37. package/lib/managers/push.manager.js +60 -0
  38. package/lib/managers/push.manager.js.map +1 -0
  39. package/lib/managers/voucher.manager.d.ts +70 -0
  40. package/lib/managers/voucher.manager.js +114 -0
  41. package/lib/managers/voucher.manager.js.map +1 -0
  42. package/lib/schemas/access-token.d.ts +27 -0
  43. package/lib/schemas/access-token.js +2 -0
  44. package/lib/schemas/access-token.js.map +1 -0
  45. package/lib/schemas/ads.d.ts +62 -0
  46. package/lib/schemas/ads.js +2 -0
  47. package/lib/schemas/ads.js.map +1 -0
  48. package/lib/schemas/api-range.d.ts +1 -0
  49. package/lib/schemas/api-range.js +2 -0
  50. package/lib/schemas/api-range.js.map +1 -0
  51. package/lib/schemas/attribute.d.ts +33 -0
  52. package/lib/schemas/attribute.js +2 -0
  53. package/lib/schemas/attribute.js.map +1 -0
  54. package/lib/schemas/authed-merchant.d.ts +6 -0
  55. package/lib/schemas/authed-merchant.js +2 -0
  56. package/lib/schemas/authed-merchant.js.map +1 -0
  57. package/lib/schemas/authed-shop.d.ts +11 -0
  58. package/lib/schemas/authed-shop.js +2 -0
  59. package/lib/schemas/authed-shop.js.map +1 -0
  60. package/lib/schemas/base.d.ts +11 -0
  61. package/lib/schemas/base.js +2 -0
  62. package/lib/schemas/base.js.map +1 -0
  63. package/lib/schemas/category.d.ts +12 -0
  64. package/lib/schemas/category.js +2 -0
  65. package/lib/schemas/category.js.map +1 -0
  66. package/lib/schemas/fetch.d.ts +13 -0
  67. package/lib/schemas/fetch.js +2 -0
  68. package/lib/schemas/fetch.js.map +1 -0
  69. package/lib/schemas/index.d.ts +11 -0
  70. package/lib/schemas/index.js +12 -0
  71. package/lib/schemas/index.js.map +1 -0
  72. package/lib/schemas/logistics.d.ts +157 -0
  73. package/lib/schemas/logistics.js +115 -0
  74. package/lib/schemas/logistics.js.map +1 -0
  75. package/lib/schemas/order.d.ts +592 -0
  76. package/lib/schemas/order.js +2 -0
  77. package/lib/schemas/order.js.map +1 -0
  78. package/lib/schemas/payment.d.ts +298 -0
  79. package/lib/schemas/payment.js +2 -0
  80. package/lib/schemas/payment.js.map +1 -0
  81. package/lib/schemas/product.d.ts +604 -0
  82. package/lib/schemas/product.js +14 -0
  83. package/lib/schemas/product.js.map +1 -0
  84. package/lib/schemas/public.d.ts +25 -0
  85. package/lib/schemas/public.js +2 -0
  86. package/lib/schemas/public.js.map +1 -0
  87. package/lib/schemas/push.d.ts +64 -0
  88. package/lib/schemas/push.js +2 -0
  89. package/lib/schemas/push.js.map +1 -0
  90. package/lib/schemas/region.d.ts +14 -0
  91. package/lib/schemas/region.js +16 -0
  92. package/lib/schemas/region.js.map +1 -0
  93. package/lib/schemas/voucher.d.ts +241 -0
  94. package/lib/schemas/voucher.js +15 -0
  95. package/lib/schemas/voucher.js.map +1 -0
  96. package/lib/sdk.d.ts +42 -0
  97. package/lib/sdk.js +77 -0
  98. package/lib/sdk.js.map +1 -0
  99. package/lib/storage/custom-token-storage.d.ts +10 -0
  100. package/lib/storage/custom-token-storage.js +47 -0
  101. package/lib/storage/custom-token-storage.js.map +1 -0
  102. package/lib/storage/token-storage.interface.d.ts +6 -0
  103. package/lib/storage/token-storage.interface.js +2 -0
  104. package/lib/storage/token-storage.interface.js.map +1 -0
  105. package/lib/utils/signature.d.ts +1 -0
  106. package/lib/utils/signature.js +9 -0
  107. package/lib/utils/signature.js.map +1 -0
  108. package/package.json +84 -0
@@ -0,0 +1,64 @@
1
+ import { FetchResponse } from "./fetch.js";
2
+ import { BaseResponse } from "./base.js";
3
+ export type PushConfigType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13;
4
+ export interface SetAppPushConfigParams extends Record<string, string | number | boolean | number[] | undefined> {
5
+ callback_url?: string;
6
+ set_push_config_on?: PushConfigType[];
7
+ set_push_config_off?: PushConfigType[];
8
+ blocked_shop_id_list?: number[];
9
+ }
10
+ export type SetAppPushConfigResponse = FetchResponse<{
11
+ result: string;
12
+ }>;
13
+ export type LivePushStatus = 'Normal' | 'Warning' | 'Suspended';
14
+ export interface GetAppPushConfigResponse extends FetchResponse<{
15
+ callback_url: string;
16
+ live_push_status: LivePushStatus;
17
+ suspended_time?: number;
18
+ blocked_shop_id: number[];
19
+ push_config_on_list: PushConfigType[];
20
+ push_config_off_list: PushConfigType[];
21
+ }> {
22
+ }
23
+ /**
24
+ * Push message information
25
+ */
26
+ export type PushMessage = {
27
+ /** Shopee's unique identifier for a shop. Not returned for partner level push (such as code: 1, 2, 12) */
28
+ shop_id?: number;
29
+ /** Shopee's unique identifier for a push notification */
30
+ code: number;
31
+ /** Timestamp that indicates the message was lost */
32
+ timestamp: number;
33
+ /** Main Push message data as a JSON string */
34
+ data: string;
35
+ };
36
+ /**
37
+ * Parameters for confirming consumed lost push messages
38
+ */
39
+ export interface ConfirmConsumedLostPushMessageParams {
40
+ /** The last_message_id returned by getLostPushMessage */
41
+ last_message_id: number;
42
+ }
43
+ /**
44
+ * Response for the get lost push message API
45
+ */
46
+ export interface GetLostPushMessageResponse extends BaseResponse {
47
+ response: {
48
+ /** Returns the earliest 100 lost push messages that were lost within 3 days of the current time and not confirmed to have been consumed */
49
+ push_message_list: PushMessage[];
50
+ /** Indicates whether there are more than 100 lost push messages to be consumed. If true, you need to continue calling to get the remaining lost messages */
51
+ has_next_page: boolean;
52
+ /** Specifies the end entry of data returned in the current call */
53
+ last_message_id: number;
54
+ };
55
+ /** Indicate warning details if any warning occurred */
56
+ warning?: string;
57
+ }
58
+ /**
59
+ * Response for the confirm consumed lost push message API
60
+ */
61
+ export interface ConfirmConsumedLostPushMessageResponse extends BaseResponse {
62
+ /** Indicate warning details if any warning occurred */
63
+ warning?: string;
64
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=push.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push.js","sourceRoot":"","sources":["../../src/schemas/push.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ export declare enum ShopeeRegion {
2
+ GLOBAL = "GLOBAL",
3
+ CHINA = "CHINA",
4
+ BRAZIL = "BRAZIL",
5
+ TEST_GLOBAL = "TEST_GLOBAL",
6
+ TEST_CHINA = "TEST_CHINA"
7
+ }
8
+ export declare const SHOPEE_BASE_URLS: {
9
+ readonly GLOBAL: "https://partner.shopeemobile.com/api/v2";
10
+ readonly CHINA: "https://openplatform.shopee.cn/api/v2/public";
11
+ readonly BRAZIL: "https://openplatform.shopee.com.br/api/v2";
12
+ readonly TEST_GLOBAL: "https://partner.test-stable.shopeemobile.com/api/v2";
13
+ readonly TEST_CHINA: "https://openplatform.test-stable.shopee.cn/api/v2";
14
+ };
@@ -0,0 +1,16 @@
1
+ export var ShopeeRegion;
2
+ (function (ShopeeRegion) {
3
+ ShopeeRegion["GLOBAL"] = "GLOBAL";
4
+ ShopeeRegion["CHINA"] = "CHINA";
5
+ ShopeeRegion["BRAZIL"] = "BRAZIL";
6
+ ShopeeRegion["TEST_GLOBAL"] = "TEST_GLOBAL";
7
+ ShopeeRegion["TEST_CHINA"] = "TEST_CHINA";
8
+ })(ShopeeRegion || (ShopeeRegion = {}));
9
+ export const SHOPEE_BASE_URLS = {
10
+ [ShopeeRegion.GLOBAL]: 'https://partner.shopeemobile.com/api/v2',
11
+ [ShopeeRegion.CHINA]: 'https://openplatform.shopee.cn/api/v2/public',
12
+ [ShopeeRegion.BRAZIL]: 'https://openplatform.shopee.com.br/api/v2',
13
+ [ShopeeRegion.TEST_GLOBAL]: 'https://partner.test-stable.shopeemobile.com/api/v2',
14
+ [ShopeeRegion.TEST_CHINA]: 'https://openplatform.test-stable.shopee.cn/api/v2'
15
+ };
16
+ //# sourceMappingURL=region.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"region.js","sourceRoot":"","sources":["../../src/schemas/region.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,YAMX;AAND,WAAY,YAAY;IACtB,iCAAiB,CAAA;IACjB,+BAAe,CAAA;IACf,iCAAiB,CAAA;IACjB,2CAA2B,CAAA;IAC3B,yCAAyB,CAAA;AAC3B,CAAC,EANW,YAAY,KAAZ,YAAY,QAMvB;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,yCAAyC;IAChE,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,8CAA8C;IACpE,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,2CAA2C;IAClE,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,qDAAqD;IACjF,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,mDAAmD;CACtE,CAAC"}
@@ -0,0 +1,241 @@
1
+ import { BaseResponse } from "./base.js";
2
+ /**
3
+ * Status of vouchers for filtering in voucher list query
4
+ */
5
+ export declare enum VoucherStatus {
6
+ /** All vouchers regardless of status */
7
+ ALL = "all",
8
+ /** Vouchers that have not started yet */
9
+ UPCOMING = "upcoming",
10
+ /** Currently active vouchers */
11
+ ONGOING = "ongoing",
12
+ /** Vouchers that have ended */
13
+ EXPIRED = "expired"
14
+ }
15
+ /**
16
+ * Parameters for adding a new voucher
17
+ */
18
+ export type AddVoucherParams = {
19
+ /** The name of the voucher */
20
+ voucher_name: string;
21
+ /** The code of the voucher. Only support 0-9 or A-Z or a-z. Up to 5 characters */
22
+ voucher_code: string;
23
+ /** The timing from when the voucher is valid; so buyer is allowed to claim and to use */
24
+ start_time: number;
25
+ /** The timing until when the voucher is still valid */
26
+ end_time: number;
27
+ /** The type of the voucher. 1: shop voucher, 2: product voucher */
28
+ voucher_type: number;
29
+ /** The reward type of the voucher. 1: fix_amount voucher, 2: discount_percentage voucher, 3: coin_cashback voucher */
30
+ reward_type: number;
31
+ /** The number of times for this particular voucher could be used */
32
+ usage_quantity: number;
33
+ /** The minimum spend required for using this voucher */
34
+ min_basket_price: number;
35
+ /** The discount amount set for this particular voucher. Only for fix amount voucher */
36
+ discount_amount?: number;
37
+ /** The discount percentage set for this particular voucher. Only for discount percentage or coins cashback voucher */
38
+ percentage?: number;
39
+ /** The max amount of discount/value a user can enjoy by using this particular voucher. Only for discount percentage or coins cashback voucher */
40
+ max_price?: number;
41
+ /** The FE channel where the voucher will be displayed. 1: display_all, 3: feed, 4: live streaming, [] (empty - which is hidden) */
42
+ display_channel_list?: number[];
43
+ /** The list of items which is applicable for the voucher. Only for product type voucher */
44
+ item_id_list?: number[];
45
+ /** The timing of when voucher is displayed on shop pages; so buyer is allowed to claim */
46
+ display_start_time?: number;
47
+ };
48
+ /**
49
+ * Parameters for deleting a voucher
50
+ */
51
+ export type DeleteVoucherParams = {
52
+ /** The unique identifier for the voucher you want to delete */
53
+ voucher_id: number;
54
+ };
55
+ /**
56
+ * Parameters for ending a voucher immediately
57
+ */
58
+ export type EndVoucherParams = {
59
+ /** The unique identifier for the voucher you want to end now */
60
+ voucher_id: number;
61
+ };
62
+ /**
63
+ * Parameters for updating a voucher
64
+ */
65
+ export interface UpdateVoucherParams {
66
+ /** The unique identifier of the voucher which is going to be updated */
67
+ voucher_id: number;
68
+ /** The name of the voucher */
69
+ voucher_name?: string;
70
+ /** The timing from when the voucher is valid; so buyer is allowed to claim and to use. Can only be updated if voucher has not started */
71
+ start_time?: number;
72
+ /** The timing until when the voucher is still valid. For ongoing vouchers, can only be shortened, not extended */
73
+ end_time?: number;
74
+ /** The number of times for this particular voucher could be used. For ongoing vouchers, can only be increased */
75
+ usage_quantity?: number;
76
+ /** The minimum spend required for using this voucher */
77
+ min_basket_price?: number;
78
+ /** The discount amount set for this particular voucher. Only for fix amount voucher */
79
+ discount_amount?: number;
80
+ /** The discount percentage set for this particular voucher. Only for discount percentage or coins cashback voucher */
81
+ percentage?: number;
82
+ /** The max amount of discount/value a user can enjoy by using this particular voucher. Only for discount percentage or coins cashback voucher */
83
+ max_price?: number;
84
+ /** The FE channel where the voucher will be displayed. 1: display_all, 3: feed, 4: live streaming, [] (empty - which is hidden) */
85
+ display_channel_list?: number[];
86
+ /** The list of items which is applicable for the voucher. Only for product type voucher */
87
+ item_id_list?: number[];
88
+ /** The timing of when voucher is displayed on shop pages; so buyer is allowed to claim */
89
+ display_start_time?: number;
90
+ }
91
+ /**
92
+ * Parameters for getting voucher details
93
+ */
94
+ export type GetVoucherParams = {
95
+ /** The unique identifier of a voucher used to query the voucher details */
96
+ voucher_id: number;
97
+ };
98
+ /**
99
+ * Parameters for getting a list of vouchers
100
+ */
101
+ export type GetVoucherListParams = {
102
+ /** The status filter for retrieving voucher list */
103
+ status: VoucherStatus;
104
+ /** Specifies the page number of data to return. Default 1, range 1-5000 */
105
+ page_no?: number;
106
+ /** Maximum number of entries to retrieve per page. Default 20, range 1-100 */
107
+ page_size?: number;
108
+ };
109
+ /**
110
+ * Voucher information in the list response
111
+ */
112
+ export type VoucherInfo = {
113
+ /** The unique identifier for a voucher */
114
+ voucher_id: number;
115
+ /** Voucher Code */
116
+ voucher_code: string;
117
+ /** Voucher Name */
118
+ voucher_name: string;
119
+ /** The type of the voucher. 1: shop voucher, 2: product voucher */
120
+ voucher_type: number;
121
+ /** The reward type of the voucher. 1: fix_amount voucher, 2: discount_percentage voucher, 3: coin_cashback voucher */
122
+ reward_type: number;
123
+ /** The number of times for this particular voucher could be used */
124
+ usage_quantity: number;
125
+ /** Up till now, how many times has this particular voucher already been used */
126
+ current_usage: number;
127
+ /** The timing from when the voucher is valid; so buyer is allowed to claim and to use */
128
+ start_time: number;
129
+ /** The timing until when the voucher is still valid */
130
+ end_time: number;
131
+ /** If the voucher is created by Shopee or not */
132
+ is_admin: boolean;
133
+ /** The use case for the voucher. 0: normal, 1: welcome, 2: referral, 3: shop_follow, 4: shop_game, 5: free_gift, 6: membership */
134
+ voucher_purpose: number;
135
+ /** The discount amount set for this particular voucher. Only returned for fix amount voucher */
136
+ discount_amount?: number;
137
+ /** The discount percentage set for this particular voucher. Only returned for discount percentage or coins cashback voucher */
138
+ percentage?: number;
139
+ /** The voucher status in CMT. 1: review, 2: approved, 3: reject. Only returned when attending CMT campaign and not rejected */
140
+ cmt_voucher_status?: number;
141
+ /** The timing of when voucher is displayed on shop pages; so buyer is allowed to claim */
142
+ display_start_time?: number;
143
+ /** New user or repeat buyer voucher indication. 0: regular, 1: new user, 2: repeat buyer with 1 order, 3: repeat buyer with 2 orders */
144
+ target_voucher?: number;
145
+ };
146
+ /**
147
+ * Response for the add voucher API
148
+ */
149
+ export interface AddVoucherResponse extends BaseResponse {
150
+ response: {
151
+ /** The unique identifier for the created voucher */
152
+ voucher_id: number;
153
+ };
154
+ }
155
+ /**
156
+ * Response for the delete voucher API
157
+ */
158
+ export interface DeleteVoucherResponse extends BaseResponse {
159
+ response: {
160
+ /** The unique identifier for the voucher that was deleted */
161
+ voucher_id: number;
162
+ };
163
+ }
164
+ /**
165
+ * Response for the end voucher API
166
+ */
167
+ export interface EndVoucherResponse extends BaseResponse {
168
+ response: {
169
+ /** The unique identifier for the voucher that was ended */
170
+ voucher_id: number;
171
+ };
172
+ }
173
+ /**
174
+ * Response for the update voucher API
175
+ */
176
+ export interface UpdateVoucherResponse extends BaseResponse {
177
+ response: {
178
+ /** The unique identifier of the voucher which was updated */
179
+ voucher_id: number;
180
+ };
181
+ }
182
+ /**
183
+ * Response for the get voucher API
184
+ */
185
+ export interface GetVoucherResponse extends BaseResponse {
186
+ response: {
187
+ /** The unique identifier of the voucher whose details are returned */
188
+ voucher_id: number;
189
+ /** Voucher Code */
190
+ voucher_code: string;
191
+ /** Voucher Name */
192
+ voucher_name: string;
193
+ /** The type of the voucher. 1: shop voucher, 2: product voucher */
194
+ voucher_type: number;
195
+ /** The reward type of the voucher. 1: fix_amount voucher, 2: discount_percentage voucher, 3: coin_cashback voucher */
196
+ reward_type: number;
197
+ /** The number of times for this particular voucher could be used */
198
+ usage_quantity: number;
199
+ /** Up till now, how many times has this particular voucher already been used */
200
+ current_usage: number;
201
+ /** The timing from when the voucher is valid; so buyer is allowed to claim and to use */
202
+ start_time: number;
203
+ /** The timing until when the voucher is still valid */
204
+ end_time: number;
205
+ /** If the voucher is created by Shopee or not */
206
+ is_admin: boolean;
207
+ /** The use case for the voucher. 0: normal, 1: welcome, 2: referral, 3: shop_follow, 4: shop_game, 5: free_gift, 6: membership, 7: Ads */
208
+ voucher_purpose: number;
209
+ /** The FE channel where the voucher will be displayed. 1: display_all, 2: order page, 3: feed, 4: live streaming, [] (empty - which is hidden) */
210
+ display_channel_list: number[];
211
+ /** The minimum spend required for using this voucher */
212
+ min_basket_price: number;
213
+ /** The discount percentage set for this particular voucher. Only returned for discount percentage or coins cashback voucher */
214
+ percentage?: number;
215
+ /** The max amount of discount/value a user can enjoy by using this particular voucher. Only returned for discount percentage or coins cashback voucher */
216
+ max_price?: number;
217
+ /** The discount amount set for this particular voucher. Only returned for fix amount voucher */
218
+ discount_amount?: number;
219
+ /** The voucher status in CMT. 1: review, 2: approved, 3: reject. Only returned when attending CMT campaign and not rejected */
220
+ cmt_voucher_status?: number;
221
+ /** The list of items which is applicable for the voucher. Only returned for product type voucher */
222
+ item_id_list?: number[];
223
+ /** The timing of when voucher is displayed on shop pages; so buyer is allowed to claim */
224
+ display_start_time?: number;
225
+ /** The field to mark voucher type. 1: new user voucher, 2: repeat buyer voucher with 1 order, 3: repeat buyer voucher with 2 orders */
226
+ target_voucher?: number;
227
+ /** Indicates specific business scenario. 1: shop voucher, 2: product voucher, 3: new buyer voucher, 4: repeat buyer voucher, 5: private voucher, 6: live voucher, 7: video voucher, 8: campaign voucher, 9: follow prize voucher, 10: membership voucher, 11: game prize voucher, 12: sample voucher */
228
+ usecase?: number;
229
+ };
230
+ }
231
+ /**
232
+ * Response for the get voucher list API
233
+ */
234
+ export interface GetVoucherListResponse extends BaseResponse {
235
+ response: {
236
+ /** Indicates whether there are more pages of vouchers to retrieve */
237
+ more: boolean;
238
+ /** The list of vouchers matching the query parameters */
239
+ voucher_list: VoucherInfo[];
240
+ };
241
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Status of vouchers for filtering in voucher list query
3
+ */
4
+ export var VoucherStatus;
5
+ (function (VoucherStatus) {
6
+ /** All vouchers regardless of status */
7
+ VoucherStatus["ALL"] = "all";
8
+ /** Vouchers that have not started yet */
9
+ VoucherStatus["UPCOMING"] = "upcoming";
10
+ /** Currently active vouchers */
11
+ VoucherStatus["ONGOING"] = "ongoing";
12
+ /** Vouchers that have ended */
13
+ VoucherStatus["EXPIRED"] = "expired";
14
+ })(VoucherStatus || (VoucherStatus = {}));
15
+ //# sourceMappingURL=voucher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voucher.js","sourceRoot":"","sources":["../../src/schemas/voucher.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAN,IAAY,aASX;AATD,WAAY,aAAa;IACrB,wCAAwC;IACxC,4BAAW,CAAA;IACX,yCAAyC;IACzC,sCAAqB,CAAA;IACrB,gCAAgC;IAChC,oCAAmB,CAAA;IACnB,+BAA+B;IAC/B,oCAAmB,CAAA;AACvB,CAAC,EATW,aAAa,KAAb,aAAa,QASxB"}
package/lib/sdk.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ import { ProductManager } from './managers/product.manager.js';
2
+ import { OrderManager } from './managers/order.manager.js';
3
+ import { AuthManager } from './managers/auth.manager.js';
4
+ import { ShopeeRegion } from './schemas/region.js';
5
+ import { TokenStorage } from './storage/token-storage.interface.js';
6
+ import { AccessToken } from './schemas/access-token.js';
7
+ import { PublicManager } from './managers/public.manager.js';
8
+ import { PushManager } from './managers/push.manager.js';
9
+ import { PaymentManager } from './managers/payment.manager.js';
10
+ import { LogisticsManager } from './managers/logistics.manager.js';
11
+ import { VoucherManager } from './managers/voucher.manager.js';
12
+ import { AdsManager } from './managers/ads.manager.js';
13
+ export interface ShopeeConfig {
14
+ partner_id: number;
15
+ partner_key: string;
16
+ region?: ShopeeRegion;
17
+ base_url?: string;
18
+ sdk?: ShopeeSDK;
19
+ shop_id?: number;
20
+ }
21
+ export declare class ShopeeSDK {
22
+ private config;
23
+ private tokenStorage;
24
+ readonly ads: AdsManager;
25
+ readonly product: ProductManager;
26
+ readonly order: OrderManager;
27
+ readonly auth: AuthManager;
28
+ readonly public: PublicManager;
29
+ readonly push: PushManager;
30
+ readonly payment: PaymentManager;
31
+ readonly logistics: LogisticsManager;
32
+ readonly voucher: VoucherManager;
33
+ constructor(config: ShopeeConfig, tokenStorage?: TokenStorage);
34
+ getConfig(): ShopeeConfig;
35
+ setRegion(region: ShopeeRegion): void;
36
+ setBaseUrl(baseUrl: string): void;
37
+ getAuthorizationUrl(redirect_uri: string): string;
38
+ authenticateWithCode(code: string, shopId?: number, mainAccountId?: number): Promise<AccessToken | null>;
39
+ getAuthToken(): Promise<AccessToken | null>;
40
+ refreshToken(shop_id?: number, merchant_id?: number): Promise<AccessToken | null>;
41
+ }
42
+ export default ShopeeSDK;
package/lib/sdk.js ADDED
@@ -0,0 +1,77 @@
1
+ import { ProductManager } from './managers/product.manager.js';
2
+ import { OrderManager } from './managers/order.manager.js';
3
+ import { AuthManager } from './managers/auth.manager.js';
4
+ import { ShopeeRegion, SHOPEE_BASE_URLS } from './schemas/region.js';
5
+ import { CustomTokenStorage } from './storage/custom-token-storage.js';
6
+ import { ShopeeSdkError } from './errors.js';
7
+ import { PublicManager } from './managers/public.manager.js';
8
+ import { PushManager } from './managers/push.manager.js';
9
+ import { generateSignature } from './utils/signature.js';
10
+ import { PaymentManager } from './managers/payment.manager.js';
11
+ import { LogisticsManager } from './managers/logistics.manager.js';
12
+ import { VoucherManager } from './managers/voucher.manager.js';
13
+ import { AdsManager } from './managers/ads.manager.js';
14
+ export class ShopeeSDK {
15
+ constructor(config, tokenStorage) {
16
+ this.config = {
17
+ region: ShopeeRegion.GLOBAL,
18
+ ...config,
19
+ base_url: config.base_url ||
20
+ (config.region ? SHOPEE_BASE_URLS[config.region] : SHOPEE_BASE_URLS[ShopeeRegion.GLOBAL]),
21
+ sdk: this,
22
+ };
23
+ // Initialize token storage
24
+ this.tokenStorage = tokenStorage || new CustomTokenStorage(config.shop_id);
25
+ // Initialize managers
26
+ this.ads = new AdsManager(this.config);
27
+ this.product = new ProductManager(this.config);
28
+ this.order = new OrderManager(this.config);
29
+ this.auth = new AuthManager(this.config);
30
+ this.public = new PublicManager(this.config);
31
+ this.push = new PushManager(this.config);
32
+ this.payment = new PaymentManager(this.config);
33
+ this.logistics = new LogisticsManager(this.config);
34
+ this.voucher = new VoucherManager(this.config);
35
+ }
36
+ getConfig() {
37
+ return this.config;
38
+ }
39
+ setRegion(region) {
40
+ this.config.region = region;
41
+ this.config.base_url = SHOPEE_BASE_URLS[region];
42
+ }
43
+ setBaseUrl(baseUrl) {
44
+ this.config.base_url = baseUrl;
45
+ this.config.region = undefined;
46
+ }
47
+ getAuthorizationUrl(redirect_uri) {
48
+ const timestamp = Math.floor(Date.now() / 1000);
49
+ return `${this.config.base_url}/shop/auth_partner?partner_id=${this.config.partner_id}&timestamp=${timestamp}&redirect=${redirect_uri}&sign=${generateSignature(this.config.partner_key, [
50
+ this.config.partner_id.toString(),
51
+ '/api/v2/shop/auth_partner',
52
+ timestamp.toString()
53
+ ])}`;
54
+ }
55
+ async authenticateWithCode(code, shopId, mainAccountId) {
56
+ const token = await this.auth.getAccessToken(code, shopId, mainAccountId);
57
+ await this.tokenStorage.store(token);
58
+ return token;
59
+ }
60
+ async getAuthToken() {
61
+ return this.tokenStorage.get();
62
+ }
63
+ async refreshToken(shop_id, merchant_id) {
64
+ const old_token = await this.tokenStorage.get();
65
+ if (!old_token) {
66
+ throw new ShopeeSdkError('No token found to refresh');
67
+ }
68
+ const token = await this.auth.getRefreshToken(old_token.refresh_token, shop_id ?? old_token.shop_id, merchant_id);
69
+ if (!token) {
70
+ return null;
71
+ }
72
+ await this.tokenStorage.store(token);
73
+ return token;
74
+ }
75
+ }
76
+ export default ShopeeSDK;
77
+ //# sourceMappingURL=sdk.js.map
package/lib/sdk.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk.js","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,E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CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE;YACjC,2BAA2B;YAC3B,SAAS,CAAC,QAAQ,EAAE;SACrB,CACF,EAAE,CAAC;IACN,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAC/B,IAAY,EACZ,MAAe,EACf,aAAsB;QAEtB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;QAC1E,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrC,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,YAAY;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;IACjC,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,OAAgB,EAAE,WAAoB;QAC9D,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;QAChD,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,cAAc,CAAC,2BAA2B,CAAC,CAAC;QACxD,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,CAC3C,SAAS,CAAC,aAAa,EACvB,OAAO,IAAI,SAAS,CAAC,OAAO,EAC5B,WAAW,CACZ,CAAC;QACF,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,eAAe,SAAS,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { AccessToken } from '../schemas/access-token.js';
2
+ import { TokenStorage } from './token-storage.interface.js';
3
+ export declare class CustomTokenStorage implements TokenStorage {
4
+ private readonly tokenPath;
5
+ private readonly defaultTokenPath;
6
+ constructor(shopId?: number);
7
+ store(token: AccessToken): Promise<void>;
8
+ get(): Promise<AccessToken | null>;
9
+ clear(): Promise<void>;
10
+ }
@@ -0,0 +1,47 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ export class CustomTokenStorage {
4
+ constructor(shopId) {
5
+ // create a folder in the root of the project called .token
6
+ const tokenDir = path.join(process.cwd(), '.token');
7
+ if (!fs.existsSync(tokenDir)) {
8
+ fs.mkdirSync(tokenDir, { recursive: true });
9
+ }
10
+ this.defaultTokenPath = path.join(tokenDir, 'default.json');
11
+ this.tokenPath = path.join(tokenDir, `${shopId ?? 'default'}.json`);
12
+ }
13
+ async store(token) {
14
+ try {
15
+ fs.writeFileSync(this.tokenPath, JSON.stringify(token, null, 2));
16
+ if (this.defaultTokenPath !== this.tokenPath && !fs.existsSync(this.defaultTokenPath)) {
17
+ fs.writeFileSync(this.defaultTokenPath, JSON.stringify(token, null, 2));
18
+ }
19
+ }
20
+ catch (error) {
21
+ throw new Error(`Failed to store token: ${error instanceof Error ? error.message : 'Unknown error'}`);
22
+ }
23
+ }
24
+ async get() {
25
+ try {
26
+ const data = fs.readFileSync(this.tokenPath, 'utf-8');
27
+ return JSON.parse(data);
28
+ }
29
+ catch (error) {
30
+ if (error.code === 'ENOENT') {
31
+ return null;
32
+ }
33
+ throw new Error(`Failed to get token: ${error instanceof Error ? error.message : 'Unknown error'}`);
34
+ }
35
+ }
36
+ async clear() {
37
+ try {
38
+ fs.unlinkSync(this.tokenPath);
39
+ }
40
+ catch (error) {
41
+ if (error.code !== 'ENOENT') {
42
+ throw new Error(`Failed to clear token: ${error instanceof Error ? error.message : 'Unknown error'}`);
43
+ }
44
+ }
45
+ }
46
+ }
47
+ //# sourceMappingURL=custom-token-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-token-storage.js","sourceRoot":"","sources":["../../src/storage/custom-token-storage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM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AAC;YACH,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YACtD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAgB,CAAC;QACzC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACvD,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,wBAAwB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;QACtG,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,IAAI,CAAC;YACH,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAChC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACvD,MAAM,IAAI,KAAK,CAAC,0BAA0B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;YACxG,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import { AccessToken } from '../schemas/access-token.js';
2
+ export interface TokenStorage {
3
+ store(token: AccessToken): Promise<void>;
4
+ get(): Promise<AccessToken | null>;
5
+ clear(): Promise<void>;
6
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=token-storage.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-storage.interface.js","sourceRoot":"","sources":["../../src/storage/token-storage.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export declare function generateSignature(partnerKey: string, parts: string[]): string;
@@ -0,0 +1,9 @@
1
+ import crypto from 'crypto';
2
+ export function generateSignature(partnerKey, parts) {
3
+ const baseString = parts.join('');
4
+ return crypto
5
+ .createHmac('sha256', partnerKey)
6
+ .update(baseString)
7
+ .digest('hex');
8
+ }
9
+ //# sourceMappingURL=signature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature.js","sourceRoot":"","sources":["../../src/utils/signature.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,MAAM,UAAU,iBAAiB,CAC/B,UAAkB,EAClB,KAAe;IAEf,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClC,OAAO,MAAM;SACV,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC;SAChC,MAAM,CAAC,UAAU,CAAC;SAClB,MAAM,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC"}