-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
127 lines (106 loc) · 4.02 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'use strict'
const Trailpack = require('trailpack')
const _ = require('lodash')
const lib = require('./lib')
module.exports = class ProxyCartTrailpack extends Trailpack {
/**
* Validates Configs
*/
validate () {
// Packs
if (!_.includes(_.keys(this.app.packs), 'express')) {
return Promise.reject(new Error('Trailpack-proxy-cart currently only works with express!'))
}
if (!_.includes(_.keys(this.app.packs), 'proxy-sequelize')) {
return Promise.reject(new Error('Trailpack-proxy-cart currently only works with trailpack-proxy-sequelize!'))
}
if (!_.includes(_.keys(this.app.packs), 'proxy-engine')) {
return Promise.reject(new Error('Trailpack-proxy-cart requires trailpack-proxy-engine!'))
}
if (!_.includes(_.keys(this.app.packs), 'proxy-permissions')) {
return Promise.reject(new Error('Trailpack-proxy-cart requires trailpack-proxy-permissions!'))
}
if (!_.includes(_.keys(this.app.packs), 'proxy-passport')) {
return Promise.reject(new Error('Trailpack-proxy-cart requires trailpack-proxy-passport!'))
}
if (!_.includes(_.keys(this.app.packs), 'proxy-notifications')) {
return Promise.reject(new Error('Trailpack-proxy-cart requires trailpack-proxy-notifications!'))
}
if (!_.includes(_.keys(this.app.packs), 'proxy-cart-countries')) {
return Promise.reject(new Error('Trailpack-proxy-cart requires trailpack-proxy-cart-countries!'))
}
if (!_.includes(_.keys(this.app.packs), 'proxy-generics')) {
return Promise.reject(new Error('Trailpack-proxy-cart requires trailpack-proxy-generics!'))
}
// Configs
if (!this.app.config.proxyEngine) {
return Promise.reject(new Error('No configuration found at config.proxyEngine!'))
}
if (!this.app.config.proxyCart) {
return Promise.reject(new Error('No configuration found at config.proxyCart!'))
}
if (!this.app.config.proxyNotifications) {
return Promise.reject(new Error('No configuration found at config.proxyCart!'))
}
if (!this.app.config.proxyGenerics) {
return Promise.reject(new Error('No configuration found at config.proxyGenerics!'))
}
if (!this.app.config.proxyPermissions) {
return Promise.reject(new Error('No configuration found at config.proxyPermissions!'))
}
if (!this.app.config.proxyPassport) {
return Promise.reject(new Error('No configuration found at config.proxyPassport!'))
}
if (
this.app.config.policies
&& this.app.config.policies['*']
&& this.app.config.policies['*'].indexOf('CheckPermissions.checkRoute') === -1
) {
this.app.log.warn('ProxyCart Routes are unlocked! add \'*\' : [\'CheckPermissions.checkRoute\'] to config/policies.js')
}
return Promise.all([
lib.Validator.validateDatabase.config(this.app.config.database),
lib.Validator.validateProxyCart.config(this.app.config.proxyCart),
lib.Validator.validateMiddleware.config(this.app.config.web.middlewares)
])
}
/**
* Adds Routes, Policies, Generics, and Agenda
*/
configure () {
return Promise.all([
lib.ProxyCart.configure(this.app),
lib.ProxyCart.addPolicies(this.app),
lib.ProxyCart.addRoutes(this.app),
lib.ProxyCart.resolveGenerics(this.app),
lib.ProxyCart.copyDefaults(this.app),
lib.ProxyCart.addCrons(this.app),
lib.ProxyCart.addEvents(this.app),
lib.ProxyCart.addTasks(this.app)
])
}
/**
* Loads default shop and country fixtures
*/
initialize () {
return Promise.all([
lib.Utils.buildShopFixtures(this.app)
.then(fixtures => {
this.shopFixtures = fixtures
return lib.Utils.loadShopFixtures(this.app)
}),
lib.Utils.buildCountryFixtures(this.app)
.then(fixtures => {
this.countryFixtures = fixtures
return lib.Utils.loadCountryFixtures(this.app)
})
])
}
constructor (app) {
super(app, {
config: require('./config'),
api: require('./api'),
pkg: require('./package')
})
}
}