@putdotio/sdk 11.5.1 → 12.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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as decodePutioErrorEnvelope, B as mapDecodeErrorToValidationError, C as PutioAuthError, D as PutioRateLimitError, E as PutioOperationError, F as isPutioErrorEnvelope, H as parseErrorBody, I as isPutioOperationError, L as isPutioRateLimitError, M as fallbackPutioErrorEnvelope, N as isPutioApiError, O as PutioTransportError, P as isPutioAuthError, R as makeResponseError, S as PutioApiError, T as PutioErrorEnvelopeSchema, U as responseRateLimitHeaders, V as mapTransportError, W as withOperationErrors, _ as selectJsonField, a as PutioSdkConfig, b as DEFAULT_PUTIO_UPLOAD_BASE_URL, c as makePutioFetchClient, d as makePutioSdkLayer, f as makePutioSdkLiveLayer, g as requestVoid, h as requestText, i as PutioHttpClient, j as definePutioOperationErrorSpec, k as PutioValidationError, l as makePutioFetchLayer, m as requestJson, n as toCursorSelectionForm, o as buildPutioUrl, p as requestArrayBuffer, r as OkResponseSchema, s as encodePathSegment, t as joinCsv, u as makePutioSdkConfig, v as selectJsonFields, w as PutioConfigurationError, x as DEFAULT_PUTIO_WEB_APP_URL, y as DEFAULT_PUTIO_API_BASE_URL, z as mapConfigurationError } from "./forms-Ch5rwD58.js";
1
+ import { A as PutioOperationError, B as isPutioOperationError, C as DEFAULT_PUTIO_API_BASE_URL, D as PutioAuthError, E as PutioApiError, F as definePutioOperationErrorSpec, G as mapTransportError, H as makeResponseError, I as fallbackPutioErrorEnvelope, J as withOperationErrors, K as parseErrorBody, L as isPutioApiError, M as PutioTransportError, N as PutioValidationError, O as PutioConfigurationError, P as decodePutioErrorEnvelope, R as isPutioAuthError, S as selectJsonFields, T as DEFAULT_PUTIO_WEB_APP_URL, U as mapConfigurationError, V as isPutioRateLimitError, W as mapDecodeErrorToValidationError, _ as requestArrayBuffer, a as decodeAndRun, b as requestVoid, c as PutioHttpClient, d as encodePathSegment, f as makePutioFetchClient, g as makePutioSdkLiveLayer, h as makePutioSdkLayer, i as PositiveIntegerSchema, j as PutioRateLimitError, k as PutioErrorEnvelopeSchema, l as PutioSdkConfig, m as makePutioSdkConfig, n as toCursorSelectionForm, o as makeCursorSelectionSchema, p as makePutioFetchLayer, q as responseRateLimitHeaders, r as NonEmptyStringSchema, s as OkResponseSchema, t as joinCsv, u as buildPutioUrl, v as requestJson, w as DEFAULT_PUTIO_UPLOAD_BASE_URL, x as selectJsonField, y as requestText, z as isPutioErrorEnvelope } from "./forms-Bd1tWyx0.js";
2
2
  import { Cause, Context, Effect, Exit, Layer, ManagedRuntime, Schema, SchemaIssue, SchemaParser } from "effect";
3
3
  //#region src/domains/account.ts
4
4
  const RequestedFlag$1 = Schema.Literal(1);
@@ -428,17 +428,6 @@ const deleteAllAppSpecificPasswords = () => requestJson(OkResponseSchema, {
428
428
  path: "/v2/app_specific_password/delete_all"
429
429
  }).pipe(Effect.asVoid, withOperationErrors(DeleteAllAppSpecificPasswordsErrorSpec));
430
430
  //#endregion
431
- //#region src/core/validation.ts
432
- const PositiveIntegerSchema = Schema.Int.check(Schema.isGreaterThan(0));
433
- const NonEmptyStringSchema = Schema.String.check(Schema.isMinLength(1));
434
- const decodeAndRun = (schema, input, run) => Schema.decodeUnknownEffect(schema, { onExcessProperty: "error" })(input).pipe(Effect.mapError(mapDecodeErrorToValidationError), Effect.flatMap(run));
435
- const makeCursorSelectionSchema = (idsField, excludeIdsField, fields) => Schema.Struct({
436
- cursor: Schema.optional(NonEmptyStringSchema),
437
- [excludeIdsField]: Schema.optional(Schema.Array(PositiveIntegerSchema)),
438
- [idsField]: Schema.optional(Schema.Array(PositiveIntegerSchema).check(Schema.isMinLength(1))),
439
- ...fields
440
- }).check(Schema.makeFilter((input) => input.cursor !== void 0 || input[idsField] !== void 0, { expected: "a non-empty cursor or file ID selection" }));
441
- //#endregion
442
431
  //#region src/domains/oauth.ts
443
432
  const OAuthAppBaseSchema = Schema.Struct({
444
433
  description: Schema.String,
@@ -2239,7 +2228,7 @@ const FileUploadInputSchema = Schema.Struct({
2239
2228
  });
2240
2229
  const FileUploadOptionsSchema = Schema.Struct({ oauthToken: Schema.optional(NonEmptyStringSchema) });
2241
2230
  const FileDirectAccessOptionsSchema = Schema.Struct({
2242
- oauthToken: Schema.optional(NonEmptyStringSchema),
2231
+ downloadToken: NonEmptyStringSchema,
2243
2232
  useTunnel: Schema.optional(Schema.Boolean)
2244
2233
  });
2245
2234
  const FileApiDownloadUrlOptionsSchema = FileDirectAccessOptionsSchema.pipe(Schema.fieldsAssign({ name: Schema.optional(NonEmptyStringSchema) }));
@@ -2249,7 +2238,7 @@ const FileApiMp4DownloadUrlOptionsSchema = FileDirectAccessOptionsSchema.pipe(Sc
2249
2238
  }));
2250
2239
  const FileHlsStreamUrlOptionsSchema = Schema.Struct({
2251
2240
  maxSubtitleCount: Schema.optional(PositiveIntegerSchema),
2252
- oauthToken: Schema.optional(NonEmptyStringSchema),
2241
+ downloadToken: NonEmptyStringSchema,
2253
2242
  playOriginal: Schema.optional(Schema.Boolean),
2254
2243
  subtitleLanguages: Schema.optional(Schema.Array(NonEmptyStringSchema).check(Schema.isMinLength(1)))
2255
2244
  });
@@ -2258,7 +2247,7 @@ const FileHlsMasterPlaylistOptionsSchema = Schema.Struct({
2258
2247
  playOriginal: Schema.optional(Schema.Boolean),
2259
2248
  subtitleLanguages: Schema.optional(Schema.Array(NonEmptyStringSchema).check(Schema.isMinLength(1)))
2260
2249
  });
2261
- const FileXspfPlaylistUrlOptionsSchema = Schema.Struct({ oauthToken: Schema.optional(NonEmptyStringSchema) });
2250
+ const FileXspfPlaylistUrlOptionsSchema = Schema.Struct({ downloadToken: NonEmptyStringSchema });
2262
2251
  const FilesNextFileSchema = Schema.Struct({
2263
2252
  id: Schema.Int,
2264
2253
  name: Schema.String,
@@ -2581,14 +2570,17 @@ const hasMediaMetadata = (value) => "media_metadata" in value;
2581
2570
  const hasCodecs = (value) => "content_type_and_codecs" in value;
2582
2571
  const hasMediaInfo = (value) => "media_info" in value;
2583
2572
  const useTunnelToQuery = (useTunnel) => useTunnel === false ? { notunnel: 1 } : {};
2584
- const resolveRouteContext = (oauthToken) => Effect.gen(function* () {
2573
+ const resolveRouteContext = (token) => Effect.gen(function* () {
2585
2574
  const config = yield* PutioSdkConfig;
2586
- const resolvedOauthToken = oauthToken ?? config.accessToken;
2587
- if (resolvedOauthToken) return {
2575
+ const resolvedToken = token ?? config.accessToken;
2576
+ if (resolvedToken) return {
2588
2577
  config,
2589
- oauthToken: resolvedOauthToken
2578
+ token: resolvedToken
2590
2579
  };
2591
- return yield* Effect.fail(mapConfigurationError("This helper requires an oauth token, but neither an override nor PutioSdkConfig.accessToken was provided"));
2580
+ return yield* Effect.fail(mapConfigurationError("This helper requires a token, but neither an override nor PutioSdkConfig.accessToken was provided"));
2581
+ });
2582
+ const resolveApiBaseUrl = Effect.gen(function* () {
2583
+ return (yield* PutioSdkConfig).baseUrl ?? "https://api.put.io";
2592
2584
  });
2593
2585
  const normalizeFileName = (name) => encodeURIComponent(name);
2594
2586
  const toUploadResult = (value) => {
@@ -2602,26 +2594,26 @@ const toUploadResult = (value) => {
2602
2594
  };
2603
2595
  throw new PutioValidationError({ cause: "Expected put.io upload response to contain either \"file\" or \"transfer\"" });
2604
2596
  };
2605
- const buildFileApiDownloadUrl = (baseUrl, fileId, options = {}) => buildPutioUrl(baseUrl, options.name ? `/v2/files/${encodePathSegment(fileId)}/download/${normalizeFileName(options.name)}` : `/v2/files/${encodePathSegment(fileId)}/download`, {
2597
+ const buildFileApiDownloadUrl = (baseUrl, fileId, options) => buildPutioUrl(baseUrl, options.name ? `/v2/files/${encodePathSegment(fileId)}/download/${normalizeFileName(options.name)}` : `/v2/files/${encodePathSegment(fileId)}/download`, {
2606
2598
  ...useTunnelToQuery(options.useTunnel),
2607
- oauth_token: options.oauthToken
2599
+ oauth_token: options.downloadToken
2608
2600
  });
2609
- const buildFileApiContentUrl = (baseUrl, fileId, options = {}) => buildPutioUrl(baseUrl, `/v2/files/${encodePathSegment(fileId)}/stream`, {
2601
+ const buildFileApiContentUrl = (baseUrl, fileId, options) => buildPutioUrl(baseUrl, `/v2/files/${encodePathSegment(fileId)}/stream`, {
2610
2602
  ...useTunnelToQuery(options.useTunnel),
2611
- oauth_token: options.oauthToken
2603
+ oauth_token: options.downloadToken
2612
2604
  });
2613
- const buildFileApiMp4DownloadUrl = (baseUrl, fileId, options = {}) => buildPutioUrl(baseUrl, options.name ? `/v2/files/${encodePathSegment(fileId)}/mp4/download/${normalizeFileName(options.name)}` : `/v2/files/${encodePathSegment(fileId)}/mp4/download`, {
2605
+ const buildFileApiMp4DownloadUrl = (baseUrl, fileId, options) => buildPutioUrl(baseUrl, options.name ? `/v2/files/${encodePathSegment(fileId)}/mp4/download/${normalizeFileName(options.name)}` : `/v2/files/${encodePathSegment(fileId)}/mp4/download`, {
2614
2606
  ...useTunnelToQuery(options.useTunnel),
2615
2607
  convert: options.convert ? 1 : void 0,
2616
- oauth_token: options.oauthToken
2608
+ oauth_token: options.downloadToken
2617
2609
  });
2618
- const buildFileHlsStreamUrl = (baseUrl, fileId, options = {}) => buildPutioUrl(baseUrl, `/v2/files/${encodePathSegment(fileId)}/hls/media.m3u8`, {
2610
+ const buildFileHlsStreamUrl = (baseUrl, fileId, options) => buildPutioUrl(baseUrl, `/v2/files/${encodePathSegment(fileId)}/hls/media.m3u8`, {
2619
2611
  max_subtitle_count: options.maxSubtitleCount,
2620
- oauth_token: options.oauthToken,
2612
+ oauth_token: options.downloadToken,
2621
2613
  original: typeof options.playOriginal === "boolean" ? options.playOriginal ? 1 : 0 : void 0,
2622
2614
  subtitle_languages: joinCsv(options.subtitleLanguages)
2623
2615
  });
2624
- const buildFileXspfPlaylistUrl = (baseUrl, fileId, options = {}) => buildPutioUrl(baseUrl, `/v2/files/${encodePathSegment(fileId)}/xspf`, { oauth_token: options.oauthToken });
2616
+ const buildFileXspfPlaylistUrl = (baseUrl, fileId, options) => buildPutioUrl(baseUrl, `/v2/files/${encodePathSegment(fileId)}/xspf`, { oauth_token: options.downloadToken });
2625
2617
  const createFileUploadFormData = (input) => {
2626
2618
  const formData = new FormData();
2627
2619
  formData.append("file", input.file);
@@ -2836,46 +2828,34 @@ const getDownloadUrl = (fileId) => decodeAndRun(PositiveFileIdSchema, fileId, (d
2836
2828
  method: "GET",
2837
2829
  path: `/v2/files/${encodePathSegment(decodedFileId)}/url`
2838
2830
  })).pipe(selectJsonField("url"), withOperationErrors(DownloadUrlErrorSpec));
2839
- const getApiDownloadUrl = (fileId, options = {}) => decodeAndRun(Schema.Struct({
2831
+ const getApiDownloadUrl = (fileId, options) => decodeAndRun(Schema.Struct({
2840
2832
  fileId: PositiveFileIdSchema,
2841
2833
  options: FileApiDownloadUrlOptionsSchema
2842
2834
  }), {
2843
2835
  fileId,
2844
2836
  options
2845
- }, (decoded) => resolveRouteContext(decoded.options.oauthToken).pipe(Effect.map(({ config, oauthToken }) => buildFileApiDownloadUrl(config.baseUrl ?? "https://api.put.io", decoded.fileId, {
2846
- ...decoded.options,
2847
- oauthToken
2848
- }))));
2849
- const getApiContentUrl = (fileId, options = {}) => decodeAndRun(Schema.Struct({
2837
+ }, (decoded) => resolveApiBaseUrl.pipe(Effect.map((baseUrl) => buildFileApiDownloadUrl(baseUrl, decoded.fileId, decoded.options))));
2838
+ const getApiContentUrl = (fileId, options) => decodeAndRun(Schema.Struct({
2850
2839
  fileId: PositiveFileIdSchema,
2851
2840
  options: FileDirectAccessOptionsSchema
2852
2841
  }), {
2853
2842
  fileId,
2854
2843
  options
2855
- }, (decoded) => resolveRouteContext(decoded.options.oauthToken).pipe(Effect.map(({ config, oauthToken }) => buildFileApiContentUrl(config.baseUrl ?? "https://api.put.io", decoded.fileId, {
2856
- ...decoded.options,
2857
- oauthToken
2858
- }))));
2859
- const getApiMp4DownloadUrl = (fileId, options = {}) => decodeAndRun(Schema.Struct({
2844
+ }, (decoded) => resolveApiBaseUrl.pipe(Effect.map((baseUrl) => buildFileApiContentUrl(baseUrl, decoded.fileId, decoded.options))));
2845
+ const getApiMp4DownloadUrl = (fileId, options) => decodeAndRun(Schema.Struct({
2860
2846
  fileId: PositiveFileIdSchema,
2861
2847
  options: FileApiMp4DownloadUrlOptionsSchema
2862
2848
  }), {
2863
2849
  fileId,
2864
2850
  options
2865
- }, (decoded) => resolveRouteContext(decoded.options.oauthToken).pipe(Effect.map(({ config, oauthToken }) => buildFileApiMp4DownloadUrl(config.baseUrl ?? "https://api.put.io", decoded.fileId, {
2866
- ...decoded.options,
2867
- oauthToken
2868
- }))));
2869
- const getHlsStreamUrl = (fileId, options = {}) => decodeAndRun(Schema.Struct({
2851
+ }, (decoded) => resolveApiBaseUrl.pipe(Effect.map((baseUrl) => buildFileApiMp4DownloadUrl(baseUrl, decoded.fileId, decoded.options))));
2852
+ const getHlsStreamUrl = (fileId, options) => decodeAndRun(Schema.Struct({
2870
2853
  fileId: PositiveFileIdSchema,
2871
2854
  options: FileHlsStreamUrlOptionsSchema
2872
2855
  }), {
2873
2856
  fileId,
2874
2857
  options
2875
- }, (decoded) => resolveRouteContext(decoded.options.oauthToken).pipe(Effect.map(({ config, oauthToken }) => buildFileHlsStreamUrl(config.baseUrl ?? "https://api.put.io", decoded.fileId, {
2876
- ...decoded.options,
2877
- oauthToken
2878
- }))));
2858
+ }, (decoded) => resolveApiBaseUrl.pipe(Effect.map((baseUrl) => buildFileHlsStreamUrl(baseUrl, decoded.fileId, decoded.options))));
2879
2859
  /**
2880
2860
  * Fetches the HLS master playlist the player would load, so callers can
2881
2861
  * inspect the served variant's CODECS, VIDEO-RANGE, and rendition set without
@@ -2898,13 +2878,13 @@ const getHlsMasterPlaylist = (fileId, options = {}) => decodeAndRun(Schema.Struc
2898
2878
  subtitle_languages: joinCsv(decoded.options.subtitleLanguages)
2899
2879
  }
2900
2880
  })).pipe(withOperationErrors(GetHlsMasterPlaylistErrorSpec));
2901
- const getXspfPlaylistUrl = (fileId, options = {}) => decodeAndRun(Schema.Struct({
2881
+ const getXspfPlaylistUrl = (fileId, options) => decodeAndRun(Schema.Struct({
2902
2882
  fileId: PositiveFileIdSchema,
2903
2883
  options: FileXspfPlaylistUrlOptionsSchema
2904
2884
  }), {
2905
2885
  fileId,
2906
2886
  options
2907
- }, (decoded) => resolveRouteContext(decoded.options.oauthToken).pipe(Effect.map(({ config, oauthToken }) => buildFileXspfPlaylistUrl(config.baseUrl ?? "https://api.put.io", decoded.fileId, { oauthToken }))));
2887
+ }, (decoded) => resolveApiBaseUrl.pipe(Effect.map((baseUrl) => buildFileXspfPlaylistUrl(baseUrl, decoded.fileId, decoded.options))));
2908
2888
  const listFileSubtitles = (fileId, options = {}) => decodeAndRun(FileSubtitlesInputSchema, {
2909
2889
  fileId,
2910
2890
  options
@@ -3009,10 +2989,10 @@ const createFileUploadRequest = (input, options = {}) => decodeAndRun(Schema.Str
3009
2989
  }), {
3010
2990
  input,
3011
2991
  options
3012
- }, (decoded) => resolveRouteContext(decoded.options.oauthToken).pipe(Effect.map(({ config, oauthToken }) => ({
2992
+ }, (decoded) => resolveRouteContext(decoded.options.oauthToken).pipe(Effect.map(({ config, token }) => ({
3013
2993
  body: createFileUploadFormData(decoded.input),
3014
2994
  method: "POST",
3015
- url: buildPutioUrl(config.uploadBaseUrl ?? "https://upload.put.io", "/v2/files/upload", { oauth_token: oauthToken })
2995
+ url: buildPutioUrl(config.uploadBaseUrl ?? "https://upload.put.io", "/v2/files/upload", { oauth_token: token })
3016
2996
  }))));
3017
2997
  const uploadFile = (input, options = {}) => decodeAndRun(Schema.Struct({
3018
2998
  input: FileUploadInputSchema,
@@ -3020,7 +3000,7 @@ const uploadFile = (input, options = {}) => decodeAndRun(Schema.Struct({
3020
3000
  }), {
3021
3001
  input,
3022
3002
  options
3023
- }, (decoded) => resolveRouteContext(decoded.options.oauthToken).pipe(Effect.flatMap(({ config, oauthToken }) => requestJson(FileUploadEnvelopeSchema, {
3003
+ }, (decoded) => resolveRouteContext(decoded.options.oauthToken).pipe(Effect.flatMap(({ config, token }) => requestJson(FileUploadEnvelopeSchema, {
3024
3004
  auth: { type: "none" },
3025
3005
  baseUrl: config.uploadBaseUrl ?? "https://upload.put.io",
3026
3006
  body: {
@@ -3029,7 +3009,7 @@ const uploadFile = (input, options = {}) => decodeAndRun(Schema.Struct({
3029
3009
  },
3030
3010
  method: "POST",
3031
3011
  path: "/v2/files/upload",
3032
- query: { oauth_token: oauthToken }
3012
+ query: { oauth_token: token }
3033
3013
  })))).pipe(Effect.map(toUploadResult), withOperationErrors(FileUploadErrorSpec));
3034
3014
  //#endregion
3035
3015
  //#region src/domains/friend-invites.ts