@tapi-dev/sdk 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +140 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # TAPI JavaScript SDK
2
+
3
+ Official JavaScript and TypeScript client for TAPI developer APIs.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @tapi-dev/sdk
9
+ ```
10
+
11
+ This package is ESM-first and works in runtimes with `fetch`, including modern Node.js and browser-like server runtimes.
12
+
13
+ ## Quick Start
14
+
15
+ Create one TAPI client in your app's server-side code:
16
+
17
+ ```ts
18
+ import { TapiClient } from "@tapi-dev/sdk";
19
+
20
+ export const tapi = new TapiClient({
21
+ baseUrl: process.env.TAPI_BASE_URL!,
22
+ apiKey: process.env.TAPI_API_KEY!,
23
+ appId: process.env.TAPI_APP_ID,
24
+ });
25
+ ```
26
+
27
+ Then call a TAPI website API:
28
+
29
+ ```ts
30
+ const run = await tapi.websiteApis.run("brokerage.submitTrade", {
31
+ inputs: {
32
+ symbol: "AAPL",
33
+ quantity: 1,
34
+ side: "buy",
35
+ },
36
+ });
37
+
38
+ const completedRun = await tapi.runs.wait(run.id);
39
+ console.log(completedRun.status, completedRun.result);
40
+ ```
41
+
42
+ Do not expose `TAPI_API_KEY` in public browser bundles. Put the SDK behind your own backend route, server action, or job worker when using secret API keys.
43
+
44
+ ## Configuration
45
+
46
+ ```env
47
+ TAPI_BASE_URL=https://your-tapi-api-host
48
+ TAPI_API_KEY=tapi_your_api_key
49
+ TAPI_APP_ID=your-app-id
50
+ ```
51
+
52
+ `appId` is optional. If provided, the SDK sends it as the `X-Tapi-App` header.
53
+
54
+ ## Common Project Setup
55
+
56
+ A typical application keeps the client in one small module:
57
+
58
+ ```text
59
+ src/
60
+ lib/
61
+ tapi.ts
62
+ ```
63
+
64
+ ```ts
65
+ // src/lib/tapi.ts
66
+ import { TapiClient } from "@tapi-dev/sdk";
67
+
68
+ export const tapi = new TapiClient({
69
+ baseUrl: process.env.TAPI_BASE_URL!,
70
+ apiKey: process.env.TAPI_API_KEY!,
71
+ appId: process.env.TAPI_APP_ID,
72
+ });
73
+ ```
74
+
75
+ Application code should import this shared client instead of constructing a new client in every file.
76
+
77
+ ## Available Resources
78
+
79
+ ```ts
80
+ await tapi.catalog.get();
81
+ await tapi.runners.list();
82
+ await tapi.runtime.requirements();
83
+
84
+ const run = await tapi.websiteApis.run("apiName.requestKey", {
85
+ inputs: { example: true },
86
+ priority: 5,
87
+ runnerId: "runner-id",
88
+ idempotencyKey: "request-123",
89
+ });
90
+
91
+ await tapi.runs.get(run.id);
92
+ await tapi.runs.wait(run.id, { intervalMs: 1000, timeoutMs: 300000 });
93
+ await tapi.runs.cancel(run.id);
94
+ ```
95
+
96
+ Website API requests are addressed as `<apiName>.<requestKey>`.
97
+
98
+ ## Errors
99
+
100
+ Failed HTTP responses throw `TapiError`:
101
+
102
+ ```ts
103
+ import { TapiError } from "@tapi-dev/sdk";
104
+
105
+ try {
106
+ await tapi.catalog.get();
107
+ } catch (error) {
108
+ if (error instanceof TapiError) {
109
+ console.error(error.status, error.code, error.details);
110
+ }
111
+ throw error;
112
+ }
113
+ ```
114
+
115
+ ## TypeScript
116
+
117
+ The package includes generated TypeScript declarations. Common exported types include:
118
+
119
+ ```ts
120
+ import type {
121
+ RuntimeRequirements,
122
+ SdkCatalog,
123
+ TapiRun,
124
+ TapiRunner,
125
+ WebsiteApiRunRequest,
126
+ } from "@tapi-dev/sdk";
127
+ ```
128
+
129
+ ## Local Development
130
+
131
+ From this SDK directory:
132
+
133
+ ```bash
134
+ npm ci
135
+ npm test
136
+ npm run build
137
+ npm pack --dry-run
138
+ ```
139
+
140
+ `npm pack --dry-run` shows the exact files that will be published.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapi-dev/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",