@fluxbase/sdk 0.0.1-rc.112 → 0.0.1-rc.114

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