@vaiftechnologies/vaif-client 0.1.1 → 0.1.2

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.
@@ -1,3 +1,45 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ RealtimeChannel: () => RealtimeChannel,
24
+ VaifAI: () => VaifAI,
25
+ VaifAdmin: () => VaifAdmin,
26
+ VaifApiKeys: () => VaifApiKeys,
27
+ VaifAuth: () => VaifAuth,
28
+ VaifClient: () => VaifClient,
29
+ VaifDatabase: () => VaifDatabase,
30
+ VaifFunctions: () => VaifFunctions,
31
+ VaifIntegrations: () => VaifIntegrations,
32
+ VaifProjects: () => VaifProjects,
33
+ VaifRealtime: () => VaifRealtime,
34
+ VaifSchema: () => VaifSchema,
35
+ VaifStorage: () => VaifStorage,
36
+ VaifTypeGen: () => VaifTypeGen,
37
+ createClient: () => createClient,
38
+ createTypeGen: () => createTypeGen,
39
+ createVaifClient: () => createClient
40
+ });
41
+ module.exports = __toCommonJS(index_exports);
42
+
1
43
  // src/lib/database.ts
2
44
  var VaifDatabase = class {
3
45
  constructor(client) {
@@ -1813,6 +1855,42 @@ var VaifAI = class {
1813
1855
  }
1814
1856
  return { data: response.data, error: null };
1815
1857
  }
1858
+ /**
1859
+ * Generate a plan for schema or other tasks using AI
1860
+ *
1861
+ * @example
1862
+ * ```typescript
1863
+ * const { data, error } = await vaif.ai.generatePlan({
1864
+ * projectId: 'your-project-id',
1865
+ * prompt: 'Create a users table with email and password',
1866
+ * taskType: 'plan_schema',
1867
+ * mode: 'balanced'
1868
+ * });
1869
+ * ```
1870
+ */
1871
+ async generatePlan(request) {
1872
+ const response = await this.client.request("/ai/plan", {
1873
+ method: "POST",
1874
+ body: request
1875
+ });
1876
+ if (response.error) {
1877
+ return {
1878
+ ok: false,
1879
+ plan: { steps: [] },
1880
+ costEstimateCents: 0,
1881
+ error: {
1882
+ message: response.error.message,
1883
+ code: response.error.code,
1884
+ status: response.status
1885
+ }
1886
+ };
1887
+ }
1888
+ return response.data ?? {
1889
+ ok: false,
1890
+ plan: { steps: [] },
1891
+ costEstimateCents: 0
1892
+ };
1893
+ }
1816
1894
  /**
1817
1895
  * Generate SQL migration from schema diff
1818
1896
  */
@@ -1840,6 +1918,203 @@ var VaifAI = class {
1840
1918
  }
1841
1919
  };
1842
1920
 
1921
+ // src/lib/schema.ts
1922
+ var VaifSchema = class {
1923
+ constructor(client) {
1924
+ this.client = client;
1925
+ }
1926
+ /**
1927
+ * Preview schema changes without applying them
1928
+ *
1929
+ * @example
1930
+ * ```typescript
1931
+ * const result = await vaif.schema.preview({
1932
+ * projectId: 'your-project-id',
1933
+ * definition: {
1934
+ * tables: [
1935
+ * { name: 'users', columns: [{ name: 'id', type: 'uuid', primaryKey: true }] }
1936
+ * ]
1937
+ * }
1938
+ * });
1939
+ *
1940
+ * if (result.ok) {
1941
+ * console.log('Plan steps:', result.plan);
1942
+ * console.log('SQL:', result.upSql);
1943
+ * }
1944
+ * ```
1945
+ */
1946
+ async preview(request) {
1947
+ const response = await this.client.request(
1948
+ "/schema-engine/preview",
1949
+ {
1950
+ method: "POST",
1951
+ body: request
1952
+ }
1953
+ );
1954
+ if (response.error) {
1955
+ return {
1956
+ ok: false,
1957
+ projectSchema: "",
1958
+ plan: [],
1959
+ upSql: "",
1960
+ downSql: "",
1961
+ warnings: [],
1962
+ error: {
1963
+ message: response.error.message,
1964
+ code: response.error.code,
1965
+ status: response.status,
1966
+ details: response.error.details
1967
+ }
1968
+ };
1969
+ }
1970
+ return response.data ?? {
1971
+ ok: false,
1972
+ projectSchema: "",
1973
+ plan: [],
1974
+ upSql: "",
1975
+ downSql: "",
1976
+ warnings: []
1977
+ };
1978
+ }
1979
+ /**
1980
+ * Apply schema changes to the database
1981
+ *
1982
+ * @example
1983
+ * ```typescript
1984
+ * const result = await vaif.schema.apply({
1985
+ * projectId: 'your-project-id',
1986
+ * definition: {
1987
+ * tables: [
1988
+ * { name: 'users', columns: [{ name: 'id', type: 'uuid', primaryKey: true }] }
1989
+ * ]
1990
+ * },
1991
+ * migrationName: 'add_users_table'
1992
+ * });
1993
+ *
1994
+ * if (result.ok) {
1995
+ * console.log('Applied:', result.appliedSteps, 'steps');
1996
+ * }
1997
+ * ```
1998
+ */
1999
+ async apply(request) {
2000
+ const response = await this.client.request(
2001
+ "/schema-engine/apply",
2002
+ {
2003
+ method: "POST",
2004
+ body: request
2005
+ }
2006
+ );
2007
+ if (response.error) {
2008
+ return {
2009
+ ok: false,
2010
+ projectSchema: "",
2011
+ migration: {
2012
+ id: "",
2013
+ name: "",
2014
+ status: "failed",
2015
+ appliedAt: ""
2016
+ },
2017
+ appliedSteps: 0,
2018
+ error: {
2019
+ message: response.error.message,
2020
+ code: response.error.code,
2021
+ status: response.status,
2022
+ details: response.error.details
2023
+ }
2024
+ };
2025
+ }
2026
+ return response.data ?? {
2027
+ ok: false,
2028
+ projectSchema: "",
2029
+ migration: {
2030
+ id: "",
2031
+ name: "",
2032
+ status: "failed",
2033
+ appliedAt: ""
2034
+ },
2035
+ appliedSteps: 0
2036
+ };
2037
+ }
2038
+ /**
2039
+ * Introspect current database schema
2040
+ *
2041
+ * @example
2042
+ * ```typescript
2043
+ * const result = await vaif.schema.introspect('your-project-id');
2044
+ *
2045
+ * if (result.ok) {
2046
+ * console.log('Tables:', result.tables);
2047
+ * }
2048
+ * ```
2049
+ */
2050
+ async introspect(projectId, envId) {
2051
+ const params = {};
2052
+ if (envId) {
2053
+ params.envId = envId;
2054
+ }
2055
+ const response = await this.client.request(
2056
+ `/schema-engine/introspect/${projectId}`,
2057
+ { params }
2058
+ );
2059
+ if (response.error) {
2060
+ return {
2061
+ ok: false,
2062
+ schemaExists: false,
2063
+ tables: [],
2064
+ error: {
2065
+ message: response.error.message,
2066
+ code: response.error.code,
2067
+ status: response.status
2068
+ }
2069
+ };
2070
+ }
2071
+ return response.data ?? {
2072
+ ok: false,
2073
+ schemaExists: false,
2074
+ tables: []
2075
+ };
2076
+ }
2077
+ /**
2078
+ * Get migration history for a project
2079
+ *
2080
+ * @example
2081
+ * ```typescript
2082
+ * const result = await vaif.schema.getMigrations('your-project-id');
2083
+ *
2084
+ * if (result.ok) {
2085
+ * for (const migration of result.migrations) {
2086
+ * console.log(migration.name, migration.status);
2087
+ * }
2088
+ * }
2089
+ * ```
2090
+ */
2091
+ async getMigrations(projectId, options) {
2092
+ const params = {};
2093
+ if (options?.limit) {
2094
+ params.limit = String(options.limit);
2095
+ }
2096
+ const response = await this.client.request(
2097
+ `/schema-engine/migrations/project/${projectId}`,
2098
+ { params }
2099
+ );
2100
+ if (response.error) {
2101
+ return {
2102
+ ok: false,
2103
+ migrations: [],
2104
+ error: {
2105
+ message: response.error.message,
2106
+ code: response.error.code,
2107
+ status: response.status
2108
+ }
2109
+ };
2110
+ }
2111
+ return response.data ?? {
2112
+ ok: false,
2113
+ migrations: []
2114
+ };
2115
+ }
2116
+ };
2117
+
1843
2118
  // src/lib/typegen.ts
1844
2119
  var PG_TO_TS_TYPES = {
1845
2120
  // Numeric
@@ -1958,7 +2233,7 @@ var VaifTypeGen = class {
1958
2233
  lines.push("");
1959
2234
  }
1960
2235
  }
1961
- let filteredTables = dbSchema.tables.filter((t) => {
2236
+ const filteredTables = dbSchema.tables.filter((t) => {
1962
2237
  if (tables.length > 0 && !tables.includes(t.name)) return false;
1963
2238
  if (excludeTables.includes(t.name)) return false;
1964
2239
  return true;
@@ -2050,7 +2325,7 @@ var VaifTypeGen = class {
2050
2325
  lines.push("");
2051
2326
  }
2052
2327
  }
2053
- let filteredTables = (schema.tables || []).filter((t) => {
2328
+ const filteredTables = (schema.tables || []).filter((t) => {
2054
2329
  if (tables.length > 0 && !tables.includes(t.name)) return false;
2055
2330
  if (excludeTables.includes(t.name)) return false;
2056
2331
  return true;
@@ -2442,6 +2717,556 @@ var VaifAdmin = class {
2442
2717
  }
2443
2718
  };
2444
2719
 
2720
+ // src/lib/projects.ts
2721
+ var VaifProjects = class {
2722
+ constructor(client) {
2723
+ this.client = client;
2724
+ }
2725
+ /**
2726
+ * List all projects the user has access to
2727
+ */
2728
+ async list(options) {
2729
+ const params = {};
2730
+ if (options?.orgId) {
2731
+ params.orgId = options.orgId;
2732
+ }
2733
+ const response = await this.client.request("/projects", { params });
2734
+ if (response.error) {
2735
+ throw new Error(response.error.message);
2736
+ }
2737
+ return response.data ?? [];
2738
+ }
2739
+ /**
2740
+ * Get a specific project by ID
2741
+ */
2742
+ async get(projectId) {
2743
+ const response = await this.client.request(
2744
+ `/projects/${projectId}`
2745
+ );
2746
+ if (response.error) {
2747
+ throw new Error(response.error.message);
2748
+ }
2749
+ return response.data ?? { project: {}, environments: [] };
2750
+ }
2751
+ /**
2752
+ * Create a new project
2753
+ */
2754
+ async create(options) {
2755
+ const response = await this.client.request(
2756
+ "/projects",
2757
+ {
2758
+ method: "POST",
2759
+ body: options
2760
+ }
2761
+ );
2762
+ if (response.error) {
2763
+ throw new Error(response.error.message);
2764
+ }
2765
+ return response.data ?? { project: {}, environments: [] };
2766
+ }
2767
+ /**
2768
+ * Update a project
2769
+ */
2770
+ async update(projectId, options) {
2771
+ const response = await this.client.request(
2772
+ `/projects/${projectId}`,
2773
+ {
2774
+ method: "PATCH",
2775
+ body: options
2776
+ }
2777
+ );
2778
+ if (response.error) {
2779
+ throw new Error(response.error.message);
2780
+ }
2781
+ return response.data ?? { project: {} };
2782
+ }
2783
+ /**
2784
+ * Delete a project
2785
+ */
2786
+ async delete(projectId) {
2787
+ const response = await this.client.request(
2788
+ `/projects/${projectId}`,
2789
+ {
2790
+ method: "DELETE"
2791
+ }
2792
+ );
2793
+ if (response.error) {
2794
+ throw new Error(response.error.message);
2795
+ }
2796
+ }
2797
+ /**
2798
+ * List API keys for a project
2799
+ */
2800
+ async listApiKeys(projectId) {
2801
+ const response = await this.client.request(
2802
+ `/projects/${projectId}/api-keys`
2803
+ );
2804
+ if (response.error) {
2805
+ throw new Error(response.error.message);
2806
+ }
2807
+ return response.data?.keys ?? [];
2808
+ }
2809
+ /**
2810
+ * Alias for listApiKeys
2811
+ */
2812
+ async getApiKeys(projectId) {
2813
+ return this.listApiKeys(projectId);
2814
+ }
2815
+ /**
2816
+ * Create an API key for a project
2817
+ */
2818
+ async createApiKey(projectId, options) {
2819
+ const response = await this.client.request(
2820
+ `/projects/${projectId}/api-keys`,
2821
+ {
2822
+ method: "POST",
2823
+ body: options ?? {}
2824
+ }
2825
+ );
2826
+ if (response.error) {
2827
+ throw new Error(response.error.message);
2828
+ }
2829
+ return response.data ?? { apiKeyId: "", apiKey: "" };
2830
+ }
2831
+ /**
2832
+ * Revoke an API key
2833
+ */
2834
+ async revokeApiKey(projectId, keyId) {
2835
+ const response = await this.client.request(
2836
+ `/projects/${projectId}/api-keys/${keyId}/revoke`,
2837
+ {
2838
+ method: "POST"
2839
+ }
2840
+ );
2841
+ if (response.error) {
2842
+ throw new Error(response.error.message);
2843
+ }
2844
+ }
2845
+ /**
2846
+ * Rotate an API key (revoke and create new)
2847
+ */
2848
+ async rotateApiKey(projectId, keyId) {
2849
+ const response = await this.client.request(
2850
+ `/projects/${projectId}/api-keys/${keyId}/rotate`,
2851
+ {
2852
+ method: "POST"
2853
+ }
2854
+ );
2855
+ if (response.error) {
2856
+ throw new Error(response.error.message);
2857
+ }
2858
+ return response.data ?? { apiKeyId: "", apiKey: "" };
2859
+ }
2860
+ // Project Settings Methods
2861
+ /**
2862
+ * Get project settings
2863
+ */
2864
+ async getSettings(projectId) {
2865
+ const response = await this.client.request(
2866
+ `/projects/${projectId}/settings`
2867
+ );
2868
+ if (response.error) {
2869
+ throw new Error(response.error.message);
2870
+ }
2871
+ return response.data ?? {};
2872
+ }
2873
+ /**
2874
+ * Get compute settings
2875
+ */
2876
+ async getComputeSettings(projectId) {
2877
+ const response = await this.client.request(
2878
+ `/projects/${projectId}/settings/compute`
2879
+ );
2880
+ if (response.error) {
2881
+ throw new Error(response.error.message);
2882
+ }
2883
+ return response.data ?? {
2884
+ tier: "starter",
2885
+ diskSize: 1,
2886
+ region: "us-east-1",
2887
+ autoScaling: false,
2888
+ maxInstances: 1
2889
+ };
2890
+ }
2891
+ /**
2892
+ * Update compute settings
2893
+ */
2894
+ async updateComputeSettings(projectId, settings) {
2895
+ const response = await this.client.request(
2896
+ `/projects/${projectId}/settings/compute`,
2897
+ {
2898
+ method: "PATCH",
2899
+ body: settings
2900
+ }
2901
+ );
2902
+ if (response.error) {
2903
+ throw new Error(response.error.message);
2904
+ }
2905
+ return response.data ?? {};
2906
+ }
2907
+ /**
2908
+ * Get API settings
2909
+ */
2910
+ async getApiSettings(projectId) {
2911
+ const response = await this.client.request(
2912
+ `/projects/${projectId}/settings/api`
2913
+ );
2914
+ if (response.error) {
2915
+ throw new Error(response.error.message);
2916
+ }
2917
+ return response.data ?? {
2918
+ apiVersion: "v1",
2919
+ rateLimit: 100,
2920
+ corsEnabled: true,
2921
+ corsOrigins: ["*"],
2922
+ customDomain: ""
2923
+ };
2924
+ }
2925
+ /**
2926
+ * Update API settings
2927
+ */
2928
+ async updateApiSettings(projectId, settings) {
2929
+ const response = await this.client.request(
2930
+ `/projects/${projectId}/settings/api`,
2931
+ {
2932
+ method: "PATCH",
2933
+ body: settings
2934
+ }
2935
+ );
2936
+ if (response.error) {
2937
+ throw new Error(response.error.message);
2938
+ }
2939
+ return response.data ?? {};
2940
+ }
2941
+ /**
2942
+ * Get JWT settings
2943
+ */
2944
+ async getJwtSettings(projectId) {
2945
+ const response = await this.client.request(
2946
+ `/projects/${projectId}/settings/jwt`
2947
+ );
2948
+ if (response.error) {
2949
+ throw new Error(response.error.message);
2950
+ }
2951
+ return response.data ?? {
2952
+ algorithm: "HS256",
2953
+ accessTokenExpiry: 3600,
2954
+ refreshTokenExpiry: 604800,
2955
+ refreshTokenEnabled: true,
2956
+ rotateOnUse: true,
2957
+ secretHint: "********",
2958
+ lastRotated: null
2959
+ };
2960
+ }
2961
+ /**
2962
+ * Update JWT settings
2963
+ */
2964
+ async updateJwtSettings(projectId, settings) {
2965
+ const response = await this.client.request(
2966
+ `/projects/${projectId}/settings/jwt`,
2967
+ {
2968
+ method: "PATCH",
2969
+ body: settings
2970
+ }
2971
+ );
2972
+ if (response.error) {
2973
+ throw new Error(response.error.message);
2974
+ }
2975
+ return response.data ?? {};
2976
+ }
2977
+ /**
2978
+ * Rotate JWT secret
2979
+ */
2980
+ async rotateJwtSecret(projectId) {
2981
+ const response = await this.client.request(
2982
+ `/projects/${projectId}/settings/jwt/rotate`,
2983
+ {
2984
+ method: "POST"
2985
+ }
2986
+ );
2987
+ if (response.error) {
2988
+ throw new Error(response.error.message);
2989
+ }
2990
+ return response.data ?? { secretHint: "", lastRotated: "" };
2991
+ }
2992
+ /**
2993
+ * Get addons configuration
2994
+ */
2995
+ async getAddons(projectId) {
2996
+ const response = await this.client.request(
2997
+ `/projects/${projectId}/settings/addons`
2998
+ );
2999
+ if (response.error) {
3000
+ throw new Error(response.error.message);
3001
+ }
3002
+ return response.data ?? {
3003
+ enabledAddons: [],
3004
+ currentTier: "free"
3005
+ };
3006
+ }
3007
+ /**
3008
+ * Update addons configuration
3009
+ */
3010
+ async updateAddons(projectId, enabledAddons) {
3011
+ const response = await this.client.request(
3012
+ `/projects/${projectId}/settings/addons`,
3013
+ {
3014
+ method: "PATCH",
3015
+ body: { enabledAddons }
3016
+ }
3017
+ );
3018
+ if (response.error) {
3019
+ throw new Error(response.error.message);
3020
+ }
3021
+ return response.data ?? {};
3022
+ }
3023
+ };
3024
+
3025
+ // src/lib/apiKeys.ts
3026
+ var VaifApiKeys = class {
3027
+ constructor(client) {
3028
+ this.client = client;
3029
+ }
3030
+ /**
3031
+ * List API keys for a project
3032
+ */
3033
+ async list(projectId) {
3034
+ const response = await this.client.request(
3035
+ `/projects/${projectId}/api-keys`
3036
+ );
3037
+ if (response.error) {
3038
+ throw new Error(response.error.message);
3039
+ }
3040
+ const keys = response.data?.keys ?? [];
3041
+ return keys.map((key) => ({
3042
+ ...key,
3043
+ keyHint: key.keyHint || `vaif_${key.id.slice(0, 8)}...`,
3044
+ permissions: key.scopes || key.permissions || ["read"]
3045
+ }));
3046
+ }
3047
+ /**
3048
+ * Create a new API key
3049
+ */
3050
+ async create(options) {
3051
+ const { projectId, ...body } = options;
3052
+ const requestBody = { ...body };
3053
+ if (options.permissions && !options.scopes) {
3054
+ const scopeMap = {
3055
+ read: "crud",
3056
+ write: "crud",
3057
+ admin: "crud",
3058
+ functions: "functions",
3059
+ storage: "storage",
3060
+ realtime: "realtime"
3061
+ };
3062
+ requestBody.scopes = options.permissions.map((p) => scopeMap[p] || p).filter((v, i, a) => a.indexOf(v) === i);
3063
+ }
3064
+ if (options.expiresIn && options.expiresIn !== "never") {
3065
+ const durationMatch = options.expiresIn.match(/^(\d+)([dmy])$/);
3066
+ if (durationMatch) {
3067
+ const amount = parseInt(durationMatch[1], 10);
3068
+ const unit = durationMatch[2];
3069
+ const now = /* @__PURE__ */ new Date();
3070
+ switch (unit) {
3071
+ case "d":
3072
+ now.setDate(now.getDate() + amount);
3073
+ break;
3074
+ case "m":
3075
+ now.setMonth(now.getMonth() + amount);
3076
+ break;
3077
+ case "y":
3078
+ now.setFullYear(now.getFullYear() + amount);
3079
+ break;
3080
+ }
3081
+ requestBody.expiresAt = now.toISOString();
3082
+ }
3083
+ }
3084
+ const response = await this.client.request(
3085
+ `/projects/${projectId}/api-keys`,
3086
+ {
3087
+ method: "POST",
3088
+ body: requestBody
3089
+ }
3090
+ );
3091
+ if (response.error) {
3092
+ throw new Error(response.error.message);
3093
+ }
3094
+ return {
3095
+ id: response.data?.apiKeyId ?? "",
3096
+ key: response.data?.apiKey ?? "",
3097
+ name: options.name ?? null,
3098
+ permissions: options.permissions ?? ["read"],
3099
+ expiresAt: requestBody.expiresAt ?? null
3100
+ };
3101
+ }
3102
+ /**
3103
+ * Revoke an API key
3104
+ */
3105
+ async revoke(keyId, projectId) {
3106
+ if (!projectId) {
3107
+ throw new Error("projectId is required to revoke an API key");
3108
+ }
3109
+ const response = await this.client.request(
3110
+ `/projects/${projectId}/api-keys/${keyId}/revoke`,
3111
+ {
3112
+ method: "POST"
3113
+ }
3114
+ );
3115
+ if (response.error) {
3116
+ throw new Error(response.error.message);
3117
+ }
3118
+ }
3119
+ /**
3120
+ * Rotate an API key
3121
+ */
3122
+ async rotate(keyId, projectId) {
3123
+ const response = await this.client.request(
3124
+ `/projects/${projectId}/api-keys/${keyId}/rotate`,
3125
+ {
3126
+ method: "POST"
3127
+ }
3128
+ );
3129
+ if (response.error) {
3130
+ throw new Error(response.error.message);
3131
+ }
3132
+ return {
3133
+ id: response.data?.apiKeyId ?? "",
3134
+ key: response.data?.apiKey ?? "",
3135
+ name: null,
3136
+ permissions: [],
3137
+ expiresAt: null
3138
+ };
3139
+ }
3140
+ /**
3141
+ * Update an API key
3142
+ */
3143
+ async update(projectId, keyId, options) {
3144
+ const response = await this.client.request(
3145
+ `/projects/${projectId}/api-keys/${keyId}`,
3146
+ {
3147
+ method: "PATCH",
3148
+ body: options
3149
+ }
3150
+ );
3151
+ if (response.error) {
3152
+ throw new Error(response.error.message);
3153
+ }
3154
+ return response.data?.apiKey ?? {};
3155
+ }
3156
+ };
3157
+
3158
+ // src/lib/integrations.ts
3159
+ var VaifIntegrations = class {
3160
+ constructor(client) {
3161
+ this.client = client;
3162
+ }
3163
+ /**
3164
+ * List integrations for a project
3165
+ */
3166
+ async list(projectId) {
3167
+ const response = await this.client.request(
3168
+ `/integrations/subscriptions/project/${projectId}`
3169
+ );
3170
+ if (response.error) {
3171
+ throw new Error(response.error.message);
3172
+ }
3173
+ return (response.data?.subscriptions ?? []).map((sub) => ({
3174
+ ...sub,
3175
+ enabled: !sub.updatedAt || true
3176
+ // Default to enabled if no explicit disabled state
3177
+ }));
3178
+ }
3179
+ /**
3180
+ * Create a new integration
3181
+ */
3182
+ async create(options) {
3183
+ const response = await this.client.request(
3184
+ "/integrations/subscriptions",
3185
+ {
3186
+ method: "POST",
3187
+ body: options
3188
+ }
3189
+ );
3190
+ if (response.error) {
3191
+ throw new Error(response.error.message);
3192
+ }
3193
+ return response.data?.subscription ?? {};
3194
+ }
3195
+ /**
3196
+ * Update an integration
3197
+ */
3198
+ async update(integrationId, options) {
3199
+ const response = await this.client.request(
3200
+ `/integrations/subscriptions/${integrationId}`,
3201
+ {
3202
+ method: "PATCH",
3203
+ body: options
3204
+ }
3205
+ );
3206
+ if (response.error) {
3207
+ throw new Error(response.error.message);
3208
+ }
3209
+ return response.data?.subscription ?? {};
3210
+ }
3211
+ /**
3212
+ * Delete an integration
3213
+ */
3214
+ async delete(integrationId) {
3215
+ const response = await this.client.request(
3216
+ `/integrations/subscriptions/${integrationId}`,
3217
+ {
3218
+ method: "DELETE"
3219
+ }
3220
+ );
3221
+ if (response.error) {
3222
+ throw new Error(response.error.message);
3223
+ }
3224
+ }
3225
+ /**
3226
+ * Test an integration
3227
+ */
3228
+ async test(integrationId) {
3229
+ const response = await this.client.request(
3230
+ `/integrations/subscriptions/${integrationId}/test`,
3231
+ {
3232
+ method: "POST"
3233
+ }
3234
+ );
3235
+ if (response.error) {
3236
+ throw new Error(response.error.message);
3237
+ }
3238
+ }
3239
+ /**
3240
+ * Get webhook deliveries for an integration
3241
+ */
3242
+ async getDeliveries(integrationId) {
3243
+ const response = await this.client.request(
3244
+ `/integrations/deliveries/subscription/${integrationId}`
3245
+ );
3246
+ if (response.error) {
3247
+ throw new Error(response.error.message);
3248
+ }
3249
+ return response.data?.deliveries ?? [];
3250
+ }
3251
+ /**
3252
+ * Get failed deliveries (DLQ) for a project
3253
+ */
3254
+ async getFailedDeliveries(projectId, limit) {
3255
+ const params = {};
3256
+ if (limit) {
3257
+ params.limit = String(limit);
3258
+ }
3259
+ const response = await this.client.request(
3260
+ `/integrations/dlq/project/${projectId}`,
3261
+ { params }
3262
+ );
3263
+ if (response.error) {
3264
+ throw new Error(response.error.message);
3265
+ }
3266
+ return response.data?.deliveries ?? [];
3267
+ }
3268
+ };
3269
+
2445
3270
  // src/lib/client.ts
2446
3271
  var DEFAULT_API_URL = "https://api.vaif.studio";
2447
3272
  var DEFAULT_REALTIME_URL = "wss://realtime.vaif.studio";
@@ -2500,8 +3325,12 @@ var VaifClient = class {
2500
3325
  this.functions = new VaifFunctions(this);
2501
3326
  this.auth = new VaifAuth(this);
2502
3327
  this.ai = new VaifAI(this);
3328
+ this.schema = new VaifSchema(this);
2503
3329
  this.typegen = new VaifTypeGen(this);
2504
3330
  this.admin = new VaifAdmin(this);
3331
+ this.projects = new VaifProjects(this);
3332
+ this.apiKeys = new VaifApiKeys(this);
3333
+ this.integrations = new VaifIntegrations(this);
2505
3334
  this.restoreSession();
2506
3335
  }
2507
3336
  /**
@@ -2642,18 +3471,23 @@ var VaifClient = class {
2642
3471
  }
2643
3472
  }
2644
3473
  };
2645
- export {
3474
+ // Annotate the CommonJS export names for ESM import in node:
3475
+ 0 && (module.exports = {
2646
3476
  RealtimeChannel,
2647
3477
  VaifAI,
2648
3478
  VaifAdmin,
3479
+ VaifApiKeys,
2649
3480
  VaifAuth,
2650
3481
  VaifClient,
2651
3482
  VaifDatabase,
2652
3483
  VaifFunctions,
3484
+ VaifIntegrations,
3485
+ VaifProjects,
2653
3486
  VaifRealtime,
3487
+ VaifSchema,
2654
3488
  VaifStorage,
2655
3489
  VaifTypeGen,
2656
3490
  createClient,
2657
3491
  createTypeGen,
2658
- createClient as createVaifClient
2659
- };
3492
+ createVaifClient
3493
+ });