@goable-io/sdk 0.3.0 → 0.5.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/src/index.ts CHANGED
@@ -12,8 +12,11 @@
12
12
  export { GoableClient } from "./client.ts"
13
13
  export type { FetchLike, GoableClientOptions } from "./client.ts"
14
14
  export {
15
+ type ApiErrorExtra,
16
+ DriftActiveError,
15
17
  GoableApiError,
16
18
  GoableNetworkError,
19
+ type RateLimit,
17
20
  type ZodIssueLike,
18
21
  } from "./errors.ts"
19
22
  export type * from "./types.ts"
package/src/types.ts CHANGED
@@ -11,13 +11,46 @@
11
11
  import type { components, paths } from "./generated/api.ts"
12
12
 
13
13
  // ── helpers ────────────────────────────────────────────────────────────
14
- type JsonOf<T> = T extends { content: { "application/json": infer B } } ? B : never
15
- /** application/json request body of an operation. */
16
- type ReqOf<O> = O extends { requestBody?: infer RB } ? JsonOf<NonNullable<RB>> : never
17
- /** application/json body of a response status code. */
18
- type ResOf<O, C extends number> = O extends { responses: infer R } ? (C extends keyof R ? JsonOf<R[C]> : never) : never
19
-
14
+ /** The sole media body of a request/response, whatever the media type
15
+ * (application/json, application/ld+json, or application/x-ndjson string). */
16
+ type ContentOf<T> = T extends { content: infer C } ? C[keyof C] : never
17
+ /** Request body of an operation. */
18
+ type ReqOf<O> = O extends { requestBody?: infer RB } ? ContentOf<NonNullable<RB>> : never
19
+ /** Response body for a specific status code. */
20
+ type ResOf<O, C extends number> = O extends { responses: infer R }
21
+ ? C extends keyof R
22
+ ? ContentOf<R[C]>
23
+ : never
24
+ : never
25
+ /** The 2xx success body — the first of 200 / 201 / 202 the operation declares. */
26
+ type OkOf<O> = O extends { responses: infer R }
27
+ ? 200 extends keyof R
28
+ ? ContentOf<R[200]>
29
+ : 201 extends keyof R
30
+ ? ContentOf<R[201]>
31
+ : 202 extends keyof R
32
+ ? ContentOf<R[202]>
33
+ : never
34
+ : never
35
+ /** The query-parameter object of an operation. */
36
+ type QueryOf<O> = O extends { parameters: { query?: infer Q } } ? NonNullable<Q> : never
37
+ /** The path-parameter object of an operation. */
38
+ type PathOf<O> = O extends { parameters: { path?: infer P } } ? NonNullable<P> : never
39
+ /** The `application/json` body for a specific response status — used when an
40
+ * operation declares several media types (e.g. JSON + text/csv) and we want
41
+ * only the JSON branch, not the `object | string` union `ResOf` would give. */
42
+ type JsonResOf<O, C extends number> = O extends { responses: infer R }
43
+ ? C extends keyof R
44
+ ? R[C] extends { content: { "application/json": infer J } }
45
+ ? J
46
+ : never
47
+ : never
48
+ : never
49
+
50
+ type Get<P extends keyof paths> = paths[P] extends { get: infer O } ? O : never
20
51
  type Post<P extends keyof paths> = paths[P] extends { post: infer O } ? O : never
52
+ type Put<P extends keyof paths> = paths[P] extends { put: infer O } ? O : never
53
+ type Patch<P extends keyof paths> = paths[P] extends { patch: infer O } ? O : never
21
54
 
22
55
  // ── shared primitives (from components) ───────────────────────────────────
23
56
  export type GeoPoint = components["schemas"]["GeoPoint"]
@@ -61,6 +94,111 @@ export type QuoteResponse = ResOf<Post<"/v1/underwriting/quote">, 200>
61
94
  export type RecommendSpotRequest = ReqOf<Post<"/v1/recommend-spot">>
62
95
  export type RecommendSpotResponse = ResOf<Post<"/v1/recommend-spot">, 200>
63
96
 
97
+ export type ScoreDifficultyRequest = ReqOf<Post<"/v1/score/difficulty">>
98
+ export type ScoreDifficultyResponse = OkOf<Post<"/v1/score/difficulty">>
99
+
100
+ export type ReportOutcomeRequest = ReqOf<Post<"/v1/score/{sessionId}/outcome">>
101
+ export type ReportOutcomeResponse = OkOf<Post<"/v1/score/{sessionId}/outcome">>
102
+
103
+ /** Standalone activity outcome, not tied to a scored session (`POST /v1/outcomes`). */
104
+ export type SubmitOutcomeRequest = ReqOf<Post<"/v1/outcomes">>
105
+ export type SubmitOutcomeResponse = OkOf<Post<"/v1/outcomes">>
106
+
107
+ export type EdgeCaseRequest = ReqOf<Post<"/v1/intelligence/edge-case">>
108
+ export type EdgeCaseResponse = OkOf<Post<"/v1/intelligence/edge-case">>
109
+
110
+ export type ProjectionsPortfolioRequest = ReqOf<Post<"/v1/projections/portfolio">>
111
+ export type ProjectionsPortfolioResponse = OkOf<Post<"/v1/projections/portfolio">>
112
+
113
+ export type AdaptationReportRequest = ReqOf<Post<"/v1/projections/adaptation-report">>
114
+ export type AdaptationReportResponse = OkOf<Post<"/v1/projections/adaptation-report">>
115
+
116
+ // ── underwriting policy lifecycle ─────────────────────────────────────────
117
+ export type QuoteByIdResponse = OkOf<Get<"/v1/underwriting/quote/{id}">>
118
+
119
+ export type BindPolicyRequest = ReqOf<Post<"/v1/underwriting/policy/bind">>
120
+ export type BindPolicyResponse = OkOf<Post<"/v1/underwriting/policy/bind">>
121
+
122
+ export type ListPoliciesQuery = QueryOf<Get<"/v1/underwriting/policy">>
123
+ export type ListPoliciesResponse = OkOf<Get<"/v1/underwriting/policy">>
124
+
125
+ export type PolicyResponse = OkOf<Get<"/v1/underwriting/policy/{policyId}">>
126
+
127
+ export type EvaluatePolicyResponse = OkOf<Post<"/v1/underwriting/policy/{policyId}/evaluate">>
128
+
129
+ export type SettlePolicyRequest = ReqOf<Post<"/v1/underwriting/policy/{policyId}/settle">>
130
+ export type SettlePolicyResponse = OkOf<Post<"/v1/underwriting/policy/{policyId}/settle">>
131
+
132
+ /** Serialised parametric policy record + payout event, reused across the lifecycle. */
133
+ export type SerialisedPolicy = components["schemas"]["SerialisedPolicy"]
134
+ export type SerialisedPayoutEvent = components["schemas"]["SerialisedPayoutEvent"]
135
+
136
+ // ── observations (L5.3) ───────────────────────────────────────────────────
137
+ export type CreateStationRequest = ReqOf<Post<"/v1/observations/stations">>
138
+ export type CreateStationResponse = OkOf<Post<"/v1/observations/stations">>
139
+
140
+ export type ListStationsResponse = OkOf<Get<"/v1/observations/stations">>
141
+
142
+ export type UpdateStationRequest = ReqOf<Patch<"/v1/observations/stations/{stationId}">>
143
+ export type UpdateStationResponse = OkOf<Patch<"/v1/observations/stations/{stationId}">>
144
+
145
+ export type SubmitObservationsRequest = ReqOf<Post<"/v1/observations">>
146
+ export type SubmitObservationsResponse = OkOf<Post<"/v1/observations">>
147
+
148
+ export type RecentObservationsQuery = QueryOf<Get<"/v1/observations/stations/{stationId}/recent">>
149
+ export type RecentObservationsResponse = OkOf<Get<"/v1/observations/stations/{stationId}/recent">>
150
+
151
+ // ── public / research (no-auth) ───────────────────────────────────────────
152
+ export type SustainabilityIndexQuery = QueryOf<Get<"/v1/public/sustainability-index">>
153
+ export type SustainabilityIndexResponse = OkOf<Get<"/v1/public/sustainability-index">>
154
+
155
+ export type VerificationExportQuery = QueryOf<Get<"/v1/research/verification/export">>
156
+
157
+ export type PublicSignupRequest = ReqOf<Post<"/v1/public/signup">>
158
+ export type PublicSignupResponse = OkOf<Post<"/v1/public/signup">>
159
+
160
+ export type CatalogStatsResponse = OkOf<Get<"/v1/public/catalog-stats">>
161
+
162
+ /** Legal document kinds (from the OpenAPI path-param enum). */
163
+ export type LegalDocumentKind = PathOf<Get<"/v1/legal/{kind}/current">>["kind"]
164
+ export type LegalDocumentResponse = OkOf<Get<"/v1/legal/{kind}/current">>
165
+
166
+ // ── health / audit / BYOK (tenant surfaces) ───────────────────────────────
167
+ export type HealthReadyResponse = OkOf<Get<"/v1/health/ready">>
168
+
169
+ export type AuditExportQuery = QueryOf<Get<"/v1/audit/export">>
170
+ /** The JSON body of an audit export (`format=json`, the default). The `csv`
171
+ * variant is returned as a raw `string` by the client, not this type. */
172
+ export type AuditExportResponse = JsonResOf<Get<"/v1/audit/export">, 200>
173
+
174
+ export type SetLlmKeyRequest = ReqOf<Put<"/v1/tenant/llm-key">>
175
+ export type LlmKeyStatus = OkOf<Get<"/v1/tenant/llm-key">>
176
+
177
+ // ── request options ───────────────────────────────────────────────────────
178
+ /** Per-call options for endpoints that accept an `Idempotency-Key` header
179
+ * (`bindPolicy`, `reportOutcome`) — a client-generated key so a retry after a
180
+ * network timeout can't double-apply the write. */
181
+ export interface IdempotencyOptions {
182
+ idempotencyKey?: string
183
+ }
184
+
185
+ // ── webhooks ──────────────────────────────────────────────────────────────
186
+ /** Every webhook event the platform can deliver (from the OpenAPI enum). */
187
+ export type WebhookEventType = components["schemas"]["WebhookEvent"]
188
+
189
+ /**
190
+ * A webhook delivery body, POSTed to a tenant's registered endpoint. The
191
+ * envelope shape is stable; `data` is per-event and best-effort — narrow it
192
+ * with `if (delivery.type === "underwriting.policy.bound") { ... }`. Field
193
+ * names mirror the deliverer exactly (`id` / `type` / `created`).
194
+ */
195
+ export interface WebhookDelivery<T = Record<string, unknown>> {
196
+ id: string
197
+ type: WebhookEventType
198
+ created: string
199
+ data: T
200
+ }
201
+
64
202
  export type HealthResponse = ResOf<paths["/v1/health"] extends { get: infer O } ? O : never, 200>
65
203
 
66
204
  // ── SDK-specific result types (not wire schemas) ─────────────────────────