Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Allow paginating customer / gift card searches
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomarg committed Mar 6, 2024
1 parent f66db62 commit 13a230d
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-doors-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopify/shopify-api": patch
---

Enabled returning the full response object in `Customer.search()` and `GiftCard.search()`, so that apps can paginate through the results.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ rollup.config.cjs
.eslintrc.cjs
node_modules/
dist/
packages/shopify-api/rest/admin
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages/shopify-api/rest/admin
14 changes: 12 additions & 2 deletions packages/shopify-api/rest/admin/2022-10/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
import {ResourcePath, ResourceNames} from '../../types';
import {Session} from '../../../lib/session/session';
import {ApiVersion} from '../../../lib/types';
import {logger} from '../../../lib/logger';

import {Metafield} from './metafield';

Expand Down Expand Up @@ -51,6 +52,7 @@ interface SearchArgs {
query?: unknown;
limit?: unknown;
fields?: unknown;
returnObject?: boolean;
}
interface AccountActivationUrlArgs {
[key: string]: unknown;
Expand Down Expand Up @@ -193,9 +195,17 @@ export class Customer extends Base {
query = null,
limit = null,
fields = null,
returnObject = false,
...otherArgs
}: SearchArgs
}: SearchArgs,
): Promise<unknown> {
if (!returnObject) {
logger(this.config).deprecated(
'10.0.0',
'The search() method will start returning the full response, similar to all(). Pass in returnObject: true to get the full response before the next major release.',
);
}

const response = await this.request<Customer>({
http_method: "get",
operation: "search",
Expand All @@ -206,7 +216,7 @@ export class Customer extends Base {
entity: null,
});

return response ? response.body : null;
return returnObject ? response : response?.body;
}

public async account_activation_url(
Expand Down
12 changes: 11 additions & 1 deletion packages/shopify-api/rest/admin/2022-10/gift_card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
import {ResourcePath, ResourceNames} from '../../types';
import {Session} from '../../../lib/session/session';
import {ApiVersion} from '../../../lib/types';
import {logger} from '../../../lib/logger';

interface FindArgs {
session: Session;
Expand Down Expand Up @@ -35,6 +36,7 @@ interface SearchArgs {
created_at_max?: unknown;
updated_at_min?: unknown;
updated_at_max?: unknown;
returnObject?: boolean;
}
interface DisableArgs {
[key: string]: unknown;
Expand Down Expand Up @@ -126,9 +128,17 @@ export class GiftCard extends Base {
created_at_max = null,
updated_at_min = null,
updated_at_max = null,
returnObject = false,
...otherArgs
}: SearchArgs
): Promise<unknown> {
if (!returnObject) {
logger(this.config).deprecated(
'10.0.0',
'The search() method will start returning the full response, similar to all(). Pass in returnObject: true to get the full response before the next major release.',
);
}

const response = await this.request<GiftCard>({
http_method: "get",
operation: "search",
Expand All @@ -139,7 +149,7 @@ export class GiftCard extends Base {
entity: null,
});

return response ? response.body : null;
return returnObject ? response : response?.body;
}

public async disable(
Expand Down
12 changes: 11 additions & 1 deletion packages/shopify-api/rest/admin/2023-01/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
import {ResourcePath, ResourceNames} from '../../types';
import {Session} from '../../../lib/session/session';
import {ApiVersion} from '../../../lib/types';
import {logger} from '../../../lib/logger';

import {Metafield} from './metafield';

Expand Down Expand Up @@ -51,6 +52,7 @@ interface SearchArgs {
query?: unknown;
limit?: unknown;
fields?: unknown;
returnObject?: boolean;
}
interface AccountActivationUrlArgs {
[key: string]: unknown;
Expand Down Expand Up @@ -193,9 +195,17 @@ export class Customer extends Base {
query = null,
limit = null,
fields = null,
returnObject = false,
...otherArgs
}: SearchArgs
): Promise<unknown> {
if (!returnObject) {
logger(this.config).deprecated(
'10.0.0',
'The search() method will start returning the full response, similar to all(). Pass in returnObject: true to get the full response before the next major release.',
);
}

const response = await this.request<Customer>({
http_method: "get",
operation: "search",
Expand All @@ -206,7 +216,7 @@ export class Customer extends Base {
entity: null,
});

return response ? response.body : null;
return returnObject ? response : response?.body;
}

public async account_activation_url(
Expand Down
12 changes: 11 additions & 1 deletion packages/shopify-api/rest/admin/2023-01/gift_card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
import {ResourcePath, ResourceNames} from '../../types';
import {Session} from '../../../lib/session/session';
import {ApiVersion} from '../../../lib/types';
import {logger} from '../../../lib/logger';

interface FindArgs {
session: Session;
Expand Down Expand Up @@ -35,6 +36,7 @@ interface SearchArgs {
created_at_max?: unknown;
updated_at_min?: unknown;
updated_at_max?: unknown;
returnObject?: boolean;
}
interface DisableArgs {
[key: string]: unknown;
Expand Down Expand Up @@ -126,9 +128,17 @@ export class GiftCard extends Base {
created_at_max = null,
updated_at_min = null,
updated_at_max = null,
returnObject = false,
...otherArgs
}: SearchArgs
): Promise<unknown> {
if (!returnObject) {
logger(this.config).deprecated(
'10.0.0',
'The search() method will start returning the full response, similar to all(). Pass in returnObject: true to get the full response before the next major release.',
);
}

const response = await this.request<GiftCard>({
http_method: "get",
operation: "search",
Expand All @@ -139,7 +149,7 @@ export class GiftCard extends Base {
entity: null,
});

return response ? response.body : null;
return returnObject ? response : response?.body;
}

public async disable(
Expand Down
12 changes: 11 additions & 1 deletion packages/shopify-api/rest/admin/2023-04/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
import {ResourcePath, ResourceNames} from '../../types';
import {Session} from '../../../lib/session/session';
import {ApiVersion} from '../../../lib/types';
import {logger} from '../../../lib/logger';

import {Metafield} from './metafield';

Expand Down Expand Up @@ -51,6 +52,7 @@ interface SearchArgs {
query?: unknown;
limit?: unknown;
fields?: unknown;
returnObject?: boolean;
}
interface AccountActivationUrlArgs {
[key: string]: unknown;
Expand Down Expand Up @@ -193,9 +195,17 @@ export class Customer extends Base {
query = null,
limit = null,
fields = null,
returnObject = false,
...otherArgs
}: SearchArgs
): Promise<unknown> {
if (!returnObject) {
logger(this.config).deprecated(
'10.0.0',
'The search() method will start returning the full response, similar to all(). Pass in returnObject: true to get the full response before the next major release.',
);
}

const response = await this.request<Customer>({
http_method: "get",
operation: "search",
Expand All @@ -206,7 +216,7 @@ export class Customer extends Base {
entity: null,
});

return response ? response.body : null;
return returnObject ? response : response?.body;
}

public async account_activation_url(
Expand Down
12 changes: 11 additions & 1 deletion packages/shopify-api/rest/admin/2023-04/gift_card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
import {ResourcePath, ResourceNames} from '../../types';
import {Session} from '../../../lib/session/session';
import {ApiVersion} from '../../../lib/types';
import {logger} from '../../../lib/logger';

interface FindArgs {
session: Session;
Expand Down Expand Up @@ -35,6 +36,7 @@ interface SearchArgs {
created_at_max?: unknown;
updated_at_min?: unknown;
updated_at_max?: unknown;
returnObject?: boolean;
}
interface DisableArgs {
[key: string]: unknown;
Expand Down Expand Up @@ -126,9 +128,17 @@ export class GiftCard extends Base {
created_at_max = null,
updated_at_min = null,
updated_at_max = null,
returnObject = false,
...otherArgs
}: SearchArgs
): Promise<unknown> {
if (!returnObject) {
logger(this.config).deprecated(
'10.0.0',
'The search() method will start returning the full response, similar to all(). Pass in returnObject: true to get the full response before the next major release.',
);
}

const response = await this.request<GiftCard>({
http_method: "get",
operation: "search",
Expand All @@ -139,7 +149,7 @@ export class GiftCard extends Base {
entity: null,
});

return response ? response.body : null;
return returnObject ? response : response?.body;
}

public async disable(
Expand Down
12 changes: 11 additions & 1 deletion packages/shopify-api/rest/admin/2023-07/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
import {ResourcePath, ResourceNames} from '../../types';
import {Session} from '../../../lib/session/session';
import {ApiVersion} from '../../../lib/types';
import {logger} from '../../../lib/logger';

import {Metafield} from './metafield';

Expand Down Expand Up @@ -51,6 +52,7 @@ interface SearchArgs {
query?: unknown;
limit?: unknown;
fields?: unknown;
returnObject?: boolean;
}
interface AccountActivationUrlArgs {
[key: string]: unknown;
Expand Down Expand Up @@ -193,9 +195,17 @@ export class Customer extends Base {
query = null,
limit = null,
fields = null,
returnObject = false,
...otherArgs
}: SearchArgs
): Promise<unknown> {
if (!returnObject) {
logger(this.config).deprecated(
'10.0.0',
'The search() method will start returning the full response, similar to all(). Pass in returnObject: true to get the full response before the next major release.',
);
}

const response = await this.request<Customer>({
http_method: "get",
operation: "search",
Expand All @@ -206,7 +216,7 @@ export class Customer extends Base {
entity: null,
});

return response ? response.body : null;
return returnObject ? response : response?.body;
}

public async account_activation_url(
Expand Down
12 changes: 11 additions & 1 deletion packages/shopify-api/rest/admin/2023-07/gift_card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
import {ResourcePath, ResourceNames} from '../../types';
import {Session} from '../../../lib/session/session';
import {ApiVersion} from '../../../lib/types';
import {logger} from '../../../lib/logger';

interface FindArgs {
session: Session;
Expand Down Expand Up @@ -35,6 +36,7 @@ interface SearchArgs {
created_at_max?: unknown;
updated_at_min?: unknown;
updated_at_max?: unknown;
returnObject?: boolean;
}
interface DisableArgs {
[key: string]: unknown;
Expand Down Expand Up @@ -126,9 +128,17 @@ export class GiftCard extends Base {
created_at_max = null,
updated_at_min = null,
updated_at_max = null,
returnObject = false,
...otherArgs
}: SearchArgs
): Promise<unknown> {
if (!returnObject) {
logger(this.config).deprecated(
'10.0.0',
'The search() method will start returning the full response, similar to all(). Pass in returnObject: true to get the full response before the next major release.',
);
}

const response = await this.request<GiftCard>({
http_method: "get",
operation: "search",
Expand All @@ -139,7 +149,7 @@ export class GiftCard extends Base {
entity: null,
});

return response ? response.body : null;
return returnObject ? response : response?.body;
}

public async disable(
Expand Down
Loading

0 comments on commit 13a230d

Please sign in to comment.