@quiltt/react 4.5.1 → 5.0.1

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 (91) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +15 -3
  3. package/dist/components/QuilttProviderRender-12s-pvnc98Lj.cjs +6 -0
  4. package/dist/components/QuilttSettings-12s-cLPT_GLC.cjs +6 -0
  5. package/dist/components/index.cjs +211 -0
  6. package/dist/components/index.d.ts +55 -0
  7. package/dist/components/index.js +208 -0
  8. package/dist/components/useQuilttConnector-12s-BLTzI3gE.cjs +174 -0
  9. package/dist/components/useQuilttConnector-12s-UQQcvQrO.js +174 -0
  10. package/dist/components/useQuilttRenderGuard-12s-D9WbRzZO.cjs +36 -0
  11. package/dist/components/useQuilttSession-12s-BjyJL1qZ.cjs +133 -0
  12. package/dist/components/useQuilttSession-12s-VOH0S5zh.js +133 -0
  13. package/dist/components/useQuilttSettings-12s-aDLXY6z3.cjs +10 -0
  14. package/dist/components/useScript-12s-CMIDUHrx.cjs +92 -0
  15. package/dist/{useSession-12s-7GOn4sUn.js → components/useSession-12s-BNPsfKY-.js} +28 -7
  16. package/dist/components/useSession-12s-BNotXj5T.cjs +90 -0
  17. package/dist/{useStorage-12s-DHcq3Kuh.js → components/useStorage-12s-CpG6X57D.js} +7 -17
  18. package/dist/components/useStorage-12s-D7nllsrI.cjs +61 -0
  19. package/dist/contexts/QuilttSettings-12s-BK-0SQME.js +6 -0
  20. package/dist/contexts/QuilttSettings-12s-cLPT_GLC.cjs +6 -0
  21. package/dist/contexts/index.cjs +7 -0
  22. package/dist/contexts/index.d.ts +8 -0
  23. package/dist/contexts/index.js +1 -0
  24. package/dist/hooks/QuilttProviderRender-12s-DtQtubjL.js +6 -0
  25. package/dist/hooks/QuilttProviderRender-12s-pvnc98Lj.cjs +6 -0
  26. package/dist/hooks/QuilttSettings-12s-BK-0SQME.js +6 -0
  27. package/dist/hooks/QuilttSettings-12s-cLPT_GLC.cjs +6 -0
  28. package/dist/hooks/index.cjs +31 -0
  29. package/dist/hooks/index.d.ts +142 -0
  30. package/dist/hooks/index.js +11 -0
  31. package/dist/hooks/useEventListener-12s-CV8cLxWu.cjs +34 -0
  32. package/dist/hooks/useIsomorphicLayoutEffect-12s-B8KjaroI.cjs +9 -0
  33. package/dist/{useQuilttClient-12s-CAAUait1.js → hooks/useQuilttClient-12s-Dj_MtYTU.js} +1 -1
  34. package/dist/hooks/useQuilttClient-12s-flQYSVdG.cjs +6 -0
  35. package/dist/{useQuilttConnector-12s-D8VedbrT.js → hooks/useQuilttConnector-12s-C0KJHuZN.js} +5 -4
  36. package/dist/hooks/useQuilttConnector-12s-D51PZPgm.cjs +175 -0
  37. package/dist/hooks/useQuilttInstitutions-12s-D_Kr43s3.cjs +82 -0
  38. package/dist/{useQuilttInstitutions-12s-DExzPnfb.js → hooks/useQuilttInstitutions-12s-rgLHD9ye.js} +6 -16
  39. package/dist/hooks/useQuilttRenderGuard-12s-CsS2Ma6Q.js +36 -0
  40. package/dist/hooks/useQuilttRenderGuard-12s-D9WbRzZO.cjs +36 -0
  41. package/dist/{useQuilttResolvable-12s-C0BV3AvR.js → hooks/useQuilttResolvable-12s-BUDeH696.js} +6 -16
  42. package/dist/hooks/useQuilttResolvable-12s-D8wnfNBt.cjs +76 -0
  43. package/dist/hooks/useQuilttSession-12s-C8kq5S2Y.cjs +139 -0
  44. package/dist/hooks/useQuilttSession-12s-DQFfjmob.js +135 -0
  45. package/dist/hooks/useQuilttSettings-12s--rCJoNHD.js +10 -0
  46. package/dist/hooks/useQuilttSettings-12s-aDLXY6z3.cjs +10 -0
  47. package/dist/hooks/useScript-12s-CMIDUHrx.cjs +92 -0
  48. package/dist/hooks/useScript-12s-JCgaTW9n.js +92 -0
  49. package/dist/hooks/useSession-12s-BNPsfKY-.js +90 -0
  50. package/dist/hooks/useSession-12s-BNotXj5T.cjs +90 -0
  51. package/dist/hooks/useStorage-12s-CpG6X57D.js +61 -0
  52. package/dist/hooks/useStorage-12s-D7nllsrI.cjs +61 -0
  53. package/dist/index.cjs +149 -0
  54. package/dist/index.d.ts +7 -216
  55. package/dist/index.js +7 -191
  56. package/dist/providers/QuilttAuthProvider-12s-CDgQbarX.js +60 -0
  57. package/dist/providers/QuilttAuthProvider-12s-D__FY1Qn.cjs +60 -0
  58. package/dist/providers/QuilttProviderRender-12s-DtQtubjL.js +6 -0
  59. package/dist/providers/QuilttProviderRender-12s-pvnc98Lj.cjs +6 -0
  60. package/dist/providers/QuilttSettings-12s-BK-0SQME.js +6 -0
  61. package/dist/providers/QuilttSettings-12s-cLPT_GLC.cjs +6 -0
  62. package/dist/providers/QuilttSettingsProvider-12s-D7e8dsOE.cjs +19 -0
  63. package/dist/{QuilttSettingsProvider-12s-ZcmFmOiZ.js → providers/QuilttSettingsProvider-12s-DND2gPQm.js} +8 -5
  64. package/dist/providers/index.cjs +34 -0
  65. package/dist/providers/index.d.ts +28 -0
  66. package/dist/providers/index.js +30 -0
  67. package/dist/utils/index.cjs +89 -0
  68. package/dist/utils/index.d.ts +31 -0
  69. package/dist/utils/index.js +77 -0
  70. package/package.json +38 -12
  71. package/src/hooks/useQuilttClient.ts +1 -1
  72. package/src/hooks/useQuilttConnector.ts +3 -2
  73. package/src/hooks/useQuilttInstitutions.ts +8 -23
  74. package/src/hooks/useQuilttResolvable.ts +8 -23
  75. package/src/hooks/useSession.ts +32 -6
  76. package/src/hooks/useStorage.ts +7 -15
  77. package/src/index.ts +61 -0
  78. package/src/providers/QuilttAuthProvider.tsx +12 -5
  79. package/src/providers/QuilttProvider.tsx +5 -1
  80. package/src/providers/QuilttSettingsProvider.tsx +4 -5
  81. package/src/utils/index.ts +1 -0
  82. package/src/utils/telemetry.ts +33 -0
  83. package/dist/QuilttAuthProvider-12s-DE-ePRo_.js +0 -205
  84. package/dist/useQuilttSession-12s-sRvULtJv.js +0 -39
  85. /package/dist/{QuilttProviderRender-12s-DtQtubjL.js → components/QuilttProviderRender-12s-DtQtubjL.js} +0 -0
  86. /package/dist/{QuilttSettings-12s-BK-0SQME.js → components/QuilttSettings-12s-BK-0SQME.js} +0 -0
  87. /package/dist/{useQuilttRenderGuard-12s-CsS2Ma6Q.js → components/useQuilttRenderGuard-12s-CsS2Ma6Q.js} +0 -0
  88. /package/dist/{useQuilttSettings-12s--rCJoNHD.js → components/useQuilttSettings-12s--rCJoNHD.js} +0 -0
  89. /package/dist/{useScript-12s-JCgaTW9n.js → components/useScript-12s-JCgaTW9n.js} +0 -0
  90. /package/dist/{useEventListener-12s-D_-6QIXa.js → hooks/useEventListener-12s-D_-6QIXa.js} +0 -0
  91. /package/dist/{useIsomorphicLayoutEffect-12s-DeTHOKz1.js → hooks/useIsomorphicLayoutEffect-12s-DeTHOKz1.js} +0 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,149 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ var client = require('@apollo/client');
4
+ var errors = require('@apollo/client/errors');
5
+ var react = require('@apollo/client/react');
6
+ var react$1 = require('@apollo/client/testing/react');
7
+ var core = require('@quiltt/core');
8
+ var index_cjs = require('./components/index.cjs');
9
+ var index_cjs$1 = require('./hooks/index.cjs');
10
+ var index_cjs$2 = require('./providers/index.cjs');
11
+
12
+
13
+
14
+ Object.defineProperty(exports, "ApolloClient", {
15
+ enumerable: true,
16
+ get: function () { return client.ApolloClient; }
17
+ });
18
+ Object.defineProperty(exports, "InMemoryCache", {
19
+ enumerable: true,
20
+ get: function () { return client.InMemoryCache; }
21
+ });
22
+ Object.defineProperty(exports, "NetworkStatus", {
23
+ enumerable: true,
24
+ get: function () { return client.NetworkStatus; }
25
+ });
26
+ Object.defineProperty(exports, "ObservableQuery", {
27
+ enumerable: true,
28
+ get: function () { return client.ObservableQuery; }
29
+ });
30
+ Object.defineProperty(exports, "gql", {
31
+ enumerable: true,
32
+ get: function () { return client.gql; }
33
+ });
34
+ Object.defineProperty(exports, "CombinedGraphQLErrors", {
35
+ enumerable: true,
36
+ get: function () { return errors.CombinedGraphQLErrors; }
37
+ });
38
+ Object.defineProperty(exports, "CombinedProtocolErrors", {
39
+ enumerable: true,
40
+ get: function () { return errors.CombinedProtocolErrors; }
41
+ });
42
+ Object.defineProperty(exports, "LinkError", {
43
+ enumerable: true,
44
+ get: function () { return errors.LinkError; }
45
+ });
46
+ Object.defineProperty(exports, "LocalStateError", {
47
+ enumerable: true,
48
+ get: function () { return errors.LocalStateError; }
49
+ });
50
+ Object.defineProperty(exports, "ServerError", {
51
+ enumerable: true,
52
+ get: function () { return errors.ServerError; }
53
+ });
54
+ Object.defineProperty(exports, "ServerParseError", {
55
+ enumerable: true,
56
+ get: function () { return errors.ServerParseError; }
57
+ });
58
+ Object.defineProperty(exports, "UnconventionalError", {
59
+ enumerable: true,
60
+ get: function () { return errors.UnconventionalError; }
61
+ });
62
+ Object.defineProperty(exports, "ApolloProvider", {
63
+ enumerable: true,
64
+ get: function () { return react.ApolloProvider; }
65
+ });
66
+ Object.defineProperty(exports, "createQueryPreloader", {
67
+ enumerable: true,
68
+ get: function () { return react.createQueryPreloader; }
69
+ });
70
+ Object.defineProperty(exports, "skipToken", {
71
+ enumerable: true,
72
+ get: function () { return react.skipToken; }
73
+ });
74
+ Object.defineProperty(exports, "useApolloClient", {
75
+ enumerable: true,
76
+ get: function () { return react.useApolloClient; }
77
+ });
78
+ Object.defineProperty(exports, "useBackgroundQuery", {
79
+ enumerable: true,
80
+ get: function () { return react.useBackgroundQuery; }
81
+ });
82
+ Object.defineProperty(exports, "useFragment", {
83
+ enumerable: true,
84
+ get: function () { return react.useFragment; }
85
+ });
86
+ Object.defineProperty(exports, "useLazyQuery", {
87
+ enumerable: true,
88
+ get: function () { return react.useLazyQuery; }
89
+ });
90
+ Object.defineProperty(exports, "useLoadableQuery", {
91
+ enumerable: true,
92
+ get: function () { return react.useLoadableQuery; }
93
+ });
94
+ Object.defineProperty(exports, "useMutation", {
95
+ enumerable: true,
96
+ get: function () { return react.useMutation; }
97
+ });
98
+ Object.defineProperty(exports, "useQuery", {
99
+ enumerable: true,
100
+ get: function () { return react.useQuery; }
101
+ });
102
+ Object.defineProperty(exports, "useQueryRefHandlers", {
103
+ enumerable: true,
104
+ get: function () { return react.useQueryRefHandlers; }
105
+ });
106
+ Object.defineProperty(exports, "useReactiveVar", {
107
+ enumerable: true,
108
+ get: function () { return react.useReactiveVar; }
109
+ });
110
+ Object.defineProperty(exports, "useReadQuery", {
111
+ enumerable: true,
112
+ get: function () { return react.useReadQuery; }
113
+ });
114
+ Object.defineProperty(exports, "useSubscription", {
115
+ enumerable: true,
116
+ get: function () { return react.useSubscription; }
117
+ });
118
+ Object.defineProperty(exports, "useSuspenseQuery", {
119
+ enumerable: true,
120
+ get: function () { return react.useSuspenseQuery; }
121
+ });
122
+ Object.defineProperty(exports, "MockedProvider", {
123
+ enumerable: true,
124
+ get: function () { return react$1.MockedProvider; }
125
+ });
126
+ Object.keys(core).forEach(function (k) {
127
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
128
+ enumerable: true,
129
+ get: function () { return core[k]; }
130
+ });
131
+ });
132
+ Object.keys(index_cjs).forEach(function (k) {
133
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
134
+ enumerable: true,
135
+ get: function () { return index_cjs[k]; }
136
+ });
137
+ });
138
+ Object.keys(index_cjs$1).forEach(function (k) {
139
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
140
+ enumerable: true,
141
+ get: function () { return index_cjs$1[k]; }
142
+ });
143
+ });
144
+ Object.keys(index_cjs$2).forEach(function (k) {
145
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
146
+ enumerable: true,
147
+ get: function () { return index_cjs$2[k]; }
148
+ });
149
+ });
package/dist/index.d.ts CHANGED
@@ -1,217 +1,8 @@
1
- import { ConnectorSDKCallbacks, Maybe, QuilttJWT, PasscodePayload, UnprocessableData, AuthAPI, UsernamePayload, ConnectorSDKConnectorOptions, InstitutionsData, QuilttClient } from '@quiltt/core';
1
+ export { ApolloClient, ApolloQueryResult, DocumentNode, ErrorPolicy, FetchPolicy, InMemoryCache, NetworkStatus, NormalizedCacheObject, ObservableQuery, OperationVariables, TypedDocumentNode, WatchQueryFetchPolicy, gql } from '@apollo/client';
2
+ export { CombinedGraphQLErrors, CombinedProtocolErrors, LinkError, LocalStateError, ServerError, ServerParseError, UnconventionalError } from '@apollo/client/errors';
3
+ export { ApolloProvider, MutationHookOptions, MutationResult, QueryHookOptions, QueryResult, SubscriptionHookOptions, SubscriptionResult, createQueryPreloader, skipToken, useApolloClient, useBackgroundQuery, useFragment, useLazyQuery, useLoadableQuery, useMutation, useQuery, useQueryRefHandlers, useReactiveVar, useReadQuery, useSubscription, useSuspenseQuery } from '@apollo/client/react';
4
+ export { MockedProvider } from '@apollo/client/testing/react';
2
5
  export * from '@quiltt/core';
3
- import * as react_jsx_runtime from 'react/jsx-runtime';
4
- import { JSX, ComponentType, ElementType, PropsWithChildren, MouseEvent, RefObject, useEffect, Dispatch, SetStateAction, FC } from 'react';
5
- import { useApolloClient } from '@apollo/client/react/hooks/useApolloClient.js';
6
-
7
- type PropsOf<Tag> = Tag extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[Tag] : Tag extends ComponentType<infer Props> ? Props & JSX.IntrinsicAttributes : never;
8
-
9
- type BaseQuilttButtonProps<T extends ElementType> = {
10
- as?: T;
11
- connectorId: string;
12
- connectionId?: string;
13
- institution?: string;
14
- /**
15
- * Forces complete remount when connectionId changes.
16
- * Useful as a fallback for ensuring clean state.
17
- * @default false
18
- */
19
- forceRemountOnConnectionChange?: boolean;
20
- onClick?: (event: MouseEvent<HTMLElement>) => void;
21
- };
22
- type QuilttCallbackProps = Omit<ConnectorSDKCallbacks, 'onLoad'> & {
23
- onLoad?: ConnectorSDKCallbacks['onLoad'];
24
- onHtmlLoad?: React.ReactEventHandler<HTMLElement>;
25
- };
26
- type QuilttButtonProps<T extends ElementType> = PropsWithChildren<BaseQuilttButtonProps<T> & QuilttCallbackProps>;
27
- /**
28
- * QuilttButton provides a clickable interface to open Quiltt connectors.
29
- *
30
- * When connectionId changes, the button will automatically update the existing
31
- * connector instance with the new connection details. If you need to force a
32
- * complete remount instead, set forceRemountOnConnectionChange to true.
33
- */
34
- declare const QuilttButton: <T extends ElementType = "button">({ as, connectorId, connectionId, institution, forceRemountOnConnectionChange, onEvent, onOpen, onLoad, onExit, onExitSuccess, onExitAbort, onExitError, onClick, onHtmlLoad, children, ...props }: QuilttButtonProps<T> & PropsOf<T>) => react_jsx_runtime.JSX.Element;
35
-
36
- type QuilttContainerProps<T extends ElementType> = PropsWithChildren<{
37
- as?: T;
38
- connectorId: string;
39
- connectionId?: string;
40
- /**
41
- * Forces complete remount when connectionId changes.
42
- * Useful as a fallback for ensuring clean state.
43
- * @default false
44
- */
45
- forceRemountOnConnectionChange?: boolean;
46
- } & ConnectorSDKCallbacks>;
47
- /**
48
- * QuilttContainer uses globally shared callbacks. It's recommended you only use
49
- * one Container at a time.
50
- *
51
- * When connectionId changes, the container will automatically update the existing
52
- * connector instance with the new connection details. If you need to force a
53
- * complete remount instead, set forceRemountOnConnectionChange to true.
54
- */
55
- declare const QuilttContainer: <T extends ElementType = "div">({ as, connectorId, connectionId, forceRemountOnConnectionChange, onEvent, onLoad, onExit, onExitSuccess, onExitAbort, onExitError, children, ...props }: QuilttContainerProps<T> & PropsOf<T>) => react_jsx_runtime.JSX.Element;
56
-
57
- declare function useEventListener<K extends keyof MediaQueryListEventMap>(eventName: K, handler: (event: MediaQueryListEventMap[K]) => void, element: RefObject<MediaQueryList>, options?: boolean | AddEventListenerOptions): void;
58
- declare function useEventListener<K extends keyof WindowEventMap>(eventName: K, handler: (event: WindowEventMap[K]) => void, element?: undefined, options?: boolean | AddEventListenerOptions): void;
59
- declare function useEventListener<K extends keyof HTMLElementEventMap, T extends HTMLElement = HTMLDivElement>(eventName: K, handler: (event: HTMLElementEventMap[K]) => void, element: RefObject<T>, options?: boolean | AddEventListenerOptions): void;
60
- declare function useEventListener<K extends keyof DocumentEventMap>(eventName: K, handler: (event: DocumentEventMap[K]) => void, element: RefObject<Document>, options?: boolean | AddEventListenerOptions): void;
61
-
62
- /**
63
- * This hook is a browser hook. But React code could be generated from the server without the Window API.
64
- * This hook switches between useEffect and useLayoutEffect following the execution environment.
65
- */
66
- declare const useIsomorphicLayoutEffect: typeof useEffect;
67
-
68
- type SetSession = Dispatch<SetStateAction<Maybe<string> | undefined>>;
69
- /**
70
- * Custom hook to manage JWT session state with automatic expiration handling.
71
- * Provides global singleton access to the session across components and windows.
72
- *
73
- * TODO: Support Rotation before Expiry
74
- *
75
- * Handles two types of data flow:
76
- * 1. Bottom-up (Login): Token passed through setSession callback
77
- * 2. Top-down (Refresh): State reinitialized on page reload
78
- *
79
- * @param storageKey - Key used for storing session in useStorage (defaults to 'session')
80
- * @returns [session, setSession] - Current session state and setter function
81
- */
82
- declare const useSession: (storageKey?: string) => [Maybe<QuilttJWT> | undefined, SetSession];
83
-
84
- type AuthenticateSessionCallbacks = {
85
- onSuccess?: () => unknown;
86
- onFailure?: () => unknown;
87
- onError?: (errors: UnprocessableData) => unknown;
88
- };
89
- type AuthenticateSession = (payload: PasscodePayload, callbacks: AuthenticateSessionCallbacks) => Promise<unknown>;
90
- type UseAuthenticateSession = (auth: AuthAPI, setSession: SetSession) => AuthenticateSession;
91
- declare const useAuthenticateSession: UseAuthenticateSession;
92
-
93
- type IdentifySessionCallbacks = {
94
- onSuccess?: () => unknown;
95
- onChallenged?: () => unknown;
96
- onError?: (errors: UnprocessableData) => unknown;
97
- onForbidden?: () => unknown;
98
- };
99
- type IdentifySession = (payload: UsernamePayload, callbacks: IdentifySessionCallbacks) => Promise<unknown>;
100
- type UseIdentifySession = (auth: AuthAPI, setSession: SetSession) => IdentifySession;
101
- declare const useIdentifySession: UseIdentifySession;
102
-
103
- type ImportSession = (token: string) => Promise<boolean>;
104
- type UseImportSession = (auth: AuthAPI, session: Maybe<QuilttJWT> | undefined, setSession: SetSession, environmentId?: string) => ImportSession;
105
- /**
106
- * Optionally Accepts environmentId to validate session is from with your desired environment
107
- */
108
- declare const useImportSession: UseImportSession;
109
-
110
- type RevokeSession = () => Promise<void>;
111
- type UseRevokeSession = (auth: AuthAPI, session: Maybe<QuilttJWT> | undefined, setSession: SetSession) => RevokeSession;
112
- declare const useRevokeSession: UseRevokeSession;
113
-
114
- declare const useQuilttClient: typeof useApolloClient;
115
-
116
- declare const useQuilttConnector: (connectorId?: string, options?: ConnectorSDKConnectorOptions) => {
117
- open: () => void;
118
- };
119
-
120
- type UseQuilttInstitutions = (connectorId: string, onErrorCallback?: (msg: string) => void) => {
121
- searchTerm: string;
122
- searchResults: InstitutionsData;
123
- isSearching: boolean;
124
- setSearchTerm: (term: string) => void;
125
- };
126
- declare const useQuilttInstitutions: UseQuilttInstitutions;
127
-
128
- /**
129
- * Internal hook that detects when a Quiltt SDK component may be rendered
130
- * in the same component as QuilttProvider, which is an anti-pattern that
131
- * can cause memory context issues and unexpected behavior.
132
- *
133
- * **Limitation**: Due to React context propagation, this will trigger for ALL
134
- * descendants of QuilttProvider, not just direct children. This means it may
135
- * produce false positives for valid nested component patterns. However, the
136
- * primary use case (same-component rendering) is reliably detected.
137
- *
138
- * When the flag is set, this hook will emit a console error. This primarily
139
- * helps catch the anti-pattern but may also flag valid nested structures.
140
- *
141
- * @param componentName - The name of the component calling this hook (for error messages)
142
- */
143
- declare const useQuilttRenderGuard: (componentName: string) => void;
144
-
145
- type UseQuilttResolvable = (connectorId: string, onErrorCallback?: (msg: string) => void) => {
146
- checkResolvable: (providerId: {
147
- plaid?: string;
148
- mock?: string;
149
- mx?: string;
150
- finicity?: string;
151
- akoya?: string;
152
- }) => Promise<boolean | null>;
153
- isLoading: boolean;
154
- isResolvable: boolean | null;
155
- error: string | null;
156
- };
157
- declare const useQuilttResolvable: UseQuilttResolvable;
158
-
159
- type UseQuilttSession = (environmentId?: string) => {
160
- session: Maybe<QuilttJWT> | undefined;
161
- importSession: ImportSession;
162
- identifySession: IdentifySession;
163
- authenticateSession: AuthenticateSession;
164
- revokeSession: RevokeSession;
165
- forgetSession: (token?: string) => Promise<void>;
166
- };
167
- declare const useQuilttSession: UseQuilttSession;
168
-
169
- declare const useQuilttSettings: () => {
170
- clientId?: string;
171
- };
172
-
173
- /**
174
- * Attempt to persist state with local storage, so it remains after refresh and
175
- * across open documents. Falls back to in memory storage when localStorage is
176
- * unavailable.
177
- *
178
- * This hook is used in the same way as useState except that you must pass the
179
- * storage key in the 1st parameter. If the window object is not present (as in SSR),
180
- * useStorage() will return the default nextState.
181
- *
182
- * Expect values to remain in sync
183
- * Across Hooks
184
- * Across Reloads
185
- * Across Windows (Documents)
186
- *
187
- * @param key
188
- * @param initialState
189
- * @returns {Array} [storage, setStorage]
190
- */
191
- declare const useStorage: <T>(key: string, initialState?: Maybe<T>) => [Maybe<T> | undefined, Dispatch<SetStateAction<Maybe<T> | undefined>>];
192
-
193
- type QuilttAuthProviderProps = PropsWithChildren & {
194
- /** A custom QuilttClient instance to use instead of the default */
195
- graphqlClient?: QuilttClient;
196
- /** The Quiltt Session token obtained from the server */
197
- token?: string;
198
- };
199
- /**
200
- * If a token is provided, will validate the token against the api and then import
201
- * it into trusted storage. While this process is happening, the component is put
202
- * into a loading state and the children are not rendered to prevent race conditions
203
- * from triggering within the transitionary state.
204
- */
205
- declare const QuilttAuthProvider: FC<QuilttAuthProviderProps>;
206
-
207
- type QuilttSettingsProviderProps = PropsWithChildren & {
208
- /** The Client ID to use for the passwordless Auth API */
209
- clientId?: string;
210
- };
211
- declare const QuilttSettingsProvider: FC<QuilttSettingsProviderProps>;
212
-
213
- type QuilttProviderProps = QuilttSettingsProviderProps & QuilttAuthProviderProps;
214
- declare const QuilttProvider: FC<QuilttProviderProps>;
215
-
216
- export { QuilttAuthProvider, QuilttButton, QuilttContainer, QuilttProvider, QuilttSettingsProvider, useAuthenticateSession, useEventListener, useIdentifySession, useImportSession, useIsomorphicLayoutEffect, useQuilttClient, useQuilttConnector, useQuilttInstitutions, useQuilttRenderGuard, useQuilttResolvable, useQuilttSession, useQuilttSettings, useRevokeSession, useSession, useStorage };
217
- export type { AuthenticateSession, IdentifySession, ImportSession, QuilttAuthProviderProps, QuilttSettingsProviderProps, RevokeSession, SetSession, UseQuilttInstitutions, UseQuilttResolvable, UseQuilttSession };
6
+ export * from './components/index.js';
7
+ export * from './hooks/index.js';
8
+ export * from './providers/index.js';
package/dist/index.js CHANGED
@@ -1,192 +1,8 @@
1
+ export { ApolloClient, InMemoryCache, NetworkStatus, ObservableQuery, gql } from '@apollo/client';
2
+ export { CombinedGraphQLErrors, CombinedProtocolErrors, LinkError, LocalStateError, ServerError, ServerParseError, UnconventionalError } from '@apollo/client/errors';
3
+ export { ApolloProvider, createQueryPreloader, skipToken, useApolloClient, useBackgroundQuery, useFragment, useLazyQuery, useLoadableQuery, useMutation, useQuery, useQueryRefHandlers, useReactiveVar, useReadQuery, useSubscription, useSuspenseQuery } from '@apollo/client/react';
4
+ export { MockedProvider } from '@apollo/client/testing/react';
1
5
  export * from '@quiltt/core';
2
- import { jsx } from 'react/jsx-runtime';
3
- import { useRef, useEffect } from 'react';
4
- import { u as useQuilttConnector } from './useQuilttConnector-12s-D8VedbrT.js';
5
- import { u as useQuilttRenderGuard } from './useQuilttRenderGuard-12s-CsS2Ma6Q.js';
6
- import { i as isDeepEqual, Q as QuilttAuthProvider } from './QuilttAuthProvider-12s-DE-ePRo_.js';
7
- export { b as useAuthenticateSession, a as useIdentifySession, u as useImportSession, c as useRevokeSession } from './QuilttAuthProvider-12s-DE-ePRo_.js';
8
- export { u as useEventListener } from './useEventListener-12s-D_-6QIXa.js';
9
- export { u as useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect-12s-DeTHOKz1.js';
10
- export { u as useQuilttClient } from './useQuilttClient-12s-CAAUait1.js';
11
- export { u as useQuilttInstitutions } from './useQuilttInstitutions-12s-DExzPnfb.js';
12
- export { u as useQuilttResolvable } from './useQuilttResolvable-12s-C0BV3AvR.js';
13
- export { u as useQuilttSession } from './useQuilttSession-12s-sRvULtJv.js';
14
- export { u as useQuilttSettings } from './useQuilttSettings-12s--rCJoNHD.js';
15
- export { u as useSession } from './useSession-12s-7GOn4sUn.js';
16
- export { u as useStorage } from './useStorage-12s-DHcq3Kuh.js';
17
- import { Q as QuilttProviderRender } from './QuilttProviderRender-12s-DtQtubjL.js';
18
- import { Q as QuilttSettingsProvider } from './QuilttSettingsProvider-12s-ZcmFmOiZ.js';
19
-
20
- /**
21
- * QuilttButton provides a clickable interface to open Quiltt connectors.
22
- *
23
- * When connectionId changes, the button will automatically update the existing
24
- * connector instance with the new connection details. If you need to force a
25
- * complete remount instead, set forceRemountOnConnectionChange to true.
26
- */ const QuilttButton = ({ as, connectorId, connectionId, institution, forceRemountOnConnectionChange = false, onEvent, onOpen, onLoad, onExit, onExitSuccess, onExitAbort, onExitError, onClick, onHtmlLoad, children, ...props })=>{
27
- // Check flag to warn about potential anti-pattern (may produce false positives for valid nested patterns)
28
- useQuilttRenderGuard('QuilttButton');
29
- // Keep track of previous connectionId for change detection
30
- const prevConnectionIdRef = useRef(connectionId);
31
- const prevCallbacksRef = useRef({
32
- onEvent,
33
- onOpen,
34
- onLoad,
35
- onExit,
36
- onExitSuccess,
37
- onExitAbort,
38
- onExitError
39
- });
40
- // Track if callbacks have changed to help with debugging
41
- const currentCallbacks = {
42
- onEvent,
43
- onOpen,
44
- onLoad,
45
- onExit,
46
- onExitSuccess,
47
- onExitAbort,
48
- onExitError
49
- };
50
- const callbacksChanged = !isDeepEqual(prevCallbacksRef.current, currentCallbacks);
51
- useEffect(()=>{
52
- prevCallbacksRef.current = currentCallbacks;
53
- });
54
- // Warning for potential callback reference issues
55
- useEffect(()=>{
56
- if (callbacksChanged && prevConnectionIdRef.current !== undefined) {
57
- console.warn('[Quiltt] Callback functions changed after initial render. ' + 'This may cause unexpected behavior. Consider memoizing callback functions ' + 'with useCallback to maintain stable references.');
58
- }
59
- }, [
60
- callbacksChanged
61
- ]);
62
- const { open } = useQuilttConnector(connectorId, {
63
- connectionId,
64
- institution,
65
- nonce: props?.nonce,
66
- onEvent,
67
- onOpen,
68
- onLoad,
69
- onExit,
70
- onExitSuccess,
71
- onExitAbort,
72
- onExitError
73
- });
74
- // Update previous connectionId reference
75
- useEffect(()=>{
76
- prevConnectionIdRef.current = connectionId;
77
- }, [
78
- connectionId
79
- ]);
80
- const Button = as || 'button';
81
- const handleClick = (event)=>{
82
- // Call the user's onClick handler first to allow for:
83
- // 1. Pre-open validation
84
- // 2. Preventing opening via event.preventDefault()
85
- // 3. Setting up state before connector opens
86
- onClick?.(event);
87
- // Only open if event wasn't prevented
88
- if (!event.defaultPrevented) {
89
- open();
90
- }
91
- };
92
- // Generate key for forced remounting if enabled, but respect user-provided key
93
- const buttonKey = props.key ?? (forceRemountOnConnectionChange ? `${connectorId}-${connectionId || 'no-connection'}` : undefined);
94
- return /*#__PURE__*/ jsx(Button, {
95
- onClick: handleClick,
96
- onLoad: onHtmlLoad,
97
- "quiltt-connection": connectionId,
98
- ...props,
99
- children: children
100
- }, buttonKey);
101
- };
102
-
103
- /**
104
- * QuilttContainer uses globally shared callbacks. It's recommended you only use
105
- * one Container at a time.
106
- *
107
- * When connectionId changes, the container will automatically update the existing
108
- * connector instance with the new connection details. If you need to force a
109
- * complete remount instead, set forceRemountOnConnectionChange to true.
110
- */ const QuilttContainer = ({ as, connectorId, connectionId, forceRemountOnConnectionChange = false, onEvent, onLoad, onExit, onExitSuccess, onExitAbort, onExitError, children, ...props })=>{
111
- // Check flag to warn about potential anti-pattern (may produce false positives for valid nested patterns)
112
- useQuilttRenderGuard('QuilttContainer');
113
- // Keep track of previous connectionId for change detection
114
- const prevConnectionIdRef = useRef(connectionId);
115
- const prevCallbacksRef = useRef({
116
- onEvent,
117
- onLoad,
118
- onExit,
119
- onExitSuccess,
120
- onExitAbort,
121
- onExitError
122
- });
123
- // Track if callbacks have changed to help with debugging
124
- const currentCallbacks = {
125
- onEvent,
126
- onLoad,
127
- onExit,
128
- onExitSuccess,
129
- onExitAbort,
130
- onExitError
131
- };
132
- const callbacksChanged = !isDeepEqual(prevCallbacksRef.current, currentCallbacks);
133
- useEffect(()=>{
134
- prevCallbacksRef.current = currentCallbacks;
135
- });
136
- // Warning for potential callback reference issues
137
- useEffect(()=>{
138
- if (callbacksChanged && prevConnectionIdRef.current !== undefined) {
139
- console.warn('[Quiltt] Callback functions changed after initial render. ' + 'This may cause unexpected behavior. Consider memoizing callback functions ' + 'with useCallback to maintain stable references.');
140
- }
141
- }, [
142
- callbacksChanged
143
- ]);
144
- useQuilttConnector(connectorId, {
145
- connectionId,
146
- nonce: props?.nonce,
147
- onEvent,
148
- onLoad,
149
- onExit,
150
- onExitSuccess,
151
- onExitAbort,
152
- onExitError
153
- });
154
- // Update previous connectionId reference
155
- useEffect(()=>{
156
- prevConnectionIdRef.current = connectionId;
157
- }, [
158
- connectionId
159
- ]);
160
- const Container = as || 'div';
161
- // Generate key for forced remounting if enabled, but respect user-provided key
162
- const containerKey = props.key ?? (forceRemountOnConnectionChange ? `${connectorId}-${connectionId || 'no-connection'}` : undefined);
163
- return /*#__PURE__*/ jsx(Container, {
164
- "quiltt-container": connectorId,
165
- "quiltt-connection": connectionId,
166
- ...props,
167
- children: children
168
- }, containerKey);
169
- };
170
-
171
- const QuilttProvider = ({ clientId, graphqlClient, token, children })=>{
172
- // Set a context flag that SDK components can check to warn about potential anti-patterns.
173
- // LIMITATION: This flags ALL descendants due to React context propagation, not just same-component usage.
174
- // Will produce false positives for valid patterns like: <QuilttProvider><MyPage /></QuilttProvider>
175
- // where MyPage renders SDK components (which is correct usage).
176
- // The flag-based approach is simple but imprecise - a proper solution would require render stack tracking.
177
- return /*#__PURE__*/ jsx(QuilttProviderRender.Provider, {
178
- value: {
179
- isRenderingProvider: true
180
- },
181
- children: /*#__PURE__*/ jsx(QuilttSettingsProvider, {
182
- clientId: clientId,
183
- children: /*#__PURE__*/ jsx(QuilttAuthProvider, {
184
- token: token,
185
- graphqlClient: graphqlClient,
186
- children: children
187
- })
188
- })
189
- });
190
- };
191
-
192
- export { QuilttAuthProvider, QuilttButton, QuilttContainer, QuilttProvider, QuilttSettingsProvider, useQuilttConnector, useQuilttRenderGuard };
6
+ export * from './components/index.js';
7
+ export * from './hooks/index.js';
8
+ export * from './providers/index.js';
@@ -0,0 +1,60 @@
1
+ 'use client';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { useRef, useEffect, useMemo } from 'react';
4
+ import { ApolloProvider } from '@apollo/client/react';
5
+ import { QuilttClient, InMemoryCache, createVersionLink } from '@quiltt/core';
6
+ import { useQuilttSession } from '../hooks/index.js';
7
+ import { getPlatformInfo, isDeepEqual } from '../utils/index.js';
8
+
9
+ /**
10
+ * If a token is provided, will validate the token against the api and then import
11
+ * it into trusted storage. While this process is happening, the component is put
12
+ * into a loading state and the children are not rendered to prevent race conditions
13
+ * from triggering within the transitionary state.
14
+ */ const QuilttAuthProvider = ({ graphqlClient, token, children })=>{
15
+ const { session, importSession } = useQuilttSession();
16
+ const previousSessionRef = useRef(session);
17
+ const previousTokenRef = useRef(undefined);
18
+ const importSessionRef = useRef(importSession);
19
+ // Keep importSession ref up to date
20
+ useEffect(()=>{
21
+ importSessionRef.current = importSession;
22
+ }, [
23
+ importSession
24
+ ]);
25
+ // Memoize the client to avoid unnecessary re-renders
26
+ const apolloClient = useMemo(()=>graphqlClient || new QuilttClient({
27
+ cache: new InMemoryCache(),
28
+ versionLink: createVersionLink(getPlatformInfo())
29
+ }), [
30
+ graphqlClient
31
+ ]);
32
+ // Import passed in token (only if value has changed)
33
+ useEffect(()=>{
34
+ if (token && token !== previousTokenRef.current) {
35
+ importSessionRef.current(token);
36
+ previousTokenRef.current = token;
37
+ } else if (!token) {
38
+ // Reset ref when token becomes undefined to allow re-import of same token later
39
+ previousTokenRef.current = undefined;
40
+ }
41
+ }, [
42
+ token
43
+ ]);
44
+ // Reset Client Store when session changes (using deep comparison)
45
+ useEffect(()=>{
46
+ if (!isDeepEqual(session, previousSessionRef.current)) {
47
+ apolloClient.resetStore();
48
+ previousSessionRef.current = session;
49
+ }
50
+ }, [
51
+ session,
52
+ apolloClient
53
+ ]);
54
+ return /*#__PURE__*/ jsx(ApolloProvider, {
55
+ client: apolloClient,
56
+ children: children
57
+ });
58
+ };
59
+
60
+ export { QuilttAuthProvider as Q };