@coinlist-co/react 0.12.2-rc.7b430dd → 0.12.2-rc.a59b344

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-DCW7NQXH.js → chunk-4IZ2F732.js} +52 -19
  2. package/dist/chunk-4IZ2F732.js.map +1 -0
  3. package/dist/{chunk-MOE5S6CE.js → chunk-NBO5E2RO.js} +152 -6
  4. package/dist/chunk-NBO5E2RO.js.map +1 -0
  5. package/dist/{chunk-VH34YC3Q.js → chunk-UJYSXXJF.js} +168 -3
  6. package/dist/chunk-UJYSXXJF.js.map +1 -0
  7. package/dist/client/index.cjs +469 -145
  8. package/dist/client/index.cjs.map +1 -1
  9. package/dist/client/index.d.cts +114 -35
  10. package/dist/client/index.d.ts +114 -35
  11. package/dist/client/index.js +297 -114
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/server/index.cjs +507 -116
  14. package/dist/server/index.cjs.map +1 -1
  15. package/dist/server/index.d.cts +65 -41
  16. package/dist/server/index.d.ts +65 -41
  17. package/dist/server/index.js +321 -65
  18. package/dist/server/index.js.map +1 -1
  19. package/dist/time-CFocgYyl.d.cts +50 -0
  20. package/dist/time-DvgN98Q9.d.ts +50 -0
  21. package/dist/{token-registry-snapshot-BNBNuDu1.d.ts → token-registry-snapshot-BsAfBL_b.d.ts} +9 -7
  22. package/dist/{token-registry-snapshot-CqI6dXM_.d.cts → token-registry-snapshot-Cc_eA5zM.d.cts} +9 -7
  23. package/dist/{tokens-namespace-CIWBtgt2.d.cts → tokens-namespace-D_XSpiS-.d.cts} +154 -19
  24. package/dist/{tokens-namespace-CIWBtgt2.d.ts → tokens-namespace-D_XSpiS-.d.ts} +154 -19
  25. package/dist/universal/index.cjs +333 -40
  26. package/dist/universal/index.cjs.map +1 -1
  27. package/dist/universal/index.d.cts +358 -5
  28. package/dist/universal/index.d.ts +358 -5
  29. package/dist/universal/index.js +28 -2
  30. package/package.json +1 -1
  31. package/dist/chunk-DCW7NQXH.js.map +0 -1
  32. package/dist/chunk-MOE5S6CE.js.map +0 -1
  33. package/dist/chunk-VH34YC3Q.js.map +0 -1
@@ -1,4 +1,5 @@
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.cjs';
1
+ import { A as AuthorizationCode, C as CodeVerifier, ar as OAuthSession, v as OAuthAccessToken, as as ClientCredentialsOAuth, at as Sender, L as Logger, w as OffersNamespace, K 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, u as Config, aw as ClientSecret, $ as PinoLoggerOptions } from '../tokens-namespace-D_XSpiS-.cjs';
2
+ import { S as Seconds } from '../time-CFocgYyl.cjs';
2
3
  import 'viem';
3
4
 
4
5
  interface SessionStore {
@@ -55,18 +56,36 @@ interface ServerAuthNamespace {
55
56
  * Exchanges an authorization code from `CoinListClient#auth.completeOAuth`
56
57
  * for an OAuth session and persists it via {@link SessionStore.setSession}.
57
58
  *
58
- * Throws {@link WritableSessionStoreRequiredError} if the session store does
59
- * not provide `setSession`.
59
+ * The exchange is never retried automatically: an authorization code is
60
+ * single-use, so a retry of an attempt that reached the server would fail
61
+ * anyway, and could mask why the first one did.
62
+ *
63
+ * @throws {@link WritableSessionStoreRequiredError} if the session store
64
+ * does not provide `setSession`.
65
+ * @throws {@link HttpError} if CoinList refuses the exchange.
60
66
  */
61
67
  completeOAuth(params: CompleteOAuthParams): Promise<OAuthSession>;
62
68
  /**
63
69
  * Returns a valid access token for the current session, refreshing it if it
64
70
  * is expired or near expiry. This is what you serve to
65
- * {@link ClientConfig.getAccessToken}.
71
+ * {@link ClientConfig.getAccessToken}: answer `null` with "no session"
72
+ * (e.g. a 204) and a throw with a failure (e.g. a 503), never the other way
73
+ * round - the browser signs the user out on the first and not the second.
66
74
  *
67
75
  * **Writable store**: if the token is expired, the SDK exchanges the refresh
68
76
  * 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.
77
+ * Concurrent calls for the same session in this process share one exchange.
78
+ *
79
+ * A rejected refresh token (`400 invalid_grant`) is only a *suspicion* at
80
+ * first, because the backend answers "rotated a moment ago by a concurrent
81
+ * request" and "expired or revoked" identically: the SDK writes nothing,
82
+ * so it cannot overwrite the session the winning request just stored, and
83
+ * returns `null` - or the current access token, if that has not actually
84
+ * expired yet. Only a second rejection of the same refresh token, 5 to 60
85
+ * seconds later in this process, is the verdict: the session is cleared via
86
+ * {@link SessionStore.setSession} and {@link Config.onSessionExpired} is
87
+ * called. A browser confirming through your endpoint asks again after one
88
+ * second, so it signs out on its own verdict and not on this one.
70
89
  *
71
90
  * **Read-only store** (no `setSession`): refresh is skipped entirely. The
72
91
  * stored token is returned as-is, even if it is expired — a non-null return
@@ -75,8 +94,14 @@ interface ServerAuthNamespace {
75
94
  * store (e.g. in a Route Handler) when you need the SDK to renew the session
76
95
  * automatically.
77
96
  *
78
- * @returns the access token, or `null` if there is no session or the session
79
- * could not be refreshed.
97
+ * @returns the access token, or `null` if there is no session, or the
98
+ * session was rejected (suspected or confirmed).
99
+ * @throws the underlying error - an {@link HttpError} for a 5xx or
100
+ * `invalid_client`, the `fetch` error for a network failure - when the SDK
101
+ * could not find out whether a session exists and the current access token
102
+ * has already expired. The session is left untouched. **Never treat this as
103
+ * logged out**: it means "try again", and during an outage treating it as
104
+ * logged out would sign out every user at once.
80
105
  */
81
106
  getAccessToken(): Promise<OAuthAccessToken | null>;
82
107
  /**
@@ -95,39 +120,23 @@ interface ServerAuthNamespace {
95
120
  clientCredentials(): Promise<ClientCredentialsOAuth>;
96
121
  /**
97
122
  * Revokes the current token via `POST /oauth/revoke` and clears the session.
123
+ * Does nothing when there is no session.
98
124
  *
99
- * Throws {@link WritableSessionStoreRequiredError} if the session store does
125
+ * The revoke is best-effort: if it fails for any reason - an
126
+ * {@link HttpError}, a network failure, anything else - the failure is
127
+ * logged at `'warn'` and the session is cleared regardless, because the
128
+ * cleared session is what logs the user out. Set `strict` on the server
129
+ * config to rethrow it instead.
130
+ *
131
+ * @throws {@link WritableSessionStoreRequiredError} if the session store does
100
132
  * not provide `setSession`.
133
+ * @throws whatever the {@link SessionStore} throws, in either mode. A failed
134
+ * `setSession(null)` means the session was not cleared.
135
+ * @throws the revoke failure, only when `strict` is set. The session is then
136
+ * left untouched, so the call can be retried.
101
137
  */
102
138
  logout(): Promise<void>;
103
139
  }
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
140
 
132
141
  /**
133
142
  * What the server-only namespaces need, on top of what
@@ -193,11 +202,23 @@ declare class ServerRequirementsNamespaceImpl extends RequirementsNamespaceImpl
193
202
  interface ServerConfig extends Config {
194
203
  readonly clientSecret: ClientSecret;
195
204
  readonly sessionStore: SessionStore;
196
- /** Buffer in seconds before expiry to consider token expired for refresh. */
197
- readonly accessTokenExpiryBufferSeconds?: number;
198
205
  /**
199
- * Whether SDK will throw an exception in cases it can be silent.
200
- * For example, if token revokation on logout fails.
206
+ * How many seconds before its expiry an access token is refreshed. Defaults
207
+ * to 60. Refreshing early moves the work to a single request while the
208
+ * current token still works, and a refresh that fails inside this window
209
+ * keeps serving the current token rather than failing the request.
210
+ *
211
+ * Build it with `Seconds.of(n)`, which throws a `ValidationError` unless
212
+ * `n` is a non-negative integer.
213
+ */
214
+ readonly accessTokenExpiryBufferSeconds?: Seconds;
215
+ /**
216
+ * Whether the SDK throws where it would otherwise recover and log a
217
+ * `'warn'` line. Defaults to `false`.
218
+ *
219
+ * Today it governs one thing: a failed token revoke in `auth.logout()`. By
220
+ * default the session is cleared regardless; with `strict` the failure is
221
+ * rethrown and the session is left untouched.
201
222
  */
202
223
  readonly strict?: boolean;
203
224
  }
@@ -222,7 +243,10 @@ interface ServerConfig extends Config {
222
243
  * Next.js Server Components.
223
244
  *
224
245
  * Unless a namespace says otherwise, its methods require a user session and
225
- * throw {@link NotAuthenticatedError} when there is none.
246
+ * throw {@link NotAuthenticatedError} when there is none. When the SDK could
247
+ * not find out whether there is one - CoinList's token endpoint failing, or
248
+ * the network - they throw that underlying error instead: see
249
+ * {@link ServerAuthNamespace.getAccessToken}.
226
250
  */
227
251
  interface CoinListServer {
228
252
  /**
@@ -351,4 +375,4 @@ declare class WritableSessionStoreRequiredError extends Error {
351
375
  constructor(message?: string);
352
376
  }
353
377
 
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 };
378
+ export { type CoinListServer, type CompleteOAuthParams, type ServerAuthNamespace, type ServerConfig, type ServerNamespaceContext, type ServerOffersNamespace, ServerOffersNamespaceImpl, type ServerRequirementsNamespace, ServerRequirementsNamespaceImpl, type SessionStore, WritableSessionStoreRequiredError, createCoinListServer, emptySessionStore, pinoServerLogger };
@@ -1,4 +1,5 @@
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, ar as OAuthSession, v as OAuthAccessToken, as as ClientCredentialsOAuth, at as Sender, L as Logger, w as OffersNamespace, K 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, u as Config, aw as ClientSecret, $ as PinoLoggerOptions } from '../tokens-namespace-D_XSpiS-.js';
2
+ import { S as Seconds } from '../time-DvgN98Q9.js';
2
3
  import 'viem';
3
4
 
4
5
  interface SessionStore {
@@ -55,18 +56,36 @@ interface ServerAuthNamespace {
55
56
  * Exchanges an authorization code from `CoinListClient#auth.completeOAuth`
56
57
  * for an OAuth session and persists it via {@link SessionStore.setSession}.
57
58
  *
58
- * Throws {@link WritableSessionStoreRequiredError} if the session store does
59
- * not provide `setSession`.
59
+ * The exchange is never retried automatically: an authorization code is
60
+ * single-use, so a retry of an attempt that reached the server would fail
61
+ * anyway, and could mask why the first one did.
62
+ *
63
+ * @throws {@link WritableSessionStoreRequiredError} if the session store
64
+ * does not provide `setSession`.
65
+ * @throws {@link HttpError} if CoinList refuses the exchange.
60
66
  */
61
67
  completeOAuth(params: CompleteOAuthParams): Promise<OAuthSession>;
62
68
  /**
63
69
  * Returns a valid access token for the current session, refreshing it if it
64
70
  * is expired or near expiry. This is what you serve to
65
- * {@link ClientConfig.getAccessToken}.
71
+ * {@link ClientConfig.getAccessToken}: answer `null` with "no session"
72
+ * (e.g. a 204) and a throw with a failure (e.g. a 503), never the other way
73
+ * round - the browser signs the user out on the first and not the second.
66
74
  *
67
75
  * **Writable store**: if the token is expired, the SDK exchanges the refresh
68
76
  * 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.
77
+ * Concurrent calls for the same session in this process share one exchange.
78
+ *
79
+ * A rejected refresh token (`400 invalid_grant`) is only a *suspicion* at
80
+ * first, because the backend answers "rotated a moment ago by a concurrent
81
+ * request" and "expired or revoked" identically: the SDK writes nothing,
82
+ * so it cannot overwrite the session the winning request just stored, and
83
+ * returns `null` - or the current access token, if that has not actually
84
+ * expired yet. Only a second rejection of the same refresh token, 5 to 60
85
+ * seconds later in this process, is the verdict: the session is cleared via
86
+ * {@link SessionStore.setSession} and {@link Config.onSessionExpired} is
87
+ * called. A browser confirming through your endpoint asks again after one
88
+ * second, so it signs out on its own verdict and not on this one.
70
89
  *
71
90
  * **Read-only store** (no `setSession`): refresh is skipped entirely. The
72
91
  * stored token is returned as-is, even if it is expired — a non-null return
@@ -75,8 +94,14 @@ interface ServerAuthNamespace {
75
94
  * store (e.g. in a Route Handler) when you need the SDK to renew the session
76
95
  * automatically.
77
96
  *
78
- * @returns the access token, or `null` if there is no session or the session
79
- * could not be refreshed.
97
+ * @returns the access token, or `null` if there is no session, or the
98
+ * session was rejected (suspected or confirmed).
99
+ * @throws the underlying error - an {@link HttpError} for a 5xx or
100
+ * `invalid_client`, the `fetch` error for a network failure - when the SDK
101
+ * could not find out whether a session exists and the current access token
102
+ * has already expired. The session is left untouched. **Never treat this as
103
+ * logged out**: it means "try again", and during an outage treating it as
104
+ * logged out would sign out every user at once.
80
105
  */
81
106
  getAccessToken(): Promise<OAuthAccessToken | null>;
82
107
  /**
@@ -95,39 +120,23 @@ interface ServerAuthNamespace {
95
120
  clientCredentials(): Promise<ClientCredentialsOAuth>;
96
121
  /**
97
122
  * Revokes the current token via `POST /oauth/revoke` and clears the session.
123
+ * Does nothing when there is no session.
98
124
  *
99
- * Throws {@link WritableSessionStoreRequiredError} if the session store does
125
+ * The revoke is best-effort: if it fails for any reason - an
126
+ * {@link HttpError}, a network failure, anything else - the failure is
127
+ * logged at `'warn'` and the session is cleared regardless, because the
128
+ * cleared session is what logs the user out. Set `strict` on the server
129
+ * config to rethrow it instead.
130
+ *
131
+ * @throws {@link WritableSessionStoreRequiredError} if the session store does
100
132
  * not provide `setSession`.
133
+ * @throws whatever the {@link SessionStore} throws, in either mode. A failed
134
+ * `setSession(null)` means the session was not cleared.
135
+ * @throws the revoke failure, only when `strict` is set. The session is then
136
+ * left untouched, so the call can be retried.
101
137
  */
102
138
  logout(): Promise<void>;
103
139
  }
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
140
 
132
141
  /**
133
142
  * What the server-only namespaces need, on top of what
@@ -193,11 +202,23 @@ declare class ServerRequirementsNamespaceImpl extends RequirementsNamespaceImpl
193
202
  interface ServerConfig extends Config {
194
203
  readonly clientSecret: ClientSecret;
195
204
  readonly sessionStore: SessionStore;
196
- /** Buffer in seconds before expiry to consider token expired for refresh. */
197
- readonly accessTokenExpiryBufferSeconds?: number;
198
205
  /**
199
- * Whether SDK will throw an exception in cases it can be silent.
200
- * For example, if token revokation on logout fails.
206
+ * How many seconds before its expiry an access token is refreshed. Defaults
207
+ * to 60. Refreshing early moves the work to a single request while the
208
+ * current token still works, and a refresh that fails inside this window
209
+ * keeps serving the current token rather than failing the request.
210
+ *
211
+ * Build it with `Seconds.of(n)`, which throws a `ValidationError` unless
212
+ * `n` is a non-negative integer.
213
+ */
214
+ readonly accessTokenExpiryBufferSeconds?: Seconds;
215
+ /**
216
+ * Whether the SDK throws where it would otherwise recover and log a
217
+ * `'warn'` line. Defaults to `false`.
218
+ *
219
+ * Today it governs one thing: a failed token revoke in `auth.logout()`. By
220
+ * default the session is cleared regardless; with `strict` the failure is
221
+ * rethrown and the session is left untouched.
201
222
  */
202
223
  readonly strict?: boolean;
203
224
  }
@@ -222,7 +243,10 @@ interface ServerConfig extends Config {
222
243
  * Next.js Server Components.
223
244
  *
224
245
  * Unless a namespace says otherwise, its methods require a user session and
225
- * throw {@link NotAuthenticatedError} when there is none.
246
+ * throw {@link NotAuthenticatedError} when there is none. When the SDK could
247
+ * not find out whether there is one - CoinList's token endpoint failing, or
248
+ * the network - they throw that underlying error instead: see
249
+ * {@link ServerAuthNamespace.getAccessToken}.
226
250
  */
227
251
  interface CoinListServer {
228
252
  /**
@@ -351,4 +375,4 @@ declare class WritableSessionStoreRequiredError extends Error {
351
375
  constructor(message?: string);
352
376
  }
353
377
 
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 };
378
+ export { type CoinListServer, type CompleteOAuthParams, type ServerAuthNamespace, type ServerConfig, type ServerNamespaceContext, type ServerOffersNamespace, ServerOffersNamespaceImpl, type ServerRequirementsNamespace, ServerRequirementsNamespaceImpl, type SessionStore, WritableSessionStoreRequiredError, createCoinListServer, emptySessionStore, pinoServerLogger };