@wener/common 2.0.5 → 2.0.6
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/lib/ai/qwen3vl/index.js +1 -1
- package/lib/ai/qwen3vl/utils.js +15 -15
- package/lib/ai/vision/DocLayoutElementTypeSchema.js +22 -22
- package/lib/ai/vision/ImageAnnotationSchema.js +63 -47
- package/lib/ai/vision/index.js +2 -2
- package/lib/ai/vision/resolveImageAnnotation.js +81 -95
- package/lib/cn/ChineseResidentIdNo.js +55 -41
- package/lib/cn/ChineseResidentIdNo.mod.js +6 -1
- package/lib/cn/ChineseResidentIdNo.test.js +22 -21
- package/lib/cn/DivisionCode.js +220 -235
- package/lib/cn/DivisionCode.mod.js +6 -1
- package/lib/cn/DivisionCode.test.js +92 -121
- package/lib/cn/Mod11.js +18 -37
- package/lib/cn/Mod31.js +23 -41
- package/lib/cn/UnifiedSocialCreditCode.js +143 -137
- package/lib/cn/UnifiedSocialCreditCode.mod.js +6 -1
- package/lib/cn/UnifiedSocialCreditCode.test.js +21 -15
- package/lib/cn/formatChineseAmount.js +46 -71
- package/lib/cn/index.js +6 -6
- package/lib/cn/mod.js +5 -3
- package/lib/cn/parseChineseNumber.js +81 -85
- package/lib/cn/parseChineseNumber.test.js +183 -261
- package/lib/cn/pinyin/cartesianProduct.js +19 -19
- package/lib/cn/pinyin/cartesianProduct.test.js +78 -178
- package/lib/cn/pinyin/loader.js +13 -11
- package/lib/cn/pinyin/preload.js +2 -1
- package/lib/cn/pinyin/toPinyin.test.js +149 -161
- package/lib/cn/pinyin/toPinyinPure.js +28 -23
- package/lib/cn/pinyin/transform.js +11 -11
- package/lib/cn/types.d.js +2 -2
- package/lib/consola/createStandardConsolaReporter.js +14 -15
- package/lib/consola/formatLogObject.js +149 -133
- package/lib/consola/formatLogObject.test.js +167 -178
- package/lib/consola/index.js +2 -2
- package/lib/data/formatSort.js +14 -12
- package/lib/data/formatSort.test.js +33 -33
- package/lib/data/index.js +3 -3
- package/lib/data/maybeNumber.js +23 -23
- package/lib/data/parseSort.js +75 -68
- package/lib/data/parseSort.test.js +196 -187
- package/lib/data/resolvePagination.js +38 -39
- package/lib/data/resolvePagination.test.js +228 -218
- package/lib/data/types.d.js +2 -2
- package/lib/dayjs/dayjs.js +20 -20
- package/lib/dayjs/formatDuration.js +56 -56
- package/lib/dayjs/formatDuration.test.js +63 -77
- package/lib/dayjs/index.js +4 -4
- package/lib/dayjs/parseDuration.js +21 -26
- package/lib/dayjs/parseRelativeTime.js +65 -66
- package/lib/dayjs/parseRelativeTime.test.js +227 -243
- package/lib/dayjs/resolveRelativeTime.js +73 -72
- package/lib/dayjs/resolveRelativeTime.test.js +296 -307
- package/lib/decimal/index.js +1 -1
- package/lib/decimal/parseDecimal.js +12 -12
- package/lib/drain3/Drain.js +303 -338
- package/lib/drain3/LogCluster.js +25 -25
- package/lib/drain3/Node.js +24 -24
- package/lib/drain3/TemplateMiner.js +197 -196
- package/lib/drain3/index.js +5 -5
- package/lib/drain3/persistence/FilePersistence.js +19 -19
- package/lib/drain3/persistence/MemoryPersistence.js +8 -8
- package/lib/drain3/persistence/PersistenceHandler.js +2 -2
- package/lib/drain3/types.js +2 -2
- package/lib/emittery/emitter.js +7 -7
- package/lib/emittery/index.js +1 -1
- package/lib/foundation/schema/SexType.js +15 -12
- package/lib/foundation/schema/index.js +1 -1
- package/lib/foundation/schema/parseSexType.js +15 -16
- package/lib/foundation/schema/types.js +8 -6
- package/lib/fs/FileSystemError.js +18 -18
- package/lib/fs/IFileSystem.d.js +2 -2
- package/lib/fs/MemoryFileSystem.test.js +172 -181
- package/lib/fs/createBrowserFileSystem.js +222 -235
- package/lib/fs/createMemoryFileSystem.js +472 -510
- package/lib/fs/createSandboxFileSystem.js +102 -101
- package/lib/fs/createWebDavFileSystem.js +162 -149
- package/lib/fs/createWebFileSystem.js +197 -220
- package/lib/fs/findMimeType.js +14 -14
- package/lib/fs/index.js +7 -7
- package/lib/fs/minio/createMinioFileSystem.js +959 -956
- package/lib/fs/minio/index.js +1 -1
- package/lib/fs/orpc/FileSystemContract.js +57 -57
- package/lib/fs/orpc/createContractClientFileSystem.js +88 -88
- package/lib/fs/orpc/index.js +2 -2
- package/lib/fs/orpc/server/createFileSystemContractImpl.js +62 -60
- package/lib/fs/orpc/server/index.js +1 -1
- package/lib/fs/s3/createS3MiniFileSystem.js +756 -737
- package/lib/fs/s3/index.js +1 -1
- package/lib/fs/s3/s3mini.test.js +524 -553
- package/lib/fs/scandir.js +56 -56
- package/lib/fs/server/createDatabaseFileSystem.js +834 -741
- package/lib/fs/server/createNodeFileSystem.js +407 -405
- package/lib/fs/server/dbfs.test.js +201 -214
- package/lib/fs/server/index.js +1 -1
- package/lib/fs/server/loadTestDatabase.js +40 -43
- package/lib/fs/tests/runFileSystemTest.js +352 -316
- package/lib/fs/types.js +17 -20
- package/lib/fs/utils/getFileUrl.js +24 -30
- package/lib/fs/utils.js +17 -17
- package/lib/fs/webdav/index.js +1 -1
- package/lib/index.js +2 -2
- package/lib/jsonschema/JsonSchema.js +216 -155
- package/lib/jsonschema/JsonSchema.test.js +123 -124
- package/lib/jsonschema/forEachJsonSchema.js +41 -41
- package/lib/jsonschema/index.js +2 -2
- package/lib/jsonschema/types.d.js +2 -2
- package/lib/meta/defineFileType.js +32 -38
- package/lib/meta/defineInit.js +39 -35
- package/lib/meta/defineMetadata.js +37 -34
- package/lib/meta/defineMetadata.test.js +13 -12
- package/lib/meta/index.js +3 -3
- package/lib/orpc/createOpenApiContractClient.js +26 -24
- package/lib/orpc/createRpcContractClient.js +37 -31
- package/lib/orpc/index.js +2 -2
- package/lib/orpc/resolveLinkPlugins.js +25 -25
- package/lib/password/PHC.js +187 -189
- package/lib/password/PHC.test.js +517 -535
- package/lib/password/Password.js +85 -80
- package/lib/password/Password.test.js +330 -364
- package/lib/password/createArgon2PasswordAlgorithm.js +50 -51
- package/lib/password/createBase64PasswordAlgorithm.js +11 -11
- package/lib/password/createBcryptPasswordAlgorithm.js +20 -18
- package/lib/password/createPBKDF2PasswordAlgorithm.js +65 -52
- package/lib/password/createScryptPasswordAlgorithm.js +74 -63
- package/lib/password/index.js +5 -5
- package/lib/password/server/index.js +1 -1
- package/lib/resource/Identifiable.js +2 -2
- package/lib/resource/ListQuery.js +42 -42
- package/lib/resource/getTitleOfResource.js +5 -5
- package/lib/resource/index.js +2 -2
- package/lib/resource/schema/AnyResourceSchema.js +91 -89
- package/lib/resource/schema/BaseResourceSchema.js +26 -26
- package/lib/resource/schema/ResourceActionType.js +117 -115
- package/lib/resource/schema/ResourceStatus.js +94 -92
- package/lib/resource/schema/ResourceType.js +25 -23
- package/lib/resource/schema/index.js +5 -5
- package/lib/resource/schema/types.js +86 -55
- package/lib/resource/schema/types.test.js +16 -13
- package/lib/s3/formatS3Url.js +60 -60
- package/lib/s3/formatS3Url.test.js +238 -261
- package/lib/s3/index.js +2 -2
- package/lib/s3/parseS3Url.js +61 -60
- package/lib/s3/parseS3Url.test.js +270 -269
- package/lib/schema/SchemaRegistry.js +41 -42
- package/lib/schema/SchemaRegistry.mod.js +1 -1
- package/lib/schema/TypeSchema.d.js +2 -2
- package/lib/schema/createSchemaData.js +113 -67
- package/lib/schema/findJsonSchemaByPath.js +28 -23
- package/lib/schema/formatZodError.js +112 -131
- package/lib/schema/formatZodError.test.js +192 -195
- package/lib/schema/getSchemaCache.js +7 -7
- package/lib/schema/getSchemaOptions.js +17 -16
- package/lib/schema/index.js +6 -6
- package/lib/schema/toJsonSchema.js +195 -189
- package/lib/schema/toJsonSchema.test.js +34 -26
- package/lib/schema/validate.js +105 -96
- package/lib/tools/generateSchema.js +40 -40
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +74 -74
- package/lib/utils/buildBaseUrl.js +8 -8
- package/lib/utils/buildRedactorFormSchema.js +54 -53
- package/lib/utils/getEstimateProcessTime.js +24 -19
- package/lib/utils/index.js +3 -3
- package/lib/utils/resolveFeatureOptions.js +9 -9
- package/package.json +14 -14
- package/src/ai/vision/index.ts +2 -2
- package/src/cn/index.ts +1 -2
- package/src/consola/index.ts +1 -1
- package/src/data/index.ts +3 -4
- package/src/data/resolvePagination.ts +2 -2
- package/src/dayjs/formatDuration.ts +8 -9
- package/src/dayjs/index.ts +1 -1
- package/src/dayjs/parseRelativeTime.ts +1 -1
- package/src/dayjs/resolveRelativeTime.ts +1 -1
- package/src/drain3/Drain.test.ts +2 -2
- package/src/drain3/index.ts +2 -4
- package/src/fs/createWebDavFileSystem.ts +2 -7
- package/src/fs/createWebFileSystem.ts +1 -1
- package/src/fs/index.ts +4 -4
- package/src/fs/minio/createMinioFileSystem.ts +2 -2
- package/src/fs/minio/index.ts +1 -1
- package/src/fs/s3/createS3MiniFileSystem.ts +1 -1
- package/src/fs/server/createDatabaseFileSystem.ts +84 -120
- package/src/fs/server/dbfs.test.ts +14 -10
- package/src/fs/server/index.ts +1 -0
- package/src/fs/server/loadTestDatabase.ts +8 -119
- package/src/jsonschema/index.ts +1 -1
- package/src/meta/index.ts +2 -3
- package/src/orm/createSqliteDialect.ts +17 -0
- package/src/orm/index.ts +1 -0
- package/src/orpc/createOpenApiContractClient.ts +1 -1
- package/src/orpc/index.ts +1 -1
- package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
- package/src/password/index.ts +2 -2
- package/src/resource/index.ts +3 -3
- package/src/resource/schema/index.ts +4 -4
- package/src/s3/index.ts +1 -1
- package/src/schema/SchemaRegistry.ts +1 -1
- package/src/schema/createSchemaData.ts +1 -1
- package/src/schema/findJsonSchemaByPath.ts +1 -1
- package/src/schema/index.ts +5 -5
- package/src/schema/validate.ts +1 -1
- package/src/utils/buildRedactorFormSchema.ts +1 -1
- package/src/utils/formatNumber.ts +18 -0
- package/src/utils/formatPercent.ts +17 -0
- package/src/utils/index.ts +3 -3
- package/src/utils/resolveFeatureOptions.ts +1 -1
|
@@ -1,53 +1,52 @@
|
|
|
1
|
-
import { maybeFunction } from
|
|
2
|
-
export function createArgon2PasswordAlgorithm({
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
};
|
|
1
|
+
import { maybeFunction } from '@wener/utils';
|
|
2
|
+
export function createArgon2PasswordAlgorithm({
|
|
3
|
+
type,
|
|
4
|
+
provide = async () => {
|
|
5
|
+
throw new Error('Please provide argon2');
|
|
6
|
+
// const { default: wasm } = await import('argon2-browser/dist/argon2.wasm');
|
|
7
|
+
// const argon2 = await WebAssembly.instantiateStreaming(fetch(wasm), {
|
|
8
|
+
// env: {
|
|
9
|
+
// memoryBase: 0,
|
|
10
|
+
// tableBase: 0,
|
|
11
|
+
// memory: new WebAssembly.Memory({ initial: 256 }),
|
|
12
|
+
// table: new WebAssembly.Table({ initial: 0, element: 'anyfunc' }),
|
|
13
|
+
// __memory_base: 0,
|
|
14
|
+
// __table_base: 0,
|
|
15
|
+
// },
|
|
16
|
+
// });
|
|
17
|
+
// console.log(argon2.instance.exports);
|
|
18
|
+
// const { hash } = argon2.instance.exports as any as typeof import('argon2-browser');
|
|
19
|
+
},
|
|
20
|
+
} = {}) {
|
|
21
|
+
// 0=Argon2d, 1=Argon2i, 2=Argon2id
|
|
22
|
+
const toType = {
|
|
23
|
+
argon2d: 0,
|
|
24
|
+
argon2i: 1,
|
|
25
|
+
argon2id: 2,
|
|
26
|
+
};
|
|
27
|
+
let mod;
|
|
28
|
+
const resolve = () => {
|
|
29
|
+
if (mod) return mod;
|
|
30
|
+
return Promise.resolve(maybeFunction(provide)).then((v) => (mod = v));
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
name: 'argon2',
|
|
34
|
+
ids: ['argon2i', 'argon2d', 'argon2id'],
|
|
35
|
+
async hash(password, opts) {
|
|
36
|
+
// const { hash } = await import('argon2');
|
|
37
|
+
const { hash } = await resolve();
|
|
38
|
+
const id = opts?.id;
|
|
39
|
+
return hash(password, {
|
|
40
|
+
salt: opts?.salt ? Buffer.from(opts.salt) : undefined,
|
|
41
|
+
raw: false,
|
|
42
|
+
type: toType[id || ''] ?? toType[type || ''],
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
async verify(password, hash) {
|
|
46
|
+
const { verify } = await resolve();
|
|
47
|
+
return verify(hash, password);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
//# sourceMappingURL=createArgon2PasswordAlgorithm.js.map
|
|
52
|
+
//# sourceMappingURL=createArgon2PasswordAlgorithm.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ArrayBuffers } from
|
|
1
|
+
import { ArrayBuffers } from '@wener/utils';
|
|
2
2
|
export function createBase64PasswordAlgorithm({ id = 'base64' } = {}) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
return {
|
|
4
|
+
name: id,
|
|
5
|
+
async hash(password) {
|
|
6
|
+
return `$${id}$$${ArrayBuffers.toBase64(password).replace(/=/g, '')}`;
|
|
7
|
+
},
|
|
8
|
+
async verify(password, _hash, opts) {
|
|
9
|
+
return Boolean(opts.hash) && ArrayBuffers.toString(opts.hash) === password;
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
//# sourceMappingURL=createBase64PasswordAlgorithm.js.map
|
|
14
|
+
//# sourceMappingURL=createBase64PasswordAlgorithm.js.map
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
export function createBcryptPasswordAlgorithm({
|
|
2
|
-
provider = ()=>import(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
export function createBcryptPasswordAlgorithm({
|
|
2
|
+
// provider = () => import('bcrypt').then((v) => v.default),
|
|
3
|
+
provider = () => import('bcryptjs').then((v) => v.default),
|
|
4
|
+
} = {}) {
|
|
5
|
+
// bcrypt or bcryptjs
|
|
6
|
+
return {
|
|
7
|
+
name: 'bcrypt',
|
|
8
|
+
async hash(password, opts) {
|
|
9
|
+
const { hash } = await provider();
|
|
10
|
+
return hash(password, opts?.rounds ?? 10);
|
|
11
|
+
},
|
|
12
|
+
async verify(password, hash) {
|
|
13
|
+
const { compare } = await provider();
|
|
14
|
+
if (hash.startsWith('$2y$')) {
|
|
15
|
+
hash = hash.replace(/^\$2y\$/, '$2a$');
|
|
16
|
+
}
|
|
17
|
+
return compare(password, hash);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
//# sourceMappingURL=createBcryptPasswordAlgorithm.js.map
|
|
22
|
+
//# sourceMappingURL=createBcryptPasswordAlgorithm.js.map
|
|
@@ -1,54 +1,67 @@
|
|
|
1
|
-
import { Errors } from
|
|
2
|
-
import { PHC } from
|
|
3
|
-
export function createPBKDF2PasswordAlgorithm({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
import { Errors } from '@wener/utils';
|
|
2
|
+
import { PHC } from './PHC.js';
|
|
3
|
+
export function createPBKDF2PasswordAlgorithm({
|
|
4
|
+
id,
|
|
5
|
+
digest,
|
|
6
|
+
iterations = 100000,
|
|
7
|
+
saltlen = 16,
|
|
8
|
+
keylen = digest === 'SHA-256' ? 32 : 64,
|
|
9
|
+
}) {
|
|
10
|
+
return {
|
|
11
|
+
name: id,
|
|
12
|
+
async hash(password, opts) {
|
|
13
|
+
let salt;
|
|
14
|
+
if (opts?.salt) {
|
|
15
|
+
salt = opts.salt;
|
|
16
|
+
} else {
|
|
17
|
+
salt = new Uint8Array(saltlen);
|
|
18
|
+
crypto.getRandomValues(salt);
|
|
19
|
+
}
|
|
20
|
+
const rounds = opts?.rounds ?? iterations;
|
|
21
|
+
let key = await crypto.subtle.importKey('raw', new TextEncoder().encode(password), 'PBKDF2', false, [
|
|
22
|
+
'deriveBits',
|
|
23
|
+
]);
|
|
24
|
+
let hash = await crypto.subtle.deriveBits(
|
|
25
|
+
{
|
|
26
|
+
name: 'PBKDF2',
|
|
27
|
+
iterations: rounds,
|
|
28
|
+
salt: salt,
|
|
29
|
+
hash: digest,
|
|
30
|
+
},
|
|
31
|
+
key,
|
|
32
|
+
keylen * 8,
|
|
33
|
+
);
|
|
34
|
+
return PHC.serialize({
|
|
35
|
+
id: opts?.id ?? id,
|
|
36
|
+
params: {
|
|
37
|
+
rounds,
|
|
38
|
+
},
|
|
39
|
+
salt,
|
|
40
|
+
hash: new Uint8Array(hash),
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
async verify(password, _, opts) {
|
|
44
|
+
const rounds = opts?.params?.rounds ?? iterations;
|
|
45
|
+
const salt = opts.salt;
|
|
46
|
+
const storedHash = opts.hash;
|
|
47
|
+
Errors.BadRequest.check(typeof rounds === 'number', 'Invalid rounds');
|
|
48
|
+
Errors.BadRequest.check(salt instanceof Uint8Array, 'Invalid salt');
|
|
49
|
+
Errors.BadRequest.check(storedHash instanceof Uint8Array, 'Invalid hash');
|
|
50
|
+
let key = await crypto.subtle.importKey('raw', new TextEncoder().encode(password), 'PBKDF2', false, [
|
|
51
|
+
'deriveBits',
|
|
52
|
+
]);
|
|
53
|
+
let hash = await crypto.subtle.deriveBits(
|
|
54
|
+
{
|
|
55
|
+
name: 'PBKDF2',
|
|
56
|
+
iterations: rounds,
|
|
57
|
+
salt: salt,
|
|
58
|
+
hash: digest,
|
|
59
|
+
},
|
|
60
|
+
key,
|
|
61
|
+
storedHash.length * 8,
|
|
62
|
+
);
|
|
63
|
+
return new Uint8Array(hash).every((v, i) => v === storedHash?.[i]);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
53
66
|
}
|
|
54
67
|
//# sourceMappingURL=createPBKDF2PasswordAlgorithm.js.map
|
|
@@ -1,66 +1,77 @@
|
|
|
1
|
-
import { randomBytes, scrypt, timingSafeEqual } from
|
|
2
|
-
import { Errors } from
|
|
3
|
-
import { PHC } from
|
|
1
|
+
import { randomBytes, scrypt, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { Errors } from '@wener/utils';
|
|
3
|
+
import { PHC } from './PHC.js';
|
|
4
4
|
export function createScryptPasswordAlgorithm(options = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
5
|
+
let id = options.id || 'scrypt';
|
|
6
|
+
options.cost ||= 2 ** 14;
|
|
7
|
+
options.blocksize ||= 8;
|
|
8
|
+
options.parallelism ||= 1;
|
|
9
|
+
options.saltlen ||= 16;
|
|
10
|
+
options.keylen ||= 32;
|
|
11
|
+
return {
|
|
12
|
+
name: id,
|
|
13
|
+
async hash(password, opts) {
|
|
14
|
+
const salt = opts?.salt || randomBytes(options.saltlen);
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
let N = options.cost;
|
|
17
|
+
let r = options.blocksize;
|
|
18
|
+
let p = options.parallelism;
|
|
19
|
+
scrypt(
|
|
20
|
+
password,
|
|
21
|
+
salt,
|
|
22
|
+
options.keylen,
|
|
23
|
+
{
|
|
24
|
+
N,
|
|
25
|
+
r,
|
|
26
|
+
p,
|
|
27
|
+
},
|
|
28
|
+
(err, derivedKey) => {
|
|
29
|
+
if (err) return reject(err);
|
|
30
|
+
resolve(
|
|
31
|
+
PHC.serialize({
|
|
32
|
+
id: opts?.id ?? id,
|
|
33
|
+
params: {
|
|
34
|
+
ln: N,
|
|
35
|
+
r: r,
|
|
36
|
+
p: p,
|
|
37
|
+
},
|
|
38
|
+
salt,
|
|
39
|
+
hash: derivedKey,
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
async verify(password, _hash, opts) {
|
|
47
|
+
try {
|
|
48
|
+
const salt = Errors.BadRequest.require(opts.salt);
|
|
49
|
+
const storedHash = Errors.BadRequest.require(opts.hash);
|
|
50
|
+
const N = parseInt(opts.params?.ln, 10);
|
|
51
|
+
const r = parseInt(opts.params?.r, 10);
|
|
52
|
+
const p = parseInt(opts.params?.p, 10);
|
|
53
|
+
const keylen = storedHash.length;
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
scrypt(
|
|
56
|
+
password,
|
|
57
|
+
salt,
|
|
58
|
+
keylen,
|
|
59
|
+
{
|
|
60
|
+
N,
|
|
61
|
+
r,
|
|
62
|
+
p,
|
|
63
|
+
},
|
|
64
|
+
(err, derivedKey) => {
|
|
65
|
+
if (err) return reject(err);
|
|
66
|
+
const isMatch = timingSafeEqual(derivedKey, storedHash);
|
|
67
|
+
resolve(isMatch);
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
} catch (_error) {
|
|
72
|
+
return Promise.resolve(false);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
65
76
|
}
|
|
66
77
|
//# sourceMappingURL=createScryptPasswordAlgorithm.js.map
|
package/lib/password/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
1
|
+
export { createArgon2PasswordAlgorithm } from './createArgon2PasswordAlgorithm.js';
|
|
2
|
+
export { createBase64PasswordAlgorithm } from './createBase64PasswordAlgorithm.js';
|
|
3
|
+
export { createBcryptPasswordAlgorithm } from './createBcryptPasswordAlgorithm.js';
|
|
4
|
+
export { Password } from './Password.js';
|
|
5
|
+
export { PHC } from './PHC.js';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createScryptPasswordAlgorithm } from
|
|
1
|
+
export { createScryptPasswordAlgorithm } from '../createScryptPasswordAlgorithm.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
|
2
2
|
|
|
3
|
-
//# sourceMappingURL=Identifiable.js.map
|
|
3
|
+
//# sourceMappingURL=Identifiable.js.map
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { z } from
|
|
2
|
-
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
|
|
3
|
+
const IntLikeSchema = z.coerce
|
|
4
|
+
.number()
|
|
5
|
+
.multipleOf(1)
|
|
6
|
+
.min(0)
|
|
7
|
+
.optional()
|
|
8
|
+
.overwrite((v) => v || undefined);
|
|
3
9
|
export const ListQuerySchema = z.object({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
id: z.coerce.string().optional(),
|
|
11
|
+
ids: z.array(z.coerce.string()).optional(),
|
|
12
|
+
filter: z.string().optional().describe('sql-like filter string'),
|
|
13
|
+
filters: z.array(z.any()).optional().describe('sql-like filter string'),
|
|
14
|
+
where: z.record(z.string(), z.any()).optional().describe('document query filter'),
|
|
15
|
+
search: z.string().optional(),
|
|
16
|
+
limit: IntLikeSchema,
|
|
17
|
+
offset: IntLikeSchema,
|
|
18
|
+
order: z.array(z.string()).optional().describe('order like "a,-b,c desc null last"'),
|
|
19
|
+
pageIndex: IntLikeSchema.describe('0-based page index'),
|
|
20
|
+
pageNumber: IntLikeSchema.describe('1-based page number'),
|
|
21
|
+
pageSize: IntLikeSchema,
|
|
22
|
+
cursor: z.string().optional(),
|
|
23
|
+
deleted: z.coerce.boolean().optional(),
|
|
18
24
|
});
|
|
19
25
|
export function resolveListQuery(target, ...args) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
...b.filters || []
|
|
40
|
-
],
|
|
41
|
-
search: b.search || a.search
|
|
42
|
-
};
|
|
43
|
-
}, target || {});
|
|
44
|
-
return ListQuerySchema.parse(out);
|
|
26
|
+
let out = args.reduce((a, source) => {
|
|
27
|
+
if (typeof source === 'function') {
|
|
28
|
+
const result = source(a);
|
|
29
|
+
// do not use the result as merge source
|
|
30
|
+
return result || a;
|
|
31
|
+
}
|
|
32
|
+
let b = source;
|
|
33
|
+
if (!b) return a;
|
|
34
|
+
// do not resolve id to ids
|
|
35
|
+
let ids = [...(a.ids || []), ...(b.ids || [])];
|
|
36
|
+
return {
|
|
37
|
+
...a,
|
|
38
|
+
...b,
|
|
39
|
+
ids: ids,
|
|
40
|
+
filters: [...(a.filters || []), ...(b.filters || [])],
|
|
41
|
+
search: b.search || a.search,
|
|
42
|
+
};
|
|
43
|
+
}, target || {});
|
|
44
|
+
return ListQuerySchema.parse(out);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
//# sourceMappingURL=ListQuery.js.map
|
|
47
|
+
//# sourceMappingURL=ListQuery.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export function getTitleOfResource(res) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
if (res && typeof res === 'object') {
|
|
3
|
+
return res.displayName || res.title || res.fullName || res.loginName || res.topic || res.code;
|
|
4
|
+
}
|
|
5
|
+
return undefined;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
//# sourceMappingURL=getTitleOfResource.js.map
|
|
8
|
+
//# sourceMappingURL=getTitleOfResource.js.map
|
package/lib/resource/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { getTitleOfResource } from
|
|
2
|
-
export {
|
|
1
|
+
export { getTitleOfResource } from './getTitleOfResource.js';
|
|
2
|
+
export { ListQuerySchema, resolveListQuery } from './ListQuery.js';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|