@oxyhq/services 0.0.78 → 0.0.80

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,2 @@
1
+ export declare const getClientKey: () => Promise<unknown>;
2
+ //# sourceMappingURL=getClientKey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getClientKey.d.ts","sourceRoot":"","sources":["../../src/hooks/getClientKey.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,wBAuBxB,CAAC"}
@@ -0,0 +1,19 @@
1
+ export const getClientKey = async () => {
2
+ const iframe = document.createElement("iframe");
3
+ iframe.src = "https://auth.oxy.so/share-session";
4
+ iframe.style.display = "none";
5
+ document.body.appendChild(iframe);
6
+ return new Promise((resolve) => {
7
+ const messageHandler = (event) => {
8
+ if (event.origin === "https://auth.oxy.so" && event.data.clientKey) {
9
+ window.removeEventListener("message", messageHandler);
10
+ document.body.removeChild(iframe);
11
+ resolve(event.data.clientKey);
12
+ }
13
+ };
14
+ window.addEventListener("message", messageHandler);
15
+ iframe.onload = () => {
16
+ iframe.contentWindow?.postMessage({ action: "getClientKey" }, "https://auth.oxy.so");
17
+ };
18
+ });
19
+ };
@@ -0,0 +1,6 @@
1
+ declare const useCrossDomainStorage: () => {
2
+ set: (key: string, value: string) => void;
3
+ get: (key: string) => string | null;
4
+ };
5
+ export default useCrossDomainStorage;
6
+ //# sourceMappingURL=useCrossDomainStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCrossDomainStorage.d.ts","sourceRoot":"","sources":["../../src/hooks/useCrossDomainStorage.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,qBAAqB;eACP,MAAM,SAAS,MAAM;eAKrB,MAAM;CAmBzB,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { useEffect } from "react";
2
+ const useCrossDomainStorage = () => {
3
+ const set = (key, value) => {
4
+ localStorage.setItem(key, value);
5
+ window.postMessage({ key, value }, "*");
6
+ };
7
+ const get = (key) => {
8
+ return localStorage.getItem(key);
9
+ };
10
+ const handlePostMessage = (event) => {
11
+ if (event.origin !== window.location.origin) {
12
+ const { key, value } = event.data;
13
+ localStorage.setItem(key, value);
14
+ }
15
+ };
16
+ useEffect(() => {
17
+ window.addEventListener("message", handlePostMessage);
18
+ return () => {
19
+ window.removeEventListener("message", handlePostMessage);
20
+ };
21
+ }, []);
22
+ return { set, get };
23
+ };
24
+ export default useCrossDomainStorage;
@@ -1 +1 @@
1
- {"version":3,"file":"useOxySession.d.ts","sourceRoot":"","sources":["../../src/hooks/useOxySession.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,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,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,QAAQ,CAAC;QACf,OAAO,EAAE,OAAO,CAAC;QACjB,kBAAkB,EAAE,OAAO,CAAC;KAC7B,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,2EA4D1B,CAAC;AAEH,iBAAS,aAAa;;;;EAQrB;AAED,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"useOxySession.d.ts","sourceRoot":"","sources":["../../src/hooks/useOxySession.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,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,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,QAAQ,CAAC;QACf,OAAO,EAAE,OAAO,CAAC;QACjB,kBAAkB,EAAE,OAAO,CAAC;KAC7B,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,2EAmD1B,CAAC;AAEH,iBAAS,aAAa;;;;EAQrB;AAED,eAAe,aAAa,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { useEffect } from "react";
2
2
  import axios from "axios";
3
3
  import { create } from "zustand";
4
- import localforage from "localforage";
4
+ import { getClientKey } from "./getClientKey";
5
5
  import { OXY_AUTH_URL } from "../config";
6
6
  export const useSessionStore = create((set) => {
7
7
  let isFirstFetch = true;
@@ -15,17 +15,8 @@ export const useSessionStore = create((set) => {
15
15
  set({ status: "loading" });
16
16
  isFirstFetch = false;
17
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
- }
18
+ // Get the client key using the getClientKey function
19
+ let clientKey = await getClientKey();
29
20
  const response = await axios.get(OXY_AUTH_URL + "/api/session/" + clientKey);
30
21
  if (response.status !== 200) {
31
22
  throw new Error(`Unexpected response status: ${response.status}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxyhq/services",
3
- "version": "0.0.78",
3
+ "version": "0.0.80",
4
4
  "description": "",
5
5
  "homepage": "https://oxy.so/",
6
6
  "main": "./dist/index.js",