@replicated/portal-components 0.0.23 → 0.0.25
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/components/metadata/registry.json +2 -2
- package/components/metadata/registry.md +2 -2
- package/dist/actions/branding-actions.d.mts +7 -0
- package/dist/actions/branding-actions.d.ts +7 -0
- package/dist/actions/branding-actions.js +394 -0
- package/dist/actions/branding-actions.js.map +1 -0
- package/dist/actions/index.js +0 -3
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/invite-actions.d.mts +13 -0
- package/dist/actions/invite-actions.d.ts +13 -0
- package/dist/actions/invite-actions.js +527 -0
- package/dist/actions/invite-actions.js.map +1 -0
- package/dist/actions/magic-link-actions.d.mts +8 -0
- package/dist/actions/magic-link-actions.d.ts +8 -0
- package/dist/actions/magic-link-actions.js +478 -0
- package/dist/actions/magic-link-actions.js.map +1 -0
- package/dist/actions/trial-signup-actions.d.mts +7 -0
- package/dist/actions/trial-signup-actions.d.ts +7 -0
- package/dist/actions/trial-signup-actions.js +546 -0
- package/dist/actions/trial-signup-actions.js.map +1 -0
- package/dist/esm/actions/branding-actions.js +392 -0
- package/dist/esm/actions/branding-actions.js.map +1 -0
- package/dist/esm/actions/index.js +0 -3
- package/dist/esm/actions/index.js.map +1 -1
- package/dist/esm/actions/invite-actions.js +524 -0
- package/dist/esm/actions/invite-actions.js.map +1 -0
- package/dist/esm/actions/magic-link-actions.js +476 -0
- package/dist/esm/actions/magic-link-actions.js.map +1 -0
- package/dist/esm/actions/trial-signup-actions.js +544 -0
- package/dist/esm/actions/trial-signup-actions.js.map +1 -0
- package/dist/esm/index.js +2 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/logout-action.js +2 -3
- package/dist/esm/logout-action.js.map +1 -1
- package/dist/esm/logout-button.js +10 -7
- package/dist/esm/logout-button.js.map +1 -1
- package/dist/esm/use-verify-magic-link.js +74 -0
- package/dist/esm/use-verify-magic-link.js.map +1 -0
- package/dist/esm/utils/index.js +1 -6
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -7
- package/dist/index.js.map +1 -1
- package/dist/logout-action.d.mts +5 -2
- package/dist/logout-action.d.ts +5 -2
- package/dist/logout-action.js +2 -3
- package/dist/logout-action.js.map +1 -1
- package/dist/logout-button.d.mts +4 -1
- package/dist/logout-button.d.ts +4 -1
- package/dist/logout-button.js +10 -7
- package/dist/logout-button.js.map +1 -1
- package/dist/use-verify-magic-link.d.mts +34 -0
- package/dist/use-verify-magic-link.d.ts +34 -0
- package/dist/use-verify-magic-link.js +76 -0
- package/dist/use-verify-magic-link.js.map +1 -0
- package/dist/utils/index.d.mts +1 -16
- package/dist/utils/index.d.ts +1 -16
- package/dist/utils/index.js +0 -6
- package/dist/utils/index.js.map +1 -1
- package/package.json +32 -2
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { cookies } from 'next/headers';
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
4
|
+
import { cache } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Enterprise Portal Components
|
|
8
|
+
* This file is generated by tsup. Do not edit manually.
|
|
9
|
+
*/
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
15
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
16
|
+
}) : x)(function(x) {
|
|
17
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
18
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
19
|
+
});
|
|
20
|
+
var __esm = (fn, res) => function __init() {
|
|
21
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
22
|
+
};
|
|
23
|
+
var __export = (target, all) => {
|
|
24
|
+
for (var name in all)
|
|
25
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
|
|
37
|
+
// datadog/tracer.ts
|
|
38
|
+
var tracer_exports = {};
|
|
39
|
+
__export(tracer_exports, {
|
|
40
|
+
default: () => tracer_default
|
|
41
|
+
});
|
|
42
|
+
var rawFlag, isEnabled, tracer, getRoutePattern, tracer_default;
|
|
43
|
+
var init_tracer = __esm({
|
|
44
|
+
"datadog/tracer.ts"() {
|
|
45
|
+
rawFlag = String(process.env.USE_DATADOG_APM || "").toLowerCase();
|
|
46
|
+
isEnabled = rawFlag === "true";
|
|
47
|
+
process.env.DD_TRACE_ENABLED = isEnabled ? "1" : "0";
|
|
48
|
+
tracer = null;
|
|
49
|
+
if (isEnabled) {
|
|
50
|
+
const serviceName = process.env.DD_SERVICE || "enterprise-portal";
|
|
51
|
+
const environment = process.env.DD_ENV || process.env.NODE_ENV || "development";
|
|
52
|
+
const version = process.env.DD_VERSION || process.env.NEXT_PUBLIC_VERSION || "0.0.0-dev";
|
|
53
|
+
const agentHost = process.env.DD_AGENT_HOST || process.env.DATADOG_AGENT_HOST || "127.0.0.1";
|
|
54
|
+
const agentPort = process.env.DD_TRACE_AGENT_PORT || "8126";
|
|
55
|
+
process.env.DD_SERVICE = serviceName;
|
|
56
|
+
process.env.DD_ENV = environment;
|
|
57
|
+
{
|
|
58
|
+
process.env.DD_VERSION = version;
|
|
59
|
+
}
|
|
60
|
+
process.env.DD_AGENT_HOST = agentHost;
|
|
61
|
+
process.env.DD_TRACE_AGENT_PORT = agentPort;
|
|
62
|
+
const dbmPropagationMode = process.env.DD_DBM_PROPAGATION_MODE || "full";
|
|
63
|
+
process.env.DD_DBM_PROPAGATION_MODE = dbmPropagationMode;
|
|
64
|
+
try {
|
|
65
|
+
const ddTrace = __require("dd-trace");
|
|
66
|
+
tracer = ddTrace.init({
|
|
67
|
+
service: serviceName,
|
|
68
|
+
env: environment,
|
|
69
|
+
version,
|
|
70
|
+
logInjection: true,
|
|
71
|
+
runtimeMetrics: true,
|
|
72
|
+
appsec: false,
|
|
73
|
+
profiling: false,
|
|
74
|
+
startupLogs: true
|
|
75
|
+
// Enable for debugging
|
|
76
|
+
});
|
|
77
|
+
console.log(`[datadog] Tracer initialized: service=${serviceName}, env=${environment}, version=${version}, agent=${agentHost}:${agentPort}`);
|
|
78
|
+
tracer.use("dns", false);
|
|
79
|
+
tracer.use("net", false);
|
|
80
|
+
tracer.use("http", {
|
|
81
|
+
server: {
|
|
82
|
+
hooks: {
|
|
83
|
+
request: (span, req) => {
|
|
84
|
+
if (!span) return;
|
|
85
|
+
const url = req?.url || "";
|
|
86
|
+
const method = req?.method || "GET";
|
|
87
|
+
const path = url.split("?")[0];
|
|
88
|
+
if (path.startsWith("/_next/")) {
|
|
89
|
+
span.context()._trace.isRecording = false;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const routePattern = getRoutePattern(path);
|
|
93
|
+
span.setTag("resource.name", `${method} ${routePattern}`);
|
|
94
|
+
span.setTag("http.route", routePattern);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
} catch (err) {
|
|
100
|
+
console.error("[datadog] failed to initialize tracing", err);
|
|
101
|
+
tracer = null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
getRoutePattern = (path) => {
|
|
105
|
+
const routePatterns = [
|
|
106
|
+
// Update instance routes - normalize dynamic segments (capture suffix to preserve sub-routes)
|
|
107
|
+
{ pattern: /^\/update\/instance\/[^/]+(.*)$/, replacement: "/update/instance/[instanceId]$1" }
|
|
108
|
+
];
|
|
109
|
+
for (const { pattern, replacement } of routePatterns) {
|
|
110
|
+
if (pattern.test(path)) {
|
|
111
|
+
return path.replace(pattern, replacement);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return path;
|
|
115
|
+
};
|
|
116
|
+
tracer_default = tracer;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// src/utils/observability/tracing.ts
|
|
121
|
+
var tracerCache = void 0;
|
|
122
|
+
function getTracer() {
|
|
123
|
+
if (tracerCache !== void 0) {
|
|
124
|
+
return tracerCache;
|
|
125
|
+
}
|
|
126
|
+
const rawFlag2 = String(process.env.USE_DATADOG_APM || "").toLowerCase();
|
|
127
|
+
const isEnabled2 = rawFlag2 === "true";
|
|
128
|
+
if (!isEnabled2) {
|
|
129
|
+
tracerCache = null;
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const tracerModule = (init_tracer(), __toCommonJS(tracer_exports));
|
|
134
|
+
const tracer2 = tracerModule.default || tracerModule;
|
|
135
|
+
if (tracer2 && typeof tracer2.trace === "function") {
|
|
136
|
+
tracerCache = tracer2;
|
|
137
|
+
return tracerCache;
|
|
138
|
+
}
|
|
139
|
+
} catch (err) {
|
|
140
|
+
console.warn("Failed to load tracer:", err);
|
|
141
|
+
}
|
|
142
|
+
tracerCache = null;
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
async function withTrace(name, fn) {
|
|
146
|
+
const activeTracer = getTracer();
|
|
147
|
+
if (!activeTracer) {
|
|
148
|
+
return fn(void 0);
|
|
149
|
+
}
|
|
150
|
+
return activeTracer.trace(name, async (span) => {
|
|
151
|
+
if (span) {
|
|
152
|
+
span.setTag("component", "application");
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
const result = await fn(span);
|
|
156
|
+
return result;
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if (span) {
|
|
159
|
+
span.setTag("error", error);
|
|
160
|
+
}
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
function traceServerAction(name, fn) {
|
|
166
|
+
const spanName = name.startsWith("server.action.") ? name : `server.action.${name}`;
|
|
167
|
+
const traced = async (...args) => {
|
|
168
|
+
return withTrace(spanName, async (span) => {
|
|
169
|
+
if (span) {
|
|
170
|
+
span.setTag("component", "server-action");
|
|
171
|
+
}
|
|
172
|
+
const result = await fn(...args);
|
|
173
|
+
return result;
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
return traced;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/utils/api-client.ts
|
|
180
|
+
async function authenticatedFetch(url, options = {}) {
|
|
181
|
+
const { token, ...fetchOptions } = options;
|
|
182
|
+
const headers = new Headers(fetchOptions.headers);
|
|
183
|
+
if (token) {
|
|
184
|
+
headers.set("authorization", `Bearer ${token}`);
|
|
185
|
+
}
|
|
186
|
+
const response = await fetch(url, {
|
|
187
|
+
...fetchOptions,
|
|
188
|
+
headers
|
|
189
|
+
});
|
|
190
|
+
if (response.status === 401) {
|
|
191
|
+
await handle401();
|
|
192
|
+
}
|
|
193
|
+
if (response.status === 502 || response.status === 503 || response.status === 504) {
|
|
194
|
+
await handleServerError(response.status);
|
|
195
|
+
}
|
|
196
|
+
return response;
|
|
197
|
+
}
|
|
198
|
+
async function handle401() {
|
|
199
|
+
const { redirect } = await import('next/navigation');
|
|
200
|
+
return redirect("/?expired=1");
|
|
201
|
+
}
|
|
202
|
+
function isErrorPage(url) {
|
|
203
|
+
try {
|
|
204
|
+
const urlObj = new URL(url);
|
|
205
|
+
return urlObj.pathname === "/error";
|
|
206
|
+
} catch {
|
|
207
|
+
return url === "/error" || url.startsWith("/error?");
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async function handleServerError(statusCode) {
|
|
211
|
+
const { redirect } = await import('next/navigation');
|
|
212
|
+
const { cookies: cookies2 } = await import('next/headers');
|
|
213
|
+
let sourceUrl;
|
|
214
|
+
try {
|
|
215
|
+
const { headers } = await import('next/headers');
|
|
216
|
+
const headersList = await headers();
|
|
217
|
+
const referer = headersList.get("referer");
|
|
218
|
+
const host = headersList.get("host");
|
|
219
|
+
const pathname = headersList.get("x-invoke-path") || headersList.get("x-forwarded-path");
|
|
220
|
+
if (referer && !isErrorPage(referer)) {
|
|
221
|
+
sourceUrl = referer;
|
|
222
|
+
} else if (host && pathname) {
|
|
223
|
+
const protocol = headersList.get("x-forwarded-proto") || "https";
|
|
224
|
+
sourceUrl = `${protocol}://${host}${pathname}`;
|
|
225
|
+
}
|
|
226
|
+
if (!sourceUrl || isErrorPage(sourceUrl)) {
|
|
227
|
+
const cookieStore = await cookies2();
|
|
228
|
+
const preservedSource = cookieStore.get("portal_error_source");
|
|
229
|
+
if (preservedSource?.value) {
|
|
230
|
+
sourceUrl = decodeURIComponent(preservedSource.value);
|
|
231
|
+
cookieStore.delete("portal_error_source");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
} catch (error) {
|
|
235
|
+
console.debug("[portal-components] Could not determine source URL", error);
|
|
236
|
+
}
|
|
237
|
+
const params = new URLSearchParams({ code: String(statusCode) });
|
|
238
|
+
if (sourceUrl) {
|
|
239
|
+
params.set("source", sourceUrl);
|
|
240
|
+
}
|
|
241
|
+
return redirect(`/error?${params.toString()}`);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// src/utils/constants.ts
|
|
245
|
+
var isHttpApiOrigin = () => {
|
|
246
|
+
return process.env.REPLICATED_APP_ORIGIN?.startsWith("http://") || false;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// src/actions/index.ts
|
|
250
|
+
var getApiOrigin = () => {
|
|
251
|
+
return (process.env.REPLICATED_APP_ORIGIN || "https://replicated.app").replace(/\/+$/, "");
|
|
252
|
+
};
|
|
253
|
+
var defineServerAction = (definition) => definition;
|
|
254
|
+
var fetchCustomBrandingImpl = async () => {
|
|
255
|
+
const appSlug = process.env.PORTAL_APP_SLUG;
|
|
256
|
+
if (!appSlug) {
|
|
257
|
+
throw new Error("PORTAL_APP_SLUG is not configured");
|
|
258
|
+
}
|
|
259
|
+
const url = `${getApiOrigin()}/enterprise-portal/public/branding?app_slug=${encodeURIComponent(
|
|
260
|
+
appSlug
|
|
261
|
+
)}`;
|
|
262
|
+
if (process.env.NODE_ENV !== "production") {
|
|
263
|
+
console.debug(
|
|
264
|
+
"[portal-components] fetching custom branding via %s (Enterprise Portal API)",
|
|
265
|
+
url
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
const response = await fetch(url, {
|
|
269
|
+
headers: {
|
|
270
|
+
accept: "application/json"
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
if (!response.ok) {
|
|
274
|
+
throw new Error(
|
|
275
|
+
`Custom branding request failed (${response.status} ${response.statusText})`
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
const payload = await response.json();
|
|
279
|
+
const brandingObject = {
|
|
280
|
+
logo: payload.logoUrl,
|
|
281
|
+
title: payload.title,
|
|
282
|
+
primaryColor: payload.primaryColor,
|
|
283
|
+
secondaryColor: payload.secondaryColor,
|
|
284
|
+
favicon: payload.faviconUrl,
|
|
285
|
+
supportPortalLink: payload.supportPortalLink || "",
|
|
286
|
+
background: payload.background,
|
|
287
|
+
backgroundImage: payload.backgroundImage,
|
|
288
|
+
customColor1: payload.customColor1,
|
|
289
|
+
customColor2: payload.customColor2
|
|
290
|
+
};
|
|
291
|
+
const brandingData = Buffer.from(JSON.stringify(brandingObject)).toString("base64");
|
|
292
|
+
return {
|
|
293
|
+
brandingData,
|
|
294
|
+
documentation: null
|
|
295
|
+
// Documentation not included in new API's public endpoint
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
cache(fetchCustomBrandingImpl);
|
|
299
|
+
async function listReleasesImpl() {
|
|
300
|
+
const { cookies: cookies2 } = await import('next/headers');
|
|
301
|
+
const sessionStore = await cookies2();
|
|
302
|
+
const session = sessionStore.get("portal_session");
|
|
303
|
+
const token = session?.value;
|
|
304
|
+
if (!token) {
|
|
305
|
+
throw new Error("List releases requires a session token");
|
|
306
|
+
}
|
|
307
|
+
const endpoint = `${getApiOrigin()}/enterprise-portal/releases`;
|
|
308
|
+
if (process.env.NODE_ENV !== "production") {
|
|
309
|
+
console.debug("[portal-components] fetching releases via %s (Enterprise Portal API)", endpoint);
|
|
310
|
+
}
|
|
311
|
+
const response = await authenticatedFetch(endpoint, {
|
|
312
|
+
method: "GET",
|
|
313
|
+
token,
|
|
314
|
+
headers: {
|
|
315
|
+
accept: "application/json"
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
if (!response.ok) {
|
|
319
|
+
throw new Error(
|
|
320
|
+
`List releases request failed (${response.status} ${response.statusText})`
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
const envelope = await response.json();
|
|
324
|
+
const data = envelope.data;
|
|
325
|
+
return {
|
|
326
|
+
releases: Array.isArray(data?.releases) ? data.releases : [],
|
|
327
|
+
totalCount: data?.totalCount || 0
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
traceServerAction("listReleases", listReleasesImpl);
|
|
331
|
+
var acceptInvite = defineServerAction({
|
|
332
|
+
id: "auth/accept-invite",
|
|
333
|
+
description: "Accepts a team invitation and returns a session token",
|
|
334
|
+
visibility: "customer",
|
|
335
|
+
tags: ["auth", "invite", "join"],
|
|
336
|
+
async run({ code }) {
|
|
337
|
+
if (!code || typeof code !== "string") {
|
|
338
|
+
const error = {
|
|
339
|
+
code: "invalid_code",
|
|
340
|
+
message: "Invite code is required"
|
|
341
|
+
};
|
|
342
|
+
throw error;
|
|
343
|
+
}
|
|
344
|
+
const endpoint = `${getApiOrigin()}/enterprise-portal/auth/invite/accept`;
|
|
345
|
+
if (process.env.NODE_ENV !== "production") {
|
|
346
|
+
console.debug("[portal-components] accepting invite via %s (Enterprise Portal API)", endpoint);
|
|
347
|
+
}
|
|
348
|
+
const response = await fetch(endpoint, {
|
|
349
|
+
method: "POST",
|
|
350
|
+
headers: {
|
|
351
|
+
"content-type": "application/json",
|
|
352
|
+
accept: "application/json"
|
|
353
|
+
},
|
|
354
|
+
body: JSON.stringify({ code })
|
|
355
|
+
});
|
|
356
|
+
if (!response.ok) {
|
|
357
|
+
if (response.status === 404) {
|
|
358
|
+
const error2 = {
|
|
359
|
+
code: "invalid_code",
|
|
360
|
+
message: "Invalid or expired invite code. Please check your code and try again."
|
|
361
|
+
};
|
|
362
|
+
throw error2;
|
|
363
|
+
}
|
|
364
|
+
let errorMessage = "Failed to accept invitation";
|
|
365
|
+
try {
|
|
366
|
+
const data = await response.json();
|
|
367
|
+
errorMessage = data.message || data.error || errorMessage;
|
|
368
|
+
} catch {
|
|
369
|
+
}
|
|
370
|
+
const error = {
|
|
371
|
+
code: "unknown",
|
|
372
|
+
message: errorMessage
|
|
373
|
+
};
|
|
374
|
+
throw error;
|
|
375
|
+
}
|
|
376
|
+
const payload = await response.json();
|
|
377
|
+
const token = payload?.jwt ?? payload?.token;
|
|
378
|
+
if (typeof token !== "string") {
|
|
379
|
+
throw new Error("Invite accepted but no token returned");
|
|
380
|
+
}
|
|
381
|
+
return { token };
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
var refreshInvite = defineServerAction({
|
|
385
|
+
id: "auth/refresh-invite",
|
|
386
|
+
description: "Refreshes an expired invite and resends the invitation email",
|
|
387
|
+
visibility: "customer",
|
|
388
|
+
tags: ["auth", "invite", "refresh"],
|
|
389
|
+
async run({ code }) {
|
|
390
|
+
if (!code || typeof code !== "string") {
|
|
391
|
+
throw new Error("Invite code is required");
|
|
392
|
+
}
|
|
393
|
+
const endpoint = `${getApiOrigin()}/enterprise-portal/auth/invite/refresh`;
|
|
394
|
+
if (process.env.NODE_ENV !== "production") {
|
|
395
|
+
console.debug("[portal-components] refreshing invite via %s (Enterprise Portal API)", endpoint);
|
|
396
|
+
}
|
|
397
|
+
const response = await fetch(endpoint, {
|
|
398
|
+
method: "POST",
|
|
399
|
+
headers: {
|
|
400
|
+
"content-type": "application/json",
|
|
401
|
+
accept: "application/json"
|
|
402
|
+
},
|
|
403
|
+
body: JSON.stringify({ code })
|
|
404
|
+
});
|
|
405
|
+
if (!response.ok) {
|
|
406
|
+
let errorMessage = "Failed to refresh invitation";
|
|
407
|
+
try {
|
|
408
|
+
const data = await response.json();
|
|
409
|
+
errorMessage = data.message || data.error || errorMessage;
|
|
410
|
+
} catch {
|
|
411
|
+
}
|
|
412
|
+
throw new Error(errorMessage);
|
|
413
|
+
}
|
|
414
|
+
return { success: true };
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
var fetchDocumentationImpl = async () => {
|
|
418
|
+
const { cookies: cookies2 } = await import('next/headers');
|
|
419
|
+
const sessionStore = await cookies2();
|
|
420
|
+
const session = sessionStore.get("portal_session");
|
|
421
|
+
const token = session?.value;
|
|
422
|
+
if (!token) {
|
|
423
|
+
throw new Error("Authentication required");
|
|
424
|
+
}
|
|
425
|
+
const url = `${getApiOrigin()}/enterprise-portal/documentation`;
|
|
426
|
+
if (process.env.NODE_ENV !== "production") {
|
|
427
|
+
console.debug(
|
|
428
|
+
"[portal-components] fetching documentation via %s (Enterprise Portal API)",
|
|
429
|
+
url
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
const response = await authenticatedFetch(url, {
|
|
433
|
+
method: "GET",
|
|
434
|
+
token,
|
|
435
|
+
headers: {
|
|
436
|
+
accept: "application/json"
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
if (!response.ok) {
|
|
440
|
+
throw new Error(
|
|
441
|
+
`Documentation request failed (${response.status} ${response.statusText})`
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
const data = await response.json();
|
|
445
|
+
return {
|
|
446
|
+
helmPreInstall: data.helmPreInstall || "",
|
|
447
|
+
helmPostInstall: data.helmPostInstall || "",
|
|
448
|
+
embeddedClusterPreInstall: data.embeddedClusterPreInstall || "",
|
|
449
|
+
embeddedClusterPostInstall: data.embeddedClusterPostInstall || "",
|
|
450
|
+
helmInstallUrl: data.helmInstallUrl || "",
|
|
451
|
+
embeddedClusterInstallUrl: data.embeddedClusterInstallUrl || "",
|
|
452
|
+
valuesOverrideUrl: data.valuesOverrideUrl || ""
|
|
453
|
+
};
|
|
454
|
+
};
|
|
455
|
+
cache(fetchDocumentationImpl);
|
|
456
|
+
|
|
457
|
+
// src/actions/invite-actions.ts
|
|
458
|
+
async function acceptInviteWithCookieImpl(code) {
|
|
459
|
+
try {
|
|
460
|
+
const result = await acceptInvite.run({ code });
|
|
461
|
+
const cookieStore = await cookies();
|
|
462
|
+
const secure = true;
|
|
463
|
+
const sameSiteValue = isHttpApiOrigin() ? "none" : "lax";
|
|
464
|
+
cookieStore.set("portal_session", result.token, {
|
|
465
|
+
httpOnly: true,
|
|
466
|
+
secure,
|
|
467
|
+
sameSite: sameSiteValue,
|
|
468
|
+
path: "/"
|
|
469
|
+
});
|
|
470
|
+
return { success: true };
|
|
471
|
+
} catch (error) {
|
|
472
|
+
console.error("[invite-actions] acceptInvite error:", error);
|
|
473
|
+
if (typeof error === "object" && error !== null && "code" in error) {
|
|
474
|
+
const typedError = error;
|
|
475
|
+
if (typedError.code === "expired") {
|
|
476
|
+
return {
|
|
477
|
+
success: false,
|
|
478
|
+
message: typedError.message || "Invite has expired",
|
|
479
|
+
isExpired: true
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
if (typedError.code === "invalid_code") {
|
|
483
|
+
return {
|
|
484
|
+
success: false,
|
|
485
|
+
message: typedError.message || "Invalid or expired code"
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (typeof error === "object" && error !== null && "message" in error && typeof error.message === "string") {
|
|
490
|
+
return {
|
|
491
|
+
success: false,
|
|
492
|
+
message: error.message
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
return {
|
|
496
|
+
success: false,
|
|
497
|
+
message: "Failed to accept invite. Please try again."
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
async function refreshInviteActionImpl(code) {
|
|
502
|
+
try {
|
|
503
|
+
await refreshInvite.run({ code });
|
|
504
|
+
return { success: true };
|
|
505
|
+
} catch (error) {
|
|
506
|
+
console.error("[invite-actions] refreshInvite error:", error);
|
|
507
|
+
if (typeof error === "object" && error !== null && "message" in error && typeof error.message === "string") {
|
|
508
|
+
return {
|
|
509
|
+
success: false,
|
|
510
|
+
message: error.message
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
return {
|
|
514
|
+
success: false,
|
|
515
|
+
message: "Failed to refresh invite. Please try again."
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
var acceptInviteWithCookie = traceServerAction("acceptInviteWithCookie", acceptInviteWithCookieImpl);
|
|
520
|
+
var refreshInviteAction = traceServerAction("refreshInviteAction", refreshInviteActionImpl);
|
|
521
|
+
|
|
522
|
+
export { acceptInviteWithCookie, refreshInviteAction };
|
|
523
|
+
//# sourceMappingURL=invite-actions.js.map
|
|
524
|
+
//# sourceMappingURL=invite-actions.js.map
|