@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.cjs
CHANGED
|
@@ -4544,26 +4544,26 @@ var AuthService = class {
|
|
|
4544
4544
|
body: JSON.stringify(input),
|
|
4545
4545
|
...version === 4 && { credentials: "include" }
|
|
4546
4546
|
});
|
|
4547
|
-
const
|
|
4547
|
+
const body = await res.json();
|
|
4548
4548
|
if (res.ok) {
|
|
4549
4549
|
return {
|
|
4550
4550
|
ok: true,
|
|
4551
|
-
data
|
|
4551
|
+
data: version !== 1 ? body.data ?? body : body
|
|
4552
4552
|
};
|
|
4553
4553
|
}
|
|
4554
|
-
if (
|
|
4554
|
+
if (body.code === "ACCOUNT_BLACKLISTED") {
|
|
4555
4555
|
return {
|
|
4556
4556
|
ok: false,
|
|
4557
4557
|
error: createOperationError("AccountBlacklistedError")
|
|
4558
4558
|
};
|
|
4559
4559
|
}
|
|
4560
|
-
if (
|
|
4560
|
+
if (body.code === "MEMBER_ACCOUNT_SUSPENDED") {
|
|
4561
4561
|
return {
|
|
4562
4562
|
ok: false,
|
|
4563
4563
|
error: createOperationError("AccountSuspendedError")
|
|
4564
4564
|
};
|
|
4565
4565
|
}
|
|
4566
|
-
if (
|
|
4566
|
+
if (body.code === "INVALID_RECAPTCHA_RESPONSE") {
|
|
4567
4567
|
return {
|
|
4568
4568
|
ok: false,
|
|
4569
4569
|
error: createOperationError("InvalidReCAPTCHAResponseError")
|
|
@@ -4644,20 +4644,20 @@ var AuthService = class {
|
|
|
4644
4644
|
...version === 4 && { credentials: "include" }
|
|
4645
4645
|
}
|
|
4646
4646
|
);
|
|
4647
|
-
const
|
|
4647
|
+
const body = await res.json();
|
|
4648
4648
|
if (res.ok) {
|
|
4649
4649
|
return {
|
|
4650
4650
|
ok: true,
|
|
4651
|
-
data
|
|
4651
|
+
data: version !== 1 ? body.data ?? body : body
|
|
4652
4652
|
};
|
|
4653
4653
|
}
|
|
4654
|
-
if (
|
|
4654
|
+
if (body.code === "ACCOUNT_BLACKLISTED") {
|
|
4655
4655
|
return {
|
|
4656
4656
|
ok: false,
|
|
4657
4657
|
error: createOperationError("AccountBlacklistedError")
|
|
4658
4658
|
};
|
|
4659
4659
|
}
|
|
4660
|
-
if (
|
|
4660
|
+
if (body.code === "MEMBER_ACCOUNT_SUSPENDED") {
|
|
4661
4661
|
return {
|
|
4662
4662
|
ok: false,
|
|
4663
4663
|
error: createOperationError("AccountSuspendedError")
|
|
@@ -4682,9 +4682,7 @@ var AuthService = class {
|
|
|
4682
4682
|
}
|
|
4683
4683
|
async destroySession(accessToken, version = 1) {
|
|
4684
4684
|
const headers = new Headers(this.headers);
|
|
4685
|
-
|
|
4686
|
-
headers.append("Authorization", `Bearer ${accessToken}`);
|
|
4687
|
-
}
|
|
4685
|
+
headers.append("Authorization", `Bearer ${accessToken}`);
|
|
4688
4686
|
try {
|
|
4689
4687
|
const res = await fetch(
|
|
4690
4688
|
`${this.url}${version !== 1 ? `/v${version}/session` : "/session"}`,
|
|
@@ -7538,6 +7536,7 @@ var SessionManager = class {
|
|
|
7538
7536
|
*/
|
|
7539
7537
|
v4AccessToken = null;
|
|
7540
7538
|
v4AccessTokenExpiresAt = null;
|
|
7539
|
+
v4RefreshPromise = null;
|
|
7541
7540
|
constructor(config) {
|
|
7542
7541
|
this.authService = config.authService;
|
|
7543
7542
|
this.walletService = config.walletService;
|
|
@@ -7556,13 +7555,19 @@ var SessionManager = class {
|
|
|
7556
7555
|
persist(data, version) {
|
|
7557
7556
|
const now = /* @__PURE__ */ new Date();
|
|
7558
7557
|
if (version === 4) {
|
|
7559
|
-
|
|
7558
|
+
if (!data.session || !data.accessToken) {
|
|
7559
|
+
this.logger.error(
|
|
7560
|
+
"Malformed session response: expected 'session' and 'accessToken'."
|
|
7561
|
+
);
|
|
7562
|
+
return false;
|
|
7563
|
+
}
|
|
7564
|
+
this.v4AccessToken = data.accessToken;
|
|
7560
7565
|
this.v4AccessTokenExpiresAt = addMinutes(now, 5).getTime();
|
|
7561
7566
|
localStorage.setItem(
|
|
7562
7567
|
this.storageKey,
|
|
7563
7568
|
JSON.stringify({ version, session: data.session })
|
|
7564
7569
|
);
|
|
7565
|
-
return;
|
|
7570
|
+
return true;
|
|
7566
7571
|
}
|
|
7567
7572
|
localStorage.setItem(
|
|
7568
7573
|
this.storageKey,
|
|
@@ -7573,6 +7578,16 @@ var SessionManager = class {
|
|
|
7573
7578
|
refreshTokenExpiresAt: subMinutes(addDays(now, 30), 2).getTime()
|
|
7574
7579
|
})
|
|
7575
7580
|
);
|
|
7581
|
+
return true;
|
|
7582
|
+
}
|
|
7583
|
+
malformedResponseError() {
|
|
7584
|
+
return {
|
|
7585
|
+
ok: false,
|
|
7586
|
+
error: {
|
|
7587
|
+
name: "UnknownError",
|
|
7588
|
+
message: "Something went wrong."
|
|
7589
|
+
}
|
|
7590
|
+
};
|
|
7576
7591
|
}
|
|
7577
7592
|
async create(input, version = 1) {
|
|
7578
7593
|
if (this.isServer) {
|
|
@@ -7610,7 +7625,7 @@ var SessionManager = class {
|
|
|
7610
7625
|
maxAttempt: 5
|
|
7611
7626
|
})();
|
|
7612
7627
|
if (!r1.ok) return r1;
|
|
7613
|
-
this.persist(r1.data, version);
|
|
7628
|
+
if (!this.persist(r1.data, version)) return this.malformedResponseError();
|
|
7614
7629
|
return {
|
|
7615
7630
|
ok: true,
|
|
7616
7631
|
data: null
|
|
@@ -7619,7 +7634,7 @@ var SessionManager = class {
|
|
|
7619
7634
|
if (input.type === "MOBILE_NUMBER") {
|
|
7620
7635
|
const res2 = await this.authService.createSession(input, version);
|
|
7621
7636
|
if (res2.ok) {
|
|
7622
|
-
this.persist(res2.data, version);
|
|
7637
|
+
if (!this.persist(res2.data, version)) return this.malformedResponseError();
|
|
7623
7638
|
return {
|
|
7624
7639
|
ok: true,
|
|
7625
7640
|
data: null
|
|
@@ -7637,7 +7652,7 @@ var SessionManager = class {
|
|
|
7637
7652
|
version
|
|
7638
7653
|
);
|
|
7639
7654
|
if (res2.ok) {
|
|
7640
|
-
this.persist(res2.data, version);
|
|
7655
|
+
if (!this.persist(res2.data, version)) return this.malformedResponseError();
|
|
7641
7656
|
return {
|
|
7642
7657
|
ok: true,
|
|
7643
7658
|
data: null
|
|
@@ -7649,7 +7664,7 @@ var SessionManager = class {
|
|
|
7649
7664
|
localStorage.setItem(this.platformStorageKey, "CABINET");
|
|
7650
7665
|
const res2 = await this.authService.createSession(input, version);
|
|
7651
7666
|
if (res2.ok) {
|
|
7652
|
-
this.persist(res2.data, version);
|
|
7667
|
+
if (!this.persist(res2.data, version)) return this.malformedResponseError();
|
|
7653
7668
|
return {
|
|
7654
7669
|
ok: true,
|
|
7655
7670
|
data: null
|
|
@@ -7667,7 +7682,7 @@ var SessionManager = class {
|
|
|
7667
7682
|
}
|
|
7668
7683
|
};
|
|
7669
7684
|
}
|
|
7670
|
-
this.persist(res.data, version);
|
|
7685
|
+
if (!this.persist(res.data, version)) return this.malformedResponseError();
|
|
7671
7686
|
return {
|
|
7672
7687
|
ok: true,
|
|
7673
7688
|
data: null
|
|
@@ -7678,8 +7693,8 @@ var SessionManager = class {
|
|
|
7678
7693
|
if (res.ok) {
|
|
7679
7694
|
if (this.isServer) {
|
|
7680
7695
|
this.logger.warn("'localStorage' is not available on the server.");
|
|
7681
|
-
} else {
|
|
7682
|
-
this.
|
|
7696
|
+
} else if (!this.persist(res.data, 1)) {
|
|
7697
|
+
return this.malformedResponseError();
|
|
7683
7698
|
}
|
|
7684
7699
|
return { ok: true };
|
|
7685
7700
|
} else {
|
|
@@ -7858,6 +7873,15 @@ var SessionManager = class {
|
|
|
7858
7873
|
return await this.refreshV4(session);
|
|
7859
7874
|
}
|
|
7860
7875
|
async refreshV4(session) {
|
|
7876
|
+
if (this.v4RefreshPromise) return await this.v4RefreshPromise;
|
|
7877
|
+
this.v4RefreshPromise = this.requestV4Refresh(session);
|
|
7878
|
+
try {
|
|
7879
|
+
return await this.v4RefreshPromise;
|
|
7880
|
+
} finally {
|
|
7881
|
+
this.v4RefreshPromise = null;
|
|
7882
|
+
}
|
|
7883
|
+
}
|
|
7884
|
+
async requestV4Refresh(session) {
|
|
7861
7885
|
this.logger.info("Refreshing session...");
|
|
7862
7886
|
this.refreshing = true;
|
|
7863
7887
|
const res = await this.authService.refreshSession(void 0, 4);
|