@nextxai/sdk 0.0.0-stage → 0.1.0-beta.5

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.
@@ -0,0 +1 @@
1
+ export declare const VERSION = "0.1.0-beta.5";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERSION = void 0;
4
+ exports.VERSION = "0.1.0-beta.5";
@@ -0,0 +1,43 @@
1
+ /**
2
+ * NextX SDK cho Node.js/TypeScript. Kiểu `paths` sinh từ https://developers.nextx.vn/openapi.json — chỉ gồm các tuyến
3
+ * đối tác gọi được — nên trình soạn thảo gợi đúng đường, tham số và hình dạng phản hồi.
4
+ *
5
+ * const nx = createNextXClient({ apiKey: process.env.NEXTX_API_KEY! });
6
+ * const { data, error } = await nx.GET("/api/v1/crm/contacts", { params: { query: { pageSize: 20 } } });
7
+ */
8
+ import { type Client } from "openapi-fetch";
9
+ import type { paths } from "./schema.js";
10
+ import { VERSION } from "./version.js";
11
+ export type { paths, components, operations } from "./schema.js";
12
+ export { VERSION };
13
+ export declare const PROD_URL = "https://api.nextx.vn";
14
+ export declare const SANDBOX_URL = "https://api-dev.nextx.vn";
15
+ export type NextXOptions = {
16
+ /** Mặc định prod; thử nghiệm dùng `SANDBOX_URL` (khoá sandbox không gọi được prod và ngược lại). */
17
+ baseUrl?: string;
18
+ /** Ngôn ngữ thông báo lỗi: `vi` (mặc định) hoặc `en`. */
19
+ language?: "vi" | "en";
20
+ /** Thay fetch (proxy, đo đạc, kiểm thử). */
21
+ fetch?: typeof globalThis.fetch;
22
+ } & (
23
+ /** Khoá API của workspace (`nxk_…`) — gửi ở header `X-Api-Key`. */
24
+ {
25
+ apiKey: string;
26
+ accessToken?: never;
27
+ }
28
+ /** Access token OAuth 2.0 của ứng dụng đối tác — gửi `Authorization: Bearer`; có thể là hàm để lấy token mới mỗi lần gọi. */
29
+ | {
30
+ accessToken: string | (() => string | Promise<string>);
31
+ apiKey?: never;
32
+ });
33
+ export type NextXClient = Client<paths>;
34
+ /** Lỗi theo RFC 7807 mà API trả về khi `error` khác rỗng. */
35
+ export interface NextXProblem {
36
+ type?: string;
37
+ title?: string;
38
+ status?: number;
39
+ detail?: string;
40
+ traceId?: string;
41
+ errors?: Record<string, string[]> | string[] | null;
42
+ }
43
+ export declare function createNextXClient(opts: NextXOptions): NextXClient;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * NextX SDK cho Node.js/TypeScript. Kiểu `paths` sinh từ https://developers.nextx.vn/openapi.json — chỉ gồm các tuyến
3
+ * đối tác gọi được — nên trình soạn thảo gợi đúng đường, tham số và hình dạng phản hồi.
4
+ *
5
+ * const nx = createNextXClient({ apiKey: process.env.NEXTX_API_KEY! });
6
+ * const { data, error } = await nx.GET("/api/v1/crm/contacts", { params: { query: { pageSize: 20 } } });
7
+ */
8
+ import createClient from "openapi-fetch";
9
+ import { VERSION } from "./version.js";
10
+ export { VERSION };
11
+ export const PROD_URL = "https://api.nextx.vn";
12
+ export const SANDBOX_URL = "https://api-dev.nextx.vn";
13
+ export function createNextXClient(opts) {
14
+ const { baseUrl = PROD_URL, language = "vi", fetch } = opts;
15
+ if (!opts.apiKey && !opts.accessToken)
16
+ throw new Error("NextX SDK: cần apiKey hoặc accessToken");
17
+ const client = createClient({
18
+ baseUrl: baseUrl.replace(/\/+$/, ""),
19
+ fetch,
20
+ headers: {
21
+ "Accept-Language": language,
22
+ // Trình duyệt tự bỏ User-Agent nên chỉ có tác dụng phía máy chủ.
23
+ "User-Agent": `nextx-sdk-node/${VERSION}`,
24
+ ...(opts.apiKey ? { "X-Api-Key": opts.apiKey } : {}),
25
+ },
26
+ });
27
+ const token = opts.accessToken;
28
+ if (token) {
29
+ const auth = {
30
+ async onRequest({ request }) {
31
+ request.headers.set("Authorization", `Bearer ${typeof token === "function" ? await token() : token}`);
32
+ return request;
33
+ },
34
+ };
35
+ client.use(auth);
36
+ }
37
+ return client;
38
+ }