@replicated/portal-components 0.0.18 → 0.0.19
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/change-team.d.mts +10 -0
- package/dist/actions/change-team.d.ts +10 -0
- package/dist/actions/change-team.js +399 -0
- package/dist/actions/change-team.js.map +1 -0
- package/dist/actions/index.d.mts +2 -1
- package/dist/actions/index.d.ts +2 -1
- package/dist/actions/index.js +1085 -0
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/install-actions.d.mts +2 -0
- package/dist/actions/install-actions.d.ts +2 -0
- package/dist/actions/install-actions.js +627 -0
- package/dist/actions/install-actions.js.map +1 -0
- package/dist/actions/service-account.d.mts +2 -0
- package/dist/actions/service-account.d.ts +2 -0
- package/dist/actions/service-account.js +320 -0
- package/dist/actions/service-account.js.map +1 -0
- package/dist/actions/support-bundles.d.mts +2 -0
- package/dist/actions/support-bundles.d.ts +2 -0
- package/dist/actions/support-bundles.js +606 -0
- package/dist/actions/support-bundles.js.map +1 -0
- package/dist/actions/team-settings.d.mts +2 -0
- package/dist/actions/team-settings.d.ts +2 -0
- package/dist/actions/team-settings.js +976 -0
- package/dist/actions/team-settings.js.map +1 -0
- package/dist/actions/user-settings.d.mts +2 -0
- package/dist/actions/user-settings.d.ts +2 -0
- package/dist/actions/user-settings.js +568 -0
- package/dist/actions/user-settings.js.map +1 -0
- package/dist/airgap-instances.d.mts +2 -1
- package/dist/airgap-instances.d.ts +2 -1
- package/dist/airgap-instances.js +232 -16
- package/dist/airgap-instances.js.map +1 -1
- package/dist/esm/actions/change-team.js +396 -0
- package/dist/esm/actions/change-team.js.map +1 -0
- package/dist/esm/actions/index.js +1054 -1
- package/dist/esm/actions/index.js.map +1 -1
- package/dist/esm/actions/install-actions.js +620 -0
- package/dist/esm/actions/install-actions.js.map +1 -0
- package/dist/esm/actions/service-account.js +318 -0
- package/dist/esm/actions/service-account.js.map +1 -0
- package/dist/esm/actions/support-bundles.js +601 -0
- package/dist/esm/actions/support-bundles.js.map +1 -0
- package/dist/esm/actions/team-settings.js +962 -0
- package/dist/esm/actions/team-settings.js.map +1 -0
- package/dist/esm/actions/user-settings.js +562 -0
- package/dist/esm/actions/user-settings.js.map +1 -0
- package/dist/esm/airgap-instances.js +232 -16
- package/dist/esm/airgap-instances.js.map +1 -1
- package/dist/esm/helm-install-wizard.js +9 -2
- package/dist/esm/helm-install-wizard.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/install-actions.js.map +1 -1
- package/dist/esm/instance-card.js +232 -16
- package/dist/esm/instance-card.js.map +1 -1
- package/dist/esm/license-details.js.map +1 -1
- package/dist/esm/linux-install-wizard.js +128 -96
- package/dist/esm/linux-install-wizard.js.map +1 -1
- package/dist/esm/online-instance-list.js +232 -16
- package/dist/esm/online-instance-list.js.map +1 -1
- package/dist/esm/pending-installations.js +4 -3
- package/dist/esm/pending-installations.js.map +1 -1
- package/dist/esm/support-bundle-collection-card.js +10 -4
- package/dist/esm/support-bundle-collection-card.js.map +1 -1
- package/dist/esm/support-bundles-card.js +1 -1
- package/dist/esm/support-bundles-card.js.map +1 -1
- package/dist/esm/support-card.js.map +1 -1
- package/dist/esm/top-nav.js.map +1 -1
- package/dist/esm/update-layout.js.map +1 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/helm-install-wizard.d.mts +3 -2
- package/dist/helm-install-wizard.d.ts +3 -2
- package/dist/helm-install-wizard.js +9 -2
- package/dist/helm-install-wizard.js.map +1 -1
- package/dist/{index-DkjaogsF.d.ts → index-BAiVrSSR.d.mts} +148 -1
- package/dist/{index-DkjaogsF.d.mts → index-DWt-N5od.d.ts} +148 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/install-actions.d.mts +3 -2
- package/dist/install-actions.d.ts +3 -2
- package/dist/install-actions.js.map +1 -1
- package/dist/install-card.d.mts +2 -1
- package/dist/install-card.d.ts +2 -1
- package/dist/instance-card.d.mts +2 -1
- package/dist/instance-card.d.ts +2 -1
- package/dist/instance-card.js +232 -16
- package/dist/instance-card.js.map +1 -1
- package/dist/license-card.d.mts +2 -1
- package/dist/license-card.d.ts +2 -1
- package/dist/license-details.js.map +1 -1
- package/dist/linux-install-wizard.d.mts +6 -6
- package/dist/linux-install-wizard.d.ts +6 -6
- package/dist/linux-install-wizard.js +128 -96
- package/dist/linux-install-wizard.js.map +1 -1
- package/dist/online-instance-list.d.mts +2 -1
- package/dist/online-instance-list.d.ts +2 -1
- package/dist/online-instance-list.js +232 -16
- package/dist/online-instance-list.js.map +1 -1
- package/dist/pending-installations.d.mts +6 -3
- package/dist/pending-installations.d.ts +6 -3
- package/dist/pending-installations.js +4 -3
- package/dist/pending-installations.js.map +1 -1
- package/dist/security-card.d.mts +2 -1
- package/dist/security-card.d.ts +2 -1
- package/dist/styles.css +9 -20
- package/dist/support-bundle-collection-card.js +9 -3
- package/dist/support-bundle-collection-card.js.map +1 -1
- package/dist/support-bundles-card.d.mts +2 -1
- package/dist/support-bundles-card.d.ts +2 -1
- package/dist/support-bundles-card.js +1 -1
- package/dist/support-bundles-card.js.map +1 -1
- package/dist/support-card.js.map +1 -1
- package/dist/top-nav.js.map +1 -1
- package/dist/update-layout.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +32 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const changeTeamAction: (customerId: string) => Promise<void>;
|
|
2
|
+
declare const fetchCustomersForMenu: () => Promise<{
|
|
3
|
+
customers: Array<{
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
}>;
|
|
7
|
+
currentCustomerId?: string;
|
|
8
|
+
}>;
|
|
9
|
+
|
|
10
|
+
export { changeTeamAction, fetchCustomersForMenu };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const changeTeamAction: (customerId: string) => Promise<void>;
|
|
2
|
+
declare const fetchCustomersForMenu: () => Promise<{
|
|
3
|
+
customers: Array<{
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
}>;
|
|
7
|
+
currentCustomerId?: string;
|
|
8
|
+
}>;
|
|
9
|
+
|
|
10
|
+
export { changeTeamAction, fetchCustomersForMenu };
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var headers = require('next/headers');
|
|
5
|
+
var buffer = require('buffer');
|
|
6
|
+
var react = require('react');
|
|
7
|
+
var cache = require('next/cache');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Enterprise Portal Components
|
|
11
|
+
* This file is generated by tsup. Do not edit manually.
|
|
12
|
+
*/
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
15
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
18
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
19
|
+
}) : x)(function(x) {
|
|
20
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
21
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
22
|
+
});
|
|
23
|
+
var __esm = (fn, res) => function __init() {
|
|
24
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
25
|
+
};
|
|
26
|
+
var __export = (target, all) => {
|
|
27
|
+
for (var name in all)
|
|
28
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
29
|
+
};
|
|
30
|
+
var __copyProps = (to, from, except, desc) => {
|
|
31
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
32
|
+
for (let key of __getOwnPropNames(from))
|
|
33
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
34
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
35
|
+
}
|
|
36
|
+
return to;
|
|
37
|
+
};
|
|
38
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
|
+
|
|
40
|
+
// datadog/tracer.ts
|
|
41
|
+
var tracer_exports = {};
|
|
42
|
+
__export(tracer_exports, {
|
|
43
|
+
default: () => tracer_default
|
|
44
|
+
});
|
|
45
|
+
var rawFlag, isEnabled, tracer, getRoutePattern, tracer_default;
|
|
46
|
+
var init_tracer = __esm({
|
|
47
|
+
"datadog/tracer.ts"() {
|
|
48
|
+
rawFlag = String(process.env.USE_DATADOG_APM || "").toLowerCase();
|
|
49
|
+
isEnabled = rawFlag === "true";
|
|
50
|
+
process.env.DD_TRACE_ENABLED = isEnabled ? "1" : "0";
|
|
51
|
+
tracer = null;
|
|
52
|
+
if (isEnabled) {
|
|
53
|
+
const serviceName = process.env.DD_SERVICE || "enterprise-portal";
|
|
54
|
+
const environment = process.env.DD_ENV || process.env.NODE_ENV || "development";
|
|
55
|
+
const version = process.env.DD_VERSION || process.env.NEXT_PUBLIC_VERSION || "0.0.0-dev";
|
|
56
|
+
const agentHost = process.env.DD_AGENT_HOST || process.env.DATADOG_AGENT_HOST || "127.0.0.1";
|
|
57
|
+
const agentPort = process.env.DD_TRACE_AGENT_PORT || "8126";
|
|
58
|
+
process.env.DD_SERVICE = serviceName;
|
|
59
|
+
process.env.DD_ENV = environment;
|
|
60
|
+
{
|
|
61
|
+
process.env.DD_VERSION = version;
|
|
62
|
+
}
|
|
63
|
+
process.env.DD_AGENT_HOST = agentHost;
|
|
64
|
+
process.env.DD_TRACE_AGENT_PORT = agentPort;
|
|
65
|
+
const dbmPropagationMode = process.env.DD_DBM_PROPAGATION_MODE || "full";
|
|
66
|
+
process.env.DD_DBM_PROPAGATION_MODE = dbmPropagationMode;
|
|
67
|
+
try {
|
|
68
|
+
const ddTrace = __require("dd-trace");
|
|
69
|
+
tracer = ddTrace.init({
|
|
70
|
+
service: serviceName,
|
|
71
|
+
env: environment,
|
|
72
|
+
version,
|
|
73
|
+
logInjection: true,
|
|
74
|
+
runtimeMetrics: true,
|
|
75
|
+
appsec: false,
|
|
76
|
+
profiling: false,
|
|
77
|
+
startupLogs: true
|
|
78
|
+
// Enable for debugging
|
|
79
|
+
});
|
|
80
|
+
console.log(`[datadog] Tracer initialized: service=${serviceName}, env=${environment}, version=${version}, agent=${agentHost}:${agentPort}`);
|
|
81
|
+
tracer.use("dns", false);
|
|
82
|
+
tracer.use("net", false);
|
|
83
|
+
tracer.use("http", {
|
|
84
|
+
server: {
|
|
85
|
+
hooks: {
|
|
86
|
+
request: (span, req) => {
|
|
87
|
+
if (!span) return;
|
|
88
|
+
const url = req?.url || "";
|
|
89
|
+
const method = req?.method || "GET";
|
|
90
|
+
const path = url.split("?")[0];
|
|
91
|
+
if (path.startsWith("/_next/")) {
|
|
92
|
+
span.context()._trace.isRecording = false;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const routePattern = getRoutePattern(path);
|
|
96
|
+
span.setTag("resource.name", `${method} ${routePattern}`);
|
|
97
|
+
span.setTag("http.route", routePattern);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
} catch (err) {
|
|
103
|
+
console.error("[datadog] failed to initialize tracing", err);
|
|
104
|
+
tracer = null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
getRoutePattern = (path) => {
|
|
108
|
+
const routePatterns = [
|
|
109
|
+
// Update instance routes - normalize dynamic segments (capture suffix to preserve sub-routes)
|
|
110
|
+
{ pattern: /^\/update\/instance\/[^/]+(.*)$/, replacement: "/update/instance/[instanceId]$1" }
|
|
111
|
+
];
|
|
112
|
+
for (const { pattern, replacement } of routePatterns) {
|
|
113
|
+
if (pattern.test(path)) {
|
|
114
|
+
return path.replace(pattern, replacement);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return path;
|
|
118
|
+
};
|
|
119
|
+
tracer_default = tracer;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// src/utils/api-client.ts
|
|
124
|
+
async function authenticatedFetch(url, options = {}) {
|
|
125
|
+
const { token, ...fetchOptions } = options;
|
|
126
|
+
const headers = new Headers(fetchOptions.headers);
|
|
127
|
+
if (token) {
|
|
128
|
+
headers.set("authorization", `Bearer ${token}`);
|
|
129
|
+
}
|
|
130
|
+
const response = await fetch(url, {
|
|
131
|
+
...fetchOptions,
|
|
132
|
+
headers
|
|
133
|
+
});
|
|
134
|
+
if (response.status === 401) {
|
|
135
|
+
await handle401();
|
|
136
|
+
}
|
|
137
|
+
if (response.status === 502 || response.status === 503 || response.status === 504) {
|
|
138
|
+
await handleServerError(response.status);
|
|
139
|
+
}
|
|
140
|
+
return response;
|
|
141
|
+
}
|
|
142
|
+
async function handle401() {
|
|
143
|
+
const { redirect } = await import('next/navigation');
|
|
144
|
+
return redirect("/?expired=1");
|
|
145
|
+
}
|
|
146
|
+
async function handleServerError(statusCode) {
|
|
147
|
+
const { redirect } = await import('next/navigation');
|
|
148
|
+
let sourceUrl;
|
|
149
|
+
try {
|
|
150
|
+
const { headers } = await import('next/headers');
|
|
151
|
+
const headersList = await headers();
|
|
152
|
+
const referer = headersList.get("referer");
|
|
153
|
+
const host = headersList.get("host");
|
|
154
|
+
const pathname = headersList.get("x-invoke-path") || headersList.get("x-forwarded-path");
|
|
155
|
+
if (referer) {
|
|
156
|
+
sourceUrl = referer;
|
|
157
|
+
} else if (host && pathname) {
|
|
158
|
+
const protocol = headersList.get("x-forwarded-proto") || "https";
|
|
159
|
+
sourceUrl = `${protocol}://${host}${pathname}`;
|
|
160
|
+
}
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.debug("[portal-components] Could not determine source URL", error);
|
|
163
|
+
}
|
|
164
|
+
const params = new URLSearchParams({ code: String(statusCode) });
|
|
165
|
+
if (sourceUrl) {
|
|
166
|
+
params.set("source", sourceUrl);
|
|
167
|
+
}
|
|
168
|
+
return redirect(`/error?${params.toString()}`);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/utils/observability/tracing.ts
|
|
172
|
+
var tracerCache = void 0;
|
|
173
|
+
function getTracer() {
|
|
174
|
+
if (tracerCache !== void 0) {
|
|
175
|
+
return tracerCache;
|
|
176
|
+
}
|
|
177
|
+
const rawFlag2 = String(process.env.USE_DATADOG_APM || "").toLowerCase();
|
|
178
|
+
const isEnabled2 = rawFlag2 === "true";
|
|
179
|
+
if (!isEnabled2) {
|
|
180
|
+
tracerCache = null;
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const tracerModule = (init_tracer(), __toCommonJS(tracer_exports));
|
|
185
|
+
const tracer2 = tracerModule.default || tracerModule;
|
|
186
|
+
if (tracer2 && typeof tracer2.trace === "function") {
|
|
187
|
+
tracerCache = tracer2;
|
|
188
|
+
return tracerCache;
|
|
189
|
+
}
|
|
190
|
+
} catch (err) {
|
|
191
|
+
console.warn("Failed to load tracer:", err);
|
|
192
|
+
}
|
|
193
|
+
tracerCache = null;
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
async function withTrace(name, fn) {
|
|
197
|
+
const activeTracer = getTracer();
|
|
198
|
+
if (!activeTracer) {
|
|
199
|
+
return fn(void 0);
|
|
200
|
+
}
|
|
201
|
+
return activeTracer.trace(name, async (span) => {
|
|
202
|
+
if (span) {
|
|
203
|
+
span.setTag("component", "application");
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
const result = await fn(span);
|
|
207
|
+
return result;
|
|
208
|
+
} catch (error) {
|
|
209
|
+
if (span) {
|
|
210
|
+
span.setTag("error", error);
|
|
211
|
+
}
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
function traceServerAction(name, fn) {
|
|
217
|
+
const spanName = name.startsWith("server.action.") ? name : `server.action.${name}`;
|
|
218
|
+
const traced = async (...args) => {
|
|
219
|
+
return withTrace(spanName, async (span) => {
|
|
220
|
+
if (span) {
|
|
221
|
+
span.setTag("component", "server-action");
|
|
222
|
+
}
|
|
223
|
+
const result = await fn(...args);
|
|
224
|
+
return result;
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
return traced;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// src/actions/index.ts
|
|
231
|
+
var getApiOrigin = () => {
|
|
232
|
+
return (process.env.REPLICATED_APP_ORIGIN || "https://replicated.app").replace(/\/+$/, "");
|
|
233
|
+
};
|
|
234
|
+
var defineServerAction = (definition) => definition;
|
|
235
|
+
var fetchCustomBrandingImpl = async () => {
|
|
236
|
+
const appSlug = process.env.PORTAL_APP_SLUG;
|
|
237
|
+
if (!appSlug) {
|
|
238
|
+
throw new Error("PORTAL_APP_SLUG is not configured");
|
|
239
|
+
}
|
|
240
|
+
const url = `${getApiOrigin()}/enterprise-portal/public/branding?app_slug=${encodeURIComponent(
|
|
241
|
+
appSlug
|
|
242
|
+
)}`;
|
|
243
|
+
if (process.env.NODE_ENV !== "production") {
|
|
244
|
+
console.debug(
|
|
245
|
+
"[portal-components] fetching custom branding via %s (Enterprise Portal API)",
|
|
246
|
+
url
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
const response = await fetch(url, {
|
|
250
|
+
headers: {
|
|
251
|
+
accept: "application/json"
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
if (!response.ok) {
|
|
255
|
+
throw new Error(
|
|
256
|
+
`Custom branding request failed (${response.status} ${response.statusText})`
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
const payload = await response.json();
|
|
260
|
+
const brandingObject = {
|
|
261
|
+
logo: payload.logoUrl,
|
|
262
|
+
title: payload.appName,
|
|
263
|
+
customColor1: payload.primaryColor,
|
|
264
|
+
customColor2: payload.secondaryColor,
|
|
265
|
+
favicon: payload.faviconUrl,
|
|
266
|
+
supportPortalLink: payload.supportPortalLink || ""
|
|
267
|
+
};
|
|
268
|
+
const brandingData = buffer.Buffer.from(JSON.stringify(brandingObject)).toString("base64");
|
|
269
|
+
return {
|
|
270
|
+
brandingData,
|
|
271
|
+
documentation: null
|
|
272
|
+
// Documentation not included in new API's public endpoint
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
react.cache(fetchCustomBrandingImpl);
|
|
276
|
+
var decodeJwtPayload = (token) => {
|
|
277
|
+
const parts = token.split(".");
|
|
278
|
+
if (parts.length !== 3) {
|
|
279
|
+
throw new Error("Invalid JWT received");
|
|
280
|
+
}
|
|
281
|
+
const payloadSegment = parts[1];
|
|
282
|
+
if (!payloadSegment) {
|
|
283
|
+
throw new Error("JWT payload segment missing");
|
|
284
|
+
}
|
|
285
|
+
const padded = payloadSegment.padEnd(
|
|
286
|
+
payloadSegment.length + (4 - payloadSegment.length % 4) % 4,
|
|
287
|
+
"="
|
|
288
|
+
);
|
|
289
|
+
const decoded = buffer.Buffer.from(padded, "base64").toString("utf-8");
|
|
290
|
+
return JSON.parse(decoded);
|
|
291
|
+
};
|
|
292
|
+
var getCustomerIdFromToken = (token) => {
|
|
293
|
+
const payload = decodeJwtPayload(token);
|
|
294
|
+
const customerId = payload?.customer_id || payload?.customerId;
|
|
295
|
+
if (typeof customerId !== "string" || !customerId.trim()) {
|
|
296
|
+
throw new Error("Unable to determine customer_id from session token");
|
|
297
|
+
}
|
|
298
|
+
return customerId.trim();
|
|
299
|
+
};
|
|
300
|
+
var switchCustomer = defineServerAction({
|
|
301
|
+
id: "auth/switch-customer",
|
|
302
|
+
description: "Switches the JWT to a different customer/team.",
|
|
303
|
+
visibility: "customer",
|
|
304
|
+
tags: ["auth", "customers"],
|
|
305
|
+
async run({ token, customerId }, context) {
|
|
306
|
+
if (typeof token !== "string" || token.trim().length === 0) {
|
|
307
|
+
throw new Error("switchCustomer requires a non-empty token");
|
|
308
|
+
}
|
|
309
|
+
if (typeof customerId !== "string" || customerId.trim().length === 0) {
|
|
310
|
+
throw new Error("switchCustomer requires a non-empty customerId");
|
|
311
|
+
}
|
|
312
|
+
const endpoint = `${getApiOrigin()}/enterprise-portal/auth/switch-team`;
|
|
313
|
+
const requestBody = { customer_id: customerId };
|
|
314
|
+
const response = await authenticatedFetch(endpoint, {
|
|
315
|
+
method: "POST",
|
|
316
|
+
token,
|
|
317
|
+
headers: {
|
|
318
|
+
"content-type": "application/json",
|
|
319
|
+
accept: "application/json"
|
|
320
|
+
},
|
|
321
|
+
body: JSON.stringify(requestBody),
|
|
322
|
+
signal: context?.signal
|
|
323
|
+
});
|
|
324
|
+
if (!response.ok) {
|
|
325
|
+
const errorText = await response.text();
|
|
326
|
+
console.error("[portal-components] switchCustomer error response:", errorText);
|
|
327
|
+
throw new Error(
|
|
328
|
+
`Switch customer request failed (${response.status} ${response.statusText}): ${errorText}`
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
const payload = await response.json();
|
|
332
|
+
const newToken = payload.jwt || payload.token || token;
|
|
333
|
+
return {
|
|
334
|
+
token: newToken
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
async function changeTeamActionImpl(customerId) {
|
|
339
|
+
const sessionStore = await headers.cookies();
|
|
340
|
+
const session = sessionStore.get("portal_session");
|
|
341
|
+
if (!session?.value) {
|
|
342
|
+
throw new Error("No session found");
|
|
343
|
+
}
|
|
344
|
+
const result = await switchCustomer.run({
|
|
345
|
+
token: session.value,
|
|
346
|
+
customerId
|
|
347
|
+
});
|
|
348
|
+
sessionStore.delete("portal_session");
|
|
349
|
+
sessionStore.set("portal_session", result.token, {
|
|
350
|
+
httpOnly: true,
|
|
351
|
+
secure: process.env.NODE_ENV === "production",
|
|
352
|
+
sameSite: "lax",
|
|
353
|
+
path: "/"
|
|
354
|
+
});
|
|
355
|
+
cache.revalidatePath("/", "layout");
|
|
356
|
+
}
|
|
357
|
+
var changeTeamAction = traceServerAction("changeTeamAction", changeTeamActionImpl);
|
|
358
|
+
async function fetchCustomersForMenuImpl() {
|
|
359
|
+
try {
|
|
360
|
+
const sessionStore = await headers.cookies();
|
|
361
|
+
const session = sessionStore.get("portal_session");
|
|
362
|
+
if (!session?.value) {
|
|
363
|
+
return { customers: [] };
|
|
364
|
+
}
|
|
365
|
+
const token = session.value;
|
|
366
|
+
const currentCustomerId = getCustomerIdFromToken(token);
|
|
367
|
+
const endpoint = `${getApiOrigin()}/enterprise-portal/user`;
|
|
368
|
+
const response = await fetch(endpoint, {
|
|
369
|
+
method: "GET",
|
|
370
|
+
headers: {
|
|
371
|
+
Authorization: `Bearer ${token}`,
|
|
372
|
+
Accept: "application/json"
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
if (!response.ok) {
|
|
376
|
+
console.error("[fetch-customers-for-menu] Failed to fetch user data:", response.status);
|
|
377
|
+
return { customers: [], currentCustomerId };
|
|
378
|
+
}
|
|
379
|
+
const payload = await response.json();
|
|
380
|
+
const userData = payload.data;
|
|
381
|
+
const mappedCustomers = (userData?.customers || []).map((c) => ({
|
|
382
|
+
id: c.id,
|
|
383
|
+
name: c.name
|
|
384
|
+
}));
|
|
385
|
+
return {
|
|
386
|
+
customers: mappedCustomers,
|
|
387
|
+
currentCustomerId
|
|
388
|
+
};
|
|
389
|
+
} catch (error) {
|
|
390
|
+
console.error("[fetch-customers-for-menu] Failed to fetch customers:", error);
|
|
391
|
+
return { customers: [] };
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
var fetchCustomersForMenu = traceServerAction("fetchCustomersForMenu", fetchCustomersForMenuImpl);
|
|
395
|
+
|
|
396
|
+
exports.changeTeamAction = changeTeamAction;
|
|
397
|
+
exports.fetchCustomersForMenu = fetchCustomersForMenu;
|
|
398
|
+
//# sourceMappingURL=change-team.js.map
|
|
399
|
+
//# sourceMappingURL=change-team.js.map
|