@buildspacestudio/sdk 0.2.1 → 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
package/package.json CHANGED
@@ -1,34 +1,91 @@
1
1
  {
2
2
  "name": "@buildspacestudio/sdk",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
- "main": "./dist/index.js",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
6
7
  "types": "./dist/index.d.ts",
7
8
  "sideEffects": false,
8
9
  "exports": {
9
10
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "default": "./dist/index.js"
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
12
19
  },
13
20
  "./client": {
14
- "types": "./dist/client/index.d.ts",
15
- "default": "./dist/client/index.js"
21
+ "import": {
22
+ "types": "./dist/client/index.d.ts",
23
+ "default": "./dist/client/index.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/client/index.d.cts",
27
+ "default": "./dist/client/index.cjs"
28
+ }
16
29
  },
17
30
  "./auth": {
18
- "types": "./dist/auth/index.d.ts",
19
- "default": "./dist/auth/index.js"
31
+ "import": {
32
+ "types": "./dist/auth/index.d.ts",
33
+ "default": "./dist/auth/index.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/auth/index.d.cts",
37
+ "default": "./dist/auth/index.cjs"
38
+ }
20
39
  },
21
40
  "./events": {
22
- "types": "./dist/events/index.d.ts",
23
- "default": "./dist/events/index.js"
41
+ "import": {
42
+ "types": "./dist/events/index.d.ts",
43
+ "default": "./dist/events/index.js"
44
+ },
45
+ "require": {
46
+ "types": "./dist/events/index.d.cts",
47
+ "default": "./dist/events/index.cjs"
48
+ }
24
49
  },
25
50
  "./storage": {
26
- "types": "./dist/storage/index.d.ts",
27
- "default": "./dist/storage/index.js"
51
+ "import": {
52
+ "types": "./dist/storage/index.d.ts",
53
+ "default": "./dist/storage/index.js"
54
+ },
55
+ "require": {
56
+ "types": "./dist/storage/index.d.cts",
57
+ "default": "./dist/storage/index.cjs"
58
+ }
28
59
  },
29
60
  "./notifications": {
30
- "types": "./dist/notifications/index.d.ts",
31
- "default": "./dist/notifications/index.js"
61
+ "import": {
62
+ "types": "./dist/notifications/index.d.ts",
63
+ "default": "./dist/notifications/index.js"
64
+ },
65
+ "require": {
66
+ "types": "./dist/notifications/index.d.cts",
67
+ "default": "./dist/notifications/index.cjs"
68
+ }
69
+ },
70
+ "./package.json": "./package.json"
71
+ },
72
+ "typesVersions": {
73
+ "*": {
74
+ "client": [
75
+ "./dist/client/index.d.ts"
76
+ ],
77
+ "auth": [
78
+ "./dist/auth/index.d.ts"
79
+ ],
80
+ "events": [
81
+ "./dist/events/index.d.ts"
82
+ ],
83
+ "storage": [
84
+ "./dist/storage/index.d.ts"
85
+ ],
86
+ "notifications": [
87
+ "./dist/notifications/index.d.ts"
88
+ ]
32
89
  }
33
90
  },
34
91
  "files": [
@@ -36,13 +93,15 @@
36
93
  ],
37
94
  "license": "MIT",
38
95
  "scripts": {
39
- "build": "tsc",
96
+ "build": "tsup",
40
97
  "check-types": "tsc --noEmit",
98
+ "check-publish": "bun pm pack --destination .tmp && bunx --bun @arethetypeswrong/cli --pack .tmp",
41
99
  "test": "bun run --bun vitest run",
42
100
  "test:watch": "bun run --bun vitest"
43
101
  },
44
102
  "devDependencies": {
103
+ "tsup": "^8.5.1",
45
104
  "typescript": "^5",
46
- "vitest": "^4.1.0"
105
+ "vitest": "^4.1.4"
47
106
  }
48
107
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/auth/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,4CAA4C;AAC5C,MAAM,WAAW,gBAAgB;IAC/B,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,kEAAkE;IAClE,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,4CAA4C;A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AAY,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;IAED;;;;;;;;OAQG;IACH,YAAY,CAAC,IAAsB;QACjC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAEzD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5C,CAAC;QAED,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACvD,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAEtD,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YACb,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;CACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/auth/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAA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spaceError } from "../errors";
2
- /**
3
- * Server-side authentication methods.
4
- *
5
- * Access via `buildspace.auth` on the server SDK.
6
- *
7
- * @example
8
- * ```ts
9
- * import Buildspace from "@buildspacestudio/sdk";
10
- *
11
- * const buildspace = new Buildspace(process.env.BUILDSPACE_SECRET_KEY!);
12
- *
13
- * // Handle OAuth callback
14
- * const tokens = await buildspace.auth.handleCallback(request);
15
- *
16
- * // Verify a session
17
- * const session = await buildspace.auth.getSession(sessionToken);
18
- *
19
- * // Sign out
20
- * await buildspace.auth.signOut(sessionToken);
21
- * ```
22
- */
23
- export class AuthServerNamespace {
24
- transport;
25
- constructor(transport) {
26
- this.transport = transport;
27
- }
28
- /**
29
- * Retrieve the session associated with a token.
30
- *
31
- * Returns the {@link AuthSession} if valid, or `null` if the token is
32
- * expired, revoked, or invalid (401/404).
33
- *
34
- * @throws {BuildspaceError} On unexpected server errors (5xx, network issues).
35
- */
36
- async getSession(sessionToken) {
37
- try {
38
- return await this.transport.request({
39
- service: "auth",
40
- path: "/v1/auth/session",
41
- headers: { "X-Session-Token": sessionToken },
42
- });
43
- }
44
- catch (error) {
45
- if (error instanceof BuildspaceError && (error.status === 401 || error.status === 404)) {
46
- return null;
47
- }
48
- throw error;
49
- }
50
- }
51
- /**
52
- * Exchange an OAuth authorization code for tokens.
53
- *
54
- * Extracts the `code` query parameter from the callback URL and exchanges
55
- * it with the Buildspace API for an access token and user info.
56
- *
57
- * @param request - The incoming callback request. Accepts a `Request` object,
58
- * a `URL`, or a raw URL string containing the `?code=` parameter.
59
- * @param opts - Optional settings.
60
- * @param opts.redirectUri - Override the redirect URI sent to the token endpoint.
61
- * Defaults to the origin + pathname of the callback URL.
62
- * @returns The token response containing `access_token`, `expires_in`, and `user`.
63
- *
64
- * @throws {BuildspaceError} If the code exchange fails (invalid code, expired, etc.).
65
- *
66
- * @example
67
- * ```ts
68
- * // Next.js Route Handler
69
- * export async function GET(request: Request) {
70
- * const { access_token, user } = await buildspace.auth.handleCallback(request);
71
- * // Store access_token as a session cookie
72
- * }
73
- * ```
74
- */
75
- handleCallback(request, opts) {
76
- let url;
77
- if (typeof request === "string") {
78
- url = new URL(request);
79
- }
80
- else if (request instanceof URL) {
81
- url = request;
82
- }
83
- else {
84
- url = new URL(request.url);
85
- }
86
- const code = url.searchParams.get("code");
87
- if (!code) {
88
- throw new BuildspaceError({
89
- service: "auth",
90
- status: 400,
91
- code: "auth/missing-code",
92
- message: "No auth code found in callback URL. Expected ?code= parameter.",
93
- });
94
- }
95
- const redirectUri = opts?.redirectUri ?? `${url.origin}${url.pathname}`;
96
- return this.transport.request({
97
- service: "auth",
98
- path: "/v1/auth/token",
99
- method: "POST",
100
- body: {
101
- code,
102
- redirect_uri: redirectUri,
103
- },
104
- });
105
- }
106
- /**
107
- * Revoke a specific session token.
108
- *
109
- * @param sessionToken - The token to revoke.
110
- * @throws {BuildspaceError} If the revocation fails.
111
- */
112
- async revokeSession(sessionToken) {
113
- await this.transport.request({
114
- service: "auth",
115
- path: "/v1/auth/session",
116
- method: "DELETE",
117
- headers: { "X-Session-Token": sessionToken },
118
- });
119
- }
120
- /**
121
- * Sign the user out by revoking the session and clearing the SDK's stored token.
122
- *
123
- * If the session is already expired or not found, the error is silently
124
- * ignored and the local session is still cleared.
125
- *
126
- * @param sessionToken - Token to revoke. If omitted, uses the token
127
- * previously set via `buildspace.setSession()`.
128
- */
129
- async signOut(sessionToken) {
130
- const token = sessionToken ?? this.transport.getSessionToken();
131
- try {
132
- if (token) {
133
- await this.revokeSession(token);
134
- }
135
- }
136
- catch (error) {
137
- if (!(error instanceof BuildspaceError &&
138
- error.service === "auth" &&
139
- (error.status === 401 || error.status === 404))) {
140
- throw error;
141
- }
142
- }
143
- finally {
144
- this.transport.clearSession();
145
- }
146
- }
147
- }
148
- //# sourceMappingURL=server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/auth/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA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SAAS,CAAC,YAAY,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;CACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,KAAK,sBAAsB,EAAiB,MAAM,WAAW,CAAC;AAEvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAElD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,cAAM,gBAAgB;IACpB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;IAChD,OAAO,CAAC,KAAK,CAAoC;IACjD,OAAO,CAAC,OAAO,CAAsC;IACrD,OAAO,CAAC,QAAQ,CAAuC;IAEvD;;;;;OAKG;gBACS,cAAc,EAAE,MAAM,EAAE,MAAM,GAAE,sBAA2B;IAQvE,4DAA4D;IAC5D,IAAI,IAAI,IAAI,mBAAmB,CAG9B;IAED,0DAA0D;IAC1D,IAAI,MAAM,IAAI,qBAAqB,CAGlC;IAED,uEAAuE;IACvE,IAAI,OAAO,IAAI,sBAAsB,CAGpC;IAED;;;;OAIG;IACH,IAAI,aAAa,IAAI,KAAK,CAQzB;IAED,sCAAsC;IACtC,YAAY,IAAI,IAAI;IAIpB;;;;;OAKG;IACH,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;CAGvC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAC1B,cAAc,EAAE,MAAM,EACtB,MAAM,GAAE,sBAA2B,GAClC,gBAAgB,CAElB;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
package/dist/config.d.ts DELETED
@@ -1,40 +0,0 @@
1
- export declare const DEFAULT_BASE_URL = "https://api.buildspace.studio";
2
- export declare const DEFAULT_LOGIN_URL = "https://login.buildspace.studio";
3
- export declare const DEFAULT_API_VERSION = "2025-06-01";
4
- export type ClientMode = "server" | "client";
5
- /** Configuration options for the server SDK (`new Buildspace()`). */
6
- export interface BuildspaceConfig {
7
- /** Base URL of the Buildspace API. Defaults to `"https://api.buildspace.studio"`. */
8
- baseUrl?: string;
9
- /** Custom `fetch` implementation (useful for testing or edge runtimes). */
10
- fetch?: typeof fetch;
11
- /** Base URL of the Buildspace login service. Defaults to `"https://login.buildspace.studio"`. */
12
- loginUrl?: string;
13
- /** API version string sent via the `X-Buildspace-Version` header. Defaults to `"2025-06-01"`. */
14
- version?: string;
15
- }
16
- /** Configuration for client-side event batching behavior. */
17
- export interface EventsBatchingConfig {
18
- /** How often queued events are flushed to the API, in milliseconds. Defaults to `5000`. */
19
- flushInterval?: number;
20
- /** Maximum number of events to queue before an automatic flush. Defaults to `20`. */
21
- maxBatchSize?: number;
22
- }
23
- /** Configuration options for the client SDK (`createClient()`). */
24
- export interface BuildspaceClientConfig extends BuildspaceConfig {
25
- /** Options for client-side event batching. */
26
- events?: EventsBatchingConfig;
27
- }
28
- export interface ResolvedConfig {
29
- baseUrl: string;
30
- fetch: typeof fetch;
31
- loginUrl: string;
32
- mode: ClientMode;
33
- version: string;
34
- }
35
- export declare function resolveConfig(mode: ClientMode, config?: BuildspaceConfig): ResolvedConfig;
36
- export declare function validateApiKey({ mode, key }: {
37
- key: string;
38
- mode: ClientMode;
39
- }): void;
40
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,kCAAkC,CAAC;AAChE,eAAO,MAAM,iBAAiB,oCAAoC,CAAC;AACnE,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAEhD,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE7C,qEAAqE;AACrE,MAAM,WAAW,gBAAgB;IAC/B,qFAAqF;IACrF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,iGAAiG;IACjG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iGAAiG;IACjG,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,6DAA6D;AAC7D,MAAM,WAAW,oBAAoB;IACnC,2FAA2F;IAC3F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qFAAqF;IACrF,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,mEAAmE;AACnE,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC9D,8CAA8C;IAC9C,MAAM,CAAC,EAAE,oBAAoB,CAAC;CAC/B;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,GAAE,gBAAqB,GAAG,cAAc,CAQ7F;AAMD,wBAAgB,cAAc,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,GAAG,IAAI,CAgBrF"}
package/dist/config.js DELETED
@@ -1,27 +0,0 @@
1
- export const DEFAULT_BASE_URL = "https://api.buildspace.studio";
2
- export const DEFAULT_LOGIN_URL = "https://login.buildspace.studio";
3
- export const DEFAULT_API_VERSION = "2025-06-01";
4
- export function resolveConfig(mode, config = {}) {
5
- return {
6
- mode,
7
- baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,
8
- loginUrl: config.loginUrl ?? DEFAULT_LOGIN_URL,
9
- version: config.version ?? DEFAULT_API_VERSION,
10
- fetch: config.fetch ?? fetch,
11
- };
12
- }
13
- function formatMode(mode) {
14
- return mode === "server" ? "server SDK" : "client SDK";
15
- }
16
- export function validateApiKey({ mode, key }) {
17
- if (!key) {
18
- throw new Error(`Missing API key. The ${formatMode(mode)} requires a valid Buildspace key.`);
19
- }
20
- if (mode === "server" && !key.startsWith("bs_sec_")) {
21
- throw new Error("The server SDK requires a secret key (bs_sec_*). Use createClient() from '@buildspacestudio/sdk/client' for browser usage with publishable keys.");
22
- }
23
- if (mode === "client" && !key.startsWith("bs_pub_")) {
24
- throw new Error("The client SDK requires a publishable key (bs_pub_*). Use new Buildspace() from '@buildspacestudio/sdk' for server usage with secret keys.");
25
- }
26
- }
27
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,+BAA+B,CAAC;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAG,iCAAiC,CAAC;AACnE,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAC;AAsChD,MAAM,UAAU,aAAa,CAAC,IAAgB,EAAE,SAA2B,EAAE;IAC3E,OAAO;QACL,IAAI;QACJ,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,gBAAgB;QAC3C,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,iBAAiB;QAC9C,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,mBAAmB;QAC9C,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,KAAK;KAC7B,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,IAAgB;IAClC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAAE,IAAI,EAAE,GAAG,EAAqC;IAC7E,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,wBAAwB,UAAU,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;IAC/F,CAAC;IAED,IAAI,IAAI,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CACb,kJAAkJ,CACnJ,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CACb,4IAA4I,CAC7I,CAAC;IACJ,CAAC;AACH,CAAC"}
package/dist/errors.d.ts DELETED
@@ -1,31 +0,0 @@
1
- /** Services available in the Buildspace platform. */
2
- export type BuildspaceService = "auth" | "events" | "notifications" | "storage";
3
- /**
4
- * Error thrown by all Buildspace SDK methods on failure.
5
- *
6
- * @example
7
- * ```ts
8
- * try {
9
- * await buildspace.auth.getSession(token);
10
- * } catch (err) {
11
- * if (err instanceof BuildspaceError) {
12
- * console.error(err.service, err.code, err.status, err.message);
13
- * }
14
- * }
15
- * ```
16
- */
17
- export declare class BuildspaceError extends Error {
18
- /** Machine-readable error code, e.g. `"auth/invalid-token"`. */
19
- readonly code: string;
20
- /** Which service produced the error. */
21
- readonly service: BuildspaceService;
22
- /** HTTP status code from the API. */
23
- readonly status: number;
24
- constructor({ code, message, service, status, }: {
25
- code: string;
26
- message: string;
27
- service: BuildspaceService;
28
- status: number;
29
- });
30
- }
31
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,QAAQ,GAAG,eAAe,GAAG,SAAS,CAAC;AAEhF;;;;;;;;;;;;;GAaG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,gEAAgE;IAChE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IACpC,qCAAqC;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,EACV,IAAI,EACJ,OAAO,EACP,OAAO,EACP,MAAM,GACP,EAAE;QACD,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,iBAAiB,CAAC;QAC3B,MAAM,EAAE,MAAM,CAAC;KAChB;CAOF"}
package/dist/errors.js DELETED
@@ -1,30 +0,0 @@
1
- /**
2
- * Error thrown by all Buildspace SDK methods on failure.
3
- *
4
- * @example
5
- * ```ts
6
- * try {
7
- * await buildspace.auth.getSession(token);
8
- * } catch (err) {
9
- * if (err instanceof BuildspaceError) {
10
- * console.error(err.service, err.code, err.status, err.message);
11
- * }
12
- * }
13
- * ```
14
- */
15
- export class BuildspaceError extends Error {
16
- /** Machine-readable error code, e.g. `"auth/invalid-token"`. */
17
- code;
18
- /** Which service produced the error. */
19
- service;
20
- /** HTTP status code from the API. */
21
- status;
22
- constructor({ code, message, service, status, }) {
23
- super(message);
24
- this.name = "BuildspaceError";
25
- this.code = code;
26
- this.service = service;
27
- this.status = status;
28
- }
29
- }
30
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,gEAAgE;IACvD,IAAI,CAAS;IACtB,wCAAwC;IAC/B,OAAO,CAAoB;IACpC,qCAAqC;IAC5B,MAAM,CAAS;IAExB,YAAY,EACV,IAAI,EACJ,OAAO,EACP,OAAO,EACP,MAAM,GAMP;QACC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/events/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAS7C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAC1C,OAAO,CAAC,KAAK,CAA+C;gBAG1D,SAAS,EAAE,aAAa,EACxB,MAAM,GAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAO;IAYhE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IAEtC;;;;;;;;;;OAUG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAelF;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAqB5B;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAQhC"}
@@ -1,97 +0,0 @@
1
- /**
2
- * Client-side event tracking with automatic batching.
3
- *
4
- * Events are queued in memory and flushed to the API in batches,
5
- * either on a timer or when the batch size limit is reached.
6
- *
7
- * Access via `buildspace.events` on the client SDK.
8
- *
9
- * @example
10
- * ```ts
11
- * // Fire and forget — events are queued automatically
12
- * buildspace.events.track("button.clicked", { label: "upgrade" });
13
- *
14
- * // Flush before page unload
15
- * await buildspace.events.flush();
16
- *
17
- * // Graceful shutdown (clears timer, flushes remaining)
18
- * await buildspace.events.shutdown();
19
- * ```
20
- */
21
- export class EventsClientNamespace {
22
- queue = [];
23
- transport;
24
- timer = null;
25
- constructor(transport, config = {}) {
26
- this.transport = transport;
27
- const flushInterval = config.flushInterval ?? 5000;
28
- this.maxBatchSize = config.maxBatchSize ?? 20;
29
- this.timer = setInterval(() => {
30
- this.flush().catch(() => {
31
- // best effort flush for background timer
32
- });
33
- }, flushInterval);
34
- }
35
- maxBatchSize;
36
- /**
37
- * Queue an event for batched delivery.
38
- *
39
- * This method is synchronous and returns immediately. Events are
40
- * automatically flushed when the batch size is reached or on the
41
- * configured interval.
42
- *
43
- * @param event - Event name, e.g. `"button.clicked"`.
44
- * @param properties - Arbitrary key-value data to attach.
45
- * @param actorId - Identifier of the user or entity that triggered the event.
46
- */
47
- track(event, properties, actorId) {
48
- this.queue.push({
49
- event,
50
- properties,
51
- actor_id: actorId,
52
- timestamp: new Date().toISOString(),
53
- });
54
- if (this.queue.length >= this.maxBatchSize) {
55
- this.flush().catch(() => {
56
- // best effort flush on max batch size
57
- });
58
- }
59
- }
60
- /**
61
- * Send all queued events to the API immediately.
62
- *
63
- * If the flush fails, events are re-queued for the next attempt.
64
- */
65
- async flush() {
66
- if (this.queue.length === 0) {
67
- return;
68
- }
69
- const batch = this.queue.splice(0, this.queue.length);
70
- try {
71
- await this.transport.request({
72
- service: "events",
73
- path: "/v1/events/batch",
74
- method: "POST",
75
- keepalive: true,
76
- body: { events: batch },
77
- });
78
- }
79
- catch {
80
- this.queue.unshift(...batch);
81
- throw new Error("Failed to flush events batch.");
82
- }
83
- }
84
- /**
85
- * Stop the automatic flush timer and send any remaining events.
86
- *
87
- * Call this during app shutdown or cleanup to ensure no events are lost.
88
- */
89
- async shutdown() {
90
- if (this.timer) {
91
- clearInterval(this.timer);
92
- this.timer = null;
93
- }
94
- await this.flush();
95
- }
96
- }
97
- //# sourceMappingURL=client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/events/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CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAEtD,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAO;gBACjC,OAAO,EAAE,QAAQ;gBACjB,IAAI,EAAE,kBAAkB;gBACxB,MAAM,EAAE,MAAM;gBACd,SAAS,EAAE,IAAI;gBACf,IAAI,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE;aACxB,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;QAED,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/events/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,oDAAoD;AACpD,MAAM,WAAW,kBAAkB;IACjC,iEAAiE;IACjE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8DAA8D;IAC9D,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;gBAE9B,SAAS,EAAE,aAAa;IAIpC;;;;;;;OAOG;IACH,KAAK,CACH,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAchC;;;;;;;OAOG;IACH,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CAa1F"}
@@ -1,65 +0,0 @@
1
- /**
2
- * Server-side event tracking methods.
3
- *
4
- * Access via `buildspace.events` on the server SDK.
5
- *
6
- * @example
7
- * ```ts
8
- * // Track a single event
9
- * await buildspace.events.track("user.signed_up", { plan: "pro" }, userId);
10
- *
11
- * // Batch track multiple events
12
- * await buildspace.events.batchTrack([
13
- * { event: "page.viewed", properties: { path: "/home" }, actor_id: userId },
14
- * ]);
15
- * ```
16
- */
17
- export class EventsServerNamespace {
18
- transport;
19
- constructor(transport) {
20
- this.transport = transport;
21
- }
22
- /**
23
- * Track a single event.
24
- *
25
- * @param event - Event name, e.g. `"user.signed_up"`.
26
- * @param properties - Arbitrary key-value data to attach to the event.
27
- * @param actorId - Identifier of the user or entity that triggered the event.
28
- * @returns The ID of the created event.
29
- */
30
- track(event, properties, actorId) {
31
- return this.transport.request({
32
- service: "events",
33
- path: "/v1/events",
34
- method: "POST",
35
- body: {
36
- event,
37
- properties,
38
- actor_id: actorId,
39
- timestamp: new Date().toISOString(),
40
- },
41
- });
42
- }
43
- /**
44
- * Track multiple events in a single request.
45
- *
46
- * Events without a `timestamp` are automatically timestamped.
47
- *
48
- * @param events - Array of events to track.
49
- * @returns The count and IDs of created events.
50
- */
51
- batchTrack(events) {
52
- return this.transport.request({
53
- service: "events",
54
- path: "/v1/events/batch",
55
- method: "POST",
56
- body: {
57
- events: events.map((event) => ({
58
- ...event,
59
- timestamp: event.timestamp ?? new Date().toISOString(),
60
- })),
61
- },
62
- });
63
- }
64
- }
65
- //# sourceMappingURL=server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/events/server.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,qBAAqB;IACf,SAAS,CAAgB;IAE1C,YAAY,SAAwB;QAClC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CACH,KAAa,EACb,UAAoC,EACpC,OAAgB;QAEhB,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAuB;YAClD,OAAO,EAAE,QAAQ;YACjB,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,MAAM;YACd,IAAI,EAAE;gBACJ,KAAK;gBACL,UAAU;gBACV,QAAQ,EAAE,OAAO;gBACjB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACpC;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,UAAU,CAAC,MAA4B;QACrC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAyC;YACpE,OAAO,EAAE,QAAQ;YACjB,IAAI,EAAE,kBAAkB;YACxB,MAAM,EAAE,MAAM;YACd,IAAI,EAAE;gBACJ,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;oBAC7B,GAAG,KAAK;oBACR,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;iBACvD,CAAC,CAAC;aACJ;SACF,CAAC,CAAC;IACL,CAAC;CACF"}