@terros-inc/cli 1.0.6 → 1.0.8

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.
@@ -0,0 +1,15 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import { dirname, join } from 'node:path';
3
+ import { platform, release } from 'node:os';
4
+ import { readFileSync } from 'node:fs';
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = dirname(__filename);
7
+ export function getAnalyticsHeaders() {
8
+ const packageJson = JSON.parse(readFileSync(join(__dirname, '../../package.json'), 'utf8'));
9
+ return {
10
+ 'Terros-Platform': platform(),
11
+ 'Terros-Platform-Version': release(),
12
+ 'Terros-Bundle-Identifier': 'com.terros.cli',
13
+ 'Terros-App-Version': packageJson.version,
14
+ };
15
+ }
package/dist/api/query.js CHANGED
@@ -1,9 +1,16 @@
1
+ import * as process from 'node:process';
1
2
  import { getAuthorizationHeader } from "./auth.js";
3
+ import { getAnalyticsHeaders } from "./analytics.js";
2
4
  export async function queryTerrosAPI(path, input) {
5
+ const endpoint = getApiEndpoint();
6
+ const impersonation = getImpersonationHeaders();
7
+ const analytics = getAnalyticsHeaders();
3
8
  const authorization = await getAuthorizationHeader();
4
- const res = await fetch(`https://api.terros.com${path}`, {
9
+ const res = await fetch(`${endpoint}${path}`, {
5
10
  method: 'POST',
6
11
  headers: {
12
+ ...analytics,
13
+ ...impersonation,
7
14
  Authorization: authorization,
8
15
  'Content-Type': 'application/json',
9
16
  },
@@ -11,3 +18,15 @@ export async function queryTerrosAPI(path, input) {
11
18
  });
12
19
  return (await res.json());
13
20
  }
21
+ function getApiEndpoint() {
22
+ const envEndpoint = process.env.TERROS_API_ENDPOINT;
23
+ if (envEndpoint)
24
+ return envEndpoint;
25
+ return 'https://api.terros.com';
26
+ }
27
+ function getImpersonationHeaders() {
28
+ const userId = process.env.TERROS_IMPERSONATE;
29
+ if (userId)
30
+ return { impersonate_user_id: userId };
31
+ return {};
32
+ }
package/package.json CHANGED
@@ -47,7 +47,7 @@
47
47
  "url": "git+https://github.com/terros-inc/cli.git"
48
48
  },
49
49
  "type": "module",
50
- "version": "1.0.6",
50
+ "version": "1.0.8",
51
51
  "scripts": {
52
52
  "fetch-openapi": "wget https://docs.terros.com/openapi/terros.yml",
53
53
  "build": "tsc",