@gojinko/api-client 0.1.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/auth.d.ts +35 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +64 -0
- package/dist/auth.js.map +1 -0
- package/dist/client.d.ts +21 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +60 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +33 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types/generated.d.ts +3486 -0
- package/dist/types/generated.d.ts.map +1 -0
- package/dist/types/generated.js +6 -0
- package/dist/types/generated.js.map +1 -0
- package/package.json +39 -0
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type AuthMethod = 'api_key' | 'oauth';
|
|
2
|
+
export interface ResolvedAuth {
|
|
3
|
+
readonly method: AuthMethod;
|
|
4
|
+
readonly token: string;
|
|
5
|
+
}
|
|
6
|
+
interface ConfigFile {
|
|
7
|
+
readonly api_key?: string;
|
|
8
|
+
readonly oauth_token?: string;
|
|
9
|
+
readonly base_url?: string;
|
|
10
|
+
}
|
|
11
|
+
declare const DEFAULT_BASE_URL = "https://bff.gojinko.com";
|
|
12
|
+
declare const CONFIG_DIR: string;
|
|
13
|
+
declare const CONFIG_FILE: string;
|
|
14
|
+
/**
|
|
15
|
+
* Resolve auth credentials with precedence: param > env > config file.
|
|
16
|
+
* Supports both API key (jnk_...) and OAuth JWT token.
|
|
17
|
+
*
|
|
18
|
+
* Detection: if the token starts with "jnk_" it's an API key,
|
|
19
|
+
* otherwise it's treated as an OAuth JWT.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveAuth(paramToken?: string): Promise<ResolvedAuth | undefined>;
|
|
22
|
+
/**
|
|
23
|
+
* Resolve base URL with precedence: param > env > config file > default.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveBaseUrl(paramUrl?: string): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Read the config file at ~/.jinko/config.yaml.
|
|
28
|
+
*/
|
|
29
|
+
export declare function readConfigFile(): Promise<ConfigFile | undefined>;
|
|
30
|
+
/**
|
|
31
|
+
* Write a config value to ~/.jinko/config.yaml.
|
|
32
|
+
*/
|
|
33
|
+
export declare function writeConfigFile(updates: Partial<ConfigFile>): Promise<void>;
|
|
34
|
+
export { CONFIG_DIR, CONFIG_FILE, DEFAULT_BASE_URL };
|
|
35
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC;AAE7C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,UAAU;IAClB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,QAAA,MAAM,gBAAgB,4BAA4B,CAAC;AACnD,QAAA,MAAM,UAAU,QAA4B,CAAC;AAC7C,QAAA,MAAM,WAAW,QAAkC,CAAC;AAEpD;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAaxF;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAQvE;AAED;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAOtE;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CASjF;AAED,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,CAAC"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { parse as parseYaml } from 'yaml';
|
|
5
|
+
const DEFAULT_BASE_URL = 'https://bff.gojinko.com';
|
|
6
|
+
const CONFIG_DIR = join(homedir(), '.jinko');
|
|
7
|
+
const CONFIG_FILE = join(CONFIG_DIR, 'config.yaml');
|
|
8
|
+
/**
|
|
9
|
+
* Resolve auth credentials with precedence: param > env > config file.
|
|
10
|
+
* Supports both API key (jnk_...) and OAuth JWT token.
|
|
11
|
+
*
|
|
12
|
+
* Detection: if the token starts with "jnk_" it's an API key,
|
|
13
|
+
* otherwise it's treated as an OAuth JWT.
|
|
14
|
+
*/
|
|
15
|
+
export async function resolveAuth(paramToken) {
|
|
16
|
+
const token = paramToken
|
|
17
|
+
?? process.env['JINKO_API_KEY']
|
|
18
|
+
?? process.env['JINKO_TOKEN']
|
|
19
|
+
?? (await readConfigFile())?.api_key
|
|
20
|
+
?? (await readConfigFile())?.oauth_token;
|
|
21
|
+
if (!token)
|
|
22
|
+
return undefined;
|
|
23
|
+
return {
|
|
24
|
+
method: token.startsWith('jnk_') ? 'api_key' : 'oauth',
|
|
25
|
+
token,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Resolve base URL with precedence: param > env > config file > default.
|
|
30
|
+
*/
|
|
31
|
+
export async function resolveBaseUrl(paramUrl) {
|
|
32
|
+
if (paramUrl)
|
|
33
|
+
return paramUrl;
|
|
34
|
+
const envUrl = process.env['JINKO_BASE_URL'];
|
|
35
|
+
if (envUrl)
|
|
36
|
+
return envUrl;
|
|
37
|
+
const config = await readConfigFile();
|
|
38
|
+
return config?.base_url ?? DEFAULT_BASE_URL;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Read the config file at ~/.jinko/config.yaml.
|
|
42
|
+
*/
|
|
43
|
+
export async function readConfigFile() {
|
|
44
|
+
try {
|
|
45
|
+
const content = await readFile(CONFIG_FILE, 'utf-8');
|
|
46
|
+
return parseYaml(content);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Write a config value to ~/.jinko/config.yaml.
|
|
54
|
+
*/
|
|
55
|
+
export async function writeConfigFile(updates) {
|
|
56
|
+
const { mkdir, writeFile } = await import('node:fs/promises');
|
|
57
|
+
const { stringify: stringifyYaml } = await import('yaml');
|
|
58
|
+
await mkdir(CONFIG_DIR, { recursive: true });
|
|
59
|
+
const existing = (await readConfigFile()) ?? {};
|
|
60
|
+
const merged = { ...existing, ...updates };
|
|
61
|
+
await writeFile(CONFIG_FILE, stringifyYaml(merged), 'utf-8');
|
|
62
|
+
}
|
|
63
|
+
export { CONFIG_DIR, CONFIG_FILE, DEFAULT_BASE_URL };
|
|
64
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAe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nB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAA4B;IAChE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAC9D,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;IAE1D,MAAM,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE7C,MAAM,QAAQ,GAAG,CAAC,MAAM,cAAc,EAAE,CAAC,IAAI,EAAE,CAAC;IAChD,MAAM,MAAM,GAAe,EAAE,GAAG,QAAQ,EAAE,GAAG,OAAO,EAAE,CAAC;IACvD,MAAM,SAAS,CAAC,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;AAC/D,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import createClient from 'openapi-fetch';
|
|
2
|
+
import { type ResolvedAuth } from './auth.js';
|
|
3
|
+
import type { paths } from './types/generated.js';
|
|
4
|
+
export interface ClientOptions {
|
|
5
|
+
readonly apiKey?: string;
|
|
6
|
+
readonly baseUrl?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface JinkoClient {
|
|
9
|
+
readonly raw: ReturnType<typeof createClient<paths>>;
|
|
10
|
+
readonly baseUrl: string;
|
|
11
|
+
readonly auth: ResolvedAuth;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a configured openapi-fetch client for the Jinko BFF.
|
|
15
|
+
*
|
|
16
|
+
* Auth is determined by the token format:
|
|
17
|
+
* - `jnk_...` → API key auth (X-API-Key header)
|
|
18
|
+
* - anything else → OAuth JWT (Authorization: Bearer header)
|
|
19
|
+
*/
|
|
20
|
+
export declare function createJinkoClient(options?: ClientOptions): Promise<JinkoClient>;
|
|
21
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,YAAiC,MAAM,eAAe,CAAC;AAC9D,OAAO,EAA+B,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAG3E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAqDzF"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import createClient from 'openapi-fetch';
|
|
2
|
+
import { resolveAuth, resolveBaseUrl } from './auth.js';
|
|
3
|
+
import { ApiError, AuthError } from './errors.js';
|
|
4
|
+
/**
|
|
5
|
+
* Create a configured openapi-fetch client for the Jinko BFF.
|
|
6
|
+
*
|
|
7
|
+
* Auth is determined by the token format:
|
|
8
|
+
* - `jnk_...` → API key auth (X-API-Key header)
|
|
9
|
+
* - anything else → OAuth JWT (Authorization: Bearer header)
|
|
10
|
+
*/
|
|
11
|
+
export async function createJinkoClient(options = {}) {
|
|
12
|
+
const auth = await resolveAuth(options.apiKey);
|
|
13
|
+
if (!auth) {
|
|
14
|
+
throw new AuthError();
|
|
15
|
+
}
|
|
16
|
+
const baseUrl = await resolveBaseUrl(options.baseUrl);
|
|
17
|
+
const client = createClient({ baseUrl });
|
|
18
|
+
// Auth middleware — injects the right headers based on auth method.
|
|
19
|
+
const authMiddleware = {
|
|
20
|
+
async onRequest({ request }) {
|
|
21
|
+
const headers = new Headers(request.headers);
|
|
22
|
+
headers.set('X-Tenant-ID', 'jinko');
|
|
23
|
+
headers.set('Content-Type', 'application/json');
|
|
24
|
+
headers.set('Accept', 'application/json');
|
|
25
|
+
if (auth.method === 'api_key') {
|
|
26
|
+
headers.set('X-API-Key', auth.token);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
headers.set('Authorization', `Bearer ${auth.token}`);
|
|
30
|
+
}
|
|
31
|
+
return new Request(request.url, { ...request, headers });
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
// Error middleware — converts HTTP errors to ApiError.
|
|
35
|
+
const errorMiddleware = {
|
|
36
|
+
async onResponse({ response }) {
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
let detail = { code: 'API_ERROR', message: response.statusText };
|
|
39
|
+
try {
|
|
40
|
+
const body = await response.clone().json();
|
|
41
|
+
if (body?.error) {
|
|
42
|
+
detail = { ...detail, ...body.error };
|
|
43
|
+
}
|
|
44
|
+
else if (body?.message) {
|
|
45
|
+
detail = { ...detail, message: body.message };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Response body isn't JSON — use statusText.
|
|
50
|
+
}
|
|
51
|
+
throw new ApiError({ ...detail, statusCode: response.status });
|
|
52
|
+
}
|
|
53
|
+
return response;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
client.use(authMiddleware);
|
|
57
|
+
client.use(errorMiddleware);
|
|
58
|
+
return { raw: client, baseUrl, auth };
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","source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|
|
5
|
+
}
|
|
6
|
+
export declare class ApiError extends Error {
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly statusCode: number;
|
|
9
|
+
readonly docUrl?: string;
|
|
10
|
+
constructor(detail: ApiErrorDetail & {
|
|
11
|
+
statusCode: number;
|
|
12
|
+
});
|
|
13
|
+
toJSON(): ApiErrorDetail & {
|
|
14
|
+
statusCode: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export declare class AuthError extends ApiError {
|
|
18
|
+
constructor(message?: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class ValidationError extends ApiError {
|
|
21
|
+
constructor(message: string);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEb,MAAM,EAAE,cAAc,GAAG;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE;IAQ3D,MAAM,IAAI,cAAc,GAAG;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE;CAQlD;AAED,qBAAa,SAAU,SAAQ,QAAQ;gBACzB,OAAO,SAA0E;CAI9F;AAED,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,OAAO,EAAE,MAAM;CAI5B"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export class ApiError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
statusCode;
|
|
4
|
+
docUrl;
|
|
5
|
+
constructor(detail) {
|
|
6
|
+
super(detail.message);
|
|
7
|
+
this.name = 'ApiError';
|
|
8
|
+
this.code = detail.code;
|
|
9
|
+
this.statusCode = detail.statusCode;
|
|
10
|
+
this.docUrl = detail.doc_url;
|
|
11
|
+
}
|
|
12
|
+
toJSON() {
|
|
13
|
+
return {
|
|
14
|
+
code: this.code,
|
|
15
|
+
message: this.message,
|
|
16
|
+
statusCode: this.statusCode,
|
|
17
|
+
doc_url: this.docUrl,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class AuthError extends ApiError {
|
|
22
|
+
constructor(message = 'Authentication required. Run `jinko auth login` or set JINKO_API_KEY.') {
|
|
23
|
+
super({ code: 'AUTH_REQUIRED', message, statusCode: 401 });
|
|
24
|
+
this.name = 'AuthError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class ValidationError extends ApiError {
|
|
28
|
+
constructor(message) {
|
|
29
|
+
super({ code: 'VALIDATION_ERROR', message, statusCode: 422 });
|
|
30
|
+
this.name = 'ValidationError';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,IAAI,CAAS;IACb,UAAU,CAAS;IACnB,MAAM,CAAU;IAEzB,YAAY,MAA+C;QACzD,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;IAC/B,CAAC;IAED,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,OAAO,EAAE,IAAI,CAAC,MAAM;SACrB,CAAC;IACJ,CAAC;CACF;AAED,MAAM,OAAO,SAAU,SAAQ,QAAQ;IACrC,YAAY,OAAO,GAAG,uEAAuE;QAC3F,KAAK,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;QAC3D,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createJinkoClient, type ClientOptions, type JinkoClient } from './client.js';
|
|
2
|
+
export { resolveAuth, resolveBaseUrl, readConfigFile, writeConfigFile, CONFIG_DIR, CONFIG_FILE, DEFAULT_BASE_URL, type AuthMethod, type ResolvedAuth } from './auth.js';
|
|
3
|
+
export { ApiError, AuthError, ValidationError, type ApiErrorDetail } from './errors.js';
|
|
4
|
+
export type { paths, components } from './types/generated.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AACxK,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AACxF,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createJinkoClient } from './client.js';
|
|
2
|
+
export { resolveAuth, resolveBaseUrl, readConfigFile, writeConfigFile, CONFIG_DIR, CONFIG_FILE, DEFAULT_BASE_URL } from './auth.js';
|
|
3
|
+
export { ApiError, AuthError, ValidationError } from './errors.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAwC,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAsC,MAAM,WAAW,CAAC;AACxK,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAuB,MAAM,aAAa,CAAC"}
|