diff --git a/package.json b/package.json index 3359919..431cbf6 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,10 @@ "build": "tsc -b && vite build", "lint": "eslint .", "prepublish": "npm run build", - "preview": "vite preview" + "preview": "vite preview", + "watch": "vite build --watch" }, + "types": "./dist/auth-client.d.ts", "publishConfig": { "access": "public" }, diff --git a/src/context/index.ts b/src/context/index.ts index 2474636..a1262d0 100644 --- a/src/context/index.ts +++ b/src/context/index.ts @@ -1,2 +1,2 @@ -export { OAuth2Provider } from './auth-context.tsx'; +export { OAuth2Provider } from './auth-context'; export { useOAuth2 } from './use-oauth2'; diff --git a/src/context/use-oauth2.ts b/src/context/use-oauth2.ts index 76207d0..2e47dfd 100644 --- a/src/context/use-oauth2.ts +++ b/src/context/use-oauth2.ts @@ -1,5 +1,5 @@ import { useContext } from 'react'; -import { OAuth2Context } from '../context/auth-context.tsx'; +import { OAuth2Context } from '../context/auth-context'; export const useOAuth2 = () => { const context = useContext(OAuth2Context); diff --git a/src/index.ts b/src/index.ts index 22751a9..fc55358 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -export { OAuth2Provider, useOAuth2 } from './context/'; +export * from './context/'; diff --git a/src/main.tsx b/src/main.tsx index 28368ce..4bbf491 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,6 +1,6 @@ import { StrictMode } from 'react'; import { createRoot } from 'react-dom/client'; -import App from './App.tsx'; +import App from './App'; import './index.css'; createRoot(document.getElementById('root')!).render( diff --git a/tsconfig.json b/tsconfig.json index 1ffef60..c518040 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,24 @@ { - "files": [], - "references": [ - { "path": "./tsconfig.app.json" }, - { "path": "./tsconfig.node.json" } - ] + "compilerOptions": { + "target": "ES2021", + "declaration": true, + "declarationMap": true, + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + "moduleResolution": "Node", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "allowSyntheticDefaultImports": true + }, + "include": ["src"], + "exclude": ["**/*.spec.ts"] } diff --git a/types/App.d.ts b/types/App.d.ts new file mode 100644 index 0000000..29b5ce3 --- /dev/null +++ b/types/App.d.ts @@ -0,0 +1,3 @@ +import './App.css'; +declare function App(): import("react/jsx-runtime").JSX.Element; +export default App; diff --git a/types/constants/index.d.ts b/types/constants/index.d.ts new file mode 100644 index 0000000..ec4ce46 --- /dev/null +++ b/types/constants/index.d.ts @@ -0,0 +1 @@ +export * from './urls'; diff --git a/types/constants/urls.d.ts b/types/constants/urls.d.ts new file mode 100644 index 0000000..fc8e37a --- /dev/null +++ b/types/constants/urls.d.ts @@ -0,0 +1,10 @@ +export declare const DEFAULT_OAUTH_LOGOUT_URL = "https://oauth.deriv.com/oauth2/sessions/logout"; +export declare const DEFAULT_OAUTH_ORIGIN_URL = "https://oauth.deriv.com"; +export declare const getServerInfo: () => { + appId: string | null | undefined; + lang: string | null | undefined; + serverUrl: string | null | undefined; +}; +export declare const getOauthUrl: () => string; +export declare const getOAuthLogoutUrl: () => string; +export declare const getOAuthOrigin: () => string; diff --git a/types/context/auth-context.d.ts b/types/context/auth-context.d.ts new file mode 100644 index 0000000..66ee1ef --- /dev/null +++ b/types/context/auth-context.d.ts @@ -0,0 +1,12 @@ +import React from 'react'; +type OAuth2ContextValue = { + OAuth2Logout: () => void; +}; +type OAuth2ProviderProps = { + children: React.ReactNode; + logout: () => Promise; + oauthUrl: string; +}; +export declare const OAuth2Context: React.Context; +export declare const OAuth2Provider: React.FC; +export {}; diff --git a/types/context/index.d.ts b/types/context/index.d.ts new file mode 100644 index 0000000..a1262d0 --- /dev/null +++ b/types/context/index.d.ts @@ -0,0 +1,2 @@ +export { OAuth2Provider } from './auth-context'; +export { useOAuth2 } from './use-oauth2'; diff --git a/types/context/use-oauth2.d.ts b/types/context/use-oauth2.d.ts new file mode 100644 index 0000000..9f2d7c4 --- /dev/null +++ b/types/context/use-oauth2.d.ts @@ -0,0 +1,3 @@ +export declare const useOAuth2: () => { + OAuth2Logout: () => void; +}; diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..22751a9 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1 @@ +export { OAuth2Provider, useOAuth2 } from './context/'; diff --git a/types/main.d.ts b/types/main.d.ts new file mode 100644 index 0000000..6a9a4b1 --- /dev/null +++ b/types/main.d.ts @@ -0,0 +1 @@ +import './index.css'; diff --git a/vite.config.ts b/vite.config.ts index 90c98c6..6b0ad8d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -7,15 +7,21 @@ import dts from 'vite-plugin-dts'; // https://vitejs.dev/config/ export default defineConfig({ - plugins: [react(), dts({ - include: ['src'], - exclude: ['src/**/*.spec.tsx'], - tsconfigPath: './tsconfig.app.json' - })], + plugins: [ + react(), + dts({ + include: ['src'], + exclude: ['src/**/*.spec.tsx'], + tsconfigPath: './tsconfig.app.json', + insertTypesEntry: true, + }), + ], build: { lib: { entry: resolve(__dirname, 'src/index.ts'), formats: ['es'], + name: '@deriv-com/auth-client', + fileName: 'auth-client', }, copyPublicDir: false, rollupOptions: {