@dbx-tools/auth 0.6.180 → 0.9.28

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 (53) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +116 -32
  3. package/index.ts +26 -2
  4. package/lib/exports.d.ts +2 -0
  5. package/lib/exports.js +3 -0
  6. package/lib/index.d.ts +27 -0
  7. package/lib/index.js +26 -1595
  8. package/lib/src/_logging.d.ts +10 -0
  9. package/lib/src/_logging.js +38 -0
  10. package/lib/src/_profile-core.d.ts +28 -0
  11. package/lib/src/_profile-core.js +216 -0
  12. package/lib/src/_profile.d.ts +15 -0
  13. package/lib/src/_profile.js +236 -0
  14. package/lib/src/databricks-auth.d.ts +11 -0
  15. package/lib/src/databricks-auth.js +314 -0
  16. package/lib/src/databricks-cli.d.ts +28 -0
  17. package/lib/src/databricks-cli.js +239 -0
  18. package/lib/src/errors.d.ts +7 -0
  19. package/lib/src/errors.js +14 -0
  20. package/lib/src/generated/databricks-cli-assets.json +33 -0
  21. package/lib/src/http-client.d.ts +23 -0
  22. package/lib/src/http-client.js +116 -0
  23. package/lib/src/lifecycle.d.ts +26 -0
  24. package/lib/src/lifecycle.js +229 -0
  25. package/lib/src/node-storage.d.ts +20 -0
  26. package/lib/src/node-storage.js +207 -0
  27. package/lib/src/personal-access-token.d.ts +11 -0
  28. package/lib/src/personal-access-token.js +30 -0
  29. package/lib/src/service-principal.d.ts +24 -0
  30. package/lib/src/service-principal.js +69 -0
  31. package/lib/src/storage.d.ts +20 -0
  32. package/lib/src/storage.js +98 -0
  33. package/lib/src/types.d.ts +157 -0
  34. package/lib/src/types.js +67 -0
  35. package/lib/tsconfig.tsbuildinfo +1 -0
  36. package/package.json +39 -16
  37. package/src/_logging.ts +42 -0
  38. package/src/_profile-core.ts +258 -0
  39. package/src/_profile.ts +319 -0
  40. package/src/databricks-auth.ts +416 -0
  41. package/src/databricks-cli.ts +298 -0
  42. package/src/errors.ts +16 -0
  43. package/src/generated/databricks-cli-assets.json +33 -0
  44. package/src/http-client.ts +147 -0
  45. package/src/lifecycle.ts +239 -0
  46. package/src/node-storage.ts +230 -0
  47. package/src/personal-access-token.ts +34 -0
  48. package/src/service-principal.ts +96 -0
  49. package/src/storage.ts +104 -0
  50. package/src/types.ts +188 -0
  51. package/src/_bindings-ffi.ts +0 -715
  52. package/src/_bindings.ts +0 -1794
  53. package/src/bindings.ts +0 -12
package/src/types.ts ADDED
@@ -0,0 +1,188 @@
1
+ /** Authentication strategy selected from Databricks configuration. */
2
+ export enum AuthKind {
3
+ UserToMachine = "user-to-machine",
4
+ MachineToMachine = "machine-to-machine",
5
+ PersonalAccessToken = "personal-access-token",
6
+ AppServicePrincipal = "app-service-principal",
7
+ AppOnBehalfOf = "app-on-behalf-of",
8
+ }
9
+
10
+ /** Scope of the Databricks authentication target. */
11
+ export enum TargetKind {
12
+ Workspace = "workspace",
13
+ Account = "account",
14
+ Unified = "unified",
15
+ }
16
+
17
+ /** Built-in credential storage backend. */
18
+ export enum Storage {
19
+ Auto = "auto",
20
+ Memory = "memory",
21
+ File = "file",
22
+ }
23
+
24
+ /** File organization used by a persistent credential store. */
25
+ export enum FileLayout {
26
+ Single = "single",
27
+ PerCredential = "per-credential",
28
+ }
29
+
30
+ /** Stored OAuth credential, including renewal metadata. */
31
+ export interface Token {
32
+ accessToken: string;
33
+ tokenType: string;
34
+ refreshToken?: string;
35
+ expiry?: string;
36
+ scopes: string[];
37
+ }
38
+
39
+ /** Public credential result; deliberately excludes the refresh token. */
40
+ export interface AccessToken {
41
+ accessToken: string;
42
+ tokenType: string;
43
+ expiry?: string;
44
+ scopes: string[];
45
+ }
46
+
47
+ /** Shared lifecycle configuration embedded by every provider. */
48
+ export interface AuthOptions {
49
+ refreshBufferSeconds: number;
50
+ lockTimeoutSeconds: number;
51
+ loginTimeoutSeconds: number;
52
+ }
53
+
54
+ const AUTH_DEFAULTS: AuthOptions = {
55
+ refreshBufferSeconds: 300,
56
+ lockTimeoutSeconds: 30,
57
+ loginTimeoutSeconds: 900,
58
+ };
59
+
60
+ /** Record-style factory retained for straightforward Node/Python bridging. */
61
+ export const AuthOptions = {
62
+ create(options: Partial<AuthOptions> = {}): AuthOptions {
63
+ return { ...AUTH_DEFAULTS, ...options };
64
+ },
65
+ defaults(): Readonly<AuthOptions> {
66
+ return Object.freeze({ ...AUTH_DEFAULTS });
67
+ },
68
+ };
69
+
70
+ /** Secret-free metadata discovered from one Databricks CLI profile. */
71
+ export interface DatabricksProfileSummary {
72
+ name: string;
73
+ host?: string;
74
+ accountId?: string;
75
+ workspaceId?: string;
76
+ target: TargetKind;
77
+ authKind: AuthKind;
78
+ }
79
+
80
+ /** Resolved Databricks identity and active storage backend. */
81
+ export interface DatabricksAuthStatus {
82
+ profile: string;
83
+ host: string;
84
+ storage: Storage;
85
+ }
86
+
87
+ /** Public Databricks authentication options. */
88
+ export interface DatabricksAuthOptions {
89
+ profile?: string;
90
+ host?: string;
91
+ accountId?: string;
92
+ workspaceId?: string;
93
+ configFile?: string;
94
+ clientId?: string;
95
+ clientSecret?: string;
96
+ accessToken?: string;
97
+ groupId?: string;
98
+ authType?: string;
99
+ scopes?: string[];
100
+ target?: string;
101
+ cacheDir?: string;
102
+ auth?: AuthOptions;
103
+ requestHeaders?: Record<string, string>;
104
+ accessTokenHeader?: string;
105
+ installCliInApp?: boolean;
106
+ preferUserToMachine: boolean;
107
+ }
108
+
109
+ /** Record-style factory retained for callers migrating from generated bindings. */
110
+ export const DatabricksAuthOptions = {
111
+ create(options: Partial<DatabricksAuthOptions> = {}): DatabricksAuthOptions {
112
+ return { preferUserToMachine: true, ...options };
113
+ },
114
+ defaults(): Readonly<DatabricksAuthOptions> {
115
+ return Object.freeze({ preferUserToMachine: true });
116
+ },
117
+ };
118
+
119
+ /** Resolved profile with secrets retained only for provider construction. */
120
+ export interface DatabricksProfile extends DatabricksProfileSummary {
121
+ host: string;
122
+ authType?: string;
123
+ clientId: string;
124
+ groupId?: string;
125
+ scopes: string[];
126
+ clientSecret?: string;
127
+ accessToken?: string;
128
+ cacheKey: string;
129
+ principal: string;
130
+ }
131
+
132
+ /** Cross-language lease adapter; implementations may use files, databases, or FFI. */
133
+ export interface LockAdapter {
134
+ acquire(key: string, timeoutMs: number): Promise<string>;
135
+ release(lease: string): Promise<void>;
136
+ }
137
+
138
+ /** Cross-language credential persistence contract. */
139
+ export interface CredentialStore {
140
+ load(key: string): Promise<Token | undefined>;
141
+ prepareWrite(): Promise<void>;
142
+ save(key: string, token: Token): Promise<void>;
143
+ remove(key: string): Promise<void>;
144
+ acquireLock(key: string, timeoutMs: number): Promise<string>;
145
+ releaseLock(lease: string): Promise<void>;
146
+ name(): string;
147
+ }
148
+
149
+ /** Provider-specific token acquisition. */
150
+ export interface TokenProvider {
151
+ authenticate(timeoutMs: number): Promise<Token>;
152
+ login(timeoutMs: number): Promise<Token>;
153
+ refresh(token: Token): Promise<Token>;
154
+ canAuthenticateSilently(): boolean;
155
+ }
156
+
157
+ /** Stable facade shared by Node, the CLI, and generated language bindings. */
158
+ export interface AuthClient {
159
+ challenge(): Promise<void>;
160
+ token(login?: boolean): Promise<AccessToken>;
161
+ authenticate(login?: boolean): Promise<Record<string, string>>;
162
+ authorizationHeaderForUrl(requestUrl: string, login?: boolean): Promise<string | undefined>;
163
+ requestHeadersForUrl(requestUrl: string, login?: boolean): Promise<Record<string, string>>;
164
+ forceRefreshToken(login?: boolean): Promise<AccessToken>;
165
+ refreshRejectedToken(staleAccessToken: string, login?: boolean): Promise<AccessToken>;
166
+ logout(): Promise<void>;
167
+ status(): DatabricksAuthStatus;
168
+ principal(): string;
169
+ workspaceId(): string | undefined;
170
+ authKind(): AuthKind;
171
+ profile(name?: string): DatabricksProfileSummary;
172
+ listProfiles(refresh?: boolean): DatabricksProfileSummary[];
173
+ }
174
+
175
+ /** Public OAuth client used by Databricks CLI-compatible user authentication. */
176
+ export const DEFAULT_CLIENT_ID = "databricks-cli";
177
+ /** Default Databricks profile configuration path. */
178
+ export const DEFAULT_CONFIG_FILE = "~/.databrickscfg";
179
+ /** Default Databricks account console origin. */
180
+ export const DEFAULT_ACCOUNTS_HOST = "https://accounts.cloud.databricks.com";
181
+ /** Canonical request header carrying a bearer access token. */
182
+ export const DEFAULT_ACCESS_TOKEN_HEADER = "authorization";
183
+ /** Canonical request header carrying the resolved Databricks workspace ID. */
184
+ export const WORKSPACE_ID_HEADER = "x-databricks-workspace-id";
185
+ /** Authentication type for Databricks App on-behalf-of request credentials. */
186
+ export const AUTH_TYPE_APP_OBO = "app_obo";
187
+ /** Authentication type for Databricks App service-principal credentials. */
188
+ export const AUTH_TYPE_APP_SP = "app_sp";