oneentry 1.0.166 → 1.0.168
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 +46 -0
- package/dist/auth-provider/authProviderApi.js +3 -2
- package/dist/base/asyncModules.d.ts +18 -0
- package/dist/base/asyncModules.js +34 -1
- package/dist/base/syncModules.d.ts +10 -3
- package/dist/base/syncModules.js +25 -14
- 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/discounts/discountsApi.d.ts +3 -3
- package/dist/discounts/discountsApi.js +1 -1
- package/dist/discounts/discountsInterfaces.d.ts +15 -3
- 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/forms-data/formsDataInterfaces.d.ts +130 -3
- 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/search/searchApi.d.ts +3 -2
- package/dist/search/searchApi.js +6 -2
- package/dist/search/searchInterfaces.d.ts +3 -2
- 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/dist/users/usersApi.js +3 -3
- package/esm/auth-provider/authProviderApi.js +3 -2
- package/esm/base/asyncModules.d.ts +18 -0
- package/esm/base/asyncModules.js +34 -1
- package/esm/base/syncModules.d.ts +10 -3
- package/esm/base/syncModules.js +25 -14
- 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/discounts/discountsApi.d.ts +3 -3
- package/esm/discounts/discountsApi.js +1 -1
- package/esm/discounts/discountsInterfaces.d.ts +15 -3
- 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/forms-data/formsDataInterfaces.d.ts +130 -3
- 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/search/searchApi.d.ts +3 -2
- package/esm/search/searchApi.js +6 -2
- package/esm/search/searchInterfaces.d.ts +3 -2
- 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/esm/users/usersApi.js +3 -3
- package/package.json +2 -2
|
@@ -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/dist/users/usersApi.js
CHANGED
|
@@ -147,9 +147,9 @@ class UsersApi extends asyncModules_1.default {
|
|
|
147
147
|
* @see {@link https://js-sdk.oneentry.cloud/docs/users/updateUser updateUser} documentation.
|
|
148
148
|
*/
|
|
149
149
|
async updateUser(body, langCode = this.state.lang) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const result = await this._fetchPut('/me', this._normalizePostBody(
|
|
150
|
+
// The language goes onto our own copy; the caller's body is left alone (CMS-909).
|
|
151
|
+
const payload = 'langCode' in body ? body : { ...body, langCode };
|
|
152
|
+
const result = await this._fetchPut('/me', this._normalizePostBody(payload, langCode));
|
|
153
153
|
const validated = await this._validateResponse(result, schema('UpdateUserResponseSchema'));
|
|
154
154
|
return validated;
|
|
155
155
|
}
|
|
@@ -86,8 +86,9 @@ export default class AuthProviderApi extends AsyncModules {
|
|
|
86
86
|
* @see {@link https://js-sdk.oneentry.cloud/docs/auth-provider/signUp signUp} documentation.
|
|
87
87
|
*/
|
|
88
88
|
async signUp(marker, body, langCode = this.state.lang) {
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
// `langCode` goes onto our own copy — the caller's body stays as it was
|
|
90
|
+
// given, so a retry or a second parallel call sends the same thing (CMS-909).
|
|
91
|
+
const result = await this._fetchPost(`/marker/${marker}/users/sign-up`, this._normalizePostBody({ ...body, langCode }, langCode));
|
|
91
92
|
// Validate response if validation is enabled
|
|
92
93
|
const validated = await this._validateResponse(result, schema('SignUpResponseSchema'));
|
|
93
94
|
return this._normalizeData(validated);
|
|
@@ -120,4 +120,22 @@ export default abstract class AsyncModules extends SyncModules {
|
|
|
120
120
|
* @description Define an asynchronous method 'browserResponse' that takes a path and options as parameters
|
|
121
121
|
*/
|
|
122
122
|
private browserResponse;
|
|
123
|
+
/**
|
|
124
|
+
* Turns whatever was thrown into the error shape the SDK already returns.
|
|
125
|
+
*
|
|
126
|
+
* With `isShell` on, a failure is returned rather than thrown — and a dropped
|
|
127
|
+
* connection throws a `TypeError`, whose `message` and `stack` are not
|
|
128
|
+
* enumerable. Returned as it was, it serializes to `{}` and reads exactly
|
|
129
|
+
* like an empty answer: on the sanbenitocog pilot such a value entered the
|
|
130
|
+
* page cache and was served for minutes after the link came back, and
|
|
131
|
+
* `next build` baked a site of 404s while reporting success (CMS-780).
|
|
132
|
+
*
|
|
133
|
+
* An object that already carries a `statusCode` is the platform's own error
|
|
134
|
+
* and is passed through untouched. Everything else becomes
|
|
135
|
+
* `{ statusCode: 0, message, pageData: null, timestamp }` — `statusCode: 0`
|
|
136
|
+
* says "the request never reached the platform", which no HTTP answer uses.
|
|
137
|
+
* @param {unknown} e - Whatever the try block threw.
|
|
138
|
+
* @returns {IError} The error in the shape the SDK returns for platform errors.
|
|
139
|
+
*/
|
|
140
|
+
private _toShellError;
|
|
123
141
|
}
|
package/esm/base/asyncModules.js
CHANGED
|
@@ -372,11 +372,44 @@ export default class AsyncModules extends SyncModules {
|
|
|
372
372
|
// Handle any errors that occur during the fetch process
|
|
373
373
|
// Determine whether to return or throw the error based on 'isShell' state
|
|
374
374
|
if (this.state.isShell) {
|
|
375
|
-
return e;
|
|
375
|
+
return this._toShellError(e);
|
|
376
376
|
}
|
|
377
377
|
else {
|
|
378
378
|
throw e;
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
+
/**
|
|
383
|
+
* Turns whatever was thrown into the error shape the SDK already returns.
|
|
384
|
+
*
|
|
385
|
+
* With `isShell` on, a failure is returned rather than thrown — and a dropped
|
|
386
|
+
* connection throws a `TypeError`, whose `message` and `stack` are not
|
|
387
|
+
* enumerable. Returned as it was, it serializes to `{}` and reads exactly
|
|
388
|
+
* like an empty answer: on the sanbenitocog pilot such a value entered the
|
|
389
|
+
* page cache and was served for minutes after the link came back, and
|
|
390
|
+
* `next build` baked a site of 404s while reporting success (CMS-780).
|
|
391
|
+
*
|
|
392
|
+
* An object that already carries a `statusCode` is the platform's own error
|
|
393
|
+
* and is passed through untouched. Everything else becomes
|
|
394
|
+
* `{ statusCode: 0, message, pageData: null, timestamp }` — `statusCode: 0`
|
|
395
|
+
* says "the request never reached the platform", which no HTTP answer uses.
|
|
396
|
+
* @param {unknown} e - Whatever the try block threw.
|
|
397
|
+
* @returns {IError} The error in the shape the SDK returns for platform errors.
|
|
398
|
+
*/
|
|
399
|
+
_toShellError(e) {
|
|
400
|
+
if (e && typeof e === 'object' && 'statusCode' in e) {
|
|
401
|
+
return e;
|
|
402
|
+
}
|
|
403
|
+
const message = e instanceof Error
|
|
404
|
+
? `${e.name}: ${e.message}`
|
|
405
|
+
: typeof e === 'string'
|
|
406
|
+
? e
|
|
407
|
+
: 'Request failed before a response was received';
|
|
408
|
+
return {
|
|
409
|
+
statusCode: 0,
|
|
410
|
+
message,
|
|
411
|
+
pageData: null,
|
|
412
|
+
timestamp: new Date().toISOString(),
|
|
413
|
+
};
|
|
414
|
+
}
|
|
382
415
|
}
|
|
@@ -81,10 +81,17 @@ export default abstract class SyncModules {
|
|
|
81
81
|
* 2. **formData localization**: the API expects formData as
|
|
82
82
|
* `{ "<langCode>": [...fields] }`, but callers pass a flat array or a single object.
|
|
83
83
|
* The method wraps the data into the required structure.
|
|
84
|
-
* If `formData` is absent from the body — return
|
|
85
|
-
*
|
|
84
|
+
* If `formData` is absent from the body — return a copy with only the phoneSMS cleanup applied.
|
|
85
|
+
*
|
|
86
|
+
* **The caller's object is never touched.** Methods that post a body are
|
|
87
|
+
* routinely called with one that is reused — a retry wrapper, two parallel
|
|
88
|
+
* calls, a shared default. Normalizing in place sends the already-wrapped
|
|
89
|
+
* value the second time, it is wrapped again, and the platform answers
|
|
90
|
+
* `400 "formData.en_US[0].marker" is required` about a field the caller
|
|
91
|
+
* never sent (CMS-909).
|
|
92
|
+
* @param {any} body - The body to normalize. Left unchanged.
|
|
86
93
|
* @param {string} [langCode] - The language code for normalization.
|
|
87
|
-
* @returns {any}
|
|
94
|
+
* @returns {any} A normalized copy of the body.
|
|
88
95
|
*/
|
|
89
96
|
protected _normalizePostBody(body: any, langCode?: string): any;
|
|
90
97
|
/**
|
package/esm/base/syncModules.js
CHANGED
|
@@ -218,27 +218,38 @@ export default class SyncModules {
|
|
|
218
218
|
* 2. **formData localization**: the API expects formData as
|
|
219
219
|
* `{ "<langCode>": [...fields] }`, but callers pass a flat array or a single object.
|
|
220
220
|
* The method wraps the data into the required structure.
|
|
221
|
-
* If `formData` is absent from the body — return
|
|
222
|
-
*
|
|
221
|
+
* If `formData` is absent from the body — return a copy with only the phoneSMS cleanup applied.
|
|
222
|
+
*
|
|
223
|
+
* **The caller's object is never touched.** Methods that post a body are
|
|
224
|
+
* routinely called with one that is reused — a retry wrapper, two parallel
|
|
225
|
+
* calls, a shared default. Normalizing in place sends the already-wrapped
|
|
226
|
+
* value the second time, it is wrapped again, and the platform answers
|
|
227
|
+
* `400 "formData.en_US[0].marker" is required` about a field the caller
|
|
228
|
+
* never sent (CMS-909).
|
|
229
|
+
* @param {any} body - The body to normalize. Left unchanged.
|
|
223
230
|
* @param {string} [langCode] - The language code for normalization.
|
|
224
|
-
* @returns {any}
|
|
231
|
+
* @returns {any} A normalized copy of the body.
|
|
225
232
|
*/
|
|
226
233
|
_normalizePostBody(body, langCode = this.state.lang) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
234
|
+
const next = { ...body };
|
|
235
|
+
// API does not accept phoneSMS = '' — drop the field if empty. `notificationData`
|
|
236
|
+
// is copied too: deleting the key on the original would reach the caller.
|
|
237
|
+
if (next.notificationData && next.notificationData.phoneSMS === '') {
|
|
238
|
+
next.notificationData = { ...next.notificationData };
|
|
239
|
+
delete next.notificationData.phoneSMS;
|
|
230
240
|
}
|
|
231
241
|
// If formData is not provided — no further normalization needed.
|
|
232
|
-
if (!
|
|
233
|
-
return
|
|
242
|
+
if (!next.formData)
|
|
243
|
+
return next;
|
|
234
244
|
// Wrap form fields in an object keyed by locale:
|
|
235
245
|
// [{ marker, value }] → { "en_US": [{ marker, value }] }
|
|
236
|
-
|
|
237
|
-
formData
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
246
|
+
// The fields themselves are reused by reference — they are not modified.
|
|
247
|
+
next.formData = {
|
|
248
|
+
[langCode]: Array.isArray(next.formData)
|
|
249
|
+
? next.formData
|
|
250
|
+
: [next.formData],
|
|
251
|
+
};
|
|
252
|
+
return next;
|
|
242
253
|
}
|
|
243
254
|
/**
|
|
244
255
|
* Normalizes the value of a single attribute in place.
|
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;
|