-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
64 lines (51 loc) · 1.5 KB
/
index.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
'use strict'
const APIWrapperCore = require('./core')
const APIWrapper = function(options) {
if (typeof options === 'function') {
this.options = {
apiInstance: options
}
} else {
this.options = options
this.options.appId = this.options.appId || 'DADI API wrapper'
this.options.port = this.options.port || 80
this.options.tokenUrl = this.options.tokenUrl || '/token'
const walletPath =
__dirname +
'/.wallet/token.' +
this._slugify(options.uri + options.port) +
'.' +
(options.credentials
? this._slugify(options.credentials.clientId)
: '-') +
'.json'
this.passportOptions = {
accessToken: options.accessToken,
issuer: {
uri: options.uri,
port: options.port,
endpoint: options.tokenUrl
},
credentials: options.credentials,
wallet: 'file',
walletOptions: {
path: walletPath
}
}
}
this.options.callback = this._processRequest.bind(this)
}
APIWrapper.prototype = new APIWrapperCore()
// -----------------------------------------
// Attach helpers
// -----------------------------------------
require('./lib/helpers')(APIWrapper)
// -----------------------------------------
// Attach filters
// -----------------------------------------
require('./lib/filters')(APIWrapper)
// -----------------------------------------
// Attach terminators
// -----------------------------------------
require('./lib/terminators')(APIWrapper)
module.exports = APIWrapper