Skip to content

Commit 7849a9a

Browse files
committed
refactor(FR-2529): extract backend.ai-client as standalone workspace package (#6614)
Resolves #6612(FR-2529) ## Summary - Extract `src/lib/backend.ai-client-esm.ts` (6,015 lines) into `packages/backend.ai-client/` as a standalone workspace package - Split monolithic file into 28 modular resource class files under `src/resources/` - Build with **tsup**: ESM output, `.d.ts` auto-generation, sourcemaps - Update all consumers: craco alias, global-stores import, jest mock, react-app-env.d.ts - Replace original file with thin re-export shim for backward compatibility - Follow `backend.ai-ui` patterns: naming (`backend.ai-client`), versioning (`26.4.0-alpha.0`), license (`LGPL-3.0-or-later`) ## Verification ``` === Relay: PASS === === Lint: PASS === === Format: PASS === === TypeScript: PASS === === ALL PASS === ``` Package build: `dist/index.js` (174.5KB) + `dist/index.d.ts` (65.4KB) ## Test plan - [x] `bash scripts/verify.sh` → ALL PASS - [x] `pnpm build` in `packages/backend.ai-client/` succeeds - [x] E2E smoke test: login form renders correctly (backend auth tests skipped — server unavailable in CI worktree) - [ ] Manual: verify `pnpm run dev` starts correctly and login works 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 90f2d85 commit 7849a9a

49 files changed

Lines changed: 64524 additions & 6081 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Production build (`pnpm run build`) runs these steps sequentially:
167167
- Use `make clean` before building if encountering issues
168168
- Electron app requires special build process with `make dep`
169169
- React components use Relay; ensure GraphQL schema in `/data/` is up to date
170-
- Backend.AI client library (`src/lib/backend.ai-client-esm.ts`) is aliased in Craco config
170+
- Backend.AI client library is a workspace package at `packages/backend.ai-client/` (built with tsup)
171171

172172
## Core Guidelines
173173

backend.ai-webui.code-workspace

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"path": "packages/backend.ai-ui",
99
"name": "backend.ai-ui",
1010
},
11+
{
12+
"path": "packages/backend.ai-client",
13+
"name": "backend.ai-client",
14+
},
1115
{
1216
"path": "packages/eslint-config-bai",
1317
"name": "eslint-config-bai",
@@ -38,6 +42,7 @@
3842
"i18n-ally.translate.openai.apiModel": "gpt-5-mini",
3943
"files.exclude": {
4044
"packages/backend.ai-ui": true,
45+
"packages/backend.ai-client": true,
4146
"packages/eslint-config-bai": true,
4247
"packages/backend.ai-webui-docs": true,
4348
},
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"tabWidth": 2,
3+
"semi": true,
4+
"singleQuote": true,
5+
"importOrderSeparation": true,
6+
"importOrderParserPlugins": ["typescript", "jsx"],
7+
"printWidth": 80,
8+
"bracketSpacing": true,
9+
"trailingComma": "all",
10+
"plugins": ["@trivago/prettier-plugin-sort-imports"],
11+
"singleAttributePerLine": false
12+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "backend.ai-client",
3+
"version": "26.4.0-alpha.0",
4+
"description": "Backend.AI API client library for JavaScript/TypeScript",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/lablup/backend.ai-webui/tree/main/packages/backend.ai-client"
8+
},
9+
"bugs": {
10+
"url": "https://github.com/lablup/backend.ai-webui/issues"
11+
},
12+
"author": "Lablup Inc. <contact@lablup.com>",
13+
"license": "LGPL-3.0-or-later",
14+
"keywords": [
15+
"backend.ai",
16+
"client",
17+
"sdk",
18+
"api"
19+
],
20+
"main": "./dist/index.js",
21+
"module": "./dist/index.js",
22+
"types": "./dist/index.d.ts",
23+
"sideEffects": false,
24+
"exports": {
25+
".": {
26+
"import": "./dist/index.js",
27+
"types": "./dist/index.d.ts"
28+
}
29+
},
30+
"files": [
31+
"dist"
32+
],
33+
"scripts": {
34+
"dev": "tsup --watch",
35+
"build": "tsup",
36+
"test": "vitest run",
37+
"vitest": "vitest run",
38+
"vitest:watch": "vitest",
39+
"lint": "eslint ./src --max-warnings=0",
40+
"prepublishOnly": "pnpm lint && pnpm test && pnpm build"
41+
},
42+
"dependencies": {
43+
"crypto-es": "^2.1.0"
44+
},
45+
"devDependencies": {
46+
"tsup": "^8.5.0",
47+
"typescript": "^5.9.3",
48+
"vitest": "^4.1.4"
49+
},
50+
"type": "module"
51+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// @ts-nocheck
2+
class ClientConfig {
3+
public _apiVersionMajor: string;
4+
public _apiVersion: string;
5+
public _hashType: string;
6+
public _endpoint: string;
7+
public _endpointHost: string;
8+
public _accessKey: string;
9+
public _secretKey: string;
10+
public _userId: string;
11+
public _password: string;
12+
public _proxyURL: any;
13+
public _proxyToken: any;
14+
public _connectionMode: string;
15+
16+
/**
17+
* The client Configuration object.
18+
*
19+
* @param {string} accessKey - access key to connect Backend.AI manager
20+
* @param {string} secretKey - secret key to connect Backend.AI manager
21+
* @param {string} endpoint - endpoint of Backend.AI manager
22+
* @param {string} connectionMode - connection mode. 'API', 'SESSION' is supported. `SESSION` mode requires webserver.
23+
*/
24+
constructor(
25+
accessKey?: string,
26+
secretKey?: string,
27+
endpoint?: string,
28+
connectionMode: string = 'API',
29+
) {
30+
// default configs.
31+
this._apiVersionMajor = '8';
32+
this._apiVersion = 'v8.20240915'; // For compatibility with 24.09.
33+
this._hashType = 'sha256';
34+
if (endpoint === undefined || endpoint === null) {
35+
endpoint = 'https://api.backend.ai';
36+
}
37+
endpoint = endpoint.replace(/\/+$/, '');
38+
this._endpoint = endpoint;
39+
this._endpointHost = endpoint.replace(/^[^:]+:\/\//, '');
40+
if (connectionMode === 'API') {
41+
// API mode
42+
// dynamic configs
43+
if (accessKey === undefined || accessKey === null) {
44+
throw new Error(
45+
'You must set accessKey! (either as argument or environment variable)',
46+
);
47+
}
48+
if (secretKey === undefined || secretKey === null) {
49+
throw new Error(
50+
'You must set secretKey! (either as argument or environment variable)',
51+
);
52+
}
53+
this._accessKey = accessKey;
54+
this._secretKey = secretKey;
55+
this._userId = '';
56+
this._password = '';
57+
} else {
58+
// Session mode
59+
// dynamic configs
60+
if (accessKey === undefined || accessKey === null) {
61+
throw new Error(
62+
'You must set user id! (either as argument or environment variable)',
63+
);
64+
}
65+
if (secretKey === undefined || secretKey === null) {
66+
throw new Error(
67+
'You must set password! (either as argument or environment variable)',
68+
);
69+
}
70+
this._accessKey = '';
71+
this._secretKey = '';
72+
this._userId = accessKey;
73+
this._password = secretKey;
74+
}
75+
this._proxyURL = null;
76+
this._proxyToken = null;
77+
this._connectionMode = connectionMode;
78+
}
79+
80+
get accessKey() {
81+
return this._accessKey;
82+
}
83+
84+
get secretKey() {
85+
return this._secretKey;
86+
}
87+
88+
get userId() {
89+
return this._userId;
90+
}
91+
92+
get password() {
93+
return this._password;
94+
}
95+
96+
get endpoint() {
97+
return this._endpoint;
98+
}
99+
100+
get proxyURL() {
101+
return this._proxyURL;
102+
}
103+
104+
get proxyToken() {
105+
return this._proxyToken;
106+
}
107+
108+
get endpointHost() {
109+
return this._endpointHost;
110+
}
111+
112+
get apiVersion() {
113+
return this._apiVersion;
114+
}
115+
116+
get apiVersionMajor() {
117+
return this._apiVersionMajor;
118+
}
119+
120+
get hashType() {
121+
return this._hashType;
122+
}
123+
124+
get connectionMode() {
125+
return this._connectionMode;
126+
}
127+
128+
/**
129+
* Create a ClientConfig object from environment variables.
130+
*/
131+
static createFromEnv() {
132+
return new this(
133+
process.env.BACKEND_ACCESS_KEY,
134+
process.env.BACKEND_SECRET_KEY,
135+
process.env.BACKEND_ENDPOINT,
136+
);
137+
}
138+
}
139+
140+
export { ClientConfig };

0 commit comments

Comments
 (0)