testing-package-xdsfdsfsc 1.0.15 → 1.0.16
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.
|
@@ -3,26 +3,57 @@
|
|
|
3
3
|
* (e.g. Next.js: app/api/entitlement-check/route.ts)
|
|
4
4
|
*
|
|
5
5
|
* This runs on the server (Node), so we have crypto + os for deviceId.
|
|
6
|
-
* Reads xpack (host, projectId, apiKey) from the
|
|
6
|
+
* Reads xpack (host, projectId, apiKey) from the PAID PACKAGE's package.json
|
|
7
|
+
* inside node_modules (e.g. node_modules/testing-package-xdsfdsfsc/package.json).
|
|
8
|
+
* No need to duplicate xpack in the root project — copy-paste node_modules and
|
|
9
|
+
* this route and it works.
|
|
7
10
|
*/
|
|
8
11
|
|
|
9
12
|
import { createHash } from "crypto";
|
|
10
|
-
import { readFileSync } from "fs";
|
|
13
|
+
import { readFileSync, readdirSync, existsSync } from "fs";
|
|
11
14
|
import { hostname, platform } from "os";
|
|
12
15
|
import { join } from "path";
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
type Xpack = { host?: string; projectId?: string; apiKey?: string };
|
|
18
|
+
|
|
19
|
+
function getXpackFromNodeModules(): Xpack {
|
|
20
|
+
const nodeModules = join(process.cwd(), "node_modules");
|
|
21
|
+
if (!existsSync(nodeModules)) return {};
|
|
22
|
+
try {
|
|
23
|
+
const names = readdirSync(nodeModules, { withFileTypes: true });
|
|
24
|
+
for (const dirent of names) {
|
|
25
|
+
if (dirent.name.startsWith(".") || !dirent.isDirectory()) continue;
|
|
26
|
+
const pkgPath = join(nodeModules, dirent.name, "package.json");
|
|
27
|
+
try {
|
|
28
|
+
const raw = readFileSync(pkgPath, "utf-8");
|
|
29
|
+
const pkg = JSON.parse(raw) as { xpack?: Xpack };
|
|
30
|
+
if (pkg.xpack && (pkg.xpack.projectId || pkg.xpack.apiKey)) {
|
|
31
|
+
return pkg.xpack;
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
// skip invalid or missing package.json
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
// no node_modules or unreadable
|
|
39
|
+
}
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getXpack(): Xpack {
|
|
44
|
+
const fromModules = getXpackFromNodeModules();
|
|
45
|
+
if (fromModules.projectId || fromModules.apiKey) return fromModules;
|
|
46
|
+
// Fallback: root package.json (optional, for projects that still put xpack there)
|
|
15
47
|
try {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const pkg = JSON.parse(raw) as { xpack?: { host?: string; projectId?: string; apiKey?: string } };
|
|
48
|
+
const raw = readFileSync(join(process.cwd(), "package.json"), "utf-8");
|
|
49
|
+
const pkg = JSON.parse(raw) as { xpack?: Xpack };
|
|
19
50
|
return pkg.xpack ?? {};
|
|
20
51
|
} catch {
|
|
21
52
|
return {};
|
|
22
53
|
}
|
|
23
54
|
}
|
|
24
55
|
|
|
25
|
-
const xpack =
|
|
56
|
+
const xpack = getXpack();
|
|
26
57
|
const XPACK_HOST = xpack.host ?? "https://yourapp.com";
|
|
27
58
|
const XPACK_PROJECT_ID = xpack.projectId ?? "";
|
|
28
59
|
const XPACK_API_KEY = xpack.apiKey ?? "";
|