@graph8/sdk 0.17.0 → 0.49.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/README.md +80 -0
- package/dist/index.d.mts +26892 -353
- package/dist/index.d.ts +26892 -353
- package/dist/index.js +1225 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1220 -42
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +25744 -215
- package/dist/react.d.ts +25744 -215
- package/dist/react.js +1224 -42
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +1224 -42
- package/dist/react.mjs.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -129,6 +129,86 @@ export const CTA = () => {
|
|
|
129
129
|
};
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
+
## Every endpoint: `g8.api` (generated from the contract)
|
|
133
|
+
|
|
134
|
+
The clients above are the ergonomic layer — hand-written, opinionated, and only
|
|
135
|
+
as complete as someone made them. `g8.api` is the complete one: it is
|
|
136
|
+
**generated from the published OpenAPI contract**, so it covers **every one of
|
|
137
|
+
the 587 Developer API operations**, including surfaces with no hand-written
|
|
138
|
+
client (Appointments, Radar, App Objects, Ad Campaigns, Sandbox, Landing Pages,
|
|
139
|
+
Agent, OpenSearch, ClickHouse and more).
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { g8 } from '@graph8/sdk';
|
|
143
|
+
|
|
144
|
+
g8.init({ apiKey: process.env.G8_API_KEY });
|
|
145
|
+
|
|
146
|
+
// Grouped by resource, with full autocomplete on inputs and responses.
|
|
147
|
+
const bookings = await g8.api.appointments.listBookings({ query: { take: 50 } }); // `take`, not `limit` — the types say so
|
|
148
|
+
const competitors = await g8.api.radar.listCompetitors();
|
|
149
|
+
|
|
150
|
+
// Or address an operation by its stable, published operationId.
|
|
151
|
+
const contacts = await g8.api.call('list_contacts_contacts_get', { query: { limit: 50 } });
|
|
152
|
+
|
|
153
|
+
// Path, query, headers and body are separate and individually typed.
|
|
154
|
+
const contact = await g8.api.contacts.getContact({ path: { contact_id: 123 } });
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Auto-pagination follows `pagination.next_cursor` for you:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { g8 } from '@graph8/sdk';
|
|
161
|
+
|
|
162
|
+
for await (const contact of g8.api.paginate('list_contacts_contacts_get', { query: { limit: 100 } })) {
|
|
163
|
+
console.log(contact);
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Every operation carries the side-effect tier and the API-key scope the API
|
|
168
|
+
publishes for it, so an integration can warn a human before a call that spends
|
|
169
|
+
credits or deletes something:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { g8 } from '@graph8/sdk';
|
|
173
|
+
|
|
174
|
+
const op = g8.api.operation('list_contacts_contacts_get');
|
|
175
|
+
// { method: 'GET', path: '/api/v1/contacts', tier: 'read', scope: 'contacts:read', ... }
|
|
176
|
+
|
|
177
|
+
const risky = g8.api.operations().filter((o) => o.tier === 'billable' || o.tier === 'destructive');
|
|
178
|
+
console.log(`${risky.length} operations have side effects worth confirming`);
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Contract schemas are available as types under the `G8Contract` namespace:
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import type { G8Contract } from '@graph8/sdk';
|
|
185
|
+
|
|
186
|
+
function fullName(contact: G8Contract.ContactResponse): string {
|
|
187
|
+
return [contact.first_name, contact.last_name].filter(Boolean).join(' ');
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Or let the operation map name them for you, with no import of the schema at all:
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import { g8, type ApiOutput } from '@graph8/sdk';
|
|
195
|
+
|
|
196
|
+
type ContactPage = ApiOutput<'list_contacts_contacts_get'>;
|
|
197
|
+
|
|
198
|
+
async function firstPage(): Promise<ContactPage> {
|
|
199
|
+
return g8.api.call('list_contacts_contacts_get', { query: { limit: 25 } });
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Two things to know before reaching for it:
|
|
204
|
+
|
|
205
|
+
- **It returns the raw response envelope.** The hand-written clients unwrap
|
|
206
|
+
`.data` and rename fields for you; `g8.api` gives you exactly what the
|
|
207
|
+
contract declares. Prefer the hand-written client where one exists.
|
|
208
|
+
- **It is generated — never hand-edited.** `sdk/js/src/generated/**` is produced
|
|
209
|
+
by `npm run generate` from `developer-contract/openapi.json`, and CI fails if
|
|
210
|
+
the two disagree. That is what keeps coverage at 100% as the API grows.
|
|
211
|
+
|
|
132
212
|
## Full API Reference
|
|
133
213
|
|
|
134
214
|
### Core (write key)
|