@buildspacestudio/sdk 0.3.0 → 0.4.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.
Files changed (54) hide show
  1. package/README.md +126 -0
  2. package/dist/auth/index.cjs.map +1 -1
  3. package/dist/auth/index.d.cts +3 -118
  4. package/dist/auth/index.d.ts +3 -118
  5. package/dist/auth/index.js.map +1 -1
  6. package/dist/billing/index.cjs +226 -0
  7. package/dist/billing/index.cjs.map +1 -0
  8. package/dist/billing/index.d.cts +60 -0
  9. package/dist/billing/index.d.ts +60 -0
  10. package/dist/billing/index.js +222 -0
  11. package/dist/billing/index.js.map +1 -0
  12. package/dist/client/index.cjs +130 -0
  13. package/dist/client/index.cjs.map +1 -1
  14. package/dist/client/index.d.cts +7 -3
  15. package/dist/client/index.d.ts +7 -3
  16. package/dist/client/index.js +130 -0
  17. package/dist/client/index.js.map +1 -1
  18. package/dist/client-BYUWUiGZ.d.cts +143 -0
  19. package/dist/{client-BH7LbrKM.d.ts → client-ByNR5EZz.d.ts} +1 -1
  20. package/dist/{client-C67hy1kt.d.cts → client-D0vypxWb.d.cts} +1 -1
  21. package/dist/{client-DqWXAwCr.d.cts → client-D7bqvGJv.d.cts} +1 -1
  22. package/dist/{client-Dlif1JBf.d.ts → client-DbGRRMt7.d.ts} +1 -1
  23. package/dist/client-d7kX5WfR.d.ts +143 -0
  24. package/dist/events/index.d.cts +2 -2
  25. package/dist/events/index.d.ts +2 -2
  26. package/dist/{http-U-zzKmFF.d.cts → http-D2gXpNpr.d.cts} +2 -2
  27. package/dist/{http-U-zzKmFF.d.ts → http-D2gXpNpr.d.ts} +2 -2
  28. package/dist/index.cjs +228 -0
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +13 -8
  31. package/dist/index.d.ts +13 -8
  32. package/dist/index.js +226 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/next/index.cjs +183 -0
  35. package/dist/next/index.cjs.map +1 -0
  36. package/dist/next/index.d.cts +164 -0
  37. package/dist/next/index.d.ts +164 -0
  38. package/dist/next/index.js +172 -0
  39. package/dist/next/index.js.map +1 -0
  40. package/dist/notifications/index.d.cts +1 -1
  41. package/dist/notifications/index.d.ts +1 -1
  42. package/dist/react/index.cjs +120 -0
  43. package/dist/react/index.cjs.map +1 -0
  44. package/dist/react/index.d.cts +567 -0
  45. package/dist/react/index.d.ts +567 -0
  46. package/dist/react/index.js +92 -0
  47. package/dist/react/index.js.map +1 -0
  48. package/dist/server-CoPDzSUP.d.cts +117 -0
  49. package/dist/server-Suq3tZZC.d.ts +117 -0
  50. package/dist/storage/index.cjs.map +1 -1
  51. package/dist/storage/index.d.cts +1 -1
  52. package/dist/storage/index.d.ts +1 -1
  53. package/dist/storage/index.js.map +1 -1
  54. package/package.json +51 -2
@@ -0,0 +1,117 @@
1
+ import { H as HttpTransport } from './http-D2gXpNpr.cjs';
2
+
3
+ /** A Buildspace user returned from auth endpoints. */
4
+ interface AuthUser {
5
+ /** The user's email address. */
6
+ email: string;
7
+ /** Unique user identifier. */
8
+ id: string;
9
+ /** The user's display name, or `null` if not set. */
10
+ name: string | null;
11
+ }
12
+ /**
13
+ * An active session for an authenticated user.
14
+ *
15
+ * Returned by {@link AuthServerNamespace.getSession}.
16
+ */
17
+ interface AuthSession {
18
+ /** The app this session belongs to, or `null` for platform-level sessions. */
19
+ appId: string | null;
20
+ /** The authenticated user. */
21
+ user: AuthUser;
22
+ }
23
+ /**
24
+ * Token response returned after a successful OAuth callback exchange.
25
+ *
26
+ * Returned by {@link AuthServerNamespace.handleCallback}.
27
+ */
28
+ interface TokenResponse {
29
+ /** The access token to use for authenticated requests. */
30
+ access_token: string;
31
+ /** Token lifetime in seconds. */
32
+ expires_in: number;
33
+ /** Always `"bearer"`. */
34
+ token_type: "bearer";
35
+ /** The authenticated user. */
36
+ user: AuthUser;
37
+ }
38
+ /**
39
+ * Server-side authentication methods.
40
+ *
41
+ * Access via `buildspace.auth` on the server SDK.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import Buildspace from "@buildspacestudio/sdk";
46
+ *
47
+ * const buildspace = new Buildspace(process.env.BUILDSPACE_SECRET_KEY!);
48
+ *
49
+ * // Handle OAuth callback
50
+ * const tokens = await buildspace.auth.handleCallback(request);
51
+ *
52
+ * // Verify a session
53
+ * const session = await buildspace.auth.getSession(sessionToken);
54
+ *
55
+ * // Sign out
56
+ * await buildspace.auth.signOut(sessionToken);
57
+ * ```
58
+ */
59
+ declare class AuthServerNamespace {
60
+ private readonly transport;
61
+ constructor(transport: HttpTransport);
62
+ /**
63
+ * Retrieve the session associated with a token.
64
+ *
65
+ * Returns the {@link AuthSession} if valid, or `null` if the token is
66
+ * expired, revoked, or invalid (401/404).
67
+ *
68
+ * @throws {BuildspaceError} On unexpected server errors (5xx, network issues).
69
+ */
70
+ getSession(sessionToken: string): Promise<AuthSession | null>;
71
+ /**
72
+ * Exchange an OAuth authorization code for tokens.
73
+ *
74
+ * Extracts the `code` query parameter from the callback URL and exchanges
75
+ * it with the Buildspace API for an access token and user info.
76
+ *
77
+ * @param request - The incoming callback request. Accepts a `Request` object,
78
+ * a `URL`, or a raw URL string containing the `?code=` parameter.
79
+ * @param opts - Optional settings.
80
+ * @param opts.redirectUri - Override the redirect URI sent to the token endpoint.
81
+ * Defaults to the origin + pathname of the callback URL.
82
+ * @returns The token response containing `access_token`, `expires_in`, and `user`.
83
+ *
84
+ * @throws {BuildspaceError} If the code exchange fails (invalid code, expired, etc.).
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * // Next.js Route Handler
89
+ * export async function GET(request: Request) {
90
+ * const { access_token, user } = await buildspace.auth.handleCallback(request);
91
+ * // Store access_token as a session cookie
92
+ * }
93
+ * ```
94
+ */
95
+ handleCallback(request: Request | URL | string, opts?: {
96
+ redirectUri?: string;
97
+ }): Promise<TokenResponse>;
98
+ /**
99
+ * Revoke a specific session token.
100
+ *
101
+ * @param sessionToken - The token to revoke.
102
+ * @throws {BuildspaceError} If the revocation fails.
103
+ */
104
+ revokeSession(sessionToken: string): Promise<void>;
105
+ /**
106
+ * Sign the user out by revoking the session and clearing the SDK's stored token.
107
+ *
108
+ * If the session is already expired or not found, the error is silently
109
+ * ignored and the local session is still cleared.
110
+ *
111
+ * @param sessionToken - Token to revoke. If omitted, uses the token
112
+ * previously set via `buildspace.setSession()`.
113
+ */
114
+ signOut(sessionToken?: string): Promise<void>;
115
+ }
116
+
117
+ export { AuthServerNamespace as A, type TokenResponse as T, type AuthSession as a, type AuthUser as b };
@@ -0,0 +1,117 @@
1
+ import { H as HttpTransport } from './http-D2gXpNpr.js';
2
+
3
+ /** A Buildspace user returned from auth endpoints. */
4
+ interface AuthUser {
5
+ /** The user's email address. */
6
+ email: string;
7
+ /** Unique user identifier. */
8
+ id: string;
9
+ /** The user's display name, or `null` if not set. */
10
+ name: string | null;
11
+ }
12
+ /**
13
+ * An active session for an authenticated user.
14
+ *
15
+ * Returned by {@link AuthServerNamespace.getSession}.
16
+ */
17
+ interface AuthSession {
18
+ /** The app this session belongs to, or `null` for platform-level sessions. */
19
+ appId: string | null;
20
+ /** The authenticated user. */
21
+ user: AuthUser;
22
+ }
23
+ /**
24
+ * Token response returned after a successful OAuth callback exchange.
25
+ *
26
+ * Returned by {@link AuthServerNamespace.handleCallback}.
27
+ */
28
+ interface TokenResponse {
29
+ /** The access token to use for authenticated requests. */
30
+ access_token: string;
31
+ /** Token lifetime in seconds. */
32
+ expires_in: number;
33
+ /** Always `"bearer"`. */
34
+ token_type: "bearer";
35
+ /** The authenticated user. */
36
+ user: AuthUser;
37
+ }
38
+ /**
39
+ * Server-side authentication methods.
40
+ *
41
+ * Access via `buildspace.auth` on the server SDK.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import Buildspace from "@buildspacestudio/sdk";
46
+ *
47
+ * const buildspace = new Buildspace(process.env.BUILDSPACE_SECRET_KEY!);
48
+ *
49
+ * // Handle OAuth callback
50
+ * const tokens = await buildspace.auth.handleCallback(request);
51
+ *
52
+ * // Verify a session
53
+ * const session = await buildspace.auth.getSession(sessionToken);
54
+ *
55
+ * // Sign out
56
+ * await buildspace.auth.signOut(sessionToken);
57
+ * ```
58
+ */
59
+ declare class AuthServerNamespace {
60
+ private readonly transport;
61
+ constructor(transport: HttpTransport);
62
+ /**
63
+ * Retrieve the session associated with a token.
64
+ *
65
+ * Returns the {@link AuthSession} if valid, or `null` if the token is
66
+ * expired, revoked, or invalid (401/404).
67
+ *
68
+ * @throws {BuildspaceError} On unexpected server errors (5xx, network issues).
69
+ */
70
+ getSession(sessionToken: string): Promise<AuthSession | null>;
71
+ /**
72
+ * Exchange an OAuth authorization code for tokens.
73
+ *
74
+ * Extracts the `code` query parameter from the callback URL and exchanges
75
+ * it with the Buildspace API for an access token and user info.
76
+ *
77
+ * @param request - The incoming callback request. Accepts a `Request` object,
78
+ * a `URL`, or a raw URL string containing the `?code=` parameter.
79
+ * @param opts - Optional settings.
80
+ * @param opts.redirectUri - Override the redirect URI sent to the token endpoint.
81
+ * Defaults to the origin + pathname of the callback URL.
82
+ * @returns The token response containing `access_token`, `expires_in`, and `user`.
83
+ *
84
+ * @throws {BuildspaceError} If the code exchange fails (invalid code, expired, etc.).
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * // Next.js Route Handler
89
+ * export async function GET(request: Request) {
90
+ * const { access_token, user } = await buildspace.auth.handleCallback(request);
91
+ * // Store access_token as a session cookie
92
+ * }
93
+ * ```
94
+ */
95
+ handleCallback(request: Request | URL | string, opts?: {
96
+ redirectUri?: string;
97
+ }): Promise<TokenResponse>;
98
+ /**
99
+ * Revoke a specific session token.
100
+ *
101
+ * @param sessionToken - The token to revoke.
102
+ * @throws {BuildspaceError} If the revocation fails.
103
+ */
104
+ revokeSession(sessionToken: string): Promise<void>;
105
+ /**
106
+ * Sign the user out by revoking the session and clearing the SDK's stored token.
107
+ *
108
+ * If the session is already expired or not found, the error is silently
109
+ * ignored and the local session is still cleared.
110
+ *
111
+ * @param sessionToken - Token to revoke. If omitted, uses the token
112
+ * previously set via `buildspace.setSession()`.
113
+ */
114
+ signOut(sessionToken?: string): Promise<void>;
115
+ }
116
+
117
+ export { AuthServerNamespace as A, type TokenResponse as T, type AuthSession as a, type AuthUser as b };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/errors.ts","../../src/storage/client.ts","../../src/storage/server.ts"],"names":[],"mappings":";;;AAiBO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA;AAAA,EAEhC,IAAA;AAAA;AAAA,EAEA,OAAA;AAAA;AAAA,EAEA,MAAA;AAAA,EAET,WAAA,CAAY;AAAA,IACV,IAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF,EAKG;AACD,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AACF,CAAA;;;ACMO,IAAM,yBAAN,MAA6B;AAAA,EACjB,SAAA;AAAA,EAEjB,YAAY,SAAA,EAA0B;AACpC,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,MAAM,MAAA,CAAO,IAAA,EAAmB,IAAA,EAA8C;AAC5E,IAAA,MAAM,cACJ,IAAA,CAAK,WAAA,KAAgB,IAAA,YAAgB,IAAA,GAAO,KAAK,IAAA,GAAO,0BAAA,CAAA;AAE1D,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,SAAA,CAAU,OAAA,CAA6C;AAAA,MAC/E,OAAA,EAAS,SAAA;AAAA,MACT,IAAA,EAAM,oBAAA;AAAA,MACN,MAAA,EAAQ,MAAA;AAAA,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,YAAY,IAAA,EAAM;AAAA;AACpB,KACD,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAA,CACE,QACA,IAAA,EACuC;AACvC,IAAA,OAAO,IAAA,CAAK,UAAU,OAAA,CAAsC;AAAA,MAC1D,OAAA,EAAS,SAAA;AAAA,MACT,IAAA,EAAM,qBAAA;AAAA,MACN,KAAA,EAAO;AAAA,QACL,MAAA;AAAA,QACA,OAAO,IAAA,EAAM,KAAA;AAAA,QACb,QAAQ,IAAA,EAAM;AAAA;AAChB,KACD,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,OAAO,GAAA,EAA4B;AACvC,IAAA,MAAM,IAAA,CAAK,UAAU,OAAA,CAAc;AAAA,MACjC,OAAA,EAAS,SAAA;AAAA,MACT,IAAA,EAAM,oBAAA;AAAA,MACN,MAAA,EAAQ,QAAA;AAAA,MACR,IAAA,EAAM,EAAE,GAAA;AAAI,KACb,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAA,GAIG;AACD,IAAA,OAAO,IAAA,CAAK,UAAU,OAAA,CAInB;AAAA,MACD,OAAA,EAAS,SAAA;AAAA,MACT,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACF","file":"index.cjs","sourcesContent":["/** Services available in the Buildspace platform. */\nexport type BuildspaceService = \"auth\" | \"events\" | \"notifications\" | \"storage\";\n\n/**\n * Error thrown by all Buildspace SDK methods on failure.\n *\n * @example\n * ```ts\n * try {\n * await buildspace.auth.getSession(token);\n * } catch (err) {\n * if (err instanceof BuildspaceError) {\n * console.error(err.service, err.code, err.status, err.message);\n * }\n * }\n * ```\n */\nexport class BuildspaceError extends Error {\n /** Machine-readable error code, e.g. `\"auth/invalid-token\"`. */\n readonly code: string;\n /** Which service produced the error. */\n readonly service: BuildspaceService;\n /** HTTP status code from the API. */\n readonly status: number;\n\n constructor({\n code,\n message,\n service,\n status,\n }: {\n code: string;\n message: string;\n service: BuildspaceService;\n status: number;\n }) {\n super(message);\n this.name = \"BuildspaceError\";\n this.code = code;\n this.service = service;\n this.status = status;\n }\n}\n","import { BuildspaceError } from \"../errors\";\nimport type { HttpTransport } from \"../http\";\nimport type { StorageObject } from \"./server\";\n\n/** Options for uploading a file from the client. */\nexport interface UploadOptions {\n /** MIME type override. If omitted, inferred from the `File` object or defaults to `\"application/octet-stream\"`. */\n contentType?: string;\n /** Storage path/key for the file, e.g. `\"avatars/user-123.png\"`. */\n path: string;\n}\n\n/** Result of a successful client-side file upload. */\nexport interface UploadResponse {\n /** The resolved storage key. */\n key: string;\n /** File size in bytes. */\n size: number;\n /** Signed download URL for the uploaded file. */\n url: string;\n}\n\n/** Result of requesting a signed download URL. */\nexport interface GetUrlResponse {\n /** URL lifetime in seconds, if applicable. */\n expiresIn?: number;\n /** The storage key of the object. */\n key: string;\n /** The signed download URL. */\n url: string;\n}\n\n/**\n * Client-side storage methods for uploading and managing files.\n *\n * Access via `buildspace.storage` on the client SDK.\n *\n * @example\n * ```ts\n * // Upload a file (handles signed URL + PUT automatically)\n * const { key, url } = await buildspace.storage.upload(file, {\n * path: \"avatars/user-123.png\",\n * });\n *\n * // Get a download URL for an existing file\n * const { url } = await buildspace.storage.getUrl(key);\n * ```\n */\nexport class StorageClientNamespace {\n private readonly transport: HttpTransport;\n\n constructor(transport: HttpTransport) {\n this.transport = transport;\n }\n\n /**\n * Upload a `File` or `Blob` to Buildspace storage.\n *\n * This method handles the full upload flow:\n * 1. Requests a pre-signed upload URL from the API\n * 2. Uploads the file directly to the storage provider\n * 3. Returns a signed download URL for the uploaded file\n *\n * @param file - The file or blob to upload.\n * @param opts - Upload options including the storage path.\n * @returns The storage key, file size, and a signed download URL.\n *\n * @throws {BuildspaceError} If the upload URL request or the direct upload fails.\n */\n async upload(file: File | Blob, opts: UploadOptions): Promise<UploadResponse> {\n const contentType =\n opts.contentType ?? (file instanceof File ? file.type : \"application/octet-stream\");\n\n const signed = await this.transport.request<{ key: string; upload_url: string }>({\n service: \"storage\",\n path: \"/v1/storage/upload\",\n method: \"POST\",\n body: {\n path: opts.path,\n content_type: contentType,\n size: file.size,\n },\n });\n\n const response = await this.transport.fetcher(signed.upload_url, {\n method: \"PUT\",\n headers: { \"Content-Type\": contentType },\n body: file,\n });\n\n if (!response.ok) {\n throw new BuildspaceError({\n service: \"storage\",\n status: response.status,\n code: \"storage/upload-failed\",\n message: `Direct upload failed: ${response.statusText}`,\n });\n }\n\n const { url } = await this.getUrl(signed.key);\n\n return {\n key: signed.key,\n size: file.size,\n url,\n };\n }\n\n /**\n * Get a time-limited signed URL for downloading a stored file.\n *\n * @param key - The storage key of the object.\n * @param opts - Optional settings.\n * @param opts.expiresIn - URL lifetime in seconds.\n */\n getUrl(key: string, opts?: { expiresIn?: number }): Promise<GetUrlResponse> {\n return this.transport.request<GetUrlResponse>({\n service: \"storage\",\n path: \"/v1/storage/url\",\n query: {\n key,\n expires_in: opts?.expiresIn,\n },\n });\n }\n\n /**\n * List stored objects, optionally filtered by key prefix.\n *\n * @param prefix - Only return objects whose key starts with this prefix.\n * @param opts - Pagination options.\n */\n list(\n prefix?: string,\n opts?: { limit?: number; offset?: number }\n ): Promise<{ objects: StorageObject[] }> {\n return this.transport.request<{ objects: StorageObject[] }>({\n service: \"storage\",\n path: \"/v1/storage/objects\",\n query: {\n prefix,\n limit: opts?.limit,\n offset: opts?.offset,\n },\n });\n }\n\n /**\n * Delete a stored object by key.\n *\n * @param key - The storage key of the object to delete.\n */\n async delete(key: string): Promise<void> {\n await this.transport.request<void>({\n service: \"storage\",\n path: \"/v1/storage/object\",\n method: \"DELETE\",\n body: { key },\n });\n }\n}\n","import type { HttpTransport } from \"../http\";\n\n/** Options for requesting a pre-signed upload URL on the server. */\nexport interface ServerUploadOptions {\n /** MIME type of the file, e.g. `\"image/png\"`. */\n contentType: string;\n /** Storage path/key for the file, e.g. `\"avatars/user-123.png\"`. */\n key: string;\n /** File size in bytes. */\n size: number;\n}\n\n/** Metadata for a stored object. */\nexport interface StorageObject {\n /** MIME type of the stored file. */\n contentType: string;\n /** ISO 8601 timestamp of when the object was created. */\n createdAt: string;\n /** Unique object identifier. */\n id: string;\n /** Storage key/path of the object. */\n key: string;\n /** File size in bytes. */\n size: number;\n /** ID of the user who uploaded the object, or `null` if uploaded via server key. */\n uploadedBy: string | null;\n}\n\n/**\n * Server-side storage methods for managing file uploads and downloads.\n *\n * Access via `buildspace.storage` on the server SDK.\n *\n * @example\n * ```ts\n * // Get a pre-signed upload URL\n * const { upload_url, key } = await buildspace.storage.getUploadUrl({\n * key: \"avatars/user-123.png\",\n * contentType: \"image/png\",\n * size: file.size,\n * });\n *\n * // Upload directly to the signed URL\n * await fetch(upload_url, { method: \"PUT\", body: file });\n *\n * // Get a signed download URL\n * const { url } = await buildspace.storage.getSignedUrl(key);\n * ```\n */\nexport class StorageServerNamespace {\n private readonly transport: HttpTransport;\n\n constructor(transport: HttpTransport) {\n this.transport = transport;\n }\n\n /**\n * Request a pre-signed URL for direct file upload.\n *\n * @param opts - Upload options including the storage key, content type, and file size.\n * @returns The signed upload URL, the resolved key, and expiry time in seconds.\n */\n getUploadUrl(\n opts: ServerUploadOptions\n ): Promise<{ expires_in: number; key: string; upload_url: string }> {\n return this.transport.request<{ expires_in: number; key: string; upload_url: string }>({\n service: \"storage\",\n path: \"/v1/storage/upload\",\n method: \"POST\",\n body: {\n path: opts.key,\n content_type: opts.contentType,\n size: opts.size,\n },\n });\n }\n\n /**\n * Get a time-limited signed URL for downloading a stored file.\n *\n * @param key - The storage key of the object.\n * @param opts - Optional settings.\n * @param opts.expiresIn - URL lifetime in seconds. Uses server default if omitted.\n */\n getSignedUrl(\n key: string,\n opts?: { expiresIn?: number }\n ): Promise<{ expiresIn?: number; key: string; url: string }> {\n return this.transport.request<{ expiresIn?: number; key: string; url: string }>({\n service: \"storage\",\n path: \"/v1/storage/url\",\n query: {\n key,\n expires_in: opts?.expiresIn,\n },\n });\n }\n\n /**\n * List stored objects, optionally filtered by key prefix.\n *\n * @param prefix - Only return objects whose key starts with this prefix, e.g. `\"avatars/\"`.\n * @param opts - Pagination options.\n */\n list(\n prefix?: string,\n opts?: { limit?: number; offset?: number }\n ): Promise<{ objects: StorageObject[] }> {\n return this.transport.request<{ objects: StorageObject[] }>({\n service: \"storage\",\n path: \"/v1/storage/objects\",\n query: {\n prefix,\n limit: opts?.limit,\n offset: opts?.offset,\n },\n });\n }\n\n /**\n * Delete a stored object by key.\n *\n * @param key - The storage key of the object to delete.\n */\n async delete(key: string): Promise<void> {\n await this.transport.request<void>({\n service: \"storage\",\n path: \"/v1/storage/object\",\n method: \"DELETE\",\n body: { key },\n });\n }\n\n /**\n * Get current storage usage statistics for the app.\n *\n * @returns Byte counts and object count.\n */\n getUsage(): Promise<{\n maxStorageBytes: number;\n objectCount: number;\n storageBytes: number;\n }> {\n return this.transport.request<{\n maxStorageBytes: number;\n objectCount: number;\n storageBytes: number;\n }>({\n service: \"storage\",\n path: \"/v1/storage/usage\",\n });\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/errors.ts","../../src/storage/client.ts","../../src/storage/server.ts"],"names":[],"mappings":";;;AAiBO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA;AAAA,EAEhC,IAAA;AAAA;AAAA,EAEA,OAAA;AAAA;AAAA,EAEA,MAAA;AAAA,EAET,WAAA,CAAY;AAAA,IACV,IAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF,EAKG;AACD,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AACF,CAAA;;;ACMO,IAAM,yBAAN,MAA6B;AAAA,EACjB,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AAA,CAAK,UAAU,OAAA,CAInB;AAAA,MACD,OAAA,EAAS,SAAA;AAAA,MACT,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACF","file":"index.cjs","sourcesContent":["/** Services available in the Buildspace platform. */\nexport type BuildspaceService = \"auth\" | \"billing\" | \"events\" | \"notifications\" | \"storage\";\n\n/**\n * Error thrown by all Buildspace SDK methods on failure.\n *\n * @example\n * ```ts\n * try {\n * await buildspace.auth.getSession(token);\n * } catch (err) {\n * if (err instanceof BuildspaceError) {\n * console.error(err.service, err.code, err.status, err.message);\n * }\n * }\n * ```\n */\nexport class BuildspaceError extends Error {\n /** Machine-readable error code, e.g. `\"auth/invalid-token\"`. */\n readonly code: string;\n /** Which service produced the error. */\n readonly service: BuildspaceService;\n /** HTTP status code from the API. */\n readonly status: number;\n\n constructor({\n code,\n message,\n service,\n status,\n }: {\n code: string;\n message: string;\n service: BuildspaceService;\n status: number;\n }) {\n super(message);\n this.name = \"BuildspaceError\";\n this.code = code;\n this.service = service;\n this.status = status;\n }\n}\n","import { BuildspaceError } from \"../errors\";\nimport type { HttpTransport } from \"../http\";\nimport type { StorageObject } from \"./server\";\n\n/** Options for uploading a file from the client. */\nexport interface UploadOptions {\n /** MIME type override. If omitted, inferred from the `File` object or defaults to `\"application/octet-stream\"`. */\n contentType?: string;\n /** Storage path/key for the file, e.g. `\"avatars/user-123.png\"`. */\n path: string;\n}\n\n/** Result of a successful client-side file upload. */\nexport interface UploadResponse {\n /** The resolved storage key. */\n key: string;\n /** File size in bytes. */\n size: number;\n /** Signed download URL for the uploaded file. */\n url: string;\n}\n\n/** Result of requesting a signed download URL. */\nexport interface GetUrlResponse {\n /** URL lifetime in seconds, if applicable. */\n expiresIn?: number;\n /** The storage key of the object. */\n key: string;\n /** The signed download URL. */\n url: string;\n}\n\n/**\n * Client-side storage methods for uploading and managing files.\n *\n * Access via `buildspace.storage` on the client SDK.\n *\n * @example\n * ```ts\n * // Upload a file (handles signed URL + PUT automatically)\n * const { key, url } = await buildspace.storage.upload(file, {\n * path: \"avatars/user-123.png\",\n * });\n *\n * // Get a download URL for an existing file\n * const { url } = await buildspace.storage.getUrl(key);\n * ```\n */\nexport class StorageClientNamespace {\n private readonly transport: HttpTransport;\n\n constructor(transport: HttpTransport) {\n this.transport = transport;\n }\n\n /**\n * Upload a `File` or `Blob` to Buildspace storage.\n *\n * This method handles the full upload flow:\n * 1. Requests a pre-signed upload URL from the API\n * 2. Uploads the file directly to the storage provider\n * 3. Returns a signed download URL for the uploaded file\n *\n * @param file - The file or blob to upload.\n * @param opts - Upload options including the storage path.\n * @returns The storage key, file size, and a signed download URL.\n *\n * @throws {BuildspaceError} If the upload URL request or the direct upload fails.\n */\n async upload(file: File | Blob, opts: UploadOptions): Promise<UploadResponse> {\n const contentType =\n opts.contentType ?? (file instanceof File ? file.type : \"application/octet-stream\");\n\n const signed = await this.transport.request<{ key: string; upload_url: string }>({\n service: \"storage\",\n path: \"/v1/storage/upload\",\n method: \"POST\",\n body: {\n path: opts.path,\n content_type: contentType,\n size: file.size,\n },\n });\n\n const response = await this.transport.fetcher(signed.upload_url, {\n method: \"PUT\",\n headers: { \"Content-Type\": contentType },\n body: file,\n });\n\n if (!response.ok) {\n throw new BuildspaceError({\n service: \"storage\",\n status: response.status,\n code: \"storage/upload-failed\",\n message: `Direct upload failed: ${response.statusText}`,\n });\n }\n\n const { url } = await this.getUrl(signed.key);\n\n return {\n key: signed.key,\n size: file.size,\n url,\n };\n }\n\n /**\n * Get a time-limited signed URL for downloading a stored file.\n *\n * @param key - The storage key of the object.\n * @param opts - Optional settings.\n * @param opts.expiresIn - URL lifetime in seconds.\n */\n getUrl(key: string, opts?: { expiresIn?: number }): Promise<GetUrlResponse> {\n return this.transport.request<GetUrlResponse>({\n service: \"storage\",\n path: \"/v1/storage/url\",\n query: {\n key,\n expires_in: opts?.expiresIn,\n },\n });\n }\n\n /**\n * List stored objects, optionally filtered by key prefix.\n *\n * @param prefix - Only return objects whose key starts with this prefix.\n * @param opts - Pagination options.\n */\n list(\n prefix?: string,\n opts?: { limit?: number; offset?: number }\n ): Promise<{ objects: StorageObject[] }> {\n return this.transport.request<{ objects: StorageObject[] }>({\n service: \"storage\",\n path: \"/v1/storage/objects\",\n query: {\n prefix,\n limit: opts?.limit,\n offset: opts?.offset,\n },\n });\n }\n\n /**\n * Delete a stored object by key.\n *\n * @param key - The storage key of the object to delete.\n */\n async delete(key: string): Promise<void> {\n await this.transport.request<void>({\n service: \"storage\",\n path: \"/v1/storage/object\",\n method: \"DELETE\",\n body: { key },\n });\n }\n}\n","import type { HttpTransport } from \"../http\";\n\n/** Options for requesting a pre-signed upload URL on the server. */\nexport interface ServerUploadOptions {\n /** MIME type of the file, e.g. `\"image/png\"`. */\n contentType: string;\n /** Storage path/key for the file, e.g. `\"avatars/user-123.png\"`. */\n key: string;\n /** File size in bytes. */\n size: number;\n}\n\n/** Metadata for a stored object. */\nexport interface StorageObject {\n /** MIME type of the stored file. */\n contentType: string;\n /** ISO 8601 timestamp of when the object was created. */\n createdAt: string;\n /** Unique object identifier. */\n id: string;\n /** Storage key/path of the object. */\n key: string;\n /** File size in bytes. */\n size: number;\n /** ID of the user who uploaded the object, or `null` if uploaded via server key. */\n uploadedBy: string | null;\n}\n\n/**\n * Server-side storage methods for managing file uploads and downloads.\n *\n * Access via `buildspace.storage` on the server SDK.\n *\n * @example\n * ```ts\n * // Get a pre-signed upload URL\n * const { upload_url, key } = await buildspace.storage.getUploadUrl({\n * key: \"avatars/user-123.png\",\n * contentType: \"image/png\",\n * size: file.size,\n * });\n *\n * // Upload directly to the signed URL\n * await fetch(upload_url, { method: \"PUT\", body: file });\n *\n * // Get a signed download URL\n * const { url } = await buildspace.storage.getSignedUrl(key);\n * ```\n */\nexport class StorageServerNamespace {\n private readonly transport: HttpTransport;\n\n constructor(transport: HttpTransport) {\n this.transport = transport;\n }\n\n /**\n * Request a pre-signed URL for direct file upload.\n *\n * @param opts - Upload options including the storage key, content type, and file size.\n * @returns The signed upload URL, the resolved key, and expiry time in seconds.\n */\n getUploadUrl(\n opts: ServerUploadOptions\n ): Promise<{ expires_in: number; key: string; upload_url: string }> {\n return this.transport.request<{ expires_in: number; key: string; upload_url: string }>({\n service: \"storage\",\n path: \"/v1/storage/upload\",\n method: \"POST\",\n body: {\n path: opts.key,\n content_type: opts.contentType,\n size: opts.size,\n },\n });\n }\n\n /**\n * Get a time-limited signed URL for downloading a stored file.\n *\n * @param key - The storage key of the object.\n * @param opts - Optional settings.\n * @param opts.expiresIn - URL lifetime in seconds. Uses server default if omitted.\n */\n getSignedUrl(\n key: string,\n opts?: { expiresIn?: number }\n ): Promise<{ expiresIn?: number; key: string; url: string }> {\n return this.transport.request<{ expiresIn?: number; key: string; url: string }>({\n service: \"storage\",\n path: \"/v1/storage/url\",\n query: {\n key,\n expires_in: opts?.expiresIn,\n },\n });\n }\n\n /**\n * List stored objects, optionally filtered by key prefix.\n *\n * @param prefix - Only return objects whose key starts with this prefix, e.g. `\"avatars/\"`.\n * @param opts - Pagination options.\n */\n list(\n prefix?: string,\n opts?: { limit?: number; offset?: number }\n ): Promise<{ objects: StorageObject[] }> {\n return this.transport.request<{ objects: StorageObject[] }>({\n service: \"storage\",\n path: \"/v1/storage/objects\",\n query: {\n prefix,\n limit: opts?.limit,\n offset: opts?.offset,\n },\n });\n }\n\n /**\n * Delete a stored object by key.\n *\n * @param key - The storage key of the object to delete.\n */\n async delete(key: string): Promise<void> {\n await this.transport.request<void>({\n service: \"storage\",\n path: \"/v1/storage/object\",\n method: \"DELETE\",\n body: { key },\n });\n }\n\n /**\n * Get current storage usage statistics for the app.\n *\n * @returns Byte counts and object count.\n */\n getUsage(): Promise<{\n maxStorageBytes: number;\n objectCount: number;\n storageBytes: number;\n }> {\n return this.transport.request<{\n maxStorageBytes: number;\n objectCount: number;\n storageBytes: number;\n }>({\n service: \"storage\",\n path: \"/v1/storage/usage\",\n });\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { H as HttpTransport } from '../http-U-zzKmFF.cjs';
1
+ import { H as HttpTransport } from '../http-D2gXpNpr.cjs';
2
2
 
3
3
  /** Options for requesting a pre-signed upload URL on the server. */
4
4
  interface ServerUploadOptions {
@@ -1,4 +1,4 @@
1
- import { H as HttpTransport } from '../http-U-zzKmFF.js';
1
+ import { H as HttpTransport } from '../http-D2gXpNpr.js';
2
2
 
3
3
  /** Options for requesting a pre-signed upload URL on the server. */
4
4
  interface ServerUploadOptions {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/errors.ts","../../src/storage/client.ts","../../src/storage/server.ts"],"names":[],"mappings":";AAiBO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA;AAAA,EAEhC,IAAA;AAAA;AAAA,EAEA,OAAA;AAAA;AAAA,EAEA,MAAA;AAAA,EAET,WAAA,CAAY;AAAA,IACV,IAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF,EAKG;AACD,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AAAA,EAChB;AACF,CAAA;;;ACMO,IAAM,yBAAN,MAA6B;AAAA,EACjB,SAAA;AAAA,EAEjB,YAAY,SAAA,EAA0B;AACpC,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,MAAM,MAAA,CAAO,IAAA,EAAmB,IAAA,EAA8C;AAC5E,IAAA,MAAM,cACJ,IAAA,CAAK,WAAA,KAAgB,IAAA,YAAgB,IAAA,GAAO,KAAK,IAAA,GAAO,0BAAA,CAAA;AAE1D,IAAA,MAAM,MAAA,GAAS,MAA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,CAAK,UAAU,OAAA,CAA0D;AAAA,MAC9E,OAAA,EAAS,SAAA;AAAA,MACT,IAAA,EAAM,iBAAA;AAAA,MACN,KAAA,EAAO;AAAA,QACL,GAAA;AAAA,QACA,YAAY,IAAA,EAAM;AAAA;AACpB,KACD,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAA,CACE,QACA,IAAA,EACuC;AACvC,IAAA,OAAO,IAAA,CAAK,UAAU,OAAA,CAAsC;AAAA,MAC1D,OAAA,EAAS,SAAA;AAAA,MACT,IAAA,EAAM,qBAAA;AAAA,MACN,KAAA,EAAO;AAAA,QACL,MAAA;AAAA,QACA,OAAO,IAAA,EAAM,KAAA;AAAA,QACb,QAAQ,IAAA,EAAM;AAAA;AAChB,KACD,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,OAAO,GAAA,EAA4B;AACvC,IAAA,MAAM,IAAA,CAAK,UAAU,OAAA,CAAc;AAAA,MACjC,OAAA,EAAS,SAAA;AAAA,MACT,IAAA,EAAM,oBAAA;AAAA,MACN,MAAA,EAAQ,QAAA;AAAA,MACR,IAAA,EAAM,EAAE,GAAA;AAAI,KACb,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAA,GAIG;AACD,IAAA,OAAO,IAAA,CAAK,UAAU,OAAA,CAInB;AAAA,MACD,OAAA,EAAS,SAAA;AAAA,MACT,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACF","file":"index.js","sourcesContent":["/** Services available in the Buildspace platform. */\nexport type BuildspaceService = \"auth\" | \"events\" | \"notifications\" | \"storage\";\n\n/**\n * Error thrown by all Buildspace SDK methods on failure.\n *\n * @example\n * ```ts\n * try {\n * await buildspace.auth.getSession(token);\n * } catch (err) {\n * if (err instanceof BuildspaceError) {\n * console.error(err.service, err.code, err.status, err.message);\n * }\n * }\n * ```\n */\nexport class BuildspaceError extends Error {\n /** Machine-readable error code, e.g. `\"auth/invalid-token\"`. */\n readonly code: string;\n /** Which service produced the error. */\n readonly service: BuildspaceService;\n /** HTTP status code from the API. */\n readonly status: number;\n\n constructor({\n code,\n message,\n service,\n status,\n }: {\n code: string;\n message: string;\n service: BuildspaceService;\n status: number;\n }) {\n super(message);\n this.name = \"BuildspaceError\";\n this.code = code;\n this.service = service;\n this.status = status;\n }\n}\n","import { BuildspaceError } from \"../errors\";\nimport type { HttpTransport } from \"../http\";\nimport type { StorageObject } from \"./server\";\n\n/** Options for uploading a file from the client. */\nexport interface UploadOptions {\n /** MIME type override. If omitted, inferred from the `File` object or defaults to `\"application/octet-stream\"`. */\n contentType?: string;\n /** Storage path/key for the file, e.g. `\"avatars/user-123.png\"`. */\n path: string;\n}\n\n/** Result of a successful client-side file upload. */\nexport interface UploadResponse {\n /** The resolved storage key. */\n key: string;\n /** File size in bytes. */\n size: number;\n /** Signed download URL for the uploaded file. */\n url: string;\n}\n\n/** Result of requesting a signed download URL. */\nexport interface GetUrlResponse {\n /** URL lifetime in seconds, if applicable. */\n expiresIn?: number;\n /** The storage key of the object. */\n key: string;\n /** The signed download URL. */\n url: string;\n}\n\n/**\n * Client-side storage methods for uploading and managing files.\n *\n * Access via `buildspace.storage` on the client SDK.\n *\n * @example\n * ```ts\n * // Upload a file (handles signed URL + PUT automatically)\n * const { key, url } = await buildspace.storage.upload(file, {\n * path: \"avatars/user-123.png\",\n * });\n *\n * // Get a download URL for an existing file\n * const { url } = await buildspace.storage.getUrl(key);\n * ```\n */\nexport class StorageClientNamespace {\n private readonly transport: HttpTransport;\n\n constructor(transport: HttpTransport) {\n this.transport = transport;\n }\n\n /**\n * Upload a `File` or `Blob` to Buildspace storage.\n *\n * This method handles the full upload flow:\n * 1. Requests a pre-signed upload URL from the API\n * 2. Uploads the file directly to the storage provider\n * 3. Returns a signed download URL for the uploaded file\n *\n * @param file - The file or blob to upload.\n * @param opts - Upload options including the storage path.\n * @returns The storage key, file size, and a signed download URL.\n *\n * @throws {BuildspaceError} If the upload URL request or the direct upload fails.\n */\n async upload(file: File | Blob, opts: UploadOptions): Promise<UploadResponse> {\n const contentType =\n opts.contentType ?? (file instanceof File ? file.type : \"application/octet-stream\");\n\n const signed = await this.transport.request<{ key: string; upload_url: string }>({\n service: \"storage\",\n path: \"/v1/storage/upload\",\n method: \"POST\",\n body: {\n path: opts.path,\n content_type: contentType,\n size: file.size,\n },\n });\n\n const response = await this.transport.fetcher(signed.upload_url, {\n method: \"PUT\",\n headers: { \"Content-Type\": contentType },\n body: file,\n });\n\n if (!response.ok) {\n throw new BuildspaceError({\n service: \"storage\",\n status: response.status,\n code: \"storage/upload-failed\",\n message: `Direct upload failed: ${response.statusText}`,\n });\n }\n\n const { url } = await this.getUrl(signed.key);\n\n return {\n key: signed.key,\n size: file.size,\n url,\n };\n }\n\n /**\n * Get a time-limited signed URL for downloading a stored file.\n *\n * @param key - The storage key of the object.\n * @param opts - Optional settings.\n * @param opts.expiresIn - URL lifetime in seconds.\n */\n getUrl(key: string, opts?: { expiresIn?: number }): Promise<GetUrlResponse> {\n return this.transport.request<GetUrlResponse>({\n service: \"storage\",\n path: \"/v1/storage/url\",\n query: {\n key,\n expires_in: opts?.expiresIn,\n },\n });\n }\n\n /**\n * List stored objects, optionally filtered by key prefix.\n *\n * @param prefix - Only return objects whose key starts with this prefix.\n * @param opts - Pagination options.\n */\n list(\n prefix?: string,\n opts?: { limit?: number; offset?: number }\n ): Promise<{ objects: StorageObject[] }> {\n return this.transport.request<{ objects: StorageObject[] }>({\n service: \"storage\",\n path: \"/v1/storage/objects\",\n query: {\n prefix,\n limit: opts?.limit,\n offset: opts?.offset,\n },\n });\n }\n\n /**\n * Delete a stored object by key.\n *\n * @param key - The storage key of the object to delete.\n */\n async delete(key: string): Promise<void> {\n await this.transport.request<void>({\n service: \"storage\",\n path: \"/v1/storage/object\",\n method: \"DELETE\",\n body: { key },\n });\n }\n}\n","import type { HttpTransport } from \"../http\";\n\n/** Options for requesting a pre-signed upload URL on the server. */\nexport interface ServerUploadOptions {\n /** MIME type of the file, e.g. `\"image/png\"`. */\n contentType: string;\n /** Storage path/key for the file, e.g. `\"avatars/user-123.png\"`. */\n key: string;\n /** File size in bytes. */\n size: number;\n}\n\n/** Metadata for a stored object. */\nexport interface StorageObject {\n /** MIME type of the stored file. */\n contentType: string;\n /** ISO 8601 timestamp of when the object was created. */\n createdAt: string;\n /** Unique object identifier. */\n id: string;\n /** Storage key/path of the object. */\n key: string;\n /** File size in bytes. */\n size: number;\n /** ID of the user who uploaded the object, or `null` if uploaded via server key. */\n uploadedBy: string | null;\n}\n\n/**\n * Server-side storage methods for managing file uploads and downloads.\n *\n * Access via `buildspace.storage` on the server SDK.\n *\n * @example\n * ```ts\n * // Get a pre-signed upload URL\n * const { upload_url, key } = await buildspace.storage.getUploadUrl({\n * key: \"avatars/user-123.png\",\n * contentType: \"image/png\",\n * size: file.size,\n * });\n *\n * // Upload directly to the signed URL\n * await fetch(upload_url, { method: \"PUT\", body: file });\n *\n * // Get a signed download URL\n * const { url } = await buildspace.storage.getSignedUrl(key);\n * ```\n */\nexport class StorageServerNamespace {\n private readonly transport: HttpTransport;\n\n constructor(transport: HttpTransport) {\n this.transport = transport;\n }\n\n /**\n * Request a pre-signed URL for direct file upload.\n *\n * @param opts - Upload options including the storage key, content type, and file size.\n * @returns The signed upload URL, the resolved key, and expiry time in seconds.\n */\n getUploadUrl(\n opts: ServerUploadOptions\n ): Promise<{ expires_in: number; key: string; upload_url: string }> {\n return this.transport.request<{ expires_in: number; key: string; upload_url: string }>({\n service: \"storage\",\n path: \"/v1/storage/upload\",\n method: \"POST\",\n body: {\n path: opts.key,\n content_type: opts.contentType,\n size: opts.size,\n },\n });\n }\n\n /**\n * Get a time-limited signed URL for downloading a stored file.\n *\n * @param key - The storage key of the object.\n * @param opts - Optional settings.\n * @param opts.expiresIn - URL lifetime in seconds. Uses server default if omitted.\n */\n getSignedUrl(\n key: string,\n opts?: { expiresIn?: number }\n ): Promise<{ expiresIn?: number; key: string; url: string }> {\n return this.transport.request<{ expiresIn?: number; key: string; url: string }>({\n service: \"storage\",\n path: \"/v1/storage/url\",\n query: {\n key,\n expires_in: opts?.expiresIn,\n },\n });\n }\n\n /**\n * List stored objects, optionally filtered by key prefix.\n *\n * @param prefix - Only return objects whose key starts with this prefix, e.g. `\"avatars/\"`.\n * @param opts - Pagination options.\n */\n list(\n prefix?: string,\n opts?: { limit?: number; offset?: number }\n ): Promise<{ objects: StorageObject[] }> {\n return this.transport.request<{ objects: StorageObject[] }>({\n service: \"storage\",\n path: \"/v1/storage/objects\",\n query: {\n prefix,\n limit: opts?.limit,\n offset: opts?.offset,\n },\n });\n }\n\n /**\n * Delete a stored object by key.\n *\n * @param key - The storage key of the object to delete.\n */\n async delete(key: string): Promise<void> {\n await this.transport.request<void>({\n service: \"storage\",\n path: \"/v1/storage/object\",\n method: \"DELETE\",\n body: { key },\n });\n }\n\n /**\n * Get current storage usage statistics for the app.\n *\n * @returns Byte counts and object count.\n */\n getUsage(): Promise<{\n maxStorageBytes: number;\n objectCount: number;\n storageBytes: number;\n }> {\n return this.transport.request<{\n maxStorageBytes: number;\n objectCount: number;\n storageBytes: number;\n }>({\n service: \"storage\",\n path: \"/v1/storage/usage\",\n });\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/errors.ts","../../src/storage/client.ts","../../src/storage/server.ts"],"names":[],"mappings":";AAiBO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA;AAAA,EAEhC,IAAA;AAAA;AAAA,EAEA,OAAA;AAAA;AAAA,EAEA,MAAA;AAAA,EAET,WAAA,CAAY;AAAA,IACV,IAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF,EAKG;AACD,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IA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AA,MACR,IAAA,EAAM,EAAE,GAAA;AAAI,KACb,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAA,GAIG;AACD,IAAA,OAAO,IAAA,CAAK,UAAU,OAAA,CAInB;AAAA,MACD,OAAA,EAAS,SAAA;AAAA,MACT,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACF","file":"index.js","sourcesContent":["/** Services available in the Buildspace platform. */\nexport type BuildspaceService = \"auth\" | \"billing\" | \"events\" | \"notifications\" | \"storage\";\n\n/**\n * Error thrown by all Buildspace SDK methods on failure.\n *\n * @example\n * ```ts\n * try {\n * await buildspace.auth.getSession(token);\n * } catch (err) {\n * if (err instanceof BuildspaceError) {\n * console.error(err.service, err.code, err.status, err.message);\n * }\n * }\n * ```\n */\nexport class BuildspaceError extends Error {\n /** Machine-readable error code, e.g. `\"auth/invalid-token\"`. */\n readonly code: string;\n /** Which service produced the error. */\n readonly service: BuildspaceService;\n /** HTTP status code from the API. */\n readonly status: number;\n\n constructor({\n code,\n message,\n service,\n status,\n }: {\n code: string;\n message: string;\n service: BuildspaceService;\n status: number;\n }) {\n super(message);\n this.name = \"BuildspaceError\";\n this.code = code;\n this.service = service;\n this.status = status;\n }\n}\n","import { BuildspaceError } from \"../errors\";\nimport type { HttpTransport } from \"../http\";\nimport type { StorageObject } from \"./server\";\n\n/** Options for uploading a file from the client. */\nexport interface UploadOptions {\n /** MIME type override. If omitted, inferred from the `File` object or defaults to `\"application/octet-stream\"`. */\n contentType?: string;\n /** Storage path/key for the file, e.g. `\"avatars/user-123.png\"`. */\n path: string;\n}\n\n/** Result of a successful client-side file upload. */\nexport interface UploadResponse {\n /** The resolved storage key. */\n key: string;\n /** File size in bytes. */\n size: number;\n /** Signed download URL for the uploaded file. */\n url: string;\n}\n\n/** Result of requesting a signed download URL. */\nexport interface GetUrlResponse {\n /** URL lifetime in seconds, if applicable. */\n expiresIn?: number;\n /** The storage key of the object. */\n key: string;\n /** The signed download URL. */\n url: string;\n}\n\n/**\n * Client-side storage methods for uploading and managing files.\n *\n * Access via `buildspace.storage` on the client SDK.\n *\n * @example\n * ```ts\n * // Upload a file (handles signed URL + PUT automatically)\n * const { key, url } = await buildspace.storage.upload(file, {\n * path: \"avatars/user-123.png\",\n * });\n *\n * // Get a download URL for an existing file\n * const { url } = await buildspace.storage.getUrl(key);\n * ```\n */\nexport class StorageClientNamespace {\n private readonly transport: HttpTransport;\n\n constructor(transport: HttpTransport) {\n this.transport = transport;\n }\n\n /**\n * Upload a `File` or `Blob` to Buildspace storage.\n *\n * This method handles the full upload flow:\n * 1. Requests a pre-signed upload URL from the API\n * 2. Uploads the file directly to the storage provider\n * 3. Returns a signed download URL for the uploaded file\n *\n * @param file - The file or blob to upload.\n * @param opts - Upload options including the storage path.\n * @returns The storage key, file size, and a signed download URL.\n *\n * @throws {BuildspaceError} If the upload URL request or the direct upload fails.\n */\n async upload(file: File | Blob, opts: UploadOptions): Promise<UploadResponse> {\n const contentType =\n opts.contentType ?? (file instanceof File ? file.type : \"application/octet-stream\");\n\n const signed = await this.transport.request<{ key: string; upload_url: string }>({\n service: \"storage\",\n path: \"/v1/storage/upload\",\n method: \"POST\",\n body: {\n path: opts.path,\n content_type: contentType,\n size: file.size,\n },\n });\n\n const response = await this.transport.fetcher(signed.upload_url, {\n method: \"PUT\",\n headers: { \"Content-Type\": contentType },\n body: file,\n });\n\n if (!response.ok) {\n throw new BuildspaceError({\n service: \"storage\",\n status: response.status,\n code: \"storage/upload-failed\",\n message: `Direct upload failed: ${response.statusText}`,\n });\n }\n\n const { url } = await this.getUrl(signed.key);\n\n return {\n key: signed.key,\n size: file.size,\n url,\n };\n }\n\n /**\n * Get a time-limited signed URL for downloading a stored file.\n *\n * @param key - The storage key of the object.\n * @param opts - Optional settings.\n * @param opts.expiresIn - URL lifetime in seconds.\n */\n getUrl(key: string, opts?: { expiresIn?: number }): Promise<GetUrlResponse> {\n return this.transport.request<GetUrlResponse>({\n service: \"storage\",\n path: \"/v1/storage/url\",\n query: {\n key,\n expires_in: opts?.expiresIn,\n },\n });\n }\n\n /**\n * List stored objects, optionally filtered by key prefix.\n *\n * @param prefix - Only return objects whose key starts with this prefix.\n * @param opts - Pagination options.\n */\n list(\n prefix?: string,\n opts?: { limit?: number; offset?: number }\n ): Promise<{ objects: StorageObject[] }> {\n return this.transport.request<{ objects: StorageObject[] }>({\n service: \"storage\",\n path: \"/v1/storage/objects\",\n query: {\n prefix,\n limit: opts?.limit,\n offset: opts?.offset,\n },\n });\n }\n\n /**\n * Delete a stored object by key.\n *\n * @param key - The storage key of the object to delete.\n */\n async delete(key: string): Promise<void> {\n await this.transport.request<void>({\n service: \"storage\",\n path: \"/v1/storage/object\",\n method: \"DELETE\",\n body: { key },\n });\n }\n}\n","import type { HttpTransport } from \"../http\";\n\n/** Options for requesting a pre-signed upload URL on the server. */\nexport interface ServerUploadOptions {\n /** MIME type of the file, e.g. `\"image/png\"`. */\n contentType: string;\n /** Storage path/key for the file, e.g. `\"avatars/user-123.png\"`. */\n key: string;\n /** File size in bytes. */\n size: number;\n}\n\n/** Metadata for a stored object. */\nexport interface StorageObject {\n /** MIME type of the stored file. */\n contentType: string;\n /** ISO 8601 timestamp of when the object was created. */\n createdAt: string;\n /** Unique object identifier. */\n id: string;\n /** Storage key/path of the object. */\n key: string;\n /** File size in bytes. */\n size: number;\n /** ID of the user who uploaded the object, or `null` if uploaded via server key. */\n uploadedBy: string | null;\n}\n\n/**\n * Server-side storage methods for managing file uploads and downloads.\n *\n * Access via `buildspace.storage` on the server SDK.\n *\n * @example\n * ```ts\n * // Get a pre-signed upload URL\n * const { upload_url, key } = await buildspace.storage.getUploadUrl({\n * key: \"avatars/user-123.png\",\n * contentType: \"image/png\",\n * size: file.size,\n * });\n *\n * // Upload directly to the signed URL\n * await fetch(upload_url, { method: \"PUT\", body: file });\n *\n * // Get a signed download URL\n * const { url } = await buildspace.storage.getSignedUrl(key);\n * ```\n */\nexport class StorageServerNamespace {\n private readonly transport: HttpTransport;\n\n constructor(transport: HttpTransport) {\n this.transport = transport;\n }\n\n /**\n * Request a pre-signed URL for direct file upload.\n *\n * @param opts - Upload options including the storage key, content type, and file size.\n * @returns The signed upload URL, the resolved key, and expiry time in seconds.\n */\n getUploadUrl(\n opts: ServerUploadOptions\n ): Promise<{ expires_in: number; key: string; upload_url: string }> {\n return this.transport.request<{ expires_in: number; key: string; upload_url: string }>({\n service: \"storage\",\n path: \"/v1/storage/upload\",\n method: \"POST\",\n body: {\n path: opts.key,\n content_type: opts.contentType,\n size: opts.size,\n },\n });\n }\n\n /**\n * Get a time-limited signed URL for downloading a stored file.\n *\n * @param key - The storage key of the object.\n * @param opts - Optional settings.\n * @param opts.expiresIn - URL lifetime in seconds. Uses server default if omitted.\n */\n getSignedUrl(\n key: string,\n opts?: { expiresIn?: number }\n ): Promise<{ expiresIn?: number; key: string; url: string }> {\n return this.transport.request<{ expiresIn?: number; key: string; url: string }>({\n service: \"storage\",\n path: \"/v1/storage/url\",\n query: {\n key,\n expires_in: opts?.expiresIn,\n },\n });\n }\n\n /**\n * List stored objects, optionally filtered by key prefix.\n *\n * @param prefix - Only return objects whose key starts with this prefix, e.g. `\"avatars/\"`.\n * @param opts - Pagination options.\n */\n list(\n prefix?: string,\n opts?: { limit?: number; offset?: number }\n ): Promise<{ objects: StorageObject[] }> {\n return this.transport.request<{ objects: StorageObject[] }>({\n service: \"storage\",\n path: \"/v1/storage/objects\",\n query: {\n prefix,\n limit: opts?.limit,\n offset: opts?.offset,\n },\n });\n }\n\n /**\n * Delete a stored object by key.\n *\n * @param key - The storage key of the object to delete.\n */\n async delete(key: string): Promise<void> {\n await this.transport.request<void>({\n service: \"storage\",\n path: \"/v1/storage/object\",\n method: \"DELETE\",\n body: { key },\n });\n }\n\n /**\n * Get current storage usage statistics for the app.\n *\n * @returns Byte counts and object count.\n */\n getUsage(): Promise<{\n maxStorageBytes: number;\n objectCount: number;\n storageBytes: number;\n }> {\n return this.transport.request<{\n maxStorageBytes: number;\n objectCount: number;\n storageBytes: number;\n }>({\n service: \"storage\",\n path: \"/v1/storage/usage\",\n });\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buildspacestudio/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -67,6 +67,36 @@
67
67
  "default": "./dist/notifications/index.cjs"
68
68
  }
69
69
  },
70
+ "./billing": {
71
+ "import": {
72
+ "types": "./dist/billing/index.d.ts",
73
+ "default": "./dist/billing/index.js"
74
+ },
75
+ "require": {
76
+ "types": "./dist/billing/index.d.cts",
77
+ "default": "./dist/billing/index.cjs"
78
+ }
79
+ },
80
+ "./next": {
81
+ "import": {
82
+ "types": "./dist/next/index.d.ts",
83
+ "default": "./dist/next/index.js"
84
+ },
85
+ "require": {
86
+ "types": "./dist/next/index.d.cts",
87
+ "default": "./dist/next/index.cjs"
88
+ }
89
+ },
90
+ "./react": {
91
+ "import": {
92
+ "types": "./dist/react/index.d.ts",
93
+ "default": "./dist/react/index.js"
94
+ },
95
+ "require": {
96
+ "types": "./dist/react/index.d.cts",
97
+ "default": "./dist/react/index.cjs"
98
+ }
99
+ },
70
100
  "./package.json": "./package.json"
71
101
  },
72
102
  "typesVersions": {
@@ -85,6 +115,15 @@
85
115
  ],
86
116
  "notifications": [
87
117
  "./dist/notifications/index.d.ts"
118
+ ],
119
+ "billing": [
120
+ "./dist/billing/index.d.ts"
121
+ ],
122
+ "next": [
123
+ "./dist/next/index.d.ts"
124
+ ],
125
+ "react": [
126
+ "./dist/react/index.d.ts"
88
127
  ]
89
128
  }
90
129
  },
@@ -93,13 +132,23 @@
93
132
  ],
94
133
  "license": "MIT",
95
134
  "scripts": {
96
- "build": "tsup",
135
+ "build": "rm -rf dist && tsup",
97
136
  "check-types": "tsc --noEmit",
98
137
  "check-publish": "bun pm pack --destination .tmp && bunx --bun @arethetypeswrong/cli --pack .tmp",
99
138
  "test": "bun run --bun vitest run",
100
139
  "test:watch": "bun run --bun vitest"
101
140
  },
141
+ "peerDependencies": {
142
+ "react": ">=19"
143
+ },
144
+ "peerDependenciesMeta": {
145
+ "react": {
146
+ "optional": true
147
+ }
148
+ },
102
149
  "devDependencies": {
150
+ "@types/react": "^19",
151
+ "react": "^19",
103
152
  "tsup": "^8.5.1",
104
153
  "typescript": "^5",
105
154
  "vitest": "^4.1.4"