@adgytec/adgytec-web-utils 0.0.5 → 0.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/dist/chunks/create +24 -0
- package/dist/chunks/create.map +1 -0
- package/dist/chunks/decode +15 -15
- package/dist/chunks/parse +29 -12
- package/dist/chunks/parse.map +1 -1
- package/dist/chunks/schema +212 -187
- package/dist/chunks/schema.map +1 -1
- package/dist/chunks/server +148 -0
- package/dist/chunks/server.map +1 -0
- package/dist/chunks/uploadDetails +92 -91
- package/dist/chunks/uploadDetails.map +1 -1
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +5 -3
- package/dist/constants/index.js.map +1 -1
- package/dist/constants/media_limits.d.ts +2 -0
- package/dist/errorCodes/auth.d.ts +3 -0
- package/dist/errorCodes/common.d.ts +2 -0
- package/dist/errorCodes/iam.d.ts +2 -0
- package/dist/errorCodes/index.d.ts +1 -0
- package/dist/errorCodes/index.js +31 -85
- package/dist/errorCodes/index.js.map +1 -1
- package/dist/errorCodes/media.d.ts +2 -0
- package/dist/errorCodes/overrides.d.ts +2 -0
- package/dist/errorCodes/pagination.d.ts +2 -0
- package/dist/errorCodes/reqBody.d.ts +2 -0
- package/dist/errorCodes/server.d.ts +2 -0
- package/dist/errorSchema/create.d.ts +2 -0
- package/dist/errorSchema/index.d.ts +1 -0
- package/dist/errorSchema/index.js +31 -28
- package/dist/errorSchema/index.js.map +1 -1
- package/dist/errorSchema/media.d.ts +1 -1
- package/dist/errorSchema/schema.d.ts +1 -1
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +4 -3
- package/dist/errors/normalization.d.ts +12 -0
- package/dist/errors/parse.d.ts +1 -2
- package/dist/index.js +114 -99
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/applicationError +0 -28
- package/dist/chunks/applicationError.map +0 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
const i = {
|
|
2
|
+
invalidApiKey: "invalid-api-key",
|
|
3
|
+
userNotFound: "user-not-found",
|
|
4
|
+
jwtNotAcceptable: "jwt-not-acceptable",
|
|
5
|
+
invalidSignedUrl: "invalid-signed-url",
|
|
6
|
+
hashMismatch: "hash-mismatch",
|
|
7
|
+
invalidAuthHeaderValue: "invalid-auth-header-value",
|
|
8
|
+
unsupportedAuthScheme: "unsupported-auth-scheme",
|
|
9
|
+
organizationStatusBad: "bad-org-status",
|
|
10
|
+
userNotExistsInOrganizationManagement: "user-not-exists-in-organization-management",
|
|
11
|
+
userNotExistInOrganization: "user-not-exists-in-organization",
|
|
12
|
+
userDisabled: "user-disabled",
|
|
13
|
+
tokenNotFound: "token-not-found"
|
|
14
|
+
}, d = {
|
|
15
|
+
code: "auth-error",
|
|
16
|
+
items: [
|
|
17
|
+
i.invalidApiKey,
|
|
18
|
+
i.jwtNotAcceptable,
|
|
19
|
+
i.invalidAuthHeaderValue,
|
|
20
|
+
i.unsupportedAuthScheme,
|
|
21
|
+
i.tokenNotFound
|
|
22
|
+
]
|
|
23
|
+
}, s = {
|
|
24
|
+
code: i.invalidSignedUrl,
|
|
25
|
+
items: [i.hashMismatch]
|
|
26
|
+
}, e = {
|
|
27
|
+
invalidId: "invalid-id",
|
|
28
|
+
routeNotFound: "route-not-found",
|
|
29
|
+
methodNotAllowed: "method-not-allowed",
|
|
30
|
+
networkError: "network-error",
|
|
31
|
+
unexpectedError: "unexpected-error",
|
|
32
|
+
zodError: "zod-error"
|
|
33
|
+
}, l = {
|
|
34
|
+
code: e.unexpectedError,
|
|
35
|
+
items: [
|
|
36
|
+
e.invalidId,
|
|
37
|
+
e.routeNotFound,
|
|
38
|
+
e.methodNotAllowed,
|
|
39
|
+
e.zodError
|
|
40
|
+
]
|
|
41
|
+
}, u = {
|
|
42
|
+
formValidationFailed: "validation-failed"
|
|
43
|
+
}, m = {
|
|
44
|
+
missing: "missing",
|
|
45
|
+
overflow: "overflow",
|
|
46
|
+
underflow: "underflow",
|
|
47
|
+
length: "length",
|
|
48
|
+
invalid: "invalid",
|
|
49
|
+
unknown: "unknown"
|
|
50
|
+
}, p = {
|
|
51
|
+
invalidValue: "invalid-value",
|
|
52
|
+
invalidEnumValue: "invalid-enum-value",
|
|
53
|
+
requireHttps: "require-https",
|
|
54
|
+
missingHost: "missing-host",
|
|
55
|
+
containsPath: "contains-path",
|
|
56
|
+
containsQuery: "contains-query",
|
|
57
|
+
containsFragment: "contains-fragment",
|
|
58
|
+
absoluteUrl: "absolute-url",
|
|
59
|
+
nilID: "nil-id",
|
|
60
|
+
invalidEmail: "invalid-email",
|
|
61
|
+
missingMxRecords: "missing-mx-records",
|
|
62
|
+
notDigit: "not-digit",
|
|
63
|
+
notBase64UrlEncoded: "not-base64-url-encoded",
|
|
64
|
+
invalidUrl: "invalid-url",
|
|
65
|
+
nullValue: "null-value"
|
|
66
|
+
}, r = {
|
|
67
|
+
selfPermissionMismatch: "self-permission-mismatch",
|
|
68
|
+
invalidActor: "invalid-actor",
|
|
69
|
+
permissionExplicitlyDenied: "permission-explicitly-denied",
|
|
70
|
+
missingPermission: "missing-permission"
|
|
71
|
+
}, c = {
|
|
72
|
+
code: "authorization-error",
|
|
73
|
+
items: [r.selfPermissionMismatch, r.invalidActor]
|
|
74
|
+
}, o = {
|
|
75
|
+
invalidMultipartNumber: "invalid-multipart-upload-part-number",
|
|
76
|
+
mediaObjectNotFound: "object-not-found",
|
|
77
|
+
mediaTooLarge: "media-too-large",
|
|
78
|
+
mediaItemsLimitExceeded: "media-items-limit-exceeded",
|
|
79
|
+
uploadAlreadyCompleted: "upload-already-completed",
|
|
80
|
+
unsupportedObjectUploaded: "unsupported-object-uploaded",
|
|
81
|
+
completeMultipartUploadCalledTooSoon: "complete-multipart-upload-called-too-soon",
|
|
82
|
+
singlepartUploadFailed: "singlepart-upload-failed",
|
|
83
|
+
multipartPartUploadFailed: "multipart-part-upload-failed",
|
|
84
|
+
missingETagValue: "missing-etag-value"
|
|
85
|
+
}, v = {
|
|
86
|
+
code: "media-upload-error",
|
|
87
|
+
items: [
|
|
88
|
+
o.invalidMultipartNumber,
|
|
89
|
+
o.uploadAlreadyCompleted,
|
|
90
|
+
o.unsupportedObjectUploaded,
|
|
91
|
+
o.completeMultipartUploadCalledTooSoon,
|
|
92
|
+
o.singlepartUploadFailed,
|
|
93
|
+
o.multipartPartUploadFailed,
|
|
94
|
+
o.missingETagValue
|
|
95
|
+
]
|
|
96
|
+
}, t = {
|
|
97
|
+
invalidCursorValue: "invalid-cursor-value"
|
|
98
|
+
}, g = {
|
|
99
|
+
code: e.unexpectedError,
|
|
100
|
+
items: [t.invalidCursorValue]
|
|
101
|
+
}, a = {
|
|
102
|
+
invalidRequestBody: "invalid-request-body",
|
|
103
|
+
unknownFieldInRequestBody: "unknown-field-in-request-body",
|
|
104
|
+
emptyRequestBody: "empty-request-body",
|
|
105
|
+
requestBodyTooLarge: "request-body-too-large"
|
|
106
|
+
}, h = {
|
|
107
|
+
code: e.unexpectedError,
|
|
108
|
+
items: [
|
|
109
|
+
a.invalidRequestBody,
|
|
110
|
+
a.unknownFieldInRequestBody,
|
|
111
|
+
a.emptyRequestBody,
|
|
112
|
+
a.requestBodyTooLarge
|
|
113
|
+
]
|
|
114
|
+
}, n = {
|
|
115
|
+
malformedResponseBody: "malformed-response-body",
|
|
116
|
+
malformedJsonFromServer: "malformed-json-from-server",
|
|
117
|
+
invalidResponseShape: "invalid-response-shape",
|
|
118
|
+
unknownServerError: "unknown-server-error",
|
|
119
|
+
internalServerError: "internal-server-error"
|
|
120
|
+
}, y = {
|
|
121
|
+
code: e.unexpectedError,
|
|
122
|
+
items: [
|
|
123
|
+
n.malformedJsonFromServer,
|
|
124
|
+
n.malformedResponseBody,
|
|
125
|
+
n.invalidResponseShape
|
|
126
|
+
]
|
|
127
|
+
};
|
|
128
|
+
export {
|
|
129
|
+
i as a,
|
|
130
|
+
d as b,
|
|
131
|
+
e as c,
|
|
132
|
+
l as d,
|
|
133
|
+
p as e,
|
|
134
|
+
u as f,
|
|
135
|
+
m as g,
|
|
136
|
+
c as h,
|
|
137
|
+
r as i,
|
|
138
|
+
v as j,
|
|
139
|
+
g as k,
|
|
140
|
+
a as l,
|
|
141
|
+
o as m,
|
|
142
|
+
y as n,
|
|
143
|
+
s as o,
|
|
144
|
+
t as p,
|
|
145
|
+
h as r,
|
|
146
|
+
n as s
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=server.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server","sources":["../../src/errorCodes/auth.ts","../../src/errorCodes/common.ts","../../src/errorCodes/form.ts","../../src/errorCodes/iam.ts","../../src/errorCodes/media.ts","../../src/errorCodes/pagination.ts","../../src/errorCodes/reqBody.ts","../../src/errorCodes/server.ts"],"sourcesContent":["import type { ErrorNormalization } from \"../errors\";\n\nexport const authCodes = {\n invalidApiKey: \"invalid-api-key\",\n userNotFound: \"user-not-found\",\n jwtNotAcceptable: \"jwt-not-acceptable\",\n invalidSignedUrl: \"invalid-signed-url\",\n hashMismatch: \"hash-mismatch\",\n invalidAuthHeaderValue: \"invalid-auth-header-value\",\n unsupportedAuthScheme: \"unsupported-auth-scheme\",\n organizationStatusBad: \"bad-org-status\",\n userNotExistsInOrganizationManagement:\n \"user-not-exists-in-organization-management\",\n userNotExistInOrganization: \"user-not-exists-in-organization\",\n userDisabled: \"user-disabled\",\n tokenNotFound: \"token-not-found\",\n} as const;\n\nexport const authOverrides: ErrorNormalization = {\n code: \"auth-error\",\n items: [\n authCodes.invalidApiKey,\n authCodes.jwtNotAcceptable,\n authCodes.invalidAuthHeaderValue,\n authCodes.unsupportedAuthScheme,\n authCodes.tokenNotFound,\n ],\n} as const;\n\nexport const signedURLOverrides: ErrorNormalization = {\n code: authCodes.invalidSignedUrl,\n items: [authCodes.hashMismatch],\n} as const;\n","import type { ErrorNormalization } from \"../errors\";\n\nexport const commonCodes = {\n invalidId: \"invalid-id\",\n routeNotFound: \"route-not-found\",\n methodNotAllowed: \"method-not-allowed\",\n networkError: \"network-error\",\n unexpectedError: \"unexpected-error\",\n zodError: \"zod-error\",\n} as const;\n\nexport const commonOverrides: ErrorNormalization = {\n code: commonCodes.unexpectedError,\n items: [\n commonCodes.invalidId,\n commonCodes.routeNotFound,\n commonCodes.methodNotAllowed,\n commonCodes.zodError,\n ],\n} as const;\n","export const formCodes = {\n formValidationFailed: \"validation-failed\",\n} as const;\n\nexport const formFieldTypes = {\n missing: \"missing\",\n overflow: \"overflow\",\n underflow: \"underflow\",\n length: \"length\",\n invalid: \"invalid\",\n unknown: \"unknown\",\n} as const;\n\nexport const formFieldInvalidTypeCauses = {\n invalidValue: \"invalid-value\",\n invalidEnumValue: \"invalid-enum-value\",\n requireHttps: \"require-https\",\n missingHost: \"missing-host\",\n containsPath: \"contains-path\",\n containsQuery: \"contains-query\",\n containsFragment: \"contains-fragment\",\n absoluteUrl: \"absolute-url\",\n nilID: \"nil-id\",\n invalidEmail: \"invalid-email\",\n missingMxRecords: \"missing-mx-records\",\n notDigit: \"not-digit\",\n notBase64UrlEncoded: \"not-base64-url-encoded\",\n invalidUrl: \"invalid-url\",\n nullValue: \"null-value\",\n} as const;\n","import type { ErrorNormalization } from \"../errors\";\n\nexport const iamCodes = {\n selfPermissionMismatch: \"self-permission-mismatch\",\n invalidActor: \"invalid-actor\",\n permissionExplicitlyDenied: \"permission-explicitly-denied\",\n missingPermission: \"missing-permission\",\n} as const;\n\nexport const iamOverrides: ErrorNormalization = {\n code: \"authorization-error\",\n items: [iamCodes.selfPermissionMismatch, iamCodes.invalidActor],\n} as const;\n","import type { ErrorNormalization } from \"../errors\";\n\nexport const mediaCodes = {\n invalidMultipartNumber: \"invalid-multipart-upload-part-number\",\n mediaObjectNotFound: \"object-not-found\",\n mediaTooLarge: \"media-too-large\",\n mediaItemsLimitExceeded: \"media-items-limit-exceeded\",\n uploadAlreadyCompleted: \"upload-already-completed\",\n unsupportedObjectUploaded: \"unsupported-object-uploaded\",\n completeMultipartUploadCalledTooSoon:\n \"complete-multipart-upload-called-too-soon\",\n\n singlepartUploadFailed: \"singlepart-upload-failed\",\n multipartPartUploadFailed: \"multipart-part-upload-failed\",\n missingETagValue: \"missing-etag-value\",\n} as const;\n\nexport const mediaOverrides: ErrorNormalization = {\n code: \"media-upload-error\",\n items: [\n mediaCodes.invalidMultipartNumber,\n mediaCodes.uploadAlreadyCompleted,\n mediaCodes.unsupportedObjectUploaded,\n mediaCodes.completeMultipartUploadCalledTooSoon,\n mediaCodes.singlepartUploadFailed,\n mediaCodes.multipartPartUploadFailed,\n mediaCodes.missingETagValue,\n ],\n} as const;\n","import type { ErrorNormalization } from \"../errors\";\nimport { commonCodes } from \"./common\";\n\nexport const paginationCodes = {\n invalidCursorValue: \"invalid-cursor-value\",\n} as const;\n\nexport const paginationOverrides: ErrorNormalization = {\n code: commonCodes.unexpectedError,\n items: [paginationCodes.invalidCursorValue],\n} as const;\n","import type { ErrorNormalization } from \"../errors\";\nimport { commonCodes } from \"./common\";\n\nexport const requestBodyCodes = {\n invalidRequestBody: \"invalid-request-body\",\n unknownFieldInRequestBody: \"unknown-field-in-request-body\",\n emptyRequestBody: \"empty-request-body\",\n requestBodyTooLarge: \"request-body-too-large\",\n} as const;\n\nexport const reqBodyOverrides: ErrorNormalization = {\n code: commonCodes.unexpectedError,\n items: [\n requestBodyCodes.invalidRequestBody,\n requestBodyCodes.unknownFieldInRequestBody,\n requestBodyCodes.emptyRequestBody,\n requestBodyCodes.requestBodyTooLarge,\n ],\n} as const;\n","import type { ErrorNormalization } from \"../errors\";\nimport { commonCodes } from \"./common\";\n\nexport const serverCodes = {\n malformedResponseBody: \"malformed-response-body\",\n malformedJsonFromServer: \"malformed-json-from-server\",\n invalidResponseShape: \"invalid-response-shape\",\n unknownServerError: \"unknown-server-error\",\n internalServerError: \"internal-server-error\",\n} as const;\n\nexport const serverOverrides: ErrorNormalization = {\n code: commonCodes.unexpectedError,\n items: [\n serverCodes.malformedJsonFromServer,\n serverCodes.malformedResponseBody,\n serverCodes.invalidResponseShape,\n ],\n} as const;\n"],"names":["authCodes","authOverrides","signedURLOverrides","commonCodes","commonOverrides","formCodes","formFieldTypes","formFieldInvalidTypeCauses","iamCodes","iamOverrides","mediaCodes","mediaOverrides","paginationCodes","paginationOverrides","requestBodyCodes","reqBodyOverrides","serverCodes","serverOverrides"],"mappings":"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"}
|
|
@@ -1,48 +1,49 @@
|
|
|
1
|
-
import { v7 as
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { v7 as y } from "uuid";
|
|
2
|
+
import { MediaUploadLimit as c, MediaItemsLimit as h, httpMethods as u, httpReqHeaders as l, httpRequestCredentials as f } from "../constants/index.js";
|
|
3
|
+
import { a as w, n as g } from "./create";
|
|
4
|
+
import s from "zod";
|
|
5
|
+
import { Queue as U } from "@datastructures-js/queue";
|
|
6
|
+
import { m as d } from "./server";
|
|
7
|
+
import { A as p, B as n } from "./schema";
|
|
8
|
+
import { d as C } from "./decode";
|
|
9
|
+
const P = (a) => (a.size > c && w(a.name, a.size, c), {
|
|
10
|
+
id: y(),
|
|
10
11
|
name: a.name,
|
|
11
12
|
size: a.size,
|
|
12
13
|
file: a
|
|
13
|
-
}),
|
|
14
|
+
}), F = (a) => (a.length > h && g(a.length, h), a.map(P)), R = (a) => ({
|
|
14
15
|
id: a.id,
|
|
15
16
|
size: a.size,
|
|
16
17
|
name: a.name
|
|
17
|
-
}),
|
|
18
|
-
presignPut:
|
|
19
|
-
partNumber:
|
|
20
|
-
partSize:
|
|
21
|
-
}),
|
|
22
|
-
mediaID:
|
|
23
|
-
uploadType:
|
|
24
|
-
multipartPresignPart:
|
|
25
|
-
multipartSuccessCallback:
|
|
26
|
-
}),
|
|
27
|
-
mediaID:
|
|
28
|
-
uploadType:
|
|
29
|
-
presignPut:
|
|
30
|
-
singlepartSuccessCallback:
|
|
31
|
-
}),
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
}), H = (a) => a.map(R), L = s.object({
|
|
19
|
+
presignPut: s.url(),
|
|
20
|
+
partNumber: s.int().positive().lte(1e4),
|
|
21
|
+
partSize: s.int().positive().gt(0)
|
|
22
|
+
}), S = s.object({
|
|
23
|
+
mediaID: s.uuidv7(),
|
|
24
|
+
uploadType: s.literal("multipart"),
|
|
25
|
+
multipartPresignPart: s.array(L).nonempty(),
|
|
26
|
+
multipartSuccessCallback: s.url()
|
|
27
|
+
}), N = s.object({
|
|
28
|
+
mediaID: s.uuidv7(),
|
|
29
|
+
uploadType: s.literal("singlepart"),
|
|
30
|
+
presignPut: s.url(),
|
|
31
|
+
singlepartSuccessCallback: s.url()
|
|
32
|
+
}), J = s.discriminatedUnion("uploadType", [
|
|
33
|
+
S,
|
|
34
|
+
N
|
|
34
35
|
]);
|
|
35
|
-
class
|
|
36
|
-
#
|
|
36
|
+
class z {
|
|
37
|
+
#r;
|
|
37
38
|
#t;
|
|
38
39
|
#a;
|
|
39
40
|
#i;
|
|
40
41
|
#e;
|
|
41
42
|
#n;
|
|
42
43
|
#o;
|
|
43
|
-
#
|
|
44
|
-
constructor(t, e, i,
|
|
45
|
-
this.#
|
|
44
|
+
#s;
|
|
45
|
+
constructor(t, e, i, r) {
|
|
46
|
+
this.#r = t, this.#t = e, this.#a = [], this.#i = /* @__PURE__ */ new Set(), this.#e = r, this.#n = i, this.#o = !1, this.#s = !1;
|
|
46
47
|
}
|
|
47
48
|
get failed() {
|
|
48
49
|
return this.#o;
|
|
@@ -51,7 +52,7 @@ class R {
|
|
|
51
52
|
this.#o = !0;
|
|
52
53
|
}
|
|
53
54
|
get id() {
|
|
54
|
-
return this.#
|
|
55
|
+
return this.#r;
|
|
55
56
|
}
|
|
56
57
|
get completeURL() {
|
|
57
58
|
return this.#n;
|
|
@@ -72,10 +73,10 @@ class R {
|
|
|
72
73
|
return !this.failed && this.#i.size === this.#e;
|
|
73
74
|
}
|
|
74
75
|
tryStartComplete() {
|
|
75
|
-
return this.#
|
|
76
|
+
return this.#s || !this.canComplete ? !1 : (this.#s = !0, !0);
|
|
76
77
|
}
|
|
77
78
|
resetComplete() {
|
|
78
|
-
this.#
|
|
79
|
+
this.#s = !1;
|
|
79
80
|
}
|
|
80
81
|
get totalPartsCount() {
|
|
81
82
|
return this.#e;
|
|
@@ -84,14 +85,14 @@ class R {
|
|
|
84
85
|
return this.#i.size;
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
|
-
class
|
|
88
|
-
#
|
|
88
|
+
class b {
|
|
89
|
+
#r;
|
|
89
90
|
#t;
|
|
90
91
|
#a;
|
|
91
92
|
#i;
|
|
92
93
|
#e;
|
|
93
|
-
constructor(t, e, i,
|
|
94
|
-
this.#
|
|
94
|
+
constructor(t, e, i, r) {
|
|
95
|
+
this.#r = t, this.#t = e, this.#i = r, this.#a = i, this.#e = !1;
|
|
95
96
|
}
|
|
96
97
|
get canComplete() {
|
|
97
98
|
return this.#e;
|
|
@@ -100,7 +101,7 @@ class S {
|
|
|
100
101
|
this.#e = !0;
|
|
101
102
|
}
|
|
102
103
|
get id() {
|
|
103
|
-
return this.#
|
|
104
|
+
return this.#r;
|
|
104
105
|
}
|
|
105
106
|
get blob() {
|
|
106
107
|
return this.#t;
|
|
@@ -112,28 +113,28 @@ class S {
|
|
|
112
113
|
return this.#a;
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
|
-
const
|
|
116
|
+
const D = {
|
|
116
117
|
concurrentUploads: 4,
|
|
117
118
|
retryLimit: 3
|
|
118
119
|
};
|
|
119
|
-
class
|
|
120
|
-
#
|
|
120
|
+
class M {
|
|
121
|
+
#r;
|
|
121
122
|
#t;
|
|
122
123
|
#a;
|
|
123
124
|
#i;
|
|
124
125
|
#e;
|
|
125
126
|
#n;
|
|
126
|
-
constructor(t, e, i =
|
|
127
|
-
this.#
|
|
127
|
+
constructor(t, e, i = D, r) {
|
|
128
|
+
this.#r = t, this.#t = e, this.#a = i.concurrentUploads, this.#i = i.retryLimit, this.#e = new U(), this.#n = r;
|
|
128
129
|
}
|
|
129
130
|
#o(t) {
|
|
130
131
|
return t < this.#i;
|
|
131
132
|
}
|
|
132
|
-
#
|
|
133
|
+
#s(t) {
|
|
133
134
|
this.#e.enqueue(t);
|
|
134
135
|
}
|
|
135
136
|
async init() {
|
|
136
|
-
this.#t.init(this.#
|
|
137
|
+
this.#t.init(this.#r);
|
|
137
138
|
const t = /* @__PURE__ */ new Set();
|
|
138
139
|
for await (const e of this.#m()) {
|
|
139
140
|
const i = e().finally(() => t.delete(i));
|
|
@@ -143,7 +144,7 @@ class L {
|
|
|
143
144
|
}
|
|
144
145
|
async #l(t, e) {
|
|
145
146
|
return await fetch(t, {
|
|
146
|
-
method:
|
|
147
|
+
method: u.put,
|
|
147
148
|
body: e
|
|
148
149
|
});
|
|
149
150
|
}
|
|
@@ -159,7 +160,7 @@ class L {
|
|
|
159
160
|
});
|
|
160
161
|
t.allowComplete(), await this.#h(t);
|
|
161
162
|
} catch (i) {
|
|
162
|
-
this.#o(e) ? (this.#t.uploadRetrying(t.id), this.#
|
|
163
|
+
this.#o(e) ? (this.#t.uploadRetrying(t.id), this.#s({
|
|
163
164
|
type: "singlepart-upload",
|
|
164
165
|
retryCount: e + 1,
|
|
165
166
|
singlepartObj: t
|
|
@@ -169,11 +170,11 @@ class L {
|
|
|
169
170
|
async #p(t, e, i = 0) {
|
|
170
171
|
if (!(t.failed || t.contains(e.partNumber)))
|
|
171
172
|
try {
|
|
172
|
-
const
|
|
173
|
+
const r = await this.#l(
|
|
173
174
|
e.uploadURL,
|
|
174
175
|
t.blob.slice(e.startByte, e.endByte)
|
|
175
176
|
);
|
|
176
|
-
if (!
|
|
177
|
+
if (!r.ok)
|
|
177
178
|
throw new p(
|
|
178
179
|
d.multipartPartUploadFailed,
|
|
179
180
|
{
|
|
@@ -181,7 +182,7 @@ class L {
|
|
|
181
182
|
partNumber: e.partNumber
|
|
182
183
|
}
|
|
183
184
|
);
|
|
184
|
-
const o =
|
|
185
|
+
const o = r.headers.get("ETag");
|
|
185
186
|
if (!o)
|
|
186
187
|
throw new p(d.missingETagValue, {
|
|
187
188
|
mediaID: t.id,
|
|
@@ -196,39 +197,39 @@ class L {
|
|
|
196
197
|
t.totalPartsCount
|
|
197
198
|
), !t.canComplete) return;
|
|
198
199
|
await this.#u(t);
|
|
199
|
-
} catch (
|
|
200
|
+
} catch (r) {
|
|
200
201
|
this.#o(i) ? (this.#t.multipartPartUploadRetrying(
|
|
201
202
|
t.id,
|
|
202
203
|
e.partNumber
|
|
203
|
-
), this.#
|
|
204
|
+
), this.#s({
|
|
204
205
|
type: "multipart-part-upload",
|
|
205
206
|
retryCount: i + 1,
|
|
206
207
|
multipartObj: t,
|
|
207
208
|
partInfo: e
|
|
208
|
-
})) : (t.fail(), this.#t.failed(t.id,
|
|
209
|
+
})) : (t.fail(), this.#t.failed(t.id, r));
|
|
209
210
|
}
|
|
210
211
|
}
|
|
211
212
|
async #c(t, e) {
|
|
212
|
-
let i,
|
|
213
|
+
let i, r;
|
|
213
214
|
e && (i = JSON.stringify({
|
|
214
215
|
partsInfo: e
|
|
215
|
-
}),
|
|
216
|
+
}), r = {
|
|
216
217
|
[l.contentType.key]: l.contentType.valueApplicationJSON
|
|
217
|
-
}), this.#n && (
|
|
218
|
+
}), this.#n && (r = r || {}, r[l.userLocale.key] = this.#n);
|
|
218
219
|
const o = await fetch(t, {
|
|
219
|
-
method:
|
|
220
|
+
method: u.post,
|
|
220
221
|
body: i,
|
|
221
|
-
headers:
|
|
222
|
-
credentials:
|
|
222
|
+
headers: r,
|
|
223
|
+
credentials: f.include
|
|
223
224
|
});
|
|
224
|
-
await
|
|
225
|
+
await C(o);
|
|
225
226
|
}
|
|
226
227
|
async #h(t, e = 0) {
|
|
227
228
|
if (t.canComplete)
|
|
228
229
|
try {
|
|
229
230
|
await this.#c(t.completeURL), this.#t.itemUploaded(t.id);
|
|
230
231
|
} catch (i) {
|
|
231
|
-
this.#o(e) ? (this.#t.uploadRetrying(t.id), this.#
|
|
232
|
+
this.#o(e) ? (this.#t.uploadRetrying(t.id), this.#s({
|
|
232
233
|
type: "singlepart-complete",
|
|
233
234
|
retryCount: e + 1,
|
|
234
235
|
singlepartObj: t
|
|
@@ -243,7 +244,7 @@ class L {
|
|
|
243
244
|
t.list
|
|
244
245
|
), this.#t.itemUploaded(t.id);
|
|
245
246
|
} catch (i) {
|
|
246
|
-
t.resetComplete(), this.#o(e) ? (this.#t.uploadRetrying(t.id), this.#
|
|
247
|
+
t.resetComplete(), this.#o(e) ? (this.#t.uploadRetrying(t.id), this.#s({
|
|
247
248
|
type: "multipart-complete",
|
|
248
249
|
retryCount: e + 1,
|
|
249
250
|
multipartObj: t
|
|
@@ -251,9 +252,9 @@ class L {
|
|
|
251
252
|
}
|
|
252
253
|
}
|
|
253
254
|
async *#m() {
|
|
254
|
-
for (const t of this.#
|
|
255
|
+
for (const t of this.#r) {
|
|
255
256
|
if (t.uploadType === "singlepart") {
|
|
256
|
-
const o = new
|
|
257
|
+
const o = new b(
|
|
257
258
|
t.mediaID,
|
|
258
259
|
t.file,
|
|
259
260
|
t.presignPut,
|
|
@@ -264,24 +265,24 @@ class L {
|
|
|
264
265
|
};
|
|
265
266
|
continue;
|
|
266
267
|
}
|
|
267
|
-
const e = new
|
|
268
|
+
const e = new z(
|
|
268
269
|
t.mediaID,
|
|
269
270
|
t.file,
|
|
270
271
|
t.multipartSuccessCallback,
|
|
271
272
|
t.multipartPresignPart.length
|
|
272
273
|
);
|
|
273
|
-
let i = 0,
|
|
274
|
+
let i = 0, r = 0;
|
|
274
275
|
for (const o of t.multipartPresignPart) {
|
|
275
|
-
|
|
276
|
-
const
|
|
276
|
+
r += o.partSize;
|
|
277
|
+
const m = {
|
|
277
278
|
partNumber: o.partNumber,
|
|
278
279
|
uploadURL: o.presignPut,
|
|
279
280
|
startByte: i,
|
|
280
|
-
endByte:
|
|
281
|
+
endByte: r
|
|
281
282
|
};
|
|
282
283
|
yield async () => {
|
|
283
|
-
await this.#p(e,
|
|
284
|
-
}, i =
|
|
284
|
+
await this.#p(e, m);
|
|
285
|
+
}, i = r;
|
|
285
286
|
}
|
|
286
287
|
}
|
|
287
288
|
}
|
|
@@ -329,11 +330,11 @@ class L {
|
|
|
329
330
|
}
|
|
330
331
|
}
|
|
331
332
|
}
|
|
332
|
-
const
|
|
333
|
-
await
|
|
334
|
-
},
|
|
335
|
-
await new
|
|
336
|
-
},
|
|
333
|
+
const Q = async (a, t, e, i) => {
|
|
334
|
+
await T([a], t, e, i);
|
|
335
|
+
}, T = async (a, t, e, i) => {
|
|
336
|
+
await new M(a, t, e, i).init();
|
|
337
|
+
}, E = (a, t) => {
|
|
337
338
|
if (a.id !== t.mediaID)
|
|
338
339
|
throw new n("media item and response id mismatch");
|
|
339
340
|
return {
|
|
@@ -341,7 +342,7 @@ const $ = async (a, t, e, i) => {
|
|
|
341
342
|
file: a.file,
|
|
342
343
|
size: a.size
|
|
343
344
|
};
|
|
344
|
-
},
|
|
345
|
+
}, V = (a, t) => {
|
|
345
346
|
if (a.length !== t.length)
|
|
346
347
|
throw new n(
|
|
347
348
|
`items mismatch: mediaInfos=${a.length}, apiResponses=${t.length}`
|
|
@@ -350,23 +351,23 @@ const $ = async (a, t, e, i) => {
|
|
|
350
351
|
t.map((i) => [i.mediaID, i])
|
|
351
352
|
);
|
|
352
353
|
return a.map((i) => {
|
|
353
|
-
const
|
|
354
|
-
if (!
|
|
354
|
+
const r = e.get(i.id);
|
|
355
|
+
if (!r)
|
|
355
356
|
throw new n(
|
|
356
357
|
`Could not find a matching API response for media info with id: ${i.id}`
|
|
357
358
|
);
|
|
358
|
-
return
|
|
359
|
+
return E(i, r);
|
|
359
360
|
});
|
|
360
361
|
};
|
|
361
362
|
export {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
363
|
+
J as U,
|
|
364
|
+
F as a,
|
|
365
|
+
E as b,
|
|
366
|
+
V as c,
|
|
367
|
+
H as d,
|
|
368
|
+
T as e,
|
|
369
|
+
P as n,
|
|
370
|
+
R as t,
|
|
371
|
+
Q as u
|
|
371
372
|
};
|
|
372
373
|
//# sourceMappingURL=uploadDetails.map
|