Gathering detailed insights and metrics for @commercelayer/sdk-utils
Gathering detailed insights and metrics for @commercelayer/sdk-utils
Gathering detailed insights and metrics for @commercelayer/sdk-utils
Gathering detailed insights and metrics for @commercelayer/sdk-utils
npm install @commercelayer/sdk-utils
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (99.1%)
JavaScript (0.9%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1 Stars
127 Commits
2 Watchers
13 Branches
23 Contributors
Updated on Apr 14, 2025
Latest Version
2.5.4
Package Id
@commercelayer/sdk-utils@2.5.4
Unpacked Size
62.09 kB
Size
12.58 kB
File Count
7
NPM Version
10.9.2
Node Version
22.14.0
Published on
Apr 14, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
A JavaScript Library that makes even more easier to interact with Commerce Layer API using the official JavaScript SDK.
1import CommerceLayer from "@commercelayer/sdk" 2import CommerceLayerUtils, { executeBatch } from '@commercelayer/sdk' 3 4const cl = CommerceLayer({ organization, accessToken }) 5CommerceLayerUtils(cl) 6 7await executeBatch(batch)
Common functions
Cleanups
Exports
Imports
Webhooks
This function allows to prepare and then execute a number of API calls without having to worry about current rate limits.
1for (const emailAddress of emailList) { 2 const task: Task = { 3 resourceType: "customers", 4 operation: "create", 5 resource: { email: emailAddress } as CustomerCreate, 6 onSuccess: { callback: sendEmail }, 7 onFailure: { errorHandler: handleError } 8 } 9 tasks.push(task) 10 } 11 12 const batch: Batch = { 13 tasks, 14 options: { refreshToken: refreshAccessToken } 15 } 16 17 18await executeBatch(batch)
In the example above the onSuccess
and onFailure
callbacks have been used to handle the task result in case of success or failure of the execution.
It's also possible to fill the resource attributes taking values from the result of the previous batch step. In the following example we are updating a resource taking its id from a previous retrieve
or create
task:
1const task: Task = { 2 resourceType: "customers", 3 operation: "update", 4 prepareResource: (res: TaskResourceParam, last: TaskResourceResult): TaskResourceParam => { 5 return { 6 ...res, 7 id: last.id, 8 reference: 'new-reference' 9 } 10 } 11 }
This function allows to fetch all existing resources of a specific type executing all necessary API requests respecting current API rate limits.
The limit
option can be used to retrieve only a limited number of resources.
1const skus = await retrieveAll<Sku>('skus', { limit: 100 })
This function allows to modify a set of resources of a specific type, using a filter to identify them.
1const skuData = { reference_origin: 'legacy-system-0' } 2 3const filters = { created_at_lt: '2023-01-01' } 4 5const updateResult = await updateAll('skus', skuData, { filters })
This function allows to delete a set of resources of a specific type, using a filter to identify them.
1 2const filters = { created_at_lt: '2023-01-01', reference_origin_eq: 'legacy-system-0' } 3 4const deleteResult = await deleteAll('skus', { filters })
This function allows to fetch a specific subset of resources defining page attributes that are not permitted by the API and using all the standard common filters. An error will be thrown if the page parameters are not compatible with the number of existing resources.
1 const skus = await retrievePage<Sku>('skus', { pageNumber: 16, pageSize: 139, sort: ['code'] })
Split cleanup in multiple cleanups respecting the maximum limit of resources included
1const clp: CleanupCreate = { 2 resource_type: 'customers', 3 filters: { created_at_gt: '2020-01-01'} 4} 5 6const splitClp: CleanupCreate[] = await splitCleanup(clp)
Split cleanup in multiple cleanups respecting the maximum limit of resources included and execute them
1const clp: CleanupCreate = { 2 resource_type: 'customers', 3 filters: { created_at_gt: '2020-01-01'} 4} 5 6const execClp: CleanupResult[] = await executeCleanup(clp)
Convert a list of cleanups generated by splitCleanup
to a list of tasks that can be executed by the function executeBatch
1const clps = await splitCleanup(clp) 2 3const tasks = cleanupsToBatchTasks(clps)
Split an export in multiple exports respecting the maximum limit of resources included
1const exp: ExportCreate = { 2 resource_type: 'customers', 3 filters: { created_at_gt: '2020-01-01'} 4} 5 6const splitExp: ExportCreate[] = await splitExport(exp)
Split an export in multiple exports respecting the maximum limit of resources included and execute them
1const exp: ExportCreate = { 2 resource_type: 'customers', 3 filters: { created_at_gt: '2020-01-01'} 4} 5 6const execExp: ExportResult[] = await executeExport(exp)
Convert a list of exports generated by splitExport
to a list of tasks that can be executed by the function executeBatch
1const exps = await splitExport(exp) 2 3const tasks = exportsToBatchTasks(exps)
Split an import in multiple imports respecting the maximum limit of inputs included
1const exp: ImportCreate = { 2 resource_type: 'customers', 3 inputs: [ 4 { ... }, 5 { ... }, 6 ... 7 { ... } 8 ] 9} 10 11const splitImp: ImportCreate[] = await splitImport(imp)
Split an import in multiple imports respecting the maximum limit of inputs included and execute them
1const exp: ImportCreate = { 2 resource_type: 'customers', 3 inputs: [ 4 { ... }, 5 { ... }, 6 ... 7 { ... } 8 ] 9} 10 11const execImp: ImportResult[] = await executeImport(imp)
Convert a list of imports generated by splitImport
to a list of tasks that can be executed by the function executeBatch
1const imps = await splitImport(imp) 2 3const tasks = importsToBatchTasks(imps)
This function takes in input the payload of a webhook in JSON format and transform it in the appropriate typed resource to be used with the official Typescript SDK.
1const shipment = denormalizePayload<Shipment>(webhookPayload)
No vulnerabilities found.
No security vulnerabilities found.