@fotovid/sdk 0.1.0 → 0.1.1

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.cjs CHANGED
@@ -81,6 +81,10 @@ var Fotovid = class {
81
81
  headers: {
82
82
  "content-type": "application/json",
83
83
  authorization: `Bearer ${this.#apiKey}`,
84
+ // An explicit UA identifies the SDK to the edge and to server-side
85
+ // observability. (The Python SDK's default urllib UA was blocked by
86
+ // Cloudflare with a 403 — Node's fetch UA is not, but be explicit.)
87
+ "user-agent": `fotovid-sdk/${"0.1.1"}`,
84
88
  // Billed endpoints require an idempotency key; default to a fresh
85
89
  // UUID per call, overridable to make a retry replay (not re-charge).
86
90
  "idempotency-key": options?.idempotencyKey ?? globalThis.crypto.randomUUID()
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/error.ts","../src/client.ts"],"sourcesContent":["export { Fotovid, Fotovid as default } from \"./client.js\";\nexport { FotovidError } from \"./error.js\";\nexport type {\n\tExtractAudioInput,\n\tFotovidOptions,\n\tImageFormat,\n\tImageWatermarkInput,\n\tMediaResult,\n\tProbeInput,\n\tProbeResult,\n\tRequestOptions,\n\tThumbnailInput,\n\tTrimAudioInput,\n\tTrimInput,\n\tVideoWatermarkInput,\n\tWatermarkPosition,\n\tWatermarkType,\n\tX264Preset,\n} from \"./types.js\";\n","function isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\n/** Thrown when the Fotovid API returns a non-2xx response. */\nexport class FotovidError extends Error {\n\t/** HTTP status code of the failed response. */\n\treadonly status: number;\n\t/** Parsed error body, when the response carried one. */\n\treadonly detail: unknown;\n\t/** Seconds to wait before retrying, from the `Retry-After` header (e.g. 429/503). */\n\treadonly retryAfter?: number;\n\n\tconstructor(status: number, detail: unknown, retryAfter?: number) {\n\t\tlet message: string | undefined;\n\t\tif (isRecord(detail)) {\n\t\t\tif (typeof detail.detail === \"string\") {\n\t\t\t\tmessage = detail.detail;\n\t\t\t} else if (typeof detail.message === \"string\") {\n\t\t\t\tmessage = detail.message;\n\t\t\t}\n\t\t}\n\t\tsuper(message ?? `Fotovid API request failed with status ${status}`);\n\t\tthis.name = \"FotovidError\";\n\t\tthis.status = status;\n\t\tthis.detail = detail;\n\t\tthis.retryAfter = retryAfter;\n\t}\n}\n","import { FotovidError } from \"./error.js\";\nimport type {\n\tExtractAudioInput,\n\tFotovidOptions,\n\tImageWatermarkInput,\n\tMediaResult,\n\tProbeInput,\n\tProbeResult,\n\tRequestOptions,\n\tThumbnailInput,\n\tTrimAudioInput,\n\tTrimInput,\n\tVideoWatermarkInput,\n} from \"./types.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.fotovid.co\";\n\nfunction resolveApiKey(explicit: string | undefined): string {\n\tconst key =\n\t\texplicit ??\n\t\t(typeof process !== \"undefined\" ? process.env?.FOTOVID_API_KEY : undefined);\n\tif (!key) {\n\t\tthrow new Error(\n\t\t\t\"Fotovid: missing API key. Pass { apiKey } or set FOTOVID_API_KEY.\",\n\t\t);\n\t}\n\treturn key;\n}\n\n/**\n * Typed client for the Fotovid media API. Methods mirror the REST resources\n * (`client.video.*`, `client.image.*`, `client.audio.*`); parameter names\n * match the API 1:1 (`source_url`, `watermark_image_url`, …).\n */\nexport class Fotovid {\n\treadonly #apiKey: string;\n\treadonly #baseUrl: string;\n\treadonly #fetch: typeof globalThis.fetch;\n\n\tconstructor(options: FotovidOptions = {}) {\n\t\tthis.#apiKey = resolveApiKey(options.apiKey);\n\t\tthis.#baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;\n\t\tthis.#fetch = options.fetch ?? globalThis.fetch;\n\t}\n\n\tasync #post<T>(\n\t\tpath: string,\n\t\tinput: { source_url: string },\n\t\toptions?: RequestOptions,\n\t): Promise<T> {\n\t\tconst { source_url, ...params } = input;\n\t\tconst response = await this.#fetch(new URL(path, this.#baseUrl), {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\tauthorization: `Bearer ${this.#apiKey}`,\n\t\t\t\t// Billed endpoints require an idempotency key; default to a fresh\n\t\t\t\t// UUID per call, overridable to make a retry replay (not re-charge).\n\t\t\t\t\"idempotency-key\":\n\t\t\t\t\toptions?.idempotencyKey ?? globalThis.crypto.randomUUID(),\n\t\t\t},\n\t\t\tbody: JSON.stringify({ source_url, params }),\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tlet detail: unknown;\n\t\t\ttry {\n\t\t\t\tdetail = await response.json();\n\t\t\t} catch {\n\t\t\t\t// non-JSON error body — leave detail undefined\n\t\t\t}\n\t\t\tconst ra = response.headers.get(\"retry-after\");\n\t\t\tconst retryAfter = ra ? Number(ra) : undefined;\n\t\t\tthrow new FotovidError(response.status, detail, retryAfter);\n\t\t}\n\t\treturn (await response.json()) as T;\n\t}\n\n\treadonly video = {\n\t\twatermark: (\n\t\t\tinput: VideoWatermarkInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/watermark\", input, options),\n\t\ttrim: (input: TrimInput, options?: RequestOptions): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/trim\", input, options),\n\t\textractAudio: (\n\t\t\tinput: ExtractAudioInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/extract-audio\", input, options),\n\t\tthumbnail: (\n\t\t\tinput: ThumbnailInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/extract-cover\", input, options),\n\t\tprobe: (\n\t\t\tinput: ProbeInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<ProbeResult> =>\n\t\t\tthis.#post<ProbeResult>(\"/v1/video/probe\", input, options),\n\t};\n\n\treadonly image = {\n\t\twatermark: (\n\t\t\tinput: ImageWatermarkInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/image/watermark\", input, options),\n\t};\n\n\treadonly audio = {\n\t\ttrim: (\n\t\t\tinput: TrimAudioInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/audio/trim\", input, options),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,SAAS,SAAS,OAAkD;AACnE,SAAO,OAAO,UAAU,YAAY,UAAU;AAC/C;AAGO,IAAM,eAAN,cAA2B,MAAM;AAAA;AAAA,EAE9B;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA,EAET,YAAY,QAAgB,QAAiB,YAAqB;AACjE,QAAI;AACJ,QAAI,SAAS,MAAM,GAAG;AACrB,UAAI,OAAO,OAAO,WAAW,UAAU;AACtC,kBAAU,OAAO;AAAA,MAClB,WAAW,OAAO,OAAO,YAAY,UAAU;AAC9C,kBAAU,OAAO;AAAA,MAClB;AAAA,IACD;AACA,UAAM,WAAW,0CAA0C,MAAM,EAAE;AACnE,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,SAAS;AACd,SAAK,aAAa;AAAA,EACnB;AACD;;;ACbA,IAAM,mBAAmB;AAEzB,SAAS,cAAc,UAAsC;AAC5D,QAAM,MACL,aACC,OAAO,YAAY,cAAc,QAAQ,KAAK,kBAAkB;AAClE,MAAI,CAAC,KAAK;AACT,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;AAOO,IAAM,UAAN,MAAc;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,UAA0B,CAAC,GAAG;AACzC,SAAK,UAAU,cAAc,QAAQ,MAAM;AAC3C,SAAK,WAAW,QAAQ,WAAW;AACnC,SAAK,SAAS,QAAQ,SAAS,WA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,YAEA,KAAK,MAAmB,kBAAkB,OAAO,OAAO;AAAA,EAC1D;AACD;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/error.ts","../src/client.ts"],"sourcesContent":["export { Fotovid, Fotovid as default } from \"./client.js\";\nexport { FotovidError } from \"./error.js\";\nexport type {\n\tExtractAudioInput,\n\tFotovidOptions,\n\tImageFormat,\n\tImageWatermarkInput,\n\tMediaResult,\n\tProbeInput,\n\tProbeResult,\n\tRequestOptions,\n\tThumbnailInput,\n\tTrimAudioInput,\n\tTrimInput,\n\tVideoWatermarkInput,\n\tWatermarkPosition,\n\tWatermarkType,\n\tX264Preset,\n} from \"./types.js\";\n","function isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\n/** Thrown when the Fotovid API returns a non-2xx response. */\nexport class FotovidError extends Error {\n\t/** HTTP status code of the failed response. */\n\treadonly status: number;\n\t/** Parsed error body, when the response carried one. */\n\treadonly detail: unknown;\n\t/** Seconds to wait before retrying, from the `Retry-After` header (e.g. 429/503). */\n\treadonly retryAfter?: number;\n\n\tconstructor(status: number, detail: unknown, retryAfter?: number) {\n\t\tlet message: string | undefined;\n\t\tif (isRecord(detail)) {\n\t\t\tif (typeof detail.detail === \"string\") {\n\t\t\t\tmessage = detail.detail;\n\t\t\t} else if (typeof detail.message === \"string\") {\n\t\t\t\tmessage = detail.message;\n\t\t\t}\n\t\t}\n\t\tsuper(message ?? `Fotovid API request failed with status ${status}`);\n\t\tthis.name = \"FotovidError\";\n\t\tthis.status = status;\n\t\tthis.detail = detail;\n\t\tthis.retryAfter = retryAfter;\n\t}\n}\n","import { FotovidError } from \"./error.js\";\nimport type {\n\tExtractAudioInput,\n\tFotovidOptions,\n\tImageWatermarkInput,\n\tMediaResult,\n\tProbeInput,\n\tProbeResult,\n\tRequestOptions,\n\tThumbnailInput,\n\tTrimAudioInput,\n\tTrimInput,\n\tVideoWatermarkInput,\n} from \"./types.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.fotovid.co\";\n\n// Injected at build time from package.json by tsup (see tsup.config.ts).\ndeclare const __SDK_VERSION__: string;\n\nfunction resolveApiKey(explicit: string | undefined): string {\n\tconst key =\n\t\texplicit ??\n\t\t(typeof process !== \"undefined\" ? process.env?.FOTOVID_API_KEY : undefined);\n\tif (!key) {\n\t\tthrow new Error(\n\t\t\t\"Fotovid: missing API key. Pass { apiKey } or set FOTOVID_API_KEY.\",\n\t\t);\n\t}\n\treturn key;\n}\n\n/**\n * Typed client for the Fotovid media API. Methods mirror the REST resources\n * (`client.video.*`, `client.image.*`, `client.audio.*`); parameter names\n * match the API 1:1 (`source_url`, `watermark_image_url`, …).\n */\nexport class Fotovid {\n\treadonly #apiKey: string;\n\treadonly #baseUrl: string;\n\treadonly #fetch: typeof globalThis.fetch;\n\n\tconstructor(options: FotovidOptions = {}) {\n\t\tthis.#apiKey = resolveApiKey(options.apiKey);\n\t\tthis.#baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;\n\t\tthis.#fetch = options.fetch ?? globalThis.fetch;\n\t}\n\n\tasync #post<T>(\n\t\tpath: string,\n\t\tinput: { source_url: string },\n\t\toptions?: RequestOptions,\n\t): Promise<T> {\n\t\tconst { source_url, ...params } = input;\n\t\tconst response = await this.#fetch(new URL(path, this.#baseUrl), {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\tauthorization: `Bearer ${this.#apiKey}`,\n\t\t\t\t// An explicit UA identifies the SDK to the edge and to server-side\n\t\t\t\t// observability. (The Python SDK's default urllib UA was blocked by\n\t\t\t\t// Cloudflare with a 403 — Node's fetch UA is not, but be explicit.)\n\t\t\t\t\"user-agent\": `fotovid-sdk/${__SDK_VERSION__}`,\n\t\t\t\t// Billed endpoints require an idempotency key; default to a fresh\n\t\t\t\t// UUID per call, overridable to make a retry replay (not re-charge).\n\t\t\t\t\"idempotency-key\":\n\t\t\t\t\toptions?.idempotencyKey ?? globalThis.crypto.randomUUID(),\n\t\t\t},\n\t\t\tbody: JSON.stringify({ source_url, params }),\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tlet detail: unknown;\n\t\t\ttry {\n\t\t\t\tdetail = await response.json();\n\t\t\t} catch {\n\t\t\t\t// non-JSON error body — leave detail undefined\n\t\t\t}\n\t\t\tconst ra = response.headers.get(\"retry-after\");\n\t\t\tconst retryAfter = ra ? Number(ra) : undefined;\n\t\t\tthrow new FotovidError(response.status, detail, retryAfter);\n\t\t}\n\t\treturn (await response.json()) as T;\n\t}\n\n\treadonly video = {\n\t\twatermark: (\n\t\t\tinput: VideoWatermarkInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/watermark\", input, options),\n\t\ttrim: (input: TrimInput, options?: RequestOptions): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/trim\", input, options),\n\t\textractAudio: (\n\t\t\tinput: ExtractAudioInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/extract-audio\", input, options),\n\t\tthumbnail: (\n\t\t\tinput: ThumbnailInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/extract-cover\", input, options),\n\t\tprobe: (\n\t\t\tinput: ProbeInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<ProbeResult> =>\n\t\t\tthis.#post<ProbeResult>(\"/v1/video/probe\", input, options),\n\t};\n\n\treadonly image = {\n\t\twatermark: (\n\t\t\tinput: ImageWatermarkInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/image/watermark\", input, options),\n\t};\n\n\treadonly audio = {\n\t\ttrim: (\n\t\t\tinput: TrimAudioInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n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S;AAAA,QACR,gBAAgB;AAAA,QAChB,eAAe,UAAU,KAAK,OAAO;AAAA;AAAA;AAAA;AAAA,QAIrC,cAAc,eAAe,OAAe;AAAA;AAAA;AAAA,QAG5C,mBACC,SAAS,kBAAkB,WAAW,OAAO,WAAW;AAAA,MAC1D;AAAA,MACA,MAAM,KAAK,UAAU,EAAE,YAAY,OAAO,CAAC;AAAA,IAC5C,CAAC;AACD,QAAI,CAAC,SAAS,IAAI;AACjB,UAAI;AACJ,UAAI;AACH,iBAAS,MAAM,SAAS,KAAK;AAAA,MAC9B,QAAQ;AAAA,MAER;AACA,YAAM,KAAK,SAAS,QAAQ,IAAI,aAAa;AAC7C,YAAM,aAAa,KAAK,OAAO,EAAE,IAAI;AACrC,YAAM,IAAI,aAAa,SAAS,QAAQ,QAAQ,UAAU;AAAA,IAC3D;AACA,WAAQ,MAAM,SAAS,KAAK;AAAA,EAC7B;AAAA,EAES,QAAQ;AAAA,IAChB,WAAW,CACV,OACA,YAEA,KAAK,MAAmB,uBAAuB,OAAO,OAAO;AAAA,IAC9D,MAAM,CAAC,OAAkB,YACxB,KAAK,MAAmB,kBAAkB,OAAO,OAAO;AAAA,IACzD,cAAc,CACb,OACA,YAEA,KAAK,MAAmB,2BAA2B,OAAO,OAAO;AAAA,IAClE,WAAW,CACV,OACA,YAEA,KAAK,MAAmB,2BAA2B,OAAO,OAAO;AAAA,IAClE,OAAO,CACN,OACA,YAEA,KAAK,MAAmB,mBAAmB,OAAO,OAAO;AAAA,EAC3D;AAAA,EAES,QAAQ;AAAA,IAChB,WAAW,CACV,OACA,YAEA,KAAK,MAAmB,uBAAuB,OAAO,OAAO;AAAA,EAC/D;AAAA,EAES,QAAQ;AAAA,IAChB,MAAM,CACL,OACA,YAEA,KAAK,MAAmB,kBAAkB,OAAO,OAAO;AAAA,EAC1D;AACD;","names":[]}
package/dist/index.js CHANGED
@@ -53,6 +53,10 @@ var Fotovid = class {
53
53
  headers: {
54
54
  "content-type": "application/json",
55
55
  authorization: `Bearer ${this.#apiKey}`,
56
+ // An explicit UA identifies the SDK to the edge and to server-side
57
+ // observability. (The Python SDK's default urllib UA was blocked by
58
+ // Cloudflare with a 403 — Node's fetch UA is not, but be explicit.)
59
+ "user-agent": `fotovid-sdk/${"0.1.1"}`,
56
60
  // Billed endpoints require an idempotency key; default to a fresh
57
61
  // UUID per call, overridable to make a retry replay (not re-charge).
58
62
  "idempotency-key": options?.idempotencyKey ?? globalThis.crypto.randomUUID()
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/error.ts","../src/client.ts"],"sourcesContent":["function isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\n/** Thrown when the Fotovid API returns a non-2xx response. */\nexport class FotovidError extends Error {\n\t/** HTTP status code of the failed response. */\n\treadonly status: number;\n\t/** Parsed error body, when the response carried one. */\n\treadonly detail: unknown;\n\t/** Seconds to wait before retrying, from the `Retry-After` header (e.g. 429/503). */\n\treadonly retryAfter?: number;\n\n\tconstructor(status: number, detail: unknown, retryAfter?: number) {\n\t\tlet message: string | undefined;\n\t\tif (isRecord(detail)) {\n\t\t\tif (typeof detail.detail === \"string\") {\n\t\t\t\tmessage = detail.detail;\n\t\t\t} else if (typeof detail.message === \"string\") {\n\t\t\t\tmessage = detail.message;\n\t\t\t}\n\t\t}\n\t\tsuper(message ?? `Fotovid API request failed with status ${status}`);\n\t\tthis.name = \"FotovidError\";\n\t\tthis.status = status;\n\t\tthis.detail = detail;\n\t\tthis.retryAfter = retryAfter;\n\t}\n}\n","import { FotovidError } from \"./error.js\";\nimport type {\n\tExtractAudioInput,\n\tFotovidOptions,\n\tImageWatermarkInput,\n\tMediaResult,\n\tProbeInput,\n\tProbeResult,\n\tRequestOptions,\n\tThumbnailInput,\n\tTrimAudioInput,\n\tTrimInput,\n\tVideoWatermarkInput,\n} from \"./types.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.fotovid.co\";\n\nfunction resolveApiKey(explicit: string | undefined): string {\n\tconst key =\n\t\texplicit ??\n\t\t(typeof process !== \"undefined\" ? process.env?.FOTOVID_API_KEY : undefined);\n\tif (!key) {\n\t\tthrow new Error(\n\t\t\t\"Fotovid: missing API key. Pass { apiKey } or set FOTOVID_API_KEY.\",\n\t\t);\n\t}\n\treturn key;\n}\n\n/**\n * Typed client for the Fotovid media API. Methods mirror the REST resources\n * (`client.video.*`, `client.image.*`, `client.audio.*`); parameter names\n * match the API 1:1 (`source_url`, `watermark_image_url`, …).\n */\nexport class Fotovid {\n\treadonly #apiKey: string;\n\treadonly #baseUrl: string;\n\treadonly #fetch: typeof globalThis.fetch;\n\n\tconstructor(options: FotovidOptions = {}) {\n\t\tthis.#apiKey = resolveApiKey(options.apiKey);\n\t\tthis.#baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;\n\t\tthis.#fetch = options.fetch ?? globalThis.fetch;\n\t}\n\n\tasync #post<T>(\n\t\tpath: string,\n\t\tinput: { source_url: string },\n\t\toptions?: RequestOptions,\n\t): Promise<T> {\n\t\tconst { source_url, ...params } = input;\n\t\tconst response = await this.#fetch(new URL(path, this.#baseUrl), {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\tauthorization: `Bearer ${this.#apiKey}`,\n\t\t\t\t// Billed endpoints require an idempotency key; default to a fresh\n\t\t\t\t// UUID per call, overridable to make a retry replay (not re-charge).\n\t\t\t\t\"idempotency-key\":\n\t\t\t\t\toptions?.idempotencyKey ?? globalThis.crypto.randomUUID(),\n\t\t\t},\n\t\t\tbody: JSON.stringify({ source_url, params }),\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tlet detail: unknown;\n\t\t\ttry {\n\t\t\t\tdetail = await response.json();\n\t\t\t} catch {\n\t\t\t\t// non-JSON error body — leave detail undefined\n\t\t\t}\n\t\t\tconst ra = response.headers.get(\"retry-after\");\n\t\t\tconst retryAfter = ra ? Number(ra) : undefined;\n\t\t\tthrow new FotovidError(response.status, detail, retryAfter);\n\t\t}\n\t\treturn (await response.json()) as T;\n\t}\n\n\treadonly video = {\n\t\twatermark: (\n\t\t\tinput: VideoWatermarkInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/watermark\", input, options),\n\t\ttrim: (input: TrimInput, options?: RequestOptions): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/trim\", input, options),\n\t\textractAudio: (\n\t\t\tinput: ExtractAudioInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/extract-audio\", input, options),\n\t\tthumbnail: (\n\t\t\tinput: ThumbnailInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/extract-cover\", input, options),\n\t\tprobe: (\n\t\t\tinput: ProbeInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<ProbeResult> =>\n\t\t\tthis.#post<ProbeResult>(\"/v1/video/probe\", input, options),\n\t};\n\n\treadonly image = {\n\t\twatermark: (\n\t\t\tinput: ImageWatermarkInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/image/watermark\", input, options),\n\t};\n\n\treadonly audio = {\n\t\ttrim: (\n\t\t\tinput: TrimAudioInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/audio/trim\", input, options),\n\t};\n}\n"],"mappings":";AAAA,SAAS,SAAS,OAAkD;AACnE,SAAO,OAAO,UAAU,YAAY,UAAU;AAC/C;AAGO,IAAM,eAAN,cAA2B,MAAM;AAAA;AAAA,EAE9B;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA,EAET,YAAY,QAAgB,QAAiB,YAAqB;AACjE,QAAI;AACJ,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QAAQ,IAAI,aAAa;AAC7C,YAAM,aAAa,KAAK,OAAO,EAAE,IAAI;AACrC,YAAM,IAAI,aAAa,SAAS,QAAQ,QAAQ,UAAU;AAAA,IAC3D;AACA,WAAQ,MAAM,SAAS,KAAK;AAAA,EAC7B;AAAA,EAES,QAAQ;AAAA,IAChB,WAAW,CACV,OACA,YAEA,KAAK,MAAmB,uBAAuB,OAAO,OAAO;AAAA,IAC9D,MAAM,CAAC,OAAkB,YACxB,KAAK,MAAmB,kBAAkB,OAAO,OAAO;AAAA,IACzD,cAAc,CACb,OACA,YAEA,KAAK,MAAmB,2BAA2B,OAAO,OAAO;AAAA,IAClE,WAAW,CACV,OACA,YAEA,KAAK,MAAmB,2BAA2B,OAAO,OAAO;AAAA,IAClE,OAAO,CACN,OACA,YAEA,KAAK,MAAmB,mBAAmB,OAAO,OAAO;AAAA,EAC3D;AAAA,EAES,QAAQ;AAAA,IAChB,WAAW,CACV,OACA,YAEA,KAAK,MAAmB,uBAAuB,OAAO,OAAO;AAAA,EAC/D;AAAA,EAES,QAAQ;AAAA,IAChB,MAAM,CACL,OACA,YAEA,KAAK,MAAmB,kBAAkB,OAAO,OAAO;AAAA,EAC1D;AACD;","names":[]}
1
+ {"version":3,"sources":["../src/error.ts","../src/client.ts"],"sourcesContent":["function isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\n/** Thrown when the Fotovid API returns a non-2xx response. */\nexport class FotovidError extends Error {\n\t/** HTTP status code of the failed response. */\n\treadonly status: number;\n\t/** Parsed error body, when the response carried one. */\n\treadonly detail: unknown;\n\t/** Seconds to wait before retrying, from the `Retry-After` header (e.g. 429/503). */\n\treadonly retryAfter?: number;\n\n\tconstructor(status: number, detail: unknown, retryAfter?: number) {\n\t\tlet message: string | undefined;\n\t\tif (isRecord(detail)) {\n\t\t\tif (typeof detail.detail === \"string\") {\n\t\t\t\tmessage = detail.detail;\n\t\t\t} else if (typeof detail.message === \"string\") {\n\t\t\t\tmessage = detail.message;\n\t\t\t}\n\t\t}\n\t\tsuper(message ?? `Fotovid API request failed with status ${status}`);\n\t\tthis.name = \"FotovidError\";\n\t\tthis.status = status;\n\t\tthis.detail = detail;\n\t\tthis.retryAfter = retryAfter;\n\t}\n}\n","import { FotovidError } from \"./error.js\";\nimport type {\n\tExtractAudioInput,\n\tFotovidOptions,\n\tImageWatermarkInput,\n\tMediaResult,\n\tProbeInput,\n\tProbeResult,\n\tRequestOptions,\n\tThumbnailInput,\n\tTrimAudioInput,\n\tTrimInput,\n\tVideoWatermarkInput,\n} from \"./types.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.fotovid.co\";\n\n// Injected at build time from package.json by tsup (see tsup.config.ts).\ndeclare const __SDK_VERSION__: string;\n\nfunction resolveApiKey(explicit: string | undefined): string {\n\tconst key =\n\t\texplicit ??\n\t\t(typeof process !== \"undefined\" ? process.env?.FOTOVID_API_KEY : undefined);\n\tif (!key) {\n\t\tthrow new Error(\n\t\t\t\"Fotovid: missing API key. Pass { apiKey } or set FOTOVID_API_KEY.\",\n\t\t);\n\t}\n\treturn key;\n}\n\n/**\n * Typed client for the Fotovid media API. Methods mirror the REST resources\n * (`client.video.*`, `client.image.*`, `client.audio.*`); parameter names\n * match the API 1:1 (`source_url`, `watermark_image_url`, …).\n */\nexport class Fotovid {\n\treadonly #apiKey: string;\n\treadonly #baseUrl: string;\n\treadonly #fetch: typeof globalThis.fetch;\n\n\tconstructor(options: FotovidOptions = {}) {\n\t\tthis.#apiKey = resolveApiKey(options.apiKey);\n\t\tthis.#baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;\n\t\tthis.#fetch = options.fetch ?? globalThis.fetch;\n\t}\n\n\tasync #post<T>(\n\t\tpath: string,\n\t\tinput: { source_url: string },\n\t\toptions?: RequestOptions,\n\t): Promise<T> {\n\t\tconst { source_url, ...params } = input;\n\t\tconst response = await this.#fetch(new URL(path, this.#baseUrl), {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\tauthorization: `Bearer ${this.#apiKey}`,\n\t\t\t\t// An explicit UA identifies the SDK to the edge and to server-side\n\t\t\t\t// observability. (The Python SDK's default urllib UA was blocked by\n\t\t\t\t// Cloudflare with a 403 — Node's fetch UA is not, but be explicit.)\n\t\t\t\t\"user-agent\": `fotovid-sdk/${__SDK_VERSION__}`,\n\t\t\t\t// Billed endpoints require an idempotency key; default to a fresh\n\t\t\t\t// UUID per call, overridable to make a retry replay (not re-charge).\n\t\t\t\t\"idempotency-key\":\n\t\t\t\t\toptions?.idempotencyKey ?? globalThis.crypto.randomUUID(),\n\t\t\t},\n\t\t\tbody: JSON.stringify({ source_url, params }),\n\t\t});\n\t\tif (!response.ok) {\n\t\t\tlet detail: unknown;\n\t\t\ttry {\n\t\t\t\tdetail = await response.json();\n\t\t\t} catch {\n\t\t\t\t// non-JSON error body — leave detail undefined\n\t\t\t}\n\t\t\tconst ra = response.headers.get(\"retry-after\");\n\t\t\tconst retryAfter = ra ? Number(ra) : undefined;\n\t\t\tthrow new FotovidError(response.status, detail, retryAfter);\n\t\t}\n\t\treturn (await response.json()) as T;\n\t}\n\n\treadonly video = {\n\t\twatermark: (\n\t\t\tinput: VideoWatermarkInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/watermark\", input, options),\n\t\ttrim: (input: TrimInput, options?: RequestOptions): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/trim\", input, options),\n\t\textractAudio: (\n\t\t\tinput: ExtractAudioInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/extract-audio\", input, options),\n\t\tthumbnail: (\n\t\t\tinput: ThumbnailInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/video/extract-cover\", input, options),\n\t\tprobe: (\n\t\t\tinput: ProbeInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<ProbeResult> =>\n\t\t\tthis.#post<ProbeResult>(\"/v1/video/probe\", input, options),\n\t};\n\n\treadonly image = {\n\t\twatermark: (\n\t\t\tinput: ImageWatermarkInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/image/watermark\", input, options),\n\t};\n\n\treadonly audio = {\n\t\ttrim: (\n\t\t\tinput: TrimAudioInput,\n\t\t\toptions?: RequestOptions,\n\t\t): Promise<MediaResult> =>\n\t\t\tthis.#post<MediaResult>(\"/v1/audio/trim\", input, options),\n\t};\n}\n"],"mappings":";AAAA,SAAS,SAAS,OAAkD;AACnE,SAAO,OAAO,UAAU,YAAY,UAAU;AAC/C;AAGO,IAAM,eAAN,cAA2B,MAAM;AAAA;AAAA,EAE9B;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA,EAET,YAAY,QAAgB,QAAiB,YAAqB;AACjE,QAAI;AACJ,QAAI,SAAS,MAAM,GAAG;AACrB,UAAI,OAAO,OAAO,WAAW,UAAU;AACtC,kBAAU,OAAO;AAAA,MAClB,WAAW,OAAO,OAAO,YAAY,UAAU;AAC9C,kBAAU,OAAO;AAAA,MAClB;AAAA,IACD;AACA,UAAM,WAAW,0CAA0C,MAAM,EAAE;AACnE,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,SAAS;AACd,SAAK,aAAa;AAAA,EACnB;AACD;;;ACbA,IAAM,mBAAmB;AAKzB,SAAS,cAAc,UAAsC;AAC5D,QAAM,MACL,aACC,OAAO,YAAY,cAAc,QAAQ,KAAK,kBAAkB;AAClE,MAAI,CAAC,KAAK;AACT,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;AAOO,IAAM,UAAN,MAAc;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,UAA0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AAO,OAAO;AAAA,EAC3D;AAAA,EAES,QAAQ;AAAA,IAChB,WAAW,CACV,OACA,YAEA,KAAK,MAAmB,uBAAuB,OAAO,OAAO;AAAA,EAC/D;AAAA,EAES,QAAQ;AAAA,IAChB,MAAM,CACL,OACA,YAEA,KAAK,MAAmB,kBAAkB,OAAO,OAAO;AAAA,EAC1D;AACD;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fotovid/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Typed TypeScript/Node client for the Fotovid media API",
5
5
  "license": "MIT",
6
6
  "type": "module",