@buildbase/sdk 0.0.45 → 0.0.46

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.
@@ -99,6 +99,8 @@ type DunningStateType = (typeof DunningState)[keyof typeof DunningState];
99
99
  interface ISubscription {
100
100
  _id: string;
101
101
  subscriptionStatus: SubscriptionStatusType;
102
+ /** Stripe Subscription ID (e.g. 'sub_...'). Present when linked to Stripe. */
103
+ subscriptionId?: string;
102
104
  stripePriceId?: string;
103
105
  stripeCurrentPeriodEnd?: string;
104
106
  /** When the current monthly usage period ends (quotas reset on this date). */
@@ -537,12 +539,10 @@ interface IInvoice {
537
539
  subscription: string;
538
540
  }
539
541
  interface IInvoiceListResponse {
540
- success: boolean;
541
542
  invoices: IInvoice[];
542
543
  has_more: boolean;
543
544
  }
544
545
  interface IInvoiceResponse {
545
- success: boolean;
546
546
  invoice: IInvoice;
547
547
  }
548
548
  /** Request body for POST .../workspaces/:id/subscription/usage */
@@ -1066,6 +1066,8 @@ interface IBaseApiConfig {
1066
1066
  method: string;
1067
1067
  path: string;
1068
1068
  }) => void;
1069
+ /** Called when any request receives a 401 response (session expired mid-use). */
1070
+ onUnauthorized?: () => void;
1069
1071
  /** Custom fetch implementation. */
1070
1072
  fetch?: typeof globalThis.fetch;
1071
1073
  }
@@ -1089,6 +1091,7 @@ declare abstract class BaseApi {
1089
1091
  private readonly _debug;
1090
1092
  private readonly _customHeaders;
1091
1093
  private readonly _onError?;
1094
+ private readonly _onUnauthorized?;
1092
1095
  private readonly _fetch;
1093
1096
  constructor(config: IBaseApiConfig);
1094
1097
  /** Throws if config is not ready for API calls. Called automatically by fetchJson/fetchResponse. */
@@ -1117,6 +1120,16 @@ declare abstract class BaseApi {
1117
1120
  * Caller is responsible for checking response.ok and parsing body.
1118
1121
  */
1119
1122
  protected fetchResponse(path: string, init?: RequestInit): Promise<Response>;
1123
+ /**
1124
+ * Throw an error from a failed response.
1125
+ * Tries to parse JSON error body; falls back to status-based message.
1126
+ */
1127
+ protected throwResponseError(response: Response, defaultMsg: string): Promise<never>;
1128
+ /**
1129
+ * Parse JSON and unwrap `{ success, data }` envelope if present.
1130
+ * Throws if `success` is explicitly `false`.
1131
+ */
1132
+ protected unwrapResponse<T>(response: Response, defaultMsg: string): Promise<T>;
1120
1133
  }
1121
1134
 
1122
1135
  /**
@@ -1145,7 +1158,8 @@ declare class AuthApi extends BaseApi {
1145
1158
  });
1146
1159
  /**
1147
1160
  * Initiate OAuth sign-in flow. Returns redirect URL to the auth provider.
1148
- * Uses /api/v1/auth/request (no 'public' prefix — auth endpoints are at the root).
1161
+ * Uses /api/v1/auth/request — auth endpoints sit outside the /public basePath,
1162
+ * so we build the URL directly instead of using fetchResponse.
1149
1163
  */
1150
1164
  requestAuth(params: AuthRequestParams): Promise<AuthRequestResponse>;
1151
1165
  /** Fetch user profile with the given session ID (used after OAuth redirect or from storage). */
@@ -1298,6 +1312,7 @@ interface NotificationEvent {
1298
1312
  declare class WorkspaceApi extends BaseApi {
1299
1313
  constructor(config: IOsConfig & {
1300
1314
  sessionId?: string;
1315
+ onUnauthorized?: () => void;
1301
1316
  });
1302
1317
  getWorkspaces(): Promise<IWorkspace[]>;
1303
1318
  createWorkspace(data: {
@@ -1671,23 +1686,11 @@ declare class EventEmitter {
1671
1686
  }
1672
1687
  declare const eventEmitter: EventEmitter;
1673
1688
 
1674
- /**
1675
- * Notify all subscribers to refetch credit balance (e.g. after consume or purchase).
1676
- * Called internally by useConsumeCredits, usePurchaseCredits on success.
1677
- */
1678
- declare function invalidateCreditBalance(): void;
1689
+ declare const invalidateCreditBalance: () => void;
1679
1690
 
1680
- /**
1681
- * Notify all subscribers to refetch quota usage (e.g. after recording usage).
1682
- * Called internally by useRecordUsage on success.
1683
- */
1684
- declare function invalidateQuotaUsage(): void;
1691
+ declare const invalidateQuotaUsage: () => void;
1685
1692
 
1686
- /**
1687
- * Notify all subscribers to refetch subscription (e.g. after update/cancel/resume).
1688
- * Called internally by useUpdateSubscription, useCancelSubscription, useResumeSubscription on success.
1689
- */
1690
- declare function invalidateSubscription(): void;
1693
+ declare const invalidateSubscription: () => void;
1691
1694
 
1692
1695
  /**
1693
1696
  * BuildBase URL parameter utilities.
@@ -2148,7 +2151,7 @@ declare function hasPermission(permission: string | string[], ctx: PermissionCon
2148
2151
  *
2149
2152
  * Or manually create `public/push-sw.js` with this content.
2150
2153
  */
2151
- declare const PUSH_SERVICE_WORKER_SCRIPT = "\n// BuildBase Push Notification Service Worker\n// Place this file in your app's public directory (e.g. public/push-sw.js)\n\nself.addEventListener('push', function(event) {\n if (!event.data) return;\n\n try {\n var payload = event.data.json();\n var title = payload.title || 'Notification';\n var options = {\n body: payload.body || '',\n icon: payload.icon || undefined,\n badge: payload.icon || undefined,\n data: { url: payload.url, ...(payload.data || {}) },\n tag: 'buildbase-push-' + Date.now(),\n };\n\n event.waitUntil(\n self.registration.showNotification(title, options)\n );\n } catch (e) {\n console.error('[PushSW] Failed to show notification:', e);\n }\n});\n\nself.addEventListener('notificationclick', function(event) {\n event.notification.close();\n\n var url = event.notification.data && event.notification.data.url;\n if (url) {\n event.waitUntil(\n clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function(clientList) {\n for (var i = 0; i < clientList.length; i++) {\n var client = clientList[i];\n if (client.url === url && 'focus' in client) {\n return client.focus();\n }\n }\n if (clients.openWindow) {\n return clients.openWindow(url);\n }\n })\n );\n }\n});\n";
2154
+ declare const PUSH_SERVICE_WORKER_SCRIPT = "\n// BuildBase Push Notification Service Worker\n// Place this file in your app's public directory (e.g. public/push-sw.js)\n\nself.addEventListener('push', function(event) {\n if (!event.data) return;\n\n try {\n const payload = event.data.json();\n const title = payload.title || 'Notification';\n const options = {\n body: payload.body || '',\n icon: payload.icon || undefined,\n badge: payload.icon || undefined,\n data: { url: payload.url, ...(payload.data || {}) },\n tag: 'buildbase-push-' + Date.now(),\n };\n\n event.waitUntil(\n self.registration.showNotification(title, options)\n );\n } catch (e) {\n console.error('[PushSW] Failed to show notification:', e);\n }\n});\n\nself.addEventListener('notificationclick', function(event) {\n event.notification.close();\n\n const url = event.notification.data && event.notification.data.url;\n if (url) {\n event.waitUntil(\n clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function(clientList) {\n for (let i = 0; i < clientList.length; i++) {\n const client = clientList[i];\n if (client.url === url && 'focus' in client) {\n return client.focus();\n }\n }\n if (clients.openWindow) {\n return clients.openWindow(url);\n }\n })\n );\n }\n});\n";
2152
2155
 
2153
2156
  interface BetaFormData {
2154
2157
  name?: string;
@@ -2206,6 +2209,9 @@ interface SDKMessages {
2206
2209
  error: string;
2207
2210
  refreshAction: string;
2208
2211
  retryAction: string;
2212
+ noPermissionTitle: string;
2213
+ noPermissionDescription: string;
2214
+ billingManageOnly: string;
2209
2215
  };
2210
2216
  };
2211
2217
  subscription: {
@@ -4473,7 +4479,7 @@ declare const useSubscriptionManagement: (workspaceId: string | null | undefined
4473
4479
  * return (
4474
4480
  * <div>
4475
4481
  * {invoices.map(invoice => (
4476
- * <InvoiceCard key={invoice._id} invoice={invoice} />
4482
+ * <InvoiceCard key={invoice.id} invoice={invoice} />
4477
4483
  * ))}
4478
4484
  * {hasMore && <button onClick={() => refetch()}>Load More</button>}
4479
4485
  * </div>
@@ -4501,7 +4507,7 @@ declare const useSubscriptionManagement: (workspaceId: string | null | undefined
4501
4507
  *
4502
4508
  * return (
4503
4509
  * <div>
4504
- * {invoices.map(invoice => <InvoiceCard key={invoice._id} invoice={invoice} />)}
4510
+ * {invoices.map(invoice => <InvoiceCard key={invoice.id} invoice={invoice} />)}
4505
4511
  * {hasMore && <button onClick={loadMore}>Load More</button>}
4506
4512
  * </div>
4507
4513
  * );