@mrxsys/mrx-core 2.11.0-1-and-276-20251029 → 2.11.0-2-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.
Files changed (146) hide show
  1. package/dist/errors/utils/is-nowarajs-error.ts.d.ts +2 -2
  2. package/dist/modules/data/transformers/camel-case.d.ts +2 -2
  3. package/dist/modules/data/transformers/kebab-case.d.ts +2 -2
  4. package/dist/modules/data/transformers/pascal-case.d.ts +2 -2
  5. package/dist/modules/data/transformers/snake-case.d.ts +2 -2
  6. package/dist/modules/data/types/transform-object-keys.d.ts +4 -4
  7. package/dist/modules/database/events/mssql-event-map.d.ts +1 -1
  8. package/dist/modules/database/events/table-event-map.d.ts +1 -1
  9. package/dist/modules/database/mssql.d.ts +2 -2
  10. package/dist/modules/database/table.d.ts +2 -2
  11. package/dist/modules/elysia/cache/cache.d.ts +1 -1
  12. package/dist/modules/elysia/crud/crud.d.ts +2 -2
  13. package/dist/modules/elysia/crud/operations/count.d.ts +3 -3
  14. package/dist/modules/elysia/crud/operations/delete.d.ts +3 -3
  15. package/dist/modules/elysia/crud/operations/deleteOne.d.ts +3 -3
  16. package/dist/modules/elysia/crud/operations/find.d.ts +3 -3
  17. package/dist/modules/elysia/crud/operations/findOne.d.ts +3 -3
  18. package/dist/modules/elysia/crud/operations/insert.d.ts +3 -3
  19. package/dist/modules/elysia/crud/operations/update.d.ts +3 -3
  20. package/dist/modules/elysia/crud/operations/updateOne.d.ts +3 -3
  21. package/dist/modules/elysia/crud/operations/utils/get-db-injection.d.ts +1 -1
  22. package/dist/modules/elysia/crud/types/crud-options.d.ts +1 -1
  23. package/dist/modules/elysia/crud/types/crud-schema-models-type.d.ts +9 -9
  24. package/dist/modules/elysia/crud/types/delete-schema.d.ts +2 -2
  25. package/dist/modules/elysia/crud/types/find-schema.d.ts +3 -3
  26. package/dist/modules/elysia/crud/types/insert-schema.d.ts +1 -1
  27. package/dist/modules/elysia/crud/types/properties-schema.d.ts +1 -1
  28. package/dist/modules/elysia/crud/types/response-200-schema.d.ts +1 -1
  29. package/dist/modules/elysia/crud/types/update-schema.d.ts +2 -2
  30. package/dist/modules/elysia/crud/utils/create-adaptive-where-clause-schema.d.ts +1 -1
  31. package/dist/modules/elysia/crud/utils/create-count-response-200-schema.d.ts +1 -1
  32. package/dist/modules/elysia/crud/utils/create-count-schema.d.ts +1 -1
  33. package/dist/modules/elysia/crud/utils/create-delete-schema.d.ts +1 -1
  34. package/dist/modules/elysia/crud/utils/create-filters-schema.d.ts +1 -1
  35. package/dist/modules/elysia/crud/utils/create-find-schema.d.ts +1 -1
  36. package/dist/modules/elysia/crud/utils/create-id-param-schema.d.ts +1 -1
  37. package/dist/modules/elysia/crud/utils/create-insert-schema.d.ts +1 -1
  38. package/dist/modules/elysia/crud/utils/create-order-schema.d.ts +1 -1
  39. package/dist/modules/elysia/crud/utils/create-properties-schema.d.ts +1 -1
  40. package/dist/modules/elysia/crud/utils/create-q-schema.d.ts +1 -1
  41. package/dist/modules/elysia/crud/utils/create-response-200-schema.d.ts +1 -1
  42. package/dist/modules/elysia/crud/utils/create-selected-fields-schema.d.ts +1 -1
  43. package/dist/modules/elysia/crud/utils/create-update-one-schema.d.ts +1 -1
  44. package/dist/modules/elysia/crud/utils/create-update-schema.d.ts +1 -1
  45. package/dist/modules/elysia/db-resolver/db-resolver.d.ts +2 -2
  46. package/dist/modules/elysia/rate-limit/rate-limit.d.ts +1 -1
  47. package/dist/modules/kv-store/bun-redis/bun-redis-store.d.ts +1 -1
  48. package/dist/modules/kv-store/ioredis/ioredis-store.d.ts +1 -1
  49. package/dist/modules/kv-store/memory/memory-store.d.ts +1 -1
  50. package/dist/modules/logger/events/logger-events.d.ts +1 -1
  51. package/dist/modules/logger/logger.d.ts +1 -1
  52. package/dist/modules/logger/sinks/console-logger.d.ts +2 -2
  53. package/dist/modules/logger/sinks/devnull-logger.d.ts +1 -1
  54. package/dist/modules/logger/sinks/file-logger/file-logger.d.ts +2 -2
  55. package/dist/modules/repository/repository.d.ts +2 -2
  56. package/dist/modules/repository/types/query-options.d.ts +1 -1
  57. package/dist/shared/utils/flatten.d.ts +1 -1
  58. package/package.json +1 -1
  59. package/dist/chunk-0d0zd2yg.js +0 -8
  60. package/dist/chunk-12qzn7jw.js +0 -7
  61. package/dist/chunk-441xs5k1.js +0 -53
  62. package/dist/chunk-4v86f7gp.js +0 -59
  63. package/dist/chunk-6w9ja96e.js +0 -9
  64. package/dist/chunk-7t524zqh.js +0 -26
  65. package/dist/chunk-8tffnbpn.js +0 -7
  66. package/dist/chunk-9cgzhc50.js +0 -15
  67. package/dist/chunk-9d3zvgp6.js +0 -9
  68. package/dist/chunk-9dzsj7f2.js +0 -23
  69. package/dist/chunk-9r5anep5.js +0 -11
  70. package/dist/chunk-afd82epa.js +0 -201
  71. package/dist/chunk-afyz8rg5.js +0 -209
  72. package/dist/chunk-dre2fgj0.js +0 -7
  73. package/dist/chunk-e30paw8a.js +0 -101
  74. package/dist/chunk-eeb7yskp.js +0 -61
  75. package/dist/chunk-fs3wm3p4.js +0 -32
  76. package/dist/chunk-grfyngq0.js +0 -39
  77. package/dist/chunk-gtn1kn0z.js +0 -79
  78. package/dist/chunk-jksb9ers.js +0 -7
  79. package/dist/chunk-m3grz32t.js +0 -27
  80. package/dist/chunk-mvrxngm7.js +0 -41
  81. package/dist/chunk-n0n14mf8.js +0 -7
  82. package/dist/chunk-p14h6jfs.js +0 -365
  83. package/dist/chunk-pjv1ekwr.js +0 -284
  84. package/dist/chunk-rz5p4j3p.js +0 -13
  85. package/dist/chunk-spnh9dzk.js +0 -10
  86. package/dist/chunk-sqts8vyk.js +0 -60
  87. package/dist/chunk-w7h898m3.js +0 -14
  88. package/dist/chunk-xhhj1gvj.js +0 -9
  89. package/dist/chunk-z0ct35ft.js +0 -8
  90. package/dist/errors/enums/index.js +0 -7
  91. package/dist/errors/index.js +0 -12
  92. package/dist/errors/utils/index.js +0 -16
  93. package/dist/modules/data/enums/index.js +0 -7
  94. package/dist/modules/data/index.js +0 -17
  95. package/dist/modules/data/transformers/index.js +0 -32
  96. package/dist/modules/data/types/index.js +0 -1
  97. package/dist/modules/database/enums/index.js +0 -9
  98. package/dist/modules/database/events/index.js +0 -1
  99. package/dist/modules/database/index.js +0 -16
  100. package/dist/modules/database/types/index.js +0 -1
  101. package/dist/modules/elysia/cache/index.js +0 -90
  102. package/dist/modules/elysia/cache/types/index.js +0 -1
  103. package/dist/modules/elysia/crud/enums/index.js +0 -7
  104. package/dist/modules/elysia/crud/index.js +0 -153
  105. package/dist/modules/elysia/crud/operations/index.js +0 -34
  106. package/dist/modules/elysia/crud/types/index.js +0 -1
  107. package/dist/modules/elysia/crud/utils/index.js +0 -41
  108. package/dist/modules/elysia/db-resolver/enums/index.js +0 -7
  109. package/dist/modules/elysia/db-resolver/index.js +0 -18
  110. package/dist/modules/elysia/error/enums/index.js +0 -7
  111. package/dist/modules/elysia/error/error.d.ts +0 -37
  112. package/dist/modules/elysia/error/index.js +0 -73
  113. package/dist/modules/elysia/microservice/enums/index.js +0 -7
  114. package/dist/modules/elysia/microservice/index.js +0 -100
  115. package/dist/modules/elysia/rate-limit/enums/index.js +0 -7
  116. package/dist/modules/elysia/rate-limit/index.js +0 -81
  117. package/dist/modules/elysia/rate-limit/types/index.js +0 -1
  118. package/dist/modules/jwt/enums/index.js +0 -11
  119. package/dist/modules/jwt/index.js +0 -51
  120. package/dist/modules/jwt/utils/index.js +0 -9
  121. package/dist/modules/kv-store/bun-redis/index.js +0 -84
  122. package/dist/modules/kv-store/enums/index.js +0 -7
  123. package/dist/modules/kv-store/ioredis/index.js +0 -86
  124. package/dist/modules/kv-store/memory/index.js +0 -9
  125. package/dist/modules/kv-store/types/index.js +0 -1
  126. package/dist/modules/logger/enums/index.js +0 -7
  127. package/dist/modules/logger/events/index.js +0 -1
  128. package/dist/modules/logger/index.js +0 -208
  129. package/dist/modules/logger/sinks/index.js +0 -66
  130. package/dist/modules/logger/types/index.js +0 -1
  131. package/dist/modules/mailer/enums/index.js +0 -7
  132. package/dist/modules/mailer/index.js +0 -55
  133. package/dist/modules/mailer/types/index.js +0 -1
  134. package/dist/modules/repository/index.js +0 -12
  135. package/dist/modules/repository/types/index.js +0 -1
  136. package/dist/modules/singleton-manager/enums/index.js +0 -7
  137. package/dist/modules/singleton-manager/index.js +0 -9
  138. package/dist/modules/totp/enums/index.js +0 -7
  139. package/dist/modules/totp/index.js +0 -104
  140. package/dist/modules/totp/types/index.js +0 -1
  141. package/dist/modules/totp/utils/index.js +0 -76
  142. package/dist/modules/typed-event-emitter/index.js +0 -7
  143. package/dist/modules/typed-event-emitter/types/index.js +0 -1
  144. package/dist/shared/enums/index.js +0 -7
  145. package/dist/shared/types/index.js +0 -1
  146. package/dist/shared/utils/index.js +0 -30
@@ -1,208 +0,0 @@
1
- // @bun
2
- import {
3
- LOGGER_ERROR_KEYS
4
- } from "../../chunk-rz5p4j3p.js";
5
- import {
6
- TypedEventEmitter
7
- } from "../../chunk-mvrxngm7.js";
8
- import {
9
- BaseError
10
- } from "../../chunk-9cgzhc50.js";
11
-
12
- // source/modules/logger/logger.ts
13
- class Logger extends TypedEventEmitter {
14
- _sinks;
15
- _sinkKeys = [];
16
- _worker;
17
- _maxPendingLogs;
18
- _maxMessagesInFlight;
19
- _batchSize;
20
- _batchTimeout;
21
- _autoEnd;
22
- _flushOnBeforeExit;
23
- _pendingLogs = [];
24
- _messagesInFlight = 0;
25
- _batchTimer = null;
26
- _isWriting = false;
27
- _flushResolvers = [];
28
- _closeResolver = null;
29
- _backpressureResolver = null;
30
- _handleExit = () => {
31
- this._worker.terminate();
32
- };
33
- _handleWorkerClose = () => {
34
- process.off("beforeExit", this._handleBeforeExit);
35
- process.off("exit", this._handleExit);
36
- };
37
- constructor(options) {
38
- super();
39
- const {
40
- autoEnd = true,
41
- batchSize = 50,
42
- batchTimeout = 0.1,
43
- flushOnBeforeExit = true,
44
- maxMessagesInFlight = 100,
45
- maxPendingLogs = 1e4
46
- } = options ?? {};
47
- this._sinks = {};
48
- this._maxPendingLogs = maxPendingLogs;
49
- this._maxMessagesInFlight = maxMessagesInFlight;
50
- this._batchSize = batchSize;
51
- this._batchTimeout = batchTimeout;
52
- this._autoEnd = autoEnd;
53
- this._flushOnBeforeExit = flushOnBeforeExit;
54
- this._worker = new Worker(new URL("worker-logger.ts", import.meta.url).href, { type: "module" });
55
- this._setupWorkerMessages();
56
- if (this._autoEnd)
57
- this._setupAutoEnd();
58
- }
59
- registerSink(sinkName, sinkConstructor, ...sinkArgs) {
60
- if (this._sinks[sinkName])
61
- throw new BaseError(LOGGER_ERROR_KEYS.SINK_ALREADY_ADDED);
62
- this._worker.postMessage({
63
- type: "REGISTER_SINK",
64
- sinkName,
65
- sinkClassName: sinkConstructor.name,
66
- sinkClassString: sinkConstructor.toString(),
67
- sinkArgs
68
- });
69
- this._sinks[sinkName] = sinkConstructor;
70
- this._sinkKeys.push(sinkName);
71
- return this;
72
- }
73
- error(object, sinkNames = this._sinkKeys) {
74
- this._enqueue("ERROR", object, sinkNames);
75
- }
76
- warn(object, sinkNames = this._sinkKeys) {
77
- this._enqueue("WARN", object, sinkNames);
78
- }
79
- info(object, sinkNames = this._sinkKeys) {
80
- this._enqueue("INFO", object, sinkNames);
81
- }
82
- debug(object, sinkNames = this._sinkKeys) {
83
- this._enqueue("DEBUG", object, sinkNames);
84
- }
85
- log(object, sinkNames = this._sinkKeys) {
86
- this._enqueue("LOG", object, sinkNames);
87
- }
88
- async flush() {
89
- if (this._pendingLogs.length === 0 && this._messagesInFlight === 0)
90
- return;
91
- return new Promise((resolve) => {
92
- this._flushResolvers.push(resolve);
93
- if (!this._isWriting && this._pendingLogs.length > 0) {
94
- this._isWriting = true;
95
- this._processPendingLogs();
96
- }
97
- });
98
- }
99
- async close() {
100
- await this.flush();
101
- return new Promise((resolve) => {
102
- this._closeResolver = resolve;
103
- this._worker.postMessage({ type: "CLOSE" });
104
- });
105
- }
106
- _enqueue(level, object, sinkNames) {
107
- if (this._sinkKeys.length === 0)
108
- throw new BaseError(LOGGER_ERROR_KEYS.NO_SINKS_PROVIDED, { level, object });
109
- if (this._pendingLogs.length >= this._maxPendingLogs)
110
- return;
111
- this._pendingLogs.push({
112
- sinkNames: sinkNames ?? this._sinkKeys,
113
- level,
114
- timestamp: Date.now(),
115
- object
116
- });
117
- if (this._pendingLogs.length >= this._batchSize) {
118
- if (this._batchTimer !== null) {
119
- clearTimeout(this._batchTimer);
120
- this._batchTimer = null;
121
- }
122
- this._triggerProcessing();
123
- } else if (this._batchTimeout > 0 && this._batchTimer === null) {
124
- this._batchTimer = setTimeout(() => {
125
- this._batchTimer = null;
126
- this._triggerProcessing();
127
- }, this._batchTimeout);
128
- }
129
- }
130
- _triggerProcessing() {
131
- if (this._isWriting)
132
- return;
133
- this._isWriting = true;
134
- this._processPendingLogs();
135
- }
136
- async _processPendingLogs() {
137
- while (this._pendingLogs.length > 0) {
138
- if (this._messagesInFlight >= this._maxMessagesInFlight)
139
- await new Promise((resolve) => {
140
- this._backpressureResolver = resolve;
141
- });
142
- const batch = this._pendingLogs.splice(0, this._batchSize);
143
- this._messagesInFlight++;
144
- this._worker.postMessage({
145
- type: "LOG_BATCH",
146
- logs: batch
147
- });
148
- }
149
- this._isWriting = false;
150
- this.emit("drained");
151
- }
152
- _releaseBatch() {
153
- this._messagesInFlight--;
154
- if (this._backpressureResolver !== null) {
155
- this._backpressureResolver();
156
- this._backpressureResolver = null;
157
- }
158
- }
159
- _setupWorkerMessages() {
160
- this._worker.addEventListener("message", (event) => {
161
- switch (event.data.type) {
162
- case "BATCH_COMPLETE":
163
- this._releaseBatch();
164
- if (this._messagesInFlight === 0 && this._pendingLogs.length === 0 && this._flushResolvers.length > 0) {
165
- for (const resolve of this._flushResolvers)
166
- resolve();
167
- this._flushResolvers.length = 0;
168
- }
169
- break;
170
- case "SINK_LOG_ERROR":
171
- this.emit("sinkError", new BaseError(LOGGER_ERROR_KEYS.SINK_LOG_ERROR, event.data));
172
- this._releaseBatch();
173
- break;
174
- case "SINK_CLOSE_ERROR":
175
- this.emit("sinkError", new BaseError(LOGGER_ERROR_KEYS.SINK_CLOSE_ERROR, event.data));
176
- break;
177
- case "REGISTER_SINK_ERROR":
178
- this.emit("registerSinkError", new BaseError(LOGGER_ERROR_KEYS.REGISTER_SINK_ERROR, event.data));
179
- break;
180
- case "CLOSE_COMPLETE":
181
- this._worker.terminate();
182
- if (this._closeResolver) {
183
- this._closeResolver();
184
- this._closeResolver = null;
185
- }
186
- break;
187
- }
188
- });
189
- }
190
- _setupAutoEnd() {
191
- process.on("beforeExit", this._handleBeforeExit);
192
- process.on("exit", this._handleExit);
193
- this._worker.addEventListener("close", this._handleWorkerClose);
194
- }
195
- _handleBeforeExit = () => {
196
- if (this._flushOnBeforeExit)
197
- this.flush().then(() => this.close()).catch((error) => {
198
- this.emit("onBeforeExitError", new BaseError(LOGGER_ERROR_KEYS.BEFORE_EXIT_FLUSH_ERROR, { error }));
199
- });
200
- else
201
- this.close().catch((error) => {
202
- this.emit("onBeforeExitError", new BaseError(LOGGER_ERROR_KEYS.BEFORE_EXIT_CLOSE_ERROR, { error }));
203
- });
204
- };
205
- }
206
- export {
207
- Logger
208
- };
@@ -1,66 +0,0 @@
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
- };
@@ -1 +0,0 @@
1
- // @bun
@@ -1,7 +0,0 @@
1
- // @bun
2
- import {
3
- MAILER_ERROR_KEYS
4
- } from "../../../chunk-6w9ja96e.js";
5
- export {
6
- MAILER_ERROR_KEYS
7
- };
@@ -1,55 +0,0 @@
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
- };
@@ -1 +0,0 @@
1
- // @bun
@@ -1,12 +0,0 @@
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 +0,0 @@
1
- // @bun
@@ -1,7 +0,0 @@
1
- // @bun
2
- import {
3
- SINGLETON_MANAGER_ERROR_KEYS
4
- } from "../../../chunk-z0ct35ft.js";
5
- export {
6
- SINGLETON_MANAGER_ERROR_KEYS
7
- };
@@ -1,9 +0,0 @@
1
- // @bun
2
- import {
3
- SingletonManager
4
- } from "../../chunk-fs3wm3p4.js";
5
- import"../../chunk-z0ct35ft.js";
6
- import"../../chunk-9cgzhc50.js";
7
- export {
8
- SingletonManager
9
- };
@@ -1,7 +0,0 @@
1
- // @bun
2
- import {
3
- TOTP_ERROR_KEYS
4
- } from "../../../chunk-9r5anep5.js";
5
- export {
6
- TOTP_ERROR_KEYS
7
- };
@@ -1,104 +0,0 @@
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
- };
@@ -1 +0,0 @@
1
- // @bun
@@ -1,76 +0,0 @@
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
- };
@@ -1,7 +0,0 @@
1
- // @bun
2
- import {
3
- TypedEventEmitter
4
- } from "../../chunk-mvrxngm7.js";
5
- export {
6
- TypedEventEmitter
7
- };
@@ -1 +0,0 @@
1
- // @bun
@@ -1,7 +0,0 @@
1
- // @bun
2
- import {
3
- UTILS_ERROR_KEYS
4
- } from "../../chunk-n0n14mf8.js";
5
- export {
6
- UTILS_ERROR_KEYS
7
- };
@@ -1 +0,0 @@
1
- // @bun
@@ -1,30 +0,0 @@
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
- };