@butterbase/sdk 1.1.1 → 1.2.1

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 (95) hide show
  1. package/dist/admin/admin-client.d.ts +23 -0
  2. package/dist/admin/admin-client.d.ts.map +1 -0
  3. package/dist/admin/admin-client.js +32 -0
  4. package/dist/admin/admin-client.js.map +1 -0
  5. package/dist/admin/api-keys-client.d.ts +11 -0
  6. package/dist/admin/api-keys-client.d.ts.map +1 -0
  7. package/dist/admin/api-keys-client.js +34 -0
  8. package/dist/admin/api-keys-client.js.map +1 -0
  9. package/dist/admin/audit-logs-client.d.ts +9 -0
  10. package/dist/admin/audit-logs-client.d.ts.map +1 -0
  11. package/dist/admin/audit-logs-client.js +27 -0
  12. package/dist/admin/audit-logs-client.js.map +1 -0
  13. package/dist/admin/config-client.d.ts +11 -0
  14. package/dist/admin/config-client.d.ts.map +1 -0
  15. package/dist/admin/config-client.js +34 -0
  16. package/dist/admin/config-client.js.map +1 -0
  17. package/dist/admin/frontend-client.d.ts +14 -0
  18. package/dist/admin/frontend-client.d.ts.map +1 -0
  19. package/dist/admin/frontend-client.js +61 -0
  20. package/dist/admin/frontend-client.js.map +1 -0
  21. package/dist/admin/functions-client.d.ts +14 -0
  22. package/dist/admin/functions-client.d.ts.map +1 -0
  23. package/dist/admin/functions-client.js +68 -0
  24. package/dist/admin/functions-client.js.map +1 -0
  25. package/dist/admin/oauth-client.d.ts +13 -0
  26. package/dist/admin/oauth-client.d.ts.map +1 -0
  27. package/dist/admin/oauth-client.js +52 -0
  28. package/dist/admin/oauth-client.js.map +1 -0
  29. package/dist/admin/realtime-client.d.ts +13 -0
  30. package/dist/admin/realtime-client.d.ts.map +1 -0
  31. package/dist/admin/realtime-client.js +34 -0
  32. package/dist/admin/realtime-client.js.map +1 -0
  33. package/dist/admin/rls-client.d.ts +13 -0
  34. package/dist/admin/rls-client.d.ts.map +1 -0
  35. package/dist/admin/rls-client.js +55 -0
  36. package/dist/admin/rls-client.js.map +1 -0
  37. package/dist/admin/schema-client.d.ts +15 -0
  38. package/dist/admin/schema-client.d.ts.map +1 -0
  39. package/dist/admin/schema-client.js +42 -0
  40. package/dist/admin/schema-client.js.map +1 -0
  41. package/dist/admin/types.d.ts +171 -0
  42. package/dist/admin/types.d.ts.map +1 -0
  43. package/dist/admin/types.js +3 -0
  44. package/dist/admin/types.js.map +1 -0
  45. package/dist/ai/ai-client.d.ts +32 -0
  46. package/dist/ai/ai-client.d.ts.map +1 -0
  47. package/dist/ai/ai-client.js +126 -0
  48. package/dist/ai/ai-client.js.map +1 -0
  49. package/dist/ai/types.d.ts +47 -0
  50. package/dist/ai/types.d.ts.map +1 -0
  51. package/dist/ai/types.js +2 -0
  52. package/dist/ai/types.js.map +1 -0
  53. package/dist/auth/auth-client.d.ts +10 -1
  54. package/dist/auth/auth-client.d.ts.map +1 -1
  55. package/dist/auth/auth-client.js +59 -0
  56. package/dist/auth/auth-client.js.map +1 -1
  57. package/dist/billing/billing-client.d.ts +28 -0
  58. package/dist/billing/billing-client.d.ts.map +1 -0
  59. package/dist/billing/billing-client.js +135 -0
  60. package/dist/billing/billing-client.js.map +1 -0
  61. package/dist/billing/types.d.ts +93 -0
  62. package/dist/billing/types.d.ts.map +1 -0
  63. package/dist/billing/types.js +2 -0
  64. package/dist/billing/types.js.map +1 -0
  65. package/dist/errors/index.d.ts +26 -0
  66. package/dist/errors/index.d.ts.map +1 -0
  67. package/dist/errors/index.js +64 -0
  68. package/dist/errors/index.js.map +1 -0
  69. package/dist/index.d.ts +16 -1
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +17 -0
  72. package/dist/index.js.map +1 -1
  73. package/dist/lib/butterbase-client.d.ts +18 -0
  74. package/dist/lib/butterbase-client.d.ts.map +1 -1
  75. package/dist/lib/butterbase-client.js +82 -10
  76. package/dist/lib/butterbase-client.js.map +1 -1
  77. package/dist/lib/mutation-builders.d.ts +5 -0
  78. package/dist/lib/mutation-builders.d.ts.map +1 -1
  79. package/dist/lib/mutation-builders.js +14 -1
  80. package/dist/lib/mutation-builders.js.map +1 -1
  81. package/dist/lib/query-builder.d.ts +18 -1
  82. package/dist/lib/query-builder.d.ts.map +1 -1
  83. package/dist/lib/query-builder.js +52 -2
  84. package/dist/lib/query-builder.js.map +1 -1
  85. package/dist/realtime/realtime-client.d.ts +44 -0
  86. package/dist/realtime/realtime-client.d.ts.map +1 -0
  87. package/dist/realtime/realtime-client.js +327 -0
  88. package/dist/realtime/realtime-client.js.map +1 -0
  89. package/dist/realtime/types.d.ts +26 -0
  90. package/dist/realtime/types.d.ts.map +1 -0
  91. package/dist/realtime/types.js +2 -0
  92. package/dist/realtime/types.js.map +1 -0
  93. package/dist/types/index.d.ts +9 -0
  94. package/dist/types/index.d.ts.map +1 -1
  95. package/package.json +1 -1
@@ -0,0 +1,135 @@
1
+ export class BillingClient {
2
+ client;
3
+ constructor(client) {
4
+ this.client = client;
5
+ }
6
+ // ── Admin methods (require platform auth) ──
7
+ async connectOnboard() {
8
+ try {
9
+ const data = await this.client.request('POST', `/v1/${this.client.appId}/billing/connect/onboard`);
10
+ return { data, error: null };
11
+ }
12
+ catch (error) {
13
+ return { data: null, error: error };
14
+ }
15
+ }
16
+ async connectStatus() {
17
+ try {
18
+ const data = await this.client.request('GET', `/v1/${this.client.appId}/billing/connect/status`);
19
+ return { data, error: null };
20
+ }
21
+ catch (error) {
22
+ return { data: null, error: error };
23
+ }
24
+ }
25
+ async createPlan(params) {
26
+ try {
27
+ const data = await this.client.request('POST', `/v1/${this.client.appId}/billing/plans`, params);
28
+ return { data, error: null };
29
+ }
30
+ catch (error) {
31
+ return { data: null, error: error };
32
+ }
33
+ }
34
+ async updatePlan(planId, updates) {
35
+ try {
36
+ const data = await this.client.request('PUT', `/v1/${this.client.appId}/billing/plans/${planId}`, updates);
37
+ return { data, error: null };
38
+ }
39
+ catch (error) {
40
+ return { data: null, error: error };
41
+ }
42
+ }
43
+ async createProduct(params) {
44
+ try {
45
+ const data = await this.client.request('POST', `/v1/${this.client.appId}/billing/products`, params);
46
+ return { data, error: null };
47
+ }
48
+ catch (error) {
49
+ return { data: null, error: error };
50
+ }
51
+ }
52
+ async updateProduct(productId, updates) {
53
+ try {
54
+ const data = await this.client.request('PUT', `/v1/${this.client.appId}/billing/products/${productId}`, updates);
55
+ return { data, error: null };
56
+ }
57
+ catch (error) {
58
+ return { data: null, error: error };
59
+ }
60
+ }
61
+ // ── Client methods (end-user auth) ──
62
+ async listPlans() {
63
+ try {
64
+ const data = await this.client.request('GET', `/v1/${this.client.appId}/billing/plans`);
65
+ return { data: data.plans, error: null };
66
+ }
67
+ catch (error) {
68
+ return { data: null, error: error };
69
+ }
70
+ }
71
+ async listProducts() {
72
+ try {
73
+ const data = await this.client.request('GET', `/v1/${this.client.appId}/billing/products`);
74
+ return { data: data.products, error: null };
75
+ }
76
+ catch (error) {
77
+ return { data: null, error: error };
78
+ }
79
+ }
80
+ async subscribe(params) {
81
+ try {
82
+ const data = await this.client.request('POST', `/v1/${this.client.appId}/billing/subscribe`, params);
83
+ return { data, error: null };
84
+ }
85
+ catch (error) {
86
+ return { data: null, error: error };
87
+ }
88
+ }
89
+ async getSubscription() {
90
+ try {
91
+ const data = await this.client.request('GET', `/v1/${this.client.appId}/billing/subscription`);
92
+ return { data: data.subscription, error: null };
93
+ }
94
+ catch (error) {
95
+ return { data: null, error: error };
96
+ }
97
+ }
98
+ async cancel() {
99
+ try {
100
+ const data = await this.client.request('POST', `/v1/${this.client.appId}/billing/cancel`);
101
+ return { data, error: null };
102
+ }
103
+ catch (error) {
104
+ return { data: null, error: error };
105
+ }
106
+ }
107
+ async purchase(params) {
108
+ try {
109
+ const data = await this.client.request('POST', `/v1/${this.client.appId}/billing/purchase`, params);
110
+ return { data, error: null };
111
+ }
112
+ catch (error) {
113
+ return { data: null, error: error };
114
+ }
115
+ }
116
+ async listOrders() {
117
+ try {
118
+ const data = await this.client.request('GET', `/v1/${this.client.appId}/billing/orders`);
119
+ return { data: data.orders, error: null };
120
+ }
121
+ catch (error) {
122
+ return { data: null, error: error };
123
+ }
124
+ }
125
+ async getOrder(orderId) {
126
+ try {
127
+ const data = await this.client.request('GET', `/v1/${this.client.appId}/billing/orders/${orderId}`);
128
+ return { data, error: null };
129
+ }
130
+ catch (error) {
131
+ return { data: null, error: error };
132
+ }
133
+ }
134
+ }
135
+ //# sourceMappingURL=billing-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"billing-client.js","sourceRoot":"","sources":["../../src/billing/billing-client.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,aAAa;IAChB,MAAM,CAAmB;IAEjC,YAAY,MAAwB;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,8CAA8C;IAE9C,KAAK,CAAC,cAAc;QAClB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACpC,MAAM,EAAE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,0BAA0B,CAC3D,CAAC;YACF,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAc,EAAE,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACpC,KAAK,EAAE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,yBAAyB,CACzD,CAAC;YACF,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAc,EAAE,CAAC;QAC/C,CAAC;IACH,CA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M,IAAI,CAAC,MAAM,CAAC,OAAO,CACpC,MAAM,EAAE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,mBAAmB,EAAE,MAAM,CAC5D,CAAC;YACF,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAc,EAAE,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACpC,KAAK,EAAE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,iBAAiB,CACjD,CAAC;YACF,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAC5C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAc,EAAE,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAe;QAC5B,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACpC,KAAK,EAAE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,mBAAmB,OAAO,EAAE,CAC5D,CAAC;YACF,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAc,EAAE,CAAC;QAC/C,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,93 @@
1
+ export interface Plan {
2
+ id: string;
3
+ name: string;
4
+ price_cents: number;
5
+ interval: 'month' | 'year';
6
+ features: string[];
7
+ active: boolean;
8
+ created_at: string;
9
+ updated_at?: string;
10
+ }
11
+ export interface CreatePlanParams {
12
+ name: string;
13
+ priceCents: number;
14
+ interval?: 'month' | 'year';
15
+ features?: string[];
16
+ }
17
+ export interface Product {
18
+ id: string;
19
+ name: string;
20
+ description?: string;
21
+ price_cents: number;
22
+ currency: string;
23
+ active: boolean;
24
+ metadata: Record<string, string>;
25
+ created_at: string;
26
+ updated_at?: string;
27
+ }
28
+ export interface CreateProductParams {
29
+ name: string;
30
+ description?: string;
31
+ priceCents: number;
32
+ metadata?: Record<string, string>;
33
+ }
34
+ export interface Subscription {
35
+ id: string;
36
+ plan_id: string;
37
+ status: string;
38
+ current_period_start: string;
39
+ current_period_end: string;
40
+ cancel_at_period_end: boolean;
41
+ plan_name: string;
42
+ price_cents: number;
43
+ interval: string;
44
+ features: string[];
45
+ }
46
+ export interface SubscribeParams {
47
+ planId: string;
48
+ successUrl?: string;
49
+ cancelUrl?: string;
50
+ }
51
+ export interface CheckoutSession {
52
+ sessionId: string;
53
+ url: string;
54
+ }
55
+ export interface PurchaseParams {
56
+ productId: string;
57
+ successUrl?: string;
58
+ cancelUrl?: string;
59
+ }
60
+ export interface PurchaseResult {
61
+ sessionId: string;
62
+ url: string;
63
+ orderId: string;
64
+ }
65
+ export interface Order {
66
+ id: string;
67
+ product_id: string;
68
+ amount_cents: number;
69
+ platform_fee_cents: number;
70
+ currency: string;
71
+ status: string;
72
+ created_at: string;
73
+ refunded_at?: string;
74
+ product_name: string;
75
+ product_description?: string;
76
+ metadata?: Record<string, any>;
77
+ }
78
+ export interface ConnectOnboardParams {
79
+ returnUrl?: string;
80
+ refreshUrl?: string;
81
+ }
82
+ export interface ConnectOnboardResult {
83
+ accountId: string;
84
+ onboardingUrl: string;
85
+ }
86
+ export interface ConnectStatus {
87
+ connected: boolean;
88
+ accountId?: string;
89
+ chargesEnabled?: boolean;
90
+ payoutsEnabled?: boolean;
91
+ detailsSubmitted?: boolean;
92
+ }
93
+ //# sourceMappingURL=types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AAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/billing/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ export declare class ButterbaseError extends Error {
2
+ readonly code: string;
3
+ readonly status: number;
4
+ readonly remediation?: string;
5
+ constructor(message: string, code: string, status: number, remediation?: string);
6
+ }
7
+ export declare class AuthError extends ButterbaseError {
8
+ constructor(message: string, code: string, status: number, remediation?: string);
9
+ }
10
+ export declare class ValidationError extends ButterbaseError {
11
+ constructor(message: string, code: string, status: number, remediation?: string);
12
+ }
13
+ export declare class NotFoundError extends ButterbaseError {
14
+ constructor(message: string, code: string, status: number, remediation?: string);
15
+ }
16
+ export declare class QuotaError extends ButterbaseError {
17
+ constructor(message: string, code: string, status: number, remediation?: string);
18
+ }
19
+ export declare class NetworkError extends ButterbaseError {
20
+ constructor(message: string, code?: string, status?: number, remediation?: string);
21
+ }
22
+ /**
23
+ * Parse an API error response into the appropriate ButterbaseError subclass
24
+ */
25
+ export declare function parseApiError(status: number, body: any): ButterbaseError;
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;gBAElB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;CAOhF;AAED,qBAAa,SAAU,SAAQ,eAAe;gBAChC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;CAIhF;AAED,qBAAa,eAAgB,SAAQ,eAAe;gBACtC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;CAIhF;AAED,qBAAa,aAAc,SAAQ,eAAe;gBACpC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;CAIhF;AAED,qBAAa,UAAW,SAAQ,eAAe;gBACjC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;CAIhF;AAED,qBAAa,YAAa,SAAQ,eAAe;gBACnC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAwB,EAAE,MAAM,GAAE,MAAU,EAAE,WAAW,CAAC,EAAE,MAAM;CAItG;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,eAAe,CAsBxE"}
@@ -0,0 +1,64 @@
1
+ export class ButterbaseError extends Error {
2
+ code;
3
+ status;
4
+ remediation;
5
+ constructor(message, code, status, remediation) {
6
+ super(message);
7
+ this.name = 'ButterbaseError';
8
+ this.code = code;
9
+ this.status = status;
10
+ this.remediation = remediation;
11
+ }
12
+ }
13
+ export class AuthError extends ButterbaseError {
14
+ constructor(message, code, status, remediation) {
15
+ super(message, code, status, remediation);
16
+ this.name = 'AuthError';
17
+ }
18
+ }
19
+ export class ValidationError extends ButterbaseError {
20
+ constructor(message, code, status, remediation) {
21
+ super(message, code, status, remediation);
22
+ this.name = 'ValidationError';
23
+ }
24
+ }
25
+ export class NotFoundError extends ButterbaseError {
26
+ constructor(message, code, status, remediation) {
27
+ super(message, code, status, remediation);
28
+ this.name = 'NotFoundError';
29
+ }
30
+ }
31
+ export class QuotaError extends ButterbaseError {
32
+ constructor(message, code, status, remediation) {
33
+ super(message, code, status, remediation);
34
+ this.name = 'QuotaError';
35
+ }
36
+ }
37
+ export class NetworkError extends ButterbaseError {
38
+ constructor(message, code = 'NETWORK_ERROR', status = 0, remediation) {
39
+ super(message, code, status, remediation);
40
+ this.name = 'NetworkError';
41
+ }
42
+ }
43
+ /**
44
+ * Parse an API error response into the appropriate ButterbaseError subclass
45
+ */
46
+ export function parseApiError(status, body) {
47
+ const message = body?.error || body?.message || 'Unknown error';
48
+ const code = body?.code || '';
49
+ const remediation = body?.remediation;
50
+ if (status === 401 || status === 403 || code.startsWith('AUTH_')) {
51
+ return new AuthError(message, code || 'AUTH_UNAUTHORIZED', status, remediation);
52
+ }
53
+ if (status === 404 || code === 'RESOURCE_NOT_FOUND') {
54
+ return new NotFoundError(message, code || 'RESOURCE_NOT_FOUND', status, remediation);
55
+ }
56
+ if (status === 429 || code.startsWith('QUOTA_')) {
57
+ return new QuotaError(message, code || 'QUOTA_EXCEEDED', status, remediation);
58
+ }
59
+ if (status === 400 || status === 422 || code.startsWith('VALIDATION_')) {
60
+ return new ValidationError(message, code || 'VALIDATION_INVALID', status, remediation);
61
+ }
62
+ return new ButterbaseError(message, code || 'UNKNOWN_ERROR', status, remediation);
63
+ }
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,IAAI,CAAS;IACb,MAA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BAAoB,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACzF,CAAC;IAED,OAAO,IAAI,eAAe,CAAC,OAAO,EAAE,IAAI,IAAI,eAAe,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AACpF,CAAC"}
package/dist/index.d.ts CHANGED
@@ -4,8 +4,23 @@ export { InsertBuilder, UpdateBuilder, DeleteBuilder } from './lib/mutation-buil
4
4
  export { AuthClient } from './auth/auth-client.js';
5
5
  export { StorageClient } from './storage/storage-client.js';
6
6
  export { FunctionsClient } from './functions/functions-client.js';
7
+ export { AiClient } from './ai/ai-client.js';
8
+ export { BillingClient } from './billing/billing-client.js';
9
+ export { AdminClient } from './admin/admin-client.js';
10
+ export { AdminSchemaClient } from './admin/schema-client.js';
11
+ export { AdminRlsClient } from './admin/rls-client.js';
12
+ export { AdminOAuthClient } from './admin/oauth-client.js';
13
+ export { AdminConfigClient } from './admin/config-client.js';
14
+ export { AdminFunctionsClient } from './admin/functions-client.js';
15
+ export { AdminApiKeysClient } from './admin/api-keys-client.js';
16
+ export { AdminAuditLogsClient } from './admin/audit-logs-client.js';
17
+ export { AdminFrontendClient } from './admin/frontend-client.js';
18
+ export { AdminRealtimeClient } from './admin/realtime-client.js';
19
+ export { RealtimeClient } from './realtime/realtime-client.js';
20
+ export { ButterbaseError, AuthError, ValidationError, NotFoundError, QuotaError, NetworkError, } from './errors/index.js';
7
21
  export { SessionManager } from './auth/session-manager.js';
8
22
  export { LocalSessionStorage, MemorySessionStorage, detectSessionStorage } from './auth/session-storage.js';
9
23
  export type { SessionStorage } from './auth/session-storage.js';
10
- export type { ButterbaseClientOptions, ButterbaseResponse, User, Session, SignUpParams, SignInParams, AuthResponse, LoginResponse, SignupResponse, OAuthParams, StorageObject, UploadResponse, DownloadUrlResponse, QueryOperator, QueryFilter, OrderByOptions, InvokeFunctionOptions, AuthEvent, AuthChangeCallback, Subscription, } from './types/index.js';
24
+ export type { ButterbaseClientOptions, ButterbaseResponse, User, Session, SignUpParams, SignInParams, AuthResponse, LoginResponse, SignupResponse, OAuthParams, OAuthCallbackResult, StorageObject, UploadResponse, DownloadUrlResponse, QueryOperator, QueryFilter, OrderByOptions, InvokeFunctionOptions, AuthEvent, AuthChangeCallback, Subscription, ChatMessage, ChatOptions, ChatCompletion, ChatStreamChunk, AiConfig, AiUsage, Plan, CreatePlanParams, Product, CreateProductParams, BillingSubscription, CheckoutSession, SubscribeParams, PurchaseParams, PurchaseResult, Order, ConnectOnboardResult, ConnectStatus, SchemaTable, SchemaColumn, SchemaIndex, SchemaDefinition, MigrationResult, Migration, RlsPolicy, CreatePolicyParams, OAuthConfig, OAuthConfigParams, AppConfig, CorsConfig, JwtConfig, DeployFunctionParams, FunctionDetails, FunctionSummary, FunctionLog, LogOptions, ApiKey, ApiKeySummary, AuditLog, AuditLogQueryOptions, Deployment, CreateDeploymentParams, RealtimeConfig, RealtimeTableResult, } from './types/index.js';
25
+ export type { RealtimeStatus, RealtimeChange, PresenceEvent, ChangeCallback, PresenceCallback, StatusCallback, RealtimeSubscription, } from './realtime/types.js';
11
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG5E,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGtD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAGzF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAGlE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,M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AC/E,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,oBAAoB,EAC9B,UAAU,EAAE,sBAAsB,EAElC,cAAc,EAAE,mBAAmB,GACpC,MAAM,kBAAkB,CAAC;AAG1B,YAAY,EACV,cAAc,EAAE,cAAc,EAAE,aAAa,EAC7C,cAAc,EAAE,gBAAgB,EAAE,cAAc,EAChD,oBAAoB,GACrB,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -8,6 +8,23 @@ export { InsertBuilder, UpdateBuilder, DeleteBuilder } from './lib/mutation-buil
8
8
  export { AuthClient } from './auth/auth-client.js';
9
9
  export { StorageClient } from './storage/storage-client.js';
10
10
  export { FunctionsClient } from './functions/functions-client.js';
11
+ export { AiClient } from './ai/ai-client.js';
12
+ export { BillingClient } from './billing/billing-client.js';
13
+ // Admin client
14
+ export { AdminClient } from './admin/admin-client.js';
15
+ export { AdminSchemaClient } from './admin/schema-client.js';
16
+ export { AdminRlsClient } from './admin/rls-client.js';
17
+ export { AdminOAuthClient } from './admin/oauth-client.js';
18
+ export { AdminConfigClient } from './admin/config-client.js';
19
+ export { AdminFunctionsClient } from './admin/functions-client.js';
20
+ export { AdminApiKeysClient } from './admin/api-keys-client.js';
21
+ export { AdminAuditLogsClient } from './admin/audit-logs-client.js';
22
+ export { AdminFrontendClient } from './admin/frontend-client.js';
23
+ export { AdminRealtimeClient } from './admin/realtime-client.js';
24
+ // Realtime client
25
+ export { RealtimeClient } from './realtime/realtime-client.js';
26
+ // Error types
27
+ export { ButterbaseError, AuthError, ValidationError, NotFoundError, QuotaError, NetworkError, } from './errors/index.js';
11
28
  // Session persistence
12
29
  export { SessionManager } from './auth/session-manager.js';
13
30
  export { LocalSessionStorage, MemorySessionStorage, detectSessionStorage } from './auth/session-storage.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,gBAAgB,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uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,kBAAkB;AAClB,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,cAAc;AACd,OAAO,EACL,eAAe,EACf,SAAS,EACT,eAAe,EACf,aAAa,EACb,UAAU,EACV,YAAY,GACb,MAAM,mBAAmB,CAAC;AAE3B,sBAAsB;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -4,6 +4,10 @@ import { StorageClient } from '../storage/storage-client.js';
4
4
  import { FunctionsClient } from '../functions/functions-client.js';
5
5
  import { SessionManager } from '../auth/session-manager.js';
6
6
  import { QueryBuilder } from './query-builder.js';
7
+ import { AiClient } from '../ai/ai-client.js';
8
+ import { BillingClient } from '../billing/billing-client.js';
9
+ import { AdminClient } from '../admin/admin-client.js';
10
+ import { RealtimeClient } from '../realtime/realtime-client.js';
7
11
  export declare class ButterbaseClient {
8
12
  readonly appId: string;
9
13
  private apiUrl;
@@ -14,7 +18,16 @@ export declare class ButterbaseClient {
14
18
  readonly auth: AuthClient;
15
19
  readonly storage: StorageClient;
16
20
  readonly functions: FunctionsClient;
21
+ readonly ai: AiClient;
22
+ readonly billing: BillingClient;
23
+ readonly admin: AdminClient;
24
+ readonly realtime: RealtimeClient;
17
25
  constructor(options: ButterbaseClientOptions);
26
+ /**
27
+ * If the current URL contains OAuth callback tokens, handle them automatically.
28
+ * This fires-and-forgets — consumers who need the result should use auth.handleOAuthCallback() instead.
29
+ */
30
+ private detectOAuthTokensFromUrl;
18
31
  /**
19
32
  * Create a query builder for a table
20
33
  */
@@ -44,6 +57,11 @@ export declare class ButterbaseClient {
44
57
  * Internal request method for blob responses (e.g., file exports)
45
58
  */
46
59
  requestBlob(method: string, path: string, body?: any, customHeaders?: Record<string, string>): Promise<Blob>;
60
+ /**
61
+ * Internal request method that returns the raw Response (for streaming).
62
+ * Handles auth headers but does not parse the body.
63
+ */
64
+ requestRaw(method: string, path: string, body?: any, customHeaders?: Record<string, string>): Promise<Response>;
47
65
  }
48
66
  /**
49
67
  * Create a new Butterbase client instance
@@ -1 +1 @@
1
- {"version":3,"file":"butterbase-client.d.ts","sourceRoot":"","sources":["../../src/lib/butterbase-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACnG,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,qBAAa,gBAAgB;IAC3B,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,OAAO,CAA0B;IAEzC,SAAgB,cAAc,EAAE,cAAc,CAAC;IAC/C,SAAgB,IAAI,EAAE,UAAU,CAAC;IACjC,SAAgB,OAAO,EAAE,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AM,EACZ,IAAI,CAAC,EAAE,GAAG,EACV,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACrC,OAAO,CAAC,CAAC,CAAC;IA6Db;;OAEG;IACG,WAAW,CACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,GAAG,EACV,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACrC,OAAO,CAAC,IAAI,CAAC;IA4ChB;;;OAGG;IACG,UAAU,CACd,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,GAAG,EACV,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACrC,OAAO,CAAC,QAAQ,CAAC;CA4CrB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,uBAAuB,GAAG,gBAAgB,CAE/E"}
@@ -4,6 +4,11 @@ import { FunctionsClient } from '../functions/functions-client.js';
4
4
  import { SessionManager } from '../auth/session-manager.js';
5
5
  import { detectSessionStorage, MemorySessionStorage } from '../auth/session-storage.js';
6
6
  import { QueryBuilder } from './query-builder.js';
7
+ import { parseApiError } from '../errors/index.js';
8
+ import { AiClient } from '../ai/ai-client.js';
9
+ import { BillingClient } from '../billing/billing-client.js';
10
+ import { AdminClient } from '../admin/admin-client.js';
11
+ import { RealtimeClient } from '../realtime/realtime-client.js';
7
12
  export class ButterbaseClient {
8
13
  appId;
9
14
  apiUrl;
@@ -14,6 +19,10 @@ export class ButterbaseClient {
14
19
  auth;
15
20
  storage;
16
21
  functions;
22
+ ai;
23
+ billing;
24
+ admin;
25
+ realtime;
17
26
  constructor(options) {
18
27
  this.appId = options.appId;
19
28
  this.apiUrl = options.apiUrl;
@@ -28,11 +37,34 @@ export class ButterbaseClient {
28
37
  this.auth = new AuthClient(this);
29
38
  this.storage = new StorageClient(this);
30
39
  this.functions = new FunctionsClient(this);
40
+ this.ai = new AiClient(this);
41
+ this.billing = new BillingClient(this);
42
+ this.admin = new AdminClient(this);
43
+ this.realtime = new RealtimeClient(this);
31
44
  // Restore session from storage
32
45
  const restored = this.sessionManager.restoreSession();
33
46
  if (restored) {
34
47
  this.accessToken = restored.accessToken;
35
48
  }
49
+ // Auto-detect OAuth tokens in the URL (browser only, opt-out with detectSessionFromUrl: false)
50
+ if (options.detectSessionFromUrl !== false) {
51
+ this.detectOAuthTokensFromUrl();
52
+ }
53
+ }
54
+ /**
55
+ * If the current URL contains OAuth callback tokens, handle them automatically.
56
+ * This fires-and-forgets — consumers who need the result should use auth.handleOAuthCallback() instead.
57
+ */
58
+ detectOAuthTokensFromUrl() {
59
+ if (typeof globalThis.window === 'undefined' || !globalThis.window.location)
60
+ return;
61
+ const params = new URLSearchParams(window.location.search);
62
+ if (params.has('access_token') && params.has('refresh_token')) {
63
+ // Kick off the callback handler; errors are surfaced via onAuthStateChange
64
+ this.auth.handleOAuthCallback().catch(() => {
65
+ // Swallow — apps that care should call handleOAuthCallback() explicitly
66
+ });
67
+ }
36
68
  }
37
69
  /**
38
70
  * Create a query builder for a table
@@ -109,15 +141,14 @@ export class ButterbaseClient {
109
141
  if (response.status === 401 && this.options.onUnauthorized) {
110
142
  this.options.onUnauthorized();
111
143
  }
112
- let errorMessage = response.statusText;
144
+ let errorBody = {};
113
145
  try {
114
- const errorData = await response.json();
115
- errorMessage = errorData.error || errorData.message || errorMessage;
146
+ errorBody = await response.json();
116
147
  }
117
148
  catch {
118
- // If JSON parsing fails, use statusText
149
+ errorBody = { error: response.statusText };
119
150
  }
120
- throw new Error(errorMessage);
151
+ throw parseApiError(response.status, errorBody);
121
152
  }
122
153
  // Handle 204 No Content
123
154
  if (response.status === 204) {
@@ -160,18 +191,59 @@ export class ButterbaseClient {
160
191
  if (response.status === 401 && this.options.onUnauthorized) {
161
192
  this.options.onUnauthorized();
162
193
  }
163
- let errorMessage = response.statusText;
194
+ let errorBody = {};
164
195
  try {
165
- const errorData = await response.json();
166
- errorMessage = errorData.error || errorData.message || errorMessage;
196
+ errorBody = await response.json();
167
197
  }
168
198
  catch {
169
- // If JSON parsing fails, use statusText
199
+ errorBody = { error: response.statusText };
170
200
  }
171
- throw new Error(errorMessage);
201
+ throw parseApiError(response.status, errorBody);
172
202
  }
173
203
  return response.blob();
174
204
  }
205
+ /**
206
+ * Internal request method that returns the raw Response (for streaming).
207
+ * Handles auth headers but does not parse the body.
208
+ */
209
+ async requestRaw(method, path, body, customHeaders) {
210
+ if (!path.endsWith('/refresh')) {
211
+ await this.ensureValidToken();
212
+ }
213
+ const headers = {
214
+ ...customHeaders,
215
+ };
216
+ const serializedBody = body !== undefined && body !== null ? JSON.stringify(body) : undefined;
217
+ if (serializedBody !== undefined) {
218
+ headers['Content-Type'] = 'application/json';
219
+ }
220
+ if (this.accessToken) {
221
+ headers['Authorization'] = `Bearer ${this.accessToken}`;
222
+ }
223
+ else if (this.anonKey) {
224
+ headers['Authorization'] = `Bearer ${this.anonKey}`;
225
+ }
226
+ const url = `${this.apiUrl}${path}`;
227
+ const response = await fetch(url, {
228
+ method,
229
+ headers,
230
+ body: serializedBody,
231
+ });
232
+ if (!response.ok) {
233
+ if (response.status === 401 && this.options.onUnauthorized) {
234
+ this.options.onUnauthorized();
235
+ }
236
+ let errorBody = {};
237
+ try {
238
+ errorBody = await response.json();
239
+ }
240
+ catch {
241
+ errorBody = { error: response.statusText };
242
+ }
243
+ throw parseApiError(response.status, errorBody);
244
+ }
245
+ return response;
246
+ }
175
247
  }
176
248
  /**
177
249
  * Create a new Butterbase client instance