@nangohq/node 0.6.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.d.ts +23 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/package.json +26 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare class Pizzly {
|
|
2
|
+
serverUrl: string;
|
|
3
|
+
secretKey: string;
|
|
4
|
+
constructor(serverUrl?: string, secretKey?: string);
|
|
5
|
+
/**
|
|
6
|
+
* Get fresh access credentials to authenticate your requests.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* For OAuth 2: returns the access token directly as a string.
|
|
10
|
+
* For OAuth 1: returns an object with 'oAuthToken' and 'oAuthTokenSecret' fields.
|
|
11
|
+
*/
|
|
12
|
+
accessToken(providerConfigKey: string, connectionId: string): Promise<any>;
|
|
13
|
+
/**
|
|
14
|
+
* Get the full (fresh) credentials payload returned by the external API, which also contains access credentials.
|
|
15
|
+
*/
|
|
16
|
+
rawTokenResponse(providerConfigKey: string, connectionId: string): Promise<any>;
|
|
17
|
+
/**
|
|
18
|
+
* Get the Connection object, which also contains access credentials and full credentials payload returned by the external API.
|
|
19
|
+
*/
|
|
20
|
+
connection(providerConfigKey: string, connectionId: string): Promise<any>;
|
|
21
|
+
private getConnection;
|
|
22
|
+
private enrichHeaders;
|
|
23
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
export class Pizzly {
|
|
3
|
+
serverUrl;
|
|
4
|
+
secretKey;
|
|
5
|
+
constructor(serverUrl, secretKey = '') {
|
|
6
|
+
this.serverUrl = serverUrl || 'http://localhost:3003';
|
|
7
|
+
if (this.serverUrl.slice(-1) === '/') {
|
|
8
|
+
this.serverUrl = this.serverUrl.slice(0, -1);
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
new URL(this.serverUrl);
|
|
12
|
+
}
|
|
13
|
+
catch (err) {
|
|
14
|
+
throw new Error(`Invalid URL provided for the Pizzly host: ${this.serverUrl}`);
|
|
15
|
+
}
|
|
16
|
+
this.secretKey = secretKey;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get fresh access credentials to authenticate your requests.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* For OAuth 2: returns the access token directly as a string.
|
|
23
|
+
* For OAuth 1: returns an object with 'oAuthToken' and 'oAuthTokenSecret' fields.
|
|
24
|
+
*/
|
|
25
|
+
async accessToken(providerConfigKey, connectionId) {
|
|
26
|
+
let response = await this.getConnection(providerConfigKey, connectionId);
|
|
27
|
+
switch (response.data.credentials.type) {
|
|
28
|
+
case 'OAUTH2':
|
|
29
|
+
return response.data.credentials.access_token;
|
|
30
|
+
case 'OAUTH1':
|
|
31
|
+
return { oAuthToken: response.data.credentials.oauth_token, oAuthTokenSecret: response.data.credentials.oauth_token_secret };
|
|
32
|
+
default:
|
|
33
|
+
throw Error(`Unrecognized OAuth type '${response.data.credentials.type}' in stored credentials.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get the full (fresh) credentials payload returned by the external API, which also contains access credentials.
|
|
38
|
+
*/
|
|
39
|
+
async rawTokenResponse(providerConfigKey, connectionId) {
|
|
40
|
+
let response = await this.getConnection(providerConfigKey, connectionId);
|
|
41
|
+
return response.data.credentials.raw;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get the Connection object, which also contains access credentials and full credentials payload returned by the external API.
|
|
45
|
+
*/
|
|
46
|
+
async connection(providerConfigKey, connectionId) {
|
|
47
|
+
let response = await this.getConnection(providerConfigKey, connectionId);
|
|
48
|
+
return response.data;
|
|
49
|
+
}
|
|
50
|
+
async getConnection(providerConfigKey, connectionId) {
|
|
51
|
+
let url = `${this.serverUrl}/connection/${connectionId}`;
|
|
52
|
+
let headers = {
|
|
53
|
+
'Content-Type': 'application/json'
|
|
54
|
+
};
|
|
55
|
+
let params = {
|
|
56
|
+
provider_config_key: providerConfigKey
|
|
57
|
+
};
|
|
58
|
+
return await axios.get(url, { params: params, headers: this.enrichHeaders(headers) });
|
|
59
|
+
}
|
|
60
|
+
enrichHeaders(headers = {}) {
|
|
61
|
+
if (this.secretKey) {
|
|
62
|
+
headers['Authorization'] = 'Basic ' + Buffer.from(process.env['NANGO_SECRET_KEY'] + ':').toString('base64');
|
|
63
|
+
}
|
|
64
|
+
return headers;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,OAAO,MAAM;IACf,SAAS,CAAS;IAClB,SAAS,CAAS;IAElB,YAAY,SAAkB,EAAE,SAAS,GAAG,EAAE;QAC1C,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,uBAAuB,CAAC;QAEtD,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;YAClC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SAChD;QAED,IAAI;YACA,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAC3B;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,6CAA6C,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;SAClF;QAED,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,WAAW,CAAC,iBAAyB,EAAE,YAAoB;QACpE,IAAI,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,i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EAAE,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC1F,CAAC;IAEO,aAAa,CAAC,UAAqD,EAAE;QACzE,IAAI,IAAI,CAAC,SAAS,EAAE;YAChB,OAAO,CAAC,eAAe,CAAC,GAAG,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;SAC/G;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ"}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nangohq/node",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Nango's Node client.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"typings": "dist/index.d.ts",
|
|
8
|
+
"keywords": [],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/NangoHQ/nango",
|
|
12
|
+
"directory": "packages/node-client"
|
|
13
|
+
},
|
|
14
|
+
"license": "SEE LICENSE IN LICENSE FILE IN GIT REPOSITORY",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"axios": "^1.2.0"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=16.7"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist/**/*",
|
|
23
|
+
"!**/*.json",
|
|
24
|
+
"README.md"
|
|
25
|
+
]
|
|
26
|
+
}
|