### Initialize OneEntry SDK Source: https://js-sdk.oneentry.cloud/docs/index Initializes the OneEntry SDK with your project URL and API token. This setup is required before making any API calls. ```javascript import { defineOneEntry } from 'oneentry'; const api = defineOneEntry('your-project-url', { token: 'your-api-token' }); ``` -------------------------------- ### Install OneEntry SDK using npm Source: https://js-sdk.oneentry.cloud/docs/index Installs the OneEntry JavaScript SDK package using npm. This is the first step to integrating the SDK into your project. ```bash npm install oneentry ``` -------------------------------- ### Initialize SDK with Token and Custom Refresh Token Logic (JavaScript) Source: https://js-sdk.oneentry.cloud/docs/index Initializes the OneEntry SDK with a token and specifies a custom function for handling refresh tokens. This example shows how to integrate with a custom authentication provider and manage token storage. ```javascript const saveTokenFromLocalStorage = (token) => { localStorage.setItem('refreshToken', token); }; const api = defineOneEntry('your-url', { token: 'my-token', langCode: 'my-langCode', auth: { customAuth: false, userToken: 'refresh.token', saveFunction: saveTokenFromLocalStorage, providerMarker: 'email' }, }); ``` -------------------------------- ### Alternative OneEntry SDK Initialization Source: https://js-sdk.oneentry.cloud/docs/index Presents an alternative method for initializing the OneEntry SDK, where the configuration object is defined separately before passing it to the SDK initialization function. ```javascript const config = { token: 'your-app-token', }; const api = defineOneEntry('your-url', config); ``` -------------------------------- ### Use OneEntry SDK to Fetch Data and Submit Forms Source: https://js-sdk.oneentry.cloud/docs/index Demonstrates common API interactions using the initialized OneEntry SDK, including fetching products, retrieving user profiles, and submitting form data. ```javascript // Fetch products const products = await api.Products.getProducts({ limit: 10 }); // Get user profile const user = await api.Users.getUser(); // Submit a form const formData = await api.FormData.postFormsData('contact-form', { name: 'John Doe', email: 'john@example.com' }); ``` -------------------------------- ### Import All OneEntry SDK Modules Source: https://js-sdk.oneentry.cloud/docs/index Shows how to import and destructure all available modules from the OneEntry SDK for comprehensive access to its functionalities. This approach allows for direct use of module methods. ```javascript import { defineOneEntry } from 'oneentry' const config = { token: 'your-app-token', } const { Admins, AttributesSets, AuthProvider, Blocks, Events, FileUploading, Forms, FormData, GeneralTypes, IntegrationCollections, Locales, Menus, Orders, Pages, Payments, ProductStatuses, Products, Settings, System, Templates, TemplatePreviews, Users, WS } = defineOneEntry('your-url', config); ``` -------------------------------- ### Interact with OneEntry API using JavaScript Source: https://js-sdk.oneentry.cloud/index Demonstrates common API interactions after initializing the SDK. It shows how to fetch products, retrieve user profiles, and submit form data using asynchronous operations. Requires the initialized API object. ```javascript // Fetch products const products = await api.Products.getProducts({ limit: 10 }); // Get user profile const user = await api.Users.getUser(); // Submit a form const formData = await api.FormData.postFormsData('contact-form', { name: 'John Doe', email: 'john@example.com' }); ``` -------------------------------- ### Initialize SDK with Token and Refresh Token Storage (JavaScript) Source: https://js-sdk.oneentry.cloud/docs/index Initializes the OneEntry SDK with a security API token and configures automatic refresh token storage using localStorage. This setup is suitable for projects requiring token protection and session persistence. ```javascript 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, providerMarker: 'email' }, }); ``` -------------------------------- ### Configure SDK for Default Additional Fields Format (JavaScript) Source: https://js-sdk.oneentry.cloud/index Initializes the SDK with default settings where 'additionalFields' is transformed into an object keyed by 'marker' for easier access, rather than the raw API array format. ```javascript const api = defineOneEntry('https://your-project.oneentry.cloud', { token: 'your-token', // rawData is false by default — no need to pass it explicitly }) // additionalFields is an object keyed by marker: const field = attribute.additionalFields['my_field'] console.log(field.value) // direct access, no array search needed ``` -------------------------------- ### Get Products with Body Parameter Filter (JavaScript) Source: https://js-sdk.oneentry.cloud/docs/products/getProducts This example shows how to use the `body` parameter with `getProducts` to apply specific filters, such as price range and page URLs. It allows for targeted product searches based on predefined criteria. ```javascript const body = [ { "attributeMarker": "price", "conditionMarker": "mth", "statusMarker": "waiting", "conditionValue": 1, "pageUrls": [ "23-laminat-floorwood-maxima" ], "isNested": false, "title": "" }, { "attributeMarker": "price", "conditionMarker": "lth", "conditionValue": 3, "pageUrls": [ "23-laminat-floorwood-maxima" ], "isNested": false, "title": "" } ]; const response = await Products.getProducts(body); ``` -------------------------------- ### Initialize SDK with Custom Authentication and Traffic Limit (JavaScript) Source: https://js-sdk.oneentry.cloud/docs/index Initializes the OneEntry SDK with custom authentication enabled and traffic limit set to true. This configuration is for scenarios where authorization is managed manually and traffic optimization is desired. ```javascript const api = defineOneEntry('https://my-project.oneentry.cloud', { langCode: 'en_US', traficLimit: true, auth: { customAuth: true, refreshToken: localStorage.getItem('refreshToken'), providerMarker: 'email' }, }); ``` -------------------------------- ### IBlockEntity Products Example Source: https://js-sdk.oneentry.cloud/docs/blocks/getBlocks This example illustrates the structure of the 'products' array within an _IBlockEntity_. Each object in the array represents a product with its ID and name. ```json [ { "id": 1, "name": "Product 1" }, { "id": 2, "name": "Product 2" } ] ``` -------------------------------- ### Orders API Usage Example Source: https://js-sdk.oneentry.cloud/docs/index/usageExamples/users/order-history This example demonstrates how to import the SDK, authenticate a user, and retrieve all orders associated with a specific storage marker. ```APIDOC ## Orders API Usage Example ### Description This example demonstrates how to import the SDK, authenticate a user, and retrieve all orders associated with a specific storage marker. ### Method GET ### Endpoint /orders/{storageMarker}/{locale}/{offset}/{limit} ### Parameters #### Path Parameters - **storageMarker** (string) - Required - The marker of the storage to retrieve orders from. - **locale** (string) - Required - The locale for the orders (e.g., 'en_US'). - **offset** (integer) - Required - The number of orders to skip. - **limit** (integer) - Required - The maximum number of orders to return. ### Request Example ```javascript // 1. Import defineOneEntry from SDK and define PROJECT_URL and APP_TOKEN import { defineOneEntry } from 'oneentry'; const PROJECT_URL = 'your-project-url'; const APP_TOKEN = 'your-app-token'; // 2. Creating an API client const { AuthProvider, Orders } = defineOneEntry(PROJECT_URL, { token: APP_TOKEN, }); // 3. auth with AuthProvider.auth() const authData = [ { marker: 'email_reg', value: 'your-user@email.com', }, { marker: 'password_reg', value: '123456', }, ]; const authResponse = await AuthProvider.auth('email', { authData, }); // 4. Get all user orders by order storage marker with Orders.getAllOrdersByMarker() const allOrders = await Orders.getAllOrdersByMarker('orders', 'en_US', 0, 30); console.log(allOrders); ``` ### Response #### Success Response (200) - **orders** (array) - An array of order objects. - **id** (integer) - The unique identifier for the order. - **storageId** (integer) - The identifier for the storage the order belongs to. - **createdDate** (string) - The date and time the order was created. - **statusIdentifier** (string) - The identifier for the order's status. - **formIdentifier** (string) - The identifier for the form used for the order. - **formData** (array) - An array of form data objects. - **type** (string) - The data type of the form field. - **marker** (string) - The marker for the form field. - **value** (string) - The value of the form field. - **attributeSetIdentifier** (string) - The identifier for the attribute set. - **totalSum** (string) - The total sum of the order. - **currency** (string) - The currency of the order. - **paymentAccountIdentifier** (string) - The identifier for the payment account. - **paymentAccountLocalizeInfos** (object) - Localized information about the payment account. - **title** (string) - The title of the payment account. - **products** (array) - An array of product objects included in the order. - **id** (integer) - The unique identifier for the product. - **title** (string) - The title of the product. - **sku** (null) - The SKU of the product (can be null). - **previewImage** (array) - An array of preview image objects for the product. - **price** (integer) - The price of the product. - **quantity** (integer) - The quantity of the product ordered. - **isCompleted** (boolean) - Indicates if the order is completed. - **total** (integer) - The total number of orders available. #### Response Example ```json { "orders": [ { "id": 87, "storageId": 1, "createdDate": "2025-04-30T20:15:12.616Z", "statusIdentifier": "upcoming", "formIdentifier": "order", "formData": [ { "type": "string", "marker": "name", "value": "John Doe" } ], "attributeSetIdentifier": "order", "totalSum": "340.00", "currency": "USD", "paymentAccountIdentifier": "cash", "paymentAccountLocalizeInfos": { "title": "Cash" }, "products": [ { "id": 14, "title": "Green ball", "sku": null, "previewImage": [], "price": 340, "quantity": 1 } ], "isCompleted": false }, { "id": 88, "storageId": 1, "createdDate": "2025-04-30T20:15:12.616Z", "statusIdentifier": "upcoming", "formIdentifier": "order", "formData": [ { "type": "string", "marker": "name", "value": "Christina Thomas" } ], "attributeSetIdentifier": "order", "totalSum": "340.00", "currency": "USD", "paymentAccountIdentifier": "cash", "paymentAccountLocalizeInfos": { "title": "Cash" }, "products": [ { "id": 14, "title": "Green ball", "sku": null, "previewImage": [], "price": 340, "quantity": 1 } ], "isCompleted": false } ], "total": 7 } ``` ``` -------------------------------- ### IProductsResponse Example Source: https://js-sdk.oneentry.cloud/docs/blocks/getBlocks An example of the _IProductsResponse_ schema, used to represent a collection of products. It includes the total number of products and an array of product entities. ```json { "total": 10, "items": [] } ``` -------------------------------- ### Payment Account Localization Example (JSON) Source: https://js-sdk.oneentry.cloud/docs/orders/getAllOrdersByMarker This JSON snippet shows an example of `paymentAccountLocalizeInfos`, which provides localized names for payment accounts. It demonstrates how different locale codes map to specific display strings. ```json { "en_US": "USD Payment", "ru_RU": "Оплата в долларах США" } ``` -------------------------------- ### Products Module Initialization Source: https://js-sdk.oneentry.cloud/docs/products Initialize the Products module with your project URL and API token. ```APIDOC ## Initialization ### Description Initialize the Products module by providing your project URL and an application token. ### Method ```javascript defineOneEntry ``` ### Endpoint N/A (Client-side SDK) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const { Products } = defineOneEntry( "your-project-url", { "token": "your-app-token" } ); ``` ### Response #### Success Response (200) N/A (Initialization returns the module object) #### Response Example N/A ``` -------------------------------- ### OneEntry SDK Strict Mode Validation Source: https://js-sdk.oneentry.cloud/docs/index Illustrates OneEntry SDK configuration for strict mode validation. Validation failures return an IError object, ensuring only validated data is processed. Includes an example of checking for errors. ```javascript const api = defineOneEntry('https://your-project.oneentry.cloud', { token: 'your-token', validation: { enabled: true, strictMode: true, // Strict mode logErrors: true, } }) const user = await api.Users.getUser() // Check if response is an error if ('statusCode' in user) { console.error('Validation failed:', user.message) } else { // Type-safe: user is IUserEntity console.log('User:', user.email) } ``` -------------------------------- ### Initialize OneEntry System Module Source: https://js-sdk.oneentry.cloud/docs/system This snippet demonstrates how to initialize the OneEntry platform and access the System module. It requires a project URL and an application token. The System module is then destructured for use. ```javascript const { System } = defineOneEntry( "your-project-url", { "token": "your-app-token" } ); ``` -------------------------------- ### Check for Errors When isShell is True (JavaScript) Source: https://js-sdk.oneentry.cloud/docs/index This example demonstrates how to handle errors when 'isShell' is true (the default behavior). Instead of throwing exceptions, errors are returned as values, requiring a check for properties like 'statusCode' or 'message' to identify and handle them. ```javascript const result = await api.someMethod(); // Check if the result is an error if ('statusCode' in result || 'message' in result) { // Error handling console.error('Error:', result); } else { // Handling a successful result console.log('Success:', result); } ``` -------------------------------- ### OAuth Sign Up and Authentication Source: https://js-sdk.oneentry.cloud/docs/index/usageExamples/auth-provider/oauth This section details the steps for user registration and authentication using OAuth. It covers importing the SDK, initializing the client, performing sign-up with `oauthSignUp` for registration, authenticating with `oauthSignUp` for authorization code, and retrieving user data with `getUser`. ```APIDOC ## POST /oauth/signup ### Description Registers a new user using OAuth provider credentials and an authorization code. ### Method POST ### Endpoint /oauth/signup ### Parameters #### Request Body - **client_id** (string) - Required - The client ID obtained from the OAuth provider. - **client_secret** (string) - Required - The client secret obtained from the OAuth provider. - **code** (string) - Required - The authorization code received from the OAuth provider. - **grant_type** (string) - Required - Must be 'registration' for user sign-up. - **redirect_uri** (string) - Required - The configured redirect URI that matches the OAuth provider settings. - **formData** (object) - Optional - Additional form data, typically for user profile fields. - **en_US** (array) - Optional - An array for localized form data. ### Request Example ```json { "client_id": "34346983-luuct343473qdkqidjopdfp3eb3k4thp.apps.googleusercontent.com", "client_secret": "43434343434", "code": "4/0AVMBsJgwewewewewewei4D7T6E_fbswxnL3g", "grant_type": "registration", "redirect_uri": "http://localhost:3000", "formData": { "en_US": [ null ] } } ``` ### Response #### Success Response (200) - **token** (string) - The authentication token for the newly registered user. - **user** (object) - Details of the registered user. #### Error Response (403) - **statusCode** (integer) - The HTTP status code, typically 403. - **timestamp** (string) - The date and time of the error. - **message** (string) - A description of the error, e.g., "Permission data not found.". - **pageData** (null) - Placeholder for page-specific data, usually null. #### Response Example (Error) ```json { "statusCode": 403, "timestamp": "2026-01-04T01:20:52.612Z", "message": "Permission data not found. Provide the permission for requested url", "pageData": null } ``` ## POST /oauth/authenticate ### Description Authenticates an existing user using an OAuth provider and an authorization code. ### Method POST ### Endpoint /oauth/authenticate ### Parameters #### Request Body - **client_id** (string) - Required - The client ID obtained from the OAuth provider. - **client_secret** (string) - Required - The client secret obtained from the OAuth provider. - **code** (string) - Required - The authorization code received from the OAuth provider. - **grant_type** (string) - Required - Must be 'authorization_code' for user authentication. - **redirect_uri** (string) - Required - The configured redirect URI that matches the OAuth provider settings. - **formData** (object) - Optional - Additional form data, typically for user profile fields. - **en_US** (array) - Optional - An array for localized form data. ### Request Example ```json { "client_id": "34346983-luuct343473qdkqidjopdfp3eb3k4thp.apps.googleusercontent.com", "client_secret": "43434343434", "code": "4/0AVMBsJgwewewewewewei4D7T6E_fbswxnL3g", "grant_type": "authorization_code", "redirect_uri": "http://localhost:3000", "formData": { "en_US": [ null ] } } ``` ### Response #### Success Response (200) - **token** (string) - The authentication token for the user. - **user** (object) - Details of the authenticated user. #### Error Response (403) - **statusCode** (integer) - The HTTP status code, typically 403. - **timestamp** (string) - The date and time of the error. - **message** (string) - A description of the error, e.g., "Permission data not found.". - **pageData** (null) - Placeholder for page-specific data, usually null. #### Response Example (Error) ```json { "statusCode": 403, "timestamp": "2026-01-04T01:20:52.792Z", "message": "Permission data not found. Provide the permission for requested url", "pageData": null } ``` ## GET /users/me ### Description Retrieves the currently authenticated user's data. ### Method GET ### Endpoint /users/me ### Parameters No parameters are required for this endpoint. ### Request Example ```javascript const userData = await Users.getUser(); ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the user. - **email** (string) - The email address of the user. - **firstName** (string) - The first name of the user. - **lastName** (string) - The last name of the user. - **createdAt** (string) - The timestamp when the user was created. - **updatedAt** (string) - The timestamp when the user was last updated. #### Response Example ```json { "id": "user-123", "email": "user@example.com", "firstName": "John", "lastName": "Doe", "createdAt": "2023-01-01T10:00:00Z", "updatedAt": "2023-01-01T10:00:00Z" } ``` ``` -------------------------------- ### Get Product Count (JavaScript) Source: https://js-sdk.oneentry.cloud/docs/products/getProductsCount Retrieves the total count of all products. This is a minimal example demonstrating the basic usage of the getProductsCount method without any filters. ```javascript const response = await Products.getProductsCount(); ``` -------------------------------- ### Complete OAuth Sign-Up and Authentication Flow Source: https://js-sdk.oneentry.cloud/docs/index/usageExamples/auth-provider/oauth A comprehensive example demonstrating the entire OAuth sign-up and authentication process. It includes importing the SDK, initializing the client, performing both registration and authorization code grant types via 'oauthSignUp', and finally retrieving user data with 'getUser'. Error handling is included using .catch(). ```javascript // 1. Import defineOneEntry from SDK define PROJECT_URL and APP_TOKEN import { defineOneEntry } from 'oneentry'; const PROJECT_URL = 'your-project-url'; const APP_TOKEN = 'your-app-token'; // 2. Creating an API client: const { AuthProvider, Users } = defineOneEntry(PROJECT_URL, { token: APP_TOKEN, }); // 3. User registration with AuthProvider.oauthSignUp const body = { "client_id": "34346983-luuct343473qdkqidjopdfp3eb3k4thp.apps.googleusercontent.com", "client_secret": "43434343434", "code": "4/0AVMBsJgwewewewewewei4D7T6E_fbswxnL3g", "grant_type": "registration", "redirect_uri": "http://localhost:3000" }; const signUpResponse = await AuthProvider.oauthSignUp('email', body).catch((e) => e); // console.log(JSON.stringify(signUpResponse)); // 4. User authentication with AuthProvider.oauthSignUp const authBody = { "client_id": "34346983-luuct343473qdkqidjopdfp3eb3k4thp.apps.googleusercontent.com", "client_secret": "43434343434", "code": "4/0AVMBsJgwewewewewewei4D7T6E_fbswxnL3g", "grant_type": "authorization_code", "redirect_uri": "http://localhost:3000" }; const authResponse = await AuthProvider.oauthSignUp('email', authBody).catch((e) => e); // console.log(JSON.stringify(authResponse)); // 5. Now you can get user data with Users.getUser() const user = await Users.getUser().catch((e) => e); // console.log(JSON.stringify(user)); ``` -------------------------------- ### Product Preview Image Example (JSON) Source: https://js-sdk.oneentry.cloud/docs/orders/getAllOrdersByMarker This JSON snippet details the structure for a product's preview image. It includes the filename, download link, size, and a link to a preview version of the image. ```json { "filename": "image.jpg", "downloadLink": "https://example.com/image.jpg", "size": 102400, "previewLink": "https://example.com/image-preview.jpg" } ``` -------------------------------- ### OneEntry SDK Raw Additional Fields Mode Source: https://js-sdk.oneentry.cloud/docs/index Configures the OneEntry SDK to retain the original API response format for 'additionalFields' by setting `rawData: true`. This returns 'additionalFields' as an array. ```javascript const api = defineOneEntry('https://your-project.oneentry.cloud', { token: 'your-token', rawData: true, }) // additionalFields is the original array from the API: const field = attribute.additionalFields.find(f => f.marker === 'my_field') console.log(field.value) ``` -------------------------------- ### OneEntry SDK Default Additional Fields Handling Source: https://js-sdk.oneentry.cloud/docs/index Shows the default behavior of the OneEntry SDK where 'additionalFields' is transformed into an object keyed by 'marker' for easier access. 'rawData' is implicitly false. ```javascript const api = defineOneEntry('https://your-project.oneentry.cloud', { token: 'your-token', // rawData is false by default — no need to pass it explicitly }) // additionalFields is an object keyed by marker: const field = attribute.additionalFields['my_field'] console.log(field.value) // direct access, no array search needed ``` -------------------------------- ### Configure OneEntry SDK with Validation Enabled Source: https://js-sdk.oneentry.cloud/docs/index Enables response validation in the OneEntry SDK by setting the 'validation' property in the configuration. Supports enabling/disabling validation, strict mode, and error logging. ```javascript import { defineOneEntry } from 'oneentry' const api = defineOneEntry('https://your-project.oneentry.cloud', { token: 'your-token', validation: { enabled: true, strictMode: false, logErrors: true, } }) ``` -------------------------------- ### Initialize OneEntry SDK and API Clients Source: https://js-sdk.oneentry.cloud/docs/index/usageExamples/orders/tickets-order Initializes the OneEntry SDK with project URL and app token, then defines API clients for various services like AuthProvider, Forms, Orders, and Payments. This is the first step before making any API calls. ```javascript import { defineOneEntry } from 'oneentry'; const PROJECT_URL = 'your-project-url'; const APP_TOKEN = 'your-app-token'; const { AuthProvider, Forms, Orders, Payments } = defineOneEntry(PROJECT_URL, { token: APP_TOKEN, }); ``` -------------------------------- ### Set Access Token for User Authorization (JavaScript) Source: https://js-sdk.oneentry.cloud/docs/index Demonstrates how to set an access token for a specific request when user authorization is required. This method should only be used for requests that need user authentication. ```javascript const user = api.Users.setAccessToken('my.access.token').getUser(); ``` -------------------------------- ### User State Object Examples (JSON) Source: https://js-sdk.oneentry.cloud/docs/users Demonstrates how custom application-specific data can be stored within a user's state object. Examples cover e-commerce, content sites, social apps, gaming, and SaaS use cases. ```json { "orderCount": 5, "totalSpent": 499.99 } ``` ```json { "articlesRead": 25, "bookmarks": [1, 2, 3] } ``` ```json { "postsCount": 42, "followers": 150 } ``` ```json { "level": 15, "score": 9500, "achievements": [] } ``` ```json { "plan": "premium", "usage": 75 } ``` -------------------------------- ### Initialize OneEntry Products Module Source: https://js-sdk.oneentry.cloud/docs/products Initializes the OneEntry Products module with your project URL and authentication token. This is the first step to interacting with the OneEntry catalog API. ```javascript const { Products } = defineOneEntry( "your-project-url", { "token": "your-app-token" } ); ``` -------------------------------- ### OneEntry SDK Soft Mode Validation Source: https://js-sdk.oneentry.cloud/docs/index Demonstrates OneEntry SDK configuration for soft mode validation. Errors are logged to the console, and the original API response is returned even if validation fails. Useful for development. ```javascript const api = defineOneEntry('https://your-project.oneentry.cloud', { token: 'your-token', validation: { enabled: true, strictMode: false, // Soft mode logErrors: true, } }) // Even if validation fails, you'll get the API response const user = await api.Users.getUser() // Console will show validation errors if any ``` -------------------------------- ### Get All Orders Storage Objects (JavaScript) Source: https://js-sdk.oneentry.cloud/docs/orders/getAllOrdersStorage Retrieves all order storage objects using the Orders.getAllOrdersStorage method. This is a minimal example demonstrating the basic usage without any optional parameters. It returns a Promise that resolves to an array of IOrdersEntity objects. ```javascript const response = await Orders.getAllOrdersStorage(); ``` -------------------------------- ### Get Products with Minimal Configuration (JavaScript) Source: https://js-sdk.oneentry.cloud/docs/products/getProducts This snippet demonstrates the most basic usage of the `getProducts` method, retrieving products with default parameters. It's useful for quick data retrieval when no specific filtering or pagination is required. ```javascript const response = await Products.getProducts(); ``` -------------------------------- ### Get Payment Session by Order ID Source: https://js-sdk.oneentry.cloud/docs/index/usageExamples/orders/tickets-order Retrieves a payment session object using its associated order identifier. This is useful for checking the status or details of a payment related to a specific order. It returns the payment session object if found. ```javascript let sessionByOrderId = await Payments.getSessionByOrderId(order.id); console.log(sessionByOrderId); ``` -------------------------------- ### Initialize OneEntry SDK, Authenticate User, and Get Orders (JavaScript) Source: https://js-sdk.oneentry.cloud/docs/index/usageExamples/users/order-history This snippet demonstrates initializing the OneEntry SDK with project URL and app token, authenticating a user using their email and password, and then fetching all orders for a specific storage marker. It requires the 'oneentry' package and valid project/token credentials. ```javascript import { defineOneEntry } from 'oneentry'; const PROJECT_URL = 'your-project-url'; const APP_TOKEN = 'your-app-token'; const { AuthProvider, Orders } = defineOneEntry(PROJECT_URL, { token: APP_TOKEN, }); const authData = [ { marker: 'email_reg', value: 'your-user@email.com', }, { marker: 'password_reg', value: '123456', }, ]; const authResponse = await AuthProvider.auth('email', { authData, }); const allOrders = await Orders.getAllOrdersByMarker('orders', 'en_US', 0, 30); console.log(allOrders); ``` -------------------------------- ### Get Products by Page ID with Minimal Parameters (JavaScript) Source: https://js-sdk.oneentry.cloud/docs/products/getProductsByPageId This example demonstrates the minimal usage of the getProductsByPageId method. It requires only the page ID and an optional body for filtering. The response will contain product data based on the provided ID and any default or specified filters. ```javascript const response = await Products.getProductsByPageId( id, body ); ``` -------------------------------- ### Product Response Schema Example Source: https://js-sdk.oneentry.cloud/docs/products/getProductsEmptyPage Illustrates the structure of the IProductsResponse, showing the 'total' count and an array of 'items' representing product entities. Each item includes fields like 'id', 'title', and 'additional' localization information. ```json { "total": 100, "items": [ { "id": 12345, "title": "Product 1" }, { "id": 67890, "title": "Product 2" } ] } ``` -------------------------------- ### Handle API Errors with Try/Catch (JavaScript) Source: https://js-sdk.oneentry.cloud/docs/index This code block shows how to use the 'try...catch' statement to handle errors when 'isShell' is set to false in the SDK configuration. It attempts to call an API method and catches any exceptions that occur during the process. ```javascript try { const result = await api.someMethod(); // Handling a successful result } catch (error) { // Error handling } ``` -------------------------------- ### User Registration and Authentication with OneEntry JS SDK Source: https://js-sdk.oneentry.cloud/docs/index/usageExamples/users/register-user This snippet demonstrates the full user registration and authentication process using the OneEntry JS SDK. It includes importing the SDK, setting up project credentials, retrieving form data, submitting registration details, verifying email confirmation codes, and performing user authentication. Ensure you replace placeholder values like 'your-project-url', 'your-app-token', and user details with actual data. ```javascript // 1. Import defineOneEntry from SDK and define PROJECT_URL and APP_TOKEN import { defineOneEntry } from 'oneentry'; const PROJECT_URL = 'your-project-url'; const APP_TOKEN = 'your-app-token'; const emailReg = 'your-user@email.com'; // 2. Creating an API client: const { Forms, AuthProvider } = defineOneEntry(PROJECT_URL, { token: APP_TOKEN, }); // 3. We get a registration form with custom fields for generating a frontend form const form = await Forms.getFormByMarker('reg'); // 4. Preparing data for user registration and user registration const authData = [ { marker: 'email_reg', value: 'your-user@email.com', }, { marker: 'password_reg', value: '123456', }, ]; const formData = [ { marker: 'name_reg', type: 'string', value: 'UserName', }, { marker: 'phone_reg', type: 'string', value: '+18007986545', }, { marker: 'email_notification_reg', type: 'string', value: emailReg, }, ]; const notificationData = { email: emailReg, phonePush: [], phoneSMS: '+18007986545', }; const registrationData = { formIdentifier: 'reg', authData: authData, formData: formData, notificationData: notificationData, }; let newUser = await AuthProvider.signUp('email', registrationData); // 5. Generate a confirmation code (send to email) let generateCode = await AuthProvider.generateCode('email', emailReg, 'auth'); // 6. User enters code → verification const code = prompt('Enter verification code:') as string; // 7. User activation const isCorrect = await AuthProvider.checkCode( 'email', emailReg, '1', code, ); if (isCorrect) { await AuthProvider.activateUser('email', emailReg, code); console.log('✅ User activated!'); } else { console.log('❌ Invalid verification code'); } // 8. User authentication const authResponse = await AuthProvider.auth('email', { authData, }); console.log(authResponse); ``` -------------------------------- ### Get All Orders Storage Objects with Parameters (JavaScript) Source: https://js-sdk.oneentry.cloud/docs/orders/getAllOrdersStorage Retrieves all order storage objects with specified language, offset, and limit. This example shows how to use optional parameters for language code, pagination offset, and limit. It returns a Promise that resolves to an array of IOrdersEntity objects. ```javascript const response = await Orders.getAllOrdersStorage('en_US', 0, 30); ``` -------------------------------- ### JSON Example for Interval Template Configuration Source: https://js-sdk.oneentry.cloud/docs/attribute-sets/attributesets This JSON snippet illustrates the structure of an interval template, including its unique identifier, applicability range, external exceptions, and internal time slots with start and end times. It also specifies recurrence patterns like 'inEveryWeek', 'inEveryMonth', and 'inEveryYears'. ```json { "id": "0da61a19-49cb-40b1-88e6-1fa3c93a1fa6", "range": [ "2025-11-26T17:00:00.000Z", "2025-11-26T17:00:00.000Z" ], "external": [ { "date": "2025-12-17T17:00:00.000Z", "externalTimes": [ ["2025-12-17T17:25:00.000Z", "2025-12-17T17:27:00.000Z"] ] } ], "intervals": [ { "id": "01fea594-9933-47ac-af0a-ec0e0884f618", "end": { "hours": 21, "minutes": 19 }, "start": { "hours": 19, "minutes": 18 }, "period": null }, { "id": "22ba24af-1fae-4422-8c92-0635b684a306", "end": { "hours": 0, "minutes": 29 }, "start": { "hours": 0, "minutes": 25 }, "period": 2, "external": { "show": false, "value": 2 } } ], "inEveryWeek": true, "inEveryMonth": true, "inEveryYears": true } ``` -------------------------------- ### Initialize OneEntry Payments Module Source: https://js-sdk.oneentry.cloud/docs/payments Initializes the OneEntry SDK with project details and authentication token to access the Payments module. Ensure you have a valid project URL and app token. ```javascript const { Payments } = defineOneEntry( "your-project-url", { "token": "your-app-token" } ); ```