@bopen-io/messagebox-server 1.1.5
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 +372 -0
- package/knexfile.d.ts +5 -0
- package/knexfile.ts +29 -0
- package/out/knexfile.js +25 -0
- package/out/knexfile.js.map +1 -0
- package/out/src/app.js +160 -0
- package/out/src/app.js.map +1 -0
- package/out/src/config/firebase.js +150 -0
- package/out/src/config/firebase.js.map +1 -0
- package/out/src/index.js +295 -0
- package/out/src/index.js.map +1 -0
- package/out/src/migrations/2022-12-28-001-initial-migration.js +28 -0
- package/out/src/migrations/2022-12-28-001-initial-migration.js.map +1 -0
- package/out/src/migrations/2023-01-17-messages-update.js +11 -0
- package/out/src/migrations/2023-01-17-messages-update.js.map +1 -0
- package/out/src/migrations/2024-03-05-001-messageID-upgrade.js +21 -0
- package/out/src/migrations/2024-03-05-001-messageID-upgrade.js.map +1 -0
- package/out/src/migrations/2025-01-31-001-notification-permissions.js +59 -0
- package/out/src/migrations/2025-01-31-001-notification-permissions.js.map +1 -0
- package/out/src/migrations/2025-01-31-002-device-registrations.js +24 -0
- package/out/src/migrations/2025-01-31-002-device-registrations.js.map +1 -0
- package/out/src/routes/__tests/acknowledgeMessage.test.js +129 -0
- package/out/src/routes/__tests/acknowledgeMessage.test.js.map +1 -0
- package/out/src/routes/__tests/listMessages.test.js +211 -0
- package/out/src/routes/__tests/listMessages.test.js.map +1 -0
- package/out/src/routes/__tests/sendMessage.test.js +307 -0
- package/out/src/routes/__tests/sendMessage.test.js.map +1 -0
- package/out/src/routes/acknowledgeMessage.js +144 -0
- package/out/src/routes/acknowledgeMessage.js.map +1 -0
- package/out/src/routes/index.js +17 -0
- package/out/src/routes/index.js.map +1 -0
- package/out/src/routes/listDevices.js +74 -0
- package/out/src/routes/listDevices.js.map +1 -0
- package/out/src/routes/listMessages.js +186 -0
- package/out/src/routes/listMessages.js.map +1 -0
- package/out/src/routes/permissions/getPermission.js +149 -0
- package/out/src/routes/permissions/getPermission.js.map +1 -0
- package/out/src/routes/permissions/getQuote.js +165 -0
- package/out/src/routes/permissions/getQuote.js.map +1 -0
- package/out/src/routes/permissions/index.js +12 -0
- package/out/src/routes/permissions/index.js.map +1 -0
- package/out/src/routes/permissions/listPermissions.js +190 -0
- package/out/src/routes/permissions/listPermissions.js.map +1 -0
- package/out/src/routes/permissions/setPermission.js +137 -0
- package/out/src/routes/permissions/setPermission.js.map +1 -0
- package/out/src/routes/registerDevice.js +150 -0
- package/out/src/routes/registerDevice.js.map +1 -0
- package/out/src/routes/sendMessage.js +451 -0
- package/out/src/routes/sendMessage.js.map +1 -0
- package/out/src/swagger.js +49 -0
- package/out/src/swagger.js.map +1 -0
- package/out/src/types/messagePermissions.js +2 -0
- package/out/src/types/messagePermissions.js.map +1 -0
- package/out/src/types/notifications.js +2 -0
- package/out/src/types/notifications.js.map +1 -0
- package/out/src/utils/logger.js +24 -0
- package/out/src/utils/logger.js.map +1 -0
- package/out/src/utils/messagePermissions.js +126 -0
- package/out/src/utils/messagePermissions.js.map +1 -0
- package/out/src/utils/sendFCMNotification.js +121 -0
- package/out/src/utils/sendFCMNotification.js.map +1 -0
- package/out/tsconfig.tsbuildinfo +1 -0
- package/package.json +88 -0
- package/src/migrations/2022-12-28-001-initial-migration.ts +31 -0
- package/src/migrations/2023-01-17-messages-update.ts +13 -0
- package/src/migrations/2024-03-05-001-messageID-upgrade.ts +25 -0
- package/src/migrations/2025-01-31-001-notification-permissions.ts +68 -0
- package/src/migrations/2025-01-31-002-device-registrations.ts +28 -0
- package/src/templates/documentation.ejs +62 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendMessage.test.js","sourceRoot":"","sources":["../../../../src/routes/__tests/sendMessage.test.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,OAAO,WAAW,EAAE,EAAE,qBAAqB,EAA+B,MAAM,mBAAmB,CAAA;AACnG,OAAO,QAAQ,MAAM,WAAW,CAAA;A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EAAE;YACnC,IAAI,IAAI,KAAK,CAAC;gBAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA,CAAC,uBAAuB;iBACxD,IAAI,IAAI,KAAK,CAAC;gBAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA,CAAC,oBAAoB;iBAClD,IAAI,IAAI,KAAK,CAAC;gBAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,CAAA,CAAC,sCAAsC;iBACvF,IAAI,IAAI,KAAK,CAAC;gBAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA,CAAC,iBAAiB;;gBAC/C,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QACrB,CAAC,CAAC,CAAA;QAEF,MAAM,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QAEzC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAA;QAChD,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,oBAAoB,CAAC,MAAM,CAAC,gBAAgB,CAAC;YAChE,MAAM,EAAE,SAAS;SAClB,CAAC,CAAC,CAAA;IACL,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file acknowledgeMessage.ts
|
|
3
|
+
* @description
|
|
4
|
+
* Express route to allow a client to acknowledge receipt of one or more messages.
|
|
5
|
+
* Acknowledged messages are permanently removed from the database for the
|
|
6
|
+
* authenticated identity key (recipient).
|
|
7
|
+
*
|
|
8
|
+
* This is used in the MessageBox system to clear delivered messages once received
|
|
9
|
+
* and handled on the client side (e.g., after syncing or displaying them).
|
|
10
|
+
*/
|
|
11
|
+
import knexConfig from '../../knexfile.js';
|
|
12
|
+
import * as knexLib from 'knex';
|
|
13
|
+
import { Logger } from '../utils/logger.js';
|
|
14
|
+
// Determine environment and initialize Knex connection
|
|
15
|
+
const { NODE_ENV = 'development' } = process.env;
|
|
16
|
+
/**
|
|
17
|
+
* Knex instance connected based on environment (development, production, or staging).
|
|
18
|
+
*/
|
|
19
|
+
const knex = knexLib.default?.(NODE_ENV === 'production' || NODE_ENV === 'staging'
|
|
20
|
+
? knexConfig.production
|
|
21
|
+
: knexConfig.development) ?? knexLib(NODE_ENV === 'production' || NODE_ENV === 'staging'
|
|
22
|
+
? knexConfig.production
|
|
23
|
+
: knexConfig.development);
|
|
24
|
+
/**
|
|
25
|
+
* @openapi
|
|
26
|
+
* /acknowledgeMessage:
|
|
27
|
+
* post:
|
|
28
|
+
* summary: Acknowledge receipt of one or more messages
|
|
29
|
+
* description: |
|
|
30
|
+
* Removes acknowledged messages from the database for the authenticated identity key.
|
|
31
|
+
* This is used after a client has received and handled messages.
|
|
32
|
+
* tags:
|
|
33
|
+
* - Message
|
|
34
|
+
* requestBody:
|
|
35
|
+
* required: true
|
|
36
|
+
* content:
|
|
37
|
+
* application/json:
|
|
38
|
+
* schema:
|
|
39
|
+
* type: object
|
|
40
|
+
* properties:
|
|
41
|
+
* messageIds:
|
|
42
|
+
* type: array
|
|
43
|
+
* items:
|
|
44
|
+
* type: string
|
|
45
|
+
* description: Array of message IDs to acknowledge
|
|
46
|
+
* responses:
|
|
47
|
+
* 200:
|
|
48
|
+
* description: Successfully acknowledged messages
|
|
49
|
+
* content:
|
|
50
|
+
* application/json:
|
|
51
|
+
* schema:
|
|
52
|
+
* type: object
|
|
53
|
+
* properties:
|
|
54
|
+
* status:
|
|
55
|
+
* type: string
|
|
56
|
+
* example: success
|
|
57
|
+
* 400:
|
|
58
|
+
* description: Invalid input or message not found
|
|
59
|
+
* 500:
|
|
60
|
+
* description: Internal server error
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* @exports
|
|
64
|
+
* Route definition for acknowledging MessageBox messages.
|
|
65
|
+
* This object is consumed by the Express route loader to register the endpoint.
|
|
66
|
+
*/
|
|
67
|
+
export default {
|
|
68
|
+
type: 'post',
|
|
69
|
+
path: '/acknowledgeMessage',
|
|
70
|
+
knex,
|
|
71
|
+
summary: 'Use this route to acknowledge a message has been received',
|
|
72
|
+
parameters: {
|
|
73
|
+
messageIds: ['3301']
|
|
74
|
+
},
|
|
75
|
+
exampleResponse: {
|
|
76
|
+
status: 'success'
|
|
77
|
+
},
|
|
78
|
+
errors: [],
|
|
79
|
+
/**
|
|
80
|
+
* @function func
|
|
81
|
+
* @description
|
|
82
|
+
* Express route handler that processes a POST request to acknowledge messages.
|
|
83
|
+
* Deletes messages from the database where:
|
|
84
|
+
* - recipient matches the authenticated identity key
|
|
85
|
+
* - messageId matches one or more of the provided IDs
|
|
86
|
+
*
|
|
87
|
+
* Returns:
|
|
88
|
+
* - 200 success if deletion occurs
|
|
89
|
+
* - 400 if no messages were found or input is invalid
|
|
90
|
+
* - 500 on internal error
|
|
91
|
+
*
|
|
92
|
+
* @param {AcknowledgeRequest} req - Express request object containing auth and message IDs
|
|
93
|
+
* @param {Response} res - Express response object
|
|
94
|
+
* @returns {Promise<Response>} JSON response with status and optional error codes
|
|
95
|
+
*/
|
|
96
|
+
func: async (req, res) => {
|
|
97
|
+
try {
|
|
98
|
+
const { messageIds } = req.body;
|
|
99
|
+
Logger.log('[SERVER] acknowledgeMessage called for messageIds:', messageIds, 'by', req.auth.identityKey);
|
|
100
|
+
// Validate request: must be a non-empty array of strings
|
|
101
|
+
if ((messageIds == null) || (Array.isArray(messageIds) && messageIds.length === 0)) {
|
|
102
|
+
return res.status(400).json({
|
|
103
|
+
status: 'error',
|
|
104
|
+
code: 'ERR_MESSAGE_ID_REQUIRED',
|
|
105
|
+
description: 'Please provide the ID of the message(s) to acknowledge!'
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (!Array.isArray(messageIds) || messageIds.some(id => typeof id !== 'string')) {
|
|
109
|
+
return res.status(400).json({
|
|
110
|
+
status: 'error',
|
|
111
|
+
code: 'ERR_INVALID_MESSAGE_ID',
|
|
112
|
+
description: 'Message IDs must be formatted as an array of strings!'
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
// Delete acknowledged messages for this recipient from the database
|
|
116
|
+
const deleted = await knex('messages')
|
|
117
|
+
.where({ recipient: req.auth.identityKey })
|
|
118
|
+
.whereIn('messageId', Array.isArray(messageIds) ? messageIds : [messageIds])
|
|
119
|
+
.del();
|
|
120
|
+
// No matching messages found
|
|
121
|
+
if (deleted === 0) {
|
|
122
|
+
return res.status(400).json({
|
|
123
|
+
status: 'error',
|
|
124
|
+
code: 'ERR_INVALID_ACKNOWLEDGMENT',
|
|
125
|
+
description: 'Message not found!'
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// Deletion failed unexpectedly
|
|
129
|
+
if (deleted < 0) {
|
|
130
|
+
throw new Error('Deletion failed');
|
|
131
|
+
}
|
|
132
|
+
return res.status(200).json({ status: 'success' });
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
Logger.error(e);
|
|
136
|
+
return res.status(500).json({
|
|
137
|
+
status: 'error',
|
|
138
|
+
code: 'ERR_INTERNAL_ERROR',
|
|
139
|
+
description: 'An internal error has occurred while acknowledging the message'
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=acknowledgeMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acknowledgeMessage.js","sourceRoot":"","sources":["../../../src/routes/acknowledgeMessage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,UAAU,MAAM,mBAAmB,CAAA;AAC1C,OAAO,KAAK,OAAO,MAAM,MAAM,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAE3C,uDAAuD;AACvD,MAAM,EAAE,QAAQ,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC,GAAG,CAAA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GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAC1B,MAAM,EAAE,OAAO;gBACf,IAAI,EAAE,oBAAoB;gBAC1B,WAAW,EAAE,gEAAgE;aAC9E,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import sendMessage from './sendMessage.js';
|
|
2
|
+
import listMessages from './listMessages.js';
|
|
3
|
+
import acknowledgeMessage from './acknowledgeMessage.js';
|
|
4
|
+
import registerDevice from './registerDevice.js';
|
|
5
|
+
import listDevices from './listDevices.js';
|
|
6
|
+
import { permissionRoutes } from './permissions/index.js';
|
|
7
|
+
// Explicitly type the exported arrays to avoid type inference issues
|
|
8
|
+
export const preAuth = [];
|
|
9
|
+
export const postAuth = [
|
|
10
|
+
sendMessage,
|
|
11
|
+
listMessages,
|
|
12
|
+
acknowledgeMessage,
|
|
13
|
+
registerDevice,
|
|
14
|
+
listDevices,
|
|
15
|
+
...permissionRoutes
|
|
16
|
+
];
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,kBAAkB,CAAA;AAC1C,OAAO,YAAY,MAAM,mBAAmB,CAAA;AAC5C,OAAO,kBAAkB,MAAM,yBAAyB,CAAA;AACxD,OAAO,cAAc,MAAM,qBAAqB,CAAA;AAChD,OAAO,WAAW,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAEzD,qEAAqE;AACrE,MAAM,CAAC,MAAM,OAAO,GAA0D,EAAE,CAAA;AAChF,MAAM,CAAC,MAAM,QAAQ,GAA0D;IAC7E,WAAW;IACX,YAAY;IACZ,kBAAkB;IAClB,cAAc;IACd,WAAW;IACX,GAAG,gBAAgB;CACpB,CAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import knexConfig from '../../knexfile.js';
|
|
2
|
+
import * as knexLib from 'knex';
|
|
3
|
+
import { Logger } from '../utils/logger.js';
|
|
4
|
+
// Determine the environment (default to development)
|
|
5
|
+
const { NODE_ENV = 'development' } = process.env;
|
|
6
|
+
/**
|
|
7
|
+
* Knex instance connected based on environment (development, production, or staging).
|
|
8
|
+
*/
|
|
9
|
+
const knex = knexLib.default?.(NODE_ENV === 'production' || NODE_ENV === 'staging'
|
|
10
|
+
? knexConfig.production
|
|
11
|
+
: knexConfig.development) ?? knexLib(NODE_ENV === 'production' || NODE_ENV === 'staging'
|
|
12
|
+
? knexConfig.production
|
|
13
|
+
: knexConfig.development);
|
|
14
|
+
export default {
|
|
15
|
+
type: 'get',
|
|
16
|
+
path: '/devices',
|
|
17
|
+
func: async (req, res) => {
|
|
18
|
+
try {
|
|
19
|
+
Logger.log('[DEBUG] Processing list devices request');
|
|
20
|
+
// Validate authentication
|
|
21
|
+
const identityKey = req.auth?.identityKey;
|
|
22
|
+
if (identityKey == null) {
|
|
23
|
+
Logger.log('[DEBUG] Authentication required for listing devices');
|
|
24
|
+
return res.status(401).json({
|
|
25
|
+
status: 'error',
|
|
26
|
+
code: 'ERR_AUTHENTICATION_REQUIRED',
|
|
27
|
+
description: 'Authentication required.'
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
// Query devices for the authenticated user
|
|
32
|
+
const devices = await knex('device_registrations')
|
|
33
|
+
.select([
|
|
34
|
+
'id',
|
|
35
|
+
'device_id as deviceId',
|
|
36
|
+
'platform',
|
|
37
|
+
'fcm_token as fcmToken',
|
|
38
|
+
'active',
|
|
39
|
+
'created_at as createdAt',
|
|
40
|
+
'updated_at as updatedAt',
|
|
41
|
+
'last_used as lastUsed'
|
|
42
|
+
])
|
|
43
|
+
.where('identity_key', identityKey)
|
|
44
|
+
.orderBy('updated_at', 'desc');
|
|
45
|
+
Logger.log(`[DEBUG] Found ${devices.length} registered devices for ${identityKey}`);
|
|
46
|
+
return res.status(200).json({
|
|
47
|
+
status: 'success',
|
|
48
|
+
devices: devices.map(device => ({
|
|
49
|
+
...device,
|
|
50
|
+
// Truncate FCM token for security (show only last 10 characters)
|
|
51
|
+
fcmToken: `...${device.fcmToken.slice(-10)}`
|
|
52
|
+
}))
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch (dbError) {
|
|
56
|
+
Logger.error('[ERROR] Database error during device listing:', dbError);
|
|
57
|
+
return res.status(500).json({
|
|
58
|
+
status: 'error',
|
|
59
|
+
code: 'ERR_DATABASE_ERROR',
|
|
60
|
+
description: 'Failed to retrieve devices.'
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
Logger.error('[ERROR] Internal Server Error in listDevices:', error);
|
|
66
|
+
return res.status(500).json({
|
|
67
|
+
status: 'error',
|
|
68
|
+
code: 'ERR_INTERNAL',
|
|
69
|
+
description: 'An internal error has occurred.'
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=listDevices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listDevices.js","sourceRoot":"","sources":["../../../src/routes/listDevices.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,mBAAmB,CAAA;AAC1C,OAAO,KAAK,OAAO,MAAM,MAAM,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAG3C,qDAAqD;AACrD,MAAM,EAAE,QAAQ,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC,GAAG,CAAA;AAEhD;;GAEG;AACH,MAAM,IAAI,GAAkB,OAAe,CAAC,OAAO,EAAE,CACnD,QAAQ,KAAK,YAAY,IAAI,QAAQ,KAAK,SAAS;IACjD,CAAC,CAAC,UAAU,CAAC,UAAU;IACvB,CAAC,CAAC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jB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;wBAC9B,GAAG,MAAM;wBACT,iEAAiE;wBACjE,QAAQ,EAAE,MAAM,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE;qBAC7C,CAAC,CAAC;iBACJ,CAAC,CAAA;YAEJ,CAAC;YAAC,OAAO,OAAY,EAAE,CAAC;gBACtB,MAAM,CAAC,KAAK,CAAC,+CAA+C,EAAE,OAAO,CAAC,CAAA;gBACtE,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBAC1B,MAAM,EAAE,OAAO;oBACf,IAAI,EAAE,oBAAoB;oBAC1B,WAAW,EAAE,6BAA6B;iBAC3C,CAAC,CAAA;YACJ,CAAC;QAEH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,+CAA+C,EAAE,KAAK,CAAC,CAAA;YACpE,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAC1B,MAAM,EAAE,OAAO;gBACf,IAAI,EAAE,cAAc;gBACpB,WAAW,EAAE,iCAAiC;aAC/C,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file listMessages.ts
|
|
3
|
+
* @description
|
|
4
|
+
* This route allows an authenticated user to retrieve messages from a specific named messageBox.
|
|
5
|
+
*
|
|
6
|
+
* Messages are only returned if the authenticated identity has access to the specified messageBox.
|
|
7
|
+
* If the messageBox does not exist, an empty message list is returned.
|
|
8
|
+
*
|
|
9
|
+
* Typical usage: Inbox or queue retrieval for real-time or deferred message delivery.
|
|
10
|
+
*/
|
|
11
|
+
import knexConfig from '../../knexfile.js';
|
|
12
|
+
import * as knexLib from 'knex';
|
|
13
|
+
// Load the appropriate Knex configuration based on the environment
|
|
14
|
+
const { NODE_ENV = 'development' } = process.env;
|
|
15
|
+
/**
|
|
16
|
+
* Knex instance connected based on environment (development, production, or staging).
|
|
17
|
+
*/
|
|
18
|
+
const knex = knexLib.default?.(NODE_ENV === 'production' || NODE_ENV === 'staging'
|
|
19
|
+
? knexConfig.production
|
|
20
|
+
: knexConfig.development) ?? knexLib(NODE_ENV === 'production' || NODE_ENV === 'staging'
|
|
21
|
+
? knexConfig.production
|
|
22
|
+
: knexConfig.development);
|
|
23
|
+
/**
|
|
24
|
+
* @openapi
|
|
25
|
+
* /listMessages:
|
|
26
|
+
* post:
|
|
27
|
+
* summary: Retrieve messages from a specific messageBox
|
|
28
|
+
* description: |
|
|
29
|
+
* Returns all stored messages for the specified messageBox that belong to the authenticated identity.
|
|
30
|
+
* If the box does not exist or has no messages, an empty array is returned.
|
|
31
|
+
* tags:
|
|
32
|
+
* - Message
|
|
33
|
+
* requestBody:
|
|
34
|
+
* required: true
|
|
35
|
+
* content:
|
|
36
|
+
* application/json:
|
|
37
|
+
* schema:
|
|
38
|
+
* type: object
|
|
39
|
+
* properties:
|
|
40
|
+
* messageBox:
|
|
41
|
+
* type: string
|
|
42
|
+
* description: The name of the messageBox to retrieve messages from
|
|
43
|
+
* responses:
|
|
44
|
+
* 200:
|
|
45
|
+
* description: Successfully retrieved messages (can be empty)
|
|
46
|
+
* content:
|
|
47
|
+
* application/json:
|
|
48
|
+
* schema:
|
|
49
|
+
* type: object
|
|
50
|
+
* properties:
|
|
51
|
+
* status:
|
|
52
|
+
* type: string
|
|
53
|
+
* example: success
|
|
54
|
+
* messages:
|
|
55
|
+
* type: array
|
|
56
|
+
* items:
|
|
57
|
+
* type: object
|
|
58
|
+
* properties:
|
|
59
|
+
* messageId:
|
|
60
|
+
* type: string
|
|
61
|
+
* body:
|
|
62
|
+
* type: string
|
|
63
|
+
* sender:
|
|
64
|
+
* type: string
|
|
65
|
+
* createdAt:
|
|
66
|
+
* type: string
|
|
67
|
+
* format: date-time
|
|
68
|
+
* updatedAt:
|
|
69
|
+
* type: string
|
|
70
|
+
* format: date-time
|
|
71
|
+
* 400:
|
|
72
|
+
* description: Invalid or missing messageBox name
|
|
73
|
+
* 500:
|
|
74
|
+
* description: Internal server/database error
|
|
75
|
+
*/
|
|
76
|
+
/**
|
|
77
|
+
* @exports
|
|
78
|
+
* Route definition used by the Express router to expose the `/listMessages` POST endpoint.
|
|
79
|
+
* Responsible for querying stored messages from a messageBox owned by the authenticated user.
|
|
80
|
+
*/
|
|
81
|
+
export default {
|
|
82
|
+
type: 'post',
|
|
83
|
+
path: '/listMessages',
|
|
84
|
+
knex,
|
|
85
|
+
summary: 'Use this route to list messages from your messageBox.',
|
|
86
|
+
parameters: {
|
|
87
|
+
messageBox: 'The name of the messageBox you would like to list messages from.'
|
|
88
|
+
},
|
|
89
|
+
exampleResponse: {
|
|
90
|
+
status: 'success',
|
|
91
|
+
messages: [
|
|
92
|
+
{
|
|
93
|
+
messageId: '3301',
|
|
94
|
+
body: '{}',
|
|
95
|
+
sender: '028d37b941208cd6b8a4c28288eda5f2f16c2b3ab0fcb6d13c18b47fe37b971fc1'
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* @function func
|
|
101
|
+
* @description
|
|
102
|
+
* Express handler for listing stored messages in a specified messageBox.
|
|
103
|
+
*
|
|
104
|
+
* Input:
|
|
105
|
+
* - `req.body.messageBox`: Name of the messageBox to retrieve messages from.
|
|
106
|
+
* - `req.auth.identityKey`: Authenticated user’s public identity key.
|
|
107
|
+
*
|
|
108
|
+
* Behavior:
|
|
109
|
+
* - Checks if the specified messageBox exists for the identity.
|
|
110
|
+
* - If found, returns all messages in that messageBox.
|
|
111
|
+
* - If not found, returns an empty array.
|
|
112
|
+
* - Normalizes all message bodies to strings for consistent output.
|
|
113
|
+
*
|
|
114
|
+
* Output:
|
|
115
|
+
* - 200 with `{ status: 'success', messages: [...] }`
|
|
116
|
+
* - 400 if input is missing or malformed.
|
|
117
|
+
* - 500 on internal server/database errors.
|
|
118
|
+
*
|
|
119
|
+
* @param {ListMessagesRequest} req - Authenticated request containing the messageBox name
|
|
120
|
+
* @param {Response} res - Express response object
|
|
121
|
+
* @returns {Promise<Response>} JSON response containing message records or an error
|
|
122
|
+
*/
|
|
123
|
+
func: async (req, res) => {
|
|
124
|
+
try {
|
|
125
|
+
const { messageBox } = req.body;
|
|
126
|
+
// Validate a messageBox is provided and is a string
|
|
127
|
+
if (messageBox == null || messageBox === '') {
|
|
128
|
+
return res.status(400).json({
|
|
129
|
+
status: 'error',
|
|
130
|
+
code: 'ERR_MESSAGEBOX_REQUIRED',
|
|
131
|
+
description: 'Please provide the name of a valid MessageBox!'
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (typeof messageBox !== 'string') {
|
|
135
|
+
return res.status(400).json({
|
|
136
|
+
status: 'error',
|
|
137
|
+
code: 'ERR_INVALID_MESSAGEBOX',
|
|
138
|
+
description: 'MessageBox name must be a string!'
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
// Find the messageBox ID for this user
|
|
142
|
+
const [messageBoxRecord] = await knex('messageBox')
|
|
143
|
+
.where({
|
|
144
|
+
identityKey: req.auth?.identityKey,
|
|
145
|
+
type: messageBox
|
|
146
|
+
})
|
|
147
|
+
.select('messageBoxId');
|
|
148
|
+
// Return empty array if no messageBox was found
|
|
149
|
+
if (messageBoxRecord === undefined) {
|
|
150
|
+
return res.status(200).json({
|
|
151
|
+
status: 'success',
|
|
152
|
+
messages: []
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
// Retrieve all messages associated with the messageBox
|
|
156
|
+
const messages = await knex('messages')
|
|
157
|
+
.where({
|
|
158
|
+
recipient: req.auth?.identityKey,
|
|
159
|
+
messageBoxId: messageBoxRecord.messageBoxId
|
|
160
|
+
})
|
|
161
|
+
.select('messageId', 'body', 'sender', 'created_at', 'updated_at');
|
|
162
|
+
// Normalize all message bodies to strings and convert to camelCase
|
|
163
|
+
const formattedMessages = messages.map(message => ({
|
|
164
|
+
messageId: message.messageId,
|
|
165
|
+
body: typeof message.body === 'string' ? message.body : JSON.stringify(message.body),
|
|
166
|
+
sender: message.sender,
|
|
167
|
+
createdAt: message.created_at,
|
|
168
|
+
updatedAt: message.updated_at
|
|
169
|
+
}));
|
|
170
|
+
// Return a list of matching messages
|
|
171
|
+
return res.status(200).json({
|
|
172
|
+
status: 'success',
|
|
173
|
+
messages: formattedMessages
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
console.error(e);
|
|
178
|
+
return res.status(500).json({
|
|
179
|
+
status: 'error',
|
|
180
|
+
code: 'ERR_INTERNAL_ERROR',
|
|
181
|
+
description: 'An internal error has occurred while listing messages.'
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=listMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listMessages.js","sourceRoot":"","sources":["../../../src/routes/listMessages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,UAAU,MAAM,mBAAmB,CAAA;AAC1C,OAAO,KAAK,OAAO,MAAM,MAAM,CAAA;AAG/B,mEAAmE;AACnE,MAAM,EAAE,QAAQ,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC,GAAG,CAAA;AAEhD;;GAEG;AACH,MAAM,IAAI,GAAkB,OAAe,CAAC,OAAO,EAAE,CACnD,QAAQ,KAAK,YAAY,IAAI,QAAQ,KAAK,SAAS;IACjD,CAAC,CAAC,UAAU,CAAC,UAAU;IACvB,CAAC,CAAC,UAAU,CAAC,WAAW,CAC3B,IAAK,OAAe,CACnB,QAAQ,KAAK,YAAY,IAAI,QAAQ,KAAK,SAAS;IACjD,CAAC,CAAC,UAAU,CAAC,UAAU;IACvB,CAAC,CAAC,UAAU,CAAC,WAAW,CAC3B,CAAA;AAWD;;;;;;;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,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAC1B,MAAM,EAAE,OAAO;gBACf,IAAI,EAAE,oBAAoB;gBAC1B,WAAW,EAAE,wDAAwD;aACtE,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { PublicKey } from '@bsv/sdk';
|
|
2
|
+
import { Logger } from '../../utils/logger.js';
|
|
3
|
+
import knexConfig from '../../../knexfile.js';
|
|
4
|
+
import * as knexLib from 'knex';
|
|
5
|
+
// Determine the environment (default to development)
|
|
6
|
+
const { NODE_ENV = 'development' } = process.env;
|
|
7
|
+
/**
|
|
8
|
+
* Knex instance connected based on environment (development, production, or staging).
|
|
9
|
+
*/
|
|
10
|
+
const knex = knexLib.default?.(NODE_ENV === 'production' || NODE_ENV === 'staging'
|
|
11
|
+
? knexConfig.production
|
|
12
|
+
: knexConfig.development) ?? knexLib(NODE_ENV === 'production' || NODE_ENV === 'staging'
|
|
13
|
+
? knexConfig.production
|
|
14
|
+
: knexConfig.development);
|
|
15
|
+
/**
|
|
16
|
+
* @swagger
|
|
17
|
+
* /permissions/get:
|
|
18
|
+
* get:
|
|
19
|
+
* summary: Get message permission for a sender/box combination
|
|
20
|
+
* description: Retrieve the permission setting for a specific sender and message box combination
|
|
21
|
+
* tags:
|
|
22
|
+
* - Permissions
|
|
23
|
+
* parameters:
|
|
24
|
+
* - in: query
|
|
25
|
+
* name: sender
|
|
26
|
+
* required: false
|
|
27
|
+
* schema:
|
|
28
|
+
* type: string
|
|
29
|
+
* description: identityKey of the sender to check (omit for box-wide default)
|
|
30
|
+
* - in: query
|
|
31
|
+
* name: messageBox
|
|
32
|
+
* required: true
|
|
33
|
+
* schema:
|
|
34
|
+
* type: string
|
|
35
|
+
* description: messageBox type to check
|
|
36
|
+
* responses:
|
|
37
|
+
* 200:
|
|
38
|
+
* description: Permission setting retrieved successfully (or undefined if not set)
|
|
39
|
+
* 400:
|
|
40
|
+
* description: Invalid request parameters
|
|
41
|
+
* 401:
|
|
42
|
+
* description: Authentication required
|
|
43
|
+
* 500:
|
|
44
|
+
* description: Internal server error
|
|
45
|
+
*/
|
|
46
|
+
export default {
|
|
47
|
+
type: 'get',
|
|
48
|
+
path: '/permissions/get',
|
|
49
|
+
func: async (req, res) => {
|
|
50
|
+
try {
|
|
51
|
+
Logger.log('[DEBUG] Processing get message permission request');
|
|
52
|
+
// Validate authentication
|
|
53
|
+
if (req.auth?.identityKey == null) {
|
|
54
|
+
Logger.log('[DEBUG] Authentication required for get permission');
|
|
55
|
+
return res.status(401).json({
|
|
56
|
+
status: 'error',
|
|
57
|
+
code: 'ERR_AUTHENTICATION_REQUIRED',
|
|
58
|
+
description: 'Authentication required.'
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const { sender, messageBox } = req.query;
|
|
62
|
+
// Validate required parameters
|
|
63
|
+
if (messageBox == null) {
|
|
64
|
+
Logger.log('[DEBUG] Missing required parameters for get permission');
|
|
65
|
+
return res.status(400).json({
|
|
66
|
+
status: 'error',
|
|
67
|
+
code: 'ERR_MISSING_PARAMETERS',
|
|
68
|
+
description: 'messageBox parameter is required.'
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
// Validate sender public key format if provided
|
|
72
|
+
if (sender != null) {
|
|
73
|
+
try {
|
|
74
|
+
PublicKey.fromString(sender);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
Logger.log('[DEBUG] Invalid sender public key format');
|
|
78
|
+
return res.status(400).json({
|
|
79
|
+
status: 'error',
|
|
80
|
+
code: 'ERR_INVALID_PUBLIC_KEY',
|
|
81
|
+
description: 'Invalid sender public key format.'
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const recipient = req.auth.identityKey;
|
|
86
|
+
// Get message permission directly from database
|
|
87
|
+
const whereClause = {
|
|
88
|
+
recipient,
|
|
89
|
+
message_box: messageBox
|
|
90
|
+
};
|
|
91
|
+
// Add sender condition (null for box-wide, specific sender for sender-specific)
|
|
92
|
+
if (sender != null) {
|
|
93
|
+
whereClause.sender = sender;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
whereClause.sender = null;
|
|
97
|
+
}
|
|
98
|
+
const permission = await knex('message_permissions')
|
|
99
|
+
.where(whereClause)
|
|
100
|
+
.select('recipient_fee', 'created_at', 'updated_at')
|
|
101
|
+
.first();
|
|
102
|
+
Logger.log(`[DEBUG] Permission record for ${sender ?? 'box-wide'} -> ${recipient} (${messageBox}): ${JSON.stringify(permission)}`);
|
|
103
|
+
if (permission != null) {
|
|
104
|
+
// Helper function to determine status from recipient fee
|
|
105
|
+
const getStatusFromFee = (fee) => {
|
|
106
|
+
if (fee === -1)
|
|
107
|
+
return 'blocked';
|
|
108
|
+
if (fee === 0)
|
|
109
|
+
return 'always_allow';
|
|
110
|
+
return 'payment_required';
|
|
111
|
+
};
|
|
112
|
+
// Permission is set, return it
|
|
113
|
+
return res.status(200).json({
|
|
114
|
+
status: 'success',
|
|
115
|
+
description: sender != null
|
|
116
|
+
? `Permission setting found for sender ${sender} to ${messageBox}.`
|
|
117
|
+
: `Box-wide permission setting found for ${messageBox}.`,
|
|
118
|
+
permission: {
|
|
119
|
+
sender: sender ?? null,
|
|
120
|
+
messageBox,
|
|
121
|
+
recipientFee: permission.recipient_fee,
|
|
122
|
+
status: getStatusFromFee(permission.recipient_fee),
|
|
123
|
+
createdAt: permission.created_at.toISOString(),
|
|
124
|
+
updatedAt: permission.updated_at.toISOString()
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// No permission set, return undefined
|
|
130
|
+
return res.status(200).json({
|
|
131
|
+
status: 'success',
|
|
132
|
+
description: sender != null
|
|
133
|
+
? `No permission setting found for sender ${sender} to ${messageBox}.`
|
|
134
|
+
: `No box-wide permission setting found for ${messageBox}.`,
|
|
135
|
+
permission: undefined
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
Logger.error('[ERROR] Internal Server Error in get permission:', error);
|
|
141
|
+
return res.status(500).json({
|
|
142
|
+
status: 'error',
|
|
143
|
+
code: 'ERR_INTERNAL',
|
|
144
|
+
description: 'An internal error has occurred.'
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=getPermission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPermission.js","sourceRoot":"","sources":["../../../../src/routes/permissions/getPermission.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAE9C,OAAO,UAAU,MAAM,sBAAsB,CAAA;AAC7C,OAAO,KAAK,OAAO,MAAM,MAAM,CAAA;AAE/B,qDAAqD;AACrD,MAAM,EAAE,QAAQ,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC,GAAG,CAAA;AAEhD;;GAEG;AACH,MAAM,IAAI,GAAkB,OAAe,CAAC,OAAO,EAAE,CACnD,QAAQ,KAAK,YAAY,IAAI,QAAQ,KAAK,SAAS;IACjD,CAAC,CAAC,UAAU,CAAC,UAAU;IACvB,CAAC,CAAC,UAAU,CAAC,WAAW,CAC3B,IAAK,OAAe,CACnB,QAAQ,KAAK,YAAY,IAAI,QAAQ,KAAK,SAAS;IACjD,CAAC,CAAC,UAAU,CAAC,UAAU;IACvB,CAAC,CAAC,UAAU,CAAC,WAAW,CAC3B,CAAA;AASD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAe;IACb,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE,KAAK,EAAE,GAAyB,EAAE,GAAa,EAAqB,EAAE;QAC1E,IAAI,CAAC;YACH,MAAM,CAAC,GAAG,CAAC,mDAAm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