@coinlist-co/react 0.4.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 (61) hide show
  1. package/dist/chunk-CRACFEJ4.js +17 -0
  2. package/dist/chunk-CRACFEJ4.js.map +1 -0
  3. package/dist/{chunk-NC45IO63.js → chunk-N3WBC2VS.js} +20 -325
  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 +1013 -220
  8. package/dist/client/index.cjs.map +1 -1
  9. package/dist/client/index.d.cts +526 -9
  10. package/dist/client/index.d.ts +526 -9
  11. package/dist/client/index.js +1464 -94
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/{participation-DMMEDxON.d.cts → requirement-BEO42QOr.d.cts} +204 -2
  14. package/dist/{participation-E-bT-GXJ.d.ts → requirement-BEO42QOr.d.ts} +204 -2
  15. package/dist/server/index.cjs +9 -91
  16. package/dist/server/index.cjs.map +1 -1
  17. package/dist/server/index.d.cts +4 -21
  18. package/dist/server/index.d.ts +4 -21
  19. package/dist/server/index.js +14 -78
  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 +35 -16
  26. package/dist/shared/index.js.map +1 -0
  27. package/package.json +7 -22
  28. package/dist/RequirementItem-B-MvcxSr.d.cts +0 -37
  29. package/dist/RequirementItem-DcYot2uC.d.ts +0 -37
  30. package/dist/chunk-EHZ6PIGN.js +0 -414
  31. package/dist/chunk-EHZ6PIGN.js.map +0 -1
  32. package/dist/chunk-NC45IO63.js.map +0 -1
  33. package/dist/chunk-RIFATQB5.js +0 -257
  34. package/dist/chunk-RIFATQB5.js.map +0 -1
  35. package/dist/chunk-UGJUTRXC.js +0 -304
  36. package/dist/chunk-UGJUTRXC.js.map +0 -1
  37. package/dist/chunk-YJQMJFA7.js +0 -16
  38. package/dist/chunk-YJQMJFA7.js.map +0 -1
  39. package/dist/client/components/index.cjs +0 -1108
  40. package/dist/client/components/index.cjs.map +0 -1
  41. package/dist/client/components/index.d.cts +0 -139
  42. package/dist/client/components/index.d.ts +0 -139
  43. package/dist/client/components/index.js +0 -558
  44. package/dist/client/components/index.js.map +0 -1
  45. package/dist/client/core/index.cjs +0 -1047
  46. package/dist/client/core/index.cjs.map +0 -1
  47. package/dist/client/core/index.d.cts +0 -23
  48. package/dist/client/core/index.d.ts +0 -23
  49. package/dist/client/core/index.js.map +0 -1
  50. package/dist/client/hooks/index.cjs +0 -307
  51. package/dist/client/hooks/index.cjs.map +0 -1
  52. package/dist/client/hooks/index.d.cts +0 -126
  53. package/dist/client/hooks/index.d.ts +0 -126
  54. package/dist/client/hooks/index.js +0 -19
  55. package/dist/client/hooks/index.js.map +0 -1
  56. package/dist/coinlist-client-BSxpqylo.d.ts +0 -158
  57. package/dist/coinlist-client-Cah5c_aF.d.cts +0 -158
  58. package/dist/requirement-XWT0T_zO.d.cts +0 -205
  59. package/dist/requirement-XWT0T_zO.d.ts +0 -205
  60. package/dist/useCoinListRequirements-B5-ZPOMz.d.ts +0 -80
  61. package/dist/useCoinListRequirements-Cuc32Tqw.d.cts +0 -80
@@ -1,126 +0,0 @@
1
- import { a as CoinListClient, O as OauthClientErrorReason } from '../../coinlist-client-Cah5c_aF.cjs';
2
- import { a as OfferDetail, b as OfferId } from '../../requirement-XWT0T_zO.cjs';
3
- export { L as LoadOffersReason, a as LoadOffersState, b as LoadRequirementsReason, c as LoadRequirementsState, U as UseCoinListOffersOptions, d as UseCoinListOffersResult, e as UseCoinListRequirementsOptions, f as UseCoinListRequirementsResult, u as useCoinListOffers, g as useCoinListRequirements } from '../../useCoinListRequirements-Cuc32Tqw.cjs';
4
- import { A as AuthorizationCode, c as CodeVerifier, j as Participation } from '../../participation-DMMEDxON.cjs';
5
-
6
- interface UseCoinListResult {
7
- /**
8
- * Indicates whether the CoinList client has been initialized and ready to use.
9
- * While isReady is false, then the current user state will be `unknown`.
10
- */
11
- isReady: boolean;
12
- coinlist: CoinListClient;
13
- }
14
- declare function useCoinList(): UseCoinListResult;
15
-
16
- type LoadOfferDetailsReason = 'not-authenticated' | 'generic-error';
17
- type LoadOfferDetailsState = {
18
- type: 'LOADING';
19
- } | {
20
- type: 'ERROR';
21
- reason: LoadOfferDetailsReason;
22
- } | {
23
- type: 'CONTENT';
24
- offerDetail: OfferDetail;
25
- };
26
- interface UseCoinListOfferDetailsOptions {
27
- /**
28
- * Offer detail pre-fetched on the server (e.g. via `CoinListServer.fetchOfferDetails()`).
29
- * When provided, the hook uses this data as-is and skips the client-side fetch entirely.
30
- */
31
- serverData?: OfferDetail;
32
- }
33
- interface UseCoinListOfferDetailsResult {
34
- offerDetailsState: LoadOfferDetailsState;
35
- }
36
- /**
37
- * Loads CoinList offer details for a given offer id and exposes a UI-friendly state.
38
- *
39
- * Pass `serverData` (pre-fetched server-side) to use that data as-is and skip
40
- * the client-side fetch entirely.
41
- *
42
- * Returns `LOADING` while CoinList is initializing or while details are being fetched.
43
- * Returns `CONTENT` with the offer when `fetchOfferDetails()` succeeds.
44
- * Returns `ERROR` with:
45
- * - `not-authenticated` when fetching fails with {@link NotAuthenticatedError}
46
- * - `generic-error` for any other failure
47
- */
48
- declare function useCoinListOfferDetails(offerId: OfferId, options?: UseCoinListOfferDetailsOptions): UseCoinListOfferDetailsResult;
49
-
50
- /**
51
- * Reasons passed to {@link UseCompleteCoinListOAuthOptions.onFailure} when the
52
- * OAuth callback cannot be completed. Includes PKCE / redirect validation
53
- * errors from {@link CoinListClient.completeOAuth} and a dedicated value when
54
- * {@link UseCompleteCoinListOAuthOptions.postOAuthComplete} fails or rejects.
55
- */
56
- type CompleteCoinListOAuthFailureReason = OauthClientErrorReason | 'complete_request_failed';
57
- interface UseCompleteCoinListOAuthOptions {
58
- /**
59
- * Exchange the authorization code on your backend (e.g. POST to your API).
60
- * Return `true` when the session was established successfully, `false` when
61
- * the request completed but signing in failed. Rejections are treated like
62
- * `false` and reported as {@link CompleteCoinListOAuthFailureReason}
63
- * `"complete_request_failed"`.
64
- */
65
- postOAuthComplete: (payload: {
66
- code: AuthorizationCode;
67
- codeVerifier: CodeVerifier;
68
- }) => Promise<boolean>;
69
- /**
70
- * Called when the user denied access (`error` query parameter), when
71
- * {@link CoinListClient.completeOAuth} fails PKCE/state validation, or when
72
- * {@link UseCompleteCoinListOAuthOptions.postOAuthComplete} fails.
73
- */
74
- onFailure: (reason: CompleteCoinListOAuthFailureReason) => void | Promise<void>;
75
- /** Invoked after {@link UseCompleteCoinListOAuthOptions.postOAuthComplete} succeeds and {@link CoinListClient.init} has refreshed the client session. */
76
- onSuccess: () => void | Promise<void>;
77
- }
78
- /**
79
- * Runs the CoinList OAuth callback once on mount: validates the redirect URL via
80
- * {@link CoinListClient.completeOAuth}, exchanges the code via {@link UseCompleteCoinListOAuthOptions.postOAuthComplete},
81
- * refreshes tokens with {@link CoinListClient.init}, then calls {@link UseCompleteCoinListOAuthOptions.onSuccess}.
82
- *
83
- * Framework-agnostic: reads `window.location` like {@link CoinListClient.completeOAuth}. Supply
84
- * {@link UseCompleteCoinListOAuthOptions.postOAuthComplete}, {@link UseCompleteCoinListOAuthOptions.onFailure},
85
- * and {@link UseCompleteCoinListOAuthOptions.onSuccess} to perform redirects or routing in your app.
86
- *
87
- * Must be used within {@link CoinListProvider}.
88
- */
89
- declare function useCompleteCoinListOAuth(options: UseCompleteCoinListOAuthOptions): void;
90
-
91
- type LoadParticipationsReason = 'not-authenticated' | 'generic-error';
92
- type LoadParticipationsState = {
93
- type: 'LOADING';
94
- } | {
95
- type: 'ERROR';
96
- reason: LoadParticipationsReason;
97
- } | {
98
- type: 'CONTENT';
99
- participations: Participation[];
100
- };
101
- interface UseParticipationsOptions {
102
- /**
103
- * Participations pre-fetched on the server (e.g. via `CoinListServer.fetchAllParticipations()`).
104
- * When provided, the hook uses this data as-is and skips the client-side fetch entirely.
105
- */
106
- serverData?: Participation[];
107
- }
108
- interface UseParticipationsResult {
109
- participationsState: LoadParticipationsState;
110
- }
111
- /**
112
- * Loads all CoinList participations for the current user and exposes a UI-friendly state.
113
- * Optionally filters by offer when `offerId` is provided.
114
- *
115
- * Pass `serverData` (pre-fetched server-side) to use that data as-is and skip
116
- * the client-side fetch entirely.
117
- *
118
- * Returns `LOADING` while CoinList is initializing or while participations are being fetched.
119
- * Returns `CONTENT` with all participations when `fetchAllParticipations()` succeeds.
120
- * Returns `ERROR` with:
121
- * - `not-authenticated` when fetching fails with {@link NotAuthenticatedError}
122
- * - `generic-error` for any other failure
123
- */
124
- declare function useParticipations(offerId?: OfferId, options?: UseParticipationsOptions): UseParticipationsResult;
125
-
126
- export { type CompleteCoinListOAuthFailureReason, type LoadOfferDetailsReason, type LoadOfferDetailsState, type LoadParticipationsReason, type LoadParticipationsState, type UseCoinListOfferDetailsOptions, type UseCoinListOfferDetailsResult, type UseCompleteCoinListOAuthOptions, type UseParticipationsOptions, type UseParticipationsResult, useCoinList, useCoinListOfferDetails, useCompleteCoinListOAuth, useParticipations };
@@ -1,126 +0,0 @@
1
- import { a as CoinListClient, O as OauthClientErrorReason } from '../../coinlist-client-BSxpqylo.js';
2
- import { a as OfferDetail, b as OfferId } from '../../requirement-XWT0T_zO.js';
3
- export { L as LoadOffersReason, a as LoadOffersState, b as LoadRequirementsReason, c as LoadRequirementsState, U as UseCoinListOffersOptions, d as UseCoinListOffersResult, e as UseCoinListRequirementsOptions, f as UseCoinListRequirementsResult, u as useCoinListOffers, g as useCoinListRequirements } from '../../useCoinListRequirements-B5-ZPOMz.js';
4
- import { A as AuthorizationCode, c as CodeVerifier, j as Participation } from '../../participation-E-bT-GXJ.js';
5
-
6
- interface UseCoinListResult {
7
- /**
8
- * Indicates whether the CoinList client has been initialized and ready to use.
9
- * While isReady is false, then the current user state will be `unknown`.
10
- */
11
- isReady: boolean;
12
- coinlist: CoinListClient;
13
- }
14
- declare function useCoinList(): UseCoinListResult;
15
-
16
- type LoadOfferDetailsReason = 'not-authenticated' | 'generic-error';
17
- type LoadOfferDetailsState = {
18
- type: 'LOADING';
19
- } | {
20
- type: 'ERROR';
21
- reason: LoadOfferDetailsReason;
22
- } | {
23
- type: 'CONTENT';
24
- offerDetail: OfferDetail;
25
- };
26
- interface UseCoinListOfferDetailsOptions {
27
- /**
28
- * Offer detail pre-fetched on the server (e.g. via `CoinListServer.fetchOfferDetails()`).
29
- * When provided, the hook uses this data as-is and skips the client-side fetch entirely.
30
- */
31
- serverData?: OfferDetail;
32
- }
33
- interface UseCoinListOfferDetailsResult {
34
- offerDetailsState: LoadOfferDetailsState;
35
- }
36
- /**
37
- * Loads CoinList offer details for a given offer id and exposes a UI-friendly state.
38
- *
39
- * Pass `serverData` (pre-fetched server-side) to use that data as-is and skip
40
- * the client-side fetch entirely.
41
- *
42
- * Returns `LOADING` while CoinList is initializing or while details are being fetched.
43
- * Returns `CONTENT` with the offer when `fetchOfferDetails()` succeeds.
44
- * Returns `ERROR` with:
45
- * - `not-authenticated` when fetching fails with {@link NotAuthenticatedError}
46
- * - `generic-error` for any other failure
47
- */
48
- declare function useCoinListOfferDetails(offerId: OfferId, options?: UseCoinListOfferDetailsOptions): UseCoinListOfferDetailsResult;
49
-
50
- /**
51
- * Reasons passed to {@link UseCompleteCoinListOAuthOptions.onFailure} when the
52
- * OAuth callback cannot be completed. Includes PKCE / redirect validation
53
- * errors from {@link CoinListClient.completeOAuth} and a dedicated value when
54
- * {@link UseCompleteCoinListOAuthOptions.postOAuthComplete} fails or rejects.
55
- */
56
- type CompleteCoinListOAuthFailureReason = OauthClientErrorReason | 'complete_request_failed';
57
- interface UseCompleteCoinListOAuthOptions {
58
- /**
59
- * Exchange the authorization code on your backend (e.g. POST to your API).
60
- * Return `true` when the session was established successfully, `false` when
61
- * the request completed but signing in failed. Rejections are treated like
62
- * `false` and reported as {@link CompleteCoinListOAuthFailureReason}
63
- * `"complete_request_failed"`.
64
- */
65
- postOAuthComplete: (payload: {
66
- code: AuthorizationCode;
67
- codeVerifier: CodeVerifier;
68
- }) => Promise<boolean>;
69
- /**
70
- * Called when the user denied access (`error` query parameter), when
71
- * {@link CoinListClient.completeOAuth} fails PKCE/state validation, or when
72
- * {@link UseCompleteCoinListOAuthOptions.postOAuthComplete} fails.
73
- */
74
- onFailure: (reason: CompleteCoinListOAuthFailureReason) => void | Promise<void>;
75
- /** Invoked after {@link UseCompleteCoinListOAuthOptions.postOAuthComplete} succeeds and {@link CoinListClient.init} has refreshed the client session. */
76
- onSuccess: () => void | Promise<void>;
77
- }
78
- /**
79
- * Runs the CoinList OAuth callback once on mount: validates the redirect URL via
80
- * {@link CoinListClient.completeOAuth}, exchanges the code via {@link UseCompleteCoinListOAuthOptions.postOAuthComplete},
81
- * refreshes tokens with {@link CoinListClient.init}, then calls {@link UseCompleteCoinListOAuthOptions.onSuccess}.
82
- *
83
- * Framework-agnostic: reads `window.location` like {@link CoinListClient.completeOAuth}. Supply
84
- * {@link UseCompleteCoinListOAuthOptions.postOAuthComplete}, {@link UseCompleteCoinListOAuthOptions.onFailure},
85
- * and {@link UseCompleteCoinListOAuthOptions.onSuccess} to perform redirects or routing in your app.
86
- *
87
- * Must be used within {@link CoinListProvider}.
88
- */
89
- declare function useCompleteCoinListOAuth(options: UseCompleteCoinListOAuthOptions): void;
90
-
91
- type LoadParticipationsReason = 'not-authenticated' | 'generic-error';
92
- type LoadParticipationsState = {
93
- type: 'LOADING';
94
- } | {
95
- type: 'ERROR';
96
- reason: LoadParticipationsReason;
97
- } | {
98
- type: 'CONTENT';
99
- participations: Participation[];
100
- };
101
- interface UseParticipationsOptions {
102
- /**
103
- * Participations pre-fetched on the server (e.g. via `CoinListServer.fetchAllParticipations()`).
104
- * When provided, the hook uses this data as-is and skips the client-side fetch entirely.
105
- */
106
- serverData?: Participation[];
107
- }
108
- interface UseParticipationsResult {
109
- participationsState: LoadParticipationsState;
110
- }
111
- /**
112
- * Loads all CoinList participations for the current user and exposes a UI-friendly state.
113
- * Optionally filters by offer when `offerId` is provided.
114
- *
115
- * Pass `serverData` (pre-fetched server-side) to use that data as-is and skip
116
- * the client-side fetch entirely.
117
- *
118
- * Returns `LOADING` while CoinList is initializing or while participations are being fetched.
119
- * Returns `CONTENT` with all participations when `fetchAllParticipations()` succeeds.
120
- * Returns `ERROR` with:
121
- * - `not-authenticated` when fetching fails with {@link NotAuthenticatedError}
122
- * - `generic-error` for any other failure
123
- */
124
- declare function useParticipations(offerId?: OfferId, options?: UseParticipationsOptions): UseParticipationsResult;
125
-
126
- export { type CompleteCoinListOAuthFailureReason, type LoadOfferDetailsReason, type LoadOfferDetailsState, type LoadParticipationsReason, type LoadParticipationsState, type UseCoinListOfferDetailsOptions, type UseCoinListOfferDetailsResult, type UseCompleteCoinListOAuthOptions, type UseParticipationsOptions, type UseParticipationsResult, useCoinList, useCoinListOfferDetails, useCompleteCoinListOAuth, useParticipations };
@@ -1,19 +0,0 @@
1
- import {
2
- useCoinList,
3
- useCoinListOfferDetails,
4
- useCoinListOffers,
5
- useCoinListRequirements,
6
- useCompleteCoinListOAuth,
7
- useParticipations
8
- } from "../../chunk-UGJUTRXC.js";
9
- import "../../chunk-RIFATQB5.js";
10
- import "../../chunk-NC45IO63.js";
11
- export {
12
- useCoinList,
13
- useCoinListOfferDetails,
14
- useCoinListOffers,
15
- useCoinListRequirements,
16
- useCompleteCoinListOAuth,
17
- useParticipations
18
- };
19
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,158 +0,0 @@
1
- import { A as AuthorizationCode, c as CodeVerifier, o as Config, O as OAuthAccessToken, i as PaginationParams, P as PaginatedResponse, j as Participation, m as ParticipationsPaginationParams, k as ParticipationId, d as CreateParticipationParams } from './participation-E-bT-GXJ.js';
2
- import { O as Offer, b as OfferId, a as OfferDetail, d as OfferOptionId, R as Requirement, h as RequirementStatusInfo } from './requirement-XWT0T_zO.js';
3
-
4
- type AuthState = 'unknown' | 'logged-in' | 'logged-out';
5
- /** Discriminated error reasons from {@link CoinListClient.completeOAuth}. */
6
- type OauthClientErrorReason = 'user_canceled' | 'missing_state' | 'invalid_state' | 'missing_code' | 'missing_code_verifier';
7
- type OauthClientResult = {
8
- type: 'ok';
9
- code: AuthorizationCode;
10
- codeVerifier: CodeVerifier;
11
- } | {
12
- type: 'error';
13
- reason: OauthClientErrorReason;
14
- };
15
-
16
- interface ClientConfig extends Config {
17
- /**
18
- * The SDK user must provide this function. It is responsible for fetching a
19
- * valid {@link OAuthAccessToken}, or **null** for logged-out users. If your
20
- * backend is in TypeScript, it is recommended to use
21
- * {@link CoinListServer#accessToken} from `@/server/coinlist.server`.
22
- */
23
- getAccessToken: () => Promise<OAuthAccessToken | null>;
24
- /**
25
- * Recommended to leave undefined. Used to change the CoinList environment;
26
- * default is production.
27
- */
28
- coinlistBaseUrl?: string;
29
- }
30
- interface CoinListClient {
31
- /**
32
- * Calls the provided {@link ClientConfig.getAccessToken} lambda to determine
33
- * the user's {@link AuthState}. This is called automatically by {@link CoinListProvider};
34
- * you typically do not need to call it yourself unless you are using the client
35
- * outside of the provider.
36
- */
37
- init(): Promise<AuthState>;
38
- /**
39
- * Returns the current auth state: `'logged-in'`, `'logged-out'`, or `'unknown'`.
40
- * Returns **unknown** until {@link CoinListClient.init} has completed. It is
41
- * recommended to use the `const { isReady, coinlist } = useCoinList()` hook to know when
42
- * the SDK has initialized, or to manually await {@link CoinListClient.init}
43
- * before relying on this value.
44
- */
45
- getAuthState(): AuthState;
46
- /**
47
- * Starts the OAuth flow with PKCE. Generates a random `state` and `code_verifier`,
48
- * stores them in sessionStorage (for validation in {@link CoinListClient.completeOAuth}
49
- * on redirect), then redirects the user to the CoinList authorization page. After
50
- * the user authorizes, they are sent back to your application's redirect URI; call
51
- * {@link CoinListClient.completeOAuth} on that page to finish the flow.
52
- */
53
- startOAuth(): Promise<void>;
54
- /**
55
- * Completes the OAuth flow on the FE with PKCE and state validation. Parses the
56
- * redirect URL (state, code) and validates them against sessionStorage
57
- * (state, code_verifier). The state check protects against CSRF (cross-site
58
- * request forgery). Call this on the frontend page the user is redirected
59
- * to after authorizing.
60
- *
61
- * On `ok`: Call your backend to exchange the short-lived `authorizationCode`
62
- * (and the returned `codeVerifier`) for a long-lived session. If your backend
63
- * is in TypeScript, you can use {@link CoinListServer#completeOAuth} from
64
- * `@/server/coinlist.server` (CoinListServer) to perform that exchange.
65
- *
66
- * 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.
67
- */
68
- completeOAuth(): OauthClientResult;
69
- /**
70
- * Clears the in-memory access token. Note: you need to manually
71
- * also logout on the backend via CoinListServer#logout to clear the session cookie.
72
- */
73
- logout(): void;
74
- /**
75
- * Fetches all offers by iterating through every paginated response.
76
- *
77
- * This method must be called only when the user's {@link AuthState} is
78
- * `'logged-in'`. If the user is not authenticated, it throws
79
- * {@link NotAuthenticatedError}.
80
- */
81
- fetchAllOffers(): Promise<Offer[]>;
82
- /**
83
- * Fetches a single page of offers.
84
- *
85
- * This method must be called only when the user's {@link AuthState} is
86
- * `'logged-in'`. If the user is not authenticated, it throws
87
- * {@link NotAuthenticatedError}.
88
- */
89
- fetchOffersPage(params: PaginationParams): Promise<PaginatedResponse<Offer>>;
90
- /**
91
- * Fetches details for a given offer by its id.
92
- *
93
- * This method must be called only when the user's {@link AuthState} is
94
- * `'logged-in'`. If the user is not authenticated, it throws
95
- * {@link NotAuthenticatedError}.
96
- */
97
- fetchOfferDetails(id: OfferId): Promise<OfferDetail>;
98
- /**
99
- * Fetches all participations by iterating through every paginated response.
100
- *
101
- * This method must be called only when the user's {@link AuthState} is
102
- * `'logged-in'`. If the user is not authenticated, it throws
103
- * {@link NotAuthenticatedError}.
104
- */
105
- fetchAllParticipations(offerId?: OfferId): Promise<Participation[]>;
106
- /**
107
- * Fetches a single page of participations, optionally filtered by offer.
108
- *
109
- * This method must be called only when the user's {@link AuthState} is
110
- * `'logged-in'`. If the user is not authenticated, it throws
111
- * {@link NotAuthenticatedError}.
112
- */
113
- fetchParticipationsPage(params: ParticipationsPaginationParams): Promise<PaginatedResponse<Participation>>;
114
- /**
115
- * Fetches a participation by id.
116
- *
117
- * This method must be called only when the user's {@link AuthState} is
118
- * `'logged-in'`. If the user is not authenticated, it throws
119
- * {@link NotAuthenticatedError}.
120
- */
121
- fetchParticipation(id: ParticipationId): Promise<Participation>;
122
- /**
123
- * Creates a participation.
124
- *
125
- * This method must be called only when the user's {@link AuthState} is
126
- * `'logged-in'`. If the user is not authenticated, it throws
127
- * {@link NotAuthenticatedError}.
128
- */
129
- createParticipation(params: CreateParticipationParams): Promise<Participation>;
130
- /**
131
- * Fetches the requirements for all options of a given offer, grouped by option ID.
132
- *
133
- * This method must be called only when the user's {@link AuthState} is
134
- * `'logged-in'`. If the user is not authenticated, it throws
135
- * {@link NotAuthenticatedError}.
136
- */
137
- fetchOfferRequirements(offerId: OfferId): Promise<Record<OfferOptionId, Requirement[]>>;
138
- /**
139
- * Fetches the user's requirement statuses for a given offer.
140
- *
141
- * This method must be called only when the user's {@link AuthState} is
142
- * `'logged-in'`. If the user is not authenticated, it throws
143
- * {@link NotAuthenticatedError}.
144
- */
145
- fetchRequirementStatuses(offerId: OfferId): Promise<RequirementStatusInfo[]>;
146
- /**
147
- * Opens the CoinList page for completing a given requirement in a new tab.
148
- * For `jurisdiction` requirements there is no CTA, so this is a no-op.
149
- */
150
- handleRequirement(requirement: Requirement): void;
151
- /**
152
- * Opens the CoinList support ticket page in a new tab.
153
- */
154
- contactSupport(): void;
155
- }
156
- declare function createCoinListClient(config: ClientConfig): CoinListClient;
157
-
158
- export { type AuthState as A, type ClientConfig as C, type OauthClientErrorReason as O, type CoinListClient as a, type OauthClientResult as b, createCoinListClient as c };
@@ -1,158 +0,0 @@
1
- import { A as AuthorizationCode, c as CodeVerifier, o as Config, O as OAuthAccessToken, i as PaginationParams, P as PaginatedResponse, j as Participation, m as ParticipationsPaginationParams, k as ParticipationId, d as CreateParticipationParams } from './participation-DMMEDxON.cjs';
2
- import { O as Offer, b as OfferId, a as OfferDetail, d as OfferOptionId, R as Requirement, h as RequirementStatusInfo } from './requirement-XWT0T_zO.cjs';
3
-
4
- type AuthState = 'unknown' | 'logged-in' | 'logged-out';
5
- /** Discriminated error reasons from {@link CoinListClient.completeOAuth}. */
6
- type OauthClientErrorReason = 'user_canceled' | 'missing_state' | 'invalid_state' | 'missing_code' | 'missing_code_verifier';
7
- type OauthClientResult = {
8
- type: 'ok';
9
- code: AuthorizationCode;
10
- codeVerifier: CodeVerifier;
11
- } | {
12
- type: 'error';
13
- reason: OauthClientErrorReason;
14
- };
15
-
16
- interface ClientConfig extends Config {
17
- /**
18
- * The SDK user must provide this function. It is responsible for fetching a
19
- * valid {@link OAuthAccessToken}, or **null** for logged-out users. If your
20
- * backend is in TypeScript, it is recommended to use
21
- * {@link CoinListServer#accessToken} from `@/server/coinlist.server`.
22
- */
23
- getAccessToken: () => Promise<OAuthAccessToken | null>;
24
- /**
25
- * Recommended to leave undefined. Used to change the CoinList environment;
26
- * default is production.
27
- */
28
- coinlistBaseUrl?: string;
29
- }
30
- interface CoinListClient {
31
- /**
32
- * Calls the provided {@link ClientConfig.getAccessToken} lambda to determine
33
- * the user's {@link AuthState}. This is called automatically by {@link CoinListProvider};
34
- * you typically do not need to call it yourself unless you are using the client
35
- * outside of the provider.
36
- */
37
- init(): Promise<AuthState>;
38
- /**
39
- * Returns the current auth state: `'logged-in'`, `'logged-out'`, or `'unknown'`.
40
- * Returns **unknown** until {@link CoinListClient.init} has completed. It is
41
- * recommended to use the `const { isReady, coinlist } = useCoinList()` hook to know when
42
- * the SDK has initialized, or to manually await {@link CoinListClient.init}
43
- * before relying on this value.
44
- */
45
- getAuthState(): AuthState;
46
- /**
47
- * Starts the OAuth flow with PKCE. Generates a random `state` and `code_verifier`,
48
- * stores them in sessionStorage (for validation in {@link CoinListClient.completeOAuth}
49
- * on redirect), then redirects the user to the CoinList authorization page. After
50
- * the user authorizes, they are sent back to your application's redirect URI; call
51
- * {@link CoinListClient.completeOAuth} on that page to finish the flow.
52
- */
53
- startOAuth(): Promise<void>;
54
- /**
55
- * Completes the OAuth flow on the FE with PKCE and state validation. Parses the
56
- * redirect URL (state, code) and validates them against sessionStorage
57
- * (state, code_verifier). The state check protects against CSRF (cross-site
58
- * request forgery). Call this on the frontend page the user is redirected
59
- * to after authorizing.
60
- *
61
- * On `ok`: Call your backend to exchange the short-lived `authorizationCode`
62
- * (and the returned `codeVerifier`) for a long-lived session. If your backend
63
- * is in TypeScript, you can use {@link CoinListServer#completeOAuth} from
64
- * `@/server/coinlist.server` (CoinListServer) to perform that exchange.
65
- *
66
- * 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.
67
- */
68
- completeOAuth(): OauthClientResult;
69
- /**
70
- * Clears the in-memory access token. Note: you need to manually
71
- * also logout on the backend via CoinListServer#logout to clear the session cookie.
72
- */
73
- logout(): void;
74
- /**
75
- * Fetches all offers by iterating through every paginated response.
76
- *
77
- * This method must be called only when the user's {@link AuthState} is
78
- * `'logged-in'`. If the user is not authenticated, it throws
79
- * {@link NotAuthenticatedError}.
80
- */
81
- fetchAllOffers(): Promise<Offer[]>;
82
- /**
83
- * Fetches a single page of offers.
84
- *
85
- * This method must be called only when the user's {@link AuthState} is
86
- * `'logged-in'`. If the user is not authenticated, it throws
87
- * {@link NotAuthenticatedError}.
88
- */
89
- fetchOffersPage(params: PaginationParams): Promise<PaginatedResponse<Offer>>;
90
- /**
91
- * Fetches details for a given offer by its id.
92
- *
93
- * This method must be called only when the user's {@link AuthState} is
94
- * `'logged-in'`. If the user is not authenticated, it throws
95
- * {@link NotAuthenticatedError}.
96
- */
97
- fetchOfferDetails(id: OfferId): Promise<OfferDetail>;
98
- /**
99
- * Fetches all participations by iterating through every paginated response.
100
- *
101
- * This method must be called only when the user's {@link AuthState} is
102
- * `'logged-in'`. If the user is not authenticated, it throws
103
- * {@link NotAuthenticatedError}.
104
- */
105
- fetchAllParticipations(offerId?: OfferId): Promise<Participation[]>;
106
- /**
107
- * Fetches a single page of participations, optionally filtered by offer.
108
- *
109
- * This method must be called only when the user's {@link AuthState} is
110
- * `'logged-in'`. If the user is not authenticated, it throws
111
- * {@link NotAuthenticatedError}.
112
- */
113
- fetchParticipationsPage(params: ParticipationsPaginationParams): Promise<PaginatedResponse<Participation>>;
114
- /**
115
- * Fetches a participation by id.
116
- *
117
- * This method must be called only when the user's {@link AuthState} is
118
- * `'logged-in'`. If the user is not authenticated, it throws
119
- * {@link NotAuthenticatedError}.
120
- */
121
- fetchParticipation(id: ParticipationId): Promise<Participation>;
122
- /**
123
- * Creates a participation.
124
- *
125
- * This method must be called only when the user's {@link AuthState} is
126
- * `'logged-in'`. If the user is not authenticated, it throws
127
- * {@link NotAuthenticatedError}.
128
- */
129
- createParticipation(params: CreateParticipationParams): Promise<Participation>;
130
- /**
131
- * Fetches the requirements for all options of a given offer, grouped by option ID.
132
- *
133
- * This method must be called only when the user's {@link AuthState} is
134
- * `'logged-in'`. If the user is not authenticated, it throws
135
- * {@link NotAuthenticatedError}.
136
- */
137
- fetchOfferRequirements(offerId: OfferId): Promise<Record<OfferOptionId, Requirement[]>>;
138
- /**
139
- * Fetches the user's requirement statuses for a given offer.
140
- *
141
- * This method must be called only when the user's {@link AuthState} is
142
- * `'logged-in'`. If the user is not authenticated, it throws
143
- * {@link NotAuthenticatedError}.
144
- */
145
- fetchRequirementStatuses(offerId: OfferId): Promise<RequirementStatusInfo[]>;
146
- /**
147
- * Opens the CoinList page for completing a given requirement in a new tab.
148
- * For `jurisdiction` requirements there is no CTA, so this is a no-op.
149
- */
150
- handleRequirement(requirement: Requirement): void;
151
- /**
152
- * Opens the CoinList support ticket page in a new tab.
153
- */
154
- contactSupport(): void;
155
- }
156
- declare function createCoinListClient(config: ClientConfig): CoinListClient;
157
-
158
- export { type AuthState as A, type ClientConfig as C, type OauthClientErrorReason as O, type CoinListClient as a, type OauthClientResult as b, createCoinListClient as c };