@como/como-client 0.1.292 → 0.1.991
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/index.js +3 -0
- package/lib/como.js +2022 -1396
- package/lib/config/env.js +4 -3
- package/lib/services/auth.service.js +93 -55
- package/lib/services/form.service.js +32 -0
- package/lib/services/index.js +15 -3
- package/lib/services/log.service.js +39 -0
- package/lib/services/loyalty.service.js +365 -159
- package/lib/services/ssr.service.js +75 -0
- package/package.json +8 -3
- package/src/como.js +833 -709
- package/.babelrc +0 -15
- package/.eslintignore +0 -1
- package/.eslintrc +0 -46
- package/.vscode/launch.json +0 -14
- package/.whitesource +0 -7
- package/__tests__/testExternalUrlTranslation.js +0 -84
- package/src/config/env.js +0 -33
- package/src/constants/resourceNames.js +0 -2
- package/src/interceptors/refresh.js +0 -75
- package/src/interceptors/response.js +0 -12
- package/src/services/auth.service.js +0 -54
- package/src/services/form.service.js +0 -17
- package/src/services/index.js +0 -54
- package/src/services/loyalty.service.js +0 -240
- package/src/utils/comoExternalUrlTranslator.js +0 -126
- package/src/utils/urls.js +0 -15
- package/webpack.config.js +0 -13
- package/yarn.lock +0 -5026
package/src/como.js
CHANGED
|
@@ -6,8 +6,6 @@ const comoExternalUrlTranslator = require('./utils/comoExternalUrlTranslator');
|
|
|
6
6
|
const resourceNames = require('./constants/resourceNames');
|
|
7
7
|
const urlsUtils = require('./utils/urls');
|
|
8
8
|
|
|
9
|
-
const como = {};
|
|
10
|
-
let comoData;
|
|
11
9
|
const INITIAL_COMO_DATA = {
|
|
12
10
|
env: environmentConfig,
|
|
13
11
|
token: null,
|
|
@@ -16,801 +14,927 @@ const INITIAL_COMO_DATA = {
|
|
|
16
14
|
installationId: null,
|
|
17
15
|
membership: null,
|
|
18
16
|
assets: null,
|
|
19
|
-
archivedAssets: null,
|
|
20
|
-
redeemedAssets: null,
|
|
21
17
|
mainResources: {},
|
|
22
18
|
};
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
await refresher();
|
|
20
|
+
class Como {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.comoData = {};
|
|
28
23
|
}
|
|
29
|
-
};
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const data = await api.signOn(comoData.installationId, comoData.locationId);
|
|
39
|
-
return data;
|
|
40
|
-
} catch (error) {
|
|
41
|
-
if (error.response && error.response.data) {
|
|
42
|
-
const { code, message } = error.response.data;
|
|
43
|
-
throw new Error(code || message);
|
|
25
|
+
async refreshTokenIfNeeded() {
|
|
26
|
+
const { refresher, expiresIn } = this.comoData;
|
|
27
|
+
if(!refresher){
|
|
28
|
+
console.log('No refresh for %o', this.comoData);
|
|
29
|
+
}
|
|
30
|
+
else if (expiresIn && moment(expiresIn).subtract(10, 'seconds').isBefore(moment())) {
|
|
31
|
+
await refresher();
|
|
44
32
|
}
|
|
45
|
-
throw error;
|
|
46
33
|
}
|
|
47
|
-
};
|
|
48
34
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Sign the user and returns guest token & refresh token.
|
|
38
|
+
* Requires init.
|
|
39
|
+
*/
|
|
40
|
+
// async signon(source) {
|
|
41
|
+
// const { InitApi: api } = this.comoData;
|
|
42
|
+
// try {
|
|
43
|
+
// const data = await api.signOn(this.comoData.installationId, this.comoData.locationId, this.comoData.refreshToken, source);
|
|
44
|
+
// if (data && data.config && data.config.loyaltyCDN) {
|
|
45
|
+
// this.comoData.env_params.services_root_cdn = data.config.loyaltyCDN;
|
|
46
|
+
// }
|
|
47
|
+
// return data;
|
|
48
|
+
// } catch (error) {
|
|
49
|
+
// if (error.response && error.response.data) {
|
|
50
|
+
// const { code, message } = error.response.data;
|
|
51
|
+
// throw new Error(code || message);
|
|
52
|
+
// }
|
|
53
|
+
// throw error;
|
|
54
|
+
// }
|
|
55
|
+
// }
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @param {Object} environment Environemnt object
|
|
60
|
+
* @param {string} environment.id Environment Id
|
|
61
|
+
* @param {string} environment.locationId Location Id
|
|
62
|
+
* @param {string} environment.installationId Unique installation id
|
|
63
|
+
* @param {Object} credentials Member credentials (Optional)
|
|
64
|
+
* @param {string} accessToken session id string (Optional)
|
|
65
|
+
* @param {string} refreshToken refresh token string (Optional)
|
|
66
|
+
* @param {string} expiresIn access token expiration date formatted (Optional)
|
|
67
|
+
* @param {function} refreshCallback an event callback which fires each time user's tokens gets refreshed
|
|
68
|
+
* @param {boolean} enableSignon if disabled signOn api call will not be fired. Enabled by default.
|
|
69
|
+
*/
|
|
70
|
+
async init(environment, credentials, refreshCallback, enableSignon = true) {
|
|
71
|
+
const isExists = (x => !ramda.isNil(x) && !ramda.isEmpty(x));
|
|
72
|
+
const { id: environmentId, locationId, installationId, source } = environment;
|
|
73
|
+
if (!isExists(environmentId) || !isExists(locationId) || !isExists(installationId)) {
|
|
74
|
+
throw new Error(`missing parameters: ${environment}`);
|
|
83
75
|
}
|
|
84
|
-
};
|
|
85
76
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
77
|
+
this.comoData = {
|
|
78
|
+
...INITIAL_COMO_DATA,
|
|
79
|
+
...credentials,
|
|
80
|
+
installationId,
|
|
81
|
+
locationId,
|
|
82
|
+
source,
|
|
83
|
+
env_params: {
|
|
84
|
+
...INITIAL_COMO_DATA.env[environmentId],
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const updateCredentials = (creds, isNew = false) => {
|
|
89
|
+
this.updateLocalCreds(creds);
|
|
90
|
+
if (refreshCallback && isNew) {
|
|
91
|
+
refreshCallback(creds);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const getCredentials = this.getCredentials.bind(this);
|
|
96
|
+
const { gateway } = this.comoData.env_params;
|
|
97
|
+
const { service, refresher, initService } = APIService
|
|
98
|
+
.getService(gateway, installationId, getCredentials, updateCredentials);
|
|
99
|
+
this.comoData.api = service;
|
|
100
|
+
this.comoData.initApi = initService;
|
|
101
|
+
this.comoData.refresher = refresher;
|
|
102
|
+
|
|
103
|
+
const { accessToken, refreshToken, expiresIn } = credentials;
|
|
104
|
+
let credExist = isExists(accessToken) && isExists(refreshToken);
|
|
105
|
+
let isExpired = credExist && expiresIn && moment(expiresIn).isBefore(moment());
|
|
106
|
+
let refreshFailed = false;
|
|
107
|
+
if(isExpired){
|
|
108
|
+
try{
|
|
109
|
+
const data = await this.comoData.initApi.refreshToken(installationId, refreshToken? refreshToken: 'none', locationId, source);
|
|
110
|
+
updateCredentials(data, true);
|
|
111
|
+
}catch(e){
|
|
112
|
+
console.log(`Failed to refresh token, installationId:${installationId}, refreshToken:${this.comoData.refreshToken}, locationId:${locationId}, source:${source}`);
|
|
113
|
+
//refresh failed - need to revoke and signOn again
|
|
114
|
+
initService.logError({method: 'refreshToken', installationId, locationId, source, refreshToken});
|
|
115
|
+
refreshFailed = true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
let interval = 0;
|
|
119
|
+
if(refreshFailed || !credExist){
|
|
120
|
+
while(!credExist && interval < 3000){
|
|
121
|
+
try{
|
|
122
|
+
const data = await this.comoData.initApi.signOn(installationId, locationId, refreshToken, source);
|
|
123
|
+
updateCredentials(data, true);
|
|
124
|
+
credExist = true;
|
|
125
|
+
}catch(e){
|
|
126
|
+
console.log(`Failed to signOn, installationId:${installationId}, locationId:${locationId}, source:${source}`);
|
|
127
|
+
initService.logError({method: 'signOn', installationId, locationId, source, refreshToken, interval});
|
|
128
|
+
|
|
129
|
+
interval += 1000;
|
|
130
|
+
setTimeout(() => {
|
|
131
|
+
console.log(`waking for another try of signOn, interval: ${interval}, installationId:${installationId}, locationId:${locationId}, source:${source}`);
|
|
132
|
+
initService.logError({method: 'signOn', installationId, locationId, source, refreshToken, interval});
|
|
133
|
+
}, interval);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
91
137
|
|
|
92
|
-
|
|
93
|
-
const credsNotExist = !isExists(accessToken) || !isExists(refreshToken);
|
|
94
|
-
const isExpired = expiresIn && moment(expiresIn).isBefore(moment());
|
|
95
|
-
if (enableSignon && (credsNotExist || isExpired)) {
|
|
96
|
-
await como.signon();
|
|
138
|
+
return this.getCredentials();
|
|
97
139
|
}
|
|
98
140
|
|
|
99
|
-
|
|
100
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Updates the como.js local credentials settings.
|
|
143
|
+
* Used when making api calls to janua.
|
|
144
|
+
*
|
|
145
|
+
* @param {Object} credentials credentials to update.
|
|
146
|
+
* @param {Object} accessToken access token to update.
|
|
147
|
+
* @param {Object} refreshToken refresh token to update.
|
|
148
|
+
* @param {Object} expiresIn access token expiry date to update.
|
|
149
|
+
*/
|
|
150
|
+
updateLocalCreds(credentials = {}) {
|
|
151
|
+
this.comoData.accessToken = credentials.accessToken;
|
|
152
|
+
this.comoData.token = credentials.accessToken;
|
|
153
|
+
this.comoData.refreshToken = credentials.refreshToken;
|
|
154
|
+
this.comoData.expiresIn = credentials.expiresIn;
|
|
155
|
+
}
|
|
101
156
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
como.updateLocalCreds = (credentials = {}) => {
|
|
112
|
-
comoData.accessToken = credentials.accessToken;
|
|
113
|
-
comoData.token = credentials.accessToken;
|
|
114
|
-
comoData.refreshToken = credentials.refreshToken;
|
|
115
|
-
comoData.expiresIn = credentials.expiresIn;
|
|
116
|
-
};
|
|
157
|
+
getExternalUrlByID(itemID, gpsData, assetID, accessibilityData) {
|
|
158
|
+
const locationData = this.comoData.mainResources[resourceNames.LOCATION_DATA];
|
|
159
|
+
if (locationData && locationData.WebViews && locationData.WebViews[0].item) {
|
|
160
|
+
const possibleWebViews = locationData.WebViews[0].item.filter(u => u.id === itemID);
|
|
161
|
+
const url = possibleWebViews && possibleWebViews[0] && possibleWebViews[0].url;
|
|
162
|
+
return this.translateExternalUrl(url, gpsData, assetID, accessibilityData);
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
117
166
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
167
|
+
async translateExternalUrl(url, gpsData, assetID, accessibilityData) {
|
|
168
|
+
const legacyUrl = await this.getAppModulesLegacyBaseUrl();
|
|
169
|
+
let externalUrl = url;
|
|
170
|
+
if (externalUrl && externalUrl.startsWith(legacyUrl)) {
|
|
171
|
+
externalUrl = externalUrl.replace(legacyUrl, this.comoData.env_params.app_modules_root);
|
|
172
|
+
}
|
|
173
|
+
const {
|
|
174
|
+
api, locationId, token, env_params: env, membership, assets,
|
|
175
|
+
} = this.comoData;
|
|
176
|
+
const locationData = this.comoData.mainResources && this.comoData.mainResources[resourceNames.LOCATION_DATA];
|
|
177
|
+
const apiObjects = { api, servicesRoot: env.services_root };
|
|
178
|
+
const dataToUse = {
|
|
179
|
+
locationId, token, membership, locationData, assets, gpsData, assetID, accessibilityData,
|
|
180
|
+
};
|
|
181
|
+
return comoExternalUrlTranslator.translateUrl(externalUrl, apiObjects, dataToUse);
|
|
124
182
|
}
|
|
125
|
-
return null;
|
|
126
|
-
};
|
|
127
183
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
const {
|
|
135
|
-
api, locationId, token, env_params: env, membership, assets,
|
|
136
|
-
} = comoData;
|
|
137
|
-
const locationData = comoData.mainResources && comoData.mainResources[resourceNames.LOCATION_DATA];
|
|
138
|
-
const apiObjects = { api, servicesRoot: env.services_root };
|
|
139
|
-
const dataToUse = {
|
|
140
|
-
locationId, token, membership, locationData, assets, gpsData, assetID, accessibilityData,
|
|
141
|
-
};
|
|
142
|
-
return comoExternalUrlTranslator.translateUrl(externalUrl, apiObjects, dataToUse);
|
|
143
|
-
};
|
|
184
|
+
async getFeedbackFormData() {
|
|
185
|
+
const {
|
|
186
|
+
locationId, token, env_params: env, api,
|
|
187
|
+
} = this.comoData;
|
|
188
|
+
return api.getFeedbackFormData(env.zapp_root, locationId, token);
|
|
189
|
+
}
|
|
144
190
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
191
|
+
/**
|
|
192
|
+
*
|
|
193
|
+
* @param {Object} form registration form values
|
|
194
|
+
* @param {Object} verification flow
|
|
195
|
+
* @param {string} reCaptchaToken
|
|
196
|
+
* @param {Object} source(registration origin)
|
|
197
|
+
*/
|
|
198
|
+
async register(form, verification, reCaptchaToken, source) {
|
|
199
|
+
const { api } = this.comoData;
|
|
200
|
+
try {
|
|
201
|
+
const data = await api.register(form, verification, reCaptchaToken, source);
|
|
202
|
+
return data;
|
|
203
|
+
} catch (error) {
|
|
204
|
+
if (error.response && error.response.data) {
|
|
205
|
+
const { code, message } = error.response.data;
|
|
206
|
+
throw new Error(code || message);
|
|
207
|
+
}
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
151
211
|
|
|
152
|
-
/**
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
212
|
+
/**
|
|
213
|
+
*
|
|
214
|
+
* @param {string} verification flow (code & verification step)
|
|
215
|
+
* @param {string} type verification type
|
|
216
|
+
* @param {Object} form registration form values
|
|
217
|
+
* @param {string} reCaptchaToken
|
|
218
|
+
*/
|
|
219
|
+
async registerVerify(verification, type, form, reCaptchaToken) {
|
|
220
|
+
const { api } = this.comoData;
|
|
221
|
+
try {
|
|
222
|
+
const data = await api.registerVerify(verification, type, form, reCaptchaToken);
|
|
223
|
+
return data;
|
|
224
|
+
} catch (error) {
|
|
225
|
+
if (error.response && error.response.data) {
|
|
226
|
+
const { code, message } = error.response.data;
|
|
227
|
+
throw new Error(code || message);
|
|
228
|
+
}
|
|
229
|
+
throw error;
|
|
165
230
|
}
|
|
166
|
-
throw error;
|
|
167
231
|
}
|
|
168
|
-
};
|
|
169
232
|
|
|
170
|
-
/**
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
233
|
+
/**
|
|
234
|
+
*
|
|
235
|
+
* @param {Object} form update form values
|
|
236
|
+
* @param {string} reCaptchaToken
|
|
237
|
+
* @param {string} source request source
|
|
238
|
+
*/
|
|
239
|
+
async updateProfile(form, reCaptchaToken, source) {
|
|
240
|
+
const { api } = this.comoData;
|
|
241
|
+
try {
|
|
242
|
+
const data = await api.updateProfile(form, reCaptchaToken, source);
|
|
243
|
+
return data;
|
|
244
|
+
} catch (error) {
|
|
245
|
+
if (error.response && error.response.data) {
|
|
246
|
+
const { code, message } = error.response.data;
|
|
247
|
+
throw new Error(code || message);
|
|
248
|
+
}
|
|
249
|
+
throw error;
|
|
185
250
|
}
|
|
186
|
-
throw error;
|
|
187
251
|
}
|
|
188
|
-
};
|
|
189
252
|
|
|
190
|
-
/**
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
|
|
253
|
+
/**
|
|
254
|
+
*
|
|
255
|
+
* @param {string} verificationCode code verification sent by 3rd party
|
|
256
|
+
* @param {string} type verification type
|
|
257
|
+
* @param {Object} form update form values
|
|
258
|
+
* @param {string} reCaptchaToken
|
|
259
|
+
* @param {string} source request source
|
|
260
|
+
*/
|
|
261
|
+
async updateProfileVerify(verificationCode, type, form, reCaptchaToken, source) {
|
|
262
|
+
const { api } = this.comoData;
|
|
263
|
+
try {
|
|
264
|
+
const data = await api.updateProfileVerify(verificationCode, type, form, reCaptchaToken, source);
|
|
265
|
+
return data;
|
|
266
|
+
} catch (error) {
|
|
267
|
+
if (error.response && error.response.data) {
|
|
268
|
+
const { code, message } = error.response.data;
|
|
269
|
+
throw new Error(code || message);
|
|
270
|
+
}
|
|
271
|
+
throw error;
|
|
203
272
|
}
|
|
204
|
-
throw error;
|
|
205
273
|
}
|
|
206
|
-
};
|
|
207
274
|
|
|
208
|
-
/**
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
275
|
+
/**
|
|
276
|
+
*
|
|
277
|
+
* @param {string} unsubscribeSms unsubscribe user at location
|
|
278
|
+
* @param {string} PhoneNumber phone number to identify user
|
|
279
|
+
*/
|
|
280
|
+
async unsubscribeSms(PhoneNumber) {
|
|
281
|
+
const { api, locationId } = this.comoData;
|
|
282
|
+
try {
|
|
283
|
+
const identifier = { PhoneNumber };
|
|
284
|
+
const data = await api.unsubscribeSms(locationId, identifier);
|
|
285
|
+
return data;
|
|
286
|
+
} catch (error) {
|
|
287
|
+
if (error.response && error.response.data) {
|
|
288
|
+
const { code, message } = error.response.data;
|
|
289
|
+
throw new Error(code || message);
|
|
290
|
+
}
|
|
291
|
+
throw error;
|
|
223
292
|
}
|
|
224
|
-
throw error;
|
|
225
293
|
}
|
|
226
|
-
};
|
|
227
294
|
|
|
228
|
-
/**
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
295
|
+
/**
|
|
296
|
+
*
|
|
297
|
+
* @param {Object} identifier an object which identifies the user by its credentials
|
|
298
|
+
* @param {string} type login type i.e PhoneNumber/Email/etc
|
|
299
|
+
*/
|
|
300
|
+
async login(identifier, type) {
|
|
301
|
+
const { api } = this.comoData;
|
|
302
|
+
try {
|
|
303
|
+
const data = await api.logIn(type, identifier);
|
|
304
|
+
return data;
|
|
305
|
+
} catch (error) {
|
|
306
|
+
if (error.response && error.response.data) {
|
|
307
|
+
const { code, message } = error.response.data;
|
|
308
|
+
throw new Error(code || message);
|
|
309
|
+
}
|
|
310
|
+
throw error;
|
|
242
311
|
}
|
|
243
|
-
throw error;
|
|
244
312
|
}
|
|
245
|
-
};
|
|
246
313
|
|
|
247
|
-
/**
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
314
|
+
/**
|
|
315
|
+
*
|
|
316
|
+
* @param {Object} identifier key-value identifiers
|
|
317
|
+
* @param {*} type login type i.e PhoneNumber/Email/etc
|
|
318
|
+
* @param {*} code a 2-factor verification code sent to the client
|
|
319
|
+
*/
|
|
320
|
+
async loginVerify(identifier, type, code) {
|
|
321
|
+
const { api } = this.comoData;
|
|
322
|
+
try {
|
|
323
|
+
const { consent } = await api.logInVerify(code, type, identifier);
|
|
324
|
+
this.comoData.consent = consent;
|
|
325
|
+
} catch (error) {
|
|
326
|
+
if (error.response && error.response.data) {
|
|
327
|
+
const { code: errCode, message } = error.response.data;
|
|
328
|
+
if (message && message === 'Invalid verification Code') {
|
|
329
|
+
throw new Error(message);
|
|
330
|
+
}
|
|
331
|
+
throw new Error(errCode || message);
|
|
263
332
|
}
|
|
264
|
-
throw
|
|
333
|
+
throw error;
|
|
265
334
|
}
|
|
266
|
-
|
|
335
|
+
|
|
336
|
+
return this.getCredentials();
|
|
267
337
|
}
|
|
268
338
|
|
|
269
|
-
|
|
270
|
-
|
|
339
|
+
/**
|
|
340
|
+
* Reload and sets the internal membership state.
|
|
341
|
+
* To get the reloaded membership make sure to call getMembership();
|
|
342
|
+
* @param onlyAssetKeys - include assets list full data or only the asset keys
|
|
343
|
+
* @returns {Promise<void>}
|
|
344
|
+
*/
|
|
345
|
+
async reloadMembership(onlyAssetKeys = false) {
|
|
346
|
+
const {
|
|
347
|
+
env_params: env, locationId, api,
|
|
348
|
+
} = this.comoData;
|
|
349
|
+
const membership = await api.getUserAtLocation(env.zapp_root, locationId, onlyAssetKeys);
|
|
350
|
+
this.comoData.membership = membership;
|
|
351
|
+
}
|
|
271
352
|
|
|
272
|
-
/**
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const {
|
|
280
|
-
env_params: env, locationId, api,
|
|
281
|
-
} = comoData;
|
|
282
|
-
const membership = await api.getUserAtLocation(env.zapp_root, locationId, onlyAssetKeys);
|
|
283
|
-
comoData.membership = membership;
|
|
284
|
-
};
|
|
353
|
+
/**
|
|
354
|
+
* Send an Open app request to update server.
|
|
355
|
+
*/
|
|
356
|
+
async openApp(data) {
|
|
357
|
+
const {
|
|
358
|
+
api, locationId, token, env_params: env,
|
|
359
|
+
} = this.comoData;
|
|
285
360
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
*/
|
|
289
|
-
como.openApp = async data => {
|
|
290
|
-
const {
|
|
291
|
-
api, locationId, token, env_params: env,
|
|
292
|
-
} = comoData;
|
|
361
|
+
return api.openApp(env.zapp_root, token, locationId, data);
|
|
362
|
+
}
|
|
293
363
|
|
|
294
|
-
|
|
295
|
-
|
|
364
|
+
/**
|
|
365
|
+
* Update membership status (permissions).
|
|
366
|
+
* @param {boolean} pushEnable
|
|
367
|
+
* @param {boolean} locationEnable
|
|
368
|
+
*/
|
|
369
|
+
async clientUpdateMembership(pushEnable, locationEnable) {
|
|
370
|
+
const {
|
|
371
|
+
api, locationId, token, env_params: env,
|
|
372
|
+
} = this.comoData;
|
|
373
|
+
|
|
374
|
+
return api.clientUpdateMembership(env.services_root, token, locationId, pushEnable, locationEnable);
|
|
375
|
+
}
|
|
296
376
|
|
|
297
|
-
/**
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
*/
|
|
302
|
-
como.clientUpdateMembership = async (pushEnable, locationEnable) => {
|
|
303
|
-
const {
|
|
304
|
-
api, locationId, token, env_params: env,
|
|
305
|
-
} = comoData;
|
|
306
|
-
|
|
307
|
-
return api.clientUpdateMembership(env.services_root, token, locationId, pushEnable, locationEnable);
|
|
308
|
-
};
|
|
377
|
+
/**
|
|
378
|
+
* Downloads the main resource by its id and sets the resource in the main resource's map.
|
|
379
|
+
* @param {string} resourceId Main resource id
|
|
380
|
+
*/
|
|
309
381
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
382
|
+
async downloadMainResource(resourceId) {
|
|
383
|
+
const resource = this.comoData.mainResourcesMap[resourceId];
|
|
384
|
+
if (!resource) {
|
|
385
|
+
const err = `resource ${resourceId} not found!`;
|
|
386
|
+
throw new Error(err);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const { env_params: env, api } = this.comoData;
|
|
390
|
+
const responseJson = await api.getLoyaltyResource(
|
|
391
|
+
env.services_root_cdn,
|
|
392
|
+
resource.id,
|
|
393
|
+
('Namespace' in resource) ? resource.Namespace : `location_${this.comoData.locationId}`,
|
|
394
|
+
resource.Version,
|
|
395
|
+
);
|
|
314
396
|
|
|
315
|
-
|
|
316
|
-
const resource = comoData.mainResourcesMap[resourceId];
|
|
317
|
-
if (!resource) {
|
|
318
|
-
const err = `resource ${resourceId} not found!`;
|
|
319
|
-
throw new Error(err);
|
|
397
|
+
this.comoData.mainResources[resourceId] = responseJson;
|
|
320
398
|
}
|
|
321
399
|
|
|
322
|
-
const { env_params: env, api } = comoData;
|
|
323
|
-
const responseJson = await api.getLoyaltyResource(
|
|
324
|
-
env.services_root_temp,
|
|
325
|
-
resource.id,
|
|
326
|
-
('Namespace' in resource) ? resource.Namespace : `location_${comoData.locationId}`,
|
|
327
|
-
resource.Version,
|
|
328
|
-
);
|
|
329
400
|
|
|
330
|
-
|
|
331
|
-
|
|
401
|
+
/**
|
|
402
|
+
* Reload and sets the internal location state.
|
|
403
|
+
* To get the reloaded location state make sure to call getLocationState();
|
|
404
|
+
*/
|
|
405
|
+
async reloadLocationState() {
|
|
406
|
+
const { api } = this.comoData;
|
|
407
|
+
const state = await api.getLocationState(this.comoData.env_params.zapp_root, this.comoData.locationId);
|
|
408
|
+
this.comoData.locationState = state;
|
|
409
|
+
const mainResources = state.MainResources.Resource;
|
|
410
|
+
|
|
411
|
+
this.comoData.mainResourcesMap = mainResources.reduce((total, obj) => {
|
|
412
|
+
total[obj.id] = obj; // eslint-disable-line no-param-reassign
|
|
413
|
+
return total;
|
|
414
|
+
}, {});
|
|
415
|
+
}
|
|
332
416
|
|
|
417
|
+
/**
|
|
418
|
+
* Requests an app client id by the user's location id.
|
|
419
|
+
*/
|
|
420
|
+
async getAppClientID() {
|
|
421
|
+
const {
|
|
422
|
+
env_params: env, locationId, api,
|
|
423
|
+
} = this.comoData;
|
|
424
|
+
const responseJson = await api.getShortUserId(env.zapp_root, locationId);
|
|
425
|
+
return responseJson.ID;
|
|
426
|
+
}
|
|
333
427
|
|
|
334
|
-
/**
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
comoData.mainResourcesMap = mainResources.reduce((total, obj) => {
|
|
345
|
-
total[obj.id] = obj; // eslint-disable-line no-param-reassign
|
|
346
|
-
return total;
|
|
347
|
-
}, {});
|
|
348
|
-
};
|
|
428
|
+
/**
|
|
429
|
+
* Requests a generated payment code from the loyalty server
|
|
430
|
+
*/
|
|
431
|
+
async getPaymentCode() {
|
|
432
|
+
const {
|
|
433
|
+
env_params: env, locationId, api,
|
|
434
|
+
} = this.comoData;
|
|
435
|
+
const responseJson = await api.getPaymentCode(env.zapp_root, locationId);
|
|
436
|
+
return responseJson.VerificationCode;
|
|
437
|
+
}
|
|
349
438
|
|
|
350
|
-
/**
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
439
|
+
/**
|
|
440
|
+
* Logout the user identified by its accessToken
|
|
441
|
+
*/
|
|
442
|
+
async logout() {
|
|
443
|
+
const { api } = this.comoData;
|
|
444
|
+
try {
|
|
445
|
+
const response = await api.logOut();
|
|
446
|
+
return response;
|
|
447
|
+
} catch (error) {
|
|
448
|
+
if (error.response && error.response.data) {
|
|
449
|
+
const { code: errCode, message } = error.response.data;
|
|
450
|
+
throw new Error(errCode || message);
|
|
451
|
+
}
|
|
452
|
+
throw error;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
360
455
|
|
|
361
|
-
/**
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
456
|
+
/**
|
|
457
|
+
*
|
|
458
|
+
* @param {string} assetKey asset's id
|
|
459
|
+
*/
|
|
460
|
+
async redeemAsset(assetKey) {
|
|
461
|
+
const {
|
|
462
|
+
env_params: env, locationId, api,
|
|
463
|
+
} = this.comoData;
|
|
464
|
+
const responseJson = await api.redeemAsset(env.zapp_root, locationId, assetKey);
|
|
465
|
+
return responseJson;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
*
|
|
470
|
+
* @param {string} itemId item's id
|
|
471
|
+
*/
|
|
472
|
+
async purchaseAsset(itemId) {
|
|
473
|
+
const {
|
|
474
|
+
env_params: env, token, locationId, api,
|
|
475
|
+
} = this.comoData;
|
|
476
|
+
const responseJson = await api.purchaseAsset(env.zapp_root, locationId, token, itemId);
|
|
477
|
+
return responseJson;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
async getUserPointShopDataAPI2() {
|
|
481
|
+
const {
|
|
482
|
+
env_params: env, locationId, api,
|
|
483
|
+
} = this.comoData;
|
|
484
|
+
const responseJson = await api.getUserPointShopDataAPI2(env.zapp_root, locationId);
|
|
485
|
+
return responseJson;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
async purchaseAssetAPI2(assetID) {
|
|
490
|
+
const {
|
|
491
|
+
env_params: env, locationId, api,
|
|
492
|
+
} = this.comoData;
|
|
493
|
+
const responseJson = await api.purchaseAssetAPI2(env.zapp_root, locationId, assetID);
|
|
494
|
+
return responseJson;
|
|
495
|
+
}
|
|
371
496
|
|
|
372
|
-
/**
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
497
|
+
/**
|
|
498
|
+
* Reload and sets the internal assets (expired and valid) state.
|
|
499
|
+
* To get the reloaded assets make sure to call como.getAssets();
|
|
500
|
+
*/
|
|
501
|
+
async reloadAssets() {
|
|
502
|
+
const {
|
|
503
|
+
env_params: env, locationId, api,
|
|
504
|
+
} = this.comoData;
|
|
505
|
+
const responseJson = await api.memberAssets(env.services_root, locationId);
|
|
506
|
+
this.comoData.assets = responseJson;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Merge the default app text with the location specific app texts
|
|
511
|
+
* Both DefaultAppTexts and AppTexts are a MainResource that needs to be downloaded before merge
|
|
512
|
+
*/
|
|
513
|
+
mergeTexts() {
|
|
514
|
+
if (this.comoData.mainResources.AppTexts && this.comoData.mainResources.DefaultAppTexts) {
|
|
515
|
+
this.comoData.app_texts = this.comoData.mainResources.DefaultAppTexts;
|
|
516
|
+
Object.keys(this.comoData.mainResources.AppTexts).forEach(key => {
|
|
517
|
+
this.comoData.app_texts[key] = this.comoData.mainResources.AppTexts[key];
|
|
518
|
+
});
|
|
384
519
|
}
|
|
385
|
-
throw error;
|
|
386
520
|
}
|
|
387
|
-
};
|
|
388
521
|
|
|
389
|
-
/**
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
522
|
+
/**
|
|
523
|
+
*
|
|
524
|
+
* @param {string} key app text key
|
|
525
|
+
*/
|
|
526
|
+
getTextForKey(key) { return this.comoData.app_texts[key]; }
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Downloads the main resources:
|
|
530
|
+
* - LocationData
|
|
531
|
+
* - Menu
|
|
532
|
+
* - Updates
|
|
533
|
+
* - TCAlts
|
|
534
|
+
* - AppTexts
|
|
535
|
+
* - DefaultAppTexts
|
|
536
|
+
*/
|
|
537
|
+
async downloadMainResources() {
|
|
538
|
+
const resources = [
|
|
539
|
+
'LocationData',
|
|
540
|
+
'Menu',
|
|
541
|
+
'Updates',
|
|
542
|
+
'TCAlts',
|
|
543
|
+
'AppTexts',
|
|
544
|
+
'DefaultAppTexts',
|
|
545
|
+
];
|
|
546
|
+
const downloadMainResource = this.downloadMainResource.bind(this);
|
|
547
|
+
const downloads = resources.map(downloadMainResource);
|
|
548
|
+
await Promise.all(downloads);
|
|
549
|
+
this.mergeTexts();
|
|
550
|
+
}
|
|
400
551
|
|
|
401
|
-
/**
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
env_params: env, token, locationId, api,
|
|
408
|
-
} = comoData;
|
|
409
|
-
const responseJson = await api.purchaseAsset(env.zapp_root, locationId, token, itemId);
|
|
410
|
-
return responseJson;
|
|
411
|
-
};
|
|
552
|
+
/**
|
|
553
|
+
*
|
|
554
|
+
* @param {string} type form type
|
|
555
|
+
*/
|
|
556
|
+
loadForm(type) {
|
|
557
|
+
const { api, locationId } = this.comoData;
|
|
412
558
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
* To get the reloaded assets make sure to call como.getAssets(); and como.getArchivedAssets();
|
|
416
|
-
*/
|
|
417
|
-
como.reloadAssets = async () => {
|
|
418
|
-
const {
|
|
419
|
-
env_params: env, locationId, api,
|
|
420
|
-
} = comoData;
|
|
421
|
-
const responseJson = await api.memberAssets(env.services_root, locationId);
|
|
422
|
-
|
|
423
|
-
const assets = [];
|
|
424
|
-
const archivedAssets = [];
|
|
425
|
-
const dateNow = moment().utc();
|
|
426
|
-
|
|
427
|
-
responseJson.forEach(asset => {
|
|
428
|
-
const archived = ramda.pathOr(false, ['Archived'], asset);
|
|
429
|
-
const active = ramda.pathOr(true, ['Active'], asset);
|
|
430
|
-
const validUntil = ramda.pathOr(null, ['Data', 'ValidUntil'], asset);
|
|
431
|
-
const lastAssign = ramda.pathOr(null, ['LastAssignDate'], asset);
|
|
432
|
-
const secondsValid = ramda.pathOr(null, ['Data', 'SecondsValid'], asset);
|
|
433
|
-
const lastAssignDate = moment.utc(lastAssign, 'DD.MM.YYYY HH:mm:ss');
|
|
434
|
-
let validUntilDate = moment.utc(validUntil, 'DD/MM/YYYY HH:mm:ss');
|
|
435
|
-
|
|
436
|
-
if (!archived && active) {
|
|
437
|
-
if (secondsValid !== null) {
|
|
438
|
-
validUntilDate = lastAssignDate.clone().add(secondsValid, 'seconds');
|
|
439
|
-
}
|
|
559
|
+
return api.getForm(type, locationId);
|
|
560
|
+
}
|
|
440
561
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
}
|
|
447
|
-
|
|
562
|
+
/**
|
|
563
|
+
*
|
|
564
|
+
* @param {string} type configuration type
|
|
565
|
+
*/
|
|
566
|
+
getConfigration(type) {
|
|
567
|
+
const { api, locationId } = this.comoData;
|
|
568
|
+
const locationState = this.getLocationState();
|
|
569
|
+
let version = null;
|
|
570
|
+
if (locationState) {
|
|
571
|
+
version = locationState.PublishVersion;
|
|
448
572
|
}
|
|
449
|
-
});
|
|
450
573
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
};
|
|
574
|
+
return api.getConfiguration(type, locationId, version);
|
|
575
|
+
}
|
|
454
576
|
|
|
455
|
-
/**
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}
|
|
463
|
-
const responseJson = await api.memberAssets(env.services_root, locationId, true);
|
|
464
|
-
comoData.redeemedAssets = responseJson;
|
|
465
|
-
};
|
|
577
|
+
/**
|
|
578
|
+
*
|
|
579
|
+
* @param {string} type resource type
|
|
580
|
+
*/
|
|
581
|
+
getResource(type) {
|
|
582
|
+
const { api, locationId } = this.comoData;
|
|
583
|
+
return api.getResource(type, locationId);
|
|
584
|
+
}
|
|
466
585
|
|
|
467
|
-
/**
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
Object.keys(comoData.mainResources.AppTexts).forEach(key => {
|
|
475
|
-
comoData.app_texts[key] = comoData.mainResources.AppTexts[key];
|
|
476
|
-
});
|
|
586
|
+
/**
|
|
587
|
+
*
|
|
588
|
+
* Get all legacy resources (Zapp)
|
|
589
|
+
*/
|
|
590
|
+
getLegacyResources() {
|
|
591
|
+
const { api, locationId } = this.comoData;
|
|
592
|
+
return api.getZappResource(locationId);
|
|
477
593
|
}
|
|
478
|
-
};
|
|
479
594
|
|
|
480
|
-
/**
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
* Downloads the main resources:
|
|
488
|
-
* - LocationData
|
|
489
|
-
* - Menu
|
|
490
|
-
* - Updates
|
|
491
|
-
* - TCAlts
|
|
492
|
-
* - AppTexts
|
|
493
|
-
* - DefaultAppTexts
|
|
494
|
-
*/
|
|
495
|
-
como.downloadMainResources = async () => {
|
|
496
|
-
const resources = [
|
|
497
|
-
'LocationData',
|
|
498
|
-
'Menu',
|
|
499
|
-
'Updates',
|
|
500
|
-
'TCAlts',
|
|
501
|
-
'AppTexts',
|
|
502
|
-
'DefaultAppTexts',
|
|
503
|
-
];
|
|
504
|
-
const downloads = resources.map(como.downloadMainResource);
|
|
505
|
-
await Promise.all(downloads);
|
|
506
|
-
como.mergeTexts();
|
|
507
|
-
};
|
|
595
|
+
/**
|
|
596
|
+
* Generates a new referral code for friend-referral
|
|
597
|
+
*/
|
|
598
|
+
generateReferralCode() {
|
|
599
|
+
const {
|
|
600
|
+
api, locationId, token, env_params: env,
|
|
601
|
+
} = this.comoData;
|
|
508
602
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
* @param {string} type form type
|
|
512
|
-
*/
|
|
513
|
-
como.loadForm = type => {
|
|
514
|
-
const { api, locationId } = comoData;
|
|
603
|
+
return api.generateReferralCode(env.services_root, token, locationId);
|
|
604
|
+
}
|
|
515
605
|
|
|
516
|
-
|
|
517
|
-
|
|
606
|
+
/**
|
|
607
|
+
* Check that referral code is valid
|
|
608
|
+
*/
|
|
609
|
+
verifyReferralCode(code) {
|
|
610
|
+
const {
|
|
611
|
+
api, locationId, token, env_params: env,
|
|
612
|
+
} = this.comoData;
|
|
518
613
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
* @param {string} type configuration type
|
|
522
|
-
*/
|
|
523
|
-
como.getConfigration = type => {
|
|
524
|
-
const { api, locationId } = comoData;
|
|
525
|
-
const { PublishVersion: version } = como.getLocationState();
|
|
614
|
+
return api.verifyReferralCode(env.services_root, token, locationId, code);
|
|
615
|
+
}
|
|
526
616
|
|
|
527
|
-
|
|
528
|
-
|
|
617
|
+
/**
|
|
618
|
+
* Returns current accessToken and refreshToken
|
|
619
|
+
* Caution: make sure to pass refresh callback to init to get the latest credentials
|
|
620
|
+
*/
|
|
621
|
+
getCredentials() {
|
|
622
|
+
const {
|
|
623
|
+
accessToken, refreshToken, expiresIn, consent, locationId
|
|
624
|
+
} = this.comoData;
|
|
625
|
+
return {
|
|
626
|
+
accessToken, refreshToken, expiresIn, consent, locationId
|
|
627
|
+
};
|
|
628
|
+
}
|
|
529
629
|
|
|
530
|
-
/**
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
630
|
+
/**
|
|
631
|
+
* Returns the current accessToken
|
|
632
|
+
* Caution: make sure to pass refresh callback to como.init to get the latest credentials
|
|
633
|
+
*/
|
|
634
|
+
getToken() { return this.comoData.token; }
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Returns the como.js initialized installation id
|
|
638
|
+
*/
|
|
639
|
+
getInstallationId() { return this.comoData.installationId; }
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Return the user membership object
|
|
643
|
+
* Make sure to call reloadMembership() to reload the membership object.
|
|
644
|
+
*/
|
|
645
|
+
getMembership() { return this.comoData.membership; }
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Return the user assets object
|
|
649
|
+
* Make sure to call reloadAssets() to reload the assets object.
|
|
650
|
+
*/
|
|
651
|
+
getAssets() { return this.comoData.assets; }
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Returns the location specific registration web url
|
|
655
|
+
*/
|
|
656
|
+
async getRegistrationUrl(overrides) {
|
|
657
|
+
await this.refreshTokenIfNeeded();
|
|
658
|
+
const {
|
|
659
|
+
token, installationId, locationId, env_params: env,
|
|
660
|
+
} = this.comoData;
|
|
661
|
+
|
|
662
|
+
return urlsUtils.appendQuery(
|
|
663
|
+
`${env.app_modules_root}/register?token=${token}&locationid=${locationId}`,
|
|
664
|
+
{
|
|
665
|
+
...this.getCredentials(),
|
|
666
|
+
installationId,
|
|
667
|
+
disableSuccessScreen: 'true',
|
|
668
|
+
...overrides,
|
|
669
|
+
},
|
|
670
|
+
);
|
|
671
|
+
}
|
|
538
672
|
|
|
539
|
-
/**
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
673
|
+
/**
|
|
674
|
+
* Returns the location specific profile web url
|
|
675
|
+
*/
|
|
676
|
+
async getProfileUrl(overrides) {
|
|
677
|
+
await this.refreshTokenIfNeeded();
|
|
678
|
+
const {
|
|
679
|
+
token, installationId, locationId, env_params: env,
|
|
680
|
+
} = this.comoData;
|
|
681
|
+
|
|
682
|
+
return urlsUtils.appendQuery(
|
|
683
|
+
`${env.app_modules_root}/profile?token=${token}&locationid=${locationId}`,
|
|
684
|
+
{
|
|
685
|
+
...this.getCredentials(),
|
|
686
|
+
installationId,
|
|
687
|
+
disableSuccessScreen: 'true',
|
|
688
|
+
...overrides,
|
|
689
|
+
},
|
|
690
|
+
);
|
|
691
|
+
}
|
|
546
692
|
|
|
547
|
-
|
|
548
|
-
|
|
693
|
+
/**
|
|
694
|
+
* Returns the location specific login web url
|
|
695
|
+
*/
|
|
696
|
+
async getLoginUrl() {
|
|
697
|
+
await this.refreshTokenIfNeeded();
|
|
698
|
+
const { token, locationId, env_params: env } = this.comoData;
|
|
699
|
+
return `${env.app_modules_root}/login?token=${token}&locationid=${locationId}`;
|
|
700
|
+
}
|
|
549
701
|
|
|
550
|
-
/**
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
refreshToken: comoData.refreshToken,
|
|
557
|
-
expiresIn: comoData.expiresIn,
|
|
558
|
-
consent: comoData.consent,
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
/**
|
|
562
|
-
* Returns the current accessToken
|
|
563
|
-
* Caution: make sure to pass refresh callback to como.init to get the latest credentials
|
|
564
|
-
*/
|
|
565
|
-
como.getToken = () => comoData.token;
|
|
566
|
-
|
|
567
|
-
/**
|
|
568
|
-
* Returns the como.js initialized installation id
|
|
569
|
-
*/
|
|
570
|
-
como.getInstallationId = () => comoData.installationId;
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* Return the user membership object
|
|
574
|
-
* Make sure to call reloadMembership() to reload the membership object.
|
|
575
|
-
*/
|
|
576
|
-
como.getMembership = () => comoData.membership;
|
|
577
|
-
|
|
578
|
-
/**
|
|
579
|
-
* Return the user assets object
|
|
580
|
-
* Make sure to call reloadAssets() to reload the assets object.
|
|
581
|
-
*/
|
|
582
|
-
como.getAssets = () => comoData.assets;
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* Return the user archived and expired assets object
|
|
586
|
-
* Make sure to call reloadAssets() and reloadArchivedAssets() to reload the archived assets object.
|
|
587
|
-
*/
|
|
588
|
-
como.getArchivedAssets = () => (comoData.archivedAssets || []).concat(comoData.redeemedAssets);
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* Returns the location specific registration web url
|
|
592
|
-
*/
|
|
593
|
-
como.getRegistrationUrl = async overrides => {
|
|
594
|
-
await refreshTokenIfNeeded();
|
|
595
|
-
const {
|
|
596
|
-
token, installationId, locationId, env_params: env,
|
|
597
|
-
} = comoData;
|
|
598
|
-
|
|
599
|
-
return urlsUtils.appendQuery(
|
|
600
|
-
`${env.app_modules_root}/register?token=${token}&locationid=${locationId}`,
|
|
601
|
-
{
|
|
602
|
-
...como.getCredentials(),
|
|
702
|
+
/**
|
|
703
|
+
* Returns the location data Portability url
|
|
704
|
+
*/
|
|
705
|
+
async getDataPortabilityUrl(url, overrides) {
|
|
706
|
+
await this.refreshTokenIfNeeded();
|
|
707
|
+
const {
|
|
603
708
|
installationId,
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
709
|
+
} = this.comoData;
|
|
710
|
+
|
|
711
|
+
return urlsUtils.appendQuery(
|
|
712
|
+
`${url}`,
|
|
713
|
+
{
|
|
714
|
+
installationId,
|
|
715
|
+
...overrides,
|
|
716
|
+
},
|
|
717
|
+
);
|
|
718
|
+
}
|
|
609
719
|
|
|
610
|
-
/**
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
return urlsUtils.appendQuery(
|
|
620
|
-
`${env.app_modules_root}/profile?token=${token}&locationid=${locationId}`,
|
|
621
|
-
{
|
|
622
|
-
...como.getCredentials(),
|
|
623
|
-
installationId,
|
|
624
|
-
disableSuccessScreen: 'true',
|
|
625
|
-
...overrides,
|
|
626
|
-
},
|
|
627
|
-
);
|
|
628
|
-
};
|
|
720
|
+
/**
|
|
721
|
+
* Returns app-modules legacy root url
|
|
722
|
+
*/
|
|
723
|
+
async getAppModulesLegacyBaseUrl() {
|
|
724
|
+
await this.refreshTokenIfNeeded();
|
|
725
|
+
const { env_params: env } = this.comoData;
|
|
726
|
+
return `${env.app_modules_legacy_root}`;
|
|
727
|
+
}
|
|
629
728
|
|
|
630
|
-
/**
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
729
|
+
/**
|
|
730
|
+
* Returns the location specific friend referral web url
|
|
731
|
+
*/
|
|
732
|
+
getFriendReferralInviteLink(referral) { return `${this.comoData.env_params.gateway}/ssr-modules/friend-referral/${this.comoData.locationId}?referral=${referral}`; }
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Return the location state
|
|
736
|
+
* Make sure to call reloadLocationState() to reload the location state object.
|
|
737
|
+
*/
|
|
738
|
+
getLocationState() { return this.comoData.locationState; }
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Returns the location point shop items
|
|
742
|
+
*/
|
|
743
|
+
getPointShopItems() { return this.comoData.mainResources.menu.gifts_shop_item; }
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
*
|
|
747
|
+
* @param {string} resourceName resource name
|
|
748
|
+
*/
|
|
749
|
+
getMainResource(resourceName) { return this.comoData.mainResources[resourceName]; }
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
*
|
|
753
|
+
* @param {string} resourceId resource id
|
|
754
|
+
* @param {string} namespace resource namespace
|
|
755
|
+
* @param {string|number} version resource version
|
|
756
|
+
*/
|
|
757
|
+
getResourceUrl(resourceId, namespace, version) {
|
|
758
|
+
const { api, env_params: env } = this.comoData;
|
|
759
|
+
return api.getResourceUrl(env.services_root_cdn, resourceId, namespace, version);
|
|
760
|
+
}
|
|
638
761
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
como.getAppModulesLegacyBaseUrl = async () => {
|
|
643
|
-
await refreshTokenIfNeeded();
|
|
644
|
-
const { env_params: env } = comoData;
|
|
645
|
-
return `${env.app_modules_legacy_root}`;
|
|
646
|
-
};
|
|
762
|
+
getCdnUrl() {
|
|
763
|
+
return this.comoData.env_params.services_root_cdn;
|
|
764
|
+
}
|
|
647
765
|
|
|
648
|
-
/**
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
como.getLocationState = () => comoData.locationState;
|
|
659
|
-
|
|
660
|
-
/**
|
|
661
|
-
* Returns the location point shop items
|
|
662
|
-
*/
|
|
663
|
-
como.getPointShopItems = () => comoData.mainResources.menu.gifts_shop_item;
|
|
664
|
-
|
|
665
|
-
/**
|
|
666
|
-
*
|
|
667
|
-
* @param {string} resourceName resource name
|
|
668
|
-
*/
|
|
669
|
-
como.getMainResource = resourceName => comoData.mainResources[resourceName];
|
|
670
|
-
|
|
671
|
-
/**
|
|
672
|
-
*
|
|
673
|
-
* @param {string} resourceId resource id
|
|
674
|
-
* @param {string} namespace resource namespace
|
|
675
|
-
* @param {string|number} version resource version
|
|
676
|
-
*/
|
|
677
|
-
como.getResourceUrl = (resourceId, namespace, version) => {
|
|
678
|
-
const { api, env_params: env } = comoData;
|
|
679
|
-
return api.getResourceUrl(env.services_root_temp, resourceId, namespace, version);
|
|
680
|
-
};
|
|
766
|
+
/**
|
|
767
|
+
* @param {string} identifier fcm token created by firebase
|
|
768
|
+
* @param {boolean} isFirebaseProjectMigrated is migrated to new firebase project
|
|
769
|
+
*/
|
|
770
|
+
sendPushChannel(identifier, isFirebaseProjectMigrated = false) {
|
|
771
|
+
const {
|
|
772
|
+
api, locationId, token, env_params: env,
|
|
773
|
+
} = this.comoData;
|
|
774
|
+
return api.sendPushChannel(env.services_root, locationId, token, identifier, isFirebaseProjectMigrated);
|
|
775
|
+
}
|
|
681
776
|
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
} = comoData;
|
|
689
|
-
return api.sendPushChannel(env.services_root, locationId, token, identifier);
|
|
690
|
-
};
|
|
777
|
+
async getRegionConfig() {
|
|
778
|
+
const {
|
|
779
|
+
api, locationId, token, env_params: env,
|
|
780
|
+
} = this.comoData;
|
|
781
|
+
return api.getClientBusinessBackend(env.zapp_root, token, locationId);
|
|
782
|
+
}
|
|
691
783
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
784
|
+
/**
|
|
785
|
+
* @param {string} code coupon code entered by user on App
|
|
786
|
+
*/
|
|
787
|
+
sendCouponCode(code) {
|
|
788
|
+
const {
|
|
789
|
+
api, locationId, token, env_params: env,
|
|
790
|
+
} = this.comoData;
|
|
791
|
+
return api.sendCouponCode(env.zapp_root, locationId, token, code);
|
|
792
|
+
}
|
|
698
793
|
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
} = comoData;
|
|
706
|
-
return api.sendCouponCode(env.zapp_root, locationId, token, code);
|
|
707
|
-
};
|
|
794
|
+
async addPaymentMethod(cardToken) {
|
|
795
|
+
const {
|
|
796
|
+
api, locationId, token, env_params: env,
|
|
797
|
+
} = this.comoData;
|
|
798
|
+
return api.addPaymentMethod(env.services_root, locationId, token, cardToken);
|
|
799
|
+
}
|
|
708
800
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
}
|
|
801
|
+
async knowYourData(email) {
|
|
802
|
+
const {
|
|
803
|
+
api, locationId, token, env_params: env,
|
|
804
|
+
} = this.comoData;
|
|
805
|
+
return api.knowYourData(env.services_root, locationId, token, email);
|
|
806
|
+
}
|
|
715
807
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
};
|
|
808
|
+
async consentWithdraw(consentData) {
|
|
809
|
+
const {
|
|
810
|
+
api, locationId, token, env_params: env,
|
|
811
|
+
} = this.comoData;
|
|
812
|
+
return api.consentWithdraw(env.services_root, locationId, token, consentData);
|
|
813
|
+
}
|
|
723
814
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
como.payInApp = async (amount, creditCardToken, itemName, itemNumber, membershipKey) => {
|
|
732
|
-
const {
|
|
733
|
-
env_params: env, token, locationId, api,
|
|
734
|
-
} = comoData;
|
|
735
|
-
const responseJson = await api.payInApp(env.services_root, locationId, token, amount, creditCardToken, itemName, itemNumber, membershipKey);
|
|
736
|
-
return responseJson;
|
|
737
|
-
};
|
|
815
|
+
async getPaymentMethods() {
|
|
816
|
+
const {
|
|
817
|
+
env_params: env, locationId, api,
|
|
818
|
+
} = this.comoData;
|
|
819
|
+
const responseJson = await api.getPaymentMethods(env.services_root, locationId);
|
|
820
|
+
return responseJson;
|
|
821
|
+
}
|
|
738
822
|
|
|
739
|
-
/**
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
const {
|
|
754
|
-
api, locationId, env_params: env,
|
|
755
|
-
} = comoData;
|
|
756
|
-
return api.getMemberMessages(env.services_root, locationId, tag, limit, offset);
|
|
757
|
-
};
|
|
823
|
+
/**
|
|
824
|
+
* @param {Integer} amount to charge
|
|
825
|
+
* @param {String} creditCardToken to charge from
|
|
826
|
+
* @param {String} itemName for submit purchase
|
|
827
|
+
* @param {String} itemNumber for submit purchase
|
|
828
|
+
* @param {String} membershipKey for user identification
|
|
829
|
+
*/
|
|
830
|
+
async payInApp(amount, creditCardToken, itemName, itemNumber, membershipKey) {
|
|
831
|
+
const {
|
|
832
|
+
env_params: env, token, locationId, api,
|
|
833
|
+
} = this.comoData;
|
|
834
|
+
const responseJson = await api.payInApp(env.services_root, locationId, token, amount, creditCardToken, itemName, itemNumber, membershipKey);
|
|
835
|
+
return responseJson;
|
|
836
|
+
}
|
|
758
837
|
|
|
759
|
-
/**
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
838
|
+
/**
|
|
839
|
+
* @param {string} creditCardToken which card to delete
|
|
840
|
+
*/
|
|
841
|
+
async deletePayment(creditCardToken) {
|
|
842
|
+
const {
|
|
843
|
+
env_params: env, token, locationId, api,
|
|
844
|
+
} = this.comoData;
|
|
845
|
+
const responseJson = await api.deletePayment(env.services_root, locationId, token, creditCardToken);
|
|
846
|
+
return responseJson;
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* @param {string} tag for Pop-up Message Trigger (Optional param)
|
|
850
|
+
*/
|
|
851
|
+
getMemberMessages(tag, limit, offset) {
|
|
852
|
+
const {
|
|
853
|
+
api, locationId, env_params: env,
|
|
854
|
+
} = this.comoData;
|
|
855
|
+
return api.getMemberMessages(env.services_root, locationId, tag, limit, offset);
|
|
856
|
+
}
|
|
768
857
|
|
|
769
|
-
/**
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
} = comoData;
|
|
779
|
-
return api.budgetTransfer(env.services_root, locationId, receiver, sender, amount, wallet);
|
|
780
|
-
};
|
|
858
|
+
/**
|
|
859
|
+
* @param {string} keysList keys of the messages to mark as read
|
|
860
|
+
*/
|
|
861
|
+
markAsReadMemberMessages(keysList) {
|
|
862
|
+
const {
|
|
863
|
+
api, locationId, env_params: env,
|
|
864
|
+
} = this.comoData;
|
|
865
|
+
return api.markAsReadMemberMessages(env.services_root, locationId, keysList);
|
|
866
|
+
}
|
|
781
867
|
|
|
782
|
-
/**
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
868
|
+
/**
|
|
869
|
+
* @param {String} receiver to share with
|
|
870
|
+
* @param {String} sender name
|
|
871
|
+
* @param {Integer} amount to share
|
|
872
|
+
* @param {String} type of wallet
|
|
873
|
+
*/
|
|
874
|
+
async budgetTransfer(receiver, sender, amount, wallet) {
|
|
875
|
+
const {
|
|
876
|
+
api, locationId, env_params: env,
|
|
877
|
+
} = this.comoData;
|
|
878
|
+
return api.budgetTransfer(env.services_root, locationId, receiver, sender, amount, wallet);
|
|
879
|
+
}
|
|
791
880
|
|
|
881
|
+
/**
|
|
882
|
+
* @param {string} claimId key of the credit claim to read the data for
|
|
883
|
+
*/
|
|
884
|
+
getCreditClaimData(claimId) {
|
|
885
|
+
const {
|
|
886
|
+
api, env_params: env,
|
|
887
|
+
} = this.comoData;
|
|
888
|
+
return api.getCreditClaimData(env.services_root, claimId);
|
|
889
|
+
}
|
|
792
890
|
|
|
793
|
-
/**
|
|
794
|
-
* @param {String} claimCode to use for budget transfer claim
|
|
795
|
-
*/
|
|
796
|
-
como.budgetTransferClaim = async (claimCode) => {
|
|
797
|
-
const {
|
|
798
|
-
api, locationId, env_params: env,
|
|
799
|
-
} = comoData;
|
|
800
|
-
return api.budgetTransferClaim(env.services_root, locationId, claimCode);
|
|
801
|
-
};
|
|
802
891
|
|
|
803
|
-
/**
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
892
|
+
/**
|
|
893
|
+
* @param {String} claimCode to use for budget transfer claim
|
|
894
|
+
*/
|
|
895
|
+
async budgetTransferClaim(claimCode) {
|
|
896
|
+
const {
|
|
897
|
+
api, locationId, env_params: env,
|
|
898
|
+
} = this.comoData;
|
|
899
|
+
return api.budgetTransferClaim(env.services_root, locationId, claimCode);
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* API call for claim generic action. To specify your trigger button, you need to associate it with a particular item, asset or tag.
|
|
904
|
+
* @param {string} assetKey - asset to claim
|
|
905
|
+
* @param {string} itemId - item id to claim
|
|
906
|
+
* @param {string} tag - claim all with tag
|
|
907
|
+
*/
|
|
908
|
+
claim(assetKey, itemId, tag) {
|
|
909
|
+
const {
|
|
910
|
+
env_params: env, locationId, api, token,
|
|
911
|
+
} = this.comoData;
|
|
912
|
+
return api.claim(env.zapp_root, locationId, token, assetKey, itemId, tag);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* Log user action
|
|
917
|
+
* @param {string} action
|
|
918
|
+
* @param {string} logData - log information
|
|
919
|
+
*/
|
|
920
|
+
async logUserAction(action, logData) {
|
|
921
|
+
const {
|
|
922
|
+
env_params: env, locationId, api, token,
|
|
923
|
+
} = this.comoData;
|
|
924
|
+
return api.logUserAction(env.zapp_root, locationId, token, action, logData);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* Member purchase history
|
|
929
|
+
* @param {string} limit - how manay items to return (if exists) - default value is 25
|
|
930
|
+
* @param {string} offset - default value is 0(next offset would be 25)
|
|
931
|
+
*/
|
|
932
|
+
async getPurchaseHistory(limit, offset) {
|
|
933
|
+
const {
|
|
934
|
+
locationId, api, membership
|
|
935
|
+
} = this.comoData;
|
|
936
|
+
return api.getPurchaseHistory(locationId, membership.Key, limit, offset);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
815
939
|
|
|
816
|
-
module.exports =
|
|
940
|
+
module.exports = Como;
|