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

Commit 8d885bd

Browse files
committed
Applying comments from review
1 parent 13a230d commit 8d885bd

File tree

13 files changed

+54
-147
lines changed

13 files changed

+54
-147
lines changed

packages/shopify-api/docs/guides/rest-resources.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@ To make it easier to interact with the API, this library provides resource class
1010
1111
## Resource Methods
1212

13-
| Resource Method | Description | Admin API endpoint | Return |
14-
| --------------- | ----------- | ------------------ | ------ |
15-
| `find` | Fetch a single resource by its ID | `GET /admin/api/{version}/{resource_name}/{resource_id}.json` | A single resource |
16-
| `all` | Fetch all resources of a given type | `GET /admin/api/{version}/{resource_name}.json` | [An array of resources](#all-return-value) |
17-
| `count` | Fetch the number of resources of a given type | `GET /admin/api/{version}/{resource_name}/count.json` | Integer |
18-
| `save` | If the primary key for the resource **is not set**, a new resource will be created in Shopify | `POST /admin/api/{version}/{resource_name}.json` | void Promise (If option update: true is passed, the resource will be updated with the returned data.) |
19-
| `save` | If the primary key for a resource **is set** the resource in Shopify will be updated | `PUT /admin/api/{version}/{resource_name}/{resource_id}.json` | Promise void (If option update: true is passed, the resource will be updated with the returned data.) |
20-
| `delete` | Delete an existing resource | `DELETE /admin/api/{version}/{resource_name}/{resource_id}.json` | void Promise |
13+
| Resource Method | Description | Admin API endpoint | Return |
14+
| --------------- | --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
15+
| `find` | Fetch a single resource by its ID | `GET /admin/api/{version}/{resource_name}/{resource_id}.json` | A single resource |
16+
| `all` | Fetch all resources of a given type | `GET /admin/api/{version}/{resource_name}.json` | [An array of resources](#all-return-value) |
17+
| `count` | Fetch the number of resources of a given type | `GET /admin/api/{version}/{resource_name}/count.json` | Integer |
18+
| `save` | If the primary key for the resource **is not set**, a new resource will be created in Shopify | `POST /admin/api/{version}/{resource_name}.json` | void Promise (If option update: true is passed, the resource will be updated with the returned data.) |
19+
| `save` | If the primary key for a resource **is set** the resource in Shopify will be updated | `PUT /admin/api/{version}/{resource_name}/{resource_id}.json` | Promise void (If option update: true is passed, the resource will be updated with the returned data.) |
20+
| `delete` | Delete an existing resource | `DELETE /admin/api/{version}/{resource_name}/{resource_id}.json` | void Promise |
2121

2222
Some resources will have additional methods to help with common interactions, such as the [orders method on the customer resource](https://shopify.dev/docs/api/admin-rest/2023-07/resources/customer#get-customers-customer-id-orders). Review the [REST API reference](https://shopify.dev/docs/api/admin-rest) documentation for more information.
2323

2424
### All Return Value
25+
2526
The all method will return an array of resources, along with the response headers and pagination information.
2627

2728
```
@@ -110,13 +111,12 @@ await product.save({
110111
### Create a resource
111112

112113
```ts
113-
114114
const product = new shopify.rest.Product({session: session});
115-
product.title = "Burton Custom Freestyle 151";
116-
product.body_html = "<strong>Good snowboard!</strong>";
117-
product.vendor = "Burton";
118-
product.product_type = "Snowboard";
119-
product.status = "draft";
115+
product.title = 'Burton Custom Freestyle 151';
116+
product.body_html = '<strong>Good snowboard!</strong>';
117+
product.vendor = 'Burton';
118+
product.product_type = 'Snowboard';
119+
product.status = 'draft';
120120

121121
// After promise resolves, product will be updated with the returned data
122122
await product.save({
@@ -154,7 +154,6 @@ console.log(products.pageInfo);
154154

155155
// The response headers
156156
console.log(products.headers);
157-
158157
```
159158

160159
## Mounting REST resources
@@ -201,4 +200,8 @@ do {
201200
} while (pageInfo?.nextPage);
202201
```
203202

203+
> [!NOTE]
204+
> Some resources have a `search()` method which also supports pagination, in the same way `all()` does.
205+
> To return the full response information from `search()`, set the `returnFullResponse` option when calling it.
206+
204207
[Back to guide index](../../README.md#guides)

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ 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';
109

1110
import {Metafield} from './metafield';
1211

@@ -52,7 +51,7 @@ interface SearchArgs {
5251
query?: unknown;
5352
limit?: unknown;
5453
fields?: unknown;
55-
returnObject?: boolean;
54+
returnFullResponse?: boolean;
5655
}
5756
interface AccountActivationUrlArgs {
5857
[key: string]: unknown;
@@ -195,17 +194,10 @@ export class Customer extends Base {
195194
query = null,
196195
limit = null,
197196
fields = null,
198-
returnObject = false,
197+
returnFullResponse = false,
199198
...otherArgs
200199
}: SearchArgs,
201200
): 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-
209201
const response = await this.request<Customer>({
210202
http_method: "get",
211203
operation: "search",
@@ -216,7 +208,7 @@ export class Customer extends Base {
216208
entity: null,
217209
});
218210

219-
return returnObject ? response : response?.body;
211+
return returnFullResponse ? response : response?.body;
220212
}
221213

222214
public async account_activation_url(

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ 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';
109

1110
interface FindArgs {
1211
session: Session;
@@ -36,7 +35,7 @@ interface SearchArgs {
3635
created_at_max?: unknown;
3736
updated_at_min?: unknown;
3837
updated_at_max?: unknown;
39-
returnObject?: boolean;
38+
returnFullResponse?: boolean;
4039
}
4140
interface DisableArgs {
4241
[key: string]: unknown;
@@ -128,17 +127,10 @@ export class GiftCard extends Base {
128127
created_at_max = null,
129128
updated_at_min = null,
130129
updated_at_max = null,
131-
returnObject = false,
130+
returnFullResponse = false,
132131
...otherArgs
133132
}: SearchArgs
134133
): 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-
142134
const response = await this.request<GiftCard>({
143135
http_method: "get",
144136
operation: "search",
@@ -149,7 +141,7 @@ export class GiftCard extends Base {
149141
entity: null,
150142
});
151143

152-
return returnObject ? response : response?.body;
144+
return returnFullResponse ? response : response?.body;
153145
}
154146

155147
public async disable(

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ 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';
109

1110
import {Metafield} from './metafield';
1211

@@ -52,7 +51,7 @@ interface SearchArgs {
5251
query?: unknown;
5352
limit?: unknown;
5453
fields?: unknown;
55-
returnObject?: boolean;
54+
returnFullResponse?: boolean;
5655
}
5756
interface AccountActivationUrlArgs {
5857
[key: string]: unknown;
@@ -195,17 +194,10 @@ export class Customer extends Base {
195194
query = null,
196195
limit = null,
197196
fields = null,
198-
returnObject = false,
197+
returnFullResponse = false,
199198
...otherArgs
200199
}: SearchArgs
201200
): 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-
209201
const response = await this.request<Customer>({
210202
http_method: "get",
211203
operation: "search",
@@ -216,7 +208,7 @@ export class Customer extends Base {
216208
entity: null,
217209
});
218210

219-
return returnObject ? response : response?.body;
211+
return returnFullResponse ? response : response?.body;
220212
}
221213

222214
public async account_activation_url(

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ 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';
109

1110
interface FindArgs {
1211
session: Session;
@@ -36,7 +35,7 @@ interface SearchArgs {
3635
created_at_max?: unknown;
3736
updated_at_min?: unknown;
3837
updated_at_max?: unknown;
39-
returnObject?: boolean;
38+
returnFullResponse?: boolean;
4039
}
4140
interface DisableArgs {
4241
[key: string]: unknown;
@@ -128,17 +127,10 @@ export class GiftCard extends Base {
128127
created_at_max = null,
129128
updated_at_min = null,
130129
updated_at_max = null,
131-
returnObject = false,
130+
returnFullResponse = false,
132131
...otherArgs
133132
}: SearchArgs
134133
): 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-
142134
const response = await this.request<GiftCard>({
143135
http_method: "get",
144136
operation: "search",
@@ -149,7 +141,7 @@ export class GiftCard extends Base {
149141
entity: null,
150142
});
151143

152-
return returnObject ? response : response?.body;
144+
return returnFullResponse ? response : response?.body;
153145
}
154146

155147
public async disable(

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ 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';
109

1110
import {Metafield} from './metafield';
1211

@@ -52,7 +51,7 @@ interface SearchArgs {
5251
query?: unknown;
5352
limit?: unknown;
5453
fields?: unknown;
55-
returnObject?: boolean;
54+
returnFullResponse?: boolean;
5655
}
5756
interface AccountActivationUrlArgs {
5857
[key: string]: unknown;
@@ -195,17 +194,10 @@ export class Customer extends Base {
195194
query = null,
196195
limit = null,
197196
fields = null,
198-
returnObject = false,
197+
returnFullResponse = false,
199198
...otherArgs
200199
}: SearchArgs
201200
): 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-
209201
const response = await this.request<Customer>({
210202
http_method: "get",
211203
operation: "search",
@@ -216,7 +208,7 @@ export class Customer extends Base {
216208
entity: null,
217209
});
218210

219-
return returnObject ? response : response?.body;
211+
return returnFullResponse ? response : response?.body;
220212
}
221213

222214
public async account_activation_url(

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ 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';
109

1110
interface FindArgs {
1211
session: Session;
@@ -36,7 +35,7 @@ interface SearchArgs {
3635
created_at_max?: unknown;
3736
updated_at_min?: unknown;
3837
updated_at_max?: unknown;
39-
returnObject?: boolean;
38+
returnFullResponse?: boolean;
4039
}
4140
interface DisableArgs {
4241
[key: string]: unknown;
@@ -128,17 +127,10 @@ export class GiftCard extends Base {
128127
created_at_max = null,
129128
updated_at_min = null,
130129
updated_at_max = null,
131-
returnObject = false,
130+
returnFullResponse = false,
132131
...otherArgs
133132
}: SearchArgs
134133
): 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-
142134
const response = await this.request<GiftCard>({
143135
http_method: "get",
144136
operation: "search",
@@ -149,7 +141,7 @@ export class GiftCard extends Base {
149141
entity: null,
150142
});
151143

152-
return returnObject ? response : response?.body;
144+
return returnFullResponse ? response : response?.body;
153145
}
154146

155147
public async disable(

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ 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';
109

1110
import {Metafield} from './metafield';
1211

@@ -52,7 +51,7 @@ interface SearchArgs {
5251
query?: unknown;
5352
limit?: unknown;
5453
fields?: unknown;
55-
returnObject?: boolean;
54+
returnFullResponse?: boolean;
5655
}
5756
interface AccountActivationUrlArgs {
5857
[key: string]: unknown;
@@ -195,17 +194,10 @@ export class Customer extends Base {
195194
query = null,
196195
limit = null,
197196
fields = null,
198-
returnObject = false,
197+
returnFullResponse = false,
199198
...otherArgs
200199
}: SearchArgs
201200
): 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-
209201
const response = await this.request<Customer>({
210202
http_method: "get",
211203
operation: "search",
@@ -216,7 +208,7 @@ export class Customer extends Base {
216208
entity: null,
217209
});
218210

219-
return returnObject ? response : response?.body;
211+
return returnFullResponse ? response : response?.body;
220212
}
221213

222214
public async account_activation_url(

0 commit comments

Comments
 (0)