@aouda/client 0.0.2 → 0.0.3

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.
@@ -418,6 +418,74 @@ var fs3 = __toESM(require("fs"), 1);
418
418
  var path3 = __toESM(require("path"), 1);
419
419
  var import_node_url = require("url");
420
420
 
421
+ // package.json
422
+ var package_default = {
423
+ name: "@aouda/client",
424
+ version: "0.0.3",
425
+ description: "Official TypeScript/JavaScript client library for Aouda",
426
+ type: "module",
427
+ main: "./dist/index.cjs",
428
+ module: "./dist/index.js",
429
+ types: "./dist/index.d.ts",
430
+ bin: "./dist/cli/index.js",
431
+ exports: {
432
+ ".": {
433
+ types: "./dist/index.d.ts",
434
+ import: "./dist/index.js",
435
+ require: "./dist/index.cjs"
436
+ }
437
+ },
438
+ license: "MIT",
439
+ repository: {
440
+ type: "git",
441
+ url: "https://github.com/aoudadb/aouda-client-ts.git"
442
+ },
443
+ publishConfig: {
444
+ access: "public"
445
+ },
446
+ files: [
447
+ "dist",
448
+ "README.md",
449
+ "LICENSE"
450
+ ],
451
+ scripts: {
452
+ changeset: "changeset",
453
+ "version-packages": "changeset version",
454
+ release: "changeset publish",
455
+ prepublishOnly: "npm run build",
456
+ build: "tsup",
457
+ dev: "tsup --watch",
458
+ test: "vitest run",
459
+ "test:watch": "vitest",
460
+ "test:coverage": "vitest run --coverage",
461
+ lint: "eslint src tests",
462
+ "lint:fix": "eslint src tests --fix",
463
+ format: 'prettier --write "src/**/*.ts" "tests/**/*.ts"',
464
+ typecheck: "tsc --noEmit && tsc -p tsconfig.typecheck.json --noEmit",
465
+ "generate-types": "node dist/cli/index.js generate --server http://localhost:5000 --output ./types/schema.ts"
466
+ },
467
+ engines: {
468
+ node: ">=20"
469
+ },
470
+ devDependencies: {
471
+ "@changesets/cli": "^2.29.8",
472
+ "@eslint/js": "^9.15.0",
473
+ "@types/node": "^25.2.1",
474
+ "@types/ws": "^8.18.1",
475
+ eslint: "^9.15.0",
476
+ "eslint-config-prettier": "^9.1.0",
477
+ prettier: "^3.3.3",
478
+ tsup: "^8.3.5",
479
+ typescript: "^5.6.3",
480
+ "typescript-eslint": "^8.15.0",
481
+ vitest: "^2.1.4"
482
+ },
483
+ dependencies: {
484
+ "@msgpack/msgpack": "^3.1.3",
485
+ ws: "^8.20.0"
486
+ }
487
+ };
488
+
421
489
  // src/types.ts
422
490
  var RetryPolicy;
423
491
  ((RetryPolicy2) => {
@@ -517,6 +585,54 @@ var AoudaCircuitBreakerOpenError = class extends AoudaError {
517
585
  }
518
586
  };
519
587
 
588
+ // src/local-network-fetch.ts
589
+ function resolveTargetAddressSpace(url) {
590
+ let parsed;
591
+ try {
592
+ parsed = new URL(url);
593
+ } catch {
594
+ return void 0;
595
+ }
596
+ const hostname = parsed.hostname.replace(/^\[|\]$/g, "").toLowerCase();
597
+ if (hostname === "localhost" || hostname === "::1") {
598
+ return "loopback";
599
+ }
600
+ const ipv4 = hostname.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
601
+ if (ipv4) {
602
+ const [first, second] = [Number(ipv4[1]), Number(ipv4[2])];
603
+ if (first === 127) return "loopback";
604
+ if (first === 10) return "local";
605
+ if (first === 172 && second >= 16 && second <= 31) return "local";
606
+ if (first === 192 && second === 168) return "local";
607
+ if (first === 169 && second === 254) return "local";
608
+ }
609
+ if (hostname.endsWith(".local")) {
610
+ return "local";
611
+ }
612
+ return void 0;
613
+ }
614
+ function applyLocalNetworkAccess(url, init) {
615
+ const space = resolveTargetAddressSpace(url);
616
+ if (!space) {
617
+ return init ?? {};
618
+ }
619
+ return { ...init, targetAddressSpace: space };
620
+ }
621
+ function resolveFetchUrl(input) {
622
+ if (typeof input === "string") {
623
+ return input;
624
+ }
625
+ if (input instanceof URL) {
626
+ return input.href;
627
+ }
628
+ return input.url;
629
+ }
630
+ function localNetworkFetch(input, init) {
631
+ const url = resolveFetchUrl(input);
632
+ const merged = applyLocalNetworkAccess(url, init);
633
+ return globalThis.fetch(input, merged);
634
+ }
635
+
520
636
  // src/auth/auth-handler.ts
521
637
  var DEFAULT_REFRESH_THRESHOLD_MS = 12e4;
522
638
  var CONTENT_TYPE_JSON = "application/json";
@@ -707,7 +823,7 @@ var AuthHandler = class {
707
823
  headers["Authorization"] = `Bearer ${this._accessToken}`;
708
824
  }
709
825
  try {
710
- await globalThis.fetch(url, {
826
+ await localNetworkFetch(url, {
711
827
  method: "POST",
712
828
  headers,
713
829
  signal: AbortSignal.timeout(this._timeout)
@@ -740,7 +856,7 @@ var AuthHandler = class {
740
856
  if (token) {
741
857
  headers["Authorization"] = `Bearer ${token}`;
742
858
  }
743
- const response = await globalThis.fetch(url, {
859
+ const response = await localNetworkFetch(url, {
744
860
  method: "GET",
745
861
  headers,
746
862
  signal: AbortSignal.timeout(this._timeout)
@@ -767,7 +883,7 @@ var AuthHandler = class {
767
883
  if (token) {
768
884
  headers["Authorization"] = `Bearer ${token}`;
769
885
  }
770
- const response = await globalThis.fetch(url, {
886
+ const response = await localNetworkFetch(url, {
771
887
  method: "PUT",
772
888
  headers,
773
889
  body: JSON.stringify({ currentPassword, newPassword }),
@@ -807,7 +923,7 @@ var AuthHandler = class {
807
923
  if (this._accessToken) {
808
924
  headers["Authorization"] = `Bearer ${this._accessToken}`;
809
925
  }
810
- return globalThis.fetch(url, {
926
+ return localNetworkFetch(url, {
811
927
  method,
812
928
  headers,
813
929
  body: JSON.stringify(body),
@@ -1160,7 +1276,7 @@ var AuthClient = class {
1160
1276
  if (token) {
1161
1277
  headers["Authorization"] = `Bearer ${token}`;
1162
1278
  }
1163
- const response = await globalThis.fetch(endpoint, {
1279
+ const response = await localNetworkFetch(endpoint, {
1164
1280
  method,
1165
1281
  headers,
1166
1282
  body: body !== void 0 && method !== "GET" && method !== "DELETE" ? JSON.stringify(body) : void 0,
@@ -1483,7 +1599,7 @@ var HttpTransport = class {
1483
1599
  init.body = JSON.stringify(config.body);
1484
1600
  }
1485
1601
  try {
1486
- const response = await fetch(url, init);
1602
+ const response = await localNetworkFetch(url, init);
1487
1603
  if (!response.ok) {
1488
1604
  const text = await response.text();
1489
1605
  if (config.allowStatuses?.includes(response.status) && text) {
@@ -1597,7 +1713,7 @@ var HttpTransport = class {
1597
1713
  init.body = JSON.stringify(config.body);
1598
1714
  }
1599
1715
  try {
1600
- const response = await fetch(url, init);
1716
+ const response = await localNetworkFetch(url, init);
1601
1717
  if (response.ok || config.allowStatuses?.includes(response.status)) {
1602
1718
  return response;
1603
1719
  }
@@ -4986,7 +5102,7 @@ var LongPollTransport = class {
4986
5102
  this._authHandler = options.authHandler;
4987
5103
  this._onReconnected = options.onReconnected;
4988
5104
  this._waitMs = Math.max(1, options.waitMs ?? DEFAULT_WAIT_MS);
4989
- this._fetch = options.fetchImpl ?? fetch;
5105
+ this._fetch = options.fetchImpl ?? localNetworkFetch;
4990
5106
  }
4991
5107
  get lastVersion() {
4992
5108
  return this._lastVersion;
@@ -5628,6 +5744,9 @@ function createAoudaClient(options) {
5628
5744
  return new AoudaClient(options);
5629
5745
  }
5630
5746
 
5747
+ // src/index.ts
5748
+ var version = package_default.version;
5749
+
5631
5750
  // src/cli/index.ts
5632
5751
  var import_meta = {};
5633
5752
  var HELP = `Aouda TypeScript client CLI