@solongate/proxy 0.26.2 → 0.26.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/dist/pull-push.js CHANGED
@@ -5,13 +5,15 @@ import { readFileSync as readFileSync2, writeFileSync, existsSync as existsSync2
5
5
  import { resolve as resolve2 } from "path";
6
6
 
7
7
  // src/config.ts
8
- import { readFileSync, existsSync, appendFileSync } from "fs";
8
+ import { readFileSync, existsSync } from "fs";
9
+ import { appendFile } from "fs/promises";
9
10
  import { resolve } from "path";
10
11
  async function fetchCloudPolicy(apiKey, apiUrl, policyId) {
11
12
  let resolvedId = policyId;
12
13
  if (!resolvedId) {
13
14
  const listRes = await fetch(`${apiUrl}/api/v1/policies`, {
14
- headers: { "Authorization": `Bearer ${apiKey}` }
15
+ headers: { "Authorization": `Bearer ${apiKey}` },
16
+ signal: AbortSignal.timeout(1e4)
15
17
  });
16
18
  if (!listRes.ok) {
17
19
  const body = await listRes.text().catch(() => "");
@@ -26,7 +28,8 @@ async function fetchCloudPolicy(apiKey, apiUrl, policyId) {
26
28
  }
27
29
  const url = `${apiUrl}/api/v1/policies/${resolvedId}`;
28
30
  const res = await fetch(url, {
29
- headers: { "Authorization": `Bearer ${apiKey}` }
31
+ headers: { "Authorization": `Bearer ${apiKey}` },
32
+ signal: AbortSignal.timeout(1e4)
30
33
  });
31
34
  if (!res.ok) {
32
35
  const body = await res.text().catch(() => "");
@@ -151,13 +154,13 @@ async function list(apiKey, policyId) {
151
154
  log(bold(` Policies (${policies.length})`));
152
155
  log(dim(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
153
156
  log("");
154
- for (const p of policies) {
155
- try {
156
- const full = await fetchCloudPolicy(apiKey, API_URL, p.id);
157
- printPolicySummary(p, full.rules);
158
- } catch {
159
- printPolicySummary(p, []);
160
- }
157
+ const fullPolicies = await Promise.all(
158
+ policies.map(
159
+ (p) => fetchCloudPolicy(apiKey, API_URL, p.id).then((full) => ({ policy: p, rules: full.rules })).catch(() => ({ policy: p, rules: [] }))
160
+ )
161
+ );
162
+ for (const { policy, rules } of fullPolicies) {
163
+ printPolicySummary(policy, rules);
161
164
  }
162
165
  log(dim(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
163
166
  log("");