@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.
@@ -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":";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,MAAM,IAAI,IAAI,KAAK,WAAW,IAAI;AACxC,QAAI,MAAM,OAAO;AACf,iBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,KAAmC,GAAG;AACnF,YAAI,UAAU,UAAa,UAAU,KAAM,KAAI,aAAa,IAAI,KAAK,OAAO,KAAK,CAAC;AAAA,MACpF;AAAA,IACF;AAEA,UAAM,UAAkC;AAAA,MACtC,eAAe,UAAU,KAAK,OAAO;AAAA,MACrC,QAAQ;AAAA,IACV;AACA,QAAI,MAAM,SAAS,OAAW,SAAQ,cAAc,IAAI;AAExD,UAAM,MAAM,MAAM,KAAK,OAAO,IAAI,SAAS,GAAG;AAAA,MAC5C;AAAA,MACA;AAAA,MACA,MAAM,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BAAmB,MAAM,CAAC,UAAU,mBAAmB,MAAM,CAAC,EAAE;AAAA,IAC5G;AAAA,EACF;AAAA,EAES,YAAY;AAAA,IACnB,MAAM,CAAC,WAAiC,KAAK,SAAyB,OAAO,cAAc,EAAE,OAAO,OAAO,CAAC;AAAA,IAC5G,KAAK,CAAC,OAAe,KAAK,SAAmB,OAAO,cAAc,mBAAmB,EAAE,CAAC,EAAE;AAAA,EAC5F;AAAA,EAES,WAAW;AAAA,IAClB,MAAM,CAAC,WAAgC,KAAK,SAAwB,OAAO,aAAa,EAAE,OAAO,OAAO,CAAC;AAAA,IACzG,QAAQ,CAAC,UAA8B,KAAK,SAAkB,QAAQ,aAAa,EAAE,MAAM,MAAM,CAAC;AAAA,IAClG,KAAK,CAAC,OAAe,KAAK,SAAkB,OAAO,aAAa,mBAAmB,EAAE,CAAC,EAAE;AAAA,IACxF,QAAQ,CAAC,IAAY,UACnB,KAAK,SAAkB,SAAS,aAAa,mBAAmB,EAAE,CAAC,IAAI,EAAE,MAAM,MAAM,CAAC;AAAA,EAC1F;AACF;AAGO,SAAS,kBAAkB,QAAwC;AACxE,SAAO,IAAI,YAAY,MAAM;AAC/B;","names":[]}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@ultra-network/sdk-ts",
3
+ "version": "0.1.0",
4
+ "description": "Official TypeScript SDK for the Ultra Network Public API v1 — a typed client for trips, suppliers, and bookings. Types are generated from the same OpenAPI document that powers the API, MCP server, and CLI, so they never drift from the contract.",
5
+ "keywords": [
6
+ "sdk",
7
+ "ultra",
8
+ "ultra-network",
9
+ "luxury-travel",
10
+ "api",
11
+ "openapi",
12
+ "typescript"
13
+ ],
14
+ "homepage": "https://github.com/timebinder/ultra-developers",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/timebinder/ultra-developers.git",
18
+ "directory": "packages/sdk-ts"
19
+ },
20
+ "bugs": "https://github.com/timebinder/ultra-developers/issues",
21
+ "license": "MIT",
22
+ "author": "Ultra Network",
23
+ "type": "module",
24
+ "main": "./dist/index.cjs",
25
+ "module": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js",
31
+ "require": "./dist/index.cjs"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md",
37
+ "LICENSE"
38
+ ],
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "scripts": {
43
+ "generate": "node scripts/generate.mjs",
44
+ "build": "tsup",
45
+ "type-check": "tsc --noEmit",
46
+ "prepublishOnly": "npm run build",
47
+ "clean": "rm -rf .turbo node_modules dist"
48
+ },
49
+ "devDependencies": {
50
+ "openapi-typescript": "^7.4.0"
51
+ },
52
+ "engines": {
53
+ "node": ">=20"
54
+ }
55
+ }