@vaiftechnologies/vaif-client 0.1.0 → 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.
- package/dist/{index.mjs → index.cjs} +1237 -135
- package/dist/{index.d.mts → index.d.cts} +1179 -3
- package/dist/index.d.ts +1179 -3
- package/dist/index.js +1194 -172
- package/package.json +5 -1
|
@@ -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
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -2188,144 +2463,964 @@ function createTypeGen(client) {
|
|
|
2188
2463
|
return new VaifTypeGen(client);
|
|
2189
2464
|
}
|
|
2190
2465
|
|
|
2191
|
-
// src/lib/
|
|
2192
|
-
var
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
var memoryStorage = {
|
|
2196
|
-
data: /* @__PURE__ */ new Map(),
|
|
2197
|
-
getItem(key) {
|
|
2198
|
-
return this.data.get(key) ?? null;
|
|
2199
|
-
},
|
|
2200
|
-
setItem(key, value) {
|
|
2201
|
-
this.data.set(key, value);
|
|
2202
|
-
},
|
|
2203
|
-
removeItem(key) {
|
|
2204
|
-
this.data.delete(key);
|
|
2205
|
-
}
|
|
2206
|
-
};
|
|
2207
|
-
var browserStorage = typeof window !== "undefined" && window.localStorage ? {
|
|
2208
|
-
getItem: (key) => window.localStorage.getItem(key),
|
|
2209
|
-
setItem: (key, value) => window.localStorage.setItem(key, value),
|
|
2210
|
-
removeItem: (key) => window.localStorage.removeItem(key)
|
|
2211
|
-
} : null;
|
|
2212
|
-
function createClient(options) {
|
|
2213
|
-
return new VaifClient(options);
|
|
2214
|
-
}
|
|
2215
|
-
var VaifClient = class {
|
|
2216
|
-
constructor(options) {
|
|
2217
|
-
this.accessToken = null;
|
|
2218
|
-
if (!options.projectId) {
|
|
2219
|
-
throw new Error("projectId is required");
|
|
2220
|
-
}
|
|
2221
|
-
if (!options.apiKey) {
|
|
2222
|
-
throw new Error("apiKey is required");
|
|
2223
|
-
}
|
|
2224
|
-
this.config = {
|
|
2225
|
-
projectId: options.projectId,
|
|
2226
|
-
apiKey: options.apiKey,
|
|
2227
|
-
apiUrl: options.apiUrl ?? DEFAULT_API_URL,
|
|
2228
|
-
realtimeUrl: options.realtimeUrl ?? DEFAULT_REALTIME_URL,
|
|
2229
|
-
timeout: options.timeout ?? DEFAULT_TIMEOUT,
|
|
2230
|
-
headers: options.headers ?? {},
|
|
2231
|
-
debug: options.debug ?? false,
|
|
2232
|
-
autoRefreshToken: options.autoRefreshToken ?? true,
|
|
2233
|
-
persistSession: options.persistSession ?? true,
|
|
2234
|
-
storage: options.storage ?? browserStorage ?? memoryStorage
|
|
2235
|
-
};
|
|
2236
|
-
this.db = new VaifDatabase(this);
|
|
2237
|
-
this.realtime = new VaifRealtime(this);
|
|
2238
|
-
this.storage = new VaifStorage(this);
|
|
2239
|
-
this.functions = new VaifFunctions(this);
|
|
2240
|
-
this.auth = new VaifAuth(this);
|
|
2241
|
-
this.ai = new VaifAI(this);
|
|
2242
|
-
this.typegen = new VaifTypeGen(this);
|
|
2243
|
-
this.restoreSession();
|
|
2244
|
-
}
|
|
2245
|
-
/**
|
|
2246
|
-
* Get current configuration
|
|
2247
|
-
*/
|
|
2248
|
-
getConfig() {
|
|
2249
|
-
return this.config;
|
|
2250
|
-
}
|
|
2251
|
-
/**
|
|
2252
|
-
* Set access token for authenticated requests
|
|
2253
|
-
*/
|
|
2254
|
-
setAccessToken(token) {
|
|
2255
|
-
this.accessToken = token;
|
|
2256
|
-
}
|
|
2257
|
-
/**
|
|
2258
|
-
* Get current access token
|
|
2259
|
-
*/
|
|
2260
|
-
getAccessToken() {
|
|
2261
|
-
return this.accessToken;
|
|
2466
|
+
// src/lib/admin.ts
|
|
2467
|
+
var VaifAdmin = class {
|
|
2468
|
+
constructor(client) {
|
|
2469
|
+
this.client = client;
|
|
2262
2470
|
}
|
|
2263
|
-
/**
|
|
2264
|
-
* Make an authenticated API request
|
|
2265
|
-
*/
|
|
2266
2471
|
async request(path, options = {}) {
|
|
2267
|
-
const
|
|
2268
|
-
|
|
2269
|
-
Object.entries(options.params).forEach(([key, value]) => {
|
|
2270
|
-
if (value !== void 0) {
|
|
2271
|
-
url.searchParams.set(key, String(value));
|
|
2272
|
-
}
|
|
2273
|
-
});
|
|
2274
|
-
}
|
|
2472
|
+
const config = this.client.getConfig();
|
|
2473
|
+
const url = `${config.apiUrl}/admin${path}`;
|
|
2275
2474
|
const headers = {
|
|
2276
2475
|
"Content-Type": "application/json",
|
|
2277
|
-
"X-Project-ID": this.config.projectId,
|
|
2278
|
-
apikey: this.config.apiKey,
|
|
2279
|
-
...this.config.headers,
|
|
2280
2476
|
...options.headers
|
|
2281
2477
|
};
|
|
2282
|
-
|
|
2283
|
-
|
|
2478
|
+
const token = this.client.getAccessToken();
|
|
2479
|
+
if (token) {
|
|
2480
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
2284
2481
|
}
|
|
2285
|
-
const
|
|
2286
|
-
|
|
2482
|
+
const response = await fetch(url, {
|
|
2483
|
+
...options,
|
|
2287
2484
|
headers,
|
|
2288
|
-
|
|
2289
|
-
};
|
|
2290
|
-
if (
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2485
|
+
credentials: "include"
|
|
2486
|
+
});
|
|
2487
|
+
if (!response.ok) {
|
|
2488
|
+
const error = await response.json().catch(() => ({ message: "Request failed" }));
|
|
2489
|
+
throw new Error(error.message || `Request failed with status ${response.status}`);
|
|
2490
|
+
}
|
|
2491
|
+
return response.json();
|
|
2492
|
+
}
|
|
2493
|
+
// Overview
|
|
2494
|
+
async getOverview() {
|
|
2495
|
+
return this.request("/overview");
|
|
2496
|
+
}
|
|
2497
|
+
async getSettings() {
|
|
2498
|
+
return this.request("/settings");
|
|
2499
|
+
}
|
|
2500
|
+
// Users
|
|
2501
|
+
async listUsers(params) {
|
|
2502
|
+
const query = new URLSearchParams();
|
|
2503
|
+
if (params?.limit) query.set("limit", String(params.limit));
|
|
2504
|
+
if (params?.offset) query.set("offset", String(params.offset));
|
|
2505
|
+
return this.request(`/users?${query}`);
|
|
2506
|
+
}
|
|
2507
|
+
// Organizations
|
|
2508
|
+
async listOrganizations(params) {
|
|
2509
|
+
const query = new URLSearchParams();
|
|
2510
|
+
if (params?.limit) query.set("limit", String(params.limit));
|
|
2511
|
+
if (params?.offset) query.set("offset", String(params.offset));
|
|
2512
|
+
return this.request(`/orgs?${query}`);
|
|
2513
|
+
}
|
|
2514
|
+
// Projects
|
|
2515
|
+
async listProjects(params) {
|
|
2516
|
+
const query = new URLSearchParams();
|
|
2517
|
+
if (params?.limit) query.set("limit", String(params.limit));
|
|
2518
|
+
if (params?.offset) query.set("offset", String(params.offset));
|
|
2519
|
+
return this.request(`/projects?${query}`);
|
|
2520
|
+
}
|
|
2521
|
+
// Incidents
|
|
2522
|
+
async listIncidents(status) {
|
|
2523
|
+
const query = status ? `?status=${status}` : "";
|
|
2524
|
+
const result = await this.request(`/incidents${query}`);
|
|
2525
|
+
return result.incidents;
|
|
2526
|
+
}
|
|
2527
|
+
async createIncident(data) {
|
|
2528
|
+
return this.request("/incidents", {
|
|
2529
|
+
method: "POST",
|
|
2530
|
+
body: JSON.stringify(data)
|
|
2531
|
+
});
|
|
2532
|
+
}
|
|
2533
|
+
async acknowledgeIncident(incidentId) {
|
|
2534
|
+
await this.request(`/incidents/${incidentId}/acknowledge`, { method: "POST" });
|
|
2535
|
+
}
|
|
2536
|
+
async resolveIncident(incidentId) {
|
|
2537
|
+
await this.request(`/incidents/${incidentId}/resolve`, { method: "POST" });
|
|
2538
|
+
}
|
|
2539
|
+
// Health Components
|
|
2540
|
+
async getHealthComponents() {
|
|
2541
|
+
return this.request("/health/components");
|
|
2542
|
+
}
|
|
2543
|
+
async updateHealthComponent(name, data) {
|
|
2544
|
+
await this.request(`/health/components/${name}`, {
|
|
2545
|
+
method: "PUT",
|
|
2546
|
+
body: JSON.stringify(data)
|
|
2547
|
+
});
|
|
2548
|
+
}
|
|
2549
|
+
// Queues
|
|
2550
|
+
async listQueues() {
|
|
2551
|
+
return this.request("/queues");
|
|
2552
|
+
}
|
|
2553
|
+
// Feature Flags
|
|
2554
|
+
async listFeatureFlags() {
|
|
2555
|
+
return this.request("/flags");
|
|
2556
|
+
}
|
|
2557
|
+
async createFeatureFlag(key, enabled) {
|
|
2558
|
+
return this.request("/flags", {
|
|
2559
|
+
method: "POST",
|
|
2560
|
+
body: JSON.stringify({ key, enabled })
|
|
2561
|
+
});
|
|
2562
|
+
}
|
|
2563
|
+
async updateFeatureFlag(key, enabled) {
|
|
2564
|
+
await this.request(`/flags/${key}`, {
|
|
2565
|
+
method: "PUT",
|
|
2566
|
+
body: JSON.stringify({ enabled })
|
|
2567
|
+
});
|
|
2568
|
+
}
|
|
2569
|
+
async deleteFeatureFlag(key) {
|
|
2570
|
+
await this.request(`/flags/${key}`, { method: "DELETE" });
|
|
2571
|
+
}
|
|
2572
|
+
// Regions
|
|
2573
|
+
async listRegions() {
|
|
2574
|
+
return this.request("/regions");
|
|
2575
|
+
}
|
|
2576
|
+
async updateRegion(key, data) {
|
|
2577
|
+
await this.request(`/regions/${key}`, {
|
|
2578
|
+
method: "PUT",
|
|
2579
|
+
body: JSON.stringify(data)
|
|
2580
|
+
});
|
|
2581
|
+
}
|
|
2582
|
+
// Admins
|
|
2583
|
+
async listAdmins() {
|
|
2584
|
+
const result = await this.request("/admins");
|
|
2585
|
+
return result.admins;
|
|
2586
|
+
}
|
|
2587
|
+
async addAdmin(userId, role, notes) {
|
|
2588
|
+
return this.request("/admins", {
|
|
2589
|
+
method: "POST",
|
|
2590
|
+
body: JSON.stringify({ userId, role, notes })
|
|
2591
|
+
});
|
|
2592
|
+
}
|
|
2593
|
+
async updateAdmin(adminId, data) {
|
|
2594
|
+
await this.request(`/admins/${adminId}`, {
|
|
2595
|
+
method: "PUT",
|
|
2596
|
+
body: JSON.stringify(data)
|
|
2597
|
+
});
|
|
2598
|
+
}
|
|
2599
|
+
async removeAdmin(adminId) {
|
|
2600
|
+
await this.request(`/admins/${adminId}`, { method: "DELETE" });
|
|
2601
|
+
}
|
|
2602
|
+
// AI Models
|
|
2603
|
+
async listAIModels() {
|
|
2604
|
+
return this.request("/ai-models");
|
|
2605
|
+
}
|
|
2606
|
+
async createAIModel(data) {
|
|
2607
|
+
return this.request("/ai-models", {
|
|
2608
|
+
method: "POST",
|
|
2609
|
+
body: JSON.stringify(data)
|
|
2610
|
+
});
|
|
2611
|
+
}
|
|
2612
|
+
async updateAIModel(modelId, data) {
|
|
2613
|
+
await this.request(`/ai-models/${modelId}`, {
|
|
2614
|
+
method: "PUT",
|
|
2615
|
+
body: JSON.stringify(data)
|
|
2616
|
+
});
|
|
2617
|
+
}
|
|
2618
|
+
async toggleAIModel(modelId, enabled, message) {
|
|
2619
|
+
await this.request(`/ai-models/${modelId}/toggle`, {
|
|
2620
|
+
method: "POST",
|
|
2621
|
+
body: JSON.stringify({ enabled, message })
|
|
2622
|
+
});
|
|
2623
|
+
}
|
|
2624
|
+
async deleteAIModel(modelId) {
|
|
2625
|
+
await this.request(`/ai-models/${modelId}`, { method: "DELETE" });
|
|
2626
|
+
}
|
|
2627
|
+
// Prompt Templates
|
|
2628
|
+
async listPromptTemplates(params) {
|
|
2629
|
+
const query = params?.limit ? `?limit=${params.limit}` : "";
|
|
2630
|
+
return this.request(`/prompt-templates${query}`);
|
|
2631
|
+
}
|
|
2632
|
+
async createPromptTemplate(data) {
|
|
2633
|
+
return this.request("/prompt-templates", {
|
|
2634
|
+
method: "POST",
|
|
2635
|
+
body: JSON.stringify(data)
|
|
2636
|
+
});
|
|
2637
|
+
}
|
|
2638
|
+
async updatePromptTemplate(id, data) {
|
|
2639
|
+
await this.request(`/prompt-templates/${id}`, {
|
|
2640
|
+
method: "PUT",
|
|
2641
|
+
body: JSON.stringify(data)
|
|
2642
|
+
});
|
|
2643
|
+
}
|
|
2644
|
+
async deletePromptTemplate(id) {
|
|
2645
|
+
await this.request(`/prompt-templates/${id}`, { method: "DELETE" });
|
|
2646
|
+
}
|
|
2647
|
+
// AI Sessions
|
|
2648
|
+
async listAISessions(params) {
|
|
2649
|
+
const query = new URLSearchParams();
|
|
2650
|
+
if (params?.limit) query.set("limit", String(params.limit));
|
|
2651
|
+
if (params?.offset) query.set("offset", String(params.offset));
|
|
2652
|
+
if (params?.status) query.set("status", params.status);
|
|
2653
|
+
if (params?.search) query.set("search", params.search);
|
|
2654
|
+
return this.request(`/ai-sessions?${query}`);
|
|
2655
|
+
}
|
|
2656
|
+
async getAISession(sessionId) {
|
|
2657
|
+
return this.request(`/ai-sessions/${sessionId}`);
|
|
2658
|
+
}
|
|
2659
|
+
async deleteAISession(sessionId) {
|
|
2660
|
+
await this.request(`/ai-sessions/${sessionId}`, { method: "DELETE" });
|
|
2661
|
+
}
|
|
2662
|
+
// Generated Backends
|
|
2663
|
+
async listGeneratedBackends(params) {
|
|
2664
|
+
const query = new URLSearchParams();
|
|
2665
|
+
if (params?.limit) query.set("limit", String(params.limit));
|
|
2666
|
+
if (params?.offset) query.set("offset", String(params.offset));
|
|
2667
|
+
if (params?.search) query.set("search", params.search);
|
|
2668
|
+
return this.request(`/generated-backends?${query}`);
|
|
2669
|
+
}
|
|
2670
|
+
async getGeneratedBackend(backendId) {
|
|
2671
|
+
return this.request(`/generated-backends/${backendId}`);
|
|
2672
|
+
}
|
|
2673
|
+
async deleteGeneratedBackend(backendId) {
|
|
2674
|
+
await this.request(`/generated-backends/${backendId}`, { method: "DELETE" });
|
|
2675
|
+
}
|
|
2676
|
+
// Context Snapshots
|
|
2677
|
+
async listContextSnapshots(params) {
|
|
2678
|
+
const query = new URLSearchParams();
|
|
2679
|
+
if (params?.limit) query.set("limit", String(params.limit));
|
|
2680
|
+
if (params?.offset) query.set("offset", String(params.offset));
|
|
2681
|
+
return this.request(`/context-snapshots?${query}`);
|
|
2682
|
+
}
|
|
2683
|
+
async invalidateContextSnapshot(snapshotId) {
|
|
2684
|
+
await this.request(`/context-snapshots/${snapshotId}/invalidate`, { method: "POST" });
|
|
2685
|
+
}
|
|
2686
|
+
async deleteContextSnapshot(snapshotId) {
|
|
2687
|
+
await this.request(`/context-snapshots/${snapshotId}`, { method: "DELETE" });
|
|
2688
|
+
}
|
|
2689
|
+
// Copilot
|
|
2690
|
+
async getCopilotOverview() {
|
|
2691
|
+
return this.request("/copilot/overview");
|
|
2692
|
+
}
|
|
2693
|
+
async listCopilotSessions(params) {
|
|
2694
|
+
const query = new URLSearchParams();
|
|
2695
|
+
if (params?.limit) query.set("limit", String(params.limit));
|
|
2696
|
+
if (params?.offset) query.set("offset", String(params.offset));
|
|
2697
|
+
if (params?.status) query.set("status", params.status);
|
|
2698
|
+
if (params?.search) query.set("search", params.search);
|
|
2699
|
+
return this.request(`/copilot/sessions?${query}`);
|
|
2700
|
+
}
|
|
2701
|
+
async getCopilotSession(sessionId) {
|
|
2702
|
+
return this.request(`/copilot/sessions/${sessionId}`);
|
|
2703
|
+
}
|
|
2704
|
+
async deleteCopilotSession(sessionId) {
|
|
2705
|
+
await this.request(`/copilot/sessions/${sessionId}`, { method: "DELETE" });
|
|
2706
|
+
}
|
|
2707
|
+
// DLQ (Dead Letter Queue)
|
|
2708
|
+
async listDlqMessages(params) {
|
|
2709
|
+
const query = params?.limit ? `?limit=${params.limit}` : "";
|
|
2710
|
+
return this.request(`/dlq${query}`);
|
|
2711
|
+
}
|
|
2712
|
+
async retryDlqMessage(messageId) {
|
|
2713
|
+
await this.request(`/dlq/${messageId}/retry`, { method: "POST" });
|
|
2714
|
+
}
|
|
2715
|
+
async archiveDlqMessage(messageId) {
|
|
2716
|
+
await this.request(`/dlq/${messageId}/archive`, { method: "POST" });
|
|
2717
|
+
}
|
|
2718
|
+
};
|
|
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
|
+
|
|
3270
|
+
// src/lib/client.ts
|
|
3271
|
+
var DEFAULT_API_URL = "https://api.vaif.studio";
|
|
3272
|
+
var DEFAULT_REALTIME_URL = "wss://realtime.vaif.studio";
|
|
3273
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
3274
|
+
var memoryStorage = {
|
|
3275
|
+
data: /* @__PURE__ */ new Map(),
|
|
3276
|
+
getItem(key) {
|
|
3277
|
+
return this.data.get(key) ?? null;
|
|
3278
|
+
},
|
|
3279
|
+
setItem(key, value) {
|
|
3280
|
+
this.data.set(key, value);
|
|
3281
|
+
},
|
|
3282
|
+
removeItem(key) {
|
|
3283
|
+
this.data.delete(key);
|
|
3284
|
+
}
|
|
3285
|
+
};
|
|
3286
|
+
var browserStorage = typeof window !== "undefined" && window.localStorage ? {
|
|
3287
|
+
getItem: (key) => window.localStorage.getItem(key),
|
|
3288
|
+
setItem: (key, value) => window.localStorage.setItem(key, value),
|
|
3289
|
+
removeItem: (key) => window.localStorage.removeItem(key)
|
|
3290
|
+
} : null;
|
|
3291
|
+
function createClient(options) {
|
|
3292
|
+
return new VaifClient(options);
|
|
3293
|
+
}
|
|
3294
|
+
var VaifClient = class {
|
|
3295
|
+
constructor(options) {
|
|
3296
|
+
this.accessToken = null;
|
|
3297
|
+
const isAdminClient = options.baseUrl || options.accessToken;
|
|
3298
|
+
if (!isAdminClient) {
|
|
3299
|
+
if (!options.projectId) {
|
|
3300
|
+
throw new Error("projectId is required");
|
|
3301
|
+
}
|
|
3302
|
+
if (!options.apiKey) {
|
|
3303
|
+
throw new Error("apiKey is required");
|
|
3304
|
+
}
|
|
3305
|
+
}
|
|
3306
|
+
this.config = {
|
|
3307
|
+
projectId: options.projectId ?? "",
|
|
3308
|
+
apiKey: options.apiKey ?? "",
|
|
3309
|
+
apiKeyHeader: options.apiKeyHeader ?? "apikey",
|
|
3310
|
+
apiUrl: options.baseUrl ?? options.apiUrl ?? DEFAULT_API_URL,
|
|
3311
|
+
realtimeUrl: options.realtimeUrl ?? DEFAULT_REALTIME_URL,
|
|
3312
|
+
timeout: options.timeout ?? DEFAULT_TIMEOUT,
|
|
3313
|
+
headers: options.headers ?? {},
|
|
3314
|
+
debug: options.debug ?? false,
|
|
3315
|
+
autoRefreshToken: options.autoRefreshToken ?? true,
|
|
3316
|
+
persistSession: options.persistSession ?? true,
|
|
3317
|
+
storage: options.storage ?? browserStorage ?? memoryStorage
|
|
3318
|
+
};
|
|
3319
|
+
if (options.accessToken) {
|
|
3320
|
+
this.accessToken = options.accessToken;
|
|
3321
|
+
}
|
|
3322
|
+
this.db = new VaifDatabase(this);
|
|
3323
|
+
this.realtime = new VaifRealtime(this);
|
|
3324
|
+
this.storage = new VaifStorage(this);
|
|
3325
|
+
this.functions = new VaifFunctions(this);
|
|
3326
|
+
this.auth = new VaifAuth(this);
|
|
3327
|
+
this.ai = new VaifAI(this);
|
|
3328
|
+
this.schema = new VaifSchema(this);
|
|
3329
|
+
this.typegen = new VaifTypeGen(this);
|
|
3330
|
+
this.admin = new VaifAdmin(this);
|
|
3331
|
+
this.projects = new VaifProjects(this);
|
|
3332
|
+
this.apiKeys = new VaifApiKeys(this);
|
|
3333
|
+
this.integrations = new VaifIntegrations(this);
|
|
3334
|
+
this.restoreSession();
|
|
3335
|
+
}
|
|
3336
|
+
/**
|
|
3337
|
+
* Get current configuration
|
|
3338
|
+
*/
|
|
3339
|
+
getConfig() {
|
|
3340
|
+
return this.config;
|
|
3341
|
+
}
|
|
3342
|
+
/**
|
|
3343
|
+
* Set access token for authenticated requests
|
|
3344
|
+
*/
|
|
3345
|
+
setAccessToken(token) {
|
|
3346
|
+
this.accessToken = token;
|
|
3347
|
+
}
|
|
3348
|
+
/**
|
|
3349
|
+
* Get current access token
|
|
3350
|
+
*/
|
|
3351
|
+
getAccessToken() {
|
|
3352
|
+
return this.accessToken;
|
|
3353
|
+
}
|
|
3354
|
+
/**
|
|
3355
|
+
* Make an authenticated API request
|
|
3356
|
+
*/
|
|
3357
|
+
async request(path, options = {}) {
|
|
3358
|
+
const url = new URL(path, this.config.apiUrl);
|
|
3359
|
+
if (options.params) {
|
|
3360
|
+
Object.entries(options.params).forEach(([key, value]) => {
|
|
3361
|
+
if (value !== void 0) {
|
|
3362
|
+
url.searchParams.set(key, String(value));
|
|
3363
|
+
}
|
|
3364
|
+
});
|
|
3365
|
+
}
|
|
3366
|
+
const headers = {
|
|
3367
|
+
"Content-Type": "application/json",
|
|
3368
|
+
...this.config.headers,
|
|
3369
|
+
...options.headers
|
|
3370
|
+
};
|
|
3371
|
+
if (this.config.projectId) {
|
|
3372
|
+
headers["X-Project-ID"] = this.config.projectId;
|
|
3373
|
+
}
|
|
3374
|
+
if (this.config.apiKey) {
|
|
3375
|
+
headers[this.config.apiKeyHeader] = this.config.apiKey;
|
|
3376
|
+
}
|
|
3377
|
+
if (this.accessToken) {
|
|
3378
|
+
headers.Authorization = `Bearer ${this.accessToken}`;
|
|
3379
|
+
}
|
|
3380
|
+
const fetchOptions = {
|
|
3381
|
+
method: options.method ?? "GET",
|
|
3382
|
+
headers,
|
|
3383
|
+
signal: options.signal
|
|
3384
|
+
};
|
|
3385
|
+
if (options.body && options.method !== "GET") {
|
|
3386
|
+
fetchOptions.body = JSON.stringify(options.body);
|
|
3387
|
+
}
|
|
3388
|
+
const timeoutMs = options.timeout ?? this.config.timeout;
|
|
3389
|
+
const timeoutController = new AbortController();
|
|
3390
|
+
const timeoutId = setTimeout(() => timeoutController.abort(), timeoutMs);
|
|
3391
|
+
if (options.signal) {
|
|
3392
|
+
options.signal.addEventListener("abort", () => timeoutController.abort());
|
|
3393
|
+
}
|
|
3394
|
+
fetchOptions.signal = timeoutController.signal;
|
|
3395
|
+
try {
|
|
3396
|
+
if (this.config.debug) {
|
|
3397
|
+
console.log(`[VAIF] ${options.method ?? "GET"} ${url.toString()}`);
|
|
3398
|
+
}
|
|
3399
|
+
const response = await fetch(url.toString(), fetchOptions);
|
|
3400
|
+
clearTimeout(timeoutId);
|
|
3401
|
+
const contentType = response.headers.get("content-type");
|
|
3402
|
+
let data = null;
|
|
3403
|
+
let error = null;
|
|
3404
|
+
if (contentType?.includes("application/json")) {
|
|
3405
|
+
const json = await response.json();
|
|
3406
|
+
if (response.ok) {
|
|
3407
|
+
data = json;
|
|
3408
|
+
} else {
|
|
3409
|
+
error = {
|
|
3410
|
+
message: json.message ?? json.error ?? "Request failed",
|
|
3411
|
+
code: json.code,
|
|
3412
|
+
status: response.status,
|
|
3413
|
+
details: json.details,
|
|
3414
|
+
requestId: response.headers.get("x-request-id") ?? void 0
|
|
3415
|
+
};
|
|
3416
|
+
}
|
|
3417
|
+
} else if (!response.ok) {
|
|
3418
|
+
error = {
|
|
3419
|
+
message: `Request failed with status ${response.status}`,
|
|
3420
|
+
status: response.status
|
|
3421
|
+
};
|
|
3422
|
+
}
|
|
3423
|
+
const responseHeaders = {};
|
|
2329
3424
|
response.headers.forEach((value, key) => {
|
|
2330
3425
|
responseHeaders[key] = value;
|
|
2331
3426
|
});
|
|
@@ -2376,16 +3471,23 @@ var VaifClient = class {
|
|
|
2376
3471
|
}
|
|
2377
3472
|
}
|
|
2378
3473
|
};
|
|
2379
|
-
export
|
|
3474
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3475
|
+
0 && (module.exports = {
|
|
2380
3476
|
RealtimeChannel,
|
|
2381
3477
|
VaifAI,
|
|
3478
|
+
VaifAdmin,
|
|
3479
|
+
VaifApiKeys,
|
|
2382
3480
|
VaifAuth,
|
|
2383
3481
|
VaifClient,
|
|
2384
3482
|
VaifDatabase,
|
|
2385
3483
|
VaifFunctions,
|
|
3484
|
+
VaifIntegrations,
|
|
3485
|
+
VaifProjects,
|
|
2386
3486
|
VaifRealtime,
|
|
3487
|
+
VaifSchema,
|
|
2387
3488
|
VaifStorage,
|
|
2388
3489
|
VaifTypeGen,
|
|
2389
3490
|
createClient,
|
|
2390
|
-
createTypeGen
|
|
2391
|
-
|
|
3491
|
+
createTypeGen,
|
|
3492
|
+
createVaifClient
|
|
3493
|
+
});
|