nango 0.17.6 → 0.20.1

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/entry.js ADDED
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ var node_1 = require("@nangohq/node");
55
+ // TODO this will be a local interface created by the config yaml file
56
+ //import { ticket } from '@nangohq/models';
57
+ var GithubTicketSync = /** @class */ (function (_super) {
58
+ __extends(GithubTicketSync, _super);
59
+ function GithubTicketSync() {
60
+ return _super !== null && _super.apply(this, arguments) || this;
61
+ }
62
+ //async fetchData(nango: NangoHelper): { [ticket.name]: [ticket.type] } {
63
+ GithubTicketSync.prototype.fetchData = function (nango) {
64
+ return __awaiter(this, void 0, void 0, function () {
65
+ var issues, tickets;
66
+ return __generator(this, function (_a) {
67
+ switch (_a.label) {
68
+ case 0: return [4 /*yield*/, nango.get({
69
+ endpoint: 'repos/NangoHQ/nango/issues'
70
+ })];
71
+ case 1:
72
+ issues = _a.sent();
73
+ tickets = issues.map(function (issue) { return ({
74
+ id: issue.id,
75
+ title: issue.title,
76
+ description: issue.body,
77
+ status: issue.state,
78
+ author: {
79
+ avatar_url: issue.user.avatar_url
80
+ }
81
+ }); });
82
+ return [2 /*return*/, tickets];
83
+ }
84
+ });
85
+ });
86
+ };
87
+ return GithubTicketSync;
88
+ }(node_1.NangoSync));
89
+ exports.default = GithubSync;
package/dist/index.js CHANGED
@@ -4,231 +4,193 @@
4
4
  */
5
5
  import { Command } from 'commander';
6
6
  import axios from 'axios';
7
- import https from 'https';
7
+ import chalk from 'chalk';
8
+ import figlet from 'figlet';
9
+ import fs from 'fs';
10
+ import path, { dirname } from 'path';
11
+ import { fileURLToPath } from 'url';
12
+ import yaml from 'js-yaml';
13
+ import ejs from 'ejs';
14
+ import * as dotenv from 'dotenv';
15
+ import { nangoConfigFile, loadSimplifiedConfig, checkForIntegrationFile } from '@nangohq/shared';
16
+ import { init, run, tsc, tscWatch, configWatch, dockerRun } from './sync.js';
17
+ import { hostport, checkEnvVars, enrichHeaders, httpsAgent, NANGO_INTEGRATIONS_LOCATION, buildInterfaces, setCloudHost, setStagingHost } from './utils.js';
8
18
  const program = new Command();
9
- let hostport = process.env['NANGO_HOSTPORT'] || 'http://localhost:3003';
10
- let cloudHost = 'https://api.nango.dev';
11
- let stagingHost = 'https://nango-cloud-staging.onrender.com';
12
- if (hostport.slice(-1) === '/') {
13
- hostport = hostport.slice(0, -1);
14
- }
19
+ const __filename = fileURLToPath(import.meta.url);
20
+ const __dirname = dirname(__filename);
21
+ dotenv.config();
15
22
  // Test from the package root (/packages/cli) with 'node dist/index.js'
16
23
  program
17
24
  .name('nango')
18
25
  .description(`A CLI tool to configure Nango:\n- By defaults, the CLI assumes that you are running Nango on localhost:3003\n- For Nango Cloud: Set the NANGO_HOSTPORT & NANGO_SECRET_KEY env variables\n- For Self-Hosting: set the NANGO_HOSTPORT env variable`);
26
+ program.addHelpText('before', chalk.green(figlet.textSync('Nango CLI')));
19
27
  program
20
- .command('config:list')
21
- .description('List all provider configurations.')
22
- .action(async function () {
23
- checkEnvVars();
24
- let url = hostport + '/config';
25
- await axios
26
- .get(url, { headers: enrichHeaders(), httpsAgent: httpsAgent() })
27
- .then((res) => {
28
- console.table(res.data['configs'].map((o) => {
29
- return { unique_key: o.unique_key, provider: o.provider, created: o.created_at };
30
- }));
31
- })
32
- .catch((err) => {
33
- console.log(`❌ ${err.response?.data.error || JSON.stringify(err)}`);
34
- });
28
+ .command('init')
29
+ .alias('i')
30
+ .description('Initialize a new Nango project')
31
+ .action(() => {
32
+ init();
35
33
  });
36
34
  program
37
- .command('config:get')
38
- .description('Get an provider configuration.')
39
- .argument('<provider_config_key>', 'The unique key of the provider configuration (chosen by you upon creating this provider configuration).')
40
- .action(async function () {
41
- checkEnvVars();
42
- let url = hostport + `/config/${this.args[0]}`;
43
- await axios
44
- .get(url, { headers: enrichHeaders(), httpsAgent: httpsAgent() })
45
- .then((res) => {
46
- console.table(res.data['config']);
47
- })
48
- .catch((err) => {
49
- console.log(`❌ ${err.response?.data.error || JSON.stringify(err)}`);
50
- });
35
+ .command('generate')
36
+ .alias('g')
37
+ .description('Generate a new Nango integration')
38
+ .action(() => {
39
+ const templateContents = fs.readFileSync(path.resolve(__dirname, './integration.ejs'), 'utf8');
40
+ const cwd = process.cwd();
41
+ const configContents = fs.readFileSync(path.resolve(cwd, `${NANGO_INTEGRATIONS_LOCATION}/${nangoConfigFile}`), 'utf8');
42
+ const configData = yaml.load(configContents);
43
+ const { integrations } = configData;
44
+ const { models } = configData;
45
+ const interfaceDefinitions = buildInterfaces(models);
46
+ fs.writeFileSync(`${NANGO_INTEGRATIONS_LOCATION}/models.ts`, interfaceDefinitions.join('\n'));
47
+ for (let i = 0; i < Object.keys(integrations).length; i++) {
48
+ const providerConfigKey = Object.keys(integrations)[i];
49
+ const syncObject = integrations[providerConfigKey];
50
+ const syncNames = Object.keys(syncObject);
51
+ for (let k = 0; k < syncNames.length; k++) {
52
+ const syncName = syncNames[k];
53
+ const syncData = syncObject[syncName];
54
+ const { returns: models } = syncData;
55
+ const syncNameCamel = syncName
56
+ .split('-')
57
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
58
+ .join('');
59
+ const rendered = ejs.render(templateContents, {
60
+ syncName: syncNameCamel,
61
+ interfaceNames: models.map((model) => {
62
+ const singularModel = model?.charAt(model.length - 1) === 's' ? model.slice(0, -1) : model;
63
+ return `${singularModel.charAt(0).toUpperCase()}${singularModel.slice(1)}`;
64
+ }),
65
+ mappings: models.map((model) => {
66
+ const singularModel = model.charAt(model.length - 1) === 's' ? model.slice(0, -1) : model;
67
+ return {
68
+ name: model,
69
+ type: `${singularModel.charAt(0).toUpperCase()}${singularModel.slice(1)}`
70
+ };
71
+ })
72
+ });
73
+ if (!fs.existsSync(`${NANGO_INTEGRATIONS_LOCATION}/${syncName}.ts`)) {
74
+ fs.writeFileSync(`${NANGO_INTEGRATIONS_LOCATION}/${syncName}.ts`, rendered);
75
+ }
76
+ }
77
+ }
78
+ console.log(chalk.green(`Integration files have been created`));
51
79
  });
52
80
  program
53
- .command('config:create')
54
- .description('Create an provider configuration.')
55
- .argument('<provider_config_key>', 'The unique key of the provider configuration (choose a friendly name, e.g. hubspot_staging).')
56
- .argument('<provider>', 'The provider of the 3rd-party API, must match the template keys in https://nango.dev/oauth-providers (e.g. hubspot).')
57
- .argument('<oauth_client_id>', 'The OAuth Client ID obtained from the API provider.')
58
- .argument('<oauth_client_secret>', 'The OAuth Client Secret obtained from the API provider.')
59
- .argument('<oauth_scopes>', 'The OAuth Scopes obtained from the API provider (comma-separated).')
60
- .action(async function () {
61
- checkEnvVars();
62
- let body = {
63
- provider_config_key: this.args[0],
64
- provider: this.args[1],
65
- oauth_client_id: this.args[2],
66
- oauth_client_secret: this.args[3],
67
- oauth_scopes: this.args[4]
68
- };
69
- let url = hostport + `/config`;
70
- await axios
71
- .post(url, body, { headers: enrichHeaders(), httpsAgent: httpsAgent() })
72
- .then((_) => {
73
- console.log('\n\n✅ Successfully created a new provider configuration!\n\n');
74
- })
75
- .catch((err) => {
76
- console.log(`❌ ${err.response?.data.error || JSON.stringify(err)}`);
77
- });
81
+ .command('tsc')
82
+ .description('Compile the integration files to JavaScript')
83
+ .action(() => {
84
+ tsc();
78
85
  });
79
86
  program
80
- .command('config:edit')
81
- .description('Edit an provider configuration.')
82
- .argument('<provider_config_key>', 'The unique key of the provider configuration (choose a friendly name, e.g. hubspot_staging).')
83
- .argument('<provider>', 'The provider of the 3rd-party API, must match the template keys in https://nango.dev/oauth-providers (e.g. hubspot).')
84
- .argument('<oauth_client_id>', 'The OAuth Client ID obtained from the API provider.')
85
- .argument('<oauth_client_secret>', 'The OAuth Client Secret obtained from the API provider.')
86
- .argument('<oauth_scopes>', 'The OAuth Scopes obtained from the API provider (comma-separated).')
87
+ .command('tsc:watch')
88
+ .description('Watch tsc files while developing. Set --no-compile-interfaces to disable watching the config file')
89
+ .option('--no-compile-interfaces', `Watch the ${nangoConfigFile} and recompile the interfaces on change`, true)
87
90
  .action(async function () {
88
- checkEnvVars();
89
- let body = {
90
- provider_config_key: this.args[0],
91
- provider: this.args[1],
92
- oauth_client_id: this.args[2],
93
- oauth_client_secret: this.args[3],
94
- oauth_scopes: this.args[4]
95
- };
96
- let url = hostport + `/config`;
97
- await axios
98
- .put(url, body, { headers: enrichHeaders(), httpsAgent: httpsAgent() })
99
- .then((_) => {
100
- console.log('\n\n✅ Successfully edited an existing provider configuration!\n\n');
101
- })
102
- .catch((err) => {
103
- console.log(`❌ ${err.response?.data.error || JSON.stringify(err)}`);
104
- });
91
+ const { compileInterfaces } = this.opts();
92
+ if (compileInterfaces) {
93
+ configWatch();
94
+ }
95
+ tscWatch();
105
96
  });
106
97
  program
107
- .command('config:delete')
108
- .description('Delete an provider configuration.')
109
- .argument('<provider_config_key>', 'The unique key of the provider configuration (chosen by you upon creating this provider configuration).')
110
- .action(async function () {
111
- checkEnvVars();
112
- let url = hostport + `/config/${this.args[0]}`;
113
- await axios
114
- .delete(url, { headers: enrichHeaders(), httpsAgent: httpsAgent() })
115
- .then((_) => {
116
- console.log('\n\n✅ Successfully deleted the provider configuration!\n\n');
117
- })
118
- .catch((err) => {
119
- console.log(`❌ ${err.response?.data.error || JSON.stringify(err)}`);
120
- });
98
+ .command('docker:run')
99
+ .description('Run the docker container locally')
100
+ .action(() => {
101
+ dockerRun();
121
102
  });
122
103
  program
123
- .command('connection:get')
124
- .description('Get a connection with credentials.')
125
- .argument('<provider_config_key>', 'The unique key of the provider configuration (chosen by you upon creating this provider configuration).')
126
- .argument('<connection_id>', 'The ID of the Connection.')
127
- .action(async function () {
128
- checkEnvVars();
129
- let url = hostport + `/connection/${this.args[1]}`;
130
- await axios
131
- .get(url, { params: { provider_config_key: this.args[0] }, headers: enrichHeaders(), httpsAgent: httpsAgent() })
132
- .then((res) => {
133
- console.log(res.data);
134
- })
135
- .catch((err) => {
136
- console.log(`❌ ${err.response?.data.error || JSON.stringify(err)}`);
137
- });
104
+ .command('dev')
105
+ .alias('develop')
106
+ .alias('watch')
107
+ .description('Work locally to add integration code')
108
+ .action(() => {
109
+ configWatch();
110
+ tscWatch();
111
+ dockerRun();
138
112
  });
139
113
  program
140
- .command('token:get')
141
- .description('Get an access token.')
142
- .argument('<provider_config_key>', 'The unique key of the provider configuration (chosen by you upon creating this provider configuration).')
143
- .argument('<connection_id>', 'The ID of the Connection.')
114
+ .command('deploy')
115
+ .alias('d')
116
+ .description('Deploy a Nango integration')
117
+ .option('--staging', 'Deploy to the staging instance')
118
+ .option('-v, --version [version]', 'Optional: Set a version of this deployment to tag this integraion with. Can be used for rollbacks.')
119
+ .option('-s, --sync [syncName]', 'Optional deploy only this sync name.')
144
120
  .action(async function () {
121
+ const { staging, version } = this.opts();
122
+ if (!process.env['NANGO_HOSTPORT']) {
123
+ if (staging) {
124
+ setStagingHost();
125
+ }
126
+ else {
127
+ setCloudHost();
128
+ }
129
+ }
130
+ if (hostport !== 'http://localhost:3003' && !process.env['NANGO_SECRET_KEY']) {
131
+ console.log(chalk.red(`NANGO_SECRET_KEY environment variable is not set`));
132
+ return;
133
+ }
145
134
  checkEnvVars();
146
- let url = hostport + `/connection/${this.args[1]}`;
147
- await axios
148
- .get(url, { params: { provider_config_key: this.args[0] }, headers: enrichHeaders(), httpsAgent: httpsAgent() })
149
- .then((response) => {
150
- switch (response.data.credentials.type) {
151
- case 'OAUTH2':
152
- console.table({ token: response.data.credentials.access_token });
153
- break;
154
- case 'OAUTH1':
155
- console.table(`token:${response.data.credentials.oauth_token}\nsecret:${response.data.credentials.oauth_token_secret}`);
156
- break;
157
- default:
158
- throw new Error(`Unrecognized OAuth type '${response.data.credentials.type}' in stored credentials.`);
135
+ tsc();
136
+ const cwd = process.cwd();
137
+ const config = await loadSimplifiedConfig(path.resolve(cwd, NANGO_INTEGRATIONS_LOCATION));
138
+ if (!config) {
139
+ throw new Error(`Error loading the ${nangoConfigFile} file`);
140
+ }
141
+ const postData = [];
142
+ for (const integration of config) {
143
+ const { providerConfigKey, syncs } = integration;
144
+ for (const sync of syncs) {
145
+ const { name: syncName, runs, returns: models, models: model_schema } = sync;
146
+ const { path: integrationFilePath, result: integrationFileResult } = checkForIntegrationFile(syncName, path.resolve(cwd, `${NANGO_INTEGRATIONS_LOCATION}`));
147
+ if (!integrationFileResult) {
148
+ console.log(chalk.red(`No integration file found for ${syncName} at ${integrationFilePath}. Skipping...`));
149
+ continue;
150
+ }
151
+ const body = {
152
+ syncName,
153
+ providerConfigKey,
154
+ models,
155
+ version,
156
+ runs,
157
+ fileBody: fs.readFileSync(integrationFilePath, 'utf8'),
158
+ model_schema: JSON.stringify(model_schema)
159
+ };
160
+ postData.push(body);
159
161
  }
162
+ }
163
+ const url = hostport + `/sync/deploy`;
164
+ await axios
165
+ .post(url, postData, { headers: enrichHeaders(), httpsAgent: httpsAgent() })
166
+ .then((_) => {
167
+ console.log(chalk.green(`Successfully deployed the syncs!`));
160
168
  })
161
- .catch((err) => {
162
- console.log(`❌ ${err.response?.data.error || JSON.stringify(err)}`);
169
+ .catch((_err) => {
170
+ console.log(chalk.red(`Error deploying the syncs`));
163
171
  });
164
172
  });
165
173
  program
166
- .command('connection:list')
167
- .description('List connections without credentials.')
168
- .action(async function () {
169
- checkEnvVars();
170
- let url = hostport + `/connection`;
171
- await axios
172
- .get(url, { headers: enrichHeaders(), httpsAgent: httpsAgent() })
173
- .then((res) => {
174
- console.table(res.data['connections']);
175
- })
176
- .catch((err) => {
177
- console.log(`❌ ${err.response?.data.error || JSON.stringify(err)}`);
178
- });
174
+ .command('sync:config.check')
175
+ .alias('scc')
176
+ .description('Verify the parsed sync config and output the object for verification')
177
+ .action(async () => {
178
+ const cwd = process.cwd();
179
+ const config = await loadSimplifiedConfig(path.resolve(cwd, NANGO_INTEGRATIONS_LOCATION));
180
+ console.log(chalk.green(JSON.stringify(config, null, 2)));
179
181
  });
180
182
  program
181
- .command('connection:delete')
182
- .description('Delete a connection.')
183
- .argument('<provider_config_key>', 'The unique key of the provider configuration (chosen by you upon creating this provider configuration).')
184
- .argument('<connection_id>', 'The ID of the Connection.')
183
+ .command('sync:run')
184
+ .alias('sr')
185
+ .description('Run the sync process to help with debugging')
186
+ .option('-s, --sync <syncName>', 'The name of the sync (e.g. account-sync).')
187
+ .option('-p, --provider <provider_config_key>', 'The unique key of the provider configuration (chosen by you upon creating this provider configuration).')
188
+ .option('-c, --connection <connection_id>', 'The ID of the Connection.')
189
+ .option('-l, --lastSyncDate [lastSyncDate]', 'Optional: last sync date to retrieve records greater than this date')
190
+ .option('-u, --useServerLastSyncDate', 'Optional boolean: use the server stored last sync date to retrieve records greater than this date')
185
191
  .action(async function () {
186
192
  checkEnvVars();
187
- let url = hostport + `/connection/${this.args[1]}`;
188
- await axios
189
- .delete(url, { params: { provider_config_key: this.args[0] }, headers: enrichHeaders(), httpsAgent: httpsAgent() })
190
- .then((_) => {
191
- console.log('\n\n✅ Successfully deleted the connection!\n\n');
192
- })
193
- .catch((err) => {
194
- console.log(`❌ ${err.response?.data.error || JSON.stringify(err)}`);
195
- });
193
+ run(this.args, this.opts());
196
194
  });
197
- program.parseAsync(process.argv);
198
- function enrichHeaders(headers = {}) {
199
- if ((process.env['NANGO_HOSTPORT'] === cloudHost || process.env['NANGO_HOSTPORT'] === stagingHost) && process.env['NANGO_SECRET_KEY']) {
200
- // For Nango Cloud (unified)
201
- headers['Authorization'] = 'Bearer ' + process.env['NANGO_SECRET_KEY'];
202
- }
203
- else if (process.env['NANGO_SECRET_KEY']) {
204
- // For Nango OSS
205
- headers['Authorization'] = 'Basic ' + Buffer.from(process.env['NANGO_SECRET_KEY'] + ':').toString('base64');
206
- }
207
- headers['Accept-Encoding'] = 'application/json';
208
- return headers;
209
- }
210
- function httpsAgent() {
211
- return new https.Agent({
212
- rejectUnauthorized: false
213
- });
214
- }
215
- function checkEnvVars() {
216
- if (hostport === 'http://localhost:3003') {
217
- console.log(`Assuming you are running Nango on localhost:3003 because you did not set the NANGO_HOSTPORT env var.\n\n`);
218
- }
219
- else if (hostport === cloudHost || hostport === stagingHost) {
220
- if (!process.env['NANGO_SECRET_KEY']) {
221
- console.log(`Assuming you are using Nango Cloud but your are lacking the NANGO_SECRET_KEY env var.`);
222
- }
223
- else if (hostport === cloudHost) {
224
- console.log(`Assuming you are using Nango Cloud (because you set the NANGO_HOSTPORT env var to https://api.nango.dev).`);
225
- }
226
- else if (hostport === stagingHost) {
227
- console.log(`Assuming you are using Nango Cloud (because you set the NANGO_HOSTPORT env var to https://api.staging.nango.dev).`);
228
- }
229
- }
230
- else {
231
- console.log(`Assuming you are self-hosting Nango (becauses you set the NANGO_HOSTPORT env var to ${hostport}).`);
232
- }
233
- }
195
+ program.parse();
234
196
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";AAEA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAA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OAAO,CAAC,UAAU,CAAC;KACnB,KAAK,CAAC,IAAI,CAAC;KACX,WAAW,CAAC,6CAA6C,CAAC;KAC1D,MAAM,CAAC,uBAAuB,EAAE,2CAA2C,CAAC;KAC5E,MAAM,CAAC,sCAAsC,EAAE,yGAAyG,CAAC;KACzJ,MAAM,CAAC,kCAAkC,EAAE,2BAA2B,CAAC;KACvE,MAAM,CAAC,mCAAmC,EAAE,qEAAqE,CAAC;KAClH,MAAM,CAAC,6BAA6B,EAAE,mGAAmG,CAAC;KAC1I,MAAM,CAAC,KAAK;IACT,YAAY,EAAE,CAAC;IACf,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;AAChC,CAAC,CAAC,CAAC;AAEP,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { NangoSync } from '@nangohq/node';
2
+ import { <%= interfaceNames.join(', ') %> } from './models';
3
+
4
+ export default async function fetchData(nango: NangoSync): Promise<{<% for (let i = 0; i < mappings.length; i++) { %><%= mappings[i].name %>: <%= mappings[i].type %>[]<% if (i !== mappings.length - 1) { %>, <% } %><% } %>}> {
5
+ /**
6
+ * Rest of the integration code goes below.
7
+ *
8
+ * Example:
9
+ * const response = await nango.get({
10
+ * endpoint: 'repos/NangoHQ/nango/issues'
11
+ * });
12
+ *
13
+ * const issues = response.data.map((ghIssue) => {
14
+ * const issue: Issue = {
15
+ * id: ghIssue.id,
16
+ * title: ghIssue.title,
17
+ * description: ghIssue.body,
18
+ * status: ghIssue.status,
19
+ * author: {
20
+ * avatar_url: ghIssue.user.avatar_url,
21
+ * }
22
+ * };
23
+ *
24
+ * return issue;
25
+ * });
26
+ *
27
+ * return { issues };
28
+ */
29
+ }
@@ -0,0 +1,35 @@
1
+ const tableName = '<%= tableName %>'';
2
+
3
+ exports.up = function (knex, _) {
4
+ return knex.schema.withSchema('nango').createTable(tableName, function (table) {
5
+ return knex.schema.withSchema('nango').createTable(tableName, function (table) {
6
+ table.increments('id').primary();
7
+ <% data.forEach(function(model) { %>
8
+ <% Object.keys(model).forEach(function(prop) { %>
9
+ <% if (prop === 'id') { return; } %>
10
+ <% const type = model[prop]; %>
11
+ <% switch (type) { %>
12
+ <% case 'integer': %>
13
+ table.integer('<%= prop %>');
14
+ <% break; %>
15
+ <% case 'char': %>
16
+ table.string('<%= prop %>', 255);
17
+ <% break; %>
18
+ <% case 'text': %>
19
+ table.text('<%= prop %>');
20
+ <% break; %>
21
+ <% case 'timestamp': %>
22
+ table.timestamp('<%= prop %>');
23
+ <% break; %>
24
+ <% default: %>
25
+ throw new Error(`Unknown type <%= type %> for column <%= prop %>`);
26
+ <% } %>
27
+ <% }); %>
28
+ <% }); %>
29
+ });
30
+ };
31
+
32
+ exports.down = function (knex, _) {
33
+ return knex.schema.withSchema('nango').dropTable(tableName);
34
+ };
35
+
package/dist/sync.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ interface RunArgs {
2
+ sync: string;
3
+ provider: string;
4
+ connection: string;
5
+ lastSyncDate?: string;
6
+ useServerLastSyncDate?: boolean;
7
+ }
8
+ export declare const init: () => void;
9
+ export declare const run: (args: string[], options: RunArgs) => Promise<void>;
10
+ export declare const tsc: () => void;
11
+ export declare const tscWatch: () => void;
12
+ export declare const configWatch: () => void;
13
+ /**
14
+ * Docker Run
15
+ * @desc spawn a child process to run the docker compose located in the cli
16
+ * Look into https://www.npmjs.com/package/docker-compose to avoid dependency maybe?
17
+ */
18
+ export declare const dockerRun: () => void;
19
+ export {};
package/dist/sync.js ADDED
@@ -0,0 +1,223 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import yaml from 'js-yaml';
4
+ import chalk from 'chalk';
5
+ import chokidar from 'chokidar';
6
+ import * as tsNode from 'ts-node';
7
+ import glob from 'glob';
8
+ import * as dotenv from 'dotenv';
9
+ import { spawn } from 'child_process';
10
+ import { cloudHost, stagingHost, SyncType, syncRunService, nangoConfigFile } from '@nangohq/shared';
11
+ import { hostport, getConnection, NANGO_INTEGRATIONS_LOCATION, buildInterfaces } from './utils.js';
12
+ dotenv.config();
13
+ export const init = () => {
14
+ const data = {
15
+ integrations: {
16
+ 'github-prod': {
17
+ 'github-users': {
18
+ runs: 'every hour',
19
+ returns: ['users']
20
+ },
21
+ 'github-issues': {
22
+ runs: 'every half hour',
23
+ returns: ['issues']
24
+ }
25
+ },
26
+ 'asana-dev': {
27
+ 'asana-projects': {
28
+ runs: 'every hour',
29
+ returns: ['projects']
30
+ }
31
+ }
32
+ },
33
+ models: {
34
+ issues: {
35
+ id: 'integer',
36
+ title: 'string',
37
+ description: 'string',
38
+ status: 'string',
39
+ author: {
40
+ avatar_url: 'string'
41
+ }
42
+ },
43
+ projects: {
44
+ id: 'number',
45
+ type: 'string'
46
+ },
47
+ users: {
48
+ id: 'number',
49
+ name: 'string'
50
+ }
51
+ }
52
+ };
53
+ const yamlData = yaml.dump(data);
54
+ if (!fs.existsSync(NANGO_INTEGRATIONS_LOCATION)) {
55
+ fs.mkdirSync(NANGO_INTEGRATIONS_LOCATION);
56
+ }
57
+ fs.writeFileSync(`${NANGO_INTEGRATIONS_LOCATION}/${nangoConfigFile}`, yamlData);
58
+ console.log(chalk.green(`${nangoConfigFile} file has been created`));
59
+ };
60
+ export const run = async (args, options) => {
61
+ let syncName, providerConfigKey, connectionId, suppliedLastSyncDate, useServerLastSyncDate;
62
+ if (args.length > 0) {
63
+ [syncName, providerConfigKey, connectionId, suppliedLastSyncDate, useServerLastSyncDate] = args;
64
+ }
65
+ if (Object.keys(options).length > 0) {
66
+ ({ sync: syncName, provider: providerConfigKey, connection: connectionId, lastSyncDate: suppliedLastSyncDate, useServerLastSyncDate } = options);
67
+ }
68
+ if (!syncName) {
69
+ console.log(chalk.red('Sync name is required'));
70
+ return;
71
+ }
72
+ if (!providerConfigKey) {
73
+ console.log(chalk.red('Provider config key is required'));
74
+ return;
75
+ }
76
+ if (!connectionId) {
77
+ console.log(chalk.red('Connection id is required'));
78
+ return;
79
+ }
80
+ const nangoConnection = (await getConnection(providerConfigKey, connectionId, {
81
+ 'Nango-Is-Sync': true,
82
+ 'Nango-Is-Dry-Run': true
83
+ }));
84
+ if (!nangoConnection) {
85
+ console.log(chalk.red('Connection not found'));
86
+ return;
87
+ }
88
+ if (hostport === cloudHost || hostport === stagingHost) {
89
+ process.env['NANGO_CLOUD'] = 'true';
90
+ }
91
+ let lastSyncDate = null;
92
+ if (suppliedLastSyncDate) {
93
+ lastSyncDate = new Date(suppliedLastSyncDate);
94
+ }
95
+ if (!useServerLastSyncDate) {
96
+ lastSyncDate = null;
97
+ }
98
+ const cwd = process.cwd();
99
+ const syncRun = new syncRunService({
100
+ writeToDb: false,
101
+ nangoConnection,
102
+ syncName,
103
+ syncType: SyncType.INITIAL,
104
+ loadLocation: path.resolve(cwd, `${NANGO_INTEGRATIONS_LOCATION}`)
105
+ });
106
+ try {
107
+ const results = await syncRun.run(lastSyncDate, true);
108
+ console.log(results);
109
+ process.exit(0);
110
+ }
111
+ catch (e) {
112
+ process.exit(1);
113
+ }
114
+ };
115
+ export const tsc = () => {
116
+ const cwd = process.cwd();
117
+ const tsconfig = fs.readFileSync('./node_modules/nango/tsconfig.dev.json', 'utf8');
118
+ const distDir = path.resolve(cwd, `${NANGO_INTEGRATIONS_LOCATION}/dist`);
119
+ if (!fs.existsSync(distDir)) {
120
+ fs.mkdirSync(distDir);
121
+ }
122
+ const rawNangoIntegrationLocation = NANGO_INTEGRATIONS_LOCATION.replace('./', '');
123
+ const compiler = tsNode.create({
124
+ compilerOptions: JSON.parse(tsconfig).compilerOptions
125
+ });
126
+ const integrationFiles = glob.sync(path.resolve(cwd, `${NANGO_INTEGRATIONS_LOCATION}/*.ts`));
127
+ for (const filePath of integrationFiles) {
128
+ try {
129
+ const result = compiler.compile(fs.readFileSync(filePath, 'utf8'), filePath);
130
+ const jsFilePath = path.join(path.dirname(filePath), path.basename(filePath, '.ts') + '.js');
131
+ const distJSFilePath = jsFilePath.replace(rawNangoIntegrationLocation, `${rawNangoIntegrationLocation}/dist`);
132
+ fs.writeFileSync(distJSFilePath, result);
133
+ console.log(chalk.green(`Compiled "${filePath}" successfully`));
134
+ }
135
+ catch (error) {
136
+ console.error(`Error compiling "${filePath}":`);
137
+ console.error(error);
138
+ }
139
+ }
140
+ };
141
+ export const tscWatch = () => {
142
+ const cwd = process.cwd();
143
+ const tsconfig = fs.readFileSync('./node_modules/nango/tsconfig.dev.json', 'utf8');
144
+ const watchPath = [`${NANGO_INTEGRATIONS_LOCATION}/*.ts`, `${NANGO_INTEGRATIONS_LOCATION}/${nangoConfigFile}`];
145
+ const rawNangoIntegrationLocation = NANGO_INTEGRATIONS_LOCATION.replace('./', '');
146
+ const watcher = chokidar.watch(watchPath, {
147
+ ignoreInitial: false,
148
+ ignored: (filePath) => {
149
+ return filePath === `${rawNangoIntegrationLocation}/models.ts`;
150
+ }
151
+ });
152
+ const distDir = path.resolve(cwd, `${NANGO_INTEGRATIONS_LOCATION}/dist`);
153
+ if (!fs.existsSync(distDir)) {
154
+ fs.mkdirSync(distDir);
155
+ }
156
+ watcher.on('add', (filePath) => {
157
+ if (filePath === `${rawNangoIntegrationLocation}/${nangoConfigFile}`) {
158
+ return;
159
+ }
160
+ compileFile(filePath);
161
+ });
162
+ watcher.on('change', (filePath) => {
163
+ if (filePath === `${rawNangoIntegrationLocation}/${nangoConfigFile}`) {
164
+ // config file changed, re-compile each ts file
165
+ const integrationFiles = glob.sync(path.resolve(cwd, `${NANGO_INTEGRATIONS_LOCATION}/*.ts`));
166
+ for (const file of integrationFiles) {
167
+ compileFile(file);
168
+ }
169
+ return;
170
+ }
171
+ compileFile(filePath);
172
+ });
173
+ function compileFile(filePath) {
174
+ const compiler = tsNode.create({
175
+ compilerOptions: JSON.parse(tsconfig).compilerOptions
176
+ });
177
+ try {
178
+ const result = compiler.compile(fs.readFileSync(filePath, 'utf8'), filePath);
179
+ const jsFilePath = path.join(path.dirname(filePath), path.basename(filePath, '.ts') + '.js');
180
+ const distJSFilePath = jsFilePath.replace(rawNangoIntegrationLocation, `${rawNangoIntegrationLocation}/dist`);
181
+ fs.writeFileSync(distJSFilePath, result);
182
+ console.log(chalk.green(`Compiled ${filePath} successfully`));
183
+ }
184
+ catch (error) {
185
+ console.error(`Error compiling ${filePath}:`);
186
+ console.error(error);
187
+ return;
188
+ }
189
+ }
190
+ };
191
+ export const configWatch = () => {
192
+ const watchPath = `${NANGO_INTEGRATIONS_LOCATION}/${nangoConfigFile}`;
193
+ const watcher = chokidar.watch(watchPath, { ignoreInitial: true });
194
+ watcher.on('add', (filePath) => {
195
+ buildInterface(filePath);
196
+ });
197
+ watcher.on('change', (filePath) => {
198
+ buildInterface(filePath);
199
+ });
200
+ function buildInterface(filePath) {
201
+ const cwd = process.cwd();
202
+ const configContents = fs.readFileSync(path.resolve(cwd, `${NANGO_INTEGRATIONS_LOCATION}/${nangoConfigFile}`), 'utf8');
203
+ const configData = yaml.load(configContents);
204
+ const { models } = configData;
205
+ const interfaces = buildInterfaces(models);
206
+ fs.writeFileSync(`${NANGO_INTEGRATIONS_LOCATION}/models.ts`, interfaces.join('\n'));
207
+ console.log(chalk.green(`${filePath} was updated. The interface file (${NANGO_INTEGRATIONS_LOCATION}/models.ts) was updated to reflect the updated config`));
208
+ }
209
+ };
210
+ /**
211
+ * Docker Run
212
+ * @desc spawn a child process to run the docker compose located in the cli
213
+ * Look into https://www.npmjs.com/package/docker-compose to avoid dependency maybe?
214
+ */
215
+ export const dockerRun = () => {
216
+ const cwd = process.cwd();
217
+ spawn('docker', ['compose', '-f', 'node_modules/nango/docker/docker-compose.yaml', '--project-directory', '.', 'up', '--build'], {
218
+ cwd,
219
+ detached: false,
220
+ stdio: 'inherit'
221
+ });
222
+ };
223
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.js","sourceRoot":"","sources":["../lib/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OA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AC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACpF,OAAO,CAAC,GAAG,CACP,KAAK,CAAC,KAAK,CAAC,GAAG,QAAQ,qCAAqC,2BAA2B,uDAAuD,CAAC,CAClJ,CAAC;IACN,CAAC;AACL,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE;IAC1B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAE1B,KAAK,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,+CAA+C,EAAE,qBAAqB,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE;QAC7H,GAAG;QACH,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,SAAS;KACnB,CAAC,CAAC;AACP,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import https from 'https';
3
+ import type { NangoModel } from '@nangohq/shared';
4
+ export declare const NANGO_INTEGRATIONS_LOCATION: string;
5
+ export declare const hostport: string;
6
+ export declare function setCloudHost(): void;
7
+ export declare function setStagingHost(): void;
8
+ export declare function checkEnvVars(): void;
9
+ export declare function getConnection(providerConfigKey: string, connectionId: string, headers?: Record<string, string | boolean>): Promise<any>;
10
+ export declare function enrichHeaders(headers?: Record<string, string | number | boolean>): Record<string, string | number | boolean>;
11
+ export declare function httpsAgent(): https.Agent;
12
+ export declare function getFieldType(rawField: string | NangoModel): string;
13
+ export declare function buildInterfaces(models: NangoModel): (string | undefined)[];
package/dist/utils.js ADDED
@@ -0,0 +1,135 @@
1
+ import https from 'https';
2
+ import axios from 'axios';
3
+ import { cloudHost, stagingHost } from '@nangohq/shared';
4
+ import * as dotenv from 'dotenv';
5
+ dotenv.config();
6
+ export const NANGO_INTEGRATIONS_LOCATION = process.env['NANGO_INTEGRATIONS_LOCATION'] || './nango-integrations';
7
+ let parsedHostport = process.env['NANGO_HOSTPORT'] || 'http://localhost:3003';
8
+ if (parsedHostport.slice(-1) === '/') {
9
+ parsedHostport = parsedHostport.slice(0, -1);
10
+ }
11
+ export const hostport = parsedHostport;
12
+ export function setCloudHost() {
13
+ process.env['NANGO_HOSTPORT'] = cloudHost;
14
+ }
15
+ export function setStagingHost() {
16
+ process.env['NANGO_HOSTPORT'] = stagingHost;
17
+ }
18
+ export function checkEnvVars() {
19
+ if (hostport === 'http://localhost:3003') {
20
+ console.log(`Assuming you are running Nango on localhost:3003 because you did not set the NANGO_HOSTPORT env var.\n\n`);
21
+ }
22
+ else if (hostport === cloudHost || hostport === stagingHost) {
23
+ if (!process.env['NANGO_SECRET_KEY']) {
24
+ console.log(`Assuming you are using Nango Cloud but you are missing the NANGO_SECRET_KEY env var.`);
25
+ }
26
+ else if (hostport === cloudHost) {
27
+ console.log(`Assuming you are using Nango Cloud (because you set the NANGO_HOSTPORT env var to https://api.nango.dev).`);
28
+ }
29
+ else if (hostport === stagingHost) {
30
+ console.log(`Assuming you are using Nango Cloud (because you set the NANGO_HOSTPORT env var to https://api.staging.nango.dev).`);
31
+ }
32
+ }
33
+ else {
34
+ console.log(`Assuming you are self-hosting Nango (because you set the NANGO_HOSTPORT env var to ${hostport}).`);
35
+ }
36
+ }
37
+ export async function getConnection(providerConfigKey, connectionId, headers) {
38
+ checkEnvVars();
39
+ const url = hostport + `/connection/${connectionId}`;
40
+ return await axios
41
+ .get(url, { params: { provider_config_key: providerConfigKey }, headers: enrichHeaders(headers), httpsAgent: httpsAgent() })
42
+ .then((res) => {
43
+ return res.data;
44
+ })
45
+ .catch((err) => {
46
+ console.log(`❌ ${err.response?.data.error || JSON.stringify(err)}`);
47
+ });
48
+ }
49
+ export function enrichHeaders(headers = {}) {
50
+ if ((process.env['NANGO_HOSTPORT'] === cloudHost || process.env['NANGO_HOSTPORT'] === stagingHost) && process.env['NANGO_SECRET_KEY']) {
51
+ // For Nango Cloud (unified)
52
+ headers['Authorization'] = 'Bearer ' + process.env['NANGO_SECRET_KEY'];
53
+ }
54
+ else if (process.env['NANGO_SECRET_KEY']) {
55
+ // For Nango OSS
56
+ headers['Authorization'] = 'Basic ' + Buffer.from(process.env['NANGO_SECRET_KEY'] + ':').toString('base64');
57
+ }
58
+ headers['Accept-Encoding'] = 'application/json';
59
+ return headers;
60
+ }
61
+ export function httpsAgent() {
62
+ return new https.Agent({
63
+ rejectUnauthorized: false
64
+ });
65
+ }
66
+ export function getFieldType(rawField) {
67
+ if (typeof rawField === 'string') {
68
+ let field = rawField;
69
+ let hasNull = false;
70
+ let hasUndefined = false;
71
+ let tsType = '';
72
+ if (field.indexOf('null') !== -1) {
73
+ field = field.replace(/\s*\|\s*null\s*/g, '');
74
+ hasNull = true;
75
+ }
76
+ if (field.indexOf('undefined') !== -1) {
77
+ field = field.replace(/\s*\|\s*undefined\s*/g, '');
78
+ hasUndefined = true;
79
+ }
80
+ switch (field) {
81
+ case 'boolean':
82
+ case 'bool':
83
+ tsType = 'boolean';
84
+ break;
85
+ case 'string':
86
+ tsType = 'string';
87
+ break;
88
+ case 'char':
89
+ tsType = 'string';
90
+ break;
91
+ case 'integer':
92
+ case 'int':
93
+ case 'number':
94
+ tsType = 'number';
95
+ break;
96
+ case 'date':
97
+ tsType = 'Date';
98
+ break;
99
+ }
100
+ if (hasNull) {
101
+ tsType = `${tsType} | null`;
102
+ }
103
+ if (hasUndefined) {
104
+ tsType = `${tsType} | undefined`;
105
+ }
106
+ return tsType;
107
+ }
108
+ else {
109
+ const nestedFields = Object.keys(rawField)
110
+ .map((fieldName) => ` ${fieldName}: ${getFieldType(rawField[fieldName])};`)
111
+ .join('\n');
112
+ return `{\n${nestedFields}\n}`;
113
+ }
114
+ }
115
+ export function buildInterfaces(models) {
116
+ const interfaceDefinitions = Object.keys(models).map((modelName) => {
117
+ if (modelName.charAt(0) === '_') {
118
+ return;
119
+ }
120
+ const fields = models[modelName];
121
+ const singularModelName = modelName.charAt(modelName.length - 1) === 's' ? modelName.slice(0, -1) : modelName;
122
+ const interfaceName = `${singularModelName.charAt(0).toUpperCase()}${singularModelName.slice(1)}`;
123
+ const fieldDefinitions = Object.keys(fields)
124
+ .map((fieldName) => {
125
+ const fieldModel = fields[fieldName];
126
+ const fieldType = getFieldType(fieldModel);
127
+ return ` ${fieldName}: ${fieldType};`;
128
+ })
129
+ .join('\n');
130
+ const interfaceDefinition = `export interface ${interfaceName} {\n${fieldDefinitions}\n}\n`;
131
+ return interfaceDefinition;
132
+ });
133
+ return interfaceDefinitions;
134
+ }
135
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,MAAM,CAAC,MAAM,2BAA2B,GAAG,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,IAAI,sBAAsB,CAAC;AAEhH,IAAI,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,uBAAuB,CAAC;AAE9E,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;IAClC,cAAc,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CAChD;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,cAAc,CAAC;AAEvC,MAAM,UAAU,YAAY;IACxB,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,GAAG,SAAS,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,cAAc;IAC1B,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,GAAG,WAAW,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,YA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ACV;QACD,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAe,CAAC;QAC/C,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9G,MAAM,aAAa,GAAG,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAClG,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;aACvC,GAAG,CAAC,CAAC,SAAiB,EAAE,EAAE;YACvB,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAwB,CAAC;YAC5D,MAAM,SAAS,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;YAC3C,OAAO,KAAK,SAAS,KAAK,SAAS,GAAG,CAAC;QAC3C,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QAChB,MAAM,mBAAmB,GAAG,oBAAoB,aAAa,OAAO,gBAAgB,OAAO,CAAC;QAC5F,OAAO,mBAAmB,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,OAAO,oBAAoB,CAAC;AAChC,CAAC"}
@@ -0,0 +1,68 @@
1
+ version: '3.9'
2
+ services:
3
+ nango-db:
4
+ image: postgres
5
+ container_name: nango-db
6
+ environment:
7
+ POSTGRES_PASSWORD: nango
8
+ POSTGRES_USER: nango
9
+ POSTGRES_DB: nango
10
+ ports:
11
+ - '${NANGO_DB_PORT:-5432}:5432'
12
+ volumes:
13
+ - ./nango-data:/var/lib/postgresql/data
14
+ networks:
15
+ - nango
16
+
17
+ nango-server:
18
+ image: nangohq/nango-server:0.20.1
19
+ container_name: nango-server
20
+ environment:
21
+ - TEMPORAL_ADDRESS=temporal:7233
22
+ - NANGO_DB_MIGRATION_FOLDER=/usr/nango-server/src/packages/shared/lib/db/migrations
23
+ - NANGO_CALLBACK_URL=${NANGO_CALLBACK_URL:-http://localhost:3003/oauth/callback}
24
+ restart: always
25
+ ports:
26
+ - '3003:3003'
27
+ depends_on:
28
+ - nango-db
29
+ volumes:
30
+ - "${NANGO_INTEGRATIONS_LOCATION:-./nango-integrations}:/usr/nango-server/src/packages/shared/dist/lib/nango-integrations"
31
+ networks:
32
+ - nango
33
+
34
+ nango-worker:
35
+ image: nangohq/nango-worker:0.20.1
36
+ container_name: nango-worker
37
+ restart: always
38
+ ports:
39
+ - '3004:3004'
40
+ environment:
41
+ - TEMPORAL_ADDRESS=temporal:7233
42
+ depends_on:
43
+ - nango-db
44
+ - temporal
45
+ volumes:
46
+ - "${NANGO_INTEGRATIONS_LOCATION:-./nango-integrations}:/usr/nango-worker/src/packages/shared/dist/lib/nango-integrations"
47
+ networks:
48
+ - nango
49
+
50
+ temporal:
51
+ image: temporalio/auto-setup
52
+ container_name: temporal
53
+ depends_on:
54
+ - nango-db
55
+ environment:
56
+ - DB=postgresql
57
+ - DB_PORT=5432
58
+ - POSTGRES_USER=nango
59
+ - POSTGRES_PWD=nango
60
+ - POSTGRES_SEEDS=nango-db
61
+ - LOG_LEVEL=error
62
+ ports:
63
+ - 7233:7233
64
+ networks:
65
+ - nango
66
+
67
+ networks:
68
+ nango:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nango",
3
- "version": "0.17.6",
3
+ "version": "0.20.1",
4
4
  "description": "Nango's CLI tool.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -13,18 +13,51 @@
13
13
  "directory": "packages/cli"
14
14
  },
15
15
  "license": "SEE LICENSE IN LICENSE FILE IN GIT REPOSITORY",
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "copyfiles": "copyfiles -u 1 lib/*.ejs dist",
19
+ "postbuild": "npm run copyfiles",
20
+ "dev": "npm run copyfiles && tsc -w"
21
+ },
16
22
  "dependencies": {
23
+ "@nangohq/shared": "0.20.1",
24
+ "@vercel/ncc": "^0.36.1",
17
25
  "axios": "^1.2.0",
18
- "commander": "^9.4.0"
26
+ "byots": "^5.0.0-dev.20221103.1.34",
27
+ "chokidar": "^3.5.3",
28
+ "commander": "^10.0.1",
29
+ "copyfiles": "^2.4.1",
30
+ "dotenv": "^16.0.3",
31
+ "ejs": "^3.1.9",
32
+ "esbuild": "^0.17.19",
33
+ "figlet": "^1.6.0",
34
+ "js-yaml": "^4.1.0",
35
+ "memfs": "^3.5.1",
36
+ "ora": "^6.3.1",
37
+ "ts-node": "^10.9.1",
38
+ "typescript": "^5.0.4"
19
39
  },
20
40
  "devDependencies": {
21
- "@types/commander": "^2.12.2"
41
+ "@babel/core": "^7.22.1",
42
+ "@babel/preset-env": "^7.22.4",
43
+ "@babel/preset-typescript": "^7.21.5",
44
+ "@types/commander": "^2.12.2",
45
+ "@types/ejs": "^3.1.2",
46
+ "@types/figlet": "^1.5.6",
47
+ "@types/glob": "^8.1.0",
48
+ "@types/node": "^20.1.4",
49
+ "babel-loader": "^9.1.2",
50
+ "webpack": "^5.85.1",
51
+ "webpack-cli": "^5.1.3",
52
+ "webpack-node-externals": "^3.0.0"
22
53
  },
23
54
  "engines": {
24
55
  "node": ">=16.7"
25
56
  },
26
57
  "files": [
27
58
  "dist/**/*",
59
+ "docker/**/*",
60
+ "tsconfig.dev.json",
28
61
  "!**/*.json",
29
62
  "README.md"
30
63
  ]
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "target": "ES5",
5
+ "strict": true,
6
+ "esModuleInterop": true,
7
+ "skipLibCheck": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "moduleResolution": "node",
10
+ "allowUnusedLabels": false,
11
+ "allowUnreachableCode": false,
12
+ "exactOptionalPropertyTypes": true,
13
+ "noFallthroughCasesInSwitch": true,
14
+ "noImplicitOverride": true,
15
+ "noImplicitReturns": true,
16
+ "noPropertyAccessFromIndexSignature": true,
17
+ "noUncheckedIndexedAccess": true,
18
+ "noUnusedLocals": true,
19
+ "noUnusedParameters": true,
20
+ "declaration": false,
21
+ "sourceMap": false,
22
+ "composite": false,
23
+ "checkJs": false,
24
+ "rootDir": "nango-integrations",
25
+ "outDir": "nango-integrations/dist"
26
+ },
27
+ "include": ["nango-integrations"],
28
+ "exclude": ["node_modules"]
29
+ }