@live-change/message-authentication-service 0.2.3 → 0.2.8
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 +120 -24
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -41,11 +41,18 @@ const targetProperties = {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
const messageProperties = {
|
|
45
|
+
messageData: {
|
|
46
|
+
type: Object
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
44
50
|
const Authentication = definition.model({
|
|
45
51
|
name: 'Authentication',
|
|
46
52
|
properties: {
|
|
47
53
|
...contactProperties,
|
|
48
54
|
...targetProperties,
|
|
55
|
+
...messageProperties,
|
|
49
56
|
state: {
|
|
50
57
|
type: "String",
|
|
51
58
|
validation: ['nonEmpty'],
|
|
@@ -69,11 +76,12 @@ definition.view({
|
|
|
69
76
|
|
|
70
77
|
definition.event({
|
|
71
78
|
name: 'authenticationCreated',
|
|
72
|
-
execute({ authentication, contactType, contact, action, actionProperties, targetPage }) {
|
|
79
|
+
execute({ authentication, contactType, contact, action, actionProperties, targetPage, messageData }) {
|
|
73
80
|
return Authentication.create({
|
|
74
81
|
id: authentication,
|
|
75
82
|
contactType, contact,
|
|
76
83
|
action, actionProperties, targetPage,
|
|
84
|
+
messageData,
|
|
77
85
|
state: 'created'
|
|
78
86
|
})
|
|
79
87
|
}
|
|
@@ -91,9 +99,11 @@ definition.trigger({
|
|
|
91
99
|
waitForEvents: true,
|
|
92
100
|
properties: {
|
|
93
101
|
...contactProperties,
|
|
94
|
-
...targetProperties
|
|
102
|
+
...targetProperties,
|
|
103
|
+
...messageProperties
|
|
95
104
|
},
|
|
96
|
-
async execute({ contactType, contact, action, actionProperties, targetPage
|
|
105
|
+
async execute({ contactType, contact, action, actionProperties, targetPage, messageData },
|
|
106
|
+
{ client, service }, emit) {
|
|
97
107
|
const authentication = app.generateUid()
|
|
98
108
|
const secrets = await service.trigger({
|
|
99
109
|
type: 'authenticationSecret',
|
|
@@ -107,7 +117,8 @@ definition.trigger({
|
|
|
107
117
|
action,
|
|
108
118
|
contactType,
|
|
109
119
|
contact,
|
|
110
|
-
secrets
|
|
120
|
+
secrets,
|
|
121
|
+
...messageData
|
|
111
122
|
}
|
|
112
123
|
})
|
|
113
124
|
emit({
|
|
@@ -117,9 +128,11 @@ definition.trigger({
|
|
|
117
128
|
contact,
|
|
118
129
|
action,
|
|
119
130
|
actionProperties,
|
|
120
|
-
targetPage
|
|
131
|
+
targetPage,
|
|
132
|
+
messageData
|
|
121
133
|
})
|
|
122
134
|
return {
|
|
135
|
+
type: 'sent',
|
|
123
136
|
authentication,
|
|
124
137
|
secrets: secrets.map(({ secret, ...notSecret }) => notSecret)
|
|
125
138
|
}
|
|
@@ -137,15 +150,19 @@ definition.action({
|
|
|
137
150
|
secret: {
|
|
138
151
|
type: String,
|
|
139
152
|
validation: ['nonEmpty']
|
|
153
|
+
},
|
|
154
|
+
authentication: {
|
|
155
|
+
type: Authentication
|
|
140
156
|
}
|
|
141
157
|
},
|
|
142
|
-
async execute({ secretType, secret }, { client, service }, emit) {
|
|
158
|
+
async execute({ secretType, secret, authentication = undefined }, { client, service }, emit) {
|
|
143
159
|
const secretTypeUpperCase = secretType[0].toUpperCase() + secretType.slice(1)
|
|
144
160
|
const checkResults = await service.trigger({
|
|
145
161
|
type: 'check' + secretTypeUpperCase + 'Secret',
|
|
146
|
-
secret
|
|
162
|
+
secret,
|
|
163
|
+
authentication
|
|
147
164
|
})
|
|
148
|
-
|
|
165
|
+
authentication = checkResults[0]
|
|
149
166
|
const authenticationData = await Authentication.get(authentication)
|
|
150
167
|
if(authenticationData.state == 'used') throw 'authenticationUsed'
|
|
151
168
|
const actionName = authenticationData.action
|
|
@@ -153,14 +170,17 @@ definition.action({
|
|
|
153
170
|
type: actionName+'Authenticated',
|
|
154
171
|
...authenticationData.actionProperties,
|
|
155
172
|
contactType: authenticationData.contactType,
|
|
156
|
-
contact:
|
|
173
|
+
contact: authenticationData.contact,
|
|
157
174
|
session: client.session
|
|
158
175
|
})
|
|
159
176
|
emit({
|
|
160
177
|
type: 'authenticationUsed',
|
|
161
178
|
authentication
|
|
162
179
|
})
|
|
163
|
-
return
|
|
180
|
+
return {
|
|
181
|
+
result: actionResults[0],
|
|
182
|
+
targetPage: authenticationData.targetPage
|
|
183
|
+
}
|
|
164
184
|
}
|
|
165
185
|
})
|
|
166
186
|
|
|
@@ -189,7 +209,8 @@ definition.action({
|
|
|
189
209
|
action,
|
|
190
210
|
contactType,
|
|
191
211
|
contact,
|
|
192
|
-
secrets
|
|
212
|
+
secrets,
|
|
213
|
+
...authentication.messageData
|
|
193
214
|
}
|
|
194
215
|
})
|
|
195
216
|
return {
|
|
@@ -227,11 +248,29 @@ definition.trigger({
|
|
|
227
248
|
properties: {
|
|
228
249
|
...contactProperties
|
|
229
250
|
},
|
|
230
|
-
async execute({ contactType, contact }, { client, service }, emit) {
|
|
251
|
+
async execute({ contactType, contact, session }, { client, service }, emit) {
|
|
231
252
|
const contactTypeUpperCase = contactType[0].toUpperCase() + contactType.slice(1)
|
|
232
253
|
const user = await service.trigger({
|
|
233
254
|
type: 'signIn' + contactTypeUpperCase,
|
|
234
255
|
[contactType]: contact,
|
|
256
|
+
session
|
|
257
|
+
})
|
|
258
|
+
return user
|
|
259
|
+
}
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
definition.trigger({
|
|
263
|
+
name: 'connectWithMessageAuthenticated',
|
|
264
|
+
waitForEvents: true,
|
|
265
|
+
properties: {
|
|
266
|
+
...contactProperties
|
|
267
|
+
},
|
|
268
|
+
async execute({ contactType, contact, user }, { client, service }, emit) {
|
|
269
|
+
const contactTypeUpperCase = contactType[0].toUpperCase() + contactType.slice(1)
|
|
270
|
+
await service.trigger({
|
|
271
|
+
type: 'connect' + contactTypeUpperCase,
|
|
272
|
+
[contactType]: contact,
|
|
273
|
+
user
|
|
235
274
|
})
|
|
236
275
|
return user
|
|
237
276
|
}
|
|
@@ -252,38 +291,65 @@ for(const contactType of config.contactTypes) {
|
|
|
252
291
|
}
|
|
253
292
|
}
|
|
254
293
|
|
|
255
|
-
if(contactConfig.signUp || config.signUp
|
|
294
|
+
if(contactConfig.signUp || config.signUp) {
|
|
256
295
|
definition.action({
|
|
257
|
-
name: '
|
|
296
|
+
name: 'signUp' + contactTypeUpperCaseName,
|
|
258
297
|
waitForEvents: true,
|
|
259
298
|
properties: {
|
|
260
299
|
...contactTypeProperties
|
|
261
300
|
},
|
|
262
301
|
async execute({ [contactTypeName]: contact }, { client, service }, emit) {
|
|
263
|
-
|
|
302
|
+
await service.trigger({
|
|
303
|
+
type: 'checkNew' + contactTypeUName,
|
|
304
|
+
[contactType]: contact,
|
|
305
|
+
})
|
|
306
|
+
return service.triggerService(definition.name, {
|
|
307
|
+
type: 'authenticateWithMessage',
|
|
308
|
+
contactType,
|
|
309
|
+
contact,
|
|
310
|
+
action: 'signUpWithMessage',
|
|
311
|
+
targetPage: config.signUpTargetPage || { name: 'user:signUpFinished' }
|
|
312
|
+
})
|
|
264
313
|
}
|
|
265
314
|
})
|
|
266
315
|
}
|
|
267
316
|
|
|
268
|
-
if(contactConfig.
|
|
317
|
+
if(contactConfig.signUp || config.signUp || contactConfig.signIn || config.signIn) {
|
|
269
318
|
definition.action({
|
|
270
|
-
name: '
|
|
319
|
+
name: 'signIn' + contactTypeUpperCaseName,
|
|
320
|
+
waitForEvents: true,
|
|
271
321
|
properties: {
|
|
272
322
|
...contactTypeProperties
|
|
273
323
|
},
|
|
274
324
|
async execute({ [contactTypeName]: contact }, { client, service }, emit) {
|
|
275
|
-
|
|
325
|
+
const contactData = await service.trigger({
|
|
326
|
+
type: 'get' + contactTypeUName,
|
|
327
|
+
[contactType]: contact,
|
|
328
|
+
})
|
|
329
|
+
const messageData = {
|
|
330
|
+
user: contactData.user
|
|
331
|
+
}
|
|
332
|
+
return service.triggerService(definition.name, {
|
|
333
|
+
type: 'authenticateWithMessage',
|
|
334
|
+
contactType,
|
|
335
|
+
contact,
|
|
336
|
+
messageData,
|
|
337
|
+
action: 'signInWithMessage',
|
|
338
|
+
targetPage: config.signInTargetPage || { name: 'user:signInFinished' }
|
|
339
|
+
})
|
|
276
340
|
}
|
|
277
341
|
})
|
|
278
342
|
}
|
|
279
343
|
|
|
280
|
-
if(contactConfig.
|
|
344
|
+
if(contactConfig.connect || config.connect ) {
|
|
281
345
|
definition.action({
|
|
282
|
-
name: '
|
|
283
|
-
waitForEvents: true,
|
|
346
|
+
name: 'connect' + contactTypeUpperCaseName,
|
|
284
347
|
properties: {
|
|
285
348
|
...contactTypeProperties
|
|
286
349
|
},
|
|
350
|
+
access: (params, { client }) => {
|
|
351
|
+
return !!client.user
|
|
352
|
+
},
|
|
287
353
|
async execute({ [contactTypeName]: contact }, { client, service }, emit) {
|
|
288
354
|
await service.trigger({
|
|
289
355
|
type: 'checkNew' + contactTypeUName,
|
|
@@ -293,8 +359,14 @@ for(const contactType of config.contactTypes) {
|
|
|
293
359
|
type: 'authenticateWithMessage',
|
|
294
360
|
contactType,
|
|
295
361
|
contact,
|
|
296
|
-
action: '
|
|
297
|
-
|
|
362
|
+
action: 'connectWithMessage',
|
|
363
|
+
actionProperties: {
|
|
364
|
+
user: client.user
|
|
365
|
+
},
|
|
366
|
+
messageData: {
|
|
367
|
+
user: client.user
|
|
368
|
+
},
|
|
369
|
+
targetPage: config.signUpTargetPage || { name: 'user:connectFinished' }
|
|
298
370
|
})
|
|
299
371
|
}
|
|
300
372
|
})
|
|
@@ -308,7 +380,31 @@ for(const contactType of config.contactTypes) {
|
|
|
308
380
|
...contactTypeProperties
|
|
309
381
|
},
|
|
310
382
|
async execute({ [contactType]: contact }, { client, service }, emit) {
|
|
311
|
-
|
|
383
|
+
const contactData = await service.trigger({
|
|
384
|
+
type: 'get' + contactTypeUName + 'OrNull',
|
|
385
|
+
[contactType]: contact,
|
|
386
|
+
})
|
|
387
|
+
if(contactData) {
|
|
388
|
+
const messageData = {
|
|
389
|
+
user: contactData.user
|
|
390
|
+
}
|
|
391
|
+
return service.triggerService(definition.name, {
|
|
392
|
+
type: 'authenticateWithMessage',
|
|
393
|
+
contactType,
|
|
394
|
+
contact,
|
|
395
|
+
messageData,
|
|
396
|
+
action: 'signInWithMessage',
|
|
397
|
+
targetPage: config.signInTargetPage || { name: 'user:signInFinished' }
|
|
398
|
+
})
|
|
399
|
+
} else {
|
|
400
|
+
return service.triggerService(definition.name, {
|
|
401
|
+
type: 'authenticateWithMessage',
|
|
402
|
+
contactType,
|
|
403
|
+
contact,
|
|
404
|
+
action: 'signUpWithMessage',
|
|
405
|
+
targetPage: config.signUpTargetPage || { name: 'user:signUpFinished' }
|
|
406
|
+
})
|
|
407
|
+
}
|
|
312
408
|
}
|
|
313
409
|
})
|
|
314
410
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/message-authentication-service",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"@live-change/framework": "^0.5.7",
|
|
25
25
|
"nodemailer": "^6.7.2"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "1e8102d02b6745fea401e967c211c6a9cb03e19b"
|
|
28
28
|
}
|