@signalapp/mock-server
Advanced tools
Comparing version 6.4.0 to 6.4.1
{ | ||
"name": "@signalapp/mock-server", | ||
"version": "6.4.0", | ||
"version": "6.4.1", | ||
"description": "Mock Signal Server for writing tests", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -132,2 +132,3 @@ import z from 'zod'; | ||
}, "strip", z.ZodTypeAny, { | ||
content: string; | ||
type: number; | ||
@@ -140,8 +141,7 @@ destinationDeviceId: number & { | ||
}; | ||
}, { | ||
content: string; | ||
}, { | ||
type: number; | ||
destinationDeviceId: number; | ||
destinationRegistrationId: number; | ||
content: string; | ||
}>; | ||
@@ -156,2 +156,3 @@ export type Message = z.infer<typeof MessageSchema>; | ||
}, "strip", z.ZodTypeAny, { | ||
content: string; | ||
type: number; | ||
@@ -164,12 +165,13 @@ destinationDeviceId: number & { | ||
}; | ||
}, { | ||
content: string; | ||
}, { | ||
type: number; | ||
destinationDeviceId: number; | ||
destinationRegistrationId: number; | ||
content: string; | ||
}>, "many">; | ||
timestamp: z.ZodNumber; | ||
}, "strip", z.ZodTypeAny, { | ||
timestamp: number; | ||
messages: { | ||
content: string; | ||
type: number; | ||
@@ -182,13 +184,11 @@ destinationDeviceId: number & { | ||
}; | ||
content: string; | ||
}[]; | ||
}, { | ||
timestamp: number; | ||
}, { | ||
messages: { | ||
content: string; | ||
type: number; | ||
destinationDeviceId: number; | ||
destinationRegistrationId: number; | ||
content: string; | ||
}[]; | ||
timestamp: number; | ||
}>; | ||
@@ -195,0 +195,0 @@ export type MessageList = z.infer<typeof MessageListSchema>; |
@@ -11,3 +11,3 @@ "use strict"; | ||
const util_1 = require("../util"); | ||
exports.PositiveInt = zod_1.default.number().int().positive(); | ||
exports.PositiveInt = zod_1.default.coerce.number().int().nonnegative(); | ||
exports.AciSchema = zod_1.default.string().transform(x => x); | ||
@@ -14,0 +14,0 @@ exports.PniSchema = zod_1.default.string() |
@@ -307,3 +307,3 @@ "use strict"; | ||
// | ||
async function getGroupInner(req, res) { | ||
const getGroupV1 = (0, microrouter_1.get)('/v1/groups', async (req, res) => { | ||
const auth = await groupAuthAndFetch(req, res); | ||
@@ -314,20 +314,15 @@ if (!auth) { | ||
const { group } = auth; | ||
return { | ||
group: group.state, | ||
groupSendEndorsementResponse: group.getGroupSendEndorsementResponse(auth.aciCiphertext), | ||
}; | ||
} | ||
const getGroupV1 = (0, microrouter_1.get)('/v1/groups', async (req, res) => { | ||
const response = await getGroupInner(req, res); | ||
if (!response || !response.group) { | ||
return; | ||
} | ||
return (0, micro_1.send)(res, 200, compiled_1.signalservice.Group.encode(response.group).finish()); | ||
return (0, micro_1.send)(res, 200, compiled_1.signalservice.Group.encode(group.state).finish()); | ||
}); | ||
const getGroup = (0, microrouter_1.get)('/v2/groups', async (req, res) => { | ||
const response = await getGroupInner(req, res); | ||
if (!response || !response.group) { | ||
const auth = await groupAuthAndFetch(req, res); | ||
if (!auth) { | ||
return; | ||
} | ||
return (0, micro_1.send)(res, 200, compiled_1.signalservice.GroupResponse.encode(response).finish()); | ||
const { group } = auth; | ||
const groupSendEndorsementResponse = group.getGroupSendEndorsementResponse(auth.aciCiphertext); | ||
return (0, micro_1.send)(res, 200, compiled_1.signalservice.GroupResponse.encode({ | ||
group: group.state, | ||
groupSendEndorsementResponse, | ||
}).finish()); | ||
}); | ||
@@ -363,3 +358,23 @@ const getGroupVersion = (0, microrouter_1.get)('/v1/groups/joined_at_version', async (req, res) => { | ||
} | ||
const { groupChanges } = group.getChangesSince(since); | ||
return { | ||
auth, | ||
groupChanges: group.getChangesSince(since), | ||
}; | ||
} | ||
const getGroupLogsV1 = (0, microrouter_1.get)('/v1/groups/logs/:since', async (req, res) => { | ||
const result = await getGroupLogsInner(req, res); | ||
if (!result) { | ||
return; | ||
} | ||
return (0, micro_1.send)(res, 200, compiled_1.signalservice.GroupChanges.encode({ | ||
groupChanges: result.groupChanges.groupChanges, | ||
}).finish()); | ||
}); | ||
const getGroupLogs = (0, microrouter_1.get)('/v2/groups/logs/:since', async (req, res) => { | ||
const result = await getGroupLogsInner(req, res); | ||
if (!result) { | ||
return; | ||
} | ||
const { groupChanges: { groupChanges }, auth } = result; | ||
const { group } = auth; | ||
const expirationResult = schemas_1.PositiveInt.safeParse(req.headers['cached-send-endorsements']); | ||
@@ -373,3 +388,5 @@ if (!expirationResult.success) { | ||
const encodedActions = change.groupChange?.actions; | ||
(0, assert_1.default)(encodedActions, 'Missing actions in the group change'); | ||
if (!encodedActions) { | ||
return false; | ||
} | ||
const actions = compiled_1.signalservice.GroupChange.Actions.decode(encodedActions); | ||
@@ -385,23 +402,7 @@ return (actions.addMembers.length > 0 || | ||
} | ||
return { | ||
return (0, micro_1.send)(res, 200, compiled_1.signalservice.GroupChanges.encode({ | ||
groupChanges, | ||
groupSendEndorsementResponse, | ||
}; | ||
} | ||
const getGroupLogsV1 = (0, microrouter_1.get)('/v1/groups/logs/:since', async (req, res) => { | ||
const response = await getGroupLogsInner(req, res); | ||
if (!response) { | ||
return; | ||
} | ||
return (0, micro_1.send)(res, 200, compiled_1.signalservice.GroupChanges.encode({ | ||
groupChanges: response.groupChanges, | ||
}).finish()); | ||
}); | ||
const getGroupLogs = (0, microrouter_1.get)('/v2/groups/logs/:since', async (req, res) => { | ||
const response = await getGroupLogsInner(req, res); | ||
if (!response) { | ||
return; | ||
} | ||
return (0, micro_1.send)(res, 200, compiled_1.signalservice.GroupChanges.encode(response).finish()); | ||
}); | ||
async function createGroupInner(req, res) { | ||
@@ -421,10 +422,7 @@ const auth = await groupAuth(req, res); | ||
// TODO(indutny): verify that creator is a member | ||
return { | ||
group: group.state, | ||
groupSendEndorsementResponse: group.getGroupSendEndorsementResponse(auth.aciCiphertext), | ||
}; | ||
return { auth, group }; | ||
} | ||
const createGroupV1 = (0, microrouter_1.put)('/v1/groups', async (req, res) => { | ||
const response = await createGroupInner(req, res); | ||
if (!response) { | ||
const result = await createGroupInner(req, res); | ||
if (!result) { | ||
return; | ||
@@ -435,7 +433,12 @@ } | ||
const createGroup = (0, microrouter_1.put)('/v2/groups', async (req, res) => { | ||
const response = await createGroupInner(req, res); | ||
if (!response) { | ||
const result = await createGroupInner(req, res); | ||
if (!result) { | ||
return; | ||
} | ||
return (0, micro_1.send)(res, 200, compiled_1.signalservice.GroupResponse.encode(response).finish()); | ||
const { group, auth } = result; | ||
return (0, micro_1.send)(res, 200, compiled_1.signalservice.GroupResponse.encode({ | ||
group: group.state, | ||
groupSendEndorsementResponse: group | ||
.getGroupSendEndorsementResponse(auth.aciCiphertext), | ||
}).finish()); | ||
}); | ||
@@ -460,4 +463,4 @@ async function modifyGroupInner(req, res) { | ||
return { | ||
groupChange: modifyResult.signedChange, | ||
groupSendEndorsementResponse: group.getGroupSendEndorsementResponse(auth.aciCiphertext), | ||
auth, | ||
signedChange: modifyResult.signedChange, | ||
}; | ||
@@ -473,14 +476,21 @@ } | ||
const modifyGroupV1 = (0, microrouter_1.patch)('/v1/groups', async (req, res) => { | ||
const response = await modifyGroupInner(req, res); | ||
if (!response || !response.groupChange) { | ||
const result = await modifyGroupInner(req, res); | ||
if (!result) { | ||
return; | ||
} | ||
return (0, micro_1.send)(res, 200, compiled_1.signalservice.GroupChange.encode(response.groupChange).finish()); | ||
const { signedChange } = result; | ||
return (0, micro_1.send)(res, 200, compiled_1.signalservice.GroupChange.encode(signedChange).finish()); | ||
}); | ||
const modifyGroup = (0, microrouter_1.patch)('/v2/groups', async (req, res) => { | ||
const response = await modifyGroupInner(req, res); | ||
if (!response) { | ||
const result = await modifyGroupInner(req, res); | ||
if (!result) { | ||
return; | ||
} | ||
return (0, micro_1.send)(res, 200, compiled_1.signalservice.GroupChangeResponse.encode(response).finish()); | ||
const { signedChange, auth } = result; | ||
const { group, aciCiphertext } = auth; | ||
return (0, micro_1.send)(res, 200, compiled_1.signalservice.GroupChangeResponse.encode({ | ||
groupChange: signedChange, | ||
groupSendEndorsementResponse: group | ||
.getGroupSendEndorsementResponse(aciCiphertext), | ||
}).finish()); | ||
}); | ||
@@ -487,0 +497,0 @@ // |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3651293
67544