@coinlist-co/react 0.3.0 → 0.5.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.
Files changed (71) hide show
  1. package/dist/chunk-CRACFEJ4.js +17 -0
  2. package/dist/chunk-CRACFEJ4.js.map +1 -0
  3. package/dist/{chunk-GRVV7NLV.js → chunk-N3WBC2VS.js} +218 -28
  4. package/dist/chunk-N3WBC2VS.js.map +1 -0
  5. package/dist/chunk-V6WO67RO.js +311 -0
  6. package/dist/chunk-V6WO67RO.js.map +1 -0
  7. package/dist/client/index.cjs +1393 -372
  8. package/dist/client/index.cjs.map +1 -1
  9. package/dist/client/index.d.cts +526 -10
  10. package/dist/client/index.d.ts +526 -10
  11. package/dist/client/index.js +1464 -88
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/requirement-BEO42QOr.d.cts +387 -0
  14. package/dist/requirement-BEO42QOr.d.ts +387 -0
  15. package/dist/server/index.cjs +459 -36
  16. package/dist/server/index.cjs.map +1 -1
  17. package/dist/server/index.d.cts +56 -4
  18. package/dist/server/index.d.ts +56 -4
  19. package/dist/server/index.js +69 -37
  20. package/dist/server/index.js.map +1 -1
  21. package/dist/shared/index.cjs +375 -0
  22. package/dist/shared/index.cjs.map +1 -0
  23. package/dist/shared/index.d.cts +35 -0
  24. package/dist/shared/index.d.ts +35 -0
  25. package/dist/{client/core → shared}/index.js +38 -19
  26. package/dist/shared/index.js.map +1 -0
  27. package/package.json +7 -22
  28. package/dist/RequirementItem-BpkJQep8.d.ts +0 -37
  29. package/dist/RequirementItem-BvwsFu9e.d.cts +0 -37
  30. package/dist/chunk-GRVV7NLV.js.map +0 -1
  31. package/dist/chunk-IADBIDY6.js +0 -76
  32. package/dist/chunk-IADBIDY6.js.map +0 -1
  33. package/dist/chunk-IDCROXPS.js +0 -412
  34. package/dist/chunk-IDCROXPS.js.map +0 -1
  35. package/dist/chunk-P4DTIPEX.js +0 -623
  36. package/dist/chunk-P4DTIPEX.js.map +0 -1
  37. package/dist/chunk-V5M7SA3C.js +0 -161
  38. package/dist/chunk-V5M7SA3C.js.map +0 -1
  39. package/dist/chunk-YJQMJFA7.js +0 -16
  40. package/dist/chunk-YJQMJFA7.js.map +0 -1
  41. package/dist/client/components/index.cjs +0 -1107
  42. package/dist/client/components/index.cjs.map +0 -1
  43. package/dist/client/components/index.d.cts +0 -121
  44. package/dist/client/components/index.d.ts +0 -121
  45. package/dist/client/components/index.js +0 -586
  46. package/dist/client/components/index.js.map +0 -1
  47. package/dist/client/core/index.cjs +0 -961
  48. package/dist/client/core/index.cjs.map +0 -1
  49. package/dist/client/core/index.d.cts +0 -23
  50. package/dist/client/core/index.d.ts +0 -23
  51. package/dist/client/core/index.js.map +0 -1
  52. package/dist/client/hooks/index.cjs +0 -233
  53. package/dist/client/hooks/index.cjs.map +0 -1
  54. package/dist/client/hooks/index.d.cts +0 -33
  55. package/dist/client/hooks/index.d.ts +0 -33
  56. package/dist/client/hooks/index.js +0 -19
  57. package/dist/client/hooks/index.js.map +0 -1
  58. package/dist/coinlist-client-B_dJkbwB.d.ts +0 -283
  59. package/dist/coinlist-client-DBKa6j3f.d.cts +0 -283
  60. package/dist/newtype-yKTvFdg_.d.cts +0 -6
  61. package/dist/newtype-yKTvFdg_.d.ts +0 -6
  62. package/dist/oauth-session-DgItaMKN.d.cts +0 -56
  63. package/dist/oauth-session-DnKDI5ou.d.ts +0 -56
  64. package/dist/requirement-CxbdY8l4.d.cts +0 -202
  65. package/dist/requirement-fJsQ3f9_.d.ts +0 -202
  66. package/dist/useCoinListOffers-C5lBlzcC.d.ts +0 -27
  67. package/dist/useCoinListOffers-CguwXaCX.d.cts +0 -27
  68. package/dist/useCoinListRequirements-BECx1cIw.d.ts +0 -31
  69. package/dist/useCoinListRequirements-CX2gV9gJ.d.cts +0 -31
  70. package/dist/useCompleteCoinListOAuth-BRhAqD4_.d.cts +0 -55
  71. package/dist/useCompleteCoinListOAuth-DEZpHjd6.d.ts +0 -55
@@ -1,283 +0,0 @@
1
- import { A as AuthorizationCode, c as CodeVerifier, f as Config, O as OAuthAccessToken } from './oauth-session-DnKDI5ou.js';
2
- import { N as Newtype } from './newtype-yKTvFdg_.js';
3
- import { A as AssetDto, b as OfferId, d as OfferOptionId, k as Asset, l as AssetId, O as Offer, a as OfferDetail, R as Requirement, h as RequirementStatusInfo } from './requirement-fJsQ3f9_.js';
4
-
5
- type AuthState = 'unknown' | 'logged-in' | 'logged-out';
6
- /** Discriminated error reasons from {@link CoinListClient.completeOAuth}. */
7
- type OauthClientErrorReason = 'user_canceled' | 'missing_state' | 'invalid_state' | 'missing_code' | 'missing_code_verifier';
8
- type OauthClientResult = {
9
- type: 'ok';
10
- code: AuthorizationCode;
11
- codeVerifier: CodeVerifier;
12
- } | {
13
- type: 'error';
14
- reason: OauthClientErrorReason;
15
- };
16
-
17
- type QueryParamValue = string | number | boolean | null | undefined;
18
-
19
- type Cursor = Newtype<string, 'Cursor'>;
20
- declare const Cursor: (value: string) => Cursor;
21
- interface PaginatedResponseDto<T> {
22
- data: T[];
23
- starting_after?: string;
24
- starting_before?: string;
25
- }
26
- declare function fetchAllPages<A, P extends PaginationParams = PaginationParams>(fetchPage: (params: P) => Promise<PaginatedResponse<A>>, baseParams?: Omit<P, keyof PaginationParams>): Promise<A[]>;
27
- interface PaginatedResponse<T> {
28
- data: T[];
29
- startingAfter: Cursor | null;
30
- startingBefore: Cursor | null;
31
- }
32
- declare const PaginatedResponse: {
33
- fromDto: <A, B>(dto: PaginatedResponseDto<A>, itemMapper: (item: A) => B) => PaginatedResponse<B>;
34
- };
35
- /**
36
- * Cursor-based pagination input used when requesting paginated API resources.
37
- * Set `after` or `before` to navigate relative to a known cursor, and `limit`
38
- * to control the maximum number of returned items.
39
- */
40
- interface PaginationParams {
41
- before?: Cursor;
42
- after?: Cursor;
43
- limit?: number;
44
- }
45
- declare const PaginationParams: {
46
- toQueryParams: (params: PaginationParams) => Record<string, QueryParamValue>;
47
- };
48
-
49
- type ParticipationStatusDto = 'prepared' | 'pending' | 'submitted' | 'completed' | 'failed' | 'remit_submitted' | 'remitted' | 'remit_failed';
50
- type ParticipationDto = {
51
- object: 'participation';
52
- id: string;
53
- offer_id: string;
54
- offer_option_id: string;
55
- status: ParticipationStatusDto;
56
- amount: string;
57
- amount_string: string;
58
- asset: AssetDto;
59
- chain: string;
60
- inserted_at: string | null | undefined;
61
- updated_at: string | null | undefined;
62
- wallet_address: string | null | undefined;
63
- };
64
- type CreateParticipationDto = {
65
- offer_id: string;
66
- offer_option_id: string;
67
- chain: string;
68
- wallet_address: string;
69
- amount: string;
70
- asset_id: string;
71
- approval_transaction_hash: string | null | undefined;
72
- };
73
-
74
- /** Unique identifier for a participation. */
75
- type ParticipationId = Newtype<string, 'ParticipationId'>;
76
- /** Casts a string into a typed {@link ParticipationId}. */
77
- declare const ParticipationId: (value: string) => ParticipationId;
78
- /** Blockchain identifier for where a participation is funded. */
79
- type Blockchain = Newtype<string, 'Blockchain'>;
80
- /** Casts a string into a typed {@link Blockchain}. */
81
- declare const Blockchain: (value: string) => Blockchain;
82
- /** Wallet address used for a participation. */
83
- type WalletAddress = Newtype<string, 'WalletAddress'>;
84
- /** Casts a string into a typed {@link WalletAddress}. */
85
- declare const WalletAddress: (value: string) => WalletAddress;
86
- /** Possible participation lifecycle states returned by the API. */
87
- type ParticipationStatus = ParticipationStatusDto;
88
- /** Pagination params for listing participations, with an optional offer filter. */
89
- interface ParticipationsPaginationParams extends PaginationParams {
90
- offerId?: OfferId;
91
- }
92
- declare const ParticipationsPaginationParams: {
93
- toQueryParams: (params: ParticipationsPaginationParams) => Record<string, QueryParamValue>;
94
- };
95
- /** Domain model for a participation returned by CoinList APIs. */
96
- type Participation = {
97
- /** Unique participation id. */
98
- id: ParticipationId;
99
- /** Parent offer id. */
100
- offerId: OfferId;
101
- /** Selected offer option id. */
102
- offerOptionId: OfferOptionId;
103
- /** Current processing status. */
104
- status: ParticipationStatus;
105
- /** Raw participation amount from API. */
106
- amount: string;
107
- /** Human-readable formatted amount from API. */
108
- displayAmount: string;
109
- /** Asset metadata for the participation amount. */
110
- asset: Asset;
111
- /** Funding chain identifier. */
112
- chain: Blockchain;
113
- /** Creation timestamp, if returned by API. */
114
- insertedAt: Date | null;
115
- /** Last update timestamp, if returned by API. */
116
- updatedAt: Date | null;
117
- /** Wallet used for participation, blank values normalized to null. */
118
- walletAddress: WalletAddress | null;
119
- };
120
- declare const Participation: {
121
- /** Maps API DTO shape into the SDK participation domain model. */
122
- fromDto: (dto: ParticipationDto) => Participation;
123
- };
124
- /** Parameters required to create a new participation. */
125
- type CreateParticipationParams = {
126
- /** Offer to participate in. */
127
- offerId: OfferId;
128
- /** Offer option selected for participation. */
129
- offerOptionId: OfferOptionId;
130
- /** Blockchain for funding. */
131
- chain: Blockchain;
132
- /** Wallet address that funds the participation. */
133
- walletAddress: WalletAddress;
134
- /** Raw amount to participate with. */
135
- amount: string;
136
- /** Funding asset id. */
137
- assetId: AssetId;
138
- /** Optional approval transaction hash, if applicable. */
139
- approvalTransactionHash?: string | null;
140
- };
141
- declare const CreateParticipationParams: {
142
- /** Maps participation creation params into API DTO payload. */
143
- toDto: (params: CreateParticipationParams) => CreateParticipationDto;
144
- };
145
-
146
- interface ClientConfig extends Config {
147
- /**
148
- * The SDK user must provide this function. It is responsible for fetching a
149
- * valid {@link OAuthAccessToken}, or **null** for logged-out users. If your
150
- * backend is in TypeScript, it is recommended to use
151
- * {@link CoinListServer#accessToken} from `@/server/coinlist.server`.
152
- */
153
- getAccessToken: () => Promise<OAuthAccessToken | null>;
154
- /**
155
- * Recommended to leave undefined. Used to change the CoinList environment;
156
- * default is production.
157
- */
158
- authorizationPageUrl?: string;
159
- /**
160
- * Whether the SDK should enable sandbox mode (adds `sandbox=true` when listing offers).
161
- */
162
- sandbox?: boolean;
163
- }
164
- interface CoinListClient {
165
- /**
166
- * Calls the provided {@link ClientConfig.getAccessToken} lambda to determine
167
- * the user's {@link AuthState}. This is called automatically by {@link CoinListProvider};
168
- * you typically do not need to call it yourself unless you are using the client
169
- * outside of the provider.
170
- */
171
- init(): Promise<AuthState>;
172
- /**
173
- * Returns the current auth state: `'logged-in'`, `'logged-out'`, or `'unknown'`.
174
- * Returns **unknown** until {@link CoinListClient.init} has completed. It is
175
- * recommended to use the `const { isReady, coinlist } = useCoinList()` hook to know when
176
- * the SDK has initialized, or to manually await {@link CoinListClient.init}
177
- * before relying on this value.
178
- */
179
- getAuthState(): AuthState;
180
- /**
181
- * Starts the OAuth flow with PKCE. Generates a random `state` and `code_verifier`,
182
- * stores them in sessionStorage (for validation in {@link CoinListClient.completeOAuth}
183
- * on redirect), then redirects the user to the CoinList authorization page. After
184
- * the user authorizes, they are sent back to your application's redirect URI; call
185
- * {@link CoinListClient.completeOAuth} on that page to finish the flow.
186
- */
187
- startOAuth(): Promise<void>;
188
- /**
189
- * Completes the OAuth flow on the FE with PKCE and state validation. Parses the
190
- * redirect URL (state, code) and validates them against sessionStorage
191
- * (state, code_verifier). The state check protects against CSRF (cross-site
192
- * request forgery). Call this on the frontend page the user is redirected
193
- * to after authorizing.
194
- *
195
- * On `ok`: Call your backend to exchange the short-lived `authorizationCode`
196
- * (and the returned `codeVerifier`) for a long-lived session. If your backend
197
- * is in TypeScript, you can use {@link CoinListServer#completeOAuth} from
198
- * `@/server/coinlist.server` (CoinListServer) to perform that exchange.
199
- *
200
- * On `error`: `reason` is an {@link OauthClientErrorReason} (e.g. `'missing_state'`, `'invalid_state'`) so you can switch on it and surface a message to the user.
201
- */
202
- completeOAuth(): OauthClientResult;
203
- /**
204
- * Clears the in-memory access token. Note: you need to manually
205
- * also logout on the backend via CoinListServer#logout to clear the session cookie.
206
- */
207
- logout(): void;
208
- /**
209
- * Fetches all offers by iterating through every paginated response.
210
- *
211
- * This method must be called only when the user's {@link AuthState} is
212
- * `'logged-in'`. If the user is not authenticated, it throws
213
- * {@link NotAuthenticatedError}.
214
- */
215
- fetchAllOffers(): Promise<Offer[]>;
216
- /**
217
- * Fetches a single page of offers.
218
- *
219
- * This method must be called only when the user's {@link AuthState} is
220
- * `'logged-in'`. If the user is not authenticated, it throws
221
- * {@link NotAuthenticatedError}.
222
- */
223
- fetchOffersPage(params: PaginationParams): Promise<PaginatedResponse<Offer>>;
224
- /**
225
- * Fetches details for a given offer by its id.
226
- *
227
- * This method must be called only when the user's {@link AuthState} is
228
- * `'logged-in'`. If the user is not authenticated, it throws
229
- * {@link NotAuthenticatedError}.
230
- */
231
- fetchOfferDetails(id: OfferId): Promise<OfferDetail>;
232
- /**
233
- * Fetches all participations by iterating through every paginated response.
234
- *
235
- * This method must be called only when the user's {@link AuthState} is
236
- * `'logged-in'`. If the user is not authenticated, it throws
237
- * {@link NotAuthenticatedError}.
238
- */
239
- fetchAllParticipations(offerId?: OfferId): Promise<Participation[]>;
240
- /**
241
- * Fetches a single page of participations, optionally filtered by offer.
242
- *
243
- * This method must be called only when the user's {@link AuthState} is
244
- * `'logged-in'`. If the user is not authenticated, it throws
245
- * {@link NotAuthenticatedError}.
246
- */
247
- fetchParticipationsPage(params: ParticipationsPaginationParams): Promise<PaginatedResponse<Participation>>;
248
- /**
249
- * Fetches a participation by id.
250
- *
251
- * This method must be called only when the user's {@link AuthState} is
252
- * `'logged-in'`. If the user is not authenticated, it throws
253
- * {@link NotAuthenticatedError}.
254
- */
255
- fetchParticipation(id: ParticipationId): Promise<Participation>;
256
- /**
257
- * Creates a participation.
258
- *
259
- * This method must be called only when the user's {@link AuthState} is
260
- * `'logged-in'`. If the user is not authenticated, it throws
261
- * {@link NotAuthenticatedError}.
262
- */
263
- createParticipation(params: CreateParticipationParams): Promise<Participation>;
264
- /**
265
- * Fetches the requirements for all options of a given offer, grouped by option ID.
266
- *
267
- * This method must be called only when the user's {@link AuthState} is
268
- * `'logged-in'`. If the user is not authenticated, it throws
269
- * {@link NotAuthenticatedError}.
270
- */
271
- fetchOfferRequirements(offerId: OfferId): Promise<Record<OfferOptionId, Requirement[]>>;
272
- /**
273
- * Fetches the user's requirement statuses for a given offer.
274
- *
275
- * This method must be called only when the user's {@link AuthState} is
276
- * `'logged-in'`. If the user is not authenticated, it throws
277
- * {@link NotAuthenticatedError}.
278
- */
279
- fetchRequirementStatuses(offerId: OfferId): Promise<RequirementStatusInfo[]>;
280
- }
281
- declare function createCoinListClient(config: ClientConfig): CoinListClient;
282
-
283
- export { type AuthState as A, Blockchain as B, type ClientConfig as C, type OauthClientErrorReason as O, PaginatedResponse as P, WalletAddress as W, type CoinListClient as a, CreateParticipationParams as b, Cursor as c, type OauthClientResult as d, type PaginatedResponseDto as e, PaginationParams as f, Participation as g, ParticipationId as h, type ParticipationStatus as i, ParticipationsPaginationParams as j, createCoinListClient as k, fetchAllPages as l };
@@ -1,283 +0,0 @@
1
- import { A as AuthorizationCode, c as CodeVerifier, f as Config, O as OAuthAccessToken } from './oauth-session-DgItaMKN.cjs';
2
- import { N as Newtype } from './newtype-yKTvFdg_.cjs';
3
- import { A as AssetDto, b as OfferId, d as OfferOptionId, k as Asset, l as AssetId, O as Offer, a as OfferDetail, R as Requirement, h as RequirementStatusInfo } from './requirement-CxbdY8l4.cjs';
4
-
5
- type AuthState = 'unknown' | 'logged-in' | 'logged-out';
6
- /** Discriminated error reasons from {@link CoinListClient.completeOAuth}. */
7
- type OauthClientErrorReason = 'user_canceled' | 'missing_state' | 'invalid_state' | 'missing_code' | 'missing_code_verifier';
8
- type OauthClientResult = {
9
- type: 'ok';
10
- code: AuthorizationCode;
11
- codeVerifier: CodeVerifier;
12
- } | {
13
- type: 'error';
14
- reason: OauthClientErrorReason;
15
- };
16
-
17
- type QueryParamValue = string | number | boolean | null | undefined;
18
-
19
- type Cursor = Newtype<string, 'Cursor'>;
20
- declare const Cursor: (value: string) => Cursor;
21
- interface PaginatedResponseDto<T> {
22
- data: T[];
23
- starting_after?: string;
24
- starting_before?: string;
25
- }
26
- declare function fetchAllPages<A, P extends PaginationParams = PaginationParams>(fetchPage: (params: P) => Promise<PaginatedResponse<A>>, baseParams?: Omit<P, keyof PaginationParams>): Promise<A[]>;
27
- interface PaginatedResponse<T> {
28
- data: T[];
29
- startingAfter: Cursor | null;
30
- startingBefore: Cursor | null;
31
- }
32
- declare const PaginatedResponse: {
33
- fromDto: <A, B>(dto: PaginatedResponseDto<A>, itemMapper: (item: A) => B) => PaginatedResponse<B>;
34
- };
35
- /**
36
- * Cursor-based pagination input used when requesting paginated API resources.
37
- * Set `after` or `before` to navigate relative to a known cursor, and `limit`
38
- * to control the maximum number of returned items.
39
- */
40
- interface PaginationParams {
41
- before?: Cursor;
42
- after?: Cursor;
43
- limit?: number;
44
- }
45
- declare const PaginationParams: {
46
- toQueryParams: (params: PaginationParams) => Record<string, QueryParamValue>;
47
- };
48
-
49
- type ParticipationStatusDto = 'prepared' | 'pending' | 'submitted' | 'completed' | 'failed' | 'remit_submitted' | 'remitted' | 'remit_failed';
50
- type ParticipationDto = {
51
- object: 'participation';
52
- id: string;
53
- offer_id: string;
54
- offer_option_id: string;
55
- status: ParticipationStatusDto;
56
- amount: string;
57
- amount_string: string;
58
- asset: AssetDto;
59
- chain: string;
60
- inserted_at: string | null | undefined;
61
- updated_at: string | null | undefined;
62
- wallet_address: string | null | undefined;
63
- };
64
- type CreateParticipationDto = {
65
- offer_id: string;
66
- offer_option_id: string;
67
- chain: string;
68
- wallet_address: string;
69
- amount: string;
70
- asset_id: string;
71
- approval_transaction_hash: string | null | undefined;
72
- };
73
-
74
- /** Unique identifier for a participation. */
75
- type ParticipationId = Newtype<string, 'ParticipationId'>;
76
- /** Casts a string into a typed {@link ParticipationId}. */
77
- declare const ParticipationId: (value: string) => ParticipationId;
78
- /** Blockchain identifier for where a participation is funded. */
79
- type Blockchain = Newtype<string, 'Blockchain'>;
80
- /** Casts a string into a typed {@link Blockchain}. */
81
- declare const Blockchain: (value: string) => Blockchain;
82
- /** Wallet address used for a participation. */
83
- type WalletAddress = Newtype<string, 'WalletAddress'>;
84
- /** Casts a string into a typed {@link WalletAddress}. */
85
- declare const WalletAddress: (value: string) => WalletAddress;
86
- /** Possible participation lifecycle states returned by the API. */
87
- type ParticipationStatus = ParticipationStatusDto;
88
- /** Pagination params for listing participations, with an optional offer filter. */
89
- interface ParticipationsPaginationParams extends PaginationParams {
90
- offerId?: OfferId;
91
- }
92
- declare const ParticipationsPaginationParams: {
93
- toQueryParams: (params: ParticipationsPaginationParams) => Record<string, QueryParamValue>;
94
- };
95
- /** Domain model for a participation returned by CoinList APIs. */
96
- type Participation = {
97
- /** Unique participation id. */
98
- id: ParticipationId;
99
- /** Parent offer id. */
100
- offerId: OfferId;
101
- /** Selected offer option id. */
102
- offerOptionId: OfferOptionId;
103
- /** Current processing status. */
104
- status: ParticipationStatus;
105
- /** Raw participation amount from API. */
106
- amount: string;
107
- /** Human-readable formatted amount from API. */
108
- displayAmount: string;
109
- /** Asset metadata for the participation amount. */
110
- asset: Asset;
111
- /** Funding chain identifier. */
112
- chain: Blockchain;
113
- /** Creation timestamp, if returned by API. */
114
- insertedAt: Date | null;
115
- /** Last update timestamp, if returned by API. */
116
- updatedAt: Date | null;
117
- /** Wallet used for participation, blank values normalized to null. */
118
- walletAddress: WalletAddress | null;
119
- };
120
- declare const Participation: {
121
- /** Maps API DTO shape into the SDK participation domain model. */
122
- fromDto: (dto: ParticipationDto) => Participation;
123
- };
124
- /** Parameters required to create a new participation. */
125
- type CreateParticipationParams = {
126
- /** Offer to participate in. */
127
- offerId: OfferId;
128
- /** Offer option selected for participation. */
129
- offerOptionId: OfferOptionId;
130
- /** Blockchain for funding. */
131
- chain: Blockchain;
132
- /** Wallet address that funds the participation. */
133
- walletAddress: WalletAddress;
134
- /** Raw amount to participate with. */
135
- amount: string;
136
- /** Funding asset id. */
137
- assetId: AssetId;
138
- /** Optional approval transaction hash, if applicable. */
139
- approvalTransactionHash?: string | null;
140
- };
141
- declare const CreateParticipationParams: {
142
- /** Maps participation creation params into API DTO payload. */
143
- toDto: (params: CreateParticipationParams) => CreateParticipationDto;
144
- };
145
-
146
- interface ClientConfig extends Config {
147
- /**
148
- * The SDK user must provide this function. It is responsible for fetching a
149
- * valid {@link OAuthAccessToken}, or **null** for logged-out users. If your
150
- * backend is in TypeScript, it is recommended to use
151
- * {@link CoinListServer#accessToken} from `@/server/coinlist.server`.
152
- */
153
- getAccessToken: () => Promise<OAuthAccessToken | null>;
154
- /**
155
- * Recommended to leave undefined. Used to change the CoinList environment;
156
- * default is production.
157
- */
158
- authorizationPageUrl?: string;
159
- /**
160
- * Whether the SDK should enable sandbox mode (adds `sandbox=true` when listing offers).
161
- */
162
- sandbox?: boolean;
163
- }
164
- interface CoinListClient {
165
- /**
166
- * Calls the provided {@link ClientConfig.getAccessToken} lambda to determine
167
- * the user's {@link AuthState}. This is called automatically by {@link CoinListProvider};
168
- * you typically do not need to call it yourself unless you are using the client
169
- * outside of the provider.
170
- */
171
- init(): Promise<AuthState>;
172
- /**
173
- * Returns the current auth state: `'logged-in'`, `'logged-out'`, or `'unknown'`.
174
- * Returns **unknown** until {@link CoinListClient.init} has completed. It is
175
- * recommended to use the `const { isReady, coinlist } = useCoinList()` hook to know when
176
- * the SDK has initialized, or to manually await {@link CoinListClient.init}
177
- * before relying on this value.
178
- */
179
- getAuthState(): AuthState;
180
- /**
181
- * Starts the OAuth flow with PKCE. Generates a random `state` and `code_verifier`,
182
- * stores them in sessionStorage (for validation in {@link CoinListClient.completeOAuth}
183
- * on redirect), then redirects the user to the CoinList authorization page. After
184
- * the user authorizes, they are sent back to your application's redirect URI; call
185
- * {@link CoinListClient.completeOAuth} on that page to finish the flow.
186
- */
187
- startOAuth(): Promise<void>;
188
- /**
189
- * Completes the OAuth flow on the FE with PKCE and state validation. Parses the
190
- * redirect URL (state, code) and validates them against sessionStorage
191
- * (state, code_verifier). The state check protects against CSRF (cross-site
192
- * request forgery). Call this on the frontend page the user is redirected
193
- * to after authorizing.
194
- *
195
- * On `ok`: Call your backend to exchange the short-lived `authorizationCode`
196
- * (and the returned `codeVerifier`) for a long-lived session. If your backend
197
- * is in TypeScript, you can use {@link CoinListServer#completeOAuth} from
198
- * `@/server/coinlist.server` (CoinListServer) to perform that exchange.
199
- *
200
- * On `error`: `reason` is an {@link OauthClientErrorReason} (e.g. `'missing_state'`, `'invalid_state'`) so you can switch on it and surface a message to the user.
201
- */
202
- completeOAuth(): OauthClientResult;
203
- /**
204
- * Clears the in-memory access token. Note: you need to manually
205
- * also logout on the backend via CoinListServer#logout to clear the session cookie.
206
- */
207
- logout(): void;
208
- /**
209
- * Fetches all offers by iterating through every paginated response.
210
- *
211
- * This method must be called only when the user's {@link AuthState} is
212
- * `'logged-in'`. If the user is not authenticated, it throws
213
- * {@link NotAuthenticatedError}.
214
- */
215
- fetchAllOffers(): Promise<Offer[]>;
216
- /**
217
- * Fetches a single page of offers.
218
- *
219
- * This method must be called only when the user's {@link AuthState} is
220
- * `'logged-in'`. If the user is not authenticated, it throws
221
- * {@link NotAuthenticatedError}.
222
- */
223
- fetchOffersPage(params: PaginationParams): Promise<PaginatedResponse<Offer>>;
224
- /**
225
- * Fetches details for a given offer by its id.
226
- *
227
- * This method must be called only when the user's {@link AuthState} is
228
- * `'logged-in'`. If the user is not authenticated, it throws
229
- * {@link NotAuthenticatedError}.
230
- */
231
- fetchOfferDetails(id: OfferId): Promise<OfferDetail>;
232
- /**
233
- * Fetches all participations by iterating through every paginated response.
234
- *
235
- * This method must be called only when the user's {@link AuthState} is
236
- * `'logged-in'`. If the user is not authenticated, it throws
237
- * {@link NotAuthenticatedError}.
238
- */
239
- fetchAllParticipations(offerId?: OfferId): Promise<Participation[]>;
240
- /**
241
- * Fetches a single page of participations, optionally filtered by offer.
242
- *
243
- * This method must be called only when the user's {@link AuthState} is
244
- * `'logged-in'`. If the user is not authenticated, it throws
245
- * {@link NotAuthenticatedError}.
246
- */
247
- fetchParticipationsPage(params: ParticipationsPaginationParams): Promise<PaginatedResponse<Participation>>;
248
- /**
249
- * Fetches a participation by id.
250
- *
251
- * This method must be called only when the user's {@link AuthState} is
252
- * `'logged-in'`. If the user is not authenticated, it throws
253
- * {@link NotAuthenticatedError}.
254
- */
255
- fetchParticipation(id: ParticipationId): Promise<Participation>;
256
- /**
257
- * Creates a participation.
258
- *
259
- * This method must be called only when the user's {@link AuthState} is
260
- * `'logged-in'`. If the user is not authenticated, it throws
261
- * {@link NotAuthenticatedError}.
262
- */
263
- createParticipation(params: CreateParticipationParams): Promise<Participation>;
264
- /**
265
- * Fetches the requirements for all options of a given offer, grouped by option ID.
266
- *
267
- * This method must be called only when the user's {@link AuthState} is
268
- * `'logged-in'`. If the user is not authenticated, it throws
269
- * {@link NotAuthenticatedError}.
270
- */
271
- fetchOfferRequirements(offerId: OfferId): Promise<Record<OfferOptionId, Requirement[]>>;
272
- /**
273
- * Fetches the user's requirement statuses for a given offer.
274
- *
275
- * This method must be called only when the user's {@link AuthState} is
276
- * `'logged-in'`. If the user is not authenticated, it throws
277
- * {@link NotAuthenticatedError}.
278
- */
279
- fetchRequirementStatuses(offerId: OfferId): Promise<RequirementStatusInfo[]>;
280
- }
281
- declare function createCoinListClient(config: ClientConfig): CoinListClient;
282
-
283
- export { type AuthState as A, Blockchain as B, type ClientConfig as C, type OauthClientErrorReason as O, PaginatedResponse as P, WalletAddress as W, type CoinListClient as a, CreateParticipationParams as b, Cursor as c, type OauthClientResult as d, type PaginatedResponseDto as e, PaginationParams as f, Participation as g, ParticipationId as h, type ParticipationStatus as i, ParticipationsPaginationParams as j, createCoinListClient as k, fetchAllPages as l };
@@ -1,6 +0,0 @@
1
- declare const __brand: unique symbol;
2
- type Newtype<Base, Branding> = Base & {
3
- readonly [__brand]: Branding;
4
- };
5
-
6
- export type { Newtype as N };
@@ -1,6 +0,0 @@
1
- declare const __brand: unique symbol;
2
- type Newtype<Base, Branding> = Base & {
3
- readonly [__brand]: Branding;
4
- };
5
-
6
- export type { Newtype as N };
@@ -1,56 +0,0 @@
1
- import { N as Newtype } from './newtype-yKTvFdg_.cjs';
2
-
3
- type AuthorizationCode = Newtype<string, 'AuthorizationCode'>;
4
- declare const AuthorizationCode: (value: string) => AuthorizationCode;
5
- type CodeVerifier = Newtype<string, 'CodeVerifier'>;
6
- declare const CodeVerifier: (value: string) => CodeVerifier;
7
- type CodeChallenge = Newtype<string, 'CodeChallenge'>;
8
- declare const CodeChallenge: (value: string) => CodeChallenge;
9
- type RedirectUri = Newtype<string, 'RedirectUri'>;
10
- declare const RedirectUri: (value: string) => RedirectUri;
11
- type ClientId = Newtype<string, 'ClientId'>;
12
- declare const ClientId: (value: string) => ClientId;
13
- type ClientSecret = Newtype<string, 'ClientSecret'>;
14
- declare const ClientSecret: (value: string) => ClientSecret;
15
-
16
- interface Config {
17
- /** OAuth2 public identifier. */
18
- readonly clientId: ClientId;
19
- /**
20
- * OAuth2 redirect URI. Recommended to point to a frontend page where
21
- * {@link CoinListClient#completeOauth} can be called to complete the PKCE
22
- * flow on the client side.
23
- */
24
- readonly redirectUri: RedirectUri;
25
- /**
26
- * Recommended to leave undefined. Used to change the CoinList environment;
27
- * default is production.
28
- */
29
- readonly baseUrl?: string;
30
- }
31
-
32
- /**
33
- * OAuth 2.0 token response (RFC 6749 §5.1).
34
- * Maps to OpenAPI schema OauthToken.
35
- */
36
- type OAuthSessionDto = {
37
- access_token: string;
38
- expires_in: number;
39
- refresh_token?: string;
40
- };
41
-
42
- type OAuthAccessToken = {
43
- value: string;
44
- expiresAt: Date;
45
- };
46
- type OAuthRefreshToken = Newtype<string, 'OAuthRefreshToken'>;
47
- declare const OAuthRefreshToken: (value: string) => OAuthRefreshToken;
48
- type OAuthSession = {
49
- accessToken: OAuthAccessToken;
50
- refreshToken?: OAuthRefreshToken;
51
- };
52
- declare const OAuthSession: {
53
- fromDto: (dto: OAuthSessionDto) => OAuthSession;
54
- };
55
-
56
- export { AuthorizationCode as A, ClientId as C, type OAuthAccessToken as O, RedirectUri as R, ClientSecret as a, CodeChallenge as b, CodeVerifier as c, OAuthRefreshToken as d, OAuthSession as e, type Config as f };