@poppinss/utils 7.0.0-next.3 → 7.0.0-next.4
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/build/exception-L7vjh-Gv.js +2 -0
- package/build/index.js +96 -167
- package/build/is_script_file-CbSEfxE_.js +20 -0
- package/build/main-_zxQ-frM.js +535 -0
- package/build/modules/assert.js +8 -21
- package/build/modules/base64.js +24 -41
- package/build/modules/exception.js +2 -12
- package/build/modules/fs/main.js +51 -75
- package/build/modules/json/main.js +2 -8
- package/build/modules/string/main.js +1 -4
- package/build/modules/string/string_builder.js +1 -4
- package/build/modules/types.js +1 -1
- package/build/src/compose.d.ts +4 -4
- package/package.json +27 -24
- package/build/chunk-SKNTF5Q5.js +0 -14
- package/build/chunk-XFX47BKO.js +0 -23
- package/build/chunk-YFSCSJNE.js +0 -33
package/build/index.js
CHANGED
|
@@ -1,179 +1,108 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "./
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Returns the original value
|
|
40
|
-
*/
|
|
41
|
-
release() {
|
|
42
|
-
return this.#value;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Transform the original value and create a new
|
|
46
|
-
* secret from it.
|
|
47
|
-
*/
|
|
48
|
-
map(transformFunc) {
|
|
49
|
-
return new _Secret(transformFunc(this.#value));
|
|
50
|
-
}
|
|
1
|
+
import { n as safeParse, t as safeStringify } from "./main-_zxQ-frM.js";
|
|
2
|
+
import { n as naturalSort, t as isScriptFile } from "./is_script_file-CbSEfxE_.js";
|
|
3
|
+
import { r as RuntimeException } from "./exception-L7vjh-Gv.js";
|
|
4
|
+
import { flattie } from "flattie";
|
|
5
|
+
import { Buffer } from "node:buffer";
|
|
6
|
+
import { timingSafeEqual } from "node:crypto";
|
|
7
|
+
import string from "@poppinss/string";
|
|
8
|
+
import lodash from "@poppinss/utils/lodash";
|
|
9
|
+
const REDACTED = "[redacted]";
|
|
10
|
+
var Secret = class Secret {
|
|
11
|
+
#value;
|
|
12
|
+
#keyword;
|
|
13
|
+
constructor(value, redactedKeyword) {
|
|
14
|
+
this.#value = value;
|
|
15
|
+
this.#keyword = redactedKeyword || REDACTED;
|
|
16
|
+
}
|
|
17
|
+
toJSON() {
|
|
18
|
+
return this.#keyword;
|
|
19
|
+
}
|
|
20
|
+
valueOf() {
|
|
21
|
+
return this.#keyword;
|
|
22
|
+
}
|
|
23
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
24
|
+
return this.#keyword;
|
|
25
|
+
}
|
|
26
|
+
toLocaleString() {
|
|
27
|
+
return this.#keyword;
|
|
28
|
+
}
|
|
29
|
+
toString() {
|
|
30
|
+
return this.#keyword;
|
|
31
|
+
}
|
|
32
|
+
release() {
|
|
33
|
+
return this.#value;
|
|
34
|
+
}
|
|
35
|
+
map(transformFunc) {
|
|
36
|
+
return new Secret(transformFunc(this.#value));
|
|
37
|
+
}
|
|
51
38
|
};
|
|
52
|
-
|
|
53
|
-
// src/compose.ts
|
|
54
39
|
function compose(superclass, ...mixins) {
|
|
55
|
-
|
|
40
|
+
return mixins.reduce((c, mixin) => mixin(c), superclass);
|
|
56
41
|
}
|
|
57
|
-
|
|
58
|
-
// src/flatten.ts
|
|
59
|
-
import { flattie } from "flattie";
|
|
60
42
|
function flatten(input, glue, keepNullish) {
|
|
61
|
-
|
|
43
|
+
return flattie(input, glue, keepNullish);
|
|
62
44
|
}
|
|
63
|
-
|
|
64
|
-
// src/safe_equal.ts
|
|
65
|
-
import { Buffer } from "buffer";
|
|
66
|
-
import { timingSafeEqual } from "crypto";
|
|
67
45
|
function safeEqual(trustedValue, userInput) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
Buffer.from(trustedValue),
|
|
78
|
-
Buffer.from(userInput)
|
|
79
|
-
);
|
|
46
|
+
if (typeof trustedValue === "string" && typeof userInput === "string") {
|
|
47
|
+
const trustedLength = Buffer.byteLength(trustedValue);
|
|
48
|
+
const trustedValueBuffer = Buffer.alloc(trustedLength, 0, "utf-8");
|
|
49
|
+
trustedValueBuffer.write(trustedValue);
|
|
50
|
+
const userValueBuffer = Buffer.alloc(trustedLength, 0, "utf-8");
|
|
51
|
+
userValueBuffer.write(userInput);
|
|
52
|
+
return timingSafeEqual(trustedValueBuffer, userValueBuffer) && trustedLength === Buffer.byteLength(userInput);
|
|
53
|
+
}
|
|
54
|
+
return timingSafeEqual(Buffer.from(trustedValue), Buffer.from(userInput));
|
|
80
55
|
}
|
|
81
|
-
|
|
82
|
-
// src/import_default.ts
|
|
83
56
|
async function importDefault(importFn, filePath) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
throw new RuntimeException(errorMessage, {
|
|
88
|
-
cause: {
|
|
89
|
-
source: importFn
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
return moduleExports.default;
|
|
57
|
+
const moduleExports = await importFn();
|
|
58
|
+
if (!("default" in moduleExports)) throw new RuntimeException(filePath ? `Missing "export default" in module "${filePath}"` : `Missing "export default" from lazy import "${importFn}"`, { cause: { source: importFn } });
|
|
59
|
+
return moduleExports.default;
|
|
94
60
|
}
|
|
95
|
-
|
|
96
|
-
// src/message_builder.ts
|
|
97
|
-
import string from "@poppinss/string";
|
|
98
61
|
var MessageBuilder = class {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
* Verifies the message for expiry and purpose.
|
|
125
|
-
*/
|
|
126
|
-
verify(message, purpose) {
|
|
127
|
-
const parsed = safeParse(message);
|
|
128
|
-
if (typeof parsed !== "object" || !parsed) {
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
if (!parsed.message) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
if (parsed.purpose !== purpose) {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
if (this.#isExpired(parsed)) {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
return parsed.message;
|
|
141
|
-
}
|
|
62
|
+
#getExpiryDate(expiresIn) {
|
|
63
|
+
if (!expiresIn) return;
|
|
64
|
+
const expiryMs = string.milliseconds.parse(expiresIn);
|
|
65
|
+
return new Date(Date.now() + expiryMs);
|
|
66
|
+
}
|
|
67
|
+
#isExpired(message) {
|
|
68
|
+
if (!message.expiryDate) return false;
|
|
69
|
+
const expiryDate = new Date(message.expiryDate);
|
|
70
|
+
return Number.isNaN(expiryDate.getTime()) || expiryDate < /* @__PURE__ */ new Date();
|
|
71
|
+
}
|
|
72
|
+
build(message, expiresIn, purpose) {
|
|
73
|
+
return safeStringify({
|
|
74
|
+
message,
|
|
75
|
+
purpose,
|
|
76
|
+
expiryDate: this.#getExpiryDate(expiresIn)
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
verify(message, purpose) {
|
|
80
|
+
const parsed = safeParse(message);
|
|
81
|
+
if (typeof parsed !== "object" || !parsed) return null;
|
|
82
|
+
if (!parsed.message) return null;
|
|
83
|
+
if (parsed.purpose !== purpose) return null;
|
|
84
|
+
if (this.#isExpired(parsed)) return null;
|
|
85
|
+
return parsed.message;
|
|
86
|
+
}
|
|
142
87
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
value: typeof strategy === "function" ? strategy(value) : lodash.cloneDeep(value),
|
|
163
|
-
configurable: true,
|
|
164
|
-
enumerable: true,
|
|
165
|
-
writable: true
|
|
166
|
-
});
|
|
167
|
-
}
|
|
88
|
+
function defineStaticProperty(self, propertyName, { initialValue, strategy }) {
|
|
89
|
+
if (!self.hasOwnProperty(propertyName)) {
|
|
90
|
+
const value = self[propertyName];
|
|
91
|
+
if (strategy === "define" || value === void 0) {
|
|
92
|
+
Object.defineProperty(self, propertyName, {
|
|
93
|
+
value: initialValue,
|
|
94
|
+
configurable: true,
|
|
95
|
+
enumerable: true,
|
|
96
|
+
writable: true
|
|
97
|
+
});
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
Object.defineProperty(self, propertyName, {
|
|
101
|
+
value: typeof strategy === "function" ? strategy(value) : lodash.cloneDeep(value),
|
|
102
|
+
configurable: true,
|
|
103
|
+
enumerable: true,
|
|
104
|
+
writable: true
|
|
105
|
+
});
|
|
106
|
+
}
|
|
168
107
|
}
|
|
169
|
-
export {
|
|
170
|
-
MessageBuilder,
|
|
171
|
-
Secret,
|
|
172
|
-
compose,
|
|
173
|
-
defineStaticProperty,
|
|
174
|
-
flatten,
|
|
175
|
-
importDefault,
|
|
176
|
-
isScriptFile,
|
|
177
|
-
naturalSort,
|
|
178
|
-
safeEqual
|
|
179
|
-
};
|
|
108
|
+
export { MessageBuilder, Secret, compose, defineStaticProperty, flatten, importDefault, isScriptFile, naturalSort, safeEqual };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { extname } from "node:path";
|
|
2
|
+
function naturalSort(current, next) {
|
|
3
|
+
return current.localeCompare(next, void 0, {
|
|
4
|
+
numeric: true,
|
|
5
|
+
sensitivity: "base"
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
const JS_MODULES = [
|
|
9
|
+
".js",
|
|
10
|
+
".json",
|
|
11
|
+
".cjs",
|
|
12
|
+
".mjs"
|
|
13
|
+
];
|
|
14
|
+
function isScriptFile(filePath) {
|
|
15
|
+
const ext = extname(filePath);
|
|
16
|
+
if (JS_MODULES.includes(ext)) return true;
|
|
17
|
+
if (ext === ".ts" && !filePath.endsWith(".d.ts")) return true;
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
export { naturalSort as n, isScriptFile as t };
|