@driveflux/api-functions 0.0.2 → 0.0.3
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/dist/auth/confirm.js +327 -73
- package/dist/auth/emails.js +210 -43
- package/dist/auth/formatter.js +11 -11
- package/dist/auth/otp.js +392 -122
- package/dist/auth/register.js +396 -100
- package/dist/auth/tokens.js +430 -115
- package/dist/auth/verifications.js +512 -154
- package/dist/constants.js +4 -5
- package/dist/mailjet/calls/manage-contacts-in-list.js +166 -22
- package/dist/mailjet/calls/manage-subscription-status.js +153 -13
- package/dist/mailjet/calls/request-service.js +183 -18
- package/dist/mailjet/refresh-email-preferences.js +225 -26
- package/dist/mailjet/set-contact.js +214 -23
- package/dist/mailjet/types.js +1 -2
- package/dist/mailjet/utils/convert-to-array.js +58 -9
- package/dist/mailjet/utils/extract-email-preferences.js +217 -41
- package/dist/mailjet/utils/lists.js +249 -30
- package/dist/mailjet/utils/update-email-references.js +208 -27
- package/dist/notion/client.js +197 -48
- package/dist/notion/helpful.js +170 -29
- package/dist/notion/schemas/block.js +43 -49
- package/dist/notion/schemas/common.js +14 -17
- package/dist/notion/schemas/database.js +159 -125
- package/dist/notion/schemas/emoji.js +2 -3
- package/dist/notion/schemas/file.js +10 -10
- package/dist/notion/schemas/kb.js +8 -9
- package/dist/notion/schemas/page.js +171 -126
- package/dist/notion/schemas/parent.js +8 -9
- package/dist/notion/schemas/user.js +20 -21
- package/dist/reservation/agree.js +158 -19
- package/dist/reservation/checks.js +178 -23
- package/dist/reservation/display-vehicle.js +514 -142
- package/dist/reservation/fetch-or-create.js +482 -197
- package/dist/reservation/invoice.js +501 -200
- package/dist/reservation/payer.js +177 -28
- package/dist/reservation/reserve.js +191 -31
- package/dist/reservation/types.js +1 -2
- package/dist/reservation/vehicle.js +186 -24
- package/dist/slack.js +273 -67
- package/dist/validation.js +92 -52
- package/dist/vehicle/vehicle-pricing/constants.js +36 -33
- package/dist/vehicle/vehicle-pricing/index.js +257 -99
- package/dist/vehicle/vehicle-pricing/types.js +1 -2
- package/package.json +1 -1
package/dist/slack.js
CHANGED
|
@@ -1,3 +1,148 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_without_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
8
|
+
}
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
+
try {
|
|
11
|
+
var info = gen[key](arg);
|
|
12
|
+
var value = info.value;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
reject(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _async_to_generator(fn) {
|
|
24
|
+
return function() {
|
|
25
|
+
var self = this, args = arguments;
|
|
26
|
+
return new Promise(function(resolve, reject) {
|
|
27
|
+
var gen = fn.apply(self, args);
|
|
28
|
+
function _next(value) {
|
|
29
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
+
}
|
|
31
|
+
function _throw(err) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
+
}
|
|
34
|
+
_next(undefined);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _iterable_to_array(iter) {
|
|
39
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
40
|
+
}
|
|
41
|
+
function _non_iterable_spread() {
|
|
42
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
43
|
+
}
|
|
44
|
+
function _to_consumable_array(arr) {
|
|
45
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
46
|
+
}
|
|
47
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
48
|
+
if (!o) return;
|
|
49
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
50
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
51
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
52
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
53
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
54
|
+
}
|
|
55
|
+
function _ts_generator(thisArg, body) {
|
|
56
|
+
var f, y, t, _ = {
|
|
57
|
+
label: 0,
|
|
58
|
+
sent: function() {
|
|
59
|
+
if (t[0] & 1) throw t[1];
|
|
60
|
+
return t[1];
|
|
61
|
+
},
|
|
62
|
+
trys: [],
|
|
63
|
+
ops: []
|
|
64
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
65
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
66
|
+
return this;
|
|
67
|
+
}), g;
|
|
68
|
+
function verb(n) {
|
|
69
|
+
return function(v) {
|
|
70
|
+
return step([
|
|
71
|
+
n,
|
|
72
|
+
v
|
|
73
|
+
]);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function step(op) {
|
|
77
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
78
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
79
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
80
|
+
if (y = 0, t) op = [
|
|
81
|
+
op[0] & 2,
|
|
82
|
+
t.value
|
|
83
|
+
];
|
|
84
|
+
switch(op[0]){
|
|
85
|
+
case 0:
|
|
86
|
+
case 1:
|
|
87
|
+
t = op;
|
|
88
|
+
break;
|
|
89
|
+
case 4:
|
|
90
|
+
_.label++;
|
|
91
|
+
return {
|
|
92
|
+
value: op[1],
|
|
93
|
+
done: false
|
|
94
|
+
};
|
|
95
|
+
case 5:
|
|
96
|
+
_.label++;
|
|
97
|
+
y = op[1];
|
|
98
|
+
op = [
|
|
99
|
+
0
|
|
100
|
+
];
|
|
101
|
+
continue;
|
|
102
|
+
case 7:
|
|
103
|
+
op = _.ops.pop();
|
|
104
|
+
_.trys.pop();
|
|
105
|
+
continue;
|
|
106
|
+
default:
|
|
107
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
108
|
+
_ = 0;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
112
|
+
_.label = op[1];
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
116
|
+
_.label = t[1];
|
|
117
|
+
t = op;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
if (t && _.label < t[2]) {
|
|
121
|
+
_.label = t[2];
|
|
122
|
+
_.ops.push(op);
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
if (t[2]) _.ops.pop();
|
|
126
|
+
_.trys.pop();
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
op = body.call(thisArg, _);
|
|
130
|
+
} catch (e) {
|
|
131
|
+
op = [
|
|
132
|
+
6,
|
|
133
|
+
e
|
|
134
|
+
];
|
|
135
|
+
y = 0;
|
|
136
|
+
} finally{
|
|
137
|
+
f = t = 0;
|
|
138
|
+
}
|
|
139
|
+
if (op[0] & 5) throw op[1];
|
|
140
|
+
return {
|
|
141
|
+
value: op[0] ? op[1] : void 0,
|
|
142
|
+
done: true
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
1
146
|
import { config } from '@driveflux/config/backend';
|
|
2
147
|
import { enhancedFetch } from '@driveflux/fetch';
|
|
3
148
|
import { createTaskLater } from '@driveflux/scheduler';
|
|
@@ -6,100 +151,161 @@ import { TASK_COMMIT_SLACK_CHANNEL, TASK_PIPELINE_SLACK } from './constants.js';
|
|
|
6
151
|
if (!global.__slackBlocks) {
|
|
7
152
|
global.__slackBlocks = new Map();
|
|
8
153
|
}
|
|
9
|
-
|
|
154
|
+
var slackBlocks = global.__slackBlocks;
|
|
10
155
|
/**
|
|
11
156
|
*
|
|
12
157
|
* @deprecated Use slackLater instead and commitSlack to commit
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
158
|
+
*/ export var slack = function(message) {
|
|
159
|
+
var channel = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : config.slack.defaultChannelId;
|
|
160
|
+
return _async_to_generator(function() {
|
|
161
|
+
return _ts_generator(this, function(_state) {
|
|
162
|
+
switch(_state.label){
|
|
163
|
+
case 0:
|
|
164
|
+
return [
|
|
165
|
+
4,
|
|
166
|
+
enhancedFetch('https://slack.com/api/chat.postMessage', {
|
|
167
|
+
method: 'POST',
|
|
168
|
+
headers: {
|
|
169
|
+
Authorization: "Bearer ".concat(config.slack.token)
|
|
170
|
+
},
|
|
171
|
+
body: JSON.stringify({
|
|
172
|
+
channel: channel,
|
|
173
|
+
blocks: [
|
|
174
|
+
{
|
|
175
|
+
type: 'section',
|
|
176
|
+
text: {
|
|
177
|
+
type: 'mrkdwn',
|
|
178
|
+
text: message
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
})
|
|
183
|
+
})
|
|
184
|
+
];
|
|
185
|
+
case 1:
|
|
186
|
+
return [
|
|
187
|
+
2,
|
|
188
|
+
_state.sent()
|
|
189
|
+
];
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
})();
|
|
193
|
+
};
|
|
194
|
+
export var getSlackBlocks = function(channel) {
|
|
195
|
+
return channel ? slackBlocks.get(channel) : slackBlocks;
|
|
33
196
|
};
|
|
34
|
-
export const getSlackBlocks = (channel) => channel ? slackBlocks.get(channel) : slackBlocks;
|
|
35
197
|
/**
|
|
36
198
|
* Naive implementation, however, for now (uncrowded serverless env), this works
|
|
37
199
|
* @param blocks
|
|
38
200
|
* @param channel
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
const targetChannel = (config.appEnv === 'production'
|
|
42
|
-
? channel
|
|
43
|
-
: config.slack.defaultChannelId) || config.slack.defaultChannelId;
|
|
201
|
+
*/ export function slackLater(blocks, channel) {
|
|
202
|
+
var targetChannel = (config.appEnv === 'production' ? channel : config.slack.defaultChannelId) || config.slack.defaultChannelId;
|
|
44
203
|
if (!targetChannel || !blocks) {
|
|
45
204
|
return;
|
|
46
205
|
}
|
|
47
|
-
|
|
206
|
+
var messages = slackBlocks.get(targetChannel) || new Set();
|
|
48
207
|
if (typeof blocks === 'string') {
|
|
49
208
|
messages.add({
|
|
50
209
|
type: 'section',
|
|
51
210
|
text: {
|
|
52
211
|
type: 'mrkdwn',
|
|
53
|
-
text: blocks
|
|
54
|
-
}
|
|
212
|
+
text: blocks
|
|
213
|
+
}
|
|
55
214
|
});
|
|
56
|
-
}
|
|
57
|
-
else if (!Array.isArray(blocks)) {
|
|
215
|
+
} else if (!Array.isArray(blocks)) {
|
|
58
216
|
messages.add(blocks);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
217
|
+
} else {
|
|
218
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
219
|
+
try {
|
|
220
|
+
for(var _iterator = blocks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
221
|
+
var b = _step.value;
|
|
222
|
+
messages.add(b);
|
|
223
|
+
}
|
|
224
|
+
} catch (err) {
|
|
225
|
+
_didIteratorError = true;
|
|
226
|
+
_iteratorError = err;
|
|
227
|
+
} finally{
|
|
228
|
+
try {
|
|
229
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
230
|
+
_iterator.return();
|
|
231
|
+
}
|
|
232
|
+
} finally{
|
|
233
|
+
if (_didIteratorError) {
|
|
234
|
+
throw _iteratorError;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
63
237
|
}
|
|
64
238
|
}
|
|
65
239
|
slackBlocks.set(targetChannel, messages);
|
|
66
240
|
}
|
|
67
|
-
export
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
241
|
+
export function sendSlackMessages(channel, blocks) {
|
|
242
|
+
return _async_to_generator(function() {
|
|
243
|
+
var targetChannel;
|
|
244
|
+
return _ts_generator(this, function(_state) {
|
|
245
|
+
switch(_state.label){
|
|
246
|
+
case 0:
|
|
247
|
+
targetChannel = config.appEnv === 'production' ? channel : config.slack.defaultChannelId;
|
|
248
|
+
return [
|
|
249
|
+
4,
|
|
250
|
+
enhancedFetch('https://slack.com/api/chat.postMessage', {
|
|
251
|
+
method: 'POST',
|
|
252
|
+
headers: {
|
|
253
|
+
Authorization: "Bearer ".concat(config.slack.token)
|
|
254
|
+
},
|
|
255
|
+
body: JSON.stringify({
|
|
256
|
+
channel: targetChannel,
|
|
257
|
+
blocks: Array.from(blocks)
|
|
258
|
+
})
|
|
259
|
+
})
|
|
260
|
+
];
|
|
261
|
+
case 1:
|
|
262
|
+
return [
|
|
263
|
+
2,
|
|
264
|
+
_state.sent()
|
|
265
|
+
];
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
})();
|
|
79
269
|
}
|
|
80
|
-
export
|
|
270
|
+
export var commitSlack = function() {
|
|
81
271
|
if (!slackBlocks.size) {
|
|
82
272
|
return;
|
|
83
273
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
274
|
+
var channels = slackBlocks.keys();
|
|
275
|
+
var i = 1;
|
|
276
|
+
var baseUrl = config.appEnv === 'development' ? config.tunnelUrl : config.appUrl;
|
|
277
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
278
|
+
try {
|
|
279
|
+
for(var _iterator = channels[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
280
|
+
var channel = _step.value;
|
|
281
|
+
var blocks = slackBlocks.get(channel);
|
|
282
|
+
if (!(blocks === null || blocks === void 0 ? void 0 : blocks.size)) {
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
createTaskLater({
|
|
286
|
+
pipeline: TASK_PIPELINE_SLACK,
|
|
287
|
+
name: TASK_COMMIT_SLACK_CHANNEL,
|
|
288
|
+
metadata: {
|
|
289
|
+
channel: channel,
|
|
290
|
+
blocks: _to_consumable_array(blocks)
|
|
291
|
+
},
|
|
292
|
+
taskHandlerUrl: "".concat(baseUrl || config.appUrl, "/api/hooks/slack-pipeline"),
|
|
293
|
+
scheduledAt: addSeconds(new Date(), i++)
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
} catch (err) {
|
|
297
|
+
_didIteratorError = true;
|
|
298
|
+
_iteratorError = err;
|
|
299
|
+
} finally{
|
|
300
|
+
try {
|
|
301
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
302
|
+
_iterator.return();
|
|
303
|
+
}
|
|
304
|
+
} finally{
|
|
305
|
+
if (_didIteratorError) {
|
|
306
|
+
throw _iteratorError;
|
|
307
|
+
}
|
|
91
308
|
}
|
|
92
|
-
createTaskLater({
|
|
93
|
-
pipeline: TASK_PIPELINE_SLACK,
|
|
94
|
-
name: TASK_COMMIT_SLACK_CHANNEL,
|
|
95
|
-
metadata: {
|
|
96
|
-
channel,
|
|
97
|
-
blocks: [...blocks],
|
|
98
|
-
},
|
|
99
|
-
taskHandlerUrl: `${baseUrl || config.appUrl}/api/hooks/slack-pipeline`,
|
|
100
|
-
scheduledAt: addSeconds(new Date(), i++),
|
|
101
|
-
});
|
|
102
309
|
}
|
|
103
310
|
slackBlocks.clear();
|
|
104
311
|
};
|
|
105
|
-
//# sourceMappingURL=slack.js.map
|
package/dist/validation.js
CHANGED
|
@@ -1,37 +1,65 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _object_spread(target) {
|
|
15
|
+
for(var i = 1; i < arguments.length; i++){
|
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
+
var ownKeys = Object.keys(source);
|
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
ownKeys.forEach(function(key) {
|
|
24
|
+
_define_property(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
}
|
|
1
29
|
import { makeProblem } from '@driveflux/problem';
|
|
2
30
|
import { Err } from '@driveflux/result';
|
|
3
31
|
import { getDate } from '@driveflux/utils';
|
|
4
32
|
import { isValid } from 'date-fns/isValid';
|
|
5
33
|
import toNumber from 'lodash/toNumber';
|
|
6
34
|
import { z } from 'zod';
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
message: i.message,
|
|
10
|
-
code: i.code,
|
|
11
|
-
path: i.path,
|
|
12
|
-
}));
|
|
13
|
-
return new Err(makeProblem({
|
|
14
|
-
object: 'validation-issues',
|
|
15
|
-
...validation,
|
|
16
|
-
}));
|
|
17
|
-
};
|
|
18
|
-
export const getIdOrObjectValidation = (object, extendObjectValidation) => z.union([
|
|
19
|
-
z.string(),
|
|
20
|
-
z
|
|
21
|
-
.object({ object: z.literal(object), ...extendObjectValidation })
|
|
22
|
-
.passthrough()
|
|
23
|
-
.catchall(z.any()),
|
|
24
|
-
], {
|
|
25
|
-
error: () => {
|
|
35
|
+
export var makeValidationErrorResult = function(zodError) {
|
|
36
|
+
var validation = zodError.flatten(function(i) {
|
|
26
37
|
return {
|
|
27
|
-
message:
|
|
38
|
+
message: i.message,
|
|
39
|
+
code: i.code,
|
|
40
|
+
path: i.path
|
|
28
41
|
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
});
|
|
43
|
+
return new Err(makeProblem(_object_spread({
|
|
44
|
+
object: 'validation-issues'
|
|
45
|
+
}, validation)));
|
|
46
|
+
};
|
|
47
|
+
export var getIdOrObjectValidation = function(object, extendObjectValidation) {
|
|
48
|
+
return z.union([
|
|
49
|
+
z.string(),
|
|
50
|
+
z.object(_object_spread({
|
|
51
|
+
object: z.literal(object)
|
|
52
|
+
}, extendObjectValidation)).passthrough().catchall(z.any())
|
|
53
|
+
], {
|
|
54
|
+
error: function() {
|
|
55
|
+
return {
|
|
56
|
+
message: "Invalid details. Please provide an id as a string or an object of type ".concat(object)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
export var nonEmptyStringValidator = z.string().min(1);
|
|
62
|
+
export var metadataValidation = z.object({}).catchall(z.union([
|
|
35
63
|
z.string(),
|
|
36
64
|
z.number(),
|
|
37
65
|
z.boolean(),
|
|
@@ -39,61 +67,73 @@ export const metadataValidation = z
|
|
|
39
67
|
z.array(z.number()),
|
|
40
68
|
z.array(z.boolean()),
|
|
41
69
|
z.null(),
|
|
42
|
-
z.undefined()
|
|
70
|
+
z.undefined()
|
|
43
71
|
]));
|
|
44
|
-
export
|
|
72
|
+
export var addressValidation = z.object({
|
|
45
73
|
name: z.string().optional().nullable(),
|
|
46
|
-
coordinates: z
|
|
47
|
-
.object({
|
|
74
|
+
coordinates: z.object({
|
|
48
75
|
lat: z.number().min(-90).max(90),
|
|
49
|
-
lng: z.number().min(-180).max(180)
|
|
50
|
-
})
|
|
51
|
-
.nullable()
|
|
52
|
-
.optional(),
|
|
76
|
+
lng: z.number().min(-180).max(180)
|
|
77
|
+
}).nullable().optional(),
|
|
53
78
|
street1: nonEmptyStringValidator,
|
|
54
79
|
street2: z.string().nullable().optional(),
|
|
55
80
|
city: nonEmptyStringValidator,
|
|
56
81
|
state: nonEmptyStringValidator,
|
|
57
82
|
postalCode: z.string().min(3).max(11),
|
|
58
83
|
country: nonEmptyStringValidator,
|
|
59
|
-
metadata: metadataValidation.optional().nullable()
|
|
84
|
+
metadata: metadataValidation.optional().nullable()
|
|
60
85
|
});
|
|
61
|
-
export
|
|
62
|
-
|
|
86
|
+
export var dateValidation = z.preprocess(function(d) {
|
|
87
|
+
return isValid(getDate(d)) && new Date(d);
|
|
88
|
+
}, z.date());
|
|
89
|
+
export var enhancedImageValidation = z.object({
|
|
63
90
|
default: z.string(),
|
|
64
91
|
blurBase64: z.string().optional(),
|
|
65
92
|
thumbnail: z.string().optional(),
|
|
66
93
|
small: z.string().optional(),
|
|
67
94
|
medium: z.string().optional(),
|
|
68
95
|
large: z.string().optional(),
|
|
69
|
-
description: z.string().optional()
|
|
96
|
+
description: z.string().optional()
|
|
70
97
|
});
|
|
71
|
-
export
|
|
72
|
-
|
|
98
|
+
export var getObjectValidation = function(o) {
|
|
99
|
+
return z.enum([
|
|
100
|
+
o
|
|
101
|
+
]).optional();
|
|
102
|
+
};
|
|
103
|
+
export var contactValidation = z.object({
|
|
73
104
|
id: z.string().optional(),
|
|
74
105
|
firstName: z.string(),
|
|
75
106
|
lastName: z.string(),
|
|
76
107
|
jobTitle: z.string().optional(),
|
|
77
|
-
email: z
|
|
78
|
-
.
|
|
79
|
-
|
|
80
|
-
.optional()
|
|
81
|
-
.transform((email) => email?.toLowerCase().trim()),
|
|
108
|
+
email: z.string().email().optional().transform(function(email) {
|
|
109
|
+
return email === null || email === void 0 ? void 0 : email.toLowerCase().trim();
|
|
110
|
+
}),
|
|
82
111
|
phoneNumber: z.string().optional(),
|
|
83
|
-
remarks: z.string().default('')
|
|
112
|
+
remarks: z.string().default('')
|
|
84
113
|
});
|
|
85
|
-
export
|
|
114
|
+
export var documentFileValidation = z.object({
|
|
86
115
|
id: z.string().optional(),
|
|
87
116
|
name: z.string(),
|
|
88
117
|
description: z.string().nullable().optional(),
|
|
89
118
|
url: z.string(),
|
|
90
|
-
fileType: z.preprocess((f)
|
|
119
|
+
fileType: z.preprocess(function(f) {
|
|
120
|
+
return typeof f === 'string' ? f.toLowerCase() : f;
|
|
121
|
+
}, z.enum([
|
|
122
|
+
'jpg',
|
|
123
|
+
'jpeg',
|
|
124
|
+
'png',
|
|
125
|
+
'pdf',
|
|
126
|
+
'image'
|
|
127
|
+
]).optional()),
|
|
91
128
|
mimeType: z.string().optional(),
|
|
92
129
|
uploaded: z.boolean().default(true),
|
|
93
130
|
createdAt: dateValidation.nullable().optional(),
|
|
94
131
|
updatedAt: dateValidation.nullable().optional(),
|
|
95
|
-
metadata: metadataValidation.nullable().optional()
|
|
132
|
+
metadata: metadataValidation.nullable().optional()
|
|
96
133
|
});
|
|
97
|
-
export
|
|
98
|
-
|
|
99
|
-
|
|
134
|
+
export var queryBooleanValidator = z.preprocess(function(s) {
|
|
135
|
+
return s === '1' || s === 'true';
|
|
136
|
+
}, z.boolean());
|
|
137
|
+
export var queryNumberValidator = z.preprocess(function(s) {
|
|
138
|
+
return toNumber(s);
|
|
139
|
+
}, z.number());
|