@fluxbase/sdk 0.0.1-rc.111 → 0.0.1-rc.113

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.
package/dist/index.js CHANGED
@@ -4608,7 +4608,7 @@ var EmailSettingsManager = class {
4608
4608
  /**
4609
4609
  * Get current email provider settings
4610
4610
  *
4611
- * Returns the current email configuration. Sensitive values (passwords, API keys)
4611
+ * Returns the current email configuration. Sensitive values (passwords, client keys)
4612
4612
  * are not returned - instead, boolean flags indicate whether they are set.
4613
4613
  *
4614
4614
  * @returns Promise resolving to EmailProviderSettings
@@ -4636,7 +4636,7 @@ var EmailSettingsManager = class {
4636
4636
  * Update email provider settings
4637
4637
  *
4638
4638
  * Supports partial updates - only provide the fields you want to change.
4639
- * Secret fields (passwords, API keys) are only updated if provided.
4639
+ * Secret fields (passwords, client keys) are only updated if provided.
4640
4640
  *
4641
4641
  * @param request - Settings to update (partial update supported)
4642
4642
  * @returns Promise resolving to EmailProviderSettings - Updated settings
@@ -5570,118 +5570,119 @@ var ImpersonationManager = class {
5570
5570
  };
5571
5571
 
5572
5572
  // src/management.ts
5573
- var APIKeysManager = class {
5573
+ var ClientKeysManager = class {
5574
5574
  constructor(fetch2) {
5575
5575
  this.fetch = fetch2;
5576
5576
  }
5577
5577
  /**
5578
- * Create a new API key
5578
+ * Create a new client key
5579
5579
  *
5580
- * @param request - API key configuration
5581
- * @returns Created API key with the full key value (only shown once)
5580
+ * @param request - Client key configuration
5581
+ * @returns Created client key with the full key value (only shown once)
5582
5582
  *
5583
5583
  * @example
5584
5584
  * ```typescript
5585
- * const { api_key, key } = await client.management.apiKeys.create({
5585
+ * const { client_key, key } = await client.management.clientKeys.create({
5586
5586
  * name: 'Production Service',
5587
- * description: 'API key for production service',
5587
+ * description: 'Client key for production service',
5588
5588
  * scopes: ['read:users', 'write:users'],
5589
5589
  * rate_limit_per_minute: 100,
5590
5590
  * expires_at: '2025-12-31T23:59:59Z'
5591
5591
  * })
5592
5592
  *
5593
5593
  * // Store the key securely - it won't be shown again
5594
- * console.log('API Key:', key)
5594
+ * console.log('Client Key:', key)
5595
5595
  * ```
5596
5596
  */
5597
5597
  async create(request) {
5598
- return await this.fetch.post("/api/v1/api-keys", request);
5598
+ return await this.fetch.post("/api/v1/client-keys", request);
5599
5599
  }
5600
5600
  /**
5601
- * List all API keys for the authenticated user
5601
+ * List all client keys for the authenticated user
5602
5602
  *
5603
- * @returns List of API keys (without full key values)
5603
+ * @returns List of client keys (without full key values)
5604
5604
  *
5605
5605
  * @example
5606
5606
  * ```typescript
5607
- * const { api_keys, total } = await client.management.apiKeys.list()
5607
+ * const { client_keys, total } = await client.management.clientKeys.list()
5608
5608
  *
5609
- * api_keys.forEach(key => {
5609
+ * client_keys.forEach(key => {
5610
5610
  * console.log(`${key.name}: ${key.key_prefix}... (expires: ${key.expires_at})`)
5611
5611
  * })
5612
5612
  * ```
5613
5613
  */
5614
5614
  async list() {
5615
- return await this.fetch.get("/api/v1/api-keys");
5615
+ return await this.fetch.get("/api/v1/client-keys");
5616
5616
  }
5617
5617
  /**
5618
- * Get a specific API key by ID
5618
+ * Get a specific client key by ID
5619
5619
  *
5620
- * @param keyId - API key ID
5621
- * @returns API key details
5620
+ * @param keyId - Client key ID
5621
+ * @returns Client key details
5622
5622
  *
5623
5623
  * @example
5624
5624
  * ```typescript
5625
- * const apiKey = await client.management.apiKeys.get('key-uuid')
5626
- * console.log('Last used:', apiKey.last_used_at)
5625
+ * const clientKey = await client.management.clientKeys.get('key-uuid')
5626
+ * console.log('Last used:', clientKey.last_used_at)
5627
5627
  * ```
5628
5628
  */
5629
5629
  async get(keyId) {
5630
- return await this.fetch.get(`/api/v1/api-keys/${keyId}`);
5630
+ return await this.fetch.get(`/api/v1/client-keys/${keyId}`);
5631
5631
  }
5632
5632
  /**
5633
- * Update an API key
5633
+ * Update a client key
5634
5634
  *
5635
- * @param keyId - API key ID
5635
+ * @param keyId - Client key ID
5636
5636
  * @param updates - Fields to update
5637
- * @returns Updated API key
5637
+ * @returns Updated client key
5638
5638
  *
5639
5639
  * @example
5640
5640
  * ```typescript
5641
- * const updated = await client.management.apiKeys.update('key-uuid', {
5641
+ * const updated = await client.management.clientKeys.update('key-uuid', {
5642
5642
  * name: 'Updated Name',
5643
5643
  * rate_limit_per_minute: 200
5644
5644
  * })
5645
5645
  * ```
5646
5646
  */
5647
5647
  async update(keyId, updates) {
5648
- return await this.fetch.patch(`/api/v1/api-keys/${keyId}`, updates);
5648
+ return await this.fetch.patch(`/api/v1/client-keys/${keyId}`, updates);
5649
5649
  }
5650
5650
  /**
5651
- * Revoke an API key
5651
+ * Revoke a client key
5652
5652
  *
5653
5653
  * Revoked keys can no longer be used but remain in the system for audit purposes.
5654
5654
  *
5655
- * @param keyId - API key ID
5655
+ * @param keyId - Client key ID
5656
5656
  * @returns Revocation confirmation
5657
5657
  *
5658
5658
  * @example
5659
5659
  * ```typescript
5660
- * await client.management.apiKeys.revoke('key-uuid')
5661
- * console.log('API key revoked')
5660
+ * await client.management.clientKeys.revoke('key-uuid')
5661
+ * console.log('Client key revoked')
5662
5662
  * ```
5663
5663
  */
5664
5664
  async revoke(keyId) {
5665
- return await this.fetch.post(`/api/v1/api-keys/${keyId}/revoke`, {});
5665
+ return await this.fetch.post(`/api/v1/client-keys/${keyId}/revoke`, {});
5666
5666
  }
5667
5667
  /**
5668
- * Delete an API key
5668
+ * Delete a client key
5669
5669
  *
5670
- * Permanently removes the API key from the system.
5670
+ * Permanently removes the client key from the system.
5671
5671
  *
5672
- * @param keyId - API key ID
5672
+ * @param keyId - Client key ID
5673
5673
  * @returns Deletion confirmation
5674
5674
  *
5675
5675
  * @example
5676
5676
  * ```typescript
5677
- * await client.management.apiKeys.delete('key-uuid')
5678
- * console.log('API key deleted')
5677
+ * await client.management.clientKeys.delete('key-uuid')
5678
+ * console.log('Client key deleted')
5679
5679
  * ```
5680
5680
  */
5681
5681
  async delete(keyId) {
5682
- return await this.fetch.delete(`/api/v1/api-keys/${keyId}`);
5682
+ return await this.fetch.delete(`/api/v1/client-keys/${keyId}`);
5683
5683
  }
5684
5684
  };
5685
+ var APIKeysManager = ClientKeysManager;
5685
5686
  var WebhooksManager = class {
5686
5687
  constructor(fetch2) {
5687
5688
  this.fetch = fetch2;
@@ -5930,7 +5931,8 @@ var InvitationsManager = class {
5930
5931
  };
5931
5932
  var FluxbaseManagement = class {
5932
5933
  constructor(fetch2) {
5933
- this.apiKeys = new APIKeysManager(fetch2);
5934
+ this.clientKeys = new ClientKeysManager(fetch2);
5935
+ this.apiKeys = this.clientKeys;
5934
5936
  this.webhooks = new WebhooksManager(fetch2);
5935
5937
  this.invitations = new InvitationsManager(fetch2);
5936
5938
  }
@@ -9695,6 +9697,355 @@ fragment TypeRef on __Type {
9695
9697
  }
9696
9698
  `;
9697
9699
 
9700
+ // src/branching.ts
9701
+ var FluxbaseBranching = class {
9702
+ constructor(fetch2) {
9703
+ this.fetch = fetch2;
9704
+ }
9705
+ /**
9706
+ * List all database branches
9707
+ *
9708
+ * @param options - Filter and pagination options
9709
+ * @returns Promise resolving to { data, error } tuple with branches list
9710
+ *
9711
+ * @example
9712
+ * ```typescript
9713
+ * // List all branches
9714
+ * const { data, error } = await client.branching.list()
9715
+ *
9716
+ * // Filter by status
9717
+ * const { data } = await client.branching.list({ status: 'ready' })
9718
+ *
9719
+ * // Filter by type
9720
+ * const { data } = await client.branching.list({ type: 'preview' })
9721
+ *
9722
+ * // Only show my branches
9723
+ * const { data } = await client.branching.list({ mine: true })
9724
+ *
9725
+ * // Pagination
9726
+ * const { data } = await client.branching.list({ limit: 10, offset: 20 })
9727
+ * ```
9728
+ */
9729
+ async list(options) {
9730
+ try {
9731
+ const params = new URLSearchParams();
9732
+ if (options?.status) {
9733
+ params.append("status", options.status);
9734
+ }
9735
+ if (options?.type) {
9736
+ params.append("type", options.type);
9737
+ }
9738
+ if (options?.githubRepo) {
9739
+ params.append("github_repo", options.githubRepo);
9740
+ }
9741
+ if (options?.mine) {
9742
+ params.append("mine", "true");
9743
+ }
9744
+ if (options?.limit !== void 0) {
9745
+ params.append("limit", options.limit.toString());
9746
+ }
9747
+ if (options?.offset !== void 0) {
9748
+ params.append("offset", options.offset.toString());
9749
+ }
9750
+ const queryString = params.toString();
9751
+ const url = `/api/v1/admin/branches${queryString ? `?${queryString}` : ""}`;
9752
+ const response = await this.fetch.get(url);
9753
+ return { data: response, error: null };
9754
+ } catch (err) {
9755
+ return { data: null, error: err };
9756
+ }
9757
+ }
9758
+ /**
9759
+ * Get a specific branch by ID or slug
9760
+ *
9761
+ * @param idOrSlug - Branch ID (UUID) or slug
9762
+ * @returns Promise resolving to { data, error } tuple with branch details
9763
+ *
9764
+ * @example
9765
+ * ```typescript
9766
+ * // Get by slug
9767
+ * const { data, error } = await client.branching.get('feature/add-auth')
9768
+ *
9769
+ * // Get by ID
9770
+ * const { data } = await client.branching.get('123e4567-e89b-12d3-a456-426614174000')
9771
+ * ```
9772
+ */
9773
+ async get(idOrSlug) {
9774
+ try {
9775
+ const response = await this.fetch.get(
9776
+ `/api/v1/admin/branches/${encodeURIComponent(idOrSlug)}`
9777
+ );
9778
+ return { data: response, error: null };
9779
+ } catch (err) {
9780
+ return { data: null, error: err };
9781
+ }
9782
+ }
9783
+ /**
9784
+ * Create a new database branch
9785
+ *
9786
+ * @param name - Branch name (will be converted to a slug)
9787
+ * @param options - Branch creation options
9788
+ * @returns Promise resolving to { data, error } tuple with created branch
9789
+ *
9790
+ * @example
9791
+ * ```typescript
9792
+ * // Create a simple branch
9793
+ * const { data, error } = await client.branching.create('feature/add-auth')
9794
+ *
9795
+ * // Create with options
9796
+ * const { data } = await client.branching.create('feature/add-auth', {
9797
+ * dataCloneMode: 'schema_only', // Don't clone data
9798
+ * expiresIn: '7d', // Auto-delete after 7 days
9799
+ * type: 'persistent' // Won't auto-delete on PR merge
9800
+ * })
9801
+ *
9802
+ * // Create a PR preview branch
9803
+ * const { data } = await client.branching.create('pr-123', {
9804
+ * type: 'preview',
9805
+ * githubPRNumber: 123,
9806
+ * githubRepo: 'owner/repo',
9807
+ * expiresIn: '7d'
9808
+ * })
9809
+ *
9810
+ * // Clone with full data (for debugging)
9811
+ * const { data } = await client.branching.create('debug-issue-456', {
9812
+ * dataCloneMode: 'full_clone'
9813
+ * })
9814
+ * ```
9815
+ */
9816
+ async create(name, options) {
9817
+ try {
9818
+ const body = { name };
9819
+ if (options?.parentBranchId) {
9820
+ body.parent_branch_id = options.parentBranchId;
9821
+ }
9822
+ if (options?.dataCloneMode) {
9823
+ body.data_clone_mode = options.dataCloneMode;
9824
+ }
9825
+ if (options?.type) {
9826
+ body.type = options.type;
9827
+ }
9828
+ if (options?.githubPRNumber !== void 0) {
9829
+ body.github_pr_number = options.githubPRNumber;
9830
+ }
9831
+ if (options?.githubPRUrl) {
9832
+ body.github_pr_url = options.githubPRUrl;
9833
+ }
9834
+ if (options?.githubRepo) {
9835
+ body.github_repo = options.githubRepo;
9836
+ }
9837
+ if (options?.expiresIn) {
9838
+ body.expires_in = options.expiresIn;
9839
+ }
9840
+ const response = await this.fetch.post(
9841
+ "/api/v1/admin/branches",
9842
+ body
9843
+ );
9844
+ return { data: response, error: null };
9845
+ } catch (err) {
9846
+ return { data: null, error: err };
9847
+ }
9848
+ }
9849
+ /**
9850
+ * Delete a database branch
9851
+ *
9852
+ * This permanently deletes the branch database and all its data.
9853
+ * Cannot delete the main branch.
9854
+ *
9855
+ * @param idOrSlug - Branch ID (UUID) or slug
9856
+ * @returns Promise resolving to { error } (null on success)
9857
+ *
9858
+ * @example
9859
+ * ```typescript
9860
+ * // Delete a branch
9861
+ * const { error } = await client.branching.delete('feature/add-auth')
9862
+ *
9863
+ * if (error) {
9864
+ * console.error('Failed to delete branch:', error.message)
9865
+ * }
9866
+ * ```
9867
+ */
9868
+ async delete(idOrSlug) {
9869
+ try {
9870
+ await this.fetch.delete(
9871
+ `/api/v1/admin/branches/${encodeURIComponent(idOrSlug)}`
9872
+ );
9873
+ return { error: null };
9874
+ } catch (err) {
9875
+ return { error: err };
9876
+ }
9877
+ }
9878
+ /**
9879
+ * Reset a branch to its parent state
9880
+ *
9881
+ * This drops and recreates the branch database, resetting all data
9882
+ * to match the parent branch. Cannot reset the main branch.
9883
+ *
9884
+ * @param idOrSlug - Branch ID (UUID) or slug
9885
+ * @returns Promise resolving to { data, error } tuple with reset branch
9886
+ *
9887
+ * @example
9888
+ * ```typescript
9889
+ * // Reset a branch
9890
+ * const { data, error } = await client.branching.reset('feature/add-auth')
9891
+ *
9892
+ * if (data) {
9893
+ * console.log('Branch reset, status:', data.status)
9894
+ * }
9895
+ * ```
9896
+ */
9897
+ async reset(idOrSlug) {
9898
+ try {
9899
+ const response = await this.fetch.post(
9900
+ `/api/v1/admin/branches/${encodeURIComponent(idOrSlug)}/reset`,
9901
+ {}
9902
+ );
9903
+ return { data: response, error: null };
9904
+ } catch (err) {
9905
+ return { data: null, error: err };
9906
+ }
9907
+ }
9908
+ /**
9909
+ * Get activity log for a branch
9910
+ *
9911
+ * @param idOrSlug - Branch ID (UUID) or slug
9912
+ * @param limit - Maximum number of entries to return (default: 50, max: 100)
9913
+ * @returns Promise resolving to { data, error } tuple with activity entries
9914
+ *
9915
+ * @example
9916
+ * ```typescript
9917
+ * // Get recent activity
9918
+ * const { data, error } = await client.branching.getActivity('feature/add-auth')
9919
+ *
9920
+ * if (data) {
9921
+ * for (const entry of data) {
9922
+ * console.log(`${entry.action}: ${entry.status}`)
9923
+ * }
9924
+ * }
9925
+ *
9926
+ * // Get more entries
9927
+ * const { data } = await client.branching.getActivity('feature/add-auth', 100)
9928
+ * ```
9929
+ */
9930
+ async getActivity(idOrSlug, limit = 50) {
9931
+ try {
9932
+ const response = await this.fetch.get(
9933
+ `/api/v1/admin/branches/${encodeURIComponent(idOrSlug)}/activity?limit=${limit}`
9934
+ );
9935
+ return { data: response.activity, error: null };
9936
+ } catch (err) {
9937
+ return { data: null, error: err };
9938
+ }
9939
+ }
9940
+ /**
9941
+ * Get connection pool statistics for all branches
9942
+ *
9943
+ * This is useful for monitoring and debugging branch connections.
9944
+ *
9945
+ * @returns Promise resolving to { data, error } tuple with pool stats
9946
+ *
9947
+ * @example
9948
+ * ```typescript
9949
+ * const { data, error } = await client.branching.getPoolStats()
9950
+ *
9951
+ * if (data) {
9952
+ * for (const pool of data) {
9953
+ * console.log(`${pool.slug}: ${pool.active_connections} active`)
9954
+ * }
9955
+ * }
9956
+ * ```
9957
+ */
9958
+ async getPoolStats() {
9959
+ try {
9960
+ const response = await this.fetch.get(
9961
+ "/api/v1/admin/branches/stats/pools"
9962
+ );
9963
+ return { data: response.pools, error: null };
9964
+ } catch (err) {
9965
+ return { data: null, error: err };
9966
+ }
9967
+ }
9968
+ /**
9969
+ * Check if a branch exists
9970
+ *
9971
+ * @param idOrSlug - Branch ID (UUID) or slug
9972
+ * @returns Promise resolving to true if branch exists, false otherwise
9973
+ *
9974
+ * @example
9975
+ * ```typescript
9976
+ * const exists = await client.branching.exists('feature/add-auth')
9977
+ *
9978
+ * if (!exists) {
9979
+ * await client.branching.create('feature/add-auth')
9980
+ * }
9981
+ * ```
9982
+ */
9983
+ async exists(idOrSlug) {
9984
+ const { data, error } = await this.get(idOrSlug);
9985
+ return !error && data !== null;
9986
+ }
9987
+ /**
9988
+ * Wait for a branch to be ready
9989
+ *
9990
+ * Polls the branch status until it reaches 'ready' or an error state.
9991
+ *
9992
+ * @param idOrSlug - Branch ID (UUID) or slug
9993
+ * @param options - Polling options
9994
+ * @returns Promise resolving to { data, error } tuple with ready branch
9995
+ *
9996
+ * @example
9997
+ * ```typescript
9998
+ * // Create branch and wait for it to be ready
9999
+ * const { data: branch } = await client.branching.create('feature/add-auth')
10000
+ *
10001
+ * const { data: ready, error } = await client.branching.waitForReady(branch!.slug, {
10002
+ * timeout: 60000, // 60 seconds
10003
+ * pollInterval: 1000 // Check every second
10004
+ * })
10005
+ *
10006
+ * if (ready) {
10007
+ * console.log('Branch is ready!')
10008
+ * }
10009
+ * ```
10010
+ */
10011
+ async waitForReady(idOrSlug, options) {
10012
+ const timeout = options?.timeout ?? 3e4;
10013
+ const pollInterval = options?.pollInterval ?? 1e3;
10014
+ const startTime = Date.now();
10015
+ while (Date.now() - startTime < timeout) {
10016
+ const { data, error } = await this.get(idOrSlug);
10017
+ if (error) {
10018
+ return { data: null, error };
10019
+ }
10020
+ if (!data) {
10021
+ return { data: null, error: new Error("Branch not found") };
10022
+ }
10023
+ if (data.status === "ready") {
10024
+ return { data, error: null };
10025
+ }
10026
+ if (data.status === "error") {
10027
+ return {
10028
+ data: null,
10029
+ error: new Error(data.error_message ?? "Branch creation failed")
10030
+ };
10031
+ }
10032
+ if (data.status === "deleted" || data.status === "deleting") {
10033
+ return {
10034
+ data: null,
10035
+ error: new Error("Branch was deleted")
10036
+ };
10037
+ }
10038
+ await new Promise((resolve) => setTimeout(resolve, pollInterval));
10039
+ }
10040
+ return {
10041
+ data: null,
10042
+ error: new Error(
10043
+ `Timeout waiting for branch to be ready after ${timeout}ms`
10044
+ )
10045
+ };
10046
+ }
10047
+ };
10048
+
9698
10049
  // src/query-builder.ts
9699
10050
  var URL_LENGTH_THRESHOLD = 4096;
9700
10051
  var QueryBuilder = class {
@@ -11028,6 +11379,7 @@ var FluxbaseClient = class {
11028
11379
  this.ai = new FluxbaseAI(this.fetch, wsBaseUrl);
11029
11380
  this.vector = new FluxbaseVector(this.fetch);
11030
11381
  this.graphql = new FluxbaseGraphQL(this.fetch);
11382
+ this.branching = new FluxbaseBranching(this.fetch);
11031
11383
  const rpcInstance = new FluxbaseRPC(this.fetch);
11032
11384
  const rpcCallable = async (fn, params) => {
11033
11385
  const result = await rpcInstance.invoke(fn, params);
@@ -11274,6 +11626,6 @@ function assertType(value, validator, errorMessage = "Type assertion failed") {
11274
11626
  }
11275
11627
  }
11276
11628
 
11277
- export { APIKeysManager, AppSettingsManager, AuthSettingsManager, DDLManager, EmailSettingsManager, EmailTemplateManager, ExecutionLogsChannel, FluxbaseAI, FluxbaseAIChat, FluxbaseAdmin, FluxbaseAdminAI, FluxbaseAdminFunctions, FluxbaseAdminJobs, FluxbaseAdminMigrations, FluxbaseAdminRPC, FluxbaseAdminStorage, FluxbaseAuth, FluxbaseClient, FluxbaseFetch, FluxbaseFunctions, FluxbaseGraphQL, FluxbaseJobs, FluxbaseManagement, FluxbaseOAuth, FluxbaseRPC, FluxbaseRealtime, FluxbaseSettings, FluxbaseStorage, FluxbaseVector, ImpersonationManager, InvitationsManager, OAuthProviderManager, QueryBuilder, RealtimeChannel, SchemaQueryBuilder, SettingsClient, StorageBucket, SystemSettingsManager, WebhooksManager, assertType, bundleCode, createClient, denoExternalPlugin, hasPostgrestError, isArray, isAuthError, isAuthSuccess, isBoolean, isFluxbaseError, isFluxbaseSuccess, isNumber, isObject, isPostgrestSuccess, isString, loadImportMap };
11629
+ export { APIKeysManager, AppSettingsManager, AuthSettingsManager, ClientKeysManager, DDLManager, EmailSettingsManager, EmailTemplateManager, ExecutionLogsChannel, FluxbaseAI, FluxbaseAIChat, FluxbaseAdmin, FluxbaseAdminAI, FluxbaseAdminFunctions, FluxbaseAdminJobs, FluxbaseAdminMigrations, FluxbaseAdminRPC, FluxbaseAdminStorage, FluxbaseAuth, FluxbaseBranching, FluxbaseClient, FluxbaseFetch, FluxbaseFunctions, FluxbaseGraphQL, FluxbaseJobs, FluxbaseManagement, FluxbaseOAuth, FluxbaseRPC, FluxbaseRealtime, FluxbaseSettings, FluxbaseStorage, FluxbaseVector, ImpersonationManager, InvitationsManager, OAuthProviderManager, QueryBuilder, RealtimeChannel, SchemaQueryBuilder, SettingsClient, StorageBucket, SystemSettingsManager, WebhooksManager, assertType, bundleCode, createClient, denoExternalPlugin, hasPostgrestError, isArray, isAuthError, isAuthSuccess, isBoolean, isFluxbaseError, isFluxbaseSuccess, isNumber, isObject, isPostgrestSuccess, isString, loadImportMap };
11278
11630
  //# sourceMappingURL=index.js.map
11279
11631
  //# sourceMappingURL=index.js.map