oneentry 1.0.166 → 1.0.167
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 +5 -1
- package/changelog.md +28 -0
- package/dist/base/utils.d.ts +5 -2
- package/dist/base/validation.d.ts +7 -5
- package/dist/base/validation.js +7 -4
- package/dist/file-uploading/fileUploadingApi.d.ts +27 -1
- package/dist/file-uploading/fileUploadingApi.js +42 -0
- package/dist/file-uploading/fileUploadingInterfaces.d.ts +102 -1
- package/dist/file-uploading/fileUploadingSchemas.d.ts +73 -0
- package/dist/file-uploading/fileUploadingSchemas.js +47 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/orders/ordersApi.d.ts +14 -0
- package/dist/orders/ordersApi.js +19 -0
- package/dist/orders/ordersInterfaces.d.ts +11 -0
- package/dist/payments/paymentsApi.d.ts +14 -1
- package/dist/payments/paymentsApi.js +18 -0
- package/dist/payments/paymentsInterfaces.d.ts +43 -1
- package/dist/payments/paymentsSchemas.d.ts +32 -0
- package/dist/payments/paymentsSchemas.js +20 -1
- package/dist/types.d.ts +1 -0
- package/dist/user-groups/userGroupsApi.d.ts +81 -0
- package/dist/user-groups/userGroupsApi.js +145 -0
- package/dist/user-groups/userGroupsInterfaces.d.ts +100 -0
- package/dist/user-groups/userGroupsInterfaces.js +2 -0
- package/dist/user-groups/userGroupsSchemas.d.ts +55 -0
- package/dist/user-groups/userGroupsSchemas.js +35 -0
- package/esm/base/utils.d.ts +5 -2
- package/esm/base/validation.d.ts +7 -5
- package/esm/base/validation.js +7 -4
- package/esm/file-uploading/fileUploadingApi.d.ts +27 -1
- package/esm/file-uploading/fileUploadingApi.js +42 -0
- package/esm/file-uploading/fileUploadingInterfaces.d.ts +102 -1
- package/esm/file-uploading/fileUploadingSchemas.d.ts +73 -0
- package/esm/file-uploading/fileUploadingSchemas.js +46 -0
- package/esm/index.d.ts +4 -0
- package/esm/index.js +3 -0
- package/esm/orders/ordersApi.d.ts +14 -0
- package/esm/orders/ordersApi.js +19 -0
- package/esm/orders/ordersInterfaces.d.ts +11 -0
- package/esm/payments/paymentsApi.d.ts +14 -1
- package/esm/payments/paymentsApi.js +18 -0
- package/esm/payments/paymentsInterfaces.d.ts +43 -1
- package/esm/payments/paymentsSchemas.d.ts +32 -0
- package/esm/payments/paymentsSchemas.js +19 -0
- package/esm/types.d.ts +1 -0
- package/esm/user-groups/userGroupsApi.d.ts +81 -0
- package/esm/user-groups/userGroupsApi.js +106 -0
- package/esm/user-groups/userGroupsInterfaces.d.ts +100 -0
- package/esm/user-groups/userGroupsInterfaces.js +1 -0
- package/esm/user-groups/userGroupsSchemas.d.ts +55 -0
- package/esm/user-groups/userGroupsSchemas.js +32 -0
- package/package.json +2 -2
|
@@ -157,5 +157,23 @@ class PaymentsApi extends asyncModules_1.default {
|
|
|
157
157
|
const result = await this._fetchGet(`/accounts/${id}`);
|
|
158
158
|
return this._normalizeData(result);
|
|
159
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Get the payment progress of an order: its stages and whether they are paid.
|
|
162
|
+
* @handleName getPaymentStagesByOrderId
|
|
163
|
+
* @param {number} id - ID of the order object. Example: 1.
|
|
164
|
+
* @returns {Promise<IPaymentProgress | IError>} Returns the payment progress of the order.
|
|
165
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
166
|
+
* @description An order can be paid in stages rather than in one payment — `partial` says
|
|
167
|
+
* which case it is, `completed` says whether nothing is left to pay, and every stage carries
|
|
168
|
+
* its own `status`. This method requires user authorization.
|
|
169
|
+
* @see For more information about configuring the {@link https://js-sdk.oneentry.cloud/docs/category/authprovider authorization module}, see the documentation in the {@link https://js-sdk.oneentry.cloud/docs/category/authprovider configuration settings section of the SDK}.
|
|
170
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/payments/getPaymentStagesByOrderId getPaymentStagesByOrderId} documentation.
|
|
171
|
+
*/
|
|
172
|
+
async getPaymentStagesByOrderId(id) {
|
|
173
|
+
const result = await this._fetchGet(`/stages/order/${id}`);
|
|
174
|
+
// Validate response if validation is enabled
|
|
175
|
+
const validated = await this._validateResponse(result, schema('PaymentProgressSchema'));
|
|
176
|
+
return this._normalizeData(validated);
|
|
177
|
+
}
|
|
160
178
|
}
|
|
161
179
|
exports.default = PaymentsApi;
|
|
@@ -66,6 +66,16 @@ interface IPaymentsApi {
|
|
|
66
66
|
* @see For more information about configuring the {@link https://js-sdk.oneentry.cloud/docs/category/authprovider authorization module}, see the documentation in the {@link https://js-sdk.oneentry.cloud/docs/category/authprovider configuration settings section of the SDK}.
|
|
67
67
|
*/
|
|
68
68
|
getAccountById(id: number): Promise<IAccountsEntity | IError>;
|
|
69
|
+
/**
|
|
70
|
+
* Get the payment progress of an order: its stages and whether they are paid.
|
|
71
|
+
* @handleName getPaymentStagesByOrderId
|
|
72
|
+
* @param {number} id - ID of the order object. Example: 1.
|
|
73
|
+
* @returns {IPaymentProgress} Returns the payment progress of the order.
|
|
74
|
+
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
75
|
+
* @description This method gets the payment stages of an order. This method requires user authorization.
|
|
76
|
+
* @see For more information about configuring the {@link https://js-sdk.oneentry.cloud/docs/category/authprovider authorization module}, see the documentation in the {@link https://js-sdk.oneentry.cloud/docs/category/authprovider configuration settings section of the SDK}.
|
|
77
|
+
*/
|
|
78
|
+
getPaymentStagesByOrderId(id: number): Promise<IPaymentProgress | IError>;
|
|
69
79
|
}
|
|
70
80
|
/**
|
|
71
81
|
* @interface ISessionsEntity
|
|
@@ -186,4 +196,36 @@ interface IPaymentAccountTestSettings {
|
|
|
186
196
|
signingSecretKey?: string;
|
|
187
197
|
useWebHookValidation?: boolean;
|
|
188
198
|
}
|
|
189
|
-
|
|
199
|
+
/**
|
|
200
|
+
* The `IPaymentProgress` interface describes the payment progress of an order.
|
|
201
|
+
* @interface IPaymentProgress
|
|
202
|
+
* @property {boolean} completed - True when every stage of the order has been paid. Example: false.
|
|
203
|
+
* @property {boolean} partial - True when the order is paid in stages rather than in one payment. Example: true.
|
|
204
|
+
* @property {IPaymentStage[]} stages - The stages themselves, in the order the API returns them.
|
|
205
|
+
* @description This interface describes the payment progress of an order — whether it is fully paid, whether it is split into stages, and the stages themselves.
|
|
206
|
+
*/
|
|
207
|
+
interface IPaymentProgress {
|
|
208
|
+
completed: boolean;
|
|
209
|
+
partial: boolean;
|
|
210
|
+
stages: IPaymentStage[];
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* The `IPaymentStage` interface describes one payment stage of an order.
|
|
214
|
+
* @interface IPaymentStage
|
|
215
|
+
* @property {string} marker - Marker of the attribute that set the price of the stage. Example: "part_a".
|
|
216
|
+
* @property {number} sessionId - Identifier of the payment session bound to the stage. Example: 100.
|
|
217
|
+
* @property {number} productId - Identifier of the product the stage belongs to. Example: 200.
|
|
218
|
+
* @property {string} title - Title of the stage. Example: "Part A".
|
|
219
|
+
* @property {number} value - Price of the stage. Example: 150.
|
|
220
|
+
* @property {"planned" | "completed"} status - Stage status: "planned" — not paid yet, "completed" — paid. Example: "planned".
|
|
221
|
+
* @description This interface describes one payment stage of an order.
|
|
222
|
+
*/
|
|
223
|
+
interface IPaymentStage {
|
|
224
|
+
marker: string;
|
|
225
|
+
sessionId: number;
|
|
226
|
+
productId: number;
|
|
227
|
+
title: string;
|
|
228
|
+
value: number;
|
|
229
|
+
status: 'planned' | 'completed';
|
|
230
|
+
}
|
|
231
|
+
export type { IAccountsEntity, IIntent, IPaymentAccountSettings, IPaymentAccountTestSettings, IPaymentProgress, IPaymentsApi, IPaymentStage, ISessionEntity, ISessionsEntity, };
|
|
@@ -92,3 +92,35 @@ export declare const PaymentAccountsResponseSchema: z.ZodArray<z.ZodObject<{
|
|
|
92
92
|
localizeInfos: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
93
93
|
updatedDate: z.ZodString;
|
|
94
94
|
}, z.core.$strip>>;
|
|
95
|
+
/**
|
|
96
|
+
* Payment stage schema
|
|
97
|
+
*/
|
|
98
|
+
export declare const PaymentStageSchema: z.ZodObject<{
|
|
99
|
+
marker: z.ZodString;
|
|
100
|
+
sessionId: z.ZodNumber;
|
|
101
|
+
productId: z.ZodNumber;
|
|
102
|
+
title: z.ZodString;
|
|
103
|
+
value: z.ZodNumber;
|
|
104
|
+
status: z.ZodEnum<{
|
|
105
|
+
completed: "completed";
|
|
106
|
+
planned: "planned";
|
|
107
|
+
}>;
|
|
108
|
+
}, z.core.$strip>;
|
|
109
|
+
/**
|
|
110
|
+
* Payment progress schema — stages of one order plus their aggregate state
|
|
111
|
+
*/
|
|
112
|
+
export declare const PaymentProgressSchema: z.ZodObject<{
|
|
113
|
+
completed: z.ZodBoolean;
|
|
114
|
+
partial: z.ZodBoolean;
|
|
115
|
+
stages: z.ZodArray<z.ZodObject<{
|
|
116
|
+
marker: z.ZodString;
|
|
117
|
+
sessionId: z.ZodNumber;
|
|
118
|
+
productId: z.ZodNumber;
|
|
119
|
+
title: z.ZodString;
|
|
120
|
+
value: z.ZodNumber;
|
|
121
|
+
status: z.ZodEnum<{
|
|
122
|
+
completed: "completed";
|
|
123
|
+
planned: "planned";
|
|
124
|
+
}>;
|
|
125
|
+
}, z.core.$strip>>;
|
|
126
|
+
}, z.core.$strip>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PaymentAccountsResponseSchema = exports.PaymentAccountSchema = exports.SinglePaymentSessionSchema = exports.PaymentSessionsResponseSchema = exports.PaymentSessionSchema = void 0;
|
|
3
|
+
exports.PaymentProgressSchema = exports.PaymentStageSchema = exports.PaymentAccountsResponseSchema = exports.PaymentAccountSchema = exports.SinglePaymentSessionSchema = exports.PaymentSessionsResponseSchema = exports.PaymentSessionSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
/**
|
|
6
6
|
* Payment session schema
|
|
@@ -54,3 +54,22 @@ exports.PaymentAccountSchema = zod_1.z.object({
|
|
|
54
54
|
* Payment accounts response schema
|
|
55
55
|
*/
|
|
56
56
|
exports.PaymentAccountsResponseSchema = zod_1.z.array(exports.PaymentAccountSchema);
|
|
57
|
+
/**
|
|
58
|
+
* Payment stage schema
|
|
59
|
+
*/
|
|
60
|
+
exports.PaymentStageSchema = zod_1.z.object({
|
|
61
|
+
marker: zod_1.z.string(),
|
|
62
|
+
sessionId: zod_1.z.number(),
|
|
63
|
+
productId: zod_1.z.number(),
|
|
64
|
+
title: zod_1.z.string(),
|
|
65
|
+
value: zod_1.z.number(),
|
|
66
|
+
status: zod_1.z.enum(['planned', 'completed']),
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* Payment progress schema — stages of one order plus their aggregate state
|
|
70
|
+
*/
|
|
71
|
+
exports.PaymentProgressSchema = zod_1.z.object({
|
|
72
|
+
completed: zod_1.z.boolean(),
|
|
73
|
+
partial: zod_1.z.boolean(),
|
|
74
|
+
stages: zod_1.z.array(exports.PaymentStageSchema),
|
|
75
|
+
});
|
package/dist/types.d.ts
CHANGED
|
@@ -31,5 +31,6 @@ export type * from './system/systemInterfaces';
|
|
|
31
31
|
export type * from './templates/templatesInterfaces';
|
|
32
32
|
export type * from './templates-preview/templatesPreviewInterfaces';
|
|
33
33
|
export type * from './user-activity/userActivityInterfaces';
|
|
34
|
+
export type * from './user-groups/userGroupsInterfaces';
|
|
34
35
|
export type * from './users/usersInterfaces';
|
|
35
36
|
export type * from './web-socket/wsInterfaces';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import AsyncModules from '../base/asyncModules';
|
|
2
|
+
import type StateModule from '../base/stateModule';
|
|
3
|
+
import type { IError } from '../base/utils';
|
|
4
|
+
import type { IUserGroupEntity, IUserGroups } from './userGroupsInterfaces';
|
|
5
|
+
/**
|
|
6
|
+
* Controllers for working with user groups
|
|
7
|
+
* @handle /api/content/user-groups
|
|
8
|
+
* @class UserGroupsApi
|
|
9
|
+
* @augments AsyncModules
|
|
10
|
+
* @implements {IUserGroups}
|
|
11
|
+
* @description User groups form a tree — a group may have a parent and children. The flat list
|
|
12
|
+
* comes from `getUserGroups`, the top level from `getRootUserGroups`, and the tree is walked
|
|
13
|
+
* downwards with `getChildUserGroupsByMarker`.
|
|
14
|
+
* @example
|
|
15
|
+
* const { UserGroups } = defineOneEntry('your-url', { token: 'your-app-token' });
|
|
16
|
+
* const roots = await UserGroups.getRootUserGroups();
|
|
17
|
+
*/
|
|
18
|
+
export default class UserGroupsApi extends AsyncModules implements IUserGroups {
|
|
19
|
+
protected state: StateModule;
|
|
20
|
+
protected _url: string;
|
|
21
|
+
/**
|
|
22
|
+
* Constructor
|
|
23
|
+
* @param {StateModule} state - StateModule instance
|
|
24
|
+
* @description Constructor initializes the UserGroupsApi with a given state.
|
|
25
|
+
*/
|
|
26
|
+
constructor(state: StateModule);
|
|
27
|
+
/**
|
|
28
|
+
* Get all user group objects.
|
|
29
|
+
* @handleName getUserGroups
|
|
30
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
31
|
+
* @returns {Promise<IUserGroupEntity[] | IError>} Returns an array of user group objects.
|
|
32
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
33
|
+
* @description Returns every group as a flat array, regardless of nesting.
|
|
34
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/user-groups/getUserGroups getUserGroups} documentation.
|
|
35
|
+
*/
|
|
36
|
+
getUserGroups(langCode?: string): Promise<IUserGroupEntity[] | IError>;
|
|
37
|
+
/**
|
|
38
|
+
* Get all top-level user group objects.
|
|
39
|
+
* @handleName getRootUserGroups
|
|
40
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
41
|
+
* @returns {Promise<IUserGroupEntity[] | IError>} Returns an array of user group objects with `parentId: null`.
|
|
42
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
43
|
+
* @description Returns the groups of the top level — those without a parent.
|
|
44
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/user-groups/getRootUserGroups getRootUserGroups} documentation.
|
|
45
|
+
*/
|
|
46
|
+
getRootUserGroups(langCode?: string): Promise<IUserGroupEntity[] | IError>;
|
|
47
|
+
/**
|
|
48
|
+
* Get a single user group object by its identifier.
|
|
49
|
+
* @handleName getUserGroupById
|
|
50
|
+
* @param {number} id - Identifier of the user group. Example: 1.
|
|
51
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
52
|
+
* @returns {Promise<IUserGroupEntity | IError>} Returns a single user group object.
|
|
53
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
54
|
+
* @description Get a single user group object by its identifier.
|
|
55
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/user-groups/getUserGroupById getUserGroupById} documentation.
|
|
56
|
+
*/
|
|
57
|
+
getUserGroupById(id: number, langCode?: string): Promise<IUserGroupEntity | IError>;
|
|
58
|
+
/**
|
|
59
|
+
* Get a single user group object by its marker.
|
|
60
|
+
* @handleName getUserGroupByMarker
|
|
61
|
+
* @param {string} marker - Text identifier of the user group. Example: "guest".
|
|
62
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
63
|
+
* @returns {Promise<IUserGroupEntity | IError>} Returns a single user group object.
|
|
64
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
65
|
+
* @description Get a single user group object by its marker.
|
|
66
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/user-groups/getUserGroupByMarker getUserGroupByMarker} documentation.
|
|
67
|
+
*/
|
|
68
|
+
getUserGroupByMarker(marker: string, langCode?: string): Promise<IUserGroupEntity | IError>;
|
|
69
|
+
/**
|
|
70
|
+
* Get the child groups of a user group.
|
|
71
|
+
* @handleName getChildUserGroupsByMarker
|
|
72
|
+
* @param {string} marker - Text identifier of the parent user group. Example: "guest".
|
|
73
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
74
|
+
* @returns {Promise<IUserGroupEntity[] | IError>} Returns an array of child user group objects, empty when the group has none.
|
|
75
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
76
|
+
* @description Get the child groups of a user group by the parent marker. The nesting is walked
|
|
77
|
+
* with this method rather than through `parentId`.
|
|
78
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/user-groups/getChildUserGroupsByMarker getChildUserGroupsByMarker} documentation.
|
|
79
|
+
*/
|
|
80
|
+
getChildUserGroupsByMarker(marker: string, langCode?: string): Promise<IUserGroupEntity[] | IError>;
|
|
81
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const asyncModules_1 = __importDefault(require("../base/asyncModules"));
|
|
40
|
+
const lazySchema_1 = __importDefault(require("../base/lazySchema"));
|
|
41
|
+
const schema = (0, lazySchema_1.default)(() => Promise.resolve().then(() => __importStar(require('./userGroupsSchemas'))));
|
|
42
|
+
/**
|
|
43
|
+
* Controllers for working with user groups
|
|
44
|
+
* @handle /api/content/user-groups
|
|
45
|
+
* @class UserGroupsApi
|
|
46
|
+
* @augments AsyncModules
|
|
47
|
+
* @implements {IUserGroups}
|
|
48
|
+
* @description User groups form a tree — a group may have a parent and children. The flat list
|
|
49
|
+
* comes from `getUserGroups`, the top level from `getRootUserGroups`, and the tree is walked
|
|
50
|
+
* downwards with `getChildUserGroupsByMarker`.
|
|
51
|
+
* @example
|
|
52
|
+
* const { UserGroups } = defineOneEntry('your-url', { token: 'your-app-token' });
|
|
53
|
+
* const roots = await UserGroups.getRootUserGroups();
|
|
54
|
+
*/
|
|
55
|
+
class UserGroupsApi extends asyncModules_1.default {
|
|
56
|
+
/**
|
|
57
|
+
* Constructor
|
|
58
|
+
* @param {StateModule} state - StateModule instance
|
|
59
|
+
* @description Constructor initializes the UserGroupsApi with a given state.
|
|
60
|
+
*/
|
|
61
|
+
constructor(state) {
|
|
62
|
+
super(state);
|
|
63
|
+
this._url = state.url + '/api/content/user-groups';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get all user group objects.
|
|
67
|
+
* @handleName getUserGroups
|
|
68
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
69
|
+
* @returns {Promise<IUserGroupEntity[] | IError>} Returns an array of user group objects.
|
|
70
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
71
|
+
* @description Returns every group as a flat array, regardless of nesting.
|
|
72
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/user-groups/getUserGroups getUserGroups} documentation.
|
|
73
|
+
*/
|
|
74
|
+
async getUserGroups(langCode = this.state.lang) {
|
|
75
|
+
const result = await this._fetchGet(`/?langCode=${langCode}`);
|
|
76
|
+
// Validate response if validation is enabled
|
|
77
|
+
const validated = await this._validateResponse(result, schema('UserGroupsResponseSchema'));
|
|
78
|
+
return this._normalizeData(validated, langCode);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get all top-level user group objects.
|
|
82
|
+
* @handleName getRootUserGroups
|
|
83
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
84
|
+
* @returns {Promise<IUserGroupEntity[] | IError>} Returns an array of user group objects with `parentId: null`.
|
|
85
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
86
|
+
* @description Returns the groups of the top level — those without a parent.
|
|
87
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/user-groups/getRootUserGroups getRootUserGroups} documentation.
|
|
88
|
+
*/
|
|
89
|
+
async getRootUserGroups(langCode = this.state.lang) {
|
|
90
|
+
const result = await this._fetchGet(`/root?langCode=${langCode}`);
|
|
91
|
+
// Validate response if validation is enabled
|
|
92
|
+
const validated = await this._validateResponse(result, schema('UserGroupsResponseSchema'));
|
|
93
|
+
return this._normalizeData(validated, langCode);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get a single user group object by its identifier.
|
|
97
|
+
* @handleName getUserGroupById
|
|
98
|
+
* @param {number} id - Identifier of the user group. Example: 1.
|
|
99
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
100
|
+
* @returns {Promise<IUserGroupEntity | IError>} Returns a single user group object.
|
|
101
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
102
|
+
* @description Get a single user group object by its identifier.
|
|
103
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/user-groups/getUserGroupById getUserGroupById} documentation.
|
|
104
|
+
*/
|
|
105
|
+
async getUserGroupById(id, langCode = this.state.lang) {
|
|
106
|
+
const result = await this._fetchGet(`/${id}?langCode=${langCode}`);
|
|
107
|
+
// Validate response if validation is enabled
|
|
108
|
+
const validated = await this._validateResponse(result, schema('UserGroupEntitySchema'));
|
|
109
|
+
return this._normalizeData(validated, langCode);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get a single user group object by its marker.
|
|
113
|
+
* @handleName getUserGroupByMarker
|
|
114
|
+
* @param {string} marker - Text identifier of the user group. Example: "guest".
|
|
115
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
116
|
+
* @returns {Promise<IUserGroupEntity | IError>} Returns a single user group object.
|
|
117
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
118
|
+
* @description Get a single user group object by its marker.
|
|
119
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/user-groups/getUserGroupByMarker getUserGroupByMarker} documentation.
|
|
120
|
+
*/
|
|
121
|
+
async getUserGroupByMarker(marker, langCode = this.state.lang) {
|
|
122
|
+
const result = await this._fetchGet(`/marker/${marker}?langCode=${langCode}`);
|
|
123
|
+
// Validate response if validation is enabled
|
|
124
|
+
const validated = await this._validateResponse(result, schema('UserGroupEntitySchema'));
|
|
125
|
+
return this._normalizeData(validated, langCode);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get the child groups of a user group.
|
|
129
|
+
* @handleName getChildUserGroupsByMarker
|
|
130
|
+
* @param {string} marker - Text identifier of the parent user group. Example: "guest".
|
|
131
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
132
|
+
* @returns {Promise<IUserGroupEntity[] | IError>} Returns an array of child user group objects, empty when the group has none.
|
|
133
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
134
|
+
* @description Get the child groups of a user group by the parent marker. The nesting is walked
|
|
135
|
+
* with this method rather than through `parentId`.
|
|
136
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/user-groups/getChildUserGroupsByMarker getChildUserGroupsByMarker} documentation.
|
|
137
|
+
*/
|
|
138
|
+
async getChildUserGroupsByMarker(marker, langCode = this.state.lang) {
|
|
139
|
+
const result = await this._fetchGet(`/marker/${marker}/children?langCode=${langCode}`);
|
|
140
|
+
// Validate response if validation is enabled
|
|
141
|
+
const validated = await this._validateResponse(result, schema('UserGroupsResponseSchema'));
|
|
142
|
+
return this._normalizeData(validated, langCode);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.default = UserGroupsApi;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { IAttributeValues, IError, ILocalizeInfo } from '../base/utils';
|
|
2
|
+
/**
|
|
3
|
+
* The `IUserGroups` interface defines methods for reading user groups.
|
|
4
|
+
* @interface IUserGroups
|
|
5
|
+
* @description User groups form a tree: a group may have a parent and children, and the tree is
|
|
6
|
+
* walked through the marker-based methods. Every method requires the project token.
|
|
7
|
+
*/
|
|
8
|
+
interface IUserGroups {
|
|
9
|
+
/**
|
|
10
|
+
* Get all user group objects.
|
|
11
|
+
* @handleName getUserGroups
|
|
12
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
13
|
+
* @returns {IUserGroupEntity[]} Returns an array of user group objects.
|
|
14
|
+
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
15
|
+
* @description This method gets all user group objects, flat, regardless of nesting.
|
|
16
|
+
*/
|
|
17
|
+
getUserGroups(langCode?: string): Promise<IUserGroupEntity[] | IError>;
|
|
18
|
+
/**
|
|
19
|
+
* Get all top-level user group objects.
|
|
20
|
+
* @handleName getRootUserGroups
|
|
21
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
22
|
+
* @returns {IUserGroupEntity[]} Returns an array of user group objects with `parentId: null`.
|
|
23
|
+
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
24
|
+
* @description This method gets the user groups of the top level — those without a parent.
|
|
25
|
+
*/
|
|
26
|
+
getRootUserGroups(langCode?: string): Promise<IUserGroupEntity[] | IError>;
|
|
27
|
+
/**
|
|
28
|
+
* Get a single user group object by its identifier.
|
|
29
|
+
* @handleName getUserGroupById
|
|
30
|
+
* @param {number} id - Identifier of the user group. Example: 1.
|
|
31
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
32
|
+
* @returns {IUserGroupEntity} Returns a single user group object.
|
|
33
|
+
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
34
|
+
* @description This method gets a single user group object by its identifier.
|
|
35
|
+
*/
|
|
36
|
+
getUserGroupById(id: number, langCode?: string): Promise<IUserGroupEntity | IError>;
|
|
37
|
+
/**
|
|
38
|
+
* Get a single user group object by its marker.
|
|
39
|
+
* @handleName getUserGroupByMarker
|
|
40
|
+
* @param {string} marker - Text identifier of the user group. Example: "guest".
|
|
41
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
42
|
+
* @returns {IUserGroupEntity} Returns a single user group object.
|
|
43
|
+
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
44
|
+
* @description This method gets a single user group object by its marker.
|
|
45
|
+
*/
|
|
46
|
+
getUserGroupByMarker(marker: string, langCode?: string): Promise<IUserGroupEntity | IError>;
|
|
47
|
+
/**
|
|
48
|
+
* Get the child groups of a user group.
|
|
49
|
+
* @handleName getChildUserGroupsByMarker
|
|
50
|
+
* @param {string} marker - Text identifier of the parent user group. Example: "guest".
|
|
51
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
52
|
+
* @returns {IUserGroupEntity[]} Returns an array of child user group objects, empty when the group has none.
|
|
53
|
+
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
54
|
+
* @description This method gets the child groups of a user group by the parent marker.
|
|
55
|
+
*/
|
|
56
|
+
getChildUserGroupsByMarker(marker: string, langCode?: string): Promise<IUserGroupEntity[] | IError>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The `IUserGroupEntity` interface defines the structure of a user group object.
|
|
60
|
+
* @interface IUserGroupEntity
|
|
61
|
+
* @property {number} id - Identifier of the user group. Example: 1.
|
|
62
|
+
* @property {number} depth - Nesting depth relative to the parent. Example: 0.
|
|
63
|
+
* @property {number | null} parentId - Identifier of the parent group, `null` for a top-level group. Example: null.
|
|
64
|
+
* @property {ILocalizeInfo} localizeInfos - Title of the group, taking localization into account.
|
|
65
|
+
* @property {boolean} isVisible - Visibility flag. Example: true.
|
|
66
|
+
* @property {string} childrenCount - Number of child groups. The API sends it as a **string**, not a number. Example: "0".
|
|
67
|
+
* @property {string} identifier - Text identifier (marker) of the group. Example: "guest".
|
|
68
|
+
* @property {boolean} isSync - Synchronization flag. Example: false.
|
|
69
|
+
* @property {IAttributeValues} attributeValues - Attribute values of the group.
|
|
70
|
+
* @property {number} [version] - Version of the object. Not present on every stand. Example: 0.
|
|
71
|
+
* @description Structure of a user group object.
|
|
72
|
+
* @example
|
|
73
|
+
* ```json
|
|
74
|
+
* {
|
|
75
|
+
* "id": 1,
|
|
76
|
+
* "depth": 0,
|
|
77
|
+
* "parentId": null,
|
|
78
|
+
* "localizeInfos": { "title": "Guest" },
|
|
79
|
+
* "isVisible": true,
|
|
80
|
+
* "childrenCount": "0",
|
|
81
|
+
* "identifier": "guest",
|
|
82
|
+
* "isSync": false,
|
|
83
|
+
* "attributeValues": {},
|
|
84
|
+
* "version": 0
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
interface IUserGroupEntity {
|
|
89
|
+
id: number;
|
|
90
|
+
depth: number;
|
|
91
|
+
parentId: number | null;
|
|
92
|
+
localizeInfos: ILocalizeInfo;
|
|
93
|
+
isVisible: boolean;
|
|
94
|
+
childrenCount: string;
|
|
95
|
+
identifier: string;
|
|
96
|
+
isSync: boolean;
|
|
97
|
+
attributeValues: IAttributeValues;
|
|
98
|
+
version?: number;
|
|
99
|
+
}
|
|
100
|
+
export type { IUserGroupEntity, IUserGroups };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation schemas for UserGroups module
|
|
3
|
+
* @description Zod schemas for validating user-group API responses
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
/**
|
|
7
|
+
* User group entity schema.
|
|
8
|
+
*
|
|
9
|
+
* `childrenCount` is a **string** here because that is what the API sends
|
|
10
|
+
* (`"0"`), even though the platform DTO declares it a number. The schema
|
|
11
|
+
* describes the raw response, so it follows the response.
|
|
12
|
+
*/
|
|
13
|
+
export declare const UserGroupEntitySchema: z.ZodObject<{
|
|
14
|
+
id: z.ZodNumber;
|
|
15
|
+
depth: z.ZodNumber;
|
|
16
|
+
parentId: z.ZodNullable<z.ZodNumber>;
|
|
17
|
+
localizeInfos: z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
18
|
+
title: z.ZodString;
|
|
19
|
+
content: z.ZodOptional<z.ZodString>;
|
|
20
|
+
menuTitle: z.ZodOptional<z.ZodString>;
|
|
21
|
+
}, z.core.$strip>>, z.ZodObject<{
|
|
22
|
+
title: z.ZodString;
|
|
23
|
+
content: z.ZodOptional<z.ZodString>;
|
|
24
|
+
menuTitle: z.ZodOptional<z.ZodString>;
|
|
25
|
+
}, z.core.$strip>]>;
|
|
26
|
+
isVisible: z.ZodBoolean;
|
|
27
|
+
childrenCount: z.ZodString;
|
|
28
|
+
identifier: z.ZodString;
|
|
29
|
+
isSync: z.ZodBoolean;
|
|
30
|
+
attributeValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
31
|
+
version: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
/**
|
|
34
|
+
* User groups response schema (array of groups)
|
|
35
|
+
*/
|
|
36
|
+
export declare const UserGroupsResponseSchema: z.ZodArray<z.ZodObject<{
|
|
37
|
+
id: z.ZodNumber;
|
|
38
|
+
depth: z.ZodNumber;
|
|
39
|
+
parentId: z.ZodNullable<z.ZodNumber>;
|
|
40
|
+
localizeInfos: z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
41
|
+
title: z.ZodString;
|
|
42
|
+
content: z.ZodOptional<z.ZodString>;
|
|
43
|
+
menuTitle: z.ZodOptional<z.ZodString>;
|
|
44
|
+
}, z.core.$strip>>, z.ZodObject<{
|
|
45
|
+
title: z.ZodString;
|
|
46
|
+
content: z.ZodOptional<z.ZodString>;
|
|
47
|
+
menuTitle: z.ZodOptional<z.ZodString>;
|
|
48
|
+
}, z.core.$strip>]>;
|
|
49
|
+
isVisible: z.ZodBoolean;
|
|
50
|
+
childrenCount: z.ZodString;
|
|
51
|
+
identifier: z.ZodString;
|
|
52
|
+
isSync: z.ZodBoolean;
|
|
53
|
+
attributeValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
54
|
+
version: z.ZodOptional<z.ZodNumber>;
|
|
55
|
+
}, z.core.$strip>>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserGroupsResponseSchema = exports.UserGroupEntitySchema = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Validation schemas for UserGroups module
|
|
6
|
+
* @description Zod schemas for validating user-group API responses
|
|
7
|
+
*/
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const validation_1 = require("../base/validation");
|
|
10
|
+
/**
|
|
11
|
+
* User group entity schema.
|
|
12
|
+
*
|
|
13
|
+
* `childrenCount` is a **string** here because that is what the API sends
|
|
14
|
+
* (`"0"`), even though the platform DTO declares it a number. The schema
|
|
15
|
+
* describes the raw response, so it follows the response.
|
|
16
|
+
*/
|
|
17
|
+
exports.UserGroupEntitySchema = zod_1.z.object({
|
|
18
|
+
id: zod_1.z.number(),
|
|
19
|
+
depth: zod_1.z.number(),
|
|
20
|
+
parentId: zod_1.z.number().nullable(),
|
|
21
|
+
localizeInfos: zod_1.z.union([
|
|
22
|
+
zod_1.z.record(zod_1.z.string(), validation_1.LocalizeInfoSchema),
|
|
23
|
+
validation_1.LocalizeInfoSchema,
|
|
24
|
+
]),
|
|
25
|
+
isVisible: zod_1.z.boolean(),
|
|
26
|
+
childrenCount: zod_1.z.string(),
|
|
27
|
+
identifier: zod_1.z.string(),
|
|
28
|
+
isSync: zod_1.z.boolean(),
|
|
29
|
+
attributeValues: validation_1.AttributeValuesSchema,
|
|
30
|
+
version: zod_1.z.number().optional(),
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* User groups response schema (array of groups)
|
|
34
|
+
*/
|
|
35
|
+
exports.UserGroupsResponseSchema = zod_1.z.array(exports.UserGroupEntitySchema);
|
package/esm/base/utils.d.ts
CHANGED
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
* @property {string} [deviceMetadata] - Device-metadata string sent as the `x-device-metadata` header on POST requests and token refresh, overriding the environment-derived fingerprint. The API binds refresh tokens to this header, so server-side flows that issue tokens on behalf of a browser (e.g. an OAuth code exchange) must pass the browser's string here — otherwise the token is bound to the server's fingerprint and cannot be refreshed from the browser. Obtain the string in the browser via `getDeviceMetadata()`. Can also be set later via `setDeviceMetadata`.
|
|
6
6
|
* @property {string} [langCode] - specify the default language to avoid specifying it in every request.
|
|
7
7
|
* @property {boolean} [traficLimit] - Some methods use multiple queries to make it easier to work with the API. Set this parameter to "false" to save traffic and decide for yourself what data you need.
|
|
8
|
-
* @property {boolean} [rawData] - Set to true to
|
|
8
|
+
* @property {boolean} [rawData] - Set to true to keep an attribute's nested `additionalFields` as the
|
|
9
|
+
* array the API sends, instead of the marker-keyed map the SDK builds by default. It turns off only that
|
|
10
|
+
* transformation — locale unwrapping, sorting by `position`, single-file unwrapping and number casting
|
|
11
|
+
* still apply. `getAdditionalFields` returns the same marker map in either mode.
|
|
9
12
|
* @property {object} [validation] - Validation settings for API responses.
|
|
10
13
|
* @property {boolean} [auth] - An object with authorization settings.
|
|
11
14
|
* @property {boolean} [auth.customAuth] - Set this flag to true if you want to configure the authorization process yourself. Set the flag to false, or do not pass it at all to have automatic authorization and token renewal.
|
|
@@ -22,7 +25,7 @@
|
|
|
22
25
|
* const config = {
|
|
23
26
|
* token: 'project.token.here',
|
|
24
27
|
* langCode: 'en_US',
|
|
25
|
-
*
|
|
28
|
+
* traficLimit: true,
|
|
26
29
|
* auth: {
|
|
27
30
|
* customAuth: false,
|
|
28
31
|
* refreshToken: 'user.refresh.token',
|
package/esm/base/validation.d.ts
CHANGED
|
@@ -99,16 +99,18 @@ export declare const AuthEntitySchema: z.ZodObject<{
|
|
|
99
99
|
*/
|
|
100
100
|
export declare function createPaginatedSchema<T extends z.ZodTypeAny>(itemSchema: T): any;
|
|
101
101
|
/**
|
|
102
|
-
* Validation helper function
|
|
102
|
+
* Validation helper function.
|
|
103
|
+
*
|
|
104
|
+
* This is the strict half of the pair: it reports a failure instead of hiding it.
|
|
105
|
+
* Strictness is the choice of function, not an option — `validateResponseSafe` is the
|
|
106
|
+
* lenient one, and `_validateResponse` picks between them by `config.validation.strictMode`.
|
|
103
107
|
* @param {z.ZodSchema<T>} schema - Zod schema to validate against
|
|
104
108
|
* @param {unknown} data - Data to validate
|
|
105
|
-
* @param {object} options - Validation options
|
|
106
|
-
* @param {boolean} options.
|
|
107
|
-
* @param {boolean} options.logErrors - Whether to log errors
|
|
109
|
+
* @param {object} [options] - Validation options
|
|
110
|
+
* @param {boolean} [options.logErrors] - Whether to log errors
|
|
108
111
|
* @returns {object} Validated data or error
|
|
109
112
|
*/
|
|
110
113
|
export declare function validateResponse<T>(schema: z.ZodSchema<T>, data: unknown, options?: {
|
|
111
|
-
strict?: boolean;
|
|
112
114
|
logErrors?: boolean;
|
|
113
115
|
}): {
|
|
114
116
|
success: true;
|
package/esm/base/validation.js
CHANGED
|
@@ -169,12 +169,15 @@ export function createPaginatedSchema(itemSchema) {
|
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
172
|
-
* Validation helper function
|
|
172
|
+
* Validation helper function.
|
|
173
|
+
*
|
|
174
|
+
* This is the strict half of the pair: it reports a failure instead of hiding it.
|
|
175
|
+
* Strictness is the choice of function, not an option — `validateResponseSafe` is the
|
|
176
|
+
* lenient one, and `_validateResponse` picks between them by `config.validation.strictMode`.
|
|
173
177
|
* @param {z.ZodSchema<T>} schema - Zod schema to validate against
|
|
174
178
|
* @param {unknown} data - Data to validate
|
|
175
|
-
* @param {object} options - Validation options
|
|
176
|
-
* @param {boolean} options.
|
|
177
|
-
* @param {boolean} options.logErrors - Whether to log errors
|
|
179
|
+
* @param {object} [options] - Validation options
|
|
180
|
+
* @param {boolean} [options.logErrors] - Whether to log errors
|
|
178
181
|
* @returns {object} Validated data or error
|
|
179
182
|
*/
|
|
180
183
|
export function validateResponse(schema, data, options) {
|