@databricks/sdk-auth 0.33.0 → 0.35.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/auth.d.ts +42 -40
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +38 -42
- package/dist/auth.js.map +1 -1
- package/dist/credentials/default/chain.d.ts +26 -22
- package/dist/credentials/default/chain.d.ts.map +1 -1
- package/dist/credentials/default/chain.js +74 -84
- package/dist/credentials/default/chain.js.map +1 -1
- package/dist/credentials/default/default-credentials.d.ts +12 -9
- package/dist/credentials/default/default-credentials.d.ts.map +1 -1
- package/dist/credentials/default/default-credentials.js +29 -20
- package/dist/credentials/default/default-credentials.js.map +1 -1
- package/dist/credentials/default/errors.d.ts +7 -4
- package/dist/credentials/default/errors.d.ts.map +1 -1
- package/dist/credentials/default/errors.js +17 -13
- package/dist/credentials/default/errors.js.map +1 -1
- package/dist/credentials/default/u2m-strategy.d.ts +6 -2
- package/dist/credentials/default/u2m-strategy.d.ts.map +1 -1
- package/dist/credentials/default/u2m-strategy.js +21 -20
- package/dist/credentials/default/u2m-strategy.js.map +1 -1
- package/dist/credentials/errors.d.ts +15 -12
- package/dist/credentials/errors.d.ts.map +1 -1
- package/dist/credentials/errors.js +40 -41
- package/dist/credentials/errors.js.map +1 -1
- package/dist/credentials/host-metadata.d.ts +22 -19
- package/dist/credentials/host-metadata.d.ts.map +1 -1
- package/dist/credentials/host-metadata.js +88 -109
- package/dist/credentials/host-metadata.js.map +1 -1
- package/dist/credentials/index.browser.d.ts +4 -11
- package/dist/credentials/index.browser.js +5 -9
- package/dist/credentials/index.d.ts +7 -14
- package/dist/credentials/index.js +8 -10
- package/dist/credentials/m2m.d.ts +29 -28
- package/dist/credentials/m2m.d.ts.map +1 -1
- package/dist/credentials/m2m.js +66 -81
- package/dist/credentials/m2m.js.map +1 -1
- package/dist/credentials/pat.d.ts +6 -5
- package/dist/credentials/pat.d.ts.map +1 -1
- package/dist/credentials/pat.js +33 -37
- package/dist/credentials/pat.js.map +1 -1
- package/dist/credentials/u2m.d.ts +17 -20
- package/dist/credentials/u2m.d.ts.map +1 -1
- package/dist/credentials/u2m.js +107 -135
- package/dist/credentials/u2m.js.map +1 -1
- package/dist/index.d.ts +6 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -7
- package/dist/index.js.map +1 -1
- package/dist/oidc/env.d.ts +6 -2
- package/dist/oidc/env.d.ts.map +1 -1
- package/dist/oidc/env.js +19 -16
- package/dist/oidc/env.js.map +1 -1
- package/dist/oidc/file.d.ts +6 -2
- package/dist/oidc/file.d.ts.map +1 -1
- package/dist/oidc/file.js +23 -25
- package/dist/oidc/file.js.map +1 -1
- package/dist/oidc/index.browser.d.ts +3 -13
- package/dist/oidc/index.browser.js +4 -11
- package/dist/oidc/index.d.ts +5 -14
- package/dist/oidc/index.js +6 -12
- package/dist/oidc/oidc.d.ts +8 -5
- package/dist/oidc/oidc.d.ts.map +1 -1
- package/dist/oidc/oidc.js +11 -7
- package/dist/oidc/oidc.js.map +1 -1
- package/dist/oidc/tokensource.d.ts +41 -41
- package/dist/oidc/tokensource.d.ts.map +1 -1
- package/dist/oidc/tokensource.js +47 -52
- package/dist/oidc/tokensource.js.map +1 -1
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/package.json +3 -3
- package/dist/credentials/index.browser.d.ts.map +0 -1
- package/dist/credentials/index.browser.js.map +0 -1
- package/dist/credentials/index.d.ts.map +0 -1
- package/dist/credentials/index.js.map +0 -1
- package/dist/oidc/index.browser.d.ts.map +0 -1
- package/dist/oidc/index.browser.js.map +0 -1
- package/dist/oidc/index.d.ts.map +0 -1
- package/dist/oidc/index.js.map +0 -1
package/dist/credentials/u2m.js
CHANGED
|
@@ -1,157 +1,129 @@
|
|
|
1
|
+
import { newTokenCredentials, tokenProviderFn } from "../auth.js";
|
|
2
|
+
import { U2mCredentialsError } from "./errors.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import { stat } from "node:fs/promises";
|
|
6
|
+
import { join, sep } from "node:path";
|
|
7
|
+
import { env, platform } from "node:process";
|
|
8
|
+
import { promisify } from "node:util";
|
|
9
|
+
|
|
10
|
+
//#region src/credentials/u2m.ts
|
|
1
11
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { execFile } from 'node:child_process';
|
|
9
|
-
import { stat } from 'node:fs/promises';
|
|
10
|
-
import { join, sep } from 'node:path';
|
|
11
|
-
import { env, platform } from 'node:process';
|
|
12
|
-
import { promisify } from 'node:util';
|
|
13
|
-
import { z } from 'zod';
|
|
14
|
-
import { newTokenCredentials, tokenProviderFn } from '../auth';
|
|
15
|
-
import { U2mCredentialsError } from './errors';
|
|
12
|
+
* Databricks CLI ("U2M") credentials. Obtains access tokens by shelling out
|
|
13
|
+
* to the `databricks` CLI binary (>= 0.100.0). The CLI must have been logged
|
|
14
|
+
* in ahead of time via `databricks auth login`.
|
|
15
|
+
*
|
|
16
|
+
* Node.js only. Not exported from the browser entry point.
|
|
17
|
+
*/
|
|
16
18
|
const execFileAsync = promisify(execFile);
|
|
17
19
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
* Distinguishes the modern Go-based Databricks CLI (>= 0.100.0) from the
|
|
21
|
+
* legacy Python CLI by minimum file size.
|
|
22
|
+
*/
|
|
21
23
|
const DATABRICKS_CLI_MIN_SIZE = 1024 * 1024;
|
|
22
24
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
const provider = tokenProviderFn(() => fetchCliToken(options));
|
|
35
|
-
return newTokenCredentials('databricks-cli', provider);
|
|
25
|
+
* Creates a TokenCredentials that obtains Databricks access tokens by
|
|
26
|
+
* shelling out to the Databricks CLI.
|
|
27
|
+
*
|
|
28
|
+
* @param options - CLI profile (required) and optional CLI binary path.
|
|
29
|
+
* @throws U2mCredentialsError when `profile` is empty, or when the CLI cannot
|
|
30
|
+
* be located, is out of date, or fails to return a usable token.
|
|
31
|
+
*/
|
|
32
|
+
function newU2mCredentials(options) {
|
|
33
|
+
if (options.profile === "") throw new U2mCredentialsError("PROFILE_REQUIRED", "profile is required");
|
|
34
|
+
return newTokenCredentials("databricks-cli", tokenProviderFn(() => fetchCliToken(options)));
|
|
36
35
|
}
|
|
37
36
|
async function fetchCliToken(options) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
]);
|
|
37
|
+
return execCliCommand([
|
|
38
|
+
await findDatabricksCli(options.cliPath),
|
|
39
|
+
"auth",
|
|
40
|
+
"token",
|
|
41
|
+
"--profile",
|
|
42
|
+
options.profile
|
|
43
|
+
]);
|
|
46
44
|
}
|
|
47
45
|
const cliTokenResponseSchema = z.object({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
access_token: z.string().min(1),
|
|
47
|
+
token_type: z.string().optional(),
|
|
48
|
+
expiry: z.string()
|
|
51
49
|
});
|
|
52
50
|
async function execCliCommand(args) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (Number.isNaN(expiry.getTime())) {
|
|
77
|
-
throw new U2mCredentialsError('INVALID_RESPONSE', `cannot parse token expiry: ${parsed.expiry}`);
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
value: parsed.access_token,
|
|
81
|
-
...(parsed.token_type !== undefined && { type: parsed.token_type }),
|
|
82
|
-
expiry,
|
|
83
|
-
};
|
|
51
|
+
const [cliPath, ...rest] = args;
|
|
52
|
+
let stdout;
|
|
53
|
+
try {
|
|
54
|
+
stdout = (await execFileAsync(cliPath, rest)).stdout;
|
|
55
|
+
} catch (e) {
|
|
56
|
+
throw new U2mCredentialsError("TOKEN_FETCH_FAILED", `cannot get access token: ${cliErrorMessage(e)}`);
|
|
57
|
+
}
|
|
58
|
+
let raw;
|
|
59
|
+
try {
|
|
60
|
+
raw = JSON.parse(stdout);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
throw new U2mCredentialsError("INVALID_RESPONSE", `cannot parse CLI response: ${e instanceof Error ? e.message : String(e)}`);
|
|
63
|
+
}
|
|
64
|
+
const result = cliTokenResponseSchema.safeParse(raw);
|
|
65
|
+
if (!result.success) throw new U2mCredentialsError("INVALID_RESPONSE", `invalid CLI response: ${result.error.message}`);
|
|
66
|
+
const parsed = result.data;
|
|
67
|
+
const expiry = new Date(parsed.expiry);
|
|
68
|
+
if (Number.isNaN(expiry.getTime())) throw new U2mCredentialsError("INVALID_RESPONSE", `cannot parse token expiry: ${parsed.expiry}`);
|
|
69
|
+
return {
|
|
70
|
+
value: parsed.access_token,
|
|
71
|
+
...parsed.token_type !== void 0 && { type: parsed.token_type },
|
|
72
|
+
expiry
|
|
73
|
+
};
|
|
84
74
|
}
|
|
85
75
|
function cliErrorMessage(e) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
return String(e);
|
|
76
|
+
if (typeof e === "object" && e !== null) {
|
|
77
|
+
const err = e;
|
|
78
|
+
if (err.stderr !== void 0) return err.stderr.toString().trim();
|
|
79
|
+
return err.message;
|
|
80
|
+
}
|
|
81
|
+
return String(e);
|
|
94
82
|
}
|
|
95
83
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
84
|
+
* Locates the `databricks` CLI binary, either at `cliPath` (if provided) or
|
|
85
|
+
* by searching `PATH`. Validates that the binary is the modern Go CLI and
|
|
86
|
+
* not the legacy Python one, via a minimum-size check.
|
|
87
|
+
*/
|
|
100
88
|
async function findDatabricksCli(cliPath) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (platform === 'win32') {
|
|
112
|
-
return findInPath('databricks.exe');
|
|
113
|
-
}
|
|
114
|
-
throw e;
|
|
115
|
-
}
|
|
89
|
+
if (cliPath !== void 0) {
|
|
90
|
+
if (cliPath.includes(sep) || cliPath.includes("/")) return validateCliPath(cliPath);
|
|
91
|
+
return findInPath(cliPath);
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
return await findInPath("databricks");
|
|
95
|
+
} catch (e) {
|
|
96
|
+
if (platform === "win32") return findInPath("databricks.exe");
|
|
97
|
+
throw e;
|
|
98
|
+
}
|
|
116
99
|
}
|
|
117
100
|
async function findInPath(name) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
catch (e) {
|
|
132
|
-
if (e instanceof U2mCredentialsError &&
|
|
133
|
-
e.code === 'LEGACY_CLI_DETECTED') {
|
|
134
|
-
legacyError = e;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
throw (legacyError ??
|
|
139
|
-
new U2mCredentialsError('CLI_NOT_FOUND', 'databricks CLI not found'));
|
|
101
|
+
const pathEnv = env.PATH ?? "";
|
|
102
|
+
if (pathEnv === "") throw new U2mCredentialsError("CLI_NOT_FOUND", "databricks CLI not found");
|
|
103
|
+
const delim = platform === "win32" ? ";" : ":";
|
|
104
|
+
let legacyError;
|
|
105
|
+
for (const dir of pathEnv.split(delim)) {
|
|
106
|
+
if (dir === "") continue;
|
|
107
|
+
try {
|
|
108
|
+
return await validateCliPath(join(dir, name));
|
|
109
|
+
} catch (e) {
|
|
110
|
+
if (e instanceof U2mCredentialsError && e.code === "LEGACY_CLI_DETECTED") legacyError = e;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
throw legacyError ?? new U2mCredentialsError("CLI_NOT_FOUND", "databricks CLI not found");
|
|
140
114
|
}
|
|
141
115
|
async function validateCliPath(path) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
if (info.size < DATABRICKS_CLI_MIN_SIZE) {
|
|
153
|
-
throw new U2mCredentialsError('LEGACY_CLI_DETECTED', 'legacy databricks CLI detected; upgrade to >= 0.100.0');
|
|
154
|
-
}
|
|
155
|
-
return path;
|
|
116
|
+
let info;
|
|
117
|
+
try {
|
|
118
|
+
info = await stat(path);
|
|
119
|
+
} catch {
|
|
120
|
+
throw new U2mCredentialsError("CLI_NOT_FOUND", "databricks CLI not found");
|
|
121
|
+
}
|
|
122
|
+
if (info.isDirectory()) throw new U2mCredentialsError("CLI_NOT_FOUND", "databricks CLI not found");
|
|
123
|
+
if (info.size < DATABRICKS_CLI_MIN_SIZE) throw new U2mCredentialsError("LEGACY_CLI_DETECTED", "legacy databricks CLI detected; upgrade to >= 0.100.0");
|
|
124
|
+
return path;
|
|
156
125
|
}
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
export { newU2mCredentials };
|
|
157
129
|
//# sourceMappingURL=u2m.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"u2m.js","
|
|
1
|
+
{"version":3,"file":"u2m.js","names":[],"sources":["../../src/credentials/u2m.ts"],"sourcesContent":["/**\n * Databricks CLI (\"U2M\") credentials. Obtains access tokens by shelling out\n * to the `databricks` CLI binary (>= 0.100.0). The CLI must have been logged\n * in ahead of time via `databricks auth login`.\n *\n * Node.js only. Not exported from the browser entry point.\n */\n\nimport {execFile} from 'node:child_process';\nimport {stat} from 'node:fs/promises';\nimport {join, sep} from 'node:path';\nimport {env, platform} from 'node:process';\nimport {promisify} from 'node:util';\n\nimport {z} from 'zod';\n\nimport type {Token, TokenCredentials} from '../auth';\nimport {newTokenCredentials, tokenProviderFn} from '../auth';\n\nimport {U2mCredentialsError} from './errors';\n\nconst execFileAsync = promisify(execFile);\n\n/**\n * Distinguishes the modern Go-based Databricks CLI (>= 0.100.0) from the\n * legacy Python CLI by minimum file size.\n */\nconst DATABRICKS_CLI_MIN_SIZE = 1024 * 1024;\n\n/** Options for the Databricks CLI auth strategy. */\nexport interface U2mCredentialsOptions {\n /**\n * The Databricks CLI profile name, as configured via `databricks auth\n * login`.\n */\n profile: string;\n\n /**\n * Path to the `databricks` CLI binary. If omitted, the binary is searched\n * for in `PATH`.\n */\n cliPath?: string;\n}\n\n/**\n * Creates a TokenCredentials that obtains Databricks access tokens by\n * shelling out to the Databricks CLI.\n *\n * @param options - CLI profile (required) and optional CLI binary path.\n * @throws U2mCredentialsError when `profile` is empty, or when the CLI cannot\n * be located, is out of date, or fails to return a usable token.\n */\nexport function newU2mCredentials(\n options: U2mCredentialsOptions\n): TokenCredentials {\n if (options.profile === '') {\n throw new U2mCredentialsError('PROFILE_REQUIRED', 'profile is required');\n }\n const provider = tokenProviderFn(() => fetchCliToken(options));\n return newTokenCredentials('databricks-cli', provider);\n}\n\nasync function fetchCliToken(options: U2mCredentialsOptions): Promise<Token> {\n const cliPath = await findDatabricksCli(options.cliPath);\n return execCliCommand([\n cliPath,\n 'auth',\n 'token',\n '--profile',\n options.profile,\n ]);\n}\n\nconst cliTokenResponseSchema = z.object({\n access_token: z.string().min(1),\n token_type: z.string().optional(),\n expiry: z.string(),\n});\n\nasync function execCliCommand(args: string[]): Promise<Token> {\n const [cliPath, ...rest] = args;\n\n let stdout: string;\n try {\n const result = await execFileAsync(cliPath, rest);\n stdout = result.stdout;\n } catch (e) {\n throw new U2mCredentialsError(\n 'TOKEN_FETCH_FAILED',\n `cannot get access token: ${cliErrorMessage(e)}`\n );\n }\n\n let raw: unknown;\n try {\n raw = JSON.parse(stdout);\n } catch (e) {\n const cause = e instanceof Error ? e.message : String(e);\n throw new U2mCredentialsError(\n 'INVALID_RESPONSE',\n `cannot parse CLI response: ${cause}`\n );\n }\n\n const result = cliTokenResponseSchema.safeParse(raw);\n if (!result.success) {\n throw new U2mCredentialsError(\n 'INVALID_RESPONSE',\n `invalid CLI response: ${result.error.message}`\n );\n }\n const parsed = result.data;\n\n const expiry = new Date(parsed.expiry);\n if (Number.isNaN(expiry.getTime())) {\n throw new U2mCredentialsError(\n 'INVALID_RESPONSE',\n `cannot parse token expiry: ${parsed.expiry}`\n );\n }\n\n return {\n value: parsed.access_token,\n ...(parsed.token_type !== undefined && {type: parsed.token_type}),\n expiry,\n };\n}\n\ninterface ExecFileError {\n stderr?: string | Buffer;\n message: string;\n}\n\nfunction cliErrorMessage(e: unknown): string {\n if (typeof e === 'object' && e !== null) {\n const err = e as ExecFileError;\n if (err.stderr !== undefined) {\n return err.stderr.toString().trim();\n }\n return err.message;\n }\n return String(e);\n}\n\n/**\n * Locates the `databricks` CLI binary, either at `cliPath` (if provided) or\n * by searching `PATH`. Validates that the binary is the modern Go CLI and\n * not the legacy Python one, via a minimum-size check.\n */\nasync function findDatabricksCli(cliPath?: string): Promise<string> {\n if (cliPath !== undefined) {\n if (cliPath.includes(sep) || cliPath.includes('/')) {\n return validateCliPath(cliPath);\n }\n return findInPath(cliPath);\n }\n try {\n return await findInPath('databricks');\n } catch (e) {\n if (platform === 'win32') {\n return findInPath('databricks.exe');\n }\n throw e;\n }\n}\n\nasync function findInPath(name: string): Promise<string> {\n const pathEnv = env.PATH ?? '';\n if (pathEnv === '') {\n throw new U2mCredentialsError('CLI_NOT_FOUND', 'databricks CLI not found');\n }\n const delim = platform === 'win32' ? ';' : ':';\n let legacyError: U2mCredentialsError | undefined;\n for (const dir of pathEnv.split(delim)) {\n if (dir === '') {\n continue;\n }\n try {\n return await validateCliPath(join(dir, name));\n } catch (e) {\n if (\n e instanceof U2mCredentialsError &&\n e.code === 'LEGACY_CLI_DETECTED'\n ) {\n legacyError = e;\n }\n }\n }\n throw (\n legacyError ??\n new U2mCredentialsError('CLI_NOT_FOUND', 'databricks CLI not found')\n );\n}\n\nasync function validateCliPath(path: string): Promise<string> {\n let info;\n try {\n info = await stat(path);\n } catch {\n throw new U2mCredentialsError('CLI_NOT_FOUND', 'databricks CLI not found');\n }\n if (info.isDirectory()) {\n throw new U2mCredentialsError('CLI_NOT_FOUND', 'databricks CLI not found');\n }\n if (info.size < DATABRICKS_CLI_MIN_SIZE) {\n throw new U2mCredentialsError(\n 'LEGACY_CLI_DETECTED',\n 'legacy databricks CLI detected; upgrade to >= 0.100.0'\n );\n }\n return path;\n}\n"],"mappings":"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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
|
-
export type { Header, Token, Credentials, TokenProvider, TokenCredentials, } from './auth';
|
|
7
|
-
export { newTokenCredentials, tokenProviderFn } from './auth';
|
|
1
|
+
import { Credentials, Header, Token, TokenCredentials, TokenProvider, newTokenCredentials, tokenProviderFn } from "./auth.js";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
8
4
|
/** Version of this auth library, sourced from package.json. */
|
|
9
|
-
|
|
5
|
+
declare const VERSION: string;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type Credentials, type Header, type Token, type TokenCredentials, type TokenProvider, VERSION, newTokenCredentials, tokenProviderFn };
|
|
10
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;cAkBa,OAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import { newTokenCredentials, tokenProviderFn } from "./auth.js";
|
|
2
|
+
import { version } from "./package.js";
|
|
3
|
+
|
|
4
|
+
//#region src/index.ts
|
|
1
5
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import pkgJson from '../package.json' with { type: 'json' };
|
|
7
|
-
export { newTokenCredentials, tokenProviderFn } from './auth';
|
|
6
|
+
* Databricks authentication library for JavaScript/TypeScript.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
8
10
|
/** Version of this auth library, sourced from package.json. */
|
|
9
|
-
|
|
11
|
+
const VERSION = version;
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { VERSION, newTokenCredentials, tokenProviderFn };
|
|
10
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","names":["pkgJson.version"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Databricks authentication library for JavaScript/TypeScript.\n *\n * @packageDocumentation\n */\n\nimport pkgJson from '../package.json' with {type: 'json'};\n\nexport type {\n Header,\n Token,\n Credentials,\n TokenProvider,\n TokenCredentials,\n} from './auth';\nexport {newTokenCredentials, tokenProviderFn} from './auth';\n\n/** Version of this auth library, sourced from package.json. */\nexport const VERSION: string = pkgJson.version;\n"],"mappings":";;;;;;;;;;AAkBA,MAAa,UAAkBA"}
|
package/dist/oidc/env.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { IdTokenProvider } from "./oidc.js";
|
|
2
|
+
|
|
3
|
+
//#region src/oidc/env.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* Returns an IdTokenProvider that reads the ID token from environment variable
|
|
4
6
|
* `name`.
|
|
@@ -6,5 +8,7 @@ import type { IdTokenProvider } from './oidc';
|
|
|
6
8
|
* Note that the IdTokenProvider does not cache the token and will read the
|
|
7
9
|
* token from environment variable `name` each time.
|
|
8
10
|
*/
|
|
9
|
-
|
|
11
|
+
declare function newEnvIdTokenProvider(name: string): IdTokenProvider;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { newEnvIdTokenProvider };
|
|
10
14
|
//# sourceMappingURL=env.d.ts.map
|
package/dist/oidc/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","
|
|
1
|
+
{"version":3,"file":"env.d.ts","names":[],"sources":["../../src/oidc/env.ts"],"mappings":";;;;;AAYA;;;;;iBAAgB,qBAAA,CAAsB,IAAA,WAAe,eAAA"}
|
package/dist/oidc/env.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { idTokenProviderFn } from "./oidc.js";
|
|
2
|
+
import { env } from "node:process";
|
|
3
|
+
|
|
4
|
+
//#region src/oidc/env.ts
|
|
3
5
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return Promise.resolve({ value: t });
|
|
17
|
-
});
|
|
6
|
+
* Returns an IdTokenProvider that reads the ID token from environment variable
|
|
7
|
+
* `name`.
|
|
8
|
+
*
|
|
9
|
+
* Note that the IdTokenProvider does not cache the token and will read the
|
|
10
|
+
* token from environment variable `name` each time.
|
|
11
|
+
*/
|
|
12
|
+
function newEnvIdTokenProvider(name) {
|
|
13
|
+
return idTokenProviderFn(() => {
|
|
14
|
+
const t = env[name];
|
|
15
|
+
if (t === void 0 || t === "") return Promise.reject(/* @__PURE__ */ new Error(`missing env var "${name}"`));
|
|
16
|
+
return Promise.resolve({ value: t });
|
|
17
|
+
});
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { newEnvIdTokenProvider };
|
|
19
22
|
//# sourceMappingURL=env.js.map
|
package/dist/oidc/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","
|
|
1
|
+
{"version":3,"file":"env.js","names":[],"sources":["../../src/oidc/env.ts"],"sourcesContent":["import {env} from 'node:process';\n\nimport type {IdTokenProvider} from './oidc';\nimport {idTokenProviderFn} from './oidc';\n\n/**\n * Returns an IdTokenProvider that reads the ID token from environment variable\n * `name`.\n *\n * Note that the IdTokenProvider does not cache the token and will read the\n * token from environment variable `name` each time.\n */\nexport function newEnvIdTokenProvider(name: string): IdTokenProvider {\n return idTokenProviderFn(() => {\n const t = env[name];\n if (t === undefined || t === '') {\n return Promise.reject(new Error(`missing env var \"${name}\"`));\n }\n return Promise.resolve({value: t});\n });\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,sBAAsB,MAA+B;AACnE,QAAO,wBAAwB;EAC7B,MAAM,IAAI,IAAI;AACd,MAAI,MAAM,UAAa,MAAM,GAC3B,QAAO,QAAQ,uBAAO,IAAI,MAAM,oBAAoB,KAAK,GAAG,CAAC;AAE/D,SAAO,QAAQ,QAAQ,EAAC,OAAO,GAAE,CAAC;GAClC"}
|
package/dist/oidc/file.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { IdTokenProvider } from "./oidc.js";
|
|
2
|
+
|
|
3
|
+
//#region src/oidc/file.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* Returns an IdTokenProvider that reads the ID token from a file. The file
|
|
4
6
|
* should contain a single line with the token.
|
|
5
7
|
*/
|
|
6
|
-
|
|
8
|
+
declare function newFileTokenProvider(path: string): IdTokenProvider;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { newFileTokenProvider };
|
|
7
11
|
//# sourceMappingURL=file.d.ts.map
|
package/dist/oidc/file.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","
|
|
1
|
+
{"version":3,"file":"file.d.ts","names":[],"sources":["../../src/oidc/file.ts"],"mappings":";;;;;AASA;;iBAAgB,oBAAA,CAAqB,IAAA,WAAe,eAAA"}
|
package/dist/oidc/file.js
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { idTokenProviderFn } from "./oidc.js";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
//#region src/oidc/file.ts
|
|
3
5
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
throw e;
|
|
21
|
-
}
|
|
22
|
-
if (content.length === 0) {
|
|
23
|
-
throw new Error(`file "${path}" is empty`);
|
|
24
|
-
}
|
|
25
|
-
return { value: content };
|
|
26
|
-
});
|
|
6
|
+
* Returns an IdTokenProvider that reads the ID token from a file. The file
|
|
7
|
+
* should contain a single line with the token.
|
|
8
|
+
*/
|
|
9
|
+
function newFileTokenProvider(path) {
|
|
10
|
+
return idTokenProviderFn(async () => {
|
|
11
|
+
if (path === "") throw new Error("missing path");
|
|
12
|
+
let content;
|
|
13
|
+
try {
|
|
14
|
+
content = await readFile(path, "utf-8");
|
|
15
|
+
} catch (e) {
|
|
16
|
+
if (e instanceof Error && "code" in e && e.code === "ENOENT") throw new Error(`file "${path}" does not exist`);
|
|
17
|
+
throw e;
|
|
18
|
+
}
|
|
19
|
+
if (content.length === 0) throw new Error(`file "${path}" is empty`);
|
|
20
|
+
return { value: content };
|
|
21
|
+
});
|
|
27
22
|
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { newFileTokenProvider };
|
|
28
26
|
//# sourceMappingURL=file.js.map
|
package/dist/oidc/file.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","
|
|
1
|
+
{"version":3,"file":"file.js","names":[],"sources":["../../src/oidc/file.ts"],"sourcesContent":["import {readFile} from 'node:fs/promises';\n\nimport type {IdTokenProvider} from './oidc';\nimport {idTokenProviderFn} from './oidc';\n\n/**\n * Returns an IdTokenProvider that reads the ID token from a file. The file\n * should contain a single line with the token.\n */\nexport function newFileTokenProvider(path: string): IdTokenProvider {\n return idTokenProviderFn(async () => {\n if (path === '') {\n throw new Error('missing path');\n }\n let content: string;\n try {\n content = await readFile(path, 'utf-8');\n } catch (e: unknown) {\n if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {\n throw new Error(`file \"${path}\" does not exist`);\n }\n throw e;\n }\n if (content.length === 0) {\n throw new Error(`file \"${path}\" is empty`);\n }\n return {value: content};\n });\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,qBAAqB,MAA+B;AAClE,QAAO,kBAAkB,YAAY;AACnC,MAAI,SAAS,GACX,OAAM,IAAI,MAAM,eAAe;EAEjC,IAAI;AACJ,MAAI;AACF,aAAU,MAAM,SAAS,MAAM,QAAQ;WAChC,GAAY;AACnB,OAAI,aAAa,SAAS,UAAU,KAAK,EAAE,SAAS,SAClD,OAAM,IAAI,MAAM,SAAS,KAAK,kBAAkB;AAElD,SAAM;;AAER,MAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MAAM,SAAS,KAAK,YAAY;AAE5C,SAAO,EAAC,OAAO,SAAQ;GACvB"}
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* This package is experimental and subject to change.
|
|
6
|
-
*
|
|
7
|
-
* @packageDocumentation
|
|
8
|
-
*/
|
|
9
|
-
export type { IdToken, IdTokenProvider } from './oidc';
|
|
10
|
-
export { idTokenProviderFn } from './oidc';
|
|
11
|
-
export type { DatabricksOidcTokenProviderConfig, OAuthAuthorizationServer, } from './tokensource';
|
|
12
|
-
export { newDatabricksOidcTokenProvider } from './tokensource';
|
|
13
|
-
//# sourceMappingURL=index.browser.d.ts.map
|
|
1
|
+
import { IdToken, IdTokenProvider, idTokenProviderFn } from "./oidc.js";
|
|
2
|
+
import { DatabricksOidcTokenProviderConfig, OAuthAuthorizationServer, newDatabricksOidcTokenProvider } from "./tokensource.js";
|
|
3
|
+
export { type DatabricksOidcTokenProviderConfig, type IdToken, type IdTokenProvider, type OAuthAuthorizationServer, idTokenProviderFn, newDatabricksOidcTokenProvider };
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* This package is experimental and subject to change.
|
|
6
|
-
*
|
|
7
|
-
* @packageDocumentation
|
|
8
|
-
*/
|
|
9
|
-
export { idTokenProviderFn } from './oidc';
|
|
10
|
-
export { newDatabricksOidcTokenProvider } from './tokensource';
|
|
11
|
-
//# sourceMappingURL=index.browser.js.map
|
|
1
|
+
import { idTokenProviderFn } from "./oidc.js";
|
|
2
|
+
import { newDatabricksOidcTokenProvider } from "./tokensource.js";
|
|
3
|
+
|
|
4
|
+
export { idTokenProviderFn, newDatabricksOidcTokenProvider };
|
package/dist/oidc/index.d.ts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @packageDocumentation
|
|
7
|
-
*/
|
|
8
|
-
export type { IdToken, IdTokenProvider } from './oidc';
|
|
9
|
-
export { idTokenProviderFn } from './oidc';
|
|
10
|
-
export { newEnvIdTokenProvider } from './env';
|
|
11
|
-
export { newFileTokenProvider } from './file';
|
|
12
|
-
export type { DatabricksOidcTokenProviderConfig, OAuthAuthorizationServer, } from './tokensource';
|
|
13
|
-
export { newDatabricksOidcTokenProvider } from './tokensource';
|
|
14
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
import { IdToken, IdTokenProvider, idTokenProviderFn } from "./oidc.js";
|
|
2
|
+
import { newEnvIdTokenProvider } from "./env.js";
|
|
3
|
+
import { newFileTokenProvider } from "./file.js";
|
|
4
|
+
import { DatabricksOidcTokenProviderConfig, OAuthAuthorizationServer, newDatabricksOidcTokenProvider } from "./tokensource.js";
|
|
5
|
+
export { type DatabricksOidcTokenProviderConfig, type IdToken, type IdTokenProvider, type OAuthAuthorizationServer, idTokenProviderFn, newDatabricksOidcTokenProvider, newEnvIdTokenProvider, newFileTokenProvider };
|
package/dist/oidc/index.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
export { idTokenProviderFn } from './oidc';
|
|
9
|
-
export { newEnvIdTokenProvider } from './env';
|
|
10
|
-
export { newFileTokenProvider } from './file';
|
|
11
|
-
export { newDatabricksOidcTokenProvider } from './tokensource';
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { idTokenProviderFn } from "./oidc.js";
|
|
2
|
+
import { newEnvIdTokenProvider } from "./env.js";
|
|
3
|
+
import { newFileTokenProvider } from "./file.js";
|
|
4
|
+
import { newDatabricksOidcTokenProvider } from "./tokensource.js";
|
|
5
|
+
|
|
6
|
+
export { idTokenProviderFn, newDatabricksOidcTokenProvider, newEnvIdTokenProvider, newFileTokenProvider };
|
package/dist/oidc/oidc.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
//#region src/oidc/oidc.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* IdToken represents an OIDC ID token that can be exchanged for a Databricks
|
|
3
4
|
* access token.
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
interface IdToken {
|
|
7
|
+
value: string;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* IdTokenProvider is anything that returns an IdToken given an audience.
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
interface IdTokenProvider {
|
|
13
|
+
idToken(audience: string): Promise<IdToken>;
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Adapter to allow the use of ordinary functions as IdTokenProvider.
|
|
@@ -17,5 +18,7 @@ export interface IdTokenProvider {
|
|
|
17
18
|
* @example
|
|
18
19
|
* const provider = idTokenProviderFn(async () => ({ value: 'my-id-token' }));
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
declare function idTokenProviderFn(fn: (audience: string) => Promise<IdToken>): IdTokenProvider;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { IdToken, IdTokenProvider, idTokenProviderFn };
|
|
21
24
|
//# sourceMappingURL=oidc.d.ts.map
|