@authhero/cloudflare-adapter 2.32.4 → 2.32.5

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.
@@ -11484,12 +11484,19 @@ function xm(e) {
11484
11484
  get: async (t, n) => {
11485
11485
  let r = await e.customDomainAdapter.get(t, n);
11486
11486
  if (!r) throw new _(404);
11487
- let i = await vm(e).get(`/custom_hostnames/${encodeURIComponent(n)}`).json(), { result: a, errors: o, success: s } = _m.parse(i);
11488
- if (!s) throw new _(503, { message: JSON.stringify(o) });
11489
- if (e.enterprise && a.custom_metadata?.tenant_id !== t) throw new _(404);
11487
+ let i;
11488
+ try {
11489
+ i = await vm(e).get(`/custom_hostnames/${encodeURIComponent(n)}`).json();
11490
+ } catch (e) {
11491
+ throw new _(503, { message: `Failed to fetch custom hostname from Cloudflare: ${e instanceof Error ? e.message : String(e)}` });
11492
+ }
11493
+ let a = _m.safeParse(i);
11494
+ if (!a.success || !a.data.success) throw new _(503, { message: `Failed to parse custom hostname response: ${JSON.stringify(a.success ? a.data.errors : a.error.issues)}` });
11495
+ let { result: o } = a.data;
11496
+ if (e.enterprise && o.custom_metadata?.tenant_id !== t) throw new _(404);
11490
11497
  return bm({
11491
11498
  ...r,
11492
- ...a
11499
+ ...o
11493
11500
  });
11494
11501
  },
11495
11502
  getByDomain: async (t) => e.customDomainAdapter.getByDomain(t),
@@ -11518,17 +11525,25 @@ function xm(e) {
11518
11525
  update: async (t, n, r) => {
11519
11526
  let { sslOverrides: i } = ym(r.domain_metadata), a = {};
11520
11527
  if (Object.keys(i).length > 0) {
11521
- let t = await vm(e).get(`/custom_hostnames/${encodeURIComponent(n)}`).json(), { result: r, success: o } = _m.parse(t);
11522
- if (!o) throw new _(503, { message: "Failed to fetch current custom hostname state" });
11528
+ let t;
11529
+ try {
11530
+ t = await vm(e).get(`/custom_hostnames/${encodeURIComponent(n)}`).json();
11531
+ } catch (e) {
11532
+ throw new _(503, { message: `Failed to fetch current custom hostname state: ${e instanceof Error ? e.message : String(e)}` });
11533
+ }
11534
+ let r = _m.safeParse(t);
11535
+ if (!r.success || !r.data.success) throw new _(503, { message: `Failed to parse current custom hostname state: ${JSON.stringify(r.success ? r.data.errors : r.error.issues)}` });
11523
11536
  a.ssl = {
11524
- method: r.ssl.method,
11525
- type: r.ssl.type,
11526
- certificate_authority: r.ssl.certificate_authority,
11537
+ method: r.data.result.ssl.method,
11538
+ type: r.data.result.ssl.type,
11539
+ certificate_authority: r.data.result.ssl.certificate_authority,
11527
11540
  ...i
11528
11541
  };
11529
11542
  }
11530
11543
  if (Object.keys(a).length > 0) {
11531
- let t = await vm(e).patch(a, `/custom_hostnames/${encodeURIComponent(n)}`).res();
11544
+ let t = await vm(e).patch(a, `/custom_hostnames/${encodeURIComponent(n)}`).res().catch((e) => {
11545
+ throw new _(503, { message: `Failed to update custom hostname: ${e instanceof Error ? e.message : String(e)}` });
11546
+ });
11532
11547
  if (!t.ok) throw new _(503, { message: await t.text() });
11533
11548
  }
11534
11549
  return e.customDomainAdapter.update(t, n, r);