@coinlist-co/react 0.12.2-rc.bc20f5b → 0.12.2-rc.e1f6c82

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 (33) hide show
  1. package/dist/{chunk-3WW5FLT7.js → chunk-EKLUJZ7T.js} +10 -10
  2. package/dist/chunk-EKLUJZ7T.js.map +1 -0
  3. package/dist/{chunk-C6GF7MDF.js → chunk-GIE4UWB3.js} +680 -619
  4. package/dist/chunk-GIE4UWB3.js.map +1 -0
  5. package/dist/chunk-MJ6YXZWH.js +22 -0
  6. package/dist/chunk-MJ6YXZWH.js.map +1 -0
  7. package/dist/{chunk-IZJ4JSSC.js → chunk-PIOQA6HW.js} +173 -234
  8. package/dist/chunk-PIOQA6HW.js.map +1 -0
  9. package/dist/client/index.d.ts +2414 -5239
  10. package/dist/client/index.js +683 -788
  11. package/dist/client/index.js.map +1 -1
  12. package/dist/server/index.d.ts +2 -32
  13. package/dist/server/index.js +6 -4
  14. package/dist/server/index.js.map +1 -1
  15. package/dist/{time-CVZpAkGY.d.cts → time-Bbqlt2x7.d.ts} +1907 -3183
  16. package/dist/{token-registry-snapshot-BkwA8KmD.d.ts → token-registry-snapshot-DttZXGvY.d.ts} +7 -41
  17. package/dist/universal/index.d.ts +57 -1044
  18. package/dist/universal/index.js +16 -42
  19. package/package.json +18 -14
  20. package/dist/chunk-3WW5FLT7.js.map +0 -1
  21. package/dist/chunk-C6GF7MDF.js.map +0 -1
  22. package/dist/chunk-IZJ4JSSC.js.map +0 -1
  23. package/dist/client/index.cjs +0 -20460
  24. package/dist/client/index.cjs.map +0 -1
  25. package/dist/client/index.d.cts +0 -8195
  26. package/dist/server/index.cjs +0 -4525
  27. package/dist/server/index.cjs.map +0 -1
  28. package/dist/server/index.d.cts +0 -382
  29. package/dist/time-CVZpAkGY.d.ts +0 -3987
  30. package/dist/token-registry-snapshot-bR14QehS.d.cts +0 -245
  31. package/dist/universal/index.cjs +0 -4562
  32. package/dist/universal/index.cjs.map +0 -1
  33. package/dist/universal/index.d.cts +0 -1362
@@ -1,382 +0,0 @@
1
- import { A as AuthorizationCode, C as CodeVerifier, aF as OAuthSession, D as OAuthAccessToken, aG as ClientCredentialsOAuth, aH as Sender, L as Logger, F as OffersNamespace, $ as Offer, aI as PaginationParams, aJ as PaginatedResponse, i as OfferId, I as OfferDetail, R as RequirementsNamespace, j as OfferOptionId, x as Requirement, y as RequirementsNamespaceImpl, U as UniversalNamespaceContext, t as WalletsNamespace, E as Erc20Namespace, h as CoinListTokenSaleNamespace, S as SuperstateSwapNamespace, m as OndoNamespace, c as CentrifugeNamespace, T as TokensNamespace, z as Config, aK as ClientSecret, Y as Seconds, a8 as PinoLoggerOptions } from '../time-CVZpAkGY.cjs';
2
- import 'viem';
3
-
4
- interface SessionStore {
5
- getSession(): Promise<OAuthSession | null>;
6
- /**
7
- * Persists or clears the OAuth session.
8
- *
9
- * **Omit this method to create a read-only store.** When absent, the SDK
10
- * skips token refresh entirely — no network call is made and no refresh
11
- * token is consumed. This is the correct approach for contexts that can read
12
- * the session but cannot write it back, such as Next.js Server Components.
13
- *
14
- * ⚠️ Do **not** implement this as a no-op (`async () => {}`). If the method
15
- * is present, the SDK assumes writes succeed: it will fire a token refresh
16
- * network call, consume the refresh token, then invoke `setSession` — which
17
- * would silently discard the new session and leave the browser holding an
18
- * invalidated refresh token. Simply **omit** `setSession` to prevent any
19
- * refresh from being attempted.
20
- *
21
- * {@link ServerAuthNamespace.completeOAuth} and
22
- * {@link ServerAuthNamespace.logout} always require a writable store and
23
- * throw {@link WritableSessionStoreRequiredError} if `setSession` is absent.
24
- */
25
- setSession?(session: OAuthSession | null): Promise<void>;
26
- }
27
- /**
28
- * The empty session store: holds no session, reads nothing, never writes.
29
- *
30
- * For server contexts that act without a user — the client-credentials grant
31
- * (`auth.clientCredentials`) and the public token registry (`tokens`) read
32
- * nothing from the store, so hosts building those paths need no store of
33
- * their own.
34
- *
35
- * `setSession` is deliberately absent, not a no-op — see
36
- * {@link SessionStore.setSession} for why a no-op is a bug.
37
- */
38
- declare function emptySessionStore(): SessionStore;
39
- /** The PKCE pair `CoinListClient#auth.completeOAuth` hands to the backend. */
40
- interface CompleteOAuthParams {
41
- /** The short-lived authorization code parsed out of the redirect URL. */
42
- code: AuthorizationCode;
43
- /** The `code_verifier` the browser generated when starting the flow. */
44
- codeVerifier: CodeVerifier;
45
- }
46
- /**
47
- * OAuth session lifecycle on your backend: exchanging authorization codes,
48
- * keeping the access token fresh, minting app-level tokens, and logging out.
49
- *
50
- * This namespace is server-only: every method needs the `clientSecret` and the
51
- * {@link SessionStore}, neither of which may exist in a browser.
52
- */
53
- interface ServerAuthNamespace {
54
- /**
55
- * Exchanges an authorization code from `CoinListClient#auth.completeOAuth`
56
- * for an OAuth session and persists it via {@link SessionStore.setSession}.
57
- *
58
- * The exchange is never retried automatically: an authorization code is
59
- * single-use, so a retry of an attempt that reached the server would fail
60
- * anyway, and could mask why the first one did.
61
- *
62
- * @throws {@link WritableSessionStoreRequiredError} if the session store
63
- * does not provide `setSession`.
64
- * @throws {@link HttpError} if CoinList refuses the exchange.
65
- */
66
- completeOAuth(params: CompleteOAuthParams): Promise<OAuthSession>;
67
- /**
68
- * Returns a valid access token for the current session, refreshing it if it
69
- * is expired or near expiry. This is what you serve to
70
- * {@link ClientConfig.getAccessToken}: answer `null` with "no session"
71
- * (e.g. a 204) and a throw with a failure (e.g. a 503), never the other way
72
- * round - the browser signs the user out on the first and not the second.
73
- *
74
- * **Writable store**: if the token is expired, the SDK exchanges the refresh
75
- * token for a new session, persists it, and returns the fresh access token.
76
- * Concurrent calls for the same session in this process share one exchange.
77
- *
78
- * A rejected refresh token (`400 invalid_grant`) is only a *suspicion* at
79
- * first, because the backend answers "rotated a moment ago by a concurrent
80
- * request" and "expired or revoked" identically: the SDK writes nothing,
81
- * so it cannot overwrite the session the winning request just stored, and
82
- * returns `null` - or the current access token, if that has not actually
83
- * expired yet. Only a second rejection of the same refresh token, 5 to 60
84
- * seconds later in this process, is the verdict: the session is cleared via
85
- * {@link SessionStore.setSession} and {@link Config.onSessionExpired} is
86
- * called. A browser confirming through your endpoint asks again after one
87
- * second, so it signs out on its own verdict and not on this one.
88
- *
89
- * **Read-only store** (no `setSession`): refresh is skipped entirely. The
90
- * stored token is returned as-is, even if it is expired — a non-null return
91
- * value does **not** guarantee the token is accepted by the API. Before
92
- * making API calls, check `token.expiresAt > new Date()`. Use a writable
93
- * store (e.g. in a Route Handler) when you need the SDK to renew the session
94
- * automatically.
95
- *
96
- * @returns the access token, or `null` if there is no session, or the
97
- * session was rejected (suspected or confirmed).
98
- * @throws the underlying error - an {@link HttpError} for a 5xx or
99
- * `invalid_client`, the `fetch` error for a network failure - when the SDK
100
- * could not find out whether a session exists and the current access token
101
- * has already expired. The session is left untouched. **Never treat this as
102
- * logged out**: it means "try again", and during an outage treating it as
103
- * logged out would sign out every user at once.
104
- */
105
- getAccessToken(): Promise<OAuthAccessToken | null>;
106
- /**
107
- * Obtains an app-level access token via the OAuth 2.0 `client_credentials`
108
- * grant (RFC 6749 §4.4). No user is involved: the token authenticates the
109
- * partner application itself and only grants access to app-level resources
110
- * such as offers and offer requirements.
111
- *
112
- * The token is **not** persisted to the {@link SessionStore} and has no
113
- * refresh token. It expires at `expiresAt`; once expired, call this method
114
- * again to obtain a fresh token — the SDK does not renew it automatically.
115
- *
116
- * Pass the result to `ServerOffersNamespace` or
117
- * `ServerRequirementsNamespace.forOffer` to read without a user session.
118
- */
119
- clientCredentials(): Promise<ClientCredentialsOAuth>;
120
- /**
121
- * Revokes the current token via `POST /oauth/revoke` and clears the session.
122
- * Does nothing when there is no session.
123
- *
124
- * The revoke is best-effort: if it fails for any reason - an
125
- * {@link HttpError}, a network failure, anything else - the failure is
126
- * logged at `'warn'` and the session is cleared regardless, because the
127
- * cleared session is what logs the user out. Set `strict` on the server
128
- * config to rethrow it instead.
129
- *
130
- * @throws {@link WritableSessionStoreRequiredError} if the session store does
131
- * not provide `setSession`.
132
- * @throws whatever the {@link SessionStore} throws, in either mode. A failed
133
- * `setSession(null)` means the session was not cleared.
134
- * @throws the revoke failure, only when `strict` is set. The session is then
135
- * left untouched, so the call can be retried.
136
- */
137
- logout(): Promise<void>;
138
- }
139
-
140
- /**
141
- * What the server-only namespaces need, on top of what
142
- * {@link UniversalNamespaceContext} provides: authentication that a caller can
143
- * satisfy with an app-level token instead of a user session.
144
- */
145
- interface ServerNamespaceContext {
146
- readonly api: Sender;
147
- /** As {@link UniversalNamespaceContext.logger}: the raw port, scoped per namespace. */
148
- readonly logger: Logger | null;
149
- /**
150
- * Requires a user session, unless `clientCreds` is supplied — an app-level
151
- * token authenticates the request on its own. Throws
152
- * {@link NotAuthenticatedError} when neither is present.
153
- */
154
- ensureAuthenticated(clientCreds?: ClientCredentialsOAuth): Promise<void>;
155
- }
156
-
157
- /**
158
- * The server-side offers namespace: the same reads as the shared
159
- * {@link OffersNamespace}, each additionally callable with an app-level token
160
- * from `ServerAuthNamespace.clientCredentials` instead of a user session.
161
- *
162
- * When a user session exists it takes precedence and `clientCreds` acts as a
163
- * fallback. Without either, the reads throw {@link NotAuthenticatedError}.
164
- */
165
- interface ServerOffersNamespace extends OffersNamespace {
166
- /** @param clientCreds app-level token to read without a user session. */
167
- list(clientCreds?: ClientCredentialsOAuth): Promise<Offer[]>;
168
- /** @param clientCreds app-level token to read without a user session. */
169
- listPage(params: PaginationParams, clientCreds?: ClientCredentialsOAuth): Promise<PaginatedResponse<Offer>>;
170
- /** @param clientCreds app-level token to read without a user session. */
171
- get(id: OfferId, clientCreds?: ClientCredentialsOAuth): Promise<OfferDetail>;
172
- }
173
- declare class ServerOffersNamespaceImpl implements ServerOffersNamespace {
174
- private readonly ctx;
175
- private readonly log;
176
- constructor(ctx: ServerNamespaceContext);
177
- list(clientCreds?: ClientCredentialsOAuth): Promise<Offer[]>;
178
- listPage(params: PaginationParams, clientCreds?: ClientCredentialsOAuth): Promise<PaginatedResponse<Offer>>;
179
- get(id: OfferId, clientCreds?: ClientCredentialsOAuth): Promise<OfferDetail>;
180
- }
181
-
182
- /**
183
- * The server-side requirements namespace: the same surface as the shared
184
- * {@link RequirementsNamespace}, except {@link forOffer} — the offer's
185
- * requirement definitions are app-level data, so it is additionally callable
186
- * with a token from `ServerAuthNamespace.clientCredentials`.
187
- *
188
- * Everything else is per-user data and needs a user session. `handle` is
189
- * client-only: there is no browser tab to open on a server.
190
- */
191
- interface ServerRequirementsNamespace extends RequirementsNamespace {
192
- /** @param clientCreds app-level token to read without a user session. */
193
- forOffer(offerId: OfferId, clientCreds?: ClientCredentialsOAuth): Promise<Record<OfferOptionId, Requirement[]>>;
194
- }
195
- declare class ServerRequirementsNamespaceImpl extends RequirementsNamespaceImpl implements ServerRequirementsNamespace {
196
- private readonly serverCtx;
197
- constructor(serverCtx: UniversalNamespaceContext & ServerNamespaceContext);
198
- forOffer(offerId: OfferId, clientCreds?: ClientCredentialsOAuth): Promise<Record<OfferOptionId, Requirement[]>>;
199
- }
200
-
201
- interface ServerConfig extends Config {
202
- readonly clientSecret: ClientSecret;
203
- readonly sessionStore: SessionStore;
204
- /**
205
- * How many seconds before its expiry an access token is refreshed. Defaults
206
- * to 60. Refreshing early moves the work to a single request while the
207
- * current token still works, and a refresh that fails inside this window
208
- * keeps serving the current token rather than failing the request.
209
- *
210
- * Build it with `Seconds.of(n)`, which throws a `ValidationError` unless
211
- * `n` is a non-negative integer.
212
- */
213
- readonly accessTokenExpiryBufferSeconds?: Seconds;
214
- /**
215
- * Whether the SDK throws where it would otherwise recover and log a
216
- * `'warn'` line. Defaults to `false`.
217
- *
218
- * Today it governs one thing: a failed token revoke in `auth.logout()`. By
219
- * default the session is cleared regardless; with `strict` the failure is
220
- * rethrown and the session is left untouched.
221
- */
222
- readonly strict?: boolean;
223
- }
224
- /**
225
- * Server-side CoinList SDK client.
226
- *
227
- * Functionality is grouped into namespaces — `coinlist.auth.getAccessToken()`,
228
- * `coinlist.offers.list()`, `coinlist.requirements.statuses(offerId)`.
229
- *
230
- * Operates in one of two modes depending on whether {@link SessionStore}
231
- * includes a `setSession` implementation:
232
- *
233
- * - **Writable store** (`setSession` provided) — full functionality: token
234
- * refresh, `auth.completeOAuth`, and `auth.logout` all work normally.
235
- *
236
- * - **Read-only store** (no `setSession`) — token refresh is skipped entirely,
237
- * meaning no network call is made and no refresh token is consumed.
238
- * `auth.completeOAuth` and `auth.logout` throw
239
- * {@link WritableSessionStoreRequiredError}. `auth.getAccessToken` may
240
- * return an expired token (see its docs). Use this mode in execution
241
- * contexts that can read the session but cannot write it back, such as
242
- * Next.js Server Components.
243
- *
244
- * Unless a namespace says otherwise, its methods require a user session and
245
- * throw {@link NotAuthenticatedError} when there is none. When the SDK could
246
- * not find out whether there is one - CoinList's token endpoint failing, or
247
- * the network - they throw that underlying error instead: see
248
- * {@link ServerAuthNamespace.getAccessToken}.
249
- */
250
- interface CoinListServer {
251
- /**
252
- * OAuth session lifecycle: exchanging an authorization code, serving a valid
253
- * access token to the browser, minting app-level tokens, and logging out —
254
- * e.g. `coinlist.auth.getAccessToken()`.
255
- */
256
- readonly auth: ServerAuthNamespace;
257
- /**
258
- * The offer catalogue — e.g. `coinlist.offers.list()`. Every read also
259
- * accepts an app-level token from {@link ServerAuthNamespace.clientCredentials}
260
- * so it can run without a user session.
261
- */
262
- readonly offers: ServerOffersNamespace;
263
- /**
264
- * Offer requirements and the operations that satisfy them — e.g.
265
- * `coinlist.requirements.statuses(offerId)`. `forOffer` also accepts an
266
- * app-level token; the rest is per-user data and needs a user session.
267
- */
268
- readonly requirements: ServerRequirementsNamespace;
269
- /**
270
- * The user's external wallets: ownership proofs and offer-option bindings —
271
- * e.g. `coinlist.wallets.list({ offerId, offerOptionId })`.
272
- */
273
- readonly wallets: WalletsNamespace;
274
- /**
275
- * Generic ERC-20 reads (token allowance and balance) — e.g.
276
- * `coinlist.erc20.getBalance({ ... })`.
277
- */
278
- readonly erc20: Erc20Namespace;
279
- /**
280
- * Token-sale operations: listing, reading, and recording participations —
281
- * e.g. `coinlist.tokenSale.list()`. The on-chain `execute`
282
- * flow is client-only and is not exposed here.
283
- */
284
- readonly tokenSale: CoinListTokenSaleNamespace;
285
- /**
286
- * On-chain swap operations: quoting a swap, reading swap-contract state, and
287
- * allow-listing a proven wallet — e.g.
288
- * `coinlist.superstate.getOutputToken({ contractAddress, chain })`.
289
- */
290
- readonly superstate: SuperstateSwapNamespace;
291
- /**
292
- * Ondo swap reads: trading status and quoting. Both are free to poll.
293
- *
294
- * No CoinList fee is applied to a quote; see {@link OndoNamespace}.
295
- *
296
- * This is Ondo's whole surface for now — the wallet-driven half arrives with
297
- * ENG-1680 and will be client-only, since it needs a wallet to sign with.
298
- */
299
- readonly ondo: OndoNamespace;
300
- /**
301
- * Centrifuge vault reads: the vault-wide ordering gate, and each wallet's
302
- * position. The status read is free to poll.
303
- */
304
- readonly centrifuge: CentrifugeNamespace;
305
- /**
306
- * Token display metadata (name, symbol, decimals, logos) from CoinList's
307
- * public token registry, keyed by chain + contract address — e.g.
308
- * `coinlist.tokens.get({ chain, address })` for an entry of
309
- * `Offer.tokens`, or `coinlist.tokens.list()` for the whole
310
- * catalogue in one request.
311
- *
312
- * Public and unauthenticated: unlike the other namespaces, its methods never
313
- * require a session, so it also works with a read-only store.
314
- */
315
- readonly tokens: TokensNamespace;
316
- }
317
- declare function createCoinListServer(config: ServerConfig): CoinListServer;
318
-
319
- /**
320
- * A {@link Logger} that writes newline-delimited JSON to stdout through pino.
321
- *
322
- * ```ts
323
- * createCoinListServer({
324
- * ...config,
325
- * logger: pinoServerLogger({ isDev: false, level: 'info' }),
326
- * });
327
- * ```
328
- *
329
- * The Node counterpart of {@link pinoClientLogger}, for a route handler, a BFF
330
- * or SSR. One line per record, which is what every log aggregator ingests
331
- * without configuration.
332
- *
333
- * ## What it deliberately does not do
334
- *
335
- * **No transport, and no `pino-pretty`.** A pino transport runs on a worker
336
- * thread through `thread-stream`, which every bundler has to be told about
337
- * (`serverExternalPackages` in Next) and which edge runtimes cannot run at
338
- * all. Pretty-printing is a pipe the host owns rather than a dependency the
339
- * SDK takes on their behalf:
340
- *
341
- * ```sh
342
- * node server.js | npx pino-pretty
343
- * ```
344
- *
345
- * **No environment-dependent formatting.** `isDev` decides which levels are
346
- * legal and nothing else, so a development record and a production record are
347
- * the same shape - what you debug is what you ship.
348
- *
349
- * If you already run pino, or want transports, redaction or `destination`,
350
- * implement {@link Logger} yourself: it is four methods over an event, and
351
- * `@opentelemetry/instrumentation-pino` patches the pino module rather than an
352
- * instance, so trace correlation reaches this logger either way.
353
- *
354
- * ## Production
355
- *
356
- * **Not advised in production**, the same as everywhere else this seam is
357
- * documented: the SDK's default answer is to leave {@link Config.logger}
358
- * undefined outside development, staging and incident reproduction. A backend
359
- * is the least bad place to disregard that - the records go to your process
360
- * and your sink rather than to a page the end user can read - but it is still
361
- * a disregard, and the retention and access questions become yours.
362
- *
363
- * If you run one, `isDev: false` restricts you to `'error'`, `'warn'` and
364
- * `'info'` - `{ isDev: false, level: 'debug' }` does not compile, see
365
- * {@link PinoLoggerOptions}. Those levels are redacted by construction, which
366
- * is a mechanism the SDK holds itself to; whether that clears your bar is a
367
- * judgement the SDK is not in a position to make for you.
368
- *
369
- * Holds no module-level state: every call builds its own pino instance, and
370
- * the level is fixed at construction, so two loggers never interfere. Fixed is
371
- * this implementation's choice, not the seam's - the SDK re-reads
372
- * {@link Logger.level} before every log call - so if you want a level you can
373
- * change at runtime, implement {@link Logger} over your own pino instance
374
- * rather than calling this.
375
- */
376
- declare function pinoServerLogger(options: PinoLoggerOptions): Logger;
377
-
378
- declare class WritableSessionStoreRequiredError extends Error {
379
- constructor(message?: string);
380
- }
381
-
382
- export { type CoinListServer, type CompleteOAuthParams, type ServerAuthNamespace, type ServerConfig, type ServerNamespaceContext, type ServerOffersNamespace, ServerOffersNamespaceImpl, type ServerRequirementsNamespace, ServerRequirementsNamespaceImpl, type SessionStore, WritableSessionStoreRequiredError, createCoinListServer, emptySessionStore, pinoServerLogger };