@tuent/sentinel 0.1.0 → 0.1.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.
@@ -3,6 +3,34 @@ import { readFileSync, writeFileSync, unlinkSync, renameSync } from "fs";
3
3
  import { execSync } from "child_process";
4
4
  import { join } from "path";
5
5
  var PID_FILENAME = "sentinel-gateway.pid";
6
+ var TOKEN_FILENAME = "sentinel-gateway.token";
7
+ function releaseTokenPath(home) {
8
+ return join(home, ".dahlia", TOKEN_FILENAME);
9
+ }
10
+ function writeReleaseToken(home, token, port) {
11
+ const p = releaseTokenPath(home);
12
+ const tmp = p + `.tmp.${process.pid}`;
13
+ writeFileSync(tmp, JSON.stringify({ token, port }) + "\n", { mode: 384 });
14
+ renameSync(tmp, p);
15
+ }
16
+ function readReleaseToken(home) {
17
+ try {
18
+ const raw = readFileSync(releaseTokenPath(home), "utf-8").trim();
19
+ const j = JSON.parse(raw);
20
+ if (typeof j.token === "string" && j.token.length > 0 && typeof j.port === "number") {
21
+ return { token: j.token, port: j.port };
22
+ }
23
+ return null;
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
28
+ function removeReleaseToken(home) {
29
+ try {
30
+ unlinkSync(releaseTokenPath(home));
31
+ } catch {
32
+ }
33
+ }
6
34
  function readPidFile(home) {
7
35
  try {
8
36
  const raw = readFileSync(join(home, ".dahlia", PID_FILENAME), "utf-8").trim();
@@ -53,10 +81,14 @@ function acquireGatewayLock(home) {
53
81
  }
54
82
 
55
83
  export {
84
+ releaseTokenPath,
85
+ writeReleaseToken,
86
+ readReleaseToken,
87
+ removeReleaseToken,
56
88
  readPidFile,
57
89
  writePidFile,
58
90
  removePidFile,
59
91
  verifyPidIsGateway,
60
92
  acquireGatewayLock
61
93
  };
62
- //# sourceMappingURL=chunk-CUJKNIKT.js.map
94
+ //# sourceMappingURL=chunk-LATQNIRW.js.map