@live-change/email-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/auth.js +42 -10
- package/package.json +2 -2
package/auth.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
const { validation } = require('@live-change/framework')
|
|
1
2
|
const definition = require('./definition.js')
|
|
2
3
|
|
|
3
4
|
const User = definition.foreignModel('user', 'User')
|
|
4
5
|
|
|
5
6
|
const Email = definition.model({
|
|
6
7
|
name: 'Email',
|
|
8
|
+
properties: {
|
|
9
|
+
email: {
|
|
10
|
+
type: String,
|
|
11
|
+
validation: ['nonEmpty', 'email']
|
|
12
|
+
}
|
|
13
|
+
},
|
|
7
14
|
userItem: {
|
|
8
15
|
userReadAccess: () => true
|
|
9
|
-
},
|
|
10
|
-
indexes: {
|
|
11
|
-
byEmail: {
|
|
12
|
-
property: 'email'
|
|
13
|
-
}
|
|
14
16
|
}
|
|
15
17
|
})
|
|
16
18
|
|
|
@@ -61,11 +63,40 @@ definition.trigger({
|
|
|
61
63
|
},
|
|
62
64
|
async execute({ email }, context, emit) {
|
|
63
65
|
const emailData = await Email.get(email)
|
|
64
|
-
if(emailData) throw 'taken'
|
|
66
|
+
if(emailData) throw { properties: { email: 'taken' } }
|
|
65
67
|
return true
|
|
66
68
|
}
|
|
67
69
|
})
|
|
68
70
|
|
|
71
|
+
definition.trigger({
|
|
72
|
+
name: "getEmail",
|
|
73
|
+
properties: {
|
|
74
|
+
email: {
|
|
75
|
+
type: String,
|
|
76
|
+
validation: ['nonEmpty', 'email']
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
async execute({ email }, context, emit) {
|
|
80
|
+
const emailData = await Email.get(email)
|
|
81
|
+
if(!emailData) throw { properties: { email: 'notFound' } }
|
|
82
|
+
return emailData
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
definition.trigger({
|
|
87
|
+
name: "getEmailOrNull",
|
|
88
|
+
properties: {
|
|
89
|
+
email: {
|
|
90
|
+
type: String,
|
|
91
|
+
validation: ['nonEmpty', 'email']
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
async execute({ email }, context, emit) {
|
|
95
|
+
const emailData = await Email.get(email)
|
|
96
|
+
return emailData
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
|
|
69
100
|
definition.trigger({
|
|
70
101
|
name: "connectEmail",
|
|
71
102
|
properties: {
|
|
@@ -79,8 +110,9 @@ definition.trigger({
|
|
|
79
110
|
}
|
|
80
111
|
},
|
|
81
112
|
async execute({ user, email }, { client, service }, emit) {
|
|
113
|
+
if(!email) throw new Error("no email")
|
|
82
114
|
const emailData = await Email.get(email)
|
|
83
|
-
if(emailData) throw 'taken'
|
|
115
|
+
if(emailData) throw { properties: { email: 'taken' } }
|
|
84
116
|
emit({
|
|
85
117
|
type: 'emailConnected',
|
|
86
118
|
user, email
|
|
@@ -103,7 +135,7 @@ definition.trigger({
|
|
|
103
135
|
},
|
|
104
136
|
async execute({ user, email }, { client, service }, emit) {
|
|
105
137
|
const emailData = await Email.get(email)
|
|
106
|
-
if(!emailData) throw 'notFound'
|
|
138
|
+
if(!emailData) throw { properties: { email: 'notFound' } }
|
|
107
139
|
emit({
|
|
108
140
|
type: 'emailDisconnected',
|
|
109
141
|
user, email
|
|
@@ -119,9 +151,9 @@ definition.trigger({
|
|
|
119
151
|
type: String
|
|
120
152
|
}
|
|
121
153
|
},
|
|
122
|
-
async execute({ email }, { client, service }, emit) {
|
|
154
|
+
async execute({ email, session }, { client, service }, emit) {
|
|
123
155
|
const emailData = await Email.get(email)
|
|
124
|
-
if(!emailData) throw '
|
|
156
|
+
if(!emailData) throw { properties: { email: 'notFound' } }
|
|
125
157
|
const { user } = emailData
|
|
126
158
|
return service.trigger({
|
|
127
159
|
type: 'signIn',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/email-service",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"jsdom": "^18.1.1",
|
|
29
29
|
"nodemailer": "^6.7.2"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "1e8102d02b6745fea401e967c211c6a9cb03e19b"
|
|
32
32
|
}
|