From 6536022c969671710caf3272b6ab1545a5eb0bee Mon Sep 17 00:00:00 2001 From: Sam Blacklock Date: Tue, 12 May 2026 18:09:59 +0100 Subject: [PATCH 1/2] fix: add missing limit and offset --- src/endpoints/catalog.js | 21 ++++++++-- src/endpoints/catalogs.js | 18 ++++++-- src/endpoints/nodes.js | 7 +++- src/types/catalogs.d.ts | 2 + src/types/nodes.d.ts | 1 - test/tests.ts | 3 ++ test/unit/catalog.ts | 88 +++++++++++++++++++++++++++++++++++++++ test/unit/catalogs.ts | 88 +++++++++++++++++++++++++++++++++++++++ test/unit/nodes.ts | 34 +++++++++++++++ 9 files changed, 253 insertions(+), 9 deletions(-) create mode 100644 test/unit/catalog.ts create mode 100644 test/unit/catalogs.ts create mode 100644 test/unit/nodes.ts diff --git a/src/endpoints/catalog.js b/src/endpoints/catalog.js index d348e42..40c9b2c 100644 --- a/src/endpoints/catalog.js +++ b/src/endpoints/catalog.js @@ -128,8 +128,13 @@ class Hierarchies extends ShopperCatalogQuery { } All({ token = null, additionalHeaders = null } = {}) { + const { limit, offset } = this + return this.request.send( - `catalog/${this.endpoint}`, + buildURL(`catalog/${this.endpoint}`, { + limit, + offset + }), 'GET', undefined, token, @@ -157,8 +162,13 @@ class Hierarchies extends ShopperCatalogQuery { token = null, additionalHeaders = null }) { + const { limit, offset } = this + return this.request.send( - `catalog/${this.endpoint}/${hierarchyId}/children`, + buildURL(`catalog/${this.endpoint}/${hierarchyId}/children`, { + limit, + offset + }), 'GET', undefined, token, @@ -174,8 +184,13 @@ class Hierarchies extends ShopperCatalogQuery { token = null, additionalHeaders = null } = {}) { + const { limit, offset } = this + return this.request.send( - `catalog/${this.endpoint}/${hierarchyId}/nodes`, + buildURL(`catalog/${this.endpoint}/${hierarchyId}/nodes`, { + limit, + offset + }), 'GET', undefined, token, diff --git a/src/endpoints/catalogs.js b/src/endpoints/catalogs.js index e12be3e..adb1031 100644 --- a/src/endpoints/catalogs.js +++ b/src/endpoints/catalogs.js @@ -12,8 +12,12 @@ class Nodes extends CRUDExtend { } All({ token = null }) { + const { limit, offset } = this return this.request.send( - `catalogs/${this.endpoint}`, + buildURL(`catalogs/${this.endpoint}`, { + limit, + offset + }), 'GET', undefined, token @@ -231,8 +235,12 @@ class Releases extends CRUDExtend { } All({ catalogId, token = null }) { + const { limit, offset } = this return this.request.send( - `catalogs/${catalogId}/${this.endpoint}`, + buildURL(`catalogs/${this.endpoint}/${catalogId}`, { + limit, + offset + }), 'GET', undefined, token @@ -397,8 +405,12 @@ class CatalogsEndpoint extends CRUDExtend { } GetCatalogReleases(catalogId, token = null) { + const { limit, offset } = this return this.request.send( - `${this.endpoint}/${catalogId}/releases`, + buildURL(`${this.endpoint}/${catalogId}/releases`, { + limit, + offset + }), 'GET', undefined, token diff --git a/src/endpoints/nodes.js b/src/endpoints/nodes.js index 5c1d689..101233a 100644 --- a/src/endpoints/nodes.js +++ b/src/endpoints/nodes.js @@ -10,10 +10,13 @@ class NodesEndpoint { this.endpoint = 'nodes' } - // TODO: API - currently not working! (can get from hierarchy relationships) All({ hierarchyId, token = null }) { + const { limit, offset } = this return this.request.send( - `hierarchies/${hierarchyId}/${this.endpoint}`, + buildURL(`hierarchies/${hierarchyId}/${this.endpoint}`, { + limit, + offset + }), 'GET', undefined, token diff --git a/src/types/catalogs.d.ts b/src/types/catalogs.d.ts index f56b94b..9f75f77 100644 --- a/src/types/catalogs.d.ts +++ b/src/types/catalogs.d.ts @@ -74,6 +74,8 @@ export interface CatalogsEndpoint Products: CatalogsProductsEndpoint Releases: CatalogsReleasesEndpoint Rules: CatalogsRulesEndpoint + Limit(value: number): CatalogsEndpoint + Offset(value: number): CatalogsEndpoint GetCatalogReleases( catalogId: string, token?: string diff --git a/src/types/nodes.d.ts b/src/types/nodes.d.ts index 048a850..3d8496c 100644 --- a/src/types/nodes.d.ts +++ b/src/types/nodes.d.ts @@ -84,7 +84,6 @@ export interface NodesEndpoint { token?: string }): Promise> - // TODO: API - currently not working! (can get from hierarchy relationships) All(options: { hierarchyId: string token?: string diff --git a/test/tests.ts b/test/tests.ts index 7192e73..c4b6ae6 100644 --- a/test/tests.ts +++ b/test/tests.ts @@ -6,8 +6,11 @@ require('./unit/customer-addresses') require('./unit/account-addresses') require('./unit/brands') require('./unit/cart') +require('./unit/catalog') +require('./unit/catalogs') require('./unit/categories') require('./unit/collections') +require('./unit/nodes') require('./unit/currencies') require('./unit/customers') require('./unit/fields') diff --git a/test/unit/catalog.ts b/test/unit/catalog.ts new file mode 100644 index 0000000..6fc9198 --- /dev/null +++ b/test/unit/catalog.ts @@ -0,0 +1,88 @@ +import { assert } from 'chai' +import nock from 'nock' +import { gateway as ElasticPathGateway } from '../../src' + +const apiUrl = 'https://euwest.api.elasticpath.com' + +describe('ElasticPath ShopperCatalog hierarchies pagination', () => { + it('should pass page[limit] and page[offset] to Hierarchies.All', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .get('/catalog/hierarchies') + .query({ + page: { + limit: 10, + offset: 20 + } + }) + .reply(200, { data: [] }) + + return ElasticPath.ShopperCatalog.Hierarchies.Limit(10) + .Offset(20) + .All() + .then(response => { + assert.exists(response.data) + }) + }) + + it('should pass page[limit] and page[offset] to GetHierarchyChildren', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .get('/catalog/hierarchies/hierarchy-1/children') + .query({ + page: { + limit: 5, + offset: 15 + } + }) + .reply(200, { data: [] }) + + return ElasticPath.ShopperCatalog.Hierarchies.Limit(5) + .Offset(15) + .GetHierarchyChildren({ hierarchyId: 'hierarchy-1' }) + .then(response => { + assert.exists(response.data) + }) + }) + + it('should pass page[limit] and page[offset] to GetHierarchyNodes', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .get('/catalog/hierarchies/hierarchy-1/nodes') + .query({ + page: { + limit: 7, + offset: 21 + } + }) + .reply(200, { data: [] }) + + return ElasticPath.ShopperCatalog.Hierarchies.Limit(7) + .Offset(21) + .GetHierarchyNodes({ hierarchyId: 'hierarchy-1' }) + .then(response => { + assert.exists(response.data) + }) + }) +}) diff --git a/test/unit/catalogs.ts b/test/unit/catalogs.ts new file mode 100644 index 0000000..63043fd --- /dev/null +++ b/test/unit/catalogs.ts @@ -0,0 +1,88 @@ +import { assert } from 'chai' +import nock from 'nock' +import { gateway as ElasticPathGateway } from '../../src' + +const apiUrl = 'https://euwest.api.elasticpath.com/pcm' + +describe('ElasticPath catalogs pagination', () => { + it('should pass page[limit] and page[offset] to Catalogs.Nodes.All', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .get('/catalogs/nodes') + .query({ + page: { + limit: 10, + offset: 20 + } + }) + .reply(200, { data: [] }) + + return ElasticPath.Catalogs.Nodes.Limit(10) + .Offset(20) + .All({}) + .then(response => { + assert.exists(response.data) + }) + }) + + it('should pass page[limit] and page[offset] to Catalogs.Releases.All', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .get('/catalogs/releases/catalog-1') + .query({ + page: { + limit: 5, + offset: 15 + } + }) + .reply(200, { data: [] }) + + return ElasticPath.Catalogs.Releases.Limit(5) + .Offset(15) + .All({ catalogId: 'catalog-1' }) + .then(response => { + assert.exists(response.data) + }) + }) + + it('should pass page[limit] and page[offset] to Catalogs.GetCatalogReleases', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .get('/catalogs/catalog-1/releases') + .query({ + page: { + limit: 7, + offset: 21 + } + }) + .reply(200, { data: [] }) + + return ElasticPath.Catalogs.Limit(7) + .Offset(21) + .GetCatalogReleases('catalog-1') + .then(response => { + assert.exists(response.data) + }) + }) +}) diff --git a/test/unit/nodes.ts b/test/unit/nodes.ts new file mode 100644 index 0000000..2e72902 --- /dev/null +++ b/test/unit/nodes.ts @@ -0,0 +1,34 @@ +import { assert } from 'chai' +import nock from 'nock' +import { gateway as ElasticPathGateway } from '../../src' + +const apiUrl = 'https://euwest.api.elasticpath.com/pcm' + +describe('ElasticPath hierarchy nodes pagination', () => { + it('should pass page[limit] and page[offset] to All', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .get('/hierarchies/hierarchy-1/nodes') + .query({ + page: { + limit: 10, + offset: 20 + } + }) + .reply(200, { data: [] }) + + return ElasticPath.Hierarchies.Nodes.Limit(10) + .Offset(20) + .All({ hierarchyId: 'hierarchy-1' }) + .then(response => { + assert.exists(response.data) + }) + }) +}) From 14a13b485b94cc406c931282d3299c3bd909a234 Mon Sep 17 00:00:00 2001 From: Sam Blacklock Date: Tue, 12 May 2026 18:14:37 +0100 Subject: [PATCH 2/2] feat: correct all releases URL --- src/endpoints/catalogs.js | 12 ++---------- src/types/catalogs.d.ts | 2 -- test/unit/catalogs.ts | 40 ++++++++++++++------------------------- 3 files changed, 16 insertions(+), 38 deletions(-) diff --git a/src/endpoints/catalogs.js b/src/endpoints/catalogs.js index adb1031..c5d1138 100644 --- a/src/endpoints/catalogs.js +++ b/src/endpoints/catalogs.js @@ -235,12 +235,8 @@ class Releases extends CRUDExtend { } All({ catalogId, token = null }) { - const { limit, offset } = this return this.request.send( - buildURL(`catalogs/${this.endpoint}/${catalogId}`, { - limit, - offset - }), + `catalogs/${catalogId}/${this.endpoint}`, 'GET', undefined, token @@ -405,12 +401,8 @@ class CatalogsEndpoint extends CRUDExtend { } GetCatalogReleases(catalogId, token = null) { - const { limit, offset } = this return this.request.send( - buildURL(`${this.endpoint}/${catalogId}/releases`, { - limit, - offset - }), + `${this.endpoint}/${catalogId}/releases`, 'GET', undefined, token diff --git a/src/types/catalogs.d.ts b/src/types/catalogs.d.ts index 9f75f77..f56b94b 100644 --- a/src/types/catalogs.d.ts +++ b/src/types/catalogs.d.ts @@ -74,8 +74,6 @@ export interface CatalogsEndpoint Products: CatalogsProductsEndpoint Releases: CatalogsReleasesEndpoint Rules: CatalogsRulesEndpoint - Limit(value: number): CatalogsEndpoint - Offset(value: number): CatalogsEndpoint GetCatalogReleases( catalogId: string, token?: string diff --git a/test/unit/catalogs.ts b/test/unit/catalogs.ts index 63043fd..877e089 100644 --- a/test/unit/catalogs.ts +++ b/test/unit/catalogs.ts @@ -31,8 +31,10 @@ describe('ElasticPath catalogs pagination', () => { assert.exists(response.data) }) }) +}) - it('should pass page[limit] and page[offset] to Catalogs.Releases.All', () => { +describe('ElasticPath catalogs Releases.All URL shape', () => { + it('should request catalogs/{catalogId}/releases (not catalogs/releases/{catalogId})', () => { const ElasticPath = ElasticPathGateway({ client_id: 'XXX' }) @@ -42,24 +44,17 @@ describe('ElasticPath catalogs pagination', () => { Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' } }) - .get('/catalogs/releases/catalog-1') - .query({ - page: { - limit: 5, - offset: 15 - } - }) + .get('/catalogs/catalog-1/releases') .reply(200, { data: [] }) - return ElasticPath.Catalogs.Releases.Limit(5) - .Offset(15) - .All({ catalogId: 'catalog-1' }) - .then(response => { - assert.exists(response.data) - }) + return ElasticPath.Catalogs.Releases.All({ + catalogId: 'catalog-1' + }).then(response => { + assert.exists(response.data) + }) }) - it('should pass page[limit] and page[offset] to Catalogs.GetCatalogReleases', () => { + it('should request catalogs/{catalogId}/releases via Catalogs.GetCatalogReleases', () => { const ElasticPath = ElasticPathGateway({ client_id: 'XXX' }) @@ -70,19 +65,12 @@ describe('ElasticPath catalogs pagination', () => { } }) .get('/catalogs/catalog-1/releases') - .query({ - page: { - limit: 7, - offset: 21 - } - }) .reply(200, { data: [] }) - return ElasticPath.Catalogs.Limit(7) - .Offset(21) - .GetCatalogReleases('catalog-1') - .then(response => { + return ElasticPath.Catalogs.GetCatalogReleases('catalog-1').then( + response => { assert.exists(response.data) - }) + } + ) }) })