@oxyhq/services 0.0.3 → 0.0.5

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.
@@ -0,0 +1,26 @@
1
+ interface SessionModel {
2
+ user: {
3
+ id: string;
4
+ username: string;
5
+ name: string;
6
+ lastname: string;
7
+ email: string;
8
+ verified: boolean;
9
+ profile_image_url: string;
10
+ created_at: string;
11
+ };
12
+ }
13
+ type SessionState = {
14
+ session: SessionModel | null;
15
+ status: string;
16
+ error: any;
17
+ fetchSessionData: () => void;
18
+ };
19
+ export declare const useSessionStore: import("zustand").UseBoundStore<import("zustand").StoreApi<SessionState>>;
20
+ declare function useOxySession(): {
21
+ session: SessionModel | null;
22
+ status: string;
23
+ error: any;
24
+ };
25
+ export default useOxySession;
26
+ //# sourceMappingURL=useOxySession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOxySession.d.ts","sourceRoot":"","sources":["../../src/hooks/useOxySession.ts"],"names":[],"mappings":"AAOA,UAAU,YAAY;IACpB,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,OAAO,CAAC;QAClB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,KAAK,YAAY,GAAG;IAClB,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,GAAG,CAAC;IACX,gBAAgB,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,eAAe,2EAmC1B,CAAC;AAEH,iBAAS,aAAa;;;;EAQrB;AAED,eAAe,aAAa,CAAC"}
@@ -0,0 +1,45 @@
1
+ import { useEffect } from "react";
2
+ import axios from "axios";
3
+ import { create } from "zustand";
4
+ import localforage from "localforage";
5
+ import { OXY_AUTH_URL } from "../config";
6
+ export const useSessionStore = create((set) => {
7
+ let isFirstFetch = true;
8
+ return {
9
+ session: null,
10
+ status: "loading",
11
+ error: null,
12
+ fetchSessionData: async () => {
13
+ try {
14
+ if (isFirstFetch) {
15
+ set({ status: "loading" });
16
+ isFirstFetch = false;
17
+ }
18
+ // Get the session ID from the URL parameters if it exists
19
+ const urlParams = new URLSearchParams(window.location.search);
20
+ let clientKey = urlParams.get("clientKey");
21
+ // If the session ID was not found in the URL parameters, get it from local storage
22
+ if (!clientKey) {
23
+ clientKey = await localforage.getItem("clientKey");
24
+ }
25
+ else {
26
+ // If the session ID was found in the URL parameters, set it in local storage
27
+ await localforage.setItem("clientKey", clientKey);
28
+ }
29
+ const response = await axios.get(OXY_AUTH_URL + "/api/session/" + clientKey);
30
+ set({ session: response.data, status: "success" });
31
+ }
32
+ catch (error) {
33
+ set({ error, status: "error" });
34
+ }
35
+ },
36
+ };
37
+ });
38
+ function useOxySession() {
39
+ const { session, status, error, fetchSessionData } = useSessionStore();
40
+ useEffect(() => {
41
+ fetchSessionData();
42
+ }, []);
43
+ return { session, status, error };
44
+ }
45
+ export default useOxySession;
@@ -17,10 +17,10 @@ type SessionState = {
17
17
  fetchSessionData: () => void;
18
18
  };
19
19
  export declare const useSessionStore: import("zustand").UseBoundStore<import("zustand").StoreApi<SessionState>>;
20
- declare function usePeableSession(): {
20
+ declare function useOxySession(): {
21
21
  session: SessionModel | null;
22
22
  status: string;
23
23
  error: any;
24
24
  };
25
- export default usePeableSession;
25
+ export default useOxySession;
26
26
  //# sourceMappingURL=usePeableSession.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePeableSession.d.ts","sourceRoot":"","sources":["../../src/hooks/usePeableSession.ts"],"names":[],"mappings":"AAOA,UAAU,YAAY;IACpB,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,OAAO,CAAC;QAClB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,KAAK,YAAY,GAAG;IAClB,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,GAAG,CAAC;IACX,gBAAgB,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,eAAe,2EAmC1B,CAAC;AAEH,iBAAS,gBAAgB;;;;EAQxB;AAED,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"usePeableSession.d.ts","sourceRoot":"","sources":["../../src/hooks/usePeableSession.ts"],"names":[],"mappings":"AAOA,UAAU,YAAY;IACpB,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,OAAO,CAAC;QAClB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,KAAK,YAAY,GAAG;IAClB,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,GAAG,CAAC;IACX,gBAAgB,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,eAAe,2EAmC1B,CAAC;AAEH,iBAAS,aAAa;;;;EAQrB;AAED,eAAe,aAAa,CAAC"}
@@ -35,11 +35,11 @@ export const useSessionStore = create((set) => {
35
35
  },
36
36
  };
37
37
  });
38
- function usePeableSession() {
38
+ function useOxySession() {
39
39
  const { session, status, error, fetchSessionData } = useSessionStore();
40
40
  useEffect(() => {
41
41
  fetchSessionData();
42
42
  }, []);
43
43
  return { session, status, error };
44
44
  }
45
- export default usePeableSession;
45
+ export default useOxySession;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import usePeableSession from "./hooks/usePeableSession";
1
+ import useOxySession from "./hooks/useOxySession";
2
2
  import getUserById from "./hooks/getUserById";
3
- export { usePeableSession, getUserById };
3
+ export { useOxySession, getUserById };
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AACxD,OAAO,WAAW,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,uBAAuB,CAAC;AAClD,OAAO,WAAW,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import usePeableSession from "./hooks/usePeableSession";
1
+ import useOxySession from "./hooks/useOxySession";
2
2
  import getUserById from "./hooks/getUserById";
3
- export { usePeableSession, getUserById };
3
+ export { useOxySession, getUserById };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxyhq/services",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "homepage": "https://oxy.so/",
6
6
  "main": "./dist/index.js",