@wener/common 2.0.2 → 2.0.3
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 +2 -0
- package/lib/ai/qwen3vl/index.js.map +1 -0
- package/lib/ai/qwen3vl/utils.js +31 -0
- package/lib/ai/qwen3vl/utils.js.map +1 -0
- package/lib/ai/vision/DocLayoutElementTypeSchema.js +28 -0
- package/lib/ai/vision/DocLayoutElementTypeSchema.js.map +1 -0
- package/lib/ai/vision/ImageAnnotationSchema.js +50 -0
- package/lib/ai/vision/ImageAnnotationSchema.js.map +1 -0
- package/lib/ai/vision/index.js +3 -0
- package/lib/ai/vision/index.js.map +1 -0
- package/lib/ai/vision/resolveImageAnnotation.js +105 -0
- package/lib/ai/vision/resolveImageAnnotation.js.map +1 -0
- package/lib/cn/ChineseResidentIdNo.js +21 -14
- package/lib/cn/ChineseResidentIdNo.js.map +1 -0
- package/lib/cn/ChineseResidentIdNo.test.js +1 -1
- package/lib/cn/DivisionCode.js +30 -25
- package/lib/cn/DivisionCode.js.map +1 -0
- package/lib/cn/DivisionCode.test.js +1 -1
- package/lib/cn/Mod11.js +38 -81
- package/lib/cn/Mod11.js.map +1 -0
- package/lib/cn/Mod31.js +41 -90
- package/lib/cn/Mod31.js.map +1 -0
- package/lib/cn/UnifiedSocialCreditCode.js +43 -34
- package/lib/cn/UnifiedSocialCreditCode.js.map +1 -0
- package/lib/cn/UnifiedSocialCreditCode.test.js +1 -1
- package/lib/cn/formatChineseAmount.js +77 -0
- package/lib/cn/formatChineseAmount.js.map +1 -0
- package/lib/cn/index.js +7 -1
- package/lib/cn/index.js.map +1 -0
- package/lib/cn/parseChineseNumber.js +94 -0
- package/lib/cn/parseChineseNumber.js.map +1 -0
- package/lib/cn/parseChineseNumber.test.js +278 -0
- package/lib/cn/pinyin/cartesianProduct.js +22 -0
- package/lib/cn/pinyin/cartesianProduct.js.map +1 -0
- package/lib/cn/pinyin/cartesianProduct.test.js +179 -0
- package/lib/cn/pinyin/data.json +23573 -0
- package/lib/cn/pinyin/loader.js +14 -0
- package/lib/cn/pinyin/loader.js.map +1 -0
- package/lib/cn/pinyin/preload.js +3 -0
- package/lib/cn/pinyin/preload.js.map +1 -0
- package/lib/cn/pinyin/toPinyin.test.js +167 -0
- package/lib/cn/pinyin/toPinyinPure.js +33 -0
- package/lib/cn/pinyin/toPinyinPure.js.map +1 -0
- package/lib/cn/pinyin/transform.js +14 -0
- package/lib/cn/pinyin/transform.js.map +1 -0
- package/lib/cn/types.d.js +2 -0
- package/lib/cn/types.d.js.map +1 -0
- package/lib/consola/createStandardConsolaReporter.js +6 -6
- package/lib/consola/createStandardConsolaReporter.js.map +1 -0
- package/lib/consola/formatLogObject.js +65 -145
- package/lib/consola/formatLogObject.js.map +1 -0
- package/lib/consola/formatLogObject.test.js +184 -0
- package/lib/consola/index.js +1 -0
- package/lib/consola/index.js.map +1 -0
- package/lib/data/formatSort.js +6 -5
- package/lib/data/formatSort.js.map +1 -0
- package/lib/data/index.js +1 -0
- package/lib/data/index.js.map +1 -0
- package/lib/data/maybeNumber.js +5 -7
- package/lib/data/maybeNumber.js.map +1 -0
- package/lib/data/parseSort.js +22 -28
- package/lib/data/parseSort.js.map +1 -0
- package/lib/data/resolvePagination.js +13 -17
- package/lib/data/resolvePagination.js.map +1 -0
- package/lib/data/types.d.js +2 -0
- package/lib/data/types.d.js.map +1 -0
- package/lib/dayjs/dayjs.js +21 -19
- package/lib/dayjs/dayjs.js.map +1 -0
- package/lib/dayjs/formatDuration.js +15 -14
- package/lib/dayjs/formatDuration.js.map +1 -0
- package/lib/dayjs/index.js +2 -0
- package/lib/dayjs/index.js.map +1 -0
- package/lib/dayjs/parseDuration.js +5 -8
- package/lib/dayjs/parseDuration.js.map +1 -0
- package/lib/dayjs/parseRelativeTime.js +90 -0
- package/lib/dayjs/parseRelativeTime.js.map +1 -0
- package/lib/dayjs/parseRelativeTime.test.js +247 -0
- package/lib/dayjs/resolveRelativeTime.js +158 -0
- package/lib/dayjs/resolveRelativeTime.js.map +1 -0
- package/lib/dayjs/resolveRelativeTime.test.js +310 -0
- package/lib/decimal/index.js +1 -0
- package/lib/decimal/index.js.map +1 -0
- package/lib/decimal/parseDecimal.js +3 -1
- package/lib/decimal/parseDecimal.js.map +1 -0
- package/lib/emittery/emitter.js +10 -0
- package/lib/emittery/emitter.js.map +1 -0
- package/lib/emittery/index.js +2 -0
- package/lib/emittery/index.js.map +1 -0
- package/lib/foundation/schema/SexType.js +5 -3
- package/lib/foundation/schema/SexType.js.map +1 -0
- package/lib/foundation/schema/index.js +1 -0
- package/lib/foundation/schema/index.js.map +1 -0
- package/lib/foundation/schema/parseSexType.js +1 -0
- package/lib/foundation/schema/parseSexType.js.map +1 -0
- package/lib/foundation/schema/types.js +4 -2
- package/lib/foundation/schema/types.js.map +1 -0
- package/lib/fs/FileSystemError.js +23 -0
- package/lib/fs/FileSystemError.js.map +1 -0
- package/lib/fs/IFileSystem.d.js +3 -0
- package/lib/fs/IFileSystem.d.js.map +1 -0
- package/lib/fs/MemoryFileSystem.test.js +188 -0
- package/lib/fs/createBrowserFileSystem.js +248 -0
- package/lib/fs/createBrowserFileSystem.js.map +1 -0
- package/lib/fs/createMemoryFileSystem.js +516 -0
- package/lib/fs/createMemoryFileSystem.js.map +1 -0
- package/lib/fs/createSandboxFileSystem.js +108 -0
- package/lib/fs/createSandboxFileSystem.js.map +1 -0
- package/lib/fs/createWebDavFileSystem.js +137 -0
- package/lib/fs/createWebDavFileSystem.js.map +1 -0
- package/lib/fs/findMimeType.js +17 -0
- package/lib/fs/findMimeType.js.map +1 -0
- package/lib/fs/index.js +8 -0
- package/lib/fs/index.js.map +1 -0
- package/lib/fs/orpc/FileSystemContract.js +93 -0
- package/lib/fs/orpc/FileSystemContract.js.map +1 -0
- package/lib/fs/orpc/createContractClientFileSystem.js +93 -0
- package/lib/fs/orpc/createContractClientFileSystem.js.map +1 -0
- package/lib/fs/orpc/index.js +3 -0
- package/lib/fs/orpc/index.js.map +1 -0
- package/lib/fs/orpc/server/createFileSystemContractImpl.js +63 -0
- package/lib/fs/orpc/server/createFileSystemContractImpl.js.map +1 -0
- package/lib/fs/orpc/server/index.js +2 -0
- package/lib/fs/orpc/server/index.js.map +1 -0
- package/lib/fs/s3/createS3MiniFileSystem.js +705 -0
- package/lib/fs/s3/createS3MiniFileSystem.js.map +1 -0
- package/lib/fs/s3/index.js +2 -0
- package/lib/fs/s3/index.js.map +1 -0
- package/lib/fs/s3/s3mini.test.js +584 -0
- package/lib/fs/scandir.js +59 -0
- package/lib/fs/scandir.js.map +1 -0
- package/lib/fs/server/createDatabaseFileSystem.js +750 -0
- package/lib/fs/server/createDatabaseFileSystem.js.map +1 -0
- package/lib/fs/server/createNodeFileSystem.js +401 -0
- package/lib/fs/server/createNodeFileSystem.js.map +1 -0
- package/lib/fs/server/dbfs.test.js +221 -0
- package/lib/fs/server/index.js +2 -0
- package/lib/fs/server/index.js.map +1 -0
- package/lib/fs/server/loadTestDatabase.js +127 -0
- package/lib/fs/server/loadTestDatabase.js.map +1 -0
- package/lib/fs/tests/runFileSystemTest.js +318 -0
- package/lib/fs/tests/runFileSystemTest.js.map +1 -0
- package/lib/fs/types.js +27 -0
- package/lib/fs/types.js.map +1 -0
- package/lib/fs/utils/getFileUrl.js +35 -0
- package/lib/fs/utils/getFileUrl.js.map +1 -0
- package/lib/fs/utils.js +22 -0
- package/lib/fs/utils.js.map +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -0
- package/lib/jsonschema/JsonSchema.js +146 -172
- package/lib/jsonschema/JsonSchema.js.map +1 -0
- package/lib/jsonschema/forEachJsonSchema.js +44 -0
- package/lib/jsonschema/forEachJsonSchema.js.map +1 -0
- package/lib/jsonschema/index.js +2 -0
- package/lib/jsonschema/index.js.map +1 -0
- package/lib/jsonschema/types.d.js +2 -0
- package/lib/jsonschema/types.d.js.map +1 -0
- package/lib/meta/defineFileType.js +20 -103
- package/lib/meta/defineFileType.js.map +1 -0
- package/lib/meta/defineInit.js +31 -250
- package/lib/meta/defineInit.js.map +1 -0
- package/lib/meta/defineMetadata.js +24 -140
- package/lib/meta/defineMetadata.js.map +1 -0
- package/lib/meta/index.js +1 -0
- package/lib/meta/index.js.map +1 -0
- package/lib/orpc/createOpenApiContractClient.js +27 -0
- package/lib/orpc/createOpenApiContractClient.js.map +1 -0
- package/lib/orpc/createRpcContractClient.js +34 -0
- package/lib/orpc/createRpcContractClient.js.map +1 -0
- package/lib/orpc/index.js +3 -0
- package/lib/orpc/index.js.map +1 -0
- package/lib/orpc/resolveLinkPlugins.js +28 -0
- package/lib/orpc/resolveLinkPlugins.js.map +1 -0
- package/lib/password/PHC.js +63 -87
- package/lib/password/PHC.js.map +1 -0
- package/lib/password/PHC.test.js +11 -3
- package/lib/password/Password.js +29 -294
- package/lib/password/Password.js.map +1 -0
- package/lib/password/Password.test.js +35 -22
- package/lib/password/createArgon2PasswordAlgorithm.js +35 -191
- package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -0
- package/lib/password/createBase64PasswordAlgorithm.js +8 -141
- package/lib/password/createBase64PasswordAlgorithm.js.map +1 -0
- package/lib/password/createBcryptPasswordAlgorithm.js +13 -168
- package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -0
- package/lib/password/createPBKDF2PasswordAlgorithm.js +46 -228
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -0
- package/lib/password/createScryptPasswordAlgorithm.js +55 -211
- package/lib/password/createScryptPasswordAlgorithm.js.map +1 -0
- package/lib/password/index.js +1 -0
- package/lib/password/index.js.map +1 -0
- package/lib/password/server/index.js +1 -0
- package/lib/password/server/index.js.map +1 -0
- package/lib/resource/Identifiable.js +2 -0
- package/lib/resource/Identifiable.js.map +1 -0
- package/lib/resource/ListQuery.js +21 -93
- package/lib/resource/ListQuery.js.map +1 -0
- package/lib/resource/getTitleOfResource.js +3 -5
- package/lib/resource/getTitleOfResource.js.map +1 -0
- package/lib/resource/index.js +1 -0
- package/lib/resource/index.js.map +1 -0
- package/lib/resource/schema/AnyResourceSchema.js +2 -1
- package/lib/resource/schema/AnyResourceSchema.js.map +1 -0
- package/lib/resource/schema/BaseResourceSchema.js +2 -1
- package/lib/resource/schema/BaseResourceSchema.js.map +1 -0
- package/lib/resource/schema/ResourceActionType.js +6 -4
- package/lib/resource/schema/ResourceActionType.js.map +1 -0
- package/lib/resource/schema/ResourceStatus.js +5 -3
- package/lib/resource/schema/ResourceStatus.js.map +1 -0
- package/lib/resource/schema/ResourceType.js +5 -3
- package/lib/resource/schema/ResourceType.js.map +1 -0
- package/lib/resource/schema/index.js +1 -0
- package/lib/resource/schema/index.js.map +1 -0
- package/lib/resource/schema/types.js +16 -20
- package/lib/resource/schema/types.js.map +1 -0
- package/lib/s3/formatS3Url.js +65 -0
- package/lib/s3/formatS3Url.js.map +1 -0
- package/lib/s3/formatS3Url.test.js +262 -0
- package/lib/s3/index.js +3 -0
- package/lib/s3/index.js.map +1 -0
- package/lib/s3/parseS3Url.js +65 -0
- package/lib/s3/parseS3Url.js.map +1 -0
- package/lib/s3/parseS3Url.test.js +270 -0
- package/lib/schema/SchemaRegistry.js +38 -38
- package/lib/schema/SchemaRegistry.js.map +1 -0
- package/lib/schema/TypeSchema.d.js +2 -0
- package/lib/schema/TypeSchema.d.js.map +1 -0
- package/lib/schema/createSchemaData.js +26 -125
- package/lib/schema/createSchemaData.js.map +1 -0
- package/lib/schema/findJsonSchemaByPath.js +13 -36
- package/lib/schema/findJsonSchemaByPath.js.map +1 -0
- package/lib/schema/formatZodError.js +140 -0
- package/lib/schema/formatZodError.js.map +1 -0
- package/lib/schema/formatZodError.test.js +196 -0
- package/lib/schema/getSchemaCache.js +5 -5
- package/lib/schema/getSchemaCache.js.map +1 -0
- package/lib/schema/getSchemaOptions.js +8 -11
- package/lib/schema/getSchemaOptions.js.map +1 -0
- package/lib/schema/index.js +2 -1
- package/lib/schema/index.js.map +1 -0
- package/lib/schema/toJsonSchema.js +47 -290
- package/lib/schema/toJsonSchema.js.map +1 -0
- package/lib/schema/validate.js +33 -45
- package/lib/schema/validate.js.map +1 -0
- package/lib/tools/generateSchema.js +39 -197
- package/lib/tools/generateSchema.js.map +1 -0
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +55 -143
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +1 -0
- package/lib/utils/buildBaseUrl.js +13 -0
- package/lib/utils/buildBaseUrl.js.map +1 -0
- package/lib/utils/buildRedactorFormSchema.js +59 -0
- package/lib/utils/buildRedactorFormSchema.js.map +1 -0
- package/lib/utils/getEstimateProcessTime.js +12 -11
- package/lib/utils/getEstimateProcessTime.js.map +1 -0
- package/lib/utils/index.js +3 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/resolveFeatureOptions.js +12 -0
- package/lib/utils/resolveFeatureOptions.js.map +1 -0
- package/package.json +61 -13
- package/src/ai/qwen3vl/index.ts +1 -0
- package/src/ai/qwen3vl/utils.ts +36 -0
- package/src/ai/vision/DocLayoutElementTypeSchema.ts +30 -0
- package/src/ai/vision/ImageAnnotationSchema.ts +60 -0
- package/src/ai/vision/index.ts +2 -0
- package/src/ai/vision/resolveImageAnnotation.ts +135 -0
- package/src/cn/ChineseResidentIdNo.test.ts +1 -1
- package/src/cn/ChineseResidentIdNo.ts +8 -0
- package/src/cn/DivisionCode.test.ts +1 -1
- package/src/cn/DivisionCode.ts +8 -0
- package/src/cn/UnifiedSocialCreditCode.test.ts +1 -1
- package/src/cn/UnifiedSocialCreditCode.ts +15 -0
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +23 -0
- package/src/cn/formatChineseAmount.ts +61 -0
- package/src/cn/index.ts +7 -1
- package/src/cn/parseChineseNumber.test.ts +159 -0
- package/src/cn/parseChineseNumber.ts +97 -0
- package/src/cn/pinyin/cartesianProduct.test.ts +64 -0
- package/src/cn/pinyin/cartesianProduct.ts +24 -0
- package/src/cn/pinyin/data.json +23573 -0
- package/src/cn/pinyin/loader.ts +12 -0
- package/src/cn/pinyin/preload.ts +3 -0
- package/src/cn/pinyin/toPinyin.test.ts +12 -0
- package/src/cn/pinyin/toPinyinPure.ts +43 -0
- package/src/cn/pinyin/transform.ts +12 -0
- package/src/consola/formatLogObject.test.ts +27 -0
- package/src/consola/formatLogObject.ts +34 -6
- package/src/dayjs/dayjs.ts +18 -18
- package/src/dayjs/index.ts +3 -1
- package/src/dayjs/parseRelativeTime.test.ts +185 -0
- package/src/dayjs/parseRelativeTime.ts +115 -0
- package/src/dayjs/resolveRelativeTime.test.ts +357 -0
- package/src/dayjs/resolveRelativeTime.ts +167 -0
- package/src/emittery/emitter.ts +9 -0
- package/src/emittery/index.ts +1 -0
- package/src/fs/FileSystemError.ts +26 -0
- package/src/fs/IFileSystem.d.ts +102 -0
- package/src/fs/MemoryFileSystem.test.ts +37 -0
- package/src/fs/createBrowserFileSystem.ts +291 -0
- package/src/fs/createMemoryFileSystem.ts +604 -0
- package/src/fs/createSandboxFileSystem.ts +136 -0
- package/src/fs/createWebDavFileSystem.ts +172 -0
- package/src/fs/findMimeType.ts +23 -0
- package/src/fs/index.ts +8 -0
- package/src/fs/orpc/FileSystemContract.ts +92 -0
- package/src/fs/orpc/createContractClientFileSystem.ts +115 -0
- package/src/fs/orpc/index.ts +2 -0
- package/src/fs/orpc/server/createFileSystemContractImpl.ts +64 -0
- package/src/fs/orpc/server/index.ts +1 -0
- package/src/fs/s3/createS3MiniFileSystem.ts +830 -0
- package/src/fs/s3/index.ts +1 -0
- package/src/fs/s3/s3mini.test.ts +264 -0
- package/src/fs/scandir.ts +75 -0
- package/src/fs/server/createDatabaseFileSystem.ts +668 -0
- package/src/fs/server/createNodeFileSystem.ts +499 -0
- package/src/fs/server/dbfs.test.ts +47 -0
- package/src/fs/server/index.ts +1 -0
- package/src/fs/server/loadTestDatabase.ts +131 -0
- package/src/fs/tests/runFileSystemTest.ts +288 -0
- package/src/fs/types.ts +29 -0
- package/src/fs/utils/getFileUrl.ts +44 -0
- package/src/fs/utils.ts +23 -0
- package/src/jsonschema/JsonSchema.ts +118 -110
- package/src/jsonschema/forEachJsonSchema.ts +50 -0
- package/src/jsonschema/index.ts +1 -0
- package/src/orpc/createOpenApiContractClient.ts +52 -0
- package/src/orpc/createRpcContractClient.ts +50 -0
- package/src/orpc/index.ts +2 -0
- package/src/orpc/resolveLinkPlugins.ts +29 -0
- package/src/password/PHC.ts +3 -3
- package/src/password/Password.test.ts +1 -1
- package/src/password/createPBKDF2PasswordAlgorithm.ts +2 -2
- package/src/resource/schema/AnyResourceSchema.ts +16 -2
- package/src/s3/formatS3Url.test.ts +254 -0
- package/src/s3/formatS3Url.ts +84 -0
- package/src/s3/index.ts +2 -0
- package/src/s3/parseS3Url.test.ts +258 -0
- package/src/s3/parseS3Url.ts +88 -0
- package/src/schema/SchemaRegistry.ts +35 -33
- package/src/schema/formatZodError.test.ts +196 -0
- package/src/schema/formatZodError.ts +151 -0
- package/src/schema/getSchemaOptions.ts +2 -2
- package/src/schema/index.ts +1 -1
- package/src/utils/buildBaseUrl.ts +12 -0
- package/src/utils/buildRedactorFormSchema.ts +85 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/resolveFeatureOptions.ts +14 -0
- package/src/cn/ChineseResidentIdNo.mod.ts +0 -7
- package/src/cn/DivisionCode.mod.ts +0 -7
- package/src/cn/UnifiedSocialCreditCode.mod.ts +0 -7
- package/src/cn/mod.ts +0 -3
- package/src/schema/SchemaRegistry.mod.ts +0 -1
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { formatS3Url } from "./formatS3Url.js";
|
|
3
|
+
describe("formatS3Url", function () {
|
|
4
|
+
it("should format basic S3 URL with default endpoint", function () {
|
|
5
|
+
var options = {
|
|
6
|
+
endpoint: "s3.amazonaws.com"
|
|
7
|
+
};
|
|
8
|
+
var result = formatS3Url(options);
|
|
9
|
+
expect(result).toBe("https://s3.amazonaws.com/");
|
|
10
|
+
});
|
|
11
|
+
it("should format S3 URL with custom endpoint", function () {
|
|
12
|
+
var options = {
|
|
13
|
+
endpoint: "custom-s3.com"
|
|
14
|
+
};
|
|
15
|
+
var result = formatS3Url(options);
|
|
16
|
+
expect(result).toBe("https://custom-s3.com/");
|
|
17
|
+
});
|
|
18
|
+
it("should format S3 URL with HTTP protocol", function () {
|
|
19
|
+
var options = {
|
|
20
|
+
endpoint: "s3.amazonaws.com",
|
|
21
|
+
useSsl: false
|
|
22
|
+
};
|
|
23
|
+
var result = formatS3Url(options);
|
|
24
|
+
expect(result).toBe("http://s3.amazonaws.com/");
|
|
25
|
+
});
|
|
26
|
+
it("should format S3 URL with port", function () {
|
|
27
|
+
var options = {
|
|
28
|
+
endpoint: "s3.amazonaws.com",
|
|
29
|
+
port: 9000
|
|
30
|
+
};
|
|
31
|
+
var result = formatS3Url(options);
|
|
32
|
+
expect(result).toBe("https://s3.amazonaws.com:9000/");
|
|
33
|
+
});
|
|
34
|
+
it("should format S3 URL with bucket in path style", function () {
|
|
35
|
+
var options = {
|
|
36
|
+
endpoint: "s3.amazonaws.com",
|
|
37
|
+
bucket: "my-bucket",
|
|
38
|
+
pathStyle: true
|
|
39
|
+
};
|
|
40
|
+
var result = formatS3Url(options);
|
|
41
|
+
expect(result).toBe("https://s3.amazonaws.com/my-bucket/");
|
|
42
|
+
});
|
|
43
|
+
it("should format S3 URL with bucket in virtual hosted style", function () {
|
|
44
|
+
var options = {
|
|
45
|
+
endpoint: "s3.amazonaws.com",
|
|
46
|
+
bucket: "my-bucket",
|
|
47
|
+
pathStyle: false
|
|
48
|
+
};
|
|
49
|
+
var result = formatS3Url(options);
|
|
50
|
+
expect(result).toBe("https://my-bucket.s3.amazonaws.com/");
|
|
51
|
+
});
|
|
52
|
+
it("should format S3 URL with credentials", function () {
|
|
53
|
+
var options = {
|
|
54
|
+
endpoint: "s3.amazonaws.com",
|
|
55
|
+
accessKeyId: "user",
|
|
56
|
+
secretAccessKey: "pass"
|
|
57
|
+
};
|
|
58
|
+
var result = formatS3Url(options, {
|
|
59
|
+
credentials: true
|
|
60
|
+
});
|
|
61
|
+
expect(result).toBe("https://user:pass@s3.amazonaws.com/");
|
|
62
|
+
});
|
|
63
|
+
it("should format S3 URL with credentials and special characters", function () {
|
|
64
|
+
var options = {
|
|
65
|
+
endpoint: "s3.amazonaws.com",
|
|
66
|
+
accessKeyId: "user@example.com",
|
|
67
|
+
secretAccessKey: "pass/word"
|
|
68
|
+
};
|
|
69
|
+
var result = formatS3Url(options, {
|
|
70
|
+
credentials: true
|
|
71
|
+
});
|
|
72
|
+
expect(result).toBe("https://user%40example.com:pass%2Fword@s3.amazonaws.com/");
|
|
73
|
+
});
|
|
74
|
+
it("should format S3 URL with region in query parameters", function () {
|
|
75
|
+
var options = {
|
|
76
|
+
endpoint: "s3.amazonaws.com",
|
|
77
|
+
region: "us-east-1"
|
|
78
|
+
};
|
|
79
|
+
var result = formatS3Url(options, {
|
|
80
|
+
useParams: true
|
|
81
|
+
});
|
|
82
|
+
expect(result).toBe("https://s3.amazonaws.com/?region=us-east-1");
|
|
83
|
+
});
|
|
84
|
+
it("should format S3 URL with pathStyle in query parameters", function () {
|
|
85
|
+
var options = {
|
|
86
|
+
endpoint: "s3.amazonaws.com",
|
|
87
|
+
pathStyle: true
|
|
88
|
+
};
|
|
89
|
+
var result = formatS3Url(options, {
|
|
90
|
+
useParams: true
|
|
91
|
+
});
|
|
92
|
+
expect(result).toBe("https://s3.amazonaws.com/?pathStyle=true");
|
|
93
|
+
});
|
|
94
|
+
it("should format S3 URL with all parameters", function () {
|
|
95
|
+
var options = {
|
|
96
|
+
endpoint: "s3.amazonaws.com",
|
|
97
|
+
accessKeyId: "user",
|
|
98
|
+
secretAccessKey: "pass",
|
|
99
|
+
region: "us-east-1",
|
|
100
|
+
port: 9000,
|
|
101
|
+
bucket: "my-bucket",
|
|
102
|
+
pathStyle: true,
|
|
103
|
+
useSsl: true
|
|
104
|
+
};
|
|
105
|
+
var result = formatS3Url(options, {
|
|
106
|
+
credentials: true,
|
|
107
|
+
useParams: true
|
|
108
|
+
});
|
|
109
|
+
expect(result).toBe("https://user:pass@s3.amazonaws.com:9000/my-bucket/?region=us-east-1&pathStyle=true");
|
|
110
|
+
});
|
|
111
|
+
it("should handle full URL as endpoint", function () {
|
|
112
|
+
var options = {
|
|
113
|
+
endpoint: "https://custom-s3.com:9000",
|
|
114
|
+
bucket: "my-bucket",
|
|
115
|
+
pathStyle: true
|
|
116
|
+
};
|
|
117
|
+
var result = formatS3Url(options);
|
|
118
|
+
expect(result).toBe("https://custom-s3.com:9000/my-bucket/");
|
|
119
|
+
});
|
|
120
|
+
it("should handle complex virtual hosted style with existing bucket in hostname", function () {
|
|
121
|
+
var options = {
|
|
122
|
+
endpoint: "my-bucket.s3.amazonaws.com",
|
|
123
|
+
bucket: "my-bucket",
|
|
124
|
+
pathStyle: false
|
|
125
|
+
};
|
|
126
|
+
var result = formatS3Url(options);
|
|
127
|
+
expect(result).toBe("https://my-bucket.s3.amazonaws.com/");
|
|
128
|
+
});
|
|
129
|
+
it("should throw error for missing endpoint", function () {
|
|
130
|
+
var options = {};
|
|
131
|
+
expect(function () {
|
|
132
|
+
return formatS3Url(options);
|
|
133
|
+
}).toThrow("Endpoint is required");
|
|
134
|
+
});
|
|
135
|
+
it("should handle endpoint without protocol by adding https://", function () {
|
|
136
|
+
var options = {
|
|
137
|
+
endpoint: "custom-s3.com"
|
|
138
|
+
};
|
|
139
|
+
var result = formatS3Url(options);
|
|
140
|
+
expect(result).toBe("https://custom-s3.com/");
|
|
141
|
+
});
|
|
142
|
+
it("should throw error for missing credentials when credentials=true", function () {
|
|
143
|
+
var options = {
|
|
144
|
+
endpoint: "s3.amazonaws.com",
|
|
145
|
+
accessKeyId: "user"
|
|
146
|
+
};
|
|
147
|
+
expect(function () {
|
|
148
|
+
return formatS3Url(options, {
|
|
149
|
+
credentials: true
|
|
150
|
+
});
|
|
151
|
+
}).toThrow("Access Key ID and Secret Access Key are required for credentials");
|
|
152
|
+
});
|
|
153
|
+
it("should throw error for invalid port", function () {
|
|
154
|
+
var options = {
|
|
155
|
+
endpoint: "s3.amazonaws.com",
|
|
156
|
+
port: 99999
|
|
157
|
+
};
|
|
158
|
+
expect(function () {
|
|
159
|
+
return formatS3Url(options);
|
|
160
|
+
}).toThrow("Port must be a valid number between 1 and 65535");
|
|
161
|
+
});
|
|
162
|
+
it("should throw error for invalid bucket name", function () {
|
|
163
|
+
var options = {
|
|
164
|
+
endpoint: "s3.amazonaws.com",
|
|
165
|
+
bucket: "Invalid Bucket Name"
|
|
166
|
+
};
|
|
167
|
+
expect(function () {
|
|
168
|
+
return formatS3Url(options);
|
|
169
|
+
}).toThrow("Invalid bucket name: Invalid Bucket Name");
|
|
170
|
+
});
|
|
171
|
+
it("should throw error for bucket name with consecutive dots", function () {
|
|
172
|
+
var options = {
|
|
173
|
+
endpoint: "s3.amazonaws.com",
|
|
174
|
+
bucket: "my..bucket"
|
|
175
|
+
};
|
|
176
|
+
expect(function () {
|
|
177
|
+
return formatS3Url(options);
|
|
178
|
+
}).toThrow("Invalid bucket name: my..bucket");
|
|
179
|
+
});
|
|
180
|
+
it("should throw error for bucket name with hyphen at start", function () {
|
|
181
|
+
var options = {
|
|
182
|
+
endpoint: "s3.amazonaws.com",
|
|
183
|
+
bucket: "-mybucket"
|
|
184
|
+
};
|
|
185
|
+
expect(function () {
|
|
186
|
+
return formatS3Url(options);
|
|
187
|
+
}).toThrow("Invalid bucket name: -mybucket");
|
|
188
|
+
});
|
|
189
|
+
it("should throw error for bucket name with hyphen at end", function () {
|
|
190
|
+
var options = {
|
|
191
|
+
endpoint: "s3.amazonaws.com",
|
|
192
|
+
bucket: "mybucket-"
|
|
193
|
+
};
|
|
194
|
+
expect(function () {
|
|
195
|
+
return formatS3Url(options);
|
|
196
|
+
}).toThrow("Invalid bucket name: mybucket-");
|
|
197
|
+
});
|
|
198
|
+
it("should handle bucket name with dot-hyphen (currently allowed)", function () {
|
|
199
|
+
var options = {
|
|
200
|
+
endpoint: "s3.amazonaws.com",
|
|
201
|
+
bucket: "my.bucket-name",
|
|
202
|
+
pathStyle: true
|
|
203
|
+
};
|
|
204
|
+
var result = formatS3Url(options);
|
|
205
|
+
expect(result).toBe("https://s3.amazonaws.com/my.bucket-name/");
|
|
206
|
+
});
|
|
207
|
+
it("should throw error for bucket name that is too short", function () {
|
|
208
|
+
var options = {
|
|
209
|
+
endpoint: "s3.amazonaws.com",
|
|
210
|
+
bucket: "ab"
|
|
211
|
+
};
|
|
212
|
+
expect(function () {
|
|
213
|
+
return formatS3Url(options);
|
|
214
|
+
}).toThrow("Invalid bucket name: ab");
|
|
215
|
+
});
|
|
216
|
+
it("should throw error for bucket name that is too long", function () {
|
|
217
|
+
var options = {
|
|
218
|
+
endpoint: "s3.amazonaws.com",
|
|
219
|
+
bucket: "a".repeat(64)
|
|
220
|
+
};
|
|
221
|
+
expect(function () {
|
|
222
|
+
return formatS3Url(options);
|
|
223
|
+
}).toThrow("Invalid bucket name: " + "a".repeat(64));
|
|
224
|
+
});
|
|
225
|
+
it("should handle valid bucket names with various formats", function () {
|
|
226
|
+
var validBuckets = [
|
|
227
|
+
"my-bucket",
|
|
228
|
+
"my.bucket",
|
|
229
|
+
"mybucket123",
|
|
230
|
+
"123bucket",
|
|
231
|
+
"test-bucket-123"
|
|
232
|
+
];
|
|
233
|
+
validBuckets.forEach(function (bucket) {
|
|
234
|
+
var options = {
|
|
235
|
+
endpoint: "s3.amazonaws.com",
|
|
236
|
+
bucket: bucket,
|
|
237
|
+
pathStyle: true
|
|
238
|
+
};
|
|
239
|
+
expect(function () {
|
|
240
|
+
return formatS3Url(options);
|
|
241
|
+
}).not.toThrow();
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
it("should handle pathname concatenation correctly in path style", function () {
|
|
245
|
+
var options = {
|
|
246
|
+
endpoint: "https://s3.amazonaws.com/path/to/something",
|
|
247
|
+
bucket: "my-bucket",
|
|
248
|
+
pathStyle: true
|
|
249
|
+
};
|
|
250
|
+
var result = formatS3Url(options);
|
|
251
|
+
expect(result).toBe("https://s3.amazonaws.com/my-bucket/path/to/something");
|
|
252
|
+
});
|
|
253
|
+
it("should handle URL with existing pathname in virtual hosted style", function () {
|
|
254
|
+
var options = {
|
|
255
|
+
endpoint: "https://s3.amazonaws.com/path/to/something",
|
|
256
|
+
bucket: "my-bucket",
|
|
257
|
+
pathStyle: false
|
|
258
|
+
};
|
|
259
|
+
var result = formatS3Url(options);
|
|
260
|
+
expect(result).toBe("https://my-bucket.s3.amazonaws.com/path/to/something");
|
|
261
|
+
});
|
|
262
|
+
});
|
package/lib/s3/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/s3/index.ts"],"sourcesContent":["export { parseS3Url, type ParseS3UrlOptions } from './parseS3Url';\nexport { formatS3Url } from './formatS3Url';\n"],"names":["parseS3Url","formatS3Url"],"mappings":"AAAA,SAASA,UAAU,QAAgC,eAAe;AAClE,SAASC,WAAW,QAAQ,gBAAgB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { parseBoolean } from "@wener/utils";
|
|
2
|
+
function isValidIpAddress(hostname) {
|
|
3
|
+
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
4
|
+
const ipv6Regex = /^\[([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}]$/;
|
|
5
|
+
return ipv4Regex.test(hostname) || ipv6Regex.test(hostname);
|
|
6
|
+
}
|
|
7
|
+
export function parseS3Url({ url = process.env.S3_URL, ...rest } = {}) {
|
|
8
|
+
if (!url) return undefined;
|
|
9
|
+
const normalizedUrl = url.startsWith('s3://') ? url.replace(/^s3:\/\//, 'https://') : url;
|
|
10
|
+
let parsed;
|
|
11
|
+
try {
|
|
12
|
+
parsed = new URL(normalizedUrl);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
throw new Error(`Invalid S3 URL: ${url}`);
|
|
15
|
+
}
|
|
16
|
+
const pathStyleParam = parsed.searchParams.get('pathStyle');
|
|
17
|
+
let pathStyle = rest.pathStyle;
|
|
18
|
+
pathStyle ??= parseBoolean(pathStyleParam, true);
|
|
19
|
+
// Auto-detect path style for IP addresses
|
|
20
|
+
if (pathStyle === undefined && isValidIpAddress(parsed.hostname)) {
|
|
21
|
+
pathStyle = true;
|
|
22
|
+
}
|
|
23
|
+
const result = {
|
|
24
|
+
accessKeyId: parsed.username || undefined,
|
|
25
|
+
secretAccessKey: parsed.password || undefined,
|
|
26
|
+
endpoint: parsed.hostname,
|
|
27
|
+
port: parsed.port ? Number(parsed.port) : undefined,
|
|
28
|
+
useSsl: parsed.protocol === 'https:',
|
|
29
|
+
region: parsed.searchParams.get('region') || undefined,
|
|
30
|
+
pathStyle
|
|
31
|
+
};
|
|
32
|
+
if (!result.port) {
|
|
33
|
+
if (result.useSsl) {
|
|
34
|
+
result.port = 443;
|
|
35
|
+
} else {
|
|
36
|
+
result.port = 80;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const pathSegments = parsed.pathname.split('/').filter(Boolean);
|
|
40
|
+
const awsVirtualHostMatch = parsed.hostname.match(/^(.*?)\.s3[.-]([a-z0-9-]+)?\.?amazonaws\.com$/);
|
|
41
|
+
if (result.pathStyle) {
|
|
42
|
+
result.bucket = pathSegments[0];
|
|
43
|
+
} else if (awsVirtualHostMatch) {
|
|
44
|
+
result.bucket = awsVirtualHostMatch[1];
|
|
45
|
+
result.endpoint = parsed.hostname;
|
|
46
|
+
if (!result.region && awsVirtualHostMatch[2]) {
|
|
47
|
+
result.region = awsVirtualHostMatch[2];
|
|
48
|
+
}
|
|
49
|
+
result.pathStyle = false;
|
|
50
|
+
} else {
|
|
51
|
+
result.bucket = pathSegments[0];
|
|
52
|
+
if (result.pathStyle === undefined) {
|
|
53
|
+
result.pathStyle = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Type-safe property assignment
|
|
57
|
+
for (const [key, value] of Object.entries(rest)){
|
|
58
|
+
if (value !== undefined && value !== null && key in result) {
|
|
59
|
+
result[key] = value;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=parseS3Url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/s3/parseS3Url.ts"],"sourcesContent":["import { parseBoolean } from '@wener/utils';\n\nexport type ParsedS3Options = {\n\taccessKeyId?: string;\n\tsecretAccessKey?: string;\n\tregion?: string;\n\tuseSsl?: boolean;\n\tbucket?: string;\n\tendpoint: string;\n\tport?: number;\n\tpathStyle?: boolean;\n\turl?: string;\n};\n\nexport type ParseS3UrlOptions = Partial<ParsedS3Options>;\n\nfunction isValidIpAddress(hostname: string): boolean {\n\tconst ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;\n\tconst ipv6Regex = /^\\[([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}]$/;\n\treturn ipv4Regex.test(hostname) || ipv6Regex.test(hostname);\n}\n\nexport function parseS3Url({ url = process.env.S3_URL, ...rest }: ParseS3UrlOptions = {}): ParsedS3Options | undefined {\n\tif (!url) return undefined;\n\n\tconst normalizedUrl = url.startsWith('s3://') ? url.replace(/^s3:\\/\\//, 'https://') : url;\n\tlet parsed: URL;\n\ttry {\n\t\tparsed = new URL(normalizedUrl);\n\t} catch (error) {\n\t\tthrow new Error(`Invalid S3 URL: ${url}`);\n\t}\n\n\tconst pathStyleParam = parsed.searchParams.get('pathStyle');\n\tlet pathStyle: boolean | undefined = rest.pathStyle;\n\tpathStyle ??= parseBoolean(pathStyleParam, true);\n\n\t// Auto-detect path style for IP addresses\n\tif (pathStyle === undefined && isValidIpAddress(parsed.hostname)) {\n\t\tpathStyle = true;\n\t}\n\n\tconst result: ParsedS3Options = {\n\t\taccessKeyId: parsed.username || undefined,\n\t\tsecretAccessKey: parsed.password || undefined,\n\t\tendpoint: parsed.hostname,\n\t\tport: parsed.port ? Number(parsed.port) : undefined,\n\t\tuseSsl: parsed.protocol === 'https:',\n\t\tregion: parsed.searchParams.get('region') || undefined,\n\t\tpathStyle,\n\t};\n\n\tif (!result.port) {\n\t\tif (result.useSsl) {\n\t\t\tresult.port = 443;\n\t\t} else {\n\t\t\tresult.port = 80;\n\t\t}\n\t}\n\n\tconst pathSegments = parsed.pathname.split('/').filter(Boolean);\n\tconst awsVirtualHostMatch = parsed.hostname.match(/^(.*?)\\.s3[.-]([a-z0-9-]+)?\\.?amazonaws\\.com$/);\n\n\tif (result.pathStyle) {\n\t\tresult.bucket = pathSegments[0];\n\t} else if (awsVirtualHostMatch) {\n\t\tresult.bucket = awsVirtualHostMatch[1];\n\t\tresult.endpoint = parsed.hostname;\n\t\tif (!result.region && awsVirtualHostMatch[2]) {\n\t\t\tresult.region = awsVirtualHostMatch[2];\n\t\t}\n\t\tresult.pathStyle = false;\n\t} else {\n\t\tresult.bucket = pathSegments[0];\n\t\tif (result.pathStyle === undefined) {\n\t\t\tresult.pathStyle = true;\n\t\t}\n\t}\n\n\t// Type-safe property assignment\n\tfor (const [key, value] of Object.entries(rest)) {\n\t\tif (value !== undefined && value !== null && key in result) {\n\t\t\t(result as Record<string, unknown>)[key] = value;\n\t\t}\n\t}\n\n\treturn result;\n}\n"],"names":["parseBoolean","isValidIpAddress","hostname","ipv4Regex","ipv6Regex","test","parseS3Url","url","process","env","S3_URL","rest","undefined","normalizedUrl","startsWith","replace","parsed","URL","error","Error","pathStyleParam","searchParams","get","pathStyle","result","accessKeyId","username","secretAccessKey","password","endpoint","port","Number","useSsl","protocol","region","pathSegments","pathname","split","filter","Boolean","awsVirtualHostMatch","match","bucket","key","value","Object","entries"],"mappings":"AAAA,SAASA,YAAY,QAAQ,eAAe;AAgB5C,SAASC,iBAAiBC,QAAgB;IACzC,MAAMC,YAAY;IAClB,MAAMC,YAAY;IAClB,OAAOD,UAAUE,IAAI,CAACH,aAAaE,UAAUC,IAAI,CAACH;AACnD;AAEA,OAAO,SAASI,WAAW,EAAEC,MAAMC,QAAQC,GAAG,CAACC,MAAM,EAAE,GAAGC,MAAyB,GAAG,CAAC,CAAC;IACvF,IAAI,CAACJ,KAAK,OAAOK;IAEjB,MAAMC,gBAAgBN,IAAIO,UAAU,CAAC,WAAWP,IAAIQ,OAAO,CAAC,YAAY,cAAcR;IACtF,IAAIS;IACJ,IAAI;QACHA,SAAS,IAAIC,IAAIJ;IAClB,EAAE,OAAOK,OAAO;QACf,MAAM,IAAIC,MAAM,CAAC,gBAAgB,EAAEZ,KAAK;IACzC;IAEA,MAAMa,iBAAiBJ,OAAOK,YAAY,CAACC,GAAG,CAAC;IAC/C,IAAIC,YAAiCZ,KAAKY,SAAS;IACnDA,cAAcvB,aAAaoB,gBAAgB;IAE3C,0CAA0C;IAC1C,IAAIG,cAAcX,aAAaX,iBAAiBe,OAAOd,QAAQ,GAAG;QACjEqB,YAAY;IACb;IAEA,MAAMC,SAA0B;QAC/BC,aAAaT,OAAOU,QAAQ,IAAId;QAChCe,iBAAiBX,OAAOY,QAAQ,IAAIhB;QACpCiB,UAAUb,OAAOd,QAAQ;QACzB4B,MAAMd,OAAOc,IAAI,GAAGC,OAAOf,OAAOc,IAAI,IAAIlB;QAC1CoB,QAAQhB,OAAOiB,QAAQ,KAAK;QAC5BC,QAAQlB,OAAOK,YAAY,CAACC,GAAG,CAAC,aAAaV;QAC7CW;IACD;IAEA,IAAI,CAACC,OAAOM,IAAI,EAAE;QACjB,IAAIN,OAAOQ,MAAM,EAAE;YAClBR,OAAOM,IAAI,GAAG;QACf,OAAO;YACNN,OAAOM,IAAI,GAAG;QACf;IACD;IAEA,MAAMK,eAAenB,OAAOoB,QAAQ,CAACC,KAAK,CAAC,KAAKC,MAAM,CAACC;IACvD,MAAMC,sBAAsBxB,OAAOd,QAAQ,CAACuC,KAAK,CAAC;IAElD,IAAIjB,OAAOD,SAAS,EAAE;QACrBC,OAAOkB,MAAM,GAAGP,YAAY,CAAC,EAAE;IAChC,OAAO,IAAIK,qBAAqB;QAC/BhB,OAAOkB,MAAM,GAAGF,mBAAmB,CAAC,EAAE;QACtChB,OAAOK,QAAQ,GAAGb,OAAOd,QAAQ;QACjC,IAAI,CAACsB,OAAOU,MAAM,IAAIM,mBAAmB,CAAC,EAAE,EAAE;YAC7ChB,OAAOU,MAAM,GAAGM,mBAAmB,CAAC,EAAE;QACvC;QACAhB,OAAOD,SAAS,GAAG;IACpB,OAAO;QACNC,OAAOkB,MAAM,GAAGP,YAAY,CAAC,EAAE;QAC/B,IAAIX,OAAOD,SAAS,KAAKX,WAAW;YACnCY,OAAOD,SAAS,GAAG;QACpB;IACD;IAEA,gCAAgC;IAChC,KAAK,MAAM,CAACoB,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACnC,MAAO;QAChD,IAAIiC,UAAUhC,aAAagC,UAAU,QAAQD,OAAOnB,QAAQ;YAC1DA,MAAkC,CAACmB,IAAI,GAAGC;QAC5C;IACD;IAEA,OAAOpB;AACR"}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { parseS3Url } from "./parseS3Url.js";
|
|
3
|
+
describe("parseS3Url", function () {
|
|
4
|
+
beforeEach(function () {
|
|
5
|
+
vi.restoreAllMocks();
|
|
6
|
+
});
|
|
7
|
+
it("should return undefined for empty URL", function () {
|
|
8
|
+
var result = parseS3Url({
|
|
9
|
+
url: ""
|
|
10
|
+
});
|
|
11
|
+
expect(result).toBeUndefined();
|
|
12
|
+
});
|
|
13
|
+
it("should return undefined for undefined URL", function () {
|
|
14
|
+
var result = parseS3Url({
|
|
15
|
+
url: undefined
|
|
16
|
+
});
|
|
17
|
+
expect(result).toBeUndefined();
|
|
18
|
+
});
|
|
19
|
+
it("should parse basic HTTPS URL", function () {
|
|
20
|
+
var result = parseS3Url({
|
|
21
|
+
url: "https://s3.amazonaws.com/bucket-name"
|
|
22
|
+
});
|
|
23
|
+
expect(result).toEqual({
|
|
24
|
+
accessKeyId: undefined,
|
|
25
|
+
secretAccessKey: undefined,
|
|
26
|
+
endpoint: "s3.amazonaws.com",
|
|
27
|
+
port: 443,
|
|
28
|
+
useSsl: true,
|
|
29
|
+
region: undefined,
|
|
30
|
+
pathStyle: true,
|
|
31
|
+
bucket: "bucket-name"
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
it("should parse basic HTTP URL", function () {
|
|
35
|
+
var result = parseS3Url({
|
|
36
|
+
url: "http://s3.amazonaws.com/bucket-name"
|
|
37
|
+
});
|
|
38
|
+
expect(result).toEqual({
|
|
39
|
+
accessKeyId: undefined,
|
|
40
|
+
secretAccessKey: undefined,
|
|
41
|
+
endpoint: "s3.amazonaws.com",
|
|
42
|
+
port: 80,
|
|
43
|
+
useSsl: false,
|
|
44
|
+
region: undefined,
|
|
45
|
+
pathStyle: true,
|
|
46
|
+
bucket: "bucket-name"
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
it("should parse S3 protocol URL", function () {
|
|
50
|
+
var result = parseS3Url({
|
|
51
|
+
url: "s3://s3.amazonaws.com/bucket-name"
|
|
52
|
+
});
|
|
53
|
+
expect(result).toEqual({
|
|
54
|
+
accessKeyId: undefined,
|
|
55
|
+
secretAccessKey: undefined,
|
|
56
|
+
endpoint: "s3.amazonaws.com",
|
|
57
|
+
port: 443,
|
|
58
|
+
useSsl: true,
|
|
59
|
+
region: undefined,
|
|
60
|
+
pathStyle: true,
|
|
61
|
+
bucket: "bucket-name"
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
it("should parse URL with credentials", function () {
|
|
65
|
+
var result = parseS3Url({
|
|
66
|
+
url: "https://user:pass@s3.amazonaws.com/bucket-name"
|
|
67
|
+
});
|
|
68
|
+
expect(result).toEqual({
|
|
69
|
+
accessKeyId: "user",
|
|
70
|
+
secretAccessKey: "pass",
|
|
71
|
+
endpoint: "s3.amazonaws.com",
|
|
72
|
+
port: 443,
|
|
73
|
+
useSsl: true,
|
|
74
|
+
region: undefined,
|
|
75
|
+
pathStyle: true,
|
|
76
|
+
bucket: "bucket-name"
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
it("should parse URL with port", function () {
|
|
80
|
+
var result = parseS3Url({
|
|
81
|
+
url: "https://s3.amazonaws.com:9000/bucket-name"
|
|
82
|
+
});
|
|
83
|
+
expect(result).toEqual({
|
|
84
|
+
accessKeyId: undefined,
|
|
85
|
+
secretAccessKey: undefined,
|
|
86
|
+
endpoint: "s3.amazonaws.com",
|
|
87
|
+
port: 9000,
|
|
88
|
+
useSsl: true,
|
|
89
|
+
region: undefined,
|
|
90
|
+
pathStyle: true,
|
|
91
|
+
bucket: "bucket-name"
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
it("should parse URL with region query parameter", function () {
|
|
95
|
+
var result = parseS3Url({
|
|
96
|
+
url: "https://s3.amazonaws.com/bucket-name?region=us-east-1"
|
|
97
|
+
});
|
|
98
|
+
expect(result).toEqual({
|
|
99
|
+
accessKeyId: undefined,
|
|
100
|
+
secretAccessKey: undefined,
|
|
101
|
+
endpoint: "s3.amazonaws.com",
|
|
102
|
+
port: 443,
|
|
103
|
+
useSsl: true,
|
|
104
|
+
region: "us-east-1",
|
|
105
|
+
pathStyle: true,
|
|
106
|
+
bucket: "bucket-name"
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
it("should parse URL with pathStyle parameter", function () {
|
|
110
|
+
var result = parseS3Url({
|
|
111
|
+
url: "https://s3.amazonaws.com/bucket-name?pathStyle=true"
|
|
112
|
+
});
|
|
113
|
+
expect(result).toEqual({
|
|
114
|
+
accessKeyId: undefined,
|
|
115
|
+
secretAccessKey: undefined,
|
|
116
|
+
endpoint: "s3.amazonaws.com",
|
|
117
|
+
port: 443,
|
|
118
|
+
useSsl: true,
|
|
119
|
+
region: undefined,
|
|
120
|
+
pathStyle: true,
|
|
121
|
+
bucket: "bucket-name"
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
it("should parse URL with pathStyle=false parameter", function () {
|
|
125
|
+
var result = parseS3Url({
|
|
126
|
+
url: "https://s3.amazonaws.com/bucket-name?pathStyle=false"
|
|
127
|
+
});
|
|
128
|
+
expect(result).toEqual({
|
|
129
|
+
accessKeyId: undefined,
|
|
130
|
+
secretAccessKey: undefined,
|
|
131
|
+
endpoint: "s3.amazonaws.com",
|
|
132
|
+
port: 443,
|
|
133
|
+
useSsl: true,
|
|
134
|
+
region: undefined,
|
|
135
|
+
pathStyle: false,
|
|
136
|
+
bucket: "bucket-name"
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
it("should detect path style for IP addresses", function () {
|
|
140
|
+
var result = parseS3Url({
|
|
141
|
+
url: "https://192.168.1.1/bucket-name"
|
|
142
|
+
});
|
|
143
|
+
expect(result).toEqual({
|
|
144
|
+
accessKeyId: undefined,
|
|
145
|
+
secretAccessKey: undefined,
|
|
146
|
+
endpoint: "192.168.1.1",
|
|
147
|
+
port: 443,
|
|
148
|
+
useSsl: true,
|
|
149
|
+
region: undefined,
|
|
150
|
+
pathStyle: true,
|
|
151
|
+
bucket: "bucket-name"
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
it("should detect path style for IPv6 addresses", function () {
|
|
155
|
+
var result = parseS3Url({
|
|
156
|
+
url: "https://[2001:db8::1]/bucket-name"
|
|
157
|
+
});
|
|
158
|
+
expect(result).toEqual({
|
|
159
|
+
accessKeyId: undefined,
|
|
160
|
+
secretAccessKey: undefined,
|
|
161
|
+
endpoint: "[2001:db8::1]",
|
|
162
|
+
port: 443,
|
|
163
|
+
useSsl: true,
|
|
164
|
+
region: undefined,
|
|
165
|
+
pathStyle: true,
|
|
166
|
+
bucket: "bucket-name"
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
it("should parse AWS virtual hosted style URL", function () {
|
|
170
|
+
var result = parseS3Url({
|
|
171
|
+
url: "https://my-bucket.s3.us-east-1.amazonaws.com"
|
|
172
|
+
});
|
|
173
|
+
expect(result).toEqual({
|
|
174
|
+
accessKeyId: undefined,
|
|
175
|
+
secretAccessKey: undefined,
|
|
176
|
+
endpoint: "my-bucket.s3.us-east-1.amazonaws.com",
|
|
177
|
+
port: 443,
|
|
178
|
+
useSsl: true,
|
|
179
|
+
region: "us-east-1",
|
|
180
|
+
pathStyle: false,
|
|
181
|
+
bucket: "my-bucket"
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
it("should parse AWS virtual hosted style URL with custom endpoint", function () {
|
|
185
|
+
var result = parseS3Url({
|
|
186
|
+
url: "https://my-bucket.s3.amazonaws.com"
|
|
187
|
+
});
|
|
188
|
+
expect(result).toEqual({
|
|
189
|
+
accessKeyId: undefined,
|
|
190
|
+
secretAccessKey: undefined,
|
|
191
|
+
endpoint: "my-bucket.s3.amazonaws.com",
|
|
192
|
+
port: 443,
|
|
193
|
+
useSsl: true,
|
|
194
|
+
region: undefined,
|
|
195
|
+
pathStyle: false,
|
|
196
|
+
bucket: "my-bucket"
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
it("should override parameters with provided options", function () {
|
|
200
|
+
var result = parseS3Url({
|
|
201
|
+
url: "https://s3.amazonaws.com/bucket-name",
|
|
202
|
+
region: "us-west-2",
|
|
203
|
+
pathStyle: false
|
|
204
|
+
});
|
|
205
|
+
expect(result).toEqual({
|
|
206
|
+
accessKeyId: undefined,
|
|
207
|
+
secretAccessKey: undefined,
|
|
208
|
+
endpoint: "s3.amazonaws.com",
|
|
209
|
+
port: 443,
|
|
210
|
+
useSsl: true,
|
|
211
|
+
region: "us-west-2",
|
|
212
|
+
pathStyle: false,
|
|
213
|
+
bucket: "bucket-name"
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
it("should use S3_URL environment variable by default", function () {
|
|
217
|
+
vi.stubEnv("S3_URL", "https://env-bucket.s3.amazonaws.com");
|
|
218
|
+
var result = parseS3Url();
|
|
219
|
+
expect(result).toEqual({
|
|
220
|
+
accessKeyId: undefined,
|
|
221
|
+
secretAccessKey: undefined,
|
|
222
|
+
endpoint: "env-bucket.s3.amazonaws.com",
|
|
223
|
+
port: 443,
|
|
224
|
+
useSsl: true,
|
|
225
|
+
region: undefined,
|
|
226
|
+
pathStyle: false,
|
|
227
|
+
bucket: "env-bucket"
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
it("should throw error for invalid URL", function () {
|
|
231
|
+
expect(function () {
|
|
232
|
+
return parseS3Url({
|
|
233
|
+
url: "invalid-url"
|
|
234
|
+
});
|
|
235
|
+
}).toThrow("Invalid S3 URL: invalid-url");
|
|
236
|
+
});
|
|
237
|
+
it("should handle complex URL with multiple parameters", function () {
|
|
238
|
+
var result = parseS3Url({
|
|
239
|
+
url: "https://user:pass@custom-s3.com:9000/my-bucket?region=us-east-1&pathStyle=true"
|
|
240
|
+
});
|
|
241
|
+
expect(result).toEqual({
|
|
242
|
+
accessKeyId: "user",
|
|
243
|
+
secretAccessKey: "pass",
|
|
244
|
+
endpoint: "custom-s3.com",
|
|
245
|
+
port: 9000,
|
|
246
|
+
useSsl: true,
|
|
247
|
+
region: "us-east-1",
|
|
248
|
+
pathStyle: true,
|
|
249
|
+
bucket: "my-bucket"
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
it("should ignore undefined and null values in rest parameters", function () {
|
|
253
|
+
var result = parseS3Url({
|
|
254
|
+
url: "https://s3.amazonaws.com/bucket-name",
|
|
255
|
+
region: "us-west-2",
|
|
256
|
+
port: undefined,
|
|
257
|
+
useSsl: null
|
|
258
|
+
});
|
|
259
|
+
expect(result).toEqual({
|
|
260
|
+
accessKeyId: undefined,
|
|
261
|
+
secretAccessKey: undefined,
|
|
262
|
+
endpoint: "s3.amazonaws.com",
|
|
263
|
+
port: 443,
|
|
264
|
+
useSsl: true,
|
|
265
|
+
region: "us-west-2",
|
|
266
|
+
pathStyle: true,
|
|
267
|
+
bucket: "bucket-name"
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
});
|