diffpx 0.0.3 → 0.0.4

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/bin/diffpx.js CHANGED
@@ -4,10 +4,7 @@ const {loadConfig} = require('../src/configLoader');
4
4
  const {runJob} = require('../src/runner');
5
5
 
6
6
  (async () => {
7
- const {config, devicesConfig, settings} = await loadConfig();
8
-
9
- const ppKey = process.env.PP_KEY;
10
- if (!ppKey) throw new Error('No API key found in .env or settings.yml');
7
+ const {config, devicesConfig, settings, diffpxKey, diffpxUrl} = await loadConfig();
11
8
 
12
9
  const timestamp = new Date().toISOString().replace('T', ' ').split('.')[0];
13
10
  const groupId = crypto.randomUUID();
@@ -15,14 +12,16 @@ const {runJob} = require('../src/runner');
15
12
  const payload = {
16
13
  timestamp,
17
14
  groupId,
18
- settings,
15
+ settings: {
16
+ ...settings
17
+ },
19
18
  devices: devicesConfig,
20
19
  snapshots: config
21
20
  };
22
21
 
23
22
  try {
24
23
  await runJob({
25
- ppKey,
24
+ diffpxKey,
26
25
  payload
27
26
  });
28
27
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diffpx",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "bin": {
5
5
  "diffpx": "bin/diffpx.js"
6
6
  },
@@ -3,9 +3,9 @@ const yaml = require('js-yaml');
3
3
  const validateConfig = require('./validateConfig');
4
4
 
5
5
  async function loadConfig() {
6
- const { config, devicesConfig } = await validateConfig();
7
- const settings = yaml.load(fs.readFileSync('settings.yml', 'utf8'));
8
- return { config, devicesConfig, settings };
6
+ const { config, devicesConfig, diffpxKey, diffpxUrl } = await validateConfig();
7
+ const settings = yaml.load(fs.readFileSync('settings.yml', 'utf8')) || {};
8
+ return { config, devicesConfig, settings, diffpxKey, diffpxUrl };
9
9
  }
10
10
 
11
11
  module.exports = { loadConfig };
package/src/runner.js CHANGED
@@ -45,7 +45,7 @@ function getProgress(status) {
45
45
  };
46
46
  }
47
47
 
48
- async function runJob({ppKey, payload}) {
48
+ async function runJob({diffpxKey, payload}) {
49
49
  const multiBar = new cliProgress.MultiBar({
50
50
  clearOnComplete: false,
51
51
  hideCursor: true,
@@ -72,14 +72,15 @@ async function runJob({ppKey, payload}) {
72
72
  let jobId = null;
73
73
 
74
74
  try {
75
- const res = await submitRun(ppKey, payload);
75
+ const diffpxUrl = process.env.DIFFPX_URL || '';
76
+ const res = await submitRun(diffpxUrl, diffpxKey, payload);
76
77
  jobId = res?.jobId || res?.id || res?.job_id || res?.data?.jobId || null;
77
78
  if (!jobId) {
78
79
  throw new Error('Server did not return a job id');
79
80
  }
80
81
 
81
- const finalStatus = await pollRun(ppKey, jobId, {
82
- intervalMs: Number(process.env.PP_POLL_INTERVAL_MS || 1000),
82
+ const finalStatus = await pollRun(diffpxUrl, diffpxKey, jobId, {
83
+ intervalMs: Number(process.env.DIFFPX_POLL_INTERVAL_MS || 1000),
83
84
  onStatus: (status) => {
84
85
  const p = getProgress(status);
85
86
 
package/src/upload.js CHANGED
@@ -1,8 +1,6 @@
1
1
  const axios = require('axios');
2
2
  require('dotenv').config({ path: require('path').join(process.cwd(), '.env') });
3
3
 
4
- const ppUrl = process.env.PP_URL || '';
5
-
6
4
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7
5
 
8
6
  function axiosErrorMessage(err) {
@@ -19,16 +17,16 @@ function axiosErrorMessage(err) {
19
17
  .join(' | ');
20
18
  }
21
19
 
22
- async function submitRun(ppKey, payload) {
23
- if (!ppUrl) {
24
- throw new Error('PP_URL not configured');
20
+ async function submitRun(diffpxUrl, diffpxKey, payload) {
21
+ if (!diffpxUrl) {
22
+ throw new Error('DIFFPX_URL not configured');
25
23
  }
26
24
 
27
25
  try {
28
- const res = await axios.post(`${ppUrl}/runs`, payload, {
26
+ const res = await axios.post(`${diffpxUrl}/runs`, payload, {
29
27
  headers: {
30
28
  'Content-Type': 'application/json',
31
- Authorization: `Bearer ${ppKey}`
29
+ Authorization: `Bearer ${diffpxKey}`
32
30
  },
33
31
  maxBodyLength: Infinity
34
32
  });
@@ -39,15 +37,15 @@ async function submitRun(ppKey, payload) {
39
37
  }
40
38
  }
41
39
 
42
- async function fetchJobStatus(ppKey, jobId) {
43
- if (!ppUrl) {
44
- throw new Error('PP_URL not configured');
40
+ async function fetchJobStatus(diffpxUrl, diffpxKey, jobId) {
41
+ if (!diffpxUrl) {
42
+ throw new Error('DIFFPX_URL not configured');
45
43
  }
46
44
 
47
45
  try {
48
- const res = await axios.get(`${ppUrl}/runs/${encodeURIComponent(jobId)}`, {
46
+ const res = await axios.get(`${diffpxUrl}/runs/${encodeURIComponent(jobId)}`, {
49
47
  headers: {
50
- Authorization: `Bearer ${ppKey}`
48
+ Authorization: `Bearer ${diffpxKey}`
51
49
  }
52
50
  });
53
51
 
@@ -57,9 +55,9 @@ async function fetchJobStatus(ppKey, jobId) {
57
55
  }
58
56
  }
59
57
 
60
- async function pollRun(ppKey, jobId, {intervalMs = 1000, onStatus} = {}) {
58
+ async function pollRun(diffpxUrl, diffpxKey, jobId, {intervalMs = 1000, onStatus} = {}) {
61
59
  for (;;) {
62
- const status = await fetchJobStatus(ppKey, jobId);
60
+ const status = await fetchJobStatus(diffpxUrl, diffpxKey, jobId);
63
61
  if (onStatus) onStatus(status);
64
62
 
65
63
  const state = String(status?.state || status?.status || '').toLowerCase();
@@ -5,12 +5,11 @@ require('dotenv').config({ path: require('path').join(process.cwd(), '.env') });
5
5
 
6
6
  async function validateConfig() {
7
7
  const errors = [];
8
+ const diffpxKey = process.env.DIFFPX_KEY;
9
+ const diffpxUrl = process.env.DIFFPX_URL;
8
10
 
9
- const ppKey = process.env.PP_KEY;
10
- const ppUrl = process.env.PP_URL;
11
-
12
- if (!ppKey) errors.push("🔴 Missing PP_KEY in .env");
13
- if (!ppUrl) errors.push("🔴 Missing PP_URL in .env");
11
+ if (!diffpxKey) errors.push("🔴 Missing DIFFPX_KEY (set in .env or CI vars)");
12
+ if (!diffpxUrl) errors.push("🔴 Missing DIFFPX_URL (set in .env or CI vars)");
14
13
 
15
14
  if (errors.length > 0) {
16
15
  console.error("🔴 Configuration check failed:");
@@ -19,14 +18,14 @@ async function validateConfig() {
19
18
  }
20
19
 
21
20
  try {
22
- await axios.get(`${ ppUrl }/auth/ping`, {
23
- headers: { Authorization: `Bearer ${ ppKey }` },
21
+ await axios.get(`${ diffpxUrl }/auth/ping`, {
22
+ headers: { Authorization: `Bearer ${ diffpxKey }` },
24
23
  timeout: 5000
25
24
  });
26
25
  } catch (err) {
27
26
  const msg = err.response?.data?.error || err.message;
28
27
  if (String(msg).includes("ECONNREFUSED") || String(msg).includes("ENOTFOUND")) {
29
- console.error("🔴 API validation failed: Connection to server failed. Make sure PP_URL in .env is correct");
28
+ console.error("🔴 API validation failed: Connection to server failed. Make sure DIFFPX_URL is correct");
30
29
  } else {
31
30
  console.error("🔴 API validation failed:", msg);
32
31
  }
@@ -66,7 +65,7 @@ async function validateConfig() {
66
65
  console.log("🟢 Configuration check passed.");
67
66
  }
68
67
 
69
- return { config, devicesConfig };
68
+ return { config, devicesConfig, diffpxKey, diffpxUrl };
70
69
  }
71
70
 
72
71
  module.exports = validateConfig;