@buildspacestudio/sdk 0.2.2 → 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 (106) hide show
  1. package/README.md +126 -0
  2. package/dist/auth/index.cjs +259 -0
  3. package/dist/auth/index.cjs.map +1 -0
  4. package/dist/auth/index.d.cts +3 -0
  5. package/dist/auth/index.d.ts +3 -5
  6. package/dist/auth/index.js +255 -2
  7. package/dist/auth/index.js.map +1 -1
  8. package/dist/billing/index.cjs +226 -0
  9. package/dist/billing/index.cjs.map +1 -0
  10. package/dist/billing/index.d.cts +60 -0
  11. package/dist/billing/index.d.ts +60 -0
  12. package/dist/billing/index.js +222 -0
  13. package/dist/billing/index.js.map +1 -0
  14. package/dist/client/index.cjs +558 -0
  15. package/dist/client/index.cjs.map +1 -0
  16. package/dist/client/index.d.cts +89 -0
  17. package/dist/client/index.d.ts +12 -7
  18. package/dist/client/index.js +546 -105
  19. package/dist/client/index.js.map +1 -1
  20. package/dist/client-BYUWUiGZ.d.cts +143 -0
  21. package/dist/{auth/client.d.ts → client-ByNR5EZz.d.ts} +7 -5
  22. package/dist/client-D0vypxWb.d.cts +58 -0
  23. package/dist/{auth/client.js → client-D7bqvGJv.d.cts} +27 -30
  24. package/dist/{events/client.d.ts → client-DbGRRMt7.d.ts} +5 -3
  25. package/dist/client-d7kX5WfR.d.ts +143 -0
  26. package/dist/events/index.cjs +131 -0
  27. package/dist/events/index.cjs.map +1 -0
  28. package/dist/events/{server.d.ts → index.d.cts} +7 -4
  29. package/dist/events/index.d.ts +59 -4
  30. package/dist/events/index.js +127 -2
  31. package/dist/events/index.js.map +1 -1
  32. package/dist/http-D2gXpNpr.d.cts +100 -0
  33. package/dist/http-D2gXpNpr.d.ts +100 -0
  34. package/dist/index.cjs +1029 -0
  35. package/dist/index.cjs.map +1 -0
  36. package/dist/index.d.cts +92 -0
  37. package/dist/index.d.ts +21 -15
  38. package/dist/index.js +1010 -106
  39. package/dist/index.js.map +1 -1
  40. package/dist/next/index.cjs +183 -0
  41. package/dist/next/index.cjs.map +1 -0
  42. package/dist/next/index.d.cts +164 -0
  43. package/dist/next/index.d.ts +164 -0
  44. package/dist/next/index.js +172 -0
  45. package/dist/next/index.js.map +1 -0
  46. package/dist/notifications/index.cjs +56 -0
  47. package/dist/notifications/index.cjs.map +1 -0
  48. package/dist/notifications/{server.d.ts → index.d.cts} +8 -6
  49. package/dist/notifications/index.d.ts +79 -3
  50. package/dist/notifications/index.js +53 -1
  51. package/dist/notifications/index.js.map +1 -1
  52. package/dist/react/index.cjs +120 -0
  53. package/dist/react/index.cjs.map +1 -0
  54. package/dist/react/index.d.cts +567 -0
  55. package/dist/react/index.d.ts +567 -0
  56. package/dist/react/index.js +92 -0
  57. package/dist/react/index.js.map +1 -0
  58. package/dist/server-CoPDzSUP.d.cts +117 -0
  59. package/dist/{auth/server.d.ts → server-Suq3tZZC.d.ts} +8 -6
  60. package/dist/storage/index.cjs +213 -0
  61. package/dist/storage/index.cjs.map +1 -0
  62. package/dist/storage/index.d.cts +195 -0
  63. package/dist/storage/index.d.ts +195 -5
  64. package/dist/storage/index.js +209 -2
  65. package/dist/storage/index.js.map +1 -1
  66. package/package.json +124 -16
  67. package/dist/auth/client.d.ts.map +0 -1
  68. package/dist/auth/client.js.map +0 -1
  69. package/dist/auth/index.d.ts.map +0 -1
  70. package/dist/auth/server.d.ts.map +0 -1
  71. package/dist/auth/server.js +0 -148
  72. package/dist/auth/server.js.map +0 -1
  73. package/dist/client/index.d.ts.map +0 -1
  74. package/dist/config.d.ts +0 -40
  75. package/dist/config.d.ts.map +0 -1
  76. package/dist/config.js +0 -27
  77. package/dist/config.js.map +0 -1
  78. package/dist/errors.d.ts +0 -31
  79. package/dist/errors.d.ts.map +0 -1
  80. package/dist/errors.js +0 -30
  81. package/dist/errors.js.map +0 -1
  82. package/dist/events/client.d.ts.map +0 -1
  83. package/dist/events/client.js +0 -97
  84. package/dist/events/client.js.map +0 -1
  85. package/dist/events/index.d.ts.map +0 -1
  86. package/dist/events/server.d.ts.map +0 -1
  87. package/dist/events/server.js +0 -65
  88. package/dist/events/server.js.map +0 -1
  89. package/dist/http.d.ts +0 -39
  90. package/dist/http.d.ts.map +0 -1
  91. package/dist/http.js +0 -74
  92. package/dist/http.js.map +0 -1
  93. package/dist/index.d.ts.map +0 -1
  94. package/dist/notifications/index.d.ts.map +0 -1
  95. package/dist/notifications/server.d.ts.map +0 -1
  96. package/dist/notifications/server.js +0 -73
  97. package/dist/notifications/server.js.map +0 -1
  98. package/dist/storage/client.d.ts +0 -91
  99. package/dist/storage/client.d.ts.map +0 -1
  100. package/dist/storage/client.js +0 -117
  101. package/dist/storage/client.js.map +0 -1
  102. package/dist/storage/index.d.ts.map +0 -1
  103. package/dist/storage/server.d.ts +0 -104
  104. package/dist/storage/server.d.ts.map +0 -1
  105. package/dist/storage/server.js +0 -104
  106. package/dist/storage/server.js.map +0 -1
@@ -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 };
@@ -1,6 +1,7 @@
1
- import type { HttpTransport } from "../http";
1
+ import { H as HttpTransport } from './http-D2gXpNpr.js';
2
+
2
3
  /** A Buildspace user returned from auth endpoints. */
3
- export interface AuthUser {
4
+ interface AuthUser {
4
5
  /** The user's email address. */
5
6
  email: string;
6
7
  /** Unique user identifier. */
@@ -13,7 +14,7 @@ export interface AuthUser {
13
14
  *
14
15
  * Returned by {@link AuthServerNamespace.getSession}.
15
16
  */
16
- export interface AuthSession {
17
+ interface AuthSession {
17
18
  /** The app this session belongs to, or `null` for platform-level sessions. */
18
19
  appId: string | null;
19
20
  /** The authenticated user. */
@@ -24,7 +25,7 @@ export interface AuthSession {
24
25
  *
25
26
  * Returned by {@link AuthServerNamespace.handleCallback}.
26
27
  */
27
- export interface TokenResponse {
28
+ interface TokenResponse {
28
29
  /** The access token to use for authenticated requests. */
29
30
  access_token: string;
30
31
  /** Token lifetime in seconds. */
@@ -55,7 +56,7 @@ export interface TokenResponse {
55
56
  * await buildspace.auth.signOut(sessionToken);
56
57
  * ```
57
58
  */
58
- export declare class AuthServerNamespace {
59
+ declare class AuthServerNamespace {
59
60
  private readonly transport;
60
61
  constructor(transport: HttpTransport);
61
62
  /**
@@ -112,4 +113,5 @@ export declare class AuthServerNamespace {
112
113
  */
113
114
  signOut(sessionToken?: string): Promise<void>;
114
115
  }
115
- //# sourceMappingURL=server.d.ts.map
116
+
117
+ export { AuthServerNamespace as A, type TokenResponse as T, type AuthSession as a, type AuthUser as b };
@@ -0,0 +1,213 @@
1
+ 'use strict';
2
+
3
+ // src/errors.ts
4
+ var BuildspaceError = class extends Error {
5
+ /** Machine-readable error code, e.g. `"auth/invalid-token"`. */
6
+ code;
7
+ /** Which service produced the error. */
8
+ service;
9
+ /** HTTP status code from the API. */
10
+ status;
11
+ constructor({
12
+ code,
13
+ message,
14
+ service,
15
+ status
16
+ }) {
17
+ super(message);
18
+ this.name = "BuildspaceError";
19
+ this.code = code;
20
+ this.service = service;
21
+ this.status = status;
22
+ }
23
+ };
24
+
25
+ // src/storage/client.ts
26
+ var StorageClientNamespace = class {
27
+ transport;
28
+ constructor(transport) {
29
+ this.transport = transport;
30
+ }
31
+ /**
32
+ * Upload a `File` or `Blob` to Buildspace storage.
33
+ *
34
+ * This method handles the full upload flow:
35
+ * 1. Requests a pre-signed upload URL from the API
36
+ * 2. Uploads the file directly to the storage provider
37
+ * 3. Returns a signed download URL for the uploaded file
38
+ *
39
+ * @param file - The file or blob to upload.
40
+ * @param opts - Upload options including the storage path.
41
+ * @returns The storage key, file size, and a signed download URL.
42
+ *
43
+ * @throws {BuildspaceError} If the upload URL request or the direct upload fails.
44
+ */
45
+ async upload(file, opts) {
46
+ const contentType = opts.contentType ?? (file instanceof File ? file.type : "application/octet-stream");
47
+ const signed = await this.transport.request({
48
+ service: "storage",
49
+ path: "/v1/storage/upload",
50
+ method: "POST",
51
+ body: {
52
+ path: opts.path,
53
+ content_type: contentType,
54
+ size: file.size
55
+ }
56
+ });
57
+ const response = await this.transport.fetcher(signed.upload_url, {
58
+ method: "PUT",
59
+ headers: { "Content-Type": contentType },
60
+ body: file
61
+ });
62
+ if (!response.ok) {
63
+ throw new BuildspaceError({
64
+ service: "storage",
65
+ status: response.status,
66
+ code: "storage/upload-failed",
67
+ message: `Direct upload failed: ${response.statusText}`
68
+ });
69
+ }
70
+ const { url } = await this.getUrl(signed.key);
71
+ return {
72
+ key: signed.key,
73
+ size: file.size,
74
+ url
75
+ };
76
+ }
77
+ /**
78
+ * Get a time-limited signed URL for downloading a stored file.
79
+ *
80
+ * @param key - The storage key of the object.
81
+ * @param opts - Optional settings.
82
+ * @param opts.expiresIn - URL lifetime in seconds.
83
+ */
84
+ getUrl(key, opts) {
85
+ return this.transport.request({
86
+ service: "storage",
87
+ path: "/v1/storage/url",
88
+ query: {
89
+ key,
90
+ expires_in: opts?.expiresIn
91
+ }
92
+ });
93
+ }
94
+ /**
95
+ * List stored objects, optionally filtered by key prefix.
96
+ *
97
+ * @param prefix - Only return objects whose key starts with this prefix.
98
+ * @param opts - Pagination options.
99
+ */
100
+ list(prefix, opts) {
101
+ return this.transport.request({
102
+ service: "storage",
103
+ path: "/v1/storage/objects",
104
+ query: {
105
+ prefix,
106
+ limit: opts?.limit,
107
+ offset: opts?.offset
108
+ }
109
+ });
110
+ }
111
+ /**
112
+ * Delete a stored object by key.
113
+ *
114
+ * @param key - The storage key of the object to delete.
115
+ */
116
+ async delete(key) {
117
+ await this.transport.request({
118
+ service: "storage",
119
+ path: "/v1/storage/object",
120
+ method: "DELETE",
121
+ body: { key }
122
+ });
123
+ }
124
+ };
125
+
126
+ // src/storage/server.ts
127
+ var StorageServerNamespace = class {
128
+ transport;
129
+ constructor(transport) {
130
+ this.transport = transport;
131
+ }
132
+ /**
133
+ * Request a pre-signed URL for direct file upload.
134
+ *
135
+ * @param opts - Upload options including the storage key, content type, and file size.
136
+ * @returns The signed upload URL, the resolved key, and expiry time in seconds.
137
+ */
138
+ getUploadUrl(opts) {
139
+ return this.transport.request({
140
+ service: "storage",
141
+ path: "/v1/storage/upload",
142
+ method: "POST",
143
+ body: {
144
+ path: opts.key,
145
+ content_type: opts.contentType,
146
+ size: opts.size
147
+ }
148
+ });
149
+ }
150
+ /**
151
+ * Get a time-limited signed URL for downloading a stored file.
152
+ *
153
+ * @param key - The storage key of the object.
154
+ * @param opts - Optional settings.
155
+ * @param opts.expiresIn - URL lifetime in seconds. Uses server default if omitted.
156
+ */
157
+ getSignedUrl(key, opts) {
158
+ return this.transport.request({
159
+ service: "storage",
160
+ path: "/v1/storage/url",
161
+ query: {
162
+ key,
163
+ expires_in: opts?.expiresIn
164
+ }
165
+ });
166
+ }
167
+ /**
168
+ * List stored objects, optionally filtered by key prefix.
169
+ *
170
+ * @param prefix - Only return objects whose key starts with this prefix, e.g. `"avatars/"`.
171
+ * @param opts - Pagination options.
172
+ */
173
+ list(prefix, opts) {
174
+ return this.transport.request({
175
+ service: "storage",
176
+ path: "/v1/storage/objects",
177
+ query: {
178
+ prefix,
179
+ limit: opts?.limit,
180
+ offset: opts?.offset
181
+ }
182
+ });
183
+ }
184
+ /**
185
+ * Delete a stored object by key.
186
+ *
187
+ * @param key - The storage key of the object to delete.
188
+ */
189
+ async delete(key) {
190
+ await this.transport.request({
191
+ service: "storage",
192
+ path: "/v1/storage/object",
193
+ method: "DELETE",
194
+ body: { key }
195
+ });
196
+ }
197
+ /**
198
+ * Get current storage usage statistics for the app.
199
+ *
200
+ * @returns Byte counts and object count.
201
+ */
202
+ getUsage() {
203
+ return this.transport.request({
204
+ service: "storage",
205
+ path: "/v1/storage/usage"
206
+ });
207
+ }
208
+ };
209
+
210
+ exports.StorageClientNamespace = StorageClientNamespace;
211
+ exports.StorageServerNamespace = StorageServerNamespace;
212
+ //# sourceMappingURL=index.cjs.map
213
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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;A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AA,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\" | \"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"]}
@@ -0,0 +1,195 @@
1
+ import { H as HttpTransport } from '../http-D2gXpNpr.cjs';
2
+
3
+ /** Options for requesting a pre-signed upload URL on the server. */
4
+ interface ServerUploadOptions {
5
+ /** MIME type of the file, e.g. `"image/png"`. */
6
+ contentType: string;
7
+ /** Storage path/key for the file, e.g. `"avatars/user-123.png"`. */
8
+ key: string;
9
+ /** File size in bytes. */
10
+ size: number;
11
+ }
12
+ /** Metadata for a stored object. */
13
+ interface StorageObject {
14
+ /** MIME type of the stored file. */
15
+ contentType: string;
16
+ /** ISO 8601 timestamp of when the object was created. */
17
+ createdAt: string;
18
+ /** Unique object identifier. */
19
+ id: string;
20
+ /** Storage key/path of the object. */
21
+ key: string;
22
+ /** File size in bytes. */
23
+ size: number;
24
+ /** ID of the user who uploaded the object, or `null` if uploaded via server key. */
25
+ uploadedBy: string | null;
26
+ }
27
+ /**
28
+ * Server-side storage methods for managing file uploads and downloads.
29
+ *
30
+ * Access via `buildspace.storage` on the server SDK.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * // Get a pre-signed upload URL
35
+ * const { upload_url, key } = await buildspace.storage.getUploadUrl({
36
+ * key: "avatars/user-123.png",
37
+ * contentType: "image/png",
38
+ * size: file.size,
39
+ * });
40
+ *
41
+ * // Upload directly to the signed URL
42
+ * await fetch(upload_url, { method: "PUT", body: file });
43
+ *
44
+ * // Get a signed download URL
45
+ * const { url } = await buildspace.storage.getSignedUrl(key);
46
+ * ```
47
+ */
48
+ declare class StorageServerNamespace {
49
+ private readonly transport;
50
+ constructor(transport: HttpTransport);
51
+ /**
52
+ * Request a pre-signed URL for direct file upload.
53
+ *
54
+ * @param opts - Upload options including the storage key, content type, and file size.
55
+ * @returns The signed upload URL, the resolved key, and expiry time in seconds.
56
+ */
57
+ getUploadUrl(opts: ServerUploadOptions): Promise<{
58
+ expires_in: number;
59
+ key: string;
60
+ upload_url: string;
61
+ }>;
62
+ /**
63
+ * Get a time-limited signed URL for downloading a stored file.
64
+ *
65
+ * @param key - The storage key of the object.
66
+ * @param opts - Optional settings.
67
+ * @param opts.expiresIn - URL lifetime in seconds. Uses server default if omitted.
68
+ */
69
+ getSignedUrl(key: string, opts?: {
70
+ expiresIn?: number;
71
+ }): Promise<{
72
+ expiresIn?: number;
73
+ key: string;
74
+ url: string;
75
+ }>;
76
+ /**
77
+ * List stored objects, optionally filtered by key prefix.
78
+ *
79
+ * @param prefix - Only return objects whose key starts with this prefix, e.g. `"avatars/"`.
80
+ * @param opts - Pagination options.
81
+ */
82
+ list(prefix?: string, opts?: {
83
+ limit?: number;
84
+ offset?: number;
85
+ }): Promise<{
86
+ objects: StorageObject[];
87
+ }>;
88
+ /**
89
+ * Delete a stored object by key.
90
+ *
91
+ * @param key - The storage key of the object to delete.
92
+ */
93
+ delete(key: string): Promise<void>;
94
+ /**
95
+ * Get current storage usage statistics for the app.
96
+ *
97
+ * @returns Byte counts and object count.
98
+ */
99
+ getUsage(): Promise<{
100
+ maxStorageBytes: number;
101
+ objectCount: number;
102
+ storageBytes: number;
103
+ }>;
104
+ }
105
+
106
+ /** Options for uploading a file from the client. */
107
+ interface UploadOptions {
108
+ /** MIME type override. If omitted, inferred from the `File` object or defaults to `"application/octet-stream"`. */
109
+ contentType?: string;
110
+ /** Storage path/key for the file, e.g. `"avatars/user-123.png"`. */
111
+ path: string;
112
+ }
113
+ /** Result of a successful client-side file upload. */
114
+ interface UploadResponse {
115
+ /** The resolved storage key. */
116
+ key: string;
117
+ /** File size in bytes. */
118
+ size: number;
119
+ /** Signed download URL for the uploaded file. */
120
+ url: string;
121
+ }
122
+ /** Result of requesting a signed download URL. */
123
+ interface GetUrlResponse {
124
+ /** URL lifetime in seconds, if applicable. */
125
+ expiresIn?: number;
126
+ /** The storage key of the object. */
127
+ key: string;
128
+ /** The signed download URL. */
129
+ url: string;
130
+ }
131
+ /**
132
+ * Client-side storage methods for uploading and managing files.
133
+ *
134
+ * Access via `buildspace.storage` on the client SDK.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * // Upload a file (handles signed URL + PUT automatically)
139
+ * const { key, url } = await buildspace.storage.upload(file, {
140
+ * path: "avatars/user-123.png",
141
+ * });
142
+ *
143
+ * // Get a download URL for an existing file
144
+ * const { url } = await buildspace.storage.getUrl(key);
145
+ * ```
146
+ */
147
+ declare class StorageClientNamespace {
148
+ private readonly transport;
149
+ constructor(transport: HttpTransport);
150
+ /**
151
+ * Upload a `File` or `Blob` to Buildspace storage.
152
+ *
153
+ * This method handles the full upload flow:
154
+ * 1. Requests a pre-signed upload URL from the API
155
+ * 2. Uploads the file directly to the storage provider
156
+ * 3. Returns a signed download URL for the uploaded file
157
+ *
158
+ * @param file - The file or blob to upload.
159
+ * @param opts - Upload options including the storage path.
160
+ * @returns The storage key, file size, and a signed download URL.
161
+ *
162
+ * @throws {BuildspaceError} If the upload URL request or the direct upload fails.
163
+ */
164
+ upload(file: File | Blob, opts: UploadOptions): Promise<UploadResponse>;
165
+ /**
166
+ * Get a time-limited signed URL for downloading a stored file.
167
+ *
168
+ * @param key - The storage key of the object.
169
+ * @param opts - Optional settings.
170
+ * @param opts.expiresIn - URL lifetime in seconds.
171
+ */
172
+ getUrl(key: string, opts?: {
173
+ expiresIn?: number;
174
+ }): Promise<GetUrlResponse>;
175
+ /**
176
+ * List stored objects, optionally filtered by key prefix.
177
+ *
178
+ * @param prefix - Only return objects whose key starts with this prefix.
179
+ * @param opts - Pagination options.
180
+ */
181
+ list(prefix?: string, opts?: {
182
+ limit?: number;
183
+ offset?: number;
184
+ }): Promise<{
185
+ objects: StorageObject[];
186
+ }>;
187
+ /**
188
+ * Delete a stored object by key.
189
+ *
190
+ * @param key - The storage key of the object to delete.
191
+ */
192
+ delete(key: string): Promise<void>;
193
+ }
194
+
195
+ export { type GetUrlResponse, type ServerUploadOptions, StorageClientNamespace, type StorageObject, StorageServerNamespace, type UploadOptions, type UploadResponse };