@venizia/ignis-helpers 0.4.6 → 0.4.7-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/LICENSE.md +1 -3
- package/README.md +4 -5
- package/dist/esm/common/redact.d.ts +25 -17
- package/dist/esm/common/redact.d.ts.map +1 -1
- package/dist/esm/common/redact.js +50 -46
- package/dist/esm/common/redact.js.map +1 -1
- package/dist/esm/common/resolvers.d.ts +7 -5
- package/dist/esm/common/resolvers.d.ts.map +1 -1
- package/dist/esm/common/resolvers.js +11 -9
- package/dist/esm/common/resolvers.js.map +1 -1
- package/dist/esm/core.d.ts +6 -3
- package/dist/esm/core.d.ts.map +1 -1
- package/dist/esm/core.js +6 -3
- package/dist/esm/core.js.map +1 -1
- package/dist/esm/modules/base.js +4 -4
- package/dist/esm/modules/base.js.map +1 -1
- package/dist/esm/modules/cron/helper.js +4 -4
- package/dist/esm/modules/cron/helper.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js +3 -3
- package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.js +5 -5
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/base.algorithm.js +3 -3
- package/dist/esm/modules/crypto/algorithms/base.algorithm.js.map +1 -1
- package/dist/esm/modules/env/app-env.d.ts.map +1 -1
- package/dist/esm/modules/env/app-env.js +2 -2
- package/dist/esm/modules/env/app-env.js.map +1 -1
- package/dist/esm/modules/logger/common/constants.d.ts +23 -21
- package/dist/esm/modules/logger/common/constants.d.ts.map +1 -1
- package/dist/esm/modules/logger/common/constants.js +45 -42
- package/dist/esm/modules/logger/common/constants.js.map +1 -1
- package/dist/esm/modules/logger/factory.d.ts +5 -3
- package/dist/esm/modules/logger/factory.d.ts.map +1 -1
- package/dist/esm/modules/logger/factory.js +5 -3
- package/dist/esm/modules/logger/factory.js.map +1 -1
- package/dist/esm/modules/logger/formatting/deep-splat.d.ts +10 -6
- package/dist/esm/modules/logger/formatting/deep-splat.d.ts.map +1 -1
- package/dist/esm/modules/logger/formatting/deep-splat.js +73 -62
- package/dist/esm/modules/logger/formatting/deep-splat.js.map +1 -1
- package/dist/esm/modules/logger/formatting/error-prettier.d.ts.map +1 -1
- package/dist/esm/modules/logger/formatting/error-prettier.js +8 -6
- package/dist/esm/modules/logger/formatting/error-prettier.js.map +1 -1
- package/dist/esm/modules/logger/hf/logger.d.ts.map +1 -1
- package/dist/esm/modules/logger/hf/logger.js +2 -2
- package/dist/esm/modules/logger/hf/logger.js.map +1 -1
- package/dist/esm/modules/logger/pino/backing.d.ts +0 -9
- package/dist/esm/modules/logger/pino/backing.d.ts.map +1 -1
- package/dist/esm/modules/logger/pino/backing.js +3 -8
- package/dist/esm/modules/logger/pino/backing.js.map +1 -1
- package/dist/esm/modules/logger/pino/destination.d.ts +6 -9
- package/dist/esm/modules/logger/pino/destination.d.ts.map +1 -1
- package/dist/esm/modules/logger/pino/destination.js +12 -13
- package/dist/esm/modules/logger/pino/destination.js.map +1 -1
- package/dist/esm/modules/logger/pino/logger.js +2 -2
- package/dist/esm/modules/logger/pino/logger.js.map +1 -1
- package/dist/esm/modules/logger/resolver.js +2 -2
- package/dist/esm/modules/logger/resolver.js.map +1 -1
- package/dist/esm/modules/logger/slot.d.ts +39 -18
- package/dist/esm/modules/logger/slot.d.ts.map +1 -1
- package/dist/esm/modules/logger/slot.js +117 -110
- package/dist/esm/modules/logger/slot.js.map +1 -1
- package/dist/esm/modules/logger/winston/common/constants.d.ts.map +1 -1
- package/dist/esm/modules/logger/winston/common/constants.js +7 -6
- package/dist/esm/modules/logger/winston/common/constants.js.map +1 -1
- package/dist/esm/modules/logger/winston/define.d.ts +0 -7
- package/dist/esm/modules/logger/winston/define.d.ts.map +1 -1
- package/dist/esm/modules/logger/winston/define.js +0 -5
- package/dist/esm/modules/logger/winston/define.js.map +1 -1
- package/dist/esm/modules/logger/winston/formats.d.ts +2 -0
- package/dist/esm/modules/logger/winston/formats.d.ts.map +1 -1
- package/dist/esm/modules/logger/winston/formats.js +17 -4
- package/dist/esm/modules/logger/winston/formats.js.map +1 -1
- package/dist/esm/modules/logger/winston/index.d.ts +3 -2
- package/dist/esm/modules/logger/winston/index.d.ts.map +1 -1
- package/dist/esm/modules/logger/winston/index.js +3 -2
- package/dist/esm/modules/logger/winston/index.js.map +1 -1
- package/dist/esm/modules/logger/winston/logger-factory.js +4 -4
- package/dist/esm/modules/logger/winston/logger-factory.js.map +1 -1
- package/dist/esm/modules/network/http-request/base-network-request.helper.js +2 -2
- package/dist/esm/modules/network/http-request/base-network-request.helper.js.map +1 -1
- package/dist/esm/modules/network/http-request/common/index.d.ts +0 -1
- package/dist/esm/modules/network/http-request/common/index.d.ts.map +1 -1
- package/dist/esm/modules/network/http-request/common/index.js +0 -1
- package/dist/esm/modules/network/http-request/common/index.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.d.ts.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js +4 -2
- package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts.map +1 -1
- package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js +6 -4
- package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js.map +1 -1
- package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js +4 -4
- package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js.map +1 -1
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +4 -4
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
- package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js +2 -2
- package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js.map +1 -1
- package/dist/esm/modules/network/utilities/query-string.d.ts +22 -20
- package/dist/esm/modules/network/utilities/query-string.d.ts.map +1 -1
- package/dist/esm/modules/network/utilities/query-string.js +48 -46
- package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts +0 -10
- package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/common/errors.js +0 -11
- package/dist/esm/modules/network/utilities/url-safety/common/errors.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/ingest.d.ts.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/ingest.js +2 -1
- package/dist/esm/modules/network/utilities/url-safety/ingest.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/policy.d.ts +10 -0
- package/dist/esm/modules/network/utilities/url-safety/policy.d.ts.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/policy.js +11 -0
- package/dist/esm/modules/network/utilities/url-safety/policy.js.map +1 -1
- package/dist/esm/modules/pool/abstract.d.ts.map +1 -1
- package/dist/esm/modules/pool/abstract.js +4 -2
- package/dist/esm/modules/pool/abstract.js.map +1 -1
- package/dist/esm/modules/queue/bullmq/helper.d.ts.map +1 -1
- package/dist/esm/modules/queue/bullmq/helper.js +6 -6
- package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
- package/dist/esm/modules/queue/common/hook.d.ts +14 -12
- package/dist/esm/modules/queue/common/hook.d.ts.map +1 -1
- package/dist/esm/modules/queue/common/hook.js +21 -19
- package/dist/esm/modules/queue/common/hook.js.map +1 -1
- package/dist/esm/modules/queue/common/index.d.ts +0 -1
- package/dist/esm/modules/queue/common/index.d.ts.map +1 -1
- package/dist/esm/modules/queue/common/index.js +0 -1
- package/dist/esm/modules/queue/common/index.js.map +1 -1
- package/dist/esm/modules/queue/internal/sequential/helper.js +8 -8
- package/dist/esm/modules/queue/internal/sequential/helper.js.map +1 -1
- package/dist/esm/modules/queue/kafka/base.js +3 -3
- package/dist/esm/modules/queue/kafka/base.js.map +1 -1
- package/dist/esm/modules/queue/kafka/bundler/index.d.ts +0 -2
- package/dist/esm/modules/queue/kafka/bundler/index.d.ts.map +1 -1
- package/dist/esm/modules/queue/kafka/bundler/index.js +0 -2
- package/dist/esm/modules/queue/kafka/bundler/index.js.map +1 -1
- package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts +8 -2
- package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts.map +1 -1
- package/dist/esm/modules/queue/kafka/bundler/plugins.js +64 -7
- package/dist/esm/modules/queue/kafka/bundler/plugins.js.map +1 -1
- package/dist/esm/modules/queue/kafka/consumer.d.ts.map +1 -1
- package/dist/esm/modules/queue/kafka/consumer.js +26 -24
- package/dist/esm/modules/queue/kafka/consumer.js.map +1 -1
- package/dist/esm/modules/queue/mqtt/helper.js +10 -10
- package/dist/esm/modules/queue/mqtt/helper.js.map +1 -1
- package/dist/esm/modules/redis/base/abstract.helper.js +8 -8
- package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
- package/dist/esm/modules/redis/cluster/cluster.helper.js +2 -2
- package/dist/esm/modules/redis/cluster/cluster.helper.js.map +1 -1
- package/dist/esm/modules/redis/factory.d.ts +13 -9
- package/dist/esm/modules/redis/factory.d.ts.map +1 -1
- package/dist/esm/modules/redis/factory.js +15 -13
- package/dist/esm/modules/redis/factory.js.map +1 -1
- package/dist/esm/modules/redis/sentinel/sentinel.helper.js +2 -2
- package/dist/esm/modules/redis/sentinel/sentinel.helper.js.map +1 -1
- package/dist/esm/modules/redis/single/single.helper.js +2 -2
- package/dist/esm/modules/redis/single/single.helper.js.map +1 -1
- package/dist/esm/modules/redis/utility.d.ts +13 -11
- package/dist/esm/modules/redis/utility.d.ts.map +1 -1
- package/dist/esm/modules/redis/utility.js +46 -44
- package/dist/esm/modules/redis/utility.js.map +1 -1
- package/dist/esm/modules/retry/helper.d.ts.map +1 -1
- package/dist/esm/modules/retry/helper.js +6 -4
- package/dist/esm/modules/retry/helper.js.map +1 -1
- package/dist/esm/modules/secrets/factory.d.ts +5 -3
- package/dist/esm/modules/secrets/factory.d.ts.map +1 -1
- package/dist/esm/modules/secrets/factory.js +36 -34
- package/dist/esm/modules/secrets/factory.js.map +1 -1
- package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.d.ts.map +1 -1
- package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js +4 -2
- package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js.map +1 -1
- package/dist/esm/modules/socket/socket-io/server/helper.d.ts.map +1 -1
- package/dist/esm/modules/socket/socket-io/server/helper.js +11 -11
- package/dist/esm/modules/socket/socket-io/server/helper.js.map +1 -1
- package/dist/esm/modules/socket/websocket/emitter/helper.d.ts.map +1 -1
- package/dist/esm/modules/socket/websocket/emitter/helper.js +3 -3
- package/dist/esm/modules/socket/websocket/emitter/helper.js.map +1 -1
- package/dist/esm/modules/socket/websocket/server/delivery.d.ts.map +1 -1
- package/dist/esm/modules/socket/websocket/server/delivery.js +5 -6
- package/dist/esm/modules/socket/websocket/server/delivery.js.map +1 -1
- package/dist/esm/modules/socket/websocket/server/helper.d.ts.map +1 -1
- package/dist/esm/modules/socket/websocket/server/helper.js +7 -7
- package/dist/esm/modules/socket/websocket/server/helper.js.map +1 -1
- package/dist/esm/modules/storage/base.d.ts.map +1 -1
- package/dist/esm/modules/storage/base.js +9 -8
- package/dist/esm/modules/storage/base.js.map +1 -1
- package/dist/esm/modules/storage/bun-s3/helper.d.ts.map +1 -1
- package/dist/esm/modules/storage/bun-s3/helper.js +25 -18
- package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
- package/dist/esm/modules/storage/bun-s3/utility.d.ts +95 -77
- package/dist/esm/modules/storage/bun-s3/utility.d.ts.map +1 -1
- package/dist/esm/modules/storage/bun-s3/utility.js +261 -244
- package/dist/esm/modules/storage/bun-s3/utility.js.map +1 -1
- package/dist/esm/modules/storage/common/errors.d.ts +0 -4
- package/dist/esm/modules/storage/common/errors.d.ts.map +1 -1
- package/dist/esm/modules/storage/common/errors.js +0 -10
- package/dist/esm/modules/storage/common/errors.js.map +1 -1
- package/dist/esm/modules/storage/common/utility.d.ts +11 -5
- package/dist/esm/modules/storage/common/utility.d.ts.map +1 -1
- package/dist/esm/modules/storage/common/utility.js +30 -17
- package/dist/esm/modules/storage/common/utility.js.map +1 -1
- package/dist/esm/modules/storage/disk/helper.d.ts.map +1 -1
- package/dist/esm/modules/storage/disk/helper.js +18 -9
- package/dist/esm/modules/storage/disk/helper.js.map +1 -1
- package/dist/esm/modules/tree/builder.d.ts.map +1 -1
- package/dist/esm/modules/tree/builder.js +2 -1
- package/dist/esm/modules/tree/builder.js.map +1 -1
- package/dist/esm/modules/uid/opaque.d.ts.map +1 -1
- package/dist/esm/modules/uid/opaque.js +4 -2
- package/dist/esm/modules/uid/opaque.js.map +1 -1
- package/dist/esm/modules/uid/uuid/helper.d.ts +1 -1
- package/dist/esm/modules/uid/uuid/helper.d.ts.map +1 -1
- package/dist/esm/modules/uid/uuid/helper.js +7 -7
- package/dist/esm/modules/uid/uuid/helper.js.map +1 -1
- package/dist/esm/modules/uid/uuid/v4.d.ts +11 -8
- package/dist/esm/modules/uid/uuid/v4.d.ts.map +1 -1
- package/dist/esm/modules/uid/uuid/v4.js +51 -46
- package/dist/esm/modules/uid/uuid/v4.js.map +1 -1
- package/dist/esm/modules/uid/uuid/v5.d.ts +17 -14
- package/dist/esm/modules/uid/uuid/v5.d.ts.map +1 -1
- package/dist/esm/modules/uid/uuid/v5.js +83 -78
- package/dist/esm/modules/uid/uuid/v5.js.map +1 -1
- package/dist/esm/modules/uid/uuid/v7.d.ts +15 -10
- package/dist/esm/modules/uid/uuid/v7.d.ts.map +1 -1
- package/dist/esm/modules/uid/uuid/v7.js +88 -79
- package/dist/esm/modules/uid/uuid/v7.js.map +1 -1
- package/dist/esm/modules/worker-thread/bus/base.js +2 -2
- package/dist/esm/modules/worker-thread/bus/base.js.map +1 -1
- package/dist/esm/modules/worker-thread/worker/base.d.ts.map +1 -1
- package/dist/esm/modules/worker-thread/worker/base.js +4 -3
- package/dist/esm/modules/worker-thread/worker/base.js.map +1 -1
- package/dist/esm/utilities/error.utility.d.ts +7 -0
- package/dist/esm/utilities/error.utility.d.ts.map +1 -0
- package/dist/esm/utilities/error.utility.js +9 -0
- package/dist/esm/utilities/error.utility.js.map +1 -0
- package/dist/esm/utilities/form-body.utility.d.ts +12 -10
- package/dist/esm/utilities/form-body.utility.d.ts.map +1 -1
- package/dist/esm/utilities/form-body.utility.js +19 -16
- package/dist/esm/utilities/form-body.utility.js.map +1 -1
- package/dist/esm/utilities/hr-time.utility.d.ts +7 -5
- package/dist/esm/utilities/hr-time.utility.d.ts.map +1 -1
- package/dist/esm/utilities/hr-time.utility.js +11 -9
- package/dist/esm/utilities/hr-time.utility.js.map +1 -1
- package/dist/esm/utilities/index.d.ts +2 -2
- package/dist/esm/utilities/index.d.ts.map +1 -1
- package/dist/esm/utilities/index.js +2 -2
- package/dist/esm/utilities/index.js.map +1 -1
- package/dist/esm/utilities/module.utility.d.ts.map +1 -1
- package/dist/esm/utilities/module.utility.js +4 -2
- package/dist/esm/utilities/module.utility.js.map +1 -1
- package/dist/esm/utilities/parse.utility.d.ts +89 -43
- package/dist/esm/utilities/parse.utility.d.ts.map +1 -1
- package/dist/esm/utilities/parse.utility.js +173 -141
- package/dist/esm/utilities/parse.utility.js.map +1 -1
- package/dist/esm/utilities/performance.utility.d.ts +15 -13
- package/dist/esm/utilities/performance.utility.d.ts.map +1 -1
- package/dist/esm/utilities/performance.utility.js +34 -29
- package/dist/esm/utilities/performance.utility.js.map +1 -1
- package/dist/esm/utilities/promise.utility.d.ts +20 -18
- package/dist/esm/utilities/promise.utility.d.ts.map +1 -1
- package/dist/esm/utilities/promise.utility.js +41 -51
- package/dist/esm/utilities/promise.utility.js.map +1 -1
- package/dist/esm/utilities/request.utility.d.ts +35 -29
- package/dist/esm/utilities/request.utility.d.ts.map +1 -1
- package/dist/esm/utilities/request.utility.js +117 -115
- package/dist/esm/utilities/request.utility.js.map +1 -1
- package/package.json +4 -15
- package/dist/esm/modules/logger/winston/formatters/deep-splat.d.ts +0 -4
- package/dist/esm/modules/logger/winston/formatters/deep-splat.d.ts.map +0 -1
- package/dist/esm/modules/logger/winston/formatters/deep-splat.js +0 -14
- package/dist/esm/modules/logger/winston/formatters/deep-splat.js.map +0 -1
- package/dist/esm/modules/logger/winston/formatters/index.d.ts +0 -2
- package/dist/esm/modules/logger/winston/formatters/index.d.ts.map +0 -1
- package/dist/esm/modules/logger/winston/formatters/index.js +0 -2
- package/dist/esm/modules/logger/winston/formatters/index.js.map +0 -1
- package/dist/esm/modules/network/http-request/common/types.d.ts +0 -2
- package/dist/esm/modules/network/http-request/common/types.d.ts.map +0 -1
- package/dist/esm/modules/network/http-request/common/types.js +0 -2
- package/dist/esm/modules/network/http-request/common/types.js.map +0 -1
- package/dist/esm/modules/queue/common/types.d.ts +0 -2
- package/dist/esm/modules/queue/common/types.d.ts.map +0 -1
- package/dist/esm/modules/queue/common/types.js +0 -2
- package/dist/esm/modules/queue/common/types.js.map +0 -1
- package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.d.ts +0 -4
- package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.d.ts.map +0 -1
- package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js +0 -28
- package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js.map +0 -1
- package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.d.ts +0 -4
- package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.d.ts.map +0 -1
- package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js +0 -26
- package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js.map +0 -1
- package/dist/esm/modules/storage/minio/helper.d.ts +0 -55
- package/dist/esm/modules/storage/minio/helper.d.ts.map +0 -1
- package/dist/esm/modules/storage/minio/helper.js +0 -176
- package/dist/esm/modules/storage/minio/helper.js.map +0 -1
- package/dist/esm/modules/storage/minio/index.d.ts +0 -2
- package/dist/esm/modules/storage/minio/index.d.ts.map +0 -1
- package/dist/esm/modules/storage/minio/index.js +0 -2
- package/dist/esm/modules/storage/minio/index.js.map +0 -1
- package/dist/esm/utilities/sleep.utility.d.ts +0 -2
- package/dist/esm/utilities/sleep.utility.d.ts.map +0 -1
- package/dist/esm/utilities/sleep.utility.js +0 -4
- package/dist/esm/utilities/sleep.utility.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getError } from '../modules/error/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { FormBodyUtility } from './form-body.utility.js';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
/** Where `parseMultipartBody` keeps an uploaded file: MEMORY (a buffer) or DISK (spooled to `uploadDir`). */
|
|
5
|
+
/** Where `RequestUtility.parseMultipartBody` keeps an uploaded file: MEMORY (a buffer) or DISK (spooled to `uploadDir`). */
|
|
6
6
|
export class MultipartStorages {
|
|
7
7
|
static { this.MEMORY = 'memory'; }
|
|
8
8
|
static { this.DISK = 'disk'; }
|
|
@@ -11,77 +11,8 @@ export class MultipartStorages {
|
|
|
11
11
|
return this.SCHEME_SET.has(value);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
export const parseMultipartBody = async (opts) => {
|
|
15
|
-
const { storage = MultipartStorages.MEMORY, uploadDir = './uploads', context } = opts;
|
|
16
|
-
if (storage === MultipartStorages.DISK && !fs.existsSync(uploadDir)) {
|
|
17
|
-
fs.mkdirSync(uploadDir, { recursive: true });
|
|
18
|
-
}
|
|
19
|
-
const formData = await readFormBody({ req: context.req });
|
|
20
|
-
const files = [];
|
|
21
|
-
const fields = {};
|
|
22
|
-
const entries = formData.entries();
|
|
23
|
-
for (const [fieldname, value] of entries) {
|
|
24
|
-
if (typeof value === 'string') {
|
|
25
|
-
// Last one wins, like a repeated query parameter.
|
|
26
|
-
fields[fieldname] = value;
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
const file = value;
|
|
30
|
-
const arrayBuffer = await file.arrayBuffer();
|
|
31
|
-
const buffer = Buffer.from(arrayBuffer);
|
|
32
|
-
const parsedFile = {
|
|
33
|
-
fieldname,
|
|
34
|
-
originalname: file.name,
|
|
35
|
-
encoding: 'utf8',
|
|
36
|
-
mimetype: file.type,
|
|
37
|
-
size: file.size,
|
|
38
|
-
};
|
|
39
|
-
switch (storage) {
|
|
40
|
-
case MultipartStorages.MEMORY: {
|
|
41
|
-
parsedFile.buffer = buffer;
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
case MultipartStorages.DISK: {
|
|
45
|
-
const timestamp = Date.now();
|
|
46
|
-
const randomString = Math.random().toString(36).substring(7);
|
|
47
|
-
// Sanitize filename to prevent path traversal
|
|
48
|
-
const sanitizedName = path.basename(file.name).replace(/[^a-zA-Z0-9._-]/g, '_');
|
|
49
|
-
const filename = `${timestamp}-${randomString}-${sanitizedName}`;
|
|
50
|
-
const filepath = path.join(uploadDir, filename);
|
|
51
|
-
fs.writeFileSync(filepath, buffer);
|
|
52
|
-
parsedFile.filename = filename;
|
|
53
|
-
parsedFile.path = filepath;
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
default: {
|
|
57
|
-
throw getError({
|
|
58
|
-
message: `[parseMultipartBody] storage: ${storage} | Invalid storage type | Valids: ['memory', 'disk']`,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
files.push(parsedFile);
|
|
63
|
-
}
|
|
64
|
-
return { files, fields };
|
|
65
|
-
};
|
|
66
|
-
/** Sanitizes a filename by removing path components and dangerous characters. The result is printable ASCII. */
|
|
67
|
-
export const sanitizeFilename = (filename) => {
|
|
68
|
-
const basename = path.basename(filename);
|
|
69
|
-
let sanitized = basename.replace(/[^\w .-]/g, '_');
|
|
70
|
-
sanitized = sanitized.replace(/^\.+/, '');
|
|
71
|
-
sanitized = sanitized.replace(/\.{2,}/g, '.');
|
|
72
|
-
sanitized = sanitized.replace(/\.\./g, '.');
|
|
73
|
-
if (!sanitized || sanitized === '.' || sanitized.includes('..')) {
|
|
74
|
-
sanitized = 'download';
|
|
75
|
-
}
|
|
76
|
-
return sanitized;
|
|
77
|
-
};
|
|
78
|
-
export const encodeRFC5987 = (filename) => {
|
|
79
|
-
return encodeURIComponent(filename)
|
|
80
|
-
.replace(/['()]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase())
|
|
81
|
-
.replace(/\*/g, '%2A');
|
|
82
|
-
};
|
|
83
14
|
/** Control, format (bidi overrides, zero-width space) and lone surrogate characters: a format character reorders the name a client shows, a lone surrogate makes `encodeURIComponent` throw. The zero-width joiner and non-joiner stay: they build emoji sequences and Persian words, and reorder nothing. */
|
|
84
|
-
const UNENCODABLE_FILENAME_CHARACTERS = /(?![
|
|
15
|
+
const UNENCODABLE_FILENAME_CHARACTERS = /(?![])[\p{Cc}\p{Cf}\p{Cs}]/gu;
|
|
85
16
|
const LEADING_DOTS = /^\.+/;
|
|
86
17
|
/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */
|
|
87
18
|
export class ContentDispositionTypes {
|
|
@@ -92,51 +23,122 @@ export class ContentDispositionTypes {
|
|
|
92
23
|
return this.SCHEME_SET.has(value);
|
|
93
24
|
}
|
|
94
25
|
}
|
|
95
|
-
export
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
.replace(UNENCODABLE_FILENAME_CHARACTERS, '_')
|
|
101
|
-
.replace(LEADING_DOTS, '');
|
|
102
|
-
const encoded = encodeRFC5987(extendedName || sanitized);
|
|
103
|
-
// filename= is the ASCII fallback for old browsers, filename*= the UTF-8 form for modern ones.
|
|
104
|
-
return `${type}; filename="${sanitized}"; filename*=UTF-8''${encoded}`;
|
|
105
|
-
};
|
|
106
|
-
/**
|
|
107
|
-
* Reads a filename out of a `Content-Disposition` value.
|
|
108
|
-
*
|
|
109
|
-
* Three forms, in the order the RFC gives them precedence: `filename*=UTF-8''...` (percent-encoded,
|
|
110
|
-
* and the one hand-rolled parsers miss), a quoted `filename="..."`, and a bare `filename=...`.
|
|
111
|
-
* Splitting on `filename=` alone returns the percent-encoded bytes for any non-ASCII name, which in
|
|
112
|
-
* a product with non-English filenames is most of them.
|
|
113
|
-
*
|
|
114
|
-
* The pair of {@link createContentDispositionHeader}: one writes the header, this one reads it.
|
|
115
|
-
*/
|
|
116
|
-
export const parseContentDisposition = (opts) => {
|
|
117
|
-
const { header } = opts;
|
|
118
|
-
if (!header) {
|
|
119
|
-
return {};
|
|
120
|
-
}
|
|
121
|
-
const type = header.split(';')[0]?.trim() || undefined;
|
|
122
|
-
// `filename*` wins when both are present - it is the one that can carry a non-ASCII name.
|
|
123
|
-
const extended = header.match(/filename\*\s*=\s*([^;]+)/i);
|
|
124
|
-
if (extended) {
|
|
125
|
-
const value = extended[1].trim();
|
|
126
|
-
// `UTF-8''name` or `UTF-8'lang'name`; anything before the last quote is charset and language.
|
|
127
|
-
const encoded = value.slice(value.lastIndexOf("'") + 1);
|
|
128
|
-
try {
|
|
129
|
-
return { type, filename: decodeURIComponent(encoded) };
|
|
26
|
+
export class RequestUtility {
|
|
27
|
+
static async parseMultipartBody(opts) {
|
|
28
|
+
const { storage = MultipartStorages.MEMORY, uploadDir = './uploads', context } = opts;
|
|
29
|
+
if (storage === MultipartStorages.DISK && !fs.existsSync(uploadDir)) {
|
|
30
|
+
fs.mkdirSync(uploadDir, { recursive: true });
|
|
130
31
|
}
|
|
131
|
-
|
|
132
|
-
|
|
32
|
+
const formData = await FormBodyUtility.readFormBody({ req: context.req });
|
|
33
|
+
const files = [];
|
|
34
|
+
const fields = {};
|
|
35
|
+
const entries = formData.entries();
|
|
36
|
+
for (const [fieldname, value] of entries) {
|
|
37
|
+
if (typeof value === 'string') {
|
|
38
|
+
// Last one wins, like a repeated query parameter.
|
|
39
|
+
fields[fieldname] = value;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const file = value;
|
|
43
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
44
|
+
const buffer = Buffer.from(arrayBuffer);
|
|
45
|
+
const parsedFile = {
|
|
46
|
+
fieldname,
|
|
47
|
+
originalname: file.name,
|
|
48
|
+
encoding: 'utf8',
|
|
49
|
+
mimetype: file.type,
|
|
50
|
+
size: file.size,
|
|
51
|
+
};
|
|
52
|
+
switch (storage) {
|
|
53
|
+
case MultipartStorages.MEMORY: {
|
|
54
|
+
parsedFile.buffer = buffer;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case MultipartStorages.DISK: {
|
|
58
|
+
const timestamp = Date.now();
|
|
59
|
+
const randomString = Math.random().toString(36).substring(7);
|
|
60
|
+
// Sanitize filename to prevent path traversal
|
|
61
|
+
const sanitizedName = path.basename(file.name).replace(/[^a-zA-Z0-9._-]/g, '_');
|
|
62
|
+
const filename = `${timestamp}-${randomString}-${sanitizedName}`;
|
|
63
|
+
const filepath = path.join(uploadDir, filename);
|
|
64
|
+
fs.writeFileSync(filepath, buffer);
|
|
65
|
+
parsedFile.filename = filename;
|
|
66
|
+
parsedFile.path = filepath;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
default: {
|
|
70
|
+
throw getError({
|
|
71
|
+
message: `[parseMultipartBody] storage: ${storage} | Invalid storage type | Valids: ['memory', 'disk']`,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
files.push(parsedFile);
|
|
133
76
|
}
|
|
77
|
+
return { files, fields };
|
|
134
78
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
79
|
+
/** Sanitizes a filename by removing path components and dangerous characters. The result is printable ASCII. */
|
|
80
|
+
static sanitizeFilename(opts) {
|
|
81
|
+
const basename = path.basename(opts.filename);
|
|
82
|
+
let sanitized = basename.replace(/[^\w .-]/g, '_');
|
|
83
|
+
sanitized = sanitized.replace(/^\.+/, '');
|
|
84
|
+
sanitized = sanitized.replace(/\.{2,}/g, '.');
|
|
85
|
+
sanitized = sanitized.replace(/\.\./g, '.');
|
|
86
|
+
if (!sanitized || sanitized === '.' || sanitized.includes('..')) {
|
|
87
|
+
sanitized = 'download';
|
|
88
|
+
}
|
|
89
|
+
return sanitized;
|
|
90
|
+
}
|
|
91
|
+
static encodeRfc5987(opts) {
|
|
92
|
+
return encodeURIComponent(opts.filename)
|
|
93
|
+
.replace(/['()]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase())
|
|
94
|
+
.replace(/\*/g, '%2A');
|
|
95
|
+
}
|
|
96
|
+
static buildContentDispositionHeader(opts) {
|
|
97
|
+
const { filename, type } = opts;
|
|
98
|
+
const sanitized = RequestUtility.sanitizeFilename({ filename });
|
|
99
|
+
const extendedName = path
|
|
100
|
+
.basename(filename)
|
|
101
|
+
.replace(UNENCODABLE_FILENAME_CHARACTERS, '_')
|
|
102
|
+
.replace(LEADING_DOTS, '');
|
|
103
|
+
const encoded = RequestUtility.encodeRfc5987({ filename: extendedName || sanitized });
|
|
104
|
+
// filename= is the ASCII fallback for old browsers, filename*= the UTF-8 form for modern ones.
|
|
105
|
+
return `${type}; filename="${sanitized}"; filename*=UTF-8''${encoded}`;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Reads a filename out of a `Content-Disposition` value.
|
|
109
|
+
*
|
|
110
|
+
* Three forms, in the order the RFC gives them precedence: `filename*=UTF-8''...` (percent-encoded,
|
|
111
|
+
* and the one hand-rolled parsers miss), a quoted `filename="..."`, and a bare `filename=...`.
|
|
112
|
+
* Splitting on `filename=` alone returns the percent-encoded bytes for any non-ASCII name, which in
|
|
113
|
+
* a product with non-English filenames is most of them.
|
|
114
|
+
*
|
|
115
|
+
* The pair of {@link RequestUtility.buildContentDispositionHeader}: one writes the header, this one reads it.
|
|
116
|
+
*/
|
|
117
|
+
static parseContentDisposition(opts) {
|
|
118
|
+
const { header } = opts;
|
|
119
|
+
if (!header) {
|
|
120
|
+
return {};
|
|
121
|
+
}
|
|
122
|
+
const type = header.split(';')[0]?.trim() || undefined;
|
|
123
|
+
// `filename*` wins when both are present - it is the one that can carry a non-ASCII name.
|
|
124
|
+
const extended = header.match(/filename\*\s*=\s*([^;]+)/i);
|
|
125
|
+
if (extended) {
|
|
126
|
+
const value = extended[1].trim();
|
|
127
|
+
// `UTF-8''name` or `UTF-8'lang'name`; anything before the last quote is charset and language.
|
|
128
|
+
const encoded = value.slice(value.lastIndexOf("'") + 1);
|
|
129
|
+
try {
|
|
130
|
+
return { type, filename: decodeURIComponent(encoded) };
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// A malformed sequence is not worth failing a download over - fall through to `filename`.
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const quoted = header.match(/filename\s*=\s*"([^"]*)"/i);
|
|
137
|
+
if (quoted) {
|
|
138
|
+
return { type, filename: quoted[1] };
|
|
139
|
+
}
|
|
140
|
+
const bare = header.match(/filename\s*=\s*([^;]+)/i);
|
|
141
|
+
return { type, filename: bare ? bare[1].trim() : undefined };
|
|
138
142
|
}
|
|
139
|
-
|
|
140
|
-
return { type, filename: bare ? bare[1].trim() : undefined };
|
|
141
|
-
};
|
|
143
|
+
}
|
|
142
144
|
//# sourceMappingURL=request.utility.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.utility.js","sourceRoot":"","sources":["../../../src/utilities/request.utility.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAS7B,6GAA6G;AAC7G,MAAM,OAAO,iBAAiB;aACZ,WAAM,GAAG,QAAQ,CAAC;aAClB,SAAI,GAAG,MAAM,CAAC;aAEd,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,MAA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AAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QAExD,IAAI,CAAC;YACH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;QACzD,CAAC;QAAC,MAAM,CAAC;YACP,0FAA0F;QAC5F,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;IACzD,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACvC,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACrD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAC/D,CAAC,CAAC","sourcesContent":["import type { TConstValue } from '@/common/types';\nimport { getError } from '@/modules/error';\nimport { readFormBody } from './form-body.utility';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nexport interface IRequestedRemark {\n id: string;\n url: string;\n method: string;\n [extra: string | symbol]: any;\n}\n\n/** Where `parseMultipartBody` keeps an uploaded file: MEMORY (a buffer) or DISK (spooled to `uploadDir`). */\nexport class MultipartStorages {\n static readonly MEMORY = 'memory';\n static readonly DISK = 'disk';\n\n static readonly SCHEME_SET = new Set<string>([this.MEMORY, this.DISK]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid multipart storage values. */\nexport type TMultipartStorage = TConstValue<typeof MultipartStorages>;\n\ninterface IParseMultipartOptions<C extends { req: any } = { req: any }> {\n storage?: TMultipartStorage;\n uploadDir?: string;\n context: C;\n}\n\ninterface IParsedFile {\n fieldname: string;\n originalname: string;\n encoding: string;\n mimetype: string;\n size: number;\n buffer?: Buffer;\n filename?: string;\n path?: string;\n}\n\n/** Files and the text fields posted beside them - dropping the second silently loses what the client sent. */\nexport interface IParsedMultipartBody {\n files: IParsedFile[];\n fields: Record<string, string>;\n}\n\nexport const parseMultipartBody = async <C extends { req: any } = { req: any }>(\n opts: IParseMultipartOptions<C>,\n): Promise<IParsedMultipartBody> => {\n const { storage = MultipartStorages.MEMORY, uploadDir = './uploads', context } = opts;\n\n if (storage === MultipartStorages.DISK && !fs.existsSync(uploadDir)) {\n fs.mkdirSync(uploadDir, { recursive: true });\n }\n\n const formData = await readFormBody({ req: context.req });\n const files: IParsedFile[] = [];\n const fields: Record<string, string> = {};\n\n const entries = formData.entries();\n for (const [fieldname, value] of entries) {\n if (typeof value === 'string') {\n // Last one wins, like a repeated query parameter.\n fields[fieldname] = value;\n continue;\n }\n\n const file = value as File;\n const arrayBuffer = await file.arrayBuffer();\n const buffer = Buffer.from(arrayBuffer);\n\n const parsedFile: IParsedFile = {\n fieldname,\n originalname: file.name,\n encoding: 'utf8',\n mimetype: file.type,\n size: file.size,\n };\n\n switch (storage) {\n case MultipartStorages.MEMORY: {\n parsedFile.buffer = buffer;\n break;\n }\n case MultipartStorages.DISK: {\n const timestamp = Date.now();\n const randomString = Math.random().toString(36).substring(7);\n // Sanitize filename to prevent path traversal\n const sanitizedName = path.basename(file.name).replace(/[^a-zA-Z0-9._-]/g, '_');\n const filename = `${timestamp}-${randomString}-${sanitizedName}`;\n const filepath = path.join(uploadDir, filename);\n\n fs.writeFileSync(filepath, buffer);\n\n parsedFile.filename = filename;\n parsedFile.path = filepath;\n break;\n }\n default: {\n throw getError({\n message: `[parseMultipartBody] storage: ${storage} | Invalid storage type | Valids: ['memory', 'disk']`,\n });\n }\n }\n\n files.push(parsedFile);\n }\n\n return { files, fields };\n};\n\n/** Sanitizes a filename by removing path components and dangerous characters. The result is printable ASCII. */\nexport const sanitizeFilename = (filename: string): string => {\n const basename = path.basename(filename);\n let sanitized = basename.replace(/[^\\w .-]/g, '_');\n sanitized = sanitized.replace(/^\\.+/, '');\n sanitized = sanitized.replace(/\\.{2,}/g, '.');\n sanitized = sanitized.replace(/\\.\\./g, '.');\n if (!sanitized || sanitized === '.' || sanitized.includes('..')) {\n sanitized = 'download';\n }\n return sanitized;\n};\n\nexport const encodeRFC5987 = (filename: string): string => {\n return encodeURIComponent(filename)\n .replace(/['()]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase())\n .replace(/\\*/g, '%2A');\n};\n\n/** Control, format (bidi overrides, zero-width space) and lone surrogate characters: a format character reorders the name a client shows, a lone surrogate makes `encodeURIComponent` throw. The zero-width joiner and non-joiner stay: they build emoji sequences and Persian words, and reorder nothing. */\nconst UNENCODABLE_FILENAME_CHARACTERS = /(?![\\u200C\\u200D])[\\p{Cc}\\p{Cf}\\p{Cs}]/gu;\nconst LEADING_DOTS = /^\\.+/;\n\n/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */\nexport class ContentDispositionTypes {\n static readonly ATTACHMENT = 'attachment';\n static readonly INLINE = 'inline';\n\n static readonly SCHEME_SET = new Set<string>([this.ATTACHMENT, this.INLINE]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid Content-Disposition type values. */\nexport type TContentDispositionType = TConstValue<typeof ContentDispositionTypes>;\n\nexport const createContentDispositionHeader = (opts: {\n filename: string;\n type: TContentDispositionType;\n}): string => {\n const { filename, type } = opts;\n const sanitized = sanitizeFilename(filename);\n const extendedName = path\n .basename(filename)\n .replace(UNENCODABLE_FILENAME_CHARACTERS, '_')\n .replace(LEADING_DOTS, '');\n const encoded = encodeRFC5987(extendedName || sanitized);\n\n // filename= is the ASCII fallback for old browsers, filename*= the UTF-8 form for modern ones.\n return `${type}; filename=\"${sanitized}\"; filename*=UTF-8''${encoded}`;\n};\n\n/**\n * Reads a filename out of a `Content-Disposition` value.\n *\n * Three forms, in the order the RFC gives them precedence: `filename*=UTF-8''...` (percent-encoded,\n * and the one hand-rolled parsers miss), a quoted `filename=\"...\"`, and a bare `filename=...`.\n * Splitting on `filename=` alone returns the percent-encoded bytes for any non-ASCII name, which in\n * a product with non-English filenames is most of them.\n *\n * The pair of {@link createContentDispositionHeader}: one writes the header, this one reads it.\n */\nexport const parseContentDisposition = (opts: {\n header: string | null | undefined;\n}): { type?: string; filename?: string } => {\n const { header } = opts;\n\n if (!header) {\n return {};\n }\n\n const type = header.split(';')[0]?.trim() || undefined;\n\n // `filename*` wins when both are present - it is the one that can carry a non-ASCII name.\n const extended = header.match(/filename\\*\\s*=\\s*([^;]+)/i);\n if (extended) {\n const value = extended[1].trim();\n // `UTF-8''name` or `UTF-8'lang'name`; anything before the last quote is charset and language.\n const encoded = value.slice(value.lastIndexOf(\"'\") + 1);\n\n try {\n return { type, filename: decodeURIComponent(encoded) };\n } catch {\n // A malformed sequence is not worth failing a download over - fall through to `filename`.\n }\n }\n\n const quoted = header.match(/filename\\s*=\\s*\"([^\"]*)\"/i);\n if (quoted) {\n return { type, filename: quoted[1] };\n }\n\n const bare = header.match(/filename\\s*=\\s*([^;]+)/i);\n return { type, filename: bare ? bare[1].trim() : undefined };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"request.utility.js","sourceRoot":"","sources":["../../../src/utilities/request.utility.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAS7B,4HAA4H;AAC5H,MAAM,OAAO,iBAAiB;aACZ,WAAM,GAAG,QAAQ,CAAC;aAClB,SAAI,GAAG,MAAM,CAAC;aAEd,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAEvE,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,I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AQ,EAAE,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;YACzD,CAAC;YAAC,MAAM,CAAC;gBACP,0FAA0F;YAC5F,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;QACzD,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QACrD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IAC/D,CAAC;CACF","sourcesContent":["import type { TConstValue } from '@/common/types';\nimport { getError } from '@/modules/error';\nimport { FormBodyUtility } from './form-body.utility';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nexport interface IRequestedRemark {\n id: string;\n url: string;\n method: string;\n [extra: string | symbol]: any;\n}\n\n/** Where `RequestUtility.parseMultipartBody` keeps an uploaded file: MEMORY (a buffer) or DISK (spooled to `uploadDir`). */\nexport class MultipartStorages {\n static readonly MEMORY = 'memory';\n static readonly DISK = 'disk';\n\n static readonly SCHEME_SET = new Set<string>([this.MEMORY, this.DISK]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid multipart storage values. */\nexport type TMultipartStorage = TConstValue<typeof MultipartStorages>;\n\ninterface IParseMultipartOptions<C extends { req: any } = { req: any }> {\n storage?: TMultipartStorage;\n uploadDir?: string;\n context: C;\n}\n\ninterface IParsedFile {\n fieldname: string;\n originalname: string;\n encoding: string;\n mimetype: string;\n size: number;\n buffer?: Buffer;\n filename?: string;\n path?: string;\n}\n\n/** Files and the text fields posted beside them - dropping the second silently loses what the client sent. */\nexport interface IParsedMultipartBody {\n files: IParsedFile[];\n fields: Record<string, string>;\n}\n\n/** Control, format (bidi overrides, zero-width space) and lone surrogate characters: a format character reorders the name a client shows, a lone surrogate makes `encodeURIComponent` throw. The zero-width joiner and non-joiner stay: they build emoji sequences and Persian words, and reorder nothing. */\nconst UNENCODABLE_FILENAME_CHARACTERS = /(?![])[\\p{Cc}\\p{Cf}\\p{Cs}]/gu;\nconst LEADING_DOTS = /^\\.+/;\n\n/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */\nexport class ContentDispositionTypes {\n static readonly ATTACHMENT = 'attachment';\n static readonly INLINE = 'inline';\n\n static readonly SCHEME_SET = new Set<string>([this.ATTACHMENT, this.INLINE]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid Content-Disposition type values. */\nexport type TContentDispositionType = TConstValue<typeof ContentDispositionTypes>;\n\nexport class RequestUtility {\n static async parseMultipartBody<C extends { req: any } = { req: any }>(\n opts: IParseMultipartOptions<C>,\n ): Promise<IParsedMultipartBody> {\n const { storage = MultipartStorages.MEMORY, uploadDir = './uploads', context } = opts;\n\n if (storage === MultipartStorages.DISK && !fs.existsSync(uploadDir)) {\n fs.mkdirSync(uploadDir, { recursive: true });\n }\n\n const formData = await FormBodyUtility.readFormBody({ req: context.req });\n const files: IParsedFile[] = [];\n const fields: Record<string, string> = {};\n\n const entries = formData.entries();\n for (const [fieldname, value] of entries) {\n if (typeof value === 'string') {\n // Last one wins, like a repeated query parameter.\n fields[fieldname] = value;\n continue;\n }\n\n const file = value as File;\n const arrayBuffer = await file.arrayBuffer();\n const buffer = Buffer.from(arrayBuffer);\n\n const parsedFile: IParsedFile = {\n fieldname,\n originalname: file.name,\n encoding: 'utf8',\n mimetype: file.type,\n size: file.size,\n };\n\n switch (storage) {\n case MultipartStorages.MEMORY: {\n parsedFile.buffer = buffer;\n break;\n }\n case MultipartStorages.DISK: {\n const timestamp = Date.now();\n const randomString = Math.random().toString(36).substring(7);\n // Sanitize filename to prevent path traversal\n const sanitizedName = path.basename(file.name).replace(/[^a-zA-Z0-9._-]/g, '_');\n const filename = `${timestamp}-${randomString}-${sanitizedName}`;\n const filepath = path.join(uploadDir, filename);\n\n fs.writeFileSync(filepath, buffer);\n\n parsedFile.filename = filename;\n parsedFile.path = filepath;\n break;\n }\n default: {\n throw getError({\n message: `[parseMultipartBody] storage: ${storage} | Invalid storage type | Valids: ['memory', 'disk']`,\n });\n }\n }\n\n files.push(parsedFile);\n }\n\n return { files, fields };\n }\n\n /** Sanitizes a filename by removing path components and dangerous characters. The result is printable ASCII. */\n static sanitizeFilename(opts: { filename: string }): string {\n const basename = path.basename(opts.filename);\n let sanitized = basename.replace(/[^\\w .-]/g, '_');\n sanitized = sanitized.replace(/^\\.+/, '');\n sanitized = sanitized.replace(/\\.{2,}/g, '.');\n sanitized = sanitized.replace(/\\.\\./g, '.');\n if (!sanitized || sanitized === '.' || sanitized.includes('..')) {\n sanitized = 'download';\n }\n return sanitized;\n }\n\n static encodeRfc5987(opts: { filename: string }): string {\n return encodeURIComponent(opts.filename)\n .replace(/['()]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase())\n .replace(/\\*/g, '%2A');\n }\n\n static buildContentDispositionHeader(opts: {\n filename: string;\n type: TContentDispositionType;\n }): string {\n const { filename, type } = opts;\n const sanitized = RequestUtility.sanitizeFilename({ filename });\n const extendedName = path\n .basename(filename)\n .replace(UNENCODABLE_FILENAME_CHARACTERS, '_')\n .replace(LEADING_DOTS, '');\n const encoded = RequestUtility.encodeRfc5987({ filename: extendedName || sanitized });\n\n // filename= is the ASCII fallback for old browsers, filename*= the UTF-8 form for modern ones.\n return `${type}; filename=\"${sanitized}\"; filename*=UTF-8''${encoded}`;\n }\n\n /**\n * Reads a filename out of a `Content-Disposition` value.\n *\n * Three forms, in the order the RFC gives them precedence: `filename*=UTF-8''...` (percent-encoded,\n * and the one hand-rolled parsers miss), a quoted `filename=\"...\"`, and a bare `filename=...`.\n * Splitting on `filename=` alone returns the percent-encoded bytes for any non-ASCII name, which in\n * a product with non-English filenames is most of them.\n *\n * The pair of {@link RequestUtility.buildContentDispositionHeader}: one writes the header, this one reads it.\n */\n static parseContentDisposition(opts: { header: string | null | undefined }): {\n type?: string;\n filename?: string;\n } {\n const { header } = opts;\n\n if (!header) {\n return {};\n }\n\n const type = header.split(';')[0]?.trim() || undefined;\n\n // `filename*` wins when both are present - it is the one that can carry a non-ASCII name.\n const extended = header.match(/filename\\*\\s*=\\s*([^;]+)/i);\n if (extended) {\n const value = extended[1].trim();\n // `UTF-8''name` or `UTF-8'lang'name`; anything before the last quote is charset and language.\n const encoded = value.slice(value.lastIndexOf(\"'\") + 1);\n\n try {\n return { type, filename: decodeURIComponent(encoded) };\n } catch {\n // A malformed sequence is not worth failing a download over - fall through to `filename`.\n }\n }\n\n const quoted = header.match(/filename\\s*=\\s*\"([^\"]*)\"/i);\n if (quoted) {\n return { type, filename: quoted[1] };\n }\n\n const bare = header.match(/filename\\s*=\\s*([^;]+)/i);\n return { type, filename: bare ? bare[1].trim() : undefined };\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venizia/ignis-helpers",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7-1",
|
|
4
4
|
"description": "Production-ready TypeScript utility library: pluggable logging (winston or pino behind one ILogger contract), Redis single/cluster/sentinel with pub/sub, BullMQ/MQTT/Kafka message queues, MinIO/Disk/Bun-S3 object storage, AES-256/RSA/ECDH cryptography, Snowflake UID generation, cron scheduling, Socket.IO/WebSocket, TCP/TLS/UDP networking, HTTP clients, secrets/Vault, worker thread pools, and environment management. Sub-path imports isolate optional peer dependencies so the root barrel never forces a peer into your bundle.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aes",
|
|
@@ -36,7 +36,6 @@
|
|
|
36
36
|
"logger",
|
|
37
37
|
"logging",
|
|
38
38
|
"message-queue",
|
|
39
|
-
"minio",
|
|
40
39
|
"mqtt",
|
|
41
40
|
"network",
|
|
42
41
|
"nodejs",
|
|
@@ -136,10 +135,6 @@
|
|
|
136
135
|
"types": "./dist/esm/modules/queue/mqtt/index.d.ts",
|
|
137
136
|
"default": "./dist/esm/modules/queue/mqtt/index.js"
|
|
138
137
|
},
|
|
139
|
-
"./minio": {
|
|
140
|
-
"types": "./dist/esm/modules/storage/minio/index.d.ts",
|
|
141
|
-
"default": "./dist/esm/modules/storage/minio/index.js"
|
|
142
|
-
},
|
|
143
138
|
"./bun-s3": {
|
|
144
139
|
"types": "./dist/esm/modules/storage/bun-s3/index.d.ts",
|
|
145
140
|
"default": "./dist/esm/modules/storage/bun-s3/index.js"
|
|
@@ -178,11 +173,10 @@
|
|
|
178
173
|
"access": "public"
|
|
179
174
|
},
|
|
180
175
|
"scripts": {
|
|
181
|
-
"force-update": "sh ../../scripts/build/force-update.sh"
|
|
182
|
-
"prepublishOnly": "make rebuild"
|
|
176
|
+
"force-update": "sh ../../scripts/build/force-update.sh"
|
|
183
177
|
},
|
|
184
178
|
"dependencies": {
|
|
185
|
-
"@venizia/ignis-inversion": "0.4.
|
|
179
|
+
"@venizia/ignis-inversion": "0.4.6-1",
|
|
186
180
|
"reflect-metadata": "^0.2.2",
|
|
187
181
|
"zod": "^4.6.7"
|
|
188
182
|
},
|
|
@@ -194,7 +188,7 @@
|
|
|
194
188
|
"@socket.io/redis-emitter": "^5.1.0",
|
|
195
189
|
"@types/bun": "^1.4.3",
|
|
196
190
|
"@types/luxon": "^3.7.6",
|
|
197
|
-
"@venizia/dev-configs": "0.4.
|
|
191
|
+
"@venizia/dev-configs": "0.4.7-1",
|
|
198
192
|
"axios": "^1.20.0",
|
|
199
193
|
"bullmq": "^6.4.0",
|
|
200
194
|
"cron": "^4.4.0",
|
|
@@ -203,7 +197,6 @@
|
|
|
203
197
|
"hono": "^4.13.13",
|
|
204
198
|
"ioredis": "^6.0.0",
|
|
205
199
|
"luxon": "^3.7.2",
|
|
206
|
-
"minio": "^8.0.7",
|
|
207
200
|
"mqtt": "^5.16.1",
|
|
208
201
|
"node-vault": "^0.13.0",
|
|
209
202
|
"oxlint": "1.89.0",
|
|
@@ -229,7 +222,6 @@
|
|
|
229
222
|
"cron": "^4.4.0",
|
|
230
223
|
"hono": "^4.13.13",
|
|
231
224
|
"ioredis": "^6.0.0",
|
|
232
|
-
"minio": "^8.0.7",
|
|
233
225
|
"mqtt": "^5.16.1",
|
|
234
226
|
"node-vault": "^0.13.0",
|
|
235
227
|
"pino": "^10.4.0",
|
|
@@ -257,9 +249,6 @@
|
|
|
257
249
|
"cron": {
|
|
258
250
|
"optional": true
|
|
259
251
|
},
|
|
260
|
-
"minio": {
|
|
261
|
-
"optional": true
|
|
262
|
-
},
|
|
263
252
|
"mqtt": {
|
|
264
253
|
"optional": true
|
|
265
254
|
},
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import winston from 'winston';
|
|
2
|
-
/** Drop-in replacement for `winston.format.splat()` that formats through {@link formatLogMessage}; every transport reads `info.message`, so widening it here widens console, file and dgram at once. */
|
|
3
|
-
export declare const deepSplat: winston.Logform.FormatWrap;
|
|
4
|
-
//# sourceMappingURL=deep-splat.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deep-splat.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/logger/winston/formatters/deep-splat.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAO9B,wMAAwM;AACxM,eAAO,MAAM,SAAS,4BASpB,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import winston from 'winston';
|
|
2
|
-
import { formatLogMessage } from '../../formatting/index.js';
|
|
3
|
-
/** Winston stashes the extra arguments of `logger.error(msg, ...args)` under this well-known key. */
|
|
4
|
-
const SPLAT = Symbol.for('splat');
|
|
5
|
-
/** Drop-in replacement for `winston.format.splat()` that formats through {@link formatLogMessage}; every transport reads `info.message`, so widening it here widens console, file and dgram at once. */
|
|
6
|
-
export const deepSplat = winston.format((info) => {
|
|
7
|
-
const args = info[SPLAT];
|
|
8
|
-
if (!args?.length || typeof info.message !== 'string') {
|
|
9
|
-
return info;
|
|
10
|
-
}
|
|
11
|
-
info.message = formatLogMessage({ message: info.message, args });
|
|
12
|
-
return info;
|
|
13
|
-
});
|
|
14
|
-
//# sourceMappingURL=deep-splat.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deep-splat.js","sourceRoot":"","sources":["../../../../../../src/modules/logger/winston/formatters/deep-splat.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,qGAAqG;AACrG,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAElC,wMAAwM;AACxM,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;IAC/C,MAAM,IAAI,GAAI,IAAgB,CAAC,KAAK,CAA+B,CAAC;IAEpE,IAAI,CAAC,IAAI,EAAE,MAAM,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QACtD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,OAAO,GAAG,gBAAgB,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACjE,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC","sourcesContent":["import winston from 'winston';\nimport { type AnyType } from '@/common/types';\nimport { formatLogMessage } from '../../formatting';\n\n/** Winston stashes the extra arguments of `logger.error(msg, ...args)` under this well-known key. */\nconst SPLAT = Symbol.for('splat');\n\n/** Drop-in replacement for `winston.format.splat()` that formats through {@link formatLogMessage}; every transport reads `info.message`, so widening it here widens console, file and dgram at once. */\nexport const deepSplat = winston.format((info) => {\n const args = (info as AnyType)[SPLAT] as Array<unknown> | undefined;\n\n if (!args?.length || typeof info.message !== 'string') {\n return info;\n }\n\n info.message = formatLogMessage({ message: info.message, args });\n return info;\n});\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/logger/winston/formatters/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/modules/logger/winston/formatters/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC","sourcesContent":["export * from './deep-splat';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/types.ts"],"names":[],"mappings":"","sourcesContent":[""]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/modules/queue/common/types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/queue/common/types.ts"],"names":[],"mappings":"","sourcesContent":[""]}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { BunPlugin } from 'bun';
|
|
2
|
-
/** `@platformatic/kafka` 2.8-2.9 resolves some dependencies through `createRequire(import.meta.url)` at module scope; `bun build --compile` cannot see through that, so the specifier stays unresolved and the binary dies with "Cannot find package" before boot - this plugin hoists those calls to static imports at bundle time. 2.10 removed the module-scope require(), so on >= 2.10 the plugin matches nothing and is inert. */
|
|
3
|
-
export declare const platformaticRequirePlugin: () => BunPlugin;
|
|
4
|
-
//# sourceMappingURL=platformatic-require.plugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"platformatic-require.plugin.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/platformatic-require.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAGrC,waAAwa;AACxa,eAAO,MAAM,yBAAyB,QAAO,SAgC3C,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { KafkaBundlerPluginNames, PlatformaticRequireSpecifiers } from './common/index.js';
|
|
2
|
-
/** `@platformatic/kafka` 2.8-2.9 resolves some dependencies through `createRequire(import.meta.url)` at module scope; `bun build --compile` cannot see through that, so the specifier stays unresolved and the binary dies with "Cannot find package" before boot - this plugin hoists those calls to static imports at bundle time. 2.10 removed the module-scope require(), so on >= 2.10 the plugin matches nothing and is inert. */
|
|
3
|
-
export const platformaticRequirePlugin = () => ({
|
|
4
|
-
name: KafkaBundlerPluginNames.PLATFORMATIC_REQUIRE,
|
|
5
|
-
setup(build) {
|
|
6
|
-
build.onLoad({ filter: PlatformaticRequireSpecifiers.MODULE_FILTER }, async (args) => {
|
|
7
|
-
const source = await Bun.file(args.path).text();
|
|
8
|
-
const imports = [];
|
|
9
|
-
const contents = source.replace(PlatformaticRequireSpecifiers.REQUIRE_PATTERN, (matched, binding, _quote, specifier) => {
|
|
10
|
-
if (PlatformaticRequireSpecifiers.SKIPPED_SPECIFIERS.includes(specifier)) {
|
|
11
|
-
return matched;
|
|
12
|
-
}
|
|
13
|
-
const alias = `${PlatformaticRequireSpecifiers.IMPORT_ALIAS_PREFIX}${imports.length}`;
|
|
14
|
-
imports.push(`import ${alias} from ${JSON.stringify(specifier)};`);
|
|
15
|
-
// No `?.default` unwrap: a default import already yields `module.exports` for CJS, and
|
|
16
|
-
// unwrapping would break JSON payloads carrying their own top-level `default` key - the
|
|
17
|
-
// draft-06 meta schema has one, so unwrapping silently replaces it with `{}`.
|
|
18
|
-
return `const ${binding} = ${alias};`;
|
|
19
|
-
});
|
|
20
|
-
// No match is not an error: upstream fixing this makes the plugin an inert no-op.
|
|
21
|
-
if (!imports.length) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
return { contents: `${imports.join('\n')}\n${contents}`, loader: 'js' };
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
//# sourceMappingURL=platformatic-require.plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"platformatic-require.plugin.js","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/platformatic-require.plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAC;AAElF,waAAwa;AACxa,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAc,EAAE,CAAC,CAAC;IACzD,IAAI,EAAE,uBAAuB,CAAC,oBAAoB;IAClD,KAAK,CAAC,KAAK;QACT,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,6BAA6B,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACnF,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;YAChD,MAAM,OAAO,GAAa,EAAE,CAAC;YAE7B,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAC7B,6BAA6B,CAAC,eAAe,EAC7C,CAAC,OAAO,EAAE,OAAe,EAAE,MAAc,EAAE,SAAiB,EAAE,EAAE;gBAC9D,IAAI,6BAA6B,CAAC,kBAAkB,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;oBACzE,OAAO,OAAO,CAAC;gBACjB,CAAC;gBAED,MAAM,KAAK,GAAG,GAAG,6BAA6B,CAAC,mBAAmB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;gBACtF,OAAO,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;gBAEnE,uFAAuF;gBACvF,wFAAwF;gBACxF,8EAA8E;gBAC9E,OAAO,SAAS,OAAO,MAAM,KAAK,GAAG,CAAC;YACxC,CAAC,CACF,CAAC;YAEF,kFAAkF;YAClF,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;gBACpB,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QAC1E,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { BunPlugin } from 'bun';\nimport { KafkaBundlerPluginNames, PlatformaticRequireSpecifiers } from './common';\n\n/** `@platformatic/kafka` 2.8-2.9 resolves some dependencies through `createRequire(import.meta.url)` at module scope; `bun build --compile` cannot see through that, so the specifier stays unresolved and the binary dies with \"Cannot find package\" before boot - this plugin hoists those calls to static imports at bundle time. 2.10 removed the module-scope require(), so on >= 2.10 the plugin matches nothing and is inert. */\nexport const platformaticRequirePlugin = (): BunPlugin => ({\n name: KafkaBundlerPluginNames.PLATFORMATIC_REQUIRE,\n setup(build) {\n build.onLoad({ filter: PlatformaticRequireSpecifiers.MODULE_FILTER }, async (args) => {\n const source = await Bun.file(args.path).text();\n const imports: string[] = [];\n\n const contents = source.replace(\n PlatformaticRequireSpecifiers.REQUIRE_PATTERN,\n (matched, binding: string, _quote: string, specifier: string) => {\n if (PlatformaticRequireSpecifiers.SKIPPED_SPECIFIERS.includes(specifier)) {\n return matched;\n }\n\n const alias = `${PlatformaticRequireSpecifiers.IMPORT_ALIAS_PREFIX}${imports.length}`;\n imports.push(`import ${alias} from ${JSON.stringify(specifier)};`);\n\n // No `?.default` unwrap: a default import already yields `module.exports` for CJS, and\n // unwrapping would break JSON payloads carrying their own top-level `default` key - the\n // draft-06 meta schema has one, so unwrapping silently replaces it with `{}`.\n return `const ${binding} = ${alias};`;\n },\n );\n\n // No match is not an error: upstream fixing this makes the plugin an inert no-op.\n if (!imports.length) {\n return undefined;\n }\n\n return { contents: `${imports.join('\\n')}\\n${contents}`, loader: 'js' };\n });\n },\n});\n"]}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { BunPlugin } from 'bun';
|
|
2
|
-
/** `@platformatic/wasm-utils`'s default entrypoint reads `native.wasm` from disk at module load and `bun build --compile` embeds JS only, so it resolves against `/$bunfs` and the binary dies with ENOENT - this plugin redirects the import to the `/bundled` entrypoint (wasm inlined). */
|
|
3
|
-
export declare const platformaticWasmPlugin: () => BunPlugin;
|
|
4
|
-
//# sourceMappingURL=platformatic-wasm.plugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"platformatic-wasm.plugin.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/platformatic-wasm.plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAIrC,8RAA8R;AAC9R,eAAO,MAAM,sBAAsB,QAAO,SAsBxC,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { getError } from '../../../error/index.js';
|
|
2
|
-
import { dirname } from 'node:path';
|
|
3
|
-
import { KafkaBundlerPluginNames, PlatformaticWasmSpecifiers } from './common/index.js';
|
|
4
|
-
/** `@platformatic/wasm-utils`'s default entrypoint reads `native.wasm` from disk at module load and `bun build --compile` embeds JS only, so it resolves against `/$bunfs` and the binary dies with ENOENT - this plugin redirects the import to the `/bundled` entrypoint (wasm inlined). */
|
|
5
|
-
export const platformaticWasmPlugin = () => ({
|
|
6
|
-
name: KafkaBundlerPluginNames.PLATFORMATIC_WASM,
|
|
7
|
-
setup(build) {
|
|
8
|
-
build.onResolve({ filter: PlatformaticWasmSpecifiers.ENTRYPOINT_FILTER }, (args) => {
|
|
9
|
-
try {
|
|
10
|
-
return {
|
|
11
|
-
path: Bun.resolveSync(PlatformaticWasmSpecifiers.BUNDLED_ENTRYPOINT, dirname(args.importer)),
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
throw getError({
|
|
16
|
-
message: [
|
|
17
|
-
`[platformaticWasmPlugin] Failed to resolve ${PlatformaticWasmSpecifiers.BUNDLED_ENTRYPOINT}`,
|
|
18
|
-
`from ${args.importer}`,
|
|
19
|
-
`| Error: ${error instanceof Error ? error.message : String(error)}`,
|
|
20
|
-
].join(' '),
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
//# sourceMappingURL=platformatic-wasm.plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"platformatic-wasm.plugin.js","sourceRoot":"","sources":["../../../../../../src/modules/queue/kafka/bundler/platformatic-wasm.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAE/E,8RAA8R;AAC9R,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAc,EAAE,CAAC,CAAC;IACtD,IAAI,EAAE,uBAAuB,CAAC,iBAAiB;IAC/C,KAAK,CAAC,KAAK;QACT,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,0BAA0B,CAAC,iBAAiB,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;YACjF,IAAI,CAAC;gBACH,OAAO;oBACL,IAAI,EAAE,GAAG,CAAC,WAAW,CACnB,0BAA0B,CAAC,kBAAkB,EAC7C,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CACvB;iBACF,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,QAAQ,CAAC;oBACb,OAAO,EAAE;wBACP,8CAA8C,0BAA0B,CAAC,kBAAkB,EAAE;wBAC7F,QAAQ,IAAI,CAAC,QAAQ,EAAE;wBACvB,YAAY,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;qBACrE,CAAC,IAAI,CAAC,GAAG,CAAC;iBACZ,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { getError } from '@/modules/error';\nimport type { BunPlugin } from 'bun';\nimport { dirname } from 'node:path';\nimport { KafkaBundlerPluginNames, PlatformaticWasmSpecifiers } from './common';\n\n/** `@platformatic/wasm-utils`'s default entrypoint reads `native.wasm` from disk at module load and `bun build --compile` embeds JS only, so it resolves against `/$bunfs` and the binary dies with ENOENT - this plugin redirects the import to the `/bundled` entrypoint (wasm inlined). */\nexport const platformaticWasmPlugin = (): BunPlugin => ({\n name: KafkaBundlerPluginNames.PLATFORMATIC_WASM,\n setup(build) {\n build.onResolve({ filter: PlatformaticWasmSpecifiers.ENTRYPOINT_FILTER }, (args) => {\n try {\n return {\n path: Bun.resolveSync(\n PlatformaticWasmSpecifiers.BUNDLED_ENTRYPOINT,\n dirname(args.importer),\n ),\n };\n } catch (error) {\n throw getError({\n message: [\n `[platformaticWasmPlugin] Failed to resolve ${PlatformaticWasmSpecifiers.BUNDLED_ENTRYPOINT}`,\n `from ${args.importer}`,\n `| Error: ${error instanceof Error ? error.message : String(error)}`,\n ].join(' '),\n });\n }\n });\n },\n});\n"]}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { type ClientOptions } from 'minio';
|
|
2
|
-
import { Readable } from 'node:stream';
|
|
3
|
-
import { BaseStorageHelper } from '../base.js';
|
|
4
|
-
import { type IBucketInfo, type IBucketRef, type IFileStat, type IListObjectsOptions, type IObjectInfo, type IObjectLocation, type IObjectRef, type IStorageHelperOptions, type IUploadFile } from '../common/index.js';
|
|
5
|
-
/** @deprecated Use `IBunS3HelperOptions` from `@venizia/ignis-helpers/bun-s3`. */
|
|
6
|
-
export interface IMinioHelperOptions extends IStorageHelperOptions, ClientOptions {
|
|
7
|
-
}
|
|
8
|
-
/** @deprecated Use `BunS3Helper` from `@venizia/ignis-helpers/bun-s3`: it reaches MinIO over the same S3 API, and adds presigned URLs, tagging and byte ranges. Removed once that path is settled. */
|
|
9
|
-
export declare class MinioHelper extends BaseStorageHelper {
|
|
10
|
-
private client;
|
|
11
|
-
private static readonly PRINTABLE_ASCII;
|
|
12
|
-
constructor(options: IMinioHelperOptions);
|
|
13
|
-
hasBucket(opts: {
|
|
14
|
-
bucket: IBucketRef;
|
|
15
|
-
}): Promise<boolean>;
|
|
16
|
-
getBuckets(): Promise<IBucketInfo[]>;
|
|
17
|
-
getBucket(opts: {
|
|
18
|
-
bucket: IBucketRef;
|
|
19
|
-
}): Promise<IBucketInfo | null>;
|
|
20
|
-
createBucket(opts: {
|
|
21
|
-
bucket: IBucketRef;
|
|
22
|
-
}): Promise<IBucketInfo | null>;
|
|
23
|
-
removeBucket(opts: {
|
|
24
|
-
bucket: IBucketRef;
|
|
25
|
-
}): Promise<boolean>;
|
|
26
|
-
protected get defaultLinkPrefix(): string;
|
|
27
|
-
/** Metadata travels as a header, which cannot carry a non-Latin-1 name. Outside printable ASCII the value is RFC 2047-encoded, the form S3 uses for such metadata. */
|
|
28
|
-
private toMetadataValue;
|
|
29
|
-
protected writeObject(opts: IObjectLocation & {
|
|
30
|
-
file: IUploadFile;
|
|
31
|
-
}): Promise<void>;
|
|
32
|
-
getObject(opts: IObjectLocation & {
|
|
33
|
-
options?: {
|
|
34
|
-
versionId?: string;
|
|
35
|
-
SSECustomerAlgorithm?: string;
|
|
36
|
-
SSECustomerKey?: string;
|
|
37
|
-
SSECustomerKeyMD5?: string;
|
|
38
|
-
};
|
|
39
|
-
}): Promise<Readable>;
|
|
40
|
-
/** A native ranged GET, so only the requested bytes leave the server. */
|
|
41
|
-
getObjectStream(opts: IObjectLocation & {
|
|
42
|
-
range?: {
|
|
43
|
-
start: number;
|
|
44
|
-
end?: number;
|
|
45
|
-
};
|
|
46
|
-
}): Promise<ReadableStream<Uint8Array>>;
|
|
47
|
-
getStat(opts: IObjectLocation): Promise<IFileStat>;
|
|
48
|
-
removeObject(opts: IObjectLocation): Promise<void>;
|
|
49
|
-
removeObjects(opts: {
|
|
50
|
-
bucket: IBucketRef;
|
|
51
|
-
objects: IObjectRef[];
|
|
52
|
-
}): Promise<void>;
|
|
53
|
-
listObjects(opts: IListObjectsOptions): Promise<IObjectInfo[]>;
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../../../src/modules/storage/minio/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EACjB,MAAM,WAAW,CAAC;AAEnB,kFAAkF;AAClF,MAAM,WAAW,mBAAoB,SAAQ,qBAAqB,EAAE,aAAa;CAAG;AAEpF,sMAAsM;AACtM,qBAAa,WAAY,SAAQ,iBAAiB;IAChD,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO,CAAC,MAAM,CAAC,QAA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