@pontive/server 1.26.0 → 1.28.0

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
@@ -1,172 +1,172 @@
1
- import { p as fe, w as we, k as me, i as ve } from "./client-BI4W1IJJ.js";
2
- import { h as yt, d as gt, e as Et, f as _t } from "./client-BI4W1IJJ.js";
3
- import { readKeylessRecord as Se, KeylessUnavailableError as te, claimLinkFor as ke, PontiveApiError as D, goneMessage as ne, ensureKeylessInstance as ye, loopbackCallbacks as ge, keylessMessage as Ee, KEYLESS_FILE as _e, ENV_FILE as Pe, KeylessInstanceGoneError as be } from "./keyless.js";
4
- import { v as Ie, s as re, u as Te, r as F, T as j, e as $, f as Re, p as Ue, g as Ce, h as Ae, i as Ne } from "./management-credential-CynS93TR.js";
5
- import { decodeJwt as $e, jwtDecrypt as Oe, EncryptJWT as Le } from "jose";
6
- const xe = 10080 * 60;
7
- function se(e) {
8
- const t = e.clientSecret ? "server" : "browser", n = ["issuer", "clientId"];
9
- t === "server" && n.push("sessionSecret");
10
- for (const s of n)
11
- if (!e[s]) {
12
- const c = { issuer: "PONTIVE_ISSUER", clientId: "PONTIVE_CLIENT_ID", sessionSecret: "PONTIVE_SESSION_SECRET" }[s];
13
- throw new Error(`@pontive/server: ${s} is required${c ? ` (pass it, or set ${c})` : ""}`);
1
+ import { p as se, w as fe, k as ke, i as Ee, h as ye } from "./client-DhAfqKrD.js";
2
+ import { j as Lt, d as Nt, e as xt, f as Gt } from "./client-DhAfqKrD.js";
3
+ import { readKeylessRecord as Se, KeylessUnavailableError as ne, claimLinkFor as ge, PontiveApiError as V, goneMessage as oe, ensureKeylessInstance as Te, loopbackCallbacks as be, keylessMessage as Pe, KEYLESS_FILE as $e, ENV_FILE as _e, KeylessInstanceGoneError as Ie } from "./keyless.js";
4
+ import { v as Oe, s as ie, u as Ce, r as K, T as z, e as L, f as Re, p as Ue, g as Ae, h as Le, i as Ne, m as xe } from "./management-credential-CynS93TR.js";
5
+ import { decodeJwt as Ge, jwtDecrypt as Me, EncryptJWT as je } from "jose";
6
+ const qe = 10080 * 60;
7
+ function ae(t) {
8
+ const e = t.clientSecret ? "server" : "browser", r = ["issuer", "clientId"];
9
+ e === "server" && r.push("sessionSecret");
10
+ for (const s of r)
11
+ if (!t[s]) {
12
+ const o = { issuer: "PONTIVE_ISSUER", clientId: "PONTIVE_CLIENT_ID", sessionSecret: "PONTIVE_SESSION_SECRET" }[s];
13
+ throw new Error(`@pontive/server: ${s} is required${o ? ` (pass it, or set ${o})` : ""}`);
14
14
  }
15
- if (t === "server" && e.sessionSecret.length < 32)
15
+ if (e === "server" && t.sessionSecret.length < 32)
16
16
  throw new Error("@pontive/server: sessionSecret must be at least 32 characters");
17
- if (e.baseUrl)
17
+ if (t.baseUrl)
18
18
  try {
19
- new URL(e.baseUrl);
19
+ new URL(t.baseUrl);
20
20
  } catch {
21
- throw new Error(`@pontive/server: baseUrl "${e.baseUrl}" is not an absolute URL`);
21
+ throw new Error(`@pontive/server: baseUrl "${t.baseUrl}" is not an absolute URL`);
22
22
  }
23
23
  return {
24
- mode: t,
25
- authPath: (e.authPath ?? "/__pontive").replace(/\/+$/, ""),
26
- issuer: e.issuer.replace(/\/+$/, ""),
27
- clientId: e.clientId,
28
- clientSecret: e.clientSecret || void 0,
29
- sessionSecret: e.sessionSecret ?? "",
30
- baseUrl: e.baseUrl ? new URL(e.baseUrl).origin : void 0,
31
- scopes: e.scopes ?? "openid email profile offline_access",
32
- basePath: (e.basePath ?? "/api/auth").replace(/\/+$/, ""),
33
- redirectUri: e.redirectUri,
34
- signInPath: e.signInPath ?? "/login",
35
- afterSignInPath: e.afterSignInPath ?? "/",
36
- prompt: e.prompt,
37
- cookieName: e.cookieName ?? "pontive_session",
38
- secureCookies: e.secureCookies,
39
- iframeSafe: e.iframeSafe ?? "auto",
40
- previewCallback: e.previewCallback ?? "auto",
41
- sessionMaxAgeSeconds: e.sessionMaxAgeSeconds ?? xe,
42
- refreshSkewSeconds: e.refreshSkewSeconds ?? 60,
43
- fetch: e.fetch ?? ((...s) => fetch(...s)),
44
- logger: e.logger ?? console
24
+ mode: e,
25
+ authPath: (t.authPath ?? "/__pontive").replace(/\/+$/, ""),
26
+ issuer: t.issuer.replace(/\/+$/, ""),
27
+ clientId: t.clientId,
28
+ clientSecret: t.clientSecret || void 0,
29
+ sessionSecret: t.sessionSecret ?? "",
30
+ baseUrl: t.baseUrl ? new URL(t.baseUrl).origin : void 0,
31
+ scopes: t.scopes ?? "openid email profile offline_access",
32
+ basePath: (t.basePath ?? "/api/auth").replace(/\/+$/, ""),
33
+ redirectUri: t.redirectUri,
34
+ signInPath: t.signInPath ?? "/login",
35
+ afterSignInPath: t.afterSignInPath ?? "/",
36
+ prompt: t.prompt,
37
+ cookieName: t.cookieName ?? "pontive_session",
38
+ secureCookies: t.secureCookies,
39
+ iframeSafe: t.iframeSafe ?? "auto",
40
+ previewCallback: t.previewCallback ?? "auto",
41
+ sessionMaxAgeSeconds: t.sessionMaxAgeSeconds ?? qe,
42
+ refreshSkewSeconds: t.refreshSkewSeconds ?? 60,
43
+ fetch: t.fetch ?? ((...s) => fetch(...s)),
44
+ logger: t.logger ?? console
45
45
  };
46
46
  }
47
- const x = 3500, V = 16;
48
- function T(e) {
49
- const t = /* @__PURE__ */ new Map();
50
- if (!e) return t;
51
- for (const n of e.split(";")) {
52
- const s = n.indexOf("=");
47
+ const G = 3500, q = 16;
48
+ function I(t) {
49
+ const e = /* @__PURE__ */ new Map();
50
+ if (!t) return e;
51
+ for (const r of t.split(";")) {
52
+ const s = r.indexOf("=");
53
53
  if (s < 0) continue;
54
- const c = n.slice(0, s).trim();
55
- !c || t.has(c) || t.set(c, n.slice(s + 1).trim());
54
+ const o = r.slice(0, s).trim();
55
+ !o || e.has(o) || e.set(o, r.slice(s + 1).trim());
56
56
  }
57
- return t;
57
+ return e;
58
58
  }
59
- function W(e) {
60
- return [...e].map(([t, n]) => `${t}=${n}`).join("; ");
59
+ function F(t) {
60
+ return [...t].map(([e, r]) => `${e}=${r}`).join("; ");
61
61
  }
62
- function C(e, t, n) {
63
- const s = n.sameSite ?? "Lax", c = [`${e}=${t}`, "Path=/", "HttpOnly", `SameSite=${s}`, `Max-Age=${n.maxAge}`];
64
- return (n.secure || s === "None") && c.push("Secure"), c.join("; ");
62
+ function R(t, e, r) {
63
+ const s = r.sameSite ?? "Lax", o = [`${t}=${e}`, "Path=/", "HttpOnly", `SameSite=${s}`, `Max-Age=${r.maxAge}`];
64
+ return (r.secure || s === "None") && o.push("Secure"), o.join("; ");
65
65
  }
66
- function U(e, t) {
67
- return t === 0 ? e : `${e}.${t}`;
66
+ function C(t, e) {
67
+ return e === 0 ? t : `${t}.${e}`;
68
68
  }
69
- function Me(e, t) {
70
- const n = e.get(t);
71
- if (n === void 0) return null;
72
- let s = n;
73
- for (let c = 1; c < V; c++) {
74
- const a = e.get(U(t, c));
75
- if (a === void 0) break;
76
- s += a;
69
+ function De(t, e) {
70
+ const r = t.get(e);
71
+ if (r === void 0) return null;
72
+ let s = r;
73
+ for (let o = 1; o < q; o++) {
74
+ const h = t.get(C(e, o));
75
+ if (h === void 0) break;
76
+ s += h;
77
77
  }
78
78
  return s;
79
79
  }
80
- function Ve(e, t, n, s) {
81
- const c = [], a = Math.max(1, Math.ceil(n.length / x));
82
- for (let i = 0; i < a; i++) {
83
- const l = n.slice(i * x, (i + 1) * x);
84
- e.set(U(t, i), l), c.push(C(U(t, i), l, s));
80
+ function He(t, e, r, s) {
81
+ const o = [], h = Math.max(1, Math.ceil(r.length / G));
82
+ for (let a = 0; a < h; a++) {
83
+ const p = r.slice(a * G, (a + 1) * G);
84
+ t.set(C(e, a), p), o.push(R(C(e, a), p, s));
85
85
  }
86
- for (let i = a; i < V; i++) {
87
- const l = U(t, i);
88
- if (!e.has(l)) break;
89
- e.delete(l), c.push(C(l, "", { ...s, maxAge: 0 }));
86
+ for (let a = h; a < q; a++) {
87
+ const p = C(e, a);
88
+ if (!t.has(p)) break;
89
+ t.delete(p), o.push(R(p, "", { ...s, maxAge: 0 }));
90
90
  }
91
- return c;
91
+ return o;
92
92
  }
93
- function G(e, t, n) {
93
+ function W(t, e, r) {
94
94
  const s = [];
95
- for (let c = 0; c < V; c++) {
96
- const a = U(t, c);
97
- if (!e.has(a)) {
98
- if (c > 0) break;
95
+ for (let o = 0; o < q; o++) {
96
+ const h = C(e, o);
97
+ if (!t.has(h)) {
98
+ if (o > 0) break;
99
99
  continue;
100
100
  }
101
- e.delete(a), s.push(C(a, "", { ...n, maxAge: 0 }));
101
+ t.delete(h), s.push(R(h, "", { ...r, maxAge: 0 }));
102
102
  }
103
103
  return s;
104
104
  }
105
- const H = "switch-organization", He = "organization_error", K = (e) => Array.isArray(e) ? e.filter((t) => typeof t == "string") : [];
106
- function oe(e) {
107
- const t = e.org_id;
108
- return typeof t != "string" || t === "" ? null : {
109
- id: t,
110
- roles: K(e.roles),
111
- permissions: K(e.permissions)
105
+ const D = "switch-organization", Ve = "organization_error", B = (t) => Array.isArray(t) ? t.filter((e) => typeof e == "string") : [];
106
+ function ce(t) {
107
+ const e = t.org_id;
108
+ return typeof e != "string" || e === "" ? null : {
109
+ id: e,
110
+ roles: B(t.roles),
111
+ permissions: B(t.permissions)
112
112
  };
113
113
  }
114
- function ze(e) {
114
+ function Ke(t) {
115
115
  try {
116
- return $e(e);
116
+ return Ge(t);
117
117
  } catch {
118
118
  return {};
119
119
  }
120
120
  }
121
- function mt(e, t, n = "/") {
122
- const s = new URLSearchParams({ organization_id: t, returnTo: n });
123
- return `${e}/${H}?${s.toString()}`;
121
+ function Ot(t, e, r = "/") {
122
+ const s = new URLSearchParams({ organization_id: e, returnTo: r });
123
+ return `${t}/${D}?${s.toString()}`;
124
124
  }
125
- const De = "__Host-pontive_access", Fe = "__Secure-pontive_session_state";
126
- function je(e) {
127
- const t = (n) => typeof e[n] == "string" ? e[n] : void 0;
125
+ const ze = "__Host-pontive_access", Fe = "__Secure-pontive_session_state";
126
+ function We(t) {
127
+ const e = (r) => typeof t[r] == "string" ? t[r] : void 0;
128
128
  return {
129
- id: t("sub") ?? "",
130
- email: t("email"),
131
- name: t("name") ?? t("email"),
132
- username: t("preferred_username"),
133
- picture: t("picture"),
134
- emailVerified: e.email_verified === !0
129
+ id: e("sub") ?? "",
130
+ email: e("email"),
131
+ name: e("name") ?? e("email"),
132
+ username: e("preferred_username"),
133
+ picture: e("picture"),
134
+ emailVerified: t.email_verified === !0
135
135
  };
136
136
  }
137
- function We(e) {
138
- const t = { issuer: e.issuer, clientId: e.clientId }, n = /* @__PURE__ */ new Map();
139
- function s(i) {
140
- for (const [l, d] of n)
141
- d.expiresAt <= i && n.delete(l);
142
- }
143
- async function c(i, l) {
144
- const d = Date.now();
145
- s(d);
146
- const u = await re(i), p = n.get(u);
147
- if (p) return p.profile;
148
- const m = Te(t, e.fetch, i).catch((S) => (n.delete(u), e.logger.warn("[pontive] could not read the user's profile:", S instanceof Error ? S.message : String(S)), null));
149
- return n.set(u, { expiresAt: l, profile: m }), m;
150
- }
151
- async function a(i) {
152
- const l = T(i).get(De);
153
- if (!l) return null;
154
- let d;
137
+ function Be(t) {
138
+ const e = { issuer: t.issuer, clientId: t.clientId }, r = /* @__PURE__ */ new Map();
139
+ function s(a) {
140
+ for (const [p, m] of r)
141
+ m.expiresAt <= a && r.delete(p);
142
+ }
143
+ async function o(a, p) {
144
+ const m = Date.now();
145
+ s(m);
146
+ const u = await ie(a), l = r.get(u);
147
+ if (l) return l.profile;
148
+ const f = Ce(e, t.fetch, a).catch((E) => (r.delete(u), t.logger.warn("[pontive] could not read the user's profile:", E instanceof Error ? E.message : String(E)), null));
149
+ return r.set(u, { expiresAt: p, profile: f }), f;
150
+ }
151
+ async function h(a) {
152
+ const p = I(a).get(ze);
153
+ if (!p) return null;
154
+ let m;
155
155
  try {
156
- d = await Ie(t, e.fetch, l);
157
- } catch (m) {
158
- return m.code !== "ERR_JWT_EXPIRED" && e.logger.warn("[pontive] access token cookie refused:", m instanceof Error ? m.message : String(m)), null;
156
+ m = await Oe(e, t.fetch, p);
157
+ } catch (f) {
158
+ return f.code !== "ERR_JWT_EXPIRED" && t.logger.warn("[pontive] access token cookie refused:", f instanceof Error ? f.message : String(f)), null;
159
159
  }
160
- const u = (d.exp ?? 0) * 1e3, p = await c(l, u);
160
+ const u = (m.exp ?? 0) * 1e3, l = await o(p, u);
161
161
  return {
162
162
  // The token's own claims win for sub: the profile describes the user the
163
163
  // token names, never another one.
164
- user: je({ ...p, ...d, sub: d.sub }),
165
- accessToken: l,
164
+ user: We({ ...l, ...m, sub: m.sub }),
165
+ accessToken: p,
166
166
  expiresAt: u,
167
- sessionId: typeof d.sid == "string" ? d.sid : void 0,
168
- organization: oe(d),
169
- claims: d
167
+ sessionId: typeof m.sid == "string" ? m.sid : void 0,
168
+ organization: ce(m),
169
+ claims: m
170
170
  };
171
171
  }
172
172
  return {
@@ -175,30 +175,30 @@ function We(e) {
175
175
  // the auth server's session handshake with the organization, which renews
176
176
  // its cookies into it — the browser stays the only thing that spends the
177
177
  // refresh token. A refused switch comes back with organization_error.
178
- async handle(i) {
179
- const l = new URL(i.url);
180
- if (l.pathname !== `${e.basePath}/${H}`) return null;
181
- const d = l.searchParams.get("organization_id"), u = Ge(l.searchParams.get("returnTo"));
182
- if (!d) return B(u);
183
- const p = new URL(`${e.authPath}/oauth2/session`, l.origin);
184
- return p.searchParams.set("client_id", e.clientId), p.searchParams.set("return_to", u), p.searchParams.set("organization_id", d), B(p.pathname + p.search);
178
+ async handle(a) {
179
+ const p = new URL(a.url);
180
+ if (p.pathname !== `${t.basePath}/${D}`) return null;
181
+ const m = p.searchParams.get("organization_id"), u = Je(p.searchParams.get("returnTo"));
182
+ if (!m) return J(u);
183
+ const l = new URL(`${t.authPath}/oauth2/session`, p.origin);
184
+ return l.searchParams.set("client_id", t.clientId), l.searchParams.set("return_to", u), l.searchParams.set("organization_id", m), J(l.pathname + l.search);
185
185
  },
186
- getSession: a,
187
- async refresh(i) {
188
- const l = i.headers.get("cookie"), d = await a(l), u = { session: d, setCookies: [], cookieHeader: l ?? "" };
189
- if (d || !T(l).has(Fe)) return u;
190
- const p = new URL(i.url), m = new URL(`${e.authPath}/oauth2/session`, p.origin);
191
- return m.searchParams.set("client_id", e.clientId), m.searchParams.set("return_to", p.pathname + p.search), { ...u, handshake: m.pathname + m.search };
186
+ getSession: h,
187
+ async refresh(a) {
188
+ const p = a.headers.get("cookie"), m = await h(p), u = { session: m, setCookies: [], cookieHeader: p ?? "" };
189
+ if (m || !I(p).has(Fe)) return u;
190
+ const l = new URL(a.url), f = new URL(`${t.authPath}/oauth2/session`, l.origin);
191
+ return f.searchParams.set("client_id", t.clientId), f.searchParams.set("return_to", l.pathname + l.search), { ...u, handshake: f.pathname + f.search };
192
192
  }
193
193
  };
194
194
  }
195
- function Ge(e) {
196
- return e && e.startsWith("/") && !e.startsWith("//") && !e.startsWith("/\\") ? e : "/";
195
+ function Je(t) {
196
+ return t && t.startsWith("/") && !t.startsWith("//") && !t.startsWith("/\\") ? t : "/";
197
197
  }
198
- function B(e) {
199
- return new Response(null, { status: 302, headers: { location: e, "cache-control": "no-store" } });
198
+ function J(t) {
199
+ return new Response(null, { status: 302, headers: { location: t, "cache-control": "no-store" } });
200
200
  }
201
- const Ke = [
201
+ const Ye = [
202
202
  "lovable.app",
203
203
  "lovableproject.com",
204
204
  "lovable.dev",
@@ -213,11 +213,11 @@ const Ke = [
213
213
  "bolt.host",
214
214
  "csb.app"
215
215
  ];
216
- function Be(e) {
217
- const t = e.toLowerCase().replace(/\.$/, "");
218
- return Ke.some((n) => t === n || t.endsWith(`.${n}`));
216
+ function Xe(t) {
217
+ const e = t.toLowerCase().replace(/\.$/, "");
218
+ return Ye.some((r) => e === r || e.endsWith(`.${r}`));
219
219
  }
220
- const Je = {
220
+ const Ze = {
221
221
  lovable: ["*.lovableproject.com", "*.lovable.app", "*.lovable.dev"],
222
222
  v0: ["*.vusercontent.net", "*.lite.vusercontent.net", "*.v0.app", "*.v0.dev"],
223
223
  vercel: ["*.vercel.app"],
@@ -229,443 +229,1375 @@ const Je = {
229
229
  "*.local-corp.webcontainer-api.io"
230
230
  ],
231
231
  codesandbox: ["*.csb.app"]
232
- }, Xe = "/oauth2/preview-callback", Ye = "pontive:authorization-response", Ze = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
233
- function Qe(e) {
234
- let t;
232
+ }, Qe = "/oauth2/preview-callback", et = "pontive:authorization-response", tt = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
233
+ function rt(t) {
234
+ let e;
235
235
  try {
236
- t = new URL(e);
236
+ e = new URL(t);
237
237
  } catch {
238
238
  return null;
239
239
  }
240
- if (t.protocol !== "https:" || t.port !== "" || t.origin !== e) return null;
241
- const n = t.hostname.split(".");
242
- for (const [s, c] of Object.entries(Je))
243
- for (const a of c) {
244
- const i = a.split(".");
245
- if (i.length === n.length && i.every((l, d) => l === "*" ? Ze.test(n[d]) : l === n[d]))
240
+ if (e.protocol !== "https:" || e.port !== "" || e.origin !== t) return null;
241
+ const r = e.hostname.split(".");
242
+ for (const [s, o] of Object.entries(Ze))
243
+ for (const h of o) {
244
+ const a = h.split(".");
245
+ if (a.length === r.length && a.every((p, m) => p === "*" ? tt.test(r[m]) : p === r[m]))
246
246
  return s;
247
247
  }
248
248
  return null;
249
249
  }
250
- function qe(e, t) {
251
- return `${e.replace(/\/$/, "")}${Xe}?origin=${encodeURIComponent(t)}`;
250
+ function st(t, e) {
251
+ return `${t.replace(/\/$/, "")}${Qe}?origin=${encodeURIComponent(e)}`;
252
252
  }
253
- const et = 3e4;
254
- class tt {
255
- constructor(t = et) {
256
- this.recentMs = t;
253
+ const nt = 3e4;
254
+ class ot {
255
+ constructor(e = nt) {
256
+ this.recentMs = e;
257
257
  }
258
258
  recentMs;
259
259
  inFlight = /* @__PURE__ */ new Map();
260
260
  recent = /* @__PURE__ */ new Map();
261
- async run(t, n) {
262
- const s = await re(t);
261
+ async run(e, r) {
262
+ const s = await ie(e);
263
263
  this.sweep();
264
- const c = this.recent.get(s);
265
- if (c) return c.result;
266
- let a = this.inFlight.get(s);
267
- return a || (a = n().then((i) => (this.recent.set(s, { at: Date.now(), result: i }), i)).finally(() => this.inFlight.delete(s)), this.inFlight.set(s, a)), a;
264
+ const o = this.recent.get(s);
265
+ if (o) return o.result;
266
+ let h = this.inFlight.get(s);
267
+ return h || (h = r().then((a) => (this.recent.set(s, { at: Date.now(), result: a }), a)).finally(() => this.inFlight.delete(s)), this.inFlight.set(s, h)), h;
268
268
  }
269
269
  sweep() {
270
- const t = Date.now() - this.recentMs;
271
- for (const [n, s] of this.recent)
272
- s.at < t && this.recent.delete(n);
270
+ const e = Date.now() - this.recentMs;
271
+ for (const [r, s] of this.recent)
272
+ s.at < e && this.recent.delete(r);
273
273
  }
274
274
  }
275
- const J = /* @__PURE__ */ new Map();
276
- function ie(e) {
277
- let t = J.get(e);
278
- return t || (t = crypto.subtle.digest("SHA-256", new TextEncoder().encode(e)).then((n) => new Uint8Array(n)), J.set(e, t)), t;
275
+ const Y = /* @__PURE__ */ new Map();
276
+ function he(t) {
277
+ let e = Y.get(t);
278
+ return e || (e = crypto.subtle.digest("SHA-256", new TextEncoder().encode(t)).then((r) => new Uint8Array(r)), Y.set(t, e)), e;
279
279
  }
280
- async function X(e, t, n) {
281
- return new Le(e).setProtectedHeader({ alg: "dir", enc: "A256GCM" }).setIssuedAt().setExpirationTime(`${n}s`).encrypt(await ie(t));
280
+ async function X(t, e, r) {
281
+ return new je(t).setProtectedHeader({ alg: "dir", enc: "A256GCM" }).setIssuedAt().setExpirationTime(`${r}s`).encrypt(await he(e));
282
282
  }
283
- async function Y(e, t) {
283
+ async function Z(t, e) {
284
284
  try {
285
- const { payload: n } = await Oe(e, await ie(t));
286
- return n;
285
+ const { payload: r } = await Me(t, await he(e));
286
+ return r;
287
287
  } catch {
288
288
  return null;
289
289
  }
290
290
  }
291
- const nt = 900, Z = 600;
292
- function Q(e, t) {
293
- return e && e.startsWith("/") && !e.startsWith("//") && !e.startsWith("/\\") ? e : t;
291
+ const it = 900, Q = 600;
292
+ function ee(t, e) {
293
+ return t && t.startsWith("/") && !t.startsWith("//") && !t.startsWith("/\\") ? t : e;
294
294
  }
295
- function b(e, t = []) {
296
- const n = new Headers({ location: e, "cache-control": "no-store" });
297
- for (const s of t) n.append("set-cookie", s);
298
- return new Response(null, { status: 302, headers: n });
295
+ function $(t, e = []) {
296
+ const r = new Headers({ location: t, "cache-control": "no-store" });
297
+ for (const s of e) r.append("set-cookie", s);
298
+ return new Response(null, { status: 302, headers: r });
299
299
  }
300
- const rt = "pontive:popup-complete";
301
- function st(e, t, n) {
302
- const c = `<!doctype html><meta charset="utf-8"><title>Signing in</title><script type="application/json" id="pontive-popup">${JSON.stringify({ message: { type: rt, url: e }, origin: t }).replace(/</g, "\\u003c")}<\/script><script>(function(){var d=JSON.parse(document.getElementById("pontive-popup").textContent);var go=function(){window.location.replace(d.message.url)};if(window.opener&&window.opener!==window){try{window.opener.postMessage(d.message,d.origin)}catch(e){}window.close();setTimeout(go,1000)}else{go()}})()<\/script>`, a = new Headers({
300
+ const at = "pontive:popup-complete";
301
+ function ct(t, e, r) {
302
+ const o = `<!doctype html><meta charset="utf-8"><title>Signing in</title><script type="application/json" id="pontive-popup">${JSON.stringify({ message: { type: at, url: t }, origin: e }).replace(/</g, "\\u003c")}<\/script><script>(function(){var d=JSON.parse(document.getElementById("pontive-popup").textContent);var go=function(){window.location.replace(d.message.url)};if(window.opener&&window.opener!==window){try{window.opener.postMessage(d.message,d.origin)}catch(e){}window.close();setTimeout(go,1000)}else{go()}})()<\/script>`, h = new Headers({
303
303
  "content-type": "text/html; charset=utf-8",
304
304
  "cache-control": "no-store",
305
305
  "content-security-policy": "default-src 'none'; script-src 'unsafe-inline'",
306
306
  "x-content-type-options": "nosniff"
307
307
  });
308
- for (const i of n) a.append("set-cookie", i);
309
- return new Response(c, { status: 200, headers: a });
308
+ for (const a of r) h.append("set-cookie", a);
309
+ return new Response(o, { status: 200, headers: h });
310
310
  }
311
- function ot(e) {
312
- const t = $(), s = `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Sign in</title><style>body{font-family:system-ui,sans-serif;margin:4rem auto;max-width:28rem;padding:0 1rem}</style><p>This preview signs in in a new window.</p><p><button id="go" type="button">Sign in</button></p><p id="status"></p><script type="application/json" id="pontive-preview-signin">${JSON.stringify({ ...e, type: Ye }).replace(/</g, "\\u003c")}<\/script><script nonce="${t}">(function(){var d=JSON.parse(document.getElementById("pontive-preview-signin").textContent);var s=document.getElementById("status");var w=null;window.addEventListener("message",function(e){if(!w||e.source!==w||e.origin!==d.authOrigin)return;var m=e.data;if(!m||m.type!==d.type||!m.response||typeof m.response!=="object")return;var u=new URL(d.callbackUrl);["code","state","iss","error","error_description","error_uri"].forEach(function(k){var v=m.response[k];if(typeof v==="string")u.searchParams.set(k,v)});try{w.close()}catch(x){}if(u.origin===location.origin)location.replace(u.toString())});document.getElementById("go").addEventListener("click",function(){w=window.open(d.popupUrl,"pontive_signin_popup","popup=yes,width=500,height=680");s.textContent=w?"Finish signing in in the new window.":"The sign-in window was blocked. Allow popups for this site and try again."})})()<\/script>`;
311
+ function ht(t) {
312
+ const e = L(), s = `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Sign in</title><style>body{font-family:system-ui,sans-serif;margin:4rem auto;max-width:28rem;padding:0 1rem}</style><p>This preview signs in in a new window.</p><p><button id="go" type="button">Sign in</button></p><p id="status"></p><script type="application/json" id="pontive-preview-signin">${JSON.stringify({ ...t, type: et }).replace(/</g, "\\u003c")}<\/script><script nonce="${e}">(function(){var d=JSON.parse(document.getElementById("pontive-preview-signin").textContent);var s=document.getElementById("status");var w=null;window.addEventListener("message",function(e){if(!w||e.source!==w||e.origin!==d.authOrigin)return;var m=e.data;if(!m||m.type!==d.type||!m.response||typeof m.response!=="object")return;var u=new URL(d.callbackUrl);["code","state","iss","error","error_description","error_uri"].forEach(function(k){var v=m.response[k];if(typeof v==="string")u.searchParams.set(k,v)});try{w.close()}catch(x){}if(u.origin===location.origin)location.replace(u.toString())});document.getElementById("go").addEventListener("click",function(){w=window.open(d.popupUrl,"pontive_signin_popup","popup=yes,width=500,height=680");s.textContent=w?"Finish signing in in the new window.":"The sign-in window was blocked. Allow popups for this site and try again."})})()<\/script>`;
313
313
  return new Response(s, {
314
314
  status: 200,
315
315
  headers: {
316
316
  "content-type": "text/html; charset=utf-8",
317
317
  "cache-control": "no-store",
318
- "content-security-policy": `default-src 'none'; script-src 'nonce-${t}'; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'`,
318
+ "content-security-policy": `default-src 'none'; script-src 'nonce-${e}'; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'`,
319
319
  "x-content-type-options": "nosniff",
320
320
  "referrer-policy": "no-referrer"
321
321
  }
322
322
  });
323
323
  }
324
- function _(e, t) {
325
- if (e.baseUrl) return e.baseUrl;
326
- const n = t.headers.get("x-forwarded-host")?.split(",")[0]?.trim() || t.headers.get("host")?.trim();
327
- if (n) {
328
- const s = t.headers.get("x-forwarded-proto")?.split(",")[0]?.trim() || new URL(t.url).protocol.replace(":", "");
324
+ function b(t, e) {
325
+ if (t.baseUrl) return t.baseUrl;
326
+ const r = e.headers.get("x-forwarded-host")?.split(",")[0]?.trim() || e.headers.get("host")?.trim();
327
+ if (r) {
328
+ const s = e.headers.get("x-forwarded-proto")?.split(",")[0]?.trim() || new URL(e.url).protocol.replace(":", "");
329
329
  try {
330
- return new URL(`${s}://${n}`).origin;
330
+ return new URL(`${s}://${r}`).origin;
331
331
  } catch {
332
332
  }
333
333
  }
334
- return new URL(t.url).origin;
334
+ return new URL(e.url).origin;
335
335
  }
336
- function it(e) {
337
- const t = (s) => typeof e[s] == "string" ? e[s] : void 0, n = t("name") ?? ([t("given_name"), t("family_name")].filter(Boolean).join(" ") || void 0) ?? t("email");
336
+ function pt(t) {
337
+ const e = (s) => typeof t[s] == "string" ? t[s] : void 0, r = e("name") ?? ([e("given_name"), e("family_name")].filter(Boolean).join(" ") || void 0) ?? e("email");
338
338
  return {
339
- id: e.sub ?? "",
340
- email: t("email"),
341
- name: n,
342
- username: t("preferred_username"),
343
- picture: t("picture"),
344
- emailVerified: e.email_verified === !0
339
+ id: t.sub ?? "",
340
+ email: e("email"),
341
+ name: r,
342
+ username: e("preferred_username"),
343
+ picture: e("picture"),
344
+ emailVerified: t.email_verified === !0
345
345
  };
346
346
  }
347
- function q(e) {
348
- return Date.now() + (e.expires_in ?? nt) * 1e3;
347
+ function te(t) {
348
+ return Date.now() + (t.expires_in ?? it) * 1e3;
349
349
  }
350
- function ae(e) {
351
- return e.mode === "browser" ? We(e) : at(e);
350
+ function pe(t) {
351
+ return t.mode === "browser" ? Be(t) : ut(t);
352
352
  }
353
- function at(e) {
354
- const t = { issuer: e.issuer, clientId: e.clientId, clientSecret: e.clientSecret }, n = `${e.cookieName}_tx`, s = new tt(), c = (r) => e.secureCookies ?? _(e, r).startsWith("https:"), a = (r) => e.iframeSafe === !0 || e.iframeSafe === "auto" && Be(new URL(_(e, r)).hostname), i = (r, o) => a(r) ? { maxAge: o, secure: !0, sameSite: "None" } : { maxAge: o, secure: c(r) }, l = (r) => e.previewCallback === "always" || e.previewCallback === "auto" && Qe(_(e, r)) !== null, d = (r) => `${_(e, r)}${e.basePath}/callback`, u = (r) => l(r) ? qe(e.issuer, _(e, r)) : e.redirectUri ?? d(r), p = (r, o) => {
355
- const h = new URL(e.signInPath, _(e, r));
356
- return o && h.searchParams.set("error", o), h.toString();
353
+ function ut(t) {
354
+ const e = { issuer: t.issuer, clientId: t.clientId, clientSecret: t.clientSecret }, r = `${t.cookieName}_tx`, s = new ot(), o = (i) => t.secureCookies ?? b(t, i).startsWith("https:"), h = (i) => t.iframeSafe === !0 || t.iframeSafe === "auto" && Xe(new URL(b(t, i)).hostname), a = (i, c) => h(i) ? { maxAge: c, secure: !0, sameSite: "None" } : { maxAge: c, secure: o(i) }, p = (i) => t.previewCallback === "always" || t.previewCallback === "auto" && rt(b(t, i)) !== null, m = (i) => `${b(t, i)}${t.basePath}/callback`, u = (i) => p(i) ? st(t.issuer, b(t, i)) : t.redirectUri ?? m(i), l = (i, c) => {
355
+ const d = new URL(t.signInPath, b(t, i));
356
+ return c && d.searchParams.set("error", c), d.toString();
357
357
  };
358
- async function m(r) {
359
- const o = Me(r, e.cookieName);
360
- if (o === null) return null;
361
- const h = await Y(o, e.sessionSecret);
362
- return h || e.logger.warn("[pontive] session cookie could not be read (sealed with another secret, or truncated)"), h;
363
- }
364
- async function S(r, o, h) {
365
- const f = await X({ ...o }, e.sessionSecret, e.sessionMaxAgeSeconds);
366
- return Ve(r, e.cookieName, f, i(h, e.sessionMaxAgeSeconds));
367
- }
368
- function P(r) {
369
- const { refreshToken: o, ...h } = r, f = ze(r.accessToken);
370
- return { ...h, organization: oe(f), claims: f };
371
- }
372
- async function R(r) {
373
- const o = new URL(r.url), h = l(r), f = o.searchParams.get("popup") === "1";
374
- if (h && !f) {
375
- const v = new URL(`${e.basePath}/login`, _(e, r));
376
- return o.searchParams.forEach((y, I) => v.searchParams.set(I, y)), v.searchParams.set("popup", "1"), ot({
377
- popupUrl: v.toString(),
378
- authOrigin: new URL(e.issuer).origin,
379
- callbackUrl: d(r)
358
+ async function f(i) {
359
+ const c = De(i, t.cookieName);
360
+ if (c === null) return null;
361
+ const d = await Z(c, t.sessionSecret);
362
+ return d || t.logger.warn("[pontive] session cookie could not be read (sealed with another secret, or truncated)"), d;
363
+ }
364
+ async function E(i, c, d) {
365
+ const w = await X({ ...c }, t.sessionSecret, t.sessionMaxAgeSeconds);
366
+ return He(i, t.cookieName, w, a(d, t.sessionMaxAgeSeconds));
367
+ }
368
+ function P(i) {
369
+ const { refreshToken: c, ...d } = i, w = Ke(i.accessToken);
370
+ return { ...d, organization: ce(w), claims: w };
371
+ }
372
+ async function O(i) {
373
+ const c = new URL(i.url), d = p(i), w = c.searchParams.get("popup") === "1";
374
+ if (d && !w) {
375
+ const k = new URL(`${t.basePath}/login`, b(t, i));
376
+ return c.searchParams.forEach((S, _) => k.searchParams.set(_, S)), k.searchParams.set("popup", "1"), ht({
377
+ popupUrl: k.toString(),
378
+ authOrigin: new URL(t.issuer).origin,
379
+ callbackUrl: m(i)
380
380
  });
381
381
  }
382
- const k = {
383
- state: $(),
384
- verifier: $(),
385
- nonce: $(),
386
- returnTo: Q(o.searchParams.get("returnTo") ?? o.searchParams.get("next"), e.afterSignInPath),
387
- popup: f,
388
- redirectUri: u(r),
389
- previewCallback: h
390
- }, w = await Re(t, e.fetch, {
391
- redirectUri: k.redirectUri,
392
- scopes: e.scopes,
393
- state: k.state,
394
- nonce: k.nonce,
395
- codeChallenge: await Ue(k.verifier),
396
- prompt: e.prompt,
382
+ const y = {
383
+ state: L(),
384
+ verifier: L(),
385
+ nonce: L(),
386
+ returnTo: ee(c.searchParams.get("returnTo") ?? c.searchParams.get("next"), t.afterSignInPath),
387
+ popup: w,
388
+ redirectUri: u(i),
389
+ previewCallback: d
390
+ }, v = await Re(e, t.fetch, {
391
+ redirectUri: y.redirectUri,
392
+ scopes: t.scopes,
393
+ state: y.state,
394
+ nonce: y.nonce,
395
+ codeChallenge: await Ue(y.verifier),
396
+ prompt: t.prompt,
397
397
  // The organization the app wants this sign-in to start in; the user is
398
398
  // never asked to pick one.
399
- organizationId: o.searchParams.get("organization_id") ?? void 0,
399
+ organizationId: c.searchParams.get("organization_id") ?? void 0,
400
400
  // Pre-fills the sign-in page with the address the user is expected to
401
401
  // sign in with — an accepted invitation sends its invitee here with it.
402
- loginHint: o.searchParams.get("login_hint") ?? void 0
403
- }), E = await X({ ...k }, e.sessionSecret, Z);
404
- return b(w, [C(n, E, i(r, Z))]);
405
- }
406
- async function A(r) {
407
- const o = new URL(r.url), h = T(r.headers.get("cookie")), f = [C(n, "", i(r, 0))], k = h.get(n), w = k ? await Y(k, e.sessionSecret) : null, E = o.searchParams.get("code"), v = (g) => w?.popup && !w.previewCallback ? st(g, _(e, r), f) : b(g, f), y = o.searchParams.get("error");
408
- if (y) return v(p(r, y));
409
- if (!w || !E || o.searchParams.get("state") !== w.state)
410
- return v(p(r, "invalid_state"));
411
- const I = o.searchParams.get("iss");
412
- if (w.previewCallback && I !== null && I !== e.issuer)
413
- return v(p(r, "invalid_issuer"));
402
+ loginHint: c.searchParams.get("login_hint") ?? void 0
403
+ }), T = await X({ ...y }, t.sessionSecret, Q);
404
+ return $(v, [R(r, T, a(i, Q))]);
405
+ }
406
+ async function U(i) {
407
+ const c = new URL(i.url), d = I(i.headers.get("cookie")), w = [R(r, "", a(i, 0))], y = d.get(r), v = y ? await Z(y, t.sessionSecret) : null, T = c.searchParams.get("code"), k = (g) => v?.popup && !v.previewCallback ? ct(g, b(t, i), w) : $(g, w), S = c.searchParams.get("error");
408
+ if (S) return k(l(i, S));
409
+ if (!v || !T || c.searchParams.get("state") !== v.state)
410
+ return k(l(i, "invalid_state"));
411
+ const _ = c.searchParams.get("iss");
412
+ if (v.previewCallback && _ !== null && _ !== t.issuer)
413
+ return k(l(i, "invalid_issuer"));
414
414
  try {
415
- const g = await Ce(t, e.fetch, {
416
- code: E,
417
- codeVerifier: w.verifier,
415
+ const g = await Ae(e, t.fetch, {
416
+ code: T,
417
+ codeVerifier: v.verifier,
418
418
  // Exactly as the authorization request named it.
419
- redirectUri: w.redirectUri ?? u(r)
419
+ redirectUri: v.redirectUri ?? u(i)
420
420
  });
421
421
  if (!g.id_token) throw new Error("the token response carried no id_token; is the openid scope requested?");
422
- const L = await Ae(t, e.fetch, g.id_token, w.nonce), de = {
423
- user: it(L),
422
+ const x = await Le(e, t.fetch, g.id_token, v.nonce), ve = {
423
+ user: pt(x),
424
424
  accessToken: g.access_token,
425
425
  refreshToken: g.refresh_token,
426
- expiresAt: q(g),
427
- sessionId: typeof L.sid == "string" ? L.sid : void 0
426
+ expiresAt: te(g),
427
+ sessionId: typeof x.sid == "string" ? x.sid : void 0
428
428
  };
429
- f.push(...await S(h, de, r));
429
+ w.push(...await E(d, ve, i));
430
430
  } catch (g) {
431
- return e.logger.warn("[pontive] sign-in failed:", g instanceof Error ? g.message : String(g)), v(p(r, "exchange_failed"));
431
+ return t.logger.warn("[pontive] sign-in failed:", g instanceof Error ? g.message : String(g)), k(l(i, "exchange_failed"));
432
432
  }
433
- return v(new URL(w.returnTo, _(e, r)).toString());
433
+ return k(new URL(v.returnTo, b(t, i)).toString());
434
434
  }
435
- async function N(r) {
436
- const o = T(r.headers.get("cookie")), h = await m(o), f = G(o, e.cookieName, i(r, 0));
437
- let k = p(r);
435
+ async function A(i) {
436
+ const c = I(i.headers.get("cookie")), d = await f(c), w = W(c, t.cookieName, a(i, 0));
437
+ let y = l(i);
438
438
  try {
439
- k = await Ne(t, e.fetch, {
440
- postLogoutRedirectUri: p(r),
441
- sessionId: h?.sessionId
442
- }) ?? k;
443
- } catch (w) {
444
- e.logger.warn("[pontive] could not reach the issuer to end its session:", w instanceof Error ? w.message : String(w));
439
+ y = await Ne(e, t.fetch, {
440
+ postLogoutRedirectUri: l(i),
441
+ sessionId: d?.sessionId
442
+ }) ?? y;
443
+ } catch (v) {
444
+ t.logger.warn("[pontive] could not reach the issuer to end its session:", v instanceof Error ? v.message : String(v));
445
445
  }
446
- return b(k, f);
446
+ return $(y, w);
447
447
  }
448
- function z(r, o) {
448
+ function H(i, c) {
449
449
  return {
450
- ...r,
451
- accessToken: o.access_token,
450
+ ...i,
451
+ accessToken: c.access_token,
452
452
  // A response without one means rotation is off: the token in hand is still current.
453
- refreshToken: o.refresh_token ?? r.refreshToken,
454
- expiresAt: q(o)
453
+ refreshToken: c.refresh_token ?? i.refreshToken,
454
+ expiresAt: te(c)
455
455
  };
456
456
  }
457
- async function pe(r) {
458
- const o = new URL(r.url), h = T(r.headers.get("cookie")), f = Q(o.searchParams.get("returnTo"), e.afterSignInPath), k = o.searchParams.get("organization_id"), w = (y) => {
459
- const I = new URL(f, _(e, r));
460
- return y && I.searchParams.set(He, y), I.toString();
461
- }, E = await m(h);
462
- if (!E?.refreshToken) return b(p(r));
463
- if (!k) return b(w("invalid_request"));
464
- let v;
457
+ async function me(i) {
458
+ const c = new URL(i.url), d = I(i.headers.get("cookie")), w = ee(c.searchParams.get("returnTo"), t.afterSignInPath), y = c.searchParams.get("organization_id"), v = (S) => {
459
+ const _ = new URL(w, b(t, i));
460
+ return S && _.searchParams.set(Ve, S), _.toString();
461
+ }, T = await f(d);
462
+ if (!T?.refreshToken) return $(l(i));
463
+ if (!y) return $(v("invalid_request"));
464
+ let k;
465
465
  try {
466
- v = await F(t, e.fetch, E.refreshToken, k);
467
- } catch (y) {
468
- return y instanceof j && y.code === "invalid_request" ? b(w("not_a_member")) : (e.logger.warn("[pontive] organization switch failed:", y instanceof Error ? y.message : String(y)), b(w("switch_failed")));
466
+ k = await K(e, t.fetch, T.refreshToken, y);
467
+ } catch (S) {
468
+ return S instanceof z && S.code === "invalid_request" ? $(v("not_a_member")) : (t.logger.warn("[pontive] organization switch failed:", S instanceof Error ? S.message : String(S)), $(v("switch_failed")));
469
469
  }
470
- return b(w(), await S(h, z(E, v), r));
470
+ return $(v(), await E(d, H(T, k), i));
471
471
  }
472
- async function he(r) {
472
+ async function we(i) {
473
473
  try {
474
- const o = await F(t, e.fetch, r.refreshToken);
475
- return z(r, o);
476
- } catch (o) {
477
- if (o instanceof j && o.status >= 400 && o.status < 500)
478
- return e.logger.warn("[pontive] refresh refused; signing out:", o.message), null;
479
- throw o;
474
+ const c = await K(e, t.fetch, i.refreshToken);
475
+ return H(i, c);
476
+ } catch (c) {
477
+ if (c instanceof z && c.status >= 400 && c.status < 500)
478
+ return t.logger.warn("[pontive] refresh refused; signing out:", c.message), null;
479
+ throw c;
480
480
  }
481
481
  }
482
482
  return {
483
- async handle(r) {
484
- const { pathname: o } = new URL(r.url);
485
- if (!o.startsWith(`${e.basePath}/`)) return null;
486
- const h = o.slice(e.basePath.length + 1);
487
- return h === "login" && r.method === "GET" ? R(r) : h === "callback" && r.method === "GET" ? A(r) : h === "logout" && (r.method === "GET" || r.method === "POST") ? N(r) : h === H && (r.method === "GET" || r.method === "POST") ? pe(r) : null;
483
+ async handle(i) {
484
+ const { pathname: c } = new URL(i.url);
485
+ if (!c.startsWith(`${t.basePath}/`)) return null;
486
+ const d = c.slice(t.basePath.length + 1);
487
+ return d === "login" && i.method === "GET" ? O(i) : d === "callback" && i.method === "GET" ? U(i) : d === "logout" && (i.method === "GET" || i.method === "POST") ? A(i) : d === D && (i.method === "GET" || i.method === "POST") ? me(i) : null;
488
488
  },
489
- async getSession(r) {
490
- const o = await m(T(r));
491
- return o ? Date.now() >= o.expiresAt ? (e.logger.warn(
489
+ async getSession(i) {
490
+ const c = await f(I(i));
491
+ return c ? Date.now() >= c.expiresAt ? (t.logger.warn(
492
492
  "[pontive] the session's access token has expired and getSession cannot refresh it. Run the SDK's middleware on this path so it refreshes before the request is handled."
493
- ), null) : P(o) : null;
493
+ ), null) : P(c) : null;
494
494
  },
495
- async refresh(r) {
496
- const o = T(r.headers.get("cookie")), h = (v) => ({
497
- session: v,
495
+ async refresh(i) {
496
+ const c = I(i.headers.get("cookie")), d = (k) => ({
497
+ session: k,
498
498
  setCookies: [],
499
- cookieHeader: r.headers.get("cookie") ?? ""
500
- }), f = await m(o);
501
- if (!f) return h(null);
502
- if (new URL(r.url).pathname.startsWith(`${e.basePath}/`))
503
- return h(Date.now() < f.expiresAt ? P(f) : null);
504
- if (Date.now() < f.expiresAt - e.refreshSkewSeconds * 1e3) return h(P(f));
505
- const k = () => ({ session: null, setCookies: G(o, e.cookieName, i(r, 0)), cookieHeader: W(o) });
506
- if (!f.refreshToken) return k();
507
- let w;
499
+ cookieHeader: i.headers.get("cookie") ?? ""
500
+ }), w = await f(c);
501
+ if (!w) return d(null);
502
+ if (new URL(i.url).pathname.startsWith(`${t.basePath}/`))
503
+ return d(Date.now() < w.expiresAt ? P(w) : null);
504
+ if (Date.now() < w.expiresAt - t.refreshSkewSeconds * 1e3) return d(P(w));
505
+ const y = () => ({ session: null, setCookies: W(c, t.cookieName, a(i, 0)), cookieHeader: F(c) });
506
+ if (!w.refreshToken) return y();
507
+ let v;
508
508
  try {
509
- w = await s.run(f.refreshToken, () => he(f));
510
- } catch (v) {
511
- return e.logger.warn("[pontive] refresh failed, will retry:", v instanceof Error ? v.message : String(v)), h(Date.now() < f.expiresAt ? P(f) : null);
509
+ v = await s.run(w.refreshToken, () => we(w));
510
+ } catch (k) {
511
+ return t.logger.warn("[pontive] refresh failed, will retry:", k instanceof Error ? k.message : String(k)), d(Date.now() < w.expiresAt ? P(w) : null);
512
512
  }
513
- if (!w) return k();
514
- const E = await S(o, w, r);
515
- return { session: P(w), setCookies: E, cookieHeader: W(o) };
513
+ if (!v) return y();
514
+ const T = await E(c, v, i);
515
+ return { session: P(v), setCookies: T, cookieHeader: F(c) };
516
516
  }
517
517
  };
518
518
  }
519
- const ct = "1.26.0", lt = "claim";
520
- function vt(e = {}, t = {}) {
521
- const n = fe(), s = we(e, n);
522
- if (me(s, n)) return ut(s, t);
523
- const c = se(s), a = ve(n) ? () => le(ce(t), c.issuer) : async () => null;
524
- return ue(c, ae(c), a);
519
+ const lt = "1.28.0", dt = "claim";
520
+ function Ct(t = {}, e = {}) {
521
+ const r = se(), s = fe(t, r);
522
+ if (ke(s, r)) return mt(s, e);
523
+ const o = ae(s), h = Ee(r) ? () => le(ue(e), o.issuer) : async () => null;
524
+ return de(o, pe(o), h);
525
525
  }
526
- function ce(e) {
527
- if (e.projectDir) return e.projectDir;
528
- const t = globalThis.process;
529
- if (typeof t?.cwd != "function") throw new te("keyless mode needs a project directory (process.cwd)");
530
- return t.cwd();
526
+ function ue(t) {
527
+ if (t.projectDir) return t.projectDir;
528
+ const e = globalThis.process;
529
+ if (typeof e?.cwd != "function") throw new ne("keyless mode needs a project directory (process.cwd)");
530
+ return e.cwd();
531
531
  }
532
- async function le(e, t) {
532
+ async function le(t, e) {
533
533
  try {
534
- const n = await Se(e);
535
- return n?.claim_token && n.issuer.replace(/\/+$/, "") === t ? n : null;
534
+ const r = await Se(t);
535
+ return r?.claim_token && r.issuer.replace(/\/+$/, "") === e ? r : null;
536
536
  } catch {
537
537
  return null;
538
538
  }
539
539
  }
540
- function O(e, t) {
541
- return new Response(`${t}
542
- `, { status: e, headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" } });
540
+ function N(t, e) {
541
+ return new Response(`${e}
542
+ `, { status: t, headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" } });
543
543
  }
544
- function ue(e, t, n) {
545
- const s = `${e.basePath}/${lt}`;
546
- async function c(a) {
544
+ function de(t, e, r) {
545
+ const s = `${t.basePath}/${dt}`;
546
+ async function o(h) {
547
547
  try {
548
- const i = await ke(a, { fetch: e.fetch });
549
- return new Response(null, { status: 302, headers: { location: i.url, "cache-control": "no-store", "referrer-policy": "no-referrer" } });
550
- } catch (i) {
551
- return i instanceof D && i.status === 409 ? O(409, "This Pontive instance has already been claimed. Nothing in your app changes; manage it in the Pontive dashboard.") : i instanceof D && i.status === 404 ? O(410, ne(a, "expired")) : (e.logger.warn("[pontive] could not create a claim link:", i instanceof Error ? i.message : String(i)), O(502, "Pontive could not create a claim link just now. Try again, or run `npx pontive claim`."));
548
+ const a = await ge(h, { fetch: t.fetch });
549
+ return new Response(null, { status: 302, headers: { location: a.url, "cache-control": "no-store", "referrer-policy": "no-referrer" } });
550
+ } catch (a) {
551
+ return a instanceof V && a.status === 409 ? N(409, "This Pontive instance has already been claimed. Nothing in your app changes; manage it in the Pontive dashboard.") : a instanceof V && a.status === 404 ? N(410, oe(h, "expired")) : (t.logger.warn("[pontive] could not create a claim link:", a instanceof Error ? a.message : String(a)), N(502, "Pontive could not create a claim link just now. Try again, or run `npx pontive claim`."));
552
552
  }
553
553
  }
554
554
  return {
555
- async handle(a) {
556
- if (a.method === "GET" && new URL(a.url).pathname === s) {
557
- const i = await n();
558
- if (i) return c(i);
555
+ async handle(h) {
556
+ if (h.method === "GET" && new URL(h.url).pathname === s) {
557
+ const a = await r();
558
+ if (a) return o(a);
559
559
  }
560
- return t.handle(a);
560
+ return e.handle(h);
561
561
  },
562
- getSession: (a) => t.getSession(a),
563
- refresh: (a) => t.refresh(a),
562
+ getSession: (h) => e.getSession(h),
563
+ refresh: (h) => e.refresh(h),
564
564
  async providerProps() {
565
- const a = await n();
565
+ const h = await r();
566
566
  return {
567
- appId: e.clientId,
568
- domain: e.mode === "browser" ? e.authPath : e.issuer,
569
- ...a ? { claimUrl: s } : {}
567
+ appId: t.clientId,
568
+ domain: t.mode === "browser" ? t.authPath : t.issuer,
569
+ ...h ? { claimUrl: s } : {}
570
570
  };
571
571
  }
572
572
  };
573
573
  }
574
- const M = /* @__PURE__ */ new Map(), ee = /* @__PURE__ */ new Set();
575
- function ut(e, t) {
576
- const n = e.logger ?? console;
577
- let s, c, a = !1;
578
- async function i() {
579
- const u = ce(t), p = (e.basePath ?? "/api/auth").replace(/\/+$/, "");
580
- let m = M.get(u);
581
- m || (m = ye({
574
+ const M = /* @__PURE__ */ new Map(), re = /* @__PURE__ */ new Set();
575
+ function mt(t, e) {
576
+ const r = t.logger ?? console;
577
+ let s, o, h = !1;
578
+ async function a() {
579
+ const u = ue(e), l = (t.basePath ?? "/api/auth").replace(/\/+$/, "");
580
+ let f = M.get(u);
581
+ f || (f = Te({
582
582
  dir: u,
583
- redirectUris: e.redirectUri ? [e.redirectUri] : ge(p),
584
- client: { name: t.clientName ?? "@pontive/server", version: ct },
585
- fetch: e.fetch
586
- }), M.set(u, m), m.catch(() => M.delete(u)));
587
- const S = await m;
588
- ee.has(u) || (ee.add(u), n.warn(`
589
- ${Ee(S.record, { created: S.created })}
583
+ redirectUris: t.redirectUri ? [t.redirectUri] : be(l),
584
+ client: { name: e.clientName ?? "@pontive/server", version: lt },
585
+ fetch: t.fetch
586
+ }), M.set(u, f), f.catch(() => M.delete(u)));
587
+ const E = await f;
588
+ re.has(u) || (re.add(u), r.warn(`
589
+ ${Pe(E.record, { created: E.created })}
590
590
  `));
591
591
  const P = globalThis.process;
592
592
  if (P?.env)
593
- for (const [A, N] of Object.entries(S.env))
594
- N !== void 0 && !P.env[A] && (P.env[A] = N);
595
- if (!e.clientSecret && !S.env.PONTIVE_CLIENT_SECRET)
593
+ for (const [U, A] of Object.entries(E.env))
594
+ A !== void 0 && !P.env[U] && (P.env[U] = A);
595
+ if (!t.clientSecret && !E.env.PONTIVE_CLIENT_SECRET)
596
596
  throw new Error(
597
- `@pontive/server: ${_e} names ${S.record.instance_id}, but PONTIVE_CLIENT_SECRET is neither in ${Pe} nor in the environment. Put it back, or run \`npx pontive init --reset\`.`
597
+ `@pontive/server: ${$e} names ${E.record.instance_id}, but PONTIVE_CLIENT_SECRET is neither in ${_e} nor in the environment. Put it back, or run \`npx pontive init --reset\`.`
598
598
  );
599
- const R = se({
600
- ...e,
601
- issuer: e.issuer || S.env.PONTIVE_ISSUER,
602
- clientId: e.clientId || S.env.PONTIVE_CLIENT_ID,
603
- clientSecret: e.clientSecret || S.env.PONTIVE_CLIENT_SECRET,
604
- sessionSecret: e.sessionSecret || S.env.PONTIVE_SESSION_SECRET,
605
- fetch: pt(e.fetch, S.record, n)
599
+ const O = ae({
600
+ ...t,
601
+ issuer: t.issuer || E.env.PONTIVE_ISSUER,
602
+ clientId: t.clientId || E.env.PONTIVE_CLIENT_ID,
603
+ clientSecret: t.clientSecret || E.env.PONTIVE_CLIENT_SECRET,
604
+ sessionSecret: t.sessionSecret || E.env.PONTIVE_SESSION_SECRET,
605
+ fetch: wt(t.fetch, E.record, r)
606
606
  });
607
- return ue(R, ae(R), () => le(u, R.issuer));
607
+ return de(O, pe(O), () => le(u, O.issuer));
608
608
  }
609
- function l() {
610
- return c ? Promise.reject(c) : (s ??= i().catch((u) => {
611
- throw s = void 0, u instanceof be && (c = u), u;
609
+ function p() {
610
+ return o ? Promise.reject(o) : (s ??= a().catch((u) => {
611
+ throw s = void 0, u instanceof Ie && (o = u), u;
612
612
  }), s);
613
613
  }
614
- function d(u) {
615
- return u instanceof te ? (a || (a = !0, n.warn(
614
+ function m(u) {
615
+ return u instanceof ne ? (h || (h = !0, r.warn(
616
616
  `[pontive] ${u.message}. Requests here proceed without a session until the dev server restarts with the PONTIVE_* variables keyless mode wrote to .env.local.`
617
617
  )), !0) : !1;
618
618
  }
619
619
  return {
620
620
  async handle(u) {
621
621
  try {
622
- return await (await l()).handle(u);
623
- } catch (p) {
624
- if (d(p)) return O(503, "Pontive keyless mode can't run in this runtime; restart the dev server.");
625
- throw p;
622
+ return await (await p()).handle(u);
623
+ } catch (l) {
624
+ if (m(l)) return N(503, "Pontive keyless mode can't run in this runtime; restart the dev server.");
625
+ throw l;
626
626
  }
627
627
  },
628
628
  async getSession(u) {
629
629
  try {
630
- return await (await l()).getSession(u);
631
- } catch (p) {
632
- if (d(p)) return null;
633
- throw p;
630
+ return await (await p()).getSession(u);
631
+ } catch (l) {
632
+ if (m(l)) return null;
633
+ throw l;
634
634
  }
635
635
  },
636
636
  async refresh(u) {
637
637
  try {
638
- return await (await l()).refresh(u);
639
- } catch (p) {
640
- if (d(p)) return { session: null, setCookies: [], cookieHeader: u.headers.get("cookie") ?? "" };
641
- throw p;
638
+ return await (await p()).refresh(u);
639
+ } catch (l) {
640
+ if (m(l)) return { session: null, setCookies: [], cookieHeader: u.headers.get("cookie") ?? "" };
641
+ throw l;
642
642
  }
643
643
  },
644
644
  async providerProps() {
645
- return (await l()).providerProps();
645
+ return (await p()).providerProps();
646
646
  }
647
647
  };
648
648
  }
649
- function pt(e, t, n) {
650
- const s = e ?? ((...a) => fetch(...a));
651
- let c = !1;
652
- return async (a, i) => {
653
- const l = await s(a, i);
654
- return l.status === 401 && !c && (typeof a == "string" ? a : a instanceof URL ? a.toString() : a.url).startsWith(t.issuer) && (c = !0, n.warn(`[pontive] ${ne(t, "refused")}`)), l;
649
+ function wt(t, e, r) {
650
+ const s = t ?? ((...h) => fetch(...h));
651
+ let o = !1;
652
+ return async (h, a) => {
653
+ const p = await s(h, a);
654
+ return p.status === 401 && !o && (typeof h == "string" ? h : h instanceof URL ? h.toString() : h.url).startsWith(e.issuer) && (o = !0, r.warn(`[pontive] ${oe(e, "refused")}`)), p;
655
655
  };
656
656
  }
657
+ const n = encodeURIComponent;
658
+ class vt {
659
+ /** @internal */
660
+ constructor(e) {
661
+ this.core = e, this.domains = new ft(e), this.instances = new kt(e), this.plans = new Et(e), this.projects = new yt(e), this.workspaces = new St(e);
662
+ }
663
+ core;
664
+ /**
665
+ * An instance's auth domains.
666
+ */
667
+ domains;
668
+ /**
669
+ * Instances: an environment of a project, its members and its secret keys for the management API.
670
+ */
671
+ instances;
672
+ /**
673
+ * The plans a workspace can be on.
674
+ */
675
+ plans;
676
+ /**
677
+ * Projects: an application with its instances, and its members and invitations.
678
+ */
679
+ projects;
680
+ /**
681
+ * Workspaces: the credential's own workspace, its members, invitations, webhooks, billing and usage.
682
+ */
683
+ workspaces;
684
+ }
685
+ class ft {
686
+ /** @internal */
687
+ constructor(e) {
688
+ this.core = e;
689
+ }
690
+ core;
691
+ /**
692
+ * Create domain.
693
+ *
694
+ * Register a hostname against an instance. The domain starts pending and carries the DNS challenge
695
+ * that must be published before it can be activated.
696
+ *
697
+ * `POST /v1/domains` (CreateDomain)
698
+ */
699
+ create(e, r) {
700
+ return this.core.request({ host: "api", method: "POST", path: "/v1/domains", body: e }, r);
701
+ }
702
+ /**
703
+ * Delete domain.
704
+ *
705
+ * Remove a domain. Refused while any app or service account is still bound to it.
706
+ *
707
+ * `DELETE /v1/domains/{domain_id}` (DeleteDomain)
708
+ */
709
+ delete(e, r) {
710
+ return this.core.request({ host: "api", method: "DELETE", path: `/v1/domains/${n(e)}` }, r);
711
+ }
712
+ /**
713
+ * List domains.
714
+ *
715
+ * Get a list of domains for an instance.
716
+ *
717
+ * `GET /v1/domains` (ListDomains)
718
+ *
719
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
720
+ */
721
+ list(e, r) {
722
+ return this.core.page("page", { host: "api", method: "GET", path: "/v1/domains", query: e }, r);
723
+ }
724
+ /**
725
+ * Verify domain.
726
+ *
727
+ * Check the DNS TXT challenge for a domain and record the outcome. Does not activate the domain;
728
+ * activation is a separate call and is refused until verification has succeeded.
729
+ *
730
+ * `POST /v1/domains/{domain_id}/verify` (VerifyDomain)
731
+ */
732
+ verify(e, r) {
733
+ return this.core.request({ host: "api", method: "POST", path: `/v1/domains/${n(e)}/verify` }, r);
734
+ }
735
+ }
736
+ class kt {
737
+ /** @internal */
738
+ constructor(e) {
739
+ this.core = e;
740
+ }
741
+ core;
742
+ /**
743
+ * Create instance.
744
+ *
745
+ * Create an instance in a project. name and slug are required for non_production and must be omitted
746
+ * for production, which is always Production/production and limited to one per project.
747
+ *
748
+ * `POST /v1/instances` (CreateInstance)
749
+ */
750
+ create(e, r) {
751
+ return this.core.request({ host: "api", method: "POST", path: "/v1/instances", body: e }, r);
752
+ }
753
+ /**
754
+ * Add an instance member.
755
+ *
756
+ * Grant roles on the instance to a member of its workspace (admin, developer, support or viewer). This
757
+ * is how a workspace member is given production access.
758
+ *
759
+ * `POST /v1/instances/{instance_id}/members` (CreateInstanceMember)
760
+ */
761
+ createMember(e, r, s) {
762
+ return this.core.request({ host: "api", method: "POST", path: `/v1/instances/${n(e)}/members`, body: r }, s);
763
+ }
764
+ /**
765
+ * Create a secret key.
766
+ *
767
+ * Create a secret key for the instance's management API. The answer carries its value once; it is
768
+ * never shown again. Needs instance:secret_keys.manage. An instance holds at most 10 active keys
769
+ * (secret_key_limit_reached); a deleted instance takes none (instance_deleted).
770
+ *
771
+ * `POST /v1/instances/{instance_id}/secret-keys` (CreateSecretKey)
772
+ */
773
+ createSecretKey(e, r, s) {
774
+ return this.core.request({ host: "api", method: "POST", path: `/v1/instances/${n(e)}/secret-keys`, body: r }, s);
775
+ }
776
+ /**
777
+ * Delete instance.
778
+ *
779
+ * Soft-delete an instance, recoverable for 30 days: it carries purge_scheduled_at, deleted_at plus 30
780
+ * days, and is purged after it. Requires {"confirm_delete": true}; without it the API returns 400
781
+ * confirmation_required. A project keeps at least one active instance: deleting its last one returns
782
+ * 409 last_active_instance. A token acting for a Pontive user (the Pontive MCP server) deletes a
783
+ * non_production instance only; the production one is refused with 403 actor_refused, to be deleted in
784
+ * the dashboard.
785
+ *
786
+ * `DELETE /v1/instances/{instance_id}` (DeleteInstance)
787
+ */
788
+ delete(e, r, s) {
789
+ return this.core.request({ host: "api", method: "DELETE", path: `/v1/instances/${n(e)}`, body: r }, s);
790
+ }
791
+ /**
792
+ * Remove an instance member.
793
+ *
794
+ * Remove a member from the instance. They stay a member of the workspace, and of the project if they
795
+ * were one.
796
+ *
797
+ * `DELETE /v1/instances/{instance_id}/members/{user_id}` (DeleteInstanceMember)
798
+ */
799
+ deleteMember(e, r, s) {
800
+ return this.core.request({ host: "api", method: "DELETE", path: `/v1/instances/${n(e)}/members/${n(r)}` }, s);
801
+ }
802
+ /**
803
+ * Get instance.
804
+ *
805
+ * Get instance details by ID.
806
+ *
807
+ * `GET /v1/instances/{instance_id}` (GetInstance)
808
+ */
809
+ get(e, r) {
810
+ return this.core.request({ host: "api", method: "GET", path: `/v1/instances/${n(e)}` }, r);
811
+ }
812
+ /**
813
+ * The caller's access to an instance.
814
+ *
815
+ * The platform permissions the caller holds on the instance, and the roles they hold on it directly.
816
+ *
817
+ * `GET /v1/instances/{instance_id}/access` (GetInstanceAccess)
818
+ */
819
+ getAccess(e, r) {
820
+ return this.core.request({ host: "api", method: "GET", path: `/v1/instances/${n(e)}/access` }, r);
821
+ }
822
+ /**
823
+ * Get a secret key.
824
+ *
825
+ * One of the instance's secret keys. Needs instance:read.
826
+ *
827
+ * `GET /v1/instances/{instance_id}/secret-keys/{secret_key_id}` (GetSecretKey)
828
+ */
829
+ getSecretKey(e, r, s) {
830
+ return this.core.request({ host: "api", method: "GET", path: `/v1/instances/${n(e)}/secret-keys/${n(r)}` }, s);
831
+ }
832
+ /**
833
+ * List instances.
834
+ *
835
+ * List the instances of a project or a workspace. One of project_id or workspace_id is required, but
836
+ * for Pontive's staff, who list every instance. A token acting for a Pontive user through an actor
837
+ * (the Pontive MCP server) lists the instances the user's own roles reach, never a staff role's: those
838
+ * of the project or workspace named, else of every workspace the user belongs to.
839
+ *
840
+ * `GET /v1/instances` (ListInstances)
841
+ *
842
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
843
+ */
844
+ list(e, r) {
845
+ return this.core.page("page", { host: "api", method: "GET", path: "/v1/instances", query: e }, r);
846
+ }
847
+ /**
848
+ * List an instance's members.
849
+ *
850
+ * List the users holding roles on the instance itself. Everyone else reaches it through its project
851
+ * and workspace.
852
+ *
853
+ * `GET /v1/instances/{instance_id}/members` (ListInstanceMembers)
854
+ *
855
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
856
+ */
857
+ listMembers(e, r, s) {
858
+ return this.core.page("page", { host: "api", method: "GET", path: `/v1/instances/${n(e)}/members`, query: r }, s);
859
+ }
860
+ /**
861
+ * List secret keys.
862
+ *
863
+ * List the instance's secret keys. Revoked keys stay listed for 30 days. Needs instance:read.
864
+ *
865
+ * `GET /v1/instances/{instance_id}/secret-keys` (ListSecretKeys)
866
+ *
867
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
868
+ */
869
+ listSecretKeys(e, r, s) {
870
+ return this.core.page("page", { host: "api", method: "GET", path: `/v1/instances/${n(e)}/secret-keys`, query: r }, s);
871
+ }
872
+ /**
873
+ * Pause instance.
874
+ *
875
+ * Pause an instance. A project keeps at least one active instance: pausing its last one returns 409
876
+ * last_active_instance.
877
+ *
878
+ * `POST /v1/instances/{instance_id}/pause` (PauseInstance)
879
+ */
880
+ pause(e, r) {
881
+ return this.core.request({ host: "api", method: "POST", path: `/v1/instances/${n(e)}/pause` }, r);
882
+ }
883
+ /**
884
+ * Purge instance.
885
+ *
886
+ * Permanently delete a deleted instance and all its data now, rather than at its purge_scheduled_at,
887
+ * and retire its host label. Cannot be undone.
888
+ *
889
+ * `POST /v1/instances/{instance_id}/purge` (PurgeInstance)
890
+ */
891
+ purge(e, r) {
892
+ return this.core.request({ host: "api", method: "POST", path: `/v1/instances/${n(e)}/purge` }, r);
893
+ }
894
+ /**
895
+ * Restore instance.
896
+ *
897
+ * Restore a soft-deleted instance within 30 days of its deletion, until its purge_scheduled_at (409
898
+ * restore_window_closed after, when it is purged).
899
+ *
900
+ * `POST /v1/instances/{instance_id}/restore` (RestoreInstance)
901
+ */
902
+ restore(e, r) {
903
+ return this.core.request({ host: "api", method: "POST", path: `/v1/instances/${n(e)}/restore` }, r);
904
+ }
905
+ /**
906
+ * Resume instance.
907
+ *
908
+ * Resume a paused instance.
909
+ *
910
+ * `POST /v1/instances/{instance_id}/resume` (ResumeInstance)
911
+ */
912
+ resume(e, r) {
913
+ return this.core.request({ host: "api", method: "POST", path: `/v1/instances/${n(e)}/resume` }, r);
914
+ }
915
+ /**
916
+ * Revoke a secret key.
917
+ *
918
+ * End a secret key and any still-valid previous value at once. Final: a revoked key cannot be
919
+ * reactivated. Needs instance:secret_keys.manage.
920
+ *
921
+ * `POST /v1/instances/{instance_id}/secret-keys/{secret_key_id}/revoke` (RevokeSecretKey)
922
+ */
923
+ revokeSecretKey(e, r, s) {
924
+ return this.core.request({ host: "api", method: "POST", path: `/v1/instances/${n(e)}/secret-keys/${n(r)}/revoke` }, s);
925
+ }
926
+ /**
927
+ * Rotate a secret key.
928
+ *
929
+ * Replace a secret key's value, keeping the key. The answer carries the new value once. The current
930
+ * value keeps working for expire_previous_in seconds (0 to 604800, default 86400). Needs
931
+ * instance:secret_keys.manage.
932
+ *
933
+ * `POST /v1/instances/{instance_id}/secret-keys/{secret_key_id}/rotate` (RotateSecretKey)
934
+ */
935
+ rotateSecretKey(e, r, s, o) {
936
+ return this.core.request({ host: "api", method: "POST", path: `/v1/instances/${n(e)}/secret-keys/${n(r)}/rotate`, body: s }, o);
937
+ }
938
+ /**
939
+ * Update instance.
940
+ *
941
+ * Update an instance. name is writable on non_production instances only; renaming the production
942
+ * instance returns instance_name_not_settable.
943
+ *
944
+ * `PATCH /v1/instances/{instance_id}` (UpdateInstance)
945
+ */
946
+ update(e, r, s) {
947
+ return this.core.request({ host: "api", method: "PATCH", path: `/v1/instances/${n(e)}`, body: r }, s);
948
+ }
949
+ /**
950
+ * Change an instance member's roles.
951
+ *
952
+ * Replace the roles a member holds on the instance.
953
+ *
954
+ * `PATCH /v1/instances/{instance_id}/members/{user_id}` (UpdateInstanceMember)
955
+ */
956
+ updateMember(e, r, s, o) {
957
+ return this.core.request({ host: "api", method: "PATCH", path: `/v1/instances/${n(e)}/members/${n(r)}`, body: s }, o);
958
+ }
959
+ /**
960
+ * Update a secret key.
961
+ *
962
+ * Change a secret key's name, description or role. A role change takes effect within 30 seconds. Needs
963
+ * instance:secret_keys.manage.
964
+ *
965
+ * `PATCH /v1/instances/{instance_id}/secret-keys/{secret_key_id}` (UpdateSecretKey)
966
+ */
967
+ updateSecretKey(e, r, s, o) {
968
+ return this.core.request({ host: "api", method: "PATCH", path: `/v1/instances/${n(e)}/secret-keys/${n(r)}`, body: s }, o);
969
+ }
970
+ }
971
+ class Et {
972
+ /** @internal */
973
+ constructor(e) {
974
+ this.core = e;
975
+ }
976
+ core;
977
+ /**
978
+ * List plans.
979
+ *
980
+ * The public plan catalog, cheapest first — the offered plans, each with its base fee at both
981
+ * intervals, included projects and seats, allowances, caps, rates and modules — and the fixed
982
+ * charges (additional project, b2b uplift, FGA instance, custom domain, seat, paused project) at both
983
+ * intervals. Amounts are cents, read from Stripe. A retired plan is not listed; the workspaces on it
984
+ * keep it.
985
+ *
986
+ * `GET /v1/plans` (ListPlans)
987
+ *
988
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
989
+ */
990
+ list(e, r) {
991
+ return this.core.page("page", { host: "api", method: "GET", path: "/v1/plans", query: e }, r);
992
+ }
993
+ }
994
+ class yt {
995
+ /** @internal */
996
+ constructor(e) {
997
+ this.core = e;
998
+ }
999
+ core;
1000
+ /**
1001
+ * Create project.
1002
+ *
1003
+ * Create a new project in a workspace. The project is created with one non_production instance
1004
+ * (Development, slug dev), returned in instances.
1005
+ *
1006
+ * `POST /v1/projects` (CreateProject)
1007
+ */
1008
+ create(e, r) {
1009
+ return this.core.request({ host: "api", method: "POST", path: "/v1/projects", body: e }, r);
1010
+ }
1011
+ /**
1012
+ * Invite to a project.
1013
+ *
1014
+ * Invite people to the project by email. Invitees who are not workspace members join the workspace
1015
+ * too, with no role there.
1016
+ *
1017
+ * `POST /v1/projects/{project_id}/invitations` (CreateProjectInvitations)
1018
+ */
1019
+ createInvitations(e, r, s) {
1020
+ return this.core.request({ host: "api", method: "POST", path: `/v1/projects/${n(e)}/invitations`, body: r }, s);
1021
+ }
1022
+ /**
1023
+ * Add a project member.
1024
+ *
1025
+ * Grant roles on the project to a member of its workspace. Someone who is not a workspace member is
1026
+ * invited instead.
1027
+ *
1028
+ * `POST /v1/projects/{project_id}/members` (CreateProjectMember)
1029
+ */
1030
+ createMember(e, r, s) {
1031
+ return this.core.request({ host: "api", method: "POST", path: `/v1/projects/${n(e)}/members`, body: r }, s);
1032
+ }
1033
+ /**
1034
+ * Delete project.
1035
+ *
1036
+ * Soft-delete a project and every instance in it, recoverable for 30 days: it carries
1037
+ * purge_scheduled_at, deleted_at plus 30 days, and is purged with its instances after it. Requires
1038
+ * {"confirm_delete": true}; without it the API returns 400 confirmation_required.
1039
+ *
1040
+ * `DELETE /v1/projects/{project_id}` (DeleteProject)
1041
+ */
1042
+ delete(e, r, s) {
1043
+ return this.core.request({ host: "api", method: "DELETE", path: `/v1/projects/${n(e)}`, body: r }, s);
1044
+ }
1045
+ /**
1046
+ * Delete a project invitation.
1047
+ *
1048
+ * Withdraw one of the project's invitations: it is deleted, and its link stops working.
1049
+ *
1050
+ * `DELETE /v1/projects/{project_id}/invitations/{invitation_id}` (DeleteProjectInvitation)
1051
+ */
1052
+ deleteInvitation(e, r, s, o) {
1053
+ return this.core.request({ host: "api", method: "DELETE", path: `/v1/projects/${n(e)}/invitations/${n(r)}`, query: s }, o);
1054
+ }
1055
+ /**
1056
+ * Remove a project member.
1057
+ *
1058
+ * Remove a member from the project. They stay a member of the workspace.
1059
+ *
1060
+ * `DELETE /v1/projects/{project_id}/members/{user_id}` (DeleteProjectMember)
1061
+ */
1062
+ deleteMember(e, r, s) {
1063
+ return this.core.request({ host: "api", method: "DELETE", path: `/v1/projects/${n(e)}/members/${n(r)}` }, s);
1064
+ }
1065
+ /**
1066
+ * Get project.
1067
+ *
1068
+ * Get project details by ID or slug.
1069
+ *
1070
+ * `GET /v1/projects/{project_id}` (GetProject)
1071
+ */
1072
+ get(e, r) {
1073
+ return this.core.request({ host: "api", method: "GET", path: `/v1/projects/${n(e)}` }, r);
1074
+ }
1075
+ /**
1076
+ * The caller's access to a project.
1077
+ *
1078
+ * The platform permissions the caller holds on the project, and the roles they hold on it directly.
1079
+ *
1080
+ * `GET /v1/projects/{project_id}/access` (GetProjectAccess)
1081
+ */
1082
+ getAccess(e, r) {
1083
+ return this.core.request({ host: "api", method: "GET", path: `/v1/projects/${n(e)}/access` }, r);
1084
+ }
1085
+ /**
1086
+ * List projects.
1087
+ *
1088
+ * Get a list of projects for a workspace.
1089
+ *
1090
+ * `GET /v1/projects` (ListProjects)
1091
+ *
1092
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
1093
+ */
1094
+ list(e, r) {
1095
+ return this.core.page("page", { host: "api", method: "GET", path: "/v1/projects", query: e }, r);
1096
+ }
1097
+ /**
1098
+ * List a project's invitations.
1099
+ *
1100
+ * List the invitations to the project.
1101
+ *
1102
+ * `GET /v1/projects/{project_id}/invitations` (ListProjectInvitations)
1103
+ *
1104
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
1105
+ */
1106
+ listInvitations(e, r, s) {
1107
+ return this.core.page("page", { host: "api", method: "GET", path: `/v1/projects/${n(e)}/invitations`, query: r }, s);
1108
+ }
1109
+ /**
1110
+ * List a project's members.
1111
+ *
1112
+ * List the users holding roles on the project itself. Workspace members reach every project through
1113
+ * the workspace and are listed there.
1114
+ *
1115
+ * `GET /v1/projects/{project_id}/members` (ListProjectMembers)
1116
+ *
1117
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
1118
+ */
1119
+ listMembers(e, r, s) {
1120
+ return this.core.page("page", { host: "api", method: "GET", path: `/v1/projects/${n(e)}/members`, query: r }, s);
1121
+ }
1122
+ /**
1123
+ * Pause project.
1124
+ *
1125
+ * Pause a project.
1126
+ *
1127
+ * `POST /v1/projects/{project_id}/pause` (PauseProject)
1128
+ */
1129
+ pause(e, r) {
1130
+ return this.core.request({ host: "api", method: "POST", path: `/v1/projects/${n(e)}/pause` }, r);
1131
+ }
1132
+ /**
1133
+ * Purge project.
1134
+ *
1135
+ * Permanently delete a deleted project and its instances now, rather than at its purge_scheduled_at,
1136
+ * and retire its slug and host labels. Cannot be undone.
1137
+ *
1138
+ * `POST /v1/projects/{project_id}/purge` (PurgeProject)
1139
+ */
1140
+ purge(e, r) {
1141
+ return this.core.request({ host: "api", method: "POST", path: `/v1/projects/${n(e)}/purge` }, r);
1142
+ }
1143
+ /**
1144
+ * Resend a project invitation.
1145
+ *
1146
+ * Send one of the project's outstanding invitations again.
1147
+ *
1148
+ * `POST /v1/projects/{project_id}/invitations/{invitation_id}/resend` (ResendProjectInvitation)
1149
+ */
1150
+ resendInvitation(e, r, s, o) {
1151
+ return this.core.request({ host: "api", method: "POST", path: `/v1/projects/${n(e)}/invitations/${n(r)}/resend`, body: s }, o);
1152
+ }
1153
+ /**
1154
+ * Restore project.
1155
+ *
1156
+ * Restore a deleted project within 30 days of its deletion, until its purge_scheduled_at (409
1157
+ * restore_window_closed after, when it is purged).
1158
+ *
1159
+ * `POST /v1/projects/{project_id}/restore` (RestoreProject)
1160
+ */
1161
+ restore(e, r) {
1162
+ return this.core.request({ host: "api", method: "POST", path: `/v1/projects/${n(e)}/restore` }, r);
1163
+ }
1164
+ /**
1165
+ * Resume project.
1166
+ *
1167
+ * Resume a paused project.
1168
+ *
1169
+ * `POST /v1/projects/{project_id}/resume` (ResumeProject)
1170
+ */
1171
+ resume(e, r) {
1172
+ return this.core.request({ host: "api", method: "POST", path: `/v1/projects/${n(e)}/resume` }, r);
1173
+ }
1174
+ /**
1175
+ * Update project.
1176
+ *
1177
+ * Update an existing project.
1178
+ *
1179
+ * `PATCH /v1/projects/{project_id}` (UpdateProject)
1180
+ */
1181
+ update(e, r, s) {
1182
+ return this.core.request({ host: "api", method: "PATCH", path: `/v1/projects/${n(e)}`, body: r }, s);
1183
+ }
1184
+ /**
1185
+ * Change a project member's roles.
1186
+ *
1187
+ * Replace the roles a member holds on the project (admin, developer or viewer)
1188
+ *
1189
+ * `PATCH /v1/projects/{project_id}/members/{user_id}` (UpdateProjectMember)
1190
+ */
1191
+ updateMember(e, r, s, o) {
1192
+ return this.core.request({ host: "api", method: "PATCH", path: `/v1/projects/${n(e)}/members/${n(r)}`, body: s }, o);
1193
+ }
1194
+ }
1195
+ class St {
1196
+ /** @internal */
1197
+ constructor(e) {
1198
+ this.core = e, this.webhooks = new gt(e);
1199
+ }
1200
+ core;
1201
+ /**
1202
+ * A workspace's webhooks: subscriptions, their deliveries, and its events.
1203
+ */
1204
+ webhooks;
1205
+ /**
1206
+ * Invite members.
1207
+ *
1208
+ * Invite people to the workspace by email.
1209
+ *
1210
+ * `POST /v1/workspaces/{workspace_id}/invitations` (CreateWorkspaceInvitations)
1211
+ */
1212
+ createInvitations(e, r, s) {
1213
+ return this.core.request({ host: "api", method: "POST", path: `/v1/workspaces/${n(e)}/invitations`, body: r }, s);
1214
+ }
1215
+ /**
1216
+ * Delete an invitation.
1217
+ *
1218
+ * Withdraw an invitation: it is deleted, and its link stops working. An invitation exists only while
1219
+ * it is open — accepting one deletes it too, and an expired one is purged.
1220
+ *
1221
+ * `DELETE /v1/workspaces/{workspace_id}/invitations/{invitation_id}` (DeleteWorkspaceInvitation)
1222
+ */
1223
+ deleteInvitation(e, r, s, o) {
1224
+ return this.core.request({ host: "api", method: "DELETE", path: `/v1/workspaces/${n(e)}/invitations/${n(r)}`, query: s }, o);
1225
+ }
1226
+ /**
1227
+ * Remove a member.
1228
+ *
1229
+ * Remove a member from the workspace. Removing an owner is an owner's; a token acting for a Pontive
1230
+ * user (the Pontive MCP server) is refused it with 403 actor_refused, as ownership is the dashboard's.
1231
+ *
1232
+ * `DELETE /v1/workspaces/{workspace_id}/members/{user_id}` (DeleteWorkspaceMember)
1233
+ */
1234
+ deleteMember(e, r, s) {
1235
+ return this.core.request({ host: "api", method: "DELETE", path: `/v1/workspaces/${n(e)}/members/${n(r)}` }, s);
1236
+ }
1237
+ /**
1238
+ * Get workspace.
1239
+ *
1240
+ * One workspace. A deleted one answers 404 to its members and is returned, with status deleted and
1241
+ * deleted_at, to Pontive's staff.
1242
+ *
1243
+ * `GET /v1/workspaces/{workspace_id}` (GetWorkspace)
1244
+ */
1245
+ get(e, r) {
1246
+ return this.core.request({ host: "api", method: "GET", path: `/v1/workspaces/${n(e)}` }, r);
1247
+ }
1248
+ /**
1249
+ * The caller's access to a workspace.
1250
+ *
1251
+ * The platform permissions the caller holds on the workspace, and the roles they hold on it directly.
1252
+ *
1253
+ * `GET /v1/workspaces/{workspace_id}/access` (GetWorkspaceAccess)
1254
+ */
1255
+ getAccess(e, r) {
1256
+ return this.core.request({ host: "api", method: "GET", path: `/v1/workspaces/${n(e)}/access` }, r);
1257
+ }
1258
+ /**
1259
+ * Get the billing account.
1260
+ *
1261
+ * The workspace's plan and billing interval, the plan a pending downgrade moves it to and when
1262
+ * (scheduled_plan, scheduled_plan_at), what it holds (projects, seats, FGA instances, custom domains),
1263
+ * what its plan grants, and the Free checklist. Pontive bills workspaces through billing-svc on the
1264
+ * Directory instance: plan and interval changes, payment and invoices are billing's, in its portal on
1265
+ * the dashboard's Billing page, not here. Any workspace member reads it.
1266
+ *
1267
+ * `GET /v1/workspaces/{workspace_id}/billing` (GetWorkspaceBilling)
1268
+ */
1269
+ getBilling(e, r) {
1270
+ return this.core.request({ host: "api", method: "GET", path: `/v1/workspaces/${n(e)}/billing` }, r);
1271
+ }
1272
+ /**
1273
+ * Workspace usage.
1274
+ *
1275
+ * The current calendar month: every meter pooled across the workspace's instances against its plan's
1276
+ * allowances and caps, split by project; tracked token counts; each project and instance. Nothing is
1277
+ * priced here. Trails real time by up to 15 minutes.
1278
+ *
1279
+ * `GET /v1/workspaces/{workspace_id}/usage` (GetWorkspaceUsage)
1280
+ */
1281
+ getUsage(e, r) {
1282
+ return this.core.request({ host: "api", method: "GET", path: `/v1/workspaces/${n(e)}/usage` }, r);
1283
+ }
1284
+ /**
1285
+ * List workspaces.
1286
+ *
1287
+ * The caller's workspaces. A deleted workspace is gone to its members: it is listed, with status
1288
+ * deleted, to Pontive's staff alone, who restore it; status=deleted lists only those.
1289
+ *
1290
+ * `GET /v1/workspaces` (ListWorkspaces)
1291
+ *
1292
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
1293
+ */
1294
+ list(e, r) {
1295
+ return this.core.page("page", { host: "api", method: "GET", path: "/v1/workspaces", query: e }, r);
1296
+ }
1297
+ /**
1298
+ * List workspace invitations.
1299
+ *
1300
+ * Get a list of the workspace's invitations.
1301
+ *
1302
+ * `GET /v1/workspaces/{workspace_id}/invitations` (ListWorkspaceInvitations)
1303
+ *
1304
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
1305
+ */
1306
+ listInvitations(e, r, s) {
1307
+ return this.core.page("page", { host: "api", method: "GET", path: `/v1/workspaces/${n(e)}/invitations`, query: r }, s);
1308
+ }
1309
+ /**
1310
+ * List a member's grants.
1311
+ *
1312
+ * The roles a workspace member holds on the workspace's projects and instances directly, on top of
1313
+ * what their workspace role reaches by inheritance.
1314
+ *
1315
+ * `GET /v1/workspaces/{workspace_id}/members/{user_id}/grants` (ListWorkspaceMemberGrants)
1316
+ *
1317
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
1318
+ */
1319
+ listMemberGrants(e, r, s, o) {
1320
+ return this.core.page("page", { host: "api", method: "GET", path: `/v1/workspaces/${n(e)}/members/${n(r)}/grants`, query: s }, o);
1321
+ }
1322
+ /**
1323
+ * List workspace members.
1324
+ *
1325
+ * Get a list of the workspace's members.
1326
+ *
1327
+ * `GET /v1/workspaces/{workspace_id}/members` (ListWorkspaceMembers)
1328
+ *
1329
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
1330
+ */
1331
+ listMembers(e, r, s) {
1332
+ return this.core.page("page", { host: "api", method: "GET", path: `/v1/workspaces/${n(e)}/members`, query: r }, s);
1333
+ }
1334
+ /**
1335
+ * Resend an invitation.
1336
+ *
1337
+ * Send an outstanding invitation again.
1338
+ *
1339
+ * `POST /v1/workspaces/{workspace_id}/invitations/{invitation_id}/resend` (ResendWorkspaceInvitation)
1340
+ */
1341
+ resendInvitation(e, r, s, o) {
1342
+ return this.core.request({ host: "api", method: "POST", path: `/v1/workspaces/${n(e)}/invitations/${n(r)}/resend`, body: s }, o);
1343
+ }
1344
+ /**
1345
+ * Update workspace.
1346
+ *
1347
+ * Update an existing workspace. The name, description and metadata need workspace:manage; the billing
1348
+ * contact needs workspace:billing.manage, and a request carrying only the billing contact needs
1349
+ * nothing else, so a billing member sets where the invoices go. A token acting for a Pontive user (the
1350
+ * Pontive MCP server) is refused the billing contact with 403 actor_refused: it is set in the
1351
+ * dashboard.
1352
+ *
1353
+ * `PATCH /v1/workspaces/{workspace_id}` (UpdateWorkspace)
1354
+ */
1355
+ update(e, r, s) {
1356
+ return this.core.request({ host: "api", method: "PATCH", path: `/v1/workspaces/${n(e)}`, body: r }, s);
1357
+ }
1358
+ /**
1359
+ * Update a member's roles.
1360
+ *
1361
+ * Replace the roles a member holds in the workspace. Granting owner, or changing an owner's roles, is
1362
+ * an owner's; a token acting for a Pontive user (the Pontive MCP server) is refused it with 403
1363
+ * actor_refused, as ownership is the dashboard's.
1364
+ *
1365
+ * `PATCH /v1/workspaces/{workspace_id}/members/{user_id}` (UpdateWorkspaceMember)
1366
+ */
1367
+ updateMember(e, r, s, o) {
1368
+ return this.core.request({ host: "api", method: "PATCH", path: `/v1/workspaces/${n(e)}/members/${n(r)}`, body: s }, o);
1369
+ }
1370
+ }
1371
+ class gt {
1372
+ /** @internal */
1373
+ constructor(e) {
1374
+ this.core = e;
1375
+ }
1376
+ core;
1377
+ /**
1378
+ * Create a workspace webhook.
1379
+ *
1380
+ * Register an endpoint for the workspace's events. The Standard Webhooks signing secret, whsec_…, is
1381
+ * answered only here. The webhook is bound to the workspace in the path. Needs
1382
+ * workspace:webhooks.manage.
1383
+ *
1384
+ * `POST /v1/workspaces/{workspace_id}/webhooks/subscriptions` (CreateWorkspaceWebhookSubscription)
1385
+ */
1386
+ createSubscription(e, r, s) {
1387
+ return this.core.request({ host: "api", method: "POST", path: `/v1/workspaces/${n(e)}/webhooks/subscriptions`, body: r }, s);
1388
+ }
1389
+ /**
1390
+ * Delete a workspace webhook.
1391
+ *
1392
+ * Needs workspace:webhooks.manage.
1393
+ *
1394
+ * `DELETE /v1/workspaces/{workspace_id}/webhooks/subscriptions/{subscription_id}`
1395
+ * (DeleteWorkspaceWebhookSubscription)
1396
+ */
1397
+ deleteSubscription(e, r, s) {
1398
+ return this.core.request({ host: "api", method: "DELETE", path: `/v1/workspaces/${n(e)}/webhooks/subscriptions/${n(r)}` }, s);
1399
+ }
1400
+ /**
1401
+ * Get a workspace webhook's activity.
1402
+ *
1403
+ * The webhook's requests and failures per interval: one bucket per hour or UTC day of the window,
1404
+ * oldest first, empty ones included. Needs workspace:webhooks.read.
1405
+ *
1406
+ * `GET /v1/workspaces/{workspace_id}/webhooks/subscriptions/{subscription_id}/activity`
1407
+ * (GetWorkspaceWebhookActivity)
1408
+ */
1409
+ getActivity(e, r, s, o) {
1410
+ return this.core.request({ host: "api", method: "GET", path: `/v1/workspaces/${n(e)}/webhooks/subscriptions/${n(r)}/activity`, query: s }, o);
1411
+ }
1412
+ /**
1413
+ * Get a workspace webhook's delivery.
1414
+ *
1415
+ * Needs workspace:webhooks.read. A delivery of another webhook is 404.
1416
+ *
1417
+ * `GET
1418
+ * /v1/workspaces/{workspace_id}/webhooks/subscriptions/{subscription_id}/deliveries/{delivery_id}`
1419
+ * (GetWorkspaceWebhookDelivery)
1420
+ */
1421
+ getDelivery(e, r, s, o) {
1422
+ return this.core.request({ host: "api", method: "GET", path: `/v1/workspaces/${n(e)}/webhooks/subscriptions/${n(r)}/deliveries/${n(s)}` }, o);
1423
+ }
1424
+ /**
1425
+ * Get one of the workspace's events.
1426
+ *
1427
+ * Needs workspace:webhooks.read. Another workspace's event is 404.
1428
+ *
1429
+ * `GET /v1/workspaces/{workspace_id}/webhooks/events/{event_id}` (GetWorkspaceWebhookEvent)
1430
+ */
1431
+ getEvent(e, r, s) {
1432
+ return this.core.request({ host: "api", method: "GET", path: `/v1/workspaces/${n(e)}/webhooks/events/${n(r)}` }, s);
1433
+ }
1434
+ /**
1435
+ * Get a workspace webhook.
1436
+ *
1437
+ * Needs workspace:webhooks.read. Another workspace's webhook is 404.
1438
+ *
1439
+ * `GET /v1/workspaces/{workspace_id}/webhooks/subscriptions/{subscription_id}`
1440
+ * (GetWorkspaceWebhookSubscription)
1441
+ */
1442
+ getSubscription(e, r, s) {
1443
+ return this.core.request({ host: "api", method: "GET", path: `/v1/workspaces/${n(e)}/webhooks/subscriptions/${n(r)}` }, s);
1444
+ }
1445
+ /**
1446
+ * List a workspace webhook's deliveries.
1447
+ *
1448
+ * The webhook's delivery attempts, walked by cursor as the events are. latest=true keeps each event's
1449
+ * newest attempt: one row per event. Needs workspace:webhooks.read.
1450
+ *
1451
+ * `GET /v1/workspaces/{workspace_id}/webhooks/subscriptions/{subscription_id}/deliveries`
1452
+ * (ListWorkspaceWebhookDeliveries)
1453
+ *
1454
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
1455
+ */
1456
+ listDeliveries(e, r, s, o) {
1457
+ return this.core.page("cursor", { host: "api", method: "GET", path: `/v1/workspaces/${n(e)}/webhooks/subscriptions/${n(r)}/deliveries`, query: s }, o);
1458
+ }
1459
+ /**
1460
+ * List the workspace's webhook event types.
1461
+ *
1462
+ * The workspace catalog: the events a workspace's webhook can subscribe to, the webhook meta-events
1463
+ * among them. Needs workspace:webhooks.read.
1464
+ *
1465
+ * `GET /v1/workspaces/{workspace_id}/webhooks/event-types` (ListWorkspaceWebhookEventTypes)
1466
+ *
1467
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
1468
+ */
1469
+ listEventTypes(e, r, s) {
1470
+ return this.core.page("page", { host: "api", method: "GET", path: `/v1/workspaces/${n(e)}/webhooks/event-types`, query: r }, s);
1471
+ }
1472
+ /**
1473
+ * List the workspace's events.
1474
+ *
1475
+ * The workspace's events, walked by cursor: newest first, next_cursor passed as before to page back,
1476
+ * null at the end, or as after to poll for what was created since, oldest first. Needs
1477
+ * workspace:webhooks.read.
1478
+ *
1479
+ * `GET /v1/workspaces/{workspace_id}/webhooks/events` (ListWorkspaceWebhookEvents)
1480
+ *
1481
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
1482
+ */
1483
+ listEvents(e, r, s) {
1484
+ return this.core.page("cursor", { host: "api", method: "GET", path: `/v1/workspaces/${n(e)}/webhooks/events`, query: r }, s);
1485
+ }
1486
+ /**
1487
+ * List the workspace's webhooks.
1488
+ *
1489
+ * Needs workspace:webhooks.read.
1490
+ *
1491
+ * `GET /v1/workspaces/{workspace_id}/webhooks/subscriptions` (ListWorkspaceWebhookSubscriptions)
1492
+ *
1493
+ * Await it for the first page, or iterate it with `for await` for every item across pages.
1494
+ */
1495
+ listSubscriptions(e, r, s) {
1496
+ return this.core.page("page", { host: "api", method: "GET", path: `/v1/workspaces/${n(e)}/webhooks/subscriptions`, query: r }, s);
1497
+ }
1498
+ /**
1499
+ * Pause a workspace webhook.
1500
+ *
1501
+ * Stop delivering without losing the configuration. Needs workspace:webhooks.manage.
1502
+ *
1503
+ * `POST /v1/workspaces/{workspace_id}/webhooks/subscriptions/{subscription_id}/pause`
1504
+ * (PauseWorkspaceWebhookSubscription)
1505
+ */
1506
+ pauseSubscription(e, r, s) {
1507
+ return this.core.request({ host: "api", method: "POST", path: `/v1/workspaces/${n(e)}/webhooks/subscriptions/${n(r)}/pause` }, s);
1508
+ }
1509
+ /**
1510
+ * Resume a workspace webhook.
1511
+ *
1512
+ * Reactivate a paused, failing or disabled webhook. Needs workspace:webhooks.manage.
1513
+ *
1514
+ * `POST /v1/workspaces/{workspace_id}/webhooks/subscriptions/{subscription_id}/resume`
1515
+ * (ResumeWorkspaceWebhookSubscription)
1516
+ */
1517
+ resumeSubscription(e, r, s) {
1518
+ return this.core.request({ host: "api", method: "POST", path: `/v1/workspaces/${n(e)}/webhooks/subscriptions/${n(r)}/resume` }, s);
1519
+ }
1520
+ /**
1521
+ * Resend a workspace webhook's delivery.
1522
+ *
1523
+ * Resend the event from its newest attempt. A failed, errored or succeeded attempt gets a fresh
1524
+ * attempt sent now; a pending one, a scheduled retry, is sent now instead of at its due time. An
1525
+ * attempt being sent, or one that already has a successor, answers 409. Needs
1526
+ * workspace:webhooks.manage.
1527
+ *
1528
+ * `POST
1529
+ * /v1/workspaces/{workspace_id}/webhooks/subscriptions/{subscription_id}/deliveries/{delivery_id}/retry`
1530
+ * (RetryWorkspaceWebhookDelivery)
1531
+ */
1532
+ retryDelivery(e, r, s, o) {
1533
+ return this.core.request({ host: "api", method: "POST", path: `/v1/workspaces/${n(e)}/webhooks/subscriptions/${n(r)}/deliveries/${n(s)}/retry` }, o);
1534
+ }
1535
+ /**
1536
+ * Rotate a workspace webhook's signing secret.
1537
+ *
1538
+ * Mint a new signing secret, answered only here. The previous secret keeps signing beside it for
1539
+ * expire_previous_in seconds: 0 to 604800, 86400 by default, 0 ending it now. Needs
1540
+ * workspace:webhooks.manage.
1541
+ *
1542
+ * `POST /v1/workspaces/{workspace_id}/webhooks/subscriptions/{subscription_id}/rotate-secret`
1543
+ * (RotateWorkspaceWebhookSecret)
1544
+ */
1545
+ rotateSecret(e, r, s, o) {
1546
+ return this.core.request({ host: "api", method: "POST", path: `/v1/workspaces/${n(e)}/webhooks/subscriptions/${n(r)}/rotate-secret`, body: s }, o);
1547
+ }
1548
+ /**
1549
+ * Update a workspace webhook.
1550
+ *
1551
+ * Change url, description, event_types, headers or metadata. Needs workspace:webhooks.manage.
1552
+ *
1553
+ * `PATCH /v1/workspaces/{workspace_id}/webhooks/subscriptions/{subscription_id}`
1554
+ * (UpdateWorkspaceWebhookSubscription)
1555
+ */
1556
+ updateSubscription(e, r, s, o) {
1557
+ return this.core.request({ host: "api", method: "PATCH", path: `/v1/workspaces/${n(e)}/webhooks/subscriptions/${n(r)}`, body: s }, o);
1558
+ }
1559
+ }
1560
+ const Tt = "https://api.pontive.com", j = (t) => t && t.trim() ? t.trim() : void 0;
1561
+ function bt() {
1562
+ const t = globalThis;
1563
+ return typeof t.window < "u" && typeof t.document < "u";
1564
+ }
1565
+ class Rt extends vt {
1566
+ constructor(e = {}) {
1567
+ const r = e.env ?? se(), s = e.workspaceKey ?? (e.token ? void 0 : j(r.PONTIVE_WORKSPACE_KEY)), o = e.token ?? (s ? void 0 : j(r.PONTIVE_ACCESS_TOKEN));
1568
+ if (!s && !o)
1569
+ throw new Error(
1570
+ "pontive: no credential: pass workspaceKey or token, or set PONTIVE_WORKSPACE_KEY or PONTIVE_ACCESS_TOKEN"
1571
+ );
1572
+ if (bt())
1573
+ throw new Error("pontive: a workspace secret key or personal access token must never reach a browser; call the platform API from your server");
1574
+ const a = { api: xe(e.platformUrl ?? j(r.PONTIVE_PLATFORM_URL) ?? Tt), authz: "", ingest: "", auth: "" }, p = s ?? o;
1575
+ super(
1576
+ new ye({
1577
+ hosts: a,
1578
+ token: async () => typeof p == "function" ? p() : p,
1579
+ invalidate: () => !1,
1580
+ maxRetries: Math.max(e.maxRetries ?? 2, 0),
1581
+ timeout: e.timeout ?? 6e4,
1582
+ fetch: e.fetch ?? globalThis.fetch.bind(globalThis)
1583
+ })
1584
+ );
1585
+ }
1586
+ }
657
1587
  export {
658
- De as ACCESS_COOKIE,
659
- lt as CLAIM_ROUTE,
660
- He as ORGANIZATION_ERROR_PARAM,
661
- yt as PONTIVE_ENV,
662
- ct as PONTIVE_SERVER_VERSION,
663
- gt as Pontive,
664
- Et as PontiveAPIError,
665
- _t as PontiveConnectionError,
1588
+ ze as ACCESS_COOKIE,
1589
+ dt as CLAIM_ROUTE,
1590
+ Ve as ORGANIZATION_ERROR_PARAM,
1591
+ Tt as PLATFORM_URL,
1592
+ Lt as PONTIVE_ENV,
1593
+ lt as PONTIVE_SERVER_VERSION,
1594
+ Nt as Pontive,
1595
+ xt as PontiveAPIError,
1596
+ Gt as PontiveConnectionError,
1597
+ Rt as PontivePlatform,
666
1598
  Fe as SESSION_HINT_COOKIE,
667
- H as SWITCH_ORGANIZATION_ROUTE,
668
- vt as createServerAuth,
669
- mt as switchOrganizationPath
1599
+ D as SWITCH_ORGANIZATION_ROUTE,
1600
+ Ct as createServerAuth,
1601
+ Ot as switchOrganizationPath
670
1602
  };
671
1603
  //# sourceMappingURL=index.js.map