@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,164 @@
1
+ import { a as AuthSession, T as TokenResponse, b as AuthUser } from '../server-Suq3tZZC.js';
2
+ import '../http-D2gXpNpr.js';
3
+
4
+ /**
5
+ * Framework adapter for Next.js (and any framework using web-standard
6
+ * `Request`/`Response` route handlers).
7
+ *
8
+ * Replaces the auth glue every creator app used to hand-roll: the OAuth
9
+ * callback route, logout + session routes, a cookie-aware `getSession()`,
10
+ * and a middleware cookie guard — all standardized on the `bs_session`
11
+ * cookie.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // app/api/auth/callback/route.ts
16
+ * import { createAuthCallback } from "@buildspacestudio/sdk/next";
17
+ * import { getServerClient } from "@/lib/buildspace";
18
+ *
19
+ * export const GET = createAuthCallback(getServerClient(), { redirectTo: "/dashboard" });
20
+ * ```
21
+ */
22
+ /** The session cookie name shared by every Buildspace app. */
23
+ declare const SESSION_COOKIE_NAME = "bs_session";
24
+ /** The minimal server-client surface the adapter needs (a `Buildspace` instance). */
25
+ interface AuthServerClient {
26
+ auth: {
27
+ getSession(sessionToken: string): Promise<AuthSession | null>;
28
+ handleCallback(request: Request | URL | string, opts?: {
29
+ redirectUri?: string;
30
+ }): Promise<TokenResponse>;
31
+ signOut(sessionToken?: string): Promise<void>;
32
+ };
33
+ }
34
+ /** Options controlling the `bs_session` cookie attributes. */
35
+ interface SessionCookieOptions {
36
+ /** Cookie domain. Omitted by default (host-only cookie). */
37
+ domain?: string;
38
+ /** Cookie path. Defaults to `/`. */
39
+ path?: string;
40
+ /** SameSite attribute. Defaults to `Lax`. */
41
+ sameSite?: "lax" | "strict" | "none";
42
+ /** Set the `Secure` attribute. Defaults to `true` outside development. */
43
+ secure?: boolean;
44
+ }
45
+ /** Build a `Set-Cookie` header value that stores the session token. */
46
+ declare function buildSessionCookie(token: string, maxAgeSeconds: number, opts?: SessionCookieOptions): string;
47
+ /** Build a `Set-Cookie` header value that clears the session cookie. */
48
+ declare function buildClearSessionCookie(opts?: SessionCookieOptions): string;
49
+ /**
50
+ * Anything the adapter can read the session cookie from: a web `Request`,
51
+ * or a cookie store with a `get(name)` method (e.g. the object returned by
52
+ * Next.js `cookies()` in Server Components and Route Handlers).
53
+ */
54
+ type SessionCookieSource = Request | {
55
+ get(name: string): {
56
+ value: string;
57
+ } | string | null | undefined;
58
+ };
59
+ /** Read the raw session token from a request or cookie store, or `null`. */
60
+ declare function getSessionToken(source: SessionCookieSource): string | null;
61
+ /** An {@link AuthSession} plus the raw token it was resolved from. */
62
+ type SessionWithToken = AuthSession & {
63
+ token: string;
64
+ };
65
+ /**
66
+ * Cookie-aware session lookup.
67
+ *
68
+ * Reads the `bs_session` cookie from the given source and verifies it with
69
+ * the Buildspace API. Returns `null` when there is no cookie or the token
70
+ * is expired/revoked. Network/5xx errors also resolve to `null` so a blip
71
+ * never crashes rendering — sign-in state degrades to "signed out".
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * // Server Component
76
+ * import { cookies } from "next/headers";
77
+ * const session = await getSession(getServerClient(), await cookies());
78
+ * ```
79
+ */
80
+ declare function getSession(client: AuthServerClient, source: SessionCookieSource): Promise<SessionWithToken | null>;
81
+ /**
82
+ * Like {@link getSession} but throws a `BuildspaceError` (401) when there is
83
+ * no valid session. Use in route handlers and server actions that must only
84
+ * run for signed-in users.
85
+ */
86
+ declare function requireSession(client: AuthServerClient, source: SessionCookieSource): Promise<SessionWithToken>;
87
+ /** Options for {@link createAuthCallback}. */
88
+ interface CreateAuthCallbackOptions {
89
+ /** Cookie attribute overrides. */
90
+ cookie?: SessionCookieOptions;
91
+ /**
92
+ * Called when the code exchange fails. Return a `Response` to control the
93
+ * error page; by default the error is rethrown (surfacing your framework's
94
+ * error handling).
95
+ */
96
+ onError?: (error: unknown, request: Request) => Response | Promise<Response>;
97
+ /**
98
+ * Signup/sign-in side effects (mirror the user into your DB, send a
99
+ * welcome email, track an event). Failures are logged and never break
100
+ * login.
101
+ */
102
+ onSignIn?: (ctx: {
103
+ accessToken: string;
104
+ request: Request;
105
+ user: AuthUser;
106
+ }) => void | Promise<void>;
107
+ /** Where to send the user after login. Defaults to `/`. */
108
+ redirectTo?: string;
109
+ }
110
+ /**
111
+ * Create the OAuth callback route handler.
112
+ *
113
+ * Exchanges the `?code=` for tokens, runs your `onSignIn` hook, stores the
114
+ * access token in the `bs_session` cookie (with `expires_in` as `Max-Age`),
115
+ * and redirects to `redirectTo`.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * // app/api/auth/callback/route.ts
120
+ * export const GET = createAuthCallback(getServerClient(), {
121
+ * redirectTo: "/dashboard",
122
+ * onSignIn: async ({ user }) => upsertUser(user),
123
+ * });
124
+ * ```
125
+ */
126
+ declare function createAuthCallback(client: AuthServerClient, options?: CreateAuthCallbackOptions): (request: Request) => Promise<Response>;
127
+ /**
128
+ * Create the logout route handler (`POST /api/auth/logout`).
129
+ *
130
+ * Revokes the session with the Buildspace API (already-expired sessions are
131
+ * ignored) and clears the `bs_session` cookie.
132
+ */
133
+ declare function createLogoutRoute(client: AuthServerClient, options?: {
134
+ cookie?: SessionCookieOptions;
135
+ }): (request: Request) => Promise<Response>;
136
+ /**
137
+ * Create the session route handler (`GET /api/auth/session`).
138
+ *
139
+ * Returns `{ session }` for the current cookie, with the raw token omitted —
140
+ * this response is safe to expose to the browser.
141
+ */
142
+ declare function createSessionRoute(client: AuthServerClient): (request: Request) => Promise<Response>;
143
+ /**
144
+ * Middleware helper: redirect requests that don't carry a session cookie.
145
+ *
146
+ * This is a fast presence check (no API call — middleware runs on every
147
+ * matched request); route handlers and pages must still verify the session
148
+ * with {@link getSession}.
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * // middleware.ts / proxy.ts
153
+ * import { createSessionCookieGuard } from "@buildspacestudio/sdk/next";
154
+ *
155
+ * export const proxy = createSessionCookieGuard({ redirectTo: "/" });
156
+ * export const config = { matcher: ["/dashboard/:path*"] };
157
+ * ```
158
+ */
159
+ declare function createSessionCookieGuard(options?: {
160
+ /** Where to send signed-out users. Defaults to `/`. */
161
+ redirectTo?: string;
162
+ }): (request: Request) => Response | undefined;
163
+
164
+ export { type AuthServerClient, type CreateAuthCallbackOptions, SESSION_COOKIE_NAME, type SessionCookieOptions, type SessionCookieSource, type SessionWithToken, buildClearSessionCookie, buildSessionCookie, createAuthCallback, createLogoutRoute, createSessionCookieGuard, createSessionRoute, getSession, getSessionToken, requireSession };
@@ -0,0 +1,172 @@
1
+ // src/errors.ts
2
+ var BuildspaceError = class extends Error {
3
+ /** Machine-readable error code, e.g. `"auth/invalid-token"`. */
4
+ code;
5
+ /** Which service produced the error. */
6
+ service;
7
+ /** HTTP status code from the API. */
8
+ status;
9
+ constructor({
10
+ code,
11
+ message,
12
+ service,
13
+ status
14
+ }) {
15
+ super(message);
16
+ this.name = "BuildspaceError";
17
+ this.code = code;
18
+ this.service = service;
19
+ this.status = status;
20
+ }
21
+ };
22
+
23
+ // src/next/index.ts
24
+ var SESSION_COOKIE_NAME = "bs_session";
25
+ function isSecureDefault() {
26
+ return globalThis.process?.env?.NODE_ENV !== "development";
27
+ }
28
+ function serializeSessionCookie(value, maxAge, opts) {
29
+ const parts = [
30
+ `${SESSION_COOKIE_NAME}=${value}`,
31
+ `Path=${opts?.path ?? "/"}`,
32
+ "HttpOnly",
33
+ `SameSite=${opts?.sameSite === "strict" ? "Strict" : opts?.sameSite === "none" ? "None" : "Lax"}`
34
+ ];
35
+ if (maxAge !== null) {
36
+ parts.push(`Max-Age=${Math.max(0, Math.floor(maxAge))}`);
37
+ }
38
+ if (opts?.secure ?? isSecureDefault()) {
39
+ parts.push("Secure");
40
+ }
41
+ if (opts?.domain) {
42
+ parts.push(`Domain=${opts.domain}`);
43
+ }
44
+ return parts.join("; ");
45
+ }
46
+ function buildSessionCookie(token, maxAgeSeconds, opts) {
47
+ return serializeSessionCookie(token, maxAgeSeconds, opts);
48
+ }
49
+ function buildClearSessionCookie(opts) {
50
+ return serializeSessionCookie("", 0, opts);
51
+ }
52
+ function parseCookieHeader(header, name) {
53
+ for (const part of header.split(";")) {
54
+ const eq = part.indexOf("=");
55
+ if (eq === -1) {
56
+ continue;
57
+ }
58
+ if (part.slice(0, eq).trim() === name) {
59
+ return part.slice(eq + 1).trim();
60
+ }
61
+ }
62
+ return null;
63
+ }
64
+ function getSessionToken(source) {
65
+ if (source instanceof Request) {
66
+ const header = source.headers.get("cookie");
67
+ return header ? parseCookieHeader(header, SESSION_COOKIE_NAME) : null;
68
+ }
69
+ const cookie = source.get(SESSION_COOKIE_NAME);
70
+ if (!cookie) {
71
+ return null;
72
+ }
73
+ const value = typeof cookie === "string" ? cookie : cookie.value;
74
+ return value || null;
75
+ }
76
+ async function getSession(client, source) {
77
+ const token = getSessionToken(source);
78
+ if (!token) {
79
+ return null;
80
+ }
81
+ try {
82
+ const session = await client.auth.getSession(token);
83
+ return session ? { ...session, token } : null;
84
+ } catch {
85
+ return null;
86
+ }
87
+ }
88
+ async function requireSession(client, source) {
89
+ const session = await getSession(client, source);
90
+ if (!session) {
91
+ throw new BuildspaceError({
92
+ service: "auth",
93
+ status: 401,
94
+ code: "auth/session-required",
95
+ message: "No valid session. The bs_session cookie is missing, expired, or revoked."
96
+ });
97
+ }
98
+ return session;
99
+ }
100
+ function createAuthCallback(client, options) {
101
+ return async (request) => {
102
+ let tokens;
103
+ try {
104
+ tokens = await client.auth.handleCallback(request);
105
+ } catch (error) {
106
+ if (options?.onError) {
107
+ return await options.onError(error, request);
108
+ }
109
+ throw error;
110
+ }
111
+ if (options?.onSignIn) {
112
+ try {
113
+ await options.onSignIn({
114
+ accessToken: tokens.access_token,
115
+ request,
116
+ user: tokens.user
117
+ });
118
+ } catch (error) {
119
+ console.error("[buildspace] onSignIn hook failed", error);
120
+ }
121
+ }
122
+ return new Response(null, {
123
+ status: 303,
124
+ headers: {
125
+ Location: options?.redirectTo ?? "/",
126
+ "Set-Cookie": buildSessionCookie(tokens.access_token, tokens.expires_in, options?.cookie)
127
+ }
128
+ });
129
+ };
130
+ }
131
+ function createLogoutRoute(client, options) {
132
+ return async (request) => {
133
+ const token = getSessionToken(request);
134
+ if (token) {
135
+ try {
136
+ await client.auth.signOut(token);
137
+ } catch (error) {
138
+ console.error("[buildspace] session revoke failed during logout", error);
139
+ }
140
+ }
141
+ return new Response(JSON.stringify({ ok: true }), {
142
+ status: 200,
143
+ headers: {
144
+ "Content-Type": "application/json",
145
+ "Set-Cookie": buildClearSessionCookie(options?.cookie)
146
+ }
147
+ });
148
+ };
149
+ }
150
+ function createSessionRoute(client) {
151
+ return async (request) => {
152
+ const session = await getSession(client, request);
153
+ const publicSession = session ? { appId: session.appId, user: session.user } : null;
154
+ return new Response(JSON.stringify({ session: publicSession }), {
155
+ status: 200,
156
+ headers: { "Content-Type": "application/json" }
157
+ });
158
+ };
159
+ }
160
+ function createSessionCookieGuard(options) {
161
+ return (request) => {
162
+ if (getSessionToken(request)) {
163
+ return;
164
+ }
165
+ const target = new URL(options?.redirectTo ?? "/", new URL(request.url).origin);
166
+ return Response.redirect(target.toString(), 307);
167
+ };
168
+ }
169
+
170
+ export { SESSION_COOKIE_NAME, buildClearSessionCookie, buildSessionCookie, createAuthCallback, createLogoutRoute, createSessionCookieGuard, createSessionRoute, getSession, getSessionToken, requireSession };
171
+ //# sourceMappingURL=index.js.map
172
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/errors.ts","../../src/next/index.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;;;ACnBO,IAAM,mBAAA,GAAsB;AA0BnC,SAAS,eAAA,GAA2B;AAClC,EAAA,OACG,UAAA,CAA0E,OAAA,EAAS,GAAA,EAChF,QAAA,KAAa,aAAA;AAErB;AAEA,SAAS,sBAAA,CACP,KAAA,EACA,MAAA,EACA,IAAA,EACQ;AACR,EAAA,MAAM,KAAA,GAAQ;AAAA,IACZ,CAAA,EAAG,mBAAmB,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA;AAAA,IAC/B,CAAA,KAAA,EAAQ,IAAA,EAAM,IAAA,IAAQ,GAAG,CAAA,CAAA;AAAA,IACzB,UAAA;AAAA,IACA,CAAA,SAAA,EAAY,MAAM,QAAA,KAAa,QAAA,GAAW,WAAW,IAAA,EAAM,QAAA,KAAa,MAAA,GAAS,MAAA,GAAS,KAAK,CAAA;AAAA,GACjG;AAEA,EAAA,IAAI,WAAW,IAAA,EAAM;AACnB,IAAA,K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ACF","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 type { AuthSession, AuthUser, TokenResponse } from \"../auth\";\nimport { BuildspaceError } from \"../errors\";\n\n/**\n * Framework adapter for Next.js (and any framework using web-standard\n * `Request`/`Response` route handlers).\n *\n * Replaces the auth glue every creator app used to hand-roll: the OAuth\n * callback route, logout + session routes, a cookie-aware `getSession()`,\n * and a middleware cookie guard — all standardized on the `bs_session`\n * cookie.\n *\n * @example\n * ```ts\n * // app/api/auth/callback/route.ts\n * import { createAuthCallback } from \"@buildspacestudio/sdk/next\";\n * import { getServerClient } from \"@/lib/buildspace\";\n *\n * export const GET = createAuthCallback(getServerClient(), { redirectTo: \"/dashboard\" });\n * ```\n */\n\n/** The session cookie name shared by every Buildspace app. */\nexport const SESSION_COOKIE_NAME = \"bs_session\";\n\n/** The minimal server-client surface the adapter needs (a `Buildspace` instance). */\nexport interface AuthServerClient {\n auth: {\n getSession(sessionToken: string): Promise<AuthSession | null>;\n handleCallback(\n request: Request | URL | string,\n opts?: { redirectUri?: string }\n ): Promise<TokenResponse>;\n signOut(sessionToken?: string): Promise<void>;\n };\n}\n\n/** Options controlling the `bs_session` cookie attributes. */\nexport interface SessionCookieOptions {\n /** Cookie domain. Omitted by default (host-only cookie). */\n domain?: string;\n /** Cookie path. Defaults to `/`. */\n path?: string;\n /** SameSite attribute. Defaults to `Lax`. */\n sameSite?: \"lax\" | \"strict\" | \"none\";\n /** Set the `Secure` attribute. Defaults to `true` outside development. */\n secure?: boolean;\n}\n\nfunction isSecureDefault(): boolean {\n return (\n (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env\n ?.NODE_ENV !== \"development\"\n );\n}\n\nfunction serializeSessionCookie(\n value: string,\n maxAge: number | null,\n opts?: SessionCookieOptions\n): string {\n const parts = [\n `${SESSION_COOKIE_NAME}=${value}`,\n `Path=${opts?.path ?? \"/\"}`,\n \"HttpOnly\",\n `SameSite=${opts?.sameSite === \"strict\" ? \"Strict\" : opts?.sameSite === \"none\" ? \"None\" : \"Lax\"}`,\n ];\n\n if (maxAge !== null) {\n parts.push(`Max-Age=${Math.max(0, Math.floor(maxAge))}`);\n }\n\n if (opts?.secure ?? isSecureDefault()) {\n parts.push(\"Secure\");\n }\n\n if (opts?.domain) {\n parts.push(`Domain=${opts.domain}`);\n }\n\n return parts.join(\"; \");\n}\n\n/** Build a `Set-Cookie` header value that stores the session token. */\nexport function buildSessionCookie(\n token: string,\n maxAgeSeconds: number,\n opts?: SessionCookieOptions\n): string {\n return serializeSessionCookie(token, maxAgeSeconds, opts);\n}\n\n/** Build a `Set-Cookie` header value that clears the session cookie. */\nexport function buildClearSessionCookie(opts?: SessionCookieOptions): string {\n return serializeSessionCookie(\"\", 0, opts);\n}\n\n/**\n * Anything the adapter can read the session cookie from: a web `Request`,\n * or a cookie store with a `get(name)` method (e.g. the object returned by\n * Next.js `cookies()` in Server Components and Route Handlers).\n */\nexport type SessionCookieSource =\n | Request\n | {\n get(name: string): { value: string } | string | null | undefined;\n };\n\nfunction parseCookieHeader(header: string, name: string): string | null {\n for (const part of header.split(\";\")) {\n const eq = part.indexOf(\"=\");\n if (eq === -1) {\n continue;\n }\n\n if (part.slice(0, eq).trim() === name) {\n return part.slice(eq + 1).trim();\n }\n }\n\n return null;\n}\n\n/** Read the raw session token from a request or cookie store, or `null`. */\nexport function getSessionToken(source: SessionCookieSource): string | null {\n if (source instanceof Request) {\n const header = source.headers.get(\"cookie\");\n return header ? parseCookieHeader(header, SESSION_COOKIE_NAME) : null;\n }\n\n const cookie = source.get(SESSION_COOKIE_NAME);\n if (!cookie) {\n return null;\n }\n\n const value = typeof cookie === \"string\" ? cookie : cookie.value;\n return value || null;\n}\n\n/** An {@link AuthSession} plus the raw token it was resolved from. */\nexport type SessionWithToken = AuthSession & { token: string };\n\n/**\n * Cookie-aware session lookup.\n *\n * Reads the `bs_session` cookie from the given source and verifies it with\n * the Buildspace API. Returns `null` when there is no cookie or the token\n * is expired/revoked. Network/5xx errors also resolve to `null` so a blip\n * never crashes rendering — sign-in state degrades to \"signed out\".\n *\n * @example\n * ```ts\n * // Server Component\n * import { cookies } from \"next/headers\";\n * const session = await getSession(getServerClient(), await cookies());\n * ```\n */\nexport async function getSession(\n client: AuthServerClient,\n source: SessionCookieSource\n): Promise<SessionWithToken | null> {\n const token = getSessionToken(source);\n if (!token) {\n return null;\n }\n\n try {\n const session = await client.auth.getSession(token);\n return session ? { ...session, token } : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Like {@link getSession} but throws a `BuildspaceError` (401) when there is\n * no valid session. Use in route handlers and server actions that must only\n * run for signed-in users.\n */\nexport async function requireSession(\n client: AuthServerClient,\n source: SessionCookieSource\n): Promise<SessionWithToken> {\n const session = await getSession(client, source);\n if (!session) {\n throw new BuildspaceError({\n service: \"auth\",\n status: 401,\n code: \"auth/session-required\",\n message: \"No valid session. The bs_session cookie is missing, expired, or revoked.\",\n });\n }\n\n return session;\n}\n\n/** Options for {@link createAuthCallback}. */\nexport interface CreateAuthCallbackOptions {\n /** Cookie attribute overrides. */\n cookie?: SessionCookieOptions;\n /**\n * Called when the code exchange fails. Return a `Response` to control the\n * error page; by default the error is rethrown (surfacing your framework's\n * error handling).\n */\n onError?: (error: unknown, request: Request) => Response | Promise<Response>;\n /**\n * Signup/sign-in side effects (mirror the user into your DB, send a\n * welcome email, track an event). Failures are logged and never break\n * login.\n */\n onSignIn?: (ctx: {\n accessToken: string;\n request: Request;\n user: AuthUser;\n }) => void | Promise<void>;\n /** Where to send the user after login. Defaults to `/`. */\n redirectTo?: string;\n}\n\n/**\n * Create the OAuth callback route handler.\n *\n * Exchanges the `?code=` for tokens, runs your `onSignIn` hook, stores the\n * access token in the `bs_session` cookie (with `expires_in` as `Max-Age`),\n * and redirects to `redirectTo`.\n *\n * @example\n * ```ts\n * // app/api/auth/callback/route.ts\n * export const GET = createAuthCallback(getServerClient(), {\n * redirectTo: \"/dashboard\",\n * onSignIn: async ({ user }) => upsertUser(user),\n * });\n * ```\n */\nexport function createAuthCallback(\n client: AuthServerClient,\n options?: CreateAuthCallbackOptions\n): (request: Request) => Promise<Response> {\n return async (request: Request): Promise<Response> => {\n let tokens: TokenResponse;\n try {\n tokens = await client.auth.handleCallback(request);\n } catch (error) {\n if (options?.onError) {\n return await options.onError(error, request);\n }\n throw error;\n }\n\n if (options?.onSignIn) {\n try {\n await options.onSignIn({\n accessToken: tokens.access_token,\n request,\n user: tokens.user,\n });\n } catch (error) {\n console.error(\"[buildspace] onSignIn hook failed\", error);\n }\n }\n\n return new Response(null, {\n status: 303,\n headers: {\n Location: options?.redirectTo ?? \"/\",\n \"Set-Cookie\": buildSessionCookie(tokens.access_token, tokens.expires_in, options?.cookie),\n },\n });\n };\n}\n\n/**\n * Create the logout route handler (`POST /api/auth/logout`).\n *\n * Revokes the session with the Buildspace API (already-expired sessions are\n * ignored) and clears the `bs_session` cookie.\n */\nexport function createLogoutRoute(\n client: AuthServerClient,\n options?: { cookie?: SessionCookieOptions }\n): (request: Request) => Promise<Response> {\n return async (request: Request): Promise<Response> => {\n const token = getSessionToken(request);\n\n if (token) {\n try {\n await client.auth.signOut(token);\n } catch (error) {\n console.error(\"[buildspace] session revoke failed during logout\", error);\n }\n }\n\n return new Response(JSON.stringify({ ok: true }), {\n status: 200,\n headers: {\n \"Content-Type\": \"application/json\",\n \"Set-Cookie\": buildClearSessionCookie(options?.cookie),\n },\n });\n };\n}\n\n/**\n * Create the session route handler (`GET /api/auth/session`).\n *\n * Returns `{ session }` for the current cookie, with the raw token omitted —\n * this response is safe to expose to the browser.\n */\nexport function createSessionRoute(\n client: AuthServerClient\n): (request: Request) => Promise<Response> {\n return async (request: Request): Promise<Response> => {\n const session = await getSession(client, request);\n const publicSession = session ? { appId: session.appId, user: session.user } : null;\n\n return new Response(JSON.stringify({ session: publicSession }), {\n status: 200,\n headers: { \"Content-Type\": \"application/json\" },\n });\n };\n}\n\n/**\n * Middleware helper: redirect requests that don't carry a session cookie.\n *\n * This is a fast presence check (no API call — middleware runs on every\n * matched request); route handlers and pages must still verify the session\n * with {@link getSession}.\n *\n * @example\n * ```ts\n * // middleware.ts / proxy.ts\n * import { createSessionCookieGuard } from \"@buildspacestudio/sdk/next\";\n *\n * export const proxy = createSessionCookieGuard({ redirectTo: \"/\" });\n * export const config = { matcher: [\"/dashboard/:path*\"] };\n * ```\n */\nexport function createSessionCookieGuard(options?: {\n /** Where to send signed-out users. Defaults to `/`. */\n redirectTo?: string;\n}): (request: Request) => Response | undefined {\n return (request: Request): Response | undefined => {\n if (getSessionToken(request)) {\n return;\n }\n\n const target = new URL(options?.redirectTo ?? \"/\", new URL(request.url).origin);\n return Response.redirect(target.toString(), 307);\n };\n}\n"]}
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ // src/notifications/server.ts
4
+ var NotificationsServerNamespace = class {
5
+ transport;
6
+ constructor(transport) {
7
+ this.transport = transport;
8
+ }
9
+ /**
10
+ * Send a custom email with inline HTML content.
11
+ *
12
+ * @param opts - Email content and recipient options.
13
+ * @returns The notification ID and optional provider message ID.
14
+ */
15
+ send(opts) {
16
+ return this.transport.request({
17
+ service: "notifications",
18
+ path: "/v1/notifications/send",
19
+ method: "POST",
20
+ body: {
21
+ to: opts.to,
22
+ subject: opts.subject,
23
+ html: opts.html,
24
+ text: opts.text,
25
+ reply_to: opts.replyTo,
26
+ metadata: opts.metadata
27
+ }
28
+ });
29
+ }
30
+ /**
31
+ * Send an email using a pre-configured template.
32
+ *
33
+ * Templates are created in the Buildspace Creator Studio.
34
+ *
35
+ * @param templateSlug - The slug of the template to use, e.g. `"welcome-email"`.
36
+ * @param opts - Recipient and template variable options.
37
+ * @returns The notification ID and optional provider message ID.
38
+ */
39
+ sendTemplate(templateSlug, opts) {
40
+ return this.transport.request({
41
+ service: "notifications",
42
+ path: "/v1/notifications/send-template",
43
+ method: "POST",
44
+ body: {
45
+ template: templateSlug,
46
+ to: opts.to,
47
+ variables: opts.variables,
48
+ metadata: opts.metadata
49
+ }
50
+ });
51
+ }
52
+ };
53
+
54
+ exports.NotificationsServerNamespace = NotificationsServerNamespace;
55
+ //# sourceMappingURL=index.cjs.map
56
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/notifications/server.ts"],"names":[],"mappings":";;;AA2DO,IAAM,+BAAN,MAAmC;AAAA,EACvB,SAAA;AAAA,EAEjB,YAAY,SAAA,EAA0B;AACpC,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,KAAK,IAAA,EAAwC;AAC3C,IAAA,OAAO,IAAA,CAAK,UAAU,OAAA,CAAoB;AAAA,MACxC,OAAA,EAAS,eAAA;AAAA,MACT,IAAA,EAAM,wBAAA;AAAA,MACN,MAAA,EAAQ,MAAA;AAAA,MACR,IAAA,EAAM;AAAA,QACJ,IAAI,IAAA,CAAK,EAAA;AAAA,QACT,SAAS,IAAA,CAAK,OAAA;AAAA,QACd,MAAM,IAAA,CAAK,IAAA;AAAA,QACX,MAAM,IAAA,CAAK,IAAA;AAAA,QACX,UAAU,IAAA,CAAK,OAAA;AAAA,QACf,UAAU,IAAA,CAAK;AAAA;AACjB,KACD,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,YAAA,CAAa,cAAsB,IAAA,EAAgD;AACjF,IAAA,OAAO,IAAA,CAAK,UAAU,OAAA,CAAoB;AAAA,MACxC,OAAA,EAAS,eAAA;AAAA,MACT,IAAA,EAAM,iCAAA;AAAA,MACN,MAAA,EAAQ,MAAA;AAAA,MACR,IAAA,EAAM;AAAA,QACJ,QAAA,EAAU,YAAA;AAAA,QACV,IAAI,IAAA,CAAK,EAAA;AAAA,QACT,WAAW,IAAA,CAAK,SAAA;AAAA,QAChB,UAAU,IAAA,CAAK;AAAA;AACjB,KACD,CAAA;AAAA,EACH;AACF","file":"index.cjs","sourcesContent":["import type { HttpTransport } from \"../http\";\n\n/** Options for sending a custom email. */\nexport interface SendOptions {\n /** HTML body of the email. */\n html: string;\n /** Arbitrary metadata to attach to the notification for tracking. */\n metadata?: Record<string, unknown>;\n /** Reply-to email address. */\n replyTo?: string;\n /** Email subject line. */\n subject: string;\n /** Plain-text fallback body. Recommended for email accessibility. */\n text?: string;\n /** Recipient email address, or an array of addresses for multiple recipients. */\n to: string | string[];\n}\n\n/** Options for sending a template-based email. */\nexport interface SendTemplateOptions {\n /** Arbitrary metadata to attach to the notification for tracking. */\n metadata?: Record<string, unknown>;\n /** Recipient email address, or an array of addresses. */\n to: string | string[];\n /** Template variable substitutions, e.g. `{ firstName: \"Alex\" }`. */\n variables?: Record<string, string>;\n}\n\n/** Result of a successfully sent notification. */\nexport interface SendResult {\n /** Buildspace notification ID. */\n id: string;\n /** Underlying email provider's message ID, if available. */\n providerMessageId?: string;\n}\n\n/**\n * Server-side notification methods for sending transactional emails.\n *\n * Access via `buildspace.notifications` on the server SDK.\n * **Not available on the client SDK** — calling `buildspace.notifications`\n * on the client throws a `BuildspaceError`.\n *\n * @example\n * ```ts\n * // Send a custom email\n * await buildspace.notifications.send({\n * to: \"user@example.com\",\n * subject: \"Welcome!\",\n * html: \"<h1>You're in!</h1>\",\n * });\n *\n * // Send from a saved template\n * await buildspace.notifications.sendTemplate(\"welcome-email\", {\n * to: \"user@example.com\",\n * variables: { firstName: \"Alex\" },\n * });\n * ```\n */\nexport class NotificationsServerNamespace {\n private readonly transport: HttpTransport;\n\n constructor(transport: HttpTransport) {\n this.transport = transport;\n }\n\n /**\n * Send a custom email with inline HTML content.\n *\n * @param opts - Email content and recipient options.\n * @returns The notification ID and optional provider message ID.\n */\n send(opts: SendOptions): Promise<SendResult> {\n return this.transport.request<SendResult>({\n service: \"notifications\",\n path: \"/v1/notifications/send\",\n method: \"POST\",\n body: {\n to: opts.to,\n subject: opts.subject,\n html: opts.html,\n text: opts.text,\n reply_to: opts.replyTo,\n metadata: opts.metadata,\n },\n });\n }\n\n /**\n * Send an email using a pre-configured template.\n *\n * Templates are created in the Buildspace Creator Studio.\n *\n * @param templateSlug - The slug of the template to use, e.g. `\"welcome-email\"`.\n * @param opts - Recipient and template variable options.\n * @returns The notification ID and optional provider message ID.\n */\n sendTemplate(templateSlug: string, opts: SendTemplateOptions): Promise<SendResult> {\n return this.transport.request<SendResult>({\n service: \"notifications\",\n path: \"/v1/notifications/send-template\",\n method: \"POST\",\n body: {\n template: templateSlug,\n to: opts.to,\n variables: opts.variables,\n metadata: opts.metadata,\n },\n });\n }\n}\n"]}
@@ -1,6 +1,7 @@
1
- import type { HttpTransport } from "../http";
1
+ import { H as HttpTransport } from '../http-D2gXpNpr.cjs';
2
+
2
3
  /** Options for sending a custom email. */
3
- export interface SendOptions {
4
+ interface SendOptions {
4
5
  /** HTML body of the email. */
5
6
  html: string;
6
7
  /** Arbitrary metadata to attach to the notification for tracking. */
@@ -15,7 +16,7 @@ export interface SendOptions {
15
16
  to: string | string[];
16
17
  }
17
18
  /** Options for sending a template-based email. */
18
- export interface SendTemplateOptions {
19
+ interface SendTemplateOptions {
19
20
  /** Arbitrary metadata to attach to the notification for tracking. */
20
21
  metadata?: Record<string, unknown>;
21
22
  /** Recipient email address, or an array of addresses. */
@@ -24,7 +25,7 @@ export interface SendTemplateOptions {
24
25
  variables?: Record<string, string>;
25
26
  }
26
27
  /** Result of a successfully sent notification. */
27
- export interface SendResult {
28
+ interface SendResult {
28
29
  /** Buildspace notification ID. */
29
30
  id: string;
30
31
  /** Underlying email provider's message ID, if available. */
@@ -53,7 +54,7 @@ export interface SendResult {
53
54
  * });
54
55
  * ```
55
56
  */
56
- export declare class NotificationsServerNamespace {
57
+ declare class NotificationsServerNamespace {
57
58
  private readonly transport;
58
59
  constructor(transport: HttpTransport);
59
60
  /**
@@ -74,4 +75,5 @@ export declare class NotificationsServerNamespace {
74
75
  */
75
76
  sendTemplate(templateSlug: string, opts: SendTemplateOptions): Promise<SendResult>;
76
77
  }
77
- //# sourceMappingURL=server.d.ts.map
78
+
79
+ export { NotificationsServerNamespace, type SendOptions, type SendResult, type SendTemplateOptions };
@@ -1,3 +1,79 @@
1
- export type { SendOptions, SendResult, SendTemplateOptions } from "./server";
2
- export { NotificationsServerNamespace } from "./server";
3
- //# sourceMappingURL=index.d.ts.map
1
+ import { H as HttpTransport } from '../http-D2gXpNpr.js';
2
+
3
+ /** Options for sending a custom email. */
4
+ interface SendOptions {
5
+ /** HTML body of the email. */
6
+ html: string;
7
+ /** Arbitrary metadata to attach to the notification for tracking. */
8
+ metadata?: Record<string, unknown>;
9
+ /** Reply-to email address. */
10
+ replyTo?: string;
11
+ /** Email subject line. */
12
+ subject: string;
13
+ /** Plain-text fallback body. Recommended for email accessibility. */
14
+ text?: string;
15
+ /** Recipient email address, or an array of addresses for multiple recipients. */
16
+ to: string | string[];
17
+ }
18
+ /** Options for sending a template-based email. */
19
+ interface SendTemplateOptions {
20
+ /** Arbitrary metadata to attach to the notification for tracking. */
21
+ metadata?: Record<string, unknown>;
22
+ /** Recipient email address, or an array of addresses. */
23
+ to: string | string[];
24
+ /** Template variable substitutions, e.g. `{ firstName: "Alex" }`. */
25
+ variables?: Record<string, string>;
26
+ }
27
+ /** Result of a successfully sent notification. */
28
+ interface SendResult {
29
+ /** Buildspace notification ID. */
30
+ id: string;
31
+ /** Underlying email provider's message ID, if available. */
32
+ providerMessageId?: string;
33
+ }
34
+ /**
35
+ * Server-side notification methods for sending transactional emails.
36
+ *
37
+ * Access via `buildspace.notifications` on the server SDK.
38
+ * **Not available on the client SDK** — calling `buildspace.notifications`
39
+ * on the client throws a `BuildspaceError`.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * // Send a custom email
44
+ * await buildspace.notifications.send({
45
+ * to: "user@example.com",
46
+ * subject: "Welcome!",
47
+ * html: "<h1>You're in!</h1>",
48
+ * });
49
+ *
50
+ * // Send from a saved template
51
+ * await buildspace.notifications.sendTemplate("welcome-email", {
52
+ * to: "user@example.com",
53
+ * variables: { firstName: "Alex" },
54
+ * });
55
+ * ```
56
+ */
57
+ declare class NotificationsServerNamespace {
58
+ private readonly transport;
59
+ constructor(transport: HttpTransport);
60
+ /**
61
+ * Send a custom email with inline HTML content.
62
+ *
63
+ * @param opts - Email content and recipient options.
64
+ * @returns The notification ID and optional provider message ID.
65
+ */
66
+ send(opts: SendOptions): Promise<SendResult>;
67
+ /**
68
+ * Send an email using a pre-configured template.
69
+ *
70
+ * Templates are created in the Buildspace Creator Studio.
71
+ *
72
+ * @param templateSlug - The slug of the template to use, e.g. `"welcome-email"`.
73
+ * @param opts - Recipient and template variable options.
74
+ * @returns The notification ID and optional provider message ID.
75
+ */
76
+ sendTemplate(templateSlug: string, opts: SendTemplateOptions): Promise<SendResult>;
77
+ }
78
+
79
+ export { NotificationsServerNamespace, type SendOptions, type SendResult, type SendTemplateOptions };
@@ -1,2 +1,54 @@
1
- export { NotificationsServerNamespace } from "./server";
1
+ // src/notifications/server.ts
2
+ var NotificationsServerNamespace = class {
3
+ transport;
4
+ constructor(transport) {
5
+ this.transport = transport;
6
+ }
7
+ /**
8
+ * Send a custom email with inline HTML content.
9
+ *
10
+ * @param opts - Email content and recipient options.
11
+ * @returns The notification ID and optional provider message ID.
12
+ */
13
+ send(opts) {
14
+ return this.transport.request({
15
+ service: "notifications",
16
+ path: "/v1/notifications/send",
17
+ method: "POST",
18
+ body: {
19
+ to: opts.to,
20
+ subject: opts.subject,
21
+ html: opts.html,
22
+ text: opts.text,
23
+ reply_to: opts.replyTo,
24
+ metadata: opts.metadata
25
+ }
26
+ });
27
+ }
28
+ /**
29
+ * Send an email using a pre-configured template.
30
+ *
31
+ * Templates are created in the Buildspace Creator Studio.
32
+ *
33
+ * @param templateSlug - The slug of the template to use, e.g. `"welcome-email"`.
34
+ * @param opts - Recipient and template variable options.
35
+ * @returns The notification ID and optional provider message ID.
36
+ */
37
+ sendTemplate(templateSlug, opts) {
38
+ return this.transport.request({
39
+ service: "notifications",
40
+ path: "/v1/notifications/send-template",
41
+ method: "POST",
42
+ body: {
43
+ template: templateSlug,
44
+ to: opts.to,
45
+ variables: opts.variables,
46
+ metadata: opts.metadata
47
+ }
48
+ });
49
+ }
50
+ };
51
+
52
+ export { NotificationsServerNamespace };
53
+ //# sourceMappingURL=index.js.map
2
54
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/notifications/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"sources":["../../src/notifications/server.ts"],"names":[],"mappings":";AA2DO,IAAM,+BAAN,MAAmC;AAAA,EACvB,SAAA;AAAA,EAEjB,YAAY,SAAA,EAA0B;AACpC,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,KAAK,IAAA,EAAwC;AAC3C,IAAA,OAAO,IAAA,CAAK,UAAU,OAAA,CAAoB;AAAA,MACxC,OAAA,EAAS,eAAA;AAAA,MACT,IAAA,EAAM,wBAAA;AAAA,MACN,MAAA,EAAQ,MAAA;AAAA,MACR,IAAA,EAAM;AAAA,QACJ,IAAI,IAAA,CAAK,EAAA;AAAA,QACT,SAAS,IAAA,CAAK,OAAA;AAAA,QACd,MAAM,IAAA,CAAK,IAAA;AAAA,QACX,MAAM,IAAA,CAAK,IAAA;AAAA,QACX,UAAU,IAAA,CAAK,OAAA;AAAA,QACf,UAAU,IAAA,CAAK;AAAA;AACjB,KACD,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,YAAA,CAAa,cAAsB,IAAA,EAAgD;AACjF,IAAA,OAAO,IAAA,CAAK,UAAU,OAAA,CAAoB;AAAA,MACxC,OAAA,EAAS,eAAA;AAAA,MACT,IAAA,EAAM,iCAAA;AAAA,MACN,MAAA,EAAQ,MAAA;AAAA,MACR,IAAA,EAAM;AAAA,QACJ,QAAA,EAAU,YAAA;AAAA,QACV,IAAI,IAAA,CAAK,EAAA;AAAA,QACT,WAAW,IAAA,CAAK,SAAA;AAAA,QAChB,UAAU,IAAA,CAAK;AAAA;AACjB,KACD,CAAA;AAAA,EACH;AACF","file":"index.js","sourcesContent":["import type { HttpTransport } from \"../http\";\n\n/** Options for sending a custom email. */\nexport interface SendOptions {\n /** HTML body of the email. */\n html: string;\n /** Arbitrary metadata to attach to the notification for tracking. */\n metadata?: Record<string, unknown>;\n /** Reply-to email address. */\n replyTo?: string;\n /** Email subject line. */\n subject: string;\n /** Plain-text fallback body. Recommended for email accessibility. */\n text?: string;\n /** Recipient email address, or an array of addresses for multiple recipients. */\n to: string | string[];\n}\n\n/** Options for sending a template-based email. */\nexport interface SendTemplateOptions {\n /** Arbitrary metadata to attach to the notification for tracking. */\n metadata?: Record<string, unknown>;\n /** Recipient email address, or an array of addresses. */\n to: string | string[];\n /** Template variable substitutions, e.g. `{ firstName: \"Alex\" }`. */\n variables?: Record<string, string>;\n}\n\n/** Result of a successfully sent notification. */\nexport interface SendResult {\n /** Buildspace notification ID. */\n id: string;\n /** Underlying email provider's message ID, if available. */\n providerMessageId?: string;\n}\n\n/**\n * Server-side notification methods for sending transactional emails.\n *\n * Access via `buildspace.notifications` on the server SDK.\n * **Not available on the client SDK** — calling `buildspace.notifications`\n * on the client throws a `BuildspaceError`.\n *\n * @example\n * ```ts\n * // Send a custom email\n * await buildspace.notifications.send({\n * to: \"user@example.com\",\n * subject: \"Welcome!\",\n * html: \"<h1>You're in!</h1>\",\n * });\n *\n * // Send from a saved template\n * await buildspace.notifications.sendTemplate(\"welcome-email\", {\n * to: \"user@example.com\",\n * variables: { firstName: \"Alex\" },\n * });\n * ```\n */\nexport class NotificationsServerNamespace {\n private readonly transport: HttpTransport;\n\n constructor(transport: HttpTransport) {\n this.transport = transport;\n }\n\n /**\n * Send a custom email with inline HTML content.\n *\n * @param opts - Email content and recipient options.\n * @returns The notification ID and optional provider message ID.\n */\n send(opts: SendOptions): Promise<SendResult> {\n return this.transport.request<SendResult>({\n service: \"notifications\",\n path: \"/v1/notifications/send\",\n method: \"POST\",\n body: {\n to: opts.to,\n subject: opts.subject,\n html: opts.html,\n text: opts.text,\n reply_to: opts.replyTo,\n metadata: opts.metadata,\n },\n });\n }\n\n /**\n * Send an email using a pre-configured template.\n *\n * Templates are created in the Buildspace Creator Studio.\n *\n * @param templateSlug - The slug of the template to use, e.g. `\"welcome-email\"`.\n * @param opts - Recipient and template variable options.\n * @returns The notification ID and optional provider message ID.\n */\n sendTemplate(templateSlug: string, opts: SendTemplateOptions): Promise<SendResult> {\n return this.transport.request<SendResult>({\n service: \"notifications\",\n path: \"/v1/notifications/send-template\",\n method: \"POST\",\n body: {\n template: templateSlug,\n to: opts.to,\n variables: opts.variables,\n metadata: opts.metadata,\n },\n });\n }\n}\n"]}