@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,9 +1,5 @@
1
- /**
2
- * Browser entry point for credential implementations. Excludes credentials
3
- * that depend on Node.js-only APIs (e.g. `databricks-cli` auth which spawns
4
- * the CLI binary).
5
- */
6
- export { M2mCredentialsError, PatCredentialsError } from './errors';
7
- export { newM2mCredentials } from './m2m';
8
- export { newPatCredentials } from './pat';
9
- //# sourceMappingURL=index.browser.js.map
1
+ import { M2mCredentialsError, PatCredentialsError } from "./errors.js";
2
+ import { newM2mCredentials } from "./m2m.js";
3
+ import { newPatCredentials } from "./pat.js";
4
+
5
+ export { M2mCredentialsError, PatCredentialsError, newM2mCredentials, newPatCredentials };
@@ -1,14 +1,7 @@
1
- /**
2
- * Credential implementations for the Databricks SDK.
3
- */
4
- export { M2mCredentialsError, PatCredentialsError, U2mCredentialsError, } from './errors';
5
- export type { M2mCredentialsErrorCode, PatCredentialsErrorCode, U2mCredentialsErrorCode, } from './errors';
6
- export { newM2mCredentials } from './m2m';
7
- export type { M2mCredentialsOptions } from './m2m';
8
- export { newPatCredentials } from './pat';
9
- export { newU2mCredentials } from './u2m';
10
- export type { U2mCredentialsOptions } from './u2m';
11
- export { defaultCredentials } from './default/default-credentials';
12
- export { DefaultCredentialsError } from './default/errors';
13
- export type { DefaultCredentialsErrorCode } from './default/errors';
14
- //# sourceMappingURL=index.d.ts.map
1
+ import { defaultCredentials } from "./default/default-credentials.js";
2
+ import { DefaultCredentialsError, DefaultCredentialsErrorCode } from "./default/errors.js";
3
+ import { M2mCredentialsError, M2mCredentialsErrorCode, PatCredentialsError, PatCredentialsErrorCode, U2mCredentialsError, U2mCredentialsErrorCode } from "./errors.js";
4
+ import { M2mCredentialsOptions, newM2mCredentials } from "./m2m.js";
5
+ import { newPatCredentials } from "./pat.js";
6
+ import { U2mCredentialsOptions, newU2mCredentials } from "./u2m.js";
7
+ export { DefaultCredentialsError, type DefaultCredentialsErrorCode, M2mCredentialsError, type M2mCredentialsErrorCode, type M2mCredentialsOptions, PatCredentialsError, type PatCredentialsErrorCode, U2mCredentialsError, type U2mCredentialsErrorCode, type U2mCredentialsOptions, defaultCredentials, newM2mCredentials, newPatCredentials, newU2mCredentials };
@@ -1,10 +1,8 @@
1
- /**
2
- * Credential implementations for the Databricks SDK.
3
- */
4
- export { M2mCredentialsError, PatCredentialsError, U2mCredentialsError, } from './errors';
5
- export { newM2mCredentials } from './m2m';
6
- export { newPatCredentials } from './pat';
7
- export { newU2mCredentials } from './u2m';
8
- export { defaultCredentials } from './default/default-credentials';
9
- export { DefaultCredentialsError } from './default/errors';
10
- //# sourceMappingURL=index.js.map
1
+ import { M2mCredentialsError, PatCredentialsError, U2mCredentialsError } from "./errors.js";
2
+ import { newM2mCredentials } from "./m2m.js";
3
+ import { newPatCredentials } from "./pat.js";
4
+ import { newU2mCredentials } from "./u2m.js";
5
+ import { DefaultCredentialsError } from "./default/errors.js";
6
+ import { defaultCredentials } from "./default/default-credentials.js";
7
+
8
+ export { DefaultCredentialsError, M2mCredentialsError, PatCredentialsError, U2mCredentialsError, defaultCredentials, newM2mCredentials, newPatCredentials, newU2mCredentials };
@@ -1,31 +1,30 @@
1
- /**
2
- * Machine-to-machine (M2M) OAuth credentials for the Databricks SDK.
3
- */
4
- import type { TokenCredentials } from '../auth';
1
+ import { TokenCredentials } from "../auth.js";
2
+
3
+ //#region src/credentials/m2m.d.ts
5
4
  /** Options for {@link newM2mCredentials}. */
6
- export interface M2mCredentialsOptions {
7
- /**
8
- * Databricks host (workspace or account) used to discover the OAuth token
9
- * endpoint.
10
- */
11
- host: string;
12
- /**
13
- * OAuth client ID issued to the service principal.
14
- */
15
- clientId: string;
16
- /**
17
- * OAuth client secret issued to the service principal.
18
- */
19
- clientSecret: string;
20
- /**
21
- * Databricks account ID. Required for account hosts.
22
- */
23
- accountId?: string;
24
- /**
25
- * OAuth scopes to request. When omitted or empty, defaults to
26
- * `['all-apis']`.
27
- */
28
- scopes?: string[];
5
+ interface M2mCredentialsOptions {
6
+ /**
7
+ * Databricks host (workspace or account) used to discover the OAuth token
8
+ * endpoint.
9
+ */
10
+ host: string;
11
+ /**
12
+ * OAuth client ID issued to the service principal.
13
+ */
14
+ clientId: string;
15
+ /**
16
+ * OAuth client secret issued to the service principal.
17
+ */
18
+ clientSecret: string;
19
+ /**
20
+ * Databricks account ID. Required for account hosts.
21
+ */
22
+ accountId?: string;
23
+ /**
24
+ * OAuth scopes to request. When omitted or empty, defaults to
25
+ * `['all-apis']`.
26
+ */
27
+ scopes?: string[];
29
28
  }
30
29
  /**
31
30
  * Creates a TokenCredentials that authenticates as a Databricks service
@@ -36,5 +35,7 @@ export interface M2mCredentialsOptions {
36
35
  * when token-endpoint discovery fails, or when the token endpoint returns
37
36
  * an error.
38
37
  */
39
- export declare function newM2mCredentials(options: M2mCredentialsOptions): TokenCredentials;
38
+ declare function newM2mCredentials(options: M2mCredentialsOptions): TokenCredentials;
39
+ //#endregion
40
+ export { M2mCredentialsOptions, newM2mCredentials };
40
41
  //# sourceMappingURL=m2m.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"m2m.d.ts","sourceRoot":"","sources":["../../src/credentials/m2m.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAQ,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAMrD,6CAA6C;AAC7C,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAID;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,qBAAqB,GAC7B,gBAAgB,CAuDlB"}
1
+ {"version":3,"file":"m2m.d.ts","names":[],"sources":["../../src/credentials/m2m.ts"],"mappings":";;;;UAaiB,qBAAA;EAAqB;;;;EAKpC,IAAA;EAqBA;;;EAhBA,QAAA;EA8B+B;;;EAzB/B,YAAA;EA0BA;;;EArBA,SAAA;;;;;EAMA,MAAA;AAAA;;;;;;;;;;iBAcc,iBAAA,CACd,OAAA,EAAS,qBAAA,GACR,gBAAA"}
@@ -1,91 +1,76 @@
1
+ import { newTokenCredentials, tokenProviderFn } from "../auth.js";
2
+ import { M2mCredentialsError } from "./errors.js";
3
+ import { resolveTokenEndpoint } from "./host-metadata.js";
4
+ import { z } from "zod";
5
+
6
+ //#region src/credentials/m2m.ts
1
7
  /**
2
- * Machine-to-machine (M2M) OAuth credentials for the Databricks SDK.
3
- */
4
- import { z } from 'zod';
5
- import { newTokenCredentials, tokenProviderFn } from '../auth';
6
- import { M2mCredentialsError } from './errors';
7
- import { resolveTokenEndpoint } from './host-metadata';
8
- const DEFAULT_SCOPES = ['all-apis'];
8
+ * Machine-to-machine (M2M) OAuth credentials for the Databricks SDK.
9
+ */
10
+ const DEFAULT_SCOPES = ["all-apis"];
9
11
  /**
10
- * Creates a TokenCredentials that authenticates as a Databricks service
11
- * principal using the OAuth client credentials grant.
12
- *
13
- * @param options - Host plus client credentials.
14
- * @throws M2mCredentialsError when host, clientId, or clientSecret is empty,
15
- * when token-endpoint discovery fails, or when the token endpoint returns
16
- * an error.
17
- */
18
- export function newM2mCredentials(options) {
19
- if (options.clientId === '') {
20
- throw new M2mCredentialsError('CLIENT_ID_REQUIRED', 'clientId is required');
21
- }
22
- if (options.clientSecret === '') {
23
- throw new M2mCredentialsError('CLIENT_SECRET_REQUIRED', 'clientSecret is required');
24
- }
25
- if (options.host === '') {
26
- throw new M2mCredentialsError('HOST_REQUIRED', 'host is required');
27
- }
28
- const scopes = options.scopes !== undefined && options.scopes.length > 0
29
- ? options.scopes
30
- : DEFAULT_SCOPES;
31
- const body = new URLSearchParams({
32
- grant_type: 'client_credentials',
33
- scope: scopes.join(' '),
34
- }).toString();
35
- // Client ID and secret are URL-encoded before Basic auth encoding to
36
- // avoid ambiguity with special characters in either value, matching the
37
- // behavior of golang.org/x/oauth2.
38
- const basicAuth = btoa(`${encodeURIComponent(options.clientId)}:${encodeURIComponent(options.clientSecret)}`);
39
- let cachedTokenEndpoint;
40
- const getTokenEndpoint = async () => {
41
- if (cachedTokenEndpoint === undefined) {
42
- try {
43
- cachedTokenEndpoint = await resolveTokenEndpoint(options.host, options.accountId);
44
- }
45
- catch (e) {
46
- throw new M2mCredentialsError('DISCOVERY_FAILED', `discovering token endpoint failed: ${stringifyError(e)}`);
47
- }
48
- }
49
- return cachedTokenEndpoint;
50
- };
51
- const provider = tokenProviderFn(async () => {
52
- const tokenEndpoint = await getTokenEndpoint();
53
- return fetchAccessToken(tokenEndpoint, basicAuth, body);
54
- });
55
- return newTokenCredentials('oauth-m2m', provider);
12
+ * Creates a TokenCredentials that authenticates as a Databricks service
13
+ * principal using the OAuth client credentials grant.
14
+ *
15
+ * @param options - Host plus client credentials.
16
+ * @throws M2mCredentialsError when host, clientId, or clientSecret is empty,
17
+ * when token-endpoint discovery fails, or when the token endpoint returns
18
+ * an error.
19
+ */
20
+ function newM2mCredentials(options) {
21
+ if (options.clientId === "") throw new M2mCredentialsError("CLIENT_ID_REQUIRED", "clientId is required");
22
+ if (options.clientSecret === "") throw new M2mCredentialsError("CLIENT_SECRET_REQUIRED", "clientSecret is required");
23
+ if (options.host === "") throw new M2mCredentialsError("HOST_REQUIRED", "host is required");
24
+ const scopes = options.scopes !== void 0 && options.scopes.length > 0 ? options.scopes : DEFAULT_SCOPES;
25
+ const body = new URLSearchParams({
26
+ grant_type: "client_credentials",
27
+ scope: scopes.join(" ")
28
+ }).toString();
29
+ const basicAuth = btoa(`${encodeURIComponent(options.clientId)}:${encodeURIComponent(options.clientSecret)}`);
30
+ let cachedTokenEndpoint;
31
+ const getTokenEndpoint = async () => {
32
+ if (cachedTokenEndpoint === void 0) try {
33
+ cachedTokenEndpoint = await resolveTokenEndpoint(options.host, options.accountId);
34
+ } catch (e) {
35
+ throw new M2mCredentialsError("DISCOVERY_FAILED", `discovering token endpoint failed: ${stringifyError(e)}`);
36
+ }
37
+ return cachedTokenEndpoint;
38
+ };
39
+ return newTokenCredentials("oauth-m2m", tokenProviderFn(async () => {
40
+ return fetchAccessToken(await getTokenEndpoint(), basicAuth, body);
41
+ }));
56
42
  }
57
43
  async function fetchAccessToken(tokenEndpoint, basicAuth, body) {
58
- const response = await fetch(tokenEndpoint, {
59
- method: 'POST',
60
- headers: {
61
- Authorization: `Basic ${basicAuth}`,
62
- 'Content-Type': 'application/x-www-form-urlencoded',
63
- },
64
- body,
65
- });
66
- if (!response.ok) {
67
- const text = await response.text();
68
- throw new M2mCredentialsError('TOKEN_REQUEST_FAILED', `token request failed with status ${response.status.toString()}: ${text}`);
69
- }
70
- const parsed = tokenResponseSchema.parse(await response.json());
71
- const expiry = parsed.expires_in !== undefined
72
- ? new Date(Date.now() + parsed.expires_in * 1000)
73
- : undefined;
74
- return {
75
- value: parsed.access_token,
76
- ...(parsed.token_type !== undefined && { type: parsed.token_type }),
77
- ...(expiry !== undefined && { expiry }),
78
- };
44
+ const response = await fetch(tokenEndpoint, {
45
+ method: "POST",
46
+ headers: {
47
+ Authorization: `Basic ${basicAuth}`,
48
+ "Content-Type": "application/x-www-form-urlencoded"
49
+ },
50
+ body
51
+ });
52
+ if (!response.ok) {
53
+ const text = await response.text();
54
+ throw new M2mCredentialsError("TOKEN_REQUEST_FAILED", `token request failed with status ${response.status.toString()}: ${text}`);
55
+ }
56
+ const parsed = tokenResponseSchema.parse(await response.json());
57
+ const expiry = parsed.expires_in !== void 0 ? new Date(Date.now() + parsed.expires_in * 1e3) : void 0;
58
+ return {
59
+ value: parsed.access_token,
60
+ ...parsed.token_type !== void 0 && { type: parsed.token_type },
61
+ ...expiry !== void 0 && { expiry }
62
+ };
79
63
  }
80
64
  const tokenResponseSchema = z.object({
81
- access_token: z.string(),
82
- token_type: z.string().optional(),
83
- expires_in: z.number().optional(),
65
+ access_token: z.string(),
66
+ token_type: z.string().optional(),
67
+ expires_in: z.number().optional()
84
68
  });
85
69
  function stringifyError(e) {
86
- if (e instanceof Error) {
87
- return e.message;
88
- }
89
- return String(e);
70
+ if (e instanceof Error) return e.message;
71
+ return String(e);
90
72
  }
73
+
74
+ //#endregion
75
+ export { newM2mCredentials };
91
76
  //# sourceMappingURL=m2m.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"m2m.js","sourceRoot":"","sources":["../../src/credentials/m2m.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAGtB,OAAO,EAAC,mBAAmB,EAAE,eAAe,EAAC,MAAM,SAAS,CAAC;AAE7D,OAAO,EAAC,mBAAmB,EAAC,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAC,oBAAoB,EAAC,MAAM,iBAAiB,CAAC;AAgCrD,MAAM,cAAc,GAAsB,CAAC,UAAU,CAAC,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAA8B;IAE9B,IAAI,OAAO,CAAC,QAAQ,KAAK,EAAE,EAAE,CAAC;QAC5B,MAAM,IAAI,mBAAmB,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,CAAC;IAC9E,CAAC;IACD,IAAI,OAAO,CAAC,YAAY,KAAK,EAAE,EAAE,CAAC;QAChC,MAAM,IAAI,mBAAmB,CAC3B,wBAAwB,EACxB,0BAA0B,CAC3B,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,EAAE,EAAE,CAAC;QACxB,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC;IACrE,CAAC;IAED,MAAM,MAAM,GACV,OAAO,CAAC,MAAM,KAAK,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QACvD,CAAC,CAAC,OAAO,CAAC,MAAM;QAChB,CAAC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,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC"}
1
+ {"version":3,"file":"m2m.js","names":[],"sources":["../../src/credentials/m2m.ts"],"sourcesContent":["/**\n * Machine-to-machine (M2M) OAuth credentials for the Databricks SDK.\n */\n\nimport {z} from 'zod';\n\nimport type {Token, TokenCredentials} from '../auth';\nimport {newTokenCredentials, tokenProviderFn} from '../auth';\n\nimport {M2mCredentialsError} from './errors';\nimport {resolveTokenEndpoint} from './host-metadata';\n\n/** Options for {@link newM2mCredentials}. */\nexport interface M2mCredentialsOptions {\n /**\n * Databricks host (workspace or account) used to discover the OAuth token\n * endpoint.\n */\n host: string;\n\n /**\n * OAuth client ID issued to the service principal.\n */\n clientId: string;\n\n /**\n * OAuth client secret issued to the service principal.\n */\n clientSecret: string;\n\n /**\n * Databricks account ID. Required for account hosts.\n */\n accountId?: string;\n\n /**\n * OAuth scopes to request. When omitted or empty, defaults to\n * `['all-apis']`.\n */\n scopes?: string[];\n}\n\nconst DEFAULT_SCOPES: readonly string[] = ['all-apis'];\n\n/**\n * Creates a TokenCredentials that authenticates as a Databricks service\n * principal using the OAuth client credentials grant.\n *\n * @param options - Host plus client credentials.\n * @throws M2mCredentialsError when host, clientId, or clientSecret is empty,\n * when token-endpoint discovery fails, or when the token endpoint returns\n * an error.\n */\nexport function newM2mCredentials(\n options: M2mCredentialsOptions\n): TokenCredentials {\n if (options.clientId === '') {\n throw new M2mCredentialsError('CLIENT_ID_REQUIRED', 'clientId is required');\n }\n if (options.clientSecret === '') {\n throw new M2mCredentialsError(\n 'CLIENT_SECRET_REQUIRED',\n 'clientSecret is required'\n );\n }\n if (options.host === '') {\n throw new M2mCredentialsError('HOST_REQUIRED', 'host is required');\n }\n\n const scopes =\n options.scopes !== undefined && options.scopes.length > 0\n ? options.scopes\n : DEFAULT_SCOPES;\n\n const body = new URLSearchParams({\n grant_type: 'client_credentials',\n scope: scopes.join(' '),\n }).toString();\n\n // Client ID and secret are URL-encoded before Basic auth encoding to\n // avoid ambiguity with special characters in either value, matching the\n // behavior of golang.org/x/oauth2.\n const basicAuth = btoa(\n `${encodeURIComponent(options.clientId)}:${encodeURIComponent(options.clientSecret)}`\n );\n\n let cachedTokenEndpoint: string | undefined;\n const getTokenEndpoint = async (): Promise<string> => {\n if (cachedTokenEndpoint === undefined) {\n try {\n cachedTokenEndpoint = await resolveTokenEndpoint(\n options.host,\n options.accountId\n );\n } catch (e) {\n throw new M2mCredentialsError(\n 'DISCOVERY_FAILED',\n `discovering token endpoint failed: ${stringifyError(e)}`\n );\n }\n }\n return cachedTokenEndpoint;\n };\n\n const provider = tokenProviderFn(async () => {\n const tokenEndpoint = await getTokenEndpoint();\n return fetchAccessToken(tokenEndpoint, basicAuth, body);\n });\n\n return newTokenCredentials('oauth-m2m', provider);\n}\n\nasync function fetchAccessToken(\n tokenEndpoint: string,\n basicAuth: string,\n body: string\n): Promise<Token> {\n const response = await fetch(tokenEndpoint, {\n method: 'POST',\n headers: {\n Authorization: `Basic ${basicAuth}`,\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body,\n });\n if (!response.ok) {\n const text = await response.text();\n throw new M2mCredentialsError(\n 'TOKEN_REQUEST_FAILED',\n `token request failed with status ${response.status.toString()}: ${text}`\n );\n }\n const parsed = tokenResponseSchema.parse(await response.json());\n const expiry =\n parsed.expires_in !== undefined\n ? new Date(Date.now() + parsed.expires_in * 1000)\n : undefined;\n return {\n value: parsed.access_token,\n ...(parsed.token_type !== undefined && {type: parsed.token_type}),\n ...(expiry !== undefined && {expiry}),\n };\n}\n\nconst tokenResponseSchema = z.object({\n access_token: z.string(),\n token_type: z.string().optional(),\n expires_in: z.number().optional(),\n});\n\nfunction stringifyError(e: unknown): string {\n if (e instanceof Error) {\n return e.message;\n }\n return String(e);\n}\n"],"mappings":";;;;;;;;;AA0CA,MAAM,iBAAoC,CAAC,WAAW;;;;;;;;;;AAWtD,SAAgB,kBACd,SACkB;AAClB,KAAI,QAAQ,aAAa,GACvB,OAAM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,UAAa,EAAC,MAAM,OAAO,YAAW;EAChE,GAAI,WAAW,UAAa,EAAC,QAAO;EACrC;;AAGH,MAAM,sBAAsB,EAAE,OAAO;CACnC,cAAc,EAAE,QAAQ;CACxB,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,YAAY,EAAE,QAAQ,CAAC,UAAU;CAClC,CAAC;AAEF,SAAS,eAAe,GAAoB;AAC1C,KAAI,aAAa,MACf,QAAO,EAAE;AAEX,QAAO,OAAO,EAAE"}
@@ -1,7 +1,6 @@
1
- /**
2
- * Personal Access Token (PAT) credentials for the Databricks SDK.
3
- */
4
- import type { Credentials } from '../auth';
1
+ import { Credentials } from "../auth.js";
2
+
3
+ //#region src/credentials/pat.d.ts
5
4
  /**
6
5
  * Creates a Credentials that can be used to authenticate with a Personal
7
6
  * Access Token.
@@ -11,5 +10,7 @@ import type { Credentials } from '../auth';
11
10
  * @throws PatCredentialsError with code `TOKEN_REQUIRED` if the token is empty
12
11
  * after trimming, or `TOKEN_MALFORMED` if it contains internal whitespace.
13
12
  */
14
- export declare function newPatCredentials(token: string): Credentials;
13
+ declare function newPatCredentials(token: string): Credentials;
14
+ //#endregion
15
+ export { newPatCredentials };
15
16
  //# sourceMappingURL=pat.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pat.d.ts","sourceRoot":"","sources":["../../src/credentials/pat.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAC,WAAW,EAAS,MAAM,SAAS,CAAC;AAIjD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAc5D"}
1
+ {"version":3,"file":"pat.d.ts","names":[],"sources":["../../src/credentials/pat.ts"],"mappings":";;;;;;;;;;;;iBAiBgB,iBAAA,CAAkB,KAAA,WAAgB,WAAA"}
@@ -1,40 +1,36 @@
1
+ import { PatCredentialsError } from "./errors.js";
2
+
3
+ //#region src/credentials/pat.ts
1
4
  /**
2
- * Personal Access Token (PAT) credentials for the Databricks SDK.
3
- */
4
- import { PatCredentialsError } from './errors';
5
- /**
6
- * Creates a Credentials that can be used to authenticate with a Personal
7
- * Access Token.
8
- *
9
- * @param token - The personal access token.
10
- * @returns Credentials for PAT authentication.
11
- * @throws PatCredentialsError with code `TOKEN_REQUIRED` if the token is empty
12
- * after trimming, or `TOKEN_MALFORMED` if it contains internal whitespace.
13
- */
14
- export function newPatCredentials(token) {
15
- const trimmed = token.trim();
16
- if (trimmed === '') {
17
- throw new PatCredentialsError('TOKEN_REQUIRED', 'token is required');
18
- }
19
- // Internal whitespace would corrupt the header even after trimming, so
20
- // reject it rather than silently producing a malformed `Bearer` value.
21
- if (/\s/.test(trimmed)) {
22
- throw new PatCredentialsError('TOKEN_MALFORMED', 'token must not contain whitespace');
23
- }
24
- return new PatCredentials(trimmed);
25
- }
26
- class PatCredentials {
27
- token;
28
- constructor(token) {
29
- this.token = token;
30
- }
31
- name() {
32
- return 'pat';
33
- }
34
- authHeaders() {
35
- return Promise.resolve([
36
- { key: 'Authorization', value: `Bearer ${this.token}` },
37
- ]);
38
- }
5
+ * Creates a Credentials that can be used to authenticate with a Personal
6
+ * Access Token.
7
+ *
8
+ * @param token - The personal access token.
9
+ * @returns Credentials for PAT authentication.
10
+ * @throws PatCredentialsError with code `TOKEN_REQUIRED` if the token is empty
11
+ * after trimming, or `TOKEN_MALFORMED` if it contains internal whitespace.
12
+ */
13
+ function newPatCredentials(token) {
14
+ const trimmed = token.trim();
15
+ if (trimmed === "") throw new PatCredentialsError("TOKEN_REQUIRED", "token is required");
16
+ if (/\s/.test(trimmed)) throw new PatCredentialsError("TOKEN_MALFORMED", "token must not contain whitespace");
17
+ return new PatCredentials(trimmed);
39
18
  }
19
+ var PatCredentials = class {
20
+ constructor(token) {
21
+ this.token = token;
22
+ }
23
+ name() {
24
+ return "pat";
25
+ }
26
+ authHeaders() {
27
+ return Promise.resolve([{
28
+ key: "Authorization",
29
+ value: `Bearer ${this.token}`
30
+ }]);
31
+ }
32
+ };
33
+
34
+ //#endregion
35
+ export { newPatCredentials };
40
36
  //# sourceMappingURL=pat.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pat.js","sourceRoot":"","sources":["../../src/credentials/pat.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAC,mBAAmB,EAAC,MAAM,UAAU,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QACnB,MAAM,IAAI,mBAAmB,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAC;IACvE,CAAC;IACD,uEAAuE;IACvE,uEAAuE;IACvE,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,mBAAmB,CAC3B,iBAAiB,EACjB,mCAAmC,CACpC,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,cAAc;IACW;IAA7B,YAA6B,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAE9C,IAAI;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,WAAW;QACT,OAAO,OAAO,CAAC,OAAO,CAAC;YACrB,EAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,UAAU,IAAI,CAAC,KAAK,EAAE,EAAC;SACtD,CAAC,CAAC;IACL,CAAC;CACF"}
1
+ {"version":3,"file":"pat.js","names":[],"sources":["../../src/credentials/pat.ts"],"sourcesContent":["/**\n * Personal Access Token (PAT) credentials for the Databricks SDK.\n */\n\nimport type {Credentials, Header} from '../auth';\n\nimport {PatCredentialsError} from './errors';\n\n/**\n * Creates a Credentials that can be used to authenticate with a Personal\n * Access Token.\n *\n * @param token - The personal access token.\n * @returns Credentials for PAT authentication.\n * @throws PatCredentialsError with code `TOKEN_REQUIRED` if the token is empty\n * after trimming, or `TOKEN_MALFORMED` if it contains internal whitespace.\n */\nexport function newPatCredentials(token: string): Credentials {\n const trimmed = token.trim();\n if (trimmed === '') {\n throw new PatCredentialsError('TOKEN_REQUIRED', 'token is required');\n }\n // Internal whitespace would corrupt the header even after trimming, so\n // reject it rather than silently producing a malformed `Bearer` value.\n if (/\\s/.test(trimmed)) {\n throw new PatCredentialsError(\n 'TOKEN_MALFORMED',\n 'token must not contain whitespace'\n );\n }\n return new PatCredentials(trimmed);\n}\n\nclass PatCredentials implements Credentials {\n constructor(private readonly token: string) {}\n\n name(): string {\n return 'pat';\n }\n\n authHeaders(): Promise<Header[]> {\n return Promise.resolve([\n {key: 'Authorization', value: `Bearer ${this.token}`},\n ]);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAiBA,SAAgB,kBAAkB,OAA4B;CAC5D,MAAM,UAAU,MAAM,MAAM;AAC5B,KAAI,YAAY,GACd,OAAM,IAAI,oBAAoB,kBAAkB,oBAAoB;AAItE,KAAI,KAAK,KAAK,QAAQ,CACpB,OAAM,IAAI,oBACR,mBACA,oCACD;AAEH,QAAO,IAAI,eAAe,QAAQ;;AAGpC,IAAM,iBAAN,MAA4C;CAC1C,YAAY,AAAiB,OAAe;EAAf;;CAE7B,OAAe;AACb,SAAO;;CAGT,cAAiC;AAC/B,SAAO,QAAQ,QAAQ,CACrB;GAAC,KAAK;GAAiB,OAAO,UAAU,KAAK;GAAQ,CACtD,CAAC"}
@@ -1,23 +1,18 @@
1
- /**
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 type { TokenCredentials } from '../auth';
1
+ import { TokenCredentials } from "../auth.js";
2
+
3
+ //#region src/credentials/u2m.d.ts
9
4
  /** Options for the Databricks CLI auth strategy. */
10
- export interface U2mCredentialsOptions {
11
- /**
12
- * The Databricks CLI profile name, as configured via `databricks auth
13
- * login`.
14
- */
15
- profile: string;
16
- /**
17
- * Path to the `databricks` CLI binary. If omitted, the binary is searched
18
- * for in `PATH`.
19
- */
20
- cliPath?: string;
5
+ interface U2mCredentialsOptions {
6
+ /**
7
+ * The Databricks CLI profile name, as configured via `databricks auth
8
+ * login`.
9
+ */
10
+ profile: string;
11
+ /**
12
+ * Path to the `databricks` CLI binary. If omitted, the binary is searched
13
+ * for in `PATH`.
14
+ */
15
+ cliPath?: string;
21
16
  }
22
17
  /**
23
18
  * Creates a TokenCredentials that obtains Databricks access tokens by
@@ -27,5 +22,7 @@ export interface U2mCredentialsOptions {
27
22
  * @throws U2mCredentialsError when `profile` is empty, or when the CLI cannot
28
23
  * be located, is out of date, or fails to return a usable token.
29
24
  */
30
- export declare function newU2mCredentials(options: U2mCredentialsOptions): TokenCredentials;
25
+ declare function newU2mCredentials(options: U2mCredentialsOptions): TokenCredentials;
26
+ //#endregion
27
+ export { U2mCredentialsOptions, newU2mCredentials };
31
28
  //# sourceMappingURL=u2m.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"u2m.d.ts","sourceRoot":"","sources":["../../src/credentials/u2m.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,OAAO,KAAK,EAAQ,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAarD,oDAAoD;AACpD,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,qBAAqB,GAC7B,gBAAgB,CAMlB"}
1
+ {"version":3,"file":"u2m.d.ts","names":[],"sources":["../../src/credentials/u2m.ts"],"mappings":";;;AAoDA;AAAA,UAtBiB,qBAAA;;;;;EAKf,OAAA;EAmBiB;;;;EAbjB,OAAA;AAAA;;;;;;;;;iBAWc,iBAAA,CACd,OAAA,EAAS,qBAAA,GACR,gBAAA"}