notte-sdk 0.0.7 → 0.0.8

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 CHANGED
@@ -5,6 +5,104 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
5
5
  throw Error('Dynamic require of "' + x + '" is not supported');
6
6
  });
7
7
 
8
+ // src/version.ts
9
+ var SDK_VERSION = true ? "0.0.8" : "dev";
10
+ var SDK_PACKAGE_NAME = true ? "notte-sdk" : "notte-sdk";
11
+
12
+ // src/version-check.ts
13
+ var DISABLE_ENV = "NOTTE_SDK_DISABLE_VERSION_CHECK";
14
+ var VERSION_CHECK_TIMEOUT_MS = 1500;
15
+ var hasStartedVersionCheck = false;
16
+ function startVersionCheck() {
17
+ if (hasStartedVersionCheck || !shouldCheckVersion()) {
18
+ return;
19
+ }
20
+ hasStartedVersionCheck = true;
21
+ const timer = setTimeout(() => {
22
+ void checkForLatestVersion().catch(() => void 0);
23
+ }, 0);
24
+ timer.unref?.();
25
+ }
26
+ async function checkForLatestVersion(options = {}) {
27
+ const currentVersion = options.currentVersion ?? SDK_VERSION;
28
+ const packageName = options.packageName ?? SDK_PACKAGE_NAME;
29
+ const fetchFn = options.fetchFn ?? globalThis.fetch;
30
+ const warnFn = options.warnFn ?? console.warn;
31
+ const env = options.env ?? getEnv();
32
+ if (!shouldCheckVersion(currentVersion, fetchFn, env)) {
33
+ return;
34
+ }
35
+ const latestVersion = await fetchLatestVersion(packageName, fetchFn);
36
+ if (!latestVersion || !isVersionGreater(latestVersion, currentVersion)) {
37
+ return;
38
+ }
39
+ warnFn(
40
+ `[${packageName}] A newer version is available: ${currentVersion} -> ${latestVersion}. Update with: npm install ${packageName}@latest`
41
+ );
42
+ }
43
+ function shouldCheckVersion(currentVersion = SDK_VERSION, fetchFn = globalThis.fetch, env = getEnv()) {
44
+ if (!fetchFn || !env || env[DISABLE_ENV] || env.NODE_ENV === "test" || env.VITEST || env.CI) {
45
+ return false;
46
+ }
47
+ return isPublishedVersion(currentVersion);
48
+ }
49
+ async function fetchLatestVersion(packageName, fetchFn) {
50
+ const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
51
+ const timeout = controller ? setTimeout(() => controller.abort(), VERSION_CHECK_TIMEOUT_MS) : void 0;
52
+ timeout?.unref?.();
53
+ try {
54
+ const response = await fetchFn(`https://registry.npmjs.org/${encodeURIComponent(packageName)}/latest`, {
55
+ headers: {
56
+ accept: "application/json"
57
+ },
58
+ signal: controller?.signal
59
+ });
60
+ if (!response.ok) {
61
+ return void 0;
62
+ }
63
+ const payload = await response.json();
64
+ return typeof payload.version === "string" ? payload.version : void 0;
65
+ } catch {
66
+ return void 0;
67
+ } finally {
68
+ if (timeout) {
69
+ clearTimeout(timeout);
70
+ }
71
+ }
72
+ }
73
+ function isPublishedVersion(version) {
74
+ return /^\d+\.\d+\.\d+/.test(version) && !version.includes("dev");
75
+ }
76
+ function isVersionGreater(candidate, current) {
77
+ const candidateVersion = parseSemver(candidate);
78
+ const currentVersion = parseSemver(current);
79
+ if (!candidateVersion || !currentVersion) {
80
+ return false;
81
+ }
82
+ for (let index = 0; index < 3; index += 1) {
83
+ if (candidateVersion.parts[index] > currentVersion.parts[index]) {
84
+ return true;
85
+ }
86
+ if (candidateVersion.parts[index] < currentVersion.parts[index]) {
87
+ return false;
88
+ }
89
+ }
90
+ return currentVersion.prerelease.length > 0 && candidateVersion.prerelease.length === 0;
91
+ }
92
+ function parseSemver(version) {
93
+ const match = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-([^+]+))?/);
94
+ if (!match) {
95
+ return void 0;
96
+ }
97
+ return {
98
+ parts: [Number(match[1]), Number(match[2]), Number(match[3])],
99
+ prerelease: match[4] ?? ""
100
+ };
101
+ }
102
+ function getEnv() {
103
+ return typeof process !== "undefined" ? process.env : void 0;
104
+ }
105
+
8
106
  // src/lib/client/core/bodySerializer.gen.ts
9
107
  var serializeFormDataPair = (data, key, value) => {
10
108
  if (typeof value === "string" || value instanceof Blob) {
@@ -2574,9 +2672,6 @@ var NottePersona = class {
2574
2672
  }
2575
2673
  };
2576
2674
 
2577
- // src/version.ts
2578
- var SDK_VERSION = true ? "0.0.7" : "dev";
2579
-
2580
2675
  // src/functions.ts
2581
2676
  var NotteFunction = class {
2582
2677
  constructor(client2, options) {
@@ -2807,6 +2902,7 @@ var NotteProxyAuthError = class extends Error {
2807
2902
  };
2808
2903
 
2809
2904
  // src/index.ts
2905
+ startVersionCheck();
2810
2906
  var createClient2 = (config) => {
2811
2907
  if (config?.baseUrl) {
2812
2908
  client.setConfig({ baseUrl: config.baseUrl });