@aouda/client 0.0.2 → 0.1.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.
@@ -923,6 +923,23 @@ interface DatabaseInfo {
923
923
  state: string;
924
924
  createdAt: string;
925
925
  options: DatabaseOptionsInfo;
926
+ /**
927
+ * True if this is an Aouda-owned infrastructure database (e.g. `_serverauth`, `_settings`).
928
+ * Internal databases are hidden from the default catalog list.
929
+ * Clients should not use internal databases as data-explorer targets.
930
+ */
931
+ isInternal: boolean;
932
+ /**
933
+ * True if this database contains auth system tables (_users, _roles, etc.).
934
+ * Application auth databases have isInternal=false and remain in the default list.
935
+ */
936
+ isAuthDatabase: boolean;
937
+ /**
938
+ * Auth database classification: "none" | "server" | "application".
939
+ * "server" databases are managed via /api/auth/admin/... (never in data explorer).
940
+ * "application" databases are end-user auth stores browsable via the data explorer.
941
+ */
942
+ authDatabaseKind: "none" | "server" | "application";
926
943
  }
927
944
  /**
928
945
  * Options when creating a database (camelCase, matches server request).
@@ -2008,7 +2025,7 @@ declare class AdminApi {
2008
2025
  * Two-layer auth model: clients connect via API key (Layer 1); user sign-in is performed
2009
2026
  * explicitly via AuthClient.signIn() (Layer 2). There is no auto-authentication on first request.
2010
2027
  *
2011
- * All auth endpoint calls use direct globalThis.fetch to avoid
2028
+ * All auth endpoint calls use direct fetch (with LNA hints) to avoid
2012
2029
  * circular refresh through the transport pipeline.
2013
2030
  *
2014
2031
  * @internal
@@ -2927,12 +2944,19 @@ declare class DatabasesApi {
2927
2944
  private readonly transport;
2928
2945
  constructor(transport: Transport);
2929
2946
  /**
2930
- * Lists all databases on the server.
2947
+ * Lists databases on the server.
2931
2948
  * GET /api/databases
2932
2949
  *
2933
- * @returns Array of database info (name, state, createdAt, options).
2950
+ * By default only operator-facing databases (isInternal === false) are returned.
2951
+ * Pass `{ includeInternal: true }` to receive the full catalog including internal
2952
+ * infrastructure databases such as `_serverauth` and `_settings`.
2953
+ *
2954
+ * @param options.includeInternal - When true, appends `?include=internal` to the request.
2955
+ * @returns Array of database info.
2934
2956
  */
2935
- list(): Promise<DatabaseInfo[]>;
2957
+ list(options?: {
2958
+ includeInternal?: boolean;
2959
+ }): Promise<DatabaseInfo[]>;
2936
2960
  /**
2937
2961
  * Creates a new database.
2938
2962
  * POST /api/databases
@@ -923,6 +923,23 @@ interface DatabaseInfo {
923
923
  state: string;
924
924
  createdAt: string;
925
925
  options: DatabaseOptionsInfo;
926
+ /**
927
+ * True if this is an Aouda-owned infrastructure database (e.g. `_serverauth`, `_settings`).
928
+ * Internal databases are hidden from the default catalog list.
929
+ * Clients should not use internal databases as data-explorer targets.
930
+ */
931
+ isInternal: boolean;
932
+ /**
933
+ * True if this database contains auth system tables (_users, _roles, etc.).
934
+ * Application auth databases have isInternal=false and remain in the default list.
935
+ */
936
+ isAuthDatabase: boolean;
937
+ /**
938
+ * Auth database classification: "none" | "server" | "application".
939
+ * "server" databases are managed via /api/auth/admin/... (never in data explorer).
940
+ * "application" databases are end-user auth stores browsable via the data explorer.
941
+ */
942
+ authDatabaseKind: "none" | "server" | "application";
926
943
  }
927
944
  /**
928
945
  * Options when creating a database (camelCase, matches server request).
@@ -2008,7 +2025,7 @@ declare class AdminApi {
2008
2025
  * Two-layer auth model: clients connect via API key (Layer 1); user sign-in is performed
2009
2026
  * explicitly via AuthClient.signIn() (Layer 2). There is no auto-authentication on first request.
2010
2027
  *
2011
- * All auth endpoint calls use direct globalThis.fetch to avoid
2028
+ * All auth endpoint calls use direct fetch (with LNA hints) to avoid
2012
2029
  * circular refresh through the transport pipeline.
2013
2030
  *
2014
2031
  * @internal
@@ -2927,12 +2944,19 @@ declare class DatabasesApi {
2927
2944
  private readonly transport;
2928
2945
  constructor(transport: Transport);
2929
2946
  /**
2930
- * Lists all databases on the server.
2947
+ * Lists databases on the server.
2931
2948
  * GET /api/databases
2932
2949
  *
2933
- * @returns Array of database info (name, state, createdAt, options).
2950
+ * By default only operator-facing databases (isInternal === false) are returned.
2951
+ * Pass `{ includeInternal: true }` to receive the full catalog including internal
2952
+ * infrastructure databases such as `_serverauth` and `_settings`.
2953
+ *
2954
+ * @param options.includeInternal - When true, appends `?include=internal` to the request.
2955
+ * @returns Array of database info.
2934
2956
  */
2935
- list(): Promise<DatabaseInfo[]>;
2957
+ list(options?: {
2958
+ includeInternal?: boolean;
2959
+ }): Promise<DatabaseInfo[]>;
2936
2960
  /**
2937
2961
  * Creates a new database.
2938
2962
  * POST /api/databases
package/dist/index.cjs CHANGED
@@ -65,13 +65,85 @@ __export(index_exports, {
65
65
  TableQuery: () => TableQuery,
66
66
  TablesApi: () => TablesApi,
67
67
  WhereGroupBuilder: () => WhereGroupBuilder,
68
+ applyLocalNetworkAccess: () => applyLocalNetworkAccess,
68
69
  coerceColumnarValue: () => coerceColumnarValue,
69
70
  createAoudaClient: () => createAoudaClient,
70
71
  createAoudaClusterMcpToolSet: () => createAoudaClusterMcpToolSet,
72
+ installLocalNetworkFetch: () => installLocalNetworkFetch,
73
+ localNetworkFetch: () => localNetworkFetch,
74
+ resolveTargetAddressSpace: () => resolveTargetAddressSpace,
71
75
  version: () => version
72
76
  });
73
77
  module.exports = __toCommonJS(index_exports);
74
78
 
79
+ // package.json
80
+ var package_default = {
81
+ name: "@aouda/client",
82
+ version: "0.1.0",
83
+ description: "Official TypeScript/JavaScript client library for Aouda",
84
+ type: "module",
85
+ main: "./dist/index.cjs",
86
+ module: "./dist/index.js",
87
+ types: "./dist/index.d.ts",
88
+ bin: "./dist/cli/index.js",
89
+ exports: {
90
+ ".": {
91
+ types: "./dist/index.d.ts",
92
+ import: "./dist/index.js",
93
+ require: "./dist/index.cjs"
94
+ }
95
+ },
96
+ license: "MIT",
97
+ repository: {
98
+ type: "git",
99
+ url: "https://github.com/aoudadb/aouda-client-ts.git"
100
+ },
101
+ publishConfig: {
102
+ access: "public"
103
+ },
104
+ files: [
105
+ "dist",
106
+ "README.md",
107
+ "LICENSE"
108
+ ],
109
+ scripts: {
110
+ changeset: "changeset",
111
+ "version-packages": "changeset version",
112
+ release: "changeset publish",
113
+ prepublishOnly: "npm run build",
114
+ build: "tsup",
115
+ dev: "tsup --watch",
116
+ test: "vitest run",
117
+ "test:watch": "vitest",
118
+ "test:coverage": "vitest run --coverage",
119
+ lint: "eslint src tests",
120
+ "lint:fix": "eslint src tests --fix",
121
+ format: 'prettier --write "src/**/*.ts" "tests/**/*.ts"',
122
+ typecheck: "tsc --noEmit && tsc -p tsconfig.typecheck.json --noEmit",
123
+ "generate-types": "node dist/cli/index.js generate --server http://localhost:5000 --output ./types/schema.ts"
124
+ },
125
+ engines: {
126
+ node: ">=20"
127
+ },
128
+ devDependencies: {
129
+ "@changesets/cli": "^2.29.8",
130
+ "@eslint/js": "^9.15.0",
131
+ "@types/node": "^25.2.1",
132
+ "@types/ws": "^8.18.1",
133
+ eslint: "^9.15.0",
134
+ "eslint-config-prettier": "^9.1.0",
135
+ prettier: "^3.3.3",
136
+ tsup: "^8.3.5",
137
+ typescript: "^5.6.3",
138
+ "typescript-eslint": "^8.15.0",
139
+ vitest: "^2.1.4"
140
+ },
141
+ dependencies: {
142
+ "@msgpack/msgpack": "^3.1.3",
143
+ ws: "^8.20.0"
144
+ }
145
+ };
146
+
75
147
  // src/types.ts
76
148
  var RetryPolicy;
77
149
  ((RetryPolicy2) => {
@@ -188,6 +260,70 @@ var AoudaCircuitBreakerOpenError = class extends AoudaError {
188
260
  }
189
261
  };
190
262
 
263
+ // src/local-network-fetch.ts
264
+ function resolveTargetAddressSpace(url) {
265
+ let parsed;
266
+ try {
267
+ parsed = new URL(url);
268
+ } catch {
269
+ return void 0;
270
+ }
271
+ const hostname = parsed.hostname.replace(/^\[|\]$/g, "").toLowerCase();
272
+ if (hostname === "localhost" || hostname === "::1") {
273
+ return "loopback";
274
+ }
275
+ const ipv4 = hostname.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
276
+ if (ipv4) {
277
+ const [first, second] = [Number(ipv4[1]), Number(ipv4[2])];
278
+ if (first === 127) return "loopback";
279
+ if (first === 10) return "local";
280
+ if (first === 172 && second >= 16 && second <= 31) return "local";
281
+ if (first === 192 && second === 168) return "local";
282
+ if (first === 169 && second === 254) return "local";
283
+ }
284
+ if (hostname.endsWith(".local")) {
285
+ return "local";
286
+ }
287
+ return void 0;
288
+ }
289
+ function applyLocalNetworkAccess(url, init) {
290
+ const space = resolveTargetAddressSpace(url);
291
+ if (!space) {
292
+ return init ?? {};
293
+ }
294
+ return { ...init, targetAddressSpace: space };
295
+ }
296
+ function resolveFetchUrl(input) {
297
+ if (typeof input === "string") {
298
+ return input;
299
+ }
300
+ if (input instanceof URL) {
301
+ return input.href;
302
+ }
303
+ return input.url;
304
+ }
305
+ function localNetworkFetch(input, init) {
306
+ const url = resolveFetchUrl(input);
307
+ const merged = applyLocalNetworkAccess(url, init);
308
+ return globalThis.fetch(input, merged);
309
+ }
310
+ var installed = false;
311
+ function installLocalNetworkFetch() {
312
+ if (installed || typeof globalThis.window === "undefined") {
313
+ return;
314
+ }
315
+ installed = true;
316
+ const nativeFetch = globalThis.fetch.bind(globalThis);
317
+ globalThis.fetch = (input, init) => {
318
+ const url = resolveFetchUrl(input);
319
+ const space = resolveTargetAddressSpace(url);
320
+ if (!space) {
321
+ return nativeFetch(input, init);
322
+ }
323
+ return nativeFetch(input, applyLocalNetworkAccess(url, init));
324
+ };
325
+ }
326
+
191
327
  // src/auth/auth-handler.ts
192
328
  var DEFAULT_REFRESH_THRESHOLD_MS = 12e4;
193
329
  var CONTENT_TYPE_JSON = "application/json";
@@ -378,7 +514,7 @@ var AuthHandler = class {
378
514
  headers["Authorization"] = `Bearer ${this._accessToken}`;
379
515
  }
380
516
  try {
381
- await globalThis.fetch(url, {
517
+ await localNetworkFetch(url, {
382
518
  method: "POST",
383
519
  headers,
384
520
  signal: AbortSignal.timeout(this._timeout)
@@ -411,7 +547,7 @@ var AuthHandler = class {
411
547
  if (token) {
412
548
  headers["Authorization"] = `Bearer ${token}`;
413
549
  }
414
- const response = await globalThis.fetch(url, {
550
+ const response = await localNetworkFetch(url, {
415
551
  method: "GET",
416
552
  headers,
417
553
  signal: AbortSignal.timeout(this._timeout)
@@ -438,7 +574,7 @@ var AuthHandler = class {
438
574
  if (token) {
439
575
  headers["Authorization"] = `Bearer ${token}`;
440
576
  }
441
- const response = await globalThis.fetch(url, {
577
+ const response = await localNetworkFetch(url, {
442
578
  method: "PUT",
443
579
  headers,
444
580
  body: JSON.stringify({ currentPassword, newPassword }),
@@ -478,7 +614,7 @@ var AuthHandler = class {
478
614
  if (this._accessToken) {
479
615
  headers["Authorization"] = `Bearer ${this._accessToken}`;
480
616
  }
481
- return globalThis.fetch(url, {
617
+ return localNetworkFetch(url, {
482
618
  method,
483
619
  headers,
484
620
  body: JSON.stringify(body),
@@ -831,7 +967,7 @@ var AuthClient = class {
831
967
  if (token) {
832
968
  headers["Authorization"] = `Bearer ${token}`;
833
969
  }
834
- const response = await globalThis.fetch(endpoint, {
970
+ const response = await localNetworkFetch(endpoint, {
835
971
  method,
836
972
  headers,
837
973
  body: body !== void 0 && method !== "GET" && method !== "DELETE" ? JSON.stringify(body) : void 0,
@@ -1154,7 +1290,7 @@ var HttpTransport = class {
1154
1290
  init.body = JSON.stringify(config.body);
1155
1291
  }
1156
1292
  try {
1157
- const response = await fetch(url, init);
1293
+ const response = await localNetworkFetch(url, init);
1158
1294
  if (!response.ok) {
1159
1295
  const text = await response.text();
1160
1296
  if (config.allowStatuses?.includes(response.status) && text) {
@@ -1268,7 +1404,7 @@ var HttpTransport = class {
1268
1404
  init.body = JSON.stringify(config.body);
1269
1405
  }
1270
1406
  try {
1271
- const response = await fetch(url, init);
1407
+ const response = await localNetworkFetch(url, init);
1272
1408
  if (response.ok || config.allowStatuses?.includes(response.status)) {
1273
1409
  return response;
1274
1410
  }
@@ -3505,13 +3641,19 @@ var DatabasesApi = class {
3505
3641
  this.transport = transport;
3506
3642
  }
3507
3643
  /**
3508
- * Lists all databases on the server.
3644
+ * Lists databases on the server.
3509
3645
  * GET /api/databases
3510
3646
  *
3511
- * @returns Array of database info (name, state, createdAt, options).
3647
+ * By default only operator-facing databases (isInternal === false) are returned.
3648
+ * Pass `{ includeInternal: true }` to receive the full catalog including internal
3649
+ * infrastructure databases such as `_serverauth` and `_settings`.
3650
+ *
3651
+ * @param options.includeInternal - When true, appends `?include=internal` to the request.
3652
+ * @returns Array of database info.
3512
3653
  */
3513
- async list() {
3514
- const response = await this.transport.get("/api/databases");
3654
+ async list(options) {
3655
+ const path = options?.includeInternal ? "/api/databases?include=internal" : "/api/databases";
3656
+ const response = await this.transport.get(path);
3515
3657
  return response.databases;
3516
3658
  }
3517
3659
  /**
@@ -4670,7 +4812,7 @@ var LongPollTransport = class {
4670
4812
  this._authHandler = options.authHandler;
4671
4813
  this._onReconnected = options.onReconnected;
4672
4814
  this._waitMs = Math.max(1, options.waitMs ?? DEFAULT_WAIT_MS);
4673
- this._fetch = options.fetchImpl ?? fetch;
4815
+ this._fetch = options.fetchImpl ?? localNetworkFetch;
4674
4816
  }
4675
4817
  get lastVersion() {
4676
4818
  return this._lastVersion;
@@ -5563,7 +5705,7 @@ function createAoudaClusterMcpToolSet(client) {
5563
5705
  }
5564
5706
 
5565
5707
  // src/index.ts
5566
- var version = "0.0.2";
5708
+ var version = package_default.version;
5567
5709
  // Annotate the CommonJS export names for ESM import in node:
5568
5710
  0 && (module.exports = {
5569
5711
  AOUDA_DATA_TYPES,
@@ -5601,9 +5743,13 @@ var version = "0.0.2";
5601
5743
  TableQuery,
5602
5744
  TablesApi,
5603
5745
  WhereGroupBuilder,
5746
+ applyLocalNetworkAccess,
5604
5747
  coerceColumnarValue,
5605
5748
  createAoudaClient,
5606
5749
  createAoudaClusterMcpToolSet,
5750
+ installLocalNetworkFetch,
5751
+ localNetworkFetch,
5752
+ resolveTargetAddressSpace,
5607
5753
  version
5608
5754
  });
5609
5755
  //# sourceMappingURL=index.cjs.map