krisspy-sdk 0.5.6 → 0.6.0

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.d.mts CHANGED
@@ -12,18 +12,30 @@ interface KrisspyClientOptions {
12
12
  * Get it from your backend settings in the Krisspy dashboard.
13
13
  */
14
14
  apiKey: string;
15
+ /**
16
+ * Service key for server-side access (bypasses RLS).
17
+ * NEVER expose this in frontend code. Use only in server-side code (Azure Functions, Node.js, etc.)
18
+ * When provided, uses /service/data/* endpoints which bypass row-level security.
19
+ */
20
+ serviceKey?: string;
21
+ /**
22
+ * Base URL of your Azure Function App.
23
+ * When set, functions.invoke() calls the Azure Function directly
24
+ * instead of going through the Krisspy backend.
25
+ *
26
+ * @example 'https://krisspy-kb-abc123.azurewebsites.net'
27
+ */
28
+ functionsUrl?: string;
15
29
  /** Custom headers to include in all requests */
16
30
  headers?: Record<string, string>;
17
31
  /** Enable debug logging */
18
32
  debug?: boolean;
19
33
  /**
20
34
  * Use RLS (Row Level Security) endpoints for data access
21
- * Default: true
22
- *
23
- * When true, uses /rls/data/* endpoints which require app user authentication
24
- * and enforce row-level security policies.
35
+ * Default: true (uses /rls/data/* with apiKey)
25
36
  *
26
- * When false, uses legacy /data/* endpoints which require backend owner auth.
37
+ * Automatically set to false when serviceKey is provided
38
+ * (uses /service/data/* which bypasses RLS).
27
39
  */
28
40
  useRLS?: boolean;
29
41
  /**
@@ -820,12 +832,13 @@ declare class QueryBuilder<T = any> {
820
832
  private limitValue?;
821
833
  private offsetValue?;
822
834
  private isSingle;
823
- private useRLS;
824
- constructor(http: HttpClient, backendId: string, tableName: string, useRLS?: boolean);
835
+ private dataMode;
836
+ constructor(http: HttpClient, backendId: string, tableName: string, dataMode?: 'rls' | 'service' | 'legacy');
825
837
  /**
826
838
  * Get the base path for data endpoints
827
- * Uses /rls/data for RLS-enabled queries (requires auth)
828
- * Uses /data for legacy queries (admin/owner only)
839
+ * - rls: /rls/data (requires apiKey + optional JWT, enforces RLS)
840
+ * - service: /service/data (requires serviceKey, bypasses RLS)
841
+ * - legacy: /data (requires backend owner auth)
829
842
  */
830
843
  private getBasePath;
831
844
  /**
@@ -954,11 +967,12 @@ declare class KrisspyClient {
954
967
  private http;
955
968
  private backendId;
956
969
  private baseUrl;
970
+ private functionsUrl;
957
971
  private _auth;
958
972
  private _storage;
959
973
  private _realtime;
960
974
  private _analytics;
961
- private useRLS;
975
+ private dataMode;
962
976
  private debug;
963
977
  constructor(options: KrisspyClientOptions);
964
978
  /**
package/dist/index.d.ts CHANGED
@@ -12,18 +12,30 @@ interface KrisspyClientOptions {
12
12
  * Get it from your backend settings in the Krisspy dashboard.
13
13
  */
14
14
  apiKey: string;
15
+ /**
16
+ * Service key for server-side access (bypasses RLS).
17
+ * NEVER expose this in frontend code. Use only in server-side code (Azure Functions, Node.js, etc.)
18
+ * When provided, uses /service/data/* endpoints which bypass row-level security.
19
+ */
20
+ serviceKey?: string;
21
+ /**
22
+ * Base URL of your Azure Function App.
23
+ * When set, functions.invoke() calls the Azure Function directly
24
+ * instead of going through the Krisspy backend.
25
+ *
26
+ * @example 'https://krisspy-kb-abc123.azurewebsites.net'
27
+ */
28
+ functionsUrl?: string;
15
29
  /** Custom headers to include in all requests */
16
30
  headers?: Record<string, string>;
17
31
  /** Enable debug logging */
18
32
  debug?: boolean;
19
33
  /**
20
34
  * Use RLS (Row Level Security) endpoints for data access
21
- * Default: true
22
- *
23
- * When true, uses /rls/data/* endpoints which require app user authentication
24
- * and enforce row-level security policies.
35
+ * Default: true (uses /rls/data/* with apiKey)
25
36
  *
26
- * When false, uses legacy /data/* endpoints which require backend owner auth.
37
+ * Automatically set to false when serviceKey is provided
38
+ * (uses /service/data/* which bypasses RLS).
27
39
  */
28
40
  useRLS?: boolean;
29
41
  /**
@@ -820,12 +832,13 @@ declare class QueryBuilder<T = any> {
820
832
  private limitValue?;
821
833
  private offsetValue?;
822
834
  private isSingle;
823
- private useRLS;
824
- constructor(http: HttpClient, backendId: string, tableName: string, useRLS?: boolean);
835
+ private dataMode;
836
+ constructor(http: HttpClient, backendId: string, tableName: string, dataMode?: 'rls' | 'service' | 'legacy');
825
837
  /**
826
838
  * Get the base path for data endpoints
827
- * Uses /rls/data for RLS-enabled queries (requires auth)
828
- * Uses /data for legacy queries (admin/owner only)
839
+ * - rls: /rls/data (requires apiKey + optional JWT, enforces RLS)
840
+ * - service: /service/data (requires serviceKey, bypasses RLS)
841
+ * - legacy: /data (requires backend owner auth)
829
842
  */
830
843
  private getBasePath;
831
844
  /**
@@ -954,11 +967,12 @@ declare class KrisspyClient {
954
967
  private http;
955
968
  private backendId;
956
969
  private baseUrl;
970
+ private functionsUrl;
957
971
  private _auth;
958
972
  private _storage;
959
973
  private _realtime;
960
974
  private _analytics;
961
- private useRLS;
975
+ private dataMode;
962
976
  private debug;
963
977
  constructor(options: KrisspyClientOptions);
964
978
  /**
package/dist/index.js CHANGED
@@ -1456,7 +1456,7 @@ var KrisspyAnalytics = class {
1456
1456
 
1457
1457
  // src/query-builder.ts
1458
1458
  var QueryBuilder = class {
1459
- constructor(http, backendId, tableName, useRLS = true) {
1459
+ constructor(http, backendId, tableName, dataMode = "rls") {
1460
1460
  this.queryParams = {};
1461
1461
  this.selectColumns = [];
1462
1462
  this.orderClauses = [];
@@ -1464,18 +1464,23 @@ var QueryBuilder = class {
1464
1464
  this.http = http;
1465
1465
  this.backendId = backendId;
1466
1466
  this.tableName = tableName;
1467
- this.useRLS = useRLS;
1467
+ this.dataMode = dataMode;
1468
1468
  }
1469
1469
  /**
1470
1470
  * Get the base path for data endpoints
1471
- * Uses /rls/data for RLS-enabled queries (requires auth)
1472
- * Uses /data for legacy queries (admin/owner only)
1471
+ * - rls: /rls/data (requires apiKey + optional JWT, enforces RLS)
1472
+ * - service: /service/data (requires serviceKey, bypasses RLS)
1473
+ * - legacy: /data (requires backend owner auth)
1473
1474
  */
1474
1475
  getBasePath() {
1475
- if (this.useRLS) {
1476
- return `/api/v1/cloud-backends/${this.backendId}/rls/data/${this.tableName}`;
1476
+ const base = `/api/v1/cloud-backends/${this.backendId}`;
1477
+ if (this.dataMode === "service") {
1478
+ return `${base}/service/data/${this.tableName}`;
1477
1479
  }
1478
- return `/api/v1/cloud-backends/${this.backendId}/data/${this.tableName}`;
1480
+ if (this.dataMode === "legacy") {
1481
+ return `${base}/data/${this.tableName}`;
1482
+ }
1483
+ return `${base}/rls/data/${this.tableName}`;
1479
1484
  }
1480
1485
  /**
1481
1486
  * Select specific columns
@@ -1737,15 +1742,27 @@ var QueryBuilder = class {
1737
1742
  // src/client.ts
1738
1743
  var KrisspyClient = class {
1739
1744
  constructor(options) {
1745
+ var _a;
1740
1746
  this.baseUrl = options.url || "https://krisspy-cloud-backend.thankfulhill-66fc9e74.westeurope.azurecontainerapps.io";
1741
1747
  this.backendId = options.backendId;
1742
1748
  this.debug = options.debug || false;
1743
- this.useRLS = options.useRLS !== false;
1749
+ this.functionsUrl = ((_a = options.functionsUrl) == null ? void 0 : _a.replace(/\/$/, "")) || null;
1750
+ if (options.serviceKey) {
1751
+ this.dataMode = "service";
1752
+ } else if (options.useRLS === false) {
1753
+ this.dataMode = "legacy";
1754
+ } else {
1755
+ this.dataMode = "rls";
1756
+ }
1757
+ const keyHeaders = {
1758
+ "apikey": options.apiKey
1759
+ };
1760
+ if (options.serviceKey) {
1761
+ keyHeaders["servicekey"] = options.serviceKey;
1762
+ }
1744
1763
  this.http = new HttpClient({
1745
1764
  baseUrl: this.baseUrl,
1746
- headers: __spreadProps(__spreadValues({}, options.headers), {
1747
- "apikey": options.apiKey
1748
- }),
1765
+ headers: __spreadValues(__spreadValues({}, options.headers), keyHeaders),
1749
1766
  debug: options.debug
1750
1767
  });
1751
1768
  this._auth = new KrisspyAuth(this.http, this.backendId, options.storage);
@@ -1913,7 +1930,7 @@ var KrisspyClient = class {
1913
1930
  * .eq('id', 123)
1914
1931
  */
1915
1932
  from(table) {
1916
- return new QueryBuilder(this.http, this.backendId, table, this.useRLS);
1933
+ return new QueryBuilder(this.http, this.backendId, table, this.dataMode);
1917
1934
  }
1918
1935
  /**
1919
1936
  * Execute raw SQL query
@@ -1923,7 +1940,8 @@ var KrisspyClient = class {
1923
1940
  */
1924
1941
  async rpc(sql, params) {
1925
1942
  var _a, _b;
1926
- const path = `/api/v1/cloud-backends/${this.backendId}/sql`;
1943
+ const suffix = this.dataMode === "service" ? "/service/sql" : "/sql";
1944
+ const path = `/api/v1/cloud-backends/${this.backendId}${suffix}`;
1927
1945
  const response = await this.http.post(path, { sql, params });
1928
1946
  if (response.error) {
1929
1947
  return { data: null, error: response.error };
@@ -1941,6 +1959,31 @@ var KrisspyClient = class {
1941
1959
  get functions() {
1942
1960
  return {
1943
1961
  invoke: async (functionName, options) => {
1962
+ if (this.functionsUrl) {
1963
+ const url = `${this.functionsUrl}/api/${functionName}`;
1964
+ try {
1965
+ const res = await fetch(url, {
1966
+ method: "POST",
1967
+ headers: __spreadValues({
1968
+ "Content-Type": "application/json"
1969
+ }, options == null ? void 0 : options.headers),
1970
+ body: (options == null ? void 0 : options.body) ? JSON.stringify(options.body) : void 0
1971
+ });
1972
+ const contentType = res.headers.get("content-type");
1973
+ let data = null;
1974
+ if (contentType == null ? void 0 : contentType.includes("application/json")) {
1975
+ data = await res.json();
1976
+ } else {
1977
+ data = await res.text();
1978
+ }
1979
+ if (!res.ok) {
1980
+ return { data: null, error: { message: (data == null ? void 0 : data.error) || (data == null ? void 0 : data.message) || `Request failed with status ${res.status}`, status: res.status } };
1981
+ }
1982
+ return { data, error: null };
1983
+ } catch (err) {
1984
+ return { data: null, error: { message: err.message || "Network error", code: "NETWORK_ERROR", status: 0 } };
1985
+ }
1986
+ }
1944
1987
  const path = `/api/v1/cloud-backends/${this.backendId}/functions/${functionName}/invoke`;
1945
1988
  const response = await this.http.post(path, options == null ? void 0 : options.body, void 0);
1946
1989
  if (response.error) {
package/dist/index.mjs CHANGED
@@ -1422,7 +1422,7 @@ var KrisspyAnalytics = class {
1422
1422
 
1423
1423
  // src/query-builder.ts
1424
1424
  var QueryBuilder = class {
1425
- constructor(http, backendId, tableName, useRLS = true) {
1425
+ constructor(http, backendId, tableName, dataMode = "rls") {
1426
1426
  this.queryParams = {};
1427
1427
  this.selectColumns = [];
1428
1428
  this.orderClauses = [];
@@ -1430,18 +1430,23 @@ var QueryBuilder = class {
1430
1430
  this.http = http;
1431
1431
  this.backendId = backendId;
1432
1432
  this.tableName = tableName;
1433
- this.useRLS = useRLS;
1433
+ this.dataMode = dataMode;
1434
1434
  }
1435
1435
  /**
1436
1436
  * Get the base path for data endpoints
1437
- * Uses /rls/data for RLS-enabled queries (requires auth)
1438
- * Uses /data for legacy queries (admin/owner only)
1437
+ * - rls: /rls/data (requires apiKey + optional JWT, enforces RLS)
1438
+ * - service: /service/data (requires serviceKey, bypasses RLS)
1439
+ * - legacy: /data (requires backend owner auth)
1439
1440
  */
1440
1441
  getBasePath() {
1441
- if (this.useRLS) {
1442
- return `/api/v1/cloud-backends/${this.backendId}/rls/data/${this.tableName}`;
1442
+ const base = `/api/v1/cloud-backends/${this.backendId}`;
1443
+ if (this.dataMode === "service") {
1444
+ return `${base}/service/data/${this.tableName}`;
1443
1445
  }
1444
- return `/api/v1/cloud-backends/${this.backendId}/data/${this.tableName}`;
1446
+ if (this.dataMode === "legacy") {
1447
+ return `${base}/data/${this.tableName}`;
1448
+ }
1449
+ return `${base}/rls/data/${this.tableName}`;
1445
1450
  }
1446
1451
  /**
1447
1452
  * Select specific columns
@@ -1703,15 +1708,27 @@ var QueryBuilder = class {
1703
1708
  // src/client.ts
1704
1709
  var KrisspyClient = class {
1705
1710
  constructor(options) {
1711
+ var _a;
1706
1712
  this.baseUrl = options.url || "https://krisspy-cloud-backend.thankfulhill-66fc9e74.westeurope.azurecontainerapps.io";
1707
1713
  this.backendId = options.backendId;
1708
1714
  this.debug = options.debug || false;
1709
- this.useRLS = options.useRLS !== false;
1715
+ this.functionsUrl = ((_a = options.functionsUrl) == null ? void 0 : _a.replace(/\/$/, "")) || null;
1716
+ if (options.serviceKey) {
1717
+ this.dataMode = "service";
1718
+ } else if (options.useRLS === false) {
1719
+ this.dataMode = "legacy";
1720
+ } else {
1721
+ this.dataMode = "rls";
1722
+ }
1723
+ const keyHeaders = {
1724
+ "apikey": options.apiKey
1725
+ };
1726
+ if (options.serviceKey) {
1727
+ keyHeaders["servicekey"] = options.serviceKey;
1728
+ }
1710
1729
  this.http = new HttpClient({
1711
1730
  baseUrl: this.baseUrl,
1712
- headers: __spreadProps(__spreadValues({}, options.headers), {
1713
- "apikey": options.apiKey
1714
- }),
1731
+ headers: __spreadValues(__spreadValues({}, options.headers), keyHeaders),
1715
1732
  debug: options.debug
1716
1733
  });
1717
1734
  this._auth = new KrisspyAuth(this.http, this.backendId, options.storage);
@@ -1879,7 +1896,7 @@ var KrisspyClient = class {
1879
1896
  * .eq('id', 123)
1880
1897
  */
1881
1898
  from(table) {
1882
- return new QueryBuilder(this.http, this.backendId, table, this.useRLS);
1899
+ return new QueryBuilder(this.http, this.backendId, table, this.dataMode);
1883
1900
  }
1884
1901
  /**
1885
1902
  * Execute raw SQL query
@@ -1889,7 +1906,8 @@ var KrisspyClient = class {
1889
1906
  */
1890
1907
  async rpc(sql, params) {
1891
1908
  var _a, _b;
1892
- const path = `/api/v1/cloud-backends/${this.backendId}/sql`;
1909
+ const suffix = this.dataMode === "service" ? "/service/sql" : "/sql";
1910
+ const path = `/api/v1/cloud-backends/${this.backendId}${suffix}`;
1893
1911
  const response = await this.http.post(path, { sql, params });
1894
1912
  if (response.error) {
1895
1913
  return { data: null, error: response.error };
@@ -1907,6 +1925,31 @@ var KrisspyClient = class {
1907
1925
  get functions() {
1908
1926
  return {
1909
1927
  invoke: async (functionName, options) => {
1928
+ if (this.functionsUrl) {
1929
+ const url = `${this.functionsUrl}/api/${functionName}`;
1930
+ try {
1931
+ const res = await fetch(url, {
1932
+ method: "POST",
1933
+ headers: __spreadValues({
1934
+ "Content-Type": "application/json"
1935
+ }, options == null ? void 0 : options.headers),
1936
+ body: (options == null ? void 0 : options.body) ? JSON.stringify(options.body) : void 0
1937
+ });
1938
+ const contentType = res.headers.get("content-type");
1939
+ let data = null;
1940
+ if (contentType == null ? void 0 : contentType.includes("application/json")) {
1941
+ data = await res.json();
1942
+ } else {
1943
+ data = await res.text();
1944
+ }
1945
+ if (!res.ok) {
1946
+ return { data: null, error: { message: (data == null ? void 0 : data.error) || (data == null ? void 0 : data.message) || `Request failed with status ${res.status}`, status: res.status } };
1947
+ }
1948
+ return { data, error: null };
1949
+ } catch (err) {
1950
+ return { data: null, error: { message: err.message || "Network error", code: "NETWORK_ERROR", status: 0 } };
1951
+ }
1952
+ }
1910
1953
  const path = `/api/v1/cloud-backends/${this.backendId}/functions/${functionName}/invoke`;
1911
1954
  const response = await this.http.post(path, options == null ? void 0 : options.body, void 0);
1912
1955
  if (response.error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "krisspy-sdk",
3
- "version": "0.5.6",
3
+ "version": "0.6.0",
4
4
  "description": "Krisspy Cloud SDK - Database, Auth, Storage, and Functions for your apps",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",