@live-change/phone-service 0.8.88 → 0.8.90
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 +17 -8
- package/package.json +4 -4
package/auth.js
CHANGED
|
@@ -2,18 +2,20 @@ import App from '@live-change/framework'
|
|
|
2
2
|
const validation = App.validation
|
|
3
3
|
import definition from './definition.js'
|
|
4
4
|
|
|
5
|
+
const preFilter = phone => {
|
|
6
|
+
// replace leading + with 0
|
|
7
|
+
phone = phone.replace(/^\+/, '0')
|
|
8
|
+
phone = phone.replace(/[^0-9]/g, '')
|
|
9
|
+
return phone
|
|
10
|
+
}
|
|
11
|
+
|
|
5
12
|
const User = definition.foreignModel('user', 'User')
|
|
6
13
|
const Phone = definition.model({
|
|
7
14
|
name: 'Phone',
|
|
8
15
|
properties: {
|
|
9
16
|
phone: {
|
|
10
17
|
type: String,
|
|
11
|
-
preFilter
|
|
12
|
-
// replace leading + with 0
|
|
13
|
-
phone = phone.replace(/^\+/, '0')
|
|
14
|
-
phone = phone.replace(/[^0-9]/g, '')
|
|
15
|
-
return phone
|
|
16
|
-
},
|
|
18
|
+
preFilter,
|
|
17
19
|
validation: ['nonEmpty', 'phone']
|
|
18
20
|
}
|
|
19
21
|
},
|
|
@@ -72,6 +74,7 @@ definition.event({
|
|
|
72
74
|
}
|
|
73
75
|
},
|
|
74
76
|
async execute({ user, phone }) {
|
|
77
|
+
phone = preFilter(phone)
|
|
75
78
|
await Phone.delete(phone)
|
|
76
79
|
}
|
|
77
80
|
})
|
|
@@ -99,8 +102,9 @@ definition.trigger({
|
|
|
99
102
|
}
|
|
100
103
|
},
|
|
101
104
|
async execute({ phone }, context, emit) {
|
|
105
|
+
phone = preFilter(phone)
|
|
102
106
|
const phoneData = await Phone.get(phone)
|
|
103
|
-
if(phoneData) throw { properties: { phone: '
|
|
107
|
+
if(phoneData) throw { properties: { phone: 'phoneTaken' } }
|
|
104
108
|
return true
|
|
105
109
|
}
|
|
106
110
|
})
|
|
@@ -114,6 +118,7 @@ definition.trigger({
|
|
|
114
118
|
}
|
|
115
119
|
},
|
|
116
120
|
async execute({ phone }, context, emit) {
|
|
121
|
+
phone = preFilter(phone)
|
|
117
122
|
const phoneData = await Phone.get(phone)
|
|
118
123
|
if(!phoneData) throw { properties: { phone: 'notFound' } }
|
|
119
124
|
return phoneData
|
|
@@ -129,6 +134,7 @@ definition.trigger({
|
|
|
129
134
|
}
|
|
130
135
|
},
|
|
131
136
|
async execute({ phone }, context, emit) {
|
|
137
|
+
phone = preFilter(phone)
|
|
132
138
|
const phoneData = await Phone.get(phone)
|
|
133
139
|
return phoneData
|
|
134
140
|
}
|
|
@@ -148,8 +154,9 @@ definition.trigger({
|
|
|
148
154
|
},
|
|
149
155
|
async execute({ user, phone }, { service }, emit) {
|
|
150
156
|
if(!phone) throw new Error("no phone")
|
|
157
|
+
phone = preFilter(phone)
|
|
151
158
|
const phoneData = await Phone.get(phone)
|
|
152
|
-
if(phoneData) throw { properties: { phone: '
|
|
159
|
+
if(phoneData) throw { properties: { phone: 'phoneTaken' } }
|
|
153
160
|
await service.trigger({ type: 'contactConnected' }, {
|
|
154
161
|
contactType: 'phone_Phone',
|
|
155
162
|
contact: phone,
|
|
@@ -176,6 +183,7 @@ definition.trigger({
|
|
|
176
183
|
}
|
|
177
184
|
},
|
|
178
185
|
async execute({ user, phone }, { client, service }, emit) {
|
|
186
|
+
phone = preFilter(phone)
|
|
179
187
|
const phoneData = await Phone.get(phone)
|
|
180
188
|
if(!phoneData) throw { properties: { phone: 'notFound' } }
|
|
181
189
|
if(phoneData.user !== user) throw { properties: { phone: 'notFound' } }
|
|
@@ -196,6 +204,7 @@ definition.trigger({
|
|
|
196
204
|
},
|
|
197
205
|
waitForEvents: true,
|
|
198
206
|
async execute({ phone, session }, { client, service }, emit) {
|
|
207
|
+
phone = preFilter(phone)
|
|
199
208
|
const phoneData = await Phone.get(phone)
|
|
200
209
|
if(!phoneData) throw { properties: { phone: 'notFound' } }
|
|
201
210
|
const { user } = phoneData
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/phone-service",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.90",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@live-change/framework": "^0.8.
|
|
26
|
-
"@live-change/relations-plugin": "^0.8.
|
|
25
|
+
"@live-change/framework": "^0.8.90",
|
|
26
|
+
"@live-change/relations-plugin": "^0.8.90",
|
|
27
27
|
"got": "^11.8.3",
|
|
28
28
|
"html-to-text": "8.1.0",
|
|
29
29
|
"jsdom": "^24.1.0",
|
|
30
30
|
"smsapi": "2.0.9"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "745223326ab078f2155434fe684611fc1398df9d"
|
|
33
33
|
}
|