@mrxsys/mrx-core 2.11.0-2-and-276-20251029 → 2.11.0-4-and-276-20251029
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/chunk-0d0zd2yg.js +8 -0
- package/dist/chunk-12qzn7jw.js +7 -0
- package/dist/chunk-441xs5k1.js +53 -0
- package/dist/chunk-4v86f7gp.js +59 -0
- package/dist/chunk-6w9ja96e.js +9 -0
- package/dist/chunk-7t524zqh.js +26 -0
- package/dist/chunk-8tffnbpn.js +7 -0
- package/dist/chunk-9cgzhc50.js +15 -0
- package/dist/chunk-9d3zvgp6.js +9 -0
- package/dist/chunk-9dzsj7f2.js +23 -0
- package/dist/chunk-9r5anep5.js +11 -0
- package/dist/chunk-afd82epa.js +201 -0
- package/dist/chunk-afyz8rg5.js +209 -0
- package/dist/chunk-dre2fgj0.js +7 -0
- package/dist/chunk-e30paw8a.js +101 -0
- package/dist/chunk-eeb7yskp.js +61 -0
- package/dist/chunk-fs3wm3p4.js +32 -0
- package/dist/chunk-grfyngq0.js +39 -0
- package/dist/chunk-gtn1kn0z.js +79 -0
- package/dist/chunk-jksb9ers.js +7 -0
- package/dist/chunk-m3grz32t.js +27 -0
- package/dist/chunk-mvrxngm7.js +41 -0
- package/dist/chunk-n0n14mf8.js +7 -0
- package/dist/chunk-p14h6jfs.js +365 -0
- package/dist/chunk-pjv1ekwr.js +284 -0
- package/dist/chunk-rz5p4j3p.js +13 -0
- package/dist/chunk-spnh9dzk.js +10 -0
- package/dist/chunk-sqts8vyk.js +60 -0
- package/dist/chunk-w7h898m3.js +14 -0
- package/dist/chunk-xhhj1gvj.js +9 -0
- package/dist/chunk-z0ct35ft.js +8 -0
- package/dist/errors/enums/index.js +7 -0
- package/dist/errors/index.js +12 -0
- package/dist/errors/utils/index.js +16 -0
- package/dist/errors/utils/is-nowarajs-error.ts.d.ts +2 -2
- package/dist/modules/data/enums/index.js +7 -0
- package/dist/modules/data/index.js +17 -0
- package/dist/modules/data/transformers/camel-case.d.ts +2 -2
- package/dist/modules/data/transformers/index.js +32 -0
- package/dist/modules/data/transformers/kebab-case.d.ts +2 -2
- package/dist/modules/data/transformers/pascal-case.d.ts +2 -2
- package/dist/modules/data/transformers/snake-case.d.ts +2 -2
- package/dist/modules/data/types/index.js +1 -0
- package/dist/modules/data/types/transform-object-keys.d.ts +4 -4
- package/dist/modules/database/enums/index.js +9 -0
- package/dist/modules/database/events/index.js +1 -0
- package/dist/modules/database/events/mssql-event-map.d.ts +1 -1
- package/dist/modules/database/events/table-event-map.d.ts +1 -1
- package/dist/modules/database/index.js +16 -0
- package/dist/modules/database/mssql.d.ts +2 -2
- package/dist/modules/database/table.d.ts +2 -2
- package/dist/modules/database/types/index.js +1 -0
- package/dist/modules/elysia/cache/cache.d.ts +1 -1
- package/dist/modules/elysia/cache/index.js +90 -0
- package/dist/modules/elysia/cache/types/index.js +1 -0
- package/dist/modules/elysia/crud/crud.d.ts +2 -2
- package/dist/modules/elysia/crud/enums/index.js +7 -0
- package/dist/modules/elysia/crud/index.js +153 -0
- package/dist/modules/elysia/crud/operations/count.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/delete.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/deleteOne.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/find.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/findOne.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/index.js +34 -0
- package/dist/modules/elysia/crud/operations/insert.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/update.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/updateOne.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/utils/get-db-injection.d.ts +1 -1
- package/dist/modules/elysia/crud/types/crud-options.d.ts +1 -1
- package/dist/modules/elysia/crud/types/crud-schema-models-type.d.ts +9 -9
- package/dist/modules/elysia/crud/types/delete-schema.d.ts +2 -2
- package/dist/modules/elysia/crud/types/find-schema.d.ts +3 -3
- package/dist/modules/elysia/crud/types/index.js +1 -0
- package/dist/modules/elysia/crud/types/insert-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/types/properties-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/types/response-200-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/types/update-schema.d.ts +2 -2
- package/dist/modules/elysia/crud/utils/create-adaptive-where-clause-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-count-response-200-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-count-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-delete-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-filters-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-find-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-id-param-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-insert-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-order-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-properties-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-q-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-response-200-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-selected-fields-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-update-one-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-update-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/index.js +41 -0
- package/dist/modules/elysia/db-resolver/db-resolver.d.ts +2 -2
- package/dist/modules/elysia/db-resolver/enums/index.js +7 -0
- package/dist/modules/elysia/db-resolver/index.js +18 -0
- package/dist/modules/elysia/error/enums/index.js +7 -0
- package/dist/modules/elysia/error/error.d.ts +5 -0
- package/dist/modules/elysia/error/index.d.ts +1 -1
- package/dist/modules/elysia/error/index.js +67 -0
- package/dist/modules/elysia/microservice/enums/index.js +7 -0
- package/dist/modules/elysia/microservice/index.js +100 -0
- package/dist/modules/elysia/rate-limit/enums/index.js +7 -0
- package/dist/modules/elysia/rate-limit/index.js +81 -0
- package/dist/modules/elysia/rate-limit/rate-limit.d.ts +1 -1
- package/dist/modules/elysia/rate-limit/types/index.js +1 -0
- package/dist/modules/jwt/enums/index.js +11 -0
- package/dist/modules/jwt/index.js +51 -0
- package/dist/modules/jwt/utils/index.js +9 -0
- package/dist/modules/kv-store/bun-redis/bun-redis-store.d.ts +1 -1
- package/dist/modules/kv-store/bun-redis/index.js +84 -0
- package/dist/modules/kv-store/enums/index.js +7 -0
- package/dist/modules/kv-store/ioredis/index.js +86 -0
- package/dist/modules/kv-store/ioredis/ioredis-store.d.ts +1 -1
- package/dist/modules/kv-store/memory/index.js +9 -0
- package/dist/modules/kv-store/memory/memory-store.d.ts +1 -1
- package/dist/modules/kv-store/types/index.js +1 -0
- package/dist/modules/logger/enums/index.js +7 -0
- package/dist/modules/logger/events/index.js +1 -0
- package/dist/modules/logger/events/logger-events.d.ts +1 -1
- package/dist/modules/logger/index.js +208 -0
- package/dist/modules/logger/logger.d.ts +1 -1
- package/dist/modules/logger/sinks/console-logger.d.ts +2 -2
- package/dist/modules/logger/sinks/devnull-logger.d.ts +1 -1
- package/dist/modules/logger/sinks/file-logger/file-logger.d.ts +2 -2
- package/dist/modules/logger/sinks/index.js +66 -0
- package/dist/modules/logger/types/index.js +1 -0
- package/dist/modules/mailer/enums/index.js +7 -0
- package/dist/modules/mailer/index.js +55 -0
- package/dist/modules/mailer/types/index.js +1 -0
- package/dist/modules/repository/index.js +12 -0
- package/dist/modules/repository/repository.d.ts +2 -2
- package/dist/modules/repository/types/index.js +1 -0
- package/dist/modules/repository/types/query-options.d.ts +1 -1
- package/dist/modules/singleton-manager/enums/index.js +7 -0
- package/dist/modules/singleton-manager/index.js +9 -0
- package/dist/modules/totp/enums/index.js +7 -0
- package/dist/modules/totp/index.js +104 -0
- package/dist/modules/totp/types/index.js +1 -0
- package/dist/modules/totp/utils/index.js +76 -0
- package/dist/modules/typed-event-emitter/index.js +7 -0
- package/dist/modules/typed-event-emitter/types/index.js +1 -0
- package/dist/shared/enums/index.js +7 -0
- package/dist/shared/types/index.js +1 -0
- package/dist/shared/utils/flatten.d.ts +1 -1
- package/dist/shared/utils/index.js +30 -0
- package/package.json +1 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
BaseError
|
|
4
|
+
} from "../../../chunk-9cgzhc50.js";
|
|
5
|
+
|
|
6
|
+
// source/modules/logger/sinks/console-logger.ts
|
|
7
|
+
class ConsoleLoggerSink {
|
|
8
|
+
async log(level, timestamp, object) {
|
|
9
|
+
const logEntry = { timestamp, level, content: object };
|
|
10
|
+
await Bun.write(Bun.stdout, JSON.stringify(logEntry) + `
|
|
11
|
+
`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
// source/modules/logger/sinks/devnull-logger.ts
|
|
15
|
+
class DevNullLoggerSink {
|
|
16
|
+
log() {}
|
|
17
|
+
}
|
|
18
|
+
// source/modules/logger/sinks/file-logger/enums/file-logger-error-keys.ts
|
|
19
|
+
var FILE_LOGGER_ERROR_KEYS = {
|
|
20
|
+
FAILED_TO_CLOSE_STREAM: "mrx-core.file_logger.error.failed_to_close_stream"
|
|
21
|
+
};
|
|
22
|
+
// source/modules/logger/sinks/file-logger/file-logger.ts
|
|
23
|
+
import { createWriteStream } from "fs";
|
|
24
|
+
class FileLoggerSink {
|
|
25
|
+
config;
|
|
26
|
+
_stream;
|
|
27
|
+
_isClosed = false;
|
|
28
|
+
constructor(config) {
|
|
29
|
+
this.config = config;
|
|
30
|
+
this._stream = createWriteStream(config.path, {
|
|
31
|
+
flags: "a",
|
|
32
|
+
encoding: "utf8",
|
|
33
|
+
highWaterMark: config.bufferSize ?? 16 * 1024
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async log(level, timestamp, object) {
|
|
37
|
+
if (this._isClosed)
|
|
38
|
+
return;
|
|
39
|
+
const logEntry = JSON.stringify({ timestamp, level, content: object }) + `
|
|
40
|
+
`;
|
|
41
|
+
const canContinue = this._stream.write(logEntry);
|
|
42
|
+
if (!canContinue)
|
|
43
|
+
await new Promise((resolve) => {
|
|
44
|
+
this._stream.once("drain", resolve);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async close() {
|
|
48
|
+
if (this._isClosed)
|
|
49
|
+
return;
|
|
50
|
+
this._isClosed = true;
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
this._stream.end((err) => {
|
|
53
|
+
if (err)
|
|
54
|
+
reject(new BaseError(FILE_LOGGER_ERROR_KEYS.FAILED_TO_CLOSE_STREAM, err.message));
|
|
55
|
+
else
|
|
56
|
+
resolve();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
FileLoggerSink,
|
|
63
|
+
FILE_LOGGER_ERROR_KEYS,
|
|
64
|
+
DevNullLoggerSink,
|
|
65
|
+
ConsoleLoggerSink
|
|
66
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// @bun
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
MAILER_ERROR_KEYS
|
|
4
|
+
} from "../../chunk-6w9ja96e.js";
|
|
5
|
+
import {
|
|
6
|
+
BaseError
|
|
7
|
+
} from "../../chunk-9cgzhc50.js";
|
|
8
|
+
|
|
9
|
+
// source/modules/mailer/smtp.ts
|
|
10
|
+
import { createTransport } from "nodemailer";
|
|
11
|
+
class SMTP {
|
|
12
|
+
_config;
|
|
13
|
+
_transporter = null;
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this._config = {
|
|
16
|
+
port: 587,
|
|
17
|
+
secure: false,
|
|
18
|
+
...config
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async connect() {
|
|
22
|
+
if (this._transporter)
|
|
23
|
+
throw new BaseError(MAILER_ERROR_KEYS.SMTP_ALREADY_CONNECTED);
|
|
24
|
+
this._transporter = createTransport({
|
|
25
|
+
host: this._config.host,
|
|
26
|
+
port: this._config.port,
|
|
27
|
+
secure: this._config.secure,
|
|
28
|
+
auth: {
|
|
29
|
+
user: this._config.credentials.user,
|
|
30
|
+
pass: this._config.credentials.pass
|
|
31
|
+
},
|
|
32
|
+
pool: true,
|
|
33
|
+
maxConnections: this._config.pool?.maxConnections ?? 5
|
|
34
|
+
});
|
|
35
|
+
try {
|
|
36
|
+
await this._transporter.verify();
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new BaseError(MAILER_ERROR_KEYS.SMTP_CONNECTION_ERROR, error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
disconnect() {
|
|
42
|
+
if (this._transporter) {
|
|
43
|
+
this._transporter.close();
|
|
44
|
+
this._transporter = null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async sendMail(options) {
|
|
48
|
+
if (!this._transporter)
|
|
49
|
+
throw new BaseError(MAILER_ERROR_KEYS.SMTP_NOT_CONNECTED);
|
|
50
|
+
return this._transporter.sendMail(options);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
SMTP
|
|
55
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// @bun
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
Repository
|
|
4
|
+
} from "../../chunk-afyz8rg5.js";
|
|
5
|
+
import"../../chunk-grfyngq0.js";
|
|
6
|
+
import"../../chunk-4v86f7gp.js";
|
|
7
|
+
import"../../chunk-7t524zqh.js";
|
|
8
|
+
import"../../chunk-sqts8vyk.js";
|
|
9
|
+
import"../../chunk-9cgzhc50.js";
|
|
10
|
+
export {
|
|
11
|
+
Repository
|
|
12
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
|
-
import type { Table } from '
|
|
3
|
-
import type { StreamWithAsyncIterable } from '
|
|
2
|
+
import type { Table } from '../../modules/database/table';
|
|
3
|
+
import type { StreamWithAsyncIterable } from '../../shared/types/stream-with-async-iterable';
|
|
4
4
|
import type { Filter } from './types/filter';
|
|
5
5
|
import type { OrderByItem } from './types/order-by-item';
|
|
6
6
|
import type { QueryOptions } from './types/query-options';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// @bun
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HTTP_STATUS_CODES } from '
|
|
1
|
+
import type { HTTP_STATUS_CODES } from '../../../errors/enums/http-status-codes';
|
|
2
2
|
import type { Filter } from './filter';
|
|
3
3
|
import type { OrderByItem } from './order-by-item';
|
|
4
4
|
import type { SelectedFields } from './selected-fields';
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
createCounterBuffer,
|
|
4
|
+
dynamicTruncation,
|
|
5
|
+
generateHmac
|
|
6
|
+
} from "../../chunk-m3grz32t.js";
|
|
7
|
+
import {
|
|
8
|
+
TOTP_ERROR_KEYS
|
|
9
|
+
} from "../../chunk-9r5anep5.js";
|
|
10
|
+
import {
|
|
11
|
+
BaseError
|
|
12
|
+
} from "../../chunk-9cgzhc50.js";
|
|
13
|
+
|
|
14
|
+
// source/modules/totp/hotp.ts
|
|
15
|
+
import { webcrypto } from "crypto";
|
|
16
|
+
var hotp = async (secret, counter, {
|
|
17
|
+
algorithm = "SHA-1",
|
|
18
|
+
digits = 6
|
|
19
|
+
} = {}) => {
|
|
20
|
+
const counterBuffer = createCounterBuffer(counter);
|
|
21
|
+
const key = await webcrypto.subtle.importKey("raw", secret, { name: "HMAC", hash: algorithm }, false, ["sign"]);
|
|
22
|
+
const hmacArray = await generateHmac(key, counterBuffer);
|
|
23
|
+
return dynamicTruncation(hmacArray, digits);
|
|
24
|
+
};
|
|
25
|
+
// source/modules/totp/otp-auth-uri.ts
|
|
26
|
+
var buildOtpAuthUri = ({
|
|
27
|
+
secretBase32,
|
|
28
|
+
label,
|
|
29
|
+
issuer,
|
|
30
|
+
algorithm = "SHA-1",
|
|
31
|
+
digits = 6,
|
|
32
|
+
period = 30
|
|
33
|
+
}) => {
|
|
34
|
+
const encodedLabel = encodeURIComponent(label);
|
|
35
|
+
const encodedIssuer = issuer ? encodeURIComponent(issuer) : undefined;
|
|
36
|
+
let uri = `otpauth://totp/${encodedLabel}?secret=${secretBase32}`;
|
|
37
|
+
if (encodedIssuer)
|
|
38
|
+
uri += `&issuer=${encodedIssuer}`;
|
|
39
|
+
if (algorithm !== "SHA-1")
|
|
40
|
+
uri += `&algorithm=${algorithm}`;
|
|
41
|
+
if (digits !== 6)
|
|
42
|
+
uri += `&digits=${digits}`;
|
|
43
|
+
if (period !== 30)
|
|
44
|
+
uri += `&period=${period}`;
|
|
45
|
+
return uri;
|
|
46
|
+
};
|
|
47
|
+
var parseOtpAuthUri = (uri) => {
|
|
48
|
+
const url = new URL(uri);
|
|
49
|
+
if (url.protocol !== "otpauth:")
|
|
50
|
+
throw new BaseError(TOTP_ERROR_KEYS.INVALID_OTP_AUTH_URI);
|
|
51
|
+
if (url.hostname !== "totp")
|
|
52
|
+
throw new BaseError(TOTP_ERROR_KEYS.INVALID_OTP_AUTH_URI);
|
|
53
|
+
const label = decodeURIComponent(url.pathname.slice(1));
|
|
54
|
+
const secretBase32 = url.searchParams.get("secret");
|
|
55
|
+
if (!secretBase32)
|
|
56
|
+
throw new BaseError(TOTP_ERROR_KEYS.MISSING_SECRET);
|
|
57
|
+
const issuerParam = url.searchParams.get("issuer");
|
|
58
|
+
const issuer = issuerParam ? decodeURIComponent(issuerParam) : undefined;
|
|
59
|
+
const algorithm = url.searchParams.get("algorithm") || "SHA-1";
|
|
60
|
+
const digits = parseInt(url.searchParams.get("digits") || "6", 10);
|
|
61
|
+
const period = parseInt(url.searchParams.get("period") || "30", 10);
|
|
62
|
+
const result = {
|
|
63
|
+
secretBase32,
|
|
64
|
+
label,
|
|
65
|
+
algorithm,
|
|
66
|
+
digits,
|
|
67
|
+
period,
|
|
68
|
+
...issuer && { issuer }
|
|
69
|
+
};
|
|
70
|
+
return result;
|
|
71
|
+
};
|
|
72
|
+
// source/modules/totp/totp.ts
|
|
73
|
+
var totp = async (secret, {
|
|
74
|
+
algorithm = "SHA-1",
|
|
75
|
+
digits = 6,
|
|
76
|
+
period = 30,
|
|
77
|
+
now = Date.now()
|
|
78
|
+
} = {}) => {
|
|
79
|
+
const timeStep = Math.floor(now / 1000 / period);
|
|
80
|
+
return hotp(secret, timeStep, { algorithm, digits });
|
|
81
|
+
};
|
|
82
|
+
var verifyTotp = async (secret, code, {
|
|
83
|
+
algorithm = "SHA-1",
|
|
84
|
+
digits = 6,
|
|
85
|
+
period = 30,
|
|
86
|
+
window = 0,
|
|
87
|
+
now = Date.now()
|
|
88
|
+
} = {}) => {
|
|
89
|
+
const currentTimeStep = Math.floor(now / 1000 / period);
|
|
90
|
+
for (let i = -window;i <= window; ++i) {
|
|
91
|
+
const timeStep = currentTimeStep + i;
|
|
92
|
+
const expectedCode = await hotp(secret, timeStep, { algorithm, digits });
|
|
93
|
+
if (expectedCode === code)
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
};
|
|
98
|
+
export {
|
|
99
|
+
verifyTotp,
|
|
100
|
+
totp,
|
|
101
|
+
parseOtpAuthUri,
|
|
102
|
+
hotp,
|
|
103
|
+
buildOtpAuthUri
|
|
104
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// @bun
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
createCounterBuffer,
|
|
4
|
+
dynamicTruncation,
|
|
5
|
+
generateHmac
|
|
6
|
+
} from "../../../chunk-m3grz32t.js";
|
|
7
|
+
import {
|
|
8
|
+
TOTP_ERROR_KEYS
|
|
9
|
+
} from "../../../chunk-9r5anep5.js";
|
|
10
|
+
import {
|
|
11
|
+
BaseError
|
|
12
|
+
} from "../../../chunk-9cgzhc50.js";
|
|
13
|
+
|
|
14
|
+
// source/modules/totp/utils/base32.ts
|
|
15
|
+
var BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
16
|
+
var base32Encode = (input, withPadding = true) => {
|
|
17
|
+
let result = "";
|
|
18
|
+
let bits = 0;
|
|
19
|
+
let value = 0;
|
|
20
|
+
const bytes = input instanceof Uint8Array ? input : new TextEncoder().encode(input);
|
|
21
|
+
for (const byte of bytes) {
|
|
22
|
+
value = value << 8 | byte;
|
|
23
|
+
bits += 8;
|
|
24
|
+
while (bits >= 5) {
|
|
25
|
+
result += BASE32_ALPHABET[value >>> bits - 5 & 31];
|
|
26
|
+
bits -= 5;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (bits > 0)
|
|
30
|
+
result += BASE32_ALPHABET[value << 5 - bits & 31];
|
|
31
|
+
if (withPadding)
|
|
32
|
+
while (result.length % 8 !== 0)
|
|
33
|
+
result += "=";
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
var base32Decode = (base32) => {
|
|
37
|
+
const cleanBase32 = base32.replace(/=+$/, "");
|
|
38
|
+
if (cleanBase32.length === 0)
|
|
39
|
+
return new Uint8Array(0);
|
|
40
|
+
const result = [];
|
|
41
|
+
let bits = 0;
|
|
42
|
+
let value = 0;
|
|
43
|
+
for (const char of cleanBase32) {
|
|
44
|
+
const charValue = BASE32_ALPHABET.indexOf(char);
|
|
45
|
+
if (charValue === -1)
|
|
46
|
+
throw new BaseError(TOTP_ERROR_KEYS.INVALID_BASE32_CHARACTER, `Invalid Base32 character: ${char}`);
|
|
47
|
+
value = value << 5 | charValue;
|
|
48
|
+
bits += 5;
|
|
49
|
+
if (bits >= 8) {
|
|
50
|
+
result.push(value >>> bits - 8 & 255);
|
|
51
|
+
bits -= 8;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return new Uint8Array(result);
|
|
55
|
+
};
|
|
56
|
+
// source/modules/totp/utils/generate-secret-bytes.ts
|
|
57
|
+
import { getRandomValues } from "crypto";
|
|
58
|
+
var generateSecretBytes = (length = 20) => {
|
|
59
|
+
if (length <= 0)
|
|
60
|
+
throw new BaseError(TOTP_ERROR_KEYS.INVALID_SECRET_LENGTH);
|
|
61
|
+
return getRandomValues(new Uint8Array(length));
|
|
62
|
+
};
|
|
63
|
+
// source/modules/totp/utils/time-remaining.ts
|
|
64
|
+
var timeRemaining = (period = 30, now = Date.now()) => {
|
|
65
|
+
const elapsed = Math.floor(now / 1000) % period;
|
|
66
|
+
return period - elapsed;
|
|
67
|
+
};
|
|
68
|
+
export {
|
|
69
|
+
timeRemaining,
|
|
70
|
+
generateSecretBytes,
|
|
71
|
+
generateHmac,
|
|
72
|
+
dynamicTruncation,
|
|
73
|
+
createCounterBuffer,
|
|
74
|
+
base32Encode,
|
|
75
|
+
base32Decode
|
|
76
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// @bun
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// @bun
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
UTILS_ERROR_KEYS
|
|
4
|
+
} from "../../chunk-n0n14mf8.js";
|
|
5
|
+
import {
|
|
6
|
+
flatten
|
|
7
|
+
} from "../../chunk-9dzsj7f2.js";
|
|
8
|
+
import {
|
|
9
|
+
isDateString,
|
|
10
|
+
makeStreamAsyncIterable
|
|
11
|
+
} from "../../chunk-grfyngq0.js";
|
|
12
|
+
import {
|
|
13
|
+
BaseError
|
|
14
|
+
} from "../../chunk-9cgzhc50.js";
|
|
15
|
+
|
|
16
|
+
// source/shared/utils/env.ts
|
|
17
|
+
import { Value } from "@sinclair/typebox/value";
|
|
18
|
+
var validateEnv = (schema, env = process.env) => {
|
|
19
|
+
try {
|
|
20
|
+
Value.Assert(schema, Value.Parse(schema, env));
|
|
21
|
+
} catch (error) {
|
|
22
|
+
throw new BaseError(UTILS_ERROR_KEYS.INVALID_ENVIRONMENT, error);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
validateEnv,
|
|
27
|
+
makeStreamAsyncIterable,
|
|
28
|
+
isDateString,
|
|
29
|
+
flatten
|
|
30
|
+
};
|