oneentry 1.0.139 → 1.0.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -1
- package/configure.js +40 -21
- package/dist/auth-provider/authProviderSchemas.d.ts +24 -30
- package/dist/auth-provider/authProviderSchemas.js +12 -15
- package/dist/auth-provider/authProvidersInterfaces.d.ts +10 -2
- package/dist/base/syncModules.js +1 -1
- package/dist/blocks/blocksApi.d.ts +2 -0
- package/dist/blocks/blocksApi.js +6 -2
- package/dist/discounts/discountsApi.d.ts +56 -0
- package/dist/discounts/discountsApi.js +82 -0
- package/dist/discounts/discountsInterfaces.d.ts +145 -0
- package/dist/discounts/discountsInterfaces.js +2 -0
- package/dist/forms/formsSchemas.d.ts +18 -33
- package/dist/forms/formsSchemas.js +6 -11
- package/dist/index.d.ts +11 -5
- package/dist/index.js +6 -0
- package/dist/integration-collections/integrationCollectionsInterfaces.d.ts +2 -2
- package/dist/integration-collections/integrationCollectionsSchemas.d.ts +2 -6
- package/dist/integration-collections/integrationCollectionsSchemas.js +1 -3
- package/dist/orders/ordersApi.d.ts +26 -3
- package/dist/orders/ordersApi.js +36 -2
- package/dist/orders/ordersInterfaces.d.ts +104 -4
- package/dist/orders/ordersSchemas.d.ts +34 -72
- package/dist/orders/ordersSchemas.js +16 -35
- package/dist/pages/pagesApi.d.ts +2 -2
- package/dist/pages/pagesApi.js +3 -3
- package/dist/pages/pagesInterfaces.d.ts +3 -3
- package/dist/payments/paymentsInterfaces.d.ts +1 -1
- package/dist/payments/paymentsSchemas.d.ts +53 -90
- package/dist/payments/paymentsSchemas.js +21 -34
- package/dist/product-statuses/productStatusesApi.d.ts +2 -2
- package/dist/product-statuses/productStatusesInterfaces.d.ts +2 -2
- package/dist/products/productsApi.d.ts +5 -4
- package/dist/products/productsApi.js +9 -5
- package/dist/products/productsInterfaces.d.ts +11 -8
- package/dist/products/productsSchemas.d.ts +14 -34
- package/dist/products/productsSchemas.js +14 -3
- package/dist/sitemap/sitemapApi.d.ts +35 -0
- package/dist/sitemap/sitemapApi.js +45 -0
- package/dist/sitemap/sitemapInterfaces.d.ts +40 -0
- package/dist/sitemap/sitemapInterfaces.js +2 -0
- package/dist/system/systemApi.d.ts +3 -25
- package/dist/system/systemApi.js +0 -24
- package/dist/system/systemInterfaces.d.ts +13 -5
- package/dist/system/systemInterfaces.js +3 -0
- package/dist/templates-preview/templatesPreviewApi.d.ts +2 -2
- package/dist/templates-preview/templatesPreviewInterfaces.d.ts +3 -3
- package/dist/users/usersApi.d.ts +2 -2
- package/dist/users/usersApi.js +0 -1
- package/dist/users/usersInterfaces.d.ts +3 -3
- package/dist/users/usersSchemas.d.ts +1 -1
- package/dist/users/usersSchemas.js +1 -1
- package/package.json +3 -78
package/README.md
CHANGED
|
@@ -18,6 +18,16 @@ To install the OneEntry SDK in your project, run the following command:
|
|
|
18
18
|
npm install oneentry
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
## Quick Start with CLI
|
|
22
|
+
|
|
23
|
+
After installation, run the interactive setup tool to generate a working example and see live data from your project:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx oneentry
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
It will ask for your project URL and API token, generate an `example.mjs` file, and optionally run it immediately — printing admins, pages and products to the console.
|
|
30
|
+
|
|
21
31
|
## Get Started
|
|
22
32
|
|
|
23
33
|
To use the OneEntry SDK in your project, import the defineOneEntry function:
|
|
@@ -33,18 +43,21 @@ const {
|
|
|
33
43
|
AttributesSets,
|
|
34
44
|
AuthProvider,
|
|
35
45
|
Blocks,
|
|
46
|
+
Discounts,
|
|
36
47
|
Events,
|
|
48
|
+
FileUploading,
|
|
37
49
|
Forms,
|
|
38
50
|
FormData,
|
|
39
|
-
FileUploading,
|
|
40
51
|
GeneralTypes,
|
|
41
52
|
IntegrationCollections,
|
|
42
53
|
Locales,
|
|
43
54
|
Menus,
|
|
44
55
|
Orders,
|
|
45
56
|
Pages,
|
|
57
|
+
Payments,
|
|
46
58
|
Products,
|
|
47
59
|
ProductStatuses,
|
|
60
|
+
Sitemap,
|
|
48
61
|
System,
|
|
49
62
|
Templates,
|
|
50
63
|
TemplatePreviews,
|
|
@@ -202,6 +215,7 @@ Now you can use the following links to jump to specific entries documentation:
|
|
|
202
215
|
- [AttributesSets](https://js-sdk.oneentry.cloud/docs/category/attributessets)
|
|
203
216
|
- [AuthProvider](https://js-sdk.oneentry.cloud/docs/category/authprovider)
|
|
204
217
|
- [Blocks](https://js-sdk.oneentry.cloud/docs/category/blocks)
|
|
218
|
+
- [Discounts](https://js-sdk.oneentry.cloud/docs/category/discounts)
|
|
205
219
|
- [Events](https://js-sdk.oneentry.cloud/docs/category/events)
|
|
206
220
|
- [FileUploading](https://js-sdk.oneentry.cloud/docs/category/fileuploading)
|
|
207
221
|
- [Forms](https://js-sdk.oneentry.cloud/docs/category/forms-1)
|
|
@@ -215,6 +229,7 @@ Now you can use the following links to jump to specific entries documentation:
|
|
|
215
229
|
- [Payments](https://js-sdk.oneentry.cloud/docs/category/payments)
|
|
216
230
|
- [ProductStatuses](https://js-sdk.oneentry.cloud/docs/category/productstatuses)
|
|
217
231
|
- [Products](https://js-sdk.oneentry.cloud/docs/category/products-1)
|
|
232
|
+
- [Sitemap](https://js-sdk.oneentry.cloud/docs/category/sitemap)
|
|
218
233
|
- [System](https://js-sdk.oneentry.cloud/docs/category/system)
|
|
219
234
|
- [Templates](https://js-sdk.oneentry.cloud/docs/category/templates)
|
|
220
235
|
- [TemplatePreviews](https://js-sdk.oneentry.cloud/docs/category/templatepreviews)
|
package/configure.js
CHANGED
|
@@ -22,50 +22,69 @@
|
|
|
22
22
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
23
23
|
|
|
24
24
|
const fs = require('fs');
|
|
25
|
-
// const path = require('path');
|
|
26
|
-
|
|
27
25
|
const readline = require('readline');
|
|
26
|
+
const { spawn } = require('child_process');
|
|
28
27
|
|
|
29
28
|
const rl = readline.createInterface({
|
|
30
29
|
input: process.stdin,
|
|
31
30
|
output: process.stdout,
|
|
32
31
|
});
|
|
33
32
|
|
|
34
|
-
rl.question('Enter project name with https://... : ', (
|
|
33
|
+
rl.question('Enter project name with https://... : ', (url) => {
|
|
35
34
|
rl.question('Enter token: ', (token) => {
|
|
36
|
-
rl.
|
|
37
|
-
|
|
35
|
+
rl.question('Run example after creating? (y/n): ', (answer) => {
|
|
36
|
+
rl.close();
|
|
37
|
+
createInterface(url, token, answer.trim().toLowerCase() === 'y');
|
|
38
|
+
});
|
|
38
39
|
});
|
|
39
40
|
});
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
|
-
* Creates an example
|
|
43
|
-
*
|
|
44
|
-
* Generates an example.ts file containing a BuildInterface type and
|
|
45
|
-
* IAttributesList interface with the provided project name and token.
|
|
43
|
+
* Creates an example JavaScript file with SDK initialization and sample requests
|
|
46
44
|
*
|
|
47
|
-
*
|
|
45
|
+
* Generates an example.mjs file with a ready-to-use defineOneEntry call
|
|
46
|
+
* that fetches admins, pages and products and prints them to the console.
|
|
47
|
+
* Run with: node example.mjs
|
|
48
|
+
* @param {string} url - Project URL with https:// (e.g., "https://example.oneentry.cloud")
|
|
48
49
|
* @param {string} token - Authentication token for API access
|
|
50
|
+
* @param {boolean} run - Whether to run the generated file immediately
|
|
49
51
|
*/
|
|
50
|
-
function createInterface(
|
|
51
|
-
const filePath = 'example.
|
|
52
|
+
function createInterface(url, token, run) {
|
|
53
|
+
const filePath = 'example.mjs';
|
|
54
|
+
const tokenLine = token ? `\n token: '${token}',` : '';
|
|
52
55
|
fs.writeFile(
|
|
53
56
|
filePath,
|
|
54
|
-
`
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
`import { defineOneEntry } from 'oneentry';
|
|
58
|
+
|
|
59
|
+
const { Admins, Pages, Products } = defineOneEntry('${url}', {${tokenLine}
|
|
60
|
+
langCode: 'en_US',
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const [admins, pages, products] = await Promise.all([
|
|
64
|
+
Admins.getAdminsInfo(),
|
|
65
|
+
Pages.getPages(),
|
|
66
|
+
Products.getProducts(),
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
console.log('Admins:', JSON.stringify(admins, null, 2));
|
|
70
|
+
console.log('Pages:', JSON.stringify(pages, null, 2));
|
|
71
|
+
console.log('Products:', JSON.stringify(products, null, 2));
|
|
72
|
+
`,
|
|
63
73
|
(err) => {
|
|
64
74
|
if (err) {
|
|
65
75
|
console.error(err);
|
|
66
76
|
return;
|
|
67
77
|
}
|
|
68
78
|
console.log(`Successfully created ${filePath}`);
|
|
79
|
+
if (!run) {
|
|
80
|
+
console.log(`Run it with: node ${filePath}`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
console.log(`Running ${filePath}...\n`);
|
|
84
|
+
const child = spawn('node', [filePath], { stdio: 'inherit' });
|
|
85
|
+
child.on('error', (e) =>
|
|
86
|
+
console.error('Failed to run script:', e.message),
|
|
87
|
+
);
|
|
69
88
|
},
|
|
70
89
|
);
|
|
71
90
|
}
|
|
@@ -70,17 +70,14 @@ export declare const UserResponseSchema: z.ZodObject<{
|
|
|
70
70
|
export declare const AuthProviderEntitySchema: z.ZodObject<{
|
|
71
71
|
id: z.ZodNumber;
|
|
72
72
|
identifier: z.ZodString;
|
|
73
|
-
type: z.
|
|
74
|
-
formIdentifier: z.
|
|
75
|
-
userGroupIdentifier: z.
|
|
73
|
+
type: z.ZodString;
|
|
74
|
+
formIdentifier: z.ZodNullable<z.ZodString>;
|
|
75
|
+
userGroupIdentifier: z.ZodString;
|
|
76
76
|
isActive: z.ZodBoolean;
|
|
77
|
-
isCheckCode: z.
|
|
78
|
-
version: z.
|
|
79
|
-
localizeInfos: z.
|
|
80
|
-
config: z.
|
|
81
|
-
marker: z.ZodOptional<z.ZodString>;
|
|
82
|
-
name: z.ZodOptional<z.ZodString>;
|
|
83
|
-
position: z.ZodOptional<z.ZodNumber>;
|
|
77
|
+
isCheckCode: z.ZodBoolean;
|
|
78
|
+
version: z.ZodNumber;
|
|
79
|
+
localizeInfos: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
80
|
+
config: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
84
81
|
}, z.core.$strip>;
|
|
85
82
|
/**
|
|
86
83
|
* Auth providers list response schema
|
|
@@ -89,17 +86,14 @@ export declare const AuthProviderEntitySchema: z.ZodObject<{
|
|
|
89
86
|
export declare const AuthProvidersResponseSchema: z.ZodArray<z.ZodObject<{
|
|
90
87
|
id: z.ZodNumber;
|
|
91
88
|
identifier: z.ZodString;
|
|
92
|
-
type: z.
|
|
93
|
-
formIdentifier: z.
|
|
94
|
-
userGroupIdentifier: z.
|
|
89
|
+
type: z.ZodString;
|
|
90
|
+
formIdentifier: z.ZodNullable<z.ZodString>;
|
|
91
|
+
userGroupIdentifier: z.ZodString;
|
|
95
92
|
isActive: z.ZodBoolean;
|
|
96
|
-
isCheckCode: z.
|
|
97
|
-
version: z.
|
|
98
|
-
localizeInfos: z.
|
|
99
|
-
config: z.
|
|
100
|
-
marker: z.ZodOptional<z.ZodString>;
|
|
101
|
-
name: z.ZodOptional<z.ZodString>;
|
|
102
|
-
position: z.ZodOptional<z.ZodNumber>;
|
|
93
|
+
isCheckCode: z.ZodBoolean;
|
|
94
|
+
version: z.ZodNumber;
|
|
95
|
+
localizeInfos: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
96
|
+
config: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
103
97
|
}, z.core.$strip>>;
|
|
104
98
|
/**
|
|
105
99
|
* Generate code response schema
|
|
@@ -122,16 +116,16 @@ export declare const LogoutResponseSchema: z.ZodObject<{
|
|
|
122
116
|
* @description Schema for validating active sessions response
|
|
123
117
|
*/
|
|
124
118
|
export declare const ActiveSessionSchema: z.ZodObject<{
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
119
|
+
deviceInfo: z.ZodObject<{
|
|
120
|
+
os: z.ZodString;
|
|
121
|
+
browser: z.ZodString;
|
|
122
|
+
location: z.ZodString;
|
|
123
|
+
}, z.core.$strip>;
|
|
130
124
|
}, z.core.$strip>;
|
|
131
125
|
export declare const ActiveSessionsResponseSchema: z.ZodArray<z.ZodObject<{
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
126
|
+
deviceInfo: z.ZodObject<{
|
|
127
|
+
os: z.ZodString;
|
|
128
|
+
browser: z.ZodString;
|
|
129
|
+
location: z.ZodString;
|
|
130
|
+
}, z.core.$strip>;
|
|
137
131
|
}, z.core.$strip>>;
|
|
@@ -38,17 +38,14 @@ exports.UserResponseSchema = validation_1.UserEntitySchema;
|
|
|
38
38
|
exports.AuthProviderEntitySchema = zod_1.z.object({
|
|
39
39
|
id: zod_1.z.number(),
|
|
40
40
|
identifier: zod_1.z.string(),
|
|
41
|
-
type: zod_1.z.string()
|
|
42
|
-
formIdentifier: zod_1.z.string().
|
|
43
|
-
userGroupIdentifier: zod_1.z.string()
|
|
41
|
+
type: zod_1.z.string(),
|
|
42
|
+
formIdentifier: zod_1.z.string().nullable(),
|
|
43
|
+
userGroupIdentifier: zod_1.z.string(),
|
|
44
44
|
isActive: zod_1.z.boolean(),
|
|
45
|
-
isCheckCode: zod_1.z.boolean()
|
|
46
|
-
version: zod_1.z.number()
|
|
47
|
-
localizeInfos: zod_1.z.record(zod_1.z.string(), zod_1.z.any())
|
|
48
|
-
config: zod_1.z.record(zod_1.z.string(), zod_1.z.any())
|
|
49
|
-
marker: zod_1.z.string().optional(),
|
|
50
|
-
name: zod_1.z.string().optional(),
|
|
51
|
-
position: zod_1.z.number().optional(),
|
|
45
|
+
isCheckCode: zod_1.z.boolean(),
|
|
46
|
+
version: zod_1.z.number(),
|
|
47
|
+
localizeInfos: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
|
|
48
|
+
config: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
|
|
52
49
|
});
|
|
53
50
|
/**
|
|
54
51
|
* Auth providers list response schema
|
|
@@ -76,10 +73,10 @@ exports.LogoutResponseSchema = zod_1.z.object({
|
|
|
76
73
|
* @description Schema for validating active sessions response
|
|
77
74
|
*/
|
|
78
75
|
exports.ActiveSessionSchema = zod_1.z.object({
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
deviceInfo: zod_1.z.object({
|
|
77
|
+
os: zod_1.z.string(),
|
|
78
|
+
browser: zod_1.z.string(),
|
|
79
|
+
location: zod_1.z.string(),
|
|
80
|
+
}),
|
|
84
81
|
});
|
|
85
82
|
exports.ActiveSessionsResponseSchema = zod_1.z.array(exports.ActiveSessionSchema);
|
|
@@ -359,19 +359,27 @@ interface IAuthProvidersEntity {
|
|
|
359
359
|
* @interface IAuthProvidersEntityConfig
|
|
360
360
|
* @property {string} accessTokenTtlSec - Access token time to live in seconds. Example: "3600".
|
|
361
361
|
* @property {string} refreshTokenTtlMc - Refresh token time to live in milliseconds. Example: "86400000".
|
|
362
|
-
* @property {string} tokenSecretKey - Token secret key. Example: "secret_key".
|
|
363
362
|
* @property {string} deleteNoneActiveUsersAfterDays - Delete none active users after days. Example: "30".
|
|
364
363
|
* @property {string} systemCodeTlsSec - System code time to live in seconds. Example: "86400".
|
|
365
364
|
* @property {string} systemCodeLength - System code length. Example: "6".
|
|
365
|
+
* @property {string | null} oauthAuthUrl - OAuth authorization URL. Example: null.
|
|
366
|
+
* @property {string | null} systemCodeOnlyNumbers - System code only numbers flag. Example: null.
|
|
366
367
|
*/
|
|
367
368
|
interface IAuthProvidersEntityConfig {
|
|
368
369
|
accessTokenTtlSec: string;
|
|
369
370
|
refreshTokenTtlMc: string;
|
|
370
|
-
tokenSecretKey: string;
|
|
371
371
|
deleteNoneActiveUsersAfterDays: string;
|
|
372
372
|
systemCodeTlsSec: string;
|
|
373
373
|
systemCodeLength: string;
|
|
374
|
+
oauthAuthUrl: string | null;
|
|
375
|
+
systemCodeOnlyNumbers: string | null;
|
|
374
376
|
}
|
|
377
|
+
/**
|
|
378
|
+
* Authentication data object.
|
|
379
|
+
* @interface IAuthData
|
|
380
|
+
* @property {string} marker - The marker identifying the auth field. Example: "login".
|
|
381
|
+
* @property {string} value - The value of the auth field. Example: "user@example.com".
|
|
382
|
+
*/
|
|
375
383
|
interface IAuthData {
|
|
376
384
|
marker: string;
|
|
377
385
|
value: string;
|
package/dist/base/syncModules.js
CHANGED
|
@@ -47,6 +47,7 @@ export default class BlocksApi extends AsyncModules implements IBlocks {
|
|
|
47
47
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
48
48
|
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
49
49
|
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
50
|
+
* @param {string} [signPrice] - Sign price.
|
|
50
51
|
* @returns {Promise<IProductsResponse | IError>} - Returns the total count and an array of product items in object by specified block marker.
|
|
51
52
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
52
53
|
*/
|
|
@@ -58,6 +59,7 @@ export default class BlocksApi extends AsyncModules implements IBlocks {
|
|
|
58
59
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
59
60
|
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
60
61
|
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
62
|
+
* @param {string} [signPrice] - Sign price.
|
|
61
63
|
* @returns {Promise<IProductsEntity[] | IError>} Return array of BlocksEntity object.
|
|
62
64
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
63
65
|
*/
|
package/dist/blocks/blocksApi.js
CHANGED
|
@@ -135,14 +135,16 @@ class BlocksApi extends asyncModules_1.default {
|
|
|
135
135
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
136
136
|
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
137
137
|
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
138
|
+
* @param {string} [signPrice] - Sign price.
|
|
138
139
|
* @returns {Promise<IProductsResponse | IError>} - Returns the total count and an array of product items in object by specified block marker.
|
|
139
140
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
140
141
|
*/
|
|
141
|
-
async getSimilarProducts(marker, langCode = this.state.lang, offset = 0, limit = 30) {
|
|
142
|
+
async getSimilarProducts(marker, langCode = this.state.lang, offset = 0, limit = 30, signPrice) {
|
|
142
143
|
const query = {
|
|
143
144
|
langCode,
|
|
144
145
|
offset,
|
|
145
146
|
limit,
|
|
147
|
+
signPrice,
|
|
146
148
|
};
|
|
147
149
|
const result = await this._fetchGet(`/${marker}/similar-products?` + this._queryParamsToString(query));
|
|
148
150
|
return this._normalizeData(result);
|
|
@@ -154,14 +156,16 @@ class BlocksApi extends asyncModules_1.default {
|
|
|
154
156
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
155
157
|
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
156
158
|
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
159
|
+
* @param {string} [signPrice] - Sign price.
|
|
157
160
|
* @returns {Promise<IProductsEntity[] | IError>} Return array of BlocksEntity object.
|
|
158
161
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
159
162
|
*/
|
|
160
|
-
async getProductsByBlockMarker(marker, langCode = this.state.lang, offset = 0, limit = 30) {
|
|
163
|
+
async getProductsByBlockMarker(marker, langCode = this.state.lang, offset = 0, limit = 30, signPrice) {
|
|
161
164
|
const query = {
|
|
162
165
|
langCode,
|
|
163
166
|
offset,
|
|
164
167
|
limit,
|
|
168
|
+
signPrice,
|
|
165
169
|
};
|
|
166
170
|
const result = await this._fetchGet(`/${marker}/products?` + this._queryParamsToString(query));
|
|
167
171
|
return this._normalizeData(result.items);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import AsyncModules from '../base/asyncModules';
|
|
2
|
+
import type StateModule from '../base/stateModule';
|
|
3
|
+
import type { IError } from '../base/utils';
|
|
4
|
+
import type { ICouponValidationResult, IDiscountsApi, IDiscountsEntity, IDiscountsResponse } from './discountsInterfaces';
|
|
5
|
+
/**
|
|
6
|
+
* Controllers for working with events
|
|
7
|
+
* @handle /api/content/events
|
|
8
|
+
* @class DiscountsApi
|
|
9
|
+
* @augments AsyncModules
|
|
10
|
+
* @implements {IDiscountsApi}
|
|
11
|
+
* @description This class provides methods to interact with events, including subscribing and unsubscribing to product events, and retrieving all subscriptions.
|
|
12
|
+
*/
|
|
13
|
+
export default class DiscountsApi extends AsyncModules implements IDiscountsApi {
|
|
14
|
+
protected state: StateModule;
|
|
15
|
+
protected _url: string;
|
|
16
|
+
/**
|
|
17
|
+
* Initializes the Constructor for DiscountsApi class with the provided state module.
|
|
18
|
+
* @class DiscountsApi
|
|
19
|
+
* @augments AsyncModules
|
|
20
|
+
* @implements {DiscountsApi}
|
|
21
|
+
* @param {StateModule} state - The state module containing the base URL and other configurations.
|
|
22
|
+
* @description Initializes the DiscountsApi with the provided state module.
|
|
23
|
+
*/
|
|
24
|
+
constructor(state: StateModule);
|
|
25
|
+
/**
|
|
26
|
+
* Return all discounts.
|
|
27
|
+
* @handleName getAllDiscounts
|
|
28
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
29
|
+
* @param {number} [offset] - Optional parameter for pagination. Default: 0.
|
|
30
|
+
* @param {number} [limit] - Optional parameter for pagination. Default: 30.
|
|
31
|
+
* @param {string} [type] - Optional parameter to filter discounts by type.
|
|
32
|
+
* @returns {Promise<IDiscountsResponse | IError>} Returns an object containing all discounts or an error object if there was an issue.
|
|
33
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
34
|
+
* @description Fetches all discounts from the server.
|
|
35
|
+
*/
|
|
36
|
+
getAllDiscounts(langCode?: string, offset?: number, limit?: number, type?: 'DISCOUNT' | 'BONUS' | 'PERSONAL_DISCOUNT' | 'PERSONAL_BONUS'): Promise<IDiscountsResponse | IError>;
|
|
37
|
+
/**
|
|
38
|
+
* Get discount by marker
|
|
39
|
+
* @handleName getDiscountByMarker
|
|
40
|
+
* @param {string} marker - Textual identifier of the discount storage object. Example: "discount_storage".
|
|
41
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
42
|
+
* @returns {Promise<IDiscountsEntity | IError>} Returns an object containing discount by marker or an error object if there was an issue.
|
|
43
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
44
|
+
* @description Fetches a discount by its marker.
|
|
45
|
+
*/
|
|
46
|
+
getDiscountByMarker(marker: string, langCode?: string): Promise<IDiscountsEntity | IError>;
|
|
47
|
+
/**
|
|
48
|
+
* Validate discounts coupon
|
|
49
|
+
* @handleName validateDiscountsCoupon
|
|
50
|
+
* @param {string} code - The coupon code to validate.
|
|
51
|
+
* @returns {Promise<ICouponValidationResult | IError>} Returns an coupon validation result or an error object if there was an issue.
|
|
52
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
53
|
+
* @description This function validates a coupon code and returns the result.
|
|
54
|
+
*/
|
|
55
|
+
validateDiscountsCoupon(code: string): Promise<ICouponValidationResult | IError>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const asyncModules_1 = __importDefault(require("../base/asyncModules"));
|
|
7
|
+
/**
|
|
8
|
+
* Controllers for working with events
|
|
9
|
+
* @handle /api/content/events
|
|
10
|
+
* @class DiscountsApi
|
|
11
|
+
* @augments AsyncModules
|
|
12
|
+
* @implements {IDiscountsApi}
|
|
13
|
+
* @description This class provides methods to interact with events, including subscribing and unsubscribing to product events, and retrieving all subscriptions.
|
|
14
|
+
*/
|
|
15
|
+
class DiscountsApi extends asyncModules_1.default {
|
|
16
|
+
/**
|
|
17
|
+
* Initializes the Constructor for DiscountsApi class with the provided state module.
|
|
18
|
+
* @class DiscountsApi
|
|
19
|
+
* @augments AsyncModules
|
|
20
|
+
* @implements {DiscountsApi}
|
|
21
|
+
* @param {StateModule} state - The state module containing the base URL and other configurations.
|
|
22
|
+
* @description Initializes the DiscountsApi with the provided state module.
|
|
23
|
+
*/
|
|
24
|
+
constructor(state) {
|
|
25
|
+
super(state);
|
|
26
|
+
this._url = state.url + '/api/content/discounts';
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Return all discounts.
|
|
30
|
+
* @handleName getAllDiscounts
|
|
31
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
32
|
+
* @param {number} [offset] - Optional parameter for pagination. Default: 0.
|
|
33
|
+
* @param {number} [limit] - Optional parameter for pagination. Default: 30.
|
|
34
|
+
* @param {string} [type] - Optional parameter to filter discounts by type.
|
|
35
|
+
* @returns {Promise<IDiscountsResponse | IError>} Returns an object containing all discounts or an error object if there was an issue.
|
|
36
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
37
|
+
* @description Fetches all discounts from the server.
|
|
38
|
+
*/
|
|
39
|
+
async getAllDiscounts(langCode = this.state.lang, offset = 0, limit = 30, type) {
|
|
40
|
+
const query = {
|
|
41
|
+
langCode,
|
|
42
|
+
offset,
|
|
43
|
+
limit,
|
|
44
|
+
type,
|
|
45
|
+
};
|
|
46
|
+
const data = await this._fetchGet(`?` + this._queryParamsToString(query));
|
|
47
|
+
return this._normalizeData(data);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get discount by marker
|
|
51
|
+
* @handleName getDiscountByMarker
|
|
52
|
+
* @param {string} marker - Textual identifier of the discount storage object. Example: "discount_storage".
|
|
53
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
54
|
+
* @returns {Promise<IDiscountsEntity | IError>} Returns an object containing discount by marker or an error object if there was an issue.
|
|
55
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
56
|
+
* @description Fetches a discount by its marker.
|
|
57
|
+
*/
|
|
58
|
+
async getDiscountByMarker(marker, langCode = this.state.lang) {
|
|
59
|
+
const query = {
|
|
60
|
+
marker: '',
|
|
61
|
+
langCode,
|
|
62
|
+
};
|
|
63
|
+
const data = await this._fetchGet(`/marker/${marker}?` + this._queryParamsToString(query));
|
|
64
|
+
return this._normalizeData(data);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Validate discounts coupon
|
|
68
|
+
* @handleName validateDiscountsCoupon
|
|
69
|
+
* @param {string} code - The coupon code to validate.
|
|
70
|
+
* @returns {Promise<ICouponValidationResult | IError>} Returns an coupon validation result or an error object if there was an issue.
|
|
71
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
72
|
+
* @description This function validates a coupon code and returns the result.
|
|
73
|
+
*/
|
|
74
|
+
async validateDiscountsCoupon(code) {
|
|
75
|
+
const query = {
|
|
76
|
+
code,
|
|
77
|
+
};
|
|
78
|
+
const data = await this._fetchGet(`/coupons/validate?` + this._queryParamsToString(query));
|
|
79
|
+
return this._normalizeData(data);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.default = DiscountsApi;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { IError } from 'base/utils';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for the Discounts API module.
|
|
4
|
+
* @interface IDiscountsApi
|
|
5
|
+
*/
|
|
6
|
+
interface IDiscountsApi {
|
|
7
|
+
/**
|
|
8
|
+
* Return all discounts.
|
|
9
|
+
* @handleName getAllSubscriptions
|
|
10
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
11
|
+
* @param {number} [offset] - Optional parameter for pagination. Default: 0.
|
|
12
|
+
* @param {number} [limit] - Optional parameter for pagination. Default: 30.
|
|
13
|
+
* @param {string} [type] - Optional parameter to filter discounts by type.
|
|
14
|
+
* @returns {Promise<IDiscountsResponse | IError>} Returns an object containing all discounts or an error object if there was an issue.
|
|
15
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
16
|
+
* @description Fetches all discounts from the server.
|
|
17
|
+
*/
|
|
18
|
+
getAllDiscounts(langCode?: string, offset?: number, limit?: number, type?: 'DISCOUNT' | 'BONUS' | 'PERSONAL_DISCOUNT' | 'PERSONAL_BONUS'): Promise<IDiscountsResponse | IError>;
|
|
19
|
+
/**
|
|
20
|
+
* Get discount by marker
|
|
21
|
+
* @handleName getDiscountByMarker
|
|
22
|
+
* @param {string} marker - Textual identifier of the discount storage object. Example: "discount_storage".
|
|
23
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
24
|
+
* @returns {Promise<IDiscountsEntity | IError>} Returns an object containing discount by marker or an error object if there was an issue.
|
|
25
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
26
|
+
* @description Fetches a discount by its marker.
|
|
27
|
+
*/
|
|
28
|
+
getDiscountByMarker(marker: string, langCode: string): Promise<IDiscountsEntity | IError>;
|
|
29
|
+
/**
|
|
30
|
+
* Validate discounts coupon
|
|
31
|
+
* @handleName validateDiscountsCoupon
|
|
32
|
+
* @param {string} code - The coupon code to validate.
|
|
33
|
+
* @returns {Promise<ICouponValidationResult | IError>} Returns an coupon validation result or an error object if there was an issue.
|
|
34
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
35
|
+
* @description This function validates a coupon code and returns the result.
|
|
36
|
+
*/
|
|
37
|
+
validateDiscountsCoupon(code: string): Promise<ICouponValidationResult | IError>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Query parameters for fetching discounts.
|
|
41
|
+
* @interface IDiscountsQuery
|
|
42
|
+
* @property {'DISCOUNT' | 'BONUS' | 'PERSONAL_DISCOUNT' | 'PERSONAL_BONUS'} [type] - Filter discounts by type.
|
|
43
|
+
* @property {string} langCode - The language code for localization. Example: "en_US".
|
|
44
|
+
* @property {number} [offset] - Offset for pagination. Default: 0.
|
|
45
|
+
* @property {number} [limit] - Limit for pagination. Default: 30.
|
|
46
|
+
*/
|
|
47
|
+
interface IDiscountsQuery {
|
|
48
|
+
type?: 'DISCOUNT' | 'BONUS' | 'PERSONAL_DISCOUNT' | 'PERSONAL_BONUS';
|
|
49
|
+
langCode: string;
|
|
50
|
+
offset?: number;
|
|
51
|
+
limit?: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Represents a discount condition.
|
|
55
|
+
* @interface IDiscountCondition
|
|
56
|
+
* @property {string} type - The type of discount condition.
|
|
57
|
+
* @property {string} [value] - The value associated with the discount condition.
|
|
58
|
+
*/
|
|
59
|
+
interface IDiscountCondition {
|
|
60
|
+
type: 'PRODUCT' | 'CATEGORY' | 'ATTRIBUTE' | 'PRODUCT_IN_CART' | 'CATEGORY_IN_CART' | 'MIN_CART_AMOUNT' | 'USER_LTV' | 'USER_ATTRIBUTE';
|
|
61
|
+
value: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Represents a discount entity.
|
|
65
|
+
* @interface IDiscountsEntity
|
|
66
|
+
* @property {number} id - The unique identifier of the discount.
|
|
67
|
+
* @property {number} [attributeSetId] - The identifier of the discount.
|
|
68
|
+
* @property {object} [localizeInfos] - The name of the discount.
|
|
69
|
+
* @property {number} [version] - The version of the discount.
|
|
70
|
+
* @property {string} [identifier] - The identifier of the discount.
|
|
71
|
+
* @property {string} [type] - The type of the discount.
|
|
72
|
+
* @property {string} [startDate] - The start date of the discount.
|
|
73
|
+
* @property {string} [endDate] - The end date of the discount.
|
|
74
|
+
* @property {Record<string, unknown>} [discountValue] - The value of the discount.
|
|
75
|
+
* @property {string} [conditionLogic] - The logic of the discount. Possible values are "AND" | "OR".
|
|
76
|
+
* @property {IDiscountCondition[]} [conditions] - The conditions of the discount.
|
|
77
|
+
* @property {object} [exclusions] - The exclusions of the discount.
|
|
78
|
+
* @property {object} [gifts] - The gifts of the discount.
|
|
79
|
+
* @property {boolean} [giftsReplaceCartItems] - Whether the gifts replace cart items.
|
|
80
|
+
* @property {object} [userGroups] - The user groups of the discount.
|
|
81
|
+
* @property {object} [userExclusions] - The user exclusions of the discount.
|
|
82
|
+
* @property {object} [attributeValues] - The attribute values of the discount.
|
|
83
|
+
* @property {string} [attributeSetIdentifier] - The identifier of the attribute set.
|
|
84
|
+
*/
|
|
85
|
+
interface IDiscountsEntity {
|
|
86
|
+
id: number;
|
|
87
|
+
attributeSetId?: number;
|
|
88
|
+
localizeInfos?: object;
|
|
89
|
+
version?: number;
|
|
90
|
+
identifier?: string;
|
|
91
|
+
type: 'DISCOUNT' | 'BONUS' | 'PERSONAL_DISCOUNT' | 'PERSONAL_BONUS';
|
|
92
|
+
startDate?: string;
|
|
93
|
+
endDate?: string;
|
|
94
|
+
discountValue?: Record<string, unknown>;
|
|
95
|
+
conditionLogic?: 'AND' | 'OR';
|
|
96
|
+
conditions?: IDiscountCondition[];
|
|
97
|
+
exclusions?: object;
|
|
98
|
+
gifts?: object;
|
|
99
|
+
giftsReplaceCartItems?: boolean;
|
|
100
|
+
userGroups?: object;
|
|
101
|
+
userExclusions?: object;
|
|
102
|
+
attributeValues?: object;
|
|
103
|
+
attributeSetIdentifier?: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Paginated response for discounts list.
|
|
107
|
+
* @interface IDiscountsResponse
|
|
108
|
+
* @property {IDiscountsEntity[]} items - Array of discount entities.
|
|
109
|
+
* @property {number} total - Total number of discounts.
|
|
110
|
+
*/
|
|
111
|
+
interface IDiscountsResponse {
|
|
112
|
+
items: IDiscountsEntity[];
|
|
113
|
+
total: number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Request body for coupon validation.
|
|
117
|
+
* @interface IDiscountsValidateCoupon
|
|
118
|
+
* @property {string} code - The coupon code to validate.
|
|
119
|
+
*/
|
|
120
|
+
interface IDiscountsValidateCoupon {
|
|
121
|
+
code: string;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Result of coupon validation.
|
|
125
|
+
* @interface ICouponValidationResult
|
|
126
|
+
* @property {boolean} valid - Whether the coupon is valid.
|
|
127
|
+
* @property {unknown} [coupon] - Coupon data if the coupon is valid.
|
|
128
|
+
* @property {string} [error] - Error message if the coupon is invalid.
|
|
129
|
+
*/
|
|
130
|
+
interface ICouponValidationResult {
|
|
131
|
+
valid: boolean;
|
|
132
|
+
coupon?: unknown;
|
|
133
|
+
error?: string;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Query parameters for fetching a discount by marker.
|
|
137
|
+
* @interface IDiscountByMarkerQuery
|
|
138
|
+
* @property {string} langCode - The language code for localization. Example: "en_US".
|
|
139
|
+
* @property {string} marker - Textual identifier of the discount. Example: "example_discount".
|
|
140
|
+
*/
|
|
141
|
+
interface IDiscountByMarkerQuery {
|
|
142
|
+
langCode: string;
|
|
143
|
+
marker: string;
|
|
144
|
+
}
|
|
145
|
+
export type { ICouponValidationResult, IDiscountByMarkerQuery, IDiscountCondition, IDiscountsApi, IDiscountsEntity, IDiscountsQuery, IDiscountsResponse, IDiscountsValidateCoupon, };
|