@live-change/email-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/auth.js +56 -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: {
|
|
@@ -81,7 +112,7 @@ definition.trigger({
|
|
|
81
112
|
async execute({ user, email }, { client, service }, emit) {
|
|
82
113
|
if(!email) throw new Error("no email")
|
|
83
114
|
const emailData = await Email.get(email)
|
|
84
|
-
if(emailData) throw 'taken'
|
|
115
|
+
if(emailData) throw { properties: { email: 'taken' } }
|
|
85
116
|
emit({
|
|
86
117
|
type: 'emailConnected',
|
|
87
118
|
user, email
|
|
@@ -104,7 +135,8 @@ definition.trigger({
|
|
|
104
135
|
},
|
|
105
136
|
async execute({ user, email }, { client, service }, emit) {
|
|
106
137
|
const emailData = await Email.get(email)
|
|
107
|
-
if(!emailData) throw 'notFound'
|
|
138
|
+
if(!emailData) throw { properties: { email: 'notFound' } }
|
|
139
|
+
if(emailData.user != user) throw { properties: { email: 'notFound' } }
|
|
108
140
|
emit({
|
|
109
141
|
type: 'emailDisconnected',
|
|
110
142
|
user, email
|
|
@@ -120,9 +152,9 @@ definition.trigger({
|
|
|
120
152
|
type: String
|
|
121
153
|
}
|
|
122
154
|
},
|
|
123
|
-
async execute({ email }, { client, service }, emit) {
|
|
155
|
+
async execute({ email, session }, { client, service }, emit) {
|
|
124
156
|
const emailData = await Email.get(email)
|
|
125
|
-
if(!emailData) throw '
|
|
157
|
+
if(!emailData) throw { properties: { email: 'notFound' } }
|
|
126
158
|
const { user } = emailData
|
|
127
159
|
return service.trigger({
|
|
128
160
|
type: 'signIn',
|
|
@@ -131,4 +163,18 @@ definition.trigger({
|
|
|
131
163
|
}
|
|
132
164
|
})
|
|
133
165
|
|
|
166
|
+
definition.trigger({
|
|
167
|
+
name: "getConnectedContacts",
|
|
168
|
+
properties: {
|
|
169
|
+
user: {
|
|
170
|
+
type: User,
|
|
171
|
+
validation: ['nonEmpty', 'email']
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
async execute({ user }, context, emit) {
|
|
175
|
+
const emails = await Email.indexRangeGet('byUser', user)
|
|
176
|
+
return emails.map(email => ({ ...email, type: 'email', contact: email.email }))
|
|
177
|
+
}
|
|
178
|
+
})
|
|
179
|
+
|
|
134
180
|
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.9",
|
|
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": "5362172c498a5d131b945c4a2f4644565a5c9a3c"
|
|
32
32
|
}
|