-
Notifications
You must be signed in to change notification settings - Fork 53
/
repl.js
executable file
·84 lines (70 loc) · 1.88 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
#!/usr/bin/env node
require('source-map-support').install();
require('core-js/stable');
const repl = require('repl');
const args = require('yargs').argv;
process.on('unhandledRejection', (err) => {
console.log(err, err.stack);
});
let packageInfo;
let EasyPostClient;
if (args.local) {
packageInfo = require('./package.json');
EasyPostClient = require(`./${args.local}`).default;
} else {
packageInfo = require('@easypost/api/package.json');
EasyPostClient = require('@easypost/api');
}
console.log(`Starting ${packageInfo.name} v${packageInfo.version} repl`);
console.log('Enter `help()` for information.');
let client;
if (process.env.API_KEY) {
client = new EasyPostClient(process.env.API_KEY);
} else {
console.log(
[
'Create an instance by using `api = new EasyPostClient(apikey)`, or restart',
'the repl with an API_KEY environment variable.',
].join(' '),
);
}
const local = repl.start('$> ');
function help() {
const helpText = [
'To try out the EasyPostClient, 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.EasyPostClient = EasyPostClient;
local.context.client = client;
local.context.help = help;