@ultra-network/sdk-ts 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ultra Network
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 ADDED
@@ -0,0 +1,91 @@
1
+ # @ultra-network/sdk-ts
2
+
3
+ Official TypeScript client for the [Ultra Network Public API v1](https://ultranetwork.co/developers).
4
+
5
+ Typed for trips, suppliers, and bookings. The types are generated from the same OpenAPI document that powers the API, MCP server, and CLI — so the SDK never drifts from the contract.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @ultra-network/sdk-ts
11
+ ```
12
+
13
+ Requires Node 20+ (or any runtime with a global `fetch`). Zero runtime dependencies.
14
+
15
+ ## Quick start
16
+
17
+ ```ts
18
+ import { UltraClient } from '@ultra-network/sdk-ts';
19
+
20
+ const ultra = new UltraClient({ apiKey: process.env.ULTRA_API_KEY! });
21
+
22
+ // Browse preferred hotel suppliers
23
+ const { data, page } = await ultra.suppliers.list({ category: 'hotel', limit: 25 });
24
+
25
+ // Build a trip
26
+ const trip = await ultra.trips.create({ client_id, title: 'Cartagena anniversary' });
27
+ await ultra.trips.items.create(trip.id, {
28
+ type: 'accommodation',
29
+ title: 'Casa San Agustín',
30
+ day_index: 0,
31
+ });
32
+
33
+ // Record a booking
34
+ const booking = await ultra.bookings.create({
35
+ trip_id: trip.id,
36
+ supplier_source: 'manual',
37
+ venue_name: 'Casa San Agustín',
38
+ total: { amount: 120000, currency: 'USD' },
39
+ });
40
+ ```
41
+
42
+ ## Errors
43
+
44
+ Every non-2xx response throws `UltraApiError`. Branch on `code`, never `message`:
45
+
46
+ ```ts
47
+ import { UltraApiError } from '@ultra-network/sdk-ts';
48
+
49
+ try {
50
+ await ultra.trips.get(id);
51
+ } catch (err) {
52
+ if (err instanceof UltraApiError && err.code === 'not_found') {
53
+ // handle the missing trip; err.requestId mirrors the X-Request-Id header
54
+ }
55
+ }
56
+ ```
57
+
58
+ ## Pagination
59
+
60
+ List methods return `{ data, page }` with an opaque keyset cursor. Pass `page.next_cursor` back as `cursor`:
61
+
62
+ ```ts
63
+ let cursor: string | undefined;
64
+ const all = [];
65
+ do {
66
+ const res = await ultra.trips.list({ cursor });
67
+ all.push(...res.data);
68
+ cursor = res.page.next_cursor ?? undefined;
69
+ } while (cursor);
70
+ ```
71
+
72
+ ## Configuration
73
+
74
+ | Option | Default | Notes |
75
+ | --- | --- | --- |
76
+ | `apiKey` | — | Required. Bearer key (`ulk_…`) from the developer dashboard. |
77
+ | `baseUrl` | `https://ultranetwork.co/api/v1` | Override for staging or self-hosted. |
78
+ | `fetch` | global `fetch` | Pass a custom implementation on runtimes without one. |
79
+
80
+ ## Spec-driven
81
+
82
+ Types live in `src/generated/schema.d.ts`, regenerated from the live OpenAPI spec with `npm run generate`. Same contract, every surface — see the [MCP server](https://www.npmjs.com/package/@ultra-network/mcp) and [CLI](https://www.npmjs.com/package/@ultra-network/cli).
83
+
84
+ ## Links
85
+
86
+ - Developer hub — https://ultranetwork.co/developers
87
+ - Interactive API reference — https://ultranetwork.co/api/v1/docs
88
+
89
+ ## License
90
+
91
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ UltraApiError: () => UltraApiError,
24
+ UltraClient: () => UltraClient,
25
+ createUltraClient: () => createUltraClient
26
+ });
27
+ module.exports = __toCommonJS(src_exports);
28
+ var UltraApiError = class extends Error {
29
+ code;
30
+ status;
31
+ requestId;
32
+ details;
33
+ constructor(message, info) {
34
+ super(message);
35
+ this.name = "UltraApiError";
36
+ this.code = info.code;
37
+ this.status = info.status;
38
+ this.requestId = info.requestId;
39
+ this.details = info.details;
40
+ }
41
+ };
42
+ var DEFAULT_BASE_URL = "https://ultranetwork.co/api/v1";
43
+ var UltraClient = class {
44
+ #apiKey;
45
+ #baseUrl;
46
+ #fetch;
47
+ constructor(config) {
48
+ if (!config?.apiKey) throw new Error("UltraClient: `apiKey` is required.");
49
+ this.#apiKey = config.apiKey;
50
+ this.#baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
51
+ this.#fetch = config.fetch ?? globalThis.fetch;
52
+ if (typeof this.#fetch !== "function") {
53
+ throw new Error("UltraClient: no `fetch` available \u2014 pass `config.fetch` on runtimes without a global fetch.");
54
+ }
55
+ }
56
+ async #request(method, path, opts) {
57
+ const url = new URL(this.#baseUrl + path);
58
+ if (opts?.query) {
59
+ for (const [key, value] of Object.entries(opts.query)) {
60
+ if (value !== void 0 && value !== null) url.searchParams.set(key, String(value));
61
+ }
62
+ }
63
+ const headers = {
64
+ Authorization: `Bearer ${this.#apiKey}`,
65
+ Accept: "application/json"
66
+ };
67
+ if (opts?.body !== void 0) headers["Content-Type"] = "application/json";
68
+ const res = await this.#fetch(url.toString(), {
69
+ method,
70
+ headers,
71
+ body: opts?.body !== void 0 ? JSON.stringify(opts.body) : void 0
72
+ });
73
+ if (res.status === 204) return void 0;
74
+ const text = await res.text();
75
+ const json = text ? JSON.parse(text) : void 0;
76
+ if (!res.ok) {
77
+ const envelope = json?.error;
78
+ throw new UltraApiError(envelope?.message ?? `Ultra API request failed with status ${res.status}`, {
79
+ code: envelope?.code ?? "unknown",
80
+ status: res.status,
81
+ requestId: envelope?.request_id ?? res.headers.get("x-request-id") ?? void 0,
82
+ details: envelope?.details
83
+ });
84
+ }
85
+ return json;
86
+ }
87
+ trips = {
88
+ list: (params) => this.#request("GET", "/trips", { query: params }),
89
+ create: (input) => this.#request("POST", "/trips", { body: input }),
90
+ get: (id) => this.#request("GET", `/trips/${encodeURIComponent(id)}`),
91
+ items: {
92
+ list: (tripId, params) => this.#request("GET", `/trips/${encodeURIComponent(tripId)}/items`, { query: params }),
93
+ create: (tripId, input) => this.#request("POST", `/trips/${encodeURIComponent(tripId)}/items`, { body: input }),
94
+ update: (tripId, itemId, input) => this.#request("PATCH", `/trips/${encodeURIComponent(tripId)}/items/${encodeURIComponent(itemId)}`, {
95
+ body: input
96
+ }),
97
+ remove: (tripId, itemId) => this.#request("DELETE", `/trips/${encodeURIComponent(tripId)}/items/${encodeURIComponent(itemId)}`)
98
+ }
99
+ };
100
+ suppliers = {
101
+ list: (params) => this.#request("GET", "/suppliers", { query: params }),
102
+ get: (id) => this.#request("GET", `/suppliers/${encodeURIComponent(id)}`)
103
+ };
104
+ bookings = {
105
+ list: (params) => this.#request("GET", "/bookings", { query: params }),
106
+ create: (input) => this.#request("POST", "/bookings", { body: input }),
107
+ get: (id) => this.#request("GET", `/bookings/${encodeURIComponent(id)}`),
108
+ update: (id, input) => this.#request("PATCH", `/bookings/${encodeURIComponent(id)}`, { body: input })
109
+ };
110
+ };
111
+ function createUltraClient(config) {
112
+ return new UltraClient(config);
113
+ }
114
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @ultra-network/sdk-ts — official TypeScript client for the Ultra Network Public API v1.\n *\n * Types are derived from the same OpenAPI document that powers the API, MCP\n * server, and CLI (see ./generated/schema). One contract, every surface.\n *\n * import { UltraClient } from '@ultra-network/sdk-ts';\n * const ultra = new UltraClient({ apiKey: process.env.ULTRA_API_KEY! });\n * const { data } = await ultra.suppliers.list({ category: 'hotel' });\n */\nimport type { components } from './generated/schema';\n\ntype Schemas = components['schemas'];\n\nexport type Money = Schemas['Money'];\nexport type PageMeta = Schemas['PageMeta'];\nexport type Trip = Schemas['Trip'];\nexport type CreateTripInput = Schemas['CreateTripInput'];\nexport type Supplier = Schemas['Supplier'];\nexport type SupplierContact = Schemas['SupplierContact'];\nexport type Booking = Schemas['Booking'];\nexport type CreateBookingInput = Schemas['CreateBookingInput'];\nexport type UpdateBookingInput = Schemas['UpdateBookingInput'];\nexport type TripItem = Schemas['TripItem'];\nexport type CreateTripItemInput = Schemas['CreateTripItemInput'];\nexport type UpdateTripItemInput = Schemas['UpdateTripItemInput'];\nexport type ApiErrorCode = Schemas['Error']['error']['code'];\n\n/** A keyset-paginated list response. Pass `page.next_cursor` back as `cursor` for the next page. */\nexport interface Page<T> {\n data: T[];\n page: PageMeta;\n}\n\nexport interface UltraClientConfig {\n /** Bearer API key (`ulk_…`), issued from the Ultra developer dashboard. */\n apiKey: string;\n /** API base URL. Defaults to the production API. */\n baseUrl?: string;\n /** Custom fetch implementation. Defaults to the global `fetch`. */\n fetch?: typeof fetch;\n}\n\nexport interface ListParams {\n cursor?: string;\n limit?: number;\n}\n\nexport interface ListTripsParams extends ListParams {\n stage?: Trip['stage'];\n organization_id?: string;\n updated_since?: string;\n}\n\nexport interface ListSuppliersParams extends ListParams {\n category?: Supplier['category'];\n country?: string;\n organization_id?: string;\n active_only?: boolean;\n updated_since?: string;\n}\n\nexport interface ListBookingsParams extends ListParams {\n trip_id?: string;\n status?: Booking['status'];\n updated_since?: string;\n}\n\n/** Thrown for any non-2xx response. Branch on `code`, never `message`. */\nexport class UltraApiError extends Error {\n readonly code: ApiErrorCode | 'unknown';\n readonly status: number;\n readonly requestId?: string;\n readonly details?: Record<string, unknown>;\n\n constructor(\n message: string,\n info: { code: ApiErrorCode | 'unknown'; status: number; requestId?: string; details?: Record<string, unknown> },\n ) {\n super(message);\n this.name = 'UltraApiError';\n this.code = info.code;\n this.status = info.status;\n this.requestId = info.requestId;\n this.details = info.details;\n }\n}\n\nconst DEFAULT_BASE_URL = 'https://ultranetwork.co/api/v1';\n\ntype QueryValue = string | number | boolean | undefined;\n\nexport class UltraClient {\n readonly #apiKey: string;\n readonly #baseUrl: string;\n readonly #fetch: typeof fetch;\n\n constructor(config: UltraClientConfig) {\n if (!config?.apiKey) throw new Error('UltraClient: `apiKey` is required.');\n this.#apiKey = config.apiKey;\n this.#baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, '');\n this.#fetch = config.fetch ?? globalThis.fetch;\n if (typeof this.#fetch !== 'function') {\n throw new Error('UltraClient: no `fetch` available — pass `config.fetch` on runtimes without a global fetch.');\n }\n }\n\n async #request<T>(\n method: string,\n path: string,\n opts?: { query?: object; body?: unknown },\n ): Promise<T> {\n const url = new URL(this.#baseUrl + path);\n if (opts?.query) {\n for (const [key, value] of Object.entries(opts.query as Record<string, QueryValue>)) {\n if (value !== undefined && value !== null) url.searchParams.set(key, String(value));\n }\n }\n\n const headers: Record<string, string> = {\n Authorization: `Bearer ${this.#apiKey}`,\n Accept: 'application/json',\n };\n if (opts?.body !== undefined) headers['Content-Type'] = 'application/json';\n\n const res = await this.#fetch(url.toString(), {\n method,\n headers,\n body: opts?.body !== undefined ? JSON.stringify(opts.body) : undefined,\n });\n\n if (res.status === 204) return undefined as T;\n\n const text = await res.text();\n const json: unknown = text ? JSON.parse(text) : undefined;\n\n if (!res.ok) {\n const envelope = (json as { error?: Schemas['Error']['error'] } | undefined)?.error;\n throw new UltraApiError(envelope?.message ?? `Ultra API request failed with status ${res.status}`, {\n code: envelope?.code ?? 'unknown',\n status: res.status,\n requestId: envelope?.request_id ?? res.headers.get('x-request-id') ?? undefined,\n details: envelope?.details,\n });\n }\n\n return json as T;\n }\n\n readonly trips = {\n list: (params?: ListTripsParams) => this.#request<Page<Trip>>('GET', '/trips', { query: params }),\n create: (input: CreateTripInput) => this.#request<Trip>('POST', '/trips', { body: input }),\n get: (id: string) => this.#request<Trip>('GET', `/trips/${encodeURIComponent(id)}`),\n items: {\n list: (tripId: string, params?: ListParams) =>\n this.#request<Page<TripItem>>('GET', `/trips/${encodeURIComponent(tripId)}/items`, { query: params }),\n create: (tripId: string, input: CreateTripItemInput) =>\n this.#request<TripItem>('POST', `/trips/${encodeURIComponent(tripId)}/items`, { body: input }),\n update: (tripId: string, itemId: string, input: UpdateTripItemInput) =>\n this.#request<TripItem>('PATCH', `/trips/${encodeURIComponent(tripId)}/items/${encodeURIComponent(itemId)}`, {\n body: input,\n }),\n remove: (tripId: string, itemId: string) =>\n this.#request<void>('DELETE', `/trips/${encodeURIComponent(tripId)}/items/${encodeURIComponent(itemId)}`),\n },\n };\n\n readonly suppliers = {\n list: (params?: ListSuppliersParams) => this.#request<Page<Supplier>>('GET', '/suppliers', { query: params }),\n get: (id: string) => this.#request<Supplier>('GET', `/suppliers/${encodeURIComponent(id)}`),\n };\n\n readonly bookings = {\n list: (params?: ListBookingsParams) => this.#request<Page<Booking>>('GET', '/bookings', { query: params }),\n create: (input: CreateBookingInput) => this.#request<Booking>('POST', '/bookings', { body: input }),\n get: (id: string) => this.#request<Booking>('GET', `/bookings/${encodeURIComponent(id)}`),\n update: (id: string, input: UpdateBookingInput) =>\n this.#request<Booking>('PATCH', `/bookings/${encodeURIComponent(id)}`, { body: input }),\n };\n}\n\n/** Convenience factory — equivalent to `new UltraClient(config)`. */\nexport function createUltraClient(config: UltraClientConfig): UltraClient {\n return new UltraClient(config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqEO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,SACA,MACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO,KAAK;AACjB,SAAK,SAAS,KAAK;AACnB,SAAK,YAAY,KAAK;AACtB,SAAK,UAAU,KAAK;AAAA,EACtB;AACF;AAEA,IAAM,mBAAmB;AAIlB,IAAM,cAAN,MAAkB;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAA2B;AACrC,QAAI,CAAC,QAAQ,OAAQ,OAAM,IAAI,MAAM,oCAAoC;AACzE,SAAK,UAAU,OAAO;AACtB,SAAK,YAAY,OAAO,WAAW,kBAAkB,QAAQ,QAAQ,EAAE;AACvE,SAAK,SAAS,OAAO,SAAS,WAAW;AACzC,QAAI,OAAO,KAAK,WAAW,YAAY;AACrC,YAAM,IAAI,MAAM,kGAA6F;AAAA,IAC/G;AAAA,EACF;AAAA,EAEA,MAAM,SACJ,QACA,MACA,MACY;AACZ,UAAM,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