upthing-sdk 1.0.0 → 1.0.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.d.ts CHANGED
@@ -34,13 +34,13 @@ export declare class UpThingSDKError extends Error {
34
34
  constructor(status: number, body: UpThingError);
35
35
  }
36
36
  export interface UpThingClientOptions {
37
- apiKey: string;
37
+ apiKey?: string;
38
38
  baseUrl?: string;
39
39
  }
40
40
  export declare class UpThingClient {
41
41
  private readonly apiKey;
42
42
  private readonly baseUrl;
43
- constructor(options: UpThingClientOptions);
43
+ constructor(options?: UpThingClientOptions);
44
44
  /**
45
45
  * Upload a file from a local path (Node.js only).
46
46
  */
@@ -66,12 +66,14 @@ export declare class UpThingClient {
66
66
  /**
67
67
  * Fetch a proxied image and return the raw Response.
68
68
  * Sends the API key via header (never exposed in the URL).
69
+ * Requires an API key — use proxyUrl() for domain-auth-only requests.
69
70
  */
70
71
  proxyFetch(url: string, options?: ProxyOptions): Promise<Response>;
71
72
  /**
72
73
  * Build a permanent delivery URL for a public_id.
73
74
  */
74
75
  permanentUrl(publicId: string): string;
76
+ private requireKey;
75
77
  private request;
76
78
  }
77
79
  export default UpThingClient;
package/dist/index.js CHANGED
@@ -11,8 +11,8 @@ export class UpThingSDKError extends Error {
11
11
  export class UpThingClient {
12
12
  apiKey;
13
13
  baseUrl;
14
- constructor(options) {
15
- this.apiKey = options.apiKey;
14
+ constructor(options = {}) {
15
+ this.apiKey = options.apiKey ?? "";
16
16
  this.baseUrl = (options.baseUrl ?? "https://upthing.2klabs.xyz").replace(/\/$/, "");
17
17
  }
18
18
  // ── Upload ──────────────────────────────────────────────────────────
@@ -79,8 +79,10 @@ export class UpThingClient {
79
79
  /**
80
80
  * Fetch a proxied image and return the raw Response.
81
81
  * Sends the API key via header (never exposed in the URL).
82
+ * Requires an API key — use proxyUrl() for domain-auth-only requests.
82
83
  */
83
84
  async proxyFetch(url, options) {
85
+ this.requireKey("proxyFetch");
84
86
  const target = this.proxyUrl(url, options);
85
87
  const res = await fetch(target, {
86
88
  headers: { "X-API-Key": this.apiKey },
@@ -99,7 +101,14 @@ export class UpThingClient {
99
101
  return `${this.baseUrl}/f/${publicId}`;
100
102
  }
101
103
  // ── Internal ────────────────────────────────────────────────────────
104
+ requireKey(method) {
105
+ if (!this.apiKey) {
106
+ throw new Error(`UpThingClient.${method}() requires an apiKey. ` +
107
+ `Pass one via new UpThingClient({ apiKey: "ak_..." }).`);
108
+ }
109
+ }
102
110
  async request(method, path, body) {
111
+ this.requireKey("request");
103
112
  const headers = {
104
113
  "X-API-Key": this.apiKey,
105
114
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "upthing-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "TypeScript SDK for upthing.2klabs.xyz — upload files, proxy images",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",