@databricks/sql 1.2.1 → 1.3.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/DBSQLClient.d.ts +7 -6
- package/dist/DBSQLClient.js +91 -59
- package/dist/DBSQLClient.js.map +1 -1
- package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.d.ts +24 -0
- package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js +165 -0
- package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js.map +1 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthManager.d.ts +47 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthManager.js +169 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthManager.js.map +1 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthPersistence.d.ts +10 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthPersistence.js +29 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthPersistence.js.map +1 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthScope.d.ts +7 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthScope.js +11 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthScope.js.map +1 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthToken.d.ts +10 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthToken.js +32 -0
- package/dist/connection/auth/DatabricksOAuth/OAuthToken.js.map +1 -0
- package/dist/connection/auth/DatabricksOAuth/index.d.ts +21 -0
- package/dist/connection/auth/DatabricksOAuth/index.js +41 -0
- package/dist/connection/auth/DatabricksOAuth/index.js.map +1 -0
- package/dist/connection/auth/PlainHttpAuthentication.d.ts +11 -11
- package/dist/connection/auth/PlainHttpAuthentication.js +15 -7
- package/dist/connection/auth/PlainHttpAuthentication.js.map +1 -1
- package/dist/connection/connections/HttpConnection.d.ts +1 -2
- package/dist/connection/connections/HttpConnection.js +24 -14
- package/dist/connection/connections/HttpConnection.js.map +1 -1
- package/dist/connection/contracts/IAuthentication.d.ts +2 -2
- package/dist/connection/contracts/IConnectionOptions.d.ts +3 -1
- package/dist/connection/contracts/IConnectionProvider.d.ts +1 -2
- package/dist/contracts/IDBSQLClient.d.ts +17 -3
- package/dist/globalConfig.d.ts +5 -0
- package/dist/globalConfig.js +5 -0
- package/dist/globalConfig.js.map +1 -1
- package/dist/hive/Commands/BaseCommand.d.ts +3 -1
- package/dist/hive/Commands/BaseCommand.js +66 -4
- package/dist/hive/Commands/BaseCommand.js.map +1 -1
- package/dist/hive/HiveDriver.d.ts +3 -2
- package/dist/hive/HiveDriver.js +116 -44
- package/dist/hive/HiveDriver.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js +8 -0
- package/dist/result/ArrowResult.js +3 -0
- package/dist/result/ArrowResult.js.map +1 -1
- package/dist/utils/areHeadersEqual.d.ts +2 -0
- package/dist/utils/areHeadersEqual.js +49 -0
- package/dist/utils/areHeadersEqual.js.map +1 -0
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -2
- package/thrift/TCLIService.d.ts +17 -0
- package/thrift/TCLIService_types.d.ts +185 -13
- package/thrift/TCLIService_types.js +2013 -279
- package/dist/connection/auth/NoSaslAuthentication.d.ts +0 -5
- package/dist/connection/auth/NoSaslAuthentication.js +0 -14
- package/dist/connection/auth/NoSaslAuthentication.js.map +0 -1
- package/dist/connection/auth/helpers/SaslPackageFactory.d.ts +0 -11
- package/dist/connection/auth/helpers/SaslPackageFactory.js +0 -20
- package/dist/connection/auth/helpers/SaslPackageFactory.js.map +0 -1
- package/dist/connection/contracts/ITransport.d.ts +0 -6
- package/dist/connection/contracts/ITransport.js +0 -3
- package/dist/connection/contracts/ITransport.js.map +0 -1
- package/dist/connection/transports/HttpTransport.d.ts +0 -8
- package/dist/connection/transports/HttpTransport.js +0 -18
- package/dist/connection/transports/HttpTransport.js.map +0 -1
- package/dist/connection/types/AuthOptions.d.ts +0 -4
- package/dist/connection/types/AuthOptions.js +0 -3
- package/dist/connection/types/AuthOptions.js.map +0 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AzureOAuthManager = exports.AWSOAuthManager = void 0;
|
|
16
|
+
const openid_client_1 = require("openid-client");
|
|
17
|
+
const HiveDriverError_1 = __importDefault(require("../../../errors/HiveDriverError"));
|
|
18
|
+
const IDBSQLLogger_1 = require("../../../contracts/IDBSQLLogger");
|
|
19
|
+
const OAuthToken_1 = __importDefault(require("./OAuthToken"));
|
|
20
|
+
const AuthorizationCode_1 = __importDefault(require("./AuthorizationCode"));
|
|
21
|
+
const OAuthScope_1 = require("./OAuthScope");
|
|
22
|
+
function getDatabricksOIDCUrl(host) {
|
|
23
|
+
const schema = host.startsWith('https://') ? '' : 'https://';
|
|
24
|
+
const trailingSlash = host.endsWith('/') ? '' : '/';
|
|
25
|
+
return `${schema}${host}${trailingSlash}oidc`;
|
|
26
|
+
}
|
|
27
|
+
class OAuthManager {
|
|
28
|
+
constructor(options) {
|
|
29
|
+
this.options = options;
|
|
30
|
+
this.logger = options.logger;
|
|
31
|
+
}
|
|
32
|
+
getScopes(requestedScopes) {
|
|
33
|
+
return requestedScopes;
|
|
34
|
+
}
|
|
35
|
+
getClient() {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
if (!this.issuer) {
|
|
38
|
+
const issuer = yield openid_client_1.Issuer.discover(this.getOIDCConfigUrl());
|
|
39
|
+
// Overwrite `authorization_endpoint` in default config (specifically needed for Azure flow
|
|
40
|
+
// where this URL has to be different)
|
|
41
|
+
this.issuer = new openid_client_1.Issuer(Object.assign(Object.assign({}, issuer.metadata), { authorization_endpoint: this.getAuthorizationUrl() }));
|
|
42
|
+
}
|
|
43
|
+
if (!this.client) {
|
|
44
|
+
this.client = new this.issuer.Client({
|
|
45
|
+
client_id: this.getClientId(),
|
|
46
|
+
token_endpoint_auth_method: 'none',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return this.client;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
refreshAccessToken(token) {
|
|
53
|
+
var _a, _b, _c;
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
try {
|
|
56
|
+
if (!token.hasExpired) {
|
|
57
|
+
// The access token is fine. Just return it.
|
|
58
|
+
return token;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(IDBSQLLogger_1.LogLevel.error, `${error}`);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
if (!token.refreshToken) {
|
|
66
|
+
const message = `OAuth access token expired on ${token.expirationTime}.`;
|
|
67
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.log(IDBSQLLogger_1.LogLevel.error, message);
|
|
68
|
+
throw new HiveDriverError_1.default(message);
|
|
69
|
+
}
|
|
70
|
+
// Try to refresh using the refresh token
|
|
71
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.log(IDBSQLLogger_1.LogLevel.debug, `Attempting to refresh OAuth access token that expired on ${token.expirationTime}`);
|
|
72
|
+
const client = yield this.getClient();
|
|
73
|
+
const { access_token: accessToken, refresh_token: refreshToken } = yield client.refresh(token.refreshToken);
|
|
74
|
+
if (!accessToken || !refreshToken) {
|
|
75
|
+
throw new Error('Failed to refresh token: invalid response');
|
|
76
|
+
}
|
|
77
|
+
return new OAuthToken_1.default(accessToken, refreshToken);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
getToken(scopes) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const client = yield this.getClient();
|
|
83
|
+
const authCode = new AuthorizationCode_1.default({
|
|
84
|
+
client,
|
|
85
|
+
ports: this.getCallbackPorts(),
|
|
86
|
+
logger: this.logger,
|
|
87
|
+
});
|
|
88
|
+
const mappedScopes = this.getScopes(scopes);
|
|
89
|
+
const { code, verifier, redirectUri } = yield authCode.fetch(mappedScopes);
|
|
90
|
+
const { access_token: accessToken, refresh_token: refreshToken } = yield client.grant({
|
|
91
|
+
grant_type: 'authorization_code',
|
|
92
|
+
code,
|
|
93
|
+
code_verifier: verifier,
|
|
94
|
+
redirect_uri: redirectUri,
|
|
95
|
+
});
|
|
96
|
+
if (!accessToken) {
|
|
97
|
+
throw new Error('Failed to fetch access token');
|
|
98
|
+
}
|
|
99
|
+
return new OAuthToken_1.default(accessToken, refreshToken);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
static getManager(options) {
|
|
103
|
+
// normalize
|
|
104
|
+
const host = options.host.toLowerCase().replace('https://', '').split('/')[0];
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
106
|
+
const managers = [AWSOAuthManager, AzureOAuthManager];
|
|
107
|
+
for (const OAuthManagerClass of managers) {
|
|
108
|
+
for (const domain of OAuthManagerClass.domains) {
|
|
109
|
+
if (host.endsWith(domain)) {
|
|
110
|
+
return new OAuthManagerClass(options);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
throw new Error(`OAuth is not supported for ${options.host}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.default = OAuthManager;
|
|
118
|
+
class AWSOAuthManager extends OAuthManager {
|
|
119
|
+
getOIDCConfigUrl() {
|
|
120
|
+
return `${getDatabricksOIDCUrl(this.options.host)}/.well-known/oauth-authorization-server`;
|
|
121
|
+
}
|
|
122
|
+
getAuthorizationUrl() {
|
|
123
|
+
return `${getDatabricksOIDCUrl(this.options.host)}/oauth2/v2.0/authorize`;
|
|
124
|
+
}
|
|
125
|
+
getClientId() {
|
|
126
|
+
var _a;
|
|
127
|
+
return (_a = this.options.clientId) !== null && _a !== void 0 ? _a : AWSOAuthManager.defaultClientId;
|
|
128
|
+
}
|
|
129
|
+
getCallbackPorts() {
|
|
130
|
+
var _a;
|
|
131
|
+
return (_a = this.options.callbackPorts) !== null && _a !== void 0 ? _a : AWSOAuthManager.defaultCallbackPorts;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.AWSOAuthManager = AWSOAuthManager;
|
|
135
|
+
AWSOAuthManager.domains = ['.cloud.databricks.com', '.dev.databricks.com'];
|
|
136
|
+
AWSOAuthManager.defaultClientId = 'databricks-sql-connector';
|
|
137
|
+
AWSOAuthManager.defaultCallbackPorts = [8030];
|
|
138
|
+
class AzureOAuthManager extends OAuthManager {
|
|
139
|
+
getOIDCConfigUrl() {
|
|
140
|
+
return 'https://login.microsoftonline.com/organizations/v2.0/.well-known/openid-configuration';
|
|
141
|
+
}
|
|
142
|
+
getAuthorizationUrl() {
|
|
143
|
+
return `${getDatabricksOIDCUrl(this.options.host)}/oauth2/v2.0/authorize`;
|
|
144
|
+
}
|
|
145
|
+
getClientId() {
|
|
146
|
+
var _a;
|
|
147
|
+
return (_a = this.options.clientId) !== null && _a !== void 0 ? _a : AzureOAuthManager.defaultClientId;
|
|
148
|
+
}
|
|
149
|
+
getCallbackPorts() {
|
|
150
|
+
var _a;
|
|
151
|
+
return (_a = this.options.callbackPorts) !== null && _a !== void 0 ? _a : AzureOAuthManager.defaultCallbackPorts;
|
|
152
|
+
}
|
|
153
|
+
getScopes(requestedScopes) {
|
|
154
|
+
var _a;
|
|
155
|
+
// There is no corresponding scopes in Azure, instead, access control will be delegated to Databricks
|
|
156
|
+
const tenantId = (_a = this.options.azureTenantId) !== null && _a !== void 0 ? _a : AzureOAuthManager.datatricksAzureApp;
|
|
157
|
+
const azureScopes = [`${tenantId}/user_impersonation`];
|
|
158
|
+
if (requestedScopes.includes(OAuthScope_1.OAuthScope.offlineAccess)) {
|
|
159
|
+
azureScopes.push(OAuthScope_1.OAuthScope.offlineAccess);
|
|
160
|
+
}
|
|
161
|
+
return azureScopes;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.AzureOAuthManager = AzureOAuthManager;
|
|
165
|
+
AzureOAuthManager.domains = ['.azuredatabricks.net', '.databricks.azure.cn', '.databricks.azure.us'];
|
|
166
|
+
AzureOAuthManager.defaultClientId = '96eecda7-19ea-49cc-abb5-240097d554f5';
|
|
167
|
+
AzureOAuthManager.defaultCallbackPorts = [8030];
|
|
168
|
+
AzureOAuthManager.datatricksAzureApp = '2ff814a6-3304-4ab8-85cb-cd0e6f879c1d';
|
|
169
|
+
//# sourceMappingURL=OAuthManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OAuthManager.js","sourceRoot":"","sources":["../../../../lib/connection/auth/DatabricksOAuth/OAuthManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iDAAmD;AACnD,sFAA8D;AAC9D,kEAAyE;AACzE,8DAAsC;AACtC,4EAAoD;AACpD,6CAAuD;AAUvD,SAAS,oBAAoB,CAAC,IAAY;IACxC,MAAM,MAAM,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,CAAC,CAAC;SAC5C;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;;AAnCH,8CAoCC;AAnCe,yBAAO,GAAG,CAAC,sBAAsB,EAAE,sBAAsB,EAAE,sBAAsB,CAAC,CAAC;AAEnF,iCAAe,GAAG,sCAAsC,CAAC;AAEzD,sCAAoB,GAAG,CAAC,IAAI,CAAC,CAAC;AAE9B,oCAAkB,GAAG,sCAAsC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import OAuthToken from './OAuthToken';
|
|
2
|
+
export default interface OAuthPersistence {
|
|
3
|
+
persist(host: string, token: OAuthToken): Promise<void>;
|
|
4
|
+
read(host: string): Promise<OAuthToken | undefined>;
|
|
5
|
+
}
|
|
6
|
+
export declare class OAuthPersistenceCache implements OAuthPersistence {
|
|
7
|
+
private tokens;
|
|
8
|
+
persist(host: string, token: OAuthToken): Promise<void>;
|
|
9
|
+
read(host: string): Promise<OAuthToken | undefined>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.OAuthPersistenceCache = void 0;
|
|
13
|
+
class OAuthPersistenceCache {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.tokens = {};
|
|
16
|
+
}
|
|
17
|
+
persist(host, token) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
this.tokens[host] = token;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
read(host) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return this.tokens[host];
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.OAuthPersistenceCache = OAuthPersistenceCache;
|
|
29
|
+
//# sourceMappingURL=OAuthPersistence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OAuthPersistence.js","sourceRoot":"","sources":["../../../../lib/connection/auth/DatabricksOAuth/OAuthPersistence.ts"],"names":[],"mappings":";;;;;;;;;;;;AAQA,MAAa,qBAAqB;IAAlC;QACU,WAAM,GAA2C,EAAE,CAAC;IAS9D,CAAC;IAPO,OAAO,CAAC,IAAY,EAAE,KAAiB;;YAC3C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC5B,CAAC;KAAA;IAEK,IAAI,CAAC,IAAY;;YACrB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;KAAA;CACF;AAVD,sDAUC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.scopeDelimiter = exports.defaultOAuthScopes = exports.OAuthScope = void 0;
|
|
4
|
+
var OAuthScope;
|
|
5
|
+
(function (OAuthScope) {
|
|
6
|
+
OAuthScope["offlineAccess"] = "offline_access";
|
|
7
|
+
OAuthScope["SQL"] = "sql";
|
|
8
|
+
})(OAuthScope = exports.OAuthScope || (exports.OAuthScope = {}));
|
|
9
|
+
exports.defaultOAuthScopes = [OAuthScope.SQL, OAuthScope.offlineAccess];
|
|
10
|
+
exports.scopeDelimiter = ' ';
|
|
11
|
+
//# sourceMappingURL=OAuthScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OAuthScope.js","sourceRoot":"","sources":["../../../../lib/connection/auth/DatabricksOAuth/OAuthScope.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,8CAAgC,CAAA;IAChC,yBAAW,CAAA;AACb,CAAC,EAHW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAGrB;AAIY,QAAA,kBAAkB,GAAgB,CAAC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC;AAE7E,QAAA,cAAc,GAAG,GAAG,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default class OAuthToken {
|
|
2
|
+
private readonly _accessToken;
|
|
3
|
+
private readonly _refreshToken?;
|
|
4
|
+
private _expirationTime?;
|
|
5
|
+
constructor(accessToken: string, refreshToken?: string);
|
|
6
|
+
get accessToken(): string;
|
|
7
|
+
get refreshToken(): string | undefined;
|
|
8
|
+
get expirationTime(): number;
|
|
9
|
+
get hasExpired(): boolean;
|
|
10
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class OAuthToken {
|
|
4
|
+
constructor(accessToken, refreshToken) {
|
|
5
|
+
this._accessToken = accessToken;
|
|
6
|
+
this._refreshToken = refreshToken;
|
|
7
|
+
}
|
|
8
|
+
get accessToken() {
|
|
9
|
+
return this._accessToken;
|
|
10
|
+
}
|
|
11
|
+
get refreshToken() {
|
|
12
|
+
return this._refreshToken;
|
|
13
|
+
}
|
|
14
|
+
get expirationTime() {
|
|
15
|
+
// This token has already been verified, and we are just parsing it.
|
|
16
|
+
// If it has been tampered with, it will be rejected on the server side.
|
|
17
|
+
// This avoids having to fetch the public key from the issuer and perform
|
|
18
|
+
// an unnecessary signature verification.
|
|
19
|
+
if (this._expirationTime === undefined) {
|
|
20
|
+
const accessTokenPayload = Buffer.from(this._accessToken.split('.')[1], 'base64').toString('utf8');
|
|
21
|
+
const decoded = JSON.parse(accessTokenPayload);
|
|
22
|
+
this._expirationTime = Number(decoded.exp);
|
|
23
|
+
}
|
|
24
|
+
return this._expirationTime;
|
|
25
|
+
}
|
|
26
|
+
get hasExpired() {
|
|
27
|
+
const now = Math.floor(Date.now() / 1000); // convert it to seconds
|
|
28
|
+
return this.expirationTime <= now;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.default = OAuthToken;
|
|
32
|
+
//# sourceMappingURL=OAuthToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OAuthToken.js","sourceRoot":"","sources":["../../../../lib/connection/auth/DatabricksOAuth/OAuthToken.ts"],"names":[],"mappings":";;AAAA,MAAqB,UAAU;IAO7B,YAAY,WAAmB,EAAE,YAAqB;QACpD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED,IAAI,cAAc;QAChB,oEAAoE;QACpE,wEAAwE;QACxE,yEAAyE;QACzE,yCAAyC;QACzC,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS,EAAE;YACtC,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YACnG,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;YAC/C,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;SAC5C;QACD,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED,IAAI,UAAU;QACZ,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,wBAAwB;QACnE,OAAO,IAAI,CAAC,cAAc,IAAI,GAAG,CAAC;IACpC,CAAC;CACF;AArCD,6BAqCC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HttpHeaders } from 'thrift';
|
|
2
|
+
import IAuthentication from '../../contracts/IAuthentication';
|
|
3
|
+
import IDBSQLLogger from '../../../contracts/IDBSQLLogger';
|
|
4
|
+
import OAuthPersistence from './OAuthPersistence';
|
|
5
|
+
import { OAuthManagerOptions } from './OAuthManager';
|
|
6
|
+
import { OAuthScopes } from './OAuthScope';
|
|
7
|
+
interface DatabricksOAuthOptions extends OAuthManagerOptions {
|
|
8
|
+
scopes?: OAuthScopes;
|
|
9
|
+
logger?: IDBSQLLogger;
|
|
10
|
+
persistence?: OAuthPersistence;
|
|
11
|
+
headers?: HttpHeaders;
|
|
12
|
+
}
|
|
13
|
+
export default class DatabricksOAuth implements IAuthentication {
|
|
14
|
+
private readonly options;
|
|
15
|
+
private readonly logger?;
|
|
16
|
+
private readonly manager;
|
|
17
|
+
private readonly defaultPersistence;
|
|
18
|
+
constructor(options: DatabricksOAuthOptions);
|
|
19
|
+
authenticate(): Promise<HttpHeaders>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const OAuthPersistence_1 = require("./OAuthPersistence");
|
|
16
|
+
const OAuthManager_1 = __importDefault(require("./OAuthManager"));
|
|
17
|
+
const OAuthScope_1 = require("./OAuthScope");
|
|
18
|
+
class DatabricksOAuth {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.defaultPersistence = new OAuthPersistence_1.OAuthPersistenceCache();
|
|
21
|
+
this.options = options;
|
|
22
|
+
this.logger = options.logger;
|
|
23
|
+
this.manager = OAuthManager_1.default.getManager(this.options);
|
|
24
|
+
}
|
|
25
|
+
authenticate() {
|
|
26
|
+
var _a;
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const { host, scopes, headers } = this.options;
|
|
29
|
+
const persistence = (_a = this.options.persistence) !== null && _a !== void 0 ? _a : this.defaultPersistence;
|
|
30
|
+
let token = yield persistence.read(host);
|
|
31
|
+
if (!token) {
|
|
32
|
+
token = yield this.manager.getToken(scopes !== null && scopes !== void 0 ? scopes : OAuthScope_1.defaultOAuthScopes);
|
|
33
|
+
}
|
|
34
|
+
token = yield this.manager.refreshAccessToken(token);
|
|
35
|
+
yield persistence.persist(host, token);
|
|
36
|
+
return Object.assign(Object.assign({}, headers), { Authorization: `Bearer ${token.accessToken}` });
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.default = DatabricksOAuth;
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lib/connection/auth/DatabricksOAuth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAGA,yDAA6E;AAC7E,kEAAmE;AACnE,6CAA+D;AAS/D,MAAqB,eAAe;IASlC,YAAY,OAA+B;QAF1B,uBAAkB,GAAG,IAAI,wCAAqB,EAAE,CAAC;QAGhE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,sBAAY,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IAEY,YAAY;;;YACvB,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;YAE/C,MAAM,WAAW,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,WAAW,mCAAI,IAAI,CAAC,kBAAkB,CAAC;YAExE,IAAI,KAAK,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACzC,IAAI,CAAC,KAAK,EAAE;gBACV,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,+BAAkB,CAAC,CAAC;aACnE;YAED,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;YACrD,MAAM,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAEvC,uCACK,OAAO,KACV,aAAa,EAAE,UAAU,KAAK,CAAC,WAAW,EAAE,IAC5C;;KACH;CACF;AAjCD,kCAiCC"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { HttpHeaders } from 'thrift';
|
|
1
2
|
import IAuthentication from '../contracts/IAuthentication';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
headers?:
|
|
6
|
-
}
|
|
3
|
+
interface PlainHttpAuthenticationOptions {
|
|
4
|
+
username?: string;
|
|
5
|
+
password?: string;
|
|
6
|
+
headers?: HttpHeaders;
|
|
7
|
+
}
|
|
7
8
|
export default class PlainHttpAuthentication implements IAuthentication {
|
|
8
|
-
private username;
|
|
9
|
-
private password;
|
|
10
|
-
private headers;
|
|
11
|
-
constructor(options:
|
|
12
|
-
authenticate(
|
|
13
|
-
private getToken;
|
|
9
|
+
private readonly username;
|
|
10
|
+
private readonly password;
|
|
11
|
+
private readonly headers;
|
|
12
|
+
constructor(options: PlainHttpAuthenticationOptions);
|
|
13
|
+
authenticate(): Promise<HttpHeaders>;
|
|
14
14
|
}
|
|
15
15
|
export {};
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
class PlainHttpAuthentication {
|
|
4
13
|
constructor(options) {
|
|
14
|
+
var _a;
|
|
5
15
|
this.username = (options === null || options === void 0 ? void 0 : options.username) || 'anonymous';
|
|
6
|
-
this.password = (options === null || options === void 0 ? void 0 : options.password) !==
|
|
16
|
+
this.password = (_a = options === null || options === void 0 ? void 0 : options.password) !== null && _a !== void 0 ? _a : 'anonymous';
|
|
7
17
|
this.headers = (options === null || options === void 0 ? void 0 : options.headers) || {};
|
|
8
18
|
}
|
|
9
|
-
authenticate(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
getToken(username, password) {
|
|
14
|
-
return `Bearer ${password}`;
|
|
19
|
+
authenticate() {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
return Object.assign(Object.assign({}, this.headers), { Authorization: `Bearer ${this.password}` });
|
|
22
|
+
});
|
|
15
23
|
}
|
|
16
24
|
}
|
|
17
25
|
exports.default = PlainHttpAuthentication;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlainHttpAuthentication.js","sourceRoot":"","sources":["../../../lib/connection/auth/PlainHttpAuthentication.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlainHttpAuthentication.js","sourceRoot":"","sources":["../../../lib/connection/auth/PlainHttpAuthentication.ts"],"names":[],"mappings":";;;;;;;;;;;AASA,MAAqB,uBAAuB;IAO1C,YAAY,OAAuC;;QACjD,IAAI,CAAC,QAAQ,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,KAAI,WAAW,CAAC;QACjD,IAAI,CAAC,QAAQ,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,mCAAI,WAAW,CAAC;QACjD,IAAI,CAAC,OAAO,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,KAAI,EAAE,CAAC;IACxC,CAAC;IAEY,YAAY;;YACvB,uCACK,IAAI,CAAC,OAAO,KACf,aAAa,EAAE,UAAU,IAAI,CAAC,QAAQ,EAAE,IACxC;QACJ,CAAC;KAAA;CACF;AAnBD,0CAmBC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import IThriftConnection from '../contracts/IThriftConnection';
|
|
2
2
|
import IConnectionProvider from '../contracts/IConnectionProvider';
|
|
3
3
|
import IConnectionOptions from '../contracts/IConnectionOptions';
|
|
4
|
-
import IAuthentication from '../contracts/IAuthentication';
|
|
5
4
|
export default class HttpConnection implements IConnectionProvider, IThriftConnection {
|
|
6
5
|
private thrift;
|
|
7
6
|
private connection;
|
|
8
|
-
connect(options: IConnectionOptions
|
|
7
|
+
connect(options: IConnectionOptions): Promise<IThriftConnection>;
|
|
9
8
|
getConnection(): any;
|
|
10
9
|
isConnected(): boolean;
|
|
11
10
|
private getNodeOptions;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -6,24 +15,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
15
|
const thrift_1 = __importDefault(require("thrift"));
|
|
7
16
|
const https_1 = __importDefault(require("https"));
|
|
8
17
|
const http_1 = __importDefault(require("http"));
|
|
9
|
-
const
|
|
18
|
+
const globalConfig_1 = __importDefault(require("../../globalConfig"));
|
|
10
19
|
class HttpConnection {
|
|
11
20
|
constructor() {
|
|
12
21
|
this.thrift = thrift_1.default;
|
|
13
22
|
}
|
|
14
|
-
connect(options
|
|
15
|
-
var _a, _b;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
connect(options) {
|
|
24
|
+
var _a, _b, _c, _d, _e, _f;
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const agentOptions = {
|
|
27
|
+
keepAlive: true,
|
|
28
|
+
maxSockets: 5,
|
|
29
|
+
keepAliveMsecs: 10000,
|
|
30
|
+
timeout: (_b = (_a = options.options) === null || _a === void 0 ? void 0 : _a.socketTimeout) !== null && _b !== void 0 ? _b : globalConfig_1.default.socketTimeout,
|
|
31
|
+
};
|
|
32
|
+
const agent = ((_c = options.options) === null || _c === void 0 ? void 0 : _c.https)
|
|
33
|
+
? new https_1.default.Agent(Object.assign(Object.assign({}, agentOptions), { minVersion: 'TLSv1.2' }))
|
|
34
|
+
: new http_1.default.Agent(agentOptions);
|
|
35
|
+
const thriftOptions = Object.assign(Object.assign({ transport: thrift_1.default.TBufferedTransport, protocol: thrift_1.default.TBinaryProtocol }, options.options), { nodeOptions: Object.assign(Object.assign(Object.assign({ agent }, this.getNodeOptions(options.options || {})), (((_d = options.options) === null || _d === void 0 ? void 0 : _d.nodeOptions) || {})), { timeout: (_f = (_e = options.options) === null || _e === void 0 ? void 0 : _e.socketTimeout) !== null && _f !== void 0 ? _f : globalConfig_1.default.socketTimeout }) });
|
|
36
|
+
this.connection = this.thrift.createHttpConnection(options.host, options.port, thriftOptions);
|
|
27
37
|
this.addCookieHandler();
|
|
28
38
|
return this;
|
|
29
39
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpConnection.js","sourceRoot":"","sources":["../../../lib/connection/connections/HttpConnection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HttpConnection.js","sourceRoot":"","sources":["../../../lib/connection/connections/HttpConnection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,oDAA4B;AAC5B,kDAA0B;AAC1B,gDAA6C;AAK7C,sEAA8C;AAS9C,MAAqB,cAAc;IAAnC;QACU,W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|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { HttpHeaders } from 'thrift';
|
|
2
3
|
export type Options = {
|
|
4
|
+
socketTimeout?: number;
|
|
3
5
|
username?: string;
|
|
4
6
|
password?: string;
|
|
5
7
|
ssl?: boolean;
|
|
@@ -9,7 +11,7 @@ export type Options = {
|
|
|
9
11
|
retry_max_delay?: number;
|
|
10
12
|
connect_timeout?: number;
|
|
11
13
|
timeout?: number;
|
|
12
|
-
headers?:
|
|
14
|
+
headers?: HttpHeaders;
|
|
13
15
|
path?: string;
|
|
14
16
|
ca?: Buffer | string;
|
|
15
17
|
cert?: Buffer | string;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import IConnectionOptions from './IConnectionOptions';
|
|
2
|
-
import IAuthentication from './IAuthentication';
|
|
3
2
|
import IThriftConnection from './IThriftConnection';
|
|
4
3
|
export default interface IConnectionProvider {
|
|
5
|
-
connect(options: IConnectionOptions
|
|
4
|
+
connect(options: IConnectionOptions): Promise<IThriftConnection>;
|
|
6
5
|
}
|
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import IDBSQLLogger from './IDBSQLLogger';
|
|
2
2
|
import IDBSQLSession from './IDBSQLSession';
|
|
3
|
+
import IAuthentication from '../connection/contracts/IAuthentication';
|
|
4
|
+
import OAuthPersistence from '../connection/auth/DatabricksOAuth/OAuthPersistence';
|
|
3
5
|
export interface ClientOptions {
|
|
4
6
|
logger?: IDBSQLLogger;
|
|
5
7
|
}
|
|
6
|
-
|
|
8
|
+
type AuthOptions = {
|
|
9
|
+
authType?: 'access-token';
|
|
10
|
+
token: string;
|
|
11
|
+
} | {
|
|
12
|
+
authType: 'databricks-oauth';
|
|
13
|
+
persistence?: OAuthPersistence;
|
|
14
|
+
azureTenantId?: string;
|
|
15
|
+
} | {
|
|
16
|
+
authType: 'custom';
|
|
17
|
+
provider: IAuthentication;
|
|
18
|
+
};
|
|
19
|
+
export type ConnectionOptions = {
|
|
7
20
|
host: string;
|
|
8
21
|
port?: number;
|
|
9
22
|
path: string;
|
|
10
|
-
token: string;
|
|
11
23
|
clientId?: string;
|
|
12
|
-
|
|
24
|
+
socketTimeout?: number;
|
|
25
|
+
} & AuthOptions;
|
|
13
26
|
export interface OpenSessionRequest {
|
|
14
27
|
initialCatalog?: string;
|
|
15
28
|
initialSchema?: string;
|
|
@@ -19,3 +32,4 @@ export default interface IDBSQLClient {
|
|
|
19
32
|
openSession(request?: OpenSessionRequest): Promise<IDBSQLSession>;
|
|
20
33
|
close(): Promise<void>;
|
|
21
34
|
}
|
|
35
|
+
export {};
|
package/dist/globalConfig.d.ts
CHANGED
package/dist/globalConfig.js
CHANGED
|
@@ -3,5 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = {
|
|
4
4
|
arrowEnabled: true,
|
|
5
5
|
useArrowNativeTypes: true,
|
|
6
|
+
socketTimeout: 15 * 60 * 1000,
|
|
7
|
+
retryMaxAttempts: 30,
|
|
8
|
+
retriesTimeout: 900 * 1000,
|
|
9
|
+
retryDelayMin: 1 * 1000,
|
|
10
|
+
retryDelayMax: 60 * 1000,
|
|
6
11
|
};
|
|
7
12
|
//# sourceMappingURL=globalConfig.js.map
|
package/dist/globalConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globalConfig.js","sourceRoot":"","sources":["../lib/globalConfig.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"globalConfig.js","sourceRoot":"","sources":["../lib/globalConfig.ts"],"names":[],"mappings":";;AAWA,kBAAe;IACb,YAAY,EAAE,IAAI;IAClB,mBAAmB,EAAE,IAAI;IACzB,aAAa,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IAE7B,gBAAgB,EAAE,EAAE;IACpB,cAAc,EAAE,GAAG,GAAG,IAAI;IAC1B,aAAa,EAAE,CAAC,GAAG,IAAI;IACvB,aAAa,EAAE,EAAE,GAAG,IAAI;CACF,CAAC"}
|