@coinlist-co/react 0.12.2-rc.8a0d02a → 0.12.2-rc.8a65e9d

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 (35) hide show
  1. package/README.md +10 -0
  2. package/dist/{chunk-C6GF7MDF.js → chunk-2FZAXGVH.js} +1011 -1184
  3. package/dist/chunk-2FZAXGVH.js.map +1 -0
  4. package/dist/{chunk-IZJ4JSSC.js → chunk-EAPBF7T2.js} +152 -234
  5. package/dist/chunk-EAPBF7T2.js.map +1 -0
  6. package/dist/chunk-IWQ6A52U.js +24 -0
  7. package/dist/chunk-IWQ6A52U.js.map +1 -0
  8. package/dist/{chunk-3WW5FLT7.js → chunk-OQ2ANYUF.js} +334 -27
  9. package/dist/chunk-OQ2ANYUF.js.map +1 -0
  10. package/dist/client/index.d.ts +3277 -5736
  11. package/dist/client/index.js +10835 -10729
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/client-credentials-BwcmPcn-.d.ts +13 -0
  14. package/dist/server/index.d.ts +54 -132
  15. package/dist/server/index.js +211 -171
  16. package/dist/server/index.js.map +1 -1
  17. package/dist/{time-CVZpAkGY.d.cts → time-ChSGmKZe.d.ts} +2194 -3422
  18. package/dist/{token-registry-snapshot-BkwA8KmD.d.ts → token-registry-snapshot-DMubXr2c.d.ts} +22 -58
  19. package/dist/universal/index.d.ts +94 -1068
  20. package/dist/universal/index.js +25 -47
  21. package/package.json +18 -14
  22. package/dist/chunk-3WW5FLT7.js.map +0 -1
  23. package/dist/chunk-C6GF7MDF.js.map +0 -1
  24. package/dist/chunk-IZJ4JSSC.js.map +0 -1
  25. package/dist/client/index.cjs +0 -20460
  26. package/dist/client/index.cjs.map +0 -1
  27. package/dist/client/index.d.cts +0 -8195
  28. package/dist/server/index.cjs +0 -4525
  29. package/dist/server/index.cjs.map +0 -1
  30. package/dist/server/index.d.cts +0 -382
  31. package/dist/time-CVZpAkGY.d.ts +0 -3987
  32. package/dist/token-registry-snapshot-bR14QehS.d.cts +0 -245
  33. package/dist/universal/index.cjs +0 -4562
  34. package/dist/universal/index.cjs.map +0 -1
  35. package/dist/universal/index.d.cts +0 -1362
@@ -1,27 +1,30 @@
1
1
  import {
2
+ API_VERSION,
2
3
  AuthenticatedApiClient,
3
- NABU_BASE_URL,
4
4
  PINO_LEVEL,
5
5
  SDK_LOGGER_NAME,
6
+ baseUrls,
7
+ createNabuApiClient,
6
8
  loggerOverPino,
7
9
  notifySessionExpired,
8
10
  publicClients,
9
11
  systemTime
10
- } from "../chunk-3WW5FLT7.js";
12
+ } from "../chunk-OQ2ANYUF.js";
13
+ import {
14
+ ClientCredentialsOAuth,
15
+ OAuthSession
16
+ } from "../chunk-IWQ6A52U.js";
11
17
  import {
12
- API_VERSION,
13
18
  Attributes,
14
19
  CentrifugeNamespaceImpl,
15
- ClientCredentialsOAuth,
16
20
  CoinListTokenSaleNamespaceImpl,
17
21
  EpochMillis,
18
22
  Erc20NamespaceImpl,
19
23
  HttpError,
20
24
  Millis,
21
25
  NotAuthenticatedError,
22
- OAuthSession,
26
+ OffersNamespaceImpl,
23
27
  OndoNamespaceImpl,
24
- PUBLIC_API_BASE_URL,
25
28
  RequirementsNamespaceImpl,
26
29
  Seconds,
27
30
  SuperstateSwapNamespaceImpl,
@@ -35,24 +38,84 @@ import {
35
38
  internalLogger,
36
39
  isExpired,
37
40
  isRejectedToken
38
- } from "../chunk-C6GF7MDF.js";
41
+ } from "../chunk-2FZAXGVH.js";
39
42
 
40
- // src/server/core/api/api-client.ts
41
- var ApiClient = class {
42
- constructor(config, fetchAccessToken, logger = null) {
43
- this.client = new AuthenticatedApiClient(
44
- config,
45
- fetchAccessToken,
46
- [],
47
- logger
48
- );
49
- }
50
- async send(request) {
51
- return this.client.send(request);
43
+ // src/server/core/auth/errors.ts
44
+ var WritableSessionStoreRequiredError = class extends Error {
45
+ constructor(message = "This operation requires a writable SessionStore. Provide a `setSession` implementation in your SessionStore to persist or clear OAuth sessions.") {
46
+ super(message);
47
+ this.name = "WritableSessionStoreRequiredError";
52
48
  }
53
49
  };
54
50
 
55
- // src/server/core/session-refresh.ts
51
+ // src/server/core/auth/server-access-token.ts
52
+ function classifyAccessToken({
53
+ session,
54
+ store,
55
+ trigger,
56
+ now,
57
+ buffer
58
+ }) {
59
+ if (session === null) {
60
+ return { type: "no-session" };
61
+ }
62
+ const token = session.accessToken;
63
+ const stale = isExpired({
64
+ expiresAt: EpochMillis.fromDate(token.expiresAt),
65
+ now,
66
+ buffer
67
+ });
68
+ switch (store.type) {
69
+ case "read-only":
70
+ return classifyReadOnly(token, trigger, stale);
71
+ case "writable": {
72
+ if (!needsRefresh(token, trigger, stale)) {
73
+ return { type: "serve", token };
74
+ }
75
+ const fallback = fallbackToken(token, trigger, now);
76
+ return session.refreshToken === void 0 && fallback !== null ? { type: "serve", token: fallback } : {
77
+ type: "refresh",
78
+ session,
79
+ setSession: store.setSession,
80
+ fallback
81
+ };
82
+ }
83
+ }
84
+ }
85
+ function classifyReadOnly(token, trigger, stale) {
86
+ switch (trigger.type) {
87
+ case "after-401":
88
+ return isRejectedToken(token, trigger.rejected) ? { type: "refuse" } : { type: "serve", token };
89
+ case "before-request":
90
+ return stale ? { type: "serve-stale", token } : { type: "serve", token };
91
+ }
92
+ }
93
+ function sessionStoreAccess(sessionStore) {
94
+ const setSession = sessionStore.setSession?.bind(sessionStore);
95
+ return setSession === void 0 ? { type: "read-only" } : { type: "writable", setSession };
96
+ }
97
+ function needsRefresh(token, trigger, stale) {
98
+ switch (trigger.type) {
99
+ case "before-request":
100
+ return stale;
101
+ case "after-401":
102
+ return trigger.rejected.type === "no-user-token" || isRejectedToken(token, trigger.rejected) || stale;
103
+ }
104
+ }
105
+ function fallbackToken(token, trigger, now) {
106
+ const unexpired = !isExpired({
107
+ expiresAt: EpochMillis.fromDate(token.expiresAt),
108
+ now
109
+ });
110
+ switch (trigger.type) {
111
+ case "after-401":
112
+ return unexpired && !isRejectedToken(token, trigger.rejected) ? token : null;
113
+ case "before-request":
114
+ return unexpired ? token : null;
115
+ }
116
+ }
117
+
118
+ // src/server/core/auth/session-refresh.ts
56
119
  var VERDICT_MIN_GAP = Millis.of(5e3);
57
120
  var REJECTION_MEMORY = Millis.of(6e4);
58
121
  var RefreshKey = {
@@ -153,38 +216,91 @@ function rejectedAt(rejection) {
153
216
  }
154
217
  var processRefreshCoordinator = new RefreshCoordinator();
155
218
 
156
- // src/server/shared/errors.ts
157
- var WritableSessionStoreRequiredError = class extends Error {
158
- constructor(message = "This operation requires a writable SessionStore. Provide a `setSession` implementation in your SessionStore to persist or clear OAuth sessions.") {
159
- super(message);
160
- this.name = "WritableSessionStoreRequiredError";
219
+ // src/universal/api/frontline/oauth.ts
220
+ async function exchangeAuthorizationCode(api, params) {
221
+ const dto = await api.send({
222
+ method: "POST",
223
+ url: "/oauth/token",
224
+ body: {
225
+ grant_type: "authorization_code",
226
+ code: params.code,
227
+ redirect_uri: params.redirectUri,
228
+ client_id: params.clientId,
229
+ client_secret: params.clientSecret,
230
+ code_verifier: params.codeVerifier
231
+ },
232
+ attributes: Attributes.notRetryable()
233
+ });
234
+ return OAuthSession.fromDto(dto);
235
+ }
236
+ async function refreshOAuthSession(api, params) {
237
+ try {
238
+ const dto = await api.send({
239
+ method: "POST",
240
+ url: "/oauth/token",
241
+ body: {
242
+ grant_type: "refresh_token",
243
+ refresh_token: params.refreshToken,
244
+ client_id: params.clientId,
245
+ client_secret: params.clientSecret
246
+ },
247
+ attributes: Attributes.notRetryable()
248
+ });
249
+ return { type: "renewed", session: OAuthSession.fromDto(dto) };
250
+ } catch (error) {
251
+ if (isInvalidGrant(error)) {
252
+ return { type: "invalid-grant" };
253
+ }
254
+ throw error;
161
255
  }
162
- };
256
+ }
257
+ async function requestClientCredentials(api, params) {
258
+ const dto = await api.send({
259
+ method: "POST",
260
+ url: "/oauth/token",
261
+ body: {
262
+ grant_type: "client_credentials",
263
+ client_id: params.clientId,
264
+ client_secret: params.clientSecret
265
+ }
266
+ });
267
+ return ClientCredentialsOAuth(OAuthSession.fromDto(dto).accessToken);
268
+ }
269
+ async function revokeOAuthToken(api, params) {
270
+ await api.send({
271
+ method: "POST",
272
+ url: "/oauth/revoke",
273
+ body: {
274
+ token: params.token.value,
275
+ client_id: params.clientId,
276
+ client_secret: params.clientSecret
277
+ }
278
+ });
279
+ }
280
+ function isInvalidGrant(error) {
281
+ if (!(error instanceof HttpError) || error.response.status !== 400) {
282
+ return false;
283
+ }
284
+ const body = error.response.body;
285
+ return typeof body === "object" && body !== null && "error" in body && body.error === "invalid_grant";
286
+ }
163
287
 
164
- // src/server/core/server-auth-namespace-impl.ts
288
+ // src/server/core/auth/auth-namespace.ts
165
289
  var ServerAuthNamespaceImpl = class {
166
290
  constructor(api, config) {
167
291
  this.api = api;
168
292
  this.config = config;
169
293
  this.log = internalLogger(config.logger ?? null, "AUTH");
170
294
  }
171
- async completeOAuth(params) {
295
+ async completeOAuth(grant) {
172
296
  return this.log.wrap("completeOAuth", void 0, async () => {
173
297
  const setSession = this.writableSessionStore();
174
- const sessionDto = await this.api.send({
175
- method: "POST",
176
- url: `/oauth/token`,
177
- body: {
178
- grant_type: "authorization_code",
179
- code: params.code,
180
- redirect_uri: this.config.redirectUri,
181
- client_id: this.config.clientId,
182
- client_secret: this.config.clientSecret,
183
- code_verifier: params.codeVerifier
184
- },
185
- attributes: Attributes.notRetryable()
298
+ const session = await exchangeAuthorizationCode(this.api, {
299
+ ...this.oauthClient(),
300
+ code: grant.code,
301
+ codeVerifier: grant.codeVerifier,
302
+ redirectUri: this.config.redirectUri
186
303
  });
187
- const session = OAuthSession.fromDto(sessionDto);
188
304
  await setSession(session);
189
305
  return session;
190
306
  });
@@ -292,48 +408,34 @@ var ServerAuthNamespaceImpl = class {
292
408
  }
293
409
  }
294
410
  /**
295
- * One `POST /oauth/token`, total: every failure comes back as a value, so
411
+ * One refresh-token grant, total: every failure comes back as a value, so
296
412
  * the coordinator can judge it once for everyone who joined.
297
- *
298
- * Never retried. The refresh token is single-use, so a retry of an attempt
299
- * that reached the server would present a token already rotated away, and
300
- * its `invalid_grant` would be judged as a rejection of the session.
301
413
  */
302
414
  async exchange(refreshToken) {
303
415
  if (refreshToken === void 0) {
304
416
  return { type: "unrenewable" };
305
417
  }
306
418
  try {
307
- const sessionDto = await this.api.send({
308
- method: "POST",
309
- url: `/oauth/token`,
310
- body: {
311
- grant_type: "refresh_token",
312
- refresh_token: refreshToken,
313
- client_id: this.config.clientId,
314
- client_secret: this.config.clientSecret
315
- },
316
- attributes: Attributes.notRetryable()
419
+ const grant = await refreshOAuthSession(this.api, {
420
+ ...this.oauthClient(),
421
+ refreshToken
317
422
  });
318
- return { type: "renewed", session: OAuthSession.fromDto(sessionDto) };
423
+ switch (grant.type) {
424
+ case "renewed":
425
+ return { type: "renewed", session: grant.session };
426
+ case "invalid-grant":
427
+ return { type: "rejected" };
428
+ }
319
429
  } catch (error) {
320
- return isInvalidGrant(error) ? { type: "rejected" } : { type: "unknown", error };
430
+ return { type: "unknown", error };
321
431
  }
322
432
  }
323
433
  async clientCredentials() {
324
- return this.log.wrap("clientCredentials", void 0, async () => {
325
- const sessionDto = await this.api.send({
326
- method: "POST",
327
- url: `/oauth/token`,
328
- body: {
329
- grant_type: "client_credentials",
330
- client_id: this.config.clientId,
331
- client_secret: this.config.clientSecret
332
- }
333
- });
334
- const session = OAuthSession.fromDto(sessionDto);
335
- return ClientCredentialsOAuth(session.accessToken);
336
- });
434
+ return this.log.wrap(
435
+ "clientCredentials",
436
+ void 0,
437
+ () => requestClientCredentials(this.api, this.oauthClient())
438
+ );
337
439
  }
338
440
  async logout() {
339
441
  return this.log.wrap("logout", void 0, () => this.revokeAndClear());
@@ -343,14 +445,9 @@ var ServerAuthNamespaceImpl = class {
343
445
  const session = await this.config.sessionStore.getSession();
344
446
  if (session == null) return;
345
447
  try {
346
- await this.api.send({
347
- method: "POST",
348
- url: `/oauth/revoke`,
349
- body: {
350
- token: session.accessToken.value,
351
- client_id: this.config.clientId,
352
- client_secret: this.config.clientSecret
353
- }
448
+ await revokeOAuthToken(this.api, {
449
+ ...this.oauthClient(),
450
+ token: session.accessToken
354
451
  });
355
452
  } catch (err) {
356
453
  if (this.config.strict) {
@@ -363,6 +460,12 @@ var ServerAuthNamespaceImpl = class {
363
460
  }
364
461
  await setSession(null);
365
462
  }
463
+ oauthClient() {
464
+ return {
465
+ clientId: this.config.clientId,
466
+ clientSecret: this.config.clientSecret
467
+ };
468
+ }
366
469
  /**
367
470
  * Returns the store's `setSession`, or throws - the guard every
368
471
  * session-writing operation shares.
@@ -377,85 +480,29 @@ var ServerAuthNamespaceImpl = class {
377
480
  }
378
481
  }
379
482
  };
380
- function classifyAccessToken({
381
- session,
382
- store,
383
- trigger,
384
- now,
385
- buffer
386
- }) {
387
- if (session === null) {
388
- return { type: "no-session" };
389
- }
390
- const token = session.accessToken;
391
- const stale = isExpired({
392
- expiresAt: EpochMillis.fromDate(token.expiresAt),
393
- now,
394
- buffer
395
- });
396
- switch (store.type) {
397
- case "read-only":
398
- return classifyReadOnly(token, trigger, stale);
399
- case "writable": {
400
- if (!needsRefresh(token, trigger, stale)) {
401
- return { type: "serve", token };
402
- }
403
- const fallback = fallbackToken(token, trigger, now);
404
- return session.refreshToken === void 0 && fallback !== null ? { type: "serve", token: fallback } : {
405
- type: "refresh",
406
- session,
407
- setSession: store.setSession,
408
- fallback
409
- };
410
- }
411
- }
412
- }
413
- function classifyReadOnly(token, trigger, stale) {
414
- switch (trigger.type) {
415
- case "after-401":
416
- return isRejectedToken(token, trigger.rejected) ? { type: "refuse" } : { type: "serve", token };
417
- case "before-request":
418
- return stale ? { type: "serve-stale", token } : { type: "serve", token };
419
- }
420
- }
421
- function sessionStoreAccess(sessionStore) {
422
- const setSession = sessionStore.setSession?.bind(sessionStore);
423
- return setSession === void 0 ? { type: "read-only" } : { type: "writable", setSession };
424
- }
425
- function needsRefresh(token, trigger, stale) {
426
- switch (trigger.type) {
427
- case "before-request":
428
- return stale;
429
- case "after-401":
430
- return trigger.rejected.type === "no-user-token" || isRejectedToken(token, trigger.rejected) || stale;
431
- }
483
+
484
+ // src/server/core/auth/session-store.ts
485
+ function emptySessionStore() {
486
+ return { getSession: async () => null };
432
487
  }
433
- function fallbackToken(token, trigger, now) {
434
- const unexpired = !isExpired({
435
- expiresAt: EpochMillis.fromDate(token.expiresAt),
436
- now
437
- });
438
- switch (trigger.type) {
439
- case "after-401":
440
- return unexpired && !isRejectedToken(token, trigger.rejected) ? token : null;
441
- case "before-request":
442
- return unexpired ? token : null;
488
+
489
+ // src/server/core/api/api-client.ts
490
+ var ApiClient = class {
491
+ constructor(config, fetchAccessToken, logger = null) {
492
+ this.client = new AuthenticatedApiClient(
493
+ config,
494
+ fetchAccessToken,
495
+ [],
496
+ logger
497
+ );
443
498
  }
444
- }
445
- function isInvalidGrant(error) {
446
- if (!(error instanceof HttpError) || error.response.status !== 400) {
447
- return false;
499
+ async send(request) {
500
+ return this.client.send(request);
448
501
  }
449
- const body = error.response.body;
450
- return typeof body === "object" && body !== null && "error" in body && body.error === "invalid_grant";
451
- }
502
+ };
452
503
 
453
- // src/server/core/server-offers-namespace.ts
454
- var ServerOffersNamespaceImpl = class {
455
- constructor(ctx) {
456
- this.ctx = ctx;
457
- this.log = internalLogger(ctx.logger, "OFFERS");
458
- }
504
+ // src/server/core/offers/server-offers-namespace.ts
505
+ var ServerOffersNamespaceImpl = class extends OffersNamespaceImpl {
459
506
  async list(clientCreds) {
460
507
  return this.log.wrap("list", clientCreds, async () => {
461
508
  await this.ctx.ensureAuthenticated(clientCreds);
@@ -476,17 +523,13 @@ var ServerOffersNamespaceImpl = class {
476
523
  }
477
524
  };
478
525
 
479
- // src/server/core/server-requirements-namespace.ts
526
+ // src/server/core/requirements/server-requirements-namespace.ts
480
527
  var ServerRequirementsNamespaceImpl = class extends RequirementsNamespaceImpl {
481
- constructor(serverCtx) {
482
- super(serverCtx);
483
- this.serverCtx = serverCtx;
484
- }
485
528
  async forOffer(offerId, clientCreds) {
486
529
  return this.log.wrap("forOffer", { offerId, clientCreds }, async () => {
487
- await this.serverCtx.ensureAuthenticated(clientCreds);
530
+ await this.ctx.ensureAuthenticated(clientCreds);
488
531
  return fetchOfferRequirements(
489
- this.serverCtx.api,
532
+ this.ctx.api,
490
533
  offerId,
491
534
  clientCreds
492
535
  );
@@ -499,9 +542,10 @@ var ACCESS_TOKEN_EXPIRY_BUFFER = Seconds.of(60);
499
542
  var CoinListServerImpl = class {
500
543
  constructor(_config) {
501
544
  const logger = _config.logger ?? null;
545
+ const urls = baseUrls(_config);
502
546
  this.api = new ApiClient(
503
547
  {
504
- baseUrl: _config.baseUrl ?? PUBLIC_API_BASE_URL,
548
+ baseUrl: urls.api,
505
549
  xApiVersion: API_VERSION
506
550
  },
507
551
  (trigger) => auth.tokenFor(trigger),
@@ -530,10 +574,10 @@ var CoinListServerImpl = class {
530
574
  this.superstate = new SuperstateSwapNamespaceImpl(ctx);
531
575
  this.ondo = new OndoNamespaceImpl(ctx);
532
576
  this.centrifuge = new CentrifugeNamespaceImpl(ctx);
533
- this.tokens = new TokensNamespaceImpl(
534
- _config.tokensBaseUrl ?? NABU_BASE_URL,
577
+ this.tokens = new TokensNamespaceImpl({
578
+ nabu: createNabuApiClient(urls.tokens, logger),
535
579
  logger
536
- );
580
+ });
537
581
  }
538
582
  /**
539
583
  * An app-level token authenticates a request on its own; without one the
@@ -551,7 +595,7 @@ function createCoinListServer(config) {
551
595
  return new CoinListServerImpl(config);
552
596
  }
553
597
 
554
- // src/server/core/observability/pino-server-logger.ts
598
+ // src/server/core/shared/observability/pino-server-logger.ts
555
599
  import { pino } from "pino";
556
600
  function pinoServerLogger(options) {
557
601
  return loggerOverPino(
@@ -565,12 +609,8 @@ function pinoServerLogger(options) {
565
609
  options.level
566
610
  );
567
611
  }
568
-
569
- // src/server/core/server-auth-namespace.ts
570
- function emptySessionStore() {
571
- return { getSession: async () => null };
572
- }
573
612
  export {
613
+ ServerAuthNamespaceImpl,
574
614
  ServerOffersNamespaceImpl,
575
615
  ServerRequirementsNamespaceImpl,
576
616
  WritableSessionStoreRequiredError,