@tryfinch/finch-api 5.22.4 → 5.22.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.22.6 (2024-05-02)
4
+
5
+ Full Changelog: [v5.22.5...v5.22.6](https://github.com/Finch-API/finch-api-node/compare/v5.22.5...v5.22.6)
6
+
7
+ ### Chores
8
+
9
+ * **internal:** move client class to separate file ([#357](https://github.com/Finch-API/finch-api-node/issues/357)) ([a8ea8e2](https://github.com/Finch-API/finch-api-node/commit/a8ea8e2891c40ea9c19b2ccca32024dd93612a8a))
10
+
11
+ ## 5.22.5 (2024-05-01)
12
+
13
+ Full Changelog: [v5.22.4...v5.22.5](https://github.com/Finch-API/finch-api-node/compare/v5.22.4...v5.22.5)
14
+
15
+ ### Chores
16
+
17
+ * **internal:** forward arguments in scripts/test ([#355](https://github.com/Finch-API/finch-api-node/issues/355)) ([b17aadc](https://github.com/Finch-API/finch-api-node/commit/b17aadc62f2803b97da79f1a67fd701255e74050))
18
+
3
19
  ## 5.22.4 (2024-04-30)
4
20
 
5
21
  Full Changelog: [v5.22.3...v5.22.4](https://github.com/Finch-API/finch-api-node/compare/v5.22.3...v5.22.4)
package/client.d.ts ADDED
@@ -0,0 +1,204 @@
1
+ import * as Core from "./core.js";
2
+ import * as Errors from "./error.js";
3
+ import { type Agent } from "./_shims/index.js";
4
+ import * as Uploads from "./uploads.js";
5
+ import * as Pagination from '@tryfinch/finch-api/pagination';
6
+ import * as API from '@tryfinch/finch-api/resources/index';
7
+ export interface ClientOptions {
8
+ accessToken?: string | null | undefined;
9
+ /**
10
+ * Defaults to process.env['FINCH_CLIENT_ID'].
11
+ */
12
+ clientId?: string | null | undefined;
13
+ /**
14
+ * Defaults to process.env['FINCH_CLIENT_SECRET'].
15
+ */
16
+ clientSecret?: string | null | undefined;
17
+ /**
18
+ * Defaults to process.env['FINCH_SANDBOX_CLIENT_ID'].
19
+ */
20
+ sandboxClientId?: string | null | undefined;
21
+ /**
22
+ * Defaults to process.env['FINCH_SANDBOX_CLIENT_SECRET'].
23
+ */
24
+ sandboxClientSecret?: string | null | undefined;
25
+ /**
26
+ * Defaults to process.env['FINCH_WEBHOOK_SECRET'].
27
+ */
28
+ webhookSecret?: string | null | undefined;
29
+ /**
30
+ * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
31
+ *
32
+ * Defaults to process.env['FINCH_BASE_URL'].
33
+ */
34
+ baseURL?: string | null | undefined;
35
+ /**
36
+ * The maximum amount of time (in milliseconds) that the client should wait for a response
37
+ * from the server before timing out a single request.
38
+ *
39
+ * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
40
+ * much longer than this timeout before the promise succeeds or fails.
41
+ */
42
+ timeout?: number;
43
+ /**
44
+ * An HTTP agent used to manage HTTP(S) connections.
45
+ *
46
+ * If not provided, an agent will be constructed by default in the Node.js environment,
47
+ * otherwise no agent is used.
48
+ */
49
+ httpAgent?: Agent;
50
+ /**
51
+ * Specify a custom `fetch` function implementation.
52
+ *
53
+ * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
54
+ * defined globally.
55
+ */
56
+ fetch?: Core.Fetch | undefined;
57
+ /**
58
+ * The maximum number of times that the client will retry a request in case of a
59
+ * temporary failure, like a network error or a 5XX error from the server.
60
+ *
61
+ * @default 2
62
+ */
63
+ maxRetries?: number;
64
+ /**
65
+ * Default headers to include with every request to the API.
66
+ *
67
+ * These can be removed in individual requests by explicitly setting the
68
+ * header to `undefined` or `null` in request options.
69
+ */
70
+ defaultHeaders?: Core.Headers;
71
+ /**
72
+ * Default query parameters to include with every request to the API.
73
+ *
74
+ * These can be removed in individual requests by explicitly setting the
75
+ * param to `undefined` in request options.
76
+ */
77
+ defaultQuery?: Core.DefaultQuery;
78
+ }
79
+ /** API Client for interfacing with the Finch API. */
80
+ export declare class Finch extends Core.APIClient {
81
+ accessToken: string | null;
82
+ clientId: string | null;
83
+ clientSecret: string | null;
84
+ sandboxClientId: string | null;
85
+ sandboxClientSecret: string | null;
86
+ webhookSecret: string | null;
87
+ private _options;
88
+ /**
89
+ * API Client for interfacing with the Finch API.
90
+ *
91
+ * @param {string | null | undefined} [opts.accessToken]
92
+ * @param {string | null | undefined} [opts.clientId=process.env['FINCH_CLIENT_ID'] ?? null]
93
+ * @param {string | null | undefined} [opts.clientSecret=process.env['FINCH_CLIENT_SECRET'] ?? null]
94
+ * @param {string | null | undefined} [opts.sandboxClientId=process.env['FINCH_SANDBOX_CLIENT_ID'] ?? null]
95
+ * @param {string | null | undefined} [opts.sandboxClientSecret=process.env['FINCH_SANDBOX_CLIENT_SECRET'] ?? null]
96
+ * @param {string | null | undefined} [opts.webhookSecret=process.env['FINCH_WEBHOOK_SECRET'] ?? null]
97
+ * @param {string} [opts.baseURL=process.env['FINCH_BASE_URL'] ?? https://api.tryfinch.com] - Override the default base URL for the API.
98
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
99
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
100
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
101
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
102
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
103
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
104
+ */
105
+ constructor({ baseURL, accessToken, clientId, clientSecret, sandboxClientId, sandboxClientSecret, webhookSecret, ...opts }?: ClientOptions);
106
+ accessTokens: API.AccessTokens;
107
+ hris: API.HRIS;
108
+ providers: API.Providers;
109
+ account: API.Account;
110
+ webhooks: API.Webhooks;
111
+ requestForwarding: API.RequestForwarding;
112
+ jobs: API.Jobs;
113
+ sandbox: API.Sandbox;
114
+ /**
115
+ * DEPRECATED: use client.accessTokens.create instead.
116
+ */
117
+ getAccessToken(code: string, options?: {
118
+ redirectUri: string;
119
+ }): Promise<string>;
120
+ /**
121
+ * Returns the authorization url which can be visited in order to obtain an
122
+ * authorization code from Finch. The authorization code can then be exchanged for
123
+ * an access token for the Finch api by calling get_access_token().
124
+ */
125
+ getAuthURL({ products, redirectUri, sandbox, }: {
126
+ products: string;
127
+ redirectUri: string;
128
+ sandbox: boolean;
129
+ }): string;
130
+ /**
131
+ * Returns a copy of the current Finch client with the given access token for
132
+ * authentication.
133
+ */
134
+ withAccessToken(accessToken: string): Finch;
135
+ protected defaultQuery(): Core.DefaultQuery | undefined;
136
+ protected defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers;
137
+ protected validateHeaders(headers: Core.Headers, customHeaders: Core.Headers): void;
138
+ protected authHeaders(opts: Core.FinalRequestOptions): Core.Headers;
139
+ protected bearerAuth(opts: Core.FinalRequestOptions): Core.Headers;
140
+ protected basicAuth(opts: Core.FinalRequestOptions): Core.Headers;
141
+ static Finch: typeof Finch;
142
+ static FinchError: typeof Errors.FinchError;
143
+ static APIError: typeof Errors.APIError;
144
+ static APIConnectionError: typeof Errors.APIConnectionError;
145
+ static APIConnectionTimeoutError: typeof Errors.APIConnectionTimeoutError;
146
+ static APIUserAbortError: typeof Errors.APIUserAbortError;
147
+ static NotFoundError: typeof Errors.NotFoundError;
148
+ static ConflictError: typeof Errors.ConflictError;
149
+ static RateLimitError: typeof Errors.RateLimitError;
150
+ static BadRequestError: typeof Errors.BadRequestError;
151
+ static AuthenticationError: typeof Errors.AuthenticationError;
152
+ static InternalServerError: typeof Errors.InternalServerError;
153
+ static PermissionDeniedError: typeof Errors.PermissionDeniedError;
154
+ static UnprocessableEntityError: typeof Errors.UnprocessableEntityError;
155
+ static toFile: typeof Uploads.toFile;
156
+ static fileFromPath: typeof Uploads.fileFromPath;
157
+ }
158
+ export declare namespace Finch {
159
+ export import RequestOptions = Core.RequestOptions;
160
+ export import SinglePage = Pagination.SinglePage;
161
+ export import SinglePageResponse = Pagination.SinglePageResponse;
162
+ export import ResponsesPage = Pagination.ResponsesPage;
163
+ export import ResponsesPageResponse = Pagination.ResponsesPageResponse;
164
+ export import IndividualsPage = Pagination.IndividualsPage;
165
+ export import IndividualsPageParams = Pagination.IndividualsPageParams;
166
+ export import IndividualsPageResponse = Pagination.IndividualsPageResponse;
167
+ export import Page = Pagination.Page;
168
+ export import PageParams = Pagination.PageParams;
169
+ export import PageResponse = Pagination.PageResponse;
170
+ export import AccessTokens = API.AccessTokens;
171
+ export import CreateAccessTokenResponse = API.CreateAccessTokenResponse;
172
+ export import AccessTokenCreateParams = API.AccessTokenCreateParams;
173
+ export import HRIS = API.HRIS;
174
+ export import Income = API.Income;
175
+ export import Location = API.Location;
176
+ export import Money = API.Money;
177
+ export import Providers = API.Providers;
178
+ export import Provider = API.Provider;
179
+ export import ProvidersSinglePage = API.ProvidersSinglePage;
180
+ export import Account = API.Account;
181
+ export import DisconnectResponse = API.DisconnectResponse;
182
+ export import Introspection = API.Introspection;
183
+ export import Webhooks = API.Webhooks;
184
+ export import AccountUpdateEvent = API.AccountUpdateEvent;
185
+ export import BaseWebhookEvent = API.BaseWebhookEvent;
186
+ export import CompanyEvent = API.CompanyEvent;
187
+ export import DirectoryEvent = API.DirectoryEvent;
188
+ export import EmploymentEvent = API.EmploymentEvent;
189
+ export import IndividualEvent = API.IndividualEvent;
190
+ export import JobCompletionEvent = API.JobCompletionEvent;
191
+ export import PayStatementEvent = API.PayStatementEvent;
192
+ export import PaymentEvent = API.PaymentEvent;
193
+ export import WebhookEvent = API.WebhookEvent;
194
+ export import RequestForwarding = API.RequestForwarding;
195
+ export import RequestForwardingForwardResponse = API.RequestForwardingForwardResponse;
196
+ export import RequestForwardingForwardParams = API.RequestForwardingForwardParams;
197
+ export import Jobs = API.Jobs;
198
+ export import Sandbox = API.Sandbox;
199
+ export import ConnectionStatusType = API.ConnectionStatusType;
200
+ export import OperationSupport = API.OperationSupport;
201
+ export import OperationSupportMatrix = API.OperationSupportMatrix;
202
+ export import Paging = API.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CAAC;CACnC"}
package/client.js ADDED
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var _a;
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.Finch = void 0;
29
+ const Core = __importStar(require("./core.js"));
30
+ const Errors = __importStar(require("./error.js"));
31
+ const Uploads = __importStar(require("./uploads.js"));
32
+ const Pagination = __importStar(require("@tryfinch/finch-api/pagination"));
33
+ const API = __importStar(require("@tryfinch/finch-api/resources/index"));
34
+ /** API Client for interfacing with the Finch API. */
35
+ class Finch extends Core.APIClient {
36
+ /**
37
+ * API Client for interfacing with the Finch API.
38
+ *
39
+ * @param {string | null | undefined} [opts.accessToken]
40
+ * @param {string | null | undefined} [opts.clientId=process.env['FINCH_CLIENT_ID'] ?? null]
41
+ * @param {string | null | undefined} [opts.clientSecret=process.env['FINCH_CLIENT_SECRET'] ?? null]
42
+ * @param {string | null | undefined} [opts.sandboxClientId=process.env['FINCH_SANDBOX_CLIENT_ID'] ?? null]
43
+ * @param {string | null | undefined} [opts.sandboxClientSecret=process.env['FINCH_SANDBOX_CLIENT_SECRET'] ?? null]
44
+ * @param {string | null | undefined} [opts.webhookSecret=process.env['FINCH_WEBHOOK_SECRET'] ?? null]
45
+ * @param {string} [opts.baseURL=process.env['FINCH_BASE_URL'] ?? https://api.tryfinch.com] - Override the default base URL for the API.
46
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
47
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
48
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
49
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
50
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
51
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
52
+ */
53
+ constructor({ baseURL = Core.readEnv('FINCH_BASE_URL'), accessToken = null, clientId = Core.readEnv('FINCH_CLIENT_ID') ?? null, clientSecret = Core.readEnv('FINCH_CLIENT_SECRET') ?? null, sandboxClientId = Core.readEnv('FINCH_SANDBOX_CLIENT_ID') ?? null, sandboxClientSecret = Core.readEnv('FINCH_SANDBOX_CLIENT_SECRET') ?? null, webhookSecret = Core.readEnv('FINCH_WEBHOOK_SECRET') ?? null, ...opts } = {}) {
54
+ const options = {
55
+ accessToken,
56
+ clientId,
57
+ clientSecret,
58
+ sandboxClientId,
59
+ sandboxClientSecret,
60
+ webhookSecret,
61
+ ...opts,
62
+ baseURL: baseURL || `https://api.tryfinch.com`,
63
+ };
64
+ super({
65
+ baseURL: options.baseURL,
66
+ timeout: options.timeout ?? 60000 /* 1 minute */,
67
+ httpAgent: options.httpAgent,
68
+ maxRetries: options.maxRetries,
69
+ fetch: options.fetch,
70
+ });
71
+ this.accessTokens = new API.AccessTokens(this);
72
+ this.hris = new API.HRIS(this);
73
+ this.providers = new API.Providers(this);
74
+ this.account = new API.Account(this);
75
+ this.webhooks = new API.Webhooks(this);
76
+ this.requestForwarding = new API.RequestForwarding(this);
77
+ this.jobs = new API.Jobs(this);
78
+ this.sandbox = new API.Sandbox(this);
79
+ this._options = options;
80
+ this.accessToken = accessToken;
81
+ this.clientId = clientId;
82
+ this.clientSecret = clientSecret;
83
+ this.sandboxClientId = sandboxClientId;
84
+ this.sandboxClientSecret = sandboxClientSecret;
85
+ this.webhookSecret = webhookSecret;
86
+ }
87
+ /**
88
+ * DEPRECATED: use client.accessTokens.create instead.
89
+ */
90
+ getAccessToken(code, options) {
91
+ if (!this.clientId) {
92
+ throw new Error('Expected the clientId to be set in order to call getAccessToken');
93
+ }
94
+ if (!this.clientSecret) {
95
+ throw new Error('Expected the clientSecret to be set in order to call getAccessToken');
96
+ }
97
+ return this.post('/auth/token', {
98
+ body: {
99
+ client_id: this.clientId,
100
+ client_secret: this.clientSecret,
101
+ code: code,
102
+ redirect_uri: options?.redirectUri,
103
+ },
104
+ headers: {
105
+ authorization: null,
106
+ },
107
+ }).then((response) => response.access_token);
108
+ }
109
+ /**
110
+ * Returns the authorization url which can be visited in order to obtain an
111
+ * authorization code from Finch. The authorization code can then be exchanged for
112
+ * an access token for the Finch api by calling get_access_token().
113
+ */
114
+ getAuthURL({ products, redirectUri, sandbox, }) {
115
+ if (!this.clientId) {
116
+ throw new Error('Expected the clientId to be set in order to call getAuthUrl');
117
+ }
118
+ const url = new URL('/authorize', 'https://connect.tryfinch.com/authorize');
119
+ url.search = this.stringifyQuery({
120
+ client_id: this.clientId,
121
+ products: products,
122
+ redirect_uri: redirectUri,
123
+ sandbox: sandbox,
124
+ });
125
+ return url.toString();
126
+ }
127
+ /**
128
+ * Returns a copy of the current Finch client with the given access token for
129
+ * authentication.
130
+ */
131
+ withAccessToken(accessToken) {
132
+ return new Finch({ ...this._options, accessToken });
133
+ }
134
+ defaultQuery() {
135
+ return this._options.defaultQuery;
136
+ }
137
+ defaultHeaders(opts) {
138
+ return {
139
+ ...super.defaultHeaders(opts),
140
+ 'Finch-API-Version': '2020-09-17',
141
+ ...this._options.defaultHeaders,
142
+ };
143
+ }
144
+ validateHeaders(headers, customHeaders) {
145
+ if (this.accessToken && headers['authorization']) {
146
+ return;
147
+ }
148
+ if (customHeaders['authorization'] === null) {
149
+ return;
150
+ }
151
+ if (this.sandboxClientId && this.sandboxClientSecret && headers['authorization']) {
152
+ return;
153
+ }
154
+ if (customHeaders['authorization'] === null) {
155
+ return;
156
+ }
157
+ throw new Error('Could not resolve authentication method. Expected either accessToken, sandboxClientId or sandboxClientSecret to be set. Or for one of the "Authorization" or "Authorization" headers to be explicitly omitted');
158
+ }
159
+ authHeaders(opts) {
160
+ const bearerAuth = this.bearerAuth(opts);
161
+ const basicAuth = this.basicAuth(opts);
162
+ if (bearerAuth != null && !Core.isEmptyObj(bearerAuth)) {
163
+ return bearerAuth;
164
+ }
165
+ return {};
166
+ }
167
+ bearerAuth(opts) {
168
+ if (this.accessToken == null) {
169
+ return {};
170
+ }
171
+ return { Authorization: `Bearer ${this.accessToken}` };
172
+ }
173
+ basicAuth(opts) {
174
+ if (!this.sandboxClientId) {
175
+ return {};
176
+ }
177
+ if (!this.sandboxClientSecret) {
178
+ return {};
179
+ }
180
+ const credentials = `${this.sandboxClientId}:${this.sandboxClientSecret}`;
181
+ const Authorization = `Basic ${Core.toBase64(credentials)}`;
182
+ return { Authorization };
183
+ }
184
+ }
185
+ exports.Finch = Finch;
186
+ _a = Finch;
187
+ Finch.Finch = _a;
188
+ Finch.FinchError = Errors.FinchError;
189
+ Finch.APIError = Errors.APIError;
190
+ Finch.APIConnectionError = Errors.APIConnectionError;
191
+ Finch.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
192
+ Finch.APIUserAbortError = Errors.APIUserAbortError;
193
+ Finch.NotFoundError = Errors.NotFoundError;
194
+ Finch.ConflictError = Errors.ConflictError;
195
+ Finch.RateLimitError = Errors.RateLimitError;
196
+ Finch.BadRequestError = Errors.BadRequestError;
197
+ Finch.AuthenticationError = Errors.AuthenticationError;
198
+ Finch.InternalServerError = Errors.InternalServerError;
199
+ Finch.PermissionDeniedError = Errors.PermissionDeniedError;
200
+ Finch.UnprocessableEntityError = Errors.UnprocessableEntityError;
201
+ Finch.toFile = Uploads.toFile;
202
+ Finch.fileFromPath = Uploads.fileFromPath;
203
+ (function (Finch) {
204
+ Finch.SinglePage = Pagination.SinglePage;
205
+ Finch.ResponsesPage = Pagination.ResponsesPage;
206
+ Finch.IndividualsPage = Pagination.IndividualsPage;
207
+ Finch.Page = Pagination.Page;
208
+ Finch.AccessTokens = API.AccessTokens;
209
+ Finch.HRIS = API.HRIS;
210
+ Finch.Providers = API.Providers;
211
+ Finch.ProvidersSinglePage = API.ProvidersSinglePage;
212
+ Finch.Account = API.Account;
213
+ Finch.Webhooks = API.Webhooks;
214
+ Finch.RequestForwarding = API.RequestForwarding;
215
+ Finch.Jobs = API.Jobs;
216
+ Finch.Sandbox = API.Sandbox;
217
+ })(Finch = exports.Finch || (exports.Finch = {}));
218
+ //# sourceMappingURL=client.js.map
package/client.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEtF,gDAA+B;AAC/B,mDAAkC;AAElC,sDAAqC;AACrC,2EAA6D;AAC7D,yEAA2D;AAuF3D,qDAAqD;AACrD,MAAa,KAAM,SAAQ,IAAI,CAAC,SAAS;IAUvC;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,EACV,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,EACxC,WAAW,GAAG,IAAI,EAClB,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,IAAI,EAClD,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,IAAI,IAAI,E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8BAAwB,GAAG,MAAM,CAAC,wBAAwB,CAAC;AAE3D,YAAM,GAAG,OAAO,CAAC,MAAM,CAAC;AACxB,kBAAY,GAAG,OAAO,CAAC,YAAY,CAAC;AAG7C,WAAiB,KAAK;IAGN,gBAAU,GAAG,UAAU,CAAC,UAAU,CAAC;IAGnC,mBAAa,GAAG,UAAU,CAAC,aAAa,CAAC;IAGzC,qBAAe,GAAG,UAAU,CAAC,eAAe,CAAC;IAI7C,UAAI,GAAG,UAAU,CAAC,IAAI,CAAC;IAIvB,kBAAY,GAAG,GAAG,CAAC,YAAY,CAAC;IAIhC,UAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IAKhB,eAAS,GAAG,GAAG,CAAC,SAAS,CAAC;IAE1B,yBAAmB,GAAG,GAAG,CAAC,mBAAmB,CAAC;IAE9C,aAAO,GAAG,GAAG,CAAC,OAAO,CAAC;IAItB,cAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;IAYxB,uBAAiB,GAAG,GAAG,CAAC,iBAAiB,CAAC;IAI1C,UAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IAEhB,aAAO,GAAG,GAAG,CAAC,OAAO,CAAC;AAMtC,CAAC,EA1DgB,KAAK,GAAL,aAAK,KAAL,aAAK,QA0DrB"}
package/client.mjs ADDED
@@ -0,0 +1,191 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+ var _a;
3
+ import * as Core from "./core.mjs";
4
+ import * as Errors from "./error.mjs";
5
+ import * as Uploads from "./uploads.mjs";
6
+ import * as Pagination from '@tryfinch/finch-api/pagination';
7
+ import * as API from '@tryfinch/finch-api/resources/index';
8
+ /** API Client for interfacing with the Finch API. */
9
+ export class Finch extends Core.APIClient {
10
+ /**
11
+ * API Client for interfacing with the Finch API.
12
+ *
13
+ * @param {string | null | undefined} [opts.accessToken]
14
+ * @param {string | null | undefined} [opts.clientId=process.env['FINCH_CLIENT_ID'] ?? null]
15
+ * @param {string | null | undefined} [opts.clientSecret=process.env['FINCH_CLIENT_SECRET'] ?? null]
16
+ * @param {string | null | undefined} [opts.sandboxClientId=process.env['FINCH_SANDBOX_CLIENT_ID'] ?? null]
17
+ * @param {string | null | undefined} [opts.sandboxClientSecret=process.env['FINCH_SANDBOX_CLIENT_SECRET'] ?? null]
18
+ * @param {string | null | undefined} [opts.webhookSecret=process.env['FINCH_WEBHOOK_SECRET'] ?? null]
19
+ * @param {string} [opts.baseURL=process.env['FINCH_BASE_URL'] ?? https://api.tryfinch.com] - Override the default base URL for the API.
20
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
21
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
22
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
23
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
24
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
25
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
26
+ */
27
+ constructor({ baseURL = Core.readEnv('FINCH_BASE_URL'), accessToken = null, clientId = Core.readEnv('FINCH_CLIENT_ID') ?? null, clientSecret = Core.readEnv('FINCH_CLIENT_SECRET') ?? null, sandboxClientId = Core.readEnv('FINCH_SANDBOX_CLIENT_ID') ?? null, sandboxClientSecret = Core.readEnv('FINCH_SANDBOX_CLIENT_SECRET') ?? null, webhookSecret = Core.readEnv('FINCH_WEBHOOK_SECRET') ?? null, ...opts } = {}) {
28
+ const options = {
29
+ accessToken,
30
+ clientId,
31
+ clientSecret,
32
+ sandboxClientId,
33
+ sandboxClientSecret,
34
+ webhookSecret,
35
+ ...opts,
36
+ baseURL: baseURL || `https://api.tryfinch.com`,
37
+ };
38
+ super({
39
+ baseURL: options.baseURL,
40
+ timeout: options.timeout ?? 60000 /* 1 minute */,
41
+ httpAgent: options.httpAgent,
42
+ maxRetries: options.maxRetries,
43
+ fetch: options.fetch,
44
+ });
45
+ this.accessTokens = new API.AccessTokens(this);
46
+ this.hris = new API.HRIS(this);
47
+ this.providers = new API.Providers(this);
48
+ this.account = new API.Account(this);
49
+ this.webhooks = new API.Webhooks(this);
50
+ this.requestForwarding = new API.RequestForwarding(this);
51
+ this.jobs = new API.Jobs(this);
52
+ this.sandbox = new API.Sandbox(this);
53
+ this._options = options;
54
+ this.accessToken = accessToken;
55
+ this.clientId = clientId;
56
+ this.clientSecret = clientSecret;
57
+ this.sandboxClientId = sandboxClientId;
58
+ this.sandboxClientSecret = sandboxClientSecret;
59
+ this.webhookSecret = webhookSecret;
60
+ }
61
+ /**
62
+ * DEPRECATED: use client.accessTokens.create instead.
63
+ */
64
+ getAccessToken(code, options) {
65
+ if (!this.clientId) {
66
+ throw new Error('Expected the clientId to be set in order to call getAccessToken');
67
+ }
68
+ if (!this.clientSecret) {
69
+ throw new Error('Expected the clientSecret to be set in order to call getAccessToken');
70
+ }
71
+ return this.post('/auth/token', {
72
+ body: {
73
+ client_id: this.clientId,
74
+ client_secret: this.clientSecret,
75
+ code: code,
76
+ redirect_uri: options?.redirectUri,
77
+ },
78
+ headers: {
79
+ authorization: null,
80
+ },
81
+ }).then((response) => response.access_token);
82
+ }
83
+ /**
84
+ * Returns the authorization url which can be visited in order to obtain an
85
+ * authorization code from Finch. The authorization code can then be exchanged for
86
+ * an access token for the Finch api by calling get_access_token().
87
+ */
88
+ getAuthURL({ products, redirectUri, sandbox, }) {
89
+ if (!this.clientId) {
90
+ throw new Error('Expected the clientId to be set in order to call getAuthUrl');
91
+ }
92
+ const url = new URL('/authorize', 'https://connect.tryfinch.com/authorize');
93
+ url.search = this.stringifyQuery({
94
+ client_id: this.clientId,
95
+ products: products,
96
+ redirect_uri: redirectUri,
97
+ sandbox: sandbox,
98
+ });
99
+ return url.toString();
100
+ }
101
+ /**
102
+ * Returns a copy of the current Finch client with the given access token for
103
+ * authentication.
104
+ */
105
+ withAccessToken(accessToken) {
106
+ return new Finch({ ...this._options, accessToken });
107
+ }
108
+ defaultQuery() {
109
+ return this._options.defaultQuery;
110
+ }
111
+ defaultHeaders(opts) {
112
+ return {
113
+ ...super.defaultHeaders(opts),
114
+ 'Finch-API-Version': '2020-09-17',
115
+ ...this._options.defaultHeaders,
116
+ };
117
+ }
118
+ validateHeaders(headers, customHeaders) {
119
+ if (this.accessToken && headers['authorization']) {
120
+ return;
121
+ }
122
+ if (customHeaders['authorization'] === null) {
123
+ return;
124
+ }
125
+ if (this.sandboxClientId && this.sandboxClientSecret && headers['authorization']) {
126
+ return;
127
+ }
128
+ if (customHeaders['authorization'] === null) {
129
+ return;
130
+ }
131
+ throw new Error('Could not resolve authentication method. Expected either accessToken, sandboxClientId or sandboxClientSecret to be set. Or for one of the "Authorization" or "Authorization" headers to be explicitly omitted');
132
+ }
133
+ authHeaders(opts) {
134
+ const bearerAuth = this.bearerAuth(opts);
135
+ const basicAuth = this.basicAuth(opts);
136
+ if (bearerAuth != null && !Core.isEmptyObj(bearerAuth)) {
137
+ return bearerAuth;
138
+ }
139
+ return {};
140
+ }
141
+ bearerAuth(opts) {
142
+ if (this.accessToken == null) {
143
+ return {};
144
+ }
145
+ return { Authorization: `Bearer ${this.accessToken}` };
146
+ }
147
+ basicAuth(opts) {
148
+ if (!this.sandboxClientId) {
149
+ return {};
150
+ }
151
+ if (!this.sandboxClientSecret) {
152
+ return {};
153
+ }
154
+ const credentials = `${this.sandboxClientId}:${this.sandboxClientSecret}`;
155
+ const Authorization = `Basic ${Core.toBase64(credentials)}`;
156
+ return { Authorization };
157
+ }
158
+ }
159
+ _a = Finch;
160
+ Finch.Finch = _a;
161
+ Finch.FinchError = Errors.FinchError;
162
+ Finch.APIError = Errors.APIError;
163
+ Finch.APIConnectionError = Errors.APIConnectionError;
164
+ Finch.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
165
+ Finch.APIUserAbortError = Errors.APIUserAbortError;
166
+ Finch.NotFoundError = Errors.NotFoundError;
167
+ Finch.ConflictError = Errors.ConflictError;
168
+ Finch.RateLimitError = Errors.RateLimitError;
169
+ Finch.BadRequestError = Errors.BadRequestError;
170
+ Finch.AuthenticationError = Errors.AuthenticationError;
171
+ Finch.InternalServerError = Errors.InternalServerError;
172
+ Finch.PermissionDeniedError = Errors.PermissionDeniedError;
173
+ Finch.UnprocessableEntityError = Errors.UnprocessableEntityError;
174
+ Finch.toFile = Uploads.toFile;
175
+ Finch.fileFromPath = Uploads.fileFromPath;
176
+ (function (Finch) {
177
+ Finch.SinglePage = Pagination.SinglePage;
178
+ Finch.ResponsesPage = Pagination.ResponsesPage;
179
+ Finch.IndividualsPage = Pagination.IndividualsPage;
180
+ Finch.Page = Pagination.Page;
181
+ Finch.AccessTokens = API.AccessTokens;
182
+ Finch.HRIS = API.HRIS;
183
+ Finch.Providers = API.Providers;
184
+ Finch.ProvidersSinglePage = API.ProvidersSinglePage;
185
+ Finch.Account = API.Account;
186
+ Finch.Webhooks = API.Webhooks;
187
+ Finch.RequestForwarding = API.RequestForwarding;
188
+ Finch.Jobs = API.Jobs;
189
+ Finch.Sandbox = API.Sandbox;
190
+ })(Finch || (Finch = {}));
191
+ //# sourceMappingURL=client.mjs.map