@buildspacestudio/sdk 0.2.2 → 0.3.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 (83) hide show
  1. package/dist/auth/index.cjs +259 -0
  2. package/dist/auth/index.cjs.map +1 -0
  3. package/dist/auth/{server.d.ts → index.d.cts} +9 -6
  4. package/dist/auth/index.d.ts +118 -5
  5. package/dist/auth/index.js +255 -2
  6. package/dist/auth/index.js.map +1 -1
  7. package/dist/client/index.cjs +428 -0
  8. package/dist/client/index.cjs.map +1 -0
  9. package/dist/client/index.d.cts +85 -0
  10. package/dist/client/index.d.ts +8 -7
  11. package/dist/client/index.js +416 -105
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/{auth/client.d.ts → client-BH7LbrKM.d.ts} +7 -5
  14. package/dist/client-C67hy1kt.d.cts +58 -0
  15. package/dist/{events/client.d.ts → client-Dlif1JBf.d.ts} +5 -3
  16. package/dist/{auth/client.js → client-DqWXAwCr.d.cts} +27 -30
  17. package/dist/events/index.cjs +131 -0
  18. package/dist/events/index.cjs.map +1 -0
  19. package/dist/events/{server.d.ts → index.d.cts} +7 -4
  20. package/dist/events/index.d.ts +59 -4
  21. package/dist/events/index.js +127 -2
  22. package/dist/events/index.js.map +1 -1
  23. package/dist/http-U-zzKmFF.d.cts +100 -0
  24. package/dist/http-U-zzKmFF.d.ts +100 -0
  25. package/dist/index.cjs +801 -0
  26. package/dist/index.cjs.map +1 -0
  27. package/dist/index.d.cts +87 -0
  28. package/dist/index.d.ts +16 -15
  29. package/dist/index.js +785 -106
  30. package/dist/index.js.map +1 -1
  31. package/dist/notifications/index.cjs +56 -0
  32. package/dist/notifications/index.cjs.map +1 -0
  33. package/dist/notifications/{server.d.ts → index.d.cts} +8 -6
  34. package/dist/notifications/index.d.ts +79 -3
  35. package/dist/notifications/index.js +53 -1
  36. package/dist/notifications/index.js.map +1 -1
  37. package/dist/storage/index.cjs +213 -0
  38. package/dist/storage/index.cjs.map +1 -0
  39. package/dist/storage/index.d.cts +195 -0
  40. package/dist/storage/index.d.ts +195 -5
  41. package/dist/storage/index.js +209 -2
  42. package/dist/storage/index.js.map +1 -1
  43. package/package.json +75 -16
  44. package/dist/auth/client.d.ts.map +0 -1
  45. package/dist/auth/client.js.map +0 -1
  46. package/dist/auth/index.d.ts.map +0 -1
  47. package/dist/auth/server.d.ts.map +0 -1
  48. package/dist/auth/server.js +0 -148
  49. package/dist/auth/server.js.map +0 -1
  50. package/dist/client/index.d.ts.map +0 -1
  51. package/dist/config.d.ts +0 -40
  52. package/dist/config.d.ts.map +0 -1
  53. package/dist/config.js +0 -27
  54. package/dist/config.js.map +0 -1
  55. package/dist/errors.d.ts +0 -31
  56. package/dist/errors.d.ts.map +0 -1
  57. package/dist/errors.js +0 -30
  58. package/dist/errors.js.map +0 -1
  59. package/dist/events/client.d.ts.map +0 -1
  60. package/dist/events/client.js +0 -97
  61. package/dist/events/client.js.map +0 -1
  62. package/dist/events/index.d.ts.map +0 -1
  63. package/dist/events/server.d.ts.map +0 -1
  64. package/dist/events/server.js +0 -65
  65. package/dist/events/server.js.map +0 -1
  66. package/dist/http.d.ts +0 -39
  67. package/dist/http.d.ts.map +0 -1
  68. package/dist/http.js +0 -74
  69. package/dist/http.js.map +0 -1
  70. package/dist/index.d.ts.map +0 -1
  71. package/dist/notifications/index.d.ts.map +0 -1
  72. package/dist/notifications/server.d.ts.map +0 -1
  73. package/dist/notifications/server.js +0 -73
  74. package/dist/notifications/server.js.map +0 -1
  75. package/dist/storage/client.d.ts +0 -91
  76. package/dist/storage/client.d.ts.map +0 -1
  77. package/dist/storage/client.js +0 -117
  78. package/dist/storage/client.js.map +0 -1
  79. package/dist/storage/index.d.ts.map +0 -1
  80. package/dist/storage/server.d.ts +0 -104
  81. package/dist/storage/server.d.ts.map +0 -1
  82. package/dist/storage/server.js +0 -104
  83. package/dist/storage/server.js.map +0 -1
@@ -0,0 +1,100 @@
1
+ type ClientMode = "server" | "client";
2
+ /** Configuration options for the server SDK (`new Buildspace()`). */
3
+ interface BuildspaceConfig {
4
+ /** Base URL of the Buildspace API. Defaults to `"https://api.buildspace.studio"`. */
5
+ baseUrl?: string;
6
+ /** Custom `fetch` implementation (useful for testing or edge runtimes). */
7
+ fetch?: typeof fetch;
8
+ /** Base URL of the Buildspace login service. Defaults to `"https://login.buildspace.studio"`. */
9
+ loginUrl?: string;
10
+ /** API version string sent via the `X-Buildspace-Version` header. Defaults to `"2025-06-01"`. */
11
+ version?: string;
12
+ }
13
+ /** Configuration for client-side event batching behavior. */
14
+ interface EventsBatchingConfig {
15
+ /** How often queued events are flushed to the API, in milliseconds. Defaults to `5000`. */
16
+ flushInterval?: number;
17
+ /** Maximum number of events to queue before an automatic flush. Defaults to `20`. */
18
+ maxBatchSize?: number;
19
+ }
20
+ /** Configuration options for the client SDK (`createClient()`). */
21
+ interface BuildspaceClientConfig extends BuildspaceConfig {
22
+ /** Options for client-side event batching. */
23
+ events?: EventsBatchingConfig;
24
+ }
25
+ interface ResolvedConfig {
26
+ baseUrl: string;
27
+ fetch: typeof fetch;
28
+ loginUrl: string;
29
+ mode: ClientMode;
30
+ version: string;
31
+ }
32
+
33
+ /** Services available in the Buildspace platform. */
34
+ type BuildspaceService = "auth" | "events" | "notifications" | "storage";
35
+ /**
36
+ * Error thrown by all Buildspace SDK methods on failure.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * try {
41
+ * await buildspace.auth.getSession(token);
42
+ * } catch (err) {
43
+ * if (err instanceof BuildspaceError) {
44
+ * console.error(err.service, err.code, err.status, err.message);
45
+ * }
46
+ * }
47
+ * ```
48
+ */
49
+ declare class BuildspaceError extends Error {
50
+ /** Machine-readable error code, e.g. `"auth/invalid-token"`. */
51
+ readonly code: string;
52
+ /** Which service produced the error. */
53
+ readonly service: BuildspaceService;
54
+ /** HTTP status code from the API. */
55
+ readonly status: number;
56
+ constructor({ code, message, service, status, }: {
57
+ code: string;
58
+ message: string;
59
+ service: BuildspaceService;
60
+ status: number;
61
+ });
62
+ }
63
+
64
+ interface RequestOptions {
65
+ body?: unknown;
66
+ headers?: Record<string, string>;
67
+ keepalive?: boolean;
68
+ method?: string;
69
+ path: string;
70
+ query?: Record<string, string | number | boolean | undefined>;
71
+ service: BuildspaceService;
72
+ }
73
+ /**
74
+ * Low-level HTTP transport used internally by all SDK namespaces.
75
+ *
76
+ * Handles authentication headers, API versioning, session tokens,
77
+ * and consistent error mapping to {@link BuildspaceError}.
78
+ */
79
+ declare class HttpTransport {
80
+ readonly baseUrl: string;
81
+ readonly fetcher: typeof fetch;
82
+ readonly key: string;
83
+ readonly loginUrl: string;
84
+ readonly mode: ClientMode;
85
+ readonly version: string;
86
+ private sessionToken;
87
+ constructor({ key, resolvedConfig }: {
88
+ key: string;
89
+ resolvedConfig: ResolvedConfig;
90
+ });
91
+ /** Remove the stored session token. */
92
+ clearSession(): void;
93
+ /** Return the current session token, or `null` if none is set. */
94
+ getSessionToken(): string | null;
95
+ /** Store a session token that will be sent as `X-Session-Token` on subsequent requests. */
96
+ setSession(sessionToken: string): void;
97
+ request<T>({ service, path, method, query, body, headers, keepalive, }: RequestOptions): Promise<T>;
98
+ }
99
+
100
+ export { type BuildspaceConfig as B, HttpTransport as H, type BuildspaceClientConfig as a, BuildspaceError as b, type BuildspaceService as c };