@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Minh Nguyen Cong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # Shopee SDK
2
+
3
+ A TypeScript SDK for interacting with the Shopee Open API, maintained by the community.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install shopee-sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { ShopeeClient } from 'shopee-sdk';
15
+
16
+ // Initialize the client
17
+ const client = new ShopeeClient({
18
+ partner_id: 123456,
19
+ partner_key: 'your-partner-key',
20
+ base_url: 'https://partner.test-stable.shopeemobile.com', // For sandbox
21
+ // base_url: 'https://partner.shopeemobile.com', // For production
22
+ });
23
+
24
+ // Authenticate (if working with shop-level APIs)
25
+ await client.auth.getToken({
26
+ code: 'authorization-code',
27
+ shop_id: 123456,
28
+ });
29
+
30
+ // Example: Get product list
31
+ const products = await client.product.getItemList({
32
+ offset: 0,
33
+ page_size: 10,
34
+ });
35
+
36
+ // Example: Add a voucher
37
+ const voucher = await client.voucher.addVoucher({
38
+ voucher_name: "Special Discount",
39
+ voucher_code: "SAVE10",
40
+ start_time: Math.floor(Date.now() / 1000),
41
+ end_time: Math.floor(Date.now() / 1000) + 7 * 24 * 60 * 60, // 7 days
42
+ voucher_type: 1, // shop voucher
43
+ reward_type: 1, // fixed amount
44
+ usage_quantity: 100,
45
+ min_basket_price: 20,
46
+ discount_amount: 10
47
+ });
48
+
49
+ // Example: Get lost push messages (partner-level API, no auth required)
50
+ const lostMessages = await client.push.getLostPushMessage();
51
+ ```
52
+
53
+ ## Features
54
+
55
+ - TypeScript support with full type definitions
56
+ - Support for all Shopee Open API endpoints
57
+ - Authentication flow helpers
58
+ - Automatic token refresh
59
+
60
+ ## Contributing
61
+
62
+ We use [Conventional Commits](https://www.conventionalcommits.org/) for commit messages to automate versioning and release notes.
63
+
64
+ Examples of commit messages:
65
+
66
+ - `feat: add support for logistics API` - Minor version bump
67
+ - `fix: correct error handling in order API` - Patch version bump
68
+ - `docs: update API documentation` - No version bump
69
+ - `feat!: rename parameters in product API` or `feat: rename parameters in product API BREAKING CHANGE: ...` - Major version bump
70
+
71
+ ## Release Process
72
+
73
+ This project uses [Release Please](https://github.com/googleapis/release-please) to automate version management and releases.
74
+
75
+ The release process follows these steps:
76
+ 1. Commits to the main branch are automatically analyzed
77
+ 2. When conventional commit messages are detected, Release Please creates or updates a release PR
78
+ 3. When the release PR is merged:
79
+ - A new GitHub tag and release is created
80
+ - The package is automatically published to npm
81
+ - The CHANGELOG.md is updated with the release notes
82
+
83
+ ## License
84
+
85
+ MIT
@@ -0,0 +1,8 @@
1
+ export declare class ShopeeSdkError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare class ShopeeApiError extends Error {
5
+ readonly status: number;
6
+ readonly data: unknown;
7
+ constructor(status: number, data: unknown);
8
+ }
package/lib/errors.js ADDED
@@ -0,0 +1,15 @@
1
+ export class ShopeeSdkError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = 'ShopeeSdkError';
5
+ }
6
+ }
7
+ export class ShopeeApiError extends Error {
8
+ constructor(status, data) {
9
+ super(`API Error: ${status} - ${JSON.stringify(data)}`);
10
+ this.name = 'ShopeeApiError';
11
+ this.status = status;
12
+ this.data = data;
13
+ }
14
+ }
15
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,KAAK;IAIvC,YAAY,MAAc,EAAE,IAAa;QACvC,KAAK,CAAC,cAAc,MAAM,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
package/lib/fetch.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { ShopeeConfig } from './sdk.js';
2
+ import { FetchOptions } from './schemas/fetch.js';
3
+ export declare class ShopeeFetch {
4
+ static fetch<T>(config: ShopeeConfig, path: string, options?: FetchOptions): Promise<T>;
5
+ }
package/lib/fetch.js ADDED
@@ -0,0 +1,105 @@
1
+ import fetch, { Headers } from 'node-fetch';
2
+ import { ShopeeApiError, ShopeeSdkError } from './errors.js';
3
+ import { generateSignature } from './utils/signature.js';
4
+ export class ShopeeFetch {
5
+ static async fetch(config, path, options = {}) {
6
+ const { method = 'GET', params = {}, body, ...restOptions } = options;
7
+ const url = new URL(`${config.base_url}${path}`);
8
+ // Add required parameters
9
+ const timestamp = Math.floor(Date.now() / 1000);
10
+ let signature = generateSignature(config.partner_key, [
11
+ config.partner_id.toString(),
12
+ url.pathname,
13
+ timestamp.toString(),
14
+ ]);
15
+ // Add query parameters
16
+ Object.keys(params).forEach((key) => (params[key] === undefined ? delete params[key] : {}));
17
+ const allParams = {
18
+ partner_id: config.partner_id,
19
+ timestamp,
20
+ ...params,
21
+ };
22
+ let authParams = {};
23
+ if (options.auth) {
24
+ const token = await config.sdk?.getAuthToken();
25
+ if (!token) {
26
+ throw new ShopeeSdkError('No access token found');
27
+ }
28
+ authParams = {
29
+ access_token: token?.access_token,
30
+ shop_id: token?.shop_id,
31
+ };
32
+ signature = generateSignature(config.partner_key, [
33
+ config.partner_id.toString(),
34
+ url.pathname,
35
+ timestamp.toString(),
36
+ token?.access_token,
37
+ token?.shop_id.toString(),
38
+ ]);
39
+ }
40
+ Object.entries({ ...allParams, ...authParams, sign: signature }).forEach(([key, value]) => {
41
+ if (Array.isArray(value)) {
42
+ value.forEach(item => {
43
+ url.searchParams.append(key, String(item));
44
+ });
45
+ }
46
+ else {
47
+ url.searchParams.append(key, String(value));
48
+ }
49
+ });
50
+ // Prepare headers
51
+ const headers = new Headers();
52
+ headers.set('Content-Type', 'application/json');
53
+ if (options.headers) {
54
+ Object.entries(options.headers).forEach(([key, value]) => {
55
+ headers.set(key, value);
56
+ });
57
+ }
58
+ // Prepare fetch options
59
+ const requestOptions = {
60
+ method,
61
+ headers: headers,
62
+ body: body ? JSON.stringify(body) : undefined,
63
+ };
64
+ try {
65
+ const response = await fetch(url.toString(), requestOptions);
66
+ const responseType = response.headers.get('Content-Type');
67
+ const responseData = responseType?.indexOf('application/json') !== -1
68
+ ? await response.json()
69
+ : await response.text();
70
+ if (responseType?.indexOf('application/json') !== -1) {
71
+ if (responseData.error) {
72
+ // Handle invalid access token error
73
+ if (responseData.error === 'invalid_acceess_token' && options.auth) {
74
+ try {
75
+ // Attempt to refresh the access token
76
+ await config.sdk?.refreshToken();
77
+ // Retry the request with the new token
78
+ return this.fetch(config, path, options);
79
+ }
80
+ catch (refreshError) {
81
+ // If refresh fails, throw the original error
82
+ throw new ShopeeApiError(response.status, responseData);
83
+ }
84
+ }
85
+ throw new ShopeeApiError(response.status, responseData);
86
+ }
87
+ const data = responseData;
88
+ return data;
89
+ }
90
+ throw new ShopeeSdkError(`Unknown response type: ${responseType}\n${responseData}`);
91
+ }
92
+ catch (error) {
93
+ if (error instanceof Error) {
94
+ if (error.name === 'FetchError') {
95
+ // Network error
96
+ throw new ShopeeSdkError(`Network error: ${error.message}`);
97
+ }
98
+ // Other errors
99
+ throw new ShopeeSdkError(`Unexpected error: ${error.message}`);
100
+ }
101
+ throw new ShopeeSdkError('Unknown error occurred');
102
+ }
103
+ }
104
+ }
105
+ //# sourceMappingURL=fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAyB,OAAO,EAAe,MAAM,YAAY,CAAC;AAGhF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,MAAM,OAAO,WAAW;IACf,MAAM,CAAC,KAAK,CAAC,KAAK,CACvB,MAAoB,EACpB,IAAY,EACZ,UAAwB,EAAE;QAE1B,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,MAAM,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO,CAAC;QACtE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,GAAG,IAAI,EAAE,CAAC,CAAC;QACjD,0BAA0B;QAC1B,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;QAChD,IAAI,SAAS,GAAG,iBAAiB,CAAC,MAAM,CAAC,WAAW,EAAE;YACpD,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE;YAC5B,GAAG,CAAC,QAAQ;YACZ,SAAS,CAAC,QAAQ,EAAE;SACrB,CAAC,CAAC;QAEH,uBAAuB;QACvB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5F,MAAM,SAAS,GAAG;YAChB,UAAU,EAA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EAAE,YAAY,EAAE,CAAC;4BACjC,uCAAuC;4BACvC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;wBAC3C,CAAC;wBAAC,OAAO,YAAY,EAAE,CAAC;4BACtB,6CAA6C;4BAC7C,MAAM,IAAI,cAAc,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;wBAC1D,CAAC;oBACH,CAAC;oBACD,MAAM,IAAI,cAAc,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;gBAC1D,CAAC;gBAED,MAAM,IAAI,GAAG,YAAiB,CAAC;gBAC/B,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,IAAI,cAAc,CAAC,0BAA0B,YAAY,KAAK,YAAY,EAAE,CAAC,CAAC;QACtF,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;gBAC3B,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;oBAChC,gBAAgB;oBAChB,MAAM,IAAI,cAAc,CAAC,kBAAkB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBAC9D,CAAC;gBACD,eAAe;gBACf,MAAM,IAAI,cAAc,CAAC,qBAAqB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACjE,CAAC;YACD,MAAM,IAAI,cAAc,CAAC,wBAAwB,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,53 @@
1
+ import { ShopeeConfig } from "../sdk.js";
2
+ import { BaseManager } from "./base.manager.js";
3
+ import { GetTotalBalanceResponse, GetShopToggleInfoResponse, GetRecommendedKeywordListParams, GetRecommendedKeywordListResponse } from "../schemas/ads.js";
4
+ export declare class AdsManager extends BaseManager {
5
+ constructor(config: ShopeeConfig);
6
+ /**
7
+ * Get seller's real-time total balance of ads credit
8
+ * @returns {Promise<GetTotalBalanceResponse>} Response containing the total balance and timestamp
9
+ *
10
+ * This API returns the seller's real-time total balance of their ads credit,
11
+ * including both paid credits and free credits.
12
+ *
13
+ * The response includes:
14
+ * - data_timestamp: The time when the balance snapshot was taken
15
+ * - total_balance: The total ads credit balance
16
+ *
17
+ * Note: This balance is real-time and represents the current available credit
18
+ * that can be used for advertising campaigns.
19
+ */
20
+ getTotalBalance(): Promise<GetTotalBalanceResponse>;
21
+ /**
22
+ * Get seller's toggle status information at the shop level
23
+ * @returns {Promise<GetShopToggleInfoResponse>} Response containing toggle statuses
24
+ *
25
+ * This API returns the seller's toggle status information indicating whether
26
+ * certain features are enabled or disabled at the shop level.
27
+ *
28
+ * The response includes:
29
+ * - data_timestamp: The time when the information was retrieved
30
+ * - auto_top_up: Whether automatic top-up is enabled (true) or disabled (false)
31
+ * - campaign_surge: Whether campaign surge is enabled (true) or disabled (false)
32
+ *
33
+ * These settings affect how ads campaigns are managed and funded.
34
+ */
35
+ getShopToggleInfo(): Promise<GetShopToggleInfoResponse>;
36
+ /**
37
+ * Get the list of recommended keywords for an item
38
+ * @param {GetRecommendedKeywordListParams} params Request parameters
39
+ * @param {number} params.item_id Shopee's unique identifier for an item
40
+ * @param {string} [params.input_keyword] The keyword seller typed in the manually add keyword window
41
+ * @returns {Promise<GetRecommendedKeywordListResponse>} Response containing recommended keywords
42
+ *
43
+ * This API is used to get the list of recommended keywords by item and optionally a search keyword.
44
+ *
45
+ * The response includes:
46
+ * - item_id: The item ID for which keywords are recommended
47
+ * - input_keyword: The keyword provided in the request (if any)
48
+ * - suggested_keywords: List of suggested keywords with quality score, search volume, and suggested bid
49
+ *
50
+ * Use this API to get keyword suggestions to improve item discoverability in search results.
51
+ */
52
+ getRecommendedKeywordList(params: GetRecommendedKeywordListParams): Promise<GetRecommendedKeywordListResponse>;
53
+ }
@@ -0,0 +1,74 @@
1
+ import { BaseManager } from "./base.manager.js";
2
+ import { ShopeeFetch } from "../fetch.js";
3
+ export class AdsManager extends BaseManager {
4
+ constructor(config) {
5
+ super(config);
6
+ }
7
+ /**
8
+ * Get seller's real-time total balance of ads credit
9
+ * @returns {Promise<GetTotalBalanceResponse>} Response containing the total balance and timestamp
10
+ *
11
+ * This API returns the seller's real-time total balance of their ads credit,
12
+ * including both paid credits and free credits.
13
+ *
14
+ * The response includes:
15
+ * - data_timestamp: The time when the balance snapshot was taken
16
+ * - total_balance: The total ads credit balance
17
+ *
18
+ * Note: This balance is real-time and represents the current available credit
19
+ * that can be used for advertising campaigns.
20
+ */
21
+ async getTotalBalance() {
22
+ const response = await ShopeeFetch.fetch(this.config, '/ads/get_total_balance', {
23
+ method: 'GET',
24
+ auth: true,
25
+ });
26
+ return response;
27
+ }
28
+ /**
29
+ * Get seller's toggle status information at the shop level
30
+ * @returns {Promise<GetShopToggleInfoResponse>} Response containing toggle statuses
31
+ *
32
+ * This API returns the seller's toggle status information indicating whether
33
+ * certain features are enabled or disabled at the shop level.
34
+ *
35
+ * The response includes:
36
+ * - data_timestamp: The time when the information was retrieved
37
+ * - auto_top_up: Whether automatic top-up is enabled (true) or disabled (false)
38
+ * - campaign_surge: Whether campaign surge is enabled (true) or disabled (false)
39
+ *
40
+ * These settings affect how ads campaigns are managed and funded.
41
+ */
42
+ async getShopToggleInfo() {
43
+ const response = await ShopeeFetch.fetch(this.config, '/ads/get_shop_toggle_info', {
44
+ method: 'GET',
45
+ auth: true,
46
+ });
47
+ return response;
48
+ }
49
+ /**
50
+ * Get the list of recommended keywords for an item
51
+ * @param {GetRecommendedKeywordListParams} params Request parameters
52
+ * @param {number} params.item_id Shopee's unique identifier for an item
53
+ * @param {string} [params.input_keyword] The keyword seller typed in the manually add keyword window
54
+ * @returns {Promise<GetRecommendedKeywordListResponse>} Response containing recommended keywords
55
+ *
56
+ * This API is used to get the list of recommended keywords by item and optionally a search keyword.
57
+ *
58
+ * The response includes:
59
+ * - item_id: The item ID for which keywords are recommended
60
+ * - input_keyword: The keyword provided in the request (if any)
61
+ * - suggested_keywords: List of suggested keywords with quality score, search volume, and suggested bid
62
+ *
63
+ * Use this API to get keyword suggestions to improve item discoverability in search results.
64
+ */
65
+ async getRecommendedKeywordList(params) {
66
+ const response = await ShopeeFetch.fetch(this.config, '/ads/get_recommended_keyword_list', {
67
+ method: 'GET',
68
+ auth: true,
69
+ params,
70
+ });
71
+ return response;
72
+ }
73
+ }
74
+ //# sourceMappingURL=ads.manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ads.manager.js","sourceRoot":"","sources":["../../src/managers/ads.manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,OAAO,UAAW,SAAQ,WAAW;IACvC,YAAY,MAAoB;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,eAAe;QACnB,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,KAAK,CACtC,IAAI,CAAC,MAAM,EACX,wBAAwB,EACxB;YACE,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,IAAI;SACX,CACF,CAAC;QAEF,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,iBAAiB;QACrB,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,KAAK,CACtC,IAAI,CAAC,MAAM,EACX,2BAA2B,EAC3B;YACE,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,IAAI;SACX,CACF,CAAC;QAEF,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,yBAAyB,CAAC,MAAuC;QACrE,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,KAAK,CACtC,IAAI,CAAC,MAAM,EACX,mCAAmC,EACnC;YACE,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,IAAI;YACV,MAAM;SACP,CACF,CAAC;QAEF,OAAO,QAAQ,CAAC;IAClB,CAAC;CACJ"}
@@ -0,0 +1,9 @@
1
+ import { ShopeeConfig } from '../sdk.js';
2
+ import { AccessToken } from '../schemas/access-token.js';
3
+ import { BaseManager } from './base.manager.js';
4
+ export declare class AuthManager extends BaseManager {
5
+ constructor(config: ShopeeConfig);
6
+ getAccessToken(code: string, shopId?: number, mainAccountId?: number): Promise<AccessToken>;
7
+ getAccessTokenByResendCode(code: string): Promise<AccessToken>;
8
+ getRefreshToken(refreshToken: string, shopId?: number, merchantId?: number): Promise<AccessToken>;
9
+ }
@@ -0,0 +1,58 @@
1
+ import { ShopeeFetch } from '../fetch.js';
2
+ import { BaseManager } from './base.manager.js';
3
+ export class AuthManager extends BaseManager {
4
+ constructor(config) {
5
+ super(config);
6
+ }
7
+ async getAccessToken(code, shopId, mainAccountId) {
8
+ const body = {
9
+ code,
10
+ partner_id: this.config.partner_id,
11
+ };
12
+ if (shopId) {
13
+ body.shop_id = shopId;
14
+ }
15
+ if (mainAccountId) {
16
+ body.main_account_id = mainAccountId;
17
+ }
18
+ const response = await ShopeeFetch.fetch(this.config, '/auth/token/get', {
19
+ method: 'POST',
20
+ body,
21
+ });
22
+ return {
23
+ ...response,
24
+ shop_id: shopId
25
+ };
26
+ }
27
+ async getAccessTokenByResendCode(code) {
28
+ const body = {
29
+ resend_code: code,
30
+ };
31
+ const response = await ShopeeFetch.fetch(this.config, '/public/get_token_by_resend_code', {
32
+ method: 'POST',
33
+ body
34
+ });
35
+ return response;
36
+ }
37
+ async getRefreshToken(refreshToken, shopId, merchantId) {
38
+ const body = {
39
+ partner_id: this.config.partner_id,
40
+ refresh_token: refreshToken,
41
+ };
42
+ if (shopId) {
43
+ body.shop_id = shopId;
44
+ }
45
+ if (merchantId) {
46
+ body.merchant_id = merchantId;
47
+ }
48
+ const response = await ShopeeFetch.fetch(this.config, '/auth/access_token/get', {
49
+ method: 'POST',
50
+ body
51
+ });
52
+ return {
53
+ ...response,
54
+ shop_id: shopId
55
+ };
56
+ }
57
+ }
58
+ //# sourceMappingURL=auth.manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.manager.js","sourceRoot":"","sources":["../../src/managers/auth.manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,OAAO,WAAY,SAAQ,WAAW;IAC1C,YAAY,MAAoB;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAEM,KAAK,CAAC,cAAc,CACzB,IAAY,EACZ,MAAe,EACf,aAAsB;QAEtB,MAAM,IAAI,GAA8C;YACtD,IAAI;YACJ,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU;SACnC,CAAC;QAEF,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACxB,CAAC;QAED,IAAI,aAAa,EAAE,CAAC;YAClB,IAAI,CAAC,eAAe,GAAG,aAAa,CAAC;QACvC,CAAC;QAED,MAAM,QAAQ,GAAgB,MAAM,WAAW,CAAC,KAAK,CAAc,IAAI,CAAC,MAAM,EAAE,iBAAiB,EAAE;YACjG,MAAM,EAAE,MAAM;YACd,IAAI;SACL,CAAC,CAAC;QAEH,OAAO;YACL,GAAG,QAAQ;YACX,OAAO,EAAE,MAAM;SAChB,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,0BAA0B,CAAC,IAAY;QAClD,MAAM,IAAI,GAA8C;YACtD,WAAW,EAAE,IAAI;SAClB,CAAC;QAEF,MAAM,QAAQ,GAAgB,MAAM,WAAW,CAAC,KAAK,CAAc,IAAI,CAAC,MAAM,EAAE,kCAAkC,EAAE;YAClH,MAAM,EAAE,MAAM;YACd,IAAI;SACL,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,YAAoB,EAAE,MAAe,EAAE,UAAmB;QACrF,MAAM,IAAI,GAA8C;YACtD,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,aAAa,EAAE,YAAY;SAC5B,CAAC;QAEF,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACxB,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAChC,CAAC;QAED,MAAM,QAAQ,GAAgB,MAAM,WAAW,CAAC,KAAK,CAAc,IAAI,CAAC,MAAM,EAAE,wBAAwB,EAAE;YACxG,MAAM,EAAE,MAAM;YACd,IAAI;SACL,CAAC,CAAC;QAGH,OAAO;YACL,GAAG,QAAQ;YACX,OAAO,EAAE,MAAM;SAChB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import { ShopeeConfig } from '../sdk.js';
2
+ export declare abstract class BaseManager {
3
+ protected config: ShopeeConfig;
4
+ constructor(config: ShopeeConfig);
5
+ }
@@ -0,0 +1,7 @@
1
+ export class BaseManager {
2
+ constructor(config) {
3
+ this.config = config;
4
+ this.config = config;
5
+ }
6
+ }
7
+ //# sourceMappingURL=base.manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.manager.js","sourceRoot":"","sources":["../../src/managers/base.manager.ts"],"names":[],"mappings":"AAEA,MAAM,OAAgB,WAAW;IAC/B,YAAsB,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ export * from './auth.manager.js';
2
+ export * from './base.manager.js';
3
+ export * from './logistics.manager.js';
4
+ export * from './order.manager.js';
5
+ export * from './order.manager.js';
6
+ export * from './product.manager.js';
7
+ export * from './public.manager.js';
8
+ export * from './push.manager.js';
9
+ export * from './voucher.manager.js';
10
+ export * from './ads.manager.js';
@@ -0,0 +1,11 @@
1
+ export * from './auth.manager.js';
2
+ export * from './base.manager.js';
3
+ export * from './logistics.manager.js';
4
+ export * from './order.manager.js';
5
+ export * from './order.manager.js';
6
+ export * from './product.manager.js';
7
+ export * from './public.manager.js';
8
+ export * from './push.manager.js';
9
+ export * from './voucher.manager.js';
10
+ export * from './ads.manager.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/managers/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { ShopeeConfig } from "../sdk.js";
2
+ import { BaseManager } from "./base.manager.js";
3
+ import { GetTrackingInfoParams, GetTrackingInfoResponse } from "../schemas/logistics.js";
4
+ export declare class LogisticsManager extends BaseManager {
5
+ constructor(config: ShopeeConfig);
6
+ /**
7
+ * Use this API to get the logistics tracking information of an order.
8
+ *
9
+ * @param params - Parameters for getting tracking information
10
+ * @param params.order_sn - Shopee's unique identifier for an order
11
+ * @param params.package_number - Shopee's unique identifier for the package under an order
12
+ *
13
+ * @returns A promise that resolves to the tracking info response containing:
14
+ * - order_sn: Order identifier
15
+ * - package_number: Package identifier
16
+ * - logistics_status: Current logistics status
17
+ * - tracking_info: Array of tracking events with:
18
+ * - update_time: Time of status update
19
+ * - description: Description of the tracking event
20
+ * - logistics_status: Status code for the event
21
+ *
22
+ * @throws {Error} When the API request fails or returns an error:
23
+ * - logistics.error_param: Order allocation in progress
24
+ * - error_not_found: Wrong parameters
25
+ * - error_permission: No permission
26
+ * - error_server: System error
27
+ * - logistics.invalid_error: Order does not exist
28
+ * - logistics.error_status_limit: Invalid order status
29
+ * - logistics.package_not_exist: Package does not exist
30
+ * - logistics.package_number_not_exist: Package number required for split order
31
+ */
32
+ getTrackingInfo(params: GetTrackingInfoParams): Promise<GetTrackingInfoResponse>;
33
+ }
@@ -0,0 +1,42 @@
1
+ import { BaseManager } from "./base.manager.js";
2
+ import { ShopeeFetch } from "../fetch.js";
3
+ export class LogisticsManager extends BaseManager {
4
+ constructor(config) {
5
+ super(config);
6
+ }
7
+ /**
8
+ * Use this API to get the logistics tracking information of an order.
9
+ *
10
+ * @param params - Parameters for getting tracking information
11
+ * @param params.order_sn - Shopee's unique identifier for an order
12
+ * @param params.package_number - Shopee's unique identifier for the package under an order
13
+ *
14
+ * @returns A promise that resolves to the tracking info response containing:
15
+ * - order_sn: Order identifier
16
+ * - package_number: Package identifier
17
+ * - logistics_status: Current logistics status
18
+ * - tracking_info: Array of tracking events with:
19
+ * - update_time: Time of status update
20
+ * - description: Description of the tracking event
21
+ * - logistics_status: Status code for the event
22
+ *
23
+ * @throws {Error} When the API request fails or returns an error:
24
+ * - logistics.error_param: Order allocation in progress
25
+ * - error_not_found: Wrong parameters
26
+ * - error_permission: No permission
27
+ * - error_server: System error
28
+ * - logistics.invalid_error: Order does not exist
29
+ * - logistics.error_status_limit: Invalid order status
30
+ * - logistics.package_not_exist: Package does not exist
31
+ * - logistics.package_number_not_exist: Package number required for split order
32
+ */
33
+ async getTrackingInfo(params) {
34
+ const response = await ShopeeFetch.fetch(this.config, '/logistics/get_tracking_info', {
35
+ method: 'GET',
36
+ auth: true,
37
+ params,
38
+ });
39
+ return response;
40
+ }
41
+ }
42
+ //# sourceMappingURL=logistics.manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logistics.manager.js","sourceRoot":"","sources":["../../src/managers/logistics.manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,OAAO,gBAAiB,SAAQ,WAAW;IAC7C,YAAY,MAAoB;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,KAAK,CAAC,eAAe,CAAC,MAA6B;QAC/C,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,KAAK,CACpC,IAAI,CAAC,MAAM,EACX,8BAA8B,EAC9B;YACI,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,IAAI;YACV,MAAM;SACT,CACJ,CAAC;QAEF,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ"}