@live-change/message-authentication-service 0.2.4 → 0.2.9
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 +150 -30
- 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
|
|
@@ -160,7 +177,10 @@ definition.action({
|
|
|
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 {
|
|
@@ -210,7 +231,7 @@ definition.trigger({
|
|
|
210
231
|
const user = app.generateUid()
|
|
211
232
|
await service.trigger({
|
|
212
233
|
type: 'connect' + contactTypeUpperCase,
|
|
213
|
-
[
|
|
234
|
+
[contactTypeName]: contact,
|
|
214
235
|
user
|
|
215
236
|
})
|
|
216
237
|
await service.trigger({
|
|
@@ -227,74 +248,149 @@ 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
|
}
|
|
238
277
|
})
|
|
239
278
|
|
|
240
279
|
for(const contactType of config.contactTypes) {
|
|
241
|
-
const contactTypeUpperCaseName = contactType[0].toUpperCase() + contactType.slice(1)
|
|
242
280
|
|
|
243
281
|
const contactConfig = (typeof contactType == "string") ? { name: contactType } : contactType
|
|
244
|
-
|
|
245
282
|
const contactTypeName = contactConfig.name
|
|
246
283
|
const contactTypeUName = contactTypeName[0].toUpperCase() + contactTypeName.slice(1)
|
|
247
284
|
|
|
248
285
|
const contactTypeProperties = {
|
|
249
|
-
[
|
|
286
|
+
[contactTypeName]: {
|
|
250
287
|
type: String,
|
|
251
288
|
validation: ['nonEmpty', contactTypeName]
|
|
252
289
|
}
|
|
253
290
|
}
|
|
254
291
|
|
|
255
|
-
if(contactConfig.signUp || config.signUp
|
|
292
|
+
if(contactConfig.signUp || config.signUp) {
|
|
256
293
|
definition.action({
|
|
257
|
-
name: '
|
|
294
|
+
name: 'signUp' + contactTypeUName,
|
|
258
295
|
waitForEvents: true,
|
|
259
296
|
properties: {
|
|
260
297
|
...contactTypeProperties
|
|
261
298
|
},
|
|
262
299
|
async execute({ [contactTypeName]: contact }, { client, service }, emit) {
|
|
263
|
-
|
|
300
|
+
await service.trigger({
|
|
301
|
+
type: 'checkNew' + contactTypeUName,
|
|
302
|
+
[contactTypeName]: contact,
|
|
303
|
+
})
|
|
304
|
+
return service.triggerService(definition.name, {
|
|
305
|
+
type: 'authenticateWithMessage',
|
|
306
|
+
contactType,
|
|
307
|
+
contact,
|
|
308
|
+
action: 'signUpWithMessage',
|
|
309
|
+
targetPage: config.signUpTargetPage || { name: 'user:signUpFinished' }
|
|
310
|
+
})
|
|
264
311
|
}
|
|
265
312
|
})
|
|
266
313
|
}
|
|
267
314
|
|
|
268
|
-
if(contactConfig.
|
|
315
|
+
if(contactConfig.signUp || config.signUp || contactConfig.signIn || config.signIn) {
|
|
269
316
|
definition.action({
|
|
270
|
-
name: '
|
|
317
|
+
name: 'signIn' + contactTypeUName,
|
|
318
|
+
waitForEvents: true,
|
|
271
319
|
properties: {
|
|
272
320
|
...contactTypeProperties
|
|
273
321
|
},
|
|
274
322
|
async execute({ [contactTypeName]: contact }, { client, service }, emit) {
|
|
275
|
-
|
|
323
|
+
const contactData = await service.trigger({
|
|
324
|
+
type: 'get' + contactTypeUName,
|
|
325
|
+
[contactTypeName]: contact,
|
|
326
|
+
})
|
|
327
|
+
const messageData = {
|
|
328
|
+
user: contactData.user
|
|
329
|
+
}
|
|
330
|
+
return service.triggerService(definition.name, {
|
|
331
|
+
type: 'authenticateWithMessage',
|
|
332
|
+
contactType,
|
|
333
|
+
contact,
|
|
334
|
+
messageData,
|
|
335
|
+
action: 'signInWithMessage',
|
|
336
|
+
targetPage: config.signInTargetPage || { name: 'user:signInFinished' }
|
|
337
|
+
})
|
|
276
338
|
}
|
|
277
339
|
})
|
|
278
340
|
}
|
|
279
341
|
|
|
280
|
-
if(contactConfig.
|
|
342
|
+
if(contactConfig.connect || config.connect ) {
|
|
281
343
|
definition.action({
|
|
282
|
-
name: '
|
|
283
|
-
waitForEvents: true,
|
|
344
|
+
name: 'connect' + contactTypeUName,
|
|
284
345
|
properties: {
|
|
285
346
|
...contactTypeProperties
|
|
286
347
|
},
|
|
348
|
+
access: (params, { client }) => {
|
|
349
|
+
return !!client.user
|
|
350
|
+
},
|
|
287
351
|
async execute({ [contactTypeName]: contact }, { client, service }, emit) {
|
|
288
352
|
await service.trigger({
|
|
289
353
|
type: 'checkNew' + contactTypeUName,
|
|
290
|
-
[
|
|
354
|
+
[contactTypeName]: contact,
|
|
291
355
|
})
|
|
292
356
|
return service.triggerService(definition.name, {
|
|
293
357
|
type: 'authenticateWithMessage',
|
|
294
358
|
contactType,
|
|
295
359
|
contact,
|
|
296
|
-
action: '
|
|
297
|
-
|
|
360
|
+
action: 'connectWithMessage',
|
|
361
|
+
actionProperties: {
|
|
362
|
+
user: client.user
|
|
363
|
+
},
|
|
364
|
+
messageData: {
|
|
365
|
+
user: client.user
|
|
366
|
+
},
|
|
367
|
+
targetPage: config.signUpTargetPage || { name: 'user:connectFinished' }
|
|
368
|
+
})
|
|
369
|
+
}
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
definition.action({
|
|
373
|
+
name: 'disconnect' + contactTypeUName,
|
|
374
|
+
properties: {
|
|
375
|
+
...contactTypeProperties
|
|
376
|
+
},
|
|
377
|
+
access: (params, { client }) => {
|
|
378
|
+
return !!client.user
|
|
379
|
+
},
|
|
380
|
+
async execute({ [contactTypeName]: contact }, { client, service }, emit) {
|
|
381
|
+
const contacts = (await service.trigger({
|
|
382
|
+
type: 'getConnectedContacts',
|
|
383
|
+
user: client.user
|
|
384
|
+
})).flat()
|
|
385
|
+
console.log("CONTACTS", contacts, contactTypeName, contact)
|
|
386
|
+
const contactData = contacts.find(c => c.type == contactTypeName && c.contact == contact)
|
|
387
|
+
if(!contactData) throw 'notFound'
|
|
388
|
+
if(contacts.length == 1) throw 'lastOne'
|
|
389
|
+
console.log("DISCONNECT", contact)
|
|
390
|
+
return await service.trigger({
|
|
391
|
+
type: 'disconnect' + contactTypeUName,
|
|
392
|
+
[contactTypeName]: contact,
|
|
393
|
+
user: client.user
|
|
298
394
|
})
|
|
299
395
|
}
|
|
300
396
|
})
|
|
@@ -302,13 +398,37 @@ for(const contactType of config.contactTypes) {
|
|
|
302
398
|
|
|
303
399
|
if(contactConfig.signUp || config.signUp) {
|
|
304
400
|
definition.action({
|
|
305
|
-
name: 'signInOrSignUp' +
|
|
401
|
+
name: 'signInOrSignUp' + contactTypeUName,
|
|
306
402
|
waitForEvents: true,
|
|
307
403
|
properties: {
|
|
308
404
|
...contactTypeProperties
|
|
309
405
|
},
|
|
310
|
-
async execute({ [
|
|
311
|
-
|
|
406
|
+
async execute({ [contactTypeName]: contact }, { client, service }, emit) {
|
|
407
|
+
const contactData = await service.trigger({
|
|
408
|
+
type: 'get' + contactTypeUName + 'OrNull',
|
|
409
|
+
[contactTypeName]: contact,
|
|
410
|
+
})
|
|
411
|
+
if(contactData) {
|
|
412
|
+
const messageData = {
|
|
413
|
+
user: contactData.user
|
|
414
|
+
}
|
|
415
|
+
return service.triggerService(definition.name, {
|
|
416
|
+
type: 'authenticateWithMessage',
|
|
417
|
+
contactType,
|
|
418
|
+
contact,
|
|
419
|
+
messageData,
|
|
420
|
+
action: 'signInWithMessage',
|
|
421
|
+
targetPage: config.signInTargetPage || { name: 'user:signInFinished' }
|
|
422
|
+
})
|
|
423
|
+
} else {
|
|
424
|
+
return service.triggerService(definition.name, {
|
|
425
|
+
type: 'authenticateWithMessage',
|
|
426
|
+
contactType,
|
|
427
|
+
contact,
|
|
428
|
+
action: 'signUpWithMessage',
|
|
429
|
+
targetPage: config.signUpTargetPage || { name: 'user:signUpFinished' }
|
|
430
|
+
})
|
|
431
|
+
}
|
|
312
432
|
}
|
|
313
433
|
})
|
|
314
434
|
}
|
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.9",
|
|
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": "5362172c498a5d131b945c4a2f4644565a5c9a3c"
|
|
28
28
|
}
|