@codixus/client 0.1.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/LICENSE +31 -0
- package/dist/index.cjs +451 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +112 -0
- package/dist/index.d.ts +112 -0
- package/dist/index.js +413 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +75 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +31 -0
- package/dist/react/index.d.ts +31 -0
- package/dist/react/index.js +51 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { CodixusClient, AuthState, SignInParams } from '../index.cjs';
|
|
4
|
+
import '@codixus/shared';
|
|
5
|
+
import 'axios';
|
|
6
|
+
|
|
7
|
+
interface CodixusContextValue {
|
|
8
|
+
client: CodixusClient;
|
|
9
|
+
auth: AuthState & {
|
|
10
|
+
signIn: (params: SignInParams) => Promise<{
|
|
11
|
+
user: Record<string, unknown>;
|
|
12
|
+
isNewUser: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
signOut: () => Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
api: CodixusClient["api"];
|
|
17
|
+
}
|
|
18
|
+
declare function CodixusProvider({ client, children, }: {
|
|
19
|
+
client: CodixusClient;
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
}): react_jsx_runtime.JSX.Element;
|
|
22
|
+
declare function useCodixus(): CodixusContextValue;
|
|
23
|
+
declare function useAuth(): AuthState & {
|
|
24
|
+
signIn: (params: SignInParams) => Promise<{
|
|
25
|
+
user: Record<string, unknown>;
|
|
26
|
+
isNewUser: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
signOut: () => Promise<void>;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { CodixusProvider, useAuth, useCodixus };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { CodixusClient, AuthState, SignInParams } from '../index.js';
|
|
4
|
+
import '@codixus/shared';
|
|
5
|
+
import 'axios';
|
|
6
|
+
|
|
7
|
+
interface CodixusContextValue {
|
|
8
|
+
client: CodixusClient;
|
|
9
|
+
auth: AuthState & {
|
|
10
|
+
signIn: (params: SignInParams) => Promise<{
|
|
11
|
+
user: Record<string, unknown>;
|
|
12
|
+
isNewUser: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
signOut: () => Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
api: CodixusClient["api"];
|
|
17
|
+
}
|
|
18
|
+
declare function CodixusProvider({ client, children, }: {
|
|
19
|
+
client: CodixusClient;
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
}): react_jsx_runtime.JSX.Element;
|
|
22
|
+
declare function useCodixus(): CodixusContextValue;
|
|
23
|
+
declare function useAuth(): AuthState & {
|
|
24
|
+
signIn: (params: SignInParams) => Promise<{
|
|
25
|
+
user: Record<string, unknown>;
|
|
26
|
+
isNewUser: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
signOut: () => Promise<void>;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { CodixusProvider, useAuth, useCodixus };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/react/provider.tsx
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
useContext,
|
|
5
|
+
useState,
|
|
6
|
+
useEffect
|
|
7
|
+
} from "react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
var CodixusContext = createContext(null);
|
|
10
|
+
function CodixusProvider({
|
|
11
|
+
client,
|
|
12
|
+
children
|
|
13
|
+
}) {
|
|
14
|
+
const [authState, setAuthState] = useState({
|
|
15
|
+
isAuthenticated: false,
|
|
16
|
+
isLoading: true,
|
|
17
|
+
user: null
|
|
18
|
+
});
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
client.init();
|
|
21
|
+
const unsubscribe = client.auth.onAuthStateChange(setAuthState);
|
|
22
|
+
return unsubscribe;
|
|
23
|
+
}, [client]);
|
|
24
|
+
const value = {
|
|
25
|
+
client,
|
|
26
|
+
auth: {
|
|
27
|
+
...authState,
|
|
28
|
+
signIn: (params) => client.auth.signIn(params),
|
|
29
|
+
signOut: () => client.auth.signOut()
|
|
30
|
+
},
|
|
31
|
+
api: client.api
|
|
32
|
+
};
|
|
33
|
+
return /* @__PURE__ */ jsx(CodixusContext.Provider, { value, children });
|
|
34
|
+
}
|
|
35
|
+
function useCodixus() {
|
|
36
|
+
const ctx = useContext(CodixusContext);
|
|
37
|
+
if (!ctx) {
|
|
38
|
+
throw new Error("useCodixus must be used within a CodixusProvider");
|
|
39
|
+
}
|
|
40
|
+
return ctx;
|
|
41
|
+
}
|
|
42
|
+
function useAuth() {
|
|
43
|
+
const { auth } = useCodixus();
|
|
44
|
+
return auth;
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
CodixusProvider,
|
|
48
|
+
useAuth,
|
|
49
|
+
useCodixus
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/react/provider.tsx"],"sourcesContent":["import {\n createContext,\n useContext,\n useState,\n useEffect,\n type ReactNode,\n} from \"react\";\nimport type { CodixusClient } from \"../index.js\";\nimport type { AuthState, SignInParams } from \"../auth/auth-manager.js\";\n\ninterface CodixusContextValue {\n client: CodixusClient;\n auth: AuthState & {\n signIn: (params: SignInParams) => Promise<{ user: Record<string, unknown>; isNewUser: boolean }>;\n signOut: () => Promise<void>;\n };\n api: CodixusClient[\"api\"];\n}\n\nconst CodixusContext = createContext<CodixusContextValue | null>(null);\n\nexport function CodixusProvider({\n client,\n children,\n}: {\n client: CodixusClient;\n children: ReactNode;\n}) {\n const [authState, setAuthState] = useState<AuthState>({\n isAuthenticated: false,\n isLoading: true,\n user: null,\n });\n\n useEffect(() => {\n client.init();\n const unsubscribe = client.auth.onAuthStateChange(setAuthState);\n return unsubscribe;\n }, [client]);\n\n const value: CodixusContextValue = {\n client,\n auth: {\n ...authState,\n signIn: (params) => client.auth.signIn(params),\n signOut: () => client.auth.signOut(),\n },\n api: client.api,\n };\n\n return (\n <CodixusContext.Provider value={value}>{children}</CodixusContext.Provider>\n );\n}\n\nexport function useCodixus(): CodixusContextValue {\n const ctx = useContext(CodixusContext);\n if (!ctx) {\n throw new Error(\"useCodixus must be used within a CodixusProvider\");\n }\n return ctx;\n}\n\nexport function useAuth() {\n const { auth } = useCodixus();\n return auth;\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AA6CH;AAhCJ,IAAM,iBAAiB,cAA0C,IAAI;AAE9D,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AACF,GAGG;AACD,QAAM,CAAC,WAAW,YAAY,IAAI,SAAoB;AAAA,IACpD,iBAAiB;AAAA,IACjB,WAAW;AAAA,IACX,MAAM;AAAA,EACR,CAAC;AAED,YAAU,MAAM;AACd,WAAO,KAAK;AACZ,UAAM,cAAc,OAAO,KAAK,kBAAkB,YAAY;AAC9D,WAAO;AAAA,EACT,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,QAA6B;AAAA,IACjC;AAAA,IACA,MAAM;AAAA,MACJ,GAAG;AAAA,MACH,QAAQ,CAAC,WAAW,OAAO,KAAK,OAAO,MAAM;AAAA,MAC7C,SAAS,MAAM,OAAO,KAAK,QAAQ;AAAA,IACrC;AAAA,IACA,KAAK,OAAO;AAAA,EACd;AAEA,SACE,oBAAC,eAAe,UAAf,EAAwB,OAAe,UAAS;AAErD;AAEO,SAAS,aAAkC;AAChD,QAAM,MAAM,WAAW,cAAc;AACrC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACpE;AACA,SAAO;AACT;AAEO,SAAS,UAAU;AACxB,QAAM,EAAE,KAAK,IAAI,WAAW;AAC5B,SAAO;AACT;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codixus/client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Client SDK for React Native and web — auth, API client, typed collections",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./react": {
|
|
17
|
+
"types": "./dist/react/index.d.ts",
|
|
18
|
+
"import": "./dist/react/index.js",
|
|
19
|
+
"require": "./dist/react/index.cjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": ["dist", "LICENSE"],
|
|
23
|
+
"keywords": ["codixus", "sdk", "client", "react-native", "auth", "api"],
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/codixus/sdk",
|
|
27
|
+
"directory": "packages/client"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup",
|
|
31
|
+
"dev": "tsup --watch",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"clean": "rm -rf dist"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@codixus/shared": "0.1.0",
|
|
38
|
+
"axios": "^1.7.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/react": "^19",
|
|
45
|
+
"react": "^19",
|
|
46
|
+
"tsup": "^8",
|
|
47
|
+
"typescript": "^5.9"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|