testing-package-xdsfdsfsc 1.0.11 → 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.

Files changed (3) hide show
  1. package/index.js +55 -0
  2. package/package.json +11 -3
  3. package/preinstall.js +38 -28
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,18 +1,26 @@
1
1
  {
2
2
  "name": "testing-package-xdsfdsfsc",
3
- "version": "1.0.11",
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",
15
18
  "dependencies": {
16
19
  "dotenv": "^16.4.5"
20
+ },
21
+ "xpack": {
22
+ "projectId": "cml5jzoa000014zxeq5lelhpl",
23
+ "apiKey": "pay_135abcf0612547dca4ea432d89f0cdb7",
24
+ "host": "https://4098f1d48526.ngrok-free.app"
17
25
  }
18
26
  }
package/preinstall.js CHANGED
@@ -1,19 +1,13 @@
1
1
  const crypto = require("crypto");
2
+ const path = require("path");
2
3
  const { hostname, platform } = require("os");
3
4
 
4
- const apiKey = "pay_135abcf0612547dca4ea432d89f0cdb7";
5
- const projectId = "cml5jzoa000014zxeq5lelhpl";
6
- const apiHost = normalizeHost("https://4098f1d48526.ngrok-free.app");
7
- const docsUrl = "https://4098f1d48526.ngrok-free.app";
8
-
9
- function requireEnv() {
10
- if (!apiKey || !projectId) {
11
- console.error(
12
- "Missing PAYGATE_API_KEY or PAYGATE_PROJECT_ID. Add them to your .env.",
13
- );
14
- process.exit(1);
15
- }
16
- }
5
+ const pkg = require(path.join(__dirname, "package.json"));
6
+ const xpack = pkg.xpack || {};
7
+ const projectId = xpack.projectId;
8
+ const apiKey = xpack.apiKey;
9
+ const apiHost = normalizeHost(xpack.host);
10
+ const docsUrl = xpack.docsUrl;
17
11
 
18
12
  function deviceFingerprint() {
19
13
  const raw = `${hostname()}-${platform()}`;
@@ -21,8 +15,13 @@ function deviceFingerprint() {
21
15
  }
22
16
 
23
17
  async function startInstall() {
24
- requireEnv();
25
- const version = "0.0.0";
18
+ if (!projectId || !apiKey) {
19
+ console.error(
20
+ "Missing xpack config. Add xpack.projectId and xpack.apiKey to package.json.",
21
+ );
22
+ process.exit(1);
23
+ }
24
+ const version = pkg.version || "0.0.0";
26
25
  console.log(`Validating install against ${apiHost}.`);
27
26
  const response = await fetch(`${apiHost}/api/install/start`, {
28
27
  method: "POST",
@@ -36,7 +35,7 @@ async function startInstall() {
36
35
  });
37
36
 
38
37
  if (response.status === 200) {
39
- console.log("Install allowed by PayGate.");
38
+ console.log("Install allowed.");
40
39
  return;
41
40
  }
42
41
 
@@ -49,29 +48,40 @@ async function startInstall() {
49
48
  ? `${apiHost}/pay?session=${session}`
50
49
  : (docsUrl ?? "not provided");
51
50
 
52
- // ANSI: bright cyan + bold for URL highlight (works in most terminals)
53
- const HL = "\x1b[96m";
51
+ // ANSI colors (work in most terminals)
52
+ const R = "\x1b[0m";
54
53
  const BOLD = "\x1b[1m";
55
- const RESET = "\x1b[0m";
54
+ const DIM = "\x1b[2m";
55
+ const UNDERLINE = "\x1b[4m";
56
+ const GOLD = "\x1b[93m";
57
+ const GREEN = "\x1b[92m";
58
+ const CYAN = "\x1b[96m";
59
+ const MAGENTA = "\x1b[95m";
60
+ const BOX = "\x1b[90m";
61
+ const SEP = "▓▓".repeat(22);
56
62
 
57
63
  // Use stdout so npm shows this as notice/info, not "npm error"
58
64
  console.log("");
65
+ console.log(` ${BOX}${SEP}${R}`);
59
66
  console.log("");
67
+ console.log(` ${GOLD}${BOLD}💳 PAYMENT REQUIRED${R}`);
68
+ console.log(` ${DIM}Pay below to unlock this package.${R}`);
60
69
  console.log("");
61
- console.log(" ╔═══════════════════════════════════════════════════════════════╗");
62
- console.log(" ║ 💳 PAYMENT REQUIRED — pay below to unlock this package ║");
63
- console.log(" ╚═══════════════════════════════════════════════════════════════╝");
70
+ console.log(` ${BOX}${SEP}${R}`);
64
71
  console.log("");
65
- console.log(" PAY HERE copy or open this link in your browser:");
72
+ console.log(` ${GREEN}${BOLD}► PAY HERE${R} ${DIM} Open in browser or copy this link:${R}`);
66
73
  console.log("");
67
- console.log(" ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
68
- console.log(` ${HL}${BOLD}${payUrl}${RESET}`);
69
- console.log(" ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
74
+ console.log(` ${BOX}${SEP}${R}`);
70
75
  console.log("");
71
- console.log(" Price: " + String(price) + " · After payment, run: npm install");
76
+ console.log(` ${CYAN}${BOLD}${UNDERLINE}${payUrl}${R}`);
72
77
  console.log("");
78
+ console.log(` ${DIM}↑ Copy the full URL above (one line). If it wrapped, paste both parts together.${R}`);
73
79
  console.log("");
80
+ console.log(` ${BOX}${SEP}${R}`);
81
+ console.log(` ${MAGENTA}Price: ${String(price)}${R}`);
82
+ console.log(` After payment, run: ${BOLD}npm install${R}`);
74
83
  console.log("");
84
+ console.log(` ${BOX}${SEP}${R}`);
75
85
  console.log("");
76
86
  process.exit(1);
77
87
  }
@@ -82,7 +92,7 @@ async function startInstall() {
82
92
  }
83
93
 
84
94
  startInstall().catch((error) => {
85
- console.error("PayGate preinstall failed:", error);
95
+ console.error("preinstall failed:", error);
86
96
  process.exit(1);
87
97
  });
88
98