@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.
Files changed (61) hide show
  1. package/components/metadata/registry.json +2 -2
  2. package/components/metadata/registry.md +2 -2
  3. package/dist/actions/branding-actions.d.mts +7 -0
  4. package/dist/actions/branding-actions.d.ts +7 -0
  5. package/dist/actions/branding-actions.js +394 -0
  6. package/dist/actions/branding-actions.js.map +1 -0
  7. package/dist/actions/index.js +0 -3
  8. package/dist/actions/index.js.map +1 -1
  9. package/dist/actions/invite-actions.d.mts +13 -0
  10. package/dist/actions/invite-actions.d.ts +13 -0
  11. package/dist/actions/invite-actions.js +527 -0
  12. package/dist/actions/invite-actions.js.map +1 -0
  13. package/dist/actions/magic-link-actions.d.mts +8 -0
  14. package/dist/actions/magic-link-actions.d.ts +8 -0
  15. package/dist/actions/magic-link-actions.js +478 -0
  16. package/dist/actions/magic-link-actions.js.map +1 -0
  17. package/dist/actions/trial-signup-actions.d.mts +7 -0
  18. package/dist/actions/trial-signup-actions.d.ts +7 -0
  19. package/dist/actions/trial-signup-actions.js +546 -0
  20. package/dist/actions/trial-signup-actions.js.map +1 -0
  21. package/dist/esm/actions/branding-actions.js +392 -0
  22. package/dist/esm/actions/branding-actions.js.map +1 -0
  23. package/dist/esm/actions/index.js +0 -3
  24. package/dist/esm/actions/index.js.map +1 -1
  25. package/dist/esm/actions/invite-actions.js +524 -0
  26. package/dist/esm/actions/invite-actions.js.map +1 -0
  27. package/dist/esm/actions/magic-link-actions.js +476 -0
  28. package/dist/esm/actions/magic-link-actions.js.map +1 -0
  29. package/dist/esm/actions/trial-signup-actions.js +544 -0
  30. package/dist/esm/actions/trial-signup-actions.js.map +1 -0
  31. package/dist/esm/index.js +2 -7
  32. package/dist/esm/index.js.map +1 -1
  33. package/dist/esm/logout-action.js +2 -3
  34. package/dist/esm/logout-action.js.map +1 -1
  35. package/dist/esm/logout-button.js +10 -7
  36. package/dist/esm/logout-button.js.map +1 -1
  37. package/dist/esm/use-verify-magic-link.js +74 -0
  38. package/dist/esm/use-verify-magic-link.js.map +1 -0
  39. package/dist/esm/utils/index.js +1 -6
  40. package/dist/esm/utils/index.js.map +1 -1
  41. package/dist/index.d.mts +1 -1
  42. package/dist/index.d.ts +1 -1
  43. package/dist/index.js +1 -7
  44. package/dist/index.js.map +1 -1
  45. package/dist/logout-action.d.mts +5 -2
  46. package/dist/logout-action.d.ts +5 -2
  47. package/dist/logout-action.js +2 -3
  48. package/dist/logout-action.js.map +1 -1
  49. package/dist/logout-button.d.mts +4 -1
  50. package/dist/logout-button.d.ts +4 -1
  51. package/dist/logout-button.js +10 -7
  52. package/dist/logout-button.js.map +1 -1
  53. package/dist/use-verify-magic-link.d.mts +34 -0
  54. package/dist/use-verify-magic-link.d.ts +34 -0
  55. package/dist/use-verify-magic-link.js +76 -0
  56. package/dist/use-verify-magic-link.js.map +1 -0
  57. package/dist/utils/index.d.mts +1 -16
  58. package/dist/utils/index.d.ts +1 -16
  59. package/dist/utils/index.js +0 -6
  60. package/dist/utils/index.js.map +1 -1
  61. package/package.json +32 -2
@@ -0,0 +1,544 @@
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 fetchCustomBrandingImpl = async () => {
254
+ const appSlug = process.env.PORTAL_APP_SLUG;
255
+ if (!appSlug) {
256
+ throw new Error("PORTAL_APP_SLUG is not configured");
257
+ }
258
+ const url = `${getApiOrigin()}/enterprise-portal/public/branding?app_slug=${encodeURIComponent(
259
+ appSlug
260
+ )}`;
261
+ if (process.env.NODE_ENV !== "production") {
262
+ console.debug(
263
+ "[portal-components] fetching custom branding via %s (Enterprise Portal API)",
264
+ url
265
+ );
266
+ }
267
+ const response = await fetch(url, {
268
+ headers: {
269
+ accept: "application/json"
270
+ }
271
+ });
272
+ if (!response.ok) {
273
+ throw new Error(
274
+ `Custom branding request failed (${response.status} ${response.statusText})`
275
+ );
276
+ }
277
+ const payload = await response.json();
278
+ const brandingObject = {
279
+ logo: payload.logoUrl,
280
+ title: payload.title,
281
+ primaryColor: payload.primaryColor,
282
+ secondaryColor: payload.secondaryColor,
283
+ favicon: payload.faviconUrl,
284
+ supportPortalLink: payload.supportPortalLink || "",
285
+ background: payload.background,
286
+ backgroundImage: payload.backgroundImage,
287
+ customColor1: payload.customColor1,
288
+ customColor2: payload.customColor2
289
+ };
290
+ const brandingData = Buffer.from(JSON.stringify(brandingObject)).toString("base64");
291
+ return {
292
+ brandingData,
293
+ documentation: null
294
+ // Documentation not included in new API's public endpoint
295
+ };
296
+ };
297
+ cache(fetchCustomBrandingImpl);
298
+ async function listReleasesImpl() {
299
+ const { cookies: cookies2 } = await import('next/headers');
300
+ const sessionStore = await cookies2();
301
+ const session = sessionStore.get("portal_session");
302
+ const token = session?.value;
303
+ if (!token) {
304
+ throw new Error("List releases requires a session token");
305
+ }
306
+ const endpoint = `${getApiOrigin()}/enterprise-portal/releases`;
307
+ if (process.env.NODE_ENV !== "production") {
308
+ console.debug("[portal-components] fetching releases via %s (Enterprise Portal API)", endpoint);
309
+ }
310
+ const response = await authenticatedFetch(endpoint, {
311
+ method: "GET",
312
+ token,
313
+ headers: {
314
+ accept: "application/json"
315
+ }
316
+ });
317
+ if (!response.ok) {
318
+ throw new Error(
319
+ `List releases request failed (${response.status} ${response.statusText})`
320
+ );
321
+ }
322
+ const envelope = await response.json();
323
+ const data = envelope.data;
324
+ return {
325
+ releases: Array.isArray(data?.releases) ? data.releases : [],
326
+ totalCount: data?.totalCount || 0
327
+ };
328
+ }
329
+ traceServerAction("listReleases", listReleasesImpl);
330
+ var fetchDocumentationImpl = async () => {
331
+ const { cookies: cookies2 } = await import('next/headers');
332
+ const sessionStore = await cookies2();
333
+ const session = sessionStore.get("portal_session");
334
+ const token = session?.value;
335
+ if (!token) {
336
+ throw new Error("Authentication required");
337
+ }
338
+ const url = `${getApiOrigin()}/enterprise-portal/documentation`;
339
+ if (process.env.NODE_ENV !== "production") {
340
+ console.debug(
341
+ "[portal-components] fetching documentation via %s (Enterprise Portal API)",
342
+ url
343
+ );
344
+ }
345
+ const response = await authenticatedFetch(url, {
346
+ method: "GET",
347
+ token,
348
+ headers: {
349
+ accept: "application/json"
350
+ }
351
+ });
352
+ if (!response.ok) {
353
+ throw new Error(
354
+ `Documentation request failed (${response.status} ${response.statusText})`
355
+ );
356
+ }
357
+ const data = await response.json();
358
+ return {
359
+ helmPreInstall: data.helmPreInstall || "",
360
+ helmPostInstall: data.helmPostInstall || "",
361
+ embeddedClusterPreInstall: data.embeddedClusterPreInstall || "",
362
+ embeddedClusterPostInstall: data.embeddedClusterPostInstall || "",
363
+ helmInstallUrl: data.helmInstallUrl || "",
364
+ embeddedClusterInstallUrl: data.embeddedClusterInstallUrl || "",
365
+ valuesOverrideUrl: data.valuesOverrideUrl || ""
366
+ };
367
+ };
368
+ cache(fetchDocumentationImpl);
369
+
370
+ // src/actions/trial-signup.ts
371
+ async function createTrialSignupImpl(payload) {
372
+ try {
373
+ const response = await fetch(
374
+ `${getApiOrigin()}/enterprise-portal/auth/trial/signup`,
375
+ {
376
+ method: "POST",
377
+ headers: {
378
+ "Content-Type": "application/json"
379
+ },
380
+ body: JSON.stringify({
381
+ app_slug: payload.appSlug,
382
+ company: payload.company,
383
+ email: payload.email
384
+ })
385
+ }
386
+ );
387
+ if (!response.ok) {
388
+ if (response.status === 403) {
389
+ return {
390
+ success: false,
391
+ error: "Trial signup is not enabled for this application."
392
+ };
393
+ }
394
+ if (response.status === 400) {
395
+ return {
396
+ success: false,
397
+ error: "Invalid request. Please check your information and try again."
398
+ };
399
+ }
400
+ return {
401
+ success: false,
402
+ error: "An error occurred. Please try again later."
403
+ };
404
+ }
405
+ const data = await response.json();
406
+ return { success: data.success };
407
+ } catch (error) {
408
+ console.error("Error creating trial signup:", error);
409
+ return {
410
+ success: false,
411
+ error: "Network error. Please try again later."
412
+ };
413
+ }
414
+ }
415
+ async function verifyTrialSignupImpl(code) {
416
+ try {
417
+ const response = await fetch(
418
+ `${getApiOrigin()}/enterprise-portal/auth/trial/signup/verify`,
419
+ {
420
+ method: "POST",
421
+ headers: {
422
+ "Content-Type": "application/json"
423
+ },
424
+ body: JSON.stringify({
425
+ code
426
+ })
427
+ }
428
+ );
429
+ if (!response.ok) {
430
+ if (response.status === 401) {
431
+ return {
432
+ success: false,
433
+ error: "Invalid or expired verification code. Please try again."
434
+ };
435
+ }
436
+ return {
437
+ success: false,
438
+ error: "An error occurred during verification. Please try again."
439
+ };
440
+ }
441
+ const data = await response.json();
442
+ const token = data.Body?.jwt || data.jwt;
443
+ if (!token) {
444
+ return {
445
+ success: false,
446
+ error: "Failed to create session. Please contact support."
447
+ };
448
+ }
449
+ const sessionStore = await cookies();
450
+ const secure = true;
451
+ const sameSiteValue = isHttpApiOrigin() ? "none" : "lax";
452
+ sessionStore.set("portal_session", token, {
453
+ httpOnly: true,
454
+ secure,
455
+ sameSite: sameSiteValue,
456
+ path: "/"
457
+ });
458
+ return {
459
+ success: true,
460
+ redirectUrl: "/"
461
+ // Redirect to home/dashboard
462
+ };
463
+ } catch (error) {
464
+ console.error("Error verifying trial signup:", error);
465
+ return {
466
+ success: false,
467
+ error: "Network error. Please try again later."
468
+ };
469
+ }
470
+ }
471
+ async function checkTrialSignupEnabledImpl(appSlug) {
472
+ try {
473
+ const params = new URLSearchParams({ app_slug: appSlug });
474
+ const url = `${getApiOrigin()}/enterprise-portal/public/app-features?${params.toString()}`;
475
+ if (process.env.NODE_ENV !== "production") {
476
+ console.debug("[portal-components] fetching app features via %s", url);
477
+ }
478
+ const response = await fetch(url, {
479
+ method: "GET",
480
+ headers: {
481
+ "Content-Type": "application/json"
482
+ },
483
+ cache: "no-store"
484
+ });
485
+ if (!response.ok) {
486
+ if (process.env.NODE_ENV !== "production") {
487
+ console.debug("[portal-components] app features request failed with status %d", response.status);
488
+ }
489
+ return { enabled: false };
490
+ }
491
+ const data = await response.json();
492
+ if (process.env.NODE_ENV !== "production") {
493
+ console.debug(
494
+ "[portal-components] app features response: trial_signup_enabled=%s, trial_expiration_days=%d, license_type=%s",
495
+ data.trial_signup_enabled,
496
+ data.trial_expiration_days,
497
+ data.license_type
498
+ );
499
+ }
500
+ return {
501
+ enabled: data.trial_signup_enabled === true,
502
+ trialExpirationDays: data.trial_expiration_days || 30,
503
+ licenseType: data.license_type || "trial",
504
+ termsAndConditionsUrl: data.terms_and_conditions_url || ""
505
+ };
506
+ } catch (error) {
507
+ console.error("[portal-components] Error checking trial signup status:", error);
508
+ return { enabled: false };
509
+ }
510
+ }
511
+ traceServerAction("createTrialSignup", createTrialSignupImpl);
512
+ var verifyTrialSignup = traceServerAction("verifyTrialSignup", verifyTrialSignupImpl);
513
+ traceServerAction("checkTrialSignupEnabled", checkTrialSignupEnabledImpl);
514
+
515
+ // src/actions/trial-signup-actions.ts
516
+ async function verifyTrialSignupWithCookieImpl(code) {
517
+ try {
518
+ const result = await verifyTrialSignup(code);
519
+ if (!result.success) {
520
+ return {
521
+ success: false,
522
+ message: result.error || "Failed to verify trial signup code"
523
+ };
524
+ }
525
+ return { success: true };
526
+ } catch (error) {
527
+ console.error("[trial-signup-actions] verifyTrialSignup error:", error);
528
+ if (typeof error === "object" && error !== null && "message" in error && typeof error.message === "string") {
529
+ return {
530
+ success: false,
531
+ message: error.message
532
+ };
533
+ }
534
+ return {
535
+ success: false,
536
+ message: "Failed to verify trial signup. Please try again."
537
+ };
538
+ }
539
+ }
540
+ var verifyTrialSignupWithCookie = traceServerAction("verifyTrialSignupWithCookie", verifyTrialSignupWithCookieImpl);
541
+
542
+ export { verifyTrialSignupWithCookie };
543
+ //# sourceMappingURL=trial-signup-actions.js.map
544
+ //# sourceMappingURL=trial-signup-actions.js.map