@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.
Files changed (79) hide show
  1. package/dist/auth.d.ts +42 -40
  2. package/dist/auth.d.ts.map +1 -1
  3. package/dist/auth.js +38 -42
  4. package/dist/auth.js.map +1 -1
  5. package/dist/credentials/default/chain.d.ts +26 -22
  6. package/dist/credentials/default/chain.d.ts.map +1 -1
  7. package/dist/credentials/default/chain.js +74 -84
  8. package/dist/credentials/default/chain.js.map +1 -1
  9. package/dist/credentials/default/default-credentials.d.ts +12 -9
  10. package/dist/credentials/default/default-credentials.d.ts.map +1 -1
  11. package/dist/credentials/default/default-credentials.js +29 -20
  12. package/dist/credentials/default/default-credentials.js.map +1 -1
  13. package/dist/credentials/default/errors.d.ts +7 -4
  14. package/dist/credentials/default/errors.d.ts.map +1 -1
  15. package/dist/credentials/default/errors.js +17 -13
  16. package/dist/credentials/default/errors.js.map +1 -1
  17. package/dist/credentials/default/u2m-strategy.d.ts +6 -2
  18. package/dist/credentials/default/u2m-strategy.d.ts.map +1 -1
  19. package/dist/credentials/default/u2m-strategy.js +21 -20
  20. package/dist/credentials/default/u2m-strategy.js.map +1 -1
  21. package/dist/credentials/errors.d.ts +15 -12
  22. package/dist/credentials/errors.d.ts.map +1 -1
  23. package/dist/credentials/errors.js +40 -41
  24. package/dist/credentials/errors.js.map +1 -1
  25. package/dist/credentials/host-metadata.d.ts +22 -19
  26. package/dist/credentials/host-metadata.d.ts.map +1 -1
  27. package/dist/credentials/host-metadata.js +88 -109
  28. package/dist/credentials/host-metadata.js.map +1 -1
  29. package/dist/credentials/index.browser.d.ts +4 -11
  30. package/dist/credentials/index.browser.js +5 -9
  31. package/dist/credentials/index.d.ts +7 -14
  32. package/dist/credentials/index.js +8 -10
  33. package/dist/credentials/m2m.d.ts +29 -28
  34. package/dist/credentials/m2m.d.ts.map +1 -1
  35. package/dist/credentials/m2m.js +66 -81
  36. package/dist/credentials/m2m.js.map +1 -1
  37. package/dist/credentials/pat.d.ts +6 -5
  38. package/dist/credentials/pat.d.ts.map +1 -1
  39. package/dist/credentials/pat.js +33 -37
  40. package/dist/credentials/pat.js.map +1 -1
  41. package/dist/credentials/u2m.d.ts +17 -20
  42. package/dist/credentials/u2m.d.ts.map +1 -1
  43. package/dist/credentials/u2m.js +107 -135
  44. package/dist/credentials/u2m.js.map +1 -1
  45. package/dist/index.d.ts +6 -8
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +12 -7
  48. package/dist/index.js.map +1 -1
  49. package/dist/oidc/env.d.ts +6 -2
  50. package/dist/oidc/env.d.ts.map +1 -1
  51. package/dist/oidc/env.js +19 -16
  52. package/dist/oidc/env.js.map +1 -1
  53. package/dist/oidc/file.d.ts +6 -2
  54. package/dist/oidc/file.d.ts.map +1 -1
  55. package/dist/oidc/file.js +23 -25
  56. package/dist/oidc/file.js.map +1 -1
  57. package/dist/oidc/index.browser.d.ts +3 -13
  58. package/dist/oidc/index.browser.js +4 -11
  59. package/dist/oidc/index.d.ts +5 -14
  60. package/dist/oidc/index.js +6 -12
  61. package/dist/oidc/oidc.d.ts +8 -5
  62. package/dist/oidc/oidc.d.ts.map +1 -1
  63. package/dist/oidc/oidc.js +11 -7
  64. package/dist/oidc/oidc.js.map +1 -1
  65. package/dist/oidc/tokensource.d.ts +41 -41
  66. package/dist/oidc/tokensource.d.ts.map +1 -1
  67. package/dist/oidc/tokensource.js +47 -52
  68. package/dist/oidc/tokensource.js.map +1 -1
  69. package/dist/package.js +6 -0
  70. package/dist/package.js.map +1 -0
  71. package/package.json +3 -3
  72. package/dist/credentials/index.browser.d.ts.map +0 -1
  73. package/dist/credentials/index.browser.js.map +0 -1
  74. package/dist/credentials/index.d.ts.map +0 -1
  75. package/dist/credentials/index.js.map +0 -1
  76. package/dist/oidc/index.browser.d.ts.map +0 -1
  77. package/dist/oidc/index.browser.js.map +0 -1
  78. package/dist/oidc/index.d.ts.map +0 -1
  79. package/dist/oidc/index.js.map +0 -1
@@ -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
- * Databricks CLI ("U2M") credentials. Obtains access tokens by shelling out
3
- * to the `databricks` CLI binary (>= 0.100.0). The CLI must have been logged
4
- * in ahead of time via `databricks auth login`.
5
- *
6
- * Node.js only. Not exported from the browser entry point.
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
- * Distinguishes the modern Go-based Databricks CLI (>= 0.100.0) from the
19
- * legacy Python CLI by minimum file size.
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
- * Creates a TokenCredentials that obtains Databricks access tokens by
24
- * shelling out to the Databricks CLI.
25
- *
26
- * @param options - CLI profile (required) and optional CLI binary path.
27
- * @throws U2mCredentialsError when `profile` is empty, or when the CLI cannot
28
- * be located, is out of date, or fails to return a usable token.
29
- */
30
- export function newU2mCredentials(options) {
31
- if (options.profile === '') {
32
- throw new U2mCredentialsError('PROFILE_REQUIRED', 'profile is required');
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
- const cliPath = await findDatabricksCli(options.cliPath);
39
- return execCliCommand([
40
- cliPath,
41
- 'auth',
42
- 'token',
43
- '--profile',
44
- options.profile,
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
- access_token: z.string().min(1),
49
- token_type: z.string().optional(),
50
- expiry: z.string(),
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
- const [cliPath, ...rest] = args;
54
- let stdout;
55
- try {
56
- const result = await execFileAsync(cliPath, rest);
57
- stdout = result.stdout;
58
- }
59
- catch (e) {
60
- throw new U2mCredentialsError('TOKEN_FETCH_FAILED', `cannot get access token: ${cliErrorMessage(e)}`);
61
- }
62
- let raw;
63
- try {
64
- raw = JSON.parse(stdout);
65
- }
66
- catch (e) {
67
- const cause = e instanceof Error ? e.message : String(e);
68
- throw new U2mCredentialsError('INVALID_RESPONSE', `cannot parse CLI response: ${cause}`);
69
- }
70
- const result = cliTokenResponseSchema.safeParse(raw);
71
- if (!result.success) {
72
- throw new U2mCredentialsError('INVALID_RESPONSE', `invalid CLI response: ${result.error.message}`);
73
- }
74
- const parsed = result.data;
75
- const expiry = new Date(parsed.expiry);
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
- if (typeof e === 'object' && e !== null) {
87
- const err = e;
88
- if (err.stderr !== undefined) {
89
- return err.stderr.toString().trim();
90
- }
91
- return err.message;
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
- * Locates the `databricks` CLI binary, either at `cliPath` (if provided) or
97
- * by searching `PATH`. Validates that the binary is the modern Go CLI and
98
- * not the legacy Python one, via a minimum-size check.
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
- if (cliPath !== undefined) {
102
- if (cliPath.includes(sep) || cliPath.includes('/')) {
103
- return validateCliPath(cliPath);
104
- }
105
- return findInPath(cliPath);
106
- }
107
- try {
108
- return await findInPath('databricks');
109
- }
110
- catch (e) {
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
- const pathEnv = env.PATH ?? '';
119
- if (pathEnv === '') {
120
- throw new U2mCredentialsError('CLI_NOT_FOUND', 'databricks CLI not found');
121
- }
122
- const delim = platform === 'win32' ? ';' : ':';
123
- let legacyError;
124
- for (const dir of pathEnv.split(delim)) {
125
- if (dir === '') {
126
- continue;
127
- }
128
- try {
129
- return await validateCliPath(join(dir, name));
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
- let info;
143
- try {
144
- info = await stat(path);
145
- }
146
- catch {
147
- throw new U2mCredentialsError('CLI_NOT_FOUND', 'databricks CLI not found');
148
- }
149
- if (info.isDirectory()) {
150
- throw new U2mCredentialsError('CLI_NOT_FOUND', 'databricks CLI not found');
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","sourceRoot":"","sources":["../../src/credentials/u2m.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAC,IAAI,EAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAC,IAAI,EAAE,GAAG,EAAC,MAAM,WAAW,CAAC;AACpC,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAC,SAAS,EAAC,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAC,CAAC,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
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":";;;;;;;;;;;;;;;;;AAqBA,MAAM,gBAAgB,UAAU,SAAS;;;;;AAMzC,MAAM,0BAA0B,OAAO;;;;;;;;;AAyBvC,SAAgB,kBACd,SACkB;AAClB,KAAI,QAAQ,YAAY,GACtB,OAAM,IAAI,oBAAoB,oBAAoB,sBAAsB;AAG1E,QAAO,oBAAoB,kBADV,sBAAsB,cAAc,QAAQ,CAAC,CACR;;AAGxD,eAAe,cAAc,SAAgD;AAE3E,QAAO,eAAe;EADN,MAAM,kBAAkB,QAAQ,QAAQ;EAGtD;EACA;EACA;EACA,QAAQ;EACT,CAAC;;AAGJ,MAAM,yBAAyB,EAAE,OAAO;CACtC,cAAc,EAAE,QAAQ,CAAC,IAAI,EAAE;CAC/B,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,QAAQ,EAAE,Q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,WAAW,MAA+B;CACvD,MAAM,UAAU,IAAI,QAAQ;AAC5B,KAAI,YAAY,GACd,OAAM,IAAI,oBAAoB,iBAAiB,2BAA2B;CAE5E,MAAM,QAAQ,aAAa,UAAU,MAAM;CAC3C,IAAI;AACJ,MAAK,MAAM,OAAO,QAAQ,MAAM,MAAM,EAAE;AACtC,MAAI,QAAQ,GACV;AAEF,MAAI;AACF,UAAO,MAAM,gBAAgB,KAAK,KAAK,KAAK,CAAC;WACtC,GAAG;AACV,OACE,aAAa,uBACb,EAAE,SAAS,sBAEX,eAAc;;;AAIpB,OACE,eACA,IAAI,oBAAoB,iBAAiB,2BAA2B;;AAIxE,eAAe,gBAAgB,MAA+B;CAC5D,IAAI;AACJ,KAAI;AACF,SAAO,MAAM,KAAK,KAAK;SACjB;AACN,QAAM,IAAI,oBAAoB,iBAAiB,2BAA2B;;AAE5E,KAAI,KAAK,aAAa,CACpB,OAAM,IAAI,oBAAoB,iBAAiB,2BAA2B;AAE5E,KAAI,KAAK,OAAO,wBACd,OAAM,IAAI,oBACR,uBACA,wDACD;AAEH,QAAO"}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,8 @@
1
- /**
2
- * Databricks authentication library for JavaScript/TypeScript.
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
- export declare const VERSION: string;
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,YAAY,EACV,MAAM,EACN,KAAK,EACL,WAAW,EACX,aAAa,EACb,gBAAgB,GACjB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAC,mBAAmB,EAAE,eAAe,EAAC,MAAM,QAAQ,CAAC;AAE5D,+DAA+D;AAC/D,eAAO,MAAM,OAAO,EAAE,MAAwB,CAAC"}
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
- * Databricks authentication library for JavaScript/TypeScript.
3
- *
4
- * @packageDocumentation
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
- export const VERSION = pkgJson.version;
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","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,OAAO,MAAM,iBAAiB,CAAC,OAAM,IAAI,EAAE,MAAM,EAAC,CAAC;AAS1D,OAAO,EAAC,mBAAmB,EAAE,eAAe,EAAC,MAAM,QAAQ,CAAC;AAE5D,+DAA+D;AAC/D,MAAM,CAAC,MAAM,OAAO,GAAW,OAAO,CAAC,OAAO,CAAC"}
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"}
@@ -1,4 +1,6 @@
1
- import type { IdTokenProvider } from './oidc';
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
- export declare function newEnvIdTokenProvider(name: string): IdTokenProvider;
11
+ declare function newEnvIdTokenProvider(name: string): IdTokenProvider;
12
+ //#endregion
13
+ export { newEnvIdTokenProvider };
10
14
  //# sourceMappingURL=env.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/oidc/env.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,QAAQ,CAAC;AAG5C;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAQnE"}
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 { env } from 'node:process';
2
- import { idTokenProviderFn } from './oidc';
1
+ import { idTokenProviderFn } from "./oidc.js";
2
+ import { env } from "node:process";
3
+
4
+ //#region src/oidc/env.ts
3
5
  /**
4
- * Returns an IdTokenProvider that reads the ID token from environment variable
5
- * `name`.
6
- *
7
- * Note that the IdTokenProvider does not cache the token and will read the
8
- * token from environment variable `name` each time.
9
- */
10
- export function newEnvIdTokenProvider(name) {
11
- return idTokenProviderFn(() => {
12
- const t = env[name];
13
- if (t === undefined || t === '') {
14
- return Promise.reject(new Error(`missing env var "${name}"`));
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
@@ -1 +1 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/oidc/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,cAAc,CAAC;AAGjC,OAAO,EAAC,iBAAiB,EAAC,MAAM,QAAQ,CAAC;AAEzC;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,OAAO,iBAAiB,CAAC,GAAG,EAAE;QAC5B,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;YAChC,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,oBAAoB,IAAI,GAAG,CAAC,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,CAAC,EAAC,KAAK,EAAE,CAAC,EAAC,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC"}
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"}
@@ -1,7 +1,11 @@
1
- import type { IdTokenProvider } from './oidc';
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
- export declare function newFileTokenProvider(path: string): IdTokenProvider;
8
+ declare function newFileTokenProvider(path: string): IdTokenProvider;
9
+ //#endregion
10
+ export { newFileTokenProvider };
7
11
  //# sourceMappingURL=file.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/oidc/file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,QAAQ,CAAC;AAG5C;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAmBlE"}
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 { readFile } from 'node:fs/promises';
2
- import { idTokenProviderFn } from './oidc';
1
+ import { idTokenProviderFn } from "./oidc.js";
2
+ import { readFile } from "node:fs/promises";
3
+
4
+ //#region src/oidc/file.ts
3
5
  /**
4
- * Returns an IdTokenProvider that reads the ID token from a file. The file
5
- * should contain a single line with the token.
6
- */
7
- export function newFileTokenProvider(path) {
8
- return idTokenProviderFn(async () => {
9
- if (path === '') {
10
- throw new Error('missing path');
11
- }
12
- let content;
13
- try {
14
- content = await readFile(path, 'utf-8');
15
- }
16
- catch (e) {
17
- if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {
18
- throw new Error(`file "${path}" does not exist`);
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
@@ -1 +1 @@
1
- {"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/oidc/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAG1C,OAAO,EAAC,iBAAiB,EAAC,MAAM,QAAQ,CAAC;AAEzC;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,OAAO,iBAAiB,CAAC,KAAK,IAAI,EAAE;QAClC,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;QAClC,CAAC;QACD,IAAI,OAAe,CAAC;QACpB,IAAI,CAAC;YACH,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC1C,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACpB,IAAI,CAAC,YAAY,KAAK,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC7D,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,kBAAkB,CAAC,CAAC;YACnD,CAAC;YACD,MAAM,CAAC,CAAC;QACV,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,YAAY,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,EAAC,KAAK,EAAE,OAAO,EAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC"}
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
- * Browser entry point for OIDC ID token utilities and the Databricks OIDC
3
- * token-exchange provider.
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
- * Browser entry point for OIDC ID token utilities and the Databricks OIDC
3
- * token-exchange provider.
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 };
@@ -1,14 +1,5 @@
1
- /**
2
- * OIDC ID token utilities and Databricks OIDC token-exchange provider.
3
- *
4
- * This package is experimental and subject to change.
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 };
@@ -1,12 +1,6 @@
1
- /**
2
- * OIDC ID token utilities and Databricks OIDC token-exchange provider.
3
- *
4
- * This package is experimental and subject to change.
5
- *
6
- * @packageDocumentation
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 };
@@ -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
- export interface IdToken {
6
- value: string;
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
- export interface IdTokenProvider {
12
- idToken(audience: string): Promise<IdToken>;
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
- export declare function idTokenProviderFn(fn: (audience: string) => Promise<IdToken>): IdTokenProvider;
21
+ declare function idTokenProviderFn(fn: (audience: string) => Promise<IdToken>): IdTokenProvider;
22
+ //#endregion
23
+ export { IdToken, IdTokenProvider, idTokenProviderFn };
21
24
  //# sourceMappingURL=oidc.d.ts.map