@putdotio/sdk 13.3.2 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -93
- package/dist/{forms-D5duroB1.js → forms-B9-NYUR5.js} +99 -80
- package/dist/forms-B9-NYUR5.js.map +1 -0
- package/dist/{index-C10OQIHs.d.ts → index-DHmXAQNF.d.ts} +253 -365
- package/dist/index.d.ts +2 -2
- package/dist/index.js +475 -638
- package/dist/index.js.map +1 -1
- package/dist/utilities.d.ts +17 -15
- package/dist/utilities.js +41 -52
- package/dist/utilities.js.map +1 -1
- package/package.json +7 -5
- package/dist/forms-D5duroB1.js.map +0 -1
package/dist/utilities.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { Hm as PutioRateLimitError, Lm as PutioKnownOperationErrorContract, Mm as PutioAuthError, Pm as PutioErrorEnvelope, Rm as PutioOperationError, Uo as FileBroad, jm as PutioApiError } from "./index-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
1
|
+
import { Hm as PutioRateLimitError, Lm as PutioKnownOperationErrorContract, Mm as PutioAuthError, Pm as PutioErrorEnvelope, Rm as PutioOperationError, Uo as FileBroad, jm as PutioApiError } from "./index-DHmXAQNF.js";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
export type DateInput = Date | string | null | undefined;
|
|
4
|
+
export declare const ensureUTC: (date?: DateInput) => string;
|
|
5
|
+
export declare const toTimeAgo: (date?: DateInput) => string;
|
|
6
|
+
export declare const formatDate: (date?: DateInput, format?: "LL" | Intl.DateTimeFormatOptions) => string;
|
|
7
|
+
export declare const daysDiff: (date1: DateInput, date2: DateInput) => number;
|
|
8
|
+
export declare const daysDiffFromNow: (date?: DateInput) => number;
|
|
9
|
+
export declare const getUnixTimestamp: (date: DateInput) => number;
|
|
10
|
+
export declare const secondsToDuration: (seconds: number | null | undefined) => string;
|
|
11
|
+
export declare const secondsToReadableDuration: (seconds: number | null | undefined) => string;
|
|
10
12
|
export type FileRenderType = "archive" | "audio" | "epub" | "folder" | "image" | "other" | "pdf" | "text" | "text/markdown" | "video";
|
|
11
13
|
export type FileRenderTypeInput = Pick<FileBroad, "content_type" | "extension" | "file_type">;
|
|
12
14
|
export declare const getFileRenderType: (file: FileRenderTypeInput) => FileRenderType;
|
|
@@ -23,6 +25,7 @@ export type FileUrlProviderOptions = {
|
|
|
23
25
|
readonly downloadToken: string;
|
|
24
26
|
};
|
|
25
27
|
export declare class FileUrlProvider {
|
|
28
|
+
#private;
|
|
26
29
|
readonly apiUrl: string;
|
|
27
30
|
/** The account download token from `getAccountInfo({ download_token: 1 })`, not the OAuth token. */
|
|
28
31
|
readonly downloadToken: string;
|
|
@@ -56,25 +59,25 @@ export type LocalizedErrorRecoverySuggestionTypeCaptcha = {
|
|
|
56
59
|
readonly description: string;
|
|
57
60
|
};
|
|
58
61
|
export type LocalizedErrorRecoverySuggestion = LocalizedErrorRecoverySuggestionTypeInstruction | LocalizedErrorRecoverySuggestionTypeAction | LocalizedErrorRecoverySuggestionTypeCaptcha;
|
|
62
|
+
export type LocalizedErrorMeta = Record<string, Schema.Json | undefined>;
|
|
59
63
|
export interface LocalizedErrorParams {
|
|
60
64
|
readonly message: string;
|
|
61
65
|
readonly recoverySuggestion: LocalizedErrorRecoverySuggestion;
|
|
62
66
|
readonly underlyingError: unknown;
|
|
63
|
-
readonly meta?:
|
|
67
|
+
readonly meta?: LocalizedErrorMeta;
|
|
64
68
|
}
|
|
65
69
|
export declare class LocalizedError extends Error {
|
|
66
70
|
readonly recoverySuggestion: LocalizedErrorRecoverySuggestion;
|
|
67
71
|
readonly underlyingError: unknown;
|
|
68
|
-
readonly meta:
|
|
72
|
+
readonly meta: LocalizedErrorMeta;
|
|
69
73
|
constructor(params: LocalizedErrorParams);
|
|
70
74
|
}
|
|
71
|
-
type
|
|
75
|
+
export type PutioErrorWithBody = PutioApiError | PutioAuthError | PutioRateLimitError | PutioOperationError<string, string, PutioKnownOperationErrorContract>;
|
|
72
76
|
export type PutioLocalizableError = {
|
|
73
77
|
readonly _tag?: string;
|
|
74
78
|
readonly body: PutioErrorEnvelope;
|
|
75
79
|
readonly status?: number;
|
|
76
80
|
};
|
|
77
|
-
export type PutioErrorWithBody = StatusAndBodyError;
|
|
78
81
|
export type LocalizeErrorFn<E> = (error: E) => Pick<LocalizedErrorParams, "message" | "recoverySuggestion" | "meta">;
|
|
79
82
|
export type APIErrorByStatusCodeLocalizer = {
|
|
80
83
|
readonly kind: "api_status_code";
|
|
@@ -96,7 +99,7 @@ export type GenericErrorLocalizer = {
|
|
|
96
99
|
readonly localize: LocalizeErrorFn<unknown>;
|
|
97
100
|
};
|
|
98
101
|
export type ErrorLocalizer<E> = APIErrorByStatusCodeLocalizer | APIErrorByErrorTypeLocalizer | MatchConditionLocalizer<E> | GenericErrorLocalizer;
|
|
99
|
-
export type ErrorLocalizerFn = (error:
|
|
102
|
+
export type ErrorLocalizerFn = <E>(error: E) => LocalizedError;
|
|
100
103
|
export declare const isErrorLocalizer: (fn: unknown) => fn is ErrorLocalizerFn;
|
|
101
104
|
export declare const createLocalizeError: <GlobalError>(globalLocalizers: ReadonlyArray<ErrorLocalizer<GlobalError>>) => <ScopedError extends GlobalError>(error: ScopedError, scopedLocalizers?: ReadonlyArray<ErrorLocalizer<ScopedError>>) => LocalizedError;
|
|
102
105
|
export declare const dotsToSpaces: (input: string) => string;
|
|
@@ -109,5 +112,4 @@ export declare const truncateMiddle: (input: string, options: {
|
|
|
109
112
|
readonly backLength: number;
|
|
110
113
|
readonly ellipsis?: string;
|
|
111
114
|
}) => string;
|
|
112
|
-
export {};
|
|
113
115
|
//# sourceMappingURL=utilities.d.ts.map
|
package/dist/utilities.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Predicate, Result, Schema } from "effect";
|
|
1
|
+
import { S as NonEmptyStringSchema, U as mapDecodeErrorToValidationError, k as PutioErrorEnvelopeSchema, o as buildPutioUrl, s as encodePathSegment, t as joinCsv } from "./forms-B9-NYUR5.js";
|
|
2
|
+
import { Data, Predicate, Result, Schema } from "effect";
|
|
3
3
|
// src/utilities/date.ts
|
|
4
4
|
const LONG_DATE_FORMATTER = new Intl.DateTimeFormat("en-US", {
|
|
5
5
|
dateStyle: "long",
|
|
@@ -7,12 +7,10 @@ const LONG_DATE_FORMATTER = new Intl.DateTimeFormat("en-US", {
|
|
|
7
7
|
});
|
|
8
8
|
const RELATIVE_TIME_FORMATTER = new Intl.RelativeTimeFormat("en", { numeric: "always" });
|
|
9
9
|
const ensureDate = (value) => {
|
|
10
|
+
if (value === null || value === void 0) return /* @__PURE__ */ new Date();
|
|
10
11
|
if (value instanceof Date) return value;
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
return new Date(value.endsWith("Z") ? value : `${value}Z`);
|
|
14
|
-
}
|
|
15
|
-
return /* @__PURE__ */ new Date();
|
|
12
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) return /* @__PURE__ */ new Date(`${value}T00:00:00.000Z`);
|
|
13
|
+
return new Date(value.endsWith("Z") ? value : `${value}Z`);
|
|
16
14
|
};
|
|
17
15
|
const toRelativeUnit = (secondsDelta) => {
|
|
18
16
|
const absoluteSeconds = Math.abs(secondsDelta);
|
|
@@ -41,15 +39,15 @@ const toRelativeUnit = (secondsDelta) => {
|
|
|
41
39
|
value: Math.round(secondsDelta)
|
|
42
40
|
};
|
|
43
41
|
};
|
|
44
|
-
const ensureUTC = (date
|
|
45
|
-
const toTimeAgo = (date
|
|
42
|
+
const ensureUTC = (date) => ensureDate(date).toISOString();
|
|
43
|
+
const toTimeAgo = (date) => {
|
|
46
44
|
if (!date) return "N/A";
|
|
47
45
|
const target = ensureDate(date);
|
|
48
46
|
const secondsDelta = Math.round((target.getTime() - Date.now()) / 1e3);
|
|
49
47
|
const { unit, value } = toRelativeUnit(secondsDelta);
|
|
50
48
|
return RELATIVE_TIME_FORMATTER.format(value, unit);
|
|
51
49
|
};
|
|
52
|
-
const formatDate = (date
|
|
50
|
+
const formatDate = (date, format = "LL") => {
|
|
53
51
|
if (!date) return "N/A";
|
|
54
52
|
const normalizedDate = ensureDate(date);
|
|
55
53
|
if (format === "LL") return LONG_DATE_FORMATTER.format(normalizedDate);
|
|
@@ -65,16 +63,15 @@ const daysDiff = (date1, date2) => {
|
|
|
65
63
|
const utcDay2 = Date.UTC(day2.getUTCFullYear(), day2.getUTCMonth(), day2.getUTCDate());
|
|
66
64
|
return Math.abs(Math.round((utcDay2 - utcDay1) / 864e5));
|
|
67
65
|
};
|
|
68
|
-
const daysDiffFromNow = (date
|
|
66
|
+
const daysDiffFromNow = (date) => {
|
|
69
67
|
if (!date) return 0;
|
|
70
68
|
return daysDiff(date, /* @__PURE__ */ new Date());
|
|
71
69
|
};
|
|
72
70
|
const getUnixTimestamp = (date) => Math.floor(ensureDate(date).getTime() / 1e3);
|
|
73
71
|
// src/utilities/duration.ts
|
|
74
|
-
const normalizeNumber = (value) => typeof value === "number" ? value : 0;
|
|
75
72
|
const formatPadded = (value) => String(value).padStart(2, "0");
|
|
76
73
|
const secondsToDuration = (seconds) => {
|
|
77
|
-
const normalizedSeconds = Math.floor(
|
|
74
|
+
const normalizedSeconds = Math.floor(seconds ?? 0);
|
|
78
75
|
if (normalizedSeconds <= 0) return "00:00";
|
|
79
76
|
const days = Math.floor(normalizedSeconds / 86400);
|
|
80
77
|
const hours = Math.floor(normalizedSeconds % 86400 / 3600);
|
|
@@ -94,7 +91,7 @@ const secondsToDuration = (seconds) => {
|
|
|
94
91
|
return [minutes, remainingSeconds].map(formatPadded).join(":");
|
|
95
92
|
};
|
|
96
93
|
const secondsToReadableDuration = (seconds) => {
|
|
97
|
-
const normalizedSeconds = Math.floor(
|
|
94
|
+
const normalizedSeconds = Math.floor(seconds ?? 0);
|
|
98
95
|
if (normalizedSeconds <= 0) return "N/A";
|
|
99
96
|
if (normalizedSeconds < 60) return `${normalizedSeconds} s`;
|
|
100
97
|
if (normalizedSeconds >= 86400) {
|
|
@@ -115,7 +112,7 @@ const secondsToReadableDuration = (seconds) => {
|
|
|
115
112
|
// src/utilities/file-render-type.ts
|
|
116
113
|
const getFileRenderType = (file) => {
|
|
117
114
|
const { content_type, extension, file_type } = file;
|
|
118
|
-
if (
|
|
115
|
+
if (content_type === null || content_type === void 0) return "other";
|
|
119
116
|
if (content_type === "application/x-directory") return "folder";
|
|
120
117
|
if (content_type.startsWith("audio") || file_type === "AUDIO") return "audio";
|
|
121
118
|
if (content_type.startsWith("video")) return "video";
|
|
@@ -140,7 +137,7 @@ const FILE_SIZE_UNITS = [
|
|
|
140
137
|
];
|
|
141
138
|
const toHumanFileSize = (fileSizeInBytes, options = {}) => {
|
|
142
139
|
const { decimals = 1, unitSeparator = " " } = options;
|
|
143
|
-
const parsed =
|
|
140
|
+
const parsed = Predicate.isString(fileSizeInBytes) ? Number.parseInt(fileSizeInBytes, 10) : fileSizeInBytes;
|
|
144
141
|
if (!Number.isFinite(parsed) || parsed <= 0) return `0${unitSeparator}B`;
|
|
145
142
|
const exponent = Math.min(Math.floor(Math.log(parsed) / Math.log(1024)), FILE_SIZE_UNITS.length - 1);
|
|
146
143
|
const normalized = parsed / 1024 ** exponent;
|
|
@@ -170,14 +167,16 @@ var FileUrlProvider = class {
|
|
|
170
167
|
this.apiUrl = `${this.baseUrl}/v2`;
|
|
171
168
|
this.downloadToken = downloadToken;
|
|
172
169
|
}
|
|
170
|
+
#fileUrl(fileId, resource, query = { oauth_token: this.downloadToken }) {
|
|
171
|
+
return buildPutioUrl(this.baseUrl, `/v2/files/${encodePathSegment(fileId)}/${resource}`, query);
|
|
172
|
+
}
|
|
173
173
|
getDownloadUrl(fileOrFileId) {
|
|
174
|
-
if (
|
|
175
|
-
|
|
176
|
-
return buildPutioUrl(this.baseUrl, `/v2/files/${encodePathSegment(fileOrFileId.id)}/download`, { oauth_token: this.downloadToken });
|
|
174
|
+
if (Predicate.isNumber(fileOrFileId)) return this.#fileUrl(fileOrFileId, "download");
|
|
175
|
+
return fileOrFileId.file_type === "FOLDER" ? null : this.#fileUrl(fileOrFileId.id, "download");
|
|
177
176
|
}
|
|
178
177
|
getHlsStreamUrl(file, params = {}) {
|
|
179
178
|
if (!isVideoFile(file)) return null;
|
|
180
|
-
return
|
|
179
|
+
return this.#fileUrl(file.id, "hls/media.m3u8", {
|
|
181
180
|
max_subtitle_count: params.maxSubtitleCount,
|
|
182
181
|
oauth_token: this.downloadToken,
|
|
183
182
|
original: params.playOriginal ? 1 : void 0,
|
|
@@ -185,23 +184,20 @@ var FileUrlProvider = class {
|
|
|
185
184
|
});
|
|
186
185
|
}
|
|
187
186
|
getMp4DownloadUrl(file) {
|
|
188
|
-
|
|
189
|
-
return buildPutioUrl(this.baseUrl, `/v2/files/${encodePathSegment(file.id)}/mp4/download`, { oauth_token: this.downloadToken });
|
|
187
|
+
return isVideoFile(file) && file.is_mp4_available ? this.#fileUrl(file.id, "mp4/download") : null;
|
|
190
188
|
}
|
|
191
189
|
getMp4StreamUrl(file) {
|
|
192
|
-
|
|
193
|
-
return buildPutioUrl(this.baseUrl, `/v2/files/${encodePathSegment(file.id)}/mp4/stream`, { oauth_token: this.downloadToken });
|
|
190
|
+
return isVideoFile(file) && file.is_mp4_available ? this.#fileUrl(file.id, "mp4/stream") : null;
|
|
194
191
|
}
|
|
195
192
|
getStreamUrl(file) {
|
|
196
193
|
switch (getFileRenderType(file)) {
|
|
197
|
-
case "audio": return
|
|
198
|
-
case "video": return
|
|
194
|
+
case "audio": return this.#fileUrl(file.id, "stream.mp3");
|
|
195
|
+
case "video": return this.#fileUrl(file.id, "stream");
|
|
199
196
|
default: return null;
|
|
200
197
|
}
|
|
201
198
|
}
|
|
202
199
|
getXspfUrl(file) {
|
|
203
|
-
|
|
204
|
-
return buildPutioUrl(this.baseUrl, `/v2/files/${encodePathSegment(file.id)}/xspf`, { oauth_token: this.downloadToken });
|
|
200
|
+
return isVideoFile(file) ? this.#fileUrl(file.id, "xspf") : null;
|
|
205
201
|
}
|
|
206
202
|
};
|
|
207
203
|
// src/utilities/localized-error.ts
|
|
@@ -217,48 +213,41 @@ var LocalizedError = class extends Error {
|
|
|
217
213
|
this.meta = params.meta ?? {};
|
|
218
214
|
}
|
|
219
215
|
};
|
|
220
|
-
|
|
221
|
-
const
|
|
216
|
+
var LocalizablePutioErrorEnvelope = class extends Data.TaggedClass("PutioErrorEnvelope") {};
|
|
217
|
+
const isLocalizablePutioErrorEnvelope = Schema.is(PutioErrorEnvelopeSchema.check(Schema.makeFilter((envelope) => "status_code" in envelope || "error_type" in envelope || "error_message" in envelope, { expected: "a put.io error envelope with a status code, error type, or error message" })));
|
|
218
|
+
const isPutioErrorWithBody = Schema.is(Schema.Struct({ body: PutioErrorEnvelopeSchema }));
|
|
222
219
|
const normalizePutioError = (error) => {
|
|
223
|
-
if (isLocalizablePutioErrorEnvelope(error)) return {
|
|
224
|
-
_tag: "PutioErrorEnvelope",
|
|
220
|
+
if (isLocalizablePutioErrorEnvelope(error)) return new LocalizablePutioErrorEnvelope({
|
|
225
221
|
body: error,
|
|
226
222
|
status: error.status_code
|
|
227
|
-
};
|
|
223
|
+
});
|
|
228
224
|
return error;
|
|
229
225
|
};
|
|
230
226
|
const isErrorLocalizer = (fn) => {
|
|
231
227
|
try {
|
|
232
|
-
return
|
|
228
|
+
return Predicate.isFunction(fn) && fn(/* @__PURE__ */ new Error("test")) instanceof LocalizedError;
|
|
233
229
|
} catch {
|
|
234
230
|
return false;
|
|
235
231
|
}
|
|
236
232
|
};
|
|
237
233
|
const createLocalizeError = (globalLocalizers) => (error, scopedLocalizers = []) => {
|
|
238
234
|
const localizers = [...scopedLocalizers, ...globalLocalizers];
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
});
|
|
246
|
-
const byMatchCondition = localizers.find((localizer) => localizer.kind === "match_condition" && localizer.match(error));
|
|
247
|
-
if (byMatchCondition) return new LocalizedError({
|
|
248
|
-
underlyingError: error,
|
|
249
|
-
...byMatchCondition.localize(error)
|
|
250
|
-
});
|
|
251
|
-
const byStatusCode = localizers.find((localizer) => localizer.kind === "api_status_code" && localizer.status_code === apiError.body.status_code);
|
|
252
|
-
if (byStatusCode) return new LocalizedError({
|
|
253
|
-
underlyingError: apiError,
|
|
254
|
-
...byStatusCode.localize(apiError)
|
|
255
|
-
});
|
|
256
|
-
}
|
|
235
|
+
const apiError = isPutioErrorWithBody(error) || isLocalizablePutioErrorEnvelope(error) ? normalizePutioError(error) : void 0;
|
|
236
|
+
const byErrorType = apiError && localizers.find((localizer) => localizer.kind === "api_error_type" && localizer.error_type === apiError.body.error_type);
|
|
237
|
+
if (apiError && byErrorType) return new LocalizedError({
|
|
238
|
+
underlyingError: apiError,
|
|
239
|
+
...byErrorType.localize(apiError)
|
|
240
|
+
});
|
|
257
241
|
const byMatchCondition = localizers.find((localizer) => localizer.kind === "match_condition" && localizer.match(error));
|
|
258
242
|
if (byMatchCondition) return new LocalizedError({
|
|
259
243
|
underlyingError: error,
|
|
260
244
|
...byMatchCondition.localize(error)
|
|
261
245
|
});
|
|
246
|
+
const byStatusCode = apiError && localizers.find((localizer) => localizer.kind === "api_status_code" && localizer.status_code === apiError.body.status_code);
|
|
247
|
+
if (apiError && byStatusCode) return new LocalizedError({
|
|
248
|
+
underlyingError: apiError,
|
|
249
|
+
...byStatusCode.localize(apiError)
|
|
250
|
+
});
|
|
262
251
|
const genericLocalizer = localizers.find((localizer) => localizer.kind === "generic");
|
|
263
252
|
if (genericLocalizer) return new LocalizedError({
|
|
264
253
|
underlyingError: error,
|
package/dist/utilities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilities.js","names":[],"sources":["../src/utilities/date.ts","../src/utilities/duration.ts","../src/utilities/file-render-type.ts","../src/utilities/file-size.ts","../src/utilities/file-url-provider.ts","../src/utilities/localized-error.ts","../src/utilities/string.ts"],"sourcesContent":["const LONG_DATE_FORMATTER = new Intl.DateTimeFormat(\"en-US\", {\n dateStyle: \"long\",\n timeZone: \"UTC\",\n});\n\nconst RELATIVE_TIME_FORMATTER = new Intl.RelativeTimeFormat(\"en\", {\n numeric: \"always\",\n});\n\nconst ensureDate = (value: unknown): Date => {\n if (value instanceof Date) {\n return value;\n }\n\n if (typeof value === \"string\") {\n if (/^\\d{4}-\\d{2}-\\d{2}$/.test(value)) {\n return new Date(`${value}T00:00:00.000Z`);\n }\n\n return new Date(value.endsWith(\"Z\") ? value : `${value}Z`);\n }\n\n return new Date();\n};\n\nconst toRelativeUnit = (secondsDelta: number) => {\n const absoluteSeconds = Math.abs(secondsDelta);\n\n if (absoluteSeconds >= 60 * 60 * 24 * 365) {\n return { unit: \"year\" as const, value: Math.round(secondsDelta / (60 * 60 * 24 * 365)) };\n }\n\n if (absoluteSeconds >= 60 * 60 * 24 * 30) {\n return { unit: \"month\" as const, value: Math.round(secondsDelta / (60 * 60 * 24 * 30)) };\n }\n\n if (absoluteSeconds >= 60 * 60 * 24) {\n return { unit: \"day\" as const, value: Math.round(secondsDelta / (60 * 60 * 24)) };\n }\n\n if (absoluteSeconds >= 60 * 60) {\n return { unit: \"hour\" as const, value: Math.round(secondsDelta / (60 * 60)) };\n }\n\n if (absoluteSeconds >= 60) {\n return { unit: \"minute\" as const, value: Math.round(secondsDelta / 60) };\n }\n\n return { unit: \"second\" as const, value: Math.round(secondsDelta) };\n};\n\nexport const ensureUTC = (date: unknown = null): string => ensureDate(date).toISOString();\n\nexport const toTimeAgo = (date: unknown = null): string => {\n if (!date) {\n return \"N/A\";\n }\n\n const target = ensureDate(date);\n const secondsDelta = Math.round((target.getTime() - Date.now()) / 1000);\n const { unit, value } = toRelativeUnit(secondsDelta);\n return RELATIVE_TIME_FORMATTER.format(value, unit);\n};\n\nexport const formatDate = (\n date: unknown = null,\n format: \"LL\" | Intl.DateTimeFormatOptions = \"LL\",\n): string => {\n if (!date) {\n return \"N/A\";\n }\n\n const normalizedDate = ensureDate(date);\n\n if (format === \"LL\") {\n return LONG_DATE_FORMATTER.format(normalizedDate);\n }\n\n return new Intl.DateTimeFormat(\"en-US\", {\n timeZone: \"UTC\",\n ...format,\n }).format(normalizedDate);\n};\n\nexport const daysDiff = (date1: unknown, date2: unknown): number => {\n const day1 = ensureDate(date1);\n const day2 = ensureDate(date2);\n\n const utcDay1 = Date.UTC(day1.getUTCFullYear(), day1.getUTCMonth(), day1.getUTCDate());\n const utcDay2 = Date.UTC(day2.getUTCFullYear(), day2.getUTCMonth(), day2.getUTCDate());\n\n return Math.abs(Math.round((utcDay2 - utcDay1) / (1000 * 60 * 60 * 24)));\n};\n\nexport const daysDiffFromNow = (date: unknown = null): number => {\n if (!date) {\n return 0;\n }\n\n return daysDiff(date, new Date());\n};\n\nexport const getUnixTimestamp = (date: unknown): number =>\n Math.floor(ensureDate(date).getTime() / 1000);\n","const normalizeNumber = (value: unknown): number => (typeof value === \"number\" ? value : 0);\n\nconst formatPadded = (value: number): string => String(value).padStart(2, \"0\");\n\nexport const secondsToDuration = (seconds: unknown): string => {\n const normalizedSeconds = Math.floor(normalizeNumber(seconds));\n\n if (normalizedSeconds <= 0) {\n return \"00:00\";\n }\n\n const days = Math.floor(normalizedSeconds / 86_400);\n const hours = Math.floor((normalizedSeconds % 86_400) / 3_600);\n const minutes = Math.floor((normalizedSeconds % 3_600) / 60);\n const remainingSeconds = normalizedSeconds % 60;\n\n if (days > 0) {\n return [days, hours, minutes, remainingSeconds].map(formatPadded).join(\":\");\n }\n\n if (normalizedSeconds >= 3_600) {\n return [Math.floor(normalizedSeconds / 3_600), minutes, remainingSeconds]\n .map(formatPadded)\n .join(\":\");\n }\n\n return [minutes, remainingSeconds].map(formatPadded).join(\":\");\n};\n\nexport const secondsToReadableDuration = (seconds: unknown): string => {\n const normalizedSeconds = Math.floor(normalizeNumber(seconds));\n\n if (normalizedSeconds <= 0) {\n return \"N/A\";\n }\n\n if (normalizedSeconds < 60) {\n return `${normalizedSeconds} s`;\n }\n\n if (normalizedSeconds >= 86_400) {\n const days = Math.floor(normalizedSeconds / 86_400);\n const roundedHours = Math.round((normalizedSeconds - days * 86_400) / 3_600);\n\n if (roundedHours === 24) {\n return `${days + 1}d`;\n }\n\n return roundedHours > 0 ? `${days}d ${roundedHours}h` : `${days}d`;\n }\n\n if (normalizedSeconds >= 3_600) {\n const hours = Math.floor(normalizedSeconds / 3_600);\n const roundedMinutes = Math.round((normalizedSeconds - hours * 3_600) / 60);\n return roundedMinutes > 0 ? `${hours}h ${roundedMinutes}m` : `${hours}h`;\n }\n\n const roundedMinutes = Math.round(normalizedSeconds / 60);\n const remainingSeconds = normalizedSeconds - roundedMinutes * 60;\n return remainingSeconds > 0 ? `${roundedMinutes}m ${remainingSeconds}s` : `${roundedMinutes}m`;\n};\n","import type { FileBroad } from \"../domains/files.js\";\n\nexport type FileRenderType =\n | \"archive\"\n | \"audio\"\n | \"epub\"\n | \"folder\"\n | \"image\"\n | \"other\"\n | \"pdf\"\n | \"text\"\n | \"text/markdown\"\n | \"video\";\n\nexport type FileRenderTypeInput = Pick<FileBroad, \"content_type\" | \"extension\" | \"file_type\">;\n\nexport const getFileRenderType = (file: FileRenderTypeInput): FileRenderType => {\n const { content_type, extension, file_type } = file;\n\n if (typeof content_type !== \"string\") {\n return \"other\";\n }\n\n if (content_type === \"application/x-directory\") {\n return \"folder\";\n }\n\n if (content_type.startsWith(\"audio\") || file_type === \"AUDIO\") {\n return \"audio\";\n }\n\n if (content_type.startsWith(\"video\")) {\n return \"video\";\n }\n\n if (content_type.startsWith(\"image\")) {\n return \"image\";\n }\n\n if (content_type === \"application/pdf\") {\n return \"pdf\";\n }\n\n if (content_type === \"application/epub+zip\") {\n return \"epub\";\n }\n\n if (content_type === \"application/zip\" || content_type === \"application/x-rar\") {\n return \"archive\";\n }\n\n if (\n content_type.startsWith(\"text\") ||\n content_type.startsWith(\"application/x-subrip\") ||\n file_type === \"TEXT\"\n ) {\n if (content_type.endsWith(\"/markdown\") || extension === \"md\") {\n return \"text/markdown\";\n }\n\n return \"text\";\n }\n\n return \"other\";\n};\n","export interface HumanFileSizeOptions {\n readonly decimals?: number;\n readonly unitSeparator?: string;\n}\n\nconst FILE_SIZE_UNITS = [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\"] as const;\n\nexport const toHumanFileSize = (\n fileSizeInBytes: string | number,\n options: HumanFileSizeOptions = {},\n): string => {\n const { decimals = 1, unitSeparator = \" \" } = options;\n const parsed =\n typeof fileSizeInBytes === \"string\" ? Number.parseInt(fileSizeInBytes, 10) : fileSizeInBytes;\n\n if (!Number.isFinite(parsed) || parsed <= 0) {\n return `0${unitSeparator}B`;\n }\n\n const exponent = Math.min(\n Math.floor(Math.log(parsed) / Math.log(1024)),\n FILE_SIZE_UNITS.length - 1,\n );\n const normalized = parsed / 1024 ** exponent;\n const fractionDigits = normalized % 1 === 0 ? 0 : decimals;\n\n return `${normalized.toFixed(fractionDigits)}${unitSeparator}${FILE_SIZE_UNITS[exponent]}`;\n};\n","import { Result, Schema } from \"effect\";\n\nimport { mapDecodeErrorToValidationError } from \"../core/errors.js\";\nimport { joinCsv } from \"../core/forms.js\";\nimport { buildPutioUrl, encodePathSegment } from \"../core/http.js\";\nimport type { FileBroad } from \"../domains/files.js\";\nimport { NonEmptyStringSchema } from \"../core/validation.js\";\nimport { getFileRenderType, type FileRenderTypeInput } from \"./file-render-type.js\";\n\nexport type FileUrlProviderInput = Pick<\n FileBroad,\n \"content_type\" | \"extension\" | \"file_type\" | \"id\" | \"is_mp4_available\"\n>;\n\nconst FileUrlProviderOptionsSchema = Schema.Struct({\n baseUrl: NonEmptyStringSchema,\n downloadToken: NonEmptyStringSchema,\n});\n\nexport type FileUrlProviderOptions = {\n /** The put.io API origin, with or without the trailing `/v2`. */\n readonly baseUrl: string;\n /** The account download token from `getAccountInfo({ download_token: 1 })`, not the OAuth token. */\n readonly downloadToken: string;\n};\n\nconst decodeOptions = (options: FileUrlProviderOptions): FileUrlProviderOptions => {\n const decoded = Schema.decodeUnknownResult(FileUrlProviderOptionsSchema, {\n onExcessProperty: \"error\",\n })(options);\n if (Result.isFailure(decoded)) {\n throw mapDecodeErrorToValidationError(decoded.failure);\n }\n return decoded.success;\n};\n\nconst normalizeApiBaseUrl = (apiUrl: string): string =>\n apiUrl.endsWith(\"/v2\") ? apiUrl.slice(0, -3) : apiUrl;\n\nconst isVideoFile = (file: FileRenderTypeInput): boolean => getFileRenderType(file) === \"video\";\n\nexport class FileUrlProvider {\n readonly apiUrl: string;\n\n /** The account download token from `getAccountInfo({ download_token: 1 })`, not the OAuth token. */\n readonly downloadToken: string;\n\n readonly baseUrl: string;\n\n constructor(options: FileUrlProviderOptions) {\n const { baseUrl, downloadToken } = decodeOptions(options);\n this.baseUrl = normalizeApiBaseUrl(baseUrl);\n this.apiUrl = `${this.baseUrl}/v2`;\n this.downloadToken = downloadToken;\n }\n\n getDownloadUrl(fileOrFileId: FileUrlProviderInput | number): string | null {\n if (typeof fileOrFileId === \"number\") {\n return buildPutioUrl(this.baseUrl, `/v2/files/${encodePathSegment(fileOrFileId)}/download`, {\n oauth_token: this.downloadToken,\n });\n }\n\n if (fileOrFileId.file_type === \"FOLDER\") {\n return null;\n }\n\n return buildPutioUrl(this.baseUrl, `/v2/files/${encodePathSegment(fileOrFileId.id)}/download`, {\n oauth_token: this.downloadToken,\n });\n }\n\n getHlsStreamUrl(\n file: FileUrlProviderInput,\n params: {\n readonly maxSubtitleCount?: number;\n readonly playOriginal?: boolean;\n readonly subtitleLanguages?: ReadonlyArray<string>;\n } = {},\n ): string | null {\n if (!isVideoFile(file)) {\n return null;\n }\n\n return buildPutioUrl(this.baseUrl, `/v2/files/${encodePathSegment(file.id)}/hls/media.m3u8`, {\n max_subtitle_count: params.maxSubtitleCount,\n oauth_token: this.downloadToken,\n original: params.playOriginal ? 1 : undefined,\n subtitle_languages: joinCsv(params.subtitleLanguages),\n });\n }\n\n getMp4DownloadUrl(file: FileUrlProviderInput): string | null {\n if (!isVideoFile(file) || !file.is_mp4_available) {\n return null;\n }\n\n return buildPutioUrl(this.baseUrl, `/v2/files/${encodePathSegment(file.id)}/mp4/download`, {\n oauth_token: this.downloadToken,\n });\n }\n\n getMp4StreamUrl(file: FileUrlProviderInput): string | null {\n if (!isVideoFile(file) || !file.is_mp4_available) {\n return null;\n }\n\n return buildPutioUrl(this.baseUrl, `/v2/files/${encodePathSegment(file.id)}/mp4/stream`, {\n oauth_token: this.downloadToken,\n });\n }\n\n getStreamUrl(file: FileUrlProviderInput): string | null {\n switch (getFileRenderType(file)) {\n case \"audio\":\n return buildPutioUrl(this.baseUrl, `/v2/files/${encodePathSegment(file.id)}/stream.mp3`, {\n oauth_token: this.downloadToken,\n });\n case \"video\":\n return buildPutioUrl(this.baseUrl, `/v2/files/${encodePathSegment(file.id)}/stream`, {\n oauth_token: this.downloadToken,\n });\n default:\n return null;\n }\n }\n\n getXspfUrl(file: FileUrlProviderInput): string | null {\n if (!isVideoFile(file)) {\n return null;\n }\n\n return buildPutioUrl(this.baseUrl, `/v2/files/${encodePathSegment(file.id)}/xspf`, {\n oauth_token: this.downloadToken,\n });\n }\n}\n","import { Predicate } from \"effect\";\n\nimport {\n PutioApiError,\n PutioAuthError,\n type PutioErrorEnvelope,\n isPutioErrorEnvelope,\n PutioOperationError,\n PutioRateLimitError,\n type PutioKnownOperationErrorContract,\n} from \"../core/errors.js\";\n\nexport type LocalizedErrorRecoverySuggestionTypeInstruction = {\n readonly type: \"instruction\";\n readonly description: string;\n};\n\nexport type LocalizedErrorRecoverySuggestionTypeAction = {\n readonly type: \"action\";\n readonly description: string;\n readonly trigger: {\n readonly label: string;\n readonly callback: () => void;\n };\n};\n\nexport type LocalizedErrorRecoverySuggestionTypeCaptcha = {\n readonly type: \"captcha\";\n readonly description: string;\n};\n\nexport type LocalizedErrorRecoverySuggestion =\n | LocalizedErrorRecoverySuggestionTypeInstruction\n | LocalizedErrorRecoverySuggestionTypeAction\n | LocalizedErrorRecoverySuggestionTypeCaptcha;\n\nexport interface LocalizedErrorParams {\n readonly message: string;\n readonly recoverySuggestion: LocalizedErrorRecoverySuggestion;\n readonly underlyingError: unknown;\n readonly meta?: Record<string, unknown>;\n}\n\nexport class LocalizedError extends Error {\n readonly recoverySuggestion: LocalizedErrorRecoverySuggestion;\n\n readonly underlyingError: unknown;\n\n readonly meta: Record<string, unknown>;\n\n constructor(params: LocalizedErrorParams) {\n super(params.message);\n this.name = \"LocalizedError\";\n this.recoverySuggestion = params.recoverySuggestion;\n this.underlyingError = params.underlyingError;\n this.meta = params.meta ?? {};\n }\n}\n\ntype StatusAndBodyError =\n | PutioApiError\n | PutioAuthError\n | PutioRateLimitError\n | PutioOperationError<string, string, PutioKnownOperationErrorContract>;\n\nexport type PutioLocalizableError = {\n readonly _tag?: string;\n readonly body: PutioErrorEnvelope;\n readonly status?: number;\n};\n\nexport type PutioErrorWithBody = StatusAndBodyError;\n\nconst isLocalizablePutioErrorEnvelope = (value: unknown): value is PutioErrorEnvelope =>\n Predicate.isObject(value) &&\n (\"status_code\" in value || \"error_type\" in value || \"error_message\" in value) &&\n isPutioErrorEnvelope(value);\n\nconst isPutioErrorWithBody = (value: unknown): value is PutioLocalizableError =>\n Predicate.isObject(value) && \"body\" in value && isPutioErrorEnvelope(value.body);\n\nconst normalizePutioError = (\n error: PutioErrorEnvelope | PutioLocalizableError,\n): PutioLocalizableError => {\n if (isLocalizablePutioErrorEnvelope(error)) {\n return {\n _tag: \"PutioErrorEnvelope\",\n body: error,\n status: error.status_code,\n };\n }\n\n return error;\n};\n\nexport type LocalizeErrorFn<E> = (\n error: E,\n) => Pick<LocalizedErrorParams, \"message\" | \"recoverySuggestion\" | \"meta\">;\n\nexport type APIErrorByStatusCodeLocalizer = {\n readonly kind: \"api_status_code\";\n readonly status_code: number;\n readonly localize: LocalizeErrorFn<PutioLocalizableError>;\n};\n\nexport type APIErrorByErrorTypeLocalizer = {\n readonly kind: \"api_error_type\";\n readonly error_type: string;\n readonly localize: LocalizeErrorFn<PutioLocalizableError>;\n};\n\nexport type MatchConditionLocalizer<E> = {\n readonly kind: \"match_condition\";\n readonly match: (error: E) => boolean;\n readonly localize: LocalizeErrorFn<E>;\n};\n\nexport type GenericErrorLocalizer = {\n readonly kind: \"generic\";\n readonly localize: LocalizeErrorFn<unknown>;\n};\n\nexport type ErrorLocalizer<E> =\n | APIErrorByStatusCodeLocalizer\n | APIErrorByErrorTypeLocalizer\n | MatchConditionLocalizer<E>\n | GenericErrorLocalizer;\n\nexport type ErrorLocalizerFn = (error: unknown) => LocalizedError;\n\nexport const isErrorLocalizer = (fn: unknown): fn is ErrorLocalizerFn => {\n try {\n return typeof fn === \"function\" && fn(new Error(\"test\")) instanceof LocalizedError;\n } catch {\n return false;\n }\n};\n\nexport const createLocalizeError =\n <GlobalError>(globalLocalizers: ReadonlyArray<ErrorLocalizer<GlobalError>>) =>\n <ScopedError extends GlobalError>(\n error: ScopedError,\n scopedLocalizers: ReadonlyArray<ErrorLocalizer<ScopedError>> = [],\n ): LocalizedError => {\n const localizers = [...scopedLocalizers, ...globalLocalizers];\n\n if (isPutioErrorWithBody(error) || isLocalizablePutioErrorEnvelope(error)) {\n const apiError = normalizePutioError(error);\n\n const byErrorType = localizers.find(\n (localizer): localizer is APIErrorByErrorTypeLocalizer =>\n localizer.kind === \"api_error_type\" && localizer.error_type === apiError.body.error_type,\n );\n\n if (byErrorType) {\n return new LocalizedError({\n underlyingError: apiError,\n ...byErrorType.localize(apiError),\n });\n }\n\n const byMatchCondition = localizers.find(\n (localizer): localizer is MatchConditionLocalizer<ScopedError> =>\n localizer.kind === \"match_condition\" && localizer.match(error),\n );\n\n if (byMatchCondition) {\n return new LocalizedError({\n underlyingError: error,\n ...byMatchCondition.localize(error),\n });\n }\n\n const byStatusCode = localizers.find(\n (localizer): localizer is APIErrorByStatusCodeLocalizer =>\n localizer.kind === \"api_status_code\" &&\n localizer.status_code === apiError.body.status_code,\n );\n\n if (byStatusCode) {\n return new LocalizedError({\n underlyingError: apiError,\n ...byStatusCode.localize(apiError),\n });\n }\n }\n\n const byMatchCondition = localizers.find(\n (localizer): localizer is MatchConditionLocalizer<ScopedError> =>\n localizer.kind === \"match_condition\" && localizer.match(error),\n );\n\n if (byMatchCondition) {\n return new LocalizedError({\n underlyingError: error,\n ...byMatchCondition.localize(error),\n });\n }\n\n const genericLocalizer = localizers.find(\n (localizer): localizer is GenericErrorLocalizer => localizer.kind === \"generic\",\n );\n\n if (genericLocalizer) {\n return new LocalizedError({\n underlyingError: error,\n ...genericLocalizer.localize(error),\n });\n }\n\n throw new Error(`No localizer found for error: ${String(error)}`);\n };\n","export const dotsToSpaces = (input: string): string => input.split(\".\").join(\" \");\n\nexport const truncate = (\n input: string,\n options: {\n readonly length: number;\n readonly ellipsis?: string;\n },\n): string => {\n const { ellipsis = \"...\", length } = options;\n\n if (input.length <= length) {\n return input;\n }\n\n return `${input.slice(0, length)}${ellipsis}`;\n};\n\nexport const truncateMiddle = (\n input: string,\n options: {\n readonly frontLength: number;\n readonly backLength: number;\n readonly ellipsis?: string;\n },\n): string => {\n const { backLength, ellipsis = \"...\", frontLength } = options;\n const preservedLength = frontLength + backLength;\n\n if (input.length <= preservedLength) {\n return input;\n }\n\n return `${input.slice(0, frontLength)}${ellipsis}${input.slice(input.length - backLength)}`;\n};\n"],"mappings":";;;AAAA,MAAM,sBAAsB,IAAI,KAAK,eAAe,SAAS;CAC3D,WAAW;CACX,UAAU;AACZ,CAAC;AAED,MAAM,0BAA0B,IAAI,KAAK,mBAAmB,MAAM,EAChE,SAAS,SACX,CAAC;AAED,MAAM,cAAc,UAAyB;CAC3C,IAAI,iBAAiB,MACnB,OAAO;CAGT,IAAI,OAAO,UAAU,UAAU;EAC7B,IAAI,sBAAsB,KAAK,KAAK,GAClC,uBAAO,IAAI,KAAK,GAAG,MAAM,eAAe;E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MAAM,UAAU,iBAClB,OAAO;CAGT,OAAO,GAAG,MAAM,MAAM,GAAG,WAAW,IAAI,WAAW,MAAM,MAAM,MAAM,SAAS,UAAU;AAC1F"}
|
|
1
|
+
{"version":3,"file":"utilities.js","names":[],"sources":["../src/utilities/date.ts","../src/utilities/duration.ts","../src/utilities/file-render-type.ts","../src/utilities/file-size.ts","../src/utilities/file-url-provider.ts","../src/utilities/localized-error.ts","../src/utilities/string.ts"],"sourcesContent":["const LONG_DATE_FORMATTER = new Intl.DateTimeFormat(\"en-US\", {\n dateStyle: \"long\",\n timeZone: \"UTC\",\n});\n\nconst RELATIVE_TIME_FORMATTER = new Intl.RelativeTimeFormat(\"en\", {\n numeric: \"always\",\n});\n\nexport type DateInput = Date | string | null | undefined;\n\nconst ensureDate = (value: DateInput): Date => {\n if (value === null || value === undefined) {\n return new Date();\n }\n\n if (value instanceof Date) {\n return value;\n }\n\n if (/^\\d{4}-\\d{2}-\\d{2}$/.test(value)) {\n return new Date(`${value}T00:00:00.000Z`);\n }\n\n return new Date(value.endsWith(\"Z\") ? value : `${value}Z`);\n};\n\nconst toRelativeUnit = (secondsDelta: number) => {\n const absoluteSeconds = Math.abs(secondsDelta);\n\n if (absoluteSeconds >= 60 * 60 * 24 * 365) {\n return { unit: \"year\" as const, value: Math.round(secondsDelta / (60 * 60 * 24 * 365)) };\n }\n\n if (absoluteSeconds >= 60 * 60 * 24 * 30) {\n return { unit: \"month\" as const, value: Math.round(secondsDelta / (60 * 60 * 24 * 30)) };\n }\n\n if (absoluteSeconds >= 60 * 60 * 24) {\n return { unit: \"day\" as const, value: Math.round(secondsDelta / (60 * 60 * 24)) };\n }\n\n if (absoluteSeconds >= 60 * 60) {\n return { unit: \"hour\" as const, value: Math.round(secondsDelta / (60 * 60)) };\n }\n\n if (absoluteSeconds >= 60) {\n return { unit: \"minute\" as const, value: Math.round(secondsDelta / 60) };\n }\n\n return { unit: \"second\" as const, value: Math.round(secondsDelta) };\n};\n\nexport const ensureUTC = (date?: DateInput): string => ensureDate(date).toISOString();\n\nexport const toTimeAgo = (date?: DateInput): string => {\n if (!date) {\n return \"N/A\";\n }\n\n const target = ensureDate(date);\n const secondsDelta = Math.round((target.getTime() - Date.now()) / 1000);\n const { unit, value } = toRelativeUnit(secondsDelta);\n\n return RELATIVE_TIME_FORMATTER.format(value, unit);\n};\n\nexport const formatDate = (\n date?: DateInput,\n format: \"LL\" | Intl.DateTimeFormatOptions = \"LL\",\n): string => {\n if (!date) {\n return \"N/A\";\n }\n\n const normalizedDate = ensureDate(date);\n\n if (format === \"LL\") {\n return LONG_DATE_FORMATTER.format(normalizedDate);\n }\n\n return new Intl.DateTimeFormat(\"en-US\", {\n timeZone: \"UTC\",\n ...format,\n }).format(normalizedDate);\n};\n\nexport const daysDiff = (date1: DateInput, date2: DateInput): number => {\n const day1 = ensureDate(date1);\n const day2 = ensureDate(date2);\n\n const utcDay1 = Date.UTC(day1.getUTCFullYear(), day1.getUTCMonth(), day1.getUTCDate());\n const utcDay2 = Date.UTC(day2.getUTCFullYear(), day2.getUTCMonth(), day2.getUTCDate());\n\n return Math.abs(Math.round((utcDay2 - utcDay1) / (1000 * 60 * 60 * 24)));\n};\n\nexport const daysDiffFromNow = (date?: DateInput): number => {\n if (!date) {\n return 0;\n }\n\n return daysDiff(date, new Date());\n};\n\nexport const getUnixTimestamp = (date: DateInput): number =>\n Math.floor(ensureDate(date).getTime() / 1000);\n","const formatPadded = (value: number): string => String(value).padStart(2, \"0\");\n\nexport const secondsToDuration = (seconds: number | null | undefined): string => {\n const normalizedSeconds = Math.floor(seconds ?? 0);\n\n if (normalizedSeconds <= 0) {\n return \"00:00\";\n }\n\n const days = Math.floor(normalizedSeconds / 86_400);\n const hours = Math.floor((normalizedSeconds % 86_400) / 3_600);\n const minutes = Math.floor((normalizedSeconds % 3_600) / 60);\n const remainingSeconds = normalizedSeconds % 60;\n\n if (days > 0) {\n return [days, hours, minutes, remainingSeconds].map(formatPadded).join(\":\");\n }\n\n if (normalizedSeconds >= 3_600) {\n return [Math.floor(normalizedSeconds / 3_600), minutes, remainingSeconds]\n .map(formatPadded)\n .join(\":\");\n }\n\n return [minutes, remainingSeconds].map(formatPadded).join(\":\");\n};\n\nexport const secondsToReadableDuration = (seconds: number | null | undefined): string => {\n const normalizedSeconds = Math.floor(seconds ?? 0);\n\n if (normalizedSeconds <= 0) {\n return \"N/A\";\n }\n\n if (normalizedSeconds < 60) {\n return `${normalizedSeconds} s`;\n }\n\n if (normalizedSeconds >= 86_400) {\n const days = Math.floor(normalizedSeconds / 86_400);\n const roundedHours = Math.round((normalizedSeconds - days * 86_400) / 3_600);\n\n if (roundedHours === 24) {\n return `${days + 1}d`;\n }\n\n return roundedHours > 0 ? `${days}d ${roundedHours}h` : `${days}d`;\n }\n\n if (normalizedSeconds >= 3_600) {\n const hours = Math.floor(normalizedSeconds / 3_600);\n const roundedMinutes = Math.round((normalizedSeconds - hours * 3_600) / 60);\n\n return roundedMinutes > 0 ? `${hours}h ${roundedMinutes}m` : `${hours}h`;\n }\n\n const roundedMinutes = Math.round(normalizedSeconds / 60);\n const remainingSeconds = normalizedSeconds - roundedMinutes * 60;\n\n return remainingSeconds > 0 ? `${roundedMinutes}m ${remainingSeconds}s` : `${roundedMinutes}m`;\n};\n","import type { FileBroad } from \"../domains/files.js\";\n\nexport type FileRenderType =\n | \"archive\"\n | \"audio\"\n | \"epub\"\n | \"folder\"\n | \"image\"\n | \"other\"\n | \"pdf\"\n | \"text\"\n | \"text/markdown\"\n | \"video\";\n\nexport type FileRenderTypeInput = Pick<FileBroad, \"content_type\" | \"extension\" | \"file_type\">;\n\nexport const getFileRenderType = (file: FileRenderTypeInput): FileRenderType => {\n const { content_type, extension, file_type } = file;\n\n if (content_type === null || content_type === undefined) {\n return \"other\";\n }\n\n if (content_type === \"application/x-directory\") {\n return \"folder\";\n }\n\n if (content_type.startsWith(\"audio\") || file_type === \"AUDIO\") {\n return \"audio\";\n }\n\n if (content_type.startsWith(\"video\")) {\n return \"video\";\n }\n\n if (content_type.startsWith(\"image\")) {\n return \"image\";\n }\n\n if (content_type === \"application/pdf\") {\n return \"pdf\";\n }\n\n if (content_type === \"application/epub+zip\") {\n return \"epub\";\n }\n\n if (content_type === \"application/zip\" || content_type === \"application/x-rar\") {\n return \"archive\";\n }\n\n if (\n content_type.startsWith(\"text\") ||\n content_type.startsWith(\"application/x-subrip\") ||\n file_type === \"TEXT\"\n ) {\n if (content_type.endsWith(\"/markdown\") || extension === \"md\") {\n return \"text/markdown\";\n }\n\n return \"text\";\n }\n\n return \"other\";\n};\n","import { Predicate } from \"effect\";\n\nexport interface HumanFileSizeOptions {\n readonly decimals?: number;\n readonly unitSeparator?: string;\n}\n\nconst FILE_SIZE_UNITS = [\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\"] as const;\n\nexport const toHumanFileSize = (\n fileSizeInBytes: string | number,\n options: HumanFileSizeOptions = {},\n): string => {\n const { decimals = 1, unitSeparator = \" \" } = options;\n\n const parsed = Predicate.isString(fileSizeInBytes)\n ? Number.parseInt(fileSizeInBytes, 10)\n : fileSizeInBytes;\n\n if (!Number.isFinite(parsed) || parsed <= 0) {\n return `0${unitSeparator}B`;\n }\n\n const exponent = Math.min(\n Math.floor(Math.log(parsed) / Math.log(1024)),\n FILE_SIZE_UNITS.length - 1,\n );\n\n const normalized = parsed / 1024 ** exponent;\n const fractionDigits = normalized % 1 === 0 ? 0 : decimals;\n\n return `${normalized.toFixed(fractionDigits)}${unitSeparator}${FILE_SIZE_UNITS[exponent]}`;\n};\n","import { Predicate, Result, Schema } from \"effect\";\n\nimport { mapDecodeErrorToValidationError } from \"../core/errors.js\";\nimport { joinCsv } from \"../core/forms.js\";\nimport { buildPutioUrl, encodePathSegment, type PutioQuery } from \"../core/http.js\";\nimport type { FileBroad } from \"../domains/files.js\";\nimport { NonEmptyStringSchema } from \"../core/validation.js\";\nimport { getFileRenderType, type FileRenderTypeInput } from \"./file-render-type.js\";\n\nexport type FileUrlProviderInput = Pick<\n FileBroad,\n \"content_type\" | \"extension\" | \"file_type\" | \"id\" | \"is_mp4_available\"\n>;\n\nconst FileUrlProviderOptionsSchema = Schema.Struct({\n baseUrl: NonEmptyStringSchema,\n downloadToken: NonEmptyStringSchema,\n});\n\nexport type FileUrlProviderOptions = {\n /** The put.io API origin, with or without the trailing `/v2`. */\n readonly baseUrl: string;\n /** The account download token from `getAccountInfo({ download_token: 1 })`, not the OAuth token. */\n readonly downloadToken: string;\n};\n\nconst decodeOptions = (options: FileUrlProviderOptions): FileUrlProviderOptions => {\n const decoded = Schema.decodeUnknownResult(FileUrlProviderOptionsSchema, {\n onExcessProperty: \"error\",\n })(options);\n\n if (Result.isFailure(decoded)) {\n throw mapDecodeErrorToValidationError(decoded.failure);\n }\n\n return decoded.success;\n};\n\nconst normalizeApiBaseUrl = (apiUrl: string): string =>\n apiUrl.endsWith(\"/v2\") ? apiUrl.slice(0, -3) : apiUrl;\n\nconst isVideoFile = (file: FileRenderTypeInput): boolean => getFileRenderType(file) === \"video\";\n\nexport class FileUrlProvider {\n readonly apiUrl: string;\n\n /** The account download token from `getAccountInfo({ download_token: 1 })`, not the OAuth token. */\n readonly downloadToken: string;\n\n readonly baseUrl: string;\n\n constructor(options: FileUrlProviderOptions) {\n const { baseUrl, downloadToken } = decodeOptions(options);\n this.baseUrl = normalizeApiBaseUrl(baseUrl);\n this.apiUrl = `${this.baseUrl}/v2`;\n this.downloadToken = downloadToken;\n }\n\n #fileUrl(\n fileId: number,\n resource: string,\n query: PutioQuery = { oauth_token: this.downloadToken },\n ): string {\n return buildPutioUrl(this.baseUrl, `/v2/files/${encodePathSegment(fileId)}/${resource}`, query);\n }\n\n getDownloadUrl(fileOrFileId: FileUrlProviderInput | number): string | null {\n if (Predicate.isNumber(fileOrFileId)) {\n return this.#fileUrl(fileOrFileId, \"download\");\n }\n\n return fileOrFileId.file_type === \"FOLDER\" ? null : this.#fileUrl(fileOrFileId.id, \"download\");\n }\n\n getHlsStreamUrl(\n file: FileUrlProviderInput,\n params: {\n readonly maxSubtitleCount?: number;\n readonly playOriginal?: boolean;\n readonly subtitleLanguages?: ReadonlyArray<string>;\n } = {},\n ): string | null {\n if (!isVideoFile(file)) {\n return null;\n }\n\n return this.#fileUrl(file.id, \"hls/media.m3u8\", {\n max_subtitle_count: params.maxSubtitleCount,\n oauth_token: this.downloadToken,\n original: params.playOriginal ? 1 : undefined,\n subtitle_languages: joinCsv(params.subtitleLanguages),\n });\n }\n\n getMp4DownloadUrl(file: FileUrlProviderInput): string | null {\n return isVideoFile(file) && file.is_mp4_available\n ? this.#fileUrl(file.id, \"mp4/download\")\n : null;\n }\n\n getMp4StreamUrl(file: FileUrlProviderInput): string | null {\n return isVideoFile(file) && file.is_mp4_available ? this.#fileUrl(file.id, \"mp4/stream\") : null;\n }\n\n getStreamUrl(file: FileUrlProviderInput): string | null {\n switch (getFileRenderType(file)) {\n case \"audio\":\n return this.#fileUrl(file.id, \"stream.mp3\");\n case \"video\":\n return this.#fileUrl(file.id, \"stream\");\n default:\n return null;\n }\n }\n\n getXspfUrl(file: FileUrlProviderInput): string | null {\n return isVideoFile(file) ? this.#fileUrl(file.id, \"xspf\") : null;\n }\n}\n","import { Data, Predicate, Schema } from \"effect\";\n\nimport {\n PutioApiError,\n PutioAuthError,\n type PutioErrorEnvelope,\n PutioErrorEnvelopeSchema,\n PutioOperationError,\n PutioRateLimitError,\n type PutioKnownOperationErrorContract,\n} from \"../core/errors.js\";\n\nexport type LocalizedErrorRecoverySuggestionTypeInstruction = {\n readonly type: \"instruction\";\n readonly description: string;\n};\n\nexport type LocalizedErrorRecoverySuggestionTypeAction = {\n readonly type: \"action\";\n readonly description: string;\n readonly trigger: {\n readonly label: string;\n readonly callback: () => void;\n };\n};\n\nexport type LocalizedErrorRecoverySuggestionTypeCaptcha = {\n readonly type: \"captcha\";\n readonly description: string;\n};\n\nexport type LocalizedErrorRecoverySuggestion =\n | LocalizedErrorRecoverySuggestionTypeInstruction\n | LocalizedErrorRecoverySuggestionTypeAction\n | LocalizedErrorRecoverySuggestionTypeCaptcha;\n\nexport type LocalizedErrorMeta = Record<string, Schema.Json | undefined>;\n\nexport interface LocalizedErrorParams {\n readonly message: string;\n readonly recoverySuggestion: LocalizedErrorRecoverySuggestion;\n readonly underlyingError: unknown;\n readonly meta?: LocalizedErrorMeta;\n}\n\nexport class LocalizedError extends Error {\n readonly recoverySuggestion: LocalizedErrorRecoverySuggestion;\n\n readonly underlyingError: unknown;\n\n readonly meta: LocalizedErrorMeta;\n\n constructor(params: LocalizedErrorParams) {\n super(params.message);\n this.name = \"LocalizedError\";\n this.recoverySuggestion = params.recoverySuggestion;\n this.underlyingError = params.underlyingError;\n this.meta = params.meta ?? {};\n }\n}\n\nexport type PutioErrorWithBody =\n | PutioApiError\n | PutioAuthError\n | PutioRateLimitError\n | PutioOperationError<string, string, PutioKnownOperationErrorContract>;\n\nexport type PutioLocalizableError = {\n readonly _tag?: string;\n readonly body: PutioErrorEnvelope;\n readonly status?: number;\n};\n\nclass LocalizablePutioErrorEnvelope extends Data.TaggedClass(\"PutioErrorEnvelope\")<{\n readonly body: PutioErrorEnvelope;\n readonly status: number | undefined;\n}> {}\n\nconst isLocalizablePutioErrorEnvelope = Schema.is(\n PutioErrorEnvelopeSchema.check(\n Schema.makeFilter(\n (envelope) =>\n \"status_code\" in envelope || \"error_type\" in envelope || \"error_message\" in envelope,\n { expected: \"a put.io error envelope with a status code, error type, or error message\" },\n ),\n ),\n);\n\nconst isPutioErrorWithBody = Schema.is(Schema.Struct({ body: PutioErrorEnvelopeSchema }));\n\nconst normalizePutioError = (\n error: PutioErrorEnvelope | PutioLocalizableError,\n): PutioLocalizableError => {\n if (isLocalizablePutioErrorEnvelope(error)) {\n return new LocalizablePutioErrorEnvelope({ body: error, status: error.status_code });\n }\n\n return error;\n};\n\nexport type LocalizeErrorFn<E> = (\n error: E,\n) => Pick<LocalizedErrorParams, \"message\" | \"recoverySuggestion\" | \"meta\">;\n\nexport type APIErrorByStatusCodeLocalizer = {\n readonly kind: \"api_status_code\";\n readonly status_code: number;\n readonly localize: LocalizeErrorFn<PutioLocalizableError>;\n};\n\nexport type APIErrorByErrorTypeLocalizer = {\n readonly kind: \"api_error_type\";\n readonly error_type: string;\n readonly localize: LocalizeErrorFn<PutioLocalizableError>;\n};\n\nexport type MatchConditionLocalizer<E> = {\n readonly kind: \"match_condition\";\n readonly match: (error: E) => boolean;\n readonly localize: LocalizeErrorFn<E>;\n};\n\nexport type GenericErrorLocalizer = {\n readonly kind: \"generic\";\n readonly localize: LocalizeErrorFn<unknown>;\n};\n\nexport type ErrorLocalizer<E> =\n | APIErrorByStatusCodeLocalizer\n | APIErrorByErrorTypeLocalizer\n | MatchConditionLocalizer<E>\n | GenericErrorLocalizer;\n\nexport type ErrorLocalizerFn = <E>(error: E) => LocalizedError;\n\nexport const isErrorLocalizer = (fn: unknown): fn is ErrorLocalizerFn => {\n try {\n return Predicate.isFunction(fn) && fn(new Error(\"test\")) instanceof LocalizedError;\n } catch {\n return false;\n }\n};\n\nexport const createLocalizeError =\n <GlobalError>(globalLocalizers: ReadonlyArray<ErrorLocalizer<GlobalError>>) =>\n <ScopedError extends GlobalError>(\n error: ScopedError,\n scopedLocalizers: ReadonlyArray<ErrorLocalizer<ScopedError>> = [],\n ): LocalizedError => {\n const localizers = [...scopedLocalizers, ...globalLocalizers];\n\n const apiError =\n isPutioErrorWithBody(error) || isLocalizablePutioErrorEnvelope(error)\n ? normalizePutioError(error)\n : undefined;\n\n const byErrorType =\n apiError &&\n localizers.find(\n (localizer): localizer is APIErrorByErrorTypeLocalizer =>\n localizer.kind === \"api_error_type\" && localizer.error_type === apiError.body.error_type,\n );\n\n if (apiError && byErrorType) {\n return new LocalizedError({\n underlyingError: apiError,\n ...byErrorType.localize(apiError),\n });\n }\n\n const byMatchCondition = localizers.find(\n (localizer): localizer is MatchConditionLocalizer<ScopedError> =>\n localizer.kind === \"match_condition\" && localizer.match(error),\n );\n\n if (byMatchCondition) {\n return new LocalizedError({\n underlyingError: error,\n ...byMatchCondition.localize(error),\n });\n }\n\n const byStatusCode =\n apiError &&\n localizers.find(\n (localizer): localizer is APIErrorByStatusCodeLocalizer =>\n localizer.kind === \"api_status_code\" &&\n localizer.status_code === apiError.body.status_code,\n );\n\n if (apiError && byStatusCode) {\n return new LocalizedError({\n underlyingError: apiError,\n ...byStatusCode.localize(apiError),\n });\n }\n\n const genericLocalizer = localizers.find(\n (localizer): localizer is GenericErrorLocalizer => localizer.kind === \"generic\",\n );\n\n if (genericLocalizer) {\n return new LocalizedError({\n underlyingError: error,\n ...genericLocalizer.localize(error),\n });\n }\n\n throw new Error(`No localizer found for error: ${String(error)}`);\n };\n","export const dotsToSpaces = (input: string): string => input.split(\".\").join(\" \");\n\nexport const truncate = (\n input: string,\n options: {\n readonly length: number;\n readonly ellipsis?: string;\n },\n): string => {\n const { ellipsis = \"...\", length } = options;\n\n if (input.length <= length) {\n return input;\n }\n\n return `${input.slice(0, length)}${ellipsis}`;\n};\n\nexport const truncateMiddle = (\n input: string,\n options: {\n readonly frontLength: number;\n readonly backLength: number;\n readonly ellipsis?: string;\n },\n): string => {\n const { backLength, ellipsis = \"...\", frontLength } = options;\n const preservedLength = frontLength + backLength;\n\n if (input.length <= preservedLength) {\n return input;\n }\n\n return `${input.slice(0, frontLength)}${ellipsis}${input.slice(input.length - backLength)}`;\n};\n"],"mappings":";;;AAAA,MAAM,sBAAsB,IAAI,KAAK,eAAe,SAAS;CAC3D,WAAW;CACX,UAAU;AACZ,CAAC;AAED,MAAM,0BAA0B,IAAI,KAAK,mBAAmB,MAAM,EAChE,SAAS,SACX,CAAC;AAID,MAAM,cAAc,UAA2B;CAC7C,IAAI,UAAU,QAAQ,UAAU,KAAA,GAC9B,uBAAO,IAAI,KAAK;CAGlB,IAAI,iBAAiB,MACnB,OAAO;CAGT,IAAI,sBAAsB,KAAK,KAAK,GAClC,uBAAO,IAAI,KAAK,GAAG,MAAM,eAAe;CAG1C,OAAO,IAAI,KAAK,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SAAS,qBACnB,UAAU,gBAAgB,SAAS,KAAK,WAC5C;CAEF,IAAI,YAAY,cACd,OAAO,IAAI,eAAe;EACxB,iBAAiB;EACjB,GAAG,aAAa,SAAS,QAAQ;CACnC,CAAC;CAGH,MAAM,mBAAmB,WAAW,MACjC,cAAkD,UAAU,SAAS,SACxE;CAEA,IAAI,kBACF,OAAO,IAAI,eAAe;EACxB,iBAAiB;EACjB,GAAG,iBAAiB,SAAS,KAAK;CACpC,CAAC;CAGH,MAAM,IAAI,MAAM,iCAAiC,OAAO,KAAK,GAAG;AAClE;;ACjNF,MAAa,gBAAgB,UAA0B,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG;AAEhF,MAAa,YACX,OACA,YAIW;CACX,MAAM,EAAE,WAAW,OAAO,WAAW;CAErC,IAAI,MAAM,UAAU,QAClB,OAAO;CAGT,OAAO,GAAG,MAAM,MAAM,GAAG,MAAM,IAAI;AACrC;AAEA,MAAa,kBACX,OACA,YAKW;CACX,MAAM,EAAE,YAAY,WAAW,OAAO,gBAAgB;CACtD,MAAM,kBAAkB,cAAc;CAEtC,IAAI,MAAM,UAAU,iBAClB,OAAO;CAGT,OAAO,GAAG,MAAM,MAAM,GAAG,WAAW,IAAI,WAAW,MAAM,MAAM,MAAM,SAAS,UAAU;AAC1F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putdotio/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"description": "Effect-first TypeScript SDK for the put.io API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect",
|
|
@@ -59,17 +59,19 @@
|
|
|
59
59
|
"test:live:targets": "vp pack && node ./scripts/test-live-targets.ts",
|
|
60
60
|
"validate:routes": "vp pack && vp run validate:routes:packed",
|
|
61
61
|
"validate:routes:packed": "node ./scripts/validate-route-matrix.ts",
|
|
62
|
-
"verify": "vp check . && vp run lint:package && knip && knip --production --no-gitignore && vp run validate:routes:packed && vp test run --coverage --passWithNoTests"
|
|
62
|
+
"verify": "vp pack && vp check . && vp run lint:package && knip && knip --production --no-gitignore && vp run validate:routes:packed && vp test run --coverage --passWithNoTests"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"effect": "4.1.2"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
69
|
+
"@oxlint/plugins": "1.91.0",
|
|
69
70
|
"@types/node": "^26.1.0",
|
|
71
|
+
"@uinaf/oxlint-plugin-no-comments": "1.0.1",
|
|
70
72
|
"@vitest/coverage-v8": "catalog:",
|
|
71
|
-
"knip": "^6.
|
|
72
|
-
"playwright": "^1.
|
|
73
|
+
"knip": "^6.44.2",
|
|
74
|
+
"playwright": "^1.65.0",
|
|
73
75
|
"publint": "^0.3.21",
|
|
74
76
|
"typescript": "^7.0.2",
|
|
75
77
|
"vite": "catalog:",
|
|
@@ -79,5 +81,5 @@
|
|
|
79
81
|
"engines": {
|
|
80
82
|
"node": ">=24.19.0"
|
|
81
83
|
},
|
|
82
|
-
"packageManager": "pnpm@12.
|
|
84
|
+
"packageManager": "pnpm@12.18.0"
|
|
83
85
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"forms-D5duroB1.js","names":[],"sources":["../src/core/errors.ts","../src/core/defaults.ts","../src/core/http.ts","../src/core/validation.ts","../src/core/forms.ts"],"sourcesContent":["import { Data, Effect, Predicate, Schema } from \"effect\";\n\nexport const PutioErrorEnvelopeSchema = Schema.Struct({\n status: Schema.optional(Schema.String),\n error: Schema.optional(Schema.String),\n error_message: Schema.optional(Schema.String),\n error_type: Schema.optional(Schema.String),\n error_uri: Schema.optional(Schema.String),\n error_id: Schema.optional(Schema.NullOr(Schema.String)),\n extra: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n status_code: Schema.optional(Schema.Int),\n details: Schema.optional(Schema.Unknown),\n});\n\nexport type PutioErrorEnvelope = Schema.Schema.Type<typeof PutioErrorEnvelopeSchema>;\n\nexport interface PutioKnownErrorContract<\n TType extends string = string,\n TStatus extends number = number,\n TBody extends PutioErrorEnvelope = PutioErrorEnvelope,\n> {\n readonly bodySchema?: Schema.Schema<TBody> | undefined;\n readonly errorType?: TType | undefined;\n readonly statusCode?: TStatus | undefined;\n}\n\ntype ContractErrorType<TContract extends PutioKnownErrorContract> =\n TContract extends PutioKnownErrorContract<infer TType, number> ? TType : never;\n\ntype ContractStatusCode<TContract extends PutioKnownErrorContract> =\n TContract extends PutioKnownErrorContract<string, infer TStatus> ? TStatus : never;\n\ntype ContractBody<TContract extends PutioKnownErrorContract> = TContract extends {\n readonly bodySchema: Schema.Schema<infer TBody extends PutioErrorEnvelope>;\n}\n ? TBody\n : PutioErrorEnvelope;\n\nexport type PutioTypedErrorEnvelope<TContract extends PutioKnownErrorContract> =\n TContract extends PutioKnownErrorContract\n ? Omit<ContractBody<TContract>, \"error_message\" | \"error_type\" | \"status_code\"> & {\n readonly error_message?: string;\n readonly error_type?: [ContractErrorType<TContract>] extends [never]\n ? string\n : ContractErrorType<TContract>;\n readonly status_code?: [ContractStatusCode<TContract>] extends [never]\n ? number\n : ContractStatusCode<TContract>;\n }\n : never;\n\nexport interface PutioOperationErrorSpec<\n TDomain extends string = string,\n TOperation extends string = string,\n TContracts extends ReadonlyArray<PutioKnownErrorContract> =\n ReadonlyArray<PutioKnownErrorContract>,\n> {\n readonly domain: TDomain;\n readonly operation: TOperation;\n readonly knownErrors: TContracts;\n}\n\ntype OperationContractOf<TSpec extends PutioOperationErrorSpec> = Extract<\n TSpec[\"knownErrors\"][number],\n PutioKnownOperationErrorContract\n>;\n\ntype OperationContractOfParts<\n TDomain extends string,\n TOperation extends string,\n TContracts extends ReadonlyArray<PutioKnownErrorContract>,\n> = OperationContractOf<PutioOperationErrorSpec<TDomain, TOperation, TContracts>>;\n\ntype PutioOperationErrorReason<TContract extends PutioKnownErrorContract> = TContract extends {\n readonly errorType: infer TType extends string;\n}\n ? {\n readonly kind: \"error_type\";\n readonly errorType: TType;\n }\n : TContract extends { readonly statusCode: infer TStatus extends number }\n ? {\n readonly kind: \"status_code\";\n readonly statusCode: TStatus;\n }\n : never;\n\nexport type PutioKnownOperationErrorContract =\n | {\n readonly errorType: string;\n readonly statusCode?: number;\n }\n | {\n readonly errorType?: undefined;\n readonly statusCode: number;\n };\n\nconst isKnownContractMatch = <TContract extends PutioKnownErrorContract>(\n contract: TContract,\n error: PutioApiError | PutioAuthError,\n): contract is Extract<TContract, PutioKnownOperationErrorContract> => {\n if (contract.bodySchema !== undefined && !Schema.is(contract.bodySchema)(error.body)) {\n return false;\n }\n\n if (contract.errorType !== undefined) {\n if (error.body.error_type !== contract.errorType) {\n return false;\n }\n\n return contract.statusCode === undefined || error.status === contract.statusCode;\n }\n\n if (contract.statusCode !== undefined) {\n return error.status === contract.statusCode;\n }\n\n return false;\n};\n\nconst isMatchableApiError = (error: PutioSdkError): error is PutioApiError | PutioAuthError =>\n error._tag === \"PutioApiError\" || error._tag === \"PutioAuthError\";\n\nconst hasOptionalString = (record: Readonly<Record<string, unknown>>, key: string): boolean =>\n !(key in record) || record[key] === undefined || typeof record[key] === \"string\";\n\nconst hasOptionalInteger = (record: Readonly<Record<string, unknown>>, key: string): boolean =>\n !(key in record) ||\n record[key] === undefined ||\n (typeof record[key] === \"number\" && Number.isInteger(record[key]));\n\nconst hasOptionalNullableString = (\n record: Readonly<Record<string, unknown>>,\n key: string,\n): boolean =>\n !(key in record) ||\n record[key] === undefined ||\n record[key] === null ||\n typeof record[key] === \"string\";\n\nconst hasOptionalRecord = (record: Readonly<Record<string, unknown>>, key: string): boolean =>\n !(key in record) || record[key] === undefined || Predicate.isObject(record[key]);\n\nconst isKnownOperationErrorContract = (value: unknown): value is PutioKnownOperationErrorContract =>\n Predicate.isObject(value) &&\n (typeof value.errorType === \"string\" || typeof value.statusCode === \"number\") &&\n hasOptionalString(value, \"errorType\") &&\n hasOptionalInteger(value, \"statusCode\");\n\nconst isOperationReason = (\n value: unknown,\n): value is PutioOperationErrorReason<PutioKnownOperationErrorContract> => {\n if (!Predicate.isObject(value)) {\n return false;\n }\n\n if (value.kind === \"error_type\") {\n return typeof value.errorType === \"string\";\n }\n\n if (value.kind === \"status_code\") {\n return typeof value.statusCode === \"number\";\n }\n\n return false;\n};\n\nfunction toOperationReason<TContract extends { readonly errorType: string }>(\n contract: TContract,\n): PutioOperationErrorReason<TContract>;\nfunction toOperationReason<TContract extends { readonly statusCode: number }>(\n contract: TContract,\n): PutioOperationErrorReason<TContract>;\nfunction toOperationReason(\n contract: PutioKnownOperationErrorContract,\n): PutioOperationErrorReason<PutioKnownOperationErrorContract> {\n if (contract.errorType !== undefined) {\n return {\n kind: \"error_type\",\n errorType: contract.errorType,\n };\n }\n\n return {\n kind: \"status_code\",\n statusCode: contract.statusCode,\n };\n}\n\nexport class PutioTransportError extends Data.TaggedError(\"PutioTransportError\")<{\n readonly cause: unknown;\n}> {}\n\nexport class PutioConfigurationError extends Data.TaggedError(\"PutioConfigurationError\")<{\n readonly cause: unknown;\n}> {}\n\nexport class PutioValidationError extends Data.TaggedError(\"PutioValidationError\")<{\n readonly cause: unknown;\n}> {}\n\nconst PutioResponseErrorFields = {\n status: Schema.Int,\n body: PutioErrorEnvelopeSchema,\n cause: Schema.optional(Schema.Defect()),\n};\n\nexport class PutioApiError extends Schema.TaggedError<PutioApiError>()(\"PutioApiError\", {\n ...PutioResponseErrorFields,\n}) {}\n\nexport class PutioAuthError extends Schema.TaggedError<PutioAuthError>()(\"PutioAuthError\", {\n ...PutioResponseErrorFields,\n}) {}\n\nexport class PutioRateLimitError extends Schema.TaggedError<PutioRateLimitError>()(\n \"PutioRateLimitError\",\n {\n ...PutioResponseErrorFields,\n action: Schema.optional(Schema.String),\n id: Schema.optional(Schema.String),\n limit: Schema.optional(Schema.String),\n remaining: Schema.optional(Schema.String),\n retryAfter: Schema.optional(Schema.String),\n reset: Schema.optional(Schema.String),\n },\n) {}\n\nexport class PutioOperationError<\n TDomain extends string,\n TOperation extends string,\n TContract extends PutioKnownOperationErrorContract,\n> extends Data.TaggedError(\"PutioOperationError\")<{\n readonly body: PutioTypedErrorEnvelope<TContract>;\n readonly contract: TContract;\n readonly domain: TDomain;\n readonly operation: TOperation;\n readonly reason: PutioOperationErrorReason<TContract>;\n readonly status: number;\n}> {}\n\nexport type PutioSdkError =\n | PutioConfigurationError\n | PutioTransportError\n | PutioValidationError\n | PutioApiError\n | PutioAuthError\n | PutioRateLimitError;\n\nexport type PutioUnhandledSdkError =\n | PutioConfigurationError\n | PutioTransportError\n | PutioValidationError\n | PutioApiError\n | PutioAuthError\n | PutioRateLimitError;\n\nexport type PutioOperationErrorFromSpec<TSpec extends PutioOperationErrorSpec> =\n PutioOperationError<TSpec[\"domain\"], TSpec[\"operation\"], OperationContractOf<TSpec>>;\n\nexport type PutioOperationFailure<TSpec extends PutioOperationErrorSpec> =\n | PutioUnhandledSdkError\n | PutioOperationErrorFromSpec<TSpec>;\n\nexport type AnyPutioOperationError = PutioOperationError<\n string,\n string,\n PutioKnownOperationErrorContract\n>;\n\nexport const definePutioOperationErrorSpec = <\n const TDomain extends string,\n const TOperation extends string,\n const TContracts extends ReadonlyArray<PutioKnownErrorContract>,\n>(\n spec: PutioOperationErrorSpec<TDomain, TOperation, TContracts>,\n) => spec;\n\nexport const decodePutioErrorEnvelope = Schema.decodeUnknownEffect(PutioErrorEnvelopeSchema);\n\nexport const isPutioErrorEnvelope = (value: unknown): value is PutioErrorEnvelope =>\n Predicate.isObject(value) &&\n hasOptionalString(value, \"status\") &&\n hasOptionalString(value, \"error\") &&\n hasOptionalString(value, \"error_message\") &&\n hasOptionalString(value, \"error_type\") &&\n hasOptionalString(value, \"error_uri\") &&\n hasOptionalNullableString(value, \"error_id\") &&\n hasOptionalRecord(value, \"extra\") &&\n hasOptionalInteger(value, \"status_code\");\n\nconst hasStatusAndBody = <TTag extends string>(\n value: unknown,\n tag: TTag,\n): value is {\n readonly _tag: TTag;\n readonly body: PutioErrorEnvelope;\n readonly status: number;\n} =>\n Predicate.isObject(value) &&\n value._tag === tag &&\n typeof value.status === \"number\" &&\n isPutioErrorEnvelope(value.body);\n\nexport const isPutioApiError = (value: unknown): value is PutioApiError =>\n hasStatusAndBody(value, \"PutioApiError\");\n\nexport const isPutioAuthError = (value: unknown): value is PutioAuthError =>\n hasStatusAndBody(value, \"PutioAuthError\");\n\nexport const isPutioRateLimitError = (value: unknown): value is PutioRateLimitError =>\n hasStatusAndBody(value, \"PutioRateLimitError\") &&\n Predicate.isObject(value) &&\n hasOptionalString(value, \"action\") &&\n hasOptionalString(value, \"id\") &&\n hasOptionalString(value, \"limit\") &&\n hasOptionalString(value, \"remaining\") &&\n hasOptionalString(value, \"retryAfter\") &&\n hasOptionalString(value, \"reset\");\n\nexport const isPutioOperationError = (value: unknown): value is AnyPutioOperationError =>\n Predicate.isObject(value) &&\n value._tag === \"PutioOperationError\" &&\n isPutioErrorEnvelope(value.body) &&\n isKnownOperationErrorContract(value.contract) &&\n typeof value.domain === \"string\" &&\n typeof value.operation === \"string\" &&\n isOperationReason(value.reason) &&\n typeof value.status === \"number\";\n\nexport const fallbackPutioErrorEnvelope = (status: number): PutioErrorEnvelope => ({\n error_message: `put.io API request failed with status ${status}`,\n status_code: status,\n});\n\nconst getHeader = (headers: Headers, name: string): string | undefined =>\n headers.get(name) ?? undefined;\n\nexport const responseRateLimitHeaders = (headers: Headers) => ({\n action: getHeader(headers, \"x-ratelimit-action\"),\n id: getHeader(headers, \"x-ratelimit-id\"),\n limit: getHeader(headers, \"x-ratelimit-limit\"),\n remaining: getHeader(headers, \"x-ratelimit-remaining\"),\n retryAfter: getHeader(headers, \"retry-after\"),\n reset: getHeader(headers, \"x-ratelimit-reset\"),\n});\n\nexport const mapDecodeErrorToValidationError = (cause: unknown) =>\n new PutioValidationError({ cause });\n\nexport const mapConfigurationError = (cause: unknown) => new PutioConfigurationError({ cause });\n\nexport const mapTransportError = (cause: unknown) => new PutioTransportError({ cause });\n\nexport const makeResponseError = (\n status: number,\n headers: Headers,\n body: PutioErrorEnvelope,\n cause?: unknown,\n): PutioSdkError => {\n if (status === 429) {\n return new PutioRateLimitError({\n status,\n body,\n ...responseRateLimitHeaders(headers),\n cause,\n });\n }\n\n if (status === 401 || status === 403) {\n return new PutioAuthError({ status, body, cause });\n }\n\n return new PutioApiError({ status, body, cause });\n};\n\nexport const parseErrorBody = (status: number, json: unknown) =>\n decodePutioErrorEnvelope(json).pipe(\n Effect.orElseSucceed(() => fallbackPutioErrorEnvelope(status)),\n );\n\nexport function withOperationErrors<\n A,\n E extends PutioSdkError,\n R,\n const TDomain extends string,\n const TOperation extends string,\n const TContracts extends ReadonlyArray<PutioKnownErrorContract>,\n>(\n effect: Effect.Effect<A, E, R>,\n spec: PutioOperationErrorSpec<TDomain, TOperation, TContracts>,\n): Effect.Effect<\n A,\n | E\n | PutioOperationError<\n TDomain,\n TOperation,\n OperationContractOfParts<TDomain, TOperation, TContracts>\n >,\n R\n>;\nexport function withOperationErrors<\n const TDomain extends string,\n const TOperation extends string,\n const TContracts extends ReadonlyArray<PutioKnownErrorContract>,\n>(\n spec: PutioOperationErrorSpec<TDomain, TOperation, TContracts>,\n): <A, E extends PutioSdkError, R>(\n effect: Effect.Effect<A, E, R>,\n) => Effect.Effect<\n A,\n | E\n | PutioOperationError<\n TDomain,\n TOperation,\n OperationContractOfParts<TDomain, TOperation, TContracts>\n >,\n R\n>;\nexport function withOperationErrors<\n A,\n E extends PutioSdkError,\n R,\n const TDomain extends string,\n const TOperation extends string,\n const TContracts extends ReadonlyArray<PutioKnownErrorContract>,\n>(\n effectOrSpec: Effect.Effect<A, E, R> | PutioOperationErrorSpec<TDomain, TOperation, TContracts>,\n maybeSpec?: PutioOperationErrorSpec<TDomain, TOperation, TContracts>,\n):\n | Effect.Effect<\n A,\n | E\n | PutioOperationError<\n TDomain,\n TOperation,\n OperationContractOfParts<TDomain, TOperation, TContracts>\n >,\n R\n >\n | (<A2, E2 extends PutioSdkError, R2>(\n effect: Effect.Effect<A2, E2, R2>,\n ) => Effect.Effect<\n A2,\n | E2\n | PutioOperationError<\n TDomain,\n TOperation,\n OperationContractOfParts<TDomain, TOperation, TContracts>\n >,\n R2\n >) {\n if (maybeSpec === undefined) {\n const spec = effectOrSpec as PutioOperationErrorSpec<TDomain, TOperation, TContracts>;\n\n return <A2, E2 extends PutioSdkError, R2>(effect: Effect.Effect<A2, E2, R2>) =>\n withOperationErrors(effect, spec);\n }\n\n const effect = effectOrSpec as Effect.Effect<A, E, R>;\n const spec = maybeSpec;\n\n return effect.pipe(\n Effect.mapError((error) => {\n if (!isMatchableApiError(error)) {\n return error;\n }\n\n const contract = spec.knownErrors.find((candidate) => isKnownContractMatch(candidate, error));\n\n if (!contract) {\n return error;\n }\n\n return new PutioOperationError({\n body: error.body as PutioTypedErrorEnvelope<\n OperationContractOfParts<TDomain, TOperation, TContracts>\n >,\n contract,\n domain: spec.domain,\n operation: spec.operation,\n reason: toOperationReason(contract),\n status: error.status,\n });\n }),\n );\n}\n","export const DEFAULT_PUTIO_API_BASE_URL = \"https://api.put.io\";\nexport const DEFAULT_PUTIO_UPLOAD_BASE_URL = \"https://upload.put.io\";\nexport const DEFAULT_PUTIO_WEB_APP_URL = \"https://app.put.io\";\n","import { Context, Effect, Layer, Schema } from \"effect\";\n\nimport {\n DEFAULT_PUTIO_API_BASE_URL,\n DEFAULT_PUTIO_UPLOAD_BASE_URL,\n DEFAULT_PUTIO_WEB_APP_URL,\n} from \"./defaults.js\";\nimport {\n fallbackPutioErrorEnvelope,\n makeResponseError,\n mapConfigurationError,\n mapDecodeErrorToValidationError,\n mapTransportError,\n parseErrorBody,\n PutioConfigurationError,\n type PutioSdkError,\n} from \"./errors.js\";\n\nexport type PutioQueryValue = string | number | boolean | null | undefined;\n\nexport type PutioQuery = Readonly<Record<string, PutioQueryValue>>;\n\nexport type PutioPathSegment = string | number | boolean;\n\nexport interface PutioSdkConfigShape {\n readonly accessToken?: string;\n readonly baseUrl?: string | URL;\n readonly headers?: HeadersInit;\n readonly uploadBaseUrl?: string | URL;\n readonly webAppUrl?: string | URL;\n}\n\nexport class PutioSdkConfig extends Context.Service<PutioSdkConfig, PutioSdkConfigShape>()(\n \"PutioSdkConfig\",\n) {}\n\nexport interface PutioHttpRequest {\n readonly body?: BodyInit;\n readonly headers: Headers;\n readonly method: PutioRequestMethod;\n readonly url: string;\n}\n\nexport interface PutioHttpResponse {\n readonly arrayBuffer: Effect.Effect<ArrayBuffer, PutioSdkError>;\n readonly headers: Headers;\n readonly json: Effect.Effect<unknown, PutioSdkError>;\n readonly status: number;\n}\n\nexport interface PutioHttpClientShape {\n readonly execute: (request: PutioHttpRequest) => Effect.Effect<PutioHttpResponse, PutioSdkError>;\n}\n\nexport class PutioHttpClient extends Context.Service<PutioHttpClient, PutioHttpClientShape>()(\n \"PutioHttpClient\",\n) {}\n\nexport type PutioSdkContext = PutioSdkConfig | PutioHttpClient;\n\nexport const makePutioSdkConfig = (config: PutioSdkConfigShape): PutioSdkConfigShape => ({\n accessToken: config.accessToken,\n baseUrl: config.baseUrl ?? DEFAULT_PUTIO_API_BASE_URL,\n headers: config.headers,\n uploadBaseUrl: config.uploadBaseUrl ?? DEFAULT_PUTIO_UPLOAD_BASE_URL,\n webAppUrl: config.webAppUrl ?? DEFAULT_PUTIO_WEB_APP_URL,\n});\n\nexport const makePutioSdkLayer = (config: PutioSdkConfigShape) =>\n Layer.succeed(PutioSdkConfig, makePutioSdkConfig(config));\n\nexport const makePutioSdkLiveLayer = (config: PutioSdkConfigShape) =>\n Layer.mergeAll(makePutioSdkLayer(config), makePutioFetchLayer());\n\nexport const makePutioFetchLayer = (\n fetchImplementation: typeof globalThis.fetch = globalThis.fetch,\n) => Layer.succeed(PutioHttpClient, makePutioFetchClient(fetchImplementation));\n\nexport const makePutioFetchClient = (\n fetchImplementation: typeof globalThis.fetch = globalThis.fetch,\n): PutioHttpClientShape => ({\n execute: (request) =>\n Effect.suspend(() => {\n const controller = new AbortController();\n const read = <A>(body: () => Promise<A>) =>\n Effect.tryPromise({ try: body, catch: mapTransportError }).pipe(\n Effect.onInterrupt(() => Effect.sync(() => controller.abort())),\n );\n\n return read(async () => {\n const response = await fetchImplementation(request.url, {\n body: request.body,\n headers: request.headers,\n method: request.method,\n signal: controller.signal,\n });\n\n return {\n arrayBuffer: read(() => response.arrayBuffer()),\n headers: response.headers,\n json: isSuccessStatus(response.status)\n ? read(() => response.json())\n : read(() => response.text()).pipe(\n Effect.flatMap((text) =>\n Schema.decodeUnknownEffect(Schema.UnknownFromJsonString)(text).pipe(\n Effect.mapError(() =>\n makeResponseError(\n response.status,\n response.headers,\n fallbackPutioErrorEnvelope(response.status),\n // Native JSON errors can quote response contents in their message.\n new SyntaxError(\"The HTTP error response body is not valid JSON\"),\n ),\n ),\n ),\n ),\n ),\n status: response.status,\n };\n });\n }),\n});\n\nexport const encodePathSegment = (value: PutioPathSegment): string =>\n encodeURIComponent(String(value));\n\nconst absoluteUrlPattern = /^(?:[a-z][a-z\\d+.-]*:|\\/\\/)/i;\n\nconst normalizeApiPath = (path: string): string => {\n if (absoluteUrlPattern.test(path)) {\n throw mapConfigurationError(\"SDK API request paths must be relative to the configured baseUrl\");\n }\n\n return path.startsWith(\"/\") ? path : `/${path}`;\n};\n\nexport const buildPutioUrl = (baseUrl: string | URL, path: string, query?: PutioQuery): string => {\n const url = new URL(normalizeApiPath(path), baseUrl);\n\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined && value !== null) {\n url.searchParams.set(key, String(value));\n }\n }\n }\n\n return url.toString();\n};\n\nconst mapUrlBuildError = (cause: unknown) =>\n cause instanceof PutioConfigurationError ? cause : mapConfigurationError(cause);\n\nexport const OkResponseSchema = Schema.Struct({\n status: Schema.Literal(\"OK\"),\n});\n\nexport type PutioAuth =\n | { readonly type: \"config-token\" }\n | { readonly type: \"token\"; readonly token: string }\n | { readonly type: \"basic\"; readonly username: string; readonly password: string }\n | { readonly type: \"none\" };\n\ntype PutioRequestMethod = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\ntype PutioRequestBody =\n | { readonly type: \"none\" }\n | { readonly type: \"json\"; readonly value: unknown }\n | { readonly type: \"form\"; readonly value: Record<string, unknown> }\n | { readonly type: \"form-data\"; readonly value: FormData };\n\ninterface PutioRequestOptions {\n readonly method: PutioRequestMethod;\n readonly path: string;\n readonly baseUrl?: string | URL;\n readonly query?: PutioQuery;\n readonly headers?: HeadersInit;\n readonly auth?: PutioAuth;\n readonly body?: PutioRequestBody;\n}\n\nconst isSuccessStatus = (status: number) => status >= 200 && status < 300;\n\nconst decodeSuccessJson = <S extends Schema.Top>(schema: S, response: PutioHttpResponse) =>\n response.json.pipe(\n Effect.flatMap((json) =>\n Schema.decodeUnknownEffect(schema)(json).pipe(\n Effect.mapError(mapDecodeErrorToValidationError),\n ),\n ),\n );\n\nconst decodeFailure = (response: PutioHttpResponse, headers: Headers) =>\n response.json.pipe(\n Effect.flatMap((json) => parseErrorBody(response.status, json)),\n Effect.map((body) => makeResponseError(response.status, headers, body)),\n );\n\nconst toBasicAuthorization = (username: string, password: string) => {\n if (typeof globalThis.btoa === \"function\") {\n return `Basic ${globalThis.btoa(`${username}:${password}`)}`;\n }\n\n throw mapConfigurationError(\n \"This runtime does not provide btoa(), so Basic auth cannot be encoded safely\",\n );\n};\n\nconst resolveAuthorization = (\n config: PutioSdkConfigShape,\n auth: PutioAuth | undefined,\n): Effect.Effect<string | undefined, PutioSdkError> => {\n const resolvedAuth = auth ?? { type: \"config-token\" as const };\n\n switch (resolvedAuth.type) {\n case \"none\":\n return Effect.succeed(undefined);\n case \"token\":\n return Effect.succeed(`Token ${resolvedAuth.token}`);\n case \"basic\":\n return Effect.try({\n try: () => toBasicAuthorization(resolvedAuth.username, resolvedAuth.password),\n catch: mapConfigurationError,\n });\n case \"config-token\":\n if (!config.accessToken) {\n return Effect.fail(\n mapConfigurationError(\n \"This endpoint requires an access token, but PutioSdkConfig.accessToken is missing\",\n ),\n );\n }\n\n return Effect.succeed(`Token ${config.accessToken}`);\n }\n};\n\nconst normalizeFormValue = (value: unknown): string => {\n if (value === null || value === undefined) {\n return \"\";\n }\n\n if (typeof value === \"string\") {\n return value;\n }\n\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n\n return JSON.stringify(value);\n};\n\nconst withBody = (body: PutioRequestBody): Effect.Effect<BodyInit | undefined, PutioSdkError> => {\n switch (body.type) {\n case \"none\":\n return Effect.succeed(undefined);\n case \"json\":\n return Effect.try({\n try: () => JSON.stringify(body.value),\n catch: mapDecodeErrorToValidationError,\n });\n case \"form\":\n return Effect.succeed(\n new URLSearchParams(\n Object.entries(body.value).flatMap(([key, value]) =>\n value === undefined ? [] : [[key, normalizeFormValue(value)]],\n ),\n ),\n );\n case \"form-data\":\n return Effect.succeed(body.value);\n }\n};\n\nconst makeRequest = (\n url: string,\n options: PutioRequestOptions,\n configHeaders: HeadersInit | undefined,\n authorization?: string,\n) =>\n Effect.gen(function* () {\n const headers = new Headers(configHeaders);\n // `auth` alone decides credentials, including `none`.\n headers.delete(\"authorization\");\n new Headers(options.headers).forEach((value, name) => headers.set(name, value));\n\n const body = options.body ?? { type: \"none\" as const };\n if (!headers.has(\"accept\")) {\n headers.set(\"accept\", \"application/json\");\n }\n\n if (authorization) {\n headers.set(\"authorization\", authorization);\n }\n\n if (body.type === \"json\" && !headers.has(\"content-type\")) {\n headers.set(\"content-type\", \"application/json\");\n }\n\n return {\n body: yield* withBody(body),\n headers,\n method: options.method,\n url,\n };\n });\n\nconst executeRequest = (options: PutioRequestOptions) =>\n Effect.gen(function* () {\n const config = yield* PutioSdkConfig;\n const httpClient = yield* PutioHttpClient;\n const authorization = yield* resolveAuthorization(config, options.auth);\n const url = yield* Effect.try({\n try: () =>\n buildPutioUrl(\n options.baseUrl ?? config.baseUrl ?? DEFAULT_PUTIO_API_BASE_URL,\n options.path,\n options.query,\n ),\n catch: mapUrlBuildError,\n });\n const request = yield* makeRequest(url, options, config.headers, authorization);\n\n return yield* httpClient.execute(request);\n });\n\nexport const requestJson = <S extends Schema.Top>(\n schema: S,\n options: PutioRequestOptions,\n): Effect.Effect<S[\"Type\"], PutioSdkError, PutioSdkContext | S[\"DecodingServices\"]> =>\n executeRequest(options).pipe(\n Effect.flatMap((response) =>\n isSuccessStatus(response.status)\n ? decodeSuccessJson(schema, response)\n : decodeFailure(response, response.headers).pipe(Effect.flatMap(Effect.fail)),\n ),\n );\n\nexport const selectJsonField =\n <K extends string>(field: K) =>\n <A extends { readonly [P in K]: unknown }, E, R>(\n effect: Effect.Effect<A, E, R>,\n ): Effect.Effect<A[K], E, R> =>\n effect.pipe(Effect.map((value) => value[field]));\n\nexport const selectJsonFields =\n <const K extends readonly string[]>(...fields: K) =>\n <A extends { readonly [P in K[number]]: unknown }, E, R>(\n effect: Effect.Effect<A, E, R>,\n ): Effect.Effect<Pick<A, K[number]>, E, R> =>\n effect.pipe(\n Effect.map(\n (value) =>\n Object.fromEntries(fields.map((field) => [field, value[field as K[number]]])) as Pick<\n A,\n K[number]\n >,\n ),\n );\n\nexport const requestArrayBuffer = (\n options: PutioRequestOptions,\n): Effect.Effect<Uint8Array, PutioSdkError, PutioSdkContext> =>\n executeRequest(options).pipe(\n Effect.flatMap((response) =>\n isSuccessStatus(response.status)\n ? response.arrayBuffer.pipe(Effect.map((buffer) => new Uint8Array(buffer)))\n : decodeFailure(response, response.headers).pipe(Effect.flatMap(Effect.fail)),\n ),\n );\n\nexport const requestText = (\n options: PutioRequestOptions,\n): Effect.Effect<string, PutioSdkError, PutioSdkContext> =>\n requestArrayBuffer(options).pipe(Effect.map((bytes) => new TextDecoder().decode(bytes)));\n\nexport const requestVoid = (\n options: PutioRequestOptions,\n): Effect.Effect<void, PutioSdkError, PutioSdkContext> =>\n executeRequest(options).pipe(\n Effect.flatMap((response) =>\n isSuccessStatus(response.status)\n ? Effect.void\n : decodeFailure(response, response.headers).pipe(Effect.flatMap(Effect.fail)),\n ),\n );\n","import { Effect, Schema } from \"effect\";\n\nimport { mapDecodeErrorToValidationError } from \"./errors.js\";\n\nexport const PositiveIntegerSchema = Schema.Int.check(Schema.isGreaterThan(0));\nexport const NonEmptyStringSchema = Schema.String.check(Schema.isMinLength(1));\n\nexport const decodeAndRun = <S extends Schema.Top, A, E, R>(\n schema: S,\n input: unknown,\n run: (decoded: S[\"Type\"]) => Effect.Effect<A, E, R>,\n) =>\n Schema.decodeUnknownEffect(schema, { onExcessProperty: \"error\" })(input).pipe(\n Effect.mapError(mapDecodeErrorToValidationError),\n Effect.flatMap(run),\n );\n\nexport const makeCursorSelectionSchema = <\n const TIdsField extends string,\n const TExcludeIdsField extends string,\n const TFields extends Schema.Struct.Fields,\n>(\n idsField: TIdsField,\n excludeIdsField: TExcludeIdsField,\n fields: TFields,\n) =>\n Schema.Struct({\n cursor: Schema.optional(NonEmptyStringSchema),\n [excludeIdsField]: Schema.optional(Schema.Array(PositiveIntegerSchema)),\n [idsField]: Schema.optional(Schema.Array(PositiveIntegerSchema).check(Schema.isMinLength(1))),\n ...fields,\n }).check(\n Schema.makeFilter((input) => input.cursor !== undefined || input[idsField] !== undefined, {\n expected: \"a non-empty cursor or file ID selection\",\n }),\n );\n","type CsvValue = string | number;\n\nexport interface CursorSelectionInput<TValue extends CsvValue = number> {\n readonly cursor?: string;\n readonly excludeIds?: ReadonlyArray<TValue>;\n readonly ids?: ReadonlyArray<TValue>;\n}\n\nexport const joinCsv = <TValue extends CsvValue>(\n values: ReadonlyArray<TValue> | undefined,\n): string | undefined => (values && values.length > 0 ? values.join(\",\") : undefined);\n\nexport const toCursorSelectionForm = <\n TValue extends CsvValue,\n const TIdsFieldName extends string = \"file_ids\",\n>(\n selection: CursorSelectionInput<TValue>,\n idsFieldName?: TIdsFieldName,\n): {\n readonly cursor?: string;\n readonly exclude_ids?: string;\n} & Record<TIdsFieldName, string | undefined> => {\n const resolvedIdsFieldName = (idsFieldName ?? \"file_ids\") as TIdsFieldName;\n\n return {\n cursor: selection.cursor,\n exclude_ids: joinCsv(selection.excludeIds),\n [resolvedIdsFieldName]: joinCsv(selection.ids),\n } as {\n readonly cursor?: string;\n readonly exclude_ids?: string;\n } & Record<TIdsFieldName, string | undefined>;\n};\n"],"mappings":";;AAEA,MAAa,2BAA2B,OAAO,OAAO;CACpD,QAAQ,OAAO,SAAS,OAAO,MAAM;CACrC,OAAO,OAAO,SAAS,OAAO,MAAM;CACpC,eAAe,OAAO,SAAS,OAAO,MAAM;CAC5C,YAAY,OAAO,SAAS,OAAO,MAAM;CACzC,WAAW,OAAO,SAAS,OAAO,MAAM;CACxC,UAAU,OAAO,SAAS,OAAO,OAAO,OAAO,MAAM,CAAC;CACtD,OAAO,OAAO,SAAS,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,CAAC;CACnE,aAAa,OAAO,SAAS,OAAO,GAAG;CACvC,SAAS,OAAO,SAAS,OAAO,OAAO;AACzC,CAAC;AAqFD,MAAM,wBACJ,UACA,UACqE;CACrE,IAAI,SAAS,eAAe,KAAA,KAAa,CAAC,OAAO,GAAG,SAAS,UAAU,CAAC,CAAC,MAAM,IAAI,GACjF,OAAO;CAGT,IAAI,SAAS,cAAc,KAAA,GAAW;EACpC,IAAI,MAAM,KAAK,eAAe,SAAS,WACrC,OAAO;EAGT,OAAO,SAAS,eAAe,KAAA,KAAa,MAAM,WAAW,SAAS;CACxE;CAEA,IAAI,SAAS,eAAe,KAAA,GAC1B,OAAO,MAAM,WAAW,SAAS;CAGnC,OAAO;AACT;AAEA,MAAM,uBAAuB,UAC3B,MAAM,SAAS,mBAAmB,MAAM,SAAS;AAEnD,MAAM,qBAAqB,QAA2C,QACpE,EAAE,OAAO,WAAW,OAAO,SAAS,KAAA,KAAa,OAAO,OAAO,SAAS;AAE1E,MAAM,sBAAsB,QAA2C,QACrE,EAAE,OAAO,WACT,OAAO,SAAS,KAAA,KACf,OAAO,OAAO,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