@driveflux/api-functions 0.0.7-next.0 → 0.0.7-next.1
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 +73 -327
- package/dist/auth/emails.js +43 -210
- package/dist/auth/formatter.js +11 -11
- package/dist/auth/otp.js +122 -392
- package/dist/auth/register.js +100 -396
- package/dist/auth/tokens.js +115 -430
- package/dist/auth/verifications.js +177 -583
- package/dist/constants.js +5 -4
- package/dist/mailjet/calls/manage-contacts-in-list.js +22 -166
- package/dist/mailjet/calls/manage-subscription-status.js +13 -153
- package/dist/mailjet/calls/request-service.js +18 -183
- package/dist/mailjet/refresh-email-preferences.js +26 -225
- package/dist/mailjet/set-contact.js +23 -214
- package/dist/mailjet/types.js +2 -1
- package/dist/mailjet/utils/convert-to-array.js +9 -58
- package/dist/mailjet/utils/extract-email-preferences.js +41 -217
- package/dist/mailjet/utils/lists.js +30 -249
- package/dist/mailjet/utils/update-email-references.js +27 -208
- package/dist/notion/client.js +48 -197
- package/dist/notion/helpful.js +29 -170
- package/dist/notion/schemas/block.js +49 -43
- package/dist/notion/schemas/common.js +17 -14
- package/dist/notion/schemas/database.js +125 -159
- package/dist/notion/schemas/emoji.js +3 -2
- package/dist/notion/schemas/file.js +10 -10
- package/dist/notion/schemas/kb.js +9 -8
- package/dist/notion/schemas/page.js +126 -171
- package/dist/notion/schemas/parent.js +9 -8
- package/dist/notion/schemas/user.js +21 -20
- package/dist/reservation/agree.js +19 -158
- package/dist/reservation/checks.js +23 -178
- package/dist/reservation/display-vehicle.js +142 -514
- package/dist/reservation/fetch-or-create.js +197 -482
- package/dist/reservation/invoice.js +198 -496
- package/dist/reservation/payer.js +28 -177
- package/dist/reservation/reserve.js +31 -191
- package/dist/reservation/types.js +2 -1
- package/dist/reservation/vehicle.js +24 -186
- package/dist/slack.js +67 -273
- package/dist/validation.js +81 -139
- package/dist/vehicle/vehicle-pricing/constants.js +33 -36
- package/dist/vehicle/vehicle-pricing/index.js +99 -257
- package/dist/vehicle/vehicle-pricing/types.js +2 -1
- package/package.json +9 -9
package/dist/slack.js
CHANGED
|
@@ -1,148 +1,3 @@
|
|
|
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
|
-
}
|
|
146
1
|
import { config } from '@driveflux/config/backend';
|
|
147
2
|
import { enhancedFetch } from '@driveflux/fetch';
|
|
148
3
|
import { createTaskLater } from '@driveflux/scheduler';
|
|
@@ -151,161 +6,100 @@ import { TASK_COMMIT_SLACK_CHANNEL, TASK_PIPELINE_SLACK } from './constants.js';
|
|
|
151
6
|
if (!global.__slackBlocks) {
|
|
152
7
|
global.__slackBlocks = new Map();
|
|
153
8
|
}
|
|
154
|
-
|
|
9
|
+
const slackBlocks = global.__slackBlocks;
|
|
155
10
|
/**
|
|
156
11
|
*
|
|
157
12
|
* @deprecated Use slackLater instead and commitSlack to commit
|
|
158
|
-
*/
|
|
159
|
-
|
|
160
|
-
return
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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;
|
|
13
|
+
*/
|
|
14
|
+
export const slack = async (message, channel = config.slack.defaultChannelId) => {
|
|
15
|
+
return await enhancedFetch('https://slack.com/api/chat.postMessage', {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: {
|
|
18
|
+
Authorization: `Bearer ${config.slack.token}`,
|
|
19
|
+
},
|
|
20
|
+
body: JSON.stringify({
|
|
21
|
+
channel,
|
|
22
|
+
blocks: [
|
|
23
|
+
{
|
|
24
|
+
type: 'section',
|
|
25
|
+
text: {
|
|
26
|
+
type: 'mrkdwn',
|
|
27
|
+
text: message,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
196
33
|
};
|
|
34
|
+
export const getSlackBlocks = (channel) => channel ? slackBlocks.get(channel) : slackBlocks;
|
|
197
35
|
/**
|
|
198
36
|
* Naive implementation, however, for now (uncrowded serverless env), this works
|
|
199
37
|
* @param blocks
|
|
200
38
|
* @param channel
|
|
201
|
-
*/
|
|
202
|
-
|
|
39
|
+
*/
|
|
40
|
+
export function slackLater(blocks, channel) {
|
|
41
|
+
const targetChannel = (config.appEnv === 'production'
|
|
42
|
+
? channel
|
|
43
|
+
: config.slack.defaultChannelId) || config.slack.defaultChannelId;
|
|
203
44
|
if (!targetChannel || !blocks) {
|
|
204
45
|
return;
|
|
205
46
|
}
|
|
206
|
-
|
|
47
|
+
const messages = slackBlocks.get(targetChannel) || new Set();
|
|
207
48
|
if (typeof blocks === 'string') {
|
|
208
49
|
messages.add({
|
|
209
50
|
type: 'section',
|
|
210
51
|
text: {
|
|
211
52
|
type: 'mrkdwn',
|
|
212
|
-
text: blocks
|
|
213
|
-
}
|
|
53
|
+
text: blocks,
|
|
54
|
+
},
|
|
214
55
|
});
|
|
215
|
-
}
|
|
56
|
+
}
|
|
57
|
+
else if (!Array.isArray(blocks)) {
|
|
216
58
|
messages.add(blocks);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
for (const b of blocks) {
|
|
62
|
+
messages.add(b);
|
|
237
63
|
}
|
|
238
64
|
}
|
|
239
65
|
slackBlocks.set(targetChannel, messages);
|
|
240
66
|
}
|
|
241
|
-
export function sendSlackMessages(channel, blocks) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
-
})();
|
|
67
|
+
export async function sendSlackMessages(channel, blocks) {
|
|
68
|
+
const targetChannel = config.appEnv === 'production' ? channel : config.slack.defaultChannelId;
|
|
69
|
+
return await enhancedFetch('https://slack.com/api/chat.postMessage', {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
headers: {
|
|
72
|
+
Authorization: `Bearer ${config.slack.token}`,
|
|
73
|
+
},
|
|
74
|
+
body: JSON.stringify({
|
|
75
|
+
channel: targetChannel,
|
|
76
|
+
blocks: Array.from(blocks),
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
269
79
|
}
|
|
270
|
-
export
|
|
80
|
+
export const commitSlack = () => {
|
|
271
81
|
if (!slackBlocks.size) {
|
|
272
82
|
return;
|
|
273
83
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
}
|
|
84
|
+
const channels = slackBlocks.keys();
|
|
85
|
+
let i = 1;
|
|
86
|
+
const baseUrl = config.appEnv === 'development' ? config.tunnelUrl : config.appUrl;
|
|
87
|
+
for (const channel of channels) {
|
|
88
|
+
const blocks = slackBlocks.get(channel);
|
|
89
|
+
if (!blocks?.size) {
|
|
90
|
+
continue;
|
|
308
91
|
}
|
|
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
|
+
});
|
|
309
102
|
}
|
|
310
103
|
slackBlocks.clear();
|
|
311
104
|
};
|
|
105
|
+
//# sourceMappingURL=slack.js.map
|
package/dist/validation.js
CHANGED
|
@@ -1,66 +1,34 @@
|
|
|
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
|
-
}
|
|
29
|
-
function _type_of(obj) {
|
|
30
|
-
"@swc/helpers - typeof";
|
|
31
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
32
|
-
}
|
|
33
1
|
import { makeProblem } from '@driveflux/problem';
|
|
34
2
|
import { Err } from '@driveflux/result';
|
|
35
|
-
import { z } from 'zod';
|
|
36
|
-
export
|
|
37
|
-
|
|
3
|
+
import { z, } from 'zod';
|
|
4
|
+
export const makeValidationErrorResult = (zodError) => {
|
|
5
|
+
const validation = zodError.flatten((i) => ({
|
|
6
|
+
message: i.message,
|
|
7
|
+
code: i.code,
|
|
8
|
+
path: i.path,
|
|
9
|
+
}));
|
|
10
|
+
return new Err(makeProblem({
|
|
11
|
+
object: 'validation-issues',
|
|
12
|
+
...validation,
|
|
13
|
+
}));
|
|
14
|
+
};
|
|
15
|
+
export const getIdOrObjectValidation = (object, extendObjectValidation) => z.union([
|
|
16
|
+
z.string(),
|
|
17
|
+
z
|
|
18
|
+
.object({ object: z.literal(object), ...extendObjectValidation })
|
|
19
|
+
.passthrough()
|
|
20
|
+
.catchall(z.any()),
|
|
21
|
+
], {
|
|
22
|
+
error: () => {
|
|
38
23
|
return {
|
|
39
|
-
message:
|
|
40
|
-
code: i.code,
|
|
41
|
-
path: i.path
|
|
24
|
+
message: `Invalid details. Please provide an id as a string or an object of type ${object}`,
|
|
42
25
|
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return z.union([
|
|
50
|
-
z.string(),
|
|
51
|
-
z.object(_object_spread({
|
|
52
|
-
object: z.literal(object)
|
|
53
|
-
}, extendObjectValidation)).passthrough().catchall(z.any())
|
|
54
|
-
], {
|
|
55
|
-
error: function() {
|
|
56
|
-
return {
|
|
57
|
-
message: "Invalid details. Please provide an id as a string or an object of type ".concat(object)
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
export var nonEmptyStringValidator = z.string().min(1);
|
|
63
|
-
export var metadataValidation = z.object({}).catchall(z.union([
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
export const nonEmptyStringValidator = z.string().min(1);
|
|
29
|
+
export const metadataValidation = z
|
|
30
|
+
.object({})
|
|
31
|
+
.catchall(z.union([
|
|
64
32
|
z.string(),
|
|
65
33
|
z.number(),
|
|
66
34
|
z.boolean(),
|
|
@@ -68,120 +36,94 @@ export var metadataValidation = z.object({}).catchall(z.union([
|
|
|
68
36
|
z.array(z.number()),
|
|
69
37
|
z.array(z.boolean()),
|
|
70
38
|
z.null(),
|
|
71
|
-
z.undefined()
|
|
39
|
+
z.undefined(),
|
|
72
40
|
]));
|
|
73
|
-
export
|
|
41
|
+
export const addressValidation = z.object({
|
|
74
42
|
name: z.string().optional().nullable(),
|
|
75
|
-
coordinates: z
|
|
43
|
+
coordinates: z
|
|
44
|
+
.object({
|
|
76
45
|
lat: z.number().min(-90).max(90),
|
|
77
|
-
lng: z.number().min(-180).max(180)
|
|
78
|
-
})
|
|
46
|
+
lng: z.number().min(-180).max(180),
|
|
47
|
+
})
|
|
48
|
+
.nullable()
|
|
49
|
+
.optional(),
|
|
79
50
|
street1: nonEmptyStringValidator,
|
|
80
51
|
street2: z.string().nullable().optional(),
|
|
81
52
|
city: nonEmptyStringValidator,
|
|
82
53
|
state: nonEmptyStringValidator,
|
|
83
54
|
postalCode: z.string().min(3).max(11),
|
|
84
|
-
country: nonEmptyStringValidator
|
|
55
|
+
country: nonEmptyStringValidator,
|
|
85
56
|
});
|
|
86
|
-
export
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return date.toISOString();
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
export var dateValidation = getIsoDatetimeToDate();
|
|
97
|
-
export var enhancedImageValidation = z.object({
|
|
57
|
+
export const getIsoDatetimeToDate = (dateValidation) => z.codec(z.iso.datetime(), dateValidation ?? z.date(), {
|
|
58
|
+
decode: (isoString) => new Date(isoString),
|
|
59
|
+
encode: (date) => date.toISOString(),
|
|
60
|
+
});
|
|
61
|
+
export const dateValidation = getIsoDatetimeToDate();
|
|
62
|
+
export const enhancedImageValidation = z.object({
|
|
98
63
|
default: z.string(),
|
|
99
64
|
blurBase64: z.string().optional(),
|
|
100
65
|
thumbnail: z.string().optional(),
|
|
101
66
|
small: z.string().optional(),
|
|
102
67
|
medium: z.string().optional(),
|
|
103
68
|
large: z.string().optional(),
|
|
104
|
-
description: z.string().optional()
|
|
69
|
+
description: z.string().optional(),
|
|
105
70
|
});
|
|
106
|
-
export
|
|
107
|
-
|
|
108
|
-
o
|
|
109
|
-
]).optional();
|
|
110
|
-
};
|
|
111
|
-
export var contactValidation = z.object({
|
|
71
|
+
export const getObjectValidation = (o) => z.enum([o]).optional();
|
|
72
|
+
export const contactValidation = z.object({
|
|
112
73
|
id: z.string().optional(),
|
|
113
74
|
firstName: z.string(),
|
|
114
75
|
lastName: z.string(),
|
|
115
76
|
jobTitle: z.string().optional(),
|
|
116
|
-
email: z
|
|
117
|
-
|
|
118
|
-
|
|
77
|
+
email: z
|
|
78
|
+
.string()
|
|
79
|
+
.email()
|
|
80
|
+
.optional()
|
|
81
|
+
.transform((email) => email?.toLowerCase().trim()),
|
|
119
82
|
phoneNumber: z.string().optional(),
|
|
120
|
-
remarks: z.string().default('')
|
|
83
|
+
remarks: z.string().default(''),
|
|
121
84
|
});
|
|
122
|
-
export
|
|
85
|
+
export const documentFileValidation = z.object({
|
|
123
86
|
id: z.string().optional(),
|
|
124
87
|
name: z.string(),
|
|
125
88
|
description: z.string().nullable().optional(),
|
|
126
89
|
url: z.string(),
|
|
127
|
-
fileType: z.preprocess(
|
|
128
|
-
return typeof f === 'string' ? f.toLowerCase() : f;
|
|
129
|
-
}, z.enum([
|
|
130
|
-
'jpg',
|
|
131
|
-
'jpeg',
|
|
132
|
-
'png',
|
|
133
|
-
'pdf',
|
|
134
|
-
'image'
|
|
135
|
-
]).optional()),
|
|
90
|
+
fileType: z.preprocess((f) => (typeof f === 'string' ? f.toLowerCase() : f), z.enum(['jpg', 'jpeg', 'png', 'pdf', 'image']).optional()),
|
|
136
91
|
mimeType: z.string().optional(),
|
|
137
92
|
uploaded: z.boolean().default(true),
|
|
138
93
|
createdAt: dateValidation.nullable().optional(),
|
|
139
94
|
updatedAt: dateValidation.nullable().optional(),
|
|
140
|
-
metadata: metadataValidation.nullable().optional()
|
|
95
|
+
metadata: metadataValidation.nullable().optional(),
|
|
141
96
|
});
|
|
142
|
-
export
|
|
143
|
-
truthy: [
|
|
144
|
-
|
|
145
|
-
'true',
|
|
146
|
-
'yes'
|
|
147
|
-
],
|
|
148
|
-
falsy: [
|
|
149
|
-
'0',
|
|
150
|
-
'false',
|
|
151
|
-
'no'
|
|
152
|
-
]
|
|
97
|
+
export const queryBooleanValidator = z.stringbool({
|
|
98
|
+
truthy: ['1', 'true', 'yes'],
|
|
99
|
+
falsy: ['0', 'false', 'no'],
|
|
153
100
|
});
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
encode: function(num) {
|
|
160
|
-
return num.toString();
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
};
|
|
164
|
-
export var queryNumberValidator = getStringToNumber();
|
|
101
|
+
const getStringToNumber = (numberValidation) => z.codec(z.string().regex(z.regexes.number), numberValidation ?? z.number(), {
|
|
102
|
+
decode: (str) => Number.parseFloat(str),
|
|
103
|
+
encode: (num) => num.toString(),
|
|
104
|
+
});
|
|
105
|
+
export const queryNumberValidator = getStringToNumber();
|
|
165
106
|
export function queryEnumArrayValidator(enumOrValidation) {
|
|
166
107
|
// Handle ZodEnum case
|
|
167
|
-
if (enumOrValidation &&
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
108
|
+
if (enumOrValidation &&
|
|
109
|
+
typeof enumOrValidation === 'object' &&
|
|
110
|
+
'_zod' in enumOrValidation) {
|
|
111
|
+
return z
|
|
112
|
+
.codec(z.string(), z.array(enumOrValidation), {
|
|
113
|
+
encode: (value) => value.join(','),
|
|
114
|
+
decode: (value) => value.split(','),
|
|
115
|
+
})
|
|
116
|
+
.or(z.array(enumOrValidation));
|
|
176
117
|
}
|
|
177
118
|
// Handle array or enum-like object case
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
119
|
+
const enumSchema = Array.isArray(enumOrValidation)
|
|
120
|
+
? z.enum(enumOrValidation)
|
|
121
|
+
: z.enum(Object.values(enumOrValidation));
|
|
122
|
+
return z
|
|
123
|
+
.codec(z.string(), z.array(enumSchema), {
|
|
124
|
+
encode: (value) => value.join(','),
|
|
125
|
+
decode: (value) => value.split(','),
|
|
126
|
+
})
|
|
127
|
+
.or(z.array(enumSchema));
|
|
187
128
|
}
|
|
129
|
+
//# sourceMappingURL=validation.js.map
|