@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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Nhật ký thay đổi
2
+
3
+ Theo [Semantic Versioning](https://semver.org/lang/vi/). Chính sách phiên bản và bỏ dần: [VERSIONING.md](VERSIONING.md).
4
+
5
+ ## 0.1.0 — 2026-10-28
6
+
7
+ Bản đầu tiên (beta). Phủ 10 phân hệ NextX: CRM, Bán hàng, Chat đa kênh, Tổng đài, DMS, Nhân sự, Marketing, Office, Thanh toán, Hoá đơn điện tử.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NextX
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,33 @@
1
- # Temporary Holding Version
1
+ # @nextxai/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > Mã trong kho này được sinh tự động từ [OpenAPI công khai](https://developers.nextx.vn/openapi.json). Đừng sửa tay — xem [CONTRIBUTING.md](CONTRIBUTING.md).
4
+
5
+ Gọi NextX API từ Node.js và TypeScript, có kiểu đầy đủ. Kiểu sinh từ [`/openapi.json`](https://developers.nextx.vn/openapi.json)
6
+ và chỉ gồm các tuyến đối tác gọi được, nên trình soạn thảo gợi đúng đường dẫn, tham số và hình dạng phản hồi.
7
+
8
+ ```sh
9
+ npm i @nextxai/sdk
10
+ ```
11
+
12
+ ```ts
13
+ import { createNextXClient, SANDBOX_URL } from "@nextxai/sdk";
14
+
15
+ // Khoá API của workspace (tạo trong phần mềm NextX) — gửi ở header X-Api-Key
16
+ const nx = createNextXClient({ apiKey: process.env.NEXTX_API_KEY!, baseUrl: SANDBOX_URL });
17
+
18
+ const { data, error } = await nx.GET("/api/v1/crm/contacts", { params: { query: { pageSize: 20 } } });
19
+ if (error) throw new Error(`${error.status} ${error.title}`);
20
+ for (const c of data.items ?? []) console.log(c.fullName);
21
+ ```
22
+
23
+ Ứng dụng đối tác dùng OAuth 2.0 thì truyền access token (có thể là hàm để lấy token mới mỗi lần gọi):
24
+ `createNextXClient({ accessToken: () => tokenStore.current() })`.
25
+
26
+ - Node.js ≥ 18, Deno, Bun và trình duyệt (dùng `fetch` chuẩn). Hỗ trợ cả ESM (`import`) và CommonJS (`require`).
27
+ - Mặc định gọi prod (`PROD_URL`). Thử nghiệm thì dùng `SANDBOX_URL` với khoá sandbox.
28
+ - Lỗi theo RFC 7807, trả trong `error` (`status`, `title`, `detail`), không ném ngoại lệ.
29
+ - Gọi ghi (POST/PUT/PATCH) nên gửi kèm `Idempotency-Key` để thử lại an toàn:
30
+ `nx.POST(path, { body, headers: { "Idempotency-Key": crypto.randomUUID() } })`.
31
+ - Không đưa khoá API ra trình duyệt của người dùng cuối. Phía máy khách, dùng access token OAuth của ứng dụng.
32
+
33
+ Tài liệu: https://developers.nextx.vn/docs/sdk · Phiên bản và bỏ dần: [VERSIONING.md](https://github.com/nextx-organization/nextx-sdk-node/blob/main/VERSIONING.md) · Giấy phép MIT
@@ -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,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SANDBOX_URL = exports.PROD_URL = exports.VERSION = void 0;
4
+ exports.createNextXClient = createNextXClient;
5
+ /**
6
+ * NextX SDK cho Node.js/TypeScript. Kiểu `paths` sinh từ https://developers.nextx.vn/openapi.json — chỉ gồm các tuyến
7
+ * đố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.
8
+ *
9
+ * const nx = createNextXClient({ apiKey: process.env.NEXTX_API_KEY! });
10
+ * const { data, error } = await nx.GET("/api/v1/crm/contacts", { params: { query: { pageSize: 20 } } });
11
+ */
12
+ const openapi_fetch_1 = require("openapi-fetch");
13
+ const version_js_1 = require("./version.js");
14
+ Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_js_1.VERSION; } });
15
+ exports.PROD_URL = "https://api.nextx.vn";
16
+ exports.SANDBOX_URL = "https://api-dev.nextx.vn";
17
+ function createNextXClient(opts) {
18
+ const { baseUrl = exports.PROD_URL, language = "vi", fetch } = opts;
19
+ if (!opts.apiKey && !opts.accessToken)
20
+ throw new Error("NextX SDK: cần apiKey hoặc accessToken");
21
+ const client = (0, openapi_fetch_1.default)({
22
+ baseUrl: baseUrl.replace(/\/+$/, ""),
23
+ fetch,
24
+ headers: {
25
+ "Accept-Language": language,
26
+ // Trình duyệt tự bỏ User-Agent nên chỉ có tác dụng phía máy chủ.
27
+ "User-Agent": `nextx-sdk-node/${version_js_1.VERSION}`,
28
+ ...(opts.apiKey ? { "X-Api-Key": opts.apiKey } : {}),
29
+ },
30
+ });
31
+ const token = opts.accessToken;
32
+ if (token) {
33
+ const auth = {
34
+ async onRequest({ request }) {
35
+ request.headers.set("Authorization", `Bearer ${typeof token === "function" ? await token() : token}`);
36
+ return request;
37
+ },
38
+ };
39
+ client.use(auth);
40
+ }
41
+ return client;
42
+ }
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}