promidas 2.0.0
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 +21 -0
- package/README.md +179 -0
- package/dist/builder.d.ts +158 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +255 -0
- package/dist/builder.js.map +1 -0
- package/dist/factory.d.ts +154 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +243 -0
- package/dist/factory.js.map +1 -0
- package/dist/fetcher/client/config.d.ts +140 -0
- package/dist/fetcher/client/config.d.ts.map +1 -0
- package/dist/fetcher/client/config.js +2 -0
- package/dist/fetcher/client/config.js.map +1 -0
- package/dist/fetcher/client/fetch-with-progress.d.ts +156 -0
- package/dist/fetcher/client/fetch-with-progress.d.ts.map +1 -0
- package/dist/fetcher/client/fetch-with-progress.js +313 -0
- package/dist/fetcher/client/fetch-with-progress.js.map +1 -0
- package/dist/fetcher/client/fetch-with-timeout.d.ts +6 -0
- package/dist/fetcher/client/fetch-with-timeout.d.ts.map +1 -0
- package/dist/fetcher/client/fetch-with-timeout.js +48 -0
- package/dist/fetcher/client/fetch-with-timeout.js.map +1 -0
- package/dist/fetcher/client/protopedia-api-custom-client.d.ts +141 -0
- package/dist/fetcher/client/protopedia-api-custom-client.d.ts.map +1 -0
- package/dist/fetcher/client/protopedia-api-custom-client.js +268 -0
- package/dist/fetcher/client/protopedia-api-custom-client.js.map +1 -0
- package/dist/fetcher/client/select-custom-fetch.d.ts +58 -0
- package/dist/fetcher/client/select-custom-fetch.d.ts.map +1 -0
- package/dist/fetcher/client/select-custom-fetch.js +58 -0
- package/dist/fetcher/client/select-custom-fetch.js.map +1 -0
- package/dist/fetcher/errors/fetcher-error.d.ts +10 -0
- package/dist/fetcher/errors/fetcher-error.d.ts.map +1 -0
- package/dist/fetcher/errors/fetcher-error.js +15 -0
- package/dist/fetcher/errors/fetcher-error.js.map +1 -0
- package/dist/fetcher/index.d.ts +73 -0
- package/dist/fetcher/index.d.ts.map +1 -0
- package/dist/fetcher/index.js +70 -0
- package/dist/fetcher/index.js.map +1 -0
- package/dist/fetcher/types/index.d.ts +9 -0
- package/dist/fetcher/types/index.d.ts.map +1 -0
- package/dist/fetcher/types/index.js +7 -0
- package/dist/fetcher/types/index.js.map +1 -0
- package/dist/fetcher/types/progress-event.types.d.ts +221 -0
- package/dist/fetcher/types/progress-event.types.d.ts.map +1 -0
- package/dist/fetcher/types/progress-event.types.js +10 -0
- package/dist/fetcher/types/progress-event.types.js.map +1 -0
- package/dist/fetcher/types/prototype-api.types.d.ts +106 -0
- package/dist/fetcher/types/prototype-api.types.d.ts.map +1 -0
- package/dist/fetcher/types/prototype-api.types.js +2 -0
- package/dist/fetcher/types/prototype-api.types.js.map +1 -0
- package/dist/fetcher/types/result.types.d.ts +75 -0
- package/dist/fetcher/types/result.types.d.ts.map +1 -0
- package/dist/fetcher/types/result.types.js +2 -0
- package/dist/fetcher/types/result.types.js.map +1 -0
- package/dist/fetcher/utils/create-client-fetch.d.ts +63 -0
- package/dist/fetcher/utils/create-client-fetch.d.ts.map +1 -0
- package/dist/fetcher/utils/create-client-fetch.js +89 -0
- package/dist/fetcher/utils/create-client-fetch.js.map +1 -0
- package/dist/fetcher/utils/create-fetch-with-stripped-headers.d.ts +6 -0
- package/dist/fetcher/utils/create-fetch-with-stripped-headers.d.ts.map +1 -0
- package/dist/fetcher/utils/create-fetch-with-stripped-headers.js +40 -0
- package/dist/fetcher/utils/create-fetch-with-stripped-headers.js.map +1 -0
- package/dist/fetcher/utils/errors/handler.d.ts +58 -0
- package/dist/fetcher/utils/errors/handler.d.ts.map +1 -0
- package/dist/fetcher/utils/errors/handler.js +243 -0
- package/dist/fetcher/utils/errors/handler.js.map +1 -0
- package/dist/fetcher/utils/errors/messages.d.ts +75 -0
- package/dist/fetcher/utils/errors/messages.d.ts.map +1 -0
- package/dist/fetcher/utils/errors/messages.js +88 -0
- package/dist/fetcher/utils/errors/messages.js.map +1 -0
- package/dist/fetcher/utils/index.d.ts +13 -0
- package/dist/fetcher/utils/index.d.ts.map +1 -0
- package/dist/fetcher/utils/index.js +12 -0
- package/dist/fetcher/utils/index.js.map +1 -0
- package/dist/fetcher/utils/log-timestamp-normalization-warnings.d.ts +10 -0
- package/dist/fetcher/utils/log-timestamp-normalization-warnings.d.ts.map +1 -0
- package/dist/fetcher/utils/log-timestamp-normalization-warnings.js +32 -0
- package/dist/fetcher/utils/log-timestamp-normalization-warnings.js.map +1 -0
- package/dist/fetcher/utils/normalize-protopedia-timestamp.d.ts +59 -0
- package/dist/fetcher/utils/normalize-protopedia-timestamp.d.ts.map +1 -0
- package/dist/fetcher/utils/normalize-protopedia-timestamp.js +81 -0
- package/dist/fetcher/utils/normalize-protopedia-timestamp.js.map +1 -0
- package/dist/fetcher/utils/normalize-prototype.d.ts +56 -0
- package/dist/fetcher/utils/normalize-prototype.d.ts.map +1 -0
- package/dist/fetcher/utils/normalize-prototype.js +113 -0
- package/dist/fetcher/utils/normalize-prototype.js.map +1 -0
- package/dist/fetcher/utils/sanitize-options.d.ts +14 -0
- package/dist/fetcher/utils/sanitize-options.d.ts.map +1 -0
- package/dist/fetcher/utils/sanitize-options.js +16 -0
- package/dist/fetcher/utils/sanitize-options.js.map +1 -0
- package/dist/fetcher/utils/string-parsers.d.ts +45 -0
- package/dist/fetcher/utils/string-parsers.d.ts.map +1 -0
- package/dist/fetcher/utils/string-parsers.js +53 -0
- package/dist/fetcher/utils/string-parsers.js.map +1 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +70 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/console-logger.d.ts +74 -0
- package/dist/logger/console-logger.d.ts.map +1 -0
- package/dist/logger/console-logger.js +113 -0
- package/dist/logger/console-logger.js.map +1 -0
- package/dist/logger/factory.d.ts +88 -0
- package/dist/logger/factory.d.ts.map +1 -0
- package/dist/logger/factory.js +94 -0
- package/dist/logger/factory.js.map +1 -0
- package/dist/logger/index.d.ts +42 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +41 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/logger/logger.types.d.ts +49 -0
- package/dist/logger/logger.types.d.ts.map +1 -0
- package/dist/logger/logger.types.js +2 -0
- package/dist/logger/logger.types.js.map +1 -0
- package/dist/repository/errors/validation-error.d.ts +24 -0
- package/dist/repository/errors/validation-error.d.ts.map +1 -0
- package/dist/repository/errors/validation-error.js +26 -0
- package/dist/repository/errors/validation-error.js.map +1 -0
- package/dist/repository/index.d.ts +122 -0
- package/dist/repository/index.d.ts.map +1 -0
- package/dist/repository/index.js +44 -0
- package/dist/repository/index.js.map +1 -0
- package/dist/repository/protopedia-in-memory-repository.d.ts +560 -0
- package/dist/repository/protopedia-in-memory-repository.d.ts.map +1 -0
- package/dist/repository/protopedia-in-memory-repository.js +929 -0
- package/dist/repository/protopedia-in-memory-repository.js.map +1 -0
- package/dist/repository/schemas/index.d.ts +9 -0
- package/dist/repository/schemas/index.d.ts.map +1 -0
- package/dist/repository/schemas/index.js +11 -0
- package/dist/repository/schemas/index.js.map +1 -0
- package/dist/repository/schemas/params.d.ts +44 -0
- package/dist/repository/schemas/params.d.ts.map +1 -0
- package/dist/repository/schemas/params.js +44 -0
- package/dist/repository/schemas/params.js.map +1 -0
- package/dist/repository/schemas/serializable-snapshot.d.ts +33 -0
- package/dist/repository/schemas/serializable-snapshot.d.ts.map +1 -0
- package/dist/repository/schemas/serializable-snapshot.js +45 -0
- package/dist/repository/schemas/serializable-snapshot.js.map +1 -0
- package/dist/repository/types/analysis.types.d.ts +89 -0
- package/dist/repository/types/analysis.types.d.ts.map +1 -0
- package/dist/repository/types/analysis.types.js +2 -0
- package/dist/repository/types/analysis.types.js.map +1 -0
- package/dist/repository/types/index.d.ts +12 -0
- package/dist/repository/types/index.d.ts.map +1 -0
- package/dist/repository/types/index.js +7 -0
- package/dist/repository/types/index.js.map +1 -0
- package/dist/repository/types/repository-events.types.d.ts +110 -0
- package/dist/repository/types/repository-events.types.d.ts.map +1 -0
- package/dist/repository/types/repository-events.types.js +2 -0
- package/dist/repository/types/repository-events.types.js.map +1 -0
- package/dist/repository/types/repository.types.d.ts +330 -0
- package/dist/repository/types/repository.types.d.ts.map +1 -0
- package/dist/repository/types/repository.types.js +2 -0
- package/dist/repository/types/repository.types.js.map +1 -0
- package/dist/repository/types/result.types.d.ts +55 -0
- package/dist/repository/types/result.types.d.ts.map +1 -0
- package/dist/repository/types/result.types.js +2 -0
- package/dist/repository/types/result.types.js.map +1 -0
- package/dist/repository/types/serialization.types.d.ts +61 -0
- package/dist/repository/types/serialization.types.d.ts.map +1 -0
- package/dist/repository/types/serialization.types.js +2 -0
- package/dist/repository/types/serialization.types.js.map +1 -0
- package/dist/repository/types/snapshot-operation.types.d.ts +140 -0
- package/dist/repository/types/snapshot-operation.types.d.ts.map +1 -0
- package/dist/repository/types/snapshot-operation.types.js +2 -0
- package/dist/repository/types/snapshot-operation.types.js.map +1 -0
- package/dist/repository/utils/convert-fetch-result.d.ts +46 -0
- package/dist/repository/utils/convert-fetch-result.d.ts.map +1 -0
- package/dist/repository/utils/convert-fetch-result.js +59 -0
- package/dist/repository/utils/convert-fetch-result.js.map +1 -0
- package/dist/repository/utils/convert-store-result.d.ts +36 -0
- package/dist/repository/utils/convert-store-result.d.ts.map +1 -0
- package/dist/repository/utils/convert-store-result.js +36 -0
- package/dist/repository/utils/convert-store-result.js.map +1 -0
- package/dist/repository/utils/emit-repository-event-safely.d.ts +5 -0
- package/dist/repository/utils/emit-repository-event-safely.d.ts.map +1 -0
- package/dist/repository/utils/emit-repository-event-safely.js +17 -0
- package/dist/repository/utils/emit-repository-event-safely.js.map +1 -0
- package/dist/repository/utils/index.d.ts +3 -0
- package/dist/repository/utils/index.d.ts.map +1 -0
- package/dist/repository/utils/index.js +3 -0
- package/dist/repository/utils/index.js.map +1 -0
- package/dist/repository/validation/index.d.ts +9 -0
- package/dist/repository/validation/index.d.ts.map +1 -0
- package/dist/repository/validation/index.js +10 -0
- package/dist/repository/validation/index.js.map +1 -0
- package/dist/repository/validation/params-validators.d.ts +46 -0
- package/dist/repository/validation/params-validators.d.ts.map +1 -0
- package/dist/repository/validation/params-validators.js +68 -0
- package/dist/repository/validation/params-validators.js.map +1 -0
- package/dist/repository/validation/serializable-snapshot.d.ts +47 -0
- package/dist/repository/validation/serializable-snapshot.d.ts.map +1 -0
- package/dist/repository/validation/serializable-snapshot.js +104 -0
- package/dist/repository/validation/serializable-snapshot.js.map +1 -0
- package/dist/schemas/index.d.ts +8 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +8 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/normalized-prototype.d.ts +56 -0
- package/dist/schemas/normalized-prototype.d.ts.map +1 -0
- package/dist/schemas/normalized-prototype.js +123 -0
- package/dist/schemas/normalized-prototype.js.map +1 -0
- package/dist/store/errors/store-error.d.ts +148 -0
- package/dist/store/errors/store-error.d.ts.map +1 -0
- package/dist/store/errors/store-error.js +156 -0
- package/dist/store/errors/store-error.js.map +1 -0
- package/dist/store/index.d.ts +84 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +83 -0
- package/dist/store/index.js.map +1 -0
- package/dist/store/store.d.ts +295 -0
- package/dist/store/store.d.ts.map +1 -0
- package/dist/store/store.js +411 -0
- package/dist/store/store.js.map +1 -0
- package/dist/store/types/index.d.ts +2 -0
- package/dist/store/types/index.d.ts.map +1 -0
- package/dist/store/types/index.js +2 -0
- package/dist/store/types/index.js.map +1 -0
- package/dist/store/types/result.types.d.ts +67 -0
- package/dist/store/types/result.types.d.ts.map +1 -0
- package/dist/store/types/result.types.js +2 -0
- package/dist/store/types/result.types.js.map +1 -0
- package/dist/types/codes.d.ts +44 -0
- package/dist/types/codes.d.ts.map +1 -0
- package/dist/types/codes.js +9 -0
- package/dist/types/codes.js.map +1 -0
- package/dist/types/index.d.ts +61 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +60 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/normalized-prototype.d.ts +95 -0
- package/dist/types/normalized-prototype.d.ts.map +1 -0
- package/dist/types/normalized-prototype.js +2 -0
- package/dist/types/normalized-prototype.js.map +1 -0
- package/dist/utils/converters/index.d.ts +15 -0
- package/dist/utils/converters/index.d.ts.map +1 -0
- package/dist/utils/converters/index.js +15 -0
- package/dist/utils/converters/index.js.map +1 -0
- package/dist/utils/converters/license-type.d.ts +23 -0
- package/dist/utils/converters/license-type.d.ts.map +1 -0
- package/dist/utils/converters/license-type.js +38 -0
- package/dist/utils/converters/license-type.js.map +1 -0
- package/dist/utils/converters/release-flag.d.ts +24 -0
- package/dist/utils/converters/release-flag.d.ts.map +1 -0
- package/dist/utils/converters/release-flag.js +40 -0
- package/dist/utils/converters/release-flag.js.map +1 -0
- package/dist/utils/converters/status.d.ts +23 -0
- package/dist/utils/converters/status.d.ts.map +1 -0
- package/dist/utils/converters/status.js +40 -0
- package/dist/utils/converters/status.js.map +1 -0
- package/dist/utils/converters/thanks-flag.d.ts +25 -0
- package/dist/utils/converters/thanks-flag.d.ts.map +1 -0
- package/dist/utils/converters/thanks-flag.js +41 -0
- package/dist/utils/converters/thanks-flag.js.map +1 -0
- package/dist/utils/deep-merge.d.ts +38 -0
- package/dist/utils/deep-merge.d.ts.map +1 -0
- package/dist/utils/deep-merge.js +85 -0
- package/dist/utils/deep-merge.js.map +1 -0
- package/dist/utils/index.d.ts +80 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +85 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger-utils.d.ts +100 -0
- package/dist/utils/logger-utils.d.ts.map +1 -0
- package/dist/utils/logger-utils.js +265 -0
- package/dist/utils/logger-utils.js.map +1 -0
- package/dist/utils/time/constants.d.ts +14 -0
- package/dist/utils/time/constants.d.ts.map +1 -0
- package/dist/utils/time/constants.js +14 -0
- package/dist/utils/time/constants.js.map +1 -0
- package/dist/utils/time/index.d.ts +28 -0
- package/dist/utils/time/index.d.ts.map +1 -0
- package/dist/utils/time/index.js +28 -0
- package/dist/utils/time/index.js.map +1 -0
- package/dist/utils/time/parser.d.ts +91 -0
- package/dist/utils/time/parser.d.ts.map +1 -0
- package/dist/utils/time/parser.js +143 -0
- package/dist/utils/time/parser.js.map +1 -0
- package/dist/utils/validation/index.d.ts +8 -0
- package/dist/utils/validation/index.d.ts.map +1 -0
- package/dist/utils/validation/index.js +7 -0
- package/dist/utils/validation/index.js.map +1 -0
- package/dist/utils/validation/normalized-prototype.d.ts +64 -0
- package/dist/utils/validation/normalized-prototype.d.ts.map +1 -0
- package/dist/utils/validation/normalized-prototype.js +97 -0
- package/dist/utils/validation/normalized-prototype.js.map +1 -0
- package/dist/utils/validation/types.d.ts +62 -0
- package/dist/utils/validation/types.d.ts.map +1 -0
- package/dist/utils/validation/types.js +8 -0
- package/dist/utils/validation/types.js.map +1 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +138 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility Functions and Data Converters.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a comprehensive set of utility functions for working with
|
|
5
|
+
* ProtoPedia data, including type-safe converters, time parsing, configuration
|
|
6
|
+
* merging, and secure logging utilities.
|
|
7
|
+
*
|
|
8
|
+
* ## Data Converters
|
|
9
|
+
*
|
|
10
|
+
* Transform ProtoPedia API numeric codes into human-readable labels:
|
|
11
|
+
*
|
|
12
|
+
* - {@link getPrototypeStatusLabel} — Convert status code to label (e.g., `1` → `'公開'`)
|
|
13
|
+
* - {@link getPrototypeReleaseFlagLabel} — Convert release flag to label (e.g., `1` → `'フリー'`)
|
|
14
|
+
* - {@link getPrototypeThanksFlagLabel} — Convert thanks flag to label (e.g., `1` → `'受付中'`)
|
|
15
|
+
* - {@link getPrototypeLicenseTypeLabel} — Convert license type to label (e.g., `1` → `'CC BY'`)
|
|
16
|
+
*
|
|
17
|
+
* ## Time Utilities
|
|
18
|
+
*
|
|
19
|
+
* Parse and normalize ProtoPedia timestamps:
|
|
20
|
+
*
|
|
21
|
+
* - {@link parseProtoPediaTimestamp} — Parse JST timestamps to UTC ISO-8601
|
|
22
|
+
* - {@link parseW3cDtfTimestamp} — Parse W3C-DTF timestamps to UTC ISO-8601
|
|
23
|
+
* - {@link JST_OFFSET_MS} — JST timezone offset constant (9 hours in milliseconds)
|
|
24
|
+
*
|
|
25
|
+
* ## Configuration Utilities
|
|
26
|
+
*
|
|
27
|
+
* Deep merge configuration objects safely:
|
|
28
|
+
*
|
|
29
|
+
* - {@link deepMerge} — Deep merge with circular reference protection and prototype pollution prevention
|
|
30
|
+
* - {@link isPlainObject} — Type guard for plain JavaScript objects
|
|
31
|
+
*
|
|
32
|
+
* ## Logging Utilities
|
|
33
|
+
*
|
|
34
|
+
* Sanitize data for secure logging:
|
|
35
|
+
*
|
|
36
|
+
* - {@link sanitizeDataForLogging} — Redact sensitive data and handle circular references
|
|
37
|
+
*
|
|
38
|
+
* ## Dependencies
|
|
39
|
+
*
|
|
40
|
+
* This module intentionally depends on `lib/types` for data structures. This is
|
|
41
|
+
* a correct architectural dependency, as utilities often operate on defined data
|
|
42
|
+
* types. This design ensures type-safe utility operations.
|
|
43
|
+
*
|
|
44
|
+
* ## Standalone Usage
|
|
45
|
+
*
|
|
46
|
+
* All utilities can be used independently without the full repository layer:
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import {
|
|
51
|
+
* getPrototypeStatusLabel,
|
|
52
|
+
* parseProtoPediaTimestamp,
|
|
53
|
+
* deepMerge,
|
|
54
|
+
* sanitizeDataForLogging,
|
|
55
|
+
* } from 'promidas/utils';
|
|
56
|
+
*
|
|
57
|
+
* // Convert status code
|
|
58
|
+
* const label = getPrototypeStatusLabel(1); // => '公開'
|
|
59
|
+
*
|
|
60
|
+
* // Parse timestamp
|
|
61
|
+
* const isoDate = parseProtoPediaTimestamp('2025-11-14 12:03:07.0');
|
|
62
|
+
* // => '2025-11-14T03:03:07.000Z'
|
|
63
|
+
*
|
|
64
|
+
* // Merge configurations
|
|
65
|
+
* const config = deepMerge(defaults, overrides);
|
|
66
|
+
*
|
|
67
|
+
* // Sanitize for logging
|
|
68
|
+
* const safe = sanitizeDataForLogging({ token: 'secret', data: 'visible' });
|
|
69
|
+
* // => { token: '[REDACTED]', data: 'visible' }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @module
|
|
73
|
+
* @see https://protopedia.gitbook.io/helpcenter/info/2022.05.23 for ProtoPedia field specifications
|
|
74
|
+
*/
|
|
75
|
+
export { getPrototypeStatusLabel, getPrototypeReleaseFlagLabel, getPrototypeThanksFlagLabel, getPrototypeLicenseTypeLabel, } from './converters/index.js';
|
|
76
|
+
export { JST_OFFSET_MS, parseProtoPediaTimestamp, parseW3cDtfTimestamp, } from './time/index.js';
|
|
77
|
+
export { deepMerge, isPlainObject } from './deep-merge.js';
|
|
78
|
+
export { sanitizeDataForLogging } from './logger-utils.js';
|
|
79
|
+
export { validateNormalizedPrototype, validateNormalizedPrototypeArray, type ValidationErrorCode, type ValidationResult, type ValidationSuccess, type ValidationFailure, } from './validation/index.js';
|
|
80
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AAGH,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAC5B,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,aAAa,EACb,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAG3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAG3D,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,EAChC,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,GACvB,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility Functions and Data Converters.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a comprehensive set of utility functions for working with
|
|
5
|
+
* ProtoPedia data, including type-safe converters, time parsing, configuration
|
|
6
|
+
* merging, and secure logging utilities.
|
|
7
|
+
*
|
|
8
|
+
* ## Data Converters
|
|
9
|
+
*
|
|
10
|
+
* Transform ProtoPedia API numeric codes into human-readable labels:
|
|
11
|
+
*
|
|
12
|
+
* - {@link getPrototypeStatusLabel} — Convert status code to label (e.g., `1` → `'公開'`)
|
|
13
|
+
* - {@link getPrototypeReleaseFlagLabel} — Convert release flag to label (e.g., `1` → `'フリー'`)
|
|
14
|
+
* - {@link getPrototypeThanksFlagLabel} — Convert thanks flag to label (e.g., `1` → `'受付中'`)
|
|
15
|
+
* - {@link getPrototypeLicenseTypeLabel} — Convert license type to label (e.g., `1` → `'CC BY'`)
|
|
16
|
+
*
|
|
17
|
+
* ## Time Utilities
|
|
18
|
+
*
|
|
19
|
+
* Parse and normalize ProtoPedia timestamps:
|
|
20
|
+
*
|
|
21
|
+
* - {@link parseProtoPediaTimestamp} — Parse JST timestamps to UTC ISO-8601
|
|
22
|
+
* - {@link parseW3cDtfTimestamp} — Parse W3C-DTF timestamps to UTC ISO-8601
|
|
23
|
+
* - {@link JST_OFFSET_MS} — JST timezone offset constant (9 hours in milliseconds)
|
|
24
|
+
*
|
|
25
|
+
* ## Configuration Utilities
|
|
26
|
+
*
|
|
27
|
+
* Deep merge configuration objects safely:
|
|
28
|
+
*
|
|
29
|
+
* - {@link deepMerge} — Deep merge with circular reference protection and prototype pollution prevention
|
|
30
|
+
* - {@link isPlainObject} — Type guard for plain JavaScript objects
|
|
31
|
+
*
|
|
32
|
+
* ## Logging Utilities
|
|
33
|
+
*
|
|
34
|
+
* Sanitize data for secure logging:
|
|
35
|
+
*
|
|
36
|
+
* - {@link sanitizeDataForLogging} — Redact sensitive data and handle circular references
|
|
37
|
+
*
|
|
38
|
+
* ## Dependencies
|
|
39
|
+
*
|
|
40
|
+
* This module intentionally depends on `lib/types` for data structures. This is
|
|
41
|
+
* a correct architectural dependency, as utilities often operate on defined data
|
|
42
|
+
* types. This design ensures type-safe utility operations.
|
|
43
|
+
*
|
|
44
|
+
* ## Standalone Usage
|
|
45
|
+
*
|
|
46
|
+
* All utilities can be used independently without the full repository layer:
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import {
|
|
51
|
+
* getPrototypeStatusLabel,
|
|
52
|
+
* parseProtoPediaTimestamp,
|
|
53
|
+
* deepMerge,
|
|
54
|
+
* sanitizeDataForLogging,
|
|
55
|
+
* } from 'promidas/utils';
|
|
56
|
+
*
|
|
57
|
+
* // Convert status code
|
|
58
|
+
* const label = getPrototypeStatusLabel(1); // => '公開'
|
|
59
|
+
*
|
|
60
|
+
* // Parse timestamp
|
|
61
|
+
* const isoDate = parseProtoPediaTimestamp('2025-11-14 12:03:07.0');
|
|
62
|
+
* // => '2025-11-14T03:03:07.000Z'
|
|
63
|
+
*
|
|
64
|
+
* // Merge configurations
|
|
65
|
+
* const config = deepMerge(defaults, overrides);
|
|
66
|
+
*
|
|
67
|
+
* // Sanitize for logging
|
|
68
|
+
* const safe = sanitizeDataForLogging({ token: 'secret', data: 'visible' });
|
|
69
|
+
* // => { token: '[REDACTED]', data: 'visible' }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @module
|
|
73
|
+
* @see https://protopedia.gitbook.io/helpcenter/info/2022.05.23 for ProtoPedia field specifications
|
|
74
|
+
*/
|
|
75
|
+
// Data Converters
|
|
76
|
+
export { getPrototypeStatusLabel, getPrototypeReleaseFlagLabel, getPrototypeThanksFlagLabel, getPrototypeLicenseTypeLabel, } from './converters/index.js';
|
|
77
|
+
// Time Utilities
|
|
78
|
+
export { JST_OFFSET_MS, parseProtoPediaTimestamp, parseW3cDtfTimestamp, } from './time/index.js';
|
|
79
|
+
// Configuration Utilities
|
|
80
|
+
export { deepMerge, isPlainObject } from './deep-merge.js';
|
|
81
|
+
// Logging Utilities
|
|
82
|
+
export { sanitizeDataForLogging } from './logger-utils.js';
|
|
83
|
+
// Validation Utilities
|
|
84
|
+
export { validateNormalizedPrototype, validateNormalizedPrototypeArray, } from './validation/index.js';
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AAEH,kBAAkB;AAClB,OAAO,EACL,uBAAuB,EACvB,4BAA4B,EAC5B,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,uBAAuB,CAAC;AAE/B,iBAAiB;AACjB,OAAO,EACL,aAAa,EACb,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAEzB,0BAA0B;AAC1B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE3D,oBAAoB;AACpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,uBAAuB;AACvB,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,GAKjC,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for secure logging operations.
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for sanitizing data before logging to prevent
|
|
5
|
+
* sensitive information leakage. It handles circular references, prototype pollution,
|
|
6
|
+
* and provides protection against DoS attacks through depth limiting.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Options for customizing data sanitization behavior.
|
|
12
|
+
*/
|
|
13
|
+
export interface SanitizeOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Additional key patterns to treat as sensitive and redact.
|
|
16
|
+
* These are added to the default list of sensitive keys.
|
|
17
|
+
*/
|
|
18
|
+
additionalSensitiveKeys?: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Sanitizes data for secure logging by redacting sensitive information.
|
|
22
|
+
*
|
|
23
|
+
* This function deeply traverses objects, arrays, and errors to redact sensitive
|
|
24
|
+
* fields while preserving structure for debugging. It provides multiple layers of
|
|
25
|
+
* protection against common security and reliability issues:
|
|
26
|
+
*
|
|
27
|
+
* **Security Features:**
|
|
28
|
+
* - Redacts sensitive keys (token, password, secret, auth, credential)
|
|
29
|
+
* - Prevents prototype pollution by skipping dangerous keys
|
|
30
|
+
* - Uses case-insensitive pattern matching for sensitive data detection
|
|
31
|
+
*
|
|
32
|
+
* **Reliability Features:**
|
|
33
|
+
* - Handles circular references using WeakSet tracking
|
|
34
|
+
* - Limits recursion depth to prevent stack overflow (max 100 levels)
|
|
35
|
+
* - Preserves non-serializable types (functions, symbols, bigints)
|
|
36
|
+
*
|
|
37
|
+
* **Type Support:**
|
|
38
|
+
* - Primitives: returned as-is (strings, numbers, booleans, null, undefined)
|
|
39
|
+
* - Functions: converted to `[Function: name]` strings
|
|
40
|
+
* - Symbols: converted to string representation
|
|
41
|
+
* - BigInts: converted to string with 'n' suffix
|
|
42
|
+
* - Errors: extracts name, message, stack, and other properties
|
|
43
|
+
* - Arrays: recursively sanitized element by element
|
|
44
|
+
* - Maps: converted to object with `__type` and `entries`; if key is sensitive, both key and value are redacted
|
|
45
|
+
* - Sets: converted to object with `__type` and `values`
|
|
46
|
+
* - Objects: recursively sanitized key by key with sensitive data redacted
|
|
47
|
+
*
|
|
48
|
+
* @param data - The data to sanitize (any type)
|
|
49
|
+
* @param options - Optional configuration for sanitization
|
|
50
|
+
* @returns A new sanitized version with sensitive information redacted
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* Basic usage with sensitive data:
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const data = {
|
|
56
|
+
* username: 'john',
|
|
57
|
+
* apiToken: 'secret-key-123',
|
|
58
|
+
* settings: { theme: 'dark' }
|
|
59
|
+
* };
|
|
60
|
+
*
|
|
61
|
+
* const sanitized = sanitizeDataForLogging(data);
|
|
62
|
+
* // Result: { username: 'john', apiToken: '***', settings: { theme: 'dark' } }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* Usage with custom sensitive keys:
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const data = {
|
|
69
|
+
* apiKey: 'secret',
|
|
70
|
+
* ssn: '123-45-6789'
|
|
71
|
+
* };
|
|
72
|
+
*
|
|
73
|
+
* const sanitized = sanitizeDataForLogging(data, {
|
|
74
|
+
* additionalSensitiveKeys: ['ssn']
|
|
75
|
+
* });
|
|
76
|
+
* // Result: { apiKey: '***', ssn: '***' } // 'apiKey' contains 'key' which might not match default, but 'ssn' will match.
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* Handling circular references:
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const obj: any = { name: 'test' };
|
|
83
|
+
* obj.self = obj;
|
|
84
|
+
*
|
|
85
|
+
* const sanitized = sanitizeDataForLogging(obj);
|
|
86
|
+
* // Result: { name: 'test', self: '[Circular]' }
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* Error object sanitization:
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const error = new Error('Failed to authenticate');
|
|
93
|
+
* error.apiToken = 'secret';
|
|
94
|
+
*
|
|
95
|
+
* const sanitized = sanitizeDataForLogging(error);
|
|
96
|
+
* // Result: { name: 'Error', message: 'Failed...', stack: '...', apiToken: '***' }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function sanitizeDataForLogging(data: unknown, options?: SanitizeOptions): unknown;
|
|
100
|
+
//# sourceMappingURL=logger-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-utils.d.ts","sourceRoot":"","sources":["../../lib/utils/logger-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA6BH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAC;CACpC;AAsED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,OAAO,EACb,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAmHT"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for secure logging operations.
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for sanitizing data before logging to prevent
|
|
5
|
+
* sensitive information leakage. It handles circular references, prototype pollution,
|
|
6
|
+
* and provides protection against DoS attacks through depth limiting.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* List of sensitive key patterns to redact in logged data.
|
|
12
|
+
* These patterns are matched case-insensitively.
|
|
13
|
+
*/
|
|
14
|
+
const SENSITIVE_KEYS = ['token', 'auth', 'password', 'secret', 'credential'];
|
|
15
|
+
/**
|
|
16
|
+
* Pre-compiled regular expression for efficient sensitive key detection.
|
|
17
|
+
* Matches any key containing tokens like 'token', 'auth', 'password', etc.
|
|
18
|
+
*/
|
|
19
|
+
const SENSITIVE_KEY_PATTERN = new RegExp(SENSITIVE_KEYS.join('|'), 'i');
|
|
20
|
+
/**
|
|
21
|
+
* Keys that are dangerous for prototype pollution attacks.
|
|
22
|
+
* These keys are always skipped during sanitization to prevent security vulnerabilities.
|
|
23
|
+
*/
|
|
24
|
+
const DANGEROUS_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
25
|
+
/**
|
|
26
|
+
* Maximum recursion depth to prevent stack overflow from deeply nested objects.
|
|
27
|
+
* This protects against DoS attacks using maliciously crafted data structures.
|
|
28
|
+
*/
|
|
29
|
+
const MAX_DEPTH = 100;
|
|
30
|
+
/**
|
|
31
|
+
* Cache for compiled RegExp patterns to avoid recompilation on every call.
|
|
32
|
+
* Key is the sorted, joined list of sensitive keys.
|
|
33
|
+
*/
|
|
34
|
+
const regexCache = new Map();
|
|
35
|
+
/**
|
|
36
|
+
* Maximum allowed length for individual custom sensitive key pattern.
|
|
37
|
+
* This prevents ReDoS attacks from excessively long or complex patterns.
|
|
38
|
+
*/
|
|
39
|
+
const MAX_PATTERN_LENGTH = 100;
|
|
40
|
+
/**
|
|
41
|
+
* Validates custom sensitive keys to prevent ReDoS attacks.
|
|
42
|
+
* @param keys - Array of custom sensitive key patterns
|
|
43
|
+
* @throws {TypeError} If any key is invalid
|
|
44
|
+
*/
|
|
45
|
+
function validateSensitiveKeys(keys) {
|
|
46
|
+
for (const key of keys) {
|
|
47
|
+
if (typeof key !== 'string') {
|
|
48
|
+
throw new TypeError(`Invalid sensitive key: expected string, got ${typeof key}`);
|
|
49
|
+
}
|
|
50
|
+
if (key.length === 0) {
|
|
51
|
+
throw new TypeError('Sensitive key cannot be empty');
|
|
52
|
+
}
|
|
53
|
+
if (key.length > MAX_PATTERN_LENGTH) {
|
|
54
|
+
throw new TypeError(`Sensitive key too long (max ${MAX_PATTERN_LENGTH} characters): ${key.slice(0, 20)}...`);
|
|
55
|
+
}
|
|
56
|
+
// Check for potentially dangerous regex patterns
|
|
57
|
+
if (/[*+{].*[*+{]/.test(key)) {
|
|
58
|
+
throw new TypeError(`Potentially dangerous regex pattern detected: ${key}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Gets or creates a cached RegExp for the given sensitive keys.
|
|
64
|
+
* @param additionalKeys - Additional keys to include in the pattern
|
|
65
|
+
* @returns Compiled RegExp for matching sensitive keys
|
|
66
|
+
*/
|
|
67
|
+
function getSensitivePattern(additionalKeys = []) {
|
|
68
|
+
if (additionalKeys.length === 0) {
|
|
69
|
+
return SENSITIVE_KEY_PATTERN;
|
|
70
|
+
}
|
|
71
|
+
// Validate custom keys before using them
|
|
72
|
+
validateSensitiveKeys(additionalKeys);
|
|
73
|
+
// Create cache key from sorted list of all keys
|
|
74
|
+
const allKeys = [...SENSITIVE_KEYS, ...additionalKeys].sort();
|
|
75
|
+
const cacheKey = allKeys.join('|');
|
|
76
|
+
// Return cached pattern if available
|
|
77
|
+
let pattern = regexCache.get(cacheKey);
|
|
78
|
+
if (!pattern) {
|
|
79
|
+
pattern = new RegExp(cacheKey, 'i');
|
|
80
|
+
regexCache.set(cacheKey, pattern);
|
|
81
|
+
}
|
|
82
|
+
return pattern;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Sanitizes data for secure logging by redacting sensitive information.
|
|
86
|
+
*
|
|
87
|
+
* This function deeply traverses objects, arrays, and errors to redact sensitive
|
|
88
|
+
* fields while preserving structure for debugging. It provides multiple layers of
|
|
89
|
+
* protection against common security and reliability issues:
|
|
90
|
+
*
|
|
91
|
+
* **Security Features:**
|
|
92
|
+
* - Redacts sensitive keys (token, password, secret, auth, credential)
|
|
93
|
+
* - Prevents prototype pollution by skipping dangerous keys
|
|
94
|
+
* - Uses case-insensitive pattern matching for sensitive data detection
|
|
95
|
+
*
|
|
96
|
+
* **Reliability Features:**
|
|
97
|
+
* - Handles circular references using WeakSet tracking
|
|
98
|
+
* - Limits recursion depth to prevent stack overflow (max 100 levels)
|
|
99
|
+
* - Preserves non-serializable types (functions, symbols, bigints)
|
|
100
|
+
*
|
|
101
|
+
* **Type Support:**
|
|
102
|
+
* - Primitives: returned as-is (strings, numbers, booleans, null, undefined)
|
|
103
|
+
* - Functions: converted to `[Function: name]` strings
|
|
104
|
+
* - Symbols: converted to string representation
|
|
105
|
+
* - BigInts: converted to string with 'n' suffix
|
|
106
|
+
* - Errors: extracts name, message, stack, and other properties
|
|
107
|
+
* - Arrays: recursively sanitized element by element
|
|
108
|
+
* - Maps: converted to object with `__type` and `entries`; if key is sensitive, both key and value are redacted
|
|
109
|
+
* - Sets: converted to object with `__type` and `values`
|
|
110
|
+
* - Objects: recursively sanitized key by key with sensitive data redacted
|
|
111
|
+
*
|
|
112
|
+
* @param data - The data to sanitize (any type)
|
|
113
|
+
* @param options - Optional configuration for sanitization
|
|
114
|
+
* @returns A new sanitized version with sensitive information redacted
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* Basic usage with sensitive data:
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const data = {
|
|
120
|
+
* username: 'john',
|
|
121
|
+
* apiToken: 'secret-key-123',
|
|
122
|
+
* settings: { theme: 'dark' }
|
|
123
|
+
* };
|
|
124
|
+
*
|
|
125
|
+
* const sanitized = sanitizeDataForLogging(data);
|
|
126
|
+
* // Result: { username: 'john', apiToken: '***', settings: { theme: 'dark' } }
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* Usage with custom sensitive keys:
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const data = {
|
|
133
|
+
* apiKey: 'secret',
|
|
134
|
+
* ssn: '123-45-6789'
|
|
135
|
+
* };
|
|
136
|
+
*
|
|
137
|
+
* const sanitized = sanitizeDataForLogging(data, {
|
|
138
|
+
* additionalSensitiveKeys: ['ssn']
|
|
139
|
+
* });
|
|
140
|
+
* // Result: { apiKey: '***', ssn: '***' } // 'apiKey' contains 'key' which might not match default, but 'ssn' will match.
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* Handling circular references:
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const obj: any = { name: 'test' };
|
|
147
|
+
* obj.self = obj;
|
|
148
|
+
*
|
|
149
|
+
* const sanitized = sanitizeDataForLogging(obj);
|
|
150
|
+
* // Result: { name: 'test', self: '[Circular]' }
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* Error object sanitization:
|
|
155
|
+
* ```typescript
|
|
156
|
+
* const error = new Error('Failed to authenticate');
|
|
157
|
+
* error.apiToken = 'secret';
|
|
158
|
+
*
|
|
159
|
+
* const sanitized = sanitizeDataForLogging(error);
|
|
160
|
+
* // Result: { name: 'Error', message: 'Failed...', stack: '...', apiToken: '***' }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export function sanitizeDataForLogging(data, options = {}) {
|
|
164
|
+
const seen = new WeakSet();
|
|
165
|
+
// Get cached regex pattern for sensitive key detection
|
|
166
|
+
const sensitivePattern = getSensitivePattern(options.additionalSensitiveKeys);
|
|
167
|
+
function isSensitive(key) {
|
|
168
|
+
return sensitivePattern.test(key);
|
|
169
|
+
}
|
|
170
|
+
// Pre-define Error property exclusion Set for performance
|
|
171
|
+
const ERROR_BASE_PROPS = new Set(['name', 'message', 'stack']);
|
|
172
|
+
function sanitize(value, depth = 0) {
|
|
173
|
+
// Depth limit check
|
|
174
|
+
if (depth >= MAX_DEPTH) {
|
|
175
|
+
return '[Max Depth Exceeded]';
|
|
176
|
+
}
|
|
177
|
+
// Primitives and null
|
|
178
|
+
if (value === null || typeof value !== 'object') {
|
|
179
|
+
if (typeof value === 'function') {
|
|
180
|
+
return `[Function: ${value.name || 'anonymous'}]`;
|
|
181
|
+
}
|
|
182
|
+
if (typeof value === 'symbol') {
|
|
183
|
+
return value.toString();
|
|
184
|
+
}
|
|
185
|
+
if (typeof value === 'bigint') {
|
|
186
|
+
return `${value.toString()}n`;
|
|
187
|
+
}
|
|
188
|
+
return value;
|
|
189
|
+
}
|
|
190
|
+
// Circular reference check
|
|
191
|
+
if (seen.has(value)) {
|
|
192
|
+
return '[Circular]';
|
|
193
|
+
}
|
|
194
|
+
seen.add(value);
|
|
195
|
+
// Handle Error objects
|
|
196
|
+
if (value instanceof Error) {
|
|
197
|
+
const errorObj = {
|
|
198
|
+
name: value.name,
|
|
199
|
+
message: value.message,
|
|
200
|
+
stack: value.stack,
|
|
201
|
+
};
|
|
202
|
+
// Copy other properties (using getOwnPropertyNames to include non-enumerable properties)
|
|
203
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
204
|
+
if (!ERROR_BASE_PROPS.has(key)) {
|
|
205
|
+
if (isSensitive(key)) {
|
|
206
|
+
errorObj[key] = '***';
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
const errorValue = value;
|
|
210
|
+
errorObj[key] = sanitize(errorValue[key], depth + 1);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return errorObj;
|
|
215
|
+
}
|
|
216
|
+
// Handle Map (preserve type information and check keys for sensitive data)
|
|
217
|
+
if (value instanceof Map) {
|
|
218
|
+
return {
|
|
219
|
+
__type: 'Map',
|
|
220
|
+
entries: Array.from(value.entries()).map(([k, v]) => {
|
|
221
|
+
// Check if key itself is sensitive (when it's a string)
|
|
222
|
+
const isKeySensitive = typeof k === 'string' && isSensitive(k);
|
|
223
|
+
const sanitizedKey = isKeySensitive ? '***' : sanitize(k, depth + 1);
|
|
224
|
+
// If key is sensitive, redact the value as well to prevent leakage
|
|
225
|
+
const sanitizedValue = isKeySensitive
|
|
226
|
+
? '***'
|
|
227
|
+
: sanitize(v, depth + 1);
|
|
228
|
+
return [sanitizedKey, sanitizedValue];
|
|
229
|
+
}),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
// Handle Set (preserve type information)
|
|
233
|
+
if (value instanceof Set) {
|
|
234
|
+
return {
|
|
235
|
+
__type: 'Set',
|
|
236
|
+
values: Array.from(value).map((v) => sanitize(v, depth + 1)),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
// Handle Arrays
|
|
240
|
+
if (Array.isArray(value)) {
|
|
241
|
+
return value.map((item) => sanitize(item, depth + 1));
|
|
242
|
+
}
|
|
243
|
+
// Handle Plain Objects
|
|
244
|
+
const sanitizedObj = {};
|
|
245
|
+
const obj = value;
|
|
246
|
+
// Iterate over own enumerable properties
|
|
247
|
+
for (const key of Object.keys(obj)) {
|
|
248
|
+
// Skip dangerous prototype pollution keys
|
|
249
|
+
if (DANGEROUS_KEYS.has(key)) {
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
// Redact sensitive keys
|
|
253
|
+
if (isSensitive(key)) {
|
|
254
|
+
sanitizedObj[key] = '***';
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
// Recursively sanitize
|
|
258
|
+
sanitizedObj[key] = sanitize(obj[key], depth + 1);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return sanitizedObj;
|
|
262
|
+
}
|
|
263
|
+
return sanitize(data);
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=logger-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-utils.js","sourceRoot":"","sources":["../../lib/utils/logger-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;GAGG;AACH,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;AAE7E;;;GAGG;AACH,MAAM,qBAAqB,GAAG,IAAI,MAAM,CACtC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,EACxB,GAAG,CACJ,CAAC;AAEF;;;GAGG;AACH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,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CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,0CAA0C;YAC1C,IAAI,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC5B,SAAS;YACX,CAAC;YAED,wBAAwB;YACxB,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;gBACrB,YAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACN,uBAAuB;gBACvB,YAAY,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time-related constants for ProtoPedia timestamp handling.
|
|
3
|
+
*
|
|
4
|
+
* @module utils/time/constants
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* JST (Japan Standard Time) offset in milliseconds.
|
|
8
|
+
*
|
|
9
|
+
* JST is UTC+9, which corresponds to 9 hours * 60 minutes * 60 seconds * 1000 ms.
|
|
10
|
+
* This constant is used to convert JST timestamps (without explicit offset)
|
|
11
|
+
* to UTC.
|
|
12
|
+
*/
|
|
13
|
+
export declare const JST_OFFSET_MS: number;
|
|
14
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../lib/utils/time/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,QAAqB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time-related constants for ProtoPedia timestamp handling.
|
|
3
|
+
*
|
|
4
|
+
* @module utils/time/constants
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* JST (Japan Standard Time) offset in milliseconds.
|
|
8
|
+
*
|
|
9
|
+
* JST is UTC+9, which corresponds to 9 hours * 60 minutes * 60 seconds * 1000 ms.
|
|
10
|
+
* This constant is used to convert JST timestamps (without explicit offset)
|
|
11
|
+
* to UTC.
|
|
12
|
+
*/
|
|
13
|
+
export const JST_OFFSET_MS = 9 * 60 * 60 * 1000;
|
|
14
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../lib/utils/time/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time utilities for ProtoPedia timestamp handling.
|
|
3
|
+
*
|
|
4
|
+
* Provides parsers and normalizers for ProtoPedia-specific JST timestamps
|
|
5
|
+
* and W3C-DTF (W3C Date and Time Formats) compliant timestamps.
|
|
6
|
+
*
|
|
7
|
+
* @module utils/time
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import {
|
|
12
|
+
* parseProtoPediaTimestamp,
|
|
13
|
+
* parseW3cDtfTimestamp,
|
|
14
|
+
* JST_OFFSET_MS,
|
|
15
|
+
* } from 'promidas/utils/time';
|
|
16
|
+
*
|
|
17
|
+
* // Parse ProtoPedia format (JST)
|
|
18
|
+
* parseProtoPediaTimestamp('2025-11-14 12:03:07.0');
|
|
19
|
+
* // => '2025-11-14T03:03:07.000Z'
|
|
20
|
+
*
|
|
21
|
+
* // Parse W3C-DTF format
|
|
22
|
+
* parseW3cDtfTimestamp('2025-11-14T12:03:07+09:00');
|
|
23
|
+
* // => '2025-11-14T03:03:07.000Z'
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export { JST_OFFSET_MS } from './constants.js';
|
|
27
|
+
export { parseProtoPediaTimestamp, parseW3cDtfTimestamp } from './parser.js';
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/utils/time/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time utilities for ProtoPedia timestamp handling.
|
|
3
|
+
*
|
|
4
|
+
* Provides parsers and normalizers for ProtoPedia-specific JST timestamps
|
|
5
|
+
* and W3C-DTF (W3C Date and Time Formats) compliant timestamps.
|
|
6
|
+
*
|
|
7
|
+
* @module utils/time
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import {
|
|
12
|
+
* parseProtoPediaTimestamp,
|
|
13
|
+
* parseW3cDtfTimestamp,
|
|
14
|
+
* JST_OFFSET_MS,
|
|
15
|
+
* } from 'promidas/utils/time';
|
|
16
|
+
*
|
|
17
|
+
* // Parse ProtoPedia format (JST)
|
|
18
|
+
* parseProtoPediaTimestamp('2025-11-14 12:03:07.0');
|
|
19
|
+
* // => '2025-11-14T03:03:07.000Z'
|
|
20
|
+
*
|
|
21
|
+
* // Parse W3C-DTF format
|
|
22
|
+
* parseW3cDtfTimestamp('2025-11-14T12:03:07+09:00');
|
|
23
|
+
* // => '2025-11-14T03:03:07.000Z'
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export { JST_OFFSET_MS } from './constants.js';
|
|
27
|
+
export { parseProtoPediaTimestamp, parseW3cDtfTimestamp } from './parser.js';
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/utils/time/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
|