@fluxbase/sdk 0.0.1-rc.24 → 0.0.1-rc.25
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 +168 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +144 -103
- package/dist/index.d.ts +144 -103
- package/dist/index.js +168 -53
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1944,87 +1944,128 @@ var AppSettingsManager = class {
|
|
|
1944
1944
|
authentication: { require_email_verification: required }
|
|
1945
1945
|
});
|
|
1946
1946
|
}
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
}
|
|
1947
|
+
// ===================================================================
|
|
1948
|
+
// CUSTOM SETTINGS METHODS
|
|
1949
|
+
// Flexible key-value storage for application-specific configuration
|
|
1950
|
+
// ===================================================================
|
|
1952
1951
|
/**
|
|
1953
|
-
*
|
|
1952
|
+
* Get a specific custom setting's value only (without metadata)
|
|
1954
1953
|
*
|
|
1955
|
-
*
|
|
1956
|
-
*
|
|
1954
|
+
* Convenience method that returns just the value field instead of the full CustomSetting object.
|
|
1955
|
+
*
|
|
1956
|
+
* @param key - Setting key (e.g., 'billing.tiers', 'features.beta_enabled')
|
|
1957
|
+
* @returns Promise resolving to the setting's value
|
|
1957
1958
|
*
|
|
1958
1959
|
* @example
|
|
1959
1960
|
* ```typescript
|
|
1960
|
-
* const
|
|
1961
|
-
*
|
|
1962
|
-
* value: { free: 1000, pro: 10000, enterprise: 100000 },
|
|
1963
|
-
* value_type: 'json',
|
|
1964
|
-
* description: 'API request quotas by tier',
|
|
1965
|
-
* metadata: { category: 'billing' }
|
|
1966
|
-
* })
|
|
1961
|
+
* const tiers = await client.admin.settings.app.getSetting('billing.tiers')
|
|
1962
|
+
* console.log(tiers) // { free: 1000, pro: 10000, enterprise: 100000 }
|
|
1967
1963
|
* ```
|
|
1968
1964
|
*/
|
|
1969
|
-
async
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
request
|
|
1965
|
+
async getSetting(key) {
|
|
1966
|
+
const setting = await this.fetch.get(
|
|
1967
|
+
`/api/v1/admin/settings/custom/${key}`
|
|
1973
1968
|
);
|
|
1969
|
+
return setting.value;
|
|
1974
1970
|
}
|
|
1975
1971
|
/**
|
|
1976
|
-
*
|
|
1972
|
+
* Get multiple custom settings' values by keys
|
|
1973
|
+
*
|
|
1974
|
+
* Fetches multiple settings in a single request and returns only their values.
|
|
1977
1975
|
*
|
|
1978
|
-
* @
|
|
1976
|
+
* @param keys - Array of setting keys to fetch
|
|
1977
|
+
* @returns Promise resolving to object mapping keys to values
|
|
1979
1978
|
*
|
|
1980
1979
|
* @example
|
|
1981
1980
|
* ```typescript
|
|
1982
|
-
* const
|
|
1983
|
-
*
|
|
1981
|
+
* const values = await client.admin.settings.app.getSettings([
|
|
1982
|
+
* 'billing.tiers',
|
|
1983
|
+
* 'features.beta_enabled'
|
|
1984
|
+
* ])
|
|
1985
|
+
* console.log(values)
|
|
1986
|
+
* // {
|
|
1987
|
+
* // 'billing.tiers': { free: 1000, pro: 10000 },
|
|
1988
|
+
* // 'features.beta_enabled': { enabled: true }
|
|
1989
|
+
* // }
|
|
1984
1990
|
* ```
|
|
1985
1991
|
*/
|
|
1986
|
-
async
|
|
1987
|
-
const
|
|
1988
|
-
"/api/v1/
|
|
1992
|
+
async getSettings(keys) {
|
|
1993
|
+
const response = await this.fetch.post(
|
|
1994
|
+
"/api/v1/settings/batch",
|
|
1995
|
+
{ keys }
|
|
1996
|
+
);
|
|
1997
|
+
return response.reduce(
|
|
1998
|
+
(acc, setting) => {
|
|
1999
|
+
acc[setting.key] = setting.value;
|
|
2000
|
+
return acc;
|
|
2001
|
+
},
|
|
2002
|
+
{}
|
|
1989
2003
|
);
|
|
1990
|
-
return { settings: Array.isArray(settings) ? settings : [] };
|
|
1991
2004
|
}
|
|
1992
2005
|
/**
|
|
1993
|
-
*
|
|
2006
|
+
* Set or create a custom setting
|
|
2007
|
+
*
|
|
2008
|
+
* Creates a new custom setting or updates an existing one.
|
|
1994
2009
|
*
|
|
1995
|
-
* @param key - Setting key
|
|
2010
|
+
* @param key - Setting key
|
|
2011
|
+
* @param value - Setting value (any JSON-serializable value)
|
|
2012
|
+
* @param options - Optional configuration (description, is_public, is_secret, etc.)
|
|
1996
2013
|
* @returns Promise resolving to CustomSetting
|
|
1997
2014
|
*
|
|
1998
2015
|
* @example
|
|
1999
2016
|
* ```typescript
|
|
2000
|
-
*
|
|
2001
|
-
*
|
|
2017
|
+
* await client.admin.settings.app.setSetting('billing.tiers', {
|
|
2018
|
+
* free: 1000,
|
|
2019
|
+
* pro: 10000,
|
|
2020
|
+
* enterprise: 100000
|
|
2021
|
+
* }, {
|
|
2022
|
+
* description: 'API quotas per billing tier',
|
|
2023
|
+
* is_public: false
|
|
2024
|
+
* })
|
|
2002
2025
|
* ```
|
|
2003
2026
|
*/
|
|
2004
|
-
async
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2027
|
+
async setSetting(key, value, options) {
|
|
2028
|
+
try {
|
|
2029
|
+
return await this.fetch.put(
|
|
2030
|
+
`/api/v1/admin/settings/custom/${key}`,
|
|
2031
|
+
{
|
|
2032
|
+
value,
|
|
2033
|
+
description: options?.description,
|
|
2034
|
+
is_public: options?.is_public,
|
|
2035
|
+
is_secret: options?.is_secret
|
|
2036
|
+
}
|
|
2037
|
+
);
|
|
2038
|
+
} catch (error) {
|
|
2039
|
+
if (error.status === 404 || error.message?.includes("not found")) {
|
|
2040
|
+
return await this.fetch.post(
|
|
2041
|
+
"/api/v1/admin/settings/custom",
|
|
2042
|
+
{
|
|
2043
|
+
key,
|
|
2044
|
+
value,
|
|
2045
|
+
value_type: options?.value_type || "json",
|
|
2046
|
+
description: options?.description,
|
|
2047
|
+
is_public: options?.is_public ?? false,
|
|
2048
|
+
is_secret: options?.is_secret ?? false
|
|
2049
|
+
}
|
|
2050
|
+
);
|
|
2051
|
+
}
|
|
2052
|
+
throw error;
|
|
2053
|
+
}
|
|
2008
2054
|
}
|
|
2009
2055
|
/**
|
|
2010
|
-
*
|
|
2056
|
+
* List all custom settings
|
|
2011
2057
|
*
|
|
2012
|
-
* @
|
|
2013
|
-
* @param request - Update request with new values
|
|
2014
|
-
* @returns Promise resolving to CustomSetting
|
|
2058
|
+
* @returns Promise resolving to array of CustomSetting objects
|
|
2015
2059
|
*
|
|
2016
2060
|
* @example
|
|
2017
2061
|
* ```typescript
|
|
2018
|
-
* const
|
|
2019
|
-
*
|
|
2020
|
-
* description: 'Updated description'
|
|
2021
|
-
* })
|
|
2062
|
+
* const settings = await client.admin.settings.app.listSettings()
|
|
2063
|
+
* settings.forEach(s => console.log(s.key, s.value))
|
|
2022
2064
|
* ```
|
|
2023
2065
|
*/
|
|
2024
|
-
async
|
|
2025
|
-
return await this.fetch.
|
|
2026
|
-
|
|
2027
|
-
request
|
|
2066
|
+
async listSettings() {
|
|
2067
|
+
return await this.fetch.get(
|
|
2068
|
+
"/api/v1/admin/settings/custom"
|
|
2028
2069
|
);
|
|
2029
2070
|
}
|
|
2030
2071
|
/**
|
|
@@ -2035,10 +2076,10 @@ var CustomSettingsManager = class {
|
|
|
2035
2076
|
*
|
|
2036
2077
|
* @example
|
|
2037
2078
|
* ```typescript
|
|
2038
|
-
* await client.admin.settings.
|
|
2079
|
+
* await client.admin.settings.app.deleteSetting('billing.tiers')
|
|
2039
2080
|
* ```
|
|
2040
2081
|
*/
|
|
2041
|
-
async
|
|
2082
|
+
async deleteSetting(key) {
|
|
2042
2083
|
await this.fetch.delete(`/api/v1/admin/settings/custom/${key}`);
|
|
2043
2084
|
}
|
|
2044
2085
|
};
|
|
@@ -2152,7 +2193,80 @@ var FluxbaseSettings = class {
|
|
|
2152
2193
|
constructor(fetch2) {
|
|
2153
2194
|
this.system = new SystemSettingsManager(fetch2);
|
|
2154
2195
|
this.app = new AppSettingsManager(fetch2);
|
|
2155
|
-
|
|
2196
|
+
}
|
|
2197
|
+
};
|
|
2198
|
+
var SettingsClient = class {
|
|
2199
|
+
constructor(fetch2) {
|
|
2200
|
+
this.fetch = fetch2;
|
|
2201
|
+
}
|
|
2202
|
+
/**
|
|
2203
|
+
* Get a single setting's value
|
|
2204
|
+
*
|
|
2205
|
+
* Returns only the value field of the setting.
|
|
2206
|
+
* Access is controlled by RLS policies - will return 403 if the user
|
|
2207
|
+
* doesn't have permission to read the setting.
|
|
2208
|
+
*
|
|
2209
|
+
* @param key - Setting key (e.g., 'features.beta_enabled')
|
|
2210
|
+
* @returns Promise resolving to the setting's value
|
|
2211
|
+
* @throws Error if setting doesn't exist or user lacks permission
|
|
2212
|
+
*
|
|
2213
|
+
* @example
|
|
2214
|
+
* ```typescript
|
|
2215
|
+
* // Get public setting (any user)
|
|
2216
|
+
* const value = await client.settings.get('features.beta_enabled')
|
|
2217
|
+
* console.log(value) // { enabled: true }
|
|
2218
|
+
*
|
|
2219
|
+
* // Get restricted setting (requires permission)
|
|
2220
|
+
* try {
|
|
2221
|
+
* const secret = await client.settings.get('internal.api_key')
|
|
2222
|
+
* } catch (error) {
|
|
2223
|
+
* console.error('Access denied:', error)
|
|
2224
|
+
* }
|
|
2225
|
+
* ```
|
|
2226
|
+
*/
|
|
2227
|
+
async get(key) {
|
|
2228
|
+
const response = await this.fetch.get(
|
|
2229
|
+
`/api/v1/settings/${encodeURIComponent(key)}`
|
|
2230
|
+
);
|
|
2231
|
+
return response.value;
|
|
2232
|
+
}
|
|
2233
|
+
/**
|
|
2234
|
+
* Get multiple settings' values by keys
|
|
2235
|
+
*
|
|
2236
|
+
* Fetches multiple settings in a single request.
|
|
2237
|
+
* Only returns settings the user has permission to read based on RLS policies.
|
|
2238
|
+
* Settings the user can't access will be omitted from the result (no error thrown).
|
|
2239
|
+
*
|
|
2240
|
+
* @param keys - Array of setting keys to fetch
|
|
2241
|
+
* @returns Promise resolving to object mapping keys to values
|
|
2242
|
+
*
|
|
2243
|
+
* @example
|
|
2244
|
+
* ```typescript
|
|
2245
|
+
* const values = await client.settings.getMany([
|
|
2246
|
+
* 'features.beta_enabled', // public - will be returned
|
|
2247
|
+
* 'features.dark_mode', // public - will be returned
|
|
2248
|
+
* 'internal.api_key' // secret - will be omitted
|
|
2249
|
+
* ])
|
|
2250
|
+
* console.log(values)
|
|
2251
|
+
* // {
|
|
2252
|
+
* // 'features.beta_enabled': { enabled: true },
|
|
2253
|
+
* // 'features.dark_mode': { enabled: false }
|
|
2254
|
+
* // // 'internal.api_key' is omitted (no error)
|
|
2255
|
+
* // }
|
|
2256
|
+
* ```
|
|
2257
|
+
*/
|
|
2258
|
+
async getMany(keys) {
|
|
2259
|
+
const response = await this.fetch.post(
|
|
2260
|
+
"/api/v1/settings/batch",
|
|
2261
|
+
{ keys }
|
|
2262
|
+
);
|
|
2263
|
+
return response.reduce(
|
|
2264
|
+
(acc, setting) => {
|
|
2265
|
+
acc[setting.key] = setting.value;
|
|
2266
|
+
return acc;
|
|
2267
|
+
},
|
|
2268
|
+
{}
|
|
2269
|
+
);
|
|
2156
2270
|
}
|
|
2157
2271
|
};
|
|
2158
2272
|
|
|
@@ -4077,8 +4191,8 @@ var FluxbaseClient = class {
|
|
|
4077
4191
|
this.fluxbaseUrl = fluxbaseUrl;
|
|
4078
4192
|
this.fluxbaseKey = fluxbaseKey;
|
|
4079
4193
|
const headers = {
|
|
4080
|
-
|
|
4081
|
-
|
|
4194
|
+
apikey: fluxbaseKey,
|
|
4195
|
+
Authorization: `Bearer ${fluxbaseKey}`,
|
|
4082
4196
|
...options?.headers
|
|
4083
4197
|
};
|
|
4084
4198
|
this.fetch = new FluxbaseFetch(fluxbaseUrl, {
|
|
@@ -4102,6 +4216,7 @@ var FluxbaseClient = class {
|
|
|
4102
4216
|
this.functions = new FluxbaseFunctions(this.fetch);
|
|
4103
4217
|
this.admin = new FluxbaseAdmin(this.fetch);
|
|
4104
4218
|
this.management = new FluxbaseManagement(this.fetch);
|
|
4219
|
+
this.settings = new SettingsClient(this.fetch);
|
|
4105
4220
|
this.setupAuthSync();
|
|
4106
4221
|
}
|
|
4107
4222
|
/**
|
|
@@ -4274,6 +4389,7 @@ exports.InvitationsManager = InvitationsManager;
|
|
|
4274
4389
|
exports.OAuthProviderManager = OAuthProviderManager;
|
|
4275
4390
|
exports.QueryBuilder = QueryBuilder;
|
|
4276
4391
|
exports.RealtimeChannel = RealtimeChannel;
|
|
4392
|
+
exports.SettingsClient = SettingsClient;
|
|
4277
4393
|
exports.StorageBucket = StorageBucket;
|
|
4278
4394
|
exports.SystemSettingsManager = SystemSettingsManager;
|
|
4279
4395
|
exports.WebhooksManager = WebhooksManager;
|