@nangohq/node 0.29.6 → 0.30.0-beta.0
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/dist/index.cjs +19 -1
- package/dist/index.js +330 -293
- package/package.json +9 -1
package/dist/index.cjs
CHANGED
|
@@ -182,7 +182,12 @@ var Nango = class {
|
|
|
182
182
|
options.paramsSerializer = config.paramsSerializer;
|
|
183
183
|
}
|
|
184
184
|
if (this.dryRun) {
|
|
185
|
-
|
|
185
|
+
const stringifyParams = (params) => {
|
|
186
|
+
return Object.keys(params).map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`).join("&");
|
|
187
|
+
};
|
|
188
|
+
console.log(
|
|
189
|
+
`Nango Proxy Request: ${method?.toUpperCase()} ${url}${config.params ? `?${stringifyParams(config.params)}` : ""}`
|
|
190
|
+
);
|
|
186
191
|
}
|
|
187
192
|
if (method?.toUpperCase() === "POST") {
|
|
188
193
|
return import_axios.default.post(url, config.data, options);
|
|
@@ -334,6 +339,19 @@ var Nango = class {
|
|
|
334
339
|
};
|
|
335
340
|
return import_axios.default.post(url, body, { headers: this.enrichHeaders(headers) });
|
|
336
341
|
}
|
|
342
|
+
async triggerAction(providerConfigKey, connectionId, actionName, input) {
|
|
343
|
+
const url = `${this.serverUrl}/action/trigger`;
|
|
344
|
+
const headers = {
|
|
345
|
+
"Connection-Id": connectionId,
|
|
346
|
+
"Provider-Config-Key": providerConfigKey
|
|
347
|
+
};
|
|
348
|
+
const body = {
|
|
349
|
+
action_name: actionName,
|
|
350
|
+
input
|
|
351
|
+
};
|
|
352
|
+
const response = await import_axios.default.post(url, body, { headers: this.enrichHeaders(headers) });
|
|
353
|
+
return response.data;
|
|
354
|
+
}
|
|
337
355
|
async createConnection(_connectionArgs) {
|
|
338
356
|
throw new Error(
|
|
339
357
|
"This method has been deprecated, please use the REST API to create a connection. See https://docs.nango.dev/api-reference/connection/post"
|
package/dist/index.js
CHANGED
|
@@ -1,315 +1,352 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
})(SyncType || (SyncType = {}));
|
|
11
|
-
export class Nango {
|
|
12
|
-
serverUrl;
|
|
13
|
-
secretKey;
|
|
14
|
-
connectionId;
|
|
15
|
-
providerConfigKey;
|
|
16
|
-
isSync = false;
|
|
17
|
-
dryRun = false;
|
|
18
|
-
activityLogId;
|
|
19
|
-
constructor(config) {
|
|
20
|
-
config.host = config.host || prodHost;
|
|
21
|
-
this.serverUrl = config.host;
|
|
22
|
-
if (this.serverUrl.slice(-1) === '/') {
|
|
23
|
-
this.serverUrl = this.serverUrl.slice(0, -1);
|
|
24
|
-
}
|
|
25
|
-
if (!config.secretKey) {
|
|
26
|
-
throw new Error('You must specify a secret key (cf. documentation).');
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
new URL(this.serverUrl);
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
throw new Error(`Invalid URL provided for the Nango host: ${this.serverUrl}`);
|
|
33
|
-
}
|
|
34
|
-
this.secretKey = config.secretKey;
|
|
35
|
-
this.connectionId = config.connectionId || '';
|
|
36
|
-
this.providerConfigKey = config.providerConfigKey || '';
|
|
37
|
-
if (config.isSync) {
|
|
38
|
-
this.isSync = config.isSync;
|
|
39
|
-
}
|
|
40
|
-
if (config.dryRun) {
|
|
41
|
-
this.dryRun = config.dryRun;
|
|
42
|
-
}
|
|
43
|
-
if (config.activityLogId) {
|
|
44
|
-
this.activityLogId = config.activityLogId;
|
|
45
|
-
}
|
|
1
|
+
// lib/index.ts
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
|
|
4
|
+
// lib/utils.ts
|
|
5
|
+
var validateProxyConfiguration = (config) => {
|
|
6
|
+
const requiredParams = ["endpoint", "providerConfigKey", "connectionId"];
|
|
7
|
+
requiredParams.forEach((param) => {
|
|
8
|
+
if (typeof config[param] === "undefined") {
|
|
9
|
+
throw new Error(`${param} is missing and is required to make a proxy call!`);
|
|
46
10
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
* @param [forceRefresh] - When set, this is used to obtain a new refresh token from the provider before the current token has expired,
|
|
55
|
-
* you can set the forceRefresh argument to true.
|
|
56
|
-
* */
|
|
57
|
-
async getToken(providerConfigKey, connectionId, forceRefresh) {
|
|
58
|
-
const response = await this.getConnectionDetails(providerConfigKey, connectionId, forceRefresh);
|
|
59
|
-
switch (response.data.credentials.type) {
|
|
60
|
-
case AuthModes.OAuth2:
|
|
61
|
-
return response.data.credentials.access_token;
|
|
62
|
-
case AuthModes.OAuth1:
|
|
63
|
-
return { oAuthToken: response.data.credentials.oauth_token, oAuthTokenSecret: response.data.credentials.oauth_token_secret };
|
|
64
|
-
default:
|
|
65
|
-
return response.data.credentials;
|
|
66
|
-
}
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var validateSyncRecordConfiguration = (config) => {
|
|
14
|
+
const requiredParams = ["model", "providerConfigKey", "connectionId"];
|
|
15
|
+
requiredParams.forEach((param) => {
|
|
16
|
+
if (typeof config[param] === "undefined") {
|
|
17
|
+
throw new Error(`${param} is missing and is required to make a proxy call!`);
|
|
67
18
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// lib/index.ts
|
|
23
|
+
var stagingHost = "https://api-staging.nango.dev";
|
|
24
|
+
var prodHost = "https://api.nango.dev";
|
|
25
|
+
var SyncType = /* @__PURE__ */ ((SyncType2) => {
|
|
26
|
+
SyncType2["INITIAL"] = "INITIAL";
|
|
27
|
+
SyncType2["INCREMENTAL"] = "INCREMENTAL";
|
|
28
|
+
return SyncType2;
|
|
29
|
+
})(SyncType || {});
|
|
30
|
+
var Nango = class {
|
|
31
|
+
serverUrl;
|
|
32
|
+
secretKey;
|
|
33
|
+
connectionId;
|
|
34
|
+
providerConfigKey;
|
|
35
|
+
isSync = false;
|
|
36
|
+
dryRun = false;
|
|
37
|
+
activityLogId;
|
|
38
|
+
constructor(config) {
|
|
39
|
+
config.host = config.host || prodHost;
|
|
40
|
+
this.serverUrl = config.host;
|
|
41
|
+
if (this.serverUrl.slice(-1) === "/") {
|
|
42
|
+
this.serverUrl = this.serverUrl.slice(0, -1);
|
|
80
43
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
* returned by the external API.
|
|
84
|
-
* @param providerConfigKey - This is the unique Config Key for the integration
|
|
85
|
-
* @param connectionId - This is the unique connection identifier used to identify this connection
|
|
86
|
-
* @param [forceRefresh] - When set, this is used to obtain a new refresh token from the provider before the current token has expired,
|
|
87
|
-
* you can set the forceRefresh argument to true.
|
|
88
|
-
* @param [refreshToken] - When set this returns the refresh token as part of the response
|
|
89
|
-
*/
|
|
90
|
-
async getConnection(providerConfigKey, connectionId, forceRefresh, refreshToken) {
|
|
91
|
-
const response = await this.getConnectionDetails(providerConfigKey, connectionId, forceRefresh, refreshToken);
|
|
92
|
-
return response.data;
|
|
44
|
+
if (!config.secretKey) {
|
|
45
|
+
throw new Error("You must specify a secret key (cf. documentation).");
|
|
93
46
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (!config.providerConfigKey && this.providerConfigKey) {
|
|
99
|
-
config.providerConfigKey = this.providerConfigKey;
|
|
100
|
-
}
|
|
101
|
-
validateProxyConfiguration(config);
|
|
102
|
-
const { providerConfigKey, connectionId, method, retries, headers: customHeaders, baseUrlOverride } = config;
|
|
103
|
-
const url = `${this.serverUrl}/proxy${config.endpoint[0] === '/' ? '' : '/'}${config.endpoint}`;
|
|
104
|
-
const customPrefixedHeaders = customHeaders && Object.keys(customHeaders).length > 0
|
|
105
|
-
? Object.keys(customHeaders).reduce((acc, key) => {
|
|
106
|
-
acc[`Nango-Proxy-${key}`] = customHeaders[key];
|
|
107
|
-
return acc;
|
|
108
|
-
}, {})
|
|
109
|
-
: {};
|
|
110
|
-
const headers = {
|
|
111
|
-
'Connection-Id': connectionId,
|
|
112
|
-
'Provider-Config-Key': providerConfigKey,
|
|
113
|
-
'Base-Url-Override': baseUrlOverride || '',
|
|
114
|
-
'Nango-Is-Sync': this.isSync,
|
|
115
|
-
'Nango-Is-Dry-Run': this.dryRun,
|
|
116
|
-
'Nango-Activity-Log-Id': this.activityLogId || '',
|
|
117
|
-
...customPrefixedHeaders
|
|
118
|
-
};
|
|
119
|
-
if (retries) {
|
|
120
|
-
headers['Retries'] = retries;
|
|
121
|
-
}
|
|
122
|
-
const options = {
|
|
123
|
-
headers: this.enrichHeaders(headers)
|
|
124
|
-
};
|
|
125
|
-
if (config.params) {
|
|
126
|
-
options.params = config.params;
|
|
127
|
-
}
|
|
128
|
-
if (config.paramsSerializer) {
|
|
129
|
-
options.paramsSerializer = config.paramsSerializer;
|
|
130
|
-
}
|
|
131
|
-
if (this.dryRun) {
|
|
132
|
-
console.log(`Nango Proxy Request: ${method?.toUpperCase()} ${url}`);
|
|
133
|
-
}
|
|
134
|
-
if (method?.toUpperCase() === 'POST') {
|
|
135
|
-
return axios.post(url, config.data, options);
|
|
136
|
-
}
|
|
137
|
-
else if (method?.toUpperCase() === 'PATCH') {
|
|
138
|
-
return axios.patch(url, config.data, options);
|
|
139
|
-
}
|
|
140
|
-
else if (method?.toUpperCase() === 'PUT') {
|
|
141
|
-
return axios.put(url, config.data, options);
|
|
142
|
-
}
|
|
143
|
-
else if (method?.toUpperCase() === 'DELETE') {
|
|
144
|
-
return axios.delete(url, options);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
return axios.get(url, options);
|
|
148
|
-
}
|
|
47
|
+
try {
|
|
48
|
+
new URL(this.serverUrl);
|
|
49
|
+
} catch (err) {
|
|
50
|
+
throw new Error(`Invalid URL provided for the Nango host: ${this.serverUrl}`);
|
|
149
51
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
52
|
+
this.secretKey = config.secretKey;
|
|
53
|
+
this.connectionId = config.connectionId || "";
|
|
54
|
+
this.providerConfigKey = config.providerConfigKey || "";
|
|
55
|
+
if (config.isSync) {
|
|
56
|
+
this.isSync = config.isSync;
|
|
155
57
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
...config,
|
|
159
|
-
method: 'POST'
|
|
160
|
-
});
|
|
58
|
+
if (config.dryRun) {
|
|
59
|
+
this.dryRun = config.dryRun;
|
|
161
60
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
...config,
|
|
165
|
-
method: 'PATCH'
|
|
166
|
-
});
|
|
61
|
+
if (config.activityLogId) {
|
|
62
|
+
this.activityLogId = config.activityLogId;
|
|
167
63
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* For OAuth 2: returns the access token directly as a string.
|
|
67
|
+
* For OAuth 2: If you want to obtain a new refresh token from the provider before the current token has expired,
|
|
68
|
+
* you can set the forceRefresh argument to true."
|
|
69
|
+
* For OAuth 1: returns an object with 'oAuthToken' and 'oAuthTokenSecret' fields.
|
|
70
|
+
* @param providerConfigKey - This is the unique Config Key for the integration
|
|
71
|
+
* @param connectionId - This is the unique connection identifier used to identify this connection
|
|
72
|
+
* @param [forceRefresh] - When set, this is used to obtain a new refresh token from the provider before the current token has expired,
|
|
73
|
+
* you can set the forceRefresh argument to true.
|
|
74
|
+
* */
|
|
75
|
+
async getToken(providerConfigKey, connectionId, forceRefresh) {
|
|
76
|
+
const response = await this.getConnectionDetails(providerConfigKey, connectionId, forceRefresh);
|
|
77
|
+
switch (response.data.credentials.type) {
|
|
78
|
+
case "OAUTH2" /* OAuth2 */:
|
|
79
|
+
return response.data.credentials.access_token;
|
|
80
|
+
case "OAUTH1" /* OAuth1 */:
|
|
81
|
+
return { oAuthToken: response.data.credentials.oauth_token, oAuthTokenSecret: response.data.credentials.oauth_token_secret };
|
|
82
|
+
default:
|
|
83
|
+
return response.data.credentials;
|
|
173
84
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
};
|
|
205
|
-
const options = {
|
|
206
|
-
headers: this.enrichHeaders(headers)
|
|
207
|
-
};
|
|
208
|
-
const response = await axios.get(url, options);
|
|
209
|
-
return response.data;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get the full (fresh) credentials payload returned by the external API,
|
|
88
|
+
* which also contains access credentials.
|
|
89
|
+
* @param providerConfigKey - This is the unique Config Key for the integration
|
|
90
|
+
* @param connectionId - This is the unique connection identifier used to identify this connection
|
|
91
|
+
* @param [forceRefresh] - When set, this is used to obtain a new refresh token from the provider before the current token has expired,
|
|
92
|
+
* you can set the forceRefresh argument to true.
|
|
93
|
+
* */
|
|
94
|
+
async getRawTokenResponse(providerConfigKey, connectionId, forceRefresh) {
|
|
95
|
+
const response = await this.getConnectionDetails(providerConfigKey, connectionId, forceRefresh);
|
|
96
|
+
const credentials = response.data.credentials;
|
|
97
|
+
return credentials.raw;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get the Connection object, which also contains access credentials and full credentials payload
|
|
101
|
+
* returned by the external API.
|
|
102
|
+
* @param providerConfigKey - This is the unique Config Key for the integration
|
|
103
|
+
* @param connectionId - This is the unique connection identifier used to identify this connection
|
|
104
|
+
* @param [forceRefresh] - When set, this is used to obtain a new refresh token from the provider before the current token has expired,
|
|
105
|
+
* you can set the forceRefresh argument to true.
|
|
106
|
+
* @param [refreshToken] - When set this returns the refresh token as part of the response
|
|
107
|
+
*/
|
|
108
|
+
async getConnection(providerConfigKey, connectionId, forceRefresh, refreshToken) {
|
|
109
|
+
const response = await this.getConnectionDetails(providerConfigKey, connectionId, forceRefresh, refreshToken);
|
|
110
|
+
return response.data;
|
|
111
|
+
}
|
|
112
|
+
async proxy(config) {
|
|
113
|
+
if (!config.connectionId && this.connectionId) {
|
|
114
|
+
config.connectionId = this.connectionId;
|
|
210
115
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const headers = {
|
|
214
|
-
'Content-Type': 'application/json',
|
|
215
|
-
'Accept-Encoding': 'application/json'
|
|
216
|
-
};
|
|
217
|
-
if (additionalHeader) {
|
|
218
|
-
Object.assign(headers, additionalHeader);
|
|
219
|
-
}
|
|
220
|
-
const params = {
|
|
221
|
-
provider_config_key: providerConfigKey,
|
|
222
|
-
force_refresh: forceRefresh,
|
|
223
|
-
refresh_token: refreshToken
|
|
224
|
-
};
|
|
225
|
-
return axios.get(url, { params: params, headers: this.enrichHeaders(headers) });
|
|
116
|
+
if (!config.providerConfigKey && this.providerConfigKey) {
|
|
117
|
+
config.providerConfigKey = this.providerConfigKey;
|
|
226
118
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
119
|
+
validateProxyConfiguration(config);
|
|
120
|
+
const { providerConfigKey, connectionId, method, retries, headers: customHeaders, baseUrlOverride } = config;
|
|
121
|
+
const url = `${this.serverUrl}/proxy${config.endpoint[0] === "/" ? "" : "/"}${config.endpoint}`;
|
|
122
|
+
const customPrefixedHeaders = customHeaders && Object.keys(customHeaders).length > 0 ? Object.keys(customHeaders).reduce((acc, key) => {
|
|
123
|
+
acc[`Nango-Proxy-${key}`] = customHeaders[key];
|
|
124
|
+
return acc;
|
|
125
|
+
}, {}) : {};
|
|
126
|
+
const headers = {
|
|
127
|
+
"Connection-Id": connectionId,
|
|
128
|
+
"Provider-Config-Key": providerConfigKey,
|
|
129
|
+
"Base-Url-Override": baseUrlOverride || "",
|
|
130
|
+
"Nango-Is-Sync": this.isSync,
|
|
131
|
+
"Nango-Is-Dry-Run": this.dryRun,
|
|
132
|
+
"Nango-Activity-Log-Id": this.activityLogId || "",
|
|
133
|
+
...customPrefixedHeaders
|
|
134
|
+
};
|
|
135
|
+
if (retries) {
|
|
136
|
+
headers["Retries"] = retries;
|
|
233
137
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
138
|
+
const options = {
|
|
139
|
+
headers: this.enrichHeaders(headers)
|
|
140
|
+
};
|
|
141
|
+
if (config.params) {
|
|
142
|
+
options.params = config.params;
|
|
238
143
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
throw new Error('Provider Config Key is required');
|
|
242
|
-
}
|
|
243
|
-
if (!connectionId) {
|
|
244
|
-
throw new Error('Connection Id is required');
|
|
245
|
-
}
|
|
246
|
-
if (!metadata) {
|
|
247
|
-
throw new Error('Metadata is required');
|
|
248
|
-
}
|
|
249
|
-
const url = `${this.serverUrl}/connection/${connectionId}/metadata?provider_config_key=${providerConfigKey}`;
|
|
250
|
-
const headers = {
|
|
251
|
-
'Provider-Config-Key': providerConfigKey
|
|
252
|
-
};
|
|
253
|
-
return axios.post(url, metadata, { headers: this.enrichHeaders(headers) });
|
|
144
|
+
if (config.paramsSerializer) {
|
|
145
|
+
options.paramsSerializer = config.paramsSerializer;
|
|
254
146
|
}
|
|
255
|
-
|
|
256
|
-
|
|
147
|
+
if (this.dryRun) {
|
|
148
|
+
const stringifyParams = (params) => {
|
|
149
|
+
return Object.keys(params).map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`).join("&");
|
|
150
|
+
};
|
|
151
|
+
console.log(
|
|
152
|
+
`Nango Proxy Request: ${method?.toUpperCase()} ${url}${config.params ? `?${stringifyParams(config.params)}` : ""}`
|
|
153
|
+
);
|
|
257
154
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
});
|
|
269
|
-
return response.data.metadata;
|
|
155
|
+
if (method?.toUpperCase() === "POST") {
|
|
156
|
+
return axios.post(url, config.data, options);
|
|
157
|
+
} else if (method?.toUpperCase() === "PATCH") {
|
|
158
|
+
return axios.patch(url, config.data, options);
|
|
159
|
+
} else if (method?.toUpperCase() === "PUT") {
|
|
160
|
+
return axios.put(url, config.data, options);
|
|
161
|
+
} else if (method?.toUpperCase() === "DELETE") {
|
|
162
|
+
return axios.delete(url, options);
|
|
163
|
+
} else {
|
|
164
|
+
return axios.get(url, options);
|
|
270
165
|
}
|
|
271
|
-
|
|
272
|
-
|
|
166
|
+
}
|
|
167
|
+
async get(config) {
|
|
168
|
+
return this.proxy({
|
|
169
|
+
...config,
|
|
170
|
+
method: "GET"
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
async post(config) {
|
|
174
|
+
return this.proxy({
|
|
175
|
+
...config,
|
|
176
|
+
method: "POST"
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
async patch(config) {
|
|
180
|
+
return this.proxy({
|
|
181
|
+
...config,
|
|
182
|
+
method: "PATCH"
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
async delete(config) {
|
|
186
|
+
return this.proxy({
|
|
187
|
+
...config,
|
|
188
|
+
method: "DELETE"
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
async getRecords(config) {
|
|
192
|
+
const { connectionId, providerConfigKey, model, delta, offset, limit, includeNangoMetadata } = config;
|
|
193
|
+
validateSyncRecordConfiguration(config);
|
|
194
|
+
const order = config?.order === "asc" ? "asc" : "desc";
|
|
195
|
+
let sortBy = "id";
|
|
196
|
+
switch (config.sortBy) {
|
|
197
|
+
case "createdAt":
|
|
198
|
+
sortBy = "created_at";
|
|
199
|
+
break;
|
|
200
|
+
case "updatedAt":
|
|
201
|
+
sortBy = "updated_at";
|
|
202
|
+
break;
|
|
273
203
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
};
|
|
286
|
-
return axios.post(url, body, { headers: this.enrichHeaders(headers) });
|
|
204
|
+
let filter = "";
|
|
205
|
+
switch (config.filter) {
|
|
206
|
+
case "deleted":
|
|
207
|
+
filter = "deleted";
|
|
208
|
+
break;
|
|
209
|
+
case "updated":
|
|
210
|
+
filter = "updated";
|
|
211
|
+
break;
|
|
212
|
+
case "added":
|
|
213
|
+
filter = "added";
|
|
214
|
+
break;
|
|
287
215
|
}
|
|
288
|
-
|
|
289
|
-
|
|
216
|
+
const includeMetadata = includeNangoMetadata || false;
|
|
217
|
+
const url = `${this.serverUrl}/sync/records/?model=${model}&order=${order}&delta=${delta || ""}&offset=${offset || ""}&limit=${limit || ""}&sort_by=${sortBy || ""}&include_nango_metadata=${includeMetadata}&filter=${filter}`;
|
|
218
|
+
const headers = {
|
|
219
|
+
"Connection-Id": connectionId,
|
|
220
|
+
"Provider-Config-Key": providerConfigKey
|
|
221
|
+
};
|
|
222
|
+
const options = {
|
|
223
|
+
headers: this.enrichHeaders(headers)
|
|
224
|
+
};
|
|
225
|
+
const response = await axios.get(url, options);
|
|
226
|
+
return response.data;
|
|
227
|
+
}
|
|
228
|
+
async getConnectionDetails(providerConfigKey, connectionId, forceRefresh = false, refreshToken = false, additionalHeader = {}) {
|
|
229
|
+
const url = `${this.serverUrl}/connection/${connectionId}`;
|
|
230
|
+
const headers = {
|
|
231
|
+
"Content-Type": "application/json",
|
|
232
|
+
"Accept-Encoding": "application/json"
|
|
233
|
+
};
|
|
234
|
+
if (additionalHeader) {
|
|
235
|
+
Object.assign(headers, additionalHeader);
|
|
290
236
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
237
|
+
const params = {
|
|
238
|
+
provider_config_key: providerConfigKey,
|
|
239
|
+
force_refresh: forceRefresh,
|
|
240
|
+
refresh_token: refreshToken
|
|
241
|
+
};
|
|
242
|
+
return axios.get(url, { params, headers: this.enrichHeaders(headers) });
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Get the list of Connections, which does not contain access credentials.
|
|
246
|
+
*/
|
|
247
|
+
async listConnections(connectionId) {
|
|
248
|
+
const response = await this.listConnectionDetails(connectionId);
|
|
249
|
+
return response.data;
|
|
250
|
+
}
|
|
251
|
+
async getIntegration(providerConfigKey, includeIntegrationCredetials = false) {
|
|
252
|
+
const url = `${this.serverUrl}/config/${providerConfigKey}`;
|
|
253
|
+
const response = await axios.get(url, { headers: this.enrichHeaders({}), params: { include_creds: includeIntegrationCredetials } });
|
|
254
|
+
return response.data;
|
|
255
|
+
}
|
|
256
|
+
async setMetadata(providerConfigKey, connectionId, metadata) {
|
|
257
|
+
if (!providerConfigKey) {
|
|
258
|
+
throw new Error("Provider Config Key is required");
|
|
298
259
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
if (connectionId) {
|
|
302
|
-
url = url.concat(`connectionId=${connectionId}`);
|
|
303
|
-
}
|
|
304
|
-
const headers = {
|
|
305
|
-
'Content-Type': 'application/json',
|
|
306
|
-
'Accept-Encoding': 'application/json'
|
|
307
|
-
};
|
|
308
|
-
return axios.get(url, { headers: this.enrichHeaders(headers) });
|
|
260
|
+
if (!connectionId) {
|
|
261
|
+
throw new Error("Connection Id is required");
|
|
309
262
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
return headers;
|
|
263
|
+
if (!metadata) {
|
|
264
|
+
throw new Error("Metadata is required");
|
|
313
265
|
}
|
|
314
|
-
}
|
|
315
|
-
|
|
266
|
+
const url = `${this.serverUrl}/connection/${connectionId}/metadata?provider_config_key=${providerConfigKey}`;
|
|
267
|
+
const headers = {
|
|
268
|
+
"Provider-Config-Key": providerConfigKey
|
|
269
|
+
};
|
|
270
|
+
return axios.post(url, metadata, { headers: this.enrichHeaders(headers) });
|
|
271
|
+
}
|
|
272
|
+
async setFieldMapping(_fieldMapping, _optionalProviderConfigKey, _optionalConnectionId) {
|
|
273
|
+
throw new Error("setFieldMapping is deprecated. Please use setMetadata instead.");
|
|
274
|
+
}
|
|
275
|
+
async getMetadata(providerConfigKey, connectionId) {
|
|
276
|
+
if (!providerConfigKey) {
|
|
277
|
+
throw new Error("Provider Config Key is required");
|
|
278
|
+
}
|
|
279
|
+
if (!connectionId) {
|
|
280
|
+
throw new Error("Connection Id is required");
|
|
281
|
+
}
|
|
282
|
+
const response = await this.getConnectionDetails(providerConfigKey, connectionId, false, false, {
|
|
283
|
+
"Nango-Is-Sync": true,
|
|
284
|
+
"Nango-Is-Dry-Run": this.dryRun
|
|
285
|
+
});
|
|
286
|
+
return response.data.metadata;
|
|
287
|
+
}
|
|
288
|
+
async getFieldMapping(_optionalProviderConfigKey, _optionalConnectionId) {
|
|
289
|
+
throw new Error("getFieldMapping is deprecated. Please use getMetadata instead.");
|
|
290
|
+
}
|
|
291
|
+
async triggerSync(providerConfigKey, connectionId, syncs) {
|
|
292
|
+
const url = `${this.serverUrl}/sync/trigger`;
|
|
293
|
+
const headers = {
|
|
294
|
+
"Connection-Id": connectionId,
|
|
295
|
+
"Provider-Config-Key": providerConfigKey
|
|
296
|
+
};
|
|
297
|
+
if (typeof syncs === "string") {
|
|
298
|
+
throw new Error("Syncs must be an array of strings. If it is a single sync, please wrap it in an array.");
|
|
299
|
+
}
|
|
300
|
+
const body = {
|
|
301
|
+
syncs: syncs || []
|
|
302
|
+
};
|
|
303
|
+
return axios.post(url, body, { headers: this.enrichHeaders(headers) });
|
|
304
|
+
}
|
|
305
|
+
async triggerAction(providerConfigKey, connectionId, actionName, input) {
|
|
306
|
+
const url = `${this.serverUrl}/action/trigger`;
|
|
307
|
+
const headers = {
|
|
308
|
+
"Connection-Id": connectionId,
|
|
309
|
+
"Provider-Config-Key": providerConfigKey
|
|
310
|
+
};
|
|
311
|
+
const body = {
|
|
312
|
+
action_name: actionName,
|
|
313
|
+
input
|
|
314
|
+
};
|
|
315
|
+
const response = await axios.post(url, body, { headers: this.enrichHeaders(headers) });
|
|
316
|
+
return response.data;
|
|
317
|
+
}
|
|
318
|
+
async createConnection(_connectionArgs) {
|
|
319
|
+
throw new Error(
|
|
320
|
+
"This method has been deprecated, please use the REST API to create a connection. See https://docs.nango.dev/api-reference/connection/post"
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
async deleteConnection(providerConfigKey, connectionId) {
|
|
324
|
+
const url = `${this.serverUrl}/connection/${connectionId}?provider_config_key=${providerConfigKey}`;
|
|
325
|
+
const headers = {
|
|
326
|
+
"Content-Type": "application/json",
|
|
327
|
+
"Accept-Encoding": "application/json"
|
|
328
|
+
};
|
|
329
|
+
return axios.delete(url, { headers: this.enrichHeaders(headers) });
|
|
330
|
+
}
|
|
331
|
+
async listConnectionDetails(connectionId) {
|
|
332
|
+
let url = `${this.serverUrl}/connection?`;
|
|
333
|
+
if (connectionId) {
|
|
334
|
+
url = url.concat(`connectionId=${connectionId}`);
|
|
335
|
+
}
|
|
336
|
+
const headers = {
|
|
337
|
+
"Content-Type": "application/json",
|
|
338
|
+
"Accept-Encoding": "application/json"
|
|
339
|
+
};
|
|
340
|
+
return axios.get(url, { headers: this.enrichHeaders(headers) });
|
|
341
|
+
}
|
|
342
|
+
enrichHeaders(headers = {}) {
|
|
343
|
+
headers["Authorization"] = "Bearer " + this.secretKey;
|
|
344
|
+
return headers;
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
export {
|
|
348
|
+
Nango,
|
|
349
|
+
SyncType,
|
|
350
|
+
prodHost,
|
|
351
|
+
stagingHost
|
|
352
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nangohq/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0-beta.0",
|
|
4
4
|
"description": "Nango's Node client.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"require": "./dist/index.cjs",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
7
15
|
"typings": "dist/index.d.ts",
|
|
8
16
|
"keywords": [],
|
|
9
17
|
"repository": {
|