Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add agent options #643

Merged
merged 12 commits into from
Jan 13, 2024
Merged
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Youkehai marked this conversation as resolved.
Show resolved Hide resolved
};

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
Youkehai marked this conversation as resolved.
Show resolved Hide resolved
};

Expand Down
4 changes: 3 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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