@phala/cloud 0.6.2 → 0.6.3

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/index.js CHANGED
@@ -969,7 +969,7 @@ function defaultUserAgent(runtime = globalThis) {
969
969
  if (runtime.window !== void 0 && runtime.document !== void 0) {
970
970
  return void 0;
971
971
  }
972
- const product = "phala-cloud-sdk-js/0.6.2";
972
+ const product = "phala-cloud-sdk-js/0.6.3";
973
973
  const token = runtimeToken(runtime);
974
974
  return token ? `${product} ${token}` : product;
975
975
  }
@@ -8085,7 +8085,7 @@ function logErrorHttpStatus(code) {
8085
8085
  }
8086
8086
  var LogAccessError = class extends ResourceError {
8087
8087
  constructor(options) {
8088
- const details = options.code ? `${options.code}: ${options.message}` : options.message;
8088
+ const details = options.message;
8089
8089
  const suggestionText = options.suggestions?.length ? `
8090
8090
  Suggestions:
8091
8091
  ${options.suggestions.map((suggestion) => `- ${suggestion}`).join("\n")}` : "";
@@ -8332,12 +8332,14 @@ function containerLogsDisabledError() {
8332
8332
  httpStatus: 409
8333
8333
  });
8334
8334
  }
8335
- async function getContainerLogEndpoint(client, id, containerName, matchContainerIdPrefix = true) {
8336
- const cvmId = resolveCvmId(id);
8337
- const info = await getCvmInfoLogs(client, cvmId);
8335
+ async function assertContainerLogsEnabled(client, id) {
8336
+ const info = await getCvmInfoLogs(client, resolveCvmId(id));
8338
8337
  if (info.public_logs === false) {
8339
8338
  throw containerLogsDisabledError();
8340
8339
  }
8340
+ }
8341
+ async function getContainerLogEndpoint(client, id, containerName, matchContainerIdPrefix = true) {
8342
+ const cvmId = resolveCvmId(id);
8341
8343
  const composition = await client.get(`/cvms/${cvmId}/composition`);
8342
8344
  if (!composition.containers?.length) {
8343
8345
  throw new Error(`No containers found for CVM '${cvmId}'`);
@@ -8437,6 +8439,9 @@ async function followLogRequests(resolveUrl, consume, signal, refreshCvm, trackE
8437
8439
  if (retryError instanceof LogAccessError && status === void 0) {
8438
8440
  throw retryError;
8439
8441
  }
8442
+ if (status === void 0 && !(retryError instanceof TypeError)) {
8443
+ throw retryError;
8444
+ }
8440
8445
  failureCount += 1;
8441
8446
  if (failureCount >= 5) throw retryError;
8442
8447
  const delayMs = Math.min(250 * 2 ** (failureCount - 1), 5e3);
@@ -8485,6 +8490,7 @@ async function streamCvmChannelLogs(client, id, channel, onData, options = {}, s
8485
8490
  }
8486
8491
  async function fetchContainerLogsEntries(client, id, options = {}) {
8487
8492
  const times = resolveLogTimeWindow(options.since, options.until);
8493
+ await assertContainerLogsEnabled(client, id);
8488
8494
  const baseUrl = await getContainerLogEndpoint(
8489
8495
  client,
8490
8496
  id,
@@ -8505,6 +8511,7 @@ async function fetchContainerLogsEntries(client, id, options = {}) {
8505
8511
  async function fetchContainerLogs(client, id, options = {}) {
8506
8512
  if (options.format === "text") {
8507
8513
  const times = resolveLogTimeWindow(options.since, options.until);
8514
+ await assertContainerLogsEnabled(client, id);
8508
8515
  const baseUrl = await getContainerLogEndpoint(
8509
8516
  client,
8510
8517
  id,
@@ -8533,6 +8540,7 @@ async function fetchContainerLogs(client, id, options = {}) {
8533
8540
  async function streamContainerLogsEntries(client, id, onEntry, options = {}, signal) {
8534
8541
  const abort = signal ?? options.signal;
8535
8542
  const times = resolveLogTimeWindow(options.since, options.until);
8543
+ await assertContainerLogsEnabled(client, id);
8536
8544
  const cursor = { since: times.since, boundaryCounts: /* @__PURE__ */ new Map() };
8537
8545
  let replayCounts = /* @__PURE__ */ new Map();
8538
8546
  let firstRequest = true;
@@ -8591,7 +8599,7 @@ async function streamContainerLogsEntries(client, id, onEntry, options = {}, sig
8591
8599
  },
8592
8600
  abort,
8593
8601
  async () => {
8594
- await getCvmInfoLogs(client, resolveCvmId(id));
8602
+ await assertContainerLogsEnabled(client, id);
8595
8603
  },
8596
8604
  true
8597
8605
  );
@@ -8637,6 +8645,7 @@ async function streamContainerLogs(client, id, onData, options = {}, signal) {
8637
8645
  if (options.format === "text") {
8638
8646
  const abort = signal ?? options.signal;
8639
8647
  const times = resolveLogTimeWindow(options.since, options.until);
8648
+ await assertContainerLogsEnabled(client, id);
8640
8649
  let firstRequest = true;
8641
8650
  await followLogRequests(
8642
8651
  async () => {
@@ -8660,7 +8669,7 @@ async function streamContainerLogs(client, id, onData, options = {}, signal) {
8660
8669
  (response) => streamContainerText(response, onData),
8661
8670
  abort,
8662
8671
  async () => {
8663
- await getCvmInfoLogs(client, resolveCvmId(id));
8672
+ await assertContainerLogsEnabled(client, id);
8664
8673
  },
8665
8674
  true
8666
8675
  );
package/dist/index.mjs CHANGED
@@ -440,7 +440,7 @@ function defaultUserAgent(runtime = globalThis) {
440
440
  if (runtime.window !== void 0 && runtime.document !== void 0) {
441
441
  return void 0;
442
442
  }
443
- const product = "phala-cloud-sdk-js/0.6.2";
443
+ const product = "phala-cloud-sdk-js/0.6.3";
444
444
  const token = runtimeToken(runtime);
445
445
  return token ? `${product} ${token}` : product;
446
446
  }
@@ -7588,7 +7588,7 @@ function logErrorHttpStatus(code) {
7588
7588
  }
7589
7589
  var LogAccessError = class extends ResourceError {
7590
7590
  constructor(options) {
7591
- const details = options.code ? `${options.code}: ${options.message}` : options.message;
7591
+ const details = options.message;
7592
7592
  const suggestionText = options.suggestions?.length ? `
7593
7593
  Suggestions:
7594
7594
  ${options.suggestions.map((suggestion) => `- ${suggestion}`).join("\n")}` : "";
@@ -7835,12 +7835,14 @@ function containerLogsDisabledError() {
7835
7835
  httpStatus: 409
7836
7836
  });
7837
7837
  }
7838
- async function getContainerLogEndpoint(client, id, containerName, matchContainerIdPrefix = true) {
7839
- const cvmId = resolveCvmId(id);
7840
- const info = await getCvmInfoLogs(client, cvmId);
7838
+ async function assertContainerLogsEnabled(client, id) {
7839
+ const info = await getCvmInfoLogs(client, resolveCvmId(id));
7841
7840
  if (info.public_logs === false) {
7842
7841
  throw containerLogsDisabledError();
7843
7842
  }
7843
+ }
7844
+ async function getContainerLogEndpoint(client, id, containerName, matchContainerIdPrefix = true) {
7845
+ const cvmId = resolveCvmId(id);
7844
7846
  const composition = await client.get(`/cvms/${cvmId}/composition`);
7845
7847
  if (!composition.containers?.length) {
7846
7848
  throw new Error(`No containers found for CVM '${cvmId}'`);
@@ -7940,6 +7942,9 @@ async function followLogRequests(resolveUrl, consume, signal, refreshCvm, trackE
7940
7942
  if (retryError instanceof LogAccessError && status === void 0) {
7941
7943
  throw retryError;
7942
7944
  }
7945
+ if (status === void 0 && !(retryError instanceof TypeError)) {
7946
+ throw retryError;
7947
+ }
7943
7948
  failureCount += 1;
7944
7949
  if (failureCount >= 5) throw retryError;
7945
7950
  const delayMs = Math.min(250 * 2 ** (failureCount - 1), 5e3);
@@ -7988,6 +7993,7 @@ async function streamCvmChannelLogs(client, id, channel, onData, options = {}, s
7988
7993
  }
7989
7994
  async function fetchContainerLogsEntries(client, id, options = {}) {
7990
7995
  const times = resolveLogTimeWindow(options.since, options.until);
7996
+ await assertContainerLogsEnabled(client, id);
7991
7997
  const baseUrl = await getContainerLogEndpoint(
7992
7998
  client,
7993
7999
  id,
@@ -8008,6 +8014,7 @@ async function fetchContainerLogsEntries(client, id, options = {}) {
8008
8014
  async function fetchContainerLogs(client, id, options = {}) {
8009
8015
  if (options.format === "text") {
8010
8016
  const times = resolveLogTimeWindow(options.since, options.until);
8017
+ await assertContainerLogsEnabled(client, id);
8011
8018
  const baseUrl = await getContainerLogEndpoint(
8012
8019
  client,
8013
8020
  id,
@@ -8036,6 +8043,7 @@ async function fetchContainerLogs(client, id, options = {}) {
8036
8043
  async function streamContainerLogsEntries(client, id, onEntry, options = {}, signal) {
8037
8044
  const abort = signal ?? options.signal;
8038
8045
  const times = resolveLogTimeWindow(options.since, options.until);
8046
+ await assertContainerLogsEnabled(client, id);
8039
8047
  const cursor = { since: times.since, boundaryCounts: /* @__PURE__ */ new Map() };
8040
8048
  let replayCounts = /* @__PURE__ */ new Map();
8041
8049
  let firstRequest = true;
@@ -8094,7 +8102,7 @@ async function streamContainerLogsEntries(client, id, onEntry, options = {}, sig
8094
8102
  },
8095
8103
  abort,
8096
8104
  async () => {
8097
- await getCvmInfoLogs(client, resolveCvmId(id));
8105
+ await assertContainerLogsEnabled(client, id);
8098
8106
  },
8099
8107
  true
8100
8108
  );
@@ -8140,6 +8148,7 @@ async function streamContainerLogs(client, id, onData, options = {}, signal) {
8140
8148
  if (options.format === "text") {
8141
8149
  const abort = signal ?? options.signal;
8142
8150
  const times = resolveLogTimeWindow(options.since, options.until);
8151
+ await assertContainerLogsEnabled(client, id);
8143
8152
  let firstRequest = true;
8144
8153
  await followLogRequests(
8145
8154
  async () => {
@@ -8163,7 +8172,7 @@ async function streamContainerLogs(client, id, onData, options = {}, signal) {
8163
8172
  (response) => streamContainerText(response, onData),
8164
8173
  abort,
8165
8174
  async () => {
8166
- await getCvmInfoLogs(client, resolveCvmId(id));
8175
+ await assertContainerLogsEnabled(client, id);
8167
8176
  },
8168
8177
  true
8169
8178
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phala/cloud",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "TypeScript SDK for Phala Cloud API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",