@quiltt/react 3.8.2 → 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 +14 -0
- 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 +1 -1
- package/dist/index.js +6 -6
- package/dist/{useQuilttClient-client-D5o2Whsn.js → useQuilttClient-client-vI5KrJv2.js} +1 -1
- package/dist/{useQuilttConnector-client-_DPRlIM5.js → useQuilttConnector-client-D1pfKDpI.js} +2 -3
- package/dist/{useQuilttSession-client-YSZevZF3.js → useQuilttSession-client-C0lMwHkc.js} +1 -1
- package/package.json +5 -6
- package/src/hooks/useQuilttClient.ts +1 -1
- package/src/providers/QuilttAuthProvider.tsx +3 -1
- package/src/version.ts +1 -2
- package/dist/QuilttAuthProvider-client-DE7DRmFG.js +0 -12994
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
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
|
+
|
|
3
17
|
## 3.8.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -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
|
@@ -2,7 +2,7 @@ import { Maybe, QuilttJWT, UsernamePayload, UnprocessableData, AuthAPI, Passcode
|
|
|
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/
|
|
5
|
+
import { useApolloClient } from '@apollo/client/react/hooks';
|
|
6
6
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
7
7
|
|
|
8
8
|
declare function useEventListener<K extends keyof MediaQueryListEventMap>(eventName: K, handler: (event: MediaQueryListEventMap[K]) => void, element: RefObject<MediaQueryList>, options?: boolean | AddEventListenerOptions): void;
|
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-_DPRlIM5.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.2';
|
|
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",
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
import type { FC, PropsWithChildren } from 'react'
|
|
4
4
|
import { useEffect, useMemo } from 'react'
|
|
5
5
|
|
|
6
|
-
import { ApolloProvider } from '@apollo/client'
|
|
6
|
+
import { ApolloProvider } from '@apollo/client/react'
|
|
7
|
+
|
|
7
8
|
import { InMemoryCache, QuilttClient } from '@quiltt/core'
|
|
9
|
+
|
|
8
10
|
import { useQuilttSession } from '../hooks'
|
|
9
11
|
|
|
10
12
|
type QuilttAuthProviderProps = PropsWithChildren & {
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const version = '3.8.2'
|
|
1
|
+
export { version } from '../package.json'
|