Skip to content

Commit 8d1ec4b

Browse files
authored
Allow override of "user-agent" header and fix "pg" options in /hooks and /connections (#4)
1 parent 0b1691f commit 8d1ec4b

File tree

6 files changed

+41
-14
lines changed

6 files changed

+41
-14
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@makehq/sdk",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"description": "Make TypeScript SDK",
55
"license": "MIT",
66
"author": "Make",

src/endpoints/connections.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { FetchFunction, JSONValue, Pagination, PickColumns } from '../types.js';
1+
import type { FetchFunction, JSONValue, PickColumns } from '../types.js';
22

33
/**
44
* Represents a connection in Make.
@@ -67,8 +67,6 @@ export type ListConnectionsOptions<C extends keyof Connection = never> = {
6767
type?: string[];
6868
/** Team ID to filter connections by (can override the main parameter) */
6969
teamId?: number;
70-
/** Pagination options */
71-
pg?: Partial<Pagination<Connection>>;
7270
};
7371

7472
/**
@@ -214,7 +212,6 @@ export class Connections {
214212
teamId,
215213
type: options?.type,
216214
cols: options?.cols,
217-
pg: options?.pg,
218215
},
219216
})
220217
).connections;

src/endpoints/hooks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export class Hooks {
165165
typeName: options?.typeName,
166166
assigned: options?.assigned,
167167
viewForScenarioId: options?.viewForScenarioId,
168+
pg: options?.pg,
168169
},
169170
})
170171
).hooks;

src/make.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ export class Make {
2929
*/
3030
public readonly zone: string;
3131

32+
/**
33+
* Request Headers
34+
* Can be used to set custom headers for all requests
35+
*/
36+
private readonly headers: Record<string, string>;
37+
3238
/**
3339
* The API version to use
3440
* Default is version 2 of the Make API
@@ -129,12 +135,15 @@ export class Make {
129135
* Create a new Make SDK instance
130136
* @param token Your Make API key or OAuth2 access token
131137
* @param zone The Make zone (e.g. eu1.make.com)
132-
* @param version API version to use (defaults to 2)
138+
* @param options Optional configuration
139+
* @param options.version API version to use (defaults to 2)
140+
* @param options.headers Custom headers to include in all requests
133141
*/
134-
constructor(token: string, zone: string, version = 2) {
142+
constructor(token: string, zone: string, options: { version?: number, headers?: Record<string, string> } = {}) {
135143
this.#token = token;
136144
this.zone = zone;
137-
this.version = version;
145+
this.version = options.version ?? 2;
146+
this.headers = options.headers ?? {};
138147
this.protocol = 'https';
139148

140149
this.users = new Users(this.fetch.bind(this));
@@ -167,12 +176,14 @@ export class Make {
167176
* @internal
168177
*/
169178
public async fetch<T = unknown>(url: string, options?: FetchOptions): Promise<T> {
170-
options = Object.assign({}, options, {
171-
headers: Object.assign({}, options?.headers, {
179+
options = {
180+
...options,
181+
headers: {
172182
'user-agent': `MakeTypeScriptSDK/${VERSION}`,
183+
...this.headers,
173184
authorization: `${isAPIKey(this.#token) ? 'Token' : 'Bearer'} ${this.#token}`,
174-
}),
175-
});
185+
},
186+
};
176187

177188
if (url.charAt(0) === '/') {
178189
if (url.charAt(1) === '/') {

test/make.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,22 @@ describe('Make SDK', () => {
3232

3333
await expect(make.users.me()).rejects.toThrow('Bad Request');
3434
});
35+
36+
it('Should allow overriding user-agent header', async () => {
37+
const makeWithCustomHeaders = new Make(MAKE_API_KEY, MAKE_ZONE, { headers: { 'user-agent': 'CustomUserAgent' } });
38+
mockFetch('GET https://make.local/api/v2/users/me', { authUser: null }, req => {
39+
expect(req.headers.get('user-agent')).toBe('CustomUserAgent');
40+
});
41+
42+
expect(await makeWithCustomHeaders.users.me()).toBe(null);
43+
});
44+
45+
it('Should allow passing custom headers to all requests', async () => {
46+
const makeWithCustomHeaders = new Make(MAKE_API_KEY, MAKE_ZONE, { headers: { 'x-custom-header': 'FooBar' } });
47+
mockFetch('GET https://make.local/api/v2/users/me', { authUser: null }, req => {
48+
expect(req.headers.get('x-custom-header')).toBe('FooBar');
49+
});
50+
51+
expect(await makeWithCustomHeaders.users.me()).toBe(null);
52+
});
3553
});

0 commit comments

Comments
 (0)