@qbraid-core/base 0.10.2 → 0.12.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/README.md +13 -0
- package/dist/src/_version.d.ts +1 -1
- package/dist/src/_version.js +1 -1
- package/dist/src/client.d.ts +18 -2
- package/dist/src/client.js +20 -87
- package/dist/src/client.js.map +1 -1
- package/dist/src/config.d.ts +14 -30
- package/dist/src/config.js +21 -168
- package/dist/src/config.js.map +1 -1
- package/dist/src/context.d.ts +0 -22
- package/dist/src/context.js +0 -87
- package/dist/src/context.js.map +1 -1
- package/dist/src/index.d.ts +6 -2
- package/dist/src/index.js +10 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/session-v1.d.ts +21 -0
- package/dist/src/session-v1.js +82 -0
- package/dist/src/session-v1.js.map +1 -0
- package/dist/src/session.d.ts +3 -0
- package/dist/src/session.js +13 -6
- package/dist/src/session.js.map +1 -1
- package/package.json +10 -7
package/README.md
CHANGED
|
@@ -15,6 +15,19 @@ npm install @qbraid-core/base
|
|
|
15
15
|
|
|
16
16
|
## Usage Example
|
|
17
17
|
|
|
18
|
+
### V1 API (Recommended)
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { QbraidSessionV1 } from '@qbraid-core/base';
|
|
22
|
+
|
|
23
|
+
const session = new QbraidSessionV1('your-api-key');
|
|
24
|
+
|
|
25
|
+
// The session client is ready to use immediately
|
|
26
|
+
console.log('Session initialized:', session.client !== null);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### V0 API (Legacy)
|
|
30
|
+
|
|
18
31
|
```typescript
|
|
19
32
|
import { QbraidClient } from '@qbraid-core/base';
|
|
20
33
|
|
package/dist/src/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.
|
|
1
|
+
export declare const version = "0.12.0";
|
package/dist/src/_version.js
CHANGED
package/dist/src/client.d.ts
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import { QbraidSession } from './session';
|
|
2
|
+
import { QbraidSessionV1 } from './session-v1';
|
|
2
3
|
import { QbraidUser } from './user';
|
|
4
|
+
/**
|
|
5
|
+
* Base qBraid client for interacting with qBraid Cloud Services.
|
|
6
|
+
* This client requires a QbraidSession to be provided.
|
|
7
|
+
* For automatic configuration loading from files, use QbraidFsClient from @qbraid-core/fs.
|
|
8
|
+
*/
|
|
3
9
|
export declare class QbraidClient {
|
|
4
10
|
/**
|
|
5
11
|
* The QbraidSession instance used by this client.
|
|
6
12
|
*/
|
|
7
13
|
protected session: QbraidSession;
|
|
8
|
-
constructor(session
|
|
14
|
+
constructor(session: QbraidSession);
|
|
9
15
|
getUser(): Promise<QbraidUser>;
|
|
10
|
-
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Base qBraid client for interacting with qBraid Cloud Services (V1 API).
|
|
19
|
+
* This client requires a QbraidSessionV1 to be provided.
|
|
20
|
+
*/
|
|
21
|
+
export declare class QbraidClientV1 {
|
|
22
|
+
/**
|
|
23
|
+
* The QbraidSessionV1 instance used by this client.
|
|
24
|
+
*/
|
|
25
|
+
protected session: QbraidSessionV1;
|
|
26
|
+
constructor(session: QbraidSessionV1);
|
|
11
27
|
}
|
package/dist/src/client.js
CHANGED
|
@@ -1,60 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) 2025, qBraid Development Team
|
|
3
3
|
// All rights reserved.
|
|
4
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
-
if (k2 === undefined) k2 = k;
|
|
6
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
-
}
|
|
10
|
-
Object.defineProperty(o, k2, desc);
|
|
11
|
-
}) : (function(o, m, k, k2) {
|
|
12
|
-
if (k2 === undefined) k2 = k;
|
|
13
|
-
o[k2] = m[k];
|
|
14
|
-
}));
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v;
|
|
19
|
-
});
|
|
20
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
-
var ownKeys = function(o) {
|
|
22
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
-
var ar = [];
|
|
24
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
-
return ar;
|
|
26
|
-
};
|
|
27
|
-
return ownKeys(o);
|
|
28
|
-
};
|
|
29
|
-
return function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
})();
|
|
37
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.QbraidClient = void 0;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const session_1 = require("./session");
|
|
5
|
+
exports.QbraidClientV1 = exports.QbraidClient = void 0;
|
|
6
|
+
/**
|
|
7
|
+
* Base qBraid client for interacting with qBraid Cloud Services.
|
|
8
|
+
* This client requires a QbraidSession to be provided.
|
|
9
|
+
* For automatic configuration loading from files, use QbraidFsClient from @qbraid-core/fs.
|
|
10
|
+
*/
|
|
45
11
|
class QbraidClient {
|
|
46
12
|
/**
|
|
47
13
|
* The QbraidSession instance used by this client.
|
|
48
14
|
*/
|
|
49
15
|
session;
|
|
50
16
|
constructor(session) {
|
|
51
|
-
if (!session) {
|
|
52
|
-
const configManager = new config_1.QbraidConfigManager();
|
|
53
|
-
const authData = configManager.getAuthData();
|
|
54
|
-
const baseURL = configManager.getUrl();
|
|
55
|
-
const userPool = session_1.DEFAULT_USER_POOL;
|
|
56
|
-
session = new session_1.QbraidSession(authData, userPool, baseURL);
|
|
57
|
-
}
|
|
58
17
|
this.session = session;
|
|
59
18
|
}
|
|
60
19
|
async getUser() {
|
|
@@ -73,46 +32,20 @@ class QbraidClient {
|
|
|
73
32
|
},
|
|
74
33
|
};
|
|
75
34
|
}
|
|
76
|
-
async runningInLab() {
|
|
77
|
-
try {
|
|
78
|
-
const utcDatetime = new Date();
|
|
79
|
-
const formattedTime = utcDatetime.toISOString().replace(/[-:]/g, '').replace(/\..+/, '');
|
|
80
|
-
const configDir = path.join(config_2.USER_CONFIG_PATH, '..', 'certs');
|
|
81
|
-
const filepath = path.join(configDir, formattedTime);
|
|
82
|
-
let fileCreated = false;
|
|
83
|
-
return await (0, context_1.ensureDirectory)(configDir, false, async () => {
|
|
84
|
-
try {
|
|
85
|
-
// Create empty file with proper error handling
|
|
86
|
-
await fs.promises.writeFile(filepath, '').catch((error) => {
|
|
87
|
-
console.error(`Failed to create test file: ${error.message}`);
|
|
88
|
-
throw error;
|
|
89
|
-
});
|
|
90
|
-
fileCreated = true;
|
|
91
|
-
const response = await this.session.client.get(`/lab/is-mounted/${formattedTime}`);
|
|
92
|
-
return Boolean(response.data?.isMounted);
|
|
93
|
-
}
|
|
94
|
-
finally {
|
|
95
|
-
if (fileCreated) {
|
|
96
|
-
try {
|
|
97
|
-
await fs.promises.unlink(filepath);
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
if (error instanceof Error) {
|
|
101
|
-
console.error(`Failed to cleanup test file ${filepath}: ${error.message}`);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
console.error(`Failed to cleanup test file ${filepath}: Unknown error`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
console.error('Error in runningInLab:', error instanceof Error ? error.message : 'Unknown error');
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
35
|
}
|
|
117
36
|
exports.QbraidClient = QbraidClient;
|
|
37
|
+
/**
|
|
38
|
+
* Base qBraid client for interacting with qBraid Cloud Services (V1 API).
|
|
39
|
+
* This client requires a QbraidSessionV1 to be provided.
|
|
40
|
+
*/
|
|
41
|
+
class QbraidClientV1 {
|
|
42
|
+
/**
|
|
43
|
+
* The QbraidSessionV1 instance used by this client.
|
|
44
|
+
*/
|
|
45
|
+
session;
|
|
46
|
+
constructor(session) {
|
|
47
|
+
this.session = session;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.QbraidClientV1 = QbraidClientV1;
|
|
118
51
|
//# sourceMappingURL=client.js.map
|
package/dist/src/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB;;;AAMvB;;;;GAIG;AACH,MAAa,YAAY;IACvB;;OAEG;IACO,OAAO,CAAgB;IAEjC,YAAY,OAAsB;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,OAAO;QAClB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAI5C,WAAW,CAAC,CAAC;QAEf,OAAO;YACL,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAa;YAChC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAe;YACpC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAkB;YAC1C,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAc;YAClC,gBAAgB,EAAE,QAAQ,CAAC,IAAI,CAAC,gBAA4B;YAC5D,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAmC;YAC3D,SAAS,EAAE;gBACT,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAiB;gBAClD,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAiB;gBAClD,SAAS,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;aACvD;SACF,CAAC;IACJ,CAAC;CACF;AA/BD,oCA+BC;AAED;;;GAGG;AACH,MAAa,cAAc;IACzB;;OAEG;IACO,OAAO,CAAkB;IACnC,YAAY,OAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AARD,wCAQC"}
|
package/dist/src/config.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { AuthData } from './session';
|
|
2
|
-
export declare const DEFAULT_CONFIG_PATH: string;
|
|
3
|
-
export declare const USER_CONFIG_PATH: string;
|
|
4
1
|
export declare const DEFAULT_CONFIG: ConfigData;
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for configuration management.
|
|
4
|
+
* Provides core configuration logic without filesystem operations.
|
|
5
|
+
* Implementations should provide their own storage mechanism.
|
|
6
|
+
*/
|
|
5
7
|
export declare abstract class ConfigManager<T> {
|
|
6
8
|
protected configPath: string;
|
|
7
9
|
protected config: T;
|
|
@@ -9,34 +11,16 @@ export declare abstract class ConfigManager<T> {
|
|
|
9
11
|
protected abstract parseConfig(content: string): T;
|
|
10
12
|
protected abstract stringifyConfig(config: T): string;
|
|
11
13
|
protected abstract getDefaultConfig(): T;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Load configuration. Implementation depends on the storage mechanism.
|
|
16
|
+
*/
|
|
17
|
+
abstract loadConfig(): T;
|
|
18
|
+
/**
|
|
19
|
+
* Save configuration. Implementation depends on the storage mechanism.
|
|
20
|
+
*/
|
|
21
|
+
abstract saveConfig(): void;
|
|
15
22
|
getConfig(): T;
|
|
16
23
|
}
|
|
17
24
|
type ConfigSection = Record<string, string>;
|
|
18
|
-
type ConfigData = Record<string, ConfigSection>;
|
|
19
|
-
export declare class QbraidConfigManager extends ConfigManager<ConfigData> {
|
|
20
|
-
constructor(filePath?: string);
|
|
21
|
-
protected parseConfig(content: string): ConfigData;
|
|
22
|
-
protected stringifyConfig(config: ConfigData): string;
|
|
23
|
-
protected getDefaultConfig(): ConfigData;
|
|
24
|
-
private initializeDefaultConfig;
|
|
25
|
-
private deepMerge;
|
|
26
|
-
getSection(section: string): Record<string, string> | undefined;
|
|
27
|
-
getValue(section: string, key: string): string | undefined;
|
|
28
|
-
setValue(section: string, key: string, value: string): void;
|
|
29
|
-
updateConfig(newConfig: ConfigData): void;
|
|
30
|
-
removeSection(section: string): void;
|
|
31
|
-
removeValue(section: string, key: string): void;
|
|
32
|
-
getApiKey(): string;
|
|
33
|
-
setApiKey(apiKey: string): void;
|
|
34
|
-
getRefreshToken(): string;
|
|
35
|
-
setRefreshToken(refreshToken: string): void;
|
|
36
|
-
getEmail(): string;
|
|
37
|
-
setEmail(email: string): void;
|
|
38
|
-
getUrl(): string;
|
|
39
|
-
setUrl(url: string): void;
|
|
40
|
-
getAuthData(): AuthData;
|
|
41
|
-
}
|
|
25
|
+
export type ConfigData = Record<string, ConfigSection>;
|
|
42
26
|
export {};
|
package/dist/src/config.js
CHANGED
|
@@ -1,56 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) 2025, qBraid Development Team
|
|
3
3
|
// All rights reserved.
|
|
4
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
-
if (k2 === undefined) k2 = k;
|
|
6
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
-
}
|
|
10
|
-
Object.defineProperty(o, k2, desc);
|
|
11
|
-
}) : (function(o, m, k, k2) {
|
|
12
|
-
if (k2 === undefined) k2 = k;
|
|
13
|
-
o[k2] = m[k];
|
|
14
|
-
}));
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v;
|
|
19
|
-
});
|
|
20
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
-
var ownKeys = function(o) {
|
|
22
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
-
var ar = [];
|
|
24
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
-
return ar;
|
|
26
|
-
};
|
|
27
|
-
return ownKeys(o);
|
|
28
|
-
};
|
|
29
|
-
return function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
})();
|
|
37
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.
|
|
39
|
-
const fs = __importStar(require("fs"));
|
|
40
|
-
const os = __importStar(require("os"));
|
|
41
|
-
const path = __importStar(require("path"));
|
|
42
|
-
const ini = __importStar(require("ini"));
|
|
5
|
+
exports.ConfigManager = exports.DEFAULT_CONFIG = void 0;
|
|
43
6
|
const session_1 = require("./session");
|
|
44
|
-
|
|
45
|
-
|
|
7
|
+
// Browser-safe env accessor: returns '' when process/env is unavailable
|
|
8
|
+
const safeEnv = (key) => {
|
|
9
|
+
try {
|
|
10
|
+
// Avoid ReferenceError in browsers without process
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
const p = globalThis.process;
|
|
13
|
+
return p?.env?.[key] ?? '';
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
};
|
|
46
19
|
exports.DEFAULT_CONFIG = {
|
|
47
20
|
default: {
|
|
48
|
-
'api-key':
|
|
49
|
-
'refresh-token':
|
|
50
|
-
email:
|
|
21
|
+
'api-key': safeEnv('QBRAID_API_KEY'),
|
|
22
|
+
'refresh-token': safeEnv('REFRESH'),
|
|
23
|
+
email: safeEnv('JUPYTERHUB_USER'),
|
|
51
24
|
url: session_1.DEFAULT_BASE_URL,
|
|
52
25
|
},
|
|
53
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Abstract base class for configuration management.
|
|
29
|
+
* Provides core configuration logic without filesystem operations.
|
|
30
|
+
* Implementations should provide their own storage mechanism.
|
|
31
|
+
*/
|
|
54
32
|
class ConfigManager {
|
|
55
33
|
configPath;
|
|
56
34
|
config;
|
|
@@ -58,134 +36,9 @@ class ConfigManager {
|
|
|
58
36
|
this.configPath = filePath;
|
|
59
37
|
this.config = this.loadConfig();
|
|
60
38
|
}
|
|
61
|
-
ensureConfigFileExists() {
|
|
62
|
-
console.log('Checking config path:', this.configPath);
|
|
63
|
-
if (!fs.existsSync(this.configPath)) {
|
|
64
|
-
const dirPath = path.dirname(this.configPath);
|
|
65
|
-
if (!fs.existsSync(dirPath)) {
|
|
66
|
-
fs.mkdirSync(dirPath, { recursive: true });
|
|
67
|
-
}
|
|
68
|
-
fs.writeFileSync(this.configPath, '', 'utf-8');
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
loadConfig() {
|
|
72
|
-
try {
|
|
73
|
-
if (fs.existsSync(this.configPath)) {
|
|
74
|
-
const fileContent = fs.readFileSync(this.configPath, 'utf-8');
|
|
75
|
-
return this.parseConfig(fileContent);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
console.warn(`Config file not found at ${this.configPath}. Initializing with default config.`);
|
|
79
|
-
return this.getDefaultConfig();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
if (error instanceof Error) {
|
|
84
|
-
console.error(`Error loading config file: ${error.message}`);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
console.error(`An unknown error occurred while loading the config file.`);
|
|
88
|
-
}
|
|
89
|
-
return this.getDefaultConfig();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
saveConfig() {
|
|
93
|
-
this.ensureConfigFileExists();
|
|
94
|
-
try {
|
|
95
|
-
const configString = this.stringifyConfig(this.config);
|
|
96
|
-
fs.writeFileSync(this.configPath, configString, 'utf-8');
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
console.error(`Error saving config file: ${error}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
39
|
getConfig() {
|
|
103
40
|
return this.config;
|
|
104
41
|
}
|
|
105
42
|
}
|
|
106
43
|
exports.ConfigManager = ConfigManager;
|
|
107
|
-
class QbraidConfigManager extends ConfigManager {
|
|
108
|
-
constructor(filePath = exports.USER_CONFIG_PATH) {
|
|
109
|
-
super(filePath);
|
|
110
|
-
this.initializeDefaultConfig();
|
|
111
|
-
}
|
|
112
|
-
parseConfig(content) {
|
|
113
|
-
return ini.parse(content);
|
|
114
|
-
}
|
|
115
|
-
stringifyConfig(config) {
|
|
116
|
-
return ini.stringify(config);
|
|
117
|
-
}
|
|
118
|
-
getDefaultConfig() {
|
|
119
|
-
return exports.DEFAULT_CONFIG;
|
|
120
|
-
}
|
|
121
|
-
initializeDefaultConfig() {
|
|
122
|
-
const currentConfig = this.getConfig();
|
|
123
|
-
const mergedConfig = this.deepMerge(exports.DEFAULT_CONFIG, currentConfig);
|
|
124
|
-
this.updateConfig(mergedConfig);
|
|
125
|
-
}
|
|
126
|
-
deepMerge(target, source) {
|
|
127
|
-
const output = { ...target };
|
|
128
|
-
Object.keys(source).forEach(key => {
|
|
129
|
-
if (typeof source[key] === 'object' && source[key] !== null) {
|
|
130
|
-
output[key] = output[key] ? { ...output[key], ...source[key] } : { ...source[key] };
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
return output;
|
|
134
|
-
}
|
|
135
|
-
getSection(section) {
|
|
136
|
-
return this.config[section];
|
|
137
|
-
}
|
|
138
|
-
getValue(section, key) {
|
|
139
|
-
return this.config[section]?.[key];
|
|
140
|
-
}
|
|
141
|
-
setValue(section, key, value) {
|
|
142
|
-
if (!this.config[section]) {
|
|
143
|
-
this.config[section] = {};
|
|
144
|
-
}
|
|
145
|
-
this.config[section][key] = value;
|
|
146
|
-
}
|
|
147
|
-
updateConfig(newConfig) {
|
|
148
|
-
this.config = { ...this.config, ...newConfig };
|
|
149
|
-
}
|
|
150
|
-
removeSection(section) {
|
|
151
|
-
delete this.config[section];
|
|
152
|
-
}
|
|
153
|
-
removeValue(section, key) {
|
|
154
|
-
if (this.config[section]) {
|
|
155
|
-
delete this.config[section][key];
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
getApiKey() {
|
|
159
|
-
return this.getValue('default', 'api-key') || '';
|
|
160
|
-
}
|
|
161
|
-
setApiKey(apiKey) {
|
|
162
|
-
this.setValue('default', 'api-key', apiKey);
|
|
163
|
-
}
|
|
164
|
-
getRefreshToken() {
|
|
165
|
-
return this.getValue('default', 'refresh-token') || '';
|
|
166
|
-
}
|
|
167
|
-
setRefreshToken(refreshToken) {
|
|
168
|
-
this.setValue('default', 'refresh-token', refreshToken);
|
|
169
|
-
}
|
|
170
|
-
getEmail() {
|
|
171
|
-
return this.getValue('default', 'email') || '';
|
|
172
|
-
}
|
|
173
|
-
setEmail(email) {
|
|
174
|
-
this.setValue('default', 'email', email);
|
|
175
|
-
}
|
|
176
|
-
getUrl() {
|
|
177
|
-
return this.getValue('default', 'url') || session_1.DEFAULT_BASE_URL;
|
|
178
|
-
}
|
|
179
|
-
setUrl(url) {
|
|
180
|
-
this.setValue('default', 'url', url);
|
|
181
|
-
}
|
|
182
|
-
getAuthData() {
|
|
183
|
-
return {
|
|
184
|
-
apiKey: this.getApiKey(),
|
|
185
|
-
refreshToken: this.getRefreshToken(),
|
|
186
|
-
email: this.getEmail(),
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
exports.QbraidConfigManager = QbraidConfigManager;
|
|
191
44
|
//# sourceMappingURL=config.js.map
|
package/dist/src/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB;;;AAEvB,uCAA6C;AAE7C,wEAAwE;AACxE,MAAM,OAAO,GAAG,CAAC,GAAW,EAAU,EAAE;IACtC,IAAI,CAAC;QACH,mDAAmD;QACnD,8DAA8D;QAC9D,MAAM,CAAC,GAAS,UAAkB,CAAC,OAAO,CAAC;QAC3C,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAEW,QAAA,cAAc,GAAe;IACxC,OAAO,EAAE;QACP,SAAS,EAAE,OAAO,CAAC,gBAAgB,CAAC;QACpC,eAAe,EAAE,OAAO,CAAC,SAAS,CAAC;QACnC,KAAK,EAAE,OAAO,CAAC,iBAAiB,CAAC;QACjC,GAAG,EAAE,0BAAgB;KACtB;CACF,CAAC;AAEF;;;;GAIG;AACH,MAAsB,aAAa;IACvB,UAAU,CAAS;IACnB,MAAM,CAAI;IAEpB,YAAY,QAAgB;QAC1B,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IAClC,CAAC;IAgBM,SAAS;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AA1BD,sCA0BC"}
|
package/dist/src/context.d.ts
CHANGED
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for a disposable resource that can be cleaned up
|
|
3
|
-
*/
|
|
4
|
-
interface Disposable {
|
|
5
|
-
dispose(): Promise<void>;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Utility function to handle resource management similar to Python's context manager
|
|
9
|
-
* @param resource A disposable resource with init and dispose methods
|
|
10
|
-
* @param fn The function to execute with the managed resource
|
|
11
|
-
*/
|
|
12
|
-
export declare function using<T extends Disposable, R>(resource: T & {
|
|
13
|
-
init(): Promise<void>;
|
|
14
|
-
}, fn: (resource: T) => Promise<R>): Promise<R>;
|
|
15
|
-
/**
|
|
16
|
-
* Ensures a directory exists during the execution of a function and optionally cleans it up
|
|
17
|
-
* @param dirPath Path to the directory
|
|
18
|
-
* @param removeIfCreated Whether to remove the directory if it was created by this function
|
|
19
|
-
* @param fn Function to execute while directory is guaranteed to exist
|
|
20
|
-
*/
|
|
21
|
-
export declare function ensureDirectory<R>(dirPath: string, removeIfCreated: boolean, fn: () => Promise<R>): Promise<R>;
|
|
22
1
|
/**
|
|
23
2
|
* Default URLs for qBraid services
|
|
24
3
|
*/
|
|
@@ -27,4 +6,3 @@ export declare const DEFAULT_LAB_URL = "https://lab.qbraid.com";
|
|
|
27
6
|
export declare const DEFAULT_QBOOK_URL = "https://qbook.qbraid.com";
|
|
28
7
|
export declare const DEFAULT_ACCOUNT_URL = "https://account.qbraid.com/";
|
|
29
8
|
export declare const DEFAULT_HUB_URL = "https://lab.qbraid.com";
|
|
30
|
-
export {};
|
package/dist/src/context.js
CHANGED
|
@@ -1,95 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) 2025, qBraid Development Team
|
|
3
3
|
// All rights reserved.
|
|
4
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
-
if (k2 === undefined) k2 = k;
|
|
6
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
-
}
|
|
10
|
-
Object.defineProperty(o, k2, desc);
|
|
11
|
-
}) : (function(o, m, k, k2) {
|
|
12
|
-
if (k2 === undefined) k2 = k;
|
|
13
|
-
o[k2] = m[k];
|
|
14
|
-
}));
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v;
|
|
19
|
-
});
|
|
20
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
-
var ownKeys = function(o) {
|
|
22
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
-
var ar = [];
|
|
24
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
-
return ar;
|
|
26
|
-
};
|
|
27
|
-
return ownKeys(o);
|
|
28
|
-
};
|
|
29
|
-
return function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
})();
|
|
37
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
5
|
exports.DEFAULT_HUB_URL = exports.DEFAULT_ACCOUNT_URL = exports.DEFAULT_QBOOK_URL = exports.DEFAULT_LAB_URL = exports.DEFAULT_API_URL = void 0;
|
|
39
|
-
exports.using = using;
|
|
40
|
-
exports.ensureDirectory = ensureDirectory;
|
|
41
|
-
const fs = __importStar(require("fs"));
|
|
42
|
-
const path = __importStar(require("path"));
|
|
43
|
-
/**
|
|
44
|
-
* Class to manage directory creation and cleanup
|
|
45
|
-
*/
|
|
46
|
-
class DirectoryManager {
|
|
47
|
-
existed;
|
|
48
|
-
path;
|
|
49
|
-
removeIfCreated;
|
|
50
|
-
constructor(dirPath, removeIfCreated) {
|
|
51
|
-
this.path = dirPath;
|
|
52
|
-
this.removeIfCreated = removeIfCreated;
|
|
53
|
-
this.existed = fs.existsSync(dirPath);
|
|
54
|
-
}
|
|
55
|
-
async init() {
|
|
56
|
-
if (!this.existed) {
|
|
57
|
-
await fs.promises.mkdir(this.path, { recursive: true });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async dispose() {
|
|
61
|
-
if (!this.existed && this.removeIfCreated) {
|
|
62
|
-
const files = await fs.promises.readdir(this.path);
|
|
63
|
-
for (const file of files) {
|
|
64
|
-
await fs.promises.unlink(path.join(this.path, file));
|
|
65
|
-
}
|
|
66
|
-
await fs.promises.rmdir(this.path);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Utility function to handle resource management similar to Python's context manager
|
|
72
|
-
* @param resource A disposable resource with init and dispose methods
|
|
73
|
-
* @param fn The function to execute with the managed resource
|
|
74
|
-
*/
|
|
75
|
-
async function using(resource, fn) {
|
|
76
|
-
await resource.init();
|
|
77
|
-
try {
|
|
78
|
-
return await fn(resource);
|
|
79
|
-
}
|
|
80
|
-
finally {
|
|
81
|
-
await resource.dispose();
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Ensures a directory exists during the execution of a function and optionally cleans it up
|
|
86
|
-
* @param dirPath Path to the directory
|
|
87
|
-
* @param removeIfCreated Whether to remove the directory if it was created by this function
|
|
88
|
-
* @param fn Function to execute while directory is guaranteed to exist
|
|
89
|
-
*/
|
|
90
|
-
async function ensureDirectory(dirPath, removeIfCreated, fn) {
|
|
91
|
-
return using(new DirectoryManager(dirPath, removeIfCreated), async () => await fn());
|
|
92
|
-
}
|
|
93
6
|
/**
|
|
94
7
|
* Default URLs for qBraid services
|
|
95
8
|
*/
|
package/dist/src/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB;;;AAEvB;;GAEG;AACU,QAAA,eAAe,GAAG,wBAAwB,CAAC;AAC3C,QAAA,eAAe,GAAG,wBAAwB,CAAC;AAC3C,QAAA,iBAAiB,GAAG,0BAA0B,CAAC;AAC/C,QAAA,mBAAmB,GAAG,6BAA6B,CAAC;AACpD,QAAA,eAAe,GAAG,wBAAwB,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
* @module base
|
|
3
3
|
*/
|
|
4
4
|
export { QbraidClient } from './client';
|
|
5
|
-
export { QbraidSession } from './session';
|
|
5
|
+
export { QbraidSession, DEFAULT_BASE_URL, DEFAULT_USER_POOL } from './session';
|
|
6
|
+
export { QbraidClientV1 } from './client';
|
|
7
|
+
export { QbraidSessionV1, DEFAULT_BASE_URL as DEFAULT_BASE_URL_V1, DEFAULT_USER_DOMAIN as DEFAULT_USER_DOMAIN_V1, } from './session-v1';
|
|
6
8
|
export { QbraidError } from './errors';
|
|
7
|
-
export { ConfigManager,
|
|
9
|
+
export { ConfigManager, DEFAULT_CONFIG } from './config';
|
|
10
|
+
export type { ConfigData } from './config';
|
|
8
11
|
export type { QbraidUser, DiskUsage } from './user';
|
|
9
12
|
export type { AuthData } from './session';
|
|
13
|
+
export type { AuthDataV1 } from './session-v1';
|
package/dist/src/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright (c) 2025, qBraid Development Team
|
|
3
3
|
// All rights reserved.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.
|
|
5
|
+
exports.DEFAULT_CONFIG = exports.ConfigManager = exports.QbraidError = exports.DEFAULT_USER_DOMAIN_V1 = exports.DEFAULT_BASE_URL_V1 = exports.QbraidSessionV1 = exports.QbraidClientV1 = exports.DEFAULT_USER_POOL = exports.DEFAULT_BASE_URL = exports.QbraidSession = exports.QbraidClient = void 0;
|
|
6
6
|
/**
|
|
7
7
|
* @module base
|
|
8
8
|
*/
|
|
@@ -10,9 +10,17 @@ var client_1 = require("./client");
|
|
|
10
10
|
Object.defineProperty(exports, "QbraidClient", { enumerable: true, get: function () { return client_1.QbraidClient; } });
|
|
11
11
|
var session_1 = require("./session");
|
|
12
12
|
Object.defineProperty(exports, "QbraidSession", { enumerable: true, get: function () { return session_1.QbraidSession; } });
|
|
13
|
+
Object.defineProperty(exports, "DEFAULT_BASE_URL", { enumerable: true, get: function () { return session_1.DEFAULT_BASE_URL; } });
|
|
14
|
+
Object.defineProperty(exports, "DEFAULT_USER_POOL", { enumerable: true, get: function () { return session_1.DEFAULT_USER_POOL; } });
|
|
15
|
+
var client_2 = require("./client");
|
|
16
|
+
Object.defineProperty(exports, "QbraidClientV1", { enumerable: true, get: function () { return client_2.QbraidClientV1; } });
|
|
17
|
+
var session_v1_1 = require("./session-v1");
|
|
18
|
+
Object.defineProperty(exports, "QbraidSessionV1", { enumerable: true, get: function () { return session_v1_1.QbraidSessionV1; } });
|
|
19
|
+
Object.defineProperty(exports, "DEFAULT_BASE_URL_V1", { enumerable: true, get: function () { return session_v1_1.DEFAULT_BASE_URL; } });
|
|
20
|
+
Object.defineProperty(exports, "DEFAULT_USER_DOMAIN_V1", { enumerable: true, get: function () { return session_v1_1.DEFAULT_USER_DOMAIN; } });
|
|
13
21
|
var errors_1 = require("./errors");
|
|
14
22
|
Object.defineProperty(exports, "QbraidError", { enumerable: true, get: function () { return errors_1.QbraidError; } });
|
|
15
23
|
var config_1 = require("./config");
|
|
16
24
|
Object.defineProperty(exports, "ConfigManager", { enumerable: true, get: function () { return config_1.ConfigManager; } });
|
|
17
|
-
Object.defineProperty(exports, "
|
|
25
|
+
Object.defineProperty(exports, "DEFAULT_CONFIG", { enumerable: true, get: function () { return config_1.DEFAULT_CONFIG; } });
|
|
18
26
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB;;;AAEvB;;GAEG;AACH,mCAAwC;AAA/B,sGAAA,YAAY,OAAA;AACrB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB;;;AAEvB;;GAEG;AACH,mCAAwC;AAA/B,sGAAA,YAAY,OAAA;AACrB,qCAA+E;AAAtE,wGAAA,aAAa,OAAA;AAAE,2GAAA,gBAAgB,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAC3D,mCAA0C;AAAjC,wGAAA,cAAc,OAAA;AACvB,2CAIsB;AAHpB,6GAAA,eAAe,OAAA;AACf,iHAAA,gBAAgB,OAAuB;AACvC,oHAAA,mBAAmB,OAA0B;AAE/C,mCAAuC;AAA9B,qGAAA,WAAW,OAAA;AACpB,mCAAyD;AAAhD,uGAAA,aAAa,OAAA;AAAE,wGAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module for making requests to the qBraid API v1.
|
|
3
|
+
*/
|
|
4
|
+
import { AxiosInstance } from 'axios';
|
|
5
|
+
export declare const DEFAULT_USER_DOMAIN = "qbraid.com";
|
|
6
|
+
export declare const DEFAULT_BASE_URL = "https://api-staging.qbraid.com/api/v1";
|
|
7
|
+
export interface AuthDataV1 {
|
|
8
|
+
apiKey: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class QbraidSessionV1 {
|
|
11
|
+
private apiKey;
|
|
12
|
+
private userDomain;
|
|
13
|
+
private baseURL;
|
|
14
|
+
client: AxiosInstance;
|
|
15
|
+
constructor(apiKey: string, userDomain?: string, baseURL?: string);
|
|
16
|
+
private authDataToHeaders;
|
|
17
|
+
private normalizeBaseURL;
|
|
18
|
+
private getUserAgent;
|
|
19
|
+
addUserAgent(userAgent: string): void;
|
|
20
|
+
private initializeClient;
|
|
21
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2025, qBraid Development Team
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.QbraidSessionV1 = exports.DEFAULT_BASE_URL = exports.DEFAULT_USER_DOMAIN = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* Module for making requests to the qBraid API v1.
|
|
11
|
+
*/
|
|
12
|
+
const axios_1 = __importDefault(require("axios"));
|
|
13
|
+
const _version_1 = require("./_version");
|
|
14
|
+
exports.DEFAULT_USER_DOMAIN = 'qbraid.com';
|
|
15
|
+
// Current default base URL for qBraid API v1
|
|
16
|
+
exports.DEFAULT_BASE_URL = 'https://api-staging.qbraid.com/api/v1';
|
|
17
|
+
class QbraidSessionV1 {
|
|
18
|
+
apiKey;
|
|
19
|
+
userDomain;
|
|
20
|
+
baseURL;
|
|
21
|
+
client;
|
|
22
|
+
constructor(apiKey, userDomain = exports.DEFAULT_USER_DOMAIN, baseURL = exports.DEFAULT_BASE_URL) {
|
|
23
|
+
this.apiKey = apiKey;
|
|
24
|
+
this.userDomain = userDomain;
|
|
25
|
+
this.baseURL = baseURL;
|
|
26
|
+
this.client = this.initializeClient();
|
|
27
|
+
}
|
|
28
|
+
authDataToHeaders(authData) {
|
|
29
|
+
let headers = {};
|
|
30
|
+
if (authData.apiKey) {
|
|
31
|
+
headers['X-Api-Key'] = `${authData.apiKey}`;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
throw new Error('Invalid authentication data. Please provide API Key for authentication.');
|
|
35
|
+
}
|
|
36
|
+
return headers;
|
|
37
|
+
}
|
|
38
|
+
normalizeBaseURL(baseURL) {
|
|
39
|
+
return baseURL.replace(/\/+$/, '');
|
|
40
|
+
}
|
|
41
|
+
getUserAgent() {
|
|
42
|
+
return `QbraidCoreJs/${_version_1.version}`;
|
|
43
|
+
}
|
|
44
|
+
addUserAgent(userAgent) {
|
|
45
|
+
const current = this.client.defaults.headers['User-Agent'];
|
|
46
|
+
if (typeof current === 'string' && !current.includes(userAgent)) {
|
|
47
|
+
this.client.defaults.headers['User-Agent'] = `${current} ${userAgent}`.trim();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
initializeClient() {
|
|
51
|
+
// Build auth headers
|
|
52
|
+
const authData = { apiKey: this.apiKey };
|
|
53
|
+
const authHeaders = this.authDataToHeaders(authData);
|
|
54
|
+
const headers = {
|
|
55
|
+
'X-Domain': this.userDomain,
|
|
56
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
57
|
+
};
|
|
58
|
+
// Some environments (browsers) disallow setting User-Agent; add only when allowed
|
|
59
|
+
try {
|
|
60
|
+
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
61
|
+
if (!isBrowser) {
|
|
62
|
+
headers['User-Agent'] = this.getUserAgent();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// ignore
|
|
67
|
+
}
|
|
68
|
+
// Create axios instance
|
|
69
|
+
const axiosInstance = axios_1.default.create({
|
|
70
|
+
baseURL: this.normalizeBaseURL(this.baseURL),
|
|
71
|
+
headers,
|
|
72
|
+
});
|
|
73
|
+
axiosInstance.interceptors.request.use(async (config) => {
|
|
74
|
+
const updatedConfig = { ...config };
|
|
75
|
+
updatedConfig.headers.set(authHeaders);
|
|
76
|
+
return updatedConfig;
|
|
77
|
+
});
|
|
78
|
+
return axiosInstance;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.QbraidSessionV1 = QbraidSessionV1;
|
|
82
|
+
//# sourceMappingURL=session-v1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-v1.js","sourceRoot":"","sources":["../../src/session-v1.ts"],"names":[],"mappings":"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"}
|
package/dist/src/session.d.ts
CHANGED
package/dist/src/session.js
CHANGED
|
@@ -9,7 +9,6 @@ exports.QbraidSession = exports.DEFAULT_BASE_URL = exports.DEFAULT_USER_POOL = v
|
|
|
9
9
|
/**
|
|
10
10
|
* Module for making requests to the qBraid API.
|
|
11
11
|
*/
|
|
12
|
-
const https_1 = require("https");
|
|
13
12
|
const axios_1 = __importDefault(require("axios"));
|
|
14
13
|
const _version_1 = require("./_version");
|
|
15
14
|
exports.DEFAULT_USER_POOL = 'qbraid';
|
|
@@ -40,13 +39,21 @@ class QbraidSession {
|
|
|
40
39
|
const authHeaders = this.authDataToHeaders(authData);
|
|
41
40
|
const headers = {
|
|
42
41
|
domain: userPool,
|
|
43
|
-
'User-Agent': this.getUserAgent(),
|
|
44
42
|
'Content-Type': 'application/json; charset=utf-8',
|
|
45
43
|
};
|
|
44
|
+
// Some environments (browsers) disallow setting User-Agent; add only when allowed
|
|
45
|
+
try {
|
|
46
|
+
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
47
|
+
if (!isBrowser) {
|
|
48
|
+
headers['User-Agent'] = this.getUserAgent();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// ignore
|
|
53
|
+
}
|
|
46
54
|
const axiosInstance = axios_1.default.create({
|
|
47
55
|
baseURL: this.normalizeBaseURL(baseURL),
|
|
48
56
|
headers,
|
|
49
|
-
httpsAgent: new https_1.Agent({ keepAlive: true }),
|
|
50
57
|
});
|
|
51
58
|
axiosInstance.interceptors.request.use(async (config) => {
|
|
52
59
|
const updatedConfig = { ...config };
|
|
@@ -59,9 +66,9 @@ class QbraidSession {
|
|
|
59
66
|
return `QbraidCoreJs/${_version_1.version}`;
|
|
60
67
|
}
|
|
61
68
|
addUserAgent(userAgent) {
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
64
|
-
this.client.defaults.headers['User-Agent'] = `${
|
|
69
|
+
const current = this.client.defaults.headers['User-Agent'];
|
|
70
|
+
if (typeof current === 'string' && !current.includes(userAgent)) {
|
|
71
|
+
this.client.defaults.headers['User-Agent'] = `${current} ${userAgent}`.trim();
|
|
65
72
|
}
|
|
66
73
|
}
|
|
67
74
|
}
|
package/dist/src/session.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB;;;;;;AAEvB;;GAEG;AAEH,
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB;;;;;;AAEvB;;GAEG;AAEH,kDAA6C;AAE7C,yCAAqC;AAExB,QAAA,iBAAiB,GAAG,QAAQ,CAAC;AAC7B,QAAA,gBAAgB,GAAG,4BAA4B,CAAC;AAQ7D,MAAa,aAAa;IACjB,MAAM,CAAgB;IAE7B,YACE,QAAkB,EAClB,WAAmB,yBAAiB,EACpC,UAAkB,wBAAgB;QAElC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC;IAEO,iBAAiB,CAAC,QAAkB;QAC1C,IAAI,OAAO,GAA2B,EAAE,CAAC;QAEzC,IAAI,QAAQ,CAAC,YAAY,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;YAC5C,OAAO,CAAC,eAAe,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC;YACjD,OAAO,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;QACpC,CAAC;aAAM,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YAC3B,OAAO,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC;QACvC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,gBAAgB,CAAC,OAAe;QACtC,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACrC,CAAC;IAEO,mBAAmB,CACzB,QAAkB,EAClB,QAAgB,EAChB,OAAe;QAEf,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAErD,MAAM,OAAO,GAA2B;YACtC,MAAM,EAAE,QAAQ;YAChB,cAAc,EAAE,iCAAiC;SAClD,CAAC;QAEF,kFAAkF;QAClF,IAAI,CAAC;YACH,MAAM,SAAS,GACb,OAAO,MAAM,KAAK,WAAW,IAAI,OAAQ,MAAc,CAAC,QAAQ,KAAK,WAAW,CAAC;YACnF,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YAC9C,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;QAED,MAAM,aAAa,GAAG,eAAK,CAAC,MAAM,CAAC;YACjC,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;YACvC,OAAO;SACR,CAAC,CAAC;QAEH,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAC,MAAM,EAAC,EAAE;YACpD,MAAM,aAAa,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;YACpC,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YACvC,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC,CAAC;QAEH,OAAO,aAAa,CAAC;IACvB,CAAC;IAEO,YAAY;QAClB,OAAO,gBAAgB,kBAAO,EAAE,CAAC;IACnC,CAAC;IAEM,YAAY,CAAC,SAAiB;QACnC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAuB,CAAC;QACjF,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YAChE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,GAAG,OAAO,IAAI,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC;QAChF,CAAC;IACH,CAAC;CACF;AA9ED,sCA8EC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qbraid-core/base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"description": "Core functionality for interacting with qBraid Cloud Services.",
|
|
@@ -27,14 +27,17 @@
|
|
|
27
27
|
"url": "git+https://github.com/qBraid/qbraid-core-js.git"
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://qbraid.github.io/qbraid-core-js/modules/base.html",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
30
|
+
"browser": {
|
|
31
|
+
"https": false,
|
|
32
|
+
"http": false,
|
|
33
|
+
"os": false,
|
|
34
|
+
"fs": false,
|
|
35
|
+
"path": false
|
|
34
36
|
},
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"axios": "^1.12.2"
|
|
37
39
|
},
|
|
40
|
+
"devDependencies": {},
|
|
38
41
|
"scripts": {
|
|
39
42
|
"clean": "rimraf dist tsconfig.tsbuildinfo src/_version.ts src/_version.js src/*.d.ts src/*.js",
|
|
40
43
|
"lint": "eslint src",
|