@databricks/sdk-core 0.34.0 → 0.36.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/apierror/apierror.d.ts +52 -49
- package/dist/apierror/apierror.d.ts.map +1 -1
- package/dist/apierror/apierror.js +124 -172
- package/dist/apierror/apierror.js.map +1 -1
- package/dist/apierror/codes/codes.d.ts +113 -113
- package/dist/apierror/codes/codes.d.ts.map +1 -1
- package/dist/apierror/codes/codes.js +24 -115
- package/dist/apierror/codes/codes.js.map +1 -1
- package/dist/apierror/codes/index.d.ts +2 -7
- package/dist/apierror/codes/index.js +3 -7
- package/dist/apierror/details.d.ts +104 -101
- package/dist/apierror/details.d.ts.map +1 -1
- package/dist/apierror/details.js +151 -226
- package/dist/apierror/details.js.map +1 -1
- package/dist/apierror/index.d.ts +3 -8
- package/dist/apierror/index.js +3 -7
- package/dist/clientinfo/agent.d.ts +6 -3
- package/dist/clientinfo/agent.d.ts.map +1 -1
- package/dist/clientinfo/agent.js +134 -112
- package/dist/clientinfo/agent.js.map +1 -1
- package/dist/clientinfo/base.d.ts +13 -15
- package/dist/clientinfo/base.d.ts.map +1 -1
- package/dist/clientinfo/base.js +50 -50
- package/dist/clientinfo/base.js.map +1 -1
- package/dist/clientinfo/clientinfo.d.ts +40 -38
- package/dist/clientinfo/clientinfo.d.ts.map +1 -1
- package/dist/clientinfo/clientinfo.js +78 -88
- package/dist/clientinfo/clientinfo.js.map +1 -1
- package/dist/clientinfo/default.browser.d.ts +6 -10
- package/dist/clientinfo/default.browser.d.ts.map +1 -1
- package/dist/clientinfo/default.browser.js +24 -16
- package/dist/clientinfo/default.browser.js.map +1 -1
- package/dist/clientinfo/default.d.ts +8 -4
- package/dist/clientinfo/default.d.ts.map +1 -1
- package/dist/clientinfo/default.js +157 -102
- package/dist/clientinfo/default.js.map +1 -1
- package/dist/clientinfo/index.browser.d.ts +4 -5
- package/dist/clientinfo/index.browser.js +5 -4
- package/dist/clientinfo/index.d.ts +4 -5
- package/dist/clientinfo/index.js +5 -4
- package/dist/clientinfo/meta-harness.d.ts +6 -3
- package/dist/clientinfo/meta-harness.d.ts.map +1 -1
- package/dist/clientinfo/meta-harness.js +30 -46
- package/dist/clientinfo/meta-harness.js.map +1 -1
- package/dist/http/http.d.ts +25 -22
- package/dist/http/http.d.ts.map +1 -1
- package/dist/http/http.js +24 -34
- package/dist/http/http.js.map +1 -1
- package/dist/http/index.d.ts +2 -8
- package/dist/http/index.js +3 -7
- package/dist/index.d.ts +1 -6
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/logger/index.d.ts +2 -8
- package/dist/logger/index.js +3 -7
- package/dist/logger/logger.d.ts +26 -23
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.js +46 -60
- package/dist/logger/logger.js.map +1 -1
- package/dist/ops/execute.d.ts +7 -3
- package/dist/ops/execute.d.ts.map +1 -1
- package/dist/ops/execute.js +55 -67
- package/dist/ops/execute.js.map +1 -1
- package/dist/ops/index.d.ts +5 -12
- package/dist/ops/index.js +4 -9
- package/dist/ops/limiter.d.ts +5 -2
- package/dist/ops/limiter.d.ts.map +1 -1
- package/dist/ops/limiter.js +0 -2
- package/dist/ops/options.d.ts +23 -19
- package/dist/ops/options.d.ts.map +1 -1
- package/dist/ops/options.js +0 -2
- package/dist/ops/retrier.d.ts +34 -31
- package/dist/ops/retrier.d.ts.map +1 -1
- package/dist/ops/retrier.js +55 -66
- package/dist/ops/retrier.js.map +1 -1
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/dist/profiles/errors.d.ts +7 -4
- package/dist/profiles/errors.d.ts.map +1 -1
- package/dist/profiles/errors.js +16 -17
- package/dist/profiles/errors.js.map +1 -1
- package/dist/profiles/index.browser.d.ts +4 -10
- package/dist/profiles/index.browser.js +4 -8
- package/dist/profiles/index.d.ts +5 -15
- package/dist/profiles/index.js +5 -13
- package/dist/profiles/ini.d.ts +6 -3
- package/dist/profiles/ini.d.ts.map +1 -1
- package/dist/profiles/ini.js +60 -108
- package/dist/profiles/ini.js.map +1 -1
- package/dist/profiles/profile.d.ts +66 -67
- package/dist/profiles/profile.d.ts.map +1 -1
- package/dist/profiles/profile.js +89 -84
- package/dist/profiles/profile.js.map +1 -1
- package/dist/profiles/resolve.d.ts +8 -9
- package/dist/profiles/resolve.d.ts.map +1 -1
- package/dist/profiles/resolve.js +140 -185
- package/dist/profiles/resolve.js.map +1 -1
- package/dist/profiles/secret.d.ts +15 -12
- package/dist/profiles/secret.d.ts.map +1 -1
- package/dist/profiles/secret.js +38 -35
- package/dist/profiles/secret.js.map +1 -1
- package/dist/wkt/fieldmask.d.ts +23 -20
- package/dist/wkt/fieldmask.d.ts.map +1 -1
- package/dist/wkt/fieldmask.js +53 -62
- package/dist/wkt/fieldmask.js.map +1 -1
- package/dist/wkt/index.d.ts +3 -4
- package/dist/wkt/index.js +3 -2
- package/dist/wkt/value.d.ts +6 -3
- package/dist/wkt/value.d.ts.map +1 -1
- package/dist/wkt/value.js +0 -2
- package/package.json +2 -2
- package/dist/apierror/codes/index.d.ts.map +0 -1
- package/dist/apierror/codes/index.js.map +0 -1
- package/dist/apierror/index.d.ts.map +0 -1
- package/dist/apierror/index.js.map +0 -1
- package/dist/clientinfo/index.browser.d.ts.map +0 -1
- package/dist/clientinfo/index.browser.js.map +0 -1
- package/dist/clientinfo/index.d.ts.map +0 -1
- package/dist/clientinfo/index.js.map +0 -1
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/logger/index.js.map +0 -1
- package/dist/ops/index.d.ts.map +0 -1
- package/dist/ops/index.js.map +0 -1
- package/dist/ops/limiter.js.map +0 -1
- package/dist/ops/options.js.map +0 -1
- package/dist/profiles/index.browser.d.ts.map +0 -1
- package/dist/profiles/index.browser.js.map +0 -1
- package/dist/profiles/index.d.ts.map +0 -1
- package/dist/profiles/index.js.map +0 -1
- package/dist/wkt/index.d.ts.map +0 -1
- package/dist/wkt/index.js.map +0 -1
- package/dist/wkt/value.js.map +0 -1
package/dist/clientinfo/agent.js
CHANGED
|
@@ -1,127 +1,149 @@
|
|
|
1
|
+
import { sanitize } from "./clientinfo.js";
|
|
2
|
+
|
|
3
|
+
//#region src/clientinfo/agent.ts
|
|
1
4
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const AGENT_ENV_VAR = 'AGENT';
|
|
15
|
-
// Name of the Vercel @vercel/detect-agent convention env var. It serves
|
|
16
|
-
// the same purpose as AGENT_ENV_VAR; agentEnvFallback consults it only when
|
|
17
|
-
// AGENT_ENV_VAR is unset or empty.
|
|
18
|
-
const AI_AGENT_ENV_VAR = 'AI_AGENT';
|
|
19
|
-
// Caps fallback values to keep the user-agent bounded. Explicit-matcher
|
|
20
|
-
// products are short by construction; only the fallback path can carry
|
|
21
|
-
// arbitrary lengths.
|
|
5
|
+
* Detects the AI coding agent (e.g. Claude Code, Cursor, Gemini CLI) that
|
|
6
|
+
* is running the current Node.js process. The detected product name is
|
|
7
|
+
* appended to the user-agent header so that Databricks can understand
|
|
8
|
+
* which agents are invoking the SDK.
|
|
9
|
+
*
|
|
10
|
+
* The agent list and precedence rules are kept in sync across the Go,
|
|
11
|
+
* Java, Python, and TypeScript SDKs.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
const AGENT_ENV_VAR = "AGENT";
|
|
16
|
+
const AI_AGENT_ENV_VAR = "AI_AGENT";
|
|
22
17
|
const MAX_AGENT_FALLBACK_LEN = 64;
|
|
23
|
-
// Canonical list of AI coding agents. Keep this list, and the AGENT /
|
|
24
|
-
// AI_AGENT fallback handling in agentEnvFallback, in sync with the Go,
|
|
25
|
-
// Java, and Python SDKs. Agents are listed alphabetically by product name.
|
|
26
18
|
const KNOWN_AGENTS = [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
19
|
+
{
|
|
20
|
+
envVar: "AMP_CURRENT_THREAD_ID",
|
|
21
|
+
product: "amp"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
envVar: "ANTIGRAVITY_AGENT",
|
|
25
|
+
product: "antigravity"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
envVar: "AUGMENT_AGENT",
|
|
29
|
+
product: "augment"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
envVar: "CLAUDECODE",
|
|
33
|
+
product: "claude-code"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
envVar: "CLINE_ACTIVE",
|
|
37
|
+
product: "cline"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
envVar: "CODEX_CI",
|
|
41
|
+
product: "codex"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
envVar: "COPILOT_CLI",
|
|
45
|
+
product: "copilot-cli"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
envVar: "CURSOR_AGENT",
|
|
49
|
+
product: "cursor"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
envVar: "GEMINI_CLI",
|
|
53
|
+
product: "gemini-cli"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
envVar: "GOOSE_TERMINAL",
|
|
57
|
+
product: "goose"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
envVar: "KIRO",
|
|
61
|
+
product: "kiro"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
envVar: "OPENCLAW_SHELL",
|
|
65
|
+
product: "openclaw"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
envVar: "OPENCODE",
|
|
69
|
+
product: "opencode"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
envVar: "VSCODE_AGENT",
|
|
73
|
+
product: "vscode-agent"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
envVar: "WINDSURF_AGENT",
|
|
77
|
+
product: "windsurf"
|
|
78
|
+
}
|
|
47
79
|
];
|
|
48
80
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
81
|
+
* Returns a sanitized, length-capped name from `AGENT` or `AI_AGENT`,
|
|
82
|
+
* preferring `AGENT` when both are non-empty. Empty is treated as unset for
|
|
83
|
+
* both. The value is passed through rather than categorized so that new
|
|
84
|
+
* names are propagated without the need to update the list of known agents.
|
|
85
|
+
*/
|
|
54
86
|
function agentEnvFallback() {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (v === undefined || v === '') {
|
|
60
|
-
return '';
|
|
61
|
-
}
|
|
62
|
-
// slice is a no-op when the value is already within the cap.
|
|
63
|
-
return sanitize(v).slice(0, MAX_AGENT_FALLBACK_LEN);
|
|
87
|
+
let v = process.env[AGENT_ENV_VAR];
|
|
88
|
+
if (v === void 0 || v === "") v = process.env[AI_AGENT_ENV_VAR];
|
|
89
|
+
if (v === void 0 || v === "") return "";
|
|
90
|
+
return sanitize(v).slice(0, MAX_AGENT_FALLBACK_LEN);
|
|
64
91
|
}
|
|
65
92
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
if (matches.length === 1) {
|
|
93
|
-
return matches[0];
|
|
94
|
-
}
|
|
95
|
-
if (matches.length > 1) {
|
|
96
|
-
return 'multiple';
|
|
97
|
-
}
|
|
98
|
-
return agentEnvFallback();
|
|
93
|
+
* Checks environment variables for known AI agents and returns the
|
|
94
|
+
* detected product name.
|
|
95
|
+
*
|
|
96
|
+
* Explicit product-specific env vars always take precedence over the
|
|
97
|
+
* generic `AGENT` and `AI_AGENT` env vars, so that an explicit signal
|
|
98
|
+
* (e.g. `CLAUDECODE=1`) always wins over a conflicting `AGENT=<name>`
|
|
99
|
+
* value.
|
|
100
|
+
*
|
|
101
|
+
* Returns:
|
|
102
|
+
*
|
|
103
|
+
* - The product name when exactly one known env var is set.
|
|
104
|
+
* - `"multiple"` when multiple known env vars are set. Agent env vars
|
|
105
|
+
* can be stacked when one agent invokes another as a subagent (e.g.
|
|
106
|
+
* Claude Code spawning a Cursor CLI subprocess), so the child process
|
|
107
|
+
* inherits env vars from multiple layers.
|
|
108
|
+
* - A sanitized, length-capped value from `AGENT` or `AI_AGENT` when no
|
|
109
|
+
* known env var is set (see {@link agentEnvFallback}).
|
|
110
|
+
* - `""` when nothing is set.
|
|
111
|
+
*/
|
|
112
|
+
function lookupAgentProvider() {
|
|
113
|
+
const matches = [];
|
|
114
|
+
for (const a of KNOWN_AGENTS) if (a.envVar in process.env) matches.push(a.product);
|
|
115
|
+
if (matches.length === 1) return matches[0];
|
|
116
|
+
if (matches.length > 1) return "multiple";
|
|
117
|
+
return agentEnvFallback();
|
|
99
118
|
}
|
|
100
119
|
let cached;
|
|
101
120
|
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
121
|
+
* Returns the detected AI agent name, cached for the process lifetime.
|
|
122
|
+
*
|
|
123
|
+
* Returns one of:
|
|
124
|
+
*
|
|
125
|
+
* - The known product name when exactly one agent is detected via
|
|
126
|
+
* explicit env matchers.
|
|
127
|
+
* - `"multiple"` when multiple explicit matchers fire for different
|
|
128
|
+
* agents (typically nested agents, e.g. Cursor CLI running as a
|
|
129
|
+
* Claude Code subagent).
|
|
130
|
+
* - A sanitized, length-capped value from `AGENT` or `AI_AGENT` when no
|
|
131
|
+
* explicit matcher fired (see {@link agentEnvFallback}).
|
|
132
|
+
* - `""` when no agent is detected.
|
|
133
|
+
*/
|
|
134
|
+
function agentProvider() {
|
|
135
|
+
cached ??= lookupAgentProvider();
|
|
136
|
+
return cached;
|
|
118
137
|
}
|
|
119
138
|
/**
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
139
|
+
* Clears the cached agent detection result so that the next call to
|
|
140
|
+
* {@link agentProvider} re-evaluates the environment. Exported for
|
|
141
|
+
* testing only.
|
|
142
|
+
*/
|
|
143
|
+
function clearAgentCache() {
|
|
144
|
+
cached = void 0;
|
|
126
145
|
}
|
|
146
|
+
|
|
147
|
+
//#endregion
|
|
148
|
+
export { agentProvider, clearAgentCache, lookupAgentProvider };
|
|
127
149
|
//# sourceMappingURL=agent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","
|
|
1
|
+
{"version":3,"file":"agent.js","names":[],"sources":["../../src/clientinfo/agent.ts"],"sourcesContent":["/**\n * Detects the AI coding agent (e.g. Claude Code, Cursor, Gemini CLI) that\n * is running the current Node.js process. The detected product name is\n * appended to the user-agent header so that Databricks can understand\n * which agents are invoking the SDK.\n *\n * The agent list and precedence rules are kept in sync across the Go,\n * Java, Python, and TypeScript SDKs.\n *\n * @module\n */\n\nimport {sanitize} from './clientinfo';\n\ninterface KnownAgent {\n readonly envVar: string;\n readonly product: string;\n}\n\n// Name of the agents.md standard env var.\nconst AGENT_ENV_VAR = 'AGENT';\n\n// Name of the Vercel @vercel/detect-agent convention env var. It serves\n// the same purpose as AGENT_ENV_VAR; agentEnvFallback consults it only when\n// AGENT_ENV_VAR is unset or empty.\nconst AI_AGENT_ENV_VAR = 'AI_AGENT';\n\n// Caps fallback values to keep the user-agent bounded. Explicit-matcher\n// products are short by construction; only the fallback path can carry\n// arbitrary lengths.\nconst MAX_AGENT_FALLBACK_LEN = 64;\n\n// Canonical list of AI coding agents. Keep this list, and the AGENT /\n// AI_AGENT fallback handling in agentEnvFallback, in sync with the Go,\n// Java, and Python SDKs. Agents are listed alphabetically by product name.\nconst KNOWN_AGENTS: readonly KnownAgent[] = [\n // The amp agent also sets AGENT=amp, handled by the central fallback.\n {envVar: 'AMP_CURRENT_THREAD_ID', product: 'amp'},\n {envVar: 'ANTIGRAVITY_AGENT', product: 'antigravity'},\n {envVar: 'AUGMENT_AGENT', product: 'augment'},\n {envVar: 'CLAUDECODE', product: 'claude-code'},\n {envVar: 'CLINE_ACTIVE', product: 'cline'},\n {envVar: 'CODEX_CI', product: 'codex'},\n {envVar: 'COPILOT_CLI', product: 'copilot-cli'},\n {envVar: 'CURSOR_AGENT', product: 'cursor'},\n {envVar: 'GEMINI_CLI', product: 'gemini-cli'},\n // The goose agent also sets AGENT=goose, handled by the central\n // fallback.\n {envVar: 'GOOSE_TERMINAL', product: 'goose'},\n {envVar: 'KIRO', product: 'kiro'},\n {envVar: 'OPENCLAW_SHELL', product: 'openclaw'},\n {envVar: 'OPENCODE', product: 'opencode'},\n // Set by VS Code 1.121+ for agent-initiated terminal commands\n // (https://code.visualstudio.com/updates/v1_121).\n {envVar: 'VSCODE_AGENT', product: 'vscode-agent'},\n {envVar: 'WINDSURF_AGENT', product: 'windsurf'},\n];\n\n/**\n * Returns a sanitized, length-capped name from `AGENT` or `AI_AGENT`,\n * preferring `AGENT` when both are non-empty. Empty is treated as unset for\n * both. The value is passed through rather than categorized so that new\n * names are propagated without the need to update the list of known agents.\n */\nfunction agentEnvFallback(): string {\n let v = process.env[AGENT_ENV_VAR];\n if (v === undefined || v === '') {\n v = process.env[AI_AGENT_ENV_VAR];\n }\n if (v === undefined || v === '') {\n return '';\n }\n // slice is a no-op when the value is already within the cap.\n return sanitize(v).slice(0, MAX_AGENT_FALLBACK_LEN);\n}\n\n/**\n * Checks environment variables for known AI agents and returns the\n * detected product name.\n *\n * Explicit product-specific env vars always take precedence over the\n * generic `AGENT` and `AI_AGENT` env vars, so that an explicit signal\n * (e.g. `CLAUDECODE=1`) always wins over a conflicting `AGENT=<name>`\n * value.\n *\n * Returns:\n *\n * - The product name when exactly one known env var is set.\n * - `\"multiple\"` when multiple known env vars are set. Agent env vars\n * can be stacked when one agent invokes another as a subagent (e.g.\n * Claude Code spawning a Cursor CLI subprocess), so the child process\n * inherits env vars from multiple layers.\n * - A sanitized, length-capped value from `AGENT` or `AI_AGENT` when no\n * known env var is set (see {@link agentEnvFallback}).\n * - `\"\"` when nothing is set.\n */\nexport function lookupAgentProvider(): string {\n const matches: string[] = [];\n for (const a of KNOWN_AGENTS) {\n if (a.envVar in process.env) {\n matches.push(a.product);\n }\n }\n if (matches.length === 1) {\n return matches[0];\n }\n if (matches.length > 1) {\n return 'multiple';\n }\n return agentEnvFallback();\n}\n\nlet cached: string | undefined;\n\n/**\n * Returns the detected AI agent name, cached for the process lifetime.\n *\n * Returns one of:\n *\n * - The known product name when exactly one agent is detected via\n * explicit env matchers.\n * - `\"multiple\"` when multiple explicit matchers fire for different\n * agents (typically nested agents, e.g. Cursor CLI running as a\n * Claude Code subagent).\n * - A sanitized, length-capped value from `AGENT` or `AI_AGENT` when no\n * explicit matcher fired (see {@link agentEnvFallback}).\n * - `\"\"` when no agent is detected.\n */\nexport function agentProvider(): string {\n cached ??= lookupAgentProvider();\n return cached;\n}\n\n/**\n * Clears the cached agent detection result so that the next call to\n * {@link agentProvider} re-evaluates the environment. Exported for\n * testing only.\n */\nexport function clearAgentCache(): void {\n cached = undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,MAAM,gBAAgB;AAKtB,MAAM,mBAAmB;AAKzB,MAAM,yBAAyB;AAK/B,MAAM,eAAsC;CAE1C;EAAC,QAAQ;EAAyB,SAAS;EAAM;CACjD;EAAC,QAAQ;EAAqB,SAAS;EAAc;CACrD;EAAC,QAAQ;EAAiB,SAAS;EAAU;CAC7C;EAAC,QAAQ;EAAc,SAAS;EAAc;CAC9C;EAAC,QAAQ;EAAgB,SAAS;EAAQ;CAC1C;EAAC,QAAQ;EAAY,SAAS;EAAQ;CACtC;EAAC,QAAQ;EAAe,SAAS;EAAc;CAC/C;EAAC,QAAQ;EAAgB,SAAS;EAAS;CAC3C;EAAC,QAAQ;EAAc,SAAS;EAAa;CAG7C;EAAC,QAAQ;EAAkB,SAAS;EAAQ;CAC5C;EAAC,QAAQ;EAAQ,SAAS;EAAO;CACjC;EAAC,QAAQ;EAAkB,SAAS;EAAW;CAC/C;EAAC,QAAQ;EAAY,SAAS;EAAW;CAGzC;EAAC,QAAQ;EAAgB,SAAS;EAAe;CACjD;EAAC,QAAQ;EAAkB,SAAS;EAAW;CAChD;;;;;;;AAQD,SAAS,mBAA2B;CAClC,IAAI,IAAI,QAAQ,IAAI;AACpB,KAAI,MAAM,UAAa,MAAM,GAC3B,KAAI,QAAQ,IAAI;AAElB,KAAI,MAAM,UAAa,MAAM,GAC3B,QAAO;AAGT,QAAO,SAAS,EAAE,CAAC,MAAM,GAAG,uBAAuB;;;;;;;;;;;;;;;;;;;;;;AAuBrD,SAAgB,sBAA8B;CAC5C,MAAM,UAAoB,EAAE;AAC5B,MAAK,MAAM,KAAK,aACd,KAAI,EAAE,UAAU,QAAQ,IACtB,SAAQ,KAAK,EAAE,QAAQ;AAG3B,KAAI,QAAQ,WAAW,EACrB,QAAO,QAAQ;AAEjB,KAAI,QAAQ,SAAS,EACnB,QAAO;AAET,QAAO,kBAAkB;;AAG3B,IAAI;;;;;;;;;;;;;;;AAgBJ,SAAgB,gBAAwB;AACtC,YAAW,qBAAqB;AAChC,QAAO;;;;;;;AAQT,SAAgB,kBAAwB;AACtC,UAAS"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
import { ClientInfo } from './clientinfo';
|
|
8
|
-
export declare const MODULE_NAME = "sdk-js-core";
|
|
9
|
-
export declare const VERSION: string;
|
|
1
|
+
import { ClientInfo } from "./clientinfo.js";
|
|
2
|
+
|
|
3
|
+
//#region src/clientinfo/base.d.ts
|
|
4
|
+
declare const MODULE_NAME = "sdk-js-core";
|
|
5
|
+
declare const VERSION: string;
|
|
10
6
|
/**
|
|
11
7
|
* Sets the product name and version globally. The version must be a
|
|
12
8
|
* valid semver string.
|
|
@@ -14,7 +10,7 @@ export declare const VERSION: string;
|
|
|
14
10
|
* Must be called before any client is created. Not safe for concurrent
|
|
15
11
|
* use.
|
|
16
12
|
*/
|
|
17
|
-
|
|
13
|
+
declare function setProduct(name: string, version: string): void;
|
|
18
14
|
/**
|
|
19
15
|
* Adds a partner identifier globally. Partner attribution is a
|
|
20
16
|
* first-class concept used for support ticket routing.
|
|
@@ -22,7 +18,7 @@ export declare function setProduct(name: string, version: string): void;
|
|
|
22
18
|
* Must be called before any client is created. Not safe for concurrent
|
|
23
19
|
* use.
|
|
24
20
|
*/
|
|
25
|
-
|
|
21
|
+
declare function setPartner(partner: string): void;
|
|
26
22
|
/**
|
|
27
23
|
* Adds a global key/value segment that will be included in every
|
|
28
24
|
* {@link createDefault} call. Same key with different values is allowed
|
|
@@ -32,8 +28,10 @@ export declare function setPartner(partner: string): void;
|
|
|
32
28
|
* Must be called before any client is created. Not safe for concurrent
|
|
33
29
|
* use.
|
|
34
30
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
declare function addToDefault(key: string, value: string): void;
|
|
32
|
+
declare function getBase(): ClientInfo;
|
|
33
|
+
declare function resetBase(): void;
|
|
34
|
+
declare function baseToString(): string;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { MODULE_NAME, VERSION, addToDefault, baseToString, getBase, resetBase, setPartner, setProduct };
|
|
39
37
|
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","
|
|
1
|
+
{"version":3,"file":"base.d.ts","names":[],"sources":["../../src/clientinfo/base.ts"],"mappings":";;;cAUa,WAAA;AAAA,cACA,OAAA;;;;;AAab;;;iBAAgB,UAAA,CAAW,IAAA,UAAc,OAAA;;AAiBzC;;;;;AAaA;iBAbgB,UAAA,CAAW,OAAA;;;;AAkB3B;;;;;AAKA;iBAVgB,YAAA,CAAa,GAAA,UAAa,KAAA;AAAA,iBAK1B,OAAA,CAAA,GAAW,UAAA;AAAA,iBAKX,SAAA,CAAA;AAAA,iBAMA,YAAA,CAAA"}
|
package/dist/clientinfo/base.js
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
+
import { ClientInfo, ClientInfoError, isSemVer } from "./clientinfo.js";
|
|
2
|
+
import { version } from "../package.js";
|
|
3
|
+
|
|
4
|
+
//#region src/clientinfo/base.ts
|
|
1
5
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export const MODULE_NAME = 'sdk-js-core';
|
|
10
|
-
export const VERSION = pkgJson.version;
|
|
11
|
-
// Holds segments added via addToDefault, setProduct, and setPartner.
|
|
12
|
-
// createDefault returns a copy of this with env detection appended.
|
|
6
|
+
* Shared state management for {@link ClientInfo} defaults. This module
|
|
7
|
+
* is browser-safe and contains no Node.js-specific APIs.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
const MODULE_NAME = "sdk-js-core";
|
|
12
|
+
const VERSION = version;
|
|
13
13
|
let base = ClientInfo.EMPTY;
|
|
14
14
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
addToDefault(name, version);
|
|
15
|
+
* Sets the product name and version globally. The version must be a
|
|
16
|
+
* valid semver string.
|
|
17
|
+
*
|
|
18
|
+
* Must be called before any client is created. Not safe for concurrent
|
|
19
|
+
* use.
|
|
20
|
+
*/
|
|
21
|
+
function setProduct(name, version) {
|
|
22
|
+
if (!isSemVer(version)) throw new ClientInfoError("INVALID_VERSION", `Invalid version: ${version}.`);
|
|
23
|
+
addToDefault(name, version);
|
|
26
24
|
}
|
|
27
25
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
* Adds a partner identifier globally. Partner attribution is a
|
|
27
|
+
* first-class concept used for support ticket routing.
|
|
28
|
+
*
|
|
29
|
+
* Must be called before any client is created. Not safe for concurrent
|
|
30
|
+
* use.
|
|
31
|
+
*/
|
|
32
|
+
function setPartner(partner) {
|
|
33
|
+
addToDefault("partner", partner);
|
|
36
34
|
}
|
|
37
35
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
* Adds a global key/value segment that will be included in every
|
|
37
|
+
* {@link createDefault} call. Same key with different values is allowed
|
|
38
|
+
* (e.g., multiple partners). Exact key+value duplicates are silently
|
|
39
|
+
* ignored.
|
|
40
|
+
*
|
|
41
|
+
* Must be called before any client is created. Not safe for concurrent
|
|
42
|
+
* use.
|
|
43
|
+
*/
|
|
44
|
+
function addToDefault(key, value) {
|
|
45
|
+
base = base.with({
|
|
46
|
+
key,
|
|
47
|
+
value
|
|
48
|
+
});
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return base;
|
|
50
|
+
function getBase() {
|
|
51
|
+
return base;
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
base = ClientInfo.EMPTY;
|
|
53
|
+
function resetBase() {
|
|
54
|
+
base = ClientInfo.EMPTY;
|
|
56
55
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
export function baseToString() {
|
|
60
|
-
return base.toString();
|
|
56
|
+
function baseToString() {
|
|
57
|
+
return base.toString();
|
|
61
58
|
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
export { MODULE_NAME, VERSION, addToDefault, baseToString, getBase, resetBase, setPartner, setProduct };
|
|
62
62
|
//# sourceMappingURL=base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","
|
|
1
|
+
{"version":3,"file":"base.js","names":["pkgJson.version"],"sources":["../../src/clientinfo/base.ts"],"sourcesContent":["/**\n * Shared state management for {@link ClientInfo} defaults. This module\n * is browser-safe and contains no Node.js-specific APIs.\n *\n * @module\n */\n\nimport {ClientInfo, ClientInfoError, isSemVer} from './clientinfo';\nimport pkgJson from '../../package.json' with {type: 'json'};\n\nexport const MODULE_NAME = 'sdk-js-core';\nexport const VERSION: string = pkgJson.version;\n\n// Holds segments added via addToDefault, setProduct, and setPartner.\n// createDefault returns a copy of this with env detection appended.\nlet base = ClientInfo.EMPTY;\n\n/**\n * Sets the product name and version globally. The version must be a\n * valid semver string.\n *\n * Must be called before any client is created. Not safe for concurrent\n * use.\n */\nexport function setProduct(name: string, version: string): void {\n if (!isSemVer(version)) {\n throw new ClientInfoError(\n 'INVALID_VERSION',\n `Invalid version: ${version}.`\n );\n }\n addToDefault(name, version);\n}\n\n/**\n * Adds a partner identifier globally. Partner attribution is a\n * first-class concept used for support ticket routing.\n *\n * Must be called before any client is created. Not safe for concurrent\n * use.\n */\nexport function setPartner(partner: string): void {\n addToDefault('partner', partner);\n}\n\n/**\n * Adds a global key/value segment that will be included in every\n * {@link createDefault} call. Same key with different values is allowed\n * (e.g., multiple partners). Exact key+value duplicates are silently\n * ignored.\n *\n * Must be called before any client is created. Not safe for concurrent\n * use.\n */\nexport function addToDefault(key: string, value: string): void {\n base = base.with({key, value});\n}\n\n// Returns the base ClientInfo for use in createDefault.\nexport function getBase(): ClientInfo {\n return base;\n}\n\n// Resets the base segments. Exported for testing only.\nexport function resetBase(): void {\n base = ClientInfo.EMPTY;\n}\n\n// Returns the base segments as a formatted string. Exported for\n// testing only.\nexport function baseToString(): string {\n return base.toString();\n}\n"],"mappings":";;;;;;;;;;AAUA,MAAa,cAAc;AAC3B,MAAa,UAAkBA;AAI/B,IAAI,OAAO,WAAW;;;;;;;;AAStB,SAAgB,WAAW,MAAc,SAAuB;AAC9D,KAAI,CAAC,SAAS,QAAQ,CACpB,OAAM,IAAI,gBACR,mBACA,oBAAoB,QAAQ,GAC7B;AAEH,cAAa,MAAM,QAAQ;;;;;;;;;AAU7B,SAAgB,WAAW,SAAuB;AAChD,cAAa,WAAW,QAAQ;;;;;;;;;;;AAYlC,SAAgB,aAAa,KAAa,OAAqB;AAC7D,QAAO,KAAK,KAAK;EAAC;EAAK;EAAM,CAAC;;AAIhC,SAAgB,UAAsB;AACpC,QAAO;;AAIT,SAAgB,YAAkB;AAChC,QAAO,WAAW;;AAKpB,SAAgB,eAAuB;AACrC,QAAO,KAAK,UAAU"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/clientinfo/clientinfo.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Collects information about the client and its environment into an
|
|
3
4
|
* immutable {@link ClientInfo} value.
|
|
@@ -7,55 +8,56 @@
|
|
|
7
8
|
*
|
|
8
9
|
* @module
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
type ClientInfoErrorCode = 'INVALID_KEY' | 'INVALID_VALUE' | 'INVALID_VERSION';
|
|
12
|
+
declare class ClientInfoError extends Error {
|
|
13
|
+
readonly code: ClientInfoErrorCode;
|
|
14
|
+
constructor(code: ClientInfoErrorCode, message: string);
|
|
14
15
|
}
|
|
15
16
|
interface Segment {
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
readonly key: string;
|
|
18
|
+
readonly value: string;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
declare function isSemVer(s: string): boolean;
|
|
21
|
+
declare function isValidSegment(s: string): boolean;
|
|
21
22
|
/**
|
|
22
23
|
* Replaces characters that are not valid in segment values with
|
|
23
24
|
* hyphens. Used for environment-sourced values (runtime version,
|
|
24
25
|
* upstream) that we do not control and cannot reject.
|
|
25
26
|
*/
|
|
26
|
-
|
|
27
|
+
declare function sanitize(s: string): string;
|
|
27
28
|
/**
|
|
28
29
|
* ClientInfo is an immutable, ordered list of key/value segments. Use
|
|
29
30
|
* {@link ClientInfo.with} to derive new values with additional segments.
|
|
30
31
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
32
|
+
declare class ClientInfo {
|
|
33
|
+
static readonly EMPTY: ClientInfo;
|
|
34
|
+
readonly segments: readonly Segment[];
|
|
35
|
+
private constructor();
|
|
36
|
+
/**
|
|
37
|
+
* Returns a new {@link ClientInfo} with the given items appended. Accepts
|
|
38
|
+
* either individual key/value pairs or another {@link ClientInfo} whose
|
|
39
|
+
* segments are merged in order. The original is not modified; mixing the
|
|
40
|
+
* two forms in a single call is supported.
|
|
41
|
+
*
|
|
42
|
+
* Keys and values on pair arguments must contain only alphanumeric
|
|
43
|
+
* characters plus `_`, `.`, `+`, or `-`. Exact key+value duplicates are
|
|
44
|
+
* silently ignored. On error, an exception is thrown (all-or-nothing).
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* base.with({key: 'partner', value: 'acme'});
|
|
49
|
+
* base.with(pkgClientInfo);
|
|
50
|
+
* base.with(pkgClientInfo, {key: 'sdk-feature', value: 'pagination'});
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
with(...items: (ClientInfo | Segment)[]): ClientInfo;
|
|
54
|
+
/**
|
|
55
|
+
* Returns a string representation of the client info suitable for
|
|
56
|
+
* inclusion in HTTP headers. Key/value pairs are formatted as
|
|
57
|
+
* "key/value" and joined by spaces in the order they were inserted.
|
|
58
|
+
*/
|
|
59
|
+
toString(): string;
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
+
//#endregion
|
|
62
|
+
export { ClientInfo, ClientInfoError, ClientInfoErrorCode, isSemVer, isValidSegment, sanitize };
|
|
61
63
|
//# sourceMappingURL=clientinfo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientinfo.d.ts","
|
|
1
|
+
{"version":3,"file":"clientinfo.d.ts","names":[],"sources":["../../src/clientinfo/clientinfo.ts"],"mappings":";;AAUA;;;;;AAKA;;;KALY,mBAAA;AAAA,cAKC,eAAA,SAAwB,KAAA;EAAA,SAC1B,IAAA,EAAM,mBAAA;cAEH,IAAA,EAAM,mBAAA,EAAqB,OAAA;AAAA;AAAA,UAO/B,OAAA;EAAA,SACC,GAAA;EAAA,SACA,KAAA;AAAA;AAAA,iBAeK,QAAA,CAAS,CAAA;AAAA,iBAIT,cAAA,CAAe,CAAA;;;;AAvB9B;;iBAgCe,QAAA,CAAS,CAAA;;;AAbzB;;cAqBa,UAAA;EAAA,gBACK,KAAA,EAAK,UAAA;EAAA,SAEZ,QAAA,WAAmB,OAAA;EAAA,QAErB,WAAA,CAAA;EAtBqB;;;;AAS9B;;;;;AAQA;;;;;;;;EA4BE,IAAA,CAAA,GAAQ,KAAA,GAAQ,UAAA,GAAa,OAAA,MAAa,UAAA;EAAU;;;;;EAkCpD,QAAA,CAAA;AAAA"}
|