Skip to content

Commit

Permalink
[api] Introduce the agent option (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
Youkehai committed Jan 13, 2024
1 parent a75493b commit 4f02cc9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -78,6 +78,10 @@ Creates a new `Shopify` instance.
attach to all outgoing requests, like `beforeRetry`, `afterResponse`, etc.
Hooks should be provided in the same format that Got expects them and will
receive the same arguments Got passes unchanged.
- `agent` - Optional - An object that is passed as the `agent` option to `got`.
This allows to use a proxy server. See
[Got documentation](https://github.com/sindresorhus/got/tree/v11.8.6?tab=readme-ov-file#proxies)
for more details.

#### Return value

Expand Down
2 changes: 2 additions & 0 deletions index.js
Expand Up @@ -154,6 +154,7 @@ Shopify.prototype.request = function request(uri, method, key, data, headers) {
parseJson: this.options.parseJson,
timeout: this.options.timeout,
responseType: 'json',
agent: this.options.agent,
method
};

Expand Down Expand Up @@ -282,6 +283,7 @@ Shopify.prototype.graphql = function graphql(data, variables) {
timeout: this.options.timeout,
responseType: 'json',
method: 'POST',
agent: this.options.agent,
body: json ? this.options.stringifyJson({ query: data, variables }) : data
};

Expand Down
4 changes: 3 additions & 1 deletion types/index.d.ts
@@ -1,7 +1,7 @@
// Type definitions for shopify-api-node
// Project: shopify-api-node
// Definitions by: Rich Buggy <rich@buggy.id.au>
import { Hooks } from 'got';
import { Hooks, Agents } from 'got';

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

export interface IPrivateShopifyConfig {
Expand All @@ -801,6 +802,7 @@ declare namespace Shopify {
shopName: string;
timeout?: number;
hooks?: Hooks;
agent?: Agents;
}

export interface ICallLimits {
Expand Down
16 changes: 16 additions & 0 deletions types/index.test-d.ts
Expand Up @@ -27,6 +27,22 @@ new Shopify({
}
});

// Accepts the `agent` option.
new Shopify({
shopName: 'my-shopify-store.myshopify.com',
accessToken: '111',
agent: {
// https: new HttpsProxyAgent({
// keepAlive: true,
// keepAliveMsecs: 1000,
// maxSockets: 256,
// maxFreeSockets: 256,
// scheduling: 'lifo',
// proxy: 'https://localhost:8080'
// })
}
});

expectType<number>(client.callLimits.remaining);
expectType<number>(client.callLimits.current);
expectType<number>(client.callLimits.max);
Expand Down

0 comments on commit 4f02cc9

Please sign in to comment.