@coinlist-co/react 0.11.0 → 0.11.1-rc.8cfcd2a

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/dist/{chunk-B2HCVPCQ.js → chunk-5KYO7OOX.js} +26 -11
  2. package/dist/chunk-5KYO7OOX.js.map +1 -0
  3. package/dist/chunk-AQIHCFW4.js +279 -0
  4. package/dist/chunk-AQIHCFW4.js.map +1 -0
  5. package/dist/{chunk-UIIXXLA7.js → chunk-ZVB6KWZ2.js} +484 -141
  6. package/dist/chunk-ZVB6KWZ2.js.map +1 -0
  7. package/dist/client/index.cjs +1308 -462
  8. package/dist/client/index.cjs.map +1 -1
  9. package/dist/client/index.d.cts +216 -211
  10. package/dist/client/index.d.ts +216 -211
  11. package/dist/client/index.js +464 -108
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/collections-DrJFEDHl.d.cts +116 -0
  14. package/dist/collections-pLtrj6fw.d.ts +116 -0
  15. package/dist/{config-B5mwS_2l.d.cts → config-C6vlghJY.d.cts} +713 -22
  16. package/dist/{config-B5mwS_2l.d.ts → config-C6vlghJY.d.ts} +713 -22
  17. package/dist/server/index.cjs +766 -209
  18. package/dist/server/index.cjs.map +1 -1
  19. package/dist/server/index.d.cts +80 -3
  20. package/dist/server/index.d.ts +80 -3
  21. package/dist/server/index.js +120 -51
  22. package/dist/server/index.js.map +1 -1
  23. package/dist/shared/index.cjs +487 -124
  24. package/dist/shared/index.cjs.map +1 -1
  25. package/dist/shared/index.d.cts +18 -5
  26. package/dist/shared/index.d.ts +18 -5
  27. package/dist/shared/index.js +8 -2
  28. package/package.json +3 -2
  29. package/dist/chunk-B2HCVPCQ.js.map +0 -1
  30. package/dist/chunk-KDGNDAHA.js +0 -146
  31. package/dist/chunk-KDGNDAHA.js.map +0 -1
  32. package/dist/chunk-UIIXXLA7.js.map +0 -1
  33. package/dist/collections-BhDkYmzV.d.cts +0 -65
  34. package/dist/collections-CZhHoQHr.d.ts +0 -65
@@ -1,4 +1,4 @@
1
- import { A as AuthorizationCode, C as CodeVerifier, a1 as OAuthSession, r as OAuthAccessToken, a2 as ClientCredentialsOAuth, q as Config, a3 as ClientSecret, a4 as Sender, s as OffersNamespace, y as Offer, a5 as PaginationParams, a6 as PaginatedResponse, O as OfferId, v as OfferDetail, R as RequirementsNamespace, e as OfferOptionId, o as Requirement, p as RequirementsNamespaceImpl, S as SharedNamespaceContext, W as WalletsNamespace, b as Erc20Namespace, d as CoinListTokenSaleNamespace, l as SuperstateSwapNamespace, h as OndoNamespace, t as TokensNamespace } from '../config-B5mwS_2l.cjs';
1
+ import { A as AuthorizationCode, C as CodeVerifier, ah as OAuthSession, s as OAuthAccessToken, ai as ClientCredentialsOAuth, r as Config, aj as ClientSecret, ak as Sender, L as Logger, t as OffersNamespace, y as Offer, al as PaginationParams, am as PaginatedResponse, O as OfferId, v as OfferDetail, R as RequirementsNamespace, d as OfferOptionId, p as Requirement, q as RequirementsNamespaceImpl, S as SharedNamespaceContext, l as WalletsNamespace, E as Erc20Namespace, c as CoinListTokenSaleNamespace, k as SuperstateSwapNamespace, g as OndoNamespace, T as TokensNamespace, M as PinoLoggerOptions } from '../config-C6vlghJY.cjs';
2
2
  import 'viem';
3
3
 
4
4
  interface SessionStore {
@@ -24,6 +24,18 @@ interface SessionStore {
24
24
  */
25
25
  setSession?(session: OAuthSession | null): Promise<void>;
26
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;
27
39
  /** The PKCE pair `CoinListClient#auth.completeOAuth` hands to the backend. */
28
40
  interface CompleteOAuthParams {
29
41
  /** The short-lived authorization code parsed out of the redirect URL. */
@@ -101,12 +113,15 @@ type ServerAuthConfig = Config & {
101
113
  declare class ServerAuthNamespaceImpl implements ServerAuthNamespace {
102
114
  private readonly api;
103
115
  private readonly config;
116
+ private readonly log;
104
117
  constructor(api: Sender, config: ServerAuthConfig);
105
- completeOAuth({ code, codeVerifier, }: CompleteOAuthParams): Promise<OAuthSession>;
118
+ completeOAuth(params: CompleteOAuthParams): Promise<OAuthSession>;
106
119
  getAccessToken(): Promise<OAuthAccessToken | null>;
120
+ private readAccessToken;
107
121
  private refreshSession;
108
122
  clientCredentials(): Promise<ClientCredentialsOAuth>;
109
123
  logout(): Promise<void>;
124
+ private revokeAndClear;
110
125
  /**
111
126
  * Returns the store's `setSession`, or throws — the guard every
112
127
  * session-writing operation shares.
@@ -121,6 +136,8 @@ declare class ServerAuthNamespaceImpl implements ServerAuthNamespace {
121
136
  */
122
137
  interface ServerNamespaceContext {
123
138
  readonly api: Sender;
139
+ /** As {@link SharedNamespaceContext.logger}: the raw port, scoped per namespace. */
140
+ readonly logger: Logger | null;
124
141
  /**
125
142
  * Requires a user session, unless `clientCreds` is supplied — an app-level
126
143
  * token authenticates the request on its own. Throws
@@ -147,6 +164,7 @@ interface ServerOffersNamespace extends OffersNamespace {
147
164
  }
148
165
  declare class ServerOffersNamespaceImpl implements ServerOffersNamespace {
149
166
  private readonly ctx;
167
+ private readonly log;
150
168
  constructor(ctx: ServerNamespaceContext);
151
169
  list(clientCreds?: ClientCredentialsOAuth): Promise<Offer[]>;
152
170
  listPage(params: PaginationParams, clientCreds?: ClientCredentialsOAuth): Promise<PaginatedResponse<Offer>>;
@@ -270,8 +288,67 @@ interface CoinListServer {
270
288
  }
271
289
  declare function createCoinListServer(config: ServerConfig): CoinListServer;
272
290
 
291
+ /**
292
+ * A {@link Logger} that writes newline-delimited JSON to stdout through pino.
293
+ *
294
+ * ```ts
295
+ * createCoinListServer({
296
+ * ...config,
297
+ * logger: pinoServerLogger({ isDev: false, level: 'info' }),
298
+ * });
299
+ * ```
300
+ *
301
+ * The Node counterpart of {@link pinoClientLogger}, for a route handler, a BFF
302
+ * or SSR. One line per record, which is what every log aggregator ingests
303
+ * without configuration.
304
+ *
305
+ * ## What it deliberately does not do
306
+ *
307
+ * **No transport, and no `pino-pretty`.** A pino transport runs on a worker
308
+ * thread through `thread-stream`, which every bundler has to be told about
309
+ * (`serverExternalPackages` in Next) and which edge runtimes cannot run at
310
+ * all. Pretty-printing is a pipe the host owns rather than a dependency the
311
+ * SDK takes on their behalf:
312
+ *
313
+ * ```sh
314
+ * node server.js | npx pino-pretty
315
+ * ```
316
+ *
317
+ * **No environment-dependent formatting.** `isDev` decides which levels are
318
+ * legal and nothing else, so a development record and a production record are
319
+ * the same shape - what you debug is what you ship.
320
+ *
321
+ * If you already run pino, or want transports, redaction or `destination`,
322
+ * implement {@link Logger} yourself: it is four methods over an event, and
323
+ * `@opentelemetry/instrumentation-pino` patches the pino module rather than an
324
+ * instance, so trace correlation reaches this logger either way.
325
+ *
326
+ * ## Production
327
+ *
328
+ * **Not advised in production**, the same as everywhere else this seam is
329
+ * documented: the SDK's default answer is to leave {@link Config.logger}
330
+ * undefined outside development, staging and incident reproduction. A backend
331
+ * is the least bad place to disregard that - the records go to your process
332
+ * and your sink rather than to a page the end user can read - but it is still
333
+ * a disregard, and the retention and access questions become yours.
334
+ *
335
+ * If you run one, `isDev: false` restricts you to `'error'`, `'warn'` and
336
+ * `'info'` - `{ isDev: false, level: 'debug' }` does not compile, see
337
+ * {@link PinoLoggerOptions}. Those levels are redacted by construction, which
338
+ * is a mechanism the SDK holds itself to; whether that clears your bar is a
339
+ * judgement the SDK is not in a position to make for you.
340
+ *
341
+ * Holds no module-level state: every call builds its own pino instance, and
342
+ * the level is fixed at construction, so two loggers never interfere. Fixed is
343
+ * this implementation's choice, not the seam's - the SDK re-reads
344
+ * {@link Logger.level} before every log call - so if you want a level you can
345
+ * change at runtime, implement {@link Logger} over your own pino instance
346
+ * rather than calling this.
347
+ */
348
+ declare function pinoServerLogger(options: PinoLoggerOptions): Logger;
349
+
273
350
  declare class WritableSessionStoreRequiredError extends Error {
274
351
  constructor(message?: string);
275
352
  }
276
353
 
277
- export { type CoinListServer, type CompleteOAuthParams, type ServerAuthConfig, type ServerAuthNamespace, ServerAuthNamespaceImpl, type ServerConfig, type ServerNamespaceContext, type ServerOffersNamespace, ServerOffersNamespaceImpl, type ServerRequirementsNamespace, ServerRequirementsNamespaceImpl, type SessionStore, WritableSessionStoreRequiredError, createCoinListServer };
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 };
@@ -1,4 +1,4 @@
1
- import { A as AuthorizationCode, C as CodeVerifier, a1 as OAuthSession, r as OAuthAccessToken, a2 as ClientCredentialsOAuth, q as Config, a3 as ClientSecret, a4 as Sender, s as OffersNamespace, y as Offer, a5 as PaginationParams, a6 as PaginatedResponse, O as OfferId, v as OfferDetail, R as RequirementsNamespace, e as OfferOptionId, o as Requirement, p as RequirementsNamespaceImpl, S as SharedNamespaceContext, W as WalletsNamespace, b as Erc20Namespace, d as CoinListTokenSaleNamespace, l as SuperstateSwapNamespace, h as OndoNamespace, t as TokensNamespace } from '../config-B5mwS_2l.js';
1
+ import { A as AuthorizationCode, C as CodeVerifier, ah as OAuthSession, s as OAuthAccessToken, ai as ClientCredentialsOAuth, r as Config, aj as ClientSecret, ak as Sender, L as Logger, t as OffersNamespace, y as Offer, al as PaginationParams, am as PaginatedResponse, O as OfferId, v as OfferDetail, R as RequirementsNamespace, d as OfferOptionId, p as Requirement, q as RequirementsNamespaceImpl, S as SharedNamespaceContext, l as WalletsNamespace, E as Erc20Namespace, c as CoinListTokenSaleNamespace, k as SuperstateSwapNamespace, g as OndoNamespace, T as TokensNamespace, M as PinoLoggerOptions } from '../config-C6vlghJY.js';
2
2
  import 'viem';
3
3
 
4
4
  interface SessionStore {
@@ -24,6 +24,18 @@ interface SessionStore {
24
24
  */
25
25
  setSession?(session: OAuthSession | null): Promise<void>;
26
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;
27
39
  /** The PKCE pair `CoinListClient#auth.completeOAuth` hands to the backend. */
28
40
  interface CompleteOAuthParams {
29
41
  /** The short-lived authorization code parsed out of the redirect URL. */
@@ -101,12 +113,15 @@ type ServerAuthConfig = Config & {
101
113
  declare class ServerAuthNamespaceImpl implements ServerAuthNamespace {
102
114
  private readonly api;
103
115
  private readonly config;
116
+ private readonly log;
104
117
  constructor(api: Sender, config: ServerAuthConfig);
105
- completeOAuth({ code, codeVerifier, }: CompleteOAuthParams): Promise<OAuthSession>;
118
+ completeOAuth(params: CompleteOAuthParams): Promise<OAuthSession>;
106
119
  getAccessToken(): Promise<OAuthAccessToken | null>;
120
+ private readAccessToken;
107
121
  private refreshSession;
108
122
  clientCredentials(): Promise<ClientCredentialsOAuth>;
109
123
  logout(): Promise<void>;
124
+ private revokeAndClear;
110
125
  /**
111
126
  * Returns the store's `setSession`, or throws — the guard every
112
127
  * session-writing operation shares.
@@ -121,6 +136,8 @@ declare class ServerAuthNamespaceImpl implements ServerAuthNamespace {
121
136
  */
122
137
  interface ServerNamespaceContext {
123
138
  readonly api: Sender;
139
+ /** As {@link SharedNamespaceContext.logger}: the raw port, scoped per namespace. */
140
+ readonly logger: Logger | null;
124
141
  /**
125
142
  * Requires a user session, unless `clientCreds` is supplied — an app-level
126
143
  * token authenticates the request on its own. Throws
@@ -147,6 +164,7 @@ interface ServerOffersNamespace extends OffersNamespace {
147
164
  }
148
165
  declare class ServerOffersNamespaceImpl implements ServerOffersNamespace {
149
166
  private readonly ctx;
167
+ private readonly log;
150
168
  constructor(ctx: ServerNamespaceContext);
151
169
  list(clientCreds?: ClientCredentialsOAuth): Promise<Offer[]>;
152
170
  listPage(params: PaginationParams, clientCreds?: ClientCredentialsOAuth): Promise<PaginatedResponse<Offer>>;
@@ -270,8 +288,67 @@ interface CoinListServer {
270
288
  }
271
289
  declare function createCoinListServer(config: ServerConfig): CoinListServer;
272
290
 
291
+ /**
292
+ * A {@link Logger} that writes newline-delimited JSON to stdout through pino.
293
+ *
294
+ * ```ts
295
+ * createCoinListServer({
296
+ * ...config,
297
+ * logger: pinoServerLogger({ isDev: false, level: 'info' }),
298
+ * });
299
+ * ```
300
+ *
301
+ * The Node counterpart of {@link pinoClientLogger}, for a route handler, a BFF
302
+ * or SSR. One line per record, which is what every log aggregator ingests
303
+ * without configuration.
304
+ *
305
+ * ## What it deliberately does not do
306
+ *
307
+ * **No transport, and no `pino-pretty`.** A pino transport runs on a worker
308
+ * thread through `thread-stream`, which every bundler has to be told about
309
+ * (`serverExternalPackages` in Next) and which edge runtimes cannot run at
310
+ * all. Pretty-printing is a pipe the host owns rather than a dependency the
311
+ * SDK takes on their behalf:
312
+ *
313
+ * ```sh
314
+ * node server.js | npx pino-pretty
315
+ * ```
316
+ *
317
+ * **No environment-dependent formatting.** `isDev` decides which levels are
318
+ * legal and nothing else, so a development record and a production record are
319
+ * the same shape - what you debug is what you ship.
320
+ *
321
+ * If you already run pino, or want transports, redaction or `destination`,
322
+ * implement {@link Logger} yourself: it is four methods over an event, and
323
+ * `@opentelemetry/instrumentation-pino` patches the pino module rather than an
324
+ * instance, so trace correlation reaches this logger either way.
325
+ *
326
+ * ## Production
327
+ *
328
+ * **Not advised in production**, the same as everywhere else this seam is
329
+ * documented: the SDK's default answer is to leave {@link Config.logger}
330
+ * undefined outside development, staging and incident reproduction. A backend
331
+ * is the least bad place to disregard that - the records go to your process
332
+ * and your sink rather than to a page the end user can read - but it is still
333
+ * a disregard, and the retention and access questions become yours.
334
+ *
335
+ * If you run one, `isDev: false` restricts you to `'error'`, `'warn'` and
336
+ * `'info'` - `{ isDev: false, level: 'debug' }` does not compile, see
337
+ * {@link PinoLoggerOptions}. Those levels are redacted by construction, which
338
+ * is a mechanism the SDK holds itself to; whether that clears your bar is a
339
+ * judgement the SDK is not in a position to make for you.
340
+ *
341
+ * Holds no module-level state: every call builds its own pino instance, and
342
+ * the level is fixed at construction, so two loggers never interfere. Fixed is
343
+ * this implementation's choice, not the seam's - the SDK re-reads
344
+ * {@link Logger.level} before every log call - so if you want a level you can
345
+ * change at runtime, implement {@link Logger} over your own pino instance
346
+ * rather than calling this.
347
+ */
348
+ declare function pinoServerLogger(options: PinoLoggerOptions): Logger;
349
+
273
350
  declare class WritableSessionStoreRequiredError extends Error {
274
351
  constructor(message?: string);
275
352
  }
276
353
 
277
- export { type CoinListServer, type CompleteOAuthParams, type ServerAuthConfig, type ServerAuthNamespace, ServerAuthNamespaceImpl, type ServerConfig, type ServerNamespaceContext, type ServerOffersNamespace, ServerOffersNamespaceImpl, type ServerRequirementsNamespace, ServerRequirementsNamespaceImpl, type SessionStore, WritableSessionStoreRequiredError, createCoinListServer };
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 };
@@ -1,7 +1,10 @@
1
1
  import {
2
2
  AuthenticatedApiClient,
3
- NABU_BASE_URL
4
- } from "../chunk-KDGNDAHA.js";
3
+ NABU_BASE_URL,
4
+ PINO_LEVEL,
5
+ SDK_LOGGER_NAME,
6
+ loggerOverPino
7
+ } from "../chunk-AQIHCFW4.js";
5
8
  import {
6
9
  API_VERSION,
7
10
  ClientCredentialsOAuth,
@@ -19,13 +22,19 @@ import {
19
22
  fetchOfferDetails,
20
23
  fetchOfferRequirements,
21
24
  fetchOffers,
22
- fetchOffersPage
23
- } from "../chunk-UIIXXLA7.js";
25
+ fetchOffersPage,
26
+ internalLogger
27
+ } from "../chunk-ZVB6KWZ2.js";
24
28
 
25
29
  // src/server/core/api/api-client.ts
26
30
  var ApiClient = class {
27
- constructor(config, fetchAccessToken) {
28
- this.client = new AuthenticatedApiClient(config, fetchAccessToken);
31
+ constructor(config, fetchAccessToken, logger = null) {
32
+ this.client = new AuthenticatedApiClient(
33
+ config,
34
+ fetchAccessToken,
35
+ [],
36
+ logger
37
+ );
29
38
  }
30
39
  async send(request) {
31
40
  return this.client.send(request);
@@ -41,33 +50,43 @@ var WritableSessionStoreRequiredError = class extends Error {
41
50
  };
42
51
 
43
52
  // src/server/core/server-auth-namespace.ts
53
+ function emptySessionStore() {
54
+ return { getSession: async () => null };
55
+ }
44
56
  var ServerAuthNamespaceImpl = class {
45
57
  constructor(api, config) {
46
58
  this.api = api;
47
59
  this.config = config;
60
+ this.log = internalLogger(config.logger ?? null, "AUTH");
48
61
  }
49
- async completeOAuth({
50
- code,
51
- codeVerifier
52
- }) {
53
- const setSession = this.writableSessionStore();
54
- const sessionDto = await this.api.send({
55
- method: "POST",
56
- url: `/oauth/token`,
57
- body: {
58
- grant_type: "authorization_code",
59
- code,
60
- redirect_uri: this.config.redirectUri,
61
- client_id: this.config.clientId,
62
- client_secret: this.config.clientSecret,
63
- code_verifier: codeVerifier
64
- }
62
+ async completeOAuth(params) {
63
+ return this.log.wrap("completeOAuth", void 0, async () => {
64
+ const setSession = this.writableSessionStore();
65
+ const sessionDto = await this.api.send({
66
+ method: "POST",
67
+ url: `/oauth/token`,
68
+ body: {
69
+ grant_type: "authorization_code",
70
+ code: params.code,
71
+ redirect_uri: this.config.redirectUri,
72
+ client_id: this.config.clientId,
73
+ client_secret: this.config.clientSecret,
74
+ code_verifier: params.codeVerifier
75
+ }
76
+ });
77
+ const session = OAuthSession.fromDto(sessionDto);
78
+ await setSession(session);
79
+ return session;
65
80
  });
66
- const session = OAuthSession.fromDto(sessionDto);
67
- await setSession(session);
68
- return session;
69
81
  }
70
82
  async getAccessToken() {
83
+ return this.log.wrap(
84
+ "getAccessToken",
85
+ void 0,
86
+ () => this.readAccessToken()
87
+ );
88
+ }
89
+ async readAccessToken() {
71
90
  const sessionStore = this.config.sessionStore;
72
91
  const session = await sessionStore.getSession();
73
92
  if (session == null) return null;
@@ -79,12 +98,19 @@ var ServerAuthNamespaceImpl = class {
79
98
  }
80
99
  const setSession = sessionStore.setSession?.bind(sessionStore);
81
100
  if (!setSession) {
101
+ this.log.child({ op: "getAccessToken" }).warn(() => ({
102
+ msg: "serving an expired token: the session store is read-only, so it cannot be refreshed"
103
+ }));
82
104
  return session.accessToken;
83
105
  }
84
106
  return this.refreshSession(session.refreshToken, setSession);
85
107
  }
86
108
  async refreshSession(refreshToken, setSession) {
109
+ const log = this.log.child({ op: "refresh" });
87
110
  if (!refreshToken) {
111
+ log.warn(() => ({
112
+ msg: "clearing the session: it carries no refresh token"
113
+ }));
88
114
  await setSession(null);
89
115
  return null;
90
116
  }
@@ -101,26 +127,36 @@ var ServerAuthNamespaceImpl = class {
101
127
  });
102
128
  const newSession = OAuthSession.fromDto(sessionDto);
103
129
  await setSession(newSession);
130
+ log.info(() => ({ msg: "session renewed" }));
104
131
  return newSession.accessToken;
105
- } catch {
132
+ } catch (error) {
133
+ log.failure(
134
+ () => ({ msg: "refresh failed; clearing the session" }),
135
+ error
136
+ );
106
137
  await setSession(null);
107
138
  return null;
108
139
  }
109
140
  }
110
141
  async clientCredentials() {
111
- const sessionDto = await this.api.send({
112
- method: "POST",
113
- url: `/oauth/token`,
114
- body: {
115
- grant_type: "client_credentials",
116
- client_id: this.config.clientId,
117
- client_secret: this.config.clientSecret
118
- }
142
+ return this.log.wrap("clientCredentials", void 0, async () => {
143
+ const sessionDto = await this.api.send({
144
+ method: "POST",
145
+ url: `/oauth/token`,
146
+ body: {
147
+ grant_type: "client_credentials",
148
+ client_id: this.config.clientId,
149
+ client_secret: this.config.clientSecret
150
+ }
151
+ });
152
+ const session = OAuthSession.fromDto(sessionDto);
153
+ return ClientCredentialsOAuth(session.accessToken);
119
154
  });
120
- const session = OAuthSession.fromDto(sessionDto);
121
- return ClientCredentialsOAuth(session.accessToken);
122
155
  }
123
156
  async logout() {
157
+ return this.log.wrap("logout", void 0, () => this.revokeAndClear());
158
+ }
159
+ async revokeAndClear() {
124
160
  const setSession = this.writableSessionStore();
125
161
  const session = await this.config.sessionStore.getSession();
126
162
  if (session == null) return;
@@ -138,6 +174,9 @@ var ServerAuthNamespaceImpl = class {
138
174
  if (!(err instanceof HttpError) || this.config.strict) {
139
175
  throw err;
140
176
  }
177
+ this.log.child({ op: "logout" }).warn(() => ({
178
+ msg: "the token was not revoked upstream; the local session is cleared regardless"
179
+ }));
141
180
  }
142
181
  await setSession(null);
143
182
  }
@@ -159,18 +198,25 @@ var ServerAuthNamespaceImpl = class {
159
198
  var ServerOffersNamespaceImpl = class {
160
199
  constructor(ctx) {
161
200
  this.ctx = ctx;
201
+ this.log = internalLogger(ctx.logger, "OFFERS");
162
202
  }
163
203
  async list(clientCreds) {
164
- await this.ctx.ensureAuthenticated(clientCreds);
165
- return fetchOffers(this.ctx.api, clientCreds);
204
+ return this.log.wrap("list", clientCreds, async () => {
205
+ await this.ctx.ensureAuthenticated(clientCreds);
206
+ return fetchOffers(this.ctx.api, clientCreds);
207
+ });
166
208
  }
167
209
  async listPage(params, clientCreds) {
168
- await this.ctx.ensureAuthenticated(clientCreds);
169
- return fetchOffersPage(this.ctx.api, params, clientCreds);
210
+ return this.log.wrap("listPage", { params, clientCreds }, async () => {
211
+ await this.ctx.ensureAuthenticated(clientCreds);
212
+ return fetchOffersPage(this.ctx.api, params, clientCreds);
213
+ });
170
214
  }
171
215
  async get(id, clientCreds) {
172
- await this.ctx.ensureAuthenticated(clientCreds);
173
- return fetchOfferDetails(this.ctx.api, id, clientCreds);
216
+ return this.log.wrap("get", { id, clientCreds }, async () => {
217
+ await this.ctx.ensureAuthenticated(clientCreds);
218
+ return fetchOfferDetails(this.ctx.api, id, clientCreds);
219
+ });
174
220
  }
175
221
  };
176
222
 
@@ -181,12 +227,14 @@ var ServerRequirementsNamespaceImpl = class extends RequirementsNamespaceImpl {
181
227
  this.serverCtx = serverCtx;
182
228
  }
183
229
  async forOffer(offerId, clientCreds) {
184
- await this.serverCtx.ensureAuthenticated(clientCreds);
185
- return fetchOfferRequirements(
186
- this.serverCtx.api,
187
- offerId,
188
- clientCreds
189
- );
230
+ return this.log.wrap("forOffer", { offerId, clientCreds }, async () => {
231
+ await this.serverCtx.ensureAuthenticated(clientCreds);
232
+ return fetchOfferRequirements(
233
+ this.serverCtx.api,
234
+ offerId,
235
+ clientCreds
236
+ );
237
+ });
190
238
  }
191
239
  };
192
240
 
@@ -195,6 +243,7 @@ var ACCESS_TOKEN_EXPIRY_BUFFER_SECONDS = 60;
195
243
  var CoinListServerImpl = class {
196
244
  constructor(_config) {
197
245
  this._config = _config;
246
+ const logger = _config.logger ?? null;
198
247
  this.api = new ApiClient(
199
248
  {
200
249
  baseUrl: _config.baseUrl ?? PUBLIC_API_BASE_URL,
@@ -204,7 +253,8 @@ var CoinListServerImpl = class {
204
253
  // fresh token. A read-only store cannot persist a new session, so return
205
254
  // null immediately — this tells the middleware to skip the retry rather
206
255
  // than re-sending with the same expired token and wasting a round-trip.
207
- (refresh) => refresh && !this._config.sessionStore.setSession ? Promise.resolve(null) : this.auth.getAccessToken()
256
+ (refresh) => refresh && !this._config.sessionStore.setSession ? Promise.resolve(null) : this.auth.getAccessToken(),
257
+ logger
208
258
  );
209
259
  this.auth = new ServerAuthNamespaceImpl(this.api, {
210
260
  ..._config,
@@ -213,6 +263,7 @@ var CoinListServerImpl = class {
213
263
  });
214
264
  const ctx = {
215
265
  api: this.api,
266
+ logger,
216
267
  ensureUserAuthenticated: () => this.ensureAuthenticated(void 0),
217
268
  ensureAuthenticated: (clientCreds) => this.ensureAuthenticated(clientCreds)
218
269
  };
@@ -224,7 +275,8 @@ var CoinListServerImpl = class {
224
275
  this.superstate = new SuperstateSwapNamespaceImpl(ctx);
225
276
  this.ondo = new OndoNamespaceImpl(ctx);
226
277
  this.tokens = new TokensNamespaceImpl(
227
- _config.tokensBaseUrl ?? NABU_BASE_URL
278
+ _config.tokensBaseUrl ?? NABU_BASE_URL,
279
+ logger
228
280
  );
229
281
  }
230
282
  /**
@@ -242,11 +294,28 @@ var CoinListServerImpl = class {
242
294
  function createCoinListServer(config) {
243
295
  return new CoinListServerImpl(config);
244
296
  }
297
+
298
+ // src/server/core/observability/pino-server-logger.ts
299
+ import { pino } from "pino";
300
+ function pinoServerLogger(options) {
301
+ return loggerOverPino(
302
+ // `name` as a child binding rather than pino's `name` option: the option
303
+ // is honoured by pino's node build and silently dropped by its browser
304
+ // build, so a binding is the only spelling that identifies the SDK in
305
+ // both environments.
306
+ pino({
307
+ level: PINO_LEVEL[options.level]
308
+ }).child({ name: SDK_LOGGER_NAME }),
309
+ options.level
310
+ );
311
+ }
245
312
  export {
246
313
  ServerAuthNamespaceImpl,
247
314
  ServerOffersNamespaceImpl,
248
315
  ServerRequirementsNamespaceImpl,
249
316
  WritableSessionStoreRequiredError,
250
- createCoinListServer
317
+ createCoinListServer,
318
+ emptySessionStore,
319
+ pinoServerLogger
251
320
  };
252
321
  //# sourceMappingURL=index.js.map