@nodatachat/sdk 1.0.0 → 2.0.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/LICENSE.md +105 -0
- package/README.md +152 -253
- package/dist/chunk-4VSHBCCU.mjs +1 -0
- package/dist/index.d.mts +818 -130
- package/dist/index.d.ts +818 -130
- package/dist/index.js +1 -628
- package/dist/index.mjs +1 -8
- package/dist/plugins/express.d.mts +1 -1
- package/dist/plugins/express.d.ts +1 -1
- package/dist/plugins/express.js +1 -663
- package/dist/plugins/express.mjs +1 -43
- package/dist/plugins/fastify.d.mts +1 -1
- package/dist/plugins/fastify.d.ts +1 -1
- package/dist/plugins/fastify.js +1 -667
- package/dist/plugins/fastify.mjs +1 -47
- package/dist/{types-DQh0UmSr.d.mts → types-BQZ_zF32.d.mts} +132 -3
- package/dist/{types-DQh0UmSr.d.ts → types-BQZ_zF32.d.ts} +132 -3
- package/package.json +28 -22
- package/dist/chunk-V6GUTSNO.mjs +0 -601
package/dist/plugins/express.mjs
CHANGED
|
@@ -1,43 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
NoData
|
|
3
|
-
} from "../chunk-V6GUTSNO.mjs";
|
|
4
|
-
|
|
5
|
-
// src/plugins/express.ts
|
|
6
|
-
function nodataExpress(config) {
|
|
7
|
-
const nd = new NoData({ apiKey: config.apiKey, baseUrl: config.baseUrl });
|
|
8
|
-
const encryptFields = config.encryptFields || [];
|
|
9
|
-
const decryptFields = config.decryptFields || [];
|
|
10
|
-
const skipPaths = config.skipPaths || [];
|
|
11
|
-
return async (req, res, next) => {
|
|
12
|
-
if (skipPaths.some((p) => req.path.startsWith(p))) {
|
|
13
|
-
return next();
|
|
14
|
-
}
|
|
15
|
-
if (decryptFields.length > 0 && req.body && typeof req.body === "object" && req.method !== "GET") {
|
|
16
|
-
const shouldDecrypt = !config.decryptHeader || req.headers[config.decryptHeader.toLowerCase()];
|
|
17
|
-
if (shouldDecrypt) {
|
|
18
|
-
try {
|
|
19
|
-
req.body = await nd.decryptObject(
|
|
20
|
-
req.body,
|
|
21
|
-
decryptFields,
|
|
22
|
-
String(req.headers["x-requester"] || "express-plugin")
|
|
23
|
-
);
|
|
24
|
-
} catch {
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (encryptFields.length > 0) {
|
|
29
|
-
const originalJson = res.json.bind(res);
|
|
30
|
-
res.json = (body) => {
|
|
31
|
-
if (body && typeof body === "object") {
|
|
32
|
-
nd.encryptObject(body, encryptFields, config.context).then((encrypted) => originalJson(encrypted)).catch(() => originalJson(body));
|
|
33
|
-
} else {
|
|
34
|
-
return originalJson(body);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
next();
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export {
|
|
42
|
-
nodataExpress
|
|
43
|
-
};
|
|
1
|
+
import{n as a}from"../chunk-4VSHBCCU.mjs";function h(e){let r=new a({apiKey:e.apiKey,baseUrl:e.baseUrl}),p=e.encryptFields||[],d=e.decryptFields||[],c=e.skipPaths||[];return async(t,o,i)=>{if(c.some(n=>t.path.startsWith(n)))return i();if(d.length>0&&t.body&&typeof t.body=="object"&&t.method!=="GET"&&(!e.decryptHeader||t.headers[e.decryptHeader.toLowerCase()]))try{t.body=await r.decryptObject(t.body,d,String(t.headers["x-requester"]||"express-plugin"))}catch{}if(p.length>0){let n=o.json.bind(o);o.json=s=>{if(s&&typeof s=="object")r.encryptObject(s,p,e.context).then(u=>n(u)).catch(()=>n(s));else return n(s)}}i()}}export{h as nodataExpress};
|