Skip to content

Commit 4f02cc9

Browse files
authored
[api] Introduce the agent option (#643)
1 parent a75493b commit 4f02cc9

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ Creates a new `Shopify` instance.
7878
attach to all outgoing requests, like `beforeRetry`, `afterResponse`, etc.
7979
Hooks should be provided in the same format that Got expects them and will
8080
receive the same arguments Got passes unchanged.
81+
- `agent` - Optional - An object that is passed as the `agent` option to `got`.
82+
This allows to use a proxy server. See
83+
[Got documentation](https://github.com/sindresorhus/got/tree/v11.8.6?tab=readme-ov-file#proxies)
84+
for more details.
8185

8286
#### Return value
8387

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ Shopify.prototype.request = function request(uri, method, key, data, headers) {
154154
parseJson: this.options.parseJson,
155155
timeout: this.options.timeout,
156156
responseType: 'json',
157+
agent: this.options.agent,
157158
method
158159
};
159160

@@ -282,6 +283,7 @@ Shopify.prototype.graphql = function graphql(data, variables) {
282283
timeout: this.options.timeout,
283284
responseType: 'json',
284285
method: 'POST',
286+
agent: this.options.agent,
285287
body: json ? this.options.stringifyJson({ query: data, variables }) : data
286288
};
287289

types/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Type definitions for shopify-api-node
22
// Project: shopify-api-node
33
// Definitions by: Rich Buggy <rich@buggy.id.au>
4-
import { Hooks } from 'got';
4+
import { Hooks, Agents } from 'got';
55

66
/*~ This is the module template file for class modules.
77
*~ You should rename it to index.d.ts and place it in a folder with the same name as the module.
@@ -789,6 +789,7 @@ declare namespace Shopify {
789789
shopName: string;
790790
timeout?: number;
791791
hooks?: Hooks;
792+
agent?: Agents;
792793
}
793794

794795
export interface IPrivateShopifyConfig {
@@ -801,6 +802,7 @@ declare namespace Shopify {
801802
shopName: string;
802803
timeout?: number;
803804
hooks?: Hooks;
805+
agent?: Agents;
804806
}
805807

806808
export interface ICallLimits {

types/index.test-d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ new Shopify({
2727
}
2828
});
2929

30+
// Accepts the `agent` option.
31+
new Shopify({
32+
shopName: 'my-shopify-store.myshopify.com',
33+
accessToken: '111',
34+
agent: {
35+
// https: new HttpsProxyAgent({
36+
// keepAlive: true,
37+
// keepAliveMsecs: 1000,
38+
// maxSockets: 256,
39+
// maxFreeSockets: 256,
40+
// scheduling: 'lifo',
41+
// proxy: 'https://localhost:8080'
42+
// })
43+
}
44+
});
45+
3046
expectType<number>(client.callLimits.remaining);
3147
expectType<number>(client.callLimits.current);
3248
expectType<number>(client.callLimits.max);

0 commit comments

Comments
 (0)