@live-change/email-service 0.2.5 → 0.2.11
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 +85 -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
|
|
|
@@ -51,6 +53,20 @@ definition.event({
|
|
|
51
53
|
}
|
|
52
54
|
})
|
|
53
55
|
|
|
56
|
+
definition.event({
|
|
57
|
+
name: "userDeleted",
|
|
58
|
+
properties: {
|
|
59
|
+
user: {
|
|
60
|
+
type: User,
|
|
61
|
+
validation: ['nonEmpty']
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
async execute({ user }) {
|
|
65
|
+
const emails = await Email.indexRangeGet('byUser', user)
|
|
66
|
+
await Promise.all(emails.map(email => Email.delete(email)))
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
|
|
54
70
|
definition.trigger({
|
|
55
71
|
name: "checkNewEmail",
|
|
56
72
|
properties: {
|
|
@@ -61,11 +77,40 @@ definition.trigger({
|
|
|
61
77
|
},
|
|
62
78
|
async execute({ email }, context, emit) {
|
|
63
79
|
const emailData = await Email.get(email)
|
|
64
|
-
if(emailData) throw 'taken'
|
|
80
|
+
if(emailData) throw { properties: { email: 'taken' } }
|
|
65
81
|
return true
|
|
66
82
|
}
|
|
67
83
|
})
|
|
68
84
|
|
|
85
|
+
definition.trigger({
|
|
86
|
+
name: "getEmail",
|
|
87
|
+
properties: {
|
|
88
|
+
email: {
|
|
89
|
+
type: String,
|
|
90
|
+
validation: ['nonEmpty', 'email']
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
async execute({ email }, context, emit) {
|
|
94
|
+
const emailData = await Email.get(email)
|
|
95
|
+
if(!emailData) throw { properties: { email: 'notFound' } }
|
|
96
|
+
return emailData
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
definition.trigger({
|
|
101
|
+
name: "getEmailOrNull",
|
|
102
|
+
properties: {
|
|
103
|
+
email: {
|
|
104
|
+
type: String,
|
|
105
|
+
validation: ['nonEmpty', 'email']
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
async execute({ email }, context, emit) {
|
|
109
|
+
const emailData = await Email.get(email)
|
|
110
|
+
return emailData
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
|
|
69
114
|
definition.trigger({
|
|
70
115
|
name: "connectEmail",
|
|
71
116
|
properties: {
|
|
@@ -81,7 +126,7 @@ definition.trigger({
|
|
|
81
126
|
async execute({ user, email }, { client, service }, emit) {
|
|
82
127
|
if(!email) throw new Error("no email")
|
|
83
128
|
const emailData = await Email.get(email)
|
|
84
|
-
if(emailData) throw 'taken'
|
|
129
|
+
if(emailData) throw { properties: { email: 'taken' } }
|
|
85
130
|
emit({
|
|
86
131
|
type: 'emailConnected',
|
|
87
132
|
user, email
|
|
@@ -104,7 +149,8 @@ definition.trigger({
|
|
|
104
149
|
},
|
|
105
150
|
async execute({ user, email }, { client, service }, emit) {
|
|
106
151
|
const emailData = await Email.get(email)
|
|
107
|
-
if(!emailData) throw 'notFound'
|
|
152
|
+
if(!emailData) throw { properties: { email: 'notFound' } }
|
|
153
|
+
if(emailData.user != user) throw { properties: { email: 'notFound' } }
|
|
108
154
|
emit({
|
|
109
155
|
type: 'emailDisconnected',
|
|
110
156
|
user, email
|
|
@@ -120,9 +166,9 @@ definition.trigger({
|
|
|
120
166
|
type: String
|
|
121
167
|
}
|
|
122
168
|
},
|
|
123
|
-
async execute({ email }, { client, service }, emit) {
|
|
169
|
+
async execute({ email, session }, { client, service }, emit) {
|
|
124
170
|
const emailData = await Email.get(email)
|
|
125
|
-
if(!emailData) throw '
|
|
171
|
+
if(!emailData) throw { properties: { email: 'notFound' } }
|
|
126
172
|
const { user } = emailData
|
|
127
173
|
return service.trigger({
|
|
128
174
|
type: 'signIn',
|
|
@@ -131,4 +177,33 @@ definition.trigger({
|
|
|
131
177
|
}
|
|
132
178
|
})
|
|
133
179
|
|
|
180
|
+
definition.trigger({
|
|
181
|
+
name: "getConnectedContacts",
|
|
182
|
+
properties: {
|
|
183
|
+
user: {
|
|
184
|
+
type: User,
|
|
185
|
+
validation: ['nonEmpty', 'email']
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
async execute({ user }, context, emit) {
|
|
189
|
+
const emails = await Email.indexRangeGet('byUser', user)
|
|
190
|
+
return emails.map(email => ({ ...email, type: 'email', contact: email.email }))
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
definition.trigger({
|
|
195
|
+
name: 'userDeleted',
|
|
196
|
+
properties: {
|
|
197
|
+
user: {
|
|
198
|
+
type: User
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
async execute({ user }, { service }, emit) {
|
|
202
|
+
emit([{
|
|
203
|
+
type: "userDeleted",
|
|
204
|
+
user
|
|
205
|
+
}])
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
|
|
134
209
|
module.exports = { Email }
|
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.11",
|
|
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": "2b95c89678f276d6b3a039652169c5fc819df8df"
|
|
32
32
|
}
|