forked from EasyPost/easypost-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.js
executable file
·87 lines (69 loc) · 1.89 KB
/
repl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env node
/* eslint import/no-extraneous-dependencies: 0, global-require: 0, import/no-unresolved: 0, no-console: 0, max-len: 0 */
require('source-map-support').install();
require('core-js/stable');
const args = require('yargs').argv;
const repl = require('repl');
process.on('unhandledRejection', (err) => {
console.log(err, err.stack);
});
let packageInfo;
let API;
if (args.local) {
packageInfo = require('./package.json');
API = require(`./${args.local}`).default;
} else {
packageInfo = require('@easypost/api/package.json');
API = require('@easypost/api');
}
console.log(`Starting ${packageInfo.name} v${packageInfo.version} repl`);
console.log('Enter `help()` for information.');
let api;
if (process.env.API_KEY) {
api = new API(process.env.API_KEY);
} else {
console.log([
'Create an instance by using `api = new API(apikey)`, or restart',
'the repl with an API_KEY environment variable.',
].join(' '));
}
const local = repl.start('$> ');
function help() {
const helpText = [
'To try out the API, use the available instance of `api` to make requests.',
'For example, try writing: `api.Address.all();`',
'Sample data is also available: toAddress, fromAddress.',
].join(' ');
console.log(helpText);
}
local.context.toAddress = {
name: 'Dr. Steve Brule',
street1: '179 N Harbor Dr',
city: 'Redondo Beach',
state: 'CA',
zip: '90277',
country: 'US',
phone: '310-808-5243',
};
local.context.fromAddress = {
name: 'EasyPost',
street1: '118 2nd Street',
street2: '4th Floor',
city: 'San Francisco',
state: 'CA',
zip: '94105',
phone: '415-123-4567',
};
local.context.badAddress = {
verify: ['delivery'],
street1: 'UNDELIVERABLE ST',
city: 'SAN FRANCISCO',
state: 'CA',
zip: '94104',
country: 'US',
company: 'EasyPost',
phone: '415-123-4567',
};
local.context.API = API;
local.context.api = api;
local.context.help = help;