@zi2/relay-sdk 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/server/fastify-plugin.d.ts +1 -0
- package/dist/server/fastify-plugin.js +17 -18
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -335,6 +335,7 @@ declare function createRelayError(key: keyof typeof RELAY_ERRORS): RelayError;
|
|
|
335
335
|
declare class AesGcmEncryption implements EncryptionAdapter {
|
|
336
336
|
private keyBuffer;
|
|
337
337
|
private allowPlaintextFallback;
|
|
338
|
+
private destroyed;
|
|
338
339
|
/**
|
|
339
340
|
* @param key 64-char hex string OR 32-byte Buffer for AES-256
|
|
340
341
|
* @param options.allowPlaintextFallback Allow decrypting legacy unencrypted values.
|
package/dist/index.js
CHANGED
|
@@ -953,6 +953,7 @@ var AUTH_TAG_HEX_LENGTH = AUTH_TAG_LENGTH * 2;
|
|
|
953
953
|
var AesGcmEncryption = class {
|
|
954
954
|
keyBuffer;
|
|
955
955
|
allowPlaintextFallback;
|
|
956
|
+
destroyed = false;
|
|
956
957
|
/**
|
|
957
958
|
* @param key 64-char hex string OR 32-byte Buffer for AES-256
|
|
958
959
|
* @param options.allowPlaintextFallback Allow decrypting legacy unencrypted values.
|
|
@@ -979,6 +980,7 @@ var AesGcmEncryption = class {
|
|
|
979
980
|
this.allowPlaintextFallback = options?.allowPlaintextFallback ?? false;
|
|
980
981
|
}
|
|
981
982
|
encrypt(plaintext) {
|
|
983
|
+
if (this.destroyed) throw new Error("Encryption instance has been destroyed");
|
|
982
984
|
const iv = crypto4.randomBytes(IV_LENGTH);
|
|
983
985
|
const cipher = crypto4.createCipheriv(ALGORITHM, this.keyBuffer, iv);
|
|
984
986
|
const encrypted = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
@@ -986,6 +988,7 @@ var AesGcmEncryption = class {
|
|
|
986
988
|
return `${iv.toString("hex")}:${authTag.toString("hex")}:${encrypted.toString("hex")}`;
|
|
987
989
|
}
|
|
988
990
|
decrypt(ciphertext) {
|
|
991
|
+
if (this.destroyed) throw new Error("Encryption instance has been destroyed");
|
|
989
992
|
const parts = ciphertext.split(":");
|
|
990
993
|
if (parts.length !== 3 || parts[0].length !== IV_HEX_LENGTH || parts[1].length !== AUTH_TAG_HEX_LENGTH) {
|
|
991
994
|
if (this.allowPlaintextFallback) {
|
|
@@ -1015,6 +1018,7 @@ var AesGcmEncryption = class {
|
|
|
1015
1018
|
*/
|
|
1016
1019
|
destroy() {
|
|
1017
1020
|
this.keyBuffer.fill(0);
|
|
1021
|
+
this.destroyed = true;
|
|
1018
1022
|
}
|
|
1019
1023
|
};
|
|
1020
1024
|
|
|
@@ -32,14 +32,14 @@ function createRouteHandlers(sdk) {
|
|
|
32
32
|
},
|
|
33
33
|
async completePairing(body) {
|
|
34
34
|
const parsed = completePairingSchema.parse(body);
|
|
35
|
-
const result = await sdk.completePairing(
|
|
36
|
-
parsed.pairingId,
|
|
37
|
-
parsed.pairingToken,
|
|
38
|
-
parsed.devicePublicKey,
|
|
39
|
-
parsed.deviceName,
|
|
40
|
-
parsed.platform,
|
|
41
|
-
parsed.phoneNumber
|
|
42
|
-
);
|
|
35
|
+
const result = await sdk.completePairing({
|
|
36
|
+
pairingId: parsed.pairingId,
|
|
37
|
+
pairingToken: parsed.pairingToken,
|
|
38
|
+
devicePublicKey: parsed.devicePublicKey,
|
|
39
|
+
deviceName: parsed.deviceName,
|
|
40
|
+
platform: parsed.platform,
|
|
41
|
+
phoneNumber: parsed.phoneNumber
|
|
42
|
+
});
|
|
43
43
|
return result;
|
|
44
44
|
},
|
|
45
45
|
async listRelays(orgId) {
|
|
@@ -61,7 +61,7 @@ function createRouteHandlers(sdk) {
|
|
|
61
61
|
async testSms(id, orgId, body) {
|
|
62
62
|
const parsed = testRelaySmsSchema.parse(body);
|
|
63
63
|
const testBody = parsed.body || "ZI2 Relay test message";
|
|
64
|
-
const result = await sdk.sendSMS(id, orgId, parsed.to, testBody);
|
|
64
|
+
const result = await sdk.sendSMS({ relayId: id, orgId, to: parsed.to, body: testBody });
|
|
65
65
|
return result;
|
|
66
66
|
},
|
|
67
67
|
async getMessages(id, orgId, query) {
|
|
@@ -75,40 +75,39 @@ function createRouteHandlers(sdk) {
|
|
|
75
75
|
// src/server/fastify-plugin.ts
|
|
76
76
|
async function relayPlugin(fastify, opts) {
|
|
77
77
|
const handlers = createRouteHandlers(opts.sdk);
|
|
78
|
-
|
|
79
|
-
fastify.post(`${prefix}/pair/initiate`, async (request, reply) => {
|
|
78
|
+
fastify.post("/pair/initiate", async (request, reply) => {
|
|
80
79
|
const result = await handlers.initiatePairing(request.orgId, request.userId);
|
|
81
80
|
reply.send({ success: true, data: result });
|
|
82
81
|
});
|
|
83
|
-
fastify.post(
|
|
82
|
+
fastify.post("/pair/complete", async (request, reply) => {
|
|
84
83
|
const result = await handlers.completePairing(request.body);
|
|
85
84
|
reply.send({ success: true, data: result });
|
|
86
85
|
});
|
|
87
|
-
fastify.get(
|
|
86
|
+
fastify.get("/", async (request, reply) => {
|
|
88
87
|
const relays = await handlers.listRelays(request.orgId);
|
|
89
88
|
reply.send({ success: true, data: relays });
|
|
90
89
|
});
|
|
91
|
-
fastify.get(
|
|
90
|
+
fastify.get("/:id", async (request, reply) => {
|
|
92
91
|
const { id } = request.params;
|
|
93
92
|
const relay = await handlers.getRelay(id, request.orgId);
|
|
94
93
|
reply.send({ success: true, data: relay });
|
|
95
94
|
});
|
|
96
|
-
fastify.patch(
|
|
95
|
+
fastify.patch("/:id", async (request, reply) => {
|
|
97
96
|
const { id } = request.params;
|
|
98
97
|
await handlers.updateRelay(id, request.orgId, request.body);
|
|
99
98
|
reply.send({ success: true });
|
|
100
99
|
});
|
|
101
|
-
fastify.delete(
|
|
100
|
+
fastify.delete("/:id", async (request, reply) => {
|
|
102
101
|
const { id } = request.params;
|
|
103
102
|
await handlers.revokeRelay(id, request.orgId);
|
|
104
103
|
reply.send({ success: true });
|
|
105
104
|
});
|
|
106
|
-
fastify.post(
|
|
105
|
+
fastify.post("/:id/test", async (request, reply) => {
|
|
107
106
|
const { id } = request.params;
|
|
108
107
|
const result = await handlers.testSms(id, request.orgId, request.body);
|
|
109
108
|
reply.send({ success: true, data: result });
|
|
110
109
|
});
|
|
111
|
-
fastify.get(
|
|
110
|
+
fastify.get("/:id/messages", async (request, reply) => {
|
|
112
111
|
const { id } = request.params;
|
|
113
112
|
const result = await handlers.getMessages(id, request.orgId, request.query);
|
|
114
113
|
reply.send({ success: true, data: result });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zi2/relay-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Enterprise SMS relay SDK with E2E encryption, provider fallback, and PCI DSS v4 compliance",
|
|
5
5
|
"author": "Zenith Intelligence Technologies <dev@zisquare.app>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|