@brightchain/brightchain-api-lib 0.14.0 → 0.16.0
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/package.json +5 -5
- package/src/browser.d.ts +13 -0
- package/src/browser.d.ts.map +1 -0
- package/src/browser.js +16 -0
- package/src/browser.js.map +1 -0
- package/src/index.d.ts +4 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +6 -1
- package/src/index.js.map +1 -1
- package/src/lib/application-base.d.ts +8 -37
- package/src/lib/application-base.d.ts.map +1 -1
- package/src/lib/application-base.js +8 -80
- package/src/lib/application-base.js.map +1 -1
- package/src/lib/application.d.ts +37 -7
- package/src/lib/application.d.ts.map +1 -1
- package/src/lib/application.js +130 -118
- package/src/lib/application.js.map +1 -1
- package/src/lib/auth/aclEnforcedAvailability.d.ts +57 -0
- package/src/lib/auth/aclEnforcedAvailability.d.ts.map +1 -0
- package/src/lib/auth/aclEnforcedAvailability.js +87 -0
- package/src/lib/auth/aclEnforcedAvailability.js.map +1 -0
- package/src/lib/auth/aclEnforcedBlockStore.d.ts +66 -0
- package/src/lib/auth/aclEnforcedBlockStore.d.ts.map +1 -0
- package/src/lib/auth/aclEnforcedBlockStore.js +83 -0
- package/src/lib/auth/aclEnforcedBlockStore.js.map +1 -0
- package/src/lib/auth/ecdsaNodeAuthenticator.d.ts +46 -0
- package/src/lib/auth/ecdsaNodeAuthenticator.d.ts.map +1 -0
- package/src/lib/auth/ecdsaNodeAuthenticator.js +110 -0
- package/src/lib/auth/ecdsaNodeAuthenticator.js.map +1 -0
- package/src/lib/auth/index.d.ts +7 -0
- package/src/lib/auth/index.d.ts.map +1 -0
- package/src/lib/auth/index.js +13 -0
- package/src/lib/auth/index.js.map +1 -0
- package/src/lib/auth/poolAclBootstrap.d.ts +36 -0
- package/src/lib/auth/poolAclBootstrap.d.ts.map +1 -0
- package/src/lib/auth/poolAclBootstrap.js +64 -0
- package/src/lib/auth/poolAclBootstrap.js.map +1 -0
- package/src/lib/auth/poolAclStore.d.ts +77 -0
- package/src/lib/auth/poolAclStore.d.ts.map +1 -0
- package/src/lib/auth/poolAclStore.js +189 -0
- package/src/lib/auth/poolAclStore.js.map +1 -0
- package/src/lib/auth/poolAclUpdater.d.ts +79 -0
- package/src/lib/auth/poolAclUpdater.d.ts.map +1 -0
- package/src/lib/auth/poolAclUpdater.js +144 -0
- package/src/lib/auth/poolAclUpdater.js.map +1 -0
- package/src/lib/availability/availabilityService.d.ts +2 -2
- package/src/lib/availability/availabilityService.d.ts.map +1 -1
- package/src/lib/availability/availabilityService.js +12 -5
- package/src/lib/availability/availabilityService.js.map +1 -1
- package/src/lib/availability/blockRegistry.d.ts +45 -3
- package/src/lib/availability/blockRegistry.d.ts.map +1 -1
- package/src/lib/availability/blockRegistry.js +123 -5
- package/src/lib/availability/blockRegistry.js.map +1 -1
- package/src/lib/availability/discoveryProtocol.d.ts +30 -1
- package/src/lib/availability/discoveryProtocol.d.ts.map +1 -1
- package/src/lib/availability/discoveryProtocol.js +76 -0
- package/src/lib/availability/discoveryProtocol.js.map +1 -1
- package/src/lib/availability/gossipService.d.ts +45 -6
- package/src/lib/availability/gossipService.d.ts.map +1 -1
- package/src/lib/availability/gossipService.js +177 -5
- package/src/lib/availability/gossipService.js.map +1 -1
- package/src/lib/availability/reconciliationService.d.ts +88 -1
- package/src/lib/availability/reconciliationService.d.ts.map +1 -1
- package/src/lib/availability/reconciliationService.js +246 -48
- package/src/lib/availability/reconciliationService.js.map +1 -1
- package/src/lib/blockFetch/blockFetcher.d.ts +100 -0
- package/src/lib/blockFetch/blockFetcher.d.ts.map +1 -0
- package/src/lib/blockFetch/blockFetcher.js +279 -0
- package/src/lib/blockFetch/blockFetcher.js.map +1 -0
- package/src/lib/blockFetch/fetchQueue.d.ts +88 -0
- package/src/lib/blockFetch/fetchQueue.d.ts.map +1 -0
- package/src/lib/blockFetch/fetchQueue.js +204 -0
- package/src/lib/blockFetch/fetchQueue.js.map +1 -0
- package/src/lib/blockFetch/httpBlockFetchTransport.d.ts +65 -0
- package/src/lib/blockFetch/httpBlockFetchTransport.d.ts.map +1 -0
- package/src/lib/blockFetch/httpBlockFetchTransport.js +104 -0
- package/src/lib/blockFetch/httpBlockFetchTransport.js.map +1 -0
- package/src/lib/blockFetch/index.d.ts +10 -0
- package/src/lib/blockFetch/index.d.ts.map +1 -0
- package/src/lib/blockFetch/index.js +13 -0
- package/src/lib/blockFetch/index.js.map +1 -0
- package/src/lib/constants.js +2 -2
- package/src/lib/constants.js.map +1 -1
- package/src/lib/controllers/api/blocks.d.ts.map +1 -1
- package/src/lib/controllers/api/blocks.js +290 -290
- package/src/lib/controllers/api/blocks.js.map +1 -1
- package/src/lib/controllers/api/brightpass.d.ts +72 -0
- package/src/lib/controllers/api/brightpass.d.ts.map +1 -0
- package/src/lib/controllers/api/brightpass.js +577 -0
- package/src/lib/controllers/api/brightpass.js.map +1 -0
- package/src/lib/controllers/api/channels.d.ts +122 -0
- package/src/lib/controllers/api/channels.d.ts.map +1 -0
- package/src/lib/controllers/api/channels.js +701 -0
- package/src/lib/controllers/api/channels.js.map +1 -0
- package/src/lib/controllers/api/conversations.d.ts +89 -0
- package/src/lib/controllers/api/conversations.d.ts.map +1 -0
- package/src/lib/controllers/api/conversations.js +259 -0
- package/src/lib/controllers/api/conversations.js.map +1 -0
- package/src/lib/controllers/api/emails.d.ts +122 -0
- package/src/lib/controllers/api/emails.d.ts.map +1 -0
- package/src/lib/controllers/api/emails.js +494 -0
- package/src/lib/controllers/api/emails.js.map +1 -0
- package/src/lib/controllers/api/energy.d.ts.map +1 -1
- package/src/lib/controllers/api/energy.js +93 -93
- package/src/lib/controllers/api/energy.js.map +1 -1
- package/src/lib/controllers/api/explodingMessages.d.ts +79 -0
- package/src/lib/controllers/api/explodingMessages.d.ts.map +1 -0
- package/src/lib/controllers/api/explodingMessages.js +378 -0
- package/src/lib/controllers/api/explodingMessages.js.map +1 -0
- package/src/lib/controllers/api/groups.d.ts +94 -0
- package/src/lib/controllers/api/groups.d.ts.map +1 -0
- package/src/lib/controllers/api/groups.js +484 -0
- package/src/lib/controllers/api/groups.js.map +1 -0
- package/src/lib/controllers/api/i18n.d.ts.map +1 -1
- package/src/lib/controllers/api/i18n.js +8 -8
- package/src/lib/controllers/api/i18n.js.map +1 -1
- package/src/lib/controllers/api/index.d.ts +6 -0
- package/src/lib/controllers/api/index.d.ts.map +1 -1
- package/src/lib/controllers/api/index.js +6 -0
- package/src/lib/controllers/api/index.js.map +1 -1
- package/src/lib/controllers/api/messages.d.ts.map +1 -1
- package/src/lib/controllers/api/messages.js +2 -1
- package/src/lib/controllers/api/messages.js.map +1 -1
- package/src/lib/controllers/api/quorum.d.ts.map +1 -1
- package/src/lib/controllers/api/quorum.js +483 -483
- package/src/lib/controllers/api/quorum.js.map +1 -1
- package/src/lib/controllers/api/sessions.d.ts.map +1 -1
- package/src/lib/controllers/api/sessions.js +8 -8
- package/src/lib/controllers/api/sessions.js.map +1 -1
- package/src/lib/controllers/api/sync.d.ts +38 -2
- package/src/lib/controllers/api/sync.d.ts.map +1 -1
- package/src/lib/controllers/api/sync.js +89 -0
- package/src/lib/controllers/api/sync.js.map +1 -1
- package/src/lib/controllers/api/user.d.ts.map +1 -1
- package/src/lib/controllers/api/user.js +180 -180
- package/src/lib/controllers/api/user.js.map +1 -1
- package/src/lib/controllers/crypto/gitController.d.ts +70 -0
- package/src/lib/controllers/crypto/gitController.d.ts.map +1 -0
- package/src/lib/controllers/crypto/gitController.js +306 -0
- package/src/lib/controllers/crypto/gitController.js.map +1 -0
- package/src/lib/controllers/crypto/index.d.ts +3 -0
- package/src/lib/controllers/crypto/index.d.ts.map +1 -0
- package/src/lib/controllers/crypto/index.js +6 -0
- package/src/lib/controllers/crypto/index.js.map +1 -0
- package/src/lib/controllers/crypto/walletController.d.ts +64 -0
- package/src/lib/controllers/crypto/walletController.d.ts.map +1 -0
- package/src/lib/controllers/crypto/walletController.js +260 -0
- package/src/lib/controllers/crypto/walletController.js.map +1 -0
- package/src/lib/controllers/identity/deviceController.d.ts +96 -0
- package/src/lib/controllers/identity/deviceController.d.ts.map +1 -0
- package/src/lib/controllers/identity/deviceController.js +355 -0
- package/src/lib/controllers/identity/deviceController.js.map +1 -0
- package/src/lib/controllers/identity/directoryController.d.ts +75 -0
- package/src/lib/controllers/identity/directoryController.d.ts.map +1 -0
- package/src/lib/controllers/identity/directoryController.js +288 -0
- package/src/lib/controllers/identity/directoryController.js.map +1 -0
- package/src/lib/controllers/identity/identityProofController.d.ts +94 -0
- package/src/lib/controllers/identity/identityProofController.d.ts.map +1 -0
- package/src/lib/controllers/identity/identityProofController.js +454 -0
- package/src/lib/controllers/identity/identityProofController.js.map +1 -0
- package/src/lib/controllers/identity/index.d.ts +4 -0
- package/src/lib/controllers/identity/index.d.ts.map +1 -0
- package/src/lib/controllers/identity/index.js +7 -0
- package/src/lib/controllers/identity/index.js.map +1 -0
- package/src/lib/controllers/index.d.ts +2 -0
- package/src/lib/controllers/index.d.ts.map +1 -1
- package/src/lib/controllers/index.js +2 -0
- package/src/lib/controllers/index.js.map +1 -1
- package/src/lib/encryption/encryptedMetadataService.d.ts +87 -0
- package/src/lib/encryption/encryptedMetadataService.d.ts.map +1 -0
- package/src/lib/encryption/encryptedMetadataService.js +224 -0
- package/src/lib/encryption/encryptedMetadataService.js.map +1 -0
- package/src/lib/encryption/encryptionAwareReplication.d.ts +76 -0
- package/src/lib/encryption/encryptionAwareReplication.d.ts.map +1 -0
- package/src/lib/encryption/encryptionAwareReplication.js +116 -0
- package/src/lib/encryption/encryptionAwareReplication.js.map +1 -0
- package/src/lib/encryption/errors.d.ts +49 -0
- package/src/lib/encryption/errors.d.ts.map +1 -0
- package/src/lib/encryption/errors.js +80 -0
- package/src/lib/encryption/errors.js.map +1 -0
- package/src/lib/encryption/index.d.ts +6 -0
- package/src/lib/encryption/index.d.ts.map +1 -0
- package/src/lib/encryption/index.js +9 -0
- package/src/lib/encryption/index.js.map +1 -0
- package/src/lib/encryption/poolEncryptionService.d.ts +94 -0
- package/src/lib/encryption/poolEncryptionService.d.ts.map +1 -0
- package/src/lib/encryption/poolEncryptionService.js +252 -0
- package/src/lib/encryption/poolEncryptionService.js.map +1 -0
- package/src/lib/encryption/poolKeyManager.d.ts +82 -0
- package/src/lib/encryption/poolKeyManager.d.ts.map +1 -0
- package/src/lib/encryption/poolKeyManager.js +156 -0
- package/src/lib/encryption/poolKeyManager.js.map +1 -0
- package/src/lib/environment.d.ts +3 -0
- package/src/lib/environment.d.ts.map +1 -1
- package/src/lib/environment.js +5 -0
- package/src/lib/environment.js.map +1 -1
- package/src/lib/interfaces/application.d.ts +7 -1
- package/src/lib/interfaces/application.d.ts.map +1 -1
- package/src/lib/interfaces/brightchain-init-result.d.ts +17 -0
- package/src/lib/interfaces/brightchain-init-result.d.ts.map +1 -0
- package/src/lib/interfaces/brightchain-init-result.js +9 -0
- package/src/lib/interfaces/brightchain-init-result.js.map +1 -0
- package/src/lib/interfaces/environment.d.ts +7 -1
- package/src/lib/interfaces/environment.d.ts.map +1 -1
- package/src/lib/interfaces/index.d.ts +1 -1
- package/src/lib/interfaces/index.d.ts.map +1 -1
- package/src/lib/interfaces/requests/getBlockDataRequest.d.ts +12 -0
- package/src/lib/interfaces/requests/getBlockDataRequest.d.ts.map +1 -0
- package/src/lib/interfaces/{blockStore.js → requests/getBlockDataRequest.js} +1 -1
- package/src/lib/interfaces/requests/getBlockDataRequest.js.map +1 -0
- package/src/lib/interfaces/requests/index.d.ts +1 -0
- package/src/lib/interfaces/requests/index.d.ts.map +1 -1
- package/src/lib/routers/api.d.ts +54 -1
- package/src/lib/routers/api.d.ts.map +1 -1
- package/src/lib/routers/api.js +77 -0
- package/src/lib/routers/api.js.map +1 -1
- package/src/lib/routers/app.d.ts +22 -14
- package/src/lib/routers/app.d.ts.map +1 -1
- package/src/lib/routers/app.js +28 -116
- package/src/lib/routers/app.js.map +1 -1
- package/src/lib/services/blockStore.d.ts +5 -2
- package/src/lib/services/blockStore.d.ts.map +1 -1
- package/src/lib/services/blockStore.js +4 -0
- package/src/lib/services/blockStore.js.map +1 -1
- package/src/lib/services/brightpass/auditLogger.d.ts +77 -0
- package/src/lib/services/brightpass/auditLogger.d.ts.map +1 -0
- package/src/lib/services/brightpass/auditLogger.js +184 -0
- package/src/lib/services/brightpass/auditLogger.js.map +1 -0
- package/src/lib/services/brightpass/vaultEncryption.d.ts +82 -0
- package/src/lib/services/brightpass/vaultEncryption.d.ts.map +1 -0
- package/src/lib/services/brightpass/vaultEncryption.js +144 -0
- package/src/lib/services/brightpass/vaultEncryption.js.map +1 -0
- package/src/lib/services/brightpass.d.ts +294 -0
- package/src/lib/services/brightpass.d.ts.map +1 -0
- package/src/lib/services/brightpass.js +1260 -0
- package/src/lib/services/brightpass.js.map +1 -0
- package/src/lib/services/brightpass.property.helpers.d.ts +23 -0
- package/src/lib/services/brightpass.property.helpers.d.ts.map +1 -0
- package/src/lib/services/brightpass.property.helpers.js +113 -0
- package/src/lib/services/brightpass.property.helpers.js.map +1 -0
- package/src/lib/services/eventNotificationSystem.d.ts +69 -3
- package/src/lib/services/eventNotificationSystem.d.ts.map +1 -1
- package/src/lib/services/eventNotificationSystem.js +200 -0
- package/src/lib/services/eventNotificationSystem.js.map +1 -1
- package/src/lib/services/expirationScheduler.d.ts +90 -0
- package/src/lib/services/expirationScheduler.d.ts.map +1 -0
- package/src/lib/services/expirationScheduler.js +131 -0
- package/src/lib/services/expirationScheduler.js.map +1 -0
- package/src/lib/services/fecUsageExample.d.ts +2 -2
- package/src/lib/services/index.d.ts +2 -0
- package/src/lib/services/index.d.ts.map +1 -1
- package/src/lib/services/index.js +2 -0
- package/src/lib/services/index.js.map +1 -1
- package/src/lib/services/paginationService.d.ts +18 -0
- package/src/lib/services/paginationService.d.ts.map +1 -0
- package/src/lib/services/paginationService.js +32 -0
- package/src/lib/services/paginationService.js.map +1 -0
- package/src/lib/services/presenceService.d.ts +76 -0
- package/src/lib/services/presenceService.d.ts.map +1 -0
- package/src/lib/services/presenceService.js +143 -0
- package/src/lib/services/presenceService.js.map +1 -0
- package/src/lib/services/wireConversationPromotion.d.ts +23 -0
- package/src/lib/services/wireConversationPromotion.d.ts.map +1 -0
- package/src/lib/services/wireConversationPromotion.js +26 -0
- package/src/lib/services/wireConversationPromotion.js.map +1 -0
- package/src/lib/stores/availabilityAwareBlockStore.d.ts +115 -10
- package/src/lib/stores/availabilityAwareBlockStore.d.ts.map +1 -1
- package/src/lib/stores/availabilityAwareBlockStore.js +267 -23
- package/src/lib/stores/availabilityAwareBlockStore.js.map +1 -1
- package/src/lib/stores/diskBlockAsyncStore.d.ts +81 -2
- package/src/lib/stores/diskBlockAsyncStore.d.ts.map +1 -1
- package/src/lib/stores/diskBlockAsyncStore.js +297 -10
- package/src/lib/stores/diskBlockAsyncStore.js.map +1 -1
- package/src/lib/upstream-stubs.d.ts +36 -0
- package/src/lib/upstream-stubs.d.ts.map +1 -0
- package/src/lib/upstream-stubs.js +43 -0
- package/src/lib/upstream-stubs.js.map +1 -0
- package/src/lib/utils/communicationValidation.d.ts +44 -0
- package/src/lib/utils/communicationValidation.d.ts.map +1 -0
- package/src/lib/utils/communicationValidation.js +291 -0
- package/src/lib/utils/communicationValidation.js.map +1 -0
- package/src/lib/utils/emailValidation.d.ts +19 -0
- package/src/lib/utils/emailValidation.d.ts.map +1 -0
- package/src/lib/utils/emailValidation.js +232 -0
- package/src/lib/utils/emailValidation.js.map +1 -0
- package/src/lib/interfaces/blockStore.d.ts +0 -7
- package/src/lib/interfaces/blockStore.d.ts.map +0 -1
- package/src/lib/interfaces/blockStore.js.map +0 -1
|
@@ -7,99 +7,6 @@ const base_1 = require("../base");
|
|
|
7
7
|
class EnergyController extends base_1.BaseController {
|
|
8
8
|
constructor(application) {
|
|
9
9
|
super(application);
|
|
10
|
-
this.handleGetBalance = async (req) => {
|
|
11
|
-
const user = req.user;
|
|
12
|
-
if (!user) {
|
|
13
|
-
return {
|
|
14
|
-
statusCode: 401,
|
|
15
|
-
response: {
|
|
16
|
-
message: 'Not authenticated',
|
|
17
|
-
error: 'Not authenticated',
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
const energyStore = this.application.services.get('energyStore');
|
|
23
|
-
const memberChecksum = brightchain_lib_1.Checksum.fromHex(user.memberId);
|
|
24
|
-
const account = energyStore.get(memberChecksum);
|
|
25
|
-
if (!account) {
|
|
26
|
-
return {
|
|
27
|
-
statusCode: 404,
|
|
28
|
-
response: {
|
|
29
|
-
message: 'Energy account not found',
|
|
30
|
-
error: 'Energy account not found',
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
statusCode: 200,
|
|
36
|
-
response: {
|
|
37
|
-
message: 'Balance retrieved',
|
|
38
|
-
balance: account.balance,
|
|
39
|
-
earned: account.earned,
|
|
40
|
-
spent: account.spent,
|
|
41
|
-
reserved: account.reserved,
|
|
42
|
-
reputation: account.reputation,
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return {
|
|
48
|
-
statusCode: 500,
|
|
49
|
-
response: {
|
|
50
|
-
message: 'Failed to retrieve balance',
|
|
51
|
-
error: 'Failed to retrieve balance',
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
this.handleGetTransactions = async (req) => {
|
|
57
|
-
const user = req.user;
|
|
58
|
-
if (!user) {
|
|
59
|
-
return {
|
|
60
|
-
statusCode: 401,
|
|
61
|
-
response: {
|
|
62
|
-
message: 'Not authenticated',
|
|
63
|
-
error: 'Not authenticated',
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
const energyLedger = this.application.services.get('energyLedger');
|
|
69
|
-
const memberChecksum = brightchain_lib_1.Checksum.fromHex(user.memberId);
|
|
70
|
-
const transactions = energyLedger.getByMember(memberChecksum);
|
|
71
|
-
// Map transactions to API response format
|
|
72
|
-
const transactionList = transactions.map((tx) => ({
|
|
73
|
-
id: tx.id.toHex(),
|
|
74
|
-
timestamp: tx.timestamp.toISOString(),
|
|
75
|
-
source: tx.source.toHex(),
|
|
76
|
-
destination: tx.destination.toHex(),
|
|
77
|
-
amount: tx.amount,
|
|
78
|
-
operationType: tx.operationType,
|
|
79
|
-
blockId: tx.blockId?.toHex(),
|
|
80
|
-
metadata: tx.metadata,
|
|
81
|
-
}));
|
|
82
|
-
// Sort by timestamp descending (most recent first)
|
|
83
|
-
transactionList.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
|
84
|
-
return {
|
|
85
|
-
statusCode: 200,
|
|
86
|
-
response: {
|
|
87
|
-
message: 'Transactions retrieved',
|
|
88
|
-
transactions: transactionList,
|
|
89
|
-
count: transactionList.length,
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
return {
|
|
95
|
-
statusCode: 500,
|
|
96
|
-
response: {
|
|
97
|
-
message: 'Failed to retrieve transactions',
|
|
98
|
-
error: 'Failed to retrieve transactions',
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
10
|
}
|
|
104
11
|
initRouteDefinitions() {
|
|
105
12
|
this.routeDefinitions = [
|
|
@@ -119,6 +26,99 @@ class EnergyController extends base_1.BaseController {
|
|
|
119
26
|
getTransactions: this.handleGetTransactions.bind(this),
|
|
120
27
|
};
|
|
121
28
|
}
|
|
29
|
+
async handleGetBalance(req) {
|
|
30
|
+
const user = req.user;
|
|
31
|
+
if (!user) {
|
|
32
|
+
return {
|
|
33
|
+
statusCode: 401,
|
|
34
|
+
response: {
|
|
35
|
+
message: 'Not authenticated',
|
|
36
|
+
error: 'Not authenticated',
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const energyStore = this.application.services.get('energyStore');
|
|
42
|
+
const memberChecksum = brightchain_lib_1.Checksum.fromHex(user.memberId);
|
|
43
|
+
const account = energyStore.get(memberChecksum);
|
|
44
|
+
if (!account) {
|
|
45
|
+
return {
|
|
46
|
+
statusCode: 404,
|
|
47
|
+
response: {
|
|
48
|
+
message: 'Energy account not found',
|
|
49
|
+
error: 'Energy account not found',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
statusCode: 200,
|
|
55
|
+
response: {
|
|
56
|
+
message: 'Balance retrieved',
|
|
57
|
+
balance: account.balance,
|
|
58
|
+
earned: account.earned,
|
|
59
|
+
spent: account.spent,
|
|
60
|
+
reserved: account.reserved,
|
|
61
|
+
reputation: account.reputation,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return {
|
|
67
|
+
statusCode: 500,
|
|
68
|
+
response: {
|
|
69
|
+
message: 'Failed to retrieve balance',
|
|
70
|
+
error: 'Failed to retrieve balance',
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async handleGetTransactions(req) {
|
|
76
|
+
const user = req.user;
|
|
77
|
+
if (!user) {
|
|
78
|
+
return {
|
|
79
|
+
statusCode: 401,
|
|
80
|
+
response: {
|
|
81
|
+
message: 'Not authenticated',
|
|
82
|
+
error: 'Not authenticated',
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const energyLedger = this.application.services.get('energyLedger');
|
|
88
|
+
const memberChecksum = brightchain_lib_1.Checksum.fromHex(user.memberId);
|
|
89
|
+
const transactions = energyLedger.getByMember(memberChecksum);
|
|
90
|
+
// Map transactions to API response format
|
|
91
|
+
const transactionList = transactions.map((tx) => ({
|
|
92
|
+
id: tx.id.toHex(),
|
|
93
|
+
timestamp: tx.timestamp.toISOString(),
|
|
94
|
+
source: tx.source.toHex(),
|
|
95
|
+
destination: tx.destination.toHex(),
|
|
96
|
+
amount: tx.amount,
|
|
97
|
+
operationType: tx.operationType,
|
|
98
|
+
blockId: tx.blockId?.toHex(),
|
|
99
|
+
metadata: tx.metadata,
|
|
100
|
+
}));
|
|
101
|
+
// Sort by timestamp descending (most recent first)
|
|
102
|
+
transactionList.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
|
103
|
+
return {
|
|
104
|
+
statusCode: 200,
|
|
105
|
+
response: {
|
|
106
|
+
message: 'Transactions retrieved',
|
|
107
|
+
transactions: transactionList,
|
|
108
|
+
count: transactionList.length,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return {
|
|
114
|
+
statusCode: 500,
|
|
115
|
+
response: {
|
|
116
|
+
message: 'Failed to retrieve transactions',
|
|
117
|
+
error: 'Failed to retrieve transactions',
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
122
|
}
|
|
123
123
|
exports.EnergyController = EnergyController;
|
|
124
124
|
//# sourceMappingURL=energy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"energy.js","sourceRoot":"","sources":["../../../../../../brightchain-api-lib/src/lib/controllers/api/energy.ts"],"names":[],"mappings":";;;AAAA,kEAIsC;AAGtC,4EAO6C;AAG7C,kCAAyC;AAOzC,MAAa,gBAEX,SAAQ,qBAKT;IACC,YAAY,WAAyC;QACnD,KAAK,CAAC,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"energy.js","sourceRoot":"","sources":["../../../../../../brightchain-api-lib/src/lib/controllers/api/energy.ts"],"names":[],"mappings":";;;AAAA,kEAIsC;AAGtC,4EAO6C;AAG7C,kCAAyC;AAOzC,MAAa,gBAEX,SAAQ,qBAKT;IACC,YAAY,WAAyC;QACnD,KAAK,CAAC,WAAW,CAAC,CAAC;IACrB,CAAC;IAES,oBAAoB;QAC5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AM,CAAC,KAAK,EAAE;gBACzB,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE;gBACnC,MAAM,EAAE,EAAE,CAAC,MAAM;gBACjB,aAAa,EAAE,EAAE,CAAC,aAAa;gBAC/B,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE;gBAC5B,QAAQ,EAAE,EAAE,CAAC,QAAQ;aACtB,CAAC,CAAC,CAAC;YAEJ,mDAAmD;YACnD,eAAe,CAAC,IAAI,CAClB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACP,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CACpE,CAAC;YAEF,OAAO;gBACL,UAAU,EAAE,GAAG;gBACf,QAAQ,EAAE;oBACR,OAAO,EAAE,wBAAwB;oBACjC,YAAY,EAAE,eAAe;oBAC7B,KAAK,EAAE,eAAe,CAAC,MAAM;iBACP;aACzB,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO;gBACL,UAAU,EAAE,GAAG;gBACf,QAAQ,EAAE;oBACR,OAAO,EAAE,iCAAiC;oBAC1C,KAAK,EAAE,iCAAiC;iBACzC;aACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AA9ID,4CA8IC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExplodingMessagesController — REST API for self-destructing message operations.
|
|
3
|
+
*
|
|
4
|
+
* Routes:
|
|
5
|
+
* PUT /:id/set-expiration — Set expiration on a message
|
|
6
|
+
* POST /:id/mark-read — Mark a message as read by a member
|
|
7
|
+
* GET /expired — List expired messages
|
|
8
|
+
* POST /:id/explode — Force-explode a message
|
|
9
|
+
* GET /:id/expiration-info — Get expiration status of a message
|
|
10
|
+
*
|
|
11
|
+
* Requirements: 8.1-8.9
|
|
12
|
+
*/
|
|
13
|
+
import { ICommunicationMessage } from '@brightchain/brightchain-lib/lib/interfaces/communication';
|
|
14
|
+
import type { IExplodeMessageResponse, IGetExpirationInfoResponse, IGetExpiredResponse, IMarkReadResponse, ISetExpirationResponse } from '@brightchain/brightchain-lib/lib/interfaces/responses/explodingMessageResponses';
|
|
15
|
+
import { PlatformID } from '@digitaldefiance/ecies-lib';
|
|
16
|
+
import { CoreLanguageCode } from '@digitaldefiance/i18n-lib';
|
|
17
|
+
import { ApiErrorResponse, ApiRequestHandler, TypedHandlers } from '@digitaldefiance/node-express-suite';
|
|
18
|
+
import { IBrightChainApplication } from '../../interfaces/application';
|
|
19
|
+
import { DefaultBackendIdType } from '../../shared-types';
|
|
20
|
+
import { BaseController } from '../base';
|
|
21
|
+
type ExplodingMessageApiResponse = ISetExpirationResponse | IMarkReadResponse | IGetExpiredResponse | IExplodeMessageResponse | IGetExpirationInfoResponse | ApiErrorResponse;
|
|
22
|
+
interface ExplodingMessageHandlers extends TypedHandlers {
|
|
23
|
+
setExpiration: ApiRequestHandler<ISetExpirationResponse | ApiErrorResponse>;
|
|
24
|
+
markRead: ApiRequestHandler<IMarkReadResponse | ApiErrorResponse>;
|
|
25
|
+
getExpired: ApiRequestHandler<IGetExpiredResponse | ApiErrorResponse>;
|
|
26
|
+
explodeMessage: ApiRequestHandler<IExplodeMessageResponse | ApiErrorResponse>;
|
|
27
|
+
getExpirationInfo: ApiRequestHandler<IGetExpirationInfoResponse | ApiErrorResponse>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Controller for exploding (self-destructing) message operations.
|
|
31
|
+
*
|
|
32
|
+
* Delegates to {@link ExplodingMessageService} in brightchain-lib for
|
|
33
|
+
* core expiration logic including time-based and read-count-based
|
|
34
|
+
* message self-destruction.
|
|
35
|
+
*
|
|
36
|
+
* @requirements 8.1, 8.2, 8.3, 8.4, 8.5, 8.7, 8.8
|
|
37
|
+
*/
|
|
38
|
+
export declare class ExplodingMessagesController<TID extends PlatformID = DefaultBackendIdType> extends BaseController<TID, ExplodingMessageApiResponse, ExplodingMessageHandlers, CoreLanguageCode> {
|
|
39
|
+
private messageStore;
|
|
40
|
+
constructor(application: IBrightChainApplication<TID>);
|
|
41
|
+
/**
|
|
42
|
+
* Inject a message into the store (for integration with message passing).
|
|
43
|
+
*/
|
|
44
|
+
registerMessage(message: ICommunicationMessage): void;
|
|
45
|
+
protected initRouteDefinitions(): void;
|
|
46
|
+
/**
|
|
47
|
+
* PUT /:id/set-expiration — Set expiration on a message.
|
|
48
|
+
*
|
|
49
|
+
* @requirements 8.1, 8.2, 8.5
|
|
50
|
+
*/
|
|
51
|
+
private handleSetExpiration;
|
|
52
|
+
/**
|
|
53
|
+
* POST /:id/mark-read — Mark a message as read.
|
|
54
|
+
*
|
|
55
|
+
* @requirements 8.2, 8.3, 8.8
|
|
56
|
+
*/
|
|
57
|
+
private handleMarkRead;
|
|
58
|
+
/**
|
|
59
|
+
* GET /expired — List all expired messages.
|
|
60
|
+
*
|
|
61
|
+
* @requirements 8.4, 8.8
|
|
62
|
+
*/
|
|
63
|
+
private handleGetExpired;
|
|
64
|
+
/**
|
|
65
|
+
* POST /:id/explode — Force-explode a message.
|
|
66
|
+
*
|
|
67
|
+
* @requirements 8.4, 8.7
|
|
68
|
+
*/
|
|
69
|
+
private handleExplodeMessage;
|
|
70
|
+
/**
|
|
71
|
+
* GET /:id/expiration-info — Get expiration status.
|
|
72
|
+
*
|
|
73
|
+
* @requirements 8.8
|
|
74
|
+
*/
|
|
75
|
+
private handleGetExpirationInfo;
|
|
76
|
+
private mapExplodingError;
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=explodingMessages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explodingMessages.d.ts","sourceRoot":"","sources":["../../../../../../brightchain-api-lib/src/lib/controllers/api/explodingMessages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,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IAIrD;;OAEG;IACI,eAAe,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI;IAM5D,SAAS,CAAC,oBAAoB,IAAI,IAAI;IAwHtC;;;;OAIG;YACW,mBAAmB;IAyCjC;;;;OAIG;YACW,cAAc;IA6C5B;;;;OAIG;YACW,gBAAgB;IA2B9B;;;;OAIG;YACW,oBAAoB;IAmClC;;;;OAIG;YACW,uBAAuB;IAwCrC,OAAO,CAAC,iBAAiB;CAwB1B"}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ExplodingMessagesController — REST API for self-destructing message operations.
|
|
4
|
+
*
|
|
5
|
+
* Routes:
|
|
6
|
+
* PUT /:id/set-expiration — Set expiration on a message
|
|
7
|
+
* POST /:id/mark-read — Mark a message as read by a member
|
|
8
|
+
* GET /expired — List expired messages
|
|
9
|
+
* POST /:id/explode — Force-explode a message
|
|
10
|
+
* GET /:id/expiration-info — Get expiration status of a message
|
|
11
|
+
*
|
|
12
|
+
* Requirements: 8.1-8.9
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ExplodingMessagesController = void 0;
|
|
16
|
+
const explodingMessageService_1 = require("@brightchain/brightchain-lib/lib/services/communication/explodingMessageService");
|
|
17
|
+
const node_express_suite_1 = require("@digitaldefiance/node-express-suite");
|
|
18
|
+
const errorResponse_1 = require("../../utils/errorResponse");
|
|
19
|
+
const base_1 = require("../base");
|
|
20
|
+
// ─── Message store (in-memory for now, replaced by persistence layer) ───────
|
|
21
|
+
/**
|
|
22
|
+
* Simple in-memory message store for exploding message operations.
|
|
23
|
+
* In production, this would be replaced by the actual message persistence layer.
|
|
24
|
+
*/
|
|
25
|
+
class ExplodingMessageStore {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.messages = new Map();
|
|
28
|
+
}
|
|
29
|
+
get(id) {
|
|
30
|
+
return this.messages.get(id);
|
|
31
|
+
}
|
|
32
|
+
set(message) {
|
|
33
|
+
this.messages.set(String(message.id), message);
|
|
34
|
+
}
|
|
35
|
+
getAll() {
|
|
36
|
+
return Array.from(this.messages.values());
|
|
37
|
+
}
|
|
38
|
+
remove(id) {
|
|
39
|
+
return this.messages.delete(id);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// ─── Controller ─────────────────────────────────────────────────────────────
|
|
43
|
+
/**
|
|
44
|
+
* Controller for exploding (self-destructing) message operations.
|
|
45
|
+
*
|
|
46
|
+
* Delegates to {@link ExplodingMessageService} in brightchain-lib for
|
|
47
|
+
* core expiration logic including time-based and read-count-based
|
|
48
|
+
* message self-destruction.
|
|
49
|
+
*
|
|
50
|
+
* @requirements 8.1, 8.2, 8.3, 8.4, 8.5, 8.7, 8.8
|
|
51
|
+
*/
|
|
52
|
+
class ExplodingMessagesController extends base_1.BaseController {
|
|
53
|
+
constructor(application) {
|
|
54
|
+
super(application);
|
|
55
|
+
this.messageStore = new ExplodingMessageStore();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Inject a message into the store (for integration with message passing).
|
|
59
|
+
*/
|
|
60
|
+
registerMessage(message) {
|
|
61
|
+
this.messageStore.set(message);
|
|
62
|
+
}
|
|
63
|
+
// ─── Route definitions ──────────────────────────────────────────────────
|
|
64
|
+
initRouteDefinitions() {
|
|
65
|
+
const noAuth = {
|
|
66
|
+
useAuthentication: false,
|
|
67
|
+
useCryptoAuthentication: false,
|
|
68
|
+
};
|
|
69
|
+
this.routeDefinitions = [
|
|
70
|
+
(0, node_express_suite_1.routeConfig)('put', '/:id/set-expiration', {
|
|
71
|
+
...noAuth,
|
|
72
|
+
handlerKey: 'setExpiration',
|
|
73
|
+
openapi: {
|
|
74
|
+
summary: 'Set message expiration',
|
|
75
|
+
description: 'Configure time-based or read-count-based expiration on a message.',
|
|
76
|
+
tags: ['Exploding Messages'],
|
|
77
|
+
responses: {
|
|
78
|
+
200: {
|
|
79
|
+
schema: 'SetExpirationResponse',
|
|
80
|
+
description: 'Expiration set successfully',
|
|
81
|
+
},
|
|
82
|
+
400: {
|
|
83
|
+
schema: 'ApiErrorResponse',
|
|
84
|
+
description: 'Invalid expiration settings',
|
|
85
|
+
},
|
|
86
|
+
404: {
|
|
87
|
+
schema: 'ApiErrorResponse',
|
|
88
|
+
description: 'Message not found',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
(0, node_express_suite_1.routeConfig)('post', '/:id/mark-read', {
|
|
94
|
+
...noAuth,
|
|
95
|
+
handlerKey: 'markRead',
|
|
96
|
+
openapi: {
|
|
97
|
+
summary: 'Mark message as read',
|
|
98
|
+
description: 'Record that a member has read the message. Returns whether the message should explode.',
|
|
99
|
+
tags: ['Exploding Messages'],
|
|
100
|
+
responses: {
|
|
101
|
+
200: {
|
|
102
|
+
schema: 'MarkReadResponse',
|
|
103
|
+
description: 'Read recorded',
|
|
104
|
+
},
|
|
105
|
+
404: {
|
|
106
|
+
schema: 'ApiErrorResponse',
|
|
107
|
+
description: 'Message not found',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
}),
|
|
112
|
+
(0, node_express_suite_1.routeConfig)('get', '/expired', {
|
|
113
|
+
...noAuth,
|
|
114
|
+
handlerKey: 'getExpired',
|
|
115
|
+
openapi: {
|
|
116
|
+
summary: 'List expired messages',
|
|
117
|
+
description: 'Returns all messages that have expired and should be deleted.',
|
|
118
|
+
tags: ['Exploding Messages'],
|
|
119
|
+
responses: {
|
|
120
|
+
200: {
|
|
121
|
+
schema: 'GetExpiredResponse',
|
|
122
|
+
description: 'List of expired messages',
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
}),
|
|
127
|
+
(0, node_express_suite_1.routeConfig)('post', '/:id/explode', {
|
|
128
|
+
...noAuth,
|
|
129
|
+
handlerKey: 'explodeMessage',
|
|
130
|
+
openapi: {
|
|
131
|
+
summary: 'Force-explode a message',
|
|
132
|
+
description: 'Immediately explode (permanently delete) a message regardless of expiration settings.',
|
|
133
|
+
tags: ['Exploding Messages'],
|
|
134
|
+
responses: {
|
|
135
|
+
200: {
|
|
136
|
+
schema: 'ExplodeMessageResponse',
|
|
137
|
+
description: 'Message exploded',
|
|
138
|
+
},
|
|
139
|
+
404: {
|
|
140
|
+
schema: 'ApiErrorResponse',
|
|
141
|
+
description: 'Message not found',
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
}),
|
|
146
|
+
(0, node_express_suite_1.routeConfig)('get', '/:id/expiration-info', {
|
|
147
|
+
...noAuth,
|
|
148
|
+
handlerKey: 'getExpirationInfo',
|
|
149
|
+
openapi: {
|
|
150
|
+
summary: 'Get expiration info',
|
|
151
|
+
description: 'Returns the expiration status and remaining time/reads for a message.',
|
|
152
|
+
tags: ['Exploding Messages'],
|
|
153
|
+
responses: {
|
|
154
|
+
200: {
|
|
155
|
+
schema: 'GetExpirationInfoResponse',
|
|
156
|
+
description: 'Expiration info',
|
|
157
|
+
},
|
|
158
|
+
404: {
|
|
159
|
+
schema: 'ApiErrorResponse',
|
|
160
|
+
description: 'Message not found',
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
}),
|
|
165
|
+
];
|
|
166
|
+
this.handlers = {
|
|
167
|
+
setExpiration: this.handleSetExpiration.bind(this),
|
|
168
|
+
markRead: this.handleMarkRead.bind(this),
|
|
169
|
+
getExpired: this.handleGetExpired.bind(this),
|
|
170
|
+
explodeMessage: this.handleExplodeMessage.bind(this),
|
|
171
|
+
getExpirationInfo: this.handleGetExpirationInfo.bind(this),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
// ─── Handlers ─────────────────────────────────────────────────────────
|
|
175
|
+
/**
|
|
176
|
+
* PUT /:id/set-expiration — Set expiration on a message.
|
|
177
|
+
*
|
|
178
|
+
* @requirements 8.1, 8.2, 8.5
|
|
179
|
+
*/
|
|
180
|
+
async handleSetExpiration(req) {
|
|
181
|
+
try {
|
|
182
|
+
const { id } = req.params;
|
|
183
|
+
const { expiresAt, expiresInMs, maxReads } = req
|
|
184
|
+
.body;
|
|
185
|
+
if (!id) {
|
|
186
|
+
return (0, errorResponse_1.validationError)('Missing required parameter: id');
|
|
187
|
+
}
|
|
188
|
+
const message = this.messageStore.get(id);
|
|
189
|
+
if (!message) {
|
|
190
|
+
return (0, errorResponse_1.notFoundError)('Message', id);
|
|
191
|
+
}
|
|
192
|
+
explodingMessageService_1.ExplodingMessageService.setExpiration(message, {
|
|
193
|
+
expiresAt: expiresAt ? new Date(expiresAt) : undefined,
|
|
194
|
+
expiresInMs,
|
|
195
|
+
maxReads,
|
|
196
|
+
});
|
|
197
|
+
return {
|
|
198
|
+
statusCode: 200,
|
|
199
|
+
response: {
|
|
200
|
+
status: 'success',
|
|
201
|
+
data: {
|
|
202
|
+
messageId: id,
|
|
203
|
+
expiresAt: message.expiresAt?.toISOString(),
|
|
204
|
+
maxReads: message.maxReads,
|
|
205
|
+
},
|
|
206
|
+
message: 'Expiration set successfully',
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
return this.mapExplodingError(error);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* POST /:id/mark-read — Mark a message as read.
|
|
216
|
+
*
|
|
217
|
+
* @requirements 8.2, 8.3, 8.8
|
|
218
|
+
*/
|
|
219
|
+
async handleMarkRead(req) {
|
|
220
|
+
try {
|
|
221
|
+
const { id } = req.params;
|
|
222
|
+
const { memberId } = req.body;
|
|
223
|
+
if (!id) {
|
|
224
|
+
return (0, errorResponse_1.validationError)('Missing required parameter: id');
|
|
225
|
+
}
|
|
226
|
+
if (!memberId || typeof memberId !== 'string') {
|
|
227
|
+
return (0, errorResponse_1.validationError)('Missing required field: memberId');
|
|
228
|
+
}
|
|
229
|
+
const message = this.messageStore.get(id);
|
|
230
|
+
if (!message) {
|
|
231
|
+
return (0, errorResponse_1.notFoundError)('Message', id);
|
|
232
|
+
}
|
|
233
|
+
const shouldExplode = explodingMessageService_1.ExplodingMessageService.markRead(message, memberId);
|
|
234
|
+
if (shouldExplode) {
|
|
235
|
+
explodingMessageService_1.ExplodingMessageService.explode(message);
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
statusCode: 200,
|
|
239
|
+
response: {
|
|
240
|
+
status: 'success',
|
|
241
|
+
data: {
|
|
242
|
+
messageId: id,
|
|
243
|
+
readCount: message.readCount ?? 0,
|
|
244
|
+
shouldExplode,
|
|
245
|
+
},
|
|
246
|
+
message: shouldExplode
|
|
247
|
+
? 'Message read count exceeded — message exploded'
|
|
248
|
+
: 'Read recorded',
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
return this.mapExplodingError(error);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* GET /expired — List all expired messages.
|
|
258
|
+
*
|
|
259
|
+
* @requirements 8.4, 8.8
|
|
260
|
+
*/
|
|
261
|
+
async handleGetExpired(_req) {
|
|
262
|
+
try {
|
|
263
|
+
const allMessages = this.messageStore.getAll();
|
|
264
|
+
const result = explodingMessageService_1.ExplodingMessageService.deleteExpired(allMessages);
|
|
265
|
+
return {
|
|
266
|
+
statusCode: 200,
|
|
267
|
+
response: {
|
|
268
|
+
status: 'success',
|
|
269
|
+
data: {
|
|
270
|
+
expired: result.events.map((e) => ({
|
|
271
|
+
messageId: e.messageId,
|
|
272
|
+
reason: e.reason,
|
|
273
|
+
})),
|
|
274
|
+
totalCount: result.expired.length,
|
|
275
|
+
},
|
|
276
|
+
message: `Found ${result.expired.length} expired message(s)`,
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
return (0, errorResponse_1.handleError)(error);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* POST /:id/explode — Force-explode a message.
|
|
286
|
+
*
|
|
287
|
+
* @requirements 8.4, 8.7
|
|
288
|
+
*/
|
|
289
|
+
async handleExplodeMessage(req) {
|
|
290
|
+
try {
|
|
291
|
+
const { id } = req.params;
|
|
292
|
+
if (!id) {
|
|
293
|
+
return (0, errorResponse_1.validationError)('Missing required parameter: id');
|
|
294
|
+
}
|
|
295
|
+
const message = this.messageStore.get(id);
|
|
296
|
+
if (!message) {
|
|
297
|
+
return (0, errorResponse_1.notFoundError)('Message', id);
|
|
298
|
+
}
|
|
299
|
+
const event = explodingMessageService_1.ExplodingMessageService.explode(message);
|
|
300
|
+
return {
|
|
301
|
+
statusCode: 200,
|
|
302
|
+
response: {
|
|
303
|
+
status: 'success',
|
|
304
|
+
data: {
|
|
305
|
+
messageId: id,
|
|
306
|
+
exploded: true,
|
|
307
|
+
explodedAt: event.explodedAt.toISOString(),
|
|
308
|
+
},
|
|
309
|
+
message: 'Message exploded',
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
return this.mapExplodingError(error);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* GET /:id/expiration-info — Get expiration status.
|
|
319
|
+
*
|
|
320
|
+
* @requirements 8.8
|
|
321
|
+
*/
|
|
322
|
+
async handleGetExpirationInfo(req) {
|
|
323
|
+
try {
|
|
324
|
+
const { id } = req.params;
|
|
325
|
+
if (!id) {
|
|
326
|
+
return (0, errorResponse_1.validationError)('Missing required parameter: id');
|
|
327
|
+
}
|
|
328
|
+
const message = this.messageStore.get(id);
|
|
329
|
+
if (!message) {
|
|
330
|
+
return (0, errorResponse_1.notFoundError)('Message', id);
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
statusCode: 200,
|
|
334
|
+
response: {
|
|
335
|
+
status: 'success',
|
|
336
|
+
data: {
|
|
337
|
+
messageId: id,
|
|
338
|
+
isExploding: explodingMessageService_1.ExplodingMessageService.isExplodingMessage(message),
|
|
339
|
+
expiresAt: message.expiresAt?.toISOString(),
|
|
340
|
+
maxReads: message.maxReads,
|
|
341
|
+
readCount: message.readCount,
|
|
342
|
+
remainingTimeMs: explodingMessageService_1.ExplodingMessageService.getRemainingTime(message),
|
|
343
|
+
remainingReads: explodingMessageService_1.ExplodingMessageService.getRemainingReads(message),
|
|
344
|
+
exploded: message.exploded ?? false,
|
|
345
|
+
},
|
|
346
|
+
message: 'Expiration info retrieved',
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
return (0, errorResponse_1.handleError)(error);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
// ─── Error mapping ──────────────────────────────────────────────────
|
|
355
|
+
mapExplodingError(error) {
|
|
356
|
+
if (error instanceof explodingMessageService_1.MessageAlreadyExplodedError) {
|
|
357
|
+
return {
|
|
358
|
+
statusCode: 400,
|
|
359
|
+
response: {
|
|
360
|
+
message: error.message,
|
|
361
|
+
error: 'MESSAGE_ALREADY_EXPLODED',
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
if (error instanceof explodingMessageService_1.InvalidExpirationError) {
|
|
366
|
+
return {
|
|
367
|
+
statusCode: 400,
|
|
368
|
+
response: {
|
|
369
|
+
message: error.message,
|
|
370
|
+
error: 'INVALID_EXPIRATION',
|
|
371
|
+
},
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
return (0, errorResponse_1.handleError)(error);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
exports.ExplodingMessagesController = ExplodingMessagesController;
|
|
378
|
+
//# sourceMappingURL=explodingMessages.js.map
|