@kirill.konshin/react-native 0.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.
package/.ctirc ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "addNewline": true,
3
+ "fileExcludePatterns": [
4
+ "*.stories.*",
5
+ "*.test.*",
6
+ "*.fixture.*"
7
+ ],
8
+ "verbose": false,
9
+ "withoutBackupFile": true,
10
+ "withoutComment": true
11
+ }
@@ -0,0 +1,15 @@
1
+ vite v7.0.6 building SSR bundle for production...
2
+ create succeeded: /home/runner/work/utils/utils/packages/react-native/src
3
+ transforming...
4
+ ✓ 4 modules transformed.
5
+ rendering chunks...
6
+
7
+ [vite:dts] Start generate declaration files...
8
+ dist/index.js 0.21 kB │ map: 0.09 kB
9
+ dist/useAppState.js 0.47 kB │ map: 0.89 kB
10
+ dist/share.js 0.85 kB │ map: 1.78 kB
11
+ dist/update.js 1.05 kB │ map: 2.00 kB
12
+ [vite:dts] Declaration files built in 1414ms.
13
+
14
+ ✓ built in 2.11s
15
+ Updated package.json with exports
@@ -0,0 +1,4 @@
1
+ export * from './share';
2
+ export * from './update';
3
+ export * from './useAppState';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import { shareDialog } from "./share.js";
2
+ import { Update } from "./update.js";
3
+ import { useAppState } from "./useAppState.js";
4
+ export {
5
+ Update,
6
+ shareDialog,
7
+ useAppState
8
+ };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * data:text/plain;base64,W29iamV
3
+ * @see https://stackoverflow.com/questions/69738812/problem-to-generate-pdf-from-a-blob-in-an-expo-app-using-filesystem
4
+ * @param base64
5
+ * @param fileName
6
+ * @returns {Promise<void>}
7
+ */
8
+ export declare const shareDialog: (base64: string, fileName: string) => Promise<void>;
9
+ //# sourceMappingURL=share.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share.d.ts","sourceRoot":"","sources":["../src/share.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAU,QAAQ,MAAM,EAAE,UAAU,MAAM,KAAG,OAAO,CAAC,IAAI,CAoBhF,CAAC"}
package/dist/share.js ADDED
@@ -0,0 +1,23 @@
1
+ import * as FileSystem from "expo-file-system";
2
+ import * as Sharing from "expo-sharing";
3
+ const shareDialog = async (base64, fileName) => {
4
+ const path = `${FileSystem.documentDirectory}/${fileName}`;
5
+ try {
6
+ if (!await Sharing.isAvailableAsync()) throw new Error("Sharing is not available");
7
+ const [header, buffer] = base64.split(",");
8
+ const [, mimeTypeStr] = header.split(":");
9
+ const [mimeType] = mimeTypeStr.split(";");
10
+ await FileSystem.writeAsStringAsync(`${path}`, buffer, {
11
+ encoding: FileSystem.EncodingType.Base64
12
+ });
13
+ await Sharing.shareAsync(path, { mimeType, UTI: fileName, dialogTitle: "Save or share document" });
14
+ } catch (error) {
15
+ alert("Sharing failed: " + error.message);
16
+ } finally {
17
+ await FileSystem.deleteAsync(path);
18
+ }
19
+ };
20
+ export {
21
+ shareDialog
22
+ };
23
+ //# sourceMappingURL=share.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share.js","sources":["../src/share.ts"],"sourcesContent":["import * as FileSystem from 'expo-file-system';\nimport * as Sharing from 'expo-sharing';\n\n/**\n * data:text/plain;base64,W29iamV\n * @see https://stackoverflow.com/questions/69738812/problem-to-generate-pdf-from-a-blob-in-an-expo-app-using-filesystem\n * @param base64\n * @param fileName\n * @returns {Promise<void>}\n */\nexport const shareDialog = async (base64: string, fileName: string): Promise<void> => {\n const path = `${FileSystem.documentDirectory}/${fileName}`;\n\n try {\n if (!(await Sharing.isAvailableAsync())) throw new Error('Sharing is not available');\n\n const [header, buffer] = base64.split(',');\n const [, mimeTypeStr] = header.split(':');\n const [mimeType] = mimeTypeStr.split(';');\n\n await FileSystem.writeAsStringAsync(`${path}`, buffer, {\n encoding: FileSystem.EncodingType.Base64,\n });\n\n await Sharing.shareAsync(path, { mimeType, UTI: fileName, dialogTitle: 'Save or share document' });\n } catch (error) {\n alert('Sharing failed: ' + error.message);\n } finally {\n await FileSystem.deleteAsync(path);\n }\n};\n"],"names":[],"mappings":";;AAUO,MAAM,cAAc,OAAO,QAAgB,aAAoC;AAClF,QAAM,OAAO,GAAG,WAAW,iBAAiB,IAAI,QAAQ;AAExD,MAAI;AACA,QAAI,CAAE,MAAM,QAAQ,iBAAA,EAAqB,OAAM,IAAI,MAAM,0BAA0B;AAEnF,UAAM,CAAC,QAAQ,MAAM,IAAI,OAAO,MAAM,GAAG;AACzC,UAAM,CAAA,EAAG,WAAW,IAAI,OAAO,MAAM,GAAG;AACxC,UAAM,CAAC,QAAQ,IAAI,YAAY,MAAM,GAAG;AAExC,UAAM,WAAW,mBAAmB,GAAG,IAAI,IAAI,QAAQ;AAAA,MACnD,UAAU,WAAW,aAAa;AAAA,IAAA,CACrC;AAED,UAAM,QAAQ,WAAW,MAAM,EAAE,UAAU,KAAK,UAAU,aAAa,0BAA0B;AAAA,EACrG,SAAS,OAAO;AACZ,UAAM,qBAAqB,MAAM,OAAO;AAAA,EAC5C,UAAA;AACI,UAAM,WAAW,YAAY,IAAI;AAAA,EACrC;AACJ;"}
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+ export declare const Update: FC<any>;
3
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../src/update.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAuB,MAAM,OAAO,CAAC;AAGhD,eAAO,MAAM,MAAM,EAAE,EAAE,CAAC,GAAG,CAmC1B,CAAC"}
package/dist/update.js ADDED
@@ -0,0 +1,40 @@
1
+ import { jsxs } from "react/jsx-runtime";
2
+ import * as Updates from "expo-updates";
3
+ import { useState, useEffect } from "react";
4
+ import { Text } from "react-native";
5
+ const Update = function Update2({ children }) {
6
+ const [updating, setUpdating] = useState(true);
7
+ useEffect(() => {
8
+ (async () => {
9
+ try {
10
+ if (__DEV__) {
11
+ setUpdating(false);
12
+ return;
13
+ }
14
+ const update = await Updates.checkForUpdateAsync();
15
+ if (!update.isAvailable) {
16
+ setUpdating(false);
17
+ return;
18
+ }
19
+ await Updates.fetchUpdateAsync();
20
+ alert("Update is available. App will reload.");
21
+ await Updates.reloadAsync();
22
+ } catch (error) {
23
+ alert(`Error fetching latest Expo update: ${error}`);
24
+ setUpdating(false);
25
+ }
26
+ })();
27
+ });
28
+ if (updating) {
29
+ return /* @__PURE__ */ jsxs(Text, { children: [
30
+ "Checking for updates (",
31
+ Updates.channel,
32
+ ")..."
33
+ ] });
34
+ }
35
+ return children;
36
+ };
37
+ export {
38
+ Update
39
+ };
40
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.js","sources":["../src/update.tsx"],"sourcesContent":["import * as Updates from 'expo-updates';\nimport { FC, useEffect, useState } from 'react';\nimport { Text } from 'react-native';\n\nexport const Update: FC<any> = function Update({ children }) {\n //FIXME useUpdates https://blog.expo.dev/feature-preview-updates-js-api-for-expo-updates-3b92beb40dab\n const [updating, setUpdating] = useState(true);\n\n useEffect(() => {\n (async () => {\n try {\n if (__DEV__) {\n setUpdating(false);\n return;\n }\n\n const update = await Updates.checkForUpdateAsync();\n\n if (!update.isAvailable) {\n setUpdating(false);\n return;\n }\n\n await Updates.fetchUpdateAsync();\n alert('Update is available. App will reload.');\n await Updates.reloadAsync();\n } catch (error) {\n // You can also add an alert() to see the error message in case of an error when fetching updates.\n alert(`Error fetching latest Expo update: ${error}`);\n setUpdating(false);\n }\n })();\n });\n\n if (updating) {\n return <Text>Checking for updates ({Updates.channel})...</Text>;\n }\n\n return children;\n};\n"],"names":["Update"],"mappings":";;;;AAIO,MAAM,SAAkB,SAASA,QAAO,EAAE,YAAY;AAEzD,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,IAAI;AAE7C,YAAU,MAAM;AACZ,KAAC,YAAY;AACT,UAAI;AACA,YAAI,SAAS;AACT,sBAAY,KAAK;AACjB;AAAA,QACJ;AAEA,cAAM,SAAS,MAAM,QAAQ,oBAAA;AAE7B,YAAI,CAAC,OAAO,aAAa;AACrB,sBAAY,KAAK;AACjB;AAAA,QACJ;AAEA,cAAM,QAAQ,iBAAA;AACd,cAAM,uCAAuC;AAC7C,cAAM,QAAQ,YAAA;AAAA,MAClB,SAAS,OAAO;AAEZ,cAAM,sCAAsC,KAAK,EAAE;AACnD,oBAAY,KAAK;AAAA,MACrB;AAAA,IACJ,GAAA;AAAA,EACJ,CAAC;AAED,MAAI,UAAU;AACV,gCAAQ,MAAA,EAAK,UAAA;AAAA,MAAA;AAAA,MAAuB,QAAQ;AAAA,MAAQ;AAAA,IAAA,GAAI;AAAA,EAC5D;AAEA,SAAO;AACX;"}
@@ -0,0 +1,2 @@
1
+ export declare function useAppState(): 'active' | 'background' | 'inactive' | 'unknown' | 'extension';
2
+ //# sourceMappingURL=useAppState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAppState.d.ts","sourceRoot":"","sources":["../src/useAppState.ts"],"names":[],"mappings":"AAGA,wBAAgB,WAAW,IAAI,QAAQ,GAAG,YAAY,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,CAc5F"}
@@ -0,0 +1,18 @@
1
+ import { useState, useEffect } from "react";
2
+ import { AppState } from "react-native";
3
+ function useAppState() {
4
+ const [appState, setAppState] = useState(AppState.currentState);
5
+ useEffect(() => {
6
+ const subscription = AppState.addEventListener("change", (nextAppState) => {
7
+ setAppState(nextAppState);
8
+ });
9
+ return () => {
10
+ subscription.remove();
11
+ };
12
+ }, []);
13
+ return appState;
14
+ }
15
+ export {
16
+ useAppState
17
+ };
18
+ //# sourceMappingURL=useAppState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAppState.js","sources":["../src/useAppState.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { AppState } from 'react-native';\n\nexport function useAppState(): 'active' | 'background' | 'inactive' | 'unknown' | 'extension' {\n const [appState, setAppState] = useState(AppState.currentState);\n\n useEffect(() => {\n const subscription = AppState.addEventListener('change', (nextAppState) => {\n setAppState(nextAppState);\n });\n\n return () => {\n subscription.remove();\n };\n }, []);\n\n return appState;\n}\n"],"names":[],"mappings":";;AAGO,SAAS,cAA8E;AAC1F,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,SAAS,YAAY;AAE9D,YAAU,MAAM;AACZ,UAAM,eAAe,SAAS,iBAAiB,UAAU,CAAC,iBAAiB;AACvE,kBAAY,YAAY;AAAA,IAC5B,CAAC;AAED,WAAO,MAAM;AACT,mBAAa,OAAA;AAAA,IACjB;AAAA,EACJ,GAAG,CAAA,CAAE;AAEL,SAAO;AACX;"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@kirill.konshin/react-native",
3
+ "description": "Utilities",
4
+ "version": "0.0.1",
5
+ "type": "module",
6
+ "scripts": {
7
+ "----- BUILD -----": "",
8
+ "clean": "rm -rf dist .tscache tsconfig.tsbuildinfo",
9
+ "build": "vite build",
10
+ "build:index": "cti create ./src",
11
+ "build:check-types": "attw --pack .",
12
+ "start": "yarn build --watch",
13
+ "wait": "wait-on ./dist/index.js",
14
+ "----- TEST -----": "",
15
+ "test:disabled": "vitest run --coverage",
16
+ "test:watch": "vitest watch --coverage",
17
+ "----- STORYBOOK -----": "",
18
+ "storybook:start": "storybook dev -p 6006",
19
+ "storybook:build": "storybook build"
20
+ },
21
+ "dependencies": {
22
+ "expo-file-system": "^18.1.11",
23
+ "expo-sharing": "^13.1.5",
24
+ "expo-updates": "^0.28.17"
25
+ },
26
+ "devDependencies": {
27
+ "@kirill.konshin/utils-private": "*",
28
+ "react": "^19.1.1",
29
+ "react-native": "^0.80.2"
30
+ },
31
+ "peerDependencies": {
32
+ "react": "^19",
33
+ "react-native": "^0.80"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "react": {
37
+ "optional": true
38
+ },
39
+ "react-native": {
40
+ "optional": true
41
+ }
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "author": "Kirill Konshin <kirill@konshin.org> (https://konshin.org)",
47
+ "license": "MIT",
48
+ "exports": {
49
+ ".": {
50
+ "import": {
51
+ "import": "./dist/index.js",
52
+ "types": "./dist/index.d.ts"
53
+ }
54
+ }
55
+ },
56
+ "main": "./dist/index.js",
57
+ "module": "./dist/index.js",
58
+ "types": "./dist/index.d.ts"
59
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './share';
2
+ export * from './update';
3
+ export * from './useAppState';
package/src/share.ts ADDED
@@ -0,0 +1,31 @@
1
+ import * as FileSystem from 'expo-file-system';
2
+ import * as Sharing from 'expo-sharing';
3
+
4
+ /**
5
+ * data:text/plain;base64,W29iamV
6
+ * @see https://stackoverflow.com/questions/69738812/problem-to-generate-pdf-from-a-blob-in-an-expo-app-using-filesystem
7
+ * @param base64
8
+ * @param fileName
9
+ * @returns {Promise<void>}
10
+ */
11
+ export const shareDialog = async (base64: string, fileName: string): Promise<void> => {
12
+ const path = `${FileSystem.documentDirectory}/${fileName}`;
13
+
14
+ try {
15
+ if (!(await Sharing.isAvailableAsync())) throw new Error('Sharing is not available');
16
+
17
+ const [header, buffer] = base64.split(',');
18
+ const [, mimeTypeStr] = header.split(':');
19
+ const [mimeType] = mimeTypeStr.split(';');
20
+
21
+ await FileSystem.writeAsStringAsync(`${path}`, buffer, {
22
+ encoding: FileSystem.EncodingType.Base64,
23
+ });
24
+
25
+ await Sharing.shareAsync(path, { mimeType, UTI: fileName, dialogTitle: 'Save or share document' });
26
+ } catch (error) {
27
+ alert('Sharing failed: ' + error.message);
28
+ } finally {
29
+ await FileSystem.deleteAsync(path);
30
+ }
31
+ };
package/src/update.tsx ADDED
@@ -0,0 +1,40 @@
1
+ import * as Updates from 'expo-updates';
2
+ import { FC, useEffect, useState } from 'react';
3
+ import { Text } from 'react-native';
4
+
5
+ export const Update: FC<any> = function Update({ children }) {
6
+ //FIXME useUpdates https://blog.expo.dev/feature-preview-updates-js-api-for-expo-updates-3b92beb40dab
7
+ const [updating, setUpdating] = useState(true);
8
+
9
+ useEffect(() => {
10
+ (async () => {
11
+ try {
12
+ if (__DEV__) {
13
+ setUpdating(false);
14
+ return;
15
+ }
16
+
17
+ const update = await Updates.checkForUpdateAsync();
18
+
19
+ if (!update.isAvailable) {
20
+ setUpdating(false);
21
+ return;
22
+ }
23
+
24
+ await Updates.fetchUpdateAsync();
25
+ alert('Update is available. App will reload.');
26
+ await Updates.reloadAsync();
27
+ } catch (error) {
28
+ // You can also add an alert() to see the error message in case of an error when fetching updates.
29
+ alert(`Error fetching latest Expo update: ${error}`);
30
+ setUpdating(false);
31
+ }
32
+ })();
33
+ });
34
+
35
+ if (updating) {
36
+ return <Text>Checking for updates ({Updates.channel})...</Text>;
37
+ }
38
+
39
+ return children;
40
+ };
@@ -0,0 +1,18 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { AppState } from 'react-native';
3
+
4
+ export function useAppState(): 'active' | 'background' | 'inactive' | 'unknown' | 'extension' {
5
+ const [appState, setAppState] = useState(AppState.currentState);
6
+
7
+ useEffect(() => {
8
+ const subscription = AppState.addEventListener('change', (nextAppState) => {
9
+ setAppState(nextAppState);
10
+ });
11
+
12
+ return () => {
13
+ subscription.remove();
14
+ };
15
+ }, []);
16
+
17
+ return appState;
18
+ }
@@ -0,0 +1,177 @@
1
+ // 'use client';
2
+ //
3
+ // import { Auth0Provider, useAuth0 } from '@auth0/auth0-react';
4
+ // import { Button, ButtonProps } from 'react-bootstrap';
5
+ // import { useRouter } from 'next/navigation';
6
+ // import { useEffect } from 'react';
7
+ // import { emitter } from '../api/apiClient';
8
+ // import RestResponse from '../api/restResponse';
9
+ // import { useToaster } from '../redux/toasterSlice';
10
+ // import { end_session } from '../api/miscCommands';
11
+ // import { createAuth0Client, Auth0Client } from '@auth0/auth0-spa-js';
12
+ //
13
+ // const isSSR = typeof window === 'undefined';
14
+ //
15
+ // const origin = !isSSR ? window.location.origin : '';
16
+ //
17
+ // // @ts-ignore
18
+ // export const isReactNative = () => !isSSR && window.ReactNativeWebView?.postMessage;
19
+ //
20
+ // // @ts-ignore
21
+ // export const postMessage = (data: any = null) => window.ReactNativeWebView?.postMessage(JSON.stringify(data));
22
+ //
23
+ // if (isReactNative()) {
24
+ // const originalConsole = { ...console };
25
+ //
26
+ // const makeLogger =
27
+ // (type) =>
28
+ // (...args) => {
29
+ // postMessage(
30
+ // JSON.stringify({
31
+ // type,
32
+ // data: args,
33
+ // })
34
+ // );
35
+ // originalConsole[type].apply(console, args);
36
+ // };
37
+ //
38
+ // console.log = makeLogger('log');
39
+ // console.log = makeLogger('error');
40
+ // console.log = makeLogger('info');
41
+ // console.log = makeLogger('warn');
42
+ // }
43
+ //
44
+ // export const externalAuth =
45
+ // !isSSR && window['auth0data']
46
+ // ? ({
47
+ // user: window['auth0data'].user,
48
+ // getAccessTokenSilently: async () => window['auth0data'].token.accessToken,
49
+ // isLoading: !window['auth0data'].user,
50
+ // isAuthenticated: !!window['auth0data'].user,
51
+ // loginWithRedirect: () => {},
52
+ // logout: () => postMessage({ type: 'logout' }),
53
+ // } as any)
54
+ // : null;
55
+ //
56
+ // export const useAuth = (): ReturnType<typeof useAuth0> => {
57
+ // const auth0 = useAuth0();
58
+ // return externalAuth || auth0;
59
+ // };
60
+ //
61
+ // // To support passing parameters and hints to Auth0 we need to use lower level API
62
+ // const auth0Config = {
63
+ // domain: process.env.NEXT_PUBLIC_AUTH0_DOMAIN as string,
64
+ // clientId: process.env.NEXT_PUBLIC_AUTH0_CLIENT_ID as string,
65
+ // redirectUri: origin,
66
+ // audience: process.env.NEXT_PUBLIC_AUTH0_AUDIENCE,
67
+ // };
68
+ //
69
+ // let auth0ClientInstance: Auth0Client | null = null;
70
+ //
71
+ // const getAuth0Client = async () => {
72
+ // if (!auth0ClientInstance) {
73
+ // auth0ClientInstance = await createAuth0Client(auth0Config);
74
+ // }
75
+ // return auth0ClientInstance;
76
+ // };
77
+ //
78
+ // export const useExtendedAuth = () => {
79
+ // const auth = useAuth0();
80
+ //
81
+ // const extendedLoginWithRedirect = async (options: any) => {
82
+ // if (options.login_hint || options.screen_hint) {
83
+ // const auth0Client = await getAuth0Client();
84
+ // return auth0Client.loginWithRedirect(options);
85
+ // }
86
+ //
87
+ // return auth.loginWithRedirect(options);
88
+ // };
89
+ //
90
+ // return {
91
+ // ...auth,
92
+ // loginWithRedirect: extendedLoginWithRedirect,
93
+ // };
94
+ // };
95
+ //
96
+ // export const Provider = ({ children, authParams = {} }) => {
97
+ // return (
98
+ // <Auth0Provider
99
+ // domain={process.env.NEXT_PUBLIC_AUTH0_DOMAIN as string}
100
+ // clientId={process.env.NEXT_PUBLIC_AUTH0_CLIENT_ID as string}
101
+ // authorizationParams={{
102
+ // ...authParams,
103
+ // redirect_uri: origin,
104
+ // audience: process.env.NEXT_PUBLIC_AUTH0_AUDIENCE,
105
+ // }}
106
+ // >
107
+ // {children}
108
+ // </Auth0Provider>
109
+ // );
110
+ // };
111
+ //
112
+ // export const LoginButton = (props: ButtonProps) => {
113
+ // const { loginWithRedirect } = useAuth(); //FIXME add state
114
+ // return (
115
+ // <Button {...props} onClick={() => loginWithRedirect()}>
116
+ // Log In
117
+ // </Button>
118
+ // );
119
+ // };
120
+ //
121
+ // export const LogoutButton = ({ as: Cmp = Button, children, ...props }: any) => {
122
+ // const { logout, isAuthenticated, isLoading } = useAuth();
123
+ // if (!isAuthenticated || isLoading) return null;
124
+ //
125
+ // const handleLogout = async () => {
126
+ // try {
127
+ // await end_session();
128
+ // } catch (e) {
129
+ // console.error('Cannot end session', e); // will get here if in Native
130
+ // }
131
+ // logout({ logoutParams: { returnTo: origin } });
132
+ // };
133
+ //
134
+ // return (
135
+ // <Cmp {...props} onClick={handleLogout} role="button">
136
+ // {children || 'Log Out'}
137
+ // </Cmp>
138
+ // );
139
+ // };
140
+ //
141
+ // export const useLogoutTracker = () => {
142
+ // const router = useRouter();
143
+ // const { logout } = useAuth();
144
+ // const { setToast } = useToaster();
145
+ //
146
+ // useEffect(() => {
147
+ // let onError;
148
+ //
149
+ // emitter.on(
150
+ // 'error',
151
+ // (onError = (restResponse: RestResponse) => {
152
+ // if (restResponse.code === 401 || restResponse.message.includes('(Unauthorized)')) {
153
+ // if (restResponse.message.includes('OpenAI API Key')) {
154
+ // setToast('Your account is not provisioned yet. Please check your email for instructions.');
155
+ // return;
156
+ // }
157
+ //
158
+ // if (externalAuth) {
159
+ // externalAuth.logout();
160
+ // return;
161
+ // }
162
+ //
163
+ // logout({
164
+ // async openUrl() {
165
+ // router.replace('/' as any); //FIXME Return to the same page
166
+ // setToast('You have been logged out');
167
+ // },
168
+ // });
169
+ // }
170
+ // })
171
+ // );
172
+ //
173
+ // return () => {
174
+ // emitter.off('error', onError);
175
+ // };
176
+ // }, [logout, router, setToast]);
177
+ // };
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../utils-private/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "declarationDir": "dist"
7
+ },
8
+ "include": ["src"],
9
+ "exclude": []
10
+ }
package/turbo.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "https://turbo.build/schema.json",
3
+ "extends": ["//"],
4
+ "tasks": {
5
+ "build": {
6
+ "dependsOn": ["^build"],
7
+ "outputs": ["src/**/*/index.ts", "package.json", "dist/**/*"]
8
+ }
9
+ }
10
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,2 @@
1
+ import config from '../utils-private/vite.config';
2
+ export default config;