@mattrika/server-utils 0.0.0-stage → 1.0.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/index.esm.js ADDED
@@ -0,0 +1,552 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import pino from 'pino';
4
+ import { HTTPException } from 'hono/http-exception';
5
+ import { z } from '@hono/zod-openapi';
6
+ import crypto from 'crypto';
7
+ import argon2 from '@node-rs/argon2';
8
+ import { INTERNAL_SERVER_ERROR, NOT_FOUND, UNPROCESSABLE_ENTITY } from 'stoker/http-status-codes';
9
+ import { sign, verify } from 'hono/jwt';
10
+
11
+ const DEFAULT_PAGE_SIZE = 20;
12
+ const MAX_PAGE_SIZE = 100;
13
+
14
+ const MAX_SIZE = 1024 * 1024; // 1MB
15
+ async function safeResponseBody(res) {
16
+ try {
17
+ const contentType = res.headers.get('content-type') || '';
18
+ const disposition = res.headers.get('content-disposition') || '';
19
+ // ❌ Skip downloads
20
+ if (disposition.includes('attachment')) {
21
+ return '[FILE DOWNLOAD SKIPPED]';
22
+ }
23
+ // ❌ Skip non-JSON responses
24
+ if (!contentType.includes('application/json')) {
25
+ return '[NON-JSON RESPONSE]';
26
+ }
27
+ const text = await res.clone().text();
28
+ if (!text) return undefined;
29
+ const size = Buffer.byteLength(text, 'utf8');
30
+ if (size > MAX_SIZE) return `[RESPONSE TOO LARGE: ${Math.round(size / 1024)} KB]`;
31
+ return JSON.parse(text);
32
+ } catch {
33
+ return '[UNREADABLE RESPONSE]';
34
+ }
35
+ }
36
+ async function safeRequestBody(req) {
37
+ try {
38
+ const contentType = req.header('content-type') || '';
39
+ // ❌ Skip file uploads
40
+ if (contentType.includes('multipart/form-data')) {
41
+ return '[FILE UPLOAD SKIPPED]';
42
+ }
43
+ if (!contentType.includes('application/json')) {
44
+ return undefined;
45
+ }
46
+ const text = await req.raw.clone().text();
47
+ if (!text) return undefined;
48
+ const size = Buffer.byteLength(text, 'utf8');
49
+ if (size > MAX_SIZE) return `[BODY TOO LARGE: ${Math.round(size / 1024)} KB]`;
50
+ return JSON.parse(text);
51
+ } catch {
52
+ return '[UNREADABLE REQUEST BODY]';
53
+ }
54
+ }
55
+ function ensureDirExists(filePath) {
56
+ const dir = path.dirname(filePath);
57
+ if (!fs.existsSync(dir)) {
58
+ fs.mkdirSync(dir, {
59
+ recursive: true
60
+ });
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Checks whether APP_ENV environment variable is set to 'production' or NODE_ENV environment variable is set to 'production', in that order.
66
+ * @returns boolean
67
+ */
68
+ function isProductionAppEnvironment() {
69
+ const appEnv = process?.env?.['APP_ENV'];
70
+ if (appEnv === 'production') return true;
71
+ const nodeEnv = process?.env?.['NODE_ENV'];
72
+ if (nodeEnv === 'production') return true;
73
+ return false;
74
+ }
75
+
76
+ const logFilePath = './logs/app.log';
77
+ let transport;
78
+ function pinoLogger() {
79
+ const isProd = isProductionAppEnvironment();
80
+ try {
81
+ // ensure logs folder exists
82
+ ensureDirExists(logFilePath);
83
+ transport = isProd ? pino.transport({
84
+ target: 'pino/file',
85
+ options: {
86
+ destination: logFilePath
87
+ }
88
+ }) : pino.transport({
89
+ targets: [{
90
+ target: 'pino-pretty',
91
+ options: {
92
+ colorize: true,
93
+ levelFirst: true,
94
+ translateTime: 'SYS:standard'
95
+ }
96
+ }]
97
+ });
98
+ } catch (err) {
99
+ console.error('⚠️ Logger file transport failed, falling back to stdout', err);
100
+ transport = undefined;
101
+ }
102
+ return pino({
103
+ level: process.env?.['PINO_LOG_LEVEL'] || 'info',
104
+ timestamp: pino.stdTimeFunctions.isoTime,
105
+ serializers: {
106
+ err: pino.stdSerializers.errWithCause
107
+ },
108
+ formatters: {
109
+ bindings: bindings => ({
110
+ pid: bindings?.['pid'],
111
+ host: bindings?.['hostname'],
112
+ node_version: process.version
113
+ })
114
+ },
115
+ redact: {
116
+ paths: ['req.headers.authorization', 'req.headers.cookie', 'req.body.password', 'req.body.confirmPassword', 'req.body.oldPassword', 'req.body.newPassword', 'req.body.token', 'req.body.refreshToken', 'req.body.accessToken', 'req.body.*.password', 'req.body.*.token', 'req.body.*.refreshToken', 'req.body.*.accessToken', 'res.body.token', 'res.body.refreshToken', 'res.body.accessToken', 'res.body.data.token', 'res.body.data.refreshToken', 'res.body.data.accessToken', 'res.body.*.token', 'res.body.*.refreshToken', 'res.body.*.accessToken'],
117
+ censor: '[REDACTED]'
118
+ }
119
+ }, transport);
120
+ }
121
+
122
+ const pinoLoggerMiddleware = () => {
123
+ return async (c, next) => {
124
+ const start = Date.now();
125
+ const logger = pinoLogger();
126
+ const childLogger = logger.child({
127
+ requestId: c.var['requestId'],
128
+ req: {
129
+ method: c.req.method,
130
+ path: c.req.path,
131
+ query: c.req.query(),
132
+ headers: c.req.header(),
133
+ body: c.req.method !== 'GET' ? await safeRequestBody(c.req) : undefined
134
+ }
135
+ });
136
+ c.set('logger', childLogger);
137
+ childLogger.info('Incoming request');
138
+ try {
139
+ await next();
140
+ const responseBody = await safeResponseBody(c.res);
141
+ childLogger.info({
142
+ res: {
143
+ status: c.res.status,
144
+ durationMs: Date.now() - start,
145
+ body: responseBody
146
+ }
147
+ }, 'Request completed');
148
+ } catch (err) {
149
+ if (err instanceof HTTPException) {
150
+ childLogger.warn({
151
+ res: {
152
+ status: err.status
153
+ },
154
+ error: err.message
155
+ }, 'HTTP error');
156
+ throw err;
157
+ }
158
+ childLogger.error({
159
+ err
160
+ }, 'Unhandled server error');
161
+ throw err;
162
+ }
163
+ };
164
+ };
165
+
166
+ const zPagination = z.object({
167
+ page: z.coerce.number().optional(),
168
+ size: z.coerce.number().optional()
169
+ });
170
+ const zCommonQuery = z.object({
171
+ search: z.string().optional(),
172
+ orderBy: z.string().optional(),
173
+ sortOrder: z.enum(['asc', 'desc']).optional()
174
+ }).extend(zPagination.shape);
175
+ const zId = z.object({
176
+ id: z.string()
177
+ });
178
+ const zIds = z.object({
179
+ ids: z.array(z.string()).min(1)
180
+ });
181
+ const zPassword = z.string().min(8).max(128).regex(/[A-Z]/, 'Must contain at least one uppercase letter').regex(/[0-9]/, 'Must contain at least one number').regex(/[^A-Za-z0-9\s]/, 'Must contain at least one special character');
182
+ const zEmpty = z.object({});
183
+ const zFile = z.object({
184
+ file: z.instanceof(File).openapi({
185
+ type: 'string',
186
+ format: 'binary'
187
+ }).optional(),
188
+ files: z.array(z.instanceof(File).openapi({
189
+ type: 'string',
190
+ format: 'binary'
191
+ })).optional()
192
+ });
193
+
194
+ // `argon2.Algorithm` is an ambient `const enum`, so its members cannot be
195
+ // accessed when `isolatedModules` is enabled. Argon2id === 2; typing the
196
+ // literal against the library's own option type keeps it type-safe.
197
+ const ARGON2ID = 2;
198
+ class CryptoService {
199
+ static async hash(plain) {
200
+ return argon2.hash(plain, {
201
+ algorithm: ARGON2ID,
202
+ memoryCost: 1 << 16,
203
+ // 64 MB
204
+ timeCost: 3,
205
+ parallelism: 1
206
+ });
207
+ }
208
+ static async verify(plain, hash) {
209
+ return argon2.verify(hash, plain);
210
+ }
211
+ static random64chars() {
212
+ // 32 bytes hex -> 64 hex chars
213
+ return crypto.randomBytes(32).toString('hex');
214
+ }
215
+ }
216
+
217
+ const zResponsePagination = z.object({
218
+ page: z.number(),
219
+ size: z.number(),
220
+ totalItems: z.number(),
221
+ totalPages: z.number()
222
+ });
223
+ function ApiResponse(dataSchema, description) {
224
+ return {
225
+ content: {
226
+ 'application/json': {
227
+ schema: z.object({
228
+ data: dataSchema,
229
+ message: z.string(),
230
+ success: z.boolean(),
231
+ error: z.any().optional(),
232
+ meta: z.any().optional()
233
+ })
234
+ }
235
+ },
236
+ description
237
+ };
238
+ }
239
+ function ApiListResponse(dataSchema, description) {
240
+ return {
241
+ content: {
242
+ 'application/json': {
243
+ schema: z.object({
244
+ data: dataSchema,
245
+ message: z.string(),
246
+ success: z.boolean(),
247
+ error: z.any().optional(),
248
+ meta: z.any().optional(),
249
+ pagination: zResponsePagination
250
+ })
251
+ }
252
+ },
253
+ description
254
+ };
255
+ }
256
+ // 1. Base Stream Schema
257
+ const zStreamResponse = z.object({
258
+ body: z.custom(val => val instanceof ReadableStream, {
259
+ message: 'Body must be a ReadableStream'
260
+ }),
261
+ headers: z.object({
262
+ 'Content-Type': z.string().default('application/octet-stream'),
263
+ 'Content-Disposition': z.string().refine(val => val.startsWith('inline; filename="'), {
264
+ message: 'Must follow format: inline; filename="..."'
265
+ })
266
+ }).optional()
267
+ });
268
+ // 2. Generic API Response for ReadableStream
269
+ function StreamResponse(description) {
270
+ return {
271
+ content: {
272
+ 'application/octet-stream': {
273
+ schema: zStreamResponse
274
+ }
275
+ },
276
+ description
277
+ };
278
+ }
279
+ function ApiPdfResponse(description) {
280
+ return {
281
+ content: {
282
+ 'application/pdf': {
283
+ schema: z.object({
284
+ format: z.literal('binary'),
285
+ type: z.literal('string')
286
+ })
287
+ }
288
+ },
289
+ description
290
+ };
291
+ }
292
+
293
+ function throwHttpError(error, defaultMessage = 'Something went wrong') {
294
+ const code = error instanceof Error ? Number.isNaN(error.cause) ? INTERNAL_SERVER_ERROR : error.cause : INTERNAL_SERVER_ERROR;
295
+ throw new HTTPException(code, {
296
+ message: error.message ?? defaultMessage,
297
+ cause: error
298
+ });
299
+ }
300
+ function isUniqueViolationPg(error) {
301
+ const e = error;
302
+ return e?.code === '23505'; // unique_violation
303
+ }
304
+
305
+ function toErrorCode(value) {
306
+ if (value === undefined || value === null || Number.isNaN(value)) {
307
+ return 500;
308
+ }
309
+ return typeof value === 'number' ? Math.max(value, 0) : 500;
310
+ }
311
+ function onErrorFn(debugLog = true) {
312
+ return async (err, c) => {
313
+ const statusCode = 'status' in err ? toErrorCode(err.status) : 'cause' in err ? toErrorCode(err.cause) : INTERNAL_SERVER_ERROR;
314
+ let originalError = err;
315
+ const seen = new Set([err]);
316
+ while (originalError.cause instanceof Error && !seen.has(originalError.cause)) {
317
+ originalError = originalError.cause;
318
+ seen.add(originalError);
319
+ }
320
+ const logger = c.get('logger');
321
+ logger.error({
322
+ err,
323
+ path: c.req.path,
324
+ method: c.req.method
325
+ }, 'Request failed');
326
+ if (debugLog) {
327
+ console.error(err);
328
+ }
329
+ return c.json({
330
+ data: null,
331
+ error: !debugLog ? undefined : err,
332
+ message: originalError.message || err.message,
333
+ success: false
334
+ }, statusCode);
335
+ };
336
+ }
337
+
338
+ const notFoundFn = c => {
339
+ return c.json({
340
+ success: false,
341
+ error: 'Not Found',
342
+ data: {},
343
+ message: `Not Found - ${c.req.path}`
344
+ }, NOT_FOUND);
345
+ };
346
+
347
+ function buildPaginationResponse(page, size, total) {
348
+ const numPage = Number(page);
349
+ const positivePage = Number.isFinite(numPage) ? Math.max(numPage, 1) : 1;
350
+ const numSize = Number(size);
351
+ const positiveSize = Number.isFinite(numSize) && numSize > 0 ? numSize : DEFAULT_PAGE_SIZE;
352
+ const numTotal = Number(total);
353
+ const positiveTotal = Number.isFinite(numTotal) ? Math.max(numTotal, 0) : 0;
354
+ const totalPages = Math.ceil(positiveTotal / positiveSize);
355
+ return {
356
+ page: positivePage,
357
+ size: positiveSize,
358
+ totalItems: positiveTotal,
359
+ totalPages
360
+ };
361
+ }
362
+
363
+ /**
364
+ * @module constants
365
+ * @summary Useful constants
366
+ * @description
367
+ * Collection of useful date constants.
368
+ *
369
+ * The constants could be imported from `date-fns/constants`:
370
+ *
371
+ * ```ts
372
+ * import { maxTime, minTime } from "./constants/date-fns/constants";
373
+ *
374
+ * function isAllowedTime(time) {
375
+ * return time <= maxTime && time >= minTime;
376
+ * }
377
+ * ```
378
+ */
379
+
380
+
381
+ /**
382
+ * @constant
383
+ * @name constructFromSymbol
384
+ * @summary Symbol enabling Date extensions to inherit properties from the reference date.
385
+ *
386
+ * The symbol is used to enable the `constructFrom` function to construct a date
387
+ * using a reference date and a value. It allows to transfer extra properties
388
+ * from the reference date to the new date. It's useful for extensions like
389
+ * [`TZDate`](https://github.com/date-fns/tz) that accept a time zone as
390
+ * a constructor argument.
391
+ */
392
+ const constructFromSymbol = Symbol.for("constructDateFrom");
393
+
394
+ /**
395
+ * @name constructFrom
396
+ * @category Generic Helpers
397
+ * @summary Constructs a date using the reference date and the value
398
+ *
399
+ * @description
400
+ * The function constructs a new date using the constructor from the reference
401
+ * date and the given value. It helps to build generic functions that accept
402
+ * date extensions.
403
+ *
404
+ * It defaults to `Date` if the passed reference date is a number or a string.
405
+ *
406
+ * Starting from v3.7.0, it allows to construct a date using `[Symbol.for("constructDateFrom")]`
407
+ * enabling to transfer extra properties from the reference date to the new date.
408
+ * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
409
+ * that accept a time zone as a constructor argument.
410
+ *
411
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
412
+ *
413
+ * @param date - The reference date to take constructor from
414
+ * @param value - The value to create the date
415
+ *
416
+ * @returns Date initialized using the given date and value
417
+ *
418
+ * @example
419
+ * import { constructFrom } from "./constructFrom/date-fns";
420
+ *
421
+ * // A function that clones a date preserving the original type
422
+ * function cloneDate<DateType extends Date>(date: DateType): DateType {
423
+ * return constructFrom(
424
+ * date, // Use constructor from the given date
425
+ * date.getTime() // Use the date value to create a new date
426
+ * );
427
+ * }
428
+ */
429
+ function constructFrom(date, value) {
430
+ if (typeof date === "function") return date(value);
431
+
432
+ if (date && typeof date === "object" && constructFromSymbol in date)
433
+ return date[constructFromSymbol](value);
434
+
435
+ if (date instanceof Date) return new date.constructor(value);
436
+
437
+ return new Date(value);
438
+ }
439
+
440
+ /**
441
+ * @name toDate
442
+ * @category Common Helpers
443
+ * @summary Convert the given argument to an instance of Date.
444
+ *
445
+ * @description
446
+ * Convert the given argument to an instance of Date.
447
+ *
448
+ * If the argument is an instance of Date, the function returns its clone.
449
+ *
450
+ * If the argument is a number, it is treated as a timestamp.
451
+ *
452
+ * If the argument is none of the above, the function returns Invalid Date.
453
+ *
454
+ * Starting from v3.7.0, it clones a date using `[Symbol.for("constructDateFrom")]`
455
+ * enabling to transfer extra properties from the reference date to the new date.
456
+ * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
457
+ * that accept a time zone as a constructor argument.
458
+ *
459
+ * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
460
+ *
461
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
462
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
463
+ *
464
+ * @param argument - The value to convert
465
+ *
466
+ * @returns The parsed date in the local time zone
467
+ *
468
+ * @example
469
+ * // Clone the date:
470
+ * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
471
+ * //=> Tue Feb 11 2014 11:30:30
472
+ *
473
+ * @example
474
+ * // Convert the timestamp to date:
475
+ * const result = toDate(1392098430000)
476
+ * //=> Tue Feb 11 2014 11:30:30
477
+ */
478
+ function toDate(argument, context) {
479
+ // [TODO] Get rid of `toDate` or `constructFrom`?
480
+ return constructFrom(argument, argument);
481
+ }
482
+
483
+ /**
484
+ * @name isAfter
485
+ * @category Common Helpers
486
+ * @summary Is the first date after the second one?
487
+ *
488
+ * @description
489
+ * Is the first date after the second one?
490
+ *
491
+ * @param date - The date that should be after the other one to return true
492
+ * @param dateToCompare - The date to compare with
493
+ *
494
+ * @returns The first date is after the second date
495
+ *
496
+ * @example
497
+ * // Is 10 July 1989 after 11 February 1987?
498
+ * const result = isAfter(new Date(1989, 6, 10), new Date(1987, 1, 11))
499
+ * //=> true
500
+ */
501
+ function isAfter(date, dateToCompare) {
502
+ return +toDate(date) > +toDate(dateToCompare);
503
+ }
504
+
505
+ class TokenUtil {
506
+ alg;
507
+ secret;
508
+ constructor(secret, alg = 'HS256') {
509
+ this.alg = alg;
510
+ this.secret = secret;
511
+ }
512
+ async create(payload, lifeSeconds = 15 * 60) {
513
+ if (payload.exp === undefined) {
514
+ // JWT NumericDate claims (`exp`) are seconds since the epoch.
515
+ payload.exp = Math.floor(Date.now() / 1000) + lifeSeconds;
516
+ }
517
+ return await sign(payload, this.secret, this.alg);
518
+ }
519
+ async decode(token) {
520
+ return await verify(token, this.secret, this.alg);
521
+ }
522
+ async decodeUnexpired(token) {
523
+ // Disable Hono's built-in `exp` check so an expired token resolves to
524
+ // `null` instead of throwing, then validate it here.
525
+ const {
526
+ exp,
527
+ ...rest
528
+ } = await verify(token, this.secret, {
529
+ alg: this.alg,
530
+ exp: false
531
+ });
532
+ const nowSeconds = Math.floor(Date.now() / 1000);
533
+ if (exp !== undefined && exp <= nowSeconds) return null;
534
+ return {
535
+ exp: exp,
536
+ ...rest
537
+ };
538
+ }
539
+ expiresWithin(exp, seconds) {
540
+ return isAfter(new Date(), new Date(exp - seconds * 1000));
541
+ }
542
+ }
543
+
544
+ function validationHook(result, _c) {
545
+ if (!result.success) {
546
+ throwHttpError(new Error('Validation error', {
547
+ cause: UNPROCESSABLE_ENTITY
548
+ }));
549
+ }
550
+ }
551
+
552
+ export { ApiListResponse, ApiPdfResponse, ApiResponse, CryptoService, DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE, StreamResponse, TokenUtil, buildPaginationResponse, ensureDirExists, isProductionAppEnvironment, isUniqueViolationPg, notFoundFn, onErrorFn, pinoLogger, pinoLoggerMiddleware, safeRequestBody, safeResponseBody, throwHttpError, validationHook, zCommonQuery, zEmpty, zFile, zId, zIds, zPagination, zPassword, zResponsePagination, zStreamResponse };
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@mattrika/server-utils",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.1",
4
+ "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/mattrika/libs"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "dependencies": {
13
+ "tslib": "^2.3.0"
14
+ },
15
+ "peerDependencies": {
16
+ "@hono/zod-openapi": "^1.6.3",
17
+ "@node-rs/argon2": "^2.2.2",
18
+ "es-toolkit": "^1.52.0",
19
+ "hono": "^4.13.13",
20
+ "pino": "^10.4.0",
21
+ "stoker": "^2.0.1",
22
+ "zod": "^4.6.7"
23
+ },
24
+ "exports": {
25
+ "./package.json": "./package.json",
26
+ ".": {
27
+ "module": "./index.esm.js",
28
+ "types": "./index.d.ts",
29
+ "import": "./index.cjs.mjs",
30
+ "default": "./index.cjs.js"
31
+ }
32
+ },
33
+ "module": "./index.esm.js",
34
+ "main": "./index.cjs.js",
35
+ "types": "./index.d.ts"
6
36
  }
package/src/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ export * from './lib/constants/common.values';
2
+ export * from './lib/pino-logger/logger.helpers';
3
+ export * from './lib/pino-logger/pino-logger';
4
+ export * from './lib/pino-logger/pino-logger.middleware';
5
+ export * from './lib/predicates/is-prod';
6
+ export * from './lib/schemas/common.schema';
7
+ export * from './lib/services/crypto.service';
8
+ export * from './lib/utils/api-response.util';
9
+ export * from './lib/utils/error.util';
10
+ export * from './lib/utils/on-error';
11
+ export * from './lib/utils/on-not-found';
12
+ export * from './lib/utils/pagination.util';
13
+ export * from './lib/utils/token.util';
14
+ export * from './lib/utils/validation-hook';
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_PAGE_SIZE = 20;
2
+ export declare const MAX_PAGE_SIZE = 100;
@@ -0,0 +1,4 @@
1
+ import type { HonoRequest } from 'hono';
2
+ export declare function safeResponseBody(res: Response): Promise<any>;
3
+ export declare function safeRequestBody(req: HonoRequest): Promise<any>;
4
+ export declare function ensureDirExists(filePath: string): void;
@@ -0,0 +1,2 @@
1
+ import pino from 'pino';
2
+ export declare function pinoLogger(): pino.Logger<never, boolean>;
@@ -0,0 +1,2 @@
1
+ import type { MiddlewareHandler } from 'hono';
2
+ export declare const pinoLoggerMiddleware: () => MiddlewareHandler;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Checks whether APP_ENV environment variable is set to 'production' or NODE_ENV environment variable is set to 'production', in that order.
3
+ * @returns boolean
4
+ */
5
+ export declare function isProductionAppEnvironment(): boolean;
@@ -0,0 +1,29 @@
1
+ import { z } from '@hono/zod-openapi';
2
+ export declare const zPagination: z.ZodObject<{
3
+ page: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
4
+ size: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
5
+ }, z.core.$strip>;
6
+ export declare const zCommonQuery: z.ZodObject<{
7
+ search: z.ZodOptional<z.ZodString>;
8
+ orderBy: z.ZodOptional<z.ZodString>;
9
+ sortOrder: z.ZodOptional<z.ZodEnum<{
10
+ asc: "asc";
11
+ desc: "desc";
12
+ }>>;
13
+ page: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
14
+ size: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
15
+ }, z.core.$strip>;
16
+ export declare const zId: z.ZodObject<{
17
+ id: z.ZodString;
18
+ }, z.core.$strip>;
19
+ export declare const zIds: z.ZodObject<{
20
+ ids: z.ZodArray<z.ZodString>;
21
+ }, z.core.$strip>;
22
+ export declare const zPassword: z.ZodString;
23
+ export declare const zEmpty: z.ZodObject<{}, z.core.$strip>;
24
+ export declare const zFile: z.ZodObject<{
25
+ file: z.ZodOptional<z.ZodInstanceOf<File>>;
26
+ files: z.ZodOptional<z.ZodArray<z.ZodInstanceOf<File>>>;
27
+ }, z.core.$strip>;
28
+ export type CommonQueryParams = z.infer<typeof zCommonQuery>;
29
+ export type PaginationParams = z.infer<typeof zPagination>;
@@ -0,0 +1,5 @@
1
+ export declare class CryptoService {
2
+ static hash(plain: string): Promise<string>;
3
+ static verify(plain: string, hash: string): Promise<boolean>;
4
+ static random64chars(): string;
5
+ }