@xanots/sdk 0.0.1

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.
Files changed (106) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +384 -0
  3. package/dist/agent-file-refresh-7XCACU34.js +95 -0
  4. package/dist/bin.d.ts +1 -0
  5. package/dist/bin.js +184 -0
  6. package/dist/capture-HUV5BNTC.js +32 -0
  7. package/dist/chunk-26CNBZE2.js +963 -0
  8. package/dist/chunk-33ND6LKO.js +78 -0
  9. package/dist/chunk-3DUAGYGP.js +1550 -0
  10. package/dist/chunk-3IGNIP6R.js +89 -0
  11. package/dist/chunk-47WDWMBJ.js +14 -0
  12. package/dist/chunk-4BXJGVZ3.js +318 -0
  13. package/dist/chunk-4HT3BNZ7.js +675 -0
  14. package/dist/chunk-4YMD2OOZ.js +23 -0
  15. package/dist/chunk-5WGEURVI.js +156 -0
  16. package/dist/chunk-5YTBTF25.js +29 -0
  17. package/dist/chunk-6DHBYBTO.js +166 -0
  18. package/dist/chunk-76QBEIGO.js +66 -0
  19. package/dist/chunk-7DKX2SPN.js +100 -0
  20. package/dist/chunk-7REDODS2.js +468 -0
  21. package/dist/chunk-C56BC2FY.js +254 -0
  22. package/dist/chunk-DGSF2Q5H.js +60 -0
  23. package/dist/chunk-EMCAWMHC.js +3982 -0
  24. package/dist/chunk-EZG76F7R.js +159 -0
  25. package/dist/chunk-FJ6ZS5KB.js +3607 -0
  26. package/dist/chunk-GNPVYOPB.js +17 -0
  27. package/dist/chunk-HJPTWBLH.js +38 -0
  28. package/dist/chunk-IZW6MK3U.js +248 -0
  29. package/dist/chunk-LH6Z6KFV.js +247 -0
  30. package/dist/chunk-MZUI3JNX.js +93 -0
  31. package/dist/chunk-NDZFBZHC.js +167 -0
  32. package/dist/chunk-NOO35BQ2.js +37 -0
  33. package/dist/chunk-NUQCEOKA.js +13 -0
  34. package/dist/chunk-QTNO2WD6.js +56 -0
  35. package/dist/chunk-RVB7ITKN.js +49 -0
  36. package/dist/chunk-TRU5OHQ5.js +6904 -0
  37. package/dist/chunk-VKFQJEMW.js +814 -0
  38. package/dist/chunk-VTIL47DT.js +125 -0
  39. package/dist/chunk-WHOJWOSV.js +112 -0
  40. package/dist/chunk-WKP4D5MO.js +1692 -0
  41. package/dist/chunk-X4DVXBFY.js +38 -0
  42. package/dist/chunk-XQ22GLYS.js +118 -0
  43. package/dist/chunk-YDZYMZBE.js +670 -0
  44. package/dist/chunk-YGPIY3WT.js +1146 -0
  45. package/dist/chunk-YYRDLFSJ.js +602 -0
  46. package/dist/chunk-ZUTSMMAG.js +46 -0
  47. package/dist/cli.d.ts +331 -0
  48. package/dist/cli.js +33 -0
  49. package/dist/codegen-command-OOKK6AZK.js +40 -0
  50. package/dist/codegen.d.ts +114 -0
  51. package/dist/codegen.js +71 -0
  52. package/dist/completion-TIPPZN7H.js +298 -0
  53. package/dist/config-NL33PN4D.js +84 -0
  54. package/dist/deploy-command-4EQ7XX5G.js +451 -0
  55. package/dist/env-target-IFJ5QDHC.js +16 -0
  56. package/dist/ephemeral-command-3X3I4ULC.js +242 -0
  57. package/dist/index.d.ts +4477 -0
  58. package/dist/index.js +300 -0
  59. package/dist/init-command-R6H7ZXW5.js +27 -0
  60. package/dist/internal.d.ts +74 -0
  61. package/dist/internal.js +2065 -0
  62. package/dist/io-AMIKRLPC.js +11 -0
  63. package/dist/live-diff-Y3AKETHE.js +196 -0
  64. package/dist/lock-3CVKALKT.js +37 -0
  65. package/dist/lock-commands-XTR2YKLY.js +232 -0
  66. package/dist/login-command-ACJF6KWQ.js +167 -0
  67. package/dist/logout-command-MX3MJS5U.js +68 -0
  68. package/dist/loop-OM3P2Z6O.js +93 -0
  69. package/dist/marketplace-command-RATXTKXN.js +379 -0
  70. package/dist/meta-client-OW5WKWW7.js +170 -0
  71. package/dist/node.d.ts +59 -0
  72. package/dist/node.js +442 -0
  73. package/dist/profile-command-SWJ3SPKR.js +77 -0
  74. package/dist/release-command-VV5UVZKL.js +427 -0
  75. package/dist/response-CVAE2kMj.d.ts +1915 -0
  76. package/dist/routes-manifest-SP3ZXLMR.js +244 -0
  77. package/dist/runtime-V4C3AC3A.js +13 -0
  78. package/dist/sandbox-details-command-HJE5SPVG.js +18 -0
  79. package/dist/sandbox-export-command-QCJY4GMV.js +24 -0
  80. package/dist/static-host-D6KS7X45.js +138 -0
  81. package/dist/store-BQ97nKIF.d.ts +7760 -0
  82. package/dist/test-command-TSPBQHBM.js +383 -0
  83. package/dist/validate-command-4ERHJSCO.js +122 -0
  84. package/dist/verify-rollout-FAVQ6EJY.js +40 -0
  85. package/dist/workspace-K72NP7SX.js +49 -0
  86. package/dist/workspace-command-OF23DPNI.js +156 -0
  87. package/dist/workspace-export-AJMGN3CQ.js +10 -0
  88. package/llms/fields.md +104 -0
  89. package/llms/filters.md +183 -0
  90. package/llms/kinds-agent-mcp.md +11 -0
  91. package/llms/kinds-core.md +68 -0
  92. package/llms/kinds-realtime.md +76 -0
  93. package/llms/lambda.md +111 -0
  94. package/llms/legacy.md +43 -0
  95. package/llms/object-kinds.md +31 -0
  96. package/llms/statements-calls.md +23 -0
  97. package/llms/statements-catalog.md +309 -0
  98. package/llms/statements-data.md +58 -0
  99. package/llms/statements-runtime.md +48 -0
  100. package/llms/tests.md +58 -0
  101. package/llms/triggers.md +22 -0
  102. package/llms/values.md +29 -0
  103. package/llms-full.txt +1672 -0
  104. package/llms.txt +483 -0
  105. package/manifest.json +9592 -0
  106. package/package.json +110 -0
@@ -0,0 +1,254 @@
1
+ import {
2
+ OpenIdProvider,
3
+ assertHttpsOrigin,
4
+ buildTokenCredential,
5
+ clearCredential,
6
+ decodeAudience,
7
+ globalAuthFilePath,
8
+ localAuthFilePath,
9
+ oauthErrorCode,
10
+ readCredential,
11
+ resolveAuthFilePath,
12
+ resolveAuthHost,
13
+ resolveScope,
14
+ writeCredential
15
+ } from "./chunk-7REDODS2.js";
16
+ import {
17
+ detail,
18
+ hostLabel,
19
+ info,
20
+ warn
21
+ } from "./chunk-EZG76F7R.js";
22
+
23
+ // src/auth/token.ts
24
+ import lockfile from "proper-lockfile";
25
+ var EXPIRY_SKEW_MS = 3e4;
26
+ var REFRESH_LOCK_OPTS = {
27
+ retries: { retries: 30, factor: 1.3, minTimeout: 50, maxTimeout: 500 },
28
+ stale: 2e4
29
+ };
30
+ function stampExpiry(raw) {
31
+ return {
32
+ access_token: raw.access_token,
33
+ refresh_token: raw.refresh_token,
34
+ scope: raw.scope,
35
+ expires_at: Date.now() + (raw.expires_in ?? 0) * 1e3
36
+ };
37
+ }
38
+ function refreshAccessToken(authHost, clientId, refreshToken, scope) {
39
+ const provider = new OpenIdProvider({ authHost, scope: scope ?? "", clientId });
40
+ return provider.refresh(refreshToken, { scope });
41
+ }
42
+ function isTransientRefreshError(err) {
43
+ return oauthErrorCode(err) === void 0;
44
+ }
45
+ async function refreshWithRetry(authHost, clientId, refreshToken, scope) {
46
+ try {
47
+ return await refreshAccessToken(authHost, clientId, refreshToken, scope);
48
+ } catch (err) {
49
+ if (!isTransientRefreshError(err)) throw err;
50
+ detail(`Token refresh hit a network error; retrying once\u2026`);
51
+ return await refreshAccessToken(authHost, clientId, refreshToken, scope);
52
+ }
53
+ }
54
+ var ENV_INSTANCE = "XANO_INSTANCE_URL";
55
+ var ENV_WORKSPACE = "XANO_WORKSPACE_ID";
56
+ var ENV_META_TOKEN = "XANO_META_TOKEN";
57
+ function readEnvVar(name) {
58
+ const raw = process.env[name];
59
+ return raw === void 0 || raw.trim() === "" ? void 0 : raw;
60
+ }
61
+ function readEnvMetaCredential() {
62
+ const instance = readEnvVar(ENV_INSTANCE);
63
+ const workspace = readEnvVar(ENV_WORKSPACE);
64
+ const token = readEnvVar(ENV_META_TOKEN);
65
+ if (instance === void 0 && workspace === void 0 && token === void 0) return void 0;
66
+ const missing = [
67
+ instance === void 0 ? ENV_INSTANCE : void 0,
68
+ workspace === void 0 ? ENV_WORKSPACE : void 0,
69
+ token === void 0 ? ENV_META_TOKEN : void 0
70
+ ].filter((n) => n !== void 0);
71
+ if (missing.length > 0) {
72
+ const set = [ENV_INSTANCE, ENV_WORKSPACE, ENV_META_TOKEN].filter((n) => !missing.includes(n));
73
+ throw new Error(
74
+ `Incomplete meta credential in the environment: ${set.join(", ")} ${set.length === 1 ? "is" : "are"} set but ${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} not. All three are required \u2014 check for a misspelled secret name, or unset the rest to use a different credential.`
75
+ );
76
+ }
77
+ return buildTokenCredential(
78
+ {
79
+ instance,
80
+ // Parsed here, not in the validator: pass the ORIGINAL string through on a
81
+ // bad parse so the rejection quotes what was actually set, not `NaN`.
82
+ workspaceId: /^\d+$/.test(workspace.trim()) ? Number(workspace.trim()) : workspace,
83
+ token
84
+ },
85
+ {
86
+ at: "in the environment",
87
+ labels: { instance: ENV_INSTANCE, workspace: ENV_WORKSPACE, token: ENV_META_TOKEN }
88
+ }
89
+ );
90
+ }
91
+ function envMetaCredentialVarsSet() {
92
+ return [ENV_INSTANCE, ENV_WORKSPACE, ENV_META_TOKEN].filter(
93
+ (name) => readEnvVar(name) !== void 0
94
+ );
95
+ }
96
+ function noteDisplacedCredentials(args) {
97
+ const configPath = args.authFile ?? process.env.XANO_CONFIG;
98
+ if (configPath !== void 0) {
99
+ info(`Using the ${ENV_META_TOKEN} credential from the environment \u2014 ignoring ${configPath}.`);
100
+ }
101
+ if (process.env.XANO_REFRESH_TOKEN !== void 0) {
102
+ info(`Using the ${ENV_META_TOKEN} credential from the environment \u2014 ignoring XANO_REFRESH_TOKEN.`);
103
+ }
104
+ }
105
+ async function getAccessToken(args) {
106
+ const envMeta = readEnvMetaCredential();
107
+ if (envMeta) {
108
+ assertHttpsOrigin(envMeta.instance_base_url, ENV_INSTANCE);
109
+ noteDisplacedCredentials(args);
110
+ return {
111
+ access_token: envMeta.meta_api_token,
112
+ instance: envMeta.instance_base_url,
113
+ workspaceId: envMeta.workspace_id,
114
+ credentialType: "token"
115
+ };
116
+ }
117
+ const envRefresh = process.env.XANO_REFRESH_TOKEN;
118
+ if (envRefresh) {
119
+ const authHost = resolveAuthHost(args);
120
+ assertHttpsOrigin(authHost, "--origin");
121
+ const clientId = process.env.XANO_CLIENT_ID;
122
+ if (!clientId) {
123
+ throw new Error(
124
+ `XANO_REFRESH_TOKEN is set but XANO_CLIENT_ID is not. A refresh token can only be exchanged by the client that minted it \u2014 copy both values from \`.xano/auth.json\` (fields "refresh_token" and "client_id") after \`xanots login\`.`
125
+ );
126
+ }
127
+ let set;
128
+ try {
129
+ set = await refreshAccessToken(authHost, clientId, envRefresh, resolveScope(args));
130
+ } catch (err) {
131
+ throw new Error(
132
+ `XANO_REFRESH_TOKEN exchange failed: ${err instanceof Error ? err.message : String(err)}
133
+ The refresh token may be expired or already spent \u2014 refresh tokens rotate on use, so a single stored value is consumed on first exchange. Mint a fresh one via \`xanots login\`.`
134
+ );
135
+ }
136
+ const instance2 = decodeAudience(set.access_token);
137
+ if (!instance2) {
138
+ throw new Error(
139
+ `Could not determine the target instance from the token minted by XANO_REFRESH_TOKEN (no readable \`aud\` claim). Mint a fresh refresh token via \`xanots login\`.`
140
+ );
141
+ }
142
+ assertHttpsOrigin(instance2, "instance");
143
+ const { resolveScopedWorkspaceId } = await import("./workspace-K72NP7SX.js");
144
+ const workspaceId = await resolveScopedWorkspaceId({ access_token: set.access_token, instance: instance2 });
145
+ return { access_token: set.access_token, instance: instance2, workspaceId, credentialType: "oauth" };
146
+ }
147
+ const authFilePath = resolveAuthFilePath(args);
148
+ const saved = readCredential(authFilePath);
149
+ if (!saved) {
150
+ throw new Error(
151
+ `Not signed in (no credential at ${authFilePath}). Run \`xanots login\` first, or set XANO_REFRESH_TOKEN for CI.`
152
+ );
153
+ }
154
+ warnIfLocalShadowsGlobal(args, authFilePath, saved);
155
+ if (saved.type === "token") {
156
+ assertHttpsOrigin(saved.instance_base_url, "instance_base_url");
157
+ return {
158
+ access_token: saved.meta_api_token,
159
+ instance: saved.instance_base_url,
160
+ workspaceId: saved.workspace_id,
161
+ credentialType: "token"
162
+ };
163
+ }
164
+ const instance = saved.instance;
165
+ assertHttpsOrigin(instance, "instance");
166
+ if (Date.now() < saved.expires_at - EXPIRY_SKEW_MS) {
167
+ return {
168
+ access_token: saved.access_token,
169
+ instance,
170
+ workspaceId: saved.workspace_id,
171
+ credentialType: "oauth"
172
+ };
173
+ }
174
+ return refreshUnderLock(authFilePath, saved);
175
+ }
176
+ function targetOf(credential) {
177
+ return credential.type === "token" ? { instance: credential.instance_base_url, workspaceId: credential.workspace_id } : { instance: credential.instance, workspaceId: credential.workspace_id };
178
+ }
179
+ function warnIfLocalShadowsGlobal(args, resolved, saved) {
180
+ const isDefaultResolution = args.authFile === void 0 && process.env.XANO_CONFIG === void 0 && !args.local;
181
+ if (!isDefaultResolution || resolved !== localAuthFilePath()) return;
182
+ const globalPath = globalAuthFilePath();
183
+ if (globalPath === resolved) return;
184
+ let globalSaved = null;
185
+ try {
186
+ globalSaved = readCredential(globalPath);
187
+ } catch {
188
+ return;
189
+ }
190
+ if (!globalSaved) return;
191
+ const here = targetOf(saved);
192
+ const there = targetOf(globalSaved);
193
+ if (here.instance === there.instance && here.workspaceId === there.workspaceId) return;
194
+ warn(
195
+ `Using project-local ${resolved} (${hostLabel(here.instance)}, workspace ${here.workspaceId}), but a global credential for ${hostLabel(there.instance)}, workspace ${there.workspaceId} also exists \u2014 the local one wins. Remove ./.xano/auth.json (or pass --config) to use the global credential instead.`
196
+ );
197
+ }
198
+ async function refreshUnderLock(authFilePath, saved) {
199
+ const release = await lockfile.lock(authFilePath, REFRESH_LOCK_OPTS);
200
+ try {
201
+ const reread = readCredential(authFilePath);
202
+ const current = reread?.type === "oauth" ? reread : saved;
203
+ const instance = current.instance;
204
+ const workspaceId = current.workspace_id;
205
+ if (Date.now() < current.expires_at - EXPIRY_SKEW_MS) {
206
+ return { access_token: current.access_token, instance, workspaceId, credentialType: "oauth" };
207
+ }
208
+ if (!current.refresh_token) {
209
+ throw new Error(
210
+ `No usable access token for ${instance} and no refresh token is cached. Run \`xanots login\` again.`
211
+ );
212
+ }
213
+ detail(`Refreshing access token for ${hostLabel(instance)}\u2026`);
214
+ let set;
215
+ try {
216
+ set = await refreshWithRetry(current.auth_host, current.client_id, current.refresh_token, current.scope);
217
+ } catch (err) {
218
+ const message = err instanceof Error ? err.message : String(err);
219
+ if (oauthErrorCode(err) === "invalid_grant") {
220
+ clearCredential(authFilePath);
221
+ throw new Error(
222
+ `Session for ${instance} has expired or was revoked (the refresh token was rejected). Run \`xanots login\` to sign in again.`
223
+ );
224
+ }
225
+ if (isTransientRefreshError(err)) {
226
+ throw new Error(
227
+ `Token refresh for ${instance} could not reach the authorization server (${message}), even after one retry. This is a transient network error, not an auth problem \u2014 re-run the deploy. If it persists, check connectivity to ${current.auth_host}.`
228
+ );
229
+ }
230
+ throw new Error(
231
+ `Token refresh failed for ${instance}: ${message}
232
+ Run \`xanots login\` to sign in again.`
233
+ );
234
+ }
235
+ const stamped = stampExpiry(set);
236
+ writeCredential(authFilePath, {
237
+ ...current,
238
+ access_token: stamped.access_token,
239
+ refresh_token: stamped.refresh_token ?? current.refresh_token,
240
+ expires_at: stamped.expires_at,
241
+ scope: stamped.scope ?? current.scope
242
+ });
243
+ return { access_token: stamped.access_token, instance, workspaceId, credentialType: "oauth" };
244
+ } finally {
245
+ await release();
246
+ }
247
+ }
248
+
249
+ export {
250
+ ENV_WORKSPACE,
251
+ envMetaCredentialVarsSet,
252
+ getAccessToken
253
+ };
254
+ //# sourceMappingURL=chunk-C56BC2FY.js.map
@@ -0,0 +1,60 @@
1
+ import {
2
+ ensureGitignored
3
+ } from "./chunk-7REDODS2.js";
4
+ import {
5
+ atomicWrite
6
+ } from "./chunk-GNPVYOPB.js";
7
+
8
+ // src/deploy/ephemeral-state.ts
9
+ import { readFileSync, mkdirSync } from "fs";
10
+ import { dirname, join, resolve } from "path";
11
+ function ephemeralStatePath(dir) {
12
+ return join(resolve(dir), ".xano", "ephemeral.json");
13
+ }
14
+ function readEphemeralState(dir) {
15
+ const path = ephemeralStatePath(dir);
16
+ let text;
17
+ try {
18
+ text = readFileSync(path, "utf8");
19
+ } catch {
20
+ return { version: 1, environments: {} };
21
+ }
22
+ try {
23
+ const parsed = JSON.parse(text);
24
+ if (parsed && typeof parsed === "object" && typeof parsed.environments === "object") {
25
+ const envs = parsed.environments ?? {};
26
+ return { version: 1, environments: { ...envs } };
27
+ }
28
+ } catch {
29
+ }
30
+ return { version: 1, environments: {} };
31
+ }
32
+ function getEnvironment(state, workspaceId) {
33
+ return state.environments[String(workspaceId)];
34
+ }
35
+ function setEnvironment(dir, workspaceId, record) {
36
+ const state = readEphemeralState(dir);
37
+ state.environments[String(workspaceId)] = record;
38
+ writeState(dir, state);
39
+ }
40
+ function clearEnvironment(dir, workspaceId) {
41
+ const state = readEphemeralState(dir);
42
+ if (!(String(workspaceId) in state.environments)) return false;
43
+ delete state.environments[String(workspaceId)];
44
+ writeState(dir, state);
45
+ return true;
46
+ }
47
+ function writeState(dir, state) {
48
+ const path = ephemeralStatePath(dir);
49
+ mkdirSync(dirname(path), { recursive: true });
50
+ atomicWrite(path, JSON.stringify({ version: 1, environments: state.environments }, null, 2) + "\n");
51
+ ensureGitignored(path);
52
+ }
53
+
54
+ export {
55
+ readEphemeralState,
56
+ getEnvironment,
57
+ setEnvironment,
58
+ clearEnvironment
59
+ };
60
+ //# sourceMappingURL=chunk-DGSF2Q5H.js.map