testing-package-xdsfdsfsc 1.0.12 → 1.0.13
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.
Potentially problematic release.
This version of testing-package-xdsfdsfsc might be problematic. Click here for more details.
- package/index.js +55 -0
- package/package.json +6 -3
package/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: main entry for a paid package (CommonJS).
|
|
3
|
+
* Export a Promise that resolves to your API after the runtime check.
|
|
4
|
+
*
|
|
5
|
+
* Consumer usage:
|
|
6
|
+
* const api = await require("your-paid-package");
|
|
7
|
+
* api.hello();
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const crypto = require("crypto");
|
|
11
|
+
const os = require("os");
|
|
12
|
+
const pkg = require("./package.json");
|
|
13
|
+
const xpack = pkg.xpack || {};
|
|
14
|
+
|
|
15
|
+
async function assertEntitled() {
|
|
16
|
+
if (!xpack.projectId || !xpack.apiKey || !xpack.host) return;
|
|
17
|
+
const deviceId = crypto
|
|
18
|
+
.createHash("sha256")
|
|
19
|
+
.update(os.hostname() + "-" + os.platform())
|
|
20
|
+
.digest("hex");
|
|
21
|
+
const host = (xpack.host || "").replace(/\/+$/, "");
|
|
22
|
+
const res = await fetch(host + "/api/install/runtime-check", {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: { "Content-Type": "application/json" },
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
projectId: xpack.projectId,
|
|
27
|
+
apiKey: xpack.apiKey,
|
|
28
|
+
deviceId,
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
const { allowed } = await res.json();
|
|
32
|
+
if (!allowed) throw new Error("This device is not entitled. Pay at " + host);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const apiPromise = (async () => {
|
|
36
|
+
await assertEntitled();
|
|
37
|
+
// Your real API
|
|
38
|
+
return {
|
|
39
|
+
hello: () => "hi developer",
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
|
|
43
|
+
// When run directly (e.g. postinstall or `node index.js`), print greeting to terminal
|
|
44
|
+
if (require.main === module) {
|
|
45
|
+
apiPromise
|
|
46
|
+
.then((api) => {
|
|
47
|
+
console.log(api.hello());
|
|
48
|
+
})
|
|
49
|
+
.catch((err) => {
|
|
50
|
+
console.error(err.message);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = apiPromise;
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "testing-package-xdsfdsfsc",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
-
"install": "node ./preinstall.js"
|
|
8
|
+
"install": "node ./preinstall.js",
|
|
9
|
+
"postinstall": "node ./index.js",
|
|
10
|
+
"start": "node ./index.js"
|
|
9
11
|
},
|
|
10
12
|
"files": [
|
|
11
|
-
"preinstall.js"
|
|
13
|
+
"preinstall.js",
|
|
14
|
+
"index.js"
|
|
12
15
|
],
|
|
13
16
|
"author": "",
|
|
14
17
|
"license": "ISC",
|