@opexa/portal-sdk 0.59.89 → 0.59.90
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/dist/{chunk-TC4UBBE5.js → chunk-HJSVCLHQ.js} +8 -2
- package/dist/chunk-HJSVCLHQ.js.map +1 -0
- package/dist/index.cjs +45 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +40 -31
- package/dist/index.js.map +1 -1
- package/dist/services/index.cjs +6 -0
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.d.cts +2 -2
- package/dist/services/index.d.ts +2 -2
- package/dist/services/index.js +1 -1
- package/dist/{types-84uzU3iN.d.cts → types-CPRTXKkO.d.cts} +3 -2
- package/dist/{types-X-tWWFKj.d.ts → types-DZdI2ruq.d.ts} +3 -2
- package/package.json +1 -1
- package/dist/chunk-TC4UBBE5.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -4838,6 +4838,12 @@ var AuthService = class {
|
|
|
4838
4838
|
error: createOperationError("AccountSuspendedError")
|
|
4839
4839
|
};
|
|
4840
4840
|
}
|
|
4841
|
+
if (body.code === "REFRESH_TOKEN_EXPIRED") {
|
|
4842
|
+
return {
|
|
4843
|
+
ok: false,
|
|
4844
|
+
error: createOperationError("SessionExpiredError")
|
|
4845
|
+
};
|
|
4846
|
+
}
|
|
4841
4847
|
if (res.status === 403 || res.status === 401) {
|
|
4842
4848
|
return {
|
|
4843
4849
|
ok: false,
|
|
@@ -7484,7 +7490,8 @@ var SessionManager = class {
|
|
|
7484
7490
|
if (input.type === "MOBILE_NUMBER") {
|
|
7485
7491
|
const res2 = await this.authService.createSession(input, version);
|
|
7486
7492
|
if (res2.ok) {
|
|
7487
|
-
if (!this.persist(res2.data, version))
|
|
7493
|
+
if (!this.persist(res2.data, version))
|
|
7494
|
+
return this.malformedResponseError();
|
|
7488
7495
|
return {
|
|
7489
7496
|
ok: true,
|
|
7490
7497
|
data: null
|
|
@@ -7502,7 +7509,8 @@ var SessionManager = class {
|
|
|
7502
7509
|
version
|
|
7503
7510
|
);
|
|
7504
7511
|
if (res2.ok) {
|
|
7505
|
-
if (!this.persist(res2.data, version))
|
|
7512
|
+
if (!this.persist(res2.data, version))
|
|
7513
|
+
return this.malformedResponseError();
|
|
7506
7514
|
return {
|
|
7507
7515
|
ok: true,
|
|
7508
7516
|
data: null
|
|
@@ -7514,7 +7522,8 @@ var SessionManager = class {
|
|
|
7514
7522
|
localStorage.setItem(this.platformStorageKey, "CABINET");
|
|
7515
7523
|
const res2 = await this.authService.createSession(input, version);
|
|
7516
7524
|
if (res2.ok) {
|
|
7517
|
-
if (!this.persist(res2.data, version))
|
|
7525
|
+
if (!this.persist(res2.data, version))
|
|
7526
|
+
return this.malformedResponseError();
|
|
7518
7527
|
return {
|
|
7519
7528
|
ok: true,
|
|
7520
7529
|
data: null
|
|
@@ -7738,7 +7747,7 @@ var SessionManager = class {
|
|
|
7738
7747
|
this.refreshing = false;
|
|
7739
7748
|
if (!res.ok) {
|
|
7740
7749
|
this.logger.error(`Failed to refresh session: ${res.error.message}`);
|
|
7741
|
-
if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
|
|
7750
|
+
if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError" || res.error.name === "SessionExpiredError") {
|
|
7742
7751
|
this.v4AccessToken = null;
|
|
7743
7752
|
this.v4AccessTokenExpiresAt = null;
|
|
7744
7753
|
}
|
|
@@ -7785,35 +7794,38 @@ var SessionManager = class {
|
|
|
7785
7794
|
async verify() {
|
|
7786
7795
|
if (this.isServer) {
|
|
7787
7796
|
this.logger.warn("'localStorage' is not available on the server.");
|
|
7788
|
-
return true;
|
|
7797
|
+
return { valid: true };
|
|
7789
7798
|
}
|
|
7790
7799
|
const val = localStorage.getItem(this.storageKey);
|
|
7791
7800
|
if (val) {
|
|
7792
7801
|
try {
|
|
7793
7802
|
const stored = JSON.parse(val);
|
|
7794
7803
|
if (stored.version === 4) {
|
|
7795
|
-
const
|
|
7796
|
-
if (!valid) localStorage.removeItem(this.storageKey);
|
|
7797
|
-
return
|
|
7804
|
+
const res = await this.verifyV4(stored.session);
|
|
7805
|
+
if (!res.valid) localStorage.removeItem(this.storageKey);
|
|
7806
|
+
return res;
|
|
7798
7807
|
}
|
|
7799
7808
|
} catch {
|
|
7800
7809
|
}
|
|
7801
7810
|
}
|
|
7802
7811
|
const s = await this.get();
|
|
7803
|
-
if (s.error?.name === "InvalidTokenError")
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
if (!s.data) return true;
|
|
7812
|
+
if (s.error?.name === "InvalidTokenError" || s.error?.name === "SessionExpiredError" || s.error?.name === "AccountBlacklistedError") {
|
|
7813
|
+
return { valid: false, reason: "INVALID_SESSION" };
|
|
7814
|
+
}
|
|
7815
|
+
if (!s.data) return { valid: true };
|
|
7807
7816
|
const v = await this.authService.verifySession(s.data.accessToken);
|
|
7808
7817
|
if (!v) {
|
|
7809
7818
|
localStorage.removeItem(this.storageKey);
|
|
7810
7819
|
}
|
|
7811
|
-
return v;
|
|
7820
|
+
return v ? { valid: true } : { valid: false, reason: "INVALID_SESSION" };
|
|
7812
7821
|
}
|
|
7813
7822
|
async verifyV4(session) {
|
|
7814
7823
|
if (!this.v4AccessToken || !this.v4AccessTokenExpiresAt || isAfter(/* @__PURE__ */ new Date(), new Date(this.v4AccessTokenExpiresAt))) {
|
|
7815
7824
|
const res = await this.refreshV4(session);
|
|
7816
|
-
return res.ok
|
|
7825
|
+
return res.ok ? { valid: true } : {
|
|
7826
|
+
valid: false,
|
|
7827
|
+
reason: res.error.name === "SessionExpiredError" ? "REFRESH_TOKEN_EXPIRED" : "INVALID_SESSION"
|
|
7828
|
+
};
|
|
7817
7829
|
}
|
|
7818
7830
|
const v = await this.authService.verifySession(this.v4AccessToken);
|
|
7819
7831
|
if (!v) {
|
|
@@ -7821,7 +7833,7 @@ var SessionManager = class {
|
|
|
7821
7833
|
this.v4AccessToken = null;
|
|
7822
7834
|
this.v4AccessTokenExpiresAt = null;
|
|
7823
7835
|
}
|
|
7824
|
-
return v;
|
|
7836
|
+
return v ? { valid: true } : { valid: false, reason: "INVALID_SESSION" };
|
|
7825
7837
|
}
|
|
7826
7838
|
get onMaya() {
|
|
7827
7839
|
if (this.isServer) {
|
|
@@ -8172,7 +8184,7 @@ var SessionManagerCookie = class {
|
|
|
8172
8184
|
this.refreshing = false;
|
|
8173
8185
|
if (!res.ok) {
|
|
8174
8186
|
this.logger.error(`Failed to refresh session: ${res.error.message}`);
|
|
8175
|
-
if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError") {
|
|
8187
|
+
if (res.error.name === "InvalidTokenError" || res.error.name === "AccountBlacklistedError" || res.error.name === "VerificationLockedError" || res.error.name === "SessionExpiredError") {
|
|
8176
8188
|
this.v4AccessToken = null;
|
|
8177
8189
|
this.v4AccessTokenExpiresAt = null;
|
|
8178
8190
|
}
|
|
@@ -8219,35 +8231,38 @@ var SessionManagerCookie = class {
|
|
|
8219
8231
|
async verify() {
|
|
8220
8232
|
if (this.isServer) {
|
|
8221
8233
|
this.logger.warn("'client cookies' is not available on the server.");
|
|
8222
|
-
return true;
|
|
8234
|
+
return { valid: true };
|
|
8223
8235
|
}
|
|
8224
8236
|
const val = cookies__default.default.get(this.storageKey);
|
|
8225
8237
|
if (val) {
|
|
8226
8238
|
try {
|
|
8227
8239
|
const stored = JSON.parse(val);
|
|
8228
8240
|
if (stored.version === 4) {
|
|
8229
|
-
const
|
|
8230
|
-
if (!valid) cookies__default.default.remove(this.storageKey);
|
|
8231
|
-
return
|
|
8241
|
+
const res = await this.verifyV4(stored.session);
|
|
8242
|
+
if (!res.valid) cookies__default.default.remove(this.storageKey);
|
|
8243
|
+
return res;
|
|
8232
8244
|
}
|
|
8233
8245
|
} catch {
|
|
8234
8246
|
}
|
|
8235
8247
|
}
|
|
8236
8248
|
const s = await this.get();
|
|
8237
|
-
if (s.error?.name === "InvalidTokenError")
|
|
8238
|
-
|
|
8239
|
-
|
|
8240
|
-
if (!s.data) return true;
|
|
8249
|
+
if (s.error?.name === "InvalidTokenError" || s.error?.name === "SessionExpiredError" || s.error?.name === "AccountBlacklistedError") {
|
|
8250
|
+
return { valid: false, reason: "INVALID_SESSION" };
|
|
8251
|
+
}
|
|
8252
|
+
if (!s.data) return { valid: true };
|
|
8241
8253
|
const v = await this.authService.verifySession(s.data.accessToken);
|
|
8242
8254
|
if (!v) {
|
|
8243
8255
|
cookies__default.default.remove(this.storageKey);
|
|
8244
8256
|
}
|
|
8245
|
-
return v;
|
|
8257
|
+
return v ? { valid: true } : { valid: false, reason: "INVALID_SESSION" };
|
|
8246
8258
|
}
|
|
8247
8259
|
async verifyV4(session) {
|
|
8248
8260
|
if (!this.v4AccessToken || !this.v4AccessTokenExpiresAt || isAfter(/* @__PURE__ */ new Date(), new Date(this.v4AccessTokenExpiresAt))) {
|
|
8249
8261
|
const res = await this.refreshV4(session);
|
|
8250
|
-
return res.ok
|
|
8262
|
+
return res.ok ? { valid: true } : {
|
|
8263
|
+
valid: false,
|
|
8264
|
+
reason: res.error.name === "SessionExpiredError" ? "REFRESH_TOKEN_EXPIRED" : "INVALID_SESSION"
|
|
8265
|
+
};
|
|
8251
8266
|
}
|
|
8252
8267
|
const v = await this.authService.verifySession(this.v4AccessToken);
|
|
8253
8268
|
if (!v) {
|
|
@@ -8255,7 +8270,7 @@ var SessionManagerCookie = class {
|
|
|
8255
8270
|
this.v4AccessToken = null;
|
|
8256
8271
|
this.v4AccessTokenExpiresAt = null;
|
|
8257
8272
|
}
|
|
8258
|
-
return v;
|
|
8273
|
+
return v ? { valid: true } : { valid: false, reason: "INVALID_SESSION" };
|
|
8259
8274
|
}
|
|
8260
8275
|
get onMaya() {
|
|
8261
8276
|
if (this.isServer) {
|
|
@@ -10566,10 +10581,10 @@ var Sdk = class {
|
|
|
10566
10581
|
try {
|
|
10567
10582
|
res = await this.sessionManager.verify();
|
|
10568
10583
|
} catch {
|
|
10569
|
-
res = false;
|
|
10584
|
+
res = { valid: false, reason: "INVALID_SESSION" };
|
|
10570
10585
|
}
|
|
10571
|
-
if (!res) {
|
|
10572
|
-
await input.onInvalid();
|
|
10586
|
+
if (!res.valid) {
|
|
10587
|
+
await input.onInvalid(res.reason ?? "INVALID_SESSION");
|
|
10573
10588
|
}
|
|
10574
10589
|
}
|
|
10575
10590
|
timeout = assignTimeout();
|