@coinlist-co/react 0.12.1 → 0.12.2-rc.0ff2d03

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 (34) hide show
  1. package/README.md +10 -0
  2. package/dist/chunk-MJ6YXZWH.js +22 -0
  3. package/dist/chunk-MJ6YXZWH.js.map +1 -0
  4. package/dist/{chunk-VH34YC3Q.js → chunk-PWGUKS4Q.js} +199 -186
  5. package/dist/chunk-PWGUKS4Q.js.map +1 -0
  6. package/dist/{chunk-DCW7NQXH.js → chunk-QTBEDN7C.js} +52 -19
  7. package/dist/chunk-QTBEDN7C.js.map +1 -0
  8. package/dist/{chunk-MOE5S6CE.js → chunk-SVPFFLIT.js} +1314 -796
  9. package/dist/chunk-SVPFFLIT.js.map +1 -0
  10. package/dist/client/index.d.ts +3332 -4554
  11. package/dist/client/index.js +7374 -4387
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/server/index.d.ts +69 -71
  14. package/dist/server/index.js +327 -67
  15. package/dist/server/index.js.map +1 -1
  16. package/dist/{tokens-namespace-CIWBtgt2.d.cts → time-BDzqB806.d.ts} +1901 -2491
  17. package/dist/{token-registry-snapshot-CqI6dXM_.d.cts → token-registry-snapshot-cvLsnMo_.d.ts} +74 -42
  18. package/dist/universal/index.d.ts +100 -1001
  19. package/dist/universal/index.js +52 -36
  20. package/package.json +18 -14
  21. package/dist/chunk-DCW7NQXH.js.map +0 -1
  22. package/dist/chunk-MOE5S6CE.js.map +0 -1
  23. package/dist/chunk-VH34YC3Q.js.map +0 -1
  24. package/dist/client/index.cjs +0 -16840
  25. package/dist/client/index.cjs.map +0 -1
  26. package/dist/client/index.d.cts +0 -6592
  27. package/dist/server/index.cjs +0 -3878
  28. package/dist/server/index.cjs.map +0 -1
  29. package/dist/server/index.d.cts +0 -354
  30. package/dist/token-registry-snapshot-BNBNuDu1.d.ts +0 -179
  31. package/dist/tokens-namespace-CIWBtgt2.d.ts +0 -3301
  32. package/dist/universal/index.cjs +0 -4028
  33. package/dist/universal/index.cjs.map +0 -1
  34. package/dist/universal/index.d.cts +0 -1276
@@ -1,4 +1,4 @@
1
- import { A as AuthorizationCode, C as CodeVerifier, aq as OAuthSession, v as OAuthAccessToken, ar as ClientCredentialsOAuth, u as Config, as as ClientSecret, at as Sender, L as Logger, w as OffersNamespace, J as Offer, au as PaginationParams, av as PaginatedResponse, O as OfferId, z as OfferDetail, R as RequirementsNamespace, d as OfferOptionId, s as Requirement, t as RequirementsNamespaceImpl, U as UniversalNamespaceContext, o as WalletsNamespace, E as Erc20Namespace, c as CoinListTokenSaleNamespace, S as SuperstateSwapNamespace, g as OndoNamespace, T as TokensNamespace, _ as PinoLoggerOptions } from '../tokens-namespace-CIWBtgt2.js';
1
+ import { A as AuthorizationCode, C as CodeVerifier, af as OAuthSession, x as OAuthAccessToken, ag as ClientCredentialsOAuth, y as OffersNamespace, D as Offer, ah as PaginationParams, ai as PaginatedResponse, f as OfferId, G as OfferDetail, R as RequirementsNamespace, g as OfferOptionId, s as Requirement, v as WalletsNamespace, z as Erc20Namespace, i as CoinListTokenSaleNamespace, r as SuperstateSwapNamespace, m as OndoNamespace, e as CentrifugeNamespace, T as TokensNamespace, w as Config, aj as ClientSecret, M as Seconds, Z as PinoLoggerOptions, _ as Logger } from '../time-BDzqB806.js';
2
2
  import 'viem';
3
3
 
4
4
  interface SessionStore {
@@ -55,18 +55,36 @@ interface ServerAuthNamespace {
55
55
  * Exchanges an authorization code from `CoinListClient#auth.completeOAuth`
56
56
  * for an OAuth session and persists it via {@link SessionStore.setSession}.
57
57
  *
58
- * Throws {@link WritableSessionStoreRequiredError} if the session store does
59
- * not provide `setSession`.
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.
60
65
  */
61
66
  completeOAuth(params: CompleteOAuthParams): Promise<OAuthSession>;
62
67
  /**
63
68
  * Returns a valid access token for the current session, refreshing it if it
64
69
  * is expired or near expiry. This is what you serve to
65
- * {@link ClientConfig.getAccessToken}.
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.
66
73
  *
67
74
  * **Writable store**: if the token is expired, the SDK exchanges the refresh
68
75
  * token for a new session, persists it, and returns the fresh access token.
69
- * Returns `null` if there is no session or the refresh fails.
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.
70
88
  *
71
89
  * **Read-only store** (no `setSession`): refresh is skipped entirely. The
72
90
  * stored token is returned as-is, even if it is expired — a non-null return
@@ -75,8 +93,14 @@ interface ServerAuthNamespace {
75
93
  * store (e.g. in a Route Handler) when you need the SDK to renew the session
76
94
  * automatically.
77
95
  *
78
- * @returns the access token, or `null` if there is no session or the session
79
- * could not be refreshed.
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.
80
104
  */
81
105
  getAccessToken(): Promise<OAuthAccessToken | null>;
82
106
  /**
@@ -95,56 +119,23 @@ interface ServerAuthNamespace {
95
119
  clientCredentials(): Promise<ClientCredentialsOAuth>;
96
120
  /**
97
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.
98
129
  *
99
- * Throws {@link WritableSessionStoreRequiredError} if the session store does
130
+ * @throws {@link WritableSessionStoreRequiredError} if the session store does
100
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.
101
136
  */
102
137
  logout(): Promise<void>;
103
138
  }
104
- /** What {@link ServerAuthNamespaceImpl} needs out of `ServerConfig`. */
105
- type ServerAuthConfig = Config & {
106
- readonly clientSecret: ClientSecret;
107
- readonly sessionStore: SessionStore;
108
- /** Seconds before expiry at which a token counts as expired for refresh. */
109
- readonly accessTokenExpiryBufferSeconds: number;
110
- /** Whether to rethrow errors the SDK could otherwise swallow (e.g. revoke). */
111
- readonly strict: boolean;
112
- };
113
- declare class ServerAuthNamespaceImpl implements ServerAuthNamespace {
114
- private readonly api;
115
- private readonly config;
116
- private readonly log;
117
- constructor(api: Sender, config: ServerAuthConfig);
118
- completeOAuth(params: CompleteOAuthParams): Promise<OAuthSession>;
119
- getAccessToken(): Promise<OAuthAccessToken | null>;
120
- private readAccessToken;
121
- private refreshSession;
122
- clientCredentials(): Promise<ClientCredentialsOAuth>;
123
- logout(): Promise<void>;
124
- private revokeAndClear;
125
- /**
126
- * Returns the store's `setSession`, or throws — the guard every
127
- * session-writing operation shares.
128
- */
129
- private writableSessionStore;
130
- }
131
-
132
- /**
133
- * What the server-only namespaces need, on top of what
134
- * {@link UniversalNamespaceContext} provides: authentication that a caller can
135
- * satisfy with an app-level token instead of a user session.
136
- */
137
- interface ServerNamespaceContext {
138
- readonly api: Sender;
139
- /** As {@link UniversalNamespaceContext.logger}: the raw port, scoped per namespace. */
140
- readonly logger: Logger | null;
141
- /**
142
- * Requires a user session, unless `clientCreds` is supplied — an app-level
143
- * token authenticates the request on its own. Throws
144
- * {@link NotAuthenticatedError} when neither is present.
145
- */
146
- ensureAuthenticated(clientCreds?: ClientCredentialsOAuth): Promise<void>;
147
- }
148
139
 
149
140
  /**
150
141
  * The server-side offers namespace: the same reads as the shared
@@ -162,14 +153,6 @@ interface ServerOffersNamespace extends OffersNamespace {
162
153
  /** @param clientCreds app-level token to read without a user session. */
163
154
  get(id: OfferId, clientCreds?: ClientCredentialsOAuth): Promise<OfferDetail>;
164
155
  }
165
- declare class ServerOffersNamespaceImpl implements ServerOffersNamespace {
166
- private readonly ctx;
167
- private readonly log;
168
- constructor(ctx: ServerNamespaceContext);
169
- list(clientCreds?: ClientCredentialsOAuth): Promise<Offer[]>;
170
- listPage(params: PaginationParams, clientCreds?: ClientCredentialsOAuth): Promise<PaginatedResponse<Offer>>;
171
- get(id: OfferId, clientCreds?: ClientCredentialsOAuth): Promise<OfferDetail>;
172
- }
173
156
 
174
157
  /**
175
158
  * The server-side requirements namespace: the same surface as the shared
@@ -184,20 +167,27 @@ interface ServerRequirementsNamespace extends RequirementsNamespace {
184
167
  /** @param clientCreds app-level token to read without a user session. */
185
168
  forOffer(offerId: OfferId, clientCreds?: ClientCredentialsOAuth): Promise<Record<OfferOptionId, Requirement[]>>;
186
169
  }
187
- declare class ServerRequirementsNamespaceImpl extends RequirementsNamespaceImpl implements ServerRequirementsNamespace {
188
- private readonly serverCtx;
189
- constructor(serverCtx: UniversalNamespaceContext & ServerNamespaceContext);
190
- forOffer(offerId: OfferId, clientCreds?: ClientCredentialsOAuth): Promise<Record<OfferOptionId, Requirement[]>>;
191
- }
192
170
 
193
171
  interface ServerConfig extends Config {
194
172
  readonly clientSecret: ClientSecret;
195
173
  readonly sessionStore: SessionStore;
196
- /** Buffer in seconds before expiry to consider token expired for refresh. */
197
- readonly accessTokenExpiryBufferSeconds?: number;
198
174
  /**
199
- * Whether SDK will throw an exception in cases it can be silent.
200
- * For example, if token revokation on logout fails.
175
+ * How many seconds before its expiry an access token is refreshed. Defaults
176
+ * to 60. Refreshing early moves the work to a single request while the
177
+ * current token still works, and a refresh that fails inside this window
178
+ * keeps serving the current token rather than failing the request.
179
+ *
180
+ * Build it with `Seconds.of(n)`, which throws a `ValidationError` unless
181
+ * `n` is a non-negative integer.
182
+ */
183
+ readonly accessTokenExpiryBufferSeconds?: Seconds;
184
+ /**
185
+ * Whether the SDK throws where it would otherwise recover and log a
186
+ * `'warn'` line. Defaults to `false`.
187
+ *
188
+ * Today it governs one thing: a failed token revoke in `auth.logout()`. By
189
+ * default the session is cleared regardless; with `strict` the failure is
190
+ * rethrown and the session is left untouched.
201
191
  */
202
192
  readonly strict?: boolean;
203
193
  }
@@ -222,7 +212,10 @@ interface ServerConfig extends Config {
222
212
  * Next.js Server Components.
223
213
  *
224
214
  * Unless a namespace says otherwise, its methods require a user session and
225
- * throw {@link NotAuthenticatedError} when there is none.
215
+ * throw {@link NotAuthenticatedError} when there is none. When the SDK could
216
+ * not find out whether there is one - CoinList's token endpoint failing, or
217
+ * the network - they throw that underlying error instead: see
218
+ * {@link ServerAuthNamespace.getAccessToken}.
226
219
  */
227
220
  interface CoinListServer {
228
221
  /**
@@ -274,6 +267,11 @@ interface CoinListServer {
274
267
  * ENG-1680 and will be client-only, since it needs a wallet to sign with.
275
268
  */
276
269
  readonly ondo: OndoNamespace;
270
+ /**
271
+ * Centrifuge vault reads: the vault-wide ordering gate, and each wallet's
272
+ * position. The status read is free to poll.
273
+ */
274
+ readonly centrifuge: CentrifugeNamespace;
277
275
  /**
278
276
  * Token display metadata (name, symbol, decimals, logos) from CoinList's
279
277
  * public token registry, keyed by chain + contract address — e.g.
@@ -351,4 +349,4 @@ declare class WritableSessionStoreRequiredError extends Error {
351
349
  constructor(message?: string);
352
350
  }
353
351
 
354
- export { type CoinListServer, type CompleteOAuthParams, type ServerAuthConfig, type ServerAuthNamespace, ServerAuthNamespaceImpl, type ServerConfig, type ServerNamespaceContext, type ServerOffersNamespace, ServerOffersNamespaceImpl, type ServerRequirementsNamespace, ServerRequirementsNamespaceImpl, type SessionStore, WritableSessionStoreRequiredError, createCoinListServer, emptySessionStore, pinoServerLogger };
352
+ export { type CoinListServer, type CompleteOAuthParams, type ServerAuthNamespace, type ServerConfig, type ServerOffersNamespace, type ServerRequirementsNamespace, type SessionStore, WritableSessionStoreRequiredError, createCoinListServer, emptySessionStore, pinoServerLogger };