@coinlist-co/react 0.10.1 → 0.11.0
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.
- package/README.md +32 -0
- package/dist/{chunk-AQVCOWOV.js → chunk-B2HCVPCQ.js} +202 -318
- package/dist/chunk-B2HCVPCQ.js.map +1 -0
- package/dist/chunk-KDGNDAHA.js +146 -0
- package/dist/chunk-KDGNDAHA.js.map +1 -0
- package/dist/chunk-UIIXXLA7.js +1863 -0
- package/dist/chunk-UIIXXLA7.js.map +1 -0
- package/dist/client/index.cjs +10382 -3262
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +4219 -862
- package/dist/client/index.d.ts +4219 -862
- package/dist/client/index.js +8727 -2369
- package/dist/client/index.js.map +1 -1
- package/dist/collections-BhDkYmzV.d.cts +65 -0
- package/dist/collections-CZhHoQHr.d.ts +65 -0
- package/dist/config-B5mwS_2l.d.cts +1926 -0
- package/dist/config-B5mwS_2l.d.ts +1926 -0
- package/dist/server/index.cjs +981 -464
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +190 -163
- package/dist/server/index.d.ts +190 -163
- package/dist/server/index.js +151 -154
- package/dist/server/index.js.map +1 -1
- package/dist/shared/index.cjs +1810 -907
- package/dist/shared/index.cjs.map +1 -1
- package/dist/shared/index.d.cts +243 -132
- package/dist/shared/index.d.ts +243 -132
- package/dist/shared/index.js +96 -28
- package/package.json +10 -7
- package/dist/chunk-AQVCOWOV.js.map +0 -1
- package/dist/chunk-TBU3EBNM.js +0 -442
- package/dist/chunk-TBU3EBNM.js.map +0 -1
- package/dist/chunk-UOHD7US2.js +0 -855
- package/dist/chunk-UOHD7US2.js.map +0 -1
- package/dist/collections-Bv1Oxzu_.d.ts +0 -28
- package/dist/collections-DDyxbOPZ.d.cts +0 -28
- package/dist/requirement-oVZA1INj.d.cts +0 -1040
- package/dist/requirement-oVZA1INj.d.ts +0 -1040
package/dist/server/index.js
CHANGED
|
@@ -1,32 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
|
-
API_VERSION,
|
|
3
2
|
AuthenticatedApiClient,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
createKycToken,
|
|
7
|
-
fetchOfferDetails,
|
|
8
|
-
fetchOfferRequirements,
|
|
9
|
-
fetchOffers,
|
|
10
|
-
fetchOffersPage,
|
|
11
|
-
fetchPii,
|
|
12
|
-
fetchRequirementStatuses,
|
|
13
|
-
submitDocument
|
|
14
|
-
} from "../chunk-TBU3EBNM.js";
|
|
3
|
+
NABU_BASE_URL
|
|
4
|
+
} from "../chunk-KDGNDAHA.js";
|
|
15
5
|
import {
|
|
6
|
+
API_VERSION,
|
|
16
7
|
ClientCredentialsOAuth,
|
|
8
|
+
CoinListTokenSaleNamespaceImpl,
|
|
17
9
|
Erc20NamespaceImpl,
|
|
10
|
+
HttpError,
|
|
18
11
|
NotAuthenticatedError,
|
|
19
12
|
OAuthSession,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
OndoNamespaceImpl,
|
|
14
|
+
PUBLIC_API_BASE_URL,
|
|
15
|
+
RequirementsNamespaceImpl,
|
|
16
|
+
SuperstateSwapNamespaceImpl,
|
|
17
|
+
TokensNamespaceImpl,
|
|
18
|
+
WalletsNamespaceImpl,
|
|
19
|
+
fetchOfferDetails,
|
|
20
|
+
fetchOfferRequirements,
|
|
21
|
+
fetchOffers,
|
|
22
|
+
fetchOffersPage
|
|
23
|
+
} from "../chunk-UIIXXLA7.js";
|
|
27
24
|
|
|
28
|
-
// src/server/api/api.
|
|
29
|
-
var
|
|
25
|
+
// src/server/core/api/api-client.ts
|
|
26
|
+
var ApiClient = class {
|
|
30
27
|
constructor(config, fetchAccessToken) {
|
|
31
28
|
this.client = new AuthenticatedApiClient(config, fetchAccessToken);
|
|
32
29
|
}
|
|
@@ -43,48 +40,26 @@ var WritableSessionStoreRequiredError = class extends Error {
|
|
|
43
40
|
}
|
|
44
41
|
};
|
|
45
42
|
|
|
46
|
-
// src/server/
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
xApiVersion: API_VERSION
|
|
58
|
-
},
|
|
59
|
-
// When refresh=true the renewal middleware has received a 401 and wants a
|
|
60
|
-
// fresh token. A read-only store cannot persist a new session, so return
|
|
61
|
-
// null immediately — this tells the middleware to skip the retry rather
|
|
62
|
-
// than re-sending with the same expired token and wasting a round-trip.
|
|
63
|
-
(refresh) => refresh && !this._config.sessionStore.setSession ? Promise.resolve(null) : this.accessToken()
|
|
64
|
-
);
|
|
65
|
-
const ctx = {
|
|
66
|
-
api: this.api,
|
|
67
|
-
ensureUserAuthenticated: () => this.ensureUserAuthenticated()
|
|
68
|
-
};
|
|
69
|
-
this.erc20 = new Erc20NamespaceImpl(ctx);
|
|
70
|
-
this.tokenSale = new TokenSaleNamespaceImpl(ctx);
|
|
71
|
-
this.swap = new SwapNamespaceImpl(ctx);
|
|
72
|
-
}
|
|
73
|
-
async completeOAuth(code, codeVerifier) {
|
|
74
|
-
const sessionStore = this._config.sessionStore;
|
|
75
|
-
const setSession = sessionStore.setSession?.bind(sessionStore);
|
|
76
|
-
if (!setSession) {
|
|
77
|
-
throw new WritableSessionStoreRequiredError();
|
|
78
|
-
}
|
|
43
|
+
// src/server/core/server-auth-namespace.ts
|
|
44
|
+
var ServerAuthNamespaceImpl = class {
|
|
45
|
+
constructor(api, config) {
|
|
46
|
+
this.api = api;
|
|
47
|
+
this.config = config;
|
|
48
|
+
}
|
|
49
|
+
async completeOAuth({
|
|
50
|
+
code,
|
|
51
|
+
codeVerifier
|
|
52
|
+
}) {
|
|
53
|
+
const setSession = this.writableSessionStore();
|
|
79
54
|
const sessionDto = await this.api.send({
|
|
80
55
|
method: "POST",
|
|
81
56
|
url: `/oauth/token`,
|
|
82
57
|
body: {
|
|
83
58
|
grant_type: "authorization_code",
|
|
84
59
|
code,
|
|
85
|
-
redirect_uri: this.
|
|
86
|
-
client_id: this.
|
|
87
|
-
client_secret: this.
|
|
60
|
+
redirect_uri: this.config.redirectUri,
|
|
61
|
+
client_id: this.config.clientId,
|
|
62
|
+
client_secret: this.config.clientSecret,
|
|
88
63
|
code_verifier: codeVerifier
|
|
89
64
|
}
|
|
90
65
|
});
|
|
@@ -92,35 +67,21 @@ var CoinListServerImpl = class {
|
|
|
92
67
|
await setSession(session);
|
|
93
68
|
return session;
|
|
94
69
|
}
|
|
95
|
-
async
|
|
96
|
-
const
|
|
97
|
-
method: "POST",
|
|
98
|
-
url: `/oauth/token`,
|
|
99
|
-
body: {
|
|
100
|
-
grant_type: "client_credentials",
|
|
101
|
-
client_id: this._config.clientId,
|
|
102
|
-
client_secret: this._config.clientSecret
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
const session = OAuthSession.fromDto(sessionDto);
|
|
106
|
-
return ClientCredentialsOAuth(session.accessToken);
|
|
107
|
-
}
|
|
108
|
-
async accessToken() {
|
|
109
|
-
const sessionStore = this._config.sessionStore;
|
|
70
|
+
async getAccessToken() {
|
|
71
|
+
const sessionStore = this.config.sessionStore;
|
|
110
72
|
const session = await sessionStore.getSession();
|
|
111
73
|
if (session == null) return null;
|
|
112
74
|
const now = Date.now();
|
|
113
75
|
const expiresAt = session.accessToken.expiresAt.getTime();
|
|
114
|
-
const bufferMs = this.accessTokenExpiryBufferSeconds * 1e3;
|
|
76
|
+
const bufferMs = this.config.accessTokenExpiryBufferSeconds * 1e3;
|
|
115
77
|
if (expiresAt > now + bufferMs) {
|
|
116
78
|
return session.accessToken;
|
|
117
79
|
}
|
|
118
80
|
const setSession = sessionStore.setSession?.bind(sessionStore);
|
|
119
81
|
if (!setSession) {
|
|
120
82
|
return session.accessToken;
|
|
121
|
-
} else {
|
|
122
|
-
return this.refreshSession(session.refreshToken, setSession);
|
|
123
83
|
}
|
|
84
|
+
return this.refreshSession(session.refreshToken, setSession);
|
|
124
85
|
}
|
|
125
86
|
async refreshSession(refreshToken, setSession) {
|
|
126
87
|
if (!refreshToken) {
|
|
@@ -134,8 +95,8 @@ var CoinListServerImpl = class {
|
|
|
134
95
|
body: {
|
|
135
96
|
grant_type: "refresh_token",
|
|
136
97
|
refresh_token: refreshToken,
|
|
137
|
-
client_id: this.
|
|
138
|
-
client_secret: this.
|
|
98
|
+
client_id: this.config.clientId,
|
|
99
|
+
client_secret: this.config.clientSecret
|
|
139
100
|
}
|
|
140
101
|
});
|
|
141
102
|
const newSession = OAuthSession.fromDto(sessionDto);
|
|
@@ -146,109 +107,145 @@ var CoinListServerImpl = class {
|
|
|
146
107
|
return null;
|
|
147
108
|
}
|
|
148
109
|
}
|
|
110
|
+
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
|
+
}
|
|
119
|
+
});
|
|
120
|
+
const session = OAuthSession.fromDto(sessionDto);
|
|
121
|
+
return ClientCredentialsOAuth(session.accessToken);
|
|
122
|
+
}
|
|
149
123
|
async logout() {
|
|
150
|
-
const
|
|
124
|
+
const setSession = this.writableSessionStore();
|
|
125
|
+
const session = await this.config.sessionStore.getSession();
|
|
126
|
+
if (session == null) return;
|
|
127
|
+
try {
|
|
128
|
+
await this.api.send({
|
|
129
|
+
method: "POST",
|
|
130
|
+
url: `/oauth/revoke`,
|
|
131
|
+
body: {
|
|
132
|
+
token: session.accessToken.value,
|
|
133
|
+
client_id: this.config.clientId,
|
|
134
|
+
client_secret: this.config.clientSecret
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
} catch (err) {
|
|
138
|
+
if (!(err instanceof HttpError) || this.config.strict) {
|
|
139
|
+
throw err;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
await setSession(null);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns the store's `setSession`, or throws — the guard every
|
|
146
|
+
* session-writing operation shares.
|
|
147
|
+
*/
|
|
148
|
+
writableSessionStore() {
|
|
149
|
+
const sessionStore = this.config.sessionStore;
|
|
151
150
|
const setSession = sessionStore.setSession?.bind(sessionStore);
|
|
152
151
|
if (!setSession) {
|
|
153
152
|
throw new WritableSessionStoreRequiredError();
|
|
154
153
|
}
|
|
155
|
-
|
|
156
|
-
if (session != null) {
|
|
157
|
-
const tokenToRevoke = session.accessToken.value;
|
|
158
|
-
try {
|
|
159
|
-
await this.api.send({
|
|
160
|
-
method: "POST",
|
|
161
|
-
url: `/oauth/revoke`,
|
|
162
|
-
body: {
|
|
163
|
-
token: tokenToRevoke,
|
|
164
|
-
client_id: this._config.clientId,
|
|
165
|
-
client_secret: this._config.clientSecret
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
} catch (err) {
|
|
169
|
-
if (err instanceof HttpError) {
|
|
170
|
-
if (this.strict) {
|
|
171
|
-
throw err;
|
|
172
|
-
}
|
|
173
|
-
} else {
|
|
174
|
-
throw err;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
await setSession(null);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
async fetchOffers(clientCreds) {
|
|
181
|
-
await this.ensureAuthenticated(clientCreds);
|
|
182
|
-
return fetchOffers(this.api, clientCreds);
|
|
154
|
+
return setSession;
|
|
183
155
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return fetchOfferDetails(this.api, id, clientCreds);
|
|
191
|
-
}
|
|
192
|
-
async createWalletOwnershipChallenge(params) {
|
|
193
|
-
await this.ensureUserAuthenticated();
|
|
194
|
-
return createWalletOwnershipChallenge(this.api, params);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/server/core/server-offers-namespace.ts
|
|
159
|
+
var ServerOffersNamespaceImpl = class {
|
|
160
|
+
constructor(ctx) {
|
|
161
|
+
this.ctx = ctx;
|
|
195
162
|
}
|
|
196
|
-
async
|
|
197
|
-
await this.
|
|
198
|
-
return
|
|
163
|
+
async list(clientCreds) {
|
|
164
|
+
await this.ctx.ensureAuthenticated(clientCreds);
|
|
165
|
+
return fetchOffers(this.ctx.api, clientCreds);
|
|
199
166
|
}
|
|
200
|
-
async
|
|
201
|
-
await this.
|
|
202
|
-
return
|
|
203
|
-
this.api,
|
|
204
|
-
offerId,
|
|
205
|
-
offerOptionId
|
|
206
|
-
);
|
|
167
|
+
async listPage(params, clientCreds) {
|
|
168
|
+
await this.ctx.ensureAuthenticated(clientCreds);
|
|
169
|
+
return fetchOffersPage(this.ctx.api, params, clientCreds);
|
|
207
170
|
}
|
|
208
|
-
async
|
|
209
|
-
await this.
|
|
210
|
-
return
|
|
171
|
+
async get(id, clientCreds) {
|
|
172
|
+
await this.ctx.ensureAuthenticated(clientCreds);
|
|
173
|
+
return fetchOfferDetails(this.ctx.api, id, clientCreds);
|
|
211
174
|
}
|
|
212
|
-
|
|
213
|
-
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// src/server/core/server-requirements-namespace.ts
|
|
178
|
+
var ServerRequirementsNamespaceImpl = class extends RequirementsNamespaceImpl {
|
|
179
|
+
constructor(serverCtx) {
|
|
180
|
+
super(serverCtx);
|
|
181
|
+
this.serverCtx = serverCtx;
|
|
182
|
+
}
|
|
183
|
+
async forOffer(offerId, clientCreds) {
|
|
184
|
+
await this.serverCtx.ensureAuthenticated(clientCreds);
|
|
214
185
|
return fetchOfferRequirements(
|
|
215
|
-
this.api,
|
|
186
|
+
this.serverCtx.api,
|
|
216
187
|
offerId,
|
|
217
188
|
clientCreds
|
|
218
189
|
);
|
|
219
190
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// src/server/core/coinlist-server.ts
|
|
194
|
+
var ACCESS_TOKEN_EXPIRY_BUFFER_SECONDS = 60;
|
|
195
|
+
var CoinListServerImpl = class {
|
|
196
|
+
constructor(_config) {
|
|
197
|
+
this._config = _config;
|
|
198
|
+
this.api = new ApiClient(
|
|
199
|
+
{
|
|
200
|
+
baseUrl: _config.baseUrl ?? PUBLIC_API_BASE_URL,
|
|
201
|
+
xApiVersion: API_VERSION
|
|
202
|
+
},
|
|
203
|
+
// When refresh=true the renewal middleware has received a 401 and wants a
|
|
204
|
+
// fresh token. A read-only store cannot persist a new session, so return
|
|
205
|
+
// null immediately — this tells the middleware to skip the retry rather
|
|
206
|
+
// 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()
|
|
208
|
+
);
|
|
209
|
+
this.auth = new ServerAuthNamespaceImpl(this.api, {
|
|
210
|
+
..._config,
|
|
211
|
+
accessTokenExpiryBufferSeconds: _config.accessTokenExpiryBufferSeconds ?? ACCESS_TOKEN_EXPIRY_BUFFER_SECONDS,
|
|
212
|
+
strict: _config.strict ?? false
|
|
213
|
+
});
|
|
214
|
+
const ctx = {
|
|
215
|
+
api: this.api,
|
|
216
|
+
ensureUserAuthenticated: () => this.ensureAuthenticated(void 0),
|
|
217
|
+
ensureAuthenticated: (clientCreds) => this.ensureAuthenticated(clientCreds)
|
|
218
|
+
};
|
|
219
|
+
this.offers = new ServerOffersNamespaceImpl(ctx);
|
|
220
|
+
this.requirements = new ServerRequirementsNamespaceImpl(ctx);
|
|
221
|
+
this.wallets = new WalletsNamespaceImpl(ctx);
|
|
222
|
+
this.erc20 = new Erc20NamespaceImpl(ctx);
|
|
223
|
+
this.tokenSale = new CoinListTokenSaleNamespaceImpl(ctx);
|
|
224
|
+
this.superstate = new SuperstateSwapNamespaceImpl(ctx);
|
|
225
|
+
this.ondo = new OndoNamespaceImpl(ctx);
|
|
226
|
+
this.tokens = new TokensNamespaceImpl(
|
|
227
|
+
_config.tokensBaseUrl ?? NABU_BASE_URL
|
|
228
|
+
);
|
|
223
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* An app-level token authenticates a request on its own; without one the
|
|
232
|
+
* caller needs a user session.
|
|
233
|
+
*/
|
|
224
234
|
async ensureAuthenticated(clientCreds) {
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
async ensureUserAuthenticated() {
|
|
230
|
-
const token = await this.accessToken();
|
|
235
|
+
if (clientCreds) return;
|
|
236
|
+
const token = await this.auth.getAccessToken();
|
|
231
237
|
if (token === null) {
|
|
232
238
|
throw new NotAuthenticatedError();
|
|
233
239
|
}
|
|
234
240
|
}
|
|
235
|
-
async fetchPii() {
|
|
236
|
-
await this.ensureUserAuthenticated();
|
|
237
|
-
return fetchPii(this.api);
|
|
238
|
-
}
|
|
239
|
-
async submitDocument(documentType, fields) {
|
|
240
|
-
await this.ensureUserAuthenticated();
|
|
241
|
-
return submitDocument(this.api, documentType, fields);
|
|
242
|
-
}
|
|
243
|
-
async createKycToken(levelName, reset) {
|
|
244
|
-
await this.ensureUserAuthenticated();
|
|
245
|
-
return createKycToken(this.api, levelName, reset);
|
|
246
|
-
}
|
|
247
241
|
};
|
|
248
242
|
function createCoinListServer(config) {
|
|
249
243
|
return new CoinListServerImpl(config);
|
|
250
244
|
}
|
|
251
245
|
export {
|
|
246
|
+
ServerAuthNamespaceImpl,
|
|
247
|
+
ServerOffersNamespaceImpl,
|
|
248
|
+
ServerRequirementsNamespaceImpl,
|
|
252
249
|
WritableSessionStoreRequiredError,
|
|
253
250
|
createCoinListServer
|
|
254
251
|
};
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/server/api/api.server.ts","../../src/server/errors.ts","../../src/server/coinlist.server.ts"],"sourcesContent":["import { AuthenticatedApiClient } from '@/shared/api/authenticated-api-client';\nimport type { HttpClientConfig, HttpRequest } from '@/shared/api/http';\nimport type { OAuthAccessToken } from '@/shared/types/oauth-session';\n\nexport class Api {\n private readonly client: AuthenticatedApiClient;\n\n constructor(\n config: HttpClientConfig,\n fetchAccessToken: (refresh: boolean) => Promise<OAuthAccessToken | null>\n ) {\n this.client = new AuthenticatedApiClient(config, fetchAccessToken);\n }\n\n async send<TResponse>(request: HttpRequest): Promise<TResponse> {\n return this.client.send<TResponse>(request);\n }\n}\n","export class WritableSessionStoreRequiredError extends Error {\n constructor(\n message = 'This operation requires a writable SessionStore. Provide a `setSession` implementation in your SessionStore to persist or clear OAuth sessions.'\n ) {\n super(message);\n this.name = 'WritableSessionStoreRequiredError';\n }\n}\n","import { Api } from '@/server/api/api.server';\nimport { WritableSessionStoreRequiredError } from '@/server/errors';\nimport {\n API_VERSION,\n PUBLIC_API_BASE_URL,\n} from '@/shared/api/frontline/config';\nimport * as documentsApi from '@/shared/api/frontline/documents';\nimport * as kycApi from '@/shared/api/frontline/kyc';\nimport * as offersApi from '@/shared/api/frontline/offers';\nimport * as piiApi from '@/shared/api/frontline/pii';\nimport * as requirementsApi from '@/shared/api/frontline/requirements';\nimport * as walletConnectApi from '@/shared/api/frontline/wallet-connect';\nimport { HttpError } from '@/shared/api/http';\nimport type {\n PaginatedResponse,\n PaginationParams,\n} from '@/shared/api/pagination';\nimport {\n type CoinListErc20Namespace,\n Erc20NamespaceImpl,\n} from '@/shared/core/erc20-namespace';\nimport {\n type CoinListSwapNamespace,\n SwapNamespaceImpl,\n} from '@/shared/core/swap-namespace';\nimport {\n type CoinListTokenSaleNamespace,\n TokenSaleNamespaceImpl,\n} from '@/shared/core/token-sale-namespace';\nimport type { Config } from '@/shared/types/config';\nimport type {\n DocumentSubmission,\n DocumentType,\n} from '@/shared/types/document-submission';\nimport type { OAuthSessionDto } from '@/shared/types/dto/oauth-session';\nimport { NotAuthenticatedError } from '@/shared/types/errors';\nimport type { KycLevelName, KycToken } from '@/shared/types/kyc';\nimport type {\n AuthorizationCode,\n ClientSecret,\n CodeVerifier,\n} from '@/shared/types/oauth';\nimport {\n ClientCredentialsOAuth,\n type OAuthAccessToken,\n type OAuthRefreshToken,\n OAuthSession,\n} from '@/shared/types/oauth-session';\nimport type { Offer, OfferId } from '@/shared/types/offer';\nimport type { OfferDetail, OfferOptionId } from '@/shared/types/offer-detail';\nimport type {\n ConnectExternalWalletParams,\n OfferOptionAddress,\n OfferOptionAddressId,\n} from '@/shared/types/offer-option-address';\nimport type { Pii } from '@/shared/types/pii';\nimport type {\n Requirement,\n RequirementStatusInfo,\n} from '@/shared/types/requirement';\nimport type {\n CreateWalletOwnershipChallengeParams,\n WalletOwnershipChallenge,\n} from '@/shared/types/wallet-ownership-challenge';\n\n/** Buffer in seconds before expiry to consider token expired for refresh. */\nconst ACCESS_TOKEN_EXPIRY_BUFFER_SECONDS = 60;\n\nexport interface SessionStore {\n getSession(): Promise<OAuthSession | null>;\n /**\n * Persists or clears the OAuth session.\n *\n * **Omit this method to create a read-only store.** When absent, the SDK\n * skips token refresh entirely — no network call is made and no refresh\n * token is consumed. This is the correct approach for contexts that can read\n * the session but cannot write it back, such as Next.js Server Components.\n *\n * ⚠️ Do **not** implement this as a no-op (`async () => {}`). If the method\n * is present, the SDK assumes writes succeed: it will fire a token refresh\n * network call, consume the refresh token, then invoke `setSession` — which\n * would silently discard the new session and leave the browser holding an\n * invalidated refresh token. Simply **omit** `setSession` to prevent any\n * refresh from being attempted.\n *\n * {@link CoinListServer.completeOAuth} and {@link CoinListServer.logout}\n * always require a writable store and throw\n * {@link WritableSessionStoreRequiredError} if `setSession` is absent.\n */\n setSession?(session: OAuthSession | null): Promise<void>;\n}\n\nexport interface ServerConfig extends Config {\n readonly clientSecret: ClientSecret;\n readonly sessionStore: SessionStore;\n /** Buffer in seconds before expiry to consider token expired for refresh. */\n readonly accessTokenExpiryBufferSeconds?: number;\n /**\n * Whether SDK will throw an exception in cases it can be silent.\n * For example, if token revokation on logout fails.\n */\n readonly strict?: boolean;\n}\n\n/**\n * Server-side CoinList SDK client.\n *\n * Operates in one of two modes depending on whether {@link SessionStore}\n * includes a `setSession` implementation:\n *\n * - **Writable store** (`setSession` provided) — full functionality: token\n * refresh, {@link completeOAuth}, and {@link logout} all work normally.\n *\n * - **Read-only store** (no `setSession`) — token refresh is skipped entirely,\n * meaning no network call is made and no refresh token is consumed.\n * {@link completeOAuth} and {@link logout} throw\n * {@link WritableSessionStoreRequiredError}. {@link accessToken} may return\n * an expired token (see its docs). Use this mode in execution contexts that\n * can read the session but cannot write it back, such as Next.js Server\n * Components.\n */\nexport interface CoinListServer {\n /**\n * Exchanges an authorization code for an OAuth session and persists it via\n * {@link SessionStore.setSession}.\n *\n * Throws {@link WritableSessionStoreRequiredError} if the session store does\n * not provide `setSession`.\n */\n completeOAuth(\n code: AuthorizationCode,\n codeVerifier: CodeVerifier\n ): Promise<OAuthSession>;\n\n /**\n * Obtains an app-level access token via the OAuth 2.0 `client_credentials`\n * grant (RFC 6749 §4.4). No user is involved: the token authenticates the\n * partner application itself and only grants access to app-level resources\n * such as offers and offer requirements.\n *\n * The token is **not** persisted to the {@link SessionStore} and has no\n * refresh token. It expires at `expiresAt`; once expired, call this method\n * again to obtain a fresh token — the SDK does not renew it automatically.\n *\n * Pass the result to {@link fetchOffers}, {@link fetchOffersPage},\n * {@link fetchOfferDetails}, or {@link fetchOfferRequirements} to call them\n * without a user session.\n */\n clientCredentialsOAuth(): Promise<ClientCredentialsOAuth>;\n\n /**\n * Returns a valid access token for the current session, refreshing it if\n * it is expired or near expiry.\n *\n * **Writable store**: if the token is expired, the SDK exchanges the refresh\n * token for a new session, persists it, and returns the fresh access token.\n * Returns `null` if there is no session or the refresh fails.\n *\n * **Read-only store** (no `setSession`): refresh is skipped entirely. The\n * stored token is returned as-is, even if it is expired — a non-null return\n * value does **not** guarantee the token is accepted by the API. Before\n * making API calls, check `token.expiresAt > new Date()`. Use a writable\n * store (e.g. in a Route Handler) when you need the SDK to renew the session\n * automatically.\n *\n * @returns the access token, or `null` if there is no session or the session\n * could not be refreshed.\n */\n accessToken(): Promise<OAuthAccessToken | null>;\n\n /**\n * Revokes the current token via POST /oauth/revoke and clears the session.\n *\n * Throws {@link WritableSessionStoreRequiredError} if the session store does\n * not provide `setSession`.\n */\n logout(): Promise<void>;\n\n /**\n * Fetches all offers by iterating through every paginated response.\n *\n * @param clientCreds optional app-level token from\n * {@link clientCredentialsOAuth}. When provided, no user session is\n * required; if a user session exists it takes precedence and `clientCreds`\n * is used as a fallback.\n *\n * Throws {@link NotAuthenticatedError} if there is neither a user session\n * nor `clientCreds`.\n */\n fetchOffers(clientCreds?: ClientCredentialsOAuth): Promise<Offer[]>;\n\n /**\n * Fetches a single page of offers.\n *\n * @param clientCreds optional app-level token from\n * {@link clientCredentialsOAuth}. When provided, no user session is\n * required; if a user session exists it takes precedence and `clientCreds`\n * is used as a fallback.\n *\n * Throws {@link NotAuthenticatedError} if there is neither a user session\n * nor `clientCreds`.\n */\n fetchOffersPage(\n params: PaginationParams,\n clientCreds?: ClientCredentialsOAuth\n ): Promise<PaginatedResponse<Offer>>;\n\n /**\n * Fetches details for a given offer by its id.\n *\n * @param clientCreds optional app-level token from\n * {@link clientCredentialsOAuth}. When provided, no user session is\n * required; if a user session exists it takes precedence and `clientCreds`\n * is used as a fallback.\n *\n * Throws {@link NotAuthenticatedError} if there is neither a user session\n * nor `clientCreds`.\n */\n fetchOfferDetails(\n id: OfferId,\n clientCreds?: ClientCredentialsOAuth\n ): Promise<OfferDetail>;\n\n /**\n * Creates a single-use wallet-ownership challenge for the given wallet and\n * chain. The user signs the returned {@link WalletOwnershipChallenge.message}\n * with their wallet, then passes the signature to\n * {@link connectExternalWallet}.\n *\n * Throws {@link NotAuthenticatedError} if the user is not authenticated.\n */\n createWalletOwnershipChallenge(\n params: CreateWalletOwnershipChallengeParams\n ): Promise<WalletOwnershipChallenge>;\n\n /**\n * Connects a proven external wallet to an offer option, using a signature of\n * a challenge from {@link createWalletOwnershipChallenge}.\n *\n * Throws {@link NotAuthenticatedError} if the user is not authenticated.\n */\n connectExternalWallet(\n offerId: OfferId,\n params: ConnectExternalWalletParams\n ): Promise<OfferOptionAddress>;\n\n /**\n * Lists the user's proven wallet bindings for a single offer option.\n *\n * Throws {@link NotAuthenticatedError} if the user is not authenticated.\n */\n listOptionAddresses(\n offerId: OfferId,\n offerOptionId: OfferOptionId\n ): Promise<OfferOptionAddress[]>;\n\n /**\n * Removes one of the user's wallet bindings and returns the removed binding.\n *\n * Throws {@link NotAuthenticatedError} if the user is not authenticated.\n */\n removeOptionAddress(\n offerId: OfferId,\n addressId: OfferOptionAddressId\n ): Promise<OfferOptionAddress>;\n\n /**\n * Fetches the requirements for all options of a given offer, grouped by option ID.\n *\n * @param clientCreds optional app-level token from\n * {@link clientCredentialsOAuth}. When provided, no user session is\n * required; if a user session exists it takes precedence and `clientCreds`\n * is used as a fallback.\n *\n * Throws {@link NotAuthenticatedError} if there is neither a user session\n * nor `clientCreds`.\n */\n fetchOfferRequirements(\n offerId: OfferId,\n clientCreds?: ClientCredentialsOAuth\n ): Promise<Record<OfferOptionId, Requirement[]>>;\n\n /**\n * Fetches the user's requirement statuses for a given offer.\n *\n * Throws {@link NotAuthenticatedError} if the user is not authenticated.\n */\n fetchRequirementStatuses(offerId: OfferId): Promise<RequirementStatusInfo[]>;\n\n /**\n * Fetches the user's PII (tax form pre-fill data) — full legal name, date\n * of birth, jurisdiction, tax ID, and permanent address for an individual;\n * or the equivalent entity fields for a company/trust, used to pre-fill a\n * W-8BEN. Fields the entity hasn't provided are `null`.\n *\n * Throws {@link NotAuthenticatedError} if the user is not authenticated.\n */\n fetchPii(): Promise<Pii>;\n\n /**\n * Starts (or resumes) a document signing submission for the given type\n * (currently only `tax_certification`, e.g. W-8BEN/W-8BEN-E). `fields` are\n * signing-form values keyed by the document's DocuSeal field names,\n * forwarded verbatim to Passport to pre-fill the document.\n *\n * Throws {@link NotAuthenticatedError} if the user is not authenticated.\n */\n submitDocument(\n documentType: DocumentType,\n fields: Record<string, string>\n ): Promise<DocumentSubmission>;\n\n /**\n * Generic ERC-20 reads (token allowance and balance) — e.g.\n * `coinlist.erc20.getTokenBalance({ ... })`.\n *\n * These methods require a user session and throw\n * {@link NotAuthenticatedError} if the user is not authenticated.\n */\n readonly erc20: CoinListErc20Namespace;\n\n /**\n * Token-sale operations: listing, reading, and recording participations —\n * e.g. `coinlist.tokenSale.fetchParticipations()`. The on-chain\n * `executeTokenSale` flow is client-only and is not exposed here.\n *\n * These methods require a user session and throw\n * {@link NotAuthenticatedError} if the user is not authenticated.\n */\n readonly tokenSale: CoinListTokenSaleNamespace;\n\n /**\n * On-chain swap operations: quoting a swap, reading swap-contract state, and\n * proving/allow-listing wallet ownership — e.g.\n * `coinlist.swap.getOutputToken({ contractAddress, chain })`.\n *\n * These methods require a user session and throw\n * {@link NotAuthenticatedError} if the user is not authenticated.\n */\n readonly swap: CoinListSwapNamespace;\n\n /**\n * Creates a short-lived Sumsub WebSDK access token for the current user so\n * an identity verification (KYC) flow can be started, e.g. to seed the\n * client-side `IdentityVerification` component when server-rendering.\n * `levelName` selects the Sumsub verification level; defaults to the\n * backend's standard level. `reset` resets the Sumsub applicant first, so\n * an already-approved level can be executed again (e.g. to update stale\n * PII).\n *\n * Throws {@link NotAuthenticatedError} if the user is not authenticated.\n */\n createKycToken(levelName?: KycLevelName, reset?: boolean): Promise<KycToken>;\n}\n\nclass CoinListServerImpl implements CoinListServer {\n private readonly api: Api;\n private readonly baseUrl: string;\n\n private readonly accessTokenExpiryBufferSeconds: number;\n private readonly strict: boolean;\n readonly erc20: CoinListErc20Namespace;\n readonly tokenSale: CoinListTokenSaleNamespace;\n readonly swap: CoinListSwapNamespace;\n\n constructor(private readonly _config: ServerConfig) {\n this.baseUrl = _config.baseUrl ?? PUBLIC_API_BASE_URL;\n this.accessTokenExpiryBufferSeconds =\n _config.accessTokenExpiryBufferSeconds ??\n ACCESS_TOKEN_EXPIRY_BUFFER_SECONDS;\n this.strict = _config.strict ?? false;\n this.api = new Api(\n {\n baseUrl: this.baseUrl,\n xApiVersion: API_VERSION,\n },\n // When refresh=true the renewal middleware has received a 401 and wants a\n // fresh token. A read-only store cannot persist a new session, so return\n // null immediately — this tells the middleware to skip the retry rather\n // than re-sending with the same expired token and wasting a round-trip.\n (refresh) =>\n refresh && !this._config.sessionStore.setSession\n ? Promise.resolve(null)\n : this.accessToken()\n );\n const ctx = {\n api: this.api,\n ensureUserAuthenticated: () => this.ensureUserAuthenticated(),\n };\n this.erc20 = new Erc20NamespaceImpl(ctx);\n this.tokenSale = new TokenSaleNamespaceImpl(ctx);\n this.swap = new SwapNamespaceImpl(ctx);\n }\n\n async completeOAuth(\n code: AuthorizationCode,\n codeVerifier: CodeVerifier\n ): Promise<OAuthSession> {\n const sessionStore = this._config.sessionStore;\n const setSession = sessionStore.setSession?.bind(sessionStore);\n if (!setSession) {\n throw new WritableSessionStoreRequiredError();\n }\n const sessionDto = await this.api.send<OAuthSessionDto>({\n method: 'POST',\n url: `/oauth/token`,\n body: {\n grant_type: 'authorization_code',\n code,\n redirect_uri: this._config.redirectUri,\n client_id: this._config.clientId,\n client_secret: this._config.clientSecret,\n code_verifier: codeVerifier,\n },\n });\n const session = OAuthSession.fromDto(sessionDto);\n await setSession(session);\n return session;\n }\n\n async clientCredentialsOAuth(): Promise<ClientCredentialsOAuth> {\n const sessionDto = await this.api.send<OAuthSessionDto>({\n method: 'POST',\n url: `/oauth/token`,\n body: {\n grant_type: 'client_credentials',\n client_id: this._config.clientId,\n client_secret: this._config.clientSecret,\n },\n });\n const session = OAuthSession.fromDto(sessionDto);\n return ClientCredentialsOAuth(session.accessToken);\n }\n\n async accessToken(): Promise<OAuthAccessToken | null> {\n const sessionStore = this._config.sessionStore;\n const session = await sessionStore.getSession();\n if (session == null) return null;\n\n const now = Date.now();\n const expiresAt = session.accessToken.expiresAt.getTime();\n const bufferMs = this.accessTokenExpiryBufferSeconds * 1000;\n if (expiresAt > now + bufferMs) {\n // Valid access token, return it regardless\n return session.accessToken;\n }\n\n const setSession = sessionStore.setSession?.bind(sessionStore);\n if (!setSession) {\n // No write session capabilities => can't refresh!\n // Return the access token as-is\n return session.accessToken;\n } else {\n return this.refreshSession(session.refreshToken, setSession);\n }\n }\n\n private async refreshSession(\n refreshToken: OAuthRefreshToken | undefined,\n setSession: (session: OAuthSession | null) => Promise<void>\n ): Promise<OAuthAccessToken | null> {\n if (!refreshToken) {\n await setSession(null);\n return null;\n }\n\n try {\n const sessionDto = await this.api.send<OAuthSessionDto>({\n method: 'POST',\n url: `/oauth/token`,\n body: {\n grant_type: 'refresh_token',\n refresh_token: refreshToken,\n client_id: this._config.clientId,\n client_secret: this._config.clientSecret,\n },\n });\n const newSession = OAuthSession.fromDto(sessionDto);\n await setSession(newSession);\n return newSession.accessToken;\n } catch {\n await setSession(null);\n return null;\n }\n }\n\n async logout(): Promise<void> {\n const sessionStore = this._config.sessionStore;\n const setSession = sessionStore.setSession?.bind(sessionStore);\n if (!setSession) {\n throw new WritableSessionStoreRequiredError();\n }\n const session = await sessionStore.getSession();\n if (session != null) {\n const tokenToRevoke = session.accessToken.value;\n try {\n await this.api.send({\n method: 'POST',\n url: `/oauth/revoke`,\n body: {\n token: tokenToRevoke,\n client_id: this._config.clientId,\n client_secret: this._config.clientSecret,\n },\n });\n } catch (err) {\n if (err instanceof HttpError) {\n if (this.strict) {\n throw err;\n }\n } else {\n throw err;\n }\n }\n // invalidate the session\n await setSession(null);\n }\n }\n\n async fetchOffers(clientCreds?: ClientCredentialsOAuth): Promise<Offer[]> {\n await this.ensureAuthenticated(clientCreds);\n return offersApi.fetchOffers(this.api, clientCreds);\n }\n\n async fetchOffersPage(\n params: PaginationParams,\n clientCreds?: ClientCredentialsOAuth\n ): Promise<PaginatedResponse<Offer>> {\n await this.ensureAuthenticated(clientCreds);\n return offersApi.fetchOffersPage(this.api, params, clientCreds);\n }\n\n async fetchOfferDetails(\n id: OfferId,\n clientCreds?: ClientCredentialsOAuth\n ): Promise<OfferDetail> {\n await this.ensureAuthenticated(clientCreds);\n return offersApi.fetchOfferDetails(this.api, id, clientCreds);\n }\n\n async createWalletOwnershipChallenge(\n params: CreateWalletOwnershipChallengeParams\n ): Promise<WalletOwnershipChallenge> {\n await this.ensureUserAuthenticated();\n return walletConnectApi.createWalletOwnershipChallenge(this.api, params);\n }\n\n async connectExternalWallet(\n offerId: OfferId,\n params: ConnectExternalWalletParams\n ): Promise<OfferOptionAddress> {\n await this.ensureUserAuthenticated();\n return walletConnectApi.connectExternalWallet(this.api, offerId, params);\n }\n\n async listOptionAddresses(\n offerId: OfferId,\n offerOptionId: OfferOptionId\n ): Promise<OfferOptionAddress[]> {\n await this.ensureUserAuthenticated();\n return walletConnectApi.listOptionAddresses(\n this.api,\n offerId,\n offerOptionId\n );\n }\n\n async removeOptionAddress(\n offerId: OfferId,\n addressId: OfferOptionAddressId\n ): Promise<OfferOptionAddress> {\n await this.ensureUserAuthenticated();\n return walletConnectApi.removeOptionAddress(this.api, offerId, addressId);\n }\n\n async fetchOfferRequirements(\n offerId: OfferId,\n clientCreds?: ClientCredentialsOAuth\n ): Promise<Record<OfferOptionId, Requirement[]>> {\n await this.ensureAuthenticated(clientCreds);\n return requirementsApi.fetchOfferRequirements(\n this.api,\n offerId,\n clientCreds\n );\n }\n\n async fetchRequirementStatuses(\n offerId: OfferId\n ): Promise<RequirementStatusInfo[]> {\n await this.ensureUserAuthenticated();\n return requirementsApi.fetchRequirementStatuses(this.api, offerId);\n }\n\n private async ensureAuthenticated(\n clientCreds: ClientCredentialsOAuth | undefined\n ): Promise<void> {\n if (!clientCreds) {\n await this.ensureUserAuthenticated();\n }\n }\n\n private async ensureUserAuthenticated(): Promise<void> {\n const token = await this.accessToken();\n if (token === null) {\n throw new NotAuthenticatedError();\n }\n }\n\n async fetchPii(): Promise<Pii> {\n await this.ensureUserAuthenticated();\n return piiApi.fetchPii(this.api);\n }\n\n async submitDocument(\n documentType: DocumentType,\n fields: Record<string, string>\n ): Promise<DocumentSubmission> {\n await this.ensureUserAuthenticated();\n return documentsApi.submitDocument(this.api, documentType, fields);\n }\n\n async createKycToken(\n levelName?: KycLevelName,\n reset?: boolean\n ): Promise<KycToken> {\n await this.ensureUserAuthenticated();\n return kycApi.createKycToken(this.api, levelName, reset);\n }\n}\n\nexport function createCoinListServer(config: ServerConfig): CoinListServer {\n return new CoinListServerImpl(config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,IAAM,MAAN,MAAU;AAAA,EAGf,YACE,QACA,kBACA;AACA,SAAK,SAAS,IAAI,uBAAuB,QAAQ,gBAAgB;AAAA,EACnE;AAAA,EAEA,MAAM,KAAgB,SAA0C;AAC9D,WAAO,KAAK,OAAO,KAAgB,OAAO;AAAA,EAC5C;AACF;;;ACjBO,IAAM,oCAAN,cAAgD,MAAM;AAAA,EAC3D,YACE,UAAU,mJACV;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;AC2DA,IAAM,qCAAqC;AAiS3C,IAAM,qBAAN,MAAmD;AAAA,EAUjD,YAA6B,SAAuB;AAAvB;AAC3B,SAAK,UAAU,QAAQ,WAAW;AAClC,SAAK,iCACH,QAAQ,kCACR;AACF,SAAK,SAAS,QAAQ,UAAU;AAChC,SAAK,MAAM,IAAI;AAAA,MACb;AAAA,QACE,SAAS,KAAK;AAAA,QACd,aAAa;AAAA,MACf;AAAA;AAAA;AAAA;AAAA;AAAA,MAKA,CAAC,YACC,WAAW,CAAC,KAAK,QAAQ,aAAa,aAClC,QAAQ,QAAQ,IAAI,IACpB,KAAK,YAAY;AAAA,IACzB;AACA,UAAM,MAAM;AAAA,MACV,KAAK,KAAK;AAAA,MACV,yBAAyB,MAAM,KAAK,wBAAwB;AAAA,IAC9D;AACA,SAAK,QAAQ,IAAI,mBAAmB,GAAG;AACvC,SAAK,YAAY,IAAI,uBAAuB,GAAG;AAC/C,SAAK,OAAO,IAAI,kB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;AAAA,EACF;AAAA,EAEA,MAAc,0BAAyC;AACrD,UAAM,QAAQ,MAAM,KAAK,YAAY;AACrC,QAAI,UAAU,MAAM;AAClB,YAAM,IAAI,sBAAsB;AAAA,IAClC;AAAA,EACF;AAAA,EAEA,MAAM,WAAyB;AAC7B,UAAM,KAAK,wBAAwB;AACnC,WAAc,SAAS,KAAK,GAAG;AAAA,EACjC;AAAA,EAEA,MAAM,eACJ,cACA,QAC6B;AAC7B,UAAM,KAAK,wBAAwB;AACnC,WAAoB,eAAe,KAAK,KAAK,cAAc,MAAM;AAAA,EACnE;AAAA,EAEA,MAAM,eACJ,WACA,OACmB;AACnB,UAAM,KAAK,wBAAwB;AACnC,WAAc,eAAe,KAAK,KAAK,WAAW,KAAK;AAAA,EACzD;AACF;AAEO,SAAS,qBAAqB,QAAsC;AACzE,SAAO,IAAI,mBAAmB,MAAM;AACtC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/server/core/api/api-client.ts","../../src/server/errors.ts","../../src/server/core/server-auth-namespace.ts","../../src/server/core/server-offers-namespace.ts","../../src/server/core/server-requirements-namespace.ts","../../src/server/core/coinlist-server.ts"],"sourcesContent":["import { AuthenticatedApiClient } from '@/shared/api/authenticated-api-client';\nimport type { HttpClientConfig, HttpRequest } from '@/shared/api/http';\nimport type { OAuthAccessToken } from '@/shared/types/oauth-session';\n\nexport class ApiClient {\n private readonly client: AuthenticatedApiClient;\n\n constructor(\n config: HttpClientConfig,\n fetchAccessToken: (refresh: boolean) => Promise<OAuthAccessToken | null>\n ) {\n this.client = new AuthenticatedApiClient(config, fetchAccessToken);\n }\n\n async send<TResponse>(request: HttpRequest): Promise<TResponse> {\n return this.client.send<TResponse>(request);\n }\n}\n","export class WritableSessionStoreRequiredError extends Error {\n constructor(\n message = 'This operation requires a writable SessionStore. Provide a `setSession` implementation in your SessionStore to persist or clear OAuth sessions.'\n ) {\n super(message);\n this.name = 'WritableSessionStoreRequiredError';\n }\n}\n","import { WritableSessionStoreRequiredError } from '@/server/errors';\nimport { HttpError } from '@/shared/api/http';\nimport type { Sender } from '@/shared/api/http-client';\nimport type { Config } from '@/shared/types/config';\nimport type { OAuthSessionDto } from '@/shared/types/dto/oauth-session';\nimport type {\n AuthorizationCode,\n ClientSecret,\n CodeVerifier,\n} from '@/shared/types/oauth';\nimport {\n ClientCredentialsOAuth,\n type OAuthAccessToken,\n type OAuthRefreshToken,\n OAuthSession,\n} from '@/shared/types/oauth-session';\n\nexport interface SessionStore {\n getSession(): Promise<OAuthSession | null>;\n /**\n * Persists or clears the OAuth session.\n *\n * **Omit this method to create a read-only store.** When absent, the SDK\n * skips token refresh entirely — no network call is made and no refresh\n * token is consumed. This is the correct approach for contexts that can read\n * the session but cannot write it back, such as Next.js Server Components.\n *\n * ⚠️ Do **not** implement this as a no-op (`async () => {}`). If the method\n * is present, the SDK assumes writes succeed: it will fire a token refresh\n * network call, consume the refresh token, then invoke `setSession` — which\n * would silently discard the new session and leave the browser holding an\n * invalidated refresh token. Simply **omit** `setSession` to prevent any\n * refresh from being attempted.\n *\n * {@link ServerAuthNamespace.completeOAuth} and\n * {@link ServerAuthNamespace.logout} always require a writable store and\n * throw {@link WritableSessionStoreRequiredError} if `setSession` is absent.\n */\n setSession?(session: OAuthSession | null): Promise<void>;\n}\n\n/** The PKCE pair `CoinListClient#auth.completeOAuth` hands to the backend. */\nexport interface CompleteOAuthParams {\n /** The short-lived authorization code parsed out of the redirect URL. */\n code: AuthorizationCode;\n /** The `code_verifier` the browser generated when starting the flow. */\n codeVerifier: CodeVerifier;\n}\n\n/**\n * OAuth session lifecycle on your backend: exchanging authorization codes,\n * keeping the access token fresh, minting app-level tokens, and logging out.\n *\n * This namespace is server-only: every method needs the `clientSecret` and the\n * {@link SessionStore}, neither of which may exist in a browser.\n */\nexport interface ServerAuthNamespace {\n /**\n * Exchanges an authorization code from `CoinListClient#auth.completeOAuth`\n * for an OAuth session and persists it via {@link SessionStore.setSession}.\n *\n * Throws {@link WritableSessionStoreRequiredError} if the session store does\n * not provide `setSession`.\n */\n completeOAuth(params: CompleteOAuthParams): Promise<OAuthSession>;\n\n /**\n * Returns a valid access token for the current session, refreshing it if it\n * is expired or near expiry. This is what you serve to\n * {@link ClientConfig.getAccessToken}.\n *\n * **Writable store**: if the token is expired, the SDK exchanges the refresh\n * token for a new session, persists it, and returns the fresh access token.\n * Returns `null` if there is no session or the refresh fails.\n *\n * **Read-only store** (no `setSession`): refresh is skipped entirely. The\n * stored token is returned as-is, even if it is expired — a non-null return\n * value does **not** guarantee the token is accepted by the API. Before\n * making API calls, check `token.expiresAt > new Date()`. Use a writable\n * store (e.g. in a Route Handler) when you need the SDK to renew the session\n * automatically.\n *\n * @returns the access token, or `null` if there is no session or the session\n * could not be refreshed.\n */\n getAccessToken(): Promise<OAuthAccessToken | null>;\n\n /**\n * Obtains an app-level access token via the OAuth 2.0 `client_credentials`\n * grant (RFC 6749 §4.4). No user is involved: the token authenticates the\n * partner application itself and only grants access to app-level resources\n * such as offers and offer requirements.\n *\n * The token is **not** persisted to the {@link SessionStore} and has no\n * refresh token. It expires at `expiresAt`; once expired, call this method\n * again to obtain a fresh token — the SDK does not renew it automatically.\n *\n * Pass the result to `ServerOffersNamespace` or\n * `ServerRequirementsNamespace.forOffer` to read without a user session.\n */\n clientCredentials(): Promise<ClientCredentialsOAuth>;\n\n /**\n * Revokes the current token via `POST /oauth/revoke` and clears the session.\n *\n * Throws {@link WritableSessionStoreRequiredError} if the session store does\n * not provide `setSession`.\n */\n logout(): Promise<void>;\n}\n\n/** What {@link ServerAuthNamespaceImpl} needs out of `ServerConfig`. */\nexport type ServerAuthConfig = Config & {\n readonly clientSecret: ClientSecret;\n readonly sessionStore: SessionStore;\n /** Seconds before expiry at which a token counts as expired for refresh. */\n readonly accessTokenExpiryBufferSeconds: number;\n /** Whether to rethrow errors the SDK could otherwise swallow (e.g. revoke). */\n readonly strict: boolean;\n};\n\nexport class ServerAuthNamespaceImpl implements ServerAuthNamespace {\n constructor(\n private readonly api: Sender,\n private readonly config: ServerAuthConfig\n ) {}\n\n async completeOAuth({\n code,\n codeVerifier,\n }: CompleteOAuthParams): Promise<OAuthSession> {\n const setSession = this.writableSessionStore();\n const sessionDto = await this.api.send<OAuthSessionDto>({\n method: 'POST',\n url: `/oauth/token`,\n body: {\n grant_type: 'authorization_code',\n code,\n redirect_uri: this.config.redirectUri,\n client_id: this.config.clientId,\n client_secret: this.config.clientSecret,\n code_verifier: codeVerifier,\n },\n });\n const session = OAuthSession.fromDto(sessionDto);\n await setSession(session);\n return session;\n }\n\n async getAccessToken(): Promise<OAuthAccessToken | null> {\n const sessionStore = this.config.sessionStore;\n const session = await sessionStore.getSession();\n if (session == null) return null;\n\n const now = Date.now();\n const expiresAt = session.accessToken.expiresAt.getTime();\n const bufferMs = this.config.accessTokenExpiryBufferSeconds * 1000;\n if (expiresAt > now + bufferMs) {\n // Valid access token, return it regardless\n return session.accessToken;\n }\n\n const setSession = sessionStore.setSession?.bind(sessionStore);\n if (!setSession) {\n // No write session capabilities => can't refresh!\n // Return the access token as-is\n return session.accessToken;\n }\n return this.refreshSession(session.refreshToken, setSession);\n }\n\n private async refreshSession(\n refreshToken: OAuthRefreshToken | undefined,\n setSession: (session: OAuthSession | null) => Promise<void>\n ): Promise<OAuthAccessToken | null> {\n if (!refreshToken) {\n await setSession(null);\n return null;\n }\n\n try {\n const sessionDto = await this.api.send<OAuthSessionDto>({\n method: 'POST',\n url: `/oauth/token`,\n body: {\n grant_type: 'refresh_token',\n refresh_token: refreshToken,\n client_id: this.config.clientId,\n client_secret: this.config.clientSecret,\n },\n });\n const newSession = OAuthSession.fromDto(sessionDto);\n await setSession(newSession);\n return newSession.accessToken;\n } catch {\n await setSession(null);\n return null;\n }\n }\n\n async clientCredentials(): Promise<ClientCredentialsOAuth> {\n const sessionDto = await this.api.send<OAuthSessionDto>({\n method: 'POST',\n url: `/oauth/token`,\n body: {\n grant_type: 'client_credentials',\n client_id: this.config.clientId,\n client_secret: this.config.clientSecret,\n },\n });\n const session = OAuthSession.fromDto(sessionDto);\n return ClientCredentialsOAuth(session.accessToken);\n }\n\n async logout(): Promise<void> {\n const setSession = this.writableSessionStore();\n const session = await this.config.sessionStore.getSession();\n if (session == null) return;\n\n try {\n await this.api.send({\n method: 'POST',\n url: `/oauth/revoke`,\n body: {\n token: session.accessToken.value,\n client_id: this.config.clientId,\n client_secret: this.config.clientSecret,\n },\n });\n } catch (err) {\n // A failed revoke still leaves the local session invalid, so only strict\n // callers care; anything that is not an HTTP failure is a real bug.\n if (!(err instanceof HttpError) || this.config.strict) {\n throw err;\n }\n }\n await setSession(null);\n }\n\n /**\n * Returns the store's `setSession`, or throws — the guard every\n * session-writing operation shares.\n */\n private writableSessionStore(): (\n session: OAuthSession | null\n ) => Promise<void> {\n const sessionStore = this.config.sessionStore;\n const setSession = sessionStore.setSession?.bind(sessionStore);\n if (!setSession) {\n throw new WritableSessionStoreRequiredError();\n }\n return setSession;\n }\n}\n","import type { ServerNamespaceContext } from '@/server/core/server-namespace-context';\nimport * as offersApi from '@/shared/api/frontline/offers';\nimport type { OffersNamespace } from '@/shared/core/offers/offers-namespace';\nimport type { ClientCredentialsOAuth } from '@/shared/types/oauth-session';\nimport type { Offer, OfferId } from '@/shared/types/offer';\nimport type { OfferDetail } from '@/shared/types/offer-detail';\nimport type {\n PaginatedResponse,\n PaginationParams,\n} from '@/shared/types/pagination';\n\n/**\n * The server-side offers namespace: the same reads as the shared\n * {@link OffersNamespace}, each additionally callable with an app-level token\n * from `ServerAuthNamespace.clientCredentials` instead of a user session.\n *\n * When a user session exists it takes precedence and `clientCreds` acts as a\n * fallback. Without either, the reads throw {@link NotAuthenticatedError}.\n */\nexport interface ServerOffersNamespace extends OffersNamespace {\n /** @param clientCreds app-level token to read without a user session. */\n list(clientCreds?: ClientCredentialsOAuth): Promise<Offer[]>;\n\n /** @param clientCreds app-level token to read without a user session. */\n listPage(\n params: PaginationParams,\n clientCreds?: ClientCredentialsOAuth\n ): Promise<PaginatedResponse<Offer>>;\n\n /** @param clientCreds app-level token to read without a user session. */\n get(id: OfferId, clientCreds?: ClientCredentialsOAuth): Promise<OfferDetail>;\n}\n\nexport class ServerOffersNamespaceImpl implements ServerOffersNamespace {\n constructor(private readonly ctx: ServerNamespaceContext) {}\n\n async list(clientCreds?: ClientCredentialsOAuth): Promise<Offer[]> {\n await this.ctx.ensureAuthenticated(clientCreds);\n return offersApi.fetchOffers(this.ctx.api, clientCreds);\n }\n\n async listPage(\n params: PaginationParams,\n clientCreds?: ClientCredentialsOAuth\n ): Promise<PaginatedResponse<Offer>> {\n await this.ctx.ensureAuthenticated(clientCreds);\n return offersApi.fetchOffersPage(this.ctx.api, params, clientCreds);\n }\n\n async get(\n id: OfferId,\n clientCreds?: ClientCredentialsOAuth\n ): Promise<OfferDetail> {\n await this.ctx.ensureAuthenticated(clientCreds);\n return offersApi.fetchOfferDetails(this.ctx.api, id, clientCreds);\n }\n}\n","import type { ServerNamespaceContext } from '@/server/core/server-namespace-context';\nimport * as requirementsApi from '@/shared/api/frontline/requirements';\nimport type { SharedNamespaceContext } from '@/shared/core/namespace-context';\nimport {\n type RequirementsNamespace,\n RequirementsNamespaceImpl,\n} from '@/shared/core/requirements/requirements-namespace';\nimport type { ClientCredentialsOAuth } from '@/shared/types/oauth-session';\nimport type { OfferId } from '@/shared/types/offer';\nimport type { OfferOptionId } from '@/shared/types/offer-detail';\nimport type { Requirement } from '@/shared/types/requirement';\n\n/**\n * The server-side requirements namespace: the same surface as the shared\n * {@link RequirementsNamespace}, except {@link forOffer} — the offer's\n * requirement definitions are app-level data, so it is additionally callable\n * with a token from `ServerAuthNamespace.clientCredentials`.\n *\n * Everything else is per-user data and needs a user session. `handle` is\n * client-only: there is no browser tab to open on a server.\n */\nexport interface ServerRequirementsNamespace extends RequirementsNamespace {\n /** @param clientCreds app-level token to read without a user session. */\n forOffer(\n offerId: OfferId,\n clientCreds?: ClientCredentialsOAuth\n ): Promise<Record<OfferOptionId, Requirement[]>>;\n}\n\nexport class ServerRequirementsNamespaceImpl\n extends RequirementsNamespaceImpl\n implements ServerRequirementsNamespace\n{\n constructor(\n private readonly serverCtx: SharedNamespaceContext & ServerNamespaceContext\n ) {\n super(serverCtx);\n }\n\n async forOffer(\n offerId: OfferId,\n clientCreds?: ClientCredentialsOAuth\n ): Promise<Record<OfferOptionId, Requirement[]>> {\n await this.serverCtx.ensureAuthenticated(clientCreds);\n return requirementsApi.fetchOfferRequirements(\n this.serverCtx.api,\n offerId,\n clientCreds\n );\n }\n}\n","import { ApiClient } from '@/server/core/api/api-client';\nimport {\n type ServerAuthNamespace,\n ServerAuthNamespaceImpl,\n type SessionStore,\n} from '@/server/core/server-auth-namespace';\nimport type { ServerNamespaceContext } from '@/server/core/server-namespace-context';\nimport {\n type ServerOffersNamespace,\n ServerOffersNamespaceImpl,\n} from '@/server/core/server-offers-namespace';\nimport {\n type ServerRequirementsNamespace,\n ServerRequirementsNamespaceImpl,\n} from '@/server/core/server-requirements-namespace';\nimport {\n API_VERSION,\n PUBLIC_API_BASE_URL,\n} from '@/shared/api/frontline/config';\nimport { NABU_BASE_URL } from '@/shared/api/nabu/config';\nimport {\n type Erc20Namespace,\n Erc20NamespaceImpl,\n} from '@/shared/core/blockchain/erc20/erc20-namespace';\nimport {\n type CoinListTokenSaleNamespace,\n CoinListTokenSaleNamespaceImpl,\n} from '@/shared/core/checkout/coin-list/token-sale-namespace';\nimport {\n type OndoNamespace,\n OndoNamespaceImpl,\n} from '@/shared/core/checkout/ondo/ondo-namespace';\nimport {\n type SuperstateSwapNamespace,\n SuperstateSwapNamespaceImpl,\n} from '@/shared/core/checkout/superstate/swap-namespace';\nimport type { SharedNamespaceContext } from '@/shared/core/namespace-context';\nimport {\n type TokensNamespace,\n TokensNamespaceImpl,\n} from '@/shared/core/tokens/tokens-namespace';\nimport {\n type WalletsNamespace,\n WalletsNamespaceImpl,\n} from '@/shared/core/wallets/wallets-namespace';\nimport type { Config } from '@/shared/types/config';\nimport { NotAuthenticatedError } from '@/shared/types/errors';\nimport type { ClientSecret } from '@/shared/types/oauth';\nimport type { ClientCredentialsOAuth } from '@/shared/types/oauth-session';\n\nexport type { SessionStore } from '@/server/core/server-auth-namespace';\n\n/** Buffer in seconds before expiry to consider token expired for refresh. */\nconst ACCESS_TOKEN_EXPIRY_BUFFER_SECONDS = 60;\n\nexport interface ServerConfig extends Config {\n readonly clientSecret: ClientSecret;\n readonly sessionStore: SessionStore;\n /** Buffer in seconds before expiry to consider token expired for refresh. */\n readonly accessTokenExpiryBufferSeconds?: number;\n /**\n * Whether SDK will throw an exception in cases it can be silent.\n * For example, if token revokation on logout fails.\n */\n readonly strict?: boolean;\n}\n\n/**\n * Server-side CoinList SDK client.\n *\n * Functionality is grouped into namespaces — `coinlist.auth.getAccessToken()`,\n * `coinlist.offers.list()`, `coinlist.requirements.statuses(offerId)`.\n *\n * Operates in one of two modes depending on whether {@link SessionStore}\n * includes a `setSession` implementation:\n *\n * - **Writable store** (`setSession` provided) — full functionality: token\n * refresh, `auth.completeOAuth`, and `auth.logout` all work normally.\n *\n * - **Read-only store** (no `setSession`) — token refresh is skipped entirely,\n * meaning no network call is made and no refresh token is consumed.\n * `auth.completeOAuth` and `auth.logout` throw\n * {@link WritableSessionStoreRequiredError}. `auth.getAccessToken` may\n * return an expired token (see its docs). Use this mode in execution\n * contexts that can read the session but cannot write it back, such as\n * Next.js Server Components.\n *\n * Unless a namespace says otherwise, its methods require a user session and\n * throw {@link NotAuthenticatedError} when there is none.\n */\nexport interface CoinListServer {\n /**\n * OAuth session lifecycle: exchanging an authorization code, serving a valid\n * access token to the browser, minting app-level tokens, and logging out —\n * e.g. `coinlist.auth.getAccessToken()`.\n */\n readonly auth: ServerAuthNamespace;\n\n /**\n * The offer catalogue — e.g. `coinlist.offers.list()`. Every read also\n * accepts an app-level token from {@link ServerAuthNamespace.clientCredentials}\n * so it can run without a user session.\n */\n readonly offers: ServerOffersNamespace;\n\n /**\n * Offer requirements and the operations that satisfy them — e.g.\n * `coinlist.requirements.statuses(offerId)`. `forOffer` also accepts an\n * app-level token; the rest is per-user data and needs a user session.\n */\n readonly requirements: ServerRequirementsNamespace;\n\n /**\n * The user's external wallets: ownership proofs and offer-option bindings —\n * e.g. `coinlist.wallets.list({ offerId, offerOptionId })`.\n */\n readonly wallets: WalletsNamespace;\n\n /**\n * Generic ERC-20 reads (token allowance and balance) — e.g.\n * `coinlist.erc20.getBalance({ ... })`.\n */\n readonly erc20: Erc20Namespace;\n\n /**\n * Token-sale operations: listing, reading, and recording participations —\n * e.g. `coinlist.tokenSale.list()`. The on-chain `execute`\n * flow is client-only and is not exposed here.\n */\n readonly tokenSale: CoinListTokenSaleNamespace;\n\n /**\n * On-chain swap operations: quoting a swap, reading swap-contract state, and\n * allow-listing a proven wallet — e.g.\n * `coinlist.superstate.getOutputToken({ contractAddress, chain })`.\n */\n readonly superstate: SuperstateSwapNamespace;\n\n /**\n * Ondo swap reads: trading status and quoting. Both are free to poll.\n *\n * No CoinList fee is applied to a quote; see {@link OndoNamespace}.\n *\n * This is Ondo's whole surface for now — the wallet-driven half arrives with\n * ENG-1680 and will be client-only, since it needs a wallet to sign with.\n */\n readonly ondo: OndoNamespace;\n\n /**\n * Token display metadata (name, symbol, decimals, logos) from CoinList's\n * public token registry, keyed by chain + contract address — e.g.\n * `coinlist.tokens.get({ chain, address })` for an entry of\n * `OfferDetail.tokens`, or `coinlist.tokens.list(chain)` for a whole\n * catalogue in one request.\n *\n * Public and unauthenticated: unlike the other namespaces, its methods never\n * require a session, so it also works with a read-only store.\n */\n readonly tokens: TokensNamespace;\n}\n\nclass CoinListServerImpl implements CoinListServer {\n private readonly api: ApiClient;\n readonly auth: ServerAuthNamespace;\n readonly offers: ServerOffersNamespace;\n readonly requirements: ServerRequirementsNamespace;\n readonly wallets: WalletsNamespace;\n readonly erc20: Erc20Namespace;\n readonly tokenSale: CoinListTokenSaleNamespace;\n readonly superstate: SuperstateSwapNamespace;\n readonly ondo: OndoNamespace;\n readonly tokens: TokensNamespace;\n\n constructor(private readonly _config: ServerConfig) {\n this.api = new ApiClient(\n {\n baseUrl: _config.baseUrl ?? PUBLIC_API_BASE_URL,\n xApiVersion: API_VERSION,\n },\n // When refresh=true the renewal middleware has received a 401 and wants a\n // fresh token. A read-only store cannot persist a new session, so return\n // null immediately — this tells the middleware to skip the retry rather\n // than re-sending with the same expired token and wasting a round-trip.\n (refresh) =>\n refresh && !this._config.sessionStore.setSession\n ? Promise.resolve(null)\n : this.auth.getAccessToken()\n );\n this.auth = new ServerAuthNamespaceImpl(this.api, {\n ..._config,\n accessTokenExpiryBufferSeconds:\n _config.accessTokenExpiryBufferSeconds ??\n ACCESS_TOKEN_EXPIRY_BUFFER_SECONDS,\n strict: _config.strict ?? false,\n });\n\n const ctx: SharedNamespaceContext & ServerNamespaceContext = {\n api: this.api,\n ensureUserAuthenticated: () => this.ensureAuthenticated(undefined),\n ensureAuthenticated: (clientCreds) =>\n this.ensureAuthenticated(clientCreds),\n };\n this.offers = new ServerOffersNamespaceImpl(ctx);\n this.requirements = new ServerRequirementsNamespaceImpl(ctx);\n this.wallets = new WalletsNamespaceImpl(ctx);\n this.erc20 = new Erc20NamespaceImpl(ctx);\n this.tokenSale = new CoinListTokenSaleNamespaceImpl(ctx);\n this.superstate = new SuperstateSwapNamespaceImpl(ctx);\n this.ondo = new OndoNamespaceImpl(ctx);\n this.tokens = new TokensNamespaceImpl(\n _config.tokensBaseUrl ?? NABU_BASE_URL\n );\n }\n\n /**\n * An app-level token authenticates a request on its own; without one the\n * caller needs a user session.\n */\n private async ensureAuthenticated(\n clientCreds: ClientCredentialsOAuth | undefined\n ): Promise<void> {\n if (clientCreds) return;\n const token = await this.auth.getAccessToken();\n if (token === null) {\n throw new NotAuthenticatedError();\n }\n }\n}\n\nexport function createCoinListServer(config: ServerConfig): CoinListServer {\n return new CoinListServerImpl(config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAIO,IAAM,YAAN,MAAgB;AAAA,EAGrB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