@live-change/email-service 0.2.6 → 0.2.15

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.
Files changed (2) hide show
  1. package/auth.js +63 -10
  2. package/package.json +2 -2
package/auth.js CHANGED
@@ -13,11 +13,6 @@ const Email = definition.model({
13
13
  },
14
14
  userItem: {
15
15
  userReadAccess: () => true
16
- },
17
- indexes: {
18
- byEmail: {
19
- property: 'email'
20
- }
21
16
  }
22
17
  })
23
18
 
@@ -58,6 +53,20 @@ definition.event({
58
53
  }
59
54
  })
60
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
+
61
70
  definition.trigger({
62
71
  name: "checkNewEmail",
63
72
  properties: {
@@ -68,7 +77,7 @@ definition.trigger({
68
77
  },
69
78
  async execute({ email }, context, emit) {
70
79
  const emailData = await Email.get(email)
71
- if(emailData) throw 'taken'
80
+ if(emailData) throw { properties: { email: 'taken' } }
72
81
  return true
73
82
  }
74
83
  })
@@ -83,7 +92,21 @@ definition.trigger({
83
92
  },
84
93
  async execute({ email }, context, emit) {
85
94
  const emailData = await Email.get(email)
86
- if(!emailData) throw 'notFound'
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)
87
110
  return emailData
88
111
  }
89
112
  })
@@ -103,7 +126,7 @@ definition.trigger({
103
126
  async execute({ user, email }, { client, service }, emit) {
104
127
  if(!email) throw new Error("no email")
105
128
  const emailData = await Email.get(email)
106
- if(emailData) throw 'taken'
129
+ if(emailData) throw { properties: { email: 'taken' } }
107
130
  emit({
108
131
  type: 'emailConnected',
109
132
  user, email
@@ -126,7 +149,8 @@ definition.trigger({
126
149
  },
127
150
  async execute({ user, email }, { client, service }, emit) {
128
151
  const emailData = await Email.get(email)
129
- if(!emailData) throw 'notFound'
152
+ if(!emailData) throw { properties: { email: 'notFound' } }
153
+ if(emailData.user != user) throw { properties: { email: 'notFound' } }
130
154
  emit({
131
155
  type: 'emailDisconnected',
132
156
  user, email
@@ -144,7 +168,7 @@ definition.trigger({
144
168
  },
145
169
  async execute({ email, session }, { client, service }, emit) {
146
170
  const emailData = await Email.get(email)
147
- if(!emailData) throw 'emailNotFound'
171
+ if(!emailData) throw { properties: { email: 'notFound' } }
148
172
  const { user } = emailData
149
173
  return service.trigger({
150
174
  type: 'signIn',
@@ -153,4 +177,33 @@ definition.trigger({
153
177
  }
154
178
  })
155
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
+
156
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.6",
3
+ "version": "0.2.15",
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": "2491e82b350403cf187887e8f06d140e0c362860"
31
+ "gitHead": "86bc53700aca24da682d1dd414428f03cdc8d2f5"
32
32
  }