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

Commit 13a230d

Browse files
committed
Allow paginating customer / gift card searches
1 parent f66db62 commit 13a230d

File tree

15 files changed

+140
-13
lines changed

15 files changed

+140
-13
lines changed

.changeset/gentle-doors-complain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@shopify/shopify-api": patch
3+
---
4+
5+
Enabled returning the full response object in `Customer.search()` and `GiftCard.search()`, so that apps can paginate through the results.

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ rollup.config.cjs
33
.eslintrc.cjs
44
node_modules/
55
dist/
6+
packages/shopify-api/rest/admin

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages/shopify-api/rest/admin

packages/shopify-api/rest/admin/2022-10/customer.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
66
import {ResourcePath, ResourceNames} from '../../types';
77
import {Session} from '../../../lib/session/session';
88
import {ApiVersion} from '../../../lib/types';
9+
import {logger} from '../../../lib/logger';
910

1011
import {Metafield} from './metafield';
1112

@@ -51,6 +52,7 @@ interface SearchArgs {
5152
query?: unknown;
5253
limit?: unknown;
5354
fields?: unknown;
55+
returnObject?: boolean;
5456
}
5557
interface AccountActivationUrlArgs {
5658
[key: string]: unknown;
@@ -193,9 +195,17 @@ export class Customer extends Base {
193195
query = null,
194196
limit = null,
195197
fields = null,
198+
returnObject = false,
196199
...otherArgs
197-
}: SearchArgs
200+
}: SearchArgs,
198201
): Promise<unknown> {
202+
if (!returnObject) {
203+
logger(this.config).deprecated(
204+
'10.0.0',
205+
'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.',
206+
);
207+
}
208+
199209
const response = await this.request<Customer>({
200210
http_method: "get",
201211
operation: "search",
@@ -206,7 +216,7 @@ export class Customer extends Base {
206216
entity: null,
207217
});
208218

209-
return response ? response.body : null;
219+
return returnObject ? response : response?.body;
210220
}
211221

212222
public async account_activation_url(

packages/shopify-api/rest/admin/2022-10/gift_card.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
66
import {ResourcePath, ResourceNames} from '../../types';
77
import {Session} from '../../../lib/session/session';
88
import {ApiVersion} from '../../../lib/types';
9+
import {logger} from '../../../lib/logger';
910

1011
interface FindArgs {
1112
session: Session;
@@ -35,6 +36,7 @@ interface SearchArgs {
3536
created_at_max?: unknown;
3637
updated_at_min?: unknown;
3738
updated_at_max?: unknown;
39+
returnObject?: boolean;
3840
}
3941
interface DisableArgs {
4042
[key: string]: unknown;
@@ -126,9 +128,17 @@ export class GiftCard extends Base {
126128
created_at_max = null,
127129
updated_at_min = null,
128130
updated_at_max = null,
131+
returnObject = false,
129132
...otherArgs
130133
}: SearchArgs
131134
): Promise<unknown> {
135+
if (!returnObject) {
136+
logger(this.config).deprecated(
137+
'10.0.0',
138+
'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.',
139+
);
140+
}
141+
132142
const response = await this.request<GiftCard>({
133143
http_method: "get",
134144
operation: "search",
@@ -139,7 +149,7 @@ export class GiftCard extends Base {
139149
entity: null,
140150
});
141151

142-
return response ? response.body : null;
152+
return returnObject ? response : response?.body;
143153
}
144154

145155
public async disable(

packages/shopify-api/rest/admin/2023-01/customer.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
66
import {ResourcePath, ResourceNames} from '../../types';
77
import {Session} from '../../../lib/session/session';
88
import {ApiVersion} from '../../../lib/types';
9+
import {logger} from '../../../lib/logger';
910

1011
import {Metafield} from './metafield';
1112

@@ -51,6 +52,7 @@ interface SearchArgs {
5152
query?: unknown;
5253
limit?: unknown;
5354
fields?: unknown;
55+
returnObject?: boolean;
5456
}
5557
interface AccountActivationUrlArgs {
5658
[key: string]: unknown;
@@ -193,9 +195,17 @@ export class Customer extends Base {
193195
query = null,
194196
limit = null,
195197
fields = null,
198+
returnObject = false,
196199
...otherArgs
197200
}: SearchArgs
198201
): Promise<unknown> {
202+
if (!returnObject) {
203+
logger(this.config).deprecated(
204+
'10.0.0',
205+
'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.',
206+
);
207+
}
208+
199209
const response = await this.request<Customer>({
200210
http_method: "get",
201211
operation: "search",
@@ -206,7 +216,7 @@ export class Customer extends Base {
206216
entity: null,
207217
});
208218

209-
return response ? response.body : null;
219+
return returnObject ? response : response?.body;
210220
}
211221

212222
public async account_activation_url(

packages/shopify-api/rest/admin/2023-01/gift_card.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
66
import {ResourcePath, ResourceNames} from '../../types';
77
import {Session} from '../../../lib/session/session';
88
import {ApiVersion} from '../../../lib/types';
9+
import {logger} from '../../../lib/logger';
910

1011
interface FindArgs {
1112
session: Session;
@@ -35,6 +36,7 @@ interface SearchArgs {
3536
created_at_max?: unknown;
3637
updated_at_min?: unknown;
3738
updated_at_max?: unknown;
39+
returnObject?: boolean;
3840
}
3941
interface DisableArgs {
4042
[key: string]: unknown;
@@ -126,9 +128,17 @@ export class GiftCard extends Base {
126128
created_at_max = null,
127129
updated_at_min = null,
128130
updated_at_max = null,
131+
returnObject = false,
129132
...otherArgs
130133
}: SearchArgs
131134
): Promise<unknown> {
135+
if (!returnObject) {
136+
logger(this.config).deprecated(
137+
'10.0.0',
138+
'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.',
139+
);
140+
}
141+
132142
const response = await this.request<GiftCard>({
133143
http_method: "get",
134144
operation: "search",
@@ -139,7 +149,7 @@ export class GiftCard extends Base {
139149
entity: null,
140150
});
141151

142-
return response ? response.body : null;
152+
return returnObject ? response : response?.body;
143153
}
144154

145155
public async disable(

packages/shopify-api/rest/admin/2023-04/customer.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
66
import {ResourcePath, ResourceNames} from '../../types';
77
import {Session} from '../../../lib/session/session';
88
import {ApiVersion} from '../../../lib/types';
9+
import {logger} from '../../../lib/logger';
910

1011
import {Metafield} from './metafield';
1112

@@ -51,6 +52,7 @@ interface SearchArgs {
5152
query?: unknown;
5253
limit?: unknown;
5354
fields?: unknown;
55+
returnObject?: boolean;
5456
}
5557
interface AccountActivationUrlArgs {
5658
[key: string]: unknown;
@@ -193,9 +195,17 @@ export class Customer extends Base {
193195
query = null,
194196
limit = null,
195197
fields = null,
198+
returnObject = false,
196199
...otherArgs
197200
}: SearchArgs
198201
): Promise<unknown> {
202+
if (!returnObject) {
203+
logger(this.config).deprecated(
204+
'10.0.0',
205+
'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.',
206+
);
207+
}
208+
199209
const response = await this.request<Customer>({
200210
http_method: "get",
201211
operation: "search",
@@ -206,7 +216,7 @@ export class Customer extends Base {
206216
entity: null,
207217
});
208218

209-
return response ? response.body : null;
219+
return returnObject ? response : response?.body;
210220
}
211221

212222
public async account_activation_url(

packages/shopify-api/rest/admin/2023-04/gift_card.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
66
import {ResourcePath, ResourceNames} from '../../types';
77
import {Session} from '../../../lib/session/session';
88
import {ApiVersion} from '../../../lib/types';
9+
import {logger} from '../../../lib/logger';
910

1011
interface FindArgs {
1112
session: Session;
@@ -35,6 +36,7 @@ interface SearchArgs {
3536
created_at_max?: unknown;
3637
updated_at_min?: unknown;
3738
updated_at_max?: unknown;
39+
returnObject?: boolean;
3840
}
3941
interface DisableArgs {
4042
[key: string]: unknown;
@@ -126,9 +128,17 @@ export class GiftCard extends Base {
126128
created_at_max = null,
127129
updated_at_min = null,
128130
updated_at_max = null,
131+
returnObject = false,
129132
...otherArgs
130133
}: SearchArgs
131134
): Promise<unknown> {
135+
if (!returnObject) {
136+
logger(this.config).deprecated(
137+
'10.0.0',
138+
'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.',
139+
);
140+
}
141+
132142
const response = await this.request<GiftCard>({
133143
http_method: "get",
134144
operation: "search",
@@ -139,7 +149,7 @@ export class GiftCard extends Base {
139149
entity: null,
140150
});
141151

142-
return response ? response.body : null;
152+
return returnObject ? response : response?.body;
143153
}
144154

145155
public async disable(

packages/shopify-api/rest/admin/2023-07/customer.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
66
import {ResourcePath, ResourceNames} from '../../types';
77
import {Session} from '../../../lib/session/session';
88
import {ApiVersion} from '../../../lib/types';
9+
import {logger} from '../../../lib/logger';
910

1011
import {Metafield} from './metafield';
1112

@@ -51,6 +52,7 @@ interface SearchArgs {
5152
query?: unknown;
5253
limit?: unknown;
5354
fields?: unknown;
55+
returnObject?: boolean;
5456
}
5557
interface AccountActivationUrlArgs {
5658
[key: string]: unknown;
@@ -193,9 +195,17 @@ export class Customer extends Base {
193195
query = null,
194196
limit = null,
195197
fields = null,
198+
returnObject = false,
196199
...otherArgs
197200
}: SearchArgs
198201
): Promise<unknown> {
202+
if (!returnObject) {
203+
logger(this.config).deprecated(
204+
'10.0.0',
205+
'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.',
206+
);
207+
}
208+
199209
const response = await this.request<Customer>({
200210
http_method: "get",
201211
operation: "search",
@@ -206,7 +216,7 @@ export class Customer extends Base {
206216
entity: null,
207217
});
208218

209-
return response ? response.body : null;
219+
return returnObject ? response : response?.body;
210220
}
211221

212222
public async account_activation_url(

packages/shopify-api/rest/admin/2023-07/gift_card.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Base, FindAllResponse} from '../../base';
66
import {ResourcePath, ResourceNames} from '../../types';
77
import {Session} from '../../../lib/session/session';
88
import {ApiVersion} from '../../../lib/types';
9+
import {logger} from '../../../lib/logger';
910

1011
interface FindArgs {
1112
session: Session;
@@ -35,6 +36,7 @@ interface SearchArgs {
3536
created_at_max?: unknown;
3637
updated_at_min?: unknown;
3738
updated_at_max?: unknown;
39+
returnObject?: boolean;
3840
}
3941
interface DisableArgs {
4042
[key: string]: unknown;
@@ -126,9 +128,17 @@ export class GiftCard extends Base {
126128
created_at_max = null,
127129
updated_at_min = null,
128130
updated_at_max = null,
131+
returnObject = false,
129132
...otherArgs
130133
}: SearchArgs
131134
): Promise<unknown> {
135+
if (!returnObject) {
136+
logger(this.config).deprecated(
137+
'10.0.0',
138+
'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.',
139+
);
140+
}
141+
132142
const response = await this.request<GiftCard>({
133143
http_method: "get",
134144
operation: "search",
@@ -139,7 +149,7 @@ export class GiftCard extends Base {
139149
entity: null,
140150
});
141151

142-
return response ? response.body : null;
152+
return returnObject ? response : response?.body;
143153
}
144154

145155
public async disable(

0 commit comments

Comments
 (0)