oneentry
v1.0.114
Published
OneEntry NPM package
Downloads
927
Readme
OneEntry SDK
OneEntry Headless CMS SDK is an SDK that provides an easy way to interact with the OneEntry Headless CMS API.
Official Site
Visit the official AsyncModules website at https://oneentry.cloud to learn more about the AsyncModules Headless CMS.
Sign Up
To get started with AsyncModules, sign up for an account at https://account.oneentry.cloud/authentication/register.
Installation
To install the AsyncModules Headless CMS SDK in your project, run the following command:
npm install oneentry
Get Started
To use the AsyncModules Headless CMS SDK in your project, import the defineOneEntry function:
import { defineOneEntry } from 'oneentry'
const {
Admins,
AttributesSets,
AuthProvider,
Blocks,
Events,
Forms,
FormData,
FileUploading,
GeneralTypes,
IntegrationCollections,
Locales,
Menus,
Orders,
Pages,
Products,
ProductStatuses,
System,
Templates,
TemplatePreviews,
Users,
WS
} = defineOneEntry('your-url');
Or
const api = defineOneEntry('your-url');
Config
The second parameter of the constructor takes the 'config'. It contains the following values:
'token' - Set the token key if your project secure "Security API Token". If you are using certificate protection, do not pass this variable. You can read more about the security of your project here.
'langCode' - Set the "langCode" to set the default language. By specifying this parameter once, you don't have to pass the langCode to the methods ONEENTRY API. If you have not passed the default language, it will be set "en_US".
'traficLimit' - Some methods use more than one request to the CMS so that the data you receive is complete and easy to work with. Pass the value "true" for this parameter to save traffic and decide for yourself what data you need. The default value "false".
'auth' - An object with authorization settings. By default, the SDK is configured to work with tokens inside the user's session and does not require any additional work from you. At the same time, the SDK does not store the session state between sessions. If you are satisfied with such settings, do not pass the variable 'auth' at all.
The 'auth' contains the following settings:
'refreshToken' - The user's refresh token. Transfer it here from the repository to restore the user's session during initialization.
'saveFunction' - A function that works with the update refresh token. If you want to store the token between sessions, for example in local storage, pass a function here that does this. The function must accept a parameter to which the string with the token will be passed.
'customAuth' - If you want to configure authorization and work with tokens yourself, set this flag to true. If you want to use the sdk settings, set it to false or do not transfer it at all.
An example of a configuration with token protection and automatic authentication that stores state between sessions
const tokenFunction = (token) => {
localStorage.setItem('refreshToken', token)
}
const api = defineOneEntry('https://my-project.oneentry.cloud', {
token:'my-token',
langCode:'en_US',
auth: {
refreshToken: localStorage.getItem('refreshToken'),
saveFunction: tokenFunction
}
})
An example of a configuration that is protected with a certificate allows you to configure the authorization system yourself and saves data on requests.
const api = defineOneEntry('https://my-project.oneentry.cloud', {
langCode:'en_US',
traficLimit: true,
auth: {
customAuth: true,
refreshToken: localStorage.getItem('refreshToken')
}
})
If you have chosen to configure tokens yourself, you can pass the token to the method as follows. The intermediate method allows you to pass an access token to the request. Then call the required method. This method (setAccessToken) should not be called if the method does not require user authorization.
const user = api.Users.setAccessToken('my.access.token').getUser()
If you chose token protection to ensure connection security, just pass your token to the function as an optional parameter.
You can get a token as follows
- Log in to your personal account
- Go to the "Projects" tab and select a project
- Go to the "Access" tab
- Set the switch to "Security API Token"
- Log in to the project, go to the settings section and open the token tab
- Get and copy the token of your project
You can also connect a tls certificate to protect your project. In this case, do not pass the "token" at all. When using the certificate, set up a proxy in your project. Pass an empty string as an url parameter. Learn more about security
const saveTokenFromLocalStorage = (token) => {
localStorage.setItem('refreshToken', token)
}
const api = defineOneEntry('your-url', {
token: 'my-token',
langCode:'my-langCode',
auth: {
customAuth: false,
userToken: 'rerfesh.token',
saveFunction: saveTokenFromLocalStorage
}
});
Errors
If you want to escape errors inside the sc, leave the "errors" property by default. In this case, you will receive either the entity data or the error object. You need to do a type check. for example, by checking the statusCode property with ".hasOwnProperty"
However, if you want to use the construction "try {} catch(e) {}", set the property "isShell" to the value "false". In this case, you need to handle the error using "try {} catch(e) {}".
Also, you can pass custom functions that will be called inside the sdk with the appropriate error code. These functions receive an error object as an argument. You can process it yourself.
const api = defineOneEntry('your-url', {
token: 'my-token',
langCode:'my-langCode',
errors: {
isShell: false,
customErrors: {
400: (error) => console.error(error.message),
404: (error) => console.error(error.message),
500: (error) => console.error(error.message)
}
}
});
Now you can use the following links to jump to specific entries:
- Admins
- AttributesSets
- AuthProvider
- Blocks
- Events
- Forms
- FormData
- FileUploading
- GeneralTypes
- IntegrationCollections
- Locales
- Menus
- Orders
- Pages
- Payments
- Products
- ProductStatuses
- System
- Templates
- TemplatePreviews
- Users
- WS
Admins
const { Admins } = defineOneEntry('your-url');
Method accept the body as a parameter for filtering. If you don't want to set up filtering/sorting, pass an empty array or don't pass anything.
Parameters:
const body = [
{
"attributeMarker": "num",
"conditionMarker": "mth",
"conditionValue": 1
},
{
"attributeMarker": "num",
"conditionMarker": "lth",
"conditionValue": 3
}
]
attributeMarker: string text identifier attribute example: price
conditionMarker: string text identifier condition, possible values: 'in' - contains, 'nin' - does not contain, 'eq' - equal, 'neq' - not equal, 'mth' - more than, 'lth' - less than, 'exs' - exists, 'nexs' - does not exist, 'pat' - pattern, for example -, where '' any character, 'same' - same value as the selected attribute* example: in Enum: [ in, nin, eq, neq, mth, lth, exs, nexs, pat, same ]
conditionValue: number condition value example: 1
Admins.getAdminsInfo(body, langCode, offset, limit)
const value = await Admins.getAdminsInfo();
body: array array of filter objects FilterAdminsDto with search conditions example: []
langCode: string language code example: en_US
offset: number parameter for pagination, default 0 example: 0
limit number parameter for pagination, default 30 example: 30
Example return:
[
{
"id": 1764,
"identifier": "admin1",
"attributeSetId": 7,
"isSync": false,
"attributeValues": {
"marker": {
"value": "",
"type": "string"
}
},
"position": 192
}
]
id: number object identifier example: 1764
identifier: string textual identifier for the record field example: admin1 default: admin1
attributeSetId: number Attribute set identifier example: 7
isSync boolean Page indexing flag (true or false) example: false
attributeValues: Record<string, string> Array of attribute values from the index (presented as a pair of user attribute identifier: attribute value) example: OrderedMap { "en_US": OrderedMap { "marker": OrderedMap { "value": "", "type": "string" } } }
position: number Position number (for sorting) example: 192
Additional examples:
Get admins with lang en_US
const result = await Admins.getAdminsInfo([], 'en_US', 0, 30);
Get admins with lang ru_RU
const result = await Admins.getAdminsInfo([], 'ru_RU', 0, 30);
Get admins with filter by attributeMarker
const body = [
{
attributeMarker: 'string_id1',
conditionMarker: 'in',
conditionValue: 1,
},
]
const result = await Admins.getAdminsInfo(body, 'en_US', 0, 30);
AttributesSets
const { AttributesSets } = defineOneEntry('your-url');
AttributesSets.getAttributes(langCode, offset, limit, typeId, sortBy)
const value = await AttributesSets.getAttributes()
langCode: string language code example: en_US
offset: number parameter offset of record selection, default - 0 example: 0
limit: number parameter limiting the selection of records, default - 30 example: 30
typeId: any identifier of the attribute set type example: null
sortBy: string sorting key example: id
This method return all attribute sets objects and total.
Example return:
{
"total": 100,
"items": [
{
"id": 1764,
"updatedDate": "2025-01-31T21:53:39.276Z",
"version": 10,
"identifier": "my_id",
"title": "Set for pages",
"schema": {
"attribute1": {
"id": 1,
"type": "string",
"isPrice": false,
"original": true,
"identifier": "string",
"localizeInfos": {
"en_US": {
"title": "String"
}
}
}
},
"isVisible": true,
"type": {
"id": 5,
"type": "forProducts"
},
"position": 1
}
]
}
total: number Total number of found records example: 100
items: ContentPositionAttributesSetDto ContentPositionAttributesSetDto
id: number Object identifier example: 1764
updatedDate: string($date-time) Object modification date example: ''
version: number Object modification version number example: 10
identifier: string Text identifier for record field example: 'my-id'
title: string Attribute set name example: Set for pages
schema: Record<string, string> Schema JSON description (attributes used by the set) of the attribute set example: OrderedMap { "attribute1": OrderedMap { "id": 1, "type": "string", "isPrice": false, "original": true, "identifier": "string", "localizeInfos": OrderedMap { "en_US": OrderedMap { "title": "String" } } } }
title: string Attribute set name example: Set for pages
isVisible: boolean Visibility flag of the set
type: object Object of set type
position: number Position number example: 1
AttributesSets.getAttributesByMarker(marker, langCode)
const value = await AttributesSets.getAttributesByMarker('my-marker')
marker:* string text identifier (marker) of the attribute set example: 'form'
langCode: string language code example: en_US
Example return:
[
{
"type": "list",
"marker": "list1",
"position": 192,
"validators": {
"requiredValidator": {
"strict": true
},
"defaultValueValidator": {
"fieldDefaultValue": 11
}
},
"localizeInfos": {
"title": "My attribute"
},
"listTitles": [
{
"title": "red",
"value": 1,
"position": 1,
"extended": {
"value": null,
"type": null
}
},
{
"title": "yellow",
"value": 2,
"position": 2,
"extended": {
"value": null,
"type": null
}
}
],
"settings": {},
"additionalFields": [
{
"type": "string",
"value": "Your Name",
"marker": "placeholder"
}
]
}
]
type: string attribute type example: list
marker: string textual identifier of the attribute (marker) Enum: [ string, text, textWithHeader, integer, real, float, dateTime, date, time, file, image, groupOfImages, radioButton, list, button ] example: list1
position: number position number for sorting example: 192
validators: Record<string, any> set of validators for validation example: OrderedMap { "requiredValidator": OrderedMap { "strict": true }, "defaultValueValidator": OrderedMap { "fieldDefaultValue": 11 } }
localizeInfos: Record<string, any> localization data for the set (name) example: OrderedMap { "title": "My attribute" }
listTitles Record<string, any> array of values (with extended data) for attributes of type list and radioButton example: List [ OrderedMap { "title": "red", "value": 1, "position": 1, "extended": OrderedMap { "value": null, "type": null } }, OrderedMap { "title": "yellow", "value": 2, "position": 2, "extended": OrderedMap { "value": null, "type": null } } ]
settings: Record<string, any> additional attribute settings (optional) example: OrderedMap {}
additionalFields: Record<string, AttributeInSetDto> example: List [ OrderedMap { "type": "string", "value": "Your Name", "marker": "placeholder" } ] example: OrderedMap {}
AttributesSets.getSingleAttributeByMarkerSet(attributeMarker, setMarker, langCode)
const value = await AttributesSets.getSingleAttributeByMarkerSet('list1', 'list1')
setMarker:* number text identifier (marker) of the attribute set example: 'form'
attributeMarker:* string text identifier (marker) of the attribute in the set example: 'list1'
langCode: string language code example: en_US
Example return:
{
"type": "list",
"marker": "list1",
"position": 192,
"validators": {
"requiredValidator": {
"strict": true
},
"defaultValueValidator": {
"fieldDefaultValue": 11
}
},
"localizeInfos": {
"title": "My attribute"
},
"listTitles": [
{
"title": "red",
"value": 1,
"position": 1,
"extended": {
"value": null,
"type": null
}
},
{
"title": "yellow",
"value": 2,
"position": 2,
"extended": {
"value": null,
"type": null
}
}
]
}
type: string attribute type example: list
marker: string textual identifier of the attribute (marker) example: list1
position: number position number for sorting example: 192
validators: Record<string, any> set of validators for validation example: OrderedMap { "requiredValidator": OrderedMap { "strict": true }, "defaultValueValidator": OrderedMap { "fieldDefaultValue": 11 } }
localizeInfos: Record<string, any> localization data for the set (name) example: OrderedMap { "title": "My attribute" }
listTitles Record<string, any> array of values (with extended data) for list and radioButton attributes example: List [ OrderedMap { "title": "red", "value": 1, "position": 1, "extendedValue": null, "extendedValueType": null }, OrderedMap { "title": "yellow", "value": 2, "position": 2, "extendedValue": null, "extendedValueType": null } ]
AttributesSets.getAttributeSetByMarker(marker, langCode)
const value = await AttributesSets.getAttributeSetByMarker('my-marker')
marker:* string text identifier (marker) of the attribute set example: 'form'
langCode: string language code example: en_US
Example return:
{
"id": 1764,
"updatedDate": "2025-01-31T22:25:11.952Z",
"version": 10,
"identifier": "my-id",
"title": "Set for pages",
"schema": {
"attribute1": {
"id": 1,
"type": "string",
"isPrice": false,
"original": true,
"identifier": "string",
"localizeInfos": {
"en_US": {
"title": "String"
}
}
}
},
"isVisible": true,
"type": {
"id": 5,
"type": "forProducts"
},
"position": 1
}
id: number Object identifier example: 1764
updatedDate: string($date-time) Object modification date example:
version: number Object modification version number example: 10
identifier:* string Text identifier for record field example: 'my-id'
title:* string Attribute set name example: 'Set for pages'
schema:* Record<string, string> Schema JSON description (attributes used by the set) of the attribute set example: OrderedMap { "attribute1": OrderedMap { "id": 1, "type": "string", "isPrice": false, "original": true, "identifier": "string", "localizeInfos": OrderedMap { "en_US": OrderedMap { "title": "String" } } } }
isVisible:* boolean Visibility flag of the set
type:* object Object of set type
position:* number Position number example: 1
User Auth Provider
const { AuthProvider } = defineOneEntry('your-url');
AuthProvider.signUp(marker, body, langCode)
marker:* string The text identifier of the authorization provider example: email
body:* ISignUpData Request body example: { "formIdentifier": "reg", "authData": [ { "marker": "login", "value": "[email protected]" }, { "marker": "password", "value": "12345" } ], "formData": [ { "marker": "last_name", "type": "string", "value": "Name" } ], "notificationData": { "email": "[email protected]", "phonePush": ["+99999999999"], "phoneSMS": "+99999999999" } }
Method accept the body as a parameter.
Examples for body parameter with different types data:
Example with attributes of simple types formData "string", "integer", "float".
{
"formIdentifier": "reg",
"langCode": "en_US",
"authData": [
{
"marker": "login",
"value": "test"
},
{
"marker": "password",
"value": "12345"
}
],
"formData": {
"en_US": [
{
"marker": "last_name",
"type": "string",
"value": "Fyodor Ivanov"
}
]
},
"notificationData": {
"email": "[email protected]",
"phonePush": [],
"phoneSMS": "+79991234567"
}
}
Example with attributes of types "date", "dateTime", "time"
{
"formIdentifier": "reg",
"langCode": "en_US",
"authData": [
{
"marker": "login",
"value": "test"
},
{
"marker": "password",
"value": "12345"
}
],
"formData": {
"en_US": [
{
"marker": "birthday",
"type": "date",
"value": {
"fullDate": "2024-05-07T21:02:00.000Z",
"formattedValue": "08-05-2024 00:02",
"formatString": "DD-MM-YYYY HH:mm"
}
}
]
},
"notificationData": {
"email": "[email protected]",
"phonePush": [],
"phoneSMS": "+79991234567"
}
}
Example with attribute of type "text"
{
"formIdentifier": "reg",
"langCode": "en_US",
"authData": [
{
"marker": "login",
"value": "test"
},
{
"marker": "password",
"value": "12345"
}
],
"formData": {
"en_US": [
{
"marker": "about",
"type": "text",
"value": {
"htmlValue": "<p>This is me</p>",
"plainValue": "",
"params": {
"isEditorDisabled": false,
"isImageCompressed": true
}
}
}
]
},
"notificationData": {
"email": "[email protected]",
"phonePush": [],
"phoneSMS": "+79991234567"
}
}
Example with attribute type "textWithHeader"
{
"formIdentifier": "reg",
"langCode": "en_US",
"authData": [
{
"marker": "login",
"value": "test"
},
{
"marker": "password",
"value": "12345"
}
],
"formData": {
"en_US": [
{
"marker": "about",
"type": "textWithHeader",
"value": {
"header": "Header",
"htmlValue": "<p>This is me</p>",
"plainValue": "",
"params": {
"isEditorDisabled": false,
"isImageCompressed": true
}
}
}
]
},
"notificationData": {
"email": "[email protected]",
"phonePush": [],
"phoneSMS": "+79991234567"
}
}
Example with attributes type "image" and "groupOfImages"
{
"formIdentifier": "reg",
"langCode": "en_US",
"authData": [
{
"marker": "login",
"value": "test"
},
{
"marker": "password",
"value": "12345"
}
],
"formData": {
"en_US": [
{
"marker": "avatar",
"type": "image",
"value": [
{
"filename": "files/project/page/10/image/Screenshot-from-2024-05-02-15-23-14.png",
"downloadLink": "http://my-site.zone/cloud-static/files/project/page/10/image/Screenshot-from-2024-05-02-15-23-14.png",
"size": 392585,
"previewLink": "",
"params": {
"isImageCompressed": true
}
}
]
}
]
},
"notificationData": {
"email": "[email protected]",
"phonePush": [],
"phoneSMS": "+79991234567"
}
}
Example with attribute type "file"
{
"formIdentifier": "reg",
"langCode": "en_US",
"authData": [
{
"marker": "login",
"value": "test"
},
{
"marker": "password",
"value": "12345"
}
],
"formData": {
"en_US": [
{
"marker": "picture",
"type": "file",
"value": [
{
"filename": "files/project/page/10/image/Screenshot-from-2024-05-02-15-23-14.png",
"downloadLink": "http://my-site.zone/cloud-static/files/project/page/10/image/Screenshot-from-2024-05-02-15-23-14.png",
"size": 392585
}
]
}
]
},
"notificationData": {
"email": "[email protected]",
"phonePush": [],
"phoneSMS": "+79991234567"
}
}
Example with attributes type "radioButton" and "list"
{
"formIdentifier": "reg",
"langCode": "en_US",
"authData": [
{
"marker": "login",
"value": "test"
},
{
"marker": "password",
"value": "12345"
}
],
"formData": {
"en_US": [
{
"marker": "selector",
"type": "list",
"value": [
{
"title": "red",
"value": "1",
"extended": {
"value": "red",
"type": "string"
}
}
]
}
]
},
"notificationData": {
"email": "[email protected]",
"phonePush": [],
"phoneSMS": "+79991234567"
}
}
Example with attribute type "entity" (nested list)
{
"formIdentifier": "reg",
"langCode": "en_US",
"authData": [
{
"marker": "login",
"value": "test"
},
{
"marker": "password",
"value": "12345"
}
],
"formData": {
"en_US": [
{
"marker": "entity-selector",
"type": "entity",
"value": [
{
"id": "1",
"title": "red",
"value": "1",
"parentId": "null"
}
]
}
]
},
"notificationData": {
"email": "[email protected]",
"phonePush": [],
"phoneSMS": "+79991234567"
}
}
Example with one push identifier
{
"formIdentifier": "reg",
"langCode": "en_US",
"authData": [
{
"marker": "login",
"value": "test"
},
{
"marker": "password",
"value": "12345"
}
],
"formData": {
"en_US": [
{
"marker": "selector",
"type": "list",
"value": [
{
"title": "red",
"value": "1",
"extended": {
"value": "red",
"type": "string"
}
}
]
}
]
},
"notificationData": {
"email": "[email protected]",
"phonePush": [
"7DD987F846400079F4B03C058365A4869047B4A0."
],
"phoneSMS": "+79991234567"
}
}
Example with multiple push identifiers
{
"formIdentifier": "reg",
"langCode": "en_US",
"authData": [
{
"marker": "login",
"value": "test"
},
{
"marker": "password",
"value": "12345"
}
],
"formData": {
"en_US": [
{
"marker": "selector",
"type": "list",
"value": [
{
"title": "red",
"value": "1",
"extended": {
"value": "red",
"type": "string"
}
}
]
}
]
},
"notificationData": {
"email": "[email protected]",
"phonePush": [
"7DD987F846400079F4B03C058365A4869047B4A0",
"7DD987F846400079F4B03C058365A4869047B4A0",
"7DD987F846400079F4B03C058365A4869047B4A0."
],
"phoneSMS": "+79991234567"
}
}
const body = {
"formIdentifier": "reg",
"authData": [
{
"marker": "login",
"value": "test"
},
{
"marker": "password",
"value": "12345"
}
],
"formData": [
{
"marker": "last_name",
"type": "string",
"value": "Username"
}
],
"notificationData": {
"email": "[email protected]",
"phonePush": [],
"phoneSMS": "+99999999999"
}
}
const value = await AuthProvider.signUp('email', body)
formIdentifier: string textual identifier of the authorization provider's form example: reg_form
formData: form data attached to the authorization provider
authData: authorization data taken from the form attached to the authorization provider example: List [ OrderedMap { "marker": "login", "value": "test" }, OrderedMap { "marker": "password", "value": "12345" } ]
notificationData: user notification data
attributeSetId: number identifier for the used attribute set example: 7
formData: FormDataLangType Data submitted by the form example: OrderedMap { "en_US": List [ OrderedMap { "marker": "marker_1", "value": "Name" } ] }
notificationData: UserNotificationDataType data for notifying the user example: OrderedMap { "email": "[email protected]", "phonePush": "", "phoneSMS": "+79991234567" }
systemCode: string system code for performing official actions (password reset, activation) example: OrderedMap { "value": "90BDCX", "expiredDate": "2024-05-07T21:02:00.000Z" }
formIdentifier: string the text identifier of the authorization provider's form example: reg_form
authData: FormAuthDataType authorization data taken from the form linked to the authorization provider example: List [ OrderedMap { "marker": "login", "value": "test" }, OrderedMap { "marker": "password", "value": "12345" } ]
authProviderId: number ID of the authorization provider example: 1
This method will register a new user. Returns the registered user's object.
Example return:
{
"id": 1764,
"updatedDate": "2024-05-23T12:43:00.169Z",
"version": 10,
"identifier": "catalog",
"isActive": false,
"authProviderId": 1,
"formData": [
{
"marker": "login",
"value": "test"
},
{
"marker": "f-name",
"value": "Second name"
}
],
"notificationData": {
"email": "[email protected]",
"phonePush": ["+999999999"],
"phoneSMS": "+9999999999"
},
"systemCode": {
"value": "90BDCX",
"expiredDate": "2024-05-07T21:02:00.000Z"
}
}
id: number object identifier example: 1764
updatedDate: string object modification date
version: number object version number example: 10
identifier: string textual identifier for the field record example: catalog default: marker
attributeSetId: number identifier for the used attribute set example: 7
formData: FormDataLangType Data submitted by the form example: OrderedMap { "en_US": List [ OrderedMap { "marker": "marker_1", "value": "Name" } ] }
notificationData: UserNotificationDataType data for notifying the user example: OrderedMap { "email": "[email protected]", "phonePush": "", "phoneSMS": "+79991234567" }
systemCode: string system code for performing official actions (password reset, activation) example: OrderedMap { "value": "90BDCX", "expiredDate": "2024-05-07T21:02:00.000Z" }
formIdentifier: string the text identifier of the authorization provider's form example: reg_form
authData: FormAuthDataType authorization data taken from the form linked to the authorization provider example: List [ OrderedMap { "marker": "login", "value": "test" }, OrderedMap { "marker": "password", "value": "12345" } ]
authProviderId: number ID of the authorization provider example: 1
AuthProvider.generateCode(marker, userIdentifier, eventIdentifier)
const value = await AuthProvider.generateCode('email', '[email protected]', 'auth')
marker:* array The text identifier of the authorization provider example: email
userIdentifier:* string The text identifier of the user's object (user login) example: [email protected]
eventIdentifier:* string Text identifier of the event object for which the code is generated example: auth
This method receives a code to activate the user. Code is returned through the corresponding user notification method
AuthProvider.checkCode(marker, userIdentifier, code)
const value = await AuthProvider.checkCode('email', '[email protected]', 'WTGC9E')
marker:* string The text identifier of the authorization provider. example: email
userIdentifier:* string The text identifier of the user's object (user login) example: [email protected]
eventIdentifier:* string Text identifier of the event object for which the code is generated example: auth
code:* string Service code example: WTGC9E
This method checks the user's code. Returns true (if the code is correct) or false (if it is incorrect).
Example return:
true
AuthProvider.activateUser(marker, userIdentifier, code)
const value = await AuthProvider.activateUser('email', '[email protected]', 'WTGC9E')
marker:* string Textual identifier of the authentication provider example: email
userIdentifier:* string The text identifier of the user's object (user login) example: [email protected]
code:* string Service code example: WTGC9E
This method activates the user by code. If successful, it will return true.
Example return:
true
AuthProvider.auth(marker, data)
const data = {
authData: [
{
marker: "login",
value: "[email protected]"
},
{
marker: "password",
value: "12345"
}
]
}
const value = await AuthProvider.auth('email', data)
marker: string The text identifier of the authorization provider example: email
data: IAuthPostBody Array of objects contains auth information example: { authData: [{marker: "login",value: "test"},{marker: "password",value: "12345"}]}
authData: string Authorization data taken from the form attached to the authorization provider example: List [ OrderedMap { "marker": "login", "value": "test" }, OrderedMap { "marker": "password", "value": "12345" } ]
This method performs user authorization. Returns an object with a set of tokens.
Example return:
{
"userIdentifier": "[email protected]",
"authProviderIdentifier": "email",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiYXV0aFByb3ZpZGVySWRlbnRpZmllciI6ImVtYWlsIiwidXNlcklkZW50aWZpZXIiOiJ0ZXN0QHRlc3QucnUiLCJ1c2VyQWdlbnQiOiJQb3N0bWFuUnVudGltZS83LjM3LjMiLCJpYXQiOjE3MTQ1NTc2NzAsImV4cCI6MTcxNDU2MTI3MH0.vm74Ha-S37462CAF3QiDpO9b0OhlJFNDMKq4eEyoaB8",
"refreshToken": "1714557670334-cb85112d-618d-4b2a-bad5-137b19c135b9"
}
userIdentifier: string user identifier example: [email protected]
authProviderIdentifier: string auth provider identifier example: email
accessToken: string access token example:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiYXV0aFByb3ZpZGVySWRlbnRpZmllciI6ImVtYWlsIiwidXNlcklkZW50aWZpZXIiOiJ0ZXN0QHRlc3QucnUiLCJ1c2VyQWdlbnQiOiJQb3N0bWFuUnVudGltZS83LjM3LjMiLCJpYXQiOjE3MTQ1NTc2NzAsImV4cCI6MTcxNDU2MTI3MH0.vm74Ha-S37462CAF3QiDpO9b0OhlJFNDMKq4eEyoaB8
refreshToken: string refresh token example: 1714557670334-cb85112d-618d-4b2a-bad5-137b19c135b9
AuthProvider.refresh(marker, token)
const value = await AuthProvider.refresh('email', '1714557670334-cb85112d-618d-4b2a-bad5-137b19c135b9')
marker:* string The text identifier of the authorization provider. Example - email example: email
token:* string Refresh token example: 1714557670334-cb85112d-618d-4b2a-bad5-137b19c135b9
This method updates the user's token. Returns an object with a set of tokens.
Example return:
{
"userIdentifier": "[email protected]",
"authProviderIdentifier": "email",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiYXV0aFByb3ZpZGVySWRlbnRpZmllciI6ImVtYWlsIiwidXNlcklkZW50aWZpZXIiOiJ0ZXN0QHRlc3QucnUiLCJ1c2VyQWdlbnQiOiJQb3N0bWFuUnVudGltZS83LjM3LjMiLCJpYXQiOjE3MTQ1NTc2NzAsImV4cCI6MTcxNDU2MTI3MH0.vm74Ha-S37462CAF3QiDpO9b0OhlJFNDMKq4eEyoaB8",
"refreshToken": "1714557670334-cb85112d-618d-4b2a-bad5-137b19c135b9"
}
userIdentifier: string user identifier example: [email protected]
authProviderIdentifier: string auth provider identifier example: email
accessToken: string access token example:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiYXV0aFByb3ZpZGVySWRlbnRpZmllciI6ImVtYWlsIiwidXNlcklkZW50aWZpZXIiOiJ0ZXN0QHRlc3QucnUiLCJ1c2VyQWdlbnQiOiJQb3N0bWFuUnVudGltZS83LjM3LjMiLCJpYXQiOjE3MTQ1NTc2NzAsImV4cCI6MTcxNDU2MTI3MH0.vm74Ha-S37462CAF3QiDpO9b0OhlJFNDMKq4eEyoaB8
refreshToken: string refresh token example: 1714557670334-cb85112d-618d-4b2a-bad5-137b19c135b9
AuthProvider.logout(marker, token)
const value = await AuthProvider.logout('email', '1714557670334-cb85112d-618d-4b2a-bad5-137b19c135b9')
marker:* string The text identifier of the authorization provider example: email
token:* string Refresh token example: 1714557670334-cb85112d-618d-4b2a-bad5-137b19c135b9
This method performs a user logout. If successful, it will return true. This method requires user authorization.
Example return:
true
AuthProvider.changePassword(marker, userIdentifier, type, code, newPassword, repeatPassword)
const value = await AuthProvider.changePassword('email', '[email protected]', 1, 'EW32RF', 654321, 654321)
marker:* string The text identifier of the authorization provider. example: email
userIdentifier:* string The text identifier of the user's object (user login) example: [email protected]
type:* string Operation type (1 - for changing password, 2 - for recovery) example: 1
code:* string Service code example: EW32RF
newPassword:* string New password example: 654321
repeatPassword: string Optional variable contains repeat new password for validation example: 654321
This method changes the password of an authorized user. If successful, it will return true.
Example return:
true
AuthProvider.getAuthProviders(langCode, offset, limit)
const value = await AuthProvider.getAuthProviders()
langCode: string language code example: en_US
offset: number parameter for pagination, default 0 example: 0
limit: number parameter for pagination, default 30 example: 30
This method gets all the objects of the authorization providers.
Example return:
[
{
"id": 1,
"localizeInfos": {
"title": "email"
},
"config": {
"deleteNoneActiveUsersAfterDays": 2,
"systemCodeTlsSec": 120,
"systemCodeLength": 8,
"systemCodeOnlyNumbers": null
},
"version": 0,
"identifier": "email",
"type": "email",
"formIdentifier": "reg",
"isActive": true,
"isCheckCode": false
}
]
id: number object identifier example: 1764
localizeInfos: CommonLocalizeInfos block name with localization example: OrderedMap { "en_US": OrderedMap { "title": "My block" } }
version: number object version number example: 10
identifier: string textual identifier for the field record example: catalog default: marker
isActive: boolean Flag of usage example: false
isCheckCode: boolean a sign of user activation via a code example: false
type: string type of providere example: email
formIdentifier: string the marker of the form used by the provider (may be null) example: email
AuthProvider.getMarker(marker, langCode)
const value = await AuthProvider.getMarker('email')
marker:* string The text identifier of the authorization provider example: email
langCode: string language code example: en_US
Getting a single token authorization provider object.
Example return:
[
{
"id": 1,
"localizeInfos": {
"title": "email"
},
"version": 0,
"identifier": "email",
"type": "email",
"formIdentifier": "reg",
"isActive": true,
"isCheckCode": false,
"config": {
"deleteNoneActiveUsersAfterDays": 2,
"systemCodeLength": 8,
"systemCodeOnlyNumbers": null,
"systemCodeTlsSec": 120
}
}
]
id: number object identifier example: 1764
localizeInfos: CommonLocalizeInfos block name with localization example: OrderedMap { "en_US": OrderedMap { "title": "My block" } }
version: number object version number example: 10
identifier: string textual identifier for the field record example: catalog default: marker
isActive: boolean Flag of usage example: false
isCheckCode: boolean a sign of user activation via a code example: false
type: string type of providere example: email
formIdentifier: string the marker of the form used by the provider (may be null) example: email
Blocks
const { Blocks } = defineOneEntry('your-url');
Blocks.getBlocks(type, langCode, offset, limit)
const value = await Blocks.getBlocks('forTextBlock')
type:* BlockType Available values: forCatalogProducts, forBasketPage, forErrorPage, forCatalogPages, forProductPreview, forProductPage, forSimilarProductBlock, forStatisticProductBlock, forProductBlock, forForm, forFormField, forNewsPage, forNewsBlock, forNewsPreview, forOneNewsPage, forUsualPage, forTextBlock, forSlider, forOrder, service example: forTextBlock
langCode: string Language code example: en_US
offset: number Parameter for pagination. Default 0 example: 0
limit: number Parameter for pagination. Default 30 example: 30
This method return array of all blocks object and total.
Example return:
{
"total": 100,
"items": [
{
"id": 1,
"localizeInfos": {
"title": "Block"
},
"version": 0,
"position": 1,
"identifier": "block",
"type": "forTextBlock",
"templateIdentifier": null,
"isVisible": true,
"attributeValues": {}
}
]
}
total: number total number of found records example: 100
id: number object identifier example: 1764
attributeSetId: number identifier for the used attribute set example: 7
localizeInfos: CommonLocalizeInfos block name with localization example: OrderedMap { "en_US": OrderedMap { "title": "My block" } }
customSettings: BlockCustomSettings custom settings for different block types example: OrderedMap { "sliderDelay": 0, "sliderDelayType": "", "productQuantity": 4, "productSortType": "By_ID", "productSortOrder": "Descending", "productCountElementsPerRow": 10, "similarProductRules": List [ OrderedMap { "property": "Descending", "includes": "", "keywords": "", "strict": "" } ] }
version: number object version number example: 10
identifier: string textual identifier for the field record example: catalog default: marker
position: number position number (for sorting) example: 192
attributeValues: Record<string, string> array of attribute values from the index (presented as a pair of custom attribute identifier: attribute value) example: OrderedMap { "en_US": OrderedMap { "marker": OrderedMap { "value": "", "type": "string" } } }
type: string block type example: forNewsPage
templateIdentifier: string template marker used by the block (can be null) Enum: [ forCatalogProducts, forBasketPage, forErrorPage, forCatalogPages, forProductPreview, forProductPage, forSimilarProductBlock, forStatisticProductBlock, forProductBlock, forForm, forFormField, forNewsPage, forNewsBlock, forNewsPreview, forOneNewsPage, forUsualPage, forTextBlock, forSlider, service ] example: null
Blocks.getBlockByMarker(marker, langCode, offset, limit)
const value = await Blocks.getBlockByMarker('my-marker')
marker:* string Marker of Block example: my-marker
langCode: string Language code example: en_US
offset: number Parameter for pagination. Default 0 example: 0
limit: number Parameter for pagination. Default 30 example: 30
This method return one blocks object by marker.
Example return:
{
"id": 1764,
"localizeInfos": {
"en_US": {
"title": "My block"
}
},
"customSettings": {
"sliderDelay": 0,
"sliderDelayType": "",
"productConfig": {
"quantity": 2,
"sortType": "By_ID",
"sortOrder": "DESC",
"countElementsPerRow": 10
},
"similarProductRules": [
{
"property": "Descending",
"includes": "",
"keywords": "",
"strict": ""
}
],
"condition": {
"name": "title"
}
},
"version": 10,
"identifier": "catalog",
"position": 192,
"productPageUrls": [
"23-laminat-floorwood-maxima"
],
"isVisible": true,
"attributeValues": {
"en_US": {
"marker": {
"value": "",
"type": "string",
"position": 1,
"isProductPreview": false,
"isIcon": false,
"attributeFields": {
"marker": {
"type": "string",
"value": "test"
}
}
}
}
},
"type": "forNewsPage",
"templateIdentifier": null,
"attributeSetIdentifier": "my-attributes-sets"
}
id: number object identifier example: 1764
localizeInfos: CommonLocalizeInfos block name considering localization example: OrderedMap { "en_US": OrderedMap { "title": "My block" } }
customSettings: BlockCustomSettings individual settings for different types of blocks BlockCustomSettings example: OrderedMap { "sliderDelay": 0, "sliderDelayType": "", "productConfig": OrderedMap { "quantity": 2, "sortType": "By_ID", "sortOrder": "DESC", "countElementsPerRow": 10 }, "similarProductRules": List [ OrderedMap { "property": "Descending", "includes": "", "keywords": "", "strict": "" } ], "condition": OrderedMap { "name": "title" } }
version: number version number of the object change example: 10
identifier: string textual identifier for the recording field example: catalog default: marker
position: number position number (for sorting) example: 192
productPageUrls: any array of unique parts of the URL page (after the last "/") - categories from where products can be taken (optional) example: List [ "23-laminat-floorwood-maxima" ]
isVisible: boolean visibility (availability) indicator of the block example: true
attributeValues: Record<string, string> Array of attribute values from the index (type, value, array of additional fields for the attribute) example: OrderedMap { "en_US": OrderedMap { "marker": OrderedMap { "value": "", "type": "string", "position": 1, "isProductPreview": false, "isIcon": false, "attributeFields": OrderedMap { "marker": OrderedMap { "type": "string", "value": "test" } } } } }
type: string block type example: forNewsPage Enum: [ forCatalogProducts, forBasketPage, forErrorPage, forCatalogPages, forProductPreview, forProductPage, forSimilarProductBlock, forStatisticProductBlock, forProductBlock, forForm, forFormField, forNewsPage, forNewsBlock, forNewsPreview, forOneNewsPage, forUsualPage, forTextBlock, forSlider, forOrder, service ]
attributeSetId: number identifier for the used attribute set example: 7
position: number position number (for sorting) example: 192
templateIdentifier: string Template marker used by the block (can be null) example: null
Blocks.searchBlock(name, langCode)
const value = await Blocks.searchBlock('my-marker')
marker:* string Block identifier example: my-marker
langCode: string Language code example: en_US
Quick search for block objects with limited output.
Example return:
[
{
"id": 1,
"name": "my block",
"identifier": "my-block"
}
]
Events
const { Events } = defineOneEntry('your-url');
Events.getAllSubscriptions(offset, limit)
const value = await Events.getAllSubscriptions()
offset: number Pagination parameter, default is 0 example: 0
limit: number Pagination parameter, default is 30 example: 30
This method return all subscriptions to product.
Example return:
{
"total": 100,
"items": [
{
"eventMarker": "string",
"productId": 0
}
]
}
total: number Total number of records found
eventMarker: string Event marker
productId number Product identifier
Events.subscribeByMarker(marker, userId, productId)
const value = await Events.subscribeByMarker('test_event', 1, 1)
marker:* string Event marker example: test_event
productId:* string Product id example: 14
langCode: string Language code example: en_US
threshold: number Threshold value for comparing numerical value example: 0
This method subscribes to the product event. Returns nothing if the subscription was successful. This method requires user authorization.
Events.unsubscribeByMarker(marker, userId, productId)
const value = await Events.unsubscribeByMarker('test_event', 1, 1)
marker:* string Event marker example: test_event
productId:* string Product id example: 14
langCode: string Language code example: en_US
threshold: number Threshold value for comparing numerical value example: 0
This method unsubscribes to the product event. Returns nothing if the unsubscription was successful.
FileUploading
const { FileUploading } = defineOneEntry('your-url');
FileUploading.upload(data, fileQuery)
const query = {
type:"page",
entity:"editor",
id:3787,
width:0,
height:0,
compress:true,
}
const value = await FileUploading.upload(data, query)
data:* File File objects. Get data as File from your unput as e.target.files[0] example:
fileQuery: IUploadingQuery Optional set query parameters. example:
fileQuery.type: string Type, determines the folder name in the storage example: page
fileQuery.entity: string Entity name from which the file is uploaded, determines the folder name in the storage example: editor
fileQuery.id number Identifier of the object from which the file is uploaded, determines the folder name in the storage example: 3787
fileQuery.width number Optional width parameter. example: 0
fileQuery.height number Optional height parameter example: 0
fileQuery.compress boolean Optional flag of optimization (compression) for images example: true
This method uploads a file to a cloud file storage. Pass to the date the value obtained from input type "file".
Data is file object (or array), learn more - File Object
Example return:
[
{
"filename": "string",
"downloadLink": "string",
"size": 0
}
]
filename: string filename with relative path
downloadLink: string link for downloading the file
size number size of the file in bytes
FileUploading.delete(filename, fileQuery)
const query = {
type:"page",
entity:"editor",
id:3787
}
const value = await FileUploading.delete("file.png", query)
filename: string File name. example: file.png
fileQuery: IUploadingQuery Optional set query parameters example:
fileQuery.type: string Type, determines the folder name in the storage example: page
fileQuery.entity: string Entity name from which the file is uploaded, determines the folder name in the storage example: editor
fileQuery.id number Identifier of the object from which the file is uploaded, determines the folder name in the storage example: 3787
This void method delete a file from the cloud file storage.
FileUploading.getFile(id, type, entity, filename)
const value = await FileUploading.getFile(123, 'page', 'editor', 'file.png')
id: number Object identifier, from which the file is uploaded, determines the folder name in the storage example: 123
type: string Type, determines the folder name in the storage example: page
entity: string entity name, from which the file is uploaded, determines the folder name in the storage example: editor
filename: string Filename example: file.png
This method return file object by parameters.
Example return:
{
"file": "string"
}
Forms
const { Forms } = defineOneEntry('your-url');
Forms.getAllForms(langCode, offset, limit)
const value = await Forms.getAllForms()
langCode string Language code. Default "en_US" example: en_US
offset number Parameter for pagination. Default 0 example: 0
limit number Parameter for pagination. Default 30 example: 30
This method retrieves all form objects from the API. It returns a Promise that resolves to an array of FormEntity objects.
Example return:
[
{
"id": 1764,
"attributeSetId": 0,
"processingType": "email",
"localizeInfos": {
"title": "My Form",
"titleForSite": "",
"successMessage": "",
"unsuccessMessage": "",
"urlAddress": "",
"database": "0",
"script": "0"
},
"processingData": "Unknown Type: ProcessingData",
"version": 10,
"type": "data",
"identifier": "catalog",
"position": 192,
"attributes": [
{
"type": "list",
"marker": "l1",
"position": 2,
"settings": {},
"listTitles": [
{
"title": "red",
"value": 1,
"position": 1,
"extendedValue": null,
"extendedValueType": null
},
{
"title": "yellow",
"value": 2,
"position": 2,
"extendedValue": null,
"extendedValueType": null
}
],
"validators": {},
"localizeInfos": {
"title": "l1"
}
}
]
}
]
id: number object identifier example: 1764
attributeSetId: number identifier of the attribute set used
processingType: string form processing type example: email
localizeInfos: FormLocalizeInfos form name with localization Enum: [ db, email, script ] example: OrderedMap { "en_US": OrderedMap { "title": "My Form", "titleForSite": "", "successMessage": "", "unsuccessMessage": "", "urlAddress": "", "database": "0", "script": "0" } }
processingData: ProcessingData form data
version: number object version number example: 10
identifier: string textual identifier for the record field example: catalog default: marker
position: number position number (for sorting) example: 192
position: string Form type example: 'data'
attributes: array of attribute values from the used attribute set for displaying the form (taking into account the specified language) example: List [ OrderedMap { "type": "list", "marker": "l1", "position": 2, "listTitles": List [ OrderedMap { "title": "red", "value": 1, "position": 1, "extendedValue": null, "extendedValueType": null }, OrderedMap { "title": "yellow", "value": 2, "position": 2, "extendedValue": null, "extendedValueType": null } ], "validators": OrderedMap {}, "localizeInfos": OrderedMap { "title": "l1" } } ]
Forms.getFormByMarker(marker, langCode)
const value = await Forms.getFormByMarker('my-form')
marker:* string Marker of form example: my-form
langCode: string Language code. Default "en_US" example: en_US
This method retrieves a single form object based on its textual identifier (marker) from the API. It returns a Promise that resolves to a FormEntity object.
Example return:
{
"id": 1764,
"attributeSetId": 0,
"processingType": "email",
"localizeInfos": {
"title": "My Form",
"titleForSite": "",
"successMessage": "",
"unsuccessMessage": "",
"urlAddress": "",
"database": "0",
"script": "0"
},
"processingData": "Unknown Type: ProcessingData",
"version": 10,
"type": "data",
"identifier": "catalog",
"position": 192,
"attributes": [
{
"type": "list",
"marker": "l1",
"position": 2,
"settings": {},
"listTitles": [
{
"title": "red",
"value": 1,
"position": 1,
"extendedValue": null,
"extendedValueType": null
},
{
"title": "yellow",
"value": 2,
"position": 2,
"extendedValue": null,
"extendedValueType": null
}
],
"validators": {},
"localizeInfos": {
"title": "l1"
}
}
]
}
id: number object identifier example: 1764
attributeSetId: number identifier of the attribute set used
processingType: string form processing type example: email
localizeInfos: FormLocalizeInfos form name with localization Enum: [ db, email, script ] example: OrderedMap { "en_US": OrderedMap { "title": "My Form", "titleForSite": "", "successMessage": "", "unsuccessMessage": "", "urlAddress": "", "database": "0", "script": "0" } }
processingData: ProcessingData form data
version: number object version number example: 10
identifier: string textual identifier for the record field example: catalog default: marker
position: number position number (for sorting) example: 192
position: string Form type example: 'data'
attributes: array of attribute values from the used attribute set for displaying the form (taking into account the specified language) example: List [ OrderedMap { "type": "list", "marker": "l1", "position": 2, "listTitles": List [ OrderedMap { "title": "red", "value": 1, "position": 1, "extendedValue": null, "extendedValueType": null }, OrderedMap { "title": "yellow", "value": 2, "position": 2, "extendedValue": null, "extendedValueType": null } ], "validators": OrderedMap {}, "localizeInfos": OrderedMap { "title": "l1" } } ]
FormData
const { FormData } = defineOneEntry('your-url');
Methods with a post request accept as the request body an object with the form data field, which corresponds to the type of information being sent. The following are examples of form data objects for different data types.
Example with a simple type attribute "string", "number", "float"
{
"marker": "last_name",
"type": "string",
"value": "Username"
}
Example with a simple type attribute "date", "dateTime", "time"
{
"marker": "birthday",
"type": "date",
"value": {
"fullDate": "2024-05-07T21:02:00.000Z",
"formattedValue": "08-05-2024 00:02",
"formatString": "DD-MM-YYYY HH:mm"
}
}
Example with a simple type attribute "text"
{
"marker": "about",
"type": "text",
"value": {
"htmlValue": "<p>Hello world</p>",
"plainValue": "",
"params": {
"isEditorDisabled": false,
"isImageCompressed": true
}
}
}
Example with a simple type attribute "text"
{
"marker": "about",
"type": "text",
"value": {
"htmlValue": "<p>Hello world</p>",
"plainValue": "",
"params": {
"isEditorDisabled": false,
"isImageCompressed": true
}
}
}
Example with a simple type attribute "textWithHeader"
{
"marker": "about",
"type": "textWithHeader",
"value": {
"header": "Headline",
"htmlValue": "<p>Hello World</p>",
"plainValue": "",
"params": {
"isEditorDisabled": false,
"isImageCompressed": true
}
}
}
Example with a simple type attribute "image" or "groupOfImages"
{
"marker": "avatar",
"type": "image",
"value": [
{
"filename": "files/project/page/10/image/Screenshot-from-2024-05-02-15-23-14.png