@quiltt/react 3.8.1 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +5 -1
- package/dist/QuilttAuthProvider-client-pXeKB9BO.js +137 -0
- package/dist/{QuilttSettingsProvider-client-BJFjBWHn.js → QuilttSettingsProvider-client-DK_eTIy6.js} +1 -0
- package/dist/index.d.ts +3 -5
- package/dist/index.js +6 -6
- package/dist/{useQuilttClient-client-DFuCXCBx.js → useQuilttClient-client-vI5KrJv2.js} +1 -1
- package/dist/{useQuilttConnector-client-65x8U9Mn.js → useQuilttConnector-client-D1pfKDpI.js} +2 -3
- package/dist/{useQuilttSession-client-xfxBGnbt.js → useQuilttSession-client-C0lMwHkc.js} +1 -1
- package/package.json +5 -6
- package/src/hooks/useQuilttClient.ts +1 -1
- package/src/providers/QuilttAuthProvider.tsx +15 -8
- package/src/version.ts +1 -2
- package/dist/QuilttAuthProvider-client-Cp30Hh8M.js +0 -12993
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @quiltt/react
|
|
2
2
|
|
|
3
|
+
## 3.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#307](https://github.com/quiltt/quiltt-js/pull/307) [`d0033cd`](https://github.com/quiltt/quiltt-js/commit/d0033cdbdaf33f9227afa55c9a6078156809a563) Thanks [@rubendinho](https://github.com/rubendinho)! - - Significantly reduce bundle size by migrating @apollo/client to "deep entrypoint import style"
|
|
8
|
+
- Bump @apollo/client to v3.11.8
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- [#305](https://github.com/quiltt/quiltt-js/pull/305) [`803a4d0`](https://github.com/quiltt/quiltt-js/commit/803a4d09e458ed2e72781fcd475ad5f9639f2bf2) Thanks [@zubairaziz](https://github.com/zubairaziz)! - Optimize connector WebView implementation
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [[`803a4d0`](https://github.com/quiltt/quiltt-js/commit/803a4d09e458ed2e72781fcd475ad5f9639f2bf2), [`d0033cd`](https://github.com/quiltt/quiltt-js/commit/d0033cdbdaf33f9227afa55c9a6078156809a563)]:
|
|
15
|
+
- @quiltt/core@3.9.0
|
|
16
|
+
|
|
17
|
+
## 3.8.2
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- [#303](https://github.com/quiltt/quiltt-js/pull/303) [`d1ceb66`](https://github.com/quiltt/quiltt-js/commit/d1ceb6648f4c2747988f8d6cacbee9946beaea0c) Thanks [@rubendinho](https://github.com/rubendinho)! - Reduce bundle size
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [[`d1ceb66`](https://github.com/quiltt/quiltt-js/commit/d1ceb6648f4c2747988f8d6cacbee9946beaea0c)]:
|
|
24
|
+
- @quiltt/core@3.8.2
|
|
25
|
+
|
|
3
26
|
## 3.8.1
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
`@quiltt/react` provides React Components and Hooks for integrating Quiltt into React-based applications.
|
|
7
7
|
|
|
8
|
+
See the guides [here](https://www.quiltt.dev/connector/sdks/react).
|
|
9
|
+
|
|
8
10
|
## Installation
|
|
9
11
|
|
|
10
12
|
```shell
|
|
@@ -100,7 +102,9 @@ A provider component for passing Session and settings down to the rest of your a
|
|
|
100
102
|
import { QuilttProvider } from '@quiltt/react'
|
|
101
103
|
|
|
102
104
|
const Layout = ({ children }) => {
|
|
103
|
-
|
|
105
|
+
const sessionToken = "<SESSION_TOKEN_FROM_SERVER>"
|
|
106
|
+
|
|
107
|
+
return <QuilttProvider token={sessionToken}>{children}</QuilttProvider>
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
export default Layout
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useMemo, useEffect } from 'react';
|
|
3
|
+
import { JsonWebTokenParse, QuilttClient, InMemoryCache } from '@quiltt/core';
|
|
4
|
+
import '@apollo/client/react/hooks';
|
|
5
|
+
import './useQuilttSettings-client-DU_Qfc8X.js';
|
|
6
|
+
import './useSession-client-CG5lGS9F.js';
|
|
7
|
+
import { jsx } from 'react/jsx-runtime';
|
|
8
|
+
import { ApolloProvider } from '@apollo/client/react';
|
|
9
|
+
import { u as useQuilttSession } from './useQuilttSession-client-C0lMwHkc.js';
|
|
10
|
+
|
|
11
|
+
const useIdentifySession = (auth, setSession)=>{
|
|
12
|
+
const identifySession = useCallback(async (payload, callbacks)=>{
|
|
13
|
+
const response = await auth.identify(payload);
|
|
14
|
+
switch(response.status){
|
|
15
|
+
case 201:
|
|
16
|
+
setSession(response.data.token);
|
|
17
|
+
if (callbacks.onSuccess) return callbacks.onSuccess();
|
|
18
|
+
break;
|
|
19
|
+
case 202:
|
|
20
|
+
if (callbacks.onChallenged) return callbacks.onChallenged();
|
|
21
|
+
break;
|
|
22
|
+
case 422:
|
|
23
|
+
if (callbacks.onError) return callbacks.onError(response.data);
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
throw new Error(`AuthAPI.identify: Unexpected response status ${response.status}`);
|
|
27
|
+
}
|
|
28
|
+
}, [
|
|
29
|
+
auth,
|
|
30
|
+
setSession
|
|
31
|
+
]);
|
|
32
|
+
return identifySession;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const useAuthenticateSession = (auth, setSession)=>{
|
|
36
|
+
const authenticateSession = useCallback(async (payload, callbacks)=>{
|
|
37
|
+
const response = await auth.authenticate(payload);
|
|
38
|
+
switch(response.status){
|
|
39
|
+
case 201:
|
|
40
|
+
setSession(response.data.token);
|
|
41
|
+
if (callbacks.onSuccess) return callbacks.onSuccess();
|
|
42
|
+
break;
|
|
43
|
+
case 401:
|
|
44
|
+
if (callbacks.onFailure) return callbacks.onFailure();
|
|
45
|
+
break;
|
|
46
|
+
case 422:
|
|
47
|
+
if (callbacks.onError) return callbacks.onError(response.data);
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
throw new Error(`AuthAPI.authenticate: Unexpected response status ${response.status}`);
|
|
51
|
+
}
|
|
52
|
+
}, [
|
|
53
|
+
auth,
|
|
54
|
+
setSession
|
|
55
|
+
]);
|
|
56
|
+
return authenticateSession;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Optionally Accepts environmentId to validate session is from with your desired environment
|
|
61
|
+
*/ const useImportSession = (auth, session, setSession, environmentId)=>{
|
|
62
|
+
const importSession = useCallback(async (token)=>{
|
|
63
|
+
// Is there a token?
|
|
64
|
+
if (!token) return !!session;
|
|
65
|
+
// Is this token already imported?
|
|
66
|
+
if (session && session.token === token) return true;
|
|
67
|
+
const jwt = JsonWebTokenParse(token);
|
|
68
|
+
// Is this token a valid JWT?
|
|
69
|
+
if (!jwt) return false;
|
|
70
|
+
// Is this token within the expected environment?
|
|
71
|
+
if (environmentId && jwt.claims.eid !== environmentId) return false;
|
|
72
|
+
// Is this token active?
|
|
73
|
+
const response = await auth.ping(token);
|
|
74
|
+
switch(response.status){
|
|
75
|
+
case 200:
|
|
76
|
+
setSession(token);
|
|
77
|
+
return true;
|
|
78
|
+
case 401:
|
|
79
|
+
return false;
|
|
80
|
+
default:
|
|
81
|
+
throw new Error(`AuthAPI.ping: Unexpected response status ${response.status}`);
|
|
82
|
+
}
|
|
83
|
+
}, [
|
|
84
|
+
auth,
|
|
85
|
+
session,
|
|
86
|
+
setSession,
|
|
87
|
+
environmentId
|
|
88
|
+
]);
|
|
89
|
+
return importSession;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const useRevokeSession = (auth, session, setSession)=>{
|
|
93
|
+
const revokeSession = useCallback(async ()=>{
|
|
94
|
+
if (!session) return;
|
|
95
|
+
await auth.revoke(session.token);
|
|
96
|
+
setSession(null);
|
|
97
|
+
}, [
|
|
98
|
+
auth,
|
|
99
|
+
session,
|
|
100
|
+
setSession
|
|
101
|
+
]);
|
|
102
|
+
return revokeSession;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* If a token is provided, will validate the token against the api and then import
|
|
107
|
+
* it into trusted storage. While this process is happening, the component is put
|
|
108
|
+
* into a loading state and the children are not rendered to prevent race conditions
|
|
109
|
+
* from triggering within the transitionary state.
|
|
110
|
+
*
|
|
111
|
+
*/ const QuilttAuthProvider = ({ token, children })=>{
|
|
112
|
+
const { session, importSession } = useQuilttSession();
|
|
113
|
+
// @todo: extract into a provider so it can accessed by child components
|
|
114
|
+
const graphQLClient = useMemo(()=>new QuilttClient({
|
|
115
|
+
cache: new InMemoryCache()
|
|
116
|
+
}), []);
|
|
117
|
+
// Import passed in token
|
|
118
|
+
useEffect(()=>{
|
|
119
|
+
if (token) importSession(token);
|
|
120
|
+
}, [
|
|
121
|
+
token,
|
|
122
|
+
importSession
|
|
123
|
+
]);
|
|
124
|
+
// Reset Client Store when logging in or out
|
|
125
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: We should reset the store whenever the session changes
|
|
126
|
+
useEffect(()=>{
|
|
127
|
+
graphQLClient.resetStore();
|
|
128
|
+
}, [
|
|
129
|
+
session
|
|
130
|
+
]);
|
|
131
|
+
return /*#__PURE__*/ jsx(ApolloProvider, {
|
|
132
|
+
client: graphQLClient,
|
|
133
|
+
children: children
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export { QuilttAuthProvider as Q, useIdentifySession as a, useAuthenticateSession as b, useRevokeSession as c, useImportSession as u };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Maybe, QuilttJWT, UsernamePayload, UnprocessableData, AuthAPI, PasscodePayload, ConnectorSDKConnectorOptions,
|
|
1
|
+
import { Maybe, QuilttJWT, UsernamePayload, UnprocessableData, AuthAPI, PasscodePayload, ConnectorSDKConnectorOptions, ConnectorSDKCallbacks } from '@quiltt/core';
|
|
2
2
|
export * from '@quiltt/core';
|
|
3
3
|
import * as react from 'react';
|
|
4
4
|
import { RefObject, useLayoutEffect, Dispatch, SetStateAction, FC, PropsWithChildren, Component, ComponentType } from 'react';
|
|
5
|
-
import { useApolloClient } from '@apollo/client/
|
|
6
|
-
import * as _apollo_client from '@apollo/client';
|
|
5
|
+
import { useApolloClient } from '@apollo/client/react/hooks';
|
|
7
6
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
8
7
|
|
|
9
8
|
declare function useEventListener<K extends keyof MediaQueryListEventMap>(eventName: K, handler: (event: MediaQueryListEventMap[K]) => void, element: RefObject<MediaQueryList>, options?: boolean | AddEventListenerOptions): void;
|
|
@@ -111,7 +110,6 @@ type QuilttAuthProviderProps = PropsWithChildren & {
|
|
|
111
110
|
/** The Session token obtained from the server */
|
|
112
111
|
token?: string;
|
|
113
112
|
};
|
|
114
|
-
declare const GraphQLClient: QuilttClient<_apollo_client.NormalizedCacheObject>;
|
|
115
113
|
/**
|
|
116
114
|
* If a token is provided, will validate the token against the api and then import
|
|
117
115
|
* it into trusted storage. While this process is happening, the component is put
|
|
@@ -157,4 +155,4 @@ type QuilttContainerProps<T extends AnyTag> = PropsWithChildren<{
|
|
|
157
155
|
*/
|
|
158
156
|
declare const QuilttContainer: <T extends AnyTag = "div">({ as, connectorId, connectionId, onEvent, onLoad, onExit, onExitSuccess, onExitAbort, onExitError, children, ...props }: QuilttContainerProps<T> & PropsOf<T>) => react_jsx_runtime.JSX.Element;
|
|
159
157
|
|
|
160
|
-
export { type AuthenticateSession,
|
|
158
|
+
export { type AuthenticateSession, type IdentifySession, type ImportSession, QuilttAuthProvider, QuilttButton, QuilttContainer, QuilttProvider, QuilttSettings, QuilttSettingsProvider, type RevokeSession, type SetSession, type UseQuilttSession, useAuthenticateSession, useEventListener, useIdentifySession, useImportSession, useIsomorphicLayoutEffect, useQuilttClient, useQuilttConnector, useQuilttSession, useQuilttSettings, useRevokeSession, useSession, useStorage };
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export * from '@quiltt/core';
|
|
2
2
|
export { u as useEventListener } from './useEventListener-client-DVM5xwKY.js';
|
|
3
3
|
export { u as useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect-client-DeTHOKz1.js';
|
|
4
|
-
import { Q as QuilttAuthProvider } from './QuilttAuthProvider-client-
|
|
5
|
-
export {
|
|
6
|
-
export { u as useQuilttClient } from './useQuilttClient-client-
|
|
7
|
-
import { u as useQuilttConnector } from './useQuilttConnector-client-
|
|
8
|
-
export { u as useQuilttSession } from './useQuilttSession-client-
|
|
4
|
+
import { Q as QuilttAuthProvider } from './QuilttAuthProvider-client-pXeKB9BO.js';
|
|
5
|
+
export { b as useAuthenticateSession, a as useIdentifySession, u as useImportSession, c as useRevokeSession } from './QuilttAuthProvider-client-pXeKB9BO.js';
|
|
6
|
+
export { u as useQuilttClient } from './useQuilttClient-client-vI5KrJv2.js';
|
|
7
|
+
import { u as useQuilttConnector } from './useQuilttConnector-client-D1pfKDpI.js';
|
|
8
|
+
export { u as useQuilttSession } from './useQuilttSession-client-C0lMwHkc.js';
|
|
9
9
|
export { Q as QuilttSettings, u as useQuilttSettings } from './useQuilttSettings-client-DU_Qfc8X.js';
|
|
10
10
|
export { u as useSession } from './useSession-client-CG5lGS9F.js';
|
|
11
11
|
export { u as useStorage } from './useStorage-client-B3keU-oI.js';
|
|
12
12
|
import { jsx } from 'react/jsx-runtime';
|
|
13
|
-
import { Q as QuilttSettingsProvider } from './QuilttSettingsProvider-client-
|
|
13
|
+
import { Q as QuilttSettingsProvider } from './QuilttSettingsProvider-client-DK_eTIy6.js';
|
|
14
14
|
|
|
15
15
|
const QuilttProvider = ({ clientId, token, children })=>{
|
|
16
16
|
return /*#__PURE__*/ jsx(QuilttSettingsProvider, {
|
package/dist/{useQuilttConnector-client-65x8U9Mn.js → useQuilttConnector-client-D1pfKDpI.js}
RENAMED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useState, useEffect, useCallback } from 'react';
|
|
3
3
|
import { cdnBase } from '@quiltt/core';
|
|
4
|
-
import { u as useQuilttSession } from './useQuilttSession-client-
|
|
4
|
+
import { u as useQuilttSession } from './useQuilttSession-client-C0lMwHkc.js';
|
|
5
5
|
import { u as useScript } from './useScript-client-Cx5nb9RW.js';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
const version = '3.8.1';
|
|
7
|
+
var version = "3.9.0";
|
|
9
8
|
|
|
10
9
|
const useQuilttConnector = (connectorId, options)=>{
|
|
11
10
|
const status = useScript(`${cdnBase}/v1/connector.js?agent=react-${version}`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useCallback } from 'react';
|
|
3
3
|
import { AuthAPI } from '@quiltt/core';
|
|
4
|
-
import {
|
|
4
|
+
import { u as useImportSession, a as useIdentifySession, b as useAuthenticateSession, c as useRevokeSession } from './QuilttAuthProvider-client-pXeKB9BO.js';
|
|
5
5
|
import { u as useQuilttSettings } from './useQuilttSettings-client-DU_Qfc8X.js';
|
|
6
6
|
import { u as useSession } from './useSession-client-CG5lGS9F.js';
|
|
7
7
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quiltt/react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "React components and hooks for Quiltt Connector",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"quiltt",
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"CHANGELOG.md"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@
|
|
38
|
+
"@apollo/client": "^3.11.8",
|
|
39
|
+
"@quiltt/core": "3.9.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@apollo/client": "3.9.11",
|
|
42
42
|
"@biomejs/biome": "1.9.4",
|
|
43
|
-
"@types/node": "22.
|
|
43
|
+
"@types/node": "22.10.2",
|
|
44
44
|
"@types/react": "18.3.12",
|
|
45
45
|
"@types/react-dom": "18.3.1",
|
|
46
46
|
"bunchee": "5.6.1",
|
|
@@ -57,8 +57,7 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
|
-
"
|
|
61
|
-
"build": "pnpm run addVersion && bunchee",
|
|
60
|
+
"build": "bunchee",
|
|
62
61
|
"clean": "rimraf .turbo dist",
|
|
63
62
|
"dev": "bunchee --watch",
|
|
64
63
|
"lint": "TIMING=1 biome check src/ tests/ --fix",
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
3
|
import type { FC, PropsWithChildren } from 'react'
|
|
4
|
-
import { useEffect } from 'react'
|
|
4
|
+
import { useEffect, useMemo } from 'react'
|
|
5
|
+
|
|
6
|
+
import { ApolloProvider } from '@apollo/client/react'
|
|
5
7
|
|
|
6
|
-
import { ApolloProvider } from '@apollo/client'
|
|
7
8
|
import { InMemoryCache, QuilttClient } from '@quiltt/core'
|
|
9
|
+
|
|
8
10
|
import { useQuilttSession } from '../hooks'
|
|
9
11
|
|
|
10
12
|
type QuilttAuthProviderProps = PropsWithChildren & {
|
|
@@ -12,10 +14,6 @@ type QuilttAuthProviderProps = PropsWithChildren & {
|
|
|
12
14
|
token?: string
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
export const GraphQLClient = new QuilttClient({
|
|
16
|
-
cache: new InMemoryCache(),
|
|
17
|
-
})
|
|
18
|
-
|
|
19
17
|
/**
|
|
20
18
|
* If a token is provided, will validate the token against the api and then import
|
|
21
19
|
* it into trusted storage. While this process is happening, the component is put
|
|
@@ -26,6 +24,15 @@ export const GraphQLClient = new QuilttClient({
|
|
|
26
24
|
export const QuilttAuthProvider: FC<QuilttAuthProviderProps> = ({ token, children }) => {
|
|
27
25
|
const { session, importSession } = useQuilttSession()
|
|
28
26
|
|
|
27
|
+
// @todo: extract into a provider so it can accessed by child components
|
|
28
|
+
const graphQLClient = useMemo(
|
|
29
|
+
() =>
|
|
30
|
+
new QuilttClient({
|
|
31
|
+
cache: new InMemoryCache(),
|
|
32
|
+
}),
|
|
33
|
+
[]
|
|
34
|
+
)
|
|
35
|
+
|
|
29
36
|
// Import passed in token
|
|
30
37
|
useEffect(() => {
|
|
31
38
|
if (token) importSession(token)
|
|
@@ -34,10 +41,10 @@ export const QuilttAuthProvider: FC<QuilttAuthProviderProps> = ({ token, childre
|
|
|
34
41
|
// Reset Client Store when logging in or out
|
|
35
42
|
// biome-ignore lint/correctness/useExhaustiveDependencies: We should reset the store whenever the session changes
|
|
36
43
|
useEffect(() => {
|
|
37
|
-
|
|
44
|
+
graphQLClient.resetStore()
|
|
38
45
|
}, [session])
|
|
39
46
|
|
|
40
|
-
return <ApolloProvider client={
|
|
47
|
+
return <ApolloProvider client={graphQLClient}>{children}</ApolloProvider>
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
export default QuilttAuthProvider
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const version = '3.8.1'
|
|
1
|
+
export { version } from '../package.json'
|