@opexa/portal-sdk 0.59.76 → 0.59.78
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/README.md +1634 -1634
- package/dist/{chunk-7APXFZ5G.js → chunk-5WRVWQBT.js} +3 -3
- package/dist/chunk-5WRVWQBT.js.map +1 -0
- package/dist/{chunk-WVFSGB7Y.js → chunk-ROBGEUSE.js} +2 -2
- package/dist/chunk-ROBGEUSE.js.map +1 -0
- package/dist/{chunk-BDZPLMTL.js → chunk-YL46WJBV.js} +29 -19
- package/dist/chunk-YL46WJBV.js.map +1 -0
- package/dist/index.cjs +81 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +58 -14
- package/dist/index.js.map +1 -1
- package/dist/services/index.cjs +26 -16
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.d.cts +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +2 -2
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-7APXFZ5G.js.map +0 -1
- package/dist/chunk-BDZPLMTL.js.map +0 -1
- package/dist/chunk-WVFSGB7Y.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CmsPortalService, GameService, ExtensionService, FileService, WalletService, AccountService, ReportService, PortalService, TriggerService, AuthService, getFingerPrint } from './chunk-
|
|
2
|
-
import { GraphQLClient, isPlainObject } from './chunk-
|
|
3
|
-
import './chunk-
|
|
1
|
+
import { CmsPortalService, GameService, ExtensionService, FileService, WalletService, AccountService, ReportService, PortalService, TriggerService, AuthService, getFingerPrint } from './chunk-YL46WJBV.js';
|
|
2
|
+
import { GraphQLClient, isPlainObject } from './chunk-5WRVWQBT.js';
|
|
3
|
+
import './chunk-ROBGEUSE.js';
|
|
4
4
|
import { ObjectId } from '@opexa/object-id';
|
|
5
5
|
export { ObjectId } from '@opexa/object-id';
|
|
6
6
|
import { Capacitor } from '@capacitor/core';
|
|
@@ -695,9 +695,18 @@ var SessionManagerCookie = class {
|
|
|
695
695
|
this.logger.warn("'client cookies' is not available on the server.");
|
|
696
696
|
return;
|
|
697
697
|
}
|
|
698
|
+
let version = 1;
|
|
699
|
+
const val = cookies.get(this.storageKey);
|
|
700
|
+
if (val) {
|
|
701
|
+
try {
|
|
702
|
+
const stored = JSON.parse(val);
|
|
703
|
+
version = stored.version ?? 1;
|
|
704
|
+
} catch {
|
|
705
|
+
}
|
|
706
|
+
}
|
|
698
707
|
const res = await this.get();
|
|
699
708
|
if (res.data?.accessToken) {
|
|
700
|
-
await this.authService.destroySession(res.data.accessToken);
|
|
709
|
+
await this.authService.destroySession(res.data.accessToken, version);
|
|
701
710
|
}
|
|
702
711
|
this.v4AccessToken = null;
|
|
703
712
|
this.v4AccessTokenExpiresAt = null;
|
|
@@ -753,6 +762,7 @@ var SessionManager = class {
|
|
|
753
762
|
*/
|
|
754
763
|
v4AccessToken = null;
|
|
755
764
|
v4AccessTokenExpiresAt = null;
|
|
765
|
+
v4RefreshPromise = null;
|
|
756
766
|
constructor(config) {
|
|
757
767
|
this.authService = config.authService;
|
|
758
768
|
this.walletService = config.walletService;
|
|
@@ -771,13 +781,19 @@ var SessionManager = class {
|
|
|
771
781
|
persist(data, version) {
|
|
772
782
|
const now = /* @__PURE__ */ new Date();
|
|
773
783
|
if (version === 4) {
|
|
774
|
-
|
|
784
|
+
if (!data.session || !data.accessToken) {
|
|
785
|
+
this.logger.error(
|
|
786
|
+
"Malformed session response: expected 'session' and 'accessToken'."
|
|
787
|
+
);
|
|
788
|
+
return false;
|
|
789
|
+
}
|
|
790
|
+
this.v4AccessToken = data.accessToken;
|
|
775
791
|
this.v4AccessTokenExpiresAt = addMinutes(now, 5).getTime();
|
|
776
792
|
localStorage.setItem(
|
|
777
793
|
this.storageKey,
|
|
778
794
|
JSON.stringify({ version, session: data.session })
|
|
779
795
|
);
|
|
780
|
-
return;
|
|
796
|
+
return true;
|
|
781
797
|
}
|
|
782
798
|
localStorage.setItem(
|
|
783
799
|
this.storageKey,
|
|
@@ -788,6 +804,16 @@ var SessionManager = class {
|
|
|
788
804
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
789
805
|
})
|
|
790
806
|
);
|
|
807
|
+
return true;
|
|
808
|
+
}
|
|
809
|
+
malformedResponseError() {
|
|
810
|
+
return {
|
|
811
|
+
ok: false,
|
|
812
|
+
error: {
|
|
813
|
+
name: "UnknownError",
|
|
814
|
+
message: "Something went wrong."
|
|
815
|
+
}
|
|
816
|
+
};
|
|
791
817
|
}
|
|
792
818
|
async create(input, version = 1) {
|
|
793
819
|
if (this.isServer) {
|
|
@@ -825,7 +851,7 @@ var SessionManager = class {
|
|
|
825
851
|
maxAttempt: 5
|
|
826
852
|
})();
|
|
827
853
|
if (!r1.ok) return r1;
|
|
828
|
-
this.persist(r1.data, version);
|
|
854
|
+
if (!this.persist(r1.data, version)) return this.malformedResponseError();
|
|
829
855
|
return {
|
|
830
856
|
ok: true,
|
|
831
857
|
data: null
|
|
@@ -834,7 +860,7 @@ var SessionManager = class {
|
|
|
834
860
|
if (input.type === "MOBILE_NUMBER") {
|
|
835
861
|
const res2 = await this.authService.createSession(input, version);
|
|
836
862
|
if (res2.ok) {
|
|
837
|
-
this.persist(res2.data, version);
|
|
863
|
+
if (!this.persist(res2.data, version)) return this.malformedResponseError();
|
|
838
864
|
return {
|
|
839
865
|
ok: true,
|
|
840
866
|
data: null
|
|
@@ -852,7 +878,7 @@ var SessionManager = class {
|
|
|
852
878
|
version
|
|
853
879
|
);
|
|
854
880
|
if (res2.ok) {
|
|
855
|
-
this.persist(res2.data, version);
|
|
881
|
+
if (!this.persist(res2.data, version)) return this.malformedResponseError();
|
|
856
882
|
return {
|
|
857
883
|
ok: true,
|
|
858
884
|
data: null
|
|
@@ -864,7 +890,7 @@ var SessionManager = class {
|
|
|
864
890
|
localStorage.setItem(this.platformStorageKey, "CABINET");
|
|
865
891
|
const res2 = await this.authService.createSession(input, version);
|
|
866
892
|
if (res2.ok) {
|
|
867
|
-
this.persist(res2.data, version);
|
|
893
|
+
if (!this.persist(res2.data, version)) return this.malformedResponseError();
|
|
868
894
|
return {
|
|
869
895
|
ok: true,
|
|
870
896
|
data: null
|
|
@@ -882,7 +908,7 @@ var SessionManager = class {
|
|
|
882
908
|
}
|
|
883
909
|
};
|
|
884
910
|
}
|
|
885
|
-
this.persist(res.data, version);
|
|
911
|
+
if (!this.persist(res.data, version)) return this.malformedResponseError();
|
|
886
912
|
return {
|
|
887
913
|
ok: true,
|
|
888
914
|
data: null
|
|
@@ -893,8 +919,8 @@ var SessionManager = class {
|
|
|
893
919
|
if (res.ok) {
|
|
894
920
|
if (this.isServer) {
|
|
895
921
|
this.logger.warn("'localStorage' is not available on the server.");
|
|
896
|
-
} else {
|
|
897
|
-
this.
|
|
922
|
+
} else if (!this.persist(res.data, 1)) {
|
|
923
|
+
return this.malformedResponseError();
|
|
898
924
|
}
|
|
899
925
|
return { ok: true };
|
|
900
926
|
} else {
|
|
@@ -1073,6 +1099,15 @@ var SessionManager = class {
|
|
|
1073
1099
|
return await this.refreshV4(session);
|
|
1074
1100
|
}
|
|
1075
1101
|
async refreshV4(session) {
|
|
1102
|
+
if (this.v4RefreshPromise) return await this.v4RefreshPromise;
|
|
1103
|
+
this.v4RefreshPromise = this.requestV4Refresh(session);
|
|
1104
|
+
try {
|
|
1105
|
+
return await this.v4RefreshPromise;
|
|
1106
|
+
} finally {
|
|
1107
|
+
this.v4RefreshPromise = null;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
async requestV4Refresh(session) {
|
|
1076
1111
|
this.logger.info("Refreshing session...");
|
|
1077
1112
|
this.refreshing = true;
|
|
1078
1113
|
const res = await this.authService.refreshSession(void 0, 4);
|
|
@@ -1107,9 +1142,18 @@ var SessionManager = class {
|
|
|
1107
1142
|
this.logger.warn("'localStorage' is not available on the server.");
|
|
1108
1143
|
return;
|
|
1109
1144
|
}
|
|
1145
|
+
let version = 1;
|
|
1146
|
+
const val = localStorage.getItem(this.storageKey);
|
|
1147
|
+
if (val) {
|
|
1148
|
+
try {
|
|
1149
|
+
const stored = JSON.parse(val);
|
|
1150
|
+
version = stored.version ?? 1;
|
|
1151
|
+
} catch {
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1110
1154
|
const res = await this.get();
|
|
1111
1155
|
if (res.data?.accessToken) {
|
|
1112
|
-
await this.authService.destroySession(res.data.accessToken);
|
|
1156
|
+
await this.authService.destroySession(res.data.accessToken, version);
|
|
1113
1157
|
}
|
|
1114
1158
|
this.v4AccessToken = null;
|
|
1115
1159
|
this.v4AccessTokenExpiresAt = null;
|