@explorins/pers-sdk 2.1.15 → 2.1.18
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 +6 -6
- package/dist/chunks/{pers-sdk-BiP7UMJ3.js → pers-sdk-CycADST7.js} +124 -30
- package/dist/chunks/pers-sdk-CycADST7.js.map +1 -0
- package/dist/chunks/{pers-sdk-Cv7hM1I7.cjs → pers-sdk-DMoQbCgs.cjs} +124 -30
- package/dist/chunks/pers-sdk-DMoQbCgs.cjs.map +1 -0
- package/dist/chunks/{tenant-manager-BUiFM33X.cjs → tenant-manager-B4FygDMF.cjs} +16 -5
- package/dist/chunks/tenant-manager-B4FygDMF.cjs.map +1 -0
- package/dist/chunks/{tenant-manager-Bbj0bKoo.js → tenant-manager-DkWkZfCF.js} +16 -5
- package/dist/chunks/tenant-manager-DkWkZfCF.js.map +1 -0
- package/dist/chunks/{tenant-service-CsRA3O2V.js → tenant-service-BnTAZCxS.js} +26 -8
- package/dist/chunks/tenant-service-BnTAZCxS.js.map +1 -0
- package/dist/chunks/{tenant-service-fj-pkXTw.cjs → tenant-service-Ch-V3mj-.cjs} +26 -8
- package/dist/chunks/tenant-service-Ch-V3mj-.cjs.map +1 -0
- package/dist/chunks/{web3-manager-Bnsvcz3Q.js → web3-manager-DRkj7s5C.js} +2 -2
- package/dist/chunks/{web3-manager-Bnsvcz3Q.js.map → web3-manager-DRkj7s5C.js.map} +1 -1
- package/dist/chunks/{web3-manager-B0OyjqJR.cjs → web3-manager-msPdWhlR.cjs} +2 -2
- package/dist/chunks/{web3-manager-B0OyjqJR.cjs.map → web3-manager-msPdWhlR.cjs.map} +1 -1
- package/dist/core/events/event-emitter.d.ts +2 -2
- package/dist/core/events/event-types.d.ts +27 -5
- package/dist/core/events/event-types.d.ts.map +1 -1
- package/dist/core/pers-api-client.d.ts.map +1 -1
- package/dist/core.cjs +3 -3
- package/dist/core.js +3 -3
- package/dist/index.cjs +3 -3
- package/dist/index.js +3 -3
- package/dist/managers/events-manager.d.ts +20 -0
- package/dist/managers/events-manager.d.ts.map +1 -1
- package/dist/managers/tenant-manager.d.ts +15 -6
- package/dist/managers/tenant-manager.d.ts.map +1 -1
- package/dist/node.cjs +3 -3
- package/dist/node.js +3 -3
- package/dist/package.json +2 -2
- package/dist/tenant/api/tenant-api.d.ts +15 -6
- package/dist/tenant/api/tenant-api.d.ts.map +1 -1
- package/dist/tenant/services/tenant-service.d.ts +9 -5
- package/dist/tenant/services/tenant-service.d.ts.map +1 -1
- package/dist/tenant.cjs +1 -1
- package/dist/tenant.js +1 -1
- package/dist/web3-manager.cjs +3 -3
- package/dist/web3-manager.js +3 -3
- package/dist/web3.cjs +3 -3
- package/dist/web3.js +3 -3
- package/package.json +2 -2
- package/dist/chunks/pers-sdk-BiP7UMJ3.js.map +0 -1
- package/dist/chunks/pers-sdk-Cv7hM1I7.cjs.map +0 -1
- package/dist/chunks/tenant-manager-BUiFM33X.cjs.map +0 -1
- package/dist/chunks/tenant-manager-Bbj0bKoo.js.map +0 -1
- package/dist/chunks/tenant-service-CsRA3O2V.js.map +0 -1
- package/dist/chunks/tenant-service-fj-pkXTw.cjs.map +0 -1
|
@@ -10,7 +10,7 @@ var campaign = require('../campaign.cjs');
|
|
|
10
10
|
var redemptionService = require('./redemption-service-C61Qr2vI.cjs');
|
|
11
11
|
var transactionRequest_builder = require('./transaction-request.builder-CW3Wwdi3.cjs');
|
|
12
12
|
var paymentService = require('./payment-service-Bkw7ZXev.cjs');
|
|
13
|
-
var tenantManager = require('./tenant-manager-
|
|
13
|
+
var tenantManager = require('./tenant-manager-B4FygDMF.cjs');
|
|
14
14
|
var paginationUtils = require('./pagination-utils-B2jRHMSO.cjs');
|
|
15
15
|
var analyticsService = require('./analytics-service-CF9AsMQH.cjs');
|
|
16
16
|
var donation = require('../donation.cjs');
|
|
@@ -1111,6 +1111,12 @@ class PersApiClient {
|
|
|
1111
1111
|
try {
|
|
1112
1112
|
const refreshSuccessful = await this.refreshManager.attemptInternalRefresh();
|
|
1113
1113
|
if (refreshSuccessful) {
|
|
1114
|
+
// Emit TOKEN_REFRESHED event so WS clients can retry if they gave up
|
|
1115
|
+
this._events?.emitSuccess({
|
|
1116
|
+
type: 'token_refreshed',
|
|
1117
|
+
domain: 'authentication',
|
|
1118
|
+
userMessage: 'Authentication token refreshed',
|
|
1119
|
+
});
|
|
1114
1120
|
return await this.request(method, endpoint, body, { ...options, retryCount: 1 });
|
|
1115
1121
|
}
|
|
1116
1122
|
}
|
|
@@ -1497,7 +1503,7 @@ class PersEventEmitter {
|
|
|
1497
1503
|
* ```typescript
|
|
1498
1504
|
* sdk.events.emitSuccess({
|
|
1499
1505
|
* domain: 'transaction', // Only business domains allowed
|
|
1500
|
-
* type: '
|
|
1506
|
+
* type: 'transaction_confirmed',
|
|
1501
1507
|
* userMessage: 'Transaction confirmed!'
|
|
1502
1508
|
* });
|
|
1503
1509
|
* ```
|
|
@@ -1524,7 +1530,7 @@ class PersEventEmitter {
|
|
|
1524
1530
|
* ```typescript
|
|
1525
1531
|
* sdk.events.emitError({
|
|
1526
1532
|
* domain: 'validation', // Technical domains allowed
|
|
1527
|
-
* type: '
|
|
1533
|
+
* type: 'validation_failed',
|
|
1528
1534
|
* userMessage: 'Please check your input'
|
|
1529
1535
|
* });
|
|
1530
1536
|
* ```
|
|
@@ -1658,7 +1664,7 @@ class AuthManager {
|
|
|
1658
1664
|
: await authService.loginUser(jwtToken);
|
|
1659
1665
|
this.events?.emitSuccess({
|
|
1660
1666
|
domain: 'authentication',
|
|
1661
|
-
type: '
|
|
1667
|
+
type: 'login_success',
|
|
1662
1668
|
userMessage: 'Successfully logged in'
|
|
1663
1669
|
});
|
|
1664
1670
|
return result;
|
|
@@ -2031,7 +2037,7 @@ class UserManager {
|
|
|
2031
2037
|
const result = await this.userService.updateRemoteUser(userData);
|
|
2032
2038
|
this.events?.emitSuccess({
|
|
2033
2039
|
domain: 'user',
|
|
2034
|
-
type: '
|
|
2040
|
+
type: 'profile_updated',
|
|
2035
2041
|
userMessage: 'Profile updated successfully',
|
|
2036
2042
|
details: { userId: result.id }
|
|
2037
2043
|
});
|
|
@@ -2311,7 +2317,7 @@ class UserManager {
|
|
|
2311
2317
|
const result = await this.userService.deleteUser(identifier);
|
|
2312
2318
|
this.events?.emitSuccess({
|
|
2313
2319
|
domain: 'user',
|
|
2314
|
-
type: '
|
|
2320
|
+
type: 'user_deleted',
|
|
2315
2321
|
userMessage: 'User deleted successfully',
|
|
2316
2322
|
details: { identifier }
|
|
2317
2323
|
});
|
|
@@ -2344,7 +2350,7 @@ class UserManager {
|
|
|
2344
2350
|
const result = await this.userService.restoreUser(identifier);
|
|
2345
2351
|
this.events?.emitSuccess({
|
|
2346
2352
|
domain: 'user',
|
|
2347
|
-
type: '
|
|
2353
|
+
type: 'user_restored',
|
|
2348
2354
|
userMessage: 'User restored successfully',
|
|
2349
2355
|
details: { identifier, userId: result.id }
|
|
2350
2356
|
});
|
|
@@ -3034,7 +3040,7 @@ class BusinessManager {
|
|
|
3034
3040
|
const result = await this.businessService.createBusinessByDisplayName(displayName);
|
|
3035
3041
|
this.events?.emitSuccess({
|
|
3036
3042
|
domain: 'business',
|
|
3037
|
-
type: '
|
|
3043
|
+
type: 'business_created',
|
|
3038
3044
|
userMessage: 'Business created successfully',
|
|
3039
3045
|
details: { businessId: result.id, displayName: result.displayName }
|
|
3040
3046
|
});
|
|
@@ -3069,7 +3075,7 @@ class BusinessManager {
|
|
|
3069
3075
|
const result = await this.businessService.updateBusiness(businessId, businessData);
|
|
3070
3076
|
this.events?.emitSuccess({
|
|
3071
3077
|
domain: 'business',
|
|
3072
|
-
type: '
|
|
3078
|
+
type: 'business_updated',
|
|
3073
3079
|
userMessage: 'Business updated successfully',
|
|
3074
3080
|
details: { businessId: result.id, displayName: result.displayName }
|
|
3075
3081
|
});
|
|
@@ -3241,7 +3247,7 @@ class BusinessManager {
|
|
|
3241
3247
|
const result = await this.membershipService.updateMemberRole(businessId, userId, newRole);
|
|
3242
3248
|
this.events?.emitSuccess({
|
|
3243
3249
|
domain: 'business',
|
|
3244
|
-
type: '
|
|
3250
|
+
type: 'membership_updated',
|
|
3245
3251
|
userMessage: 'Membership role updated',
|
|
3246
3252
|
details: { businessId, userId, role: newRole }
|
|
3247
3253
|
});
|
|
@@ -3519,7 +3525,7 @@ class CampaignManager {
|
|
|
3519
3525
|
const result = await this.campaignService.claimCampaign(claimRequest);
|
|
3520
3526
|
this.events?.emitSuccess({
|
|
3521
3527
|
domain: 'campaign',
|
|
3522
|
-
type: '
|
|
3528
|
+
type: 'claim_success',
|
|
3523
3529
|
userMessage: 'Campaign reward claimed successfully',
|
|
3524
3530
|
details: { campaignId: claimRequest.campaignId }
|
|
3525
3531
|
});
|
|
@@ -3787,7 +3793,7 @@ class CampaignManager {
|
|
|
3787
3793
|
const result = await this.campaignService.createCampaignTrigger(data);
|
|
3788
3794
|
this.events?.emitSuccess({
|
|
3789
3795
|
domain: 'campaign',
|
|
3790
|
-
type: '
|
|
3796
|
+
type: 'campaign_trigger_created',
|
|
3791
3797
|
userMessage: `Trigger "${data.name}" created successfully`,
|
|
3792
3798
|
details: { triggerId: result.id, name: data.name }
|
|
3793
3799
|
});
|
|
@@ -3812,7 +3818,7 @@ class CampaignManager {
|
|
|
3812
3818
|
const result = await this.campaignService.updateCampaignTrigger(triggerId, data);
|
|
3813
3819
|
this.events?.emitSuccess({
|
|
3814
3820
|
domain: 'campaign',
|
|
3815
|
-
type: '
|
|
3821
|
+
type: 'campaign_trigger_updated',
|
|
3816
3822
|
userMessage: 'Trigger updated successfully',
|
|
3817
3823
|
details: { triggerId, updates: Object.keys(data) }
|
|
3818
3824
|
});
|
|
@@ -3833,7 +3839,7 @@ class CampaignManager {
|
|
|
3833
3839
|
const result = await this.campaignService.deleteCampaignTrigger(triggerId);
|
|
3834
3840
|
this.events?.emitSuccess({
|
|
3835
3841
|
domain: 'campaign',
|
|
3836
|
-
type: '
|
|
3842
|
+
type: 'campaign_trigger_deleted',
|
|
3837
3843
|
userMessage: 'Trigger deleted successfully',
|
|
3838
3844
|
details: { triggerId }
|
|
3839
3845
|
});
|
|
@@ -3862,7 +3868,7 @@ class CampaignManager {
|
|
|
3862
3868
|
const result = await this.campaignService.setCampaignTrigger(campaignId, triggerId);
|
|
3863
3869
|
this.events?.emitSuccess({
|
|
3864
3870
|
domain: 'campaign',
|
|
3865
|
-
type: '
|
|
3871
|
+
type: 'campaign_trigger_assigned',
|
|
3866
3872
|
userMessage: 'Trigger assigned to campaign',
|
|
3867
3873
|
details: { campaignId, triggerId }
|
|
3868
3874
|
});
|
|
@@ -3891,7 +3897,7 @@ class CampaignManager {
|
|
|
3891
3897
|
const result = await this.campaignService.removeCampaignTrigger(campaignId, triggerId);
|
|
3892
3898
|
this.events?.emitSuccess({
|
|
3893
3899
|
domain: 'campaign',
|
|
3894
|
-
type: '
|
|
3900
|
+
type: 'campaign_trigger_removed',
|
|
3895
3901
|
userMessage: 'Trigger removed from campaign',
|
|
3896
3902
|
details: { campaignId, triggerId }
|
|
3897
3903
|
});
|
|
@@ -4227,7 +4233,7 @@ class CampaignManager {
|
|
|
4227
4233
|
const result = await this.campaignService.assignTriggerSourceToCampaign(campaignId, triggerSourceId);
|
|
4228
4234
|
this.events?.emitSuccess({
|
|
4229
4235
|
domain: 'campaign',
|
|
4230
|
-
type: '
|
|
4236
|
+
type: 'trigger_source_assigned',
|
|
4231
4237
|
userMessage: 'Trigger source assigned to campaign',
|
|
4232
4238
|
details: { campaignId, triggerSourceId }
|
|
4233
4239
|
});
|
|
@@ -4575,7 +4581,7 @@ class RedemptionManager {
|
|
|
4575
4581
|
const result = await this.redemptionService.redeemRedemption(redemptionId);
|
|
4576
4582
|
this.events?.emitSuccess({
|
|
4577
4583
|
domain: 'redemption',
|
|
4578
|
-
type: '
|
|
4584
|
+
type: 'redeem_success',
|
|
4579
4585
|
userMessage: 'Reward redeemed successfully',
|
|
4580
4586
|
details: { redemptionId }
|
|
4581
4587
|
});
|
|
@@ -5093,7 +5099,7 @@ class TransactionManager {
|
|
|
5093
5099
|
const result = await this.transactionService.createTransaction(transactionData);
|
|
5094
5100
|
this.events?.emitSuccess({
|
|
5095
5101
|
domain: 'transaction',
|
|
5096
|
-
type: '
|
|
5102
|
+
type: 'transaction_created',
|
|
5097
5103
|
userMessage: 'Transaction created successfully',
|
|
5098
5104
|
details: { transactionId: result.transaction?.id }
|
|
5099
5105
|
});
|
|
@@ -5332,7 +5338,7 @@ class TransactionManager {
|
|
|
5332
5338
|
const result = await this.transactionService.submitSignedTransaction(signedTxData);
|
|
5333
5339
|
this.events?.emitSuccess({
|
|
5334
5340
|
domain: 'transaction',
|
|
5335
|
-
type: '
|
|
5341
|
+
type: 'transaction_submitted',
|
|
5336
5342
|
userMessage: 'Transaction submitted successfully',
|
|
5337
5343
|
details: { transactionId: result.transaction?.id }
|
|
5338
5344
|
});
|
|
@@ -7256,7 +7262,7 @@ class TriggerSourceManager {
|
|
|
7256
7262
|
const result = await this.triggerSourceService.createTriggerSource(triggerSource);
|
|
7257
7263
|
this.events?.emitSuccess({
|
|
7258
7264
|
domain: 'trigger-source',
|
|
7259
|
-
type: '
|
|
7265
|
+
type: 'trigger_source_created',
|
|
7260
7266
|
userMessage: 'Trigger source created successfully',
|
|
7261
7267
|
details: { triggerSourceId: result.id, type: result.type }
|
|
7262
7268
|
});
|
|
@@ -7288,7 +7294,7 @@ class TriggerSourceManager {
|
|
|
7288
7294
|
const result = await this.triggerSourceService.updateTriggerSource(triggerSourceId, triggerSource);
|
|
7289
7295
|
this.events?.emitSuccess({
|
|
7290
7296
|
domain: 'trigger-source',
|
|
7291
|
-
type: '
|
|
7297
|
+
type: 'trigger_source_updated',
|
|
7292
7298
|
userMessage: 'Trigger source updated successfully',
|
|
7293
7299
|
details: { triggerSourceId }
|
|
7294
7300
|
});
|
|
@@ -7315,7 +7321,7 @@ class TriggerSourceManager {
|
|
|
7315
7321
|
const result = await this.triggerSourceService.deleteTriggerSource(triggerSourceId);
|
|
7316
7322
|
this.events?.emitSuccess({
|
|
7317
7323
|
domain: 'trigger-source',
|
|
7318
|
-
type: '
|
|
7324
|
+
type: 'trigger_source_deleted',
|
|
7319
7325
|
userMessage: 'Trigger source deleted successfully',
|
|
7320
7326
|
details: { triggerSourceId }
|
|
7321
7327
|
});
|
|
@@ -7789,7 +7795,7 @@ class WebhookManager {
|
|
|
7789
7795
|
const result = await this.webhookService.createWebhook(webhook);
|
|
7790
7796
|
this.events?.emitSuccess({
|
|
7791
7797
|
domain: 'webhook',
|
|
7792
|
-
type: '
|
|
7798
|
+
type: 'webhook_created',
|
|
7793
7799
|
userMessage: 'Webhook created successfully',
|
|
7794
7800
|
details: { webhookId: result.id, name: result.name }
|
|
7795
7801
|
});
|
|
@@ -7806,7 +7812,7 @@ class WebhookManager {
|
|
|
7806
7812
|
const result = await this.webhookService.updateWebhook(webhookId, webhook);
|
|
7807
7813
|
this.events?.emitSuccess({
|
|
7808
7814
|
domain: 'webhook',
|
|
7809
|
-
type: '
|
|
7815
|
+
type: 'webhook_updated',
|
|
7810
7816
|
userMessage: 'Webhook updated successfully',
|
|
7811
7817
|
details: { webhookId }
|
|
7812
7818
|
});
|
|
@@ -7834,7 +7840,7 @@ class WebhookManager {
|
|
|
7834
7840
|
const result = await this.webhookService.deleteWebhook(webhookId);
|
|
7835
7841
|
this.events?.emitSuccess({
|
|
7836
7842
|
domain: 'webhook',
|
|
7837
|
-
type: '
|
|
7843
|
+
type: 'webhook_deleted',
|
|
7838
7844
|
userMessage: 'Webhook deleted successfully',
|
|
7839
7845
|
details: { webhookId }
|
|
7840
7846
|
});
|
|
@@ -7891,7 +7897,7 @@ class WebhookManager {
|
|
|
7891
7897
|
const result = await this.webhookService.post(hookId, body);
|
|
7892
7898
|
this.events?.emitSuccess({
|
|
7893
7899
|
domain: 'webhook',
|
|
7894
|
-
type: '
|
|
7900
|
+
type: 'webhook_triggered',
|
|
7895
7901
|
userMessage: 'Webhook triggered',
|
|
7896
7902
|
details: { hookId, executionId: result.executionId }
|
|
7897
7903
|
});
|
|
@@ -8461,12 +8467,22 @@ class WalletEventsManager {
|
|
|
8461
8467
|
this.client = null;
|
|
8462
8468
|
this.pendingHandlers = [];
|
|
8463
8469
|
this.unsubscribes = [];
|
|
8470
|
+
// Track if WS gave up reconnecting (so we can retry on token refresh)
|
|
8471
|
+
this.reconnectGaveUp = false;
|
|
8472
|
+
this.lastSubscriptions = { wallets: [], chains: [] };
|
|
8464
8473
|
this.config = {
|
|
8465
8474
|
autoReconnect: true,
|
|
8466
8475
|
connectionTimeout: 30000,
|
|
8467
8476
|
debug: false,
|
|
8468
8477
|
...config,
|
|
8469
8478
|
};
|
|
8479
|
+
// Subscribe to auth events to retry WS connection when tokens are refreshed
|
|
8480
|
+
this.authEventUnsubscribe = this.eventEmitter.subscribe((event) => {
|
|
8481
|
+
if (event.type === 'token_refreshed' && this.reconnectGaveUp) {
|
|
8482
|
+
// Tokens were refreshed and WS had given up - retry connection
|
|
8483
|
+
this.retryAfterTokenRefresh();
|
|
8484
|
+
}
|
|
8485
|
+
}, { domains: ['authentication'], levels: ['success'] });
|
|
8470
8486
|
}
|
|
8471
8487
|
/**
|
|
8472
8488
|
* Connect to real-time wallet events
|
|
@@ -8495,8 +8511,11 @@ class WalletEventsManager {
|
|
|
8495
8511
|
const wsUrl = this.config.wsUrl
|
|
8496
8512
|
|| sdkConfig.walletEventsWsUrl
|
|
8497
8513
|
|| buildWalletEventsWsUrl(sdkConfig.environment);
|
|
8498
|
-
// Create token refresher that
|
|
8514
|
+
// Create token refresher that ensures valid token before reconnecting
|
|
8515
|
+
// This triggers actual token refresh if expired, not just retrieval
|
|
8499
8516
|
const tokenRefresher = async () => {
|
|
8517
|
+
// Ensure token is refreshed if expired (calls refresh API if needed)
|
|
8518
|
+
await this.apiClient.ensureValidToken();
|
|
8500
8519
|
const freshToken = await authProvider.getToken();
|
|
8501
8520
|
if (!freshToken) {
|
|
8502
8521
|
throw new Error('Failed to refresh token');
|
|
@@ -8511,6 +8530,32 @@ class WalletEventsManager {
|
|
|
8511
8530
|
tokenRefresher,
|
|
8512
8531
|
});
|
|
8513
8532
|
await this.client.connect(token);
|
|
8533
|
+
// Reset gave-up flag on successful connection
|
|
8534
|
+
this.reconnectGaveUp = false;
|
|
8535
|
+
// Track previous state to detect reconnections and give-ups
|
|
8536
|
+
let previousState = 'connected';
|
|
8537
|
+
// Clean up previous state change listener (prevent duplicate listeners)
|
|
8538
|
+
this.stateChangeUnsubscribe?.();
|
|
8539
|
+
// Listen for state changes
|
|
8540
|
+
this.stateChangeUnsubscribe = this.client.onStateChange((state) => {
|
|
8541
|
+
if (state === 'disconnected' && previousState === 'reconnecting') {
|
|
8542
|
+
// Transitioned from reconnecting to disconnected = exhausted all attempts
|
|
8543
|
+
this.reconnectGaveUp = true;
|
|
8544
|
+
}
|
|
8545
|
+
else if (state === 'connected') {
|
|
8546
|
+
this.reconnectGaveUp = false;
|
|
8547
|
+
// Emit reconnected event so apps can refresh state (catch missed events)
|
|
8548
|
+
if (previousState === 'reconnecting') {
|
|
8549
|
+
this.eventEmitter.emitSuccess({
|
|
8550
|
+
type: 'wallet_reconnected',
|
|
8551
|
+
domain: 'wallet',
|
|
8552
|
+
userMessage: 'Wallet events reconnected',
|
|
8553
|
+
details: { previousState }
|
|
8554
|
+
});
|
|
8555
|
+
}
|
|
8556
|
+
}
|
|
8557
|
+
previousState = state;
|
|
8558
|
+
});
|
|
8514
8559
|
// Clear previous unsubscribes on new connection (prevent memory leak)
|
|
8515
8560
|
this.unsubscribes.forEach(unsub => unsub());
|
|
8516
8561
|
this.unsubscribes = [];
|
|
@@ -8527,11 +8572,26 @@ class WalletEventsManager {
|
|
|
8527
8572
|
* Disconnect from real-time events
|
|
8528
8573
|
*/
|
|
8529
8574
|
disconnect() {
|
|
8575
|
+
// Clear gave-up flag to prevent auto-reconnect after intentional disconnect
|
|
8576
|
+
this.reconnectGaveUp = false;
|
|
8577
|
+
this.stateChangeUnsubscribe?.();
|
|
8578
|
+
this.stateChangeUnsubscribe = undefined;
|
|
8530
8579
|
this.unsubscribes.forEach(unsub => unsub());
|
|
8531
8580
|
this.unsubscribes = [];
|
|
8532
8581
|
this.client?.disconnect();
|
|
8533
8582
|
this.client = null;
|
|
8534
8583
|
}
|
|
8584
|
+
/**
|
|
8585
|
+
* Full cleanup - disconnect and remove all subscriptions including auth listener
|
|
8586
|
+
* Call this when completely done with the manager (e.g., SDK disposal)
|
|
8587
|
+
*/
|
|
8588
|
+
destroy() {
|
|
8589
|
+
this.disconnect();
|
|
8590
|
+
this.authEventUnsubscribe?.();
|
|
8591
|
+
this.authEventUnsubscribe = undefined;
|
|
8592
|
+
this.reconnectGaveUp = false;
|
|
8593
|
+
this.lastSubscriptions = { wallets: [], chains: [] };
|
|
8594
|
+
}
|
|
8535
8595
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
8536
8596
|
// Subscription Methods (v1.2.0)
|
|
8537
8597
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -8556,6 +8616,8 @@ class WalletEventsManager {
|
|
|
8556
8616
|
if (!this.client) {
|
|
8557
8617
|
throw new Error('Not connected. Call connect() first.');
|
|
8558
8618
|
}
|
|
8619
|
+
// Save subscriptions for auto-resubscribe on reconnect
|
|
8620
|
+
this.lastSubscriptions.wallets = wallets;
|
|
8559
8621
|
return this.client.subscribeWallets(wallets);
|
|
8560
8622
|
}
|
|
8561
8623
|
/**
|
|
@@ -8577,6 +8639,8 @@ class WalletEventsManager {
|
|
|
8577
8639
|
if (!this.client) {
|
|
8578
8640
|
throw new Error('Not connected. Call connect() first.');
|
|
8579
8641
|
}
|
|
8642
|
+
// Save subscriptions for auto-resubscribe on reconnect
|
|
8643
|
+
this.lastSubscriptions.chains = chains;
|
|
8580
8644
|
return this.client.subscribeChains(chains);
|
|
8581
8645
|
}
|
|
8582
8646
|
/**
|
|
@@ -8666,6 +8730,36 @@ class WalletEventsManager {
|
|
|
8666
8730
|
isConnected() {
|
|
8667
8731
|
return this.getState() === 'connected';
|
|
8668
8732
|
}
|
|
8733
|
+
/**
|
|
8734
|
+
* Check if WS reconnection gave up (exhausted all attempts)
|
|
8735
|
+
* Used to determine if we should retry on token refresh
|
|
8736
|
+
*/
|
|
8737
|
+
hasReconnectGivenUp() {
|
|
8738
|
+
return this.reconnectGaveUp;
|
|
8739
|
+
}
|
|
8740
|
+
/**
|
|
8741
|
+
* Retry connection after token refresh
|
|
8742
|
+
* Called when auth tokens are refreshed and WS had previously given up
|
|
8743
|
+
* Automatically resubscribes to previous subscriptions
|
|
8744
|
+
*/
|
|
8745
|
+
async retryAfterTokenRefresh() {
|
|
8746
|
+
if (!this.reconnectGaveUp) {
|
|
8747
|
+
return; // Not in gave-up state, nothing to retry
|
|
8748
|
+
}
|
|
8749
|
+
try {
|
|
8750
|
+
await this.connect();
|
|
8751
|
+
// Restore previous subscriptions
|
|
8752
|
+
if (this.lastSubscriptions.wallets.length > 0) {
|
|
8753
|
+
await this.subscribeWallets(this.lastSubscriptions.wallets);
|
|
8754
|
+
}
|
|
8755
|
+
if (this.lastSubscriptions.chains.length > 0) {
|
|
8756
|
+
await this.subscribeChains(this.lastSubscriptions.chains);
|
|
8757
|
+
}
|
|
8758
|
+
}
|
|
8759
|
+
catch (error) {
|
|
8760
|
+
console.warn('[WalletEventsManager] Retry after token refresh failed:', error);
|
|
8761
|
+
}
|
|
8762
|
+
}
|
|
8669
8763
|
/**
|
|
8670
8764
|
* Get connection info (wallets, active chains)
|
|
8671
8765
|
*/
|
|
@@ -8870,7 +8964,7 @@ class PersSDK {
|
|
|
8870
8964
|
}
|
|
8871
8965
|
// Listen for login success events (both fresh login and session restoration)
|
|
8872
8966
|
this._events.subscribe((event) => {
|
|
8873
|
-
if (event.level === 'success' && (event.type === '
|
|
8967
|
+
if (event.level === 'success' && (event.type === 'login_success' || event.type === 'session_restored')) {
|
|
8874
8968
|
// Auto-connect and subscribe to wallet events (fire and forget, log errors)
|
|
8875
8969
|
this.connectWalletEvents().catch((err) => {
|
|
8876
8970
|
console.warn('[PersSDK] Failed to auto-connect wallet events:', err.message);
|
|
@@ -9528,4 +9622,4 @@ exports.buildWalletEventsWsUrl = buildWalletEventsWsUrl;
|
|
|
9528
9622
|
exports.createPersEventsClient = createPersEventsClient;
|
|
9529
9623
|
exports.createPersSDK = createPersSDK;
|
|
9530
9624
|
exports.mergeWithDefaults = mergeWithDefaults;
|
|
9531
|
-
//# sourceMappingURL=pers-sdk-
|
|
9625
|
+
//# sourceMappingURL=pers-sdk-DMoQbCgs.cjs.map
|