@opexa/portal-sdk 0.59.77 → 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-3WS4U4B7.js → chunk-YL46WJBV.js} +13 -15
- package/dist/chunk-YL46WJBV.js.map +1 -0
- package/dist/index.cjs +45 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -12
- package/dist/index.js.map +1 -1
- package/dist/services/index.cjs +10 -12
- package/dist/services/index.cjs.map +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-3WS4U4B7.js.map +0 -1
- package/dist/chunk-7APXFZ5G.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';
|
|
@@ -762,6 +762,7 @@ var SessionManager = class {
|
|
|
762
762
|
*/
|
|
763
763
|
v4AccessToken = null;
|
|
764
764
|
v4AccessTokenExpiresAt = null;
|
|
765
|
+
v4RefreshPromise = null;
|
|
765
766
|
constructor(config) {
|
|
766
767
|
this.authService = config.authService;
|
|
767
768
|
this.walletService = config.walletService;
|
|
@@ -780,13 +781,19 @@ var SessionManager = class {
|
|
|
780
781
|
persist(data, version) {
|
|
781
782
|
const now = /* @__PURE__ */ new Date();
|
|
782
783
|
if (version === 4) {
|
|
783
|
-
|
|
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;
|
|
784
791
|
this.v4AccessTokenExpiresAt = addMinutes(now, 5).getTime();
|
|
785
792
|
localStorage.setItem(
|
|
786
793
|
this.storageKey,
|
|
787
794
|
JSON.stringify({ version, session: data.session })
|
|
788
795
|
);
|
|
789
|
-
return;
|
|
796
|
+
return true;
|
|
790
797
|
}
|
|
791
798
|
localStorage.setItem(
|
|
792
799
|
this.storageKey,
|
|
@@ -797,6 +804,16 @@ var SessionManager = class {
|
|
|
797
804
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
798
805
|
})
|
|
799
806
|
);
|
|
807
|
+
return true;
|
|
808
|
+
}
|
|
809
|
+
malformedResponseError() {
|
|
810
|
+
return {
|
|
811
|
+
ok: false,
|
|
812
|
+
error: {
|
|
813
|
+
name: "UnknownError",
|
|
814
|
+
message: "Something went wrong."
|
|
815
|
+
}
|
|
816
|
+
};
|
|
800
817
|
}
|
|
801
818
|
async create(input, version = 1) {
|
|
802
819
|
if (this.isServer) {
|
|
@@ -834,7 +851,7 @@ var SessionManager = class {
|
|
|
834
851
|
maxAttempt: 5
|
|
835
852
|
})();
|
|
836
853
|
if (!r1.ok) return r1;
|
|
837
|
-
this.persist(r1.data, version);
|
|
854
|
+
if (!this.persist(r1.data, version)) return this.malformedResponseError();
|
|
838
855
|
return {
|
|
839
856
|
ok: true,
|
|
840
857
|
data: null
|
|
@@ -843,7 +860,7 @@ var SessionManager = class {
|
|
|
843
860
|
if (input.type === "MOBILE_NUMBER") {
|
|
844
861
|
const res2 = await this.authService.createSession(input, version);
|
|
845
862
|
if (res2.ok) {
|
|
846
|
-
this.persist(res2.data, version);
|
|
863
|
+
if (!this.persist(res2.data, version)) return this.malformedResponseError();
|
|
847
864
|
return {
|
|
848
865
|
ok: true,
|
|
849
866
|
data: null
|
|
@@ -861,7 +878,7 @@ var SessionManager = class {
|
|
|
861
878
|
version
|
|
862
879
|
);
|
|
863
880
|
if (res2.ok) {
|
|
864
|
-
this.persist(res2.data, version);
|
|
881
|
+
if (!this.persist(res2.data, version)) return this.malformedResponseError();
|
|
865
882
|
return {
|
|
866
883
|
ok: true,
|
|
867
884
|
data: null
|
|
@@ -873,7 +890,7 @@ var SessionManager = class {
|
|
|
873
890
|
localStorage.setItem(this.platformStorageKey, "CABINET");
|
|
874
891
|
const res2 = await this.authService.createSession(input, version);
|
|
875
892
|
if (res2.ok) {
|
|
876
|
-
this.persist(res2.data, version);
|
|
893
|
+
if (!this.persist(res2.data, version)) return this.malformedResponseError();
|
|
877
894
|
return {
|
|
878
895
|
ok: true,
|
|
879
896
|
data: null
|
|
@@ -891,7 +908,7 @@ var SessionManager = class {
|
|
|
891
908
|
}
|
|
892
909
|
};
|
|
893
910
|
}
|
|
894
|
-
this.persist(res.data, version);
|
|
911
|
+
if (!this.persist(res.data, version)) return this.malformedResponseError();
|
|
895
912
|
return {
|
|
896
913
|
ok: true,
|
|
897
914
|
data: null
|
|
@@ -902,8 +919,8 @@ var SessionManager = class {
|
|
|
902
919
|
if (res.ok) {
|
|
903
920
|
if (this.isServer) {
|
|
904
921
|
this.logger.warn("'localStorage' is not available on the server.");
|
|
905
|
-
} else {
|
|
906
|
-
this.
|
|
922
|
+
} else if (!this.persist(res.data, 1)) {
|
|
923
|
+
return this.malformedResponseError();
|
|
907
924
|
}
|
|
908
925
|
return { ok: true };
|
|
909
926
|
} else {
|
|
@@ -1082,6 +1099,15 @@ var SessionManager = class {
|
|
|
1082
1099
|
return await this.refreshV4(session);
|
|
1083
1100
|
}
|
|
1084
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) {
|
|
1085
1111
|
this.logger.info("Refreshing session...");
|
|
1086
1112
|
this.refreshing = true;
|
|
1087
1113
|
const res = await this.authService.refreshSession(void 0, 4);
|