diff --git a/gen/models/managementV1OIDC.ts b/gen/models/managementV1OIDC.ts index e0de7b8..4fc8979 100644 --- a/gen/models/managementV1OIDC.ts +++ b/gen/models/managementV1OIDC.ts @@ -10,7 +10,7 @@ * Do not edit the class manually. */ -import { ManagementV1OIDCClient } from '../models/managementV1OIDCClient'; +import { ManagementV1OIDCClientSpec } from '../models/managementV1OIDCClientSpec'; /** @@ -20,7 +20,7 @@ export class ManagementV1OIDC { /** * The clients that are allowed to request loft tokens */ - 'clients'?: Array; + 'clients'?: Array; /** * If true indicates that loft will act as an OIDC server */ @@ -36,7 +36,7 @@ export class ManagementV1OIDC { { "name": "clients", "baseName": "clients", - "type": "Array", + "type": "Array", "format": "" }, { diff --git a/gen/models/managementV1OIDCClient.ts b/gen/models/managementV1OIDCClient.ts index b2da84e..6a6da18 100644 --- a/gen/models/managementV1OIDCClient.ts +++ b/gen/models/managementV1OIDCClient.ts @@ -10,54 +10,60 @@ * Do not edit the class manually. */ +import { ManagementV1OIDCClientSpec } from '../models/managementV1OIDCClientSpec'; +import { V1ObjectMeta } from '../models/V1ObjectMeta'; /** -* OIDCClient holds information about a client +* OIDCClient represents an OIDC client to use with Loft as an OIDC provider */ export class ManagementV1OIDCClient { /** - * The client id of the client + * APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources */ - 'clientId'?: string; + 'apiVersion'?: string; /** - * The client secret of the client + * Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds */ - 'clientSecret'?: string; + 'kind'?: string; + 'metadata'?: V1ObjectMeta; + 'spec'?: ManagementV1OIDCClientSpec; /** - * The client name + * OIDCClientStatus holds the status */ - 'name'?: string; - /** - * A registered set of redirect URIs. When redirecting from dex to the client, the URI requested to redirect to MUST match one of these values, unless the client is \"public\". - */ - 'redirectURIs': Array; + 'status'?: any; static readonly discriminator: string | undefined = undefined; static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ { - "name": "clientId", - "baseName": "clientId", + "name": "apiVersion", + "baseName": "apiVersion", "type": "string", "format": "" }, { - "name": "clientSecret", - "baseName": "clientSecret", + "name": "kind", + "baseName": "kind", "type": "string", "format": "" }, { - "name": "name", - "baseName": "name", - "type": "string", + "name": "metadata", + "baseName": "metadata", + "type": "V1ObjectMeta", + "format": "" + }, + { + "name": "spec", + "baseName": "spec", + "type": "ManagementV1OIDCClientSpec", "format": "" }, { - "name": "redirectURIs", - "baseName": "redirectURIs", - "type": "Array", + "name": "status", + "baseName": "status", + "type": "any", "format": "" } ]; diff --git a/gen/models/managementV1OIDCClientList.ts b/gen/models/managementV1OIDCClientList.ts new file mode 100644 index 0000000..1d89007 --- /dev/null +++ b/gen/models/managementV1OIDCClientList.ts @@ -0,0 +1,64 @@ +/** + * Api + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * OpenAPI spec version: master + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { ManagementV1OIDCClient } from '../models/managementV1OIDCClient'; +import { V1ListMeta } from '../models/V1ListMeta'; + + +export class ManagementV1OIDCClientList { + /** + * APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + */ + 'apiVersion'?: string; + 'items': Array; + /** + * Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + */ + 'kind'?: string; + 'metadata'?: V1ListMeta; + + static readonly discriminator: string | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ + { + "name": "apiVersion", + "baseName": "apiVersion", + "type": "string", + "format": "" + }, + { + "name": "items", + "baseName": "items", + "type": "Array", + "format": "" + }, + { + "name": "kind", + "baseName": "kind", + "type": "string", + "format": "" + }, + { + "name": "metadata", + "baseName": "metadata", + "type": "V1ListMeta", + "format": "" + } ]; + + static getAttributeTypeMap() { + return ManagementV1OIDCClientList.attributeTypeMap; + } + + public constructor() { + } +} + diff --git a/gen/models/managementV1OIDCClientSpec.ts b/gen/models/managementV1OIDCClientSpec.ts new file mode 100644 index 0000000..067f65a --- /dev/null +++ b/gen/models/managementV1OIDCClientSpec.ts @@ -0,0 +1,71 @@ +/** + * Api + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * OpenAPI spec version: master + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** +* OIDCClientSpec holds the specification +*/ +export class ManagementV1OIDCClientSpec { + /** + * The client id of the client + */ + 'clientId'?: string; + /** + * The client secret of the client + */ + 'clientSecret'?: string; + /** + * The client name + */ + 'name'?: string; + /** + * A registered set of redirect URIs. When redirecting from dex to the client, the URI requested to redirect to MUST match one of these values, unless the client is \"public\". + */ + 'redirectURIs': Array; + + static readonly discriminator: string | undefined = undefined; + + static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [ + { + "name": "clientId", + "baseName": "clientId", + "type": "string", + "format": "" + }, + { + "name": "clientSecret", + "baseName": "clientSecret", + "type": "string", + "format": "" + }, + { + "name": "name", + "baseName": "name", + "type": "string", + "format": "" + }, + { + "name": "redirectURIs", + "baseName": "redirectURIs", + "type": "Array", + "format": "" + } ]; + + static getAttributeTypeMap() { + return ManagementV1OIDCClientSpec.attributeTypeMap; + } + + public constructor() { + } +} + diff --git a/gen/resources.ts b/gen/resources.ts index cfb2d5b..af8cd3f 100644 --- a/gen/resources.ts +++ b/gen/resources.ts @@ -31,6 +31,7 @@ import {ManagementV1LicenseRequest} from "./models/managementV1LicenseRequest" import {ManagementV1LicenseToken} from "./models/managementV1LicenseToken" import {ManagementV1License} from "./models/managementV1License" import {ManagementV1LoftUpgrade} from "./models/managementV1LoftUpgrade" +import {ManagementV1OIDCClient} from "./models/managementV1OIDCClient" import {ManagementV1OwnedAccessKey} from "./models/managementV1OwnedAccessKey" import {ManagementV1ProjectChartInfo} from "./models/managementV1ProjectChartInfo" import {ManagementV1ProjectCharts} from "./models/managementV1ProjectCharts" @@ -103,6 +104,7 @@ export type TGenResources = { ManagementV1LicenseRequest: GroupVersionResource ManagementV1LicenseToken: GroupVersionResource ManagementV1LoftUpgrade: GroupVersionResource + ManagementV1OIDCClient: GroupVersionResource ManagementV1OwnedAccessKey: GroupVersionResource ManagementV1Project: GroupVersionResource ManagementV1ProjectChartInfo: GroupVersionResource @@ -393,6 +395,14 @@ export const GenResources: TGenResources = { namespaced: false, kind: "LoftUpgrade", }, + ManagementV1OIDCClient: { + group: "management.loft.sh", + version: "v1", + resource: "oidcclients", + subResource: "", + namespaced: true, + kind: "OIDCClient", + }, ManagementV1OwnedAccessKey: { group: "management.loft.sh", version: "v1", diff --git a/lib/index.d.ts b/lib/index.d.ts index 4c17bfe..0afaa7f 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -4781,7 +4781,7 @@ declare class ManagementV1Authentication { }[]; constructor(); } -declare class ManagementV1OIDCClient { +declare class ManagementV1OIDCClientSpec { /** * The client id of the client */ @@ -4817,7 +4817,7 @@ declare class ManagementV1OIDC { /** * The clients that are allowed to request loft tokens */ - "clients"?: Array; + "clients"?: Array; /** * If true indicates that loft will act as an OIDC server */ @@ -7241,6 +7241,36 @@ declare class ManagementV1LoftUpgrade { }[]; constructor(); } +declare class ManagementV1OIDCClient { + /** + * APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + */ + "apiVersion"?: string; + /** + * Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + */ + "kind"?: string; + "metadata"?: V1ObjectMeta; + "spec"?: ManagementV1OIDCClientSpec; + /** + * OIDCClientStatus holds the status + */ + "status"?: any; + static readonly discriminator: string | undefined; + static readonly attributeTypeMap: Array<{ + name: string; + baseName: string; + type: string; + format: string; + }>; + static getAttributeTypeMap(): { + name: string; + baseName: string; + type: string; + format: string; + }[]; + constructor(); +} declare class StorageV1AccessKeyIdentity { /** * Connector is the name of the connector this access key was created from @@ -14172,6 +14202,7 @@ export type TGenResources = { ManagementV1LicenseRequest: GroupVersionResource; ManagementV1LicenseToken: GroupVersionResource; ManagementV1LoftUpgrade: GroupVersionResource; + ManagementV1OIDCClient: GroupVersionResource; ManagementV1OwnedAccessKey: GroupVersionResource; ManagementV1Project: GroupVersionResource; ManagementV1ProjectChartInfo: GroupVersionResource; diff --git a/lib/index.esm.js b/lib/index.esm.js index f4d1a0c..37859a9 100644 --- a/lib/index.esm.js +++ b/lib/index.esm.js @@ -1 +1 @@ -import m from"js-cookie";import re from"json-merge-patch";var y={loftAccessKeyIdentifier:"loft_access_key",loftImpersonateSubjectIdentifier:"loft_impersonate_subject",loftImpersonateJoinedGroupIdentifier:"loft_impersonate_joined_group"};function h(a){return a||[]}var U={ManagementV1AgentAuditEvent:{group:"management.loft.sh",version:"v1",resource:"agentauditevents",subResource:"",namespaced:!1,kind:"AgentAuditEvent"},ManagementV1Announcement:{group:"management.loft.sh",version:"v1",resource:"announcements",subResource:"",namespaced:!1,kind:"Announcement"},ManagementV1App:{group:"management.loft.sh",version:"v1",resource:"apps",subResource:"",namespaced:!1,kind:"App"},ManagementV1AppCredentials:{group:"management.loft.sh",version:"v1",resource:"apps",subResource:"credentials",namespaced:!1,kind:"AppCredentials"},ManagementV1Backup:{group:"management.loft.sh",version:"v1",resource:"backups",subResource:"",namespaced:!1,kind:"Backup"},ManagementV1BackupApply:{group:"management.loft.sh",version:"v1",resource:"backups",subResource:"apply",namespaced:!1,kind:"BackupApply"},ManagementV1Cluster:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"",namespaced:!1,kind:"Cluster"},ManagementV1ClusterAccess:{group:"management.loft.sh",version:"v1",resource:"clusteraccesses",subResource:"",namespaced:!1,kind:"ClusterAccess"},ManagementV1ClusterAccessKey:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"accesskey",namespaced:!1,kind:"ClusterAccessKey"},ManagementV1ClusterAgentConfig:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"agentconfig",namespaced:!1,kind:"ClusterAgentConfig"},ManagementV1ClusterCharts:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"charts",namespaced:!1,kind:"ClusterCharts"},ManagementV1ClusterDomain:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"domain",namespaced:!1,kind:"ClusterDomain"},ManagementV1ClusterMemberAccess:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"memberaccess",namespaced:!1,kind:"ClusterMemberAccess"},ManagementV1ClusterMembers:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"members",namespaced:!1,kind:"ClusterMembers"},ManagementV1ClusterReset:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"reset",namespaced:!1,kind:"ClusterReset"},ManagementV1ClusterRoleTemplate:{group:"management.loft.sh",version:"v1",resource:"clusterroletemplates",subResource:"",namespaced:!1,kind:"ClusterRoleTemplate"},ManagementV1ClusterVirtualClusterDefaults:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"virtualclusterdefaults",namespaced:!1,kind:"ClusterVirtualClusterDefaults"},ManagementV1Config:{group:"management.loft.sh",version:"v1",resource:"configs",subResource:"",namespaced:!1,kind:"Config"},ManagementV1ConvertVirtualClusterConfig:{group:"management.loft.sh",version:"v1",resource:"convertvirtualclusterconfig",subResource:"",namespaced:!1,kind:"ConvertVirtualClusterConfig"},ManagementV1DevPodWorkspaceInstance:{group:"management.loft.sh",version:"v1",resource:"devpodworkspaceinstances",subResource:"",namespaced:!0,kind:"DevPodWorkspaceInstance"},ManagementV1DevPodWorkspaceInstanceState:{group:"management.loft.sh",version:"v1",resource:"devpodworkspaceinstances",subResource:"state",namespaced:!0,kind:"DevPodWorkspaceInstanceState"},ManagementV1DevPodWorkspaceTemplate:{group:"management.loft.sh",version:"v1",resource:"devpodworkspacetemplates",subResource:"",namespaced:!1,kind:"DevPodWorkspaceTemplate"},ManagementV1DirectClusterEndpointToken:{group:"management.loft.sh",version:"v1",resource:"directclusterendpointtokens",subResource:"",namespaced:!1,kind:"DirectClusterEndpointToken"},ManagementV1Event:{group:"management.loft.sh",version:"v1",resource:"events",subResource:"",namespaced:!1,kind:"Event"},ManagementV1Feature:{group:"management.loft.sh",version:"v1",resource:"features",subResource:"",namespaced:!1,kind:"Feature"},ManagementV1IngressAuthToken:{group:"management.loft.sh",version:"v1",resource:"ingressauthtokens",subResource:"",namespaced:!1,kind:"IngressAuthToken"},ManagementV1Kiosk:{group:"management.loft.sh",version:"v1",resource:"kiosk",subResource:"",namespaced:!1,kind:"Kiosk"},ManagementV1License:{group:"management.loft.sh",version:"v1",resource:"licenses",subResource:"",namespaced:!1,kind:"License"},ManagementV1LicenseRequest:{group:"management.loft.sh",version:"v1",resource:"licenses",subResource:"request",namespaced:!1,kind:"LicenseRequest"},ManagementV1LicenseToken:{group:"management.loft.sh",version:"v1",resource:"licensetokens",subResource:"",namespaced:!1,kind:"LicenseToken"},ManagementV1LoftUpgrade:{group:"management.loft.sh",version:"v1",resource:"loftupgrades",subResource:"",namespaced:!1,kind:"LoftUpgrade"},ManagementV1OwnedAccessKey:{group:"management.loft.sh",version:"v1",resource:"ownedaccesskeys",subResource:"",namespaced:!1,kind:"OwnedAccessKey"},ManagementV1Project:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"",namespaced:!1,kind:"Project"},ManagementV1ProjectChartInfo:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"chartinfo",namespaced:!1,kind:"ProjectChartInfo"},ManagementV1ProjectCharts:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"charts",namespaced:!1,kind:"ProjectCharts"},ManagementV1ProjectClusters:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"clusters",namespaced:!1,kind:"ProjectClusters"},ManagementV1ProjectImportSpace:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"importspace",namespaced:!1,kind:"ProjectImportSpace"},ManagementV1ProjectMembers:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"members",namespaced:!1,kind:"ProjectMembers"},ManagementV1ProjectMigrateSpaceInstance:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"migratespaceinstance",namespaced:!1,kind:"ProjectMigrateSpaceInstance"},ManagementV1ProjectMigrateVirtualClusterInstance:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"migratevirtualclusterinstance",namespaced:!1,kind:"ProjectMigrateVirtualClusterInstance"},ManagementV1ProjectSecret:{group:"management.loft.sh",version:"v1",resource:"projectsecrets",subResource:"",namespaced:!0,kind:"ProjectSecret"},ManagementV1ProjectTemplates:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"templates",namespaced:!1,kind:"ProjectTemplates"},ManagementV1RedirectToken:{group:"management.loft.sh",version:"v1",resource:"redirecttokens",subResource:"",namespaced:!1,kind:"RedirectToken"},ManagementV1RegisterVirtualCluster:{group:"management.loft.sh",version:"v1",resource:"registervirtualclusters",subResource:"",namespaced:!1,kind:"RegisterVirtualCluster"},ManagementV1ResetAccessKey:{group:"management.loft.sh",version:"v1",resource:"resetaccesskeys",subResource:"",namespaced:!1,kind:"ResetAccessKey"},ManagementV1Runner:{group:"management.loft.sh",version:"v1",resource:"runners",subResource:"",namespaced:!1,kind:"Runner"},ManagementV1RunnerAccessKey:{group:"management.loft.sh",version:"v1",resource:"runners",subResource:"accesskey",namespaced:!1,kind:"RunnerAccessKey"},ManagementV1RunnerConfig:{group:"management.loft.sh",version:"v1",resource:"runners",subResource:"config",namespaced:!1,kind:"RunnerConfig"},ManagementV1Self:{group:"management.loft.sh",version:"v1",resource:"selves",subResource:"",namespaced:!1,kind:"Self"},ManagementV1SelfSubjectAccessReview:{group:"management.loft.sh",version:"v1",resource:"selfsubjectaccessreviews",subResource:"",namespaced:!1,kind:"SelfSubjectAccessReview"},ManagementV1SharedSecret:{group:"management.loft.sh",version:"v1",resource:"sharedsecrets",subResource:"",namespaced:!0,kind:"SharedSecret"},ManagementV1SpaceInstance:{group:"management.loft.sh",version:"v1",resource:"spaceinstances",subResource:"",namespaced:!0,kind:"SpaceInstance"},ManagementV1SpaceTemplate:{group:"management.loft.sh",version:"v1",resource:"spacetemplates",subResource:"",namespaced:!1,kind:"SpaceTemplate"},ManagementV1SubjectAccessReview:{group:"management.loft.sh",version:"v1",resource:"subjectaccessreviews",subResource:"",namespaced:!1,kind:"SubjectAccessReview"},ManagementV1Task:{group:"management.loft.sh",version:"v1",resource:"tasks",subResource:"",namespaced:!1,kind:"Task"},ManagementV1TaskLog:{group:"management.loft.sh",version:"v1",resource:"tasks",subResource:"log",namespaced:!1,kind:"TaskLog"},ManagementV1Team:{group:"management.loft.sh",version:"v1",resource:"teams",subResource:"",namespaced:!1,kind:"Team"},ManagementV1TeamAccessKeys:{group:"management.loft.sh",version:"v1",resource:"teams",subResource:"accesskeys",namespaced:!1,kind:"TeamAccessKeys"},ManagementV1TeamClusters:{group:"management.loft.sh",version:"v1",resource:"teams",subResource:"clusters",namespaced:!1,kind:"TeamClusters"},ManagementV1TranslateVClusterResourceName:{group:"management.loft.sh",version:"v1",resource:"translatevclusterresourcenames",subResource:"",namespaced:!1,kind:"TranslateVClusterResourceName"},ManagementV1User:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"",namespaced:!1,kind:"User"},ManagementV1UserAccessKeys:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"accesskeys",namespaced:!1,kind:"UserAccessKeys"},ManagementV1UserClusters:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"clusters",namespaced:!1,kind:"UserClusters"},ManagementV1UserPermissions:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"permissions",namespaced:!1,kind:"UserPermissions"},ManagementV1UserProfile:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"profile",namespaced:!1,kind:"UserProfile"},ManagementV1VirtualClusterAccessKey:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"accesskey",namespaced:!0,kind:"VirtualClusterAccessKey"},ManagementV1VirtualClusterInstance:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"",namespaced:!0,kind:"VirtualClusterInstance"},ManagementV1VirtualClusterInstanceKubeConfig:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"kubeconfig",namespaced:!0,kind:"VirtualClusterInstanceKubeConfig"},ManagementV1VirtualClusterInstanceLog:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"log",namespaced:!0,kind:"VirtualClusterInstanceLog"},ManagementV1VirtualClusterTemplate:{group:"management.loft.sh",version:"v1",resource:"virtualclustertemplates",subResource:"",namespaced:!1,kind:"VirtualClusterTemplate"}};var N="virtualcluster.loft.sh",q="v1",pe="virtualcluster.loft.sh/v1",S="cluster.loft.sh",T="v1",me="cluster.loft.sh/v1",ge="management.loft.sh",F="v1",de="management.loft.sh/v1",Ve="storage.loft.sh",fe="v1",he="storage.loft.sh/v1",B="apiextensions.k8s.io",H="v1",Re="apiextensions.k8s.io/v1",D=class{};var c={...U,ClusterV1SleepModeConfig:{group:S,version:T,resource:"sleepmodeconfigs",kind:"SleepModeConfig",namespaced:!0},ClusterV1HelmRelease:{group:S,version:T,resource:"helmreleases",kind:"HelmRelease",namespaced:!0},ClusterV1ChartInfo:{group:S,version:T,resource:"chartinfos",kind:"ChartInfo"},VirtualclusterV1HelmRelease:{group:N,version:q,resource:"helmreleases",kind:"HelmRelease",namespaced:!0},CustomResourceDefinition:{group:B,version:H,resource:"customresourcedefinitions",kind:"CustomResourceDefinition"},StorageV1ClusterQuota:{group:"storage.loft.sh",version:F,resource:"clusterquotas",kind:"ClusterQuota"},NetworkingV1Ingress:{group:"networking.k8s.io",version:"v1",resource:"ingresses",kind:"Ingress",namespaced:!0},V1StatefulSet:{group:"apps",version:"v1",resource:"statefulsets",kind:"StatefulSet",namespaced:!0},V1Deployment:{group:"apps",version:"v1",resource:"deployments",kind:"Deployment",namespaced:!0},V1Event:{group:"",version:"v1",resource:"events",kind:"Event",namespaced:!0},V1Pod:{group:"",version:"v1",resource:"pods",kind:"Pod",namespaced:!0},V1Node:{group:"",version:"v1",resource:"nodes",kind:"Node"},V1Namespace:{group:"",version:"v1",resource:"namespaces",kind:"Namespace"},V1SelfSubjectAccessReview:{group:"authorization.k8s.io",version:"v1",resource:"selfsubjectaccessreviews",kind:"SelfSubjectAccessReview"},V1ClusterRole:{group:"rbac.authorization.k8s.io",version:"v1",resource:"clusterroles",kind:"ClusterRole"},V1ClusterRoleBinding:{group:"rbac.authorization.k8s.io",version:"v1",resource:"clusterrolebindings",kind:"ClusterRoleBinding"},V1Role:{group:"rbac.authorization.k8s.io",version:"v1",resource:"roles",kind:"Role",namespaced:!0},V1RoleBinding:{group:"rbac.authorization.k8s.io",version:"v1",resource:"rolebindings",kind:"RoleBinding",namespaced:!0},V1Secret:{group:"",version:"v1",resource:"secrets",kind:"Secret",namespaced:!0},V1ConfigMap:{group:"",version:"v1",resource:"configmaps",kind:"ConfigMap",namespaced:!0},V1Service:{group:"",version:"v1",resource:"services",kind:"Service",namespaced:!0},V1User:{group:"",version:"v1",resource:"users",kind:"User",namespaced:!1},V1StorageClassList:{group:"storage.k8s.io",version:"v1",resource:"storageclasses",kind:"StorageClass",namespaced:!1},V1Beta1PodMetrics:{group:"metrics.k8s.io",version:"v1beta1",resource:"pods",kind:"PodMetrics",namespaced:!0}};function f(a,e,s){return{apiVersion:a.group?a.group+"/"+a.version:a.version,kind:a.kind,metadata:{name:e},...s}}var P=class{constructor(e,s=void 0){this.val=e;this.extra=s;this.ok=!1;this.err=!0}},w=class{constructor(e,s=void 0){this.val=e;this.extra=s;this.ok=!0;this.err=!1}};function Te(a){return"ok"in a&&typeof a.ok=="boolean"&&"err"in a&&typeof a.err=="boolean"}var E="",O="Network",Q="Forbidden",X="BadRequest",L="NotFound",K="Unauthorized",Y="AlreadyExists",Z="InternalServerError",ee="NotImplemented",se="BadGateway",A="ServiceUnavailable",te="GatewayTimeout",M=a=>{switch(a){case 400:return X;case 401:return K;case 403:return Q;case 404:return L;case 409:return Y;case 500:return Z;case 501:return ee;case 502:return se;case 503:return A;case 504:return te}return E},o=class{static Ok(){return new w(void 0)}static Value(e){return new w(e)}static Failed(e,s="",t=E,n=void 0){return new P(new x(e,t,s),n)}static Error(e){return new P(e)}static WithExtra(e,s=void 0){return e.extra=s,e}},x=class{constructor(e,s=E,t=""){this.message=e;this.type=s;this.reason=t}};var C={secure:!0,expires:365*10,sameSite:"strict"},d=y.loftAccessKeyIdentifier,R=y.loftImpersonateSubjectIdentifier,k=y.loftImpersonateJoinedGroupIdentifier,ne=["v4.channel.k8s.io","v3.channel.k8s.io","v2.channel.k8s.io","channel.k8s.io"];function oe(){return typeof window<"u"&&window.location.href.startsWith("http://localhost:3000")?"https://localhost:9898":""}function ae(){return typeof window>"u"||window.location.host==="localhost:3000"?"wss://localhost:8080":`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}`}function W(a){return[a.virtualCluster?"loft:vcluster:main":`loft:space:${a.project}:${a.space}`]}var $="/kubernetes/management",I="/kubernetes/cluster/",_="/kubernetes/virtualcluster/",J="/kubernetes/project/";function Le(a,e){return a?e&&e.endsWith("-")?`${e}${a}`:e===""?`${a}`:e?`${e}-${a}`:`p-${a}`:"p-"}function Ke(a,e){if(a)return e?e.endsWith("-")?a.replace(new RegExp(`^${e}`),""):a.replace(new RegExp(`^${e}-`),""):a.replace(/^p-/,"")}var b=class{constructor(e,s,t){this.apiHost="";this.wsHost="";this.accessKey="";this.managementNonResource=()=>new l(this,{basePath:$,headers:this.impersonationHeaders()});this.cluster=(e,s)=>new l(this,{basePath:I+e,groupVersionResource:s,headers:this.impersonationHeaders()});this.clusterNonResource=e=>new l(this,{basePath:I+e,headers:this.impersonationHeaders()});this.project=(e,s)=>new l(this,{basePath:J+e.project+"/"+(e.space?"space/"+e.space:"virtualcluster/"+e.virtualCluster),groupVersionResource:s,project:e,headers:this.impersonationHeaders(W(e))});this.projectNonResource=e=>new l(this,{basePath:J+e.project+"/"+(e.space?"space/"+e.space:"virtualcluster/"+e.virtualCluster),project:e,headers:this.impersonationHeaders(W(e))});this.apiHost=s||oe(),this.wsHost=t||ae(),this.accessKey=e||b.getAccessKey()}static getAccessKey(){return localStorage.getItem(d)}static tryCastToStatus(e){if(e.kind){if(e.kind!=="Status"||e.apiVersion!=="v1")return o.Value(null)}else return o.Value(null);return o.Value(e)}async getUser(){let e=await this.management(c.ManagementV1Self).Create(f(c.ManagementV1Self));return e.err?e:e.val.status?.user?(typeof window<"u"&&(window.loft||(window.loft={}),window.loft.instanceID=e.val.status.instanceID,window.loft.chatAuthToken=e.val.status.chatAuthToken,window.loft.user=e.val.status.user),o.Value(e.val.status.user.name)):o.Failed("no user found")}getAccessKey(){return this.accessKey}async loftVersion(e){try{let s=this.apiHost+"/version";e&&(s+="?refresh=true");let n=await(await fetch(s)).json();return o.Value(n)}catch(s){return console.error(s),o.Failed("error during version retrieval")}}impersonatedUser(){try{let e=localStorage.getItem(R);if(e)return JSON.parse(e)}catch(e){console.error(e)}}impersonate(e,s,t){s?(localStorage.setItem(R,JSON.stringify({name:e,subject:s,groups:t})),s&&m.set(R,s,C),t?.forEach(n=>{let r=m.get(k);r?(r+=", "+n,m.set(k,r,C)):m.set(k,n,C)})):(localStorage.removeItem(R),m.remove(R),m.remove(k))}async login(e,s){let t=await this.request("/auth/password/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,password:s})});if(t.err)return t;let n=t.val;return this.setAccessKey(n.accessKey),o.Ok()}async loginWithAccessKey(e){this.isLoggedIn()&&await this.logout(),this.accessKey=e;let s=await this.management(c.ManagementV1Self).Create(f(c.ManagementV1Self));return s.err?(this.clearStorage(),s):(this.setAccessKey(e),o.Ok())}isLoggedIn(){return!!this.accessKey}setAccessKey(e){this.accessKey=e,localStorage.setItem(d,e),m.set(d,e,C)}async stream(e,s){try{let t=await fetch(this.apiHost+e,s);return t.status>=400||!t.body?await this.parseResponse(e,t):o.Value(t.body.getReader())}catch(t){return o.Failed(t+"","NetworkError",O)}}async request(e,s){try{let t=await fetch(this.apiHost+e,{...s,credentials:"same-origin"});return await this.parseResponse(e,t)}catch(t){return o.Failed(t+"","NetworkError",O)}}async socket(e,s){return this.refreshCookie(),new Promise((t,n)=>{let r=new WebSocket(`${this.wsHost}${e}`,s),u=!1;r.onopen=()=>{u=!0,t(r)},r.onerror=i=>{if(!u){let p=m.get(d)!="";n(p?i:new Error("Web socket is not authenticated. Please log in again"))}}})}async parseResponse(e,s){let t=await s.text(),n;try{n=JSON.parse(t)}catch{if(s.status===404)return o.Failed("page not found","NotFound",L);if(s.status===503){if(e.includes("kiosk.sh")||e.includes("cluster.loft.sh")){let i=e.split("/");return i.length>=4&&i[0]===""&&i[1]==="kubernetes"&&i[2]==="cluster"?o.Failed(`Agent seems to be currently unavailable, it is maybe just starting up. Click here for more information`,"LoftAgentUnavailable",A):o.Failed("Agent seems to be currently unavailable, it is maybe just starting up","LoftAgentUnavailable",A)}}else if(s.status===200)return o.Value(t);return console.info("Unexpected Server Response",t),o.Failed("Unexpected server response",M(s.status),M(s.status))}let r=b.tryCastToStatus(n);return r.err?r:r.val!==null&&r.val.status==="Failure"?r.val.code===500&&(r.val.message?.indexOf("vcluster secret not found")!==-1||r.val.message.indexOf("no ready pod for virtual cluster")!==-1)?o.Failed("vcluster seems to be not ready. Please refresh in a second",r.val.reason,M(r.val.code)):o.Failed(r.val.message,r.val.reason,M(r.val.code)):s.status>=400?o.Failed("unknown error","Unknown",M(s.status)):o.Value(n)}management(e){return new l(this,{basePath:$,groupVersionResource:e,headers:this.impersonationHeaders()})}vCluster(e,s){return new l(this,{basePath:_+e.cluster+"/"+e.namespace+"/"+e.name,groupVersionResource:s,vCluster:e,headers:this.impersonationHeaders()})}vClusterNonResource(e){return new l(this,{basePath:_+e.cluster+"/"+e.namespace+"/"+e.name,vCluster:e,headers:this.impersonationHeaders()})}auto(e,s,t,n){return t?this.project(t,n):s?this.vCluster(s,n):e?this.cluster(e,n):this.management(n)}autoNonResource(e,s,t){return t?this.projectNonResource(t):s?this.vClusterNonResource(s):e?this.clusterNonResource(e):this.managementNonResource()}async doRawSocket(e,s){try{return o.Value(await this.socket(e,s))}catch(t){return console.error(t),o.Failed(t.message||JSON.stringify(t))}}async doRawStream(e,s,t){return this.doRawInternal(e,s,t,!0)}async doRaw(e,s,t){return this.doRawInternal(e,s,t)}async doRawInternal(e,s,t,n){let r=this.accessKey,u=r?new Headers({...t,Authorization:"bearer "+r,"X-Sleep-Mode-Ignore":"true","X-Platform-Client":"true"}):new Headers({...t,"X-Sleep-Mode-Ignore":"true","X-Platform-Client":"true"}),i=n?await this.stream(e,{...s,headers:u}):await this.request(e,{...s,headers:u});return i.err&&i.val.type===K&&(i.val.message==="Access key not found. Please login again"||i.val.message==="invalid bearer token")&&(this.clearStorage(),typeof window<"u"&&(window.location.href="/"),await new Promise(()=>{})),i}impersonationHeaders(e){let s=this.impersonatedUser(),t={};return s&&(s.subject&&(t["Impersonate-User"]=s.subject),[...h(s.groups),...h(e)].forEach(n=>{t["Impersonate-Joined-Group"]?t["Impersonate-Joined-Group"]+=", "+n:t["Impersonate-Joined-Group"]=n})),t}clearStorage(){this.accessKey=null,localStorage.removeItem(d),localStorage.removeItem(R),m.remove(d,{secure:!0}),m.remove(R,{secure:!0}),m.remove(k,{secure:!0})}refreshCookie(){let e=this.accessKey||localStorage.getItem(d),s=m.get(d);e&&e!=s&&m.set(d,e,C)}async logout(){let e=await this.management(c.ManagementV1Self).Create(f(c.ManagementV1Self));if(e.err)return this.clearStorage(),e;if(!e.val.status?.accessKey)return this.clearStorage(),o.Ok();let s=await this.management(c.ManagementV1OwnedAccessKey).Delete(e.val.status.accessKey);return s.err?(this.clearStorage(),s):(this.clearStorage(),o.Ok())}},l=class{constructor(e,s){this.client=e,this.options=s}Name(e){return new l(this.client,{...this.options,name:e})}Namespace(e){return e?new l(this.client,{...this.options,namespace:e}):new l(this.client,{...this.options})}Resource(e){return new l(this.client,{...this.options,groupVersionResource:e})}buildPath(e){if(this.options.groupVersionResource)if(this.options.basePath){if(!this.options.name&&this.options.groupVersionResource.subResource)return o.Failed("resource name required when subresource is used")}else return o.Failed("basePath is missing");else return o.Failed("groupVersionResource is missing");let s=[this.options.basePath];this.options.groupVersionResource.group?s.push("apis",this.options.groupVersionResource.group):s.push("api"),s.push(this.options.groupVersionResource.version),this.options.namespace&&s.push("namespaces",this.options.namespace),s.push(this.options.groupVersionResource.resource),this.options.name&&s.push(this.options.name),this.options.groupVersionResource.subResource&&s.push(this.options.groupVersionResource.subResource);let t="";if(e){let n=[];for(let r of Object.keys(e))e[r]&&(Array.isArray(e[r])?e[r].forEach(u=>{n.push(r+"="+encodeURIComponent(u))}):n.push(r+"="+encodeURIComponent(e[r])));n.length>0&&(t="?"+n.join("&"))}else t="?timeout=180s";return o.Value(s.join("/")+t)}parseResourceList(e,s,t,n,r,u){for(let i=0;i1||r&&n.find(v=>v.group===e&&v.resource===V)||n.push({resource:V,subResource:g.length>1?g[1]:void 0,group:e,version:s,kind:p.kind,namespaced:p.namespaced,verbs:p.verbs})}}async ApiResources(e,s){let t=[],n=await this.client.doRaw([this.options.basePath,"api"].join("/"));if(n.err)return n;let r=[];for(let i=0;i{let g=n.val.versions[p];if(g===void 0)return;let V=await this.client.doRaw([this.options.basePath,"api",g].join("/"));if(V.err){console.error(V.val.message);return}this.parseResourceList("",g,V.val,t,e,s)})(i)),r.length>20&&(await Promise.all(r),r=[]);r.length>0&&(await Promise.all(r),r=[]);let u=await this.client.doRaw([this.options.basePath,"apis"].join("/"));if(u.err)return u;for(let i=0;i{let j=v.versions[V];if(j===void 0)return;let G=await this.client.doRaw([this.options.basePath,"apis",v.name,j.version].join("/"));if(G.err){console.error(G.val.message);return}this.parseResourceList(v.name,j.version,G.val,t,e,s)})(g,p)),r.length>20&&(await Promise.all(r),r=[])}return r.length>0&&await Promise.all(r),o.Value(t)}async Version(){let e=[this.options.basePath,"version"];return await this.client.doRaw(e.join("/"))}async VirtualClusterInstanceLogs(e,s,t){let n=[this.options.basePath,`apis/management.loft.sh/v1/namespaces/${e}/virtualclusterinstances/${s}/log`].join("/"),r=[];if(t)for(let u of Object.keys(t))r.push(`${u}=${encodeURIComponent(t[u])}`);return r.length>0&&(n+="?"+r.join("&")),await this.client.doRawStream(n,void 0,this.options.headers)}async TaskLogs(e,s){let t=[this.options.basePath,`apis/management.loft.sh/v1/tasks/${e}/log`].join("/"),n=[];if(s)for(let r of Object.keys(s))n.push(`${r}=${encodeURIComponent(s[r])}`);return n.length>0&&(t+="?"+n.join("&")),await this.client.doRawStream(t,void 0,this.options.headers)}async Logs(e,s,t){let n=[this.options.basePath,`api/v1/namespaces/${e}/pods/${s}/log`].join("/"),r=z(t);return r.length>0&&(n+="?"+r),await this.client.doRawStream(n,void 0,this.options.headers)}async Exec(e,s,t){let n=[this.options.basePath,`api/v1/namespaces/${e}/pods/${s}/exec`].join("/"),r=z(t);return r.length>0&&(n+="?"+r),await this.client.doRawSocket(n,ne)}async Path(e,s,t){let n=[this.options.basePath,e];return await this.client.doRaw(n.join("/"),s,{...t,...this.options.headers})}ResolvePath(e){return e&&(this.options.name=e),this.buildPath()}async Get(e,s){this.options.name=e;let t=this.buildPath(s);return t.err?t:o.WithExtra(await this.client.doRaw(t.val,void 0,this.options.headers),this.options)}async List(e){if(this.options.name)return o.Failed("name is set on a list request");let s=this.buildPath(e);return s.err?s:o.WithExtra(await this.client.doRaw(s.val,void 0,this.options.headers),this.options)}async ListTable(e){if(this.options.name)return o.Failed("name is set on a list request");let s=this.buildPath(e);return s.err?s:o.WithExtra(await this.client.doRaw(s.val,void 0,{...this.options.headers,Accept:"application/json;as=Table;v=v1;g=meta.k8s.io,application/json;as=Table;v=v1beta1;g=meta.k8s.io,application/json"}),this.options)}async Create(e,s){let t=this.buildPath(s);return t.err?t:o.WithExtra(await this.client.doRaw(t.val,{method:"POST",body:JSON.stringify(e)},{...this.options.headers,"Content-Type":"application/json"}),this.options)}async PatchObject(e,s,t,n){let r=re.generate(e,s);return this.Patch(s.metadata?.name,r,t,n)}async Patch(e,s,t,n){this.options.name=e;let r=this.buildPath(n);return r.err?r:o.WithExtra(await this.client.doRaw(r.val,{method:"PATCH",body:JSON.stringify(s,function(u,i){return i===void 0?null:i})},{...this.options.headers,"Content-Type":t||"application/merge-patch+json"}),this.options)}async Update(e,s,t){this.options.name=e;let n=this.buildPath(t);return n.err?n:o.WithExtra(await this.client.doRaw(n.val,{method:"PUT",body:JSON.stringify(s)},{...this.options.headers,"Content-Type":"application/json"}),this.options)}async Delete(e,s){this.options.name=e;let t=this.buildPath(s);return t.err?t:o.WithExtra(await this.client.doRaw(t.val,{method:"DELETE"},this.options.headers),this.options)}async CanI(e){let s=this.options.groupVersionResource,t=this.options.basePath?.indexOf(I)===0?this.options.basePath.substring(I.length):void 0,n,r;this.options.project?(n=this.client.project(this.options.project,c.V1SelfSubjectAccessReview),r=f(c.V1SelfSubjectAccessReview)):this.options.vCluster?(n=this.client.vCluster(this.options.vCluster,c.V1SelfSubjectAccessReview),r=f(c.V1SelfSubjectAccessReview)):t?(n=this.client.cluster(t,c.V1SelfSubjectAccessReview),r=f(c.V1SelfSubjectAccessReview)):(n=this.client.management(c.ManagementV1SelfSubjectAccessReview),r=f(c.ManagementV1SelfSubjectAccessReview)),r.spec={resourceAttributes:{verb:e,name:this.options.name,namespace:this.options.namespace,group:s.group,version:s.version,resource:s.resource,subresource:s.subResource}};let u=await n.Create(r);return u.err?u:o.Value(!!(u.val.status?.allowed&&!u.val.status.denied))}};function z(a){let e=new URLSearchParams;for(let[s,t]of Object.entries(a))Array.isArray(t)?t.forEach(n=>{e.append(s,n)}):e.append(s,t);return e.toString()}var ie=b;export{B as APIExtensionsGroup,Re as APIExtensionsGroupVersion,H as APIExtensionsVersion,ie as Client,I as ClusterBasePath,P as Err,Y as ErrorTypeAlreadyExists,se as ErrorTypeBadGateway,X as ErrorTypeBadRequest,Q as ErrorTypeForbidden,te as ErrorTypeGatewayTimeout,Z as ErrorTypeInternalError,O as ErrorTypeNetwork,L as ErrorTypeNotFound,ee as ErrorTypeNotImplemented,A as ErrorTypeServiceUnavailable,K as ErrorTypeUnauthorized,E as ErrorTypeUnknown,x as Failed,D as List,ge as LoftSchemeGroup,S as LoftSchemeGroupCluster,Ve as LoftSchemeGroupStorage,de as LoftSchemeGroupVersion,me as LoftSchemeGroupVersionCluster,he as LoftSchemeGroupVersionStorage,pe as LoftSchemeGroupVersionVirtualCluster,N as LoftSchemeGroupVirtualCluster,F as LoftSchemeVersion,T as LoftSchemeVersionCluster,fe as LoftSchemeVersionStorage,q as LoftSchemeVersionVirtualCluster,$ as ManagementBasePath,M as MapErrorCode,f as NewResource,w as Ok,J as ProjectBasePath,c as Resources,o as Return,_ as VClusterBasePath,oe as getApiHost,Ke as getProjectFromNamespace,Le as getProjectNamespace,Te as isResult}; +import m from"js-cookie";import re from"json-merge-patch";var y={loftAccessKeyIdentifier:"loft_access_key",loftImpersonateSubjectIdentifier:"loft_impersonate_subject",loftImpersonateJoinedGroupIdentifier:"loft_impersonate_joined_group"};function h(a){return a||[]}var D={ManagementV1AgentAuditEvent:{group:"management.loft.sh",version:"v1",resource:"agentauditevents",subResource:"",namespaced:!1,kind:"AgentAuditEvent"},ManagementV1Announcement:{group:"management.loft.sh",version:"v1",resource:"announcements",subResource:"",namespaced:!1,kind:"Announcement"},ManagementV1App:{group:"management.loft.sh",version:"v1",resource:"apps",subResource:"",namespaced:!1,kind:"App"},ManagementV1AppCredentials:{group:"management.loft.sh",version:"v1",resource:"apps",subResource:"credentials",namespaced:!1,kind:"AppCredentials"},ManagementV1Backup:{group:"management.loft.sh",version:"v1",resource:"backups",subResource:"",namespaced:!1,kind:"Backup"},ManagementV1BackupApply:{group:"management.loft.sh",version:"v1",resource:"backups",subResource:"apply",namespaced:!1,kind:"BackupApply"},ManagementV1Cluster:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"",namespaced:!1,kind:"Cluster"},ManagementV1ClusterAccess:{group:"management.loft.sh",version:"v1",resource:"clusteraccesses",subResource:"",namespaced:!1,kind:"ClusterAccess"},ManagementV1ClusterAccessKey:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"accesskey",namespaced:!1,kind:"ClusterAccessKey"},ManagementV1ClusterAgentConfig:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"agentconfig",namespaced:!1,kind:"ClusterAgentConfig"},ManagementV1ClusterCharts:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"charts",namespaced:!1,kind:"ClusterCharts"},ManagementV1ClusterDomain:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"domain",namespaced:!1,kind:"ClusterDomain"},ManagementV1ClusterMemberAccess:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"memberaccess",namespaced:!1,kind:"ClusterMemberAccess"},ManagementV1ClusterMembers:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"members",namespaced:!1,kind:"ClusterMembers"},ManagementV1ClusterReset:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"reset",namespaced:!1,kind:"ClusterReset"},ManagementV1ClusterRoleTemplate:{group:"management.loft.sh",version:"v1",resource:"clusterroletemplates",subResource:"",namespaced:!1,kind:"ClusterRoleTemplate"},ManagementV1ClusterVirtualClusterDefaults:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"virtualclusterdefaults",namespaced:!1,kind:"ClusterVirtualClusterDefaults"},ManagementV1Config:{group:"management.loft.sh",version:"v1",resource:"configs",subResource:"",namespaced:!1,kind:"Config"},ManagementV1ConvertVirtualClusterConfig:{group:"management.loft.sh",version:"v1",resource:"convertvirtualclusterconfig",subResource:"",namespaced:!1,kind:"ConvertVirtualClusterConfig"},ManagementV1DevPodWorkspaceInstance:{group:"management.loft.sh",version:"v1",resource:"devpodworkspaceinstances",subResource:"",namespaced:!0,kind:"DevPodWorkspaceInstance"},ManagementV1DevPodWorkspaceInstanceState:{group:"management.loft.sh",version:"v1",resource:"devpodworkspaceinstances",subResource:"state",namespaced:!0,kind:"DevPodWorkspaceInstanceState"},ManagementV1DevPodWorkspaceTemplate:{group:"management.loft.sh",version:"v1",resource:"devpodworkspacetemplates",subResource:"",namespaced:!1,kind:"DevPodWorkspaceTemplate"},ManagementV1DirectClusterEndpointToken:{group:"management.loft.sh",version:"v1",resource:"directclusterendpointtokens",subResource:"",namespaced:!1,kind:"DirectClusterEndpointToken"},ManagementV1Event:{group:"management.loft.sh",version:"v1",resource:"events",subResource:"",namespaced:!1,kind:"Event"},ManagementV1Feature:{group:"management.loft.sh",version:"v1",resource:"features",subResource:"",namespaced:!1,kind:"Feature"},ManagementV1IngressAuthToken:{group:"management.loft.sh",version:"v1",resource:"ingressauthtokens",subResource:"",namespaced:!1,kind:"IngressAuthToken"},ManagementV1Kiosk:{group:"management.loft.sh",version:"v1",resource:"kiosk",subResource:"",namespaced:!1,kind:"Kiosk"},ManagementV1License:{group:"management.loft.sh",version:"v1",resource:"licenses",subResource:"",namespaced:!1,kind:"License"},ManagementV1LicenseRequest:{group:"management.loft.sh",version:"v1",resource:"licenses",subResource:"request",namespaced:!1,kind:"LicenseRequest"},ManagementV1LicenseToken:{group:"management.loft.sh",version:"v1",resource:"licensetokens",subResource:"",namespaced:!1,kind:"LicenseToken"},ManagementV1LoftUpgrade:{group:"management.loft.sh",version:"v1",resource:"loftupgrades",subResource:"",namespaced:!1,kind:"LoftUpgrade"},ManagementV1OIDCClient:{group:"management.loft.sh",version:"v1",resource:"oidcclients",subResource:"",namespaced:!0,kind:"OIDCClient"},ManagementV1OwnedAccessKey:{group:"management.loft.sh",version:"v1",resource:"ownedaccesskeys",subResource:"",namespaced:!1,kind:"OwnedAccessKey"},ManagementV1Project:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"",namespaced:!1,kind:"Project"},ManagementV1ProjectChartInfo:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"chartinfo",namespaced:!1,kind:"ProjectChartInfo"},ManagementV1ProjectCharts:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"charts",namespaced:!1,kind:"ProjectCharts"},ManagementV1ProjectClusters:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"clusters",namespaced:!1,kind:"ProjectClusters"},ManagementV1ProjectImportSpace:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"importspace",namespaced:!1,kind:"ProjectImportSpace"},ManagementV1ProjectMembers:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"members",namespaced:!1,kind:"ProjectMembers"},ManagementV1ProjectMigrateSpaceInstance:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"migratespaceinstance",namespaced:!1,kind:"ProjectMigrateSpaceInstance"},ManagementV1ProjectMigrateVirtualClusterInstance:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"migratevirtualclusterinstance",namespaced:!1,kind:"ProjectMigrateVirtualClusterInstance"},ManagementV1ProjectSecret:{group:"management.loft.sh",version:"v1",resource:"projectsecrets",subResource:"",namespaced:!0,kind:"ProjectSecret"},ManagementV1ProjectTemplates:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"templates",namespaced:!1,kind:"ProjectTemplates"},ManagementV1RedirectToken:{group:"management.loft.sh",version:"v1",resource:"redirecttokens",subResource:"",namespaced:!1,kind:"RedirectToken"},ManagementV1RegisterVirtualCluster:{group:"management.loft.sh",version:"v1",resource:"registervirtualclusters",subResource:"",namespaced:!1,kind:"RegisterVirtualCluster"},ManagementV1ResetAccessKey:{group:"management.loft.sh",version:"v1",resource:"resetaccesskeys",subResource:"",namespaced:!1,kind:"ResetAccessKey"},ManagementV1Runner:{group:"management.loft.sh",version:"v1",resource:"runners",subResource:"",namespaced:!1,kind:"Runner"},ManagementV1RunnerAccessKey:{group:"management.loft.sh",version:"v1",resource:"runners",subResource:"accesskey",namespaced:!1,kind:"RunnerAccessKey"},ManagementV1RunnerConfig:{group:"management.loft.sh",version:"v1",resource:"runners",subResource:"config",namespaced:!1,kind:"RunnerConfig"},ManagementV1Self:{group:"management.loft.sh",version:"v1",resource:"selves",subResource:"",namespaced:!1,kind:"Self"},ManagementV1SelfSubjectAccessReview:{group:"management.loft.sh",version:"v1",resource:"selfsubjectaccessreviews",subResource:"",namespaced:!1,kind:"SelfSubjectAccessReview"},ManagementV1SharedSecret:{group:"management.loft.sh",version:"v1",resource:"sharedsecrets",subResource:"",namespaced:!0,kind:"SharedSecret"},ManagementV1SpaceInstance:{group:"management.loft.sh",version:"v1",resource:"spaceinstances",subResource:"",namespaced:!0,kind:"SpaceInstance"},ManagementV1SpaceTemplate:{group:"management.loft.sh",version:"v1",resource:"spacetemplates",subResource:"",namespaced:!1,kind:"SpaceTemplate"},ManagementV1SubjectAccessReview:{group:"management.loft.sh",version:"v1",resource:"subjectaccessreviews",subResource:"",namespaced:!1,kind:"SubjectAccessReview"},ManagementV1Task:{group:"management.loft.sh",version:"v1",resource:"tasks",subResource:"",namespaced:!1,kind:"Task"},ManagementV1TaskLog:{group:"management.loft.sh",version:"v1",resource:"tasks",subResource:"log",namespaced:!1,kind:"TaskLog"},ManagementV1Team:{group:"management.loft.sh",version:"v1",resource:"teams",subResource:"",namespaced:!1,kind:"Team"},ManagementV1TeamAccessKeys:{group:"management.loft.sh",version:"v1",resource:"teams",subResource:"accesskeys",namespaced:!1,kind:"TeamAccessKeys"},ManagementV1TeamClusters:{group:"management.loft.sh",version:"v1",resource:"teams",subResource:"clusters",namespaced:!1,kind:"TeamClusters"},ManagementV1TranslateVClusterResourceName:{group:"management.loft.sh",version:"v1",resource:"translatevclusterresourcenames",subResource:"",namespaced:!1,kind:"TranslateVClusterResourceName"},ManagementV1User:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"",namespaced:!1,kind:"User"},ManagementV1UserAccessKeys:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"accesskeys",namespaced:!1,kind:"UserAccessKeys"},ManagementV1UserClusters:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"clusters",namespaced:!1,kind:"UserClusters"},ManagementV1UserPermissions:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"permissions",namespaced:!1,kind:"UserPermissions"},ManagementV1UserProfile:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"profile",namespaced:!1,kind:"UserProfile"},ManagementV1VirtualClusterAccessKey:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"accesskey",namespaced:!0,kind:"VirtualClusterAccessKey"},ManagementV1VirtualClusterInstance:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"",namespaced:!0,kind:"VirtualClusterInstance"},ManagementV1VirtualClusterInstanceKubeConfig:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"kubeconfig",namespaced:!0,kind:"VirtualClusterInstanceKubeConfig"},ManagementV1VirtualClusterInstanceLog:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"log",namespaced:!0,kind:"VirtualClusterInstanceLog"},ManagementV1VirtualClusterTemplate:{group:"management.loft.sh",version:"v1",resource:"virtualclustertemplates",subResource:"",namespaced:!1,kind:"VirtualClusterTemplate"}};var N="virtualcluster.loft.sh",q="v1",pe="virtualcluster.loft.sh/v1",S="cluster.loft.sh",T="v1",me="cluster.loft.sh/v1",ge="management.loft.sh",F="v1",de="management.loft.sh/v1",Ve="storage.loft.sh",fe="v1",he="storage.loft.sh/v1",B="apiextensions.k8s.io",H="v1",Re="apiextensions.k8s.io/v1",U=class{};var c={...D,ClusterV1SleepModeConfig:{group:S,version:T,resource:"sleepmodeconfigs",kind:"SleepModeConfig",namespaced:!0},ClusterV1HelmRelease:{group:S,version:T,resource:"helmreleases",kind:"HelmRelease",namespaced:!0},ClusterV1ChartInfo:{group:S,version:T,resource:"chartinfos",kind:"ChartInfo"},VirtualclusterV1HelmRelease:{group:N,version:q,resource:"helmreleases",kind:"HelmRelease",namespaced:!0},CustomResourceDefinition:{group:B,version:H,resource:"customresourcedefinitions",kind:"CustomResourceDefinition"},StorageV1ClusterQuota:{group:"storage.loft.sh",version:F,resource:"clusterquotas",kind:"ClusterQuota"},NetworkingV1Ingress:{group:"networking.k8s.io",version:"v1",resource:"ingresses",kind:"Ingress",namespaced:!0},V1StatefulSet:{group:"apps",version:"v1",resource:"statefulsets",kind:"StatefulSet",namespaced:!0},V1Deployment:{group:"apps",version:"v1",resource:"deployments",kind:"Deployment",namespaced:!0},V1Event:{group:"",version:"v1",resource:"events",kind:"Event",namespaced:!0},V1Pod:{group:"",version:"v1",resource:"pods",kind:"Pod",namespaced:!0},V1Node:{group:"",version:"v1",resource:"nodes",kind:"Node"},V1Namespace:{group:"",version:"v1",resource:"namespaces",kind:"Namespace"},V1SelfSubjectAccessReview:{group:"authorization.k8s.io",version:"v1",resource:"selfsubjectaccessreviews",kind:"SelfSubjectAccessReview"},V1ClusterRole:{group:"rbac.authorization.k8s.io",version:"v1",resource:"clusterroles",kind:"ClusterRole"},V1ClusterRoleBinding:{group:"rbac.authorization.k8s.io",version:"v1",resource:"clusterrolebindings",kind:"ClusterRoleBinding"},V1Role:{group:"rbac.authorization.k8s.io",version:"v1",resource:"roles",kind:"Role",namespaced:!0},V1RoleBinding:{group:"rbac.authorization.k8s.io",version:"v1",resource:"rolebindings",kind:"RoleBinding",namespaced:!0},V1Secret:{group:"",version:"v1",resource:"secrets",kind:"Secret",namespaced:!0},V1ConfigMap:{group:"",version:"v1",resource:"configmaps",kind:"ConfigMap",namespaced:!0},V1Service:{group:"",version:"v1",resource:"services",kind:"Service",namespaced:!0},V1User:{group:"",version:"v1",resource:"users",kind:"User",namespaced:!1},V1StorageClassList:{group:"storage.k8s.io",version:"v1",resource:"storageclasses",kind:"StorageClass",namespaced:!1},V1Beta1PodMetrics:{group:"metrics.k8s.io",version:"v1beta1",resource:"pods",kind:"PodMetrics",namespaced:!0}};function f(a,e,s){return{apiVersion:a.group?a.group+"/"+a.version:a.version,kind:a.kind,metadata:{name:e},...s}}var P=class{constructor(e,s=void 0){this.val=e;this.extra=s;this.ok=!1;this.err=!0}},w=class{constructor(e,s=void 0){this.val=e;this.extra=s;this.ok=!0;this.err=!1}};function Te(a){return"ok"in a&&typeof a.ok=="boolean"&&"err"in a&&typeof a.err=="boolean"}var E="",O="Network",Q="Forbidden",X="BadRequest",L="NotFound",K="Unauthorized",Y="AlreadyExists",Z="InternalServerError",ee="NotImplemented",se="BadGateway",A="ServiceUnavailable",te="GatewayTimeout",M=a=>{switch(a){case 400:return X;case 401:return K;case 403:return Q;case 404:return L;case 409:return Y;case 500:return Z;case 501:return ee;case 502:return se;case 503:return A;case 504:return te}return E},o=class{static Ok(){return new w(void 0)}static Value(e){return new w(e)}static Failed(e,s="",t=E,n=void 0){return new P(new x(e,t,s),n)}static Error(e){return new P(e)}static WithExtra(e,s=void 0){return e.extra=s,e}},x=class{constructor(e,s=E,t=""){this.message=e;this.type=s;this.reason=t}};var C={secure:!0,expires:365*10,sameSite:"strict"},d=y.loftAccessKeyIdentifier,R=y.loftImpersonateSubjectIdentifier,k=y.loftImpersonateJoinedGroupIdentifier,ne=["v4.channel.k8s.io","v3.channel.k8s.io","v2.channel.k8s.io","channel.k8s.io"];function oe(){return typeof window<"u"&&window.location.href.startsWith("http://localhost:3000")?"https://localhost:9898":""}function ae(){return typeof window>"u"||window.location.host==="localhost:3000"?"wss://localhost:8080":`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}`}function W(a){return[a.virtualCluster?"loft:vcluster:main":`loft:space:${a.project}:${a.space}`]}var $="/kubernetes/management",I="/kubernetes/cluster/",_="/kubernetes/virtualcluster/",J="/kubernetes/project/";function Le(a,e){return a?e&&e.endsWith("-")?`${e}${a}`:e===""?`${a}`:e?`${e}-${a}`:`p-${a}`:"p-"}function Ke(a,e){if(a)return e?e.endsWith("-")?a.replace(new RegExp(`^${e}`),""):a.replace(new RegExp(`^${e}-`),""):a.replace(/^p-/,"")}var b=class{constructor(e,s,t){this.apiHost="";this.wsHost="";this.accessKey="";this.managementNonResource=()=>new l(this,{basePath:$,headers:this.impersonationHeaders()});this.cluster=(e,s)=>new l(this,{basePath:I+e,groupVersionResource:s,headers:this.impersonationHeaders()});this.clusterNonResource=e=>new l(this,{basePath:I+e,headers:this.impersonationHeaders()});this.project=(e,s)=>new l(this,{basePath:J+e.project+"/"+(e.space?"space/"+e.space:"virtualcluster/"+e.virtualCluster),groupVersionResource:s,project:e,headers:this.impersonationHeaders(W(e))});this.projectNonResource=e=>new l(this,{basePath:J+e.project+"/"+(e.space?"space/"+e.space:"virtualcluster/"+e.virtualCluster),project:e,headers:this.impersonationHeaders(W(e))});this.apiHost=s||oe(),this.wsHost=t||ae(),this.accessKey=e||b.getAccessKey()}static getAccessKey(){return localStorage.getItem(d)}static tryCastToStatus(e){if(e.kind){if(e.kind!=="Status"||e.apiVersion!=="v1")return o.Value(null)}else return o.Value(null);return o.Value(e)}async getUser(){let e=await this.management(c.ManagementV1Self).Create(f(c.ManagementV1Self));return e.err?e:e.val.status?.user?(typeof window<"u"&&(window.loft||(window.loft={}),window.loft.instanceID=e.val.status.instanceID,window.loft.chatAuthToken=e.val.status.chatAuthToken,window.loft.user=e.val.status.user),o.Value(e.val.status.user.name)):o.Failed("no user found")}getAccessKey(){return this.accessKey}async loftVersion(e){try{let s=this.apiHost+"/version";e&&(s+="?refresh=true");let n=await(await fetch(s)).json();return o.Value(n)}catch(s){return console.error(s),o.Failed("error during version retrieval")}}impersonatedUser(){try{let e=localStorage.getItem(R);if(e)return JSON.parse(e)}catch(e){console.error(e)}}impersonate(e,s,t){s?(localStorage.setItem(R,JSON.stringify({name:e,subject:s,groups:t})),s&&m.set(R,s,C),t?.forEach(n=>{let r=m.get(k);r?(r+=", "+n,m.set(k,r,C)):m.set(k,n,C)})):(localStorage.removeItem(R),m.remove(R),m.remove(k))}async login(e,s){let t=await this.request("/auth/password/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,password:s})});if(t.err)return t;let n=t.val;return this.setAccessKey(n.accessKey),o.Ok()}async loginWithAccessKey(e){this.isLoggedIn()&&await this.logout(),this.accessKey=e;let s=await this.management(c.ManagementV1Self).Create(f(c.ManagementV1Self));return s.err?(this.clearStorage(),s):(this.setAccessKey(e),o.Ok())}isLoggedIn(){return!!this.accessKey}setAccessKey(e){this.accessKey=e,localStorage.setItem(d,e),m.set(d,e,C)}async stream(e,s){try{let t=await fetch(this.apiHost+e,s);return t.status>=400||!t.body?await this.parseResponse(e,t):o.Value(t.body.getReader())}catch(t){return o.Failed(t+"","NetworkError",O)}}async request(e,s){try{let t=await fetch(this.apiHost+e,{...s,credentials:"same-origin"});return await this.parseResponse(e,t)}catch(t){return o.Failed(t+"","NetworkError",O)}}async socket(e,s){return this.refreshCookie(),new Promise((t,n)=>{let r=new WebSocket(`${this.wsHost}${e}`,s),u=!1;r.onopen=()=>{u=!0,t(r)},r.onerror=i=>{if(!u){let p=m.get(d)!="";n(p?i:new Error("Web socket is not authenticated. Please log in again"))}}})}async parseResponse(e,s){let t=await s.text(),n;try{n=JSON.parse(t)}catch{if(s.status===404)return o.Failed("page not found","NotFound",L);if(s.status===503){if(e.includes("kiosk.sh")||e.includes("cluster.loft.sh")){let i=e.split("/");return i.length>=4&&i[0]===""&&i[1]==="kubernetes"&&i[2]==="cluster"?o.Failed(`Agent seems to be currently unavailable, it is maybe just starting up. Click here for more information`,"LoftAgentUnavailable",A):o.Failed("Agent seems to be currently unavailable, it is maybe just starting up","LoftAgentUnavailable",A)}}else if(s.status===200)return o.Value(t);return console.info("Unexpected Server Response",t),o.Failed("Unexpected server response",M(s.status),M(s.status))}let r=b.tryCastToStatus(n);return r.err?r:r.val!==null&&r.val.status==="Failure"?r.val.code===500&&(r.val.message?.indexOf("vcluster secret not found")!==-1||r.val.message.indexOf("no ready pod for virtual cluster")!==-1)?o.Failed("vcluster seems to be not ready. Please refresh in a second",r.val.reason,M(r.val.code)):o.Failed(r.val.message,r.val.reason,M(r.val.code)):s.status>=400?o.Failed("unknown error","Unknown",M(s.status)):o.Value(n)}management(e){return new l(this,{basePath:$,groupVersionResource:e,headers:this.impersonationHeaders()})}vCluster(e,s){return new l(this,{basePath:_+e.cluster+"/"+e.namespace+"/"+e.name,groupVersionResource:s,vCluster:e,headers:this.impersonationHeaders()})}vClusterNonResource(e){return new l(this,{basePath:_+e.cluster+"/"+e.namespace+"/"+e.name,vCluster:e,headers:this.impersonationHeaders()})}auto(e,s,t,n){return t?this.project(t,n):s?this.vCluster(s,n):e?this.cluster(e,n):this.management(n)}autoNonResource(e,s,t){return t?this.projectNonResource(t):s?this.vClusterNonResource(s):e?this.clusterNonResource(e):this.managementNonResource()}async doRawSocket(e,s){try{return o.Value(await this.socket(e,s))}catch(t){return console.error(t),o.Failed(t.message||JSON.stringify(t))}}async doRawStream(e,s,t){return this.doRawInternal(e,s,t,!0)}async doRaw(e,s,t){return this.doRawInternal(e,s,t)}async doRawInternal(e,s,t,n){let r=this.accessKey,u=r?new Headers({...t,Authorization:"bearer "+r,"X-Sleep-Mode-Ignore":"true","X-Platform-Client":"true"}):new Headers({...t,"X-Sleep-Mode-Ignore":"true","X-Platform-Client":"true"}),i=n?await this.stream(e,{...s,headers:u}):await this.request(e,{...s,headers:u});return i.err&&i.val.type===K&&(i.val.message==="Access key not found. Please login again"||i.val.message==="invalid bearer token")&&(this.clearStorage(),typeof window<"u"&&(window.location.href="/"),await new Promise(()=>{})),i}impersonationHeaders(e){let s=this.impersonatedUser(),t={};return s&&(s.subject&&(t["Impersonate-User"]=s.subject),[...h(s.groups),...h(e)].forEach(n=>{t["Impersonate-Joined-Group"]?t["Impersonate-Joined-Group"]+=", "+n:t["Impersonate-Joined-Group"]=n})),t}clearStorage(){this.accessKey=null,localStorage.removeItem(d),localStorage.removeItem(R),m.remove(d,{secure:!0}),m.remove(R,{secure:!0}),m.remove(k,{secure:!0})}refreshCookie(){let e=this.accessKey||localStorage.getItem(d),s=m.get(d);e&&e!=s&&m.set(d,e,C)}async logout(){let e=await this.management(c.ManagementV1Self).Create(f(c.ManagementV1Self));if(e.err)return this.clearStorage(),e;if(!e.val.status?.accessKey)return this.clearStorage(),o.Ok();let s=await this.management(c.ManagementV1OwnedAccessKey).Delete(e.val.status.accessKey);return s.err?(this.clearStorage(),s):(this.clearStorage(),o.Ok())}},l=class{constructor(e,s){this.client=e,this.options=s}Name(e){return new l(this.client,{...this.options,name:e})}Namespace(e){return e?new l(this.client,{...this.options,namespace:e}):new l(this.client,{...this.options})}Resource(e){return new l(this.client,{...this.options,groupVersionResource:e})}buildPath(e){if(this.options.groupVersionResource)if(this.options.basePath){if(!this.options.name&&this.options.groupVersionResource.subResource)return o.Failed("resource name required when subresource is used")}else return o.Failed("basePath is missing");else return o.Failed("groupVersionResource is missing");let s=[this.options.basePath];this.options.groupVersionResource.group?s.push("apis",this.options.groupVersionResource.group):s.push("api"),s.push(this.options.groupVersionResource.version),this.options.namespace&&s.push("namespaces",this.options.namespace),s.push(this.options.groupVersionResource.resource),this.options.name&&s.push(this.options.name),this.options.groupVersionResource.subResource&&s.push(this.options.groupVersionResource.subResource);let t="";if(e){let n=[];for(let r of Object.keys(e))e[r]&&(Array.isArray(e[r])?e[r].forEach(u=>{n.push(r+"="+encodeURIComponent(u))}):n.push(r+"="+encodeURIComponent(e[r])));n.length>0&&(t="?"+n.join("&"))}else t="?timeout=180s";return o.Value(s.join("/")+t)}parseResourceList(e,s,t,n,r,u){for(let i=0;i1||r&&n.find(v=>v.group===e&&v.resource===V)||n.push({resource:V,subResource:g.length>1?g[1]:void 0,group:e,version:s,kind:p.kind,namespaced:p.namespaced,verbs:p.verbs})}}async ApiResources(e,s){let t=[],n=await this.client.doRaw([this.options.basePath,"api"].join("/"));if(n.err)return n;let r=[];for(let i=0;i{let g=n.val.versions[p];if(g===void 0)return;let V=await this.client.doRaw([this.options.basePath,"api",g].join("/"));if(V.err){console.error(V.val.message);return}this.parseResourceList("",g,V.val,t,e,s)})(i)),r.length>20&&(await Promise.all(r),r=[]);r.length>0&&(await Promise.all(r),r=[]);let u=await this.client.doRaw([this.options.basePath,"apis"].join("/"));if(u.err)return u;for(let i=0;i{let j=v.versions[V];if(j===void 0)return;let G=await this.client.doRaw([this.options.basePath,"apis",v.name,j.version].join("/"));if(G.err){console.error(G.val.message);return}this.parseResourceList(v.name,j.version,G.val,t,e,s)})(g,p)),r.length>20&&(await Promise.all(r),r=[])}return r.length>0&&await Promise.all(r),o.Value(t)}async Version(){let e=[this.options.basePath,"version"];return await this.client.doRaw(e.join("/"))}async VirtualClusterInstanceLogs(e,s,t){let n=[this.options.basePath,`apis/management.loft.sh/v1/namespaces/${e}/virtualclusterinstances/${s}/log`].join("/"),r=[];if(t)for(let u of Object.keys(t))r.push(`${u}=${encodeURIComponent(t[u])}`);return r.length>0&&(n+="?"+r.join("&")),await this.client.doRawStream(n,void 0,this.options.headers)}async TaskLogs(e,s){let t=[this.options.basePath,`apis/management.loft.sh/v1/tasks/${e}/log`].join("/"),n=[];if(s)for(let r of Object.keys(s))n.push(`${r}=${encodeURIComponent(s[r])}`);return n.length>0&&(t+="?"+n.join("&")),await this.client.doRawStream(t,void 0,this.options.headers)}async Logs(e,s,t){let n=[this.options.basePath,`api/v1/namespaces/${e}/pods/${s}/log`].join("/"),r=z(t);return r.length>0&&(n+="?"+r),await this.client.doRawStream(n,void 0,this.options.headers)}async Exec(e,s,t){let n=[this.options.basePath,`api/v1/namespaces/${e}/pods/${s}/exec`].join("/"),r=z(t);return r.length>0&&(n+="?"+r),await this.client.doRawSocket(n,ne)}async Path(e,s,t){let n=[this.options.basePath,e];return await this.client.doRaw(n.join("/"),s,{...t,...this.options.headers})}ResolvePath(e){return e&&(this.options.name=e),this.buildPath()}async Get(e,s){this.options.name=e;let t=this.buildPath(s);return t.err?t:o.WithExtra(await this.client.doRaw(t.val,void 0,this.options.headers),this.options)}async List(e){if(this.options.name)return o.Failed("name is set on a list request");let s=this.buildPath(e);return s.err?s:o.WithExtra(await this.client.doRaw(s.val,void 0,this.options.headers),this.options)}async ListTable(e){if(this.options.name)return o.Failed("name is set on a list request");let s=this.buildPath(e);return s.err?s:o.WithExtra(await this.client.doRaw(s.val,void 0,{...this.options.headers,Accept:"application/json;as=Table;v=v1;g=meta.k8s.io,application/json;as=Table;v=v1beta1;g=meta.k8s.io,application/json"}),this.options)}async Create(e,s){let t=this.buildPath(s);return t.err?t:o.WithExtra(await this.client.doRaw(t.val,{method:"POST",body:JSON.stringify(e)},{...this.options.headers,"Content-Type":"application/json"}),this.options)}async PatchObject(e,s,t,n){let r=re.generate(e,s);return this.Patch(s.metadata?.name,r,t,n)}async Patch(e,s,t,n){this.options.name=e;let r=this.buildPath(n);return r.err?r:o.WithExtra(await this.client.doRaw(r.val,{method:"PATCH",body:JSON.stringify(s,function(u,i){return i===void 0?null:i})},{...this.options.headers,"Content-Type":t||"application/merge-patch+json"}),this.options)}async Update(e,s,t){this.options.name=e;let n=this.buildPath(t);return n.err?n:o.WithExtra(await this.client.doRaw(n.val,{method:"PUT",body:JSON.stringify(s)},{...this.options.headers,"Content-Type":"application/json"}),this.options)}async Delete(e,s){this.options.name=e;let t=this.buildPath(s);return t.err?t:o.WithExtra(await this.client.doRaw(t.val,{method:"DELETE"},this.options.headers),this.options)}async CanI(e){let s=this.options.groupVersionResource,t=this.options.basePath?.indexOf(I)===0?this.options.basePath.substring(I.length):void 0,n,r;this.options.project?(n=this.client.project(this.options.project,c.V1SelfSubjectAccessReview),r=f(c.V1SelfSubjectAccessReview)):this.options.vCluster?(n=this.client.vCluster(this.options.vCluster,c.V1SelfSubjectAccessReview),r=f(c.V1SelfSubjectAccessReview)):t?(n=this.client.cluster(t,c.V1SelfSubjectAccessReview),r=f(c.V1SelfSubjectAccessReview)):(n=this.client.management(c.ManagementV1SelfSubjectAccessReview),r=f(c.ManagementV1SelfSubjectAccessReview)),r.spec={resourceAttributes:{verb:e,name:this.options.name,namespace:this.options.namespace,group:s.group,version:s.version,resource:s.resource,subresource:s.subResource}};let u=await n.Create(r);return u.err?u:o.Value(!!(u.val.status?.allowed&&!u.val.status.denied))}};function z(a){let e=new URLSearchParams;for(let[s,t]of Object.entries(a))Array.isArray(t)?t.forEach(n=>{e.append(s,n)}):e.append(s,t);return e.toString()}var ie=b;export{B as APIExtensionsGroup,Re as APIExtensionsGroupVersion,H as APIExtensionsVersion,ie as Client,I as ClusterBasePath,P as Err,Y as ErrorTypeAlreadyExists,se as ErrorTypeBadGateway,X as ErrorTypeBadRequest,Q as ErrorTypeForbidden,te as ErrorTypeGatewayTimeout,Z as ErrorTypeInternalError,O as ErrorTypeNetwork,L as ErrorTypeNotFound,ee as ErrorTypeNotImplemented,A as ErrorTypeServiceUnavailable,K as ErrorTypeUnauthorized,E as ErrorTypeUnknown,x as Failed,U as List,ge as LoftSchemeGroup,S as LoftSchemeGroupCluster,Ve as LoftSchemeGroupStorage,de as LoftSchemeGroupVersion,me as LoftSchemeGroupVersionCluster,he as LoftSchemeGroupVersionStorage,pe as LoftSchemeGroupVersionVirtualCluster,N as LoftSchemeGroupVirtualCluster,F as LoftSchemeVersion,T as LoftSchemeVersionCluster,fe as LoftSchemeVersionStorage,q as LoftSchemeVersionVirtualCluster,$ as ManagementBasePath,M as MapErrorCode,f as NewResource,w as Ok,J as ProjectBasePath,c as Resources,o as Return,_ as VClusterBasePath,oe as getApiHost,Ke as getProjectFromNamespace,Le as getProjectNamespace,Te as isResult}; diff --git a/lib/index.js b/lib/index.js index 26877e9..041b737 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1 +1 @@ -"use strict";var ce=Object.create;var I=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var me=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var de=(o,e)=>{for(var s in e)I(o,s,{get:e[s],enumerable:!0})},J=(o,e,s,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of pe(e))!ge.call(o,r)&&r!==s&&I(o,r,{get:()=>e[r],enumerable:!(t=le(e,r))||t.enumerable});return o};var z=(o,e,s)=>(s=o!=null?ce(me(o)):{},J(e||!o||!o.__esModule?I(s,"default",{value:o,enumerable:!0}):s,o)),Ve=o=>J(I({},"__esModule",{value:!0}),o);var Ae={};de(Ae,{APIExtensionsGroup:()=>B,APIExtensionsGroupVersion:()=>ke,APIExtensionsVersion:()=>H,Client:()=>ue,ClusterBasePath:()=>A,Err:()=>y,ErrorTypeAlreadyExists:()=>Z,ErrorTypeBadGateway:()=>te,ErrorTypeBadRequest:()=>Y,ErrorTypeForbidden:()=>X,ErrorTypeGatewayTimeout:()=>re,ErrorTypeInternalError:()=>ee,ErrorTypeNetwork:()=>E,ErrorTypeNotFound:()=>O,ErrorTypeNotImplemented:()=>se,ErrorTypeServiceUnavailable:()=>T,ErrorTypeUnauthorized:()=>L,ErrorTypeUnknown:()=>x,Failed:()=>G,List:()=>D,LoftSchemeGroup:()=>Re,LoftSchemeGroupCluster:()=>C,LoftSchemeGroupStorage:()=>Me,LoftSchemeGroupVersion:()=>ve,LoftSchemeGroupVersionCluster:()=>he,LoftSchemeGroupVersionStorage:()=>Ce,LoftSchemeGroupVersionVirtualCluster:()=>fe,LoftSchemeGroupVirtualCluster:()=>N,LoftSchemeVersion:()=>F,LoftSchemeVersionCluster:()=>k,LoftSchemeVersionStorage:()=>be,LoftSchemeVersionVirtualCluster:()=>q,ManagementBasePath:()=>W,MapErrorCode:()=>R,NewResource:()=>d,Ok:()=>S,ProjectBasePath:()=>_,Resources:()=>c,Return:()=>a,VClusterBasePath:()=>$,getApiHost:()=>ie,getProjectFromNamespace:()=>we,getProjectNamespace:()=>Pe,isResult:()=>ye});module.exports=Ve(Ae);var p=z(require("js-cookie")),ae=z(require("json-merge-patch"));var j={loftAccessKeyIdentifier:"loft_access_key",loftImpersonateSubjectIdentifier:"loft_impersonate_subject",loftImpersonateJoinedGroupIdentifier:"loft_impersonate_joined_group"};function h(o){return o||[]}var Q={ManagementV1AgentAuditEvent:{group:"management.loft.sh",version:"v1",resource:"agentauditevents",subResource:"",namespaced:!1,kind:"AgentAuditEvent"},ManagementV1Announcement:{group:"management.loft.sh",version:"v1",resource:"announcements",subResource:"",namespaced:!1,kind:"Announcement"},ManagementV1App:{group:"management.loft.sh",version:"v1",resource:"apps",subResource:"",namespaced:!1,kind:"App"},ManagementV1AppCredentials:{group:"management.loft.sh",version:"v1",resource:"apps",subResource:"credentials",namespaced:!1,kind:"AppCredentials"},ManagementV1Backup:{group:"management.loft.sh",version:"v1",resource:"backups",subResource:"",namespaced:!1,kind:"Backup"},ManagementV1BackupApply:{group:"management.loft.sh",version:"v1",resource:"backups",subResource:"apply",namespaced:!1,kind:"BackupApply"},ManagementV1Cluster:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"",namespaced:!1,kind:"Cluster"},ManagementV1ClusterAccess:{group:"management.loft.sh",version:"v1",resource:"clusteraccesses",subResource:"",namespaced:!1,kind:"ClusterAccess"},ManagementV1ClusterAccessKey:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"accesskey",namespaced:!1,kind:"ClusterAccessKey"},ManagementV1ClusterAgentConfig:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"agentconfig",namespaced:!1,kind:"ClusterAgentConfig"},ManagementV1ClusterCharts:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"charts",namespaced:!1,kind:"ClusterCharts"},ManagementV1ClusterDomain:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"domain",namespaced:!1,kind:"ClusterDomain"},ManagementV1ClusterMemberAccess:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"memberaccess",namespaced:!1,kind:"ClusterMemberAccess"},ManagementV1ClusterMembers:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"members",namespaced:!1,kind:"ClusterMembers"},ManagementV1ClusterReset:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"reset",namespaced:!1,kind:"ClusterReset"},ManagementV1ClusterRoleTemplate:{group:"management.loft.sh",version:"v1",resource:"clusterroletemplates",subResource:"",namespaced:!1,kind:"ClusterRoleTemplate"},ManagementV1ClusterVirtualClusterDefaults:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"virtualclusterdefaults",namespaced:!1,kind:"ClusterVirtualClusterDefaults"},ManagementV1Config:{group:"management.loft.sh",version:"v1",resource:"configs",subResource:"",namespaced:!1,kind:"Config"},ManagementV1ConvertVirtualClusterConfig:{group:"management.loft.sh",version:"v1",resource:"convertvirtualclusterconfig",subResource:"",namespaced:!1,kind:"ConvertVirtualClusterConfig"},ManagementV1DevPodWorkspaceInstance:{group:"management.loft.sh",version:"v1",resource:"devpodworkspaceinstances",subResource:"",namespaced:!0,kind:"DevPodWorkspaceInstance"},ManagementV1DevPodWorkspaceInstanceState:{group:"management.loft.sh",version:"v1",resource:"devpodworkspaceinstances",subResource:"state",namespaced:!0,kind:"DevPodWorkspaceInstanceState"},ManagementV1DevPodWorkspaceTemplate:{group:"management.loft.sh",version:"v1",resource:"devpodworkspacetemplates",subResource:"",namespaced:!1,kind:"DevPodWorkspaceTemplate"},ManagementV1DirectClusterEndpointToken:{group:"management.loft.sh",version:"v1",resource:"directclusterendpointtokens",subResource:"",namespaced:!1,kind:"DirectClusterEndpointToken"},ManagementV1Event:{group:"management.loft.sh",version:"v1",resource:"events",subResource:"",namespaced:!1,kind:"Event"},ManagementV1Feature:{group:"management.loft.sh",version:"v1",resource:"features",subResource:"",namespaced:!1,kind:"Feature"},ManagementV1IngressAuthToken:{group:"management.loft.sh",version:"v1",resource:"ingressauthtokens",subResource:"",namespaced:!1,kind:"IngressAuthToken"},ManagementV1Kiosk:{group:"management.loft.sh",version:"v1",resource:"kiosk",subResource:"",namespaced:!1,kind:"Kiosk"},ManagementV1License:{group:"management.loft.sh",version:"v1",resource:"licenses",subResource:"",namespaced:!1,kind:"License"},ManagementV1LicenseRequest:{group:"management.loft.sh",version:"v1",resource:"licenses",subResource:"request",namespaced:!1,kind:"LicenseRequest"},ManagementV1LicenseToken:{group:"management.loft.sh",version:"v1",resource:"licensetokens",subResource:"",namespaced:!1,kind:"LicenseToken"},ManagementV1LoftUpgrade:{group:"management.loft.sh",version:"v1",resource:"loftupgrades",subResource:"",namespaced:!1,kind:"LoftUpgrade"},ManagementV1OwnedAccessKey:{group:"management.loft.sh",version:"v1",resource:"ownedaccesskeys",subResource:"",namespaced:!1,kind:"OwnedAccessKey"},ManagementV1Project:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"",namespaced:!1,kind:"Project"},ManagementV1ProjectChartInfo:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"chartinfo",namespaced:!1,kind:"ProjectChartInfo"},ManagementV1ProjectCharts:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"charts",namespaced:!1,kind:"ProjectCharts"},ManagementV1ProjectClusters:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"clusters",namespaced:!1,kind:"ProjectClusters"},ManagementV1ProjectImportSpace:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"importspace",namespaced:!1,kind:"ProjectImportSpace"},ManagementV1ProjectMembers:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"members",namespaced:!1,kind:"ProjectMembers"},ManagementV1ProjectMigrateSpaceInstance:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"migratespaceinstance",namespaced:!1,kind:"ProjectMigrateSpaceInstance"},ManagementV1ProjectMigrateVirtualClusterInstance:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"migratevirtualclusterinstance",namespaced:!1,kind:"ProjectMigrateVirtualClusterInstance"},ManagementV1ProjectSecret:{group:"management.loft.sh",version:"v1",resource:"projectsecrets",subResource:"",namespaced:!0,kind:"ProjectSecret"},ManagementV1ProjectTemplates:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"templates",namespaced:!1,kind:"ProjectTemplates"},ManagementV1RedirectToken:{group:"management.loft.sh",version:"v1",resource:"redirecttokens",subResource:"",namespaced:!1,kind:"RedirectToken"},ManagementV1RegisterVirtualCluster:{group:"management.loft.sh",version:"v1",resource:"registervirtualclusters",subResource:"",namespaced:!1,kind:"RegisterVirtualCluster"},ManagementV1ResetAccessKey:{group:"management.loft.sh",version:"v1",resource:"resetaccesskeys",subResource:"",namespaced:!1,kind:"ResetAccessKey"},ManagementV1Runner:{group:"management.loft.sh",version:"v1",resource:"runners",subResource:"",namespaced:!1,kind:"Runner"},ManagementV1RunnerAccessKey:{group:"management.loft.sh",version:"v1",resource:"runners",subResource:"accesskey",namespaced:!1,kind:"RunnerAccessKey"},ManagementV1RunnerConfig:{group:"management.loft.sh",version:"v1",resource:"runners",subResource:"config",namespaced:!1,kind:"RunnerConfig"},ManagementV1Self:{group:"management.loft.sh",version:"v1",resource:"selves",subResource:"",namespaced:!1,kind:"Self"},ManagementV1SelfSubjectAccessReview:{group:"management.loft.sh",version:"v1",resource:"selfsubjectaccessreviews",subResource:"",namespaced:!1,kind:"SelfSubjectAccessReview"},ManagementV1SharedSecret:{group:"management.loft.sh",version:"v1",resource:"sharedsecrets",subResource:"",namespaced:!0,kind:"SharedSecret"},ManagementV1SpaceInstance:{group:"management.loft.sh",version:"v1",resource:"spaceinstances",subResource:"",namespaced:!0,kind:"SpaceInstance"},ManagementV1SpaceTemplate:{group:"management.loft.sh",version:"v1",resource:"spacetemplates",subResource:"",namespaced:!1,kind:"SpaceTemplate"},ManagementV1SubjectAccessReview:{group:"management.loft.sh",version:"v1",resource:"subjectaccessreviews",subResource:"",namespaced:!1,kind:"SubjectAccessReview"},ManagementV1Task:{group:"management.loft.sh",version:"v1",resource:"tasks",subResource:"",namespaced:!1,kind:"Task"},ManagementV1TaskLog:{group:"management.loft.sh",version:"v1",resource:"tasks",subResource:"log",namespaced:!1,kind:"TaskLog"},ManagementV1Team:{group:"management.loft.sh",version:"v1",resource:"teams",subResource:"",namespaced:!1,kind:"Team"},ManagementV1TeamAccessKeys:{group:"management.loft.sh",version:"v1",resource:"teams",subResource:"accesskeys",namespaced:!1,kind:"TeamAccessKeys"},ManagementV1TeamClusters:{group:"management.loft.sh",version:"v1",resource:"teams",subResource:"clusters",namespaced:!1,kind:"TeamClusters"},ManagementV1TranslateVClusterResourceName:{group:"management.loft.sh",version:"v1",resource:"translatevclusterresourcenames",subResource:"",namespaced:!1,kind:"TranslateVClusterResourceName"},ManagementV1User:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"",namespaced:!1,kind:"User"},ManagementV1UserAccessKeys:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"accesskeys",namespaced:!1,kind:"UserAccessKeys"},ManagementV1UserClusters:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"clusters",namespaced:!1,kind:"UserClusters"},ManagementV1UserPermissions:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"permissions",namespaced:!1,kind:"UserPermissions"},ManagementV1UserProfile:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"profile",namespaced:!1,kind:"UserProfile"},ManagementV1VirtualClusterAccessKey:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"accesskey",namespaced:!0,kind:"VirtualClusterAccessKey"},ManagementV1VirtualClusterInstance:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"",namespaced:!0,kind:"VirtualClusterInstance"},ManagementV1VirtualClusterInstanceKubeConfig:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"kubeconfig",namespaced:!0,kind:"VirtualClusterInstanceKubeConfig"},ManagementV1VirtualClusterInstanceLog:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"log",namespaced:!0,kind:"VirtualClusterInstanceLog"},ManagementV1VirtualClusterTemplate:{group:"management.loft.sh",version:"v1",resource:"virtualclustertemplates",subResource:"",namespaced:!1,kind:"VirtualClusterTemplate"}};var N="virtualcluster.loft.sh",q="v1",fe="virtualcluster.loft.sh/v1",C="cluster.loft.sh",k="v1",he="cluster.loft.sh/v1",Re="management.loft.sh",F="v1",ve="management.loft.sh/v1",Me="storage.loft.sh",be="v1",Ce="storage.loft.sh/v1",B="apiextensions.k8s.io",H="v1",ke="apiextensions.k8s.io/v1",D=class{};var c={...Q,ClusterV1SleepModeConfig:{group:C,version:k,resource:"sleepmodeconfigs",kind:"SleepModeConfig",namespaced:!0},ClusterV1HelmRelease:{group:C,version:k,resource:"helmreleases",kind:"HelmRelease",namespaced:!0},ClusterV1ChartInfo:{group:C,version:k,resource:"chartinfos",kind:"ChartInfo"},VirtualclusterV1HelmRelease:{group:N,version:q,resource:"helmreleases",kind:"HelmRelease",namespaced:!0},CustomResourceDefinition:{group:B,version:H,resource:"customresourcedefinitions",kind:"CustomResourceDefinition"},StorageV1ClusterQuota:{group:"storage.loft.sh",version:F,resource:"clusterquotas",kind:"ClusterQuota"},NetworkingV1Ingress:{group:"networking.k8s.io",version:"v1",resource:"ingresses",kind:"Ingress",namespaced:!0},V1StatefulSet:{group:"apps",version:"v1",resource:"statefulsets",kind:"StatefulSet",namespaced:!0},V1Deployment:{group:"apps",version:"v1",resource:"deployments",kind:"Deployment",namespaced:!0},V1Event:{group:"",version:"v1",resource:"events",kind:"Event",namespaced:!0},V1Pod:{group:"",version:"v1",resource:"pods",kind:"Pod",namespaced:!0},V1Node:{group:"",version:"v1",resource:"nodes",kind:"Node"},V1Namespace:{group:"",version:"v1",resource:"namespaces",kind:"Namespace"},V1SelfSubjectAccessReview:{group:"authorization.k8s.io",version:"v1",resource:"selfsubjectaccessreviews",kind:"SelfSubjectAccessReview"},V1ClusterRole:{group:"rbac.authorization.k8s.io",version:"v1",resource:"clusterroles",kind:"ClusterRole"},V1ClusterRoleBinding:{group:"rbac.authorization.k8s.io",version:"v1",resource:"clusterrolebindings",kind:"ClusterRoleBinding"},V1Role:{group:"rbac.authorization.k8s.io",version:"v1",resource:"roles",kind:"Role",namespaced:!0},V1RoleBinding:{group:"rbac.authorization.k8s.io",version:"v1",resource:"rolebindings",kind:"RoleBinding",namespaced:!0},V1Secret:{group:"",version:"v1",resource:"secrets",kind:"Secret",namespaced:!0},V1ConfigMap:{group:"",version:"v1",resource:"configmaps",kind:"ConfigMap",namespaced:!0},V1Service:{group:"",version:"v1",resource:"services",kind:"Service",namespaced:!0},V1User:{group:"",version:"v1",resource:"users",kind:"User",namespaced:!1},V1StorageClassList:{group:"storage.k8s.io",version:"v1",resource:"storageclasses",kind:"StorageClass",namespaced:!1},V1Beta1PodMetrics:{group:"metrics.k8s.io",version:"v1beta1",resource:"pods",kind:"PodMetrics",namespaced:!0}};function d(o,e,s){return{apiVersion:o.group?o.group+"/"+o.version:o.version,kind:o.kind,metadata:{name:e},...s}}var y=class{constructor(e,s=void 0){this.val=e;this.extra=s;this.ok=!1;this.err=!0}},S=class{constructor(e,s=void 0){this.val=e;this.extra=s;this.ok=!0;this.err=!1}};function ye(o){return"ok"in o&&typeof o.ok=="boolean"&&"err"in o&&typeof o.err=="boolean"}var x="",E="Network",X="Forbidden",Y="BadRequest",O="NotFound",L="Unauthorized",Z="AlreadyExists",ee="InternalServerError",se="NotImplemented",te="BadGateway",T="ServiceUnavailable",re="GatewayTimeout",R=o=>{switch(o){case 400:return Y;case 401:return L;case 403:return X;case 404:return O;case 409:return Z;case 500:return ee;case 501:return se;case 502:return te;case 503:return T;case 504:return re}return x},a=class{static Ok(){return new S(void 0)}static Value(e){return new S(e)}static Failed(e,s="",t=x,r=void 0){return new y(new G(e,t,s),r)}static Error(e){return new y(e)}static WithExtra(e,s=void 0){return e.extra=s,e}},G=class{constructor(e,s=x,t=""){this.message=e;this.type=s;this.reason=t}};var P={secure:!0,expires:365*10,sameSite:"strict"},V=j.loftAccessKeyIdentifier,v=j.loftImpersonateSubjectIdentifier,w=j.loftImpersonateJoinedGroupIdentifier,Se=["v4.channel.k8s.io","v3.channel.k8s.io","v2.channel.k8s.io","channel.k8s.io"];function ie(){return typeof window<"u"&&window.location.href.startsWith("http://localhost:3000")?"https://localhost:9898":""}function Te(){return typeof window>"u"||window.location.host==="localhost:3000"?"wss://localhost:8080":`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}`}function ne(o){return[o.virtualCluster?"loft:vcluster:main":`loft:space:${o.project}:${o.space}`]}var W="/kubernetes/management",A="/kubernetes/cluster/",$="/kubernetes/virtualcluster/",_="/kubernetes/project/";function Pe(o,e){return o?e&&e.endsWith("-")?`${e}${o}`:e===""?`${o}`:e?`${e}-${o}`:`p-${o}`:"p-"}function we(o,e){if(o)return e?e.endsWith("-")?o.replace(new RegExp(`^${e}`),""):o.replace(new RegExp(`^${e}-`),""):o.replace(/^p-/,"")}var b=class{constructor(e,s,t){this.apiHost="";this.wsHost="";this.accessKey="";this.managementNonResource=()=>new l(this,{basePath:W,headers:this.impersonationHeaders()});this.cluster=(e,s)=>new l(this,{basePath:A+e,groupVersionResource:s,headers:this.impersonationHeaders()});this.clusterNonResource=e=>new l(this,{basePath:A+e,headers:this.impersonationHeaders()});this.project=(e,s)=>new l(this,{basePath:_+e.project+"/"+(e.space?"space/"+e.space:"virtualcluster/"+e.virtualCluster),groupVersionResource:s,project:e,headers:this.impersonationHeaders(ne(e))});this.projectNonResource=e=>new l(this,{basePath:_+e.project+"/"+(e.space?"space/"+e.space:"virtualcluster/"+e.virtualCluster),project:e,headers:this.impersonationHeaders(ne(e))});this.apiHost=s||ie(),this.wsHost=t||Te(),this.accessKey=e||b.getAccessKey()}static getAccessKey(){return localStorage.getItem(V)}static tryCastToStatus(e){if(e.kind){if(e.kind!=="Status"||e.apiVersion!=="v1")return a.Value(null)}else return a.Value(null);return a.Value(e)}async getUser(){let e=await this.management(c.ManagementV1Self).Create(d(c.ManagementV1Self));return e.err?e:e.val.status?.user?(typeof window<"u"&&(window.loft||(window.loft={}),window.loft.instanceID=e.val.status.instanceID,window.loft.chatAuthToken=e.val.status.chatAuthToken,window.loft.user=e.val.status.user),a.Value(e.val.status.user.name)):a.Failed("no user found")}getAccessKey(){return this.accessKey}async loftVersion(e){try{let s=this.apiHost+"/version";e&&(s+="?refresh=true");let r=await(await fetch(s)).json();return a.Value(r)}catch(s){return console.error(s),a.Failed("error during version retrieval")}}impersonatedUser(){try{let e=localStorage.getItem(v);if(e)return JSON.parse(e)}catch(e){console.error(e)}}impersonate(e,s,t){s?(localStorage.setItem(v,JSON.stringify({name:e,subject:s,groups:t})),s&&p.default.set(v,s,P),t?.forEach(r=>{let n=p.default.get(w);n?(n+=", "+r,p.default.set(w,n,P)):p.default.set(w,r,P)})):(localStorage.removeItem(v),p.default.remove(v),p.default.remove(w))}async login(e,s){let t=await this.request("/auth/password/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,password:s})});if(t.err)return t;let r=t.val;return this.setAccessKey(r.accessKey),a.Ok()}async loginWithAccessKey(e){this.isLoggedIn()&&await this.logout(),this.accessKey=e;let s=await this.management(c.ManagementV1Self).Create(d(c.ManagementV1Self));return s.err?(this.clearStorage(),s):(this.setAccessKey(e),a.Ok())}isLoggedIn(){return!!this.accessKey}setAccessKey(e){this.accessKey=e,localStorage.setItem(V,e),p.default.set(V,e,P)}async stream(e,s){try{let t=await fetch(this.apiHost+e,s);return t.status>=400||!t.body?await this.parseResponse(e,t):a.Value(t.body.getReader())}catch(t){return a.Failed(t+"","NetworkError",E)}}async request(e,s){try{let t=await fetch(this.apiHost+e,{...s,credentials:"same-origin"});return await this.parseResponse(e,t)}catch(t){return a.Failed(t+"","NetworkError",E)}}async socket(e,s){return this.refreshCookie(),new Promise((t,r)=>{let n=new WebSocket(`${this.wsHost}${e}`,s),u=!1;n.onopen=()=>{u=!0,t(n)},n.onerror=i=>{if(!u){let m=p.default.get(V)!="";r(m?i:new Error("Web socket is not authenticated. Please log in again"))}}})}async parseResponse(e,s){let t=await s.text(),r;try{r=JSON.parse(t)}catch{if(s.status===404)return a.Failed("page not found","NotFound",O);if(s.status===503){if(e.includes("kiosk.sh")||e.includes("cluster.loft.sh")){let i=e.split("/");return i.length>=4&&i[0]===""&&i[1]==="kubernetes"&&i[2]==="cluster"?a.Failed(`Agent seems to be currently unavailable, it is maybe just starting up. Click here for more information`,"LoftAgentUnavailable",T):a.Failed("Agent seems to be currently unavailable, it is maybe just starting up","LoftAgentUnavailable",T)}}else if(s.status===200)return a.Value(t);return console.info("Unexpected Server Response",t),a.Failed("Unexpected server response",R(s.status),R(s.status))}let n=b.tryCastToStatus(r);return n.err?n:n.val!==null&&n.val.status==="Failure"?n.val.code===500&&(n.val.message?.indexOf("vcluster secret not found")!==-1||n.val.message.indexOf("no ready pod for virtual cluster")!==-1)?a.Failed("vcluster seems to be not ready. Please refresh in a second",n.val.reason,R(n.val.code)):a.Failed(n.val.message,n.val.reason,R(n.val.code)):s.status>=400?a.Failed("unknown error","Unknown",R(s.status)):a.Value(r)}management(e){return new l(this,{basePath:W,groupVersionResource:e,headers:this.impersonationHeaders()})}vCluster(e,s){return new l(this,{basePath:$+e.cluster+"/"+e.namespace+"/"+e.name,groupVersionResource:s,vCluster:e,headers:this.impersonationHeaders()})}vClusterNonResource(e){return new l(this,{basePath:$+e.cluster+"/"+e.namespace+"/"+e.name,vCluster:e,headers:this.impersonationHeaders()})}auto(e,s,t,r){return t?this.project(t,r):s?this.vCluster(s,r):e?this.cluster(e,r):this.management(r)}autoNonResource(e,s,t){return t?this.projectNonResource(t):s?this.vClusterNonResource(s):e?this.clusterNonResource(e):this.managementNonResource()}async doRawSocket(e,s){try{return a.Value(await this.socket(e,s))}catch(t){return console.error(t),a.Failed(t.message||JSON.stringify(t))}}async doRawStream(e,s,t){return this.doRawInternal(e,s,t,!0)}async doRaw(e,s,t){return this.doRawInternal(e,s,t)}async doRawInternal(e,s,t,r){let n=this.accessKey,u=n?new Headers({...t,Authorization:"bearer "+n,"X-Sleep-Mode-Ignore":"true","X-Platform-Client":"true"}):new Headers({...t,"X-Sleep-Mode-Ignore":"true","X-Platform-Client":"true"}),i=r?await this.stream(e,{...s,headers:u}):await this.request(e,{...s,headers:u});return i.err&&i.val.type===L&&(i.val.message==="Access key not found. Please login again"||i.val.message==="invalid bearer token")&&(this.clearStorage(),typeof window<"u"&&(window.location.href="/"),await new Promise(()=>{})),i}impersonationHeaders(e){let s=this.impersonatedUser(),t={};return s&&(s.subject&&(t["Impersonate-User"]=s.subject),[...h(s.groups),...h(e)].forEach(r=>{t["Impersonate-Joined-Group"]?t["Impersonate-Joined-Group"]+=", "+r:t["Impersonate-Joined-Group"]=r})),t}clearStorage(){this.accessKey=null,localStorage.removeItem(V),localStorage.removeItem(v),p.default.remove(V,{secure:!0}),p.default.remove(v,{secure:!0}),p.default.remove(w,{secure:!0})}refreshCookie(){let e=this.accessKey||localStorage.getItem(V),s=p.default.get(V);e&&e!=s&&p.default.set(V,e,P)}async logout(){let e=await this.management(c.ManagementV1Self).Create(d(c.ManagementV1Self));if(e.err)return this.clearStorage(),e;if(!e.val.status?.accessKey)return this.clearStorage(),a.Ok();let s=await this.management(c.ManagementV1OwnedAccessKey).Delete(e.val.status.accessKey);return s.err?(this.clearStorage(),s):(this.clearStorage(),a.Ok())}},l=class{constructor(e,s){this.client=e,this.options=s}Name(e){return new l(this.client,{...this.options,name:e})}Namespace(e){return e?new l(this.client,{...this.options,namespace:e}):new l(this.client,{...this.options})}Resource(e){return new l(this.client,{...this.options,groupVersionResource:e})}buildPath(e){if(this.options.groupVersionResource)if(this.options.basePath){if(!this.options.name&&this.options.groupVersionResource.subResource)return a.Failed("resource name required when subresource is used")}else return a.Failed("basePath is missing");else return a.Failed("groupVersionResource is missing");let s=[this.options.basePath];this.options.groupVersionResource.group?s.push("apis",this.options.groupVersionResource.group):s.push("api"),s.push(this.options.groupVersionResource.version),this.options.namespace&&s.push("namespaces",this.options.namespace),s.push(this.options.groupVersionResource.resource),this.options.name&&s.push(this.options.name),this.options.groupVersionResource.subResource&&s.push(this.options.groupVersionResource.subResource);let t="";if(e){let r=[];for(let n of Object.keys(e))e[n]&&(Array.isArray(e[n])?e[n].forEach(u=>{r.push(n+"="+encodeURIComponent(u))}):r.push(n+"="+encodeURIComponent(e[n])));r.length>0&&(t="?"+r.join("&"))}else t="?timeout=180s";return a.Value(s.join("/")+t)}parseResourceList(e,s,t,r,n,u){for(let i=0;i1||n&&r.find(M=>M.group===e&&M.resource===f)||r.push({resource:f,subResource:g.length>1?g[1]:void 0,group:e,version:s,kind:m.kind,namespaced:m.namespaced,verbs:m.verbs})}}async ApiResources(e,s){let t=[],r=await this.client.doRaw([this.options.basePath,"api"].join("/"));if(r.err)return r;let n=[];for(let i=0;i{let g=r.val.versions[m];if(g===void 0)return;let f=await this.client.doRaw([this.options.basePath,"api",g].join("/"));if(f.err){console.error(f.val.message);return}this.parseResourceList("",g,f.val,t,e,s)})(i)),n.length>20&&(await Promise.all(n),n=[]);n.length>0&&(await Promise.all(n),n=[]);let u=await this.client.doRaw([this.options.basePath,"apis"].join("/"));if(u.err)return u;for(let i=0;i{let K=M.versions[f];if(K===void 0)return;let U=await this.client.doRaw([this.options.basePath,"apis",M.name,K.version].join("/"));if(U.err){console.error(U.val.message);return}this.parseResourceList(M.name,K.version,U.val,t,e,s)})(g,m)),n.length>20&&(await Promise.all(n),n=[])}return n.length>0&&await Promise.all(n),a.Value(t)}async Version(){let e=[this.options.basePath,"version"];return await this.client.doRaw(e.join("/"))}async VirtualClusterInstanceLogs(e,s,t){let r=[this.options.basePath,`apis/management.loft.sh/v1/namespaces/${e}/virtualclusterinstances/${s}/log`].join("/"),n=[];if(t)for(let u of Object.keys(t))n.push(`${u}=${encodeURIComponent(t[u])}`);return n.length>0&&(r+="?"+n.join("&")),await this.client.doRawStream(r,void 0,this.options.headers)}async TaskLogs(e,s){let t=[this.options.basePath,`apis/management.loft.sh/v1/tasks/${e}/log`].join("/"),r=[];if(s)for(let n of Object.keys(s))r.push(`${n}=${encodeURIComponent(s[n])}`);return r.length>0&&(t+="?"+r.join("&")),await this.client.doRawStream(t,void 0,this.options.headers)}async Logs(e,s,t){let r=[this.options.basePath,`api/v1/namespaces/${e}/pods/${s}/log`].join("/"),n=oe(t);return n.length>0&&(r+="?"+n),await this.client.doRawStream(r,void 0,this.options.headers)}async Exec(e,s,t){let r=[this.options.basePath,`api/v1/namespaces/${e}/pods/${s}/exec`].join("/"),n=oe(t);return n.length>0&&(r+="?"+n),await this.client.doRawSocket(r,Se)}async Path(e,s,t){let r=[this.options.basePath,e];return await this.client.doRaw(r.join("/"),s,{...t,...this.options.headers})}ResolvePath(e){return e&&(this.options.name=e),this.buildPath()}async Get(e,s){this.options.name=e;let t=this.buildPath(s);return t.err?t:a.WithExtra(await this.client.doRaw(t.val,void 0,this.options.headers),this.options)}async List(e){if(this.options.name)return a.Failed("name is set on a list request");let s=this.buildPath(e);return s.err?s:a.WithExtra(await this.client.doRaw(s.val,void 0,this.options.headers),this.options)}async ListTable(e){if(this.options.name)return a.Failed("name is set on a list request");let s=this.buildPath(e);return s.err?s:a.WithExtra(await this.client.doRaw(s.val,void 0,{...this.options.headers,Accept:"application/json;as=Table;v=v1;g=meta.k8s.io,application/json;as=Table;v=v1beta1;g=meta.k8s.io,application/json"}),this.options)}async Create(e,s){let t=this.buildPath(s);return t.err?t:a.WithExtra(await this.client.doRaw(t.val,{method:"POST",body:JSON.stringify(e)},{...this.options.headers,"Content-Type":"application/json"}),this.options)}async PatchObject(e,s,t,r){let n=ae.default.generate(e,s);return this.Patch(s.metadata?.name,n,t,r)}async Patch(e,s,t,r){this.options.name=e;let n=this.buildPath(r);return n.err?n:a.WithExtra(await this.client.doRaw(n.val,{method:"PATCH",body:JSON.stringify(s,function(u,i){return i===void 0?null:i})},{...this.options.headers,"Content-Type":t||"application/merge-patch+json"}),this.options)}async Update(e,s,t){this.options.name=e;let r=this.buildPath(t);return r.err?r:a.WithExtra(await this.client.doRaw(r.val,{method:"PUT",body:JSON.stringify(s)},{...this.options.headers,"Content-Type":"application/json"}),this.options)}async Delete(e,s){this.options.name=e;let t=this.buildPath(s);return t.err?t:a.WithExtra(await this.client.doRaw(t.val,{method:"DELETE"},this.options.headers),this.options)}async CanI(e){let s=this.options.groupVersionResource,t=this.options.basePath?.indexOf(A)===0?this.options.basePath.substring(A.length):void 0,r,n;this.options.project?(r=this.client.project(this.options.project,c.V1SelfSubjectAccessReview),n=d(c.V1SelfSubjectAccessReview)):this.options.vCluster?(r=this.client.vCluster(this.options.vCluster,c.V1SelfSubjectAccessReview),n=d(c.V1SelfSubjectAccessReview)):t?(r=this.client.cluster(t,c.V1SelfSubjectAccessReview),n=d(c.V1SelfSubjectAccessReview)):(r=this.client.management(c.ManagementV1SelfSubjectAccessReview),n=d(c.ManagementV1SelfSubjectAccessReview)),n.spec={resourceAttributes:{verb:e,name:this.options.name,namespace:this.options.namespace,group:s.group,version:s.version,resource:s.resource,subresource:s.subResource}};let u=await r.Create(n);return u.err?u:a.Value(!!(u.val.status?.allowed&&!u.val.status.denied))}};function oe(o){let e=new URLSearchParams;for(let[s,t]of Object.entries(o))Array.isArray(t)?t.forEach(r=>{e.append(s,r)}):e.append(s,t);return e.toString()}var ue=b;0&&(module.exports={APIExtensionsGroup,APIExtensionsGroupVersion,APIExtensionsVersion,Client,ClusterBasePath,Err,ErrorTypeAlreadyExists,ErrorTypeBadGateway,ErrorTypeBadRequest,ErrorTypeForbidden,ErrorTypeGatewayTimeout,ErrorTypeInternalError,ErrorTypeNetwork,ErrorTypeNotFound,ErrorTypeNotImplemented,ErrorTypeServiceUnavailable,ErrorTypeUnauthorized,ErrorTypeUnknown,Failed,List,LoftSchemeGroup,LoftSchemeGroupCluster,LoftSchemeGroupStorage,LoftSchemeGroupVersion,LoftSchemeGroupVersionCluster,LoftSchemeGroupVersionStorage,LoftSchemeGroupVersionVirtualCluster,LoftSchemeGroupVirtualCluster,LoftSchemeVersion,LoftSchemeVersionCluster,LoftSchemeVersionStorage,LoftSchemeVersionVirtualCluster,ManagementBasePath,MapErrorCode,NewResource,Ok,ProjectBasePath,Resources,Return,VClusterBasePath,getApiHost,getProjectFromNamespace,getProjectNamespace,isResult}); +"use strict";var ce=Object.create;var I=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var me=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var de=(o,e)=>{for(var s in e)I(o,s,{get:e[s],enumerable:!0})},J=(o,e,s,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of pe(e))!ge.call(o,r)&&r!==s&&I(o,r,{get:()=>e[r],enumerable:!(t=le(e,r))||t.enumerable});return o};var z=(o,e,s)=>(s=o!=null?ce(me(o)):{},J(e||!o||!o.__esModule?I(s,"default",{value:o,enumerable:!0}):s,o)),Ve=o=>J(I({},"__esModule",{value:!0}),o);var Ae={};de(Ae,{APIExtensionsGroup:()=>B,APIExtensionsGroupVersion:()=>ke,APIExtensionsVersion:()=>H,Client:()=>ue,ClusterBasePath:()=>A,Err:()=>y,ErrorTypeAlreadyExists:()=>Z,ErrorTypeBadGateway:()=>te,ErrorTypeBadRequest:()=>Y,ErrorTypeForbidden:()=>X,ErrorTypeGatewayTimeout:()=>re,ErrorTypeInternalError:()=>ee,ErrorTypeNetwork:()=>E,ErrorTypeNotFound:()=>O,ErrorTypeNotImplemented:()=>se,ErrorTypeServiceUnavailable:()=>T,ErrorTypeUnauthorized:()=>L,ErrorTypeUnknown:()=>x,Failed:()=>G,List:()=>U,LoftSchemeGroup:()=>Re,LoftSchemeGroupCluster:()=>C,LoftSchemeGroupStorage:()=>Me,LoftSchemeGroupVersion:()=>ve,LoftSchemeGroupVersionCluster:()=>he,LoftSchemeGroupVersionStorage:()=>Ce,LoftSchemeGroupVersionVirtualCluster:()=>fe,LoftSchemeGroupVirtualCluster:()=>N,LoftSchemeVersion:()=>F,LoftSchemeVersionCluster:()=>k,LoftSchemeVersionStorage:()=>be,LoftSchemeVersionVirtualCluster:()=>q,ManagementBasePath:()=>W,MapErrorCode:()=>R,NewResource:()=>d,Ok:()=>S,ProjectBasePath:()=>_,Resources:()=>c,Return:()=>a,VClusterBasePath:()=>$,getApiHost:()=>ie,getProjectFromNamespace:()=>we,getProjectNamespace:()=>Pe,isResult:()=>ye});module.exports=Ve(Ae);var p=z(require("js-cookie")),ae=z(require("json-merge-patch"));var j={loftAccessKeyIdentifier:"loft_access_key",loftImpersonateSubjectIdentifier:"loft_impersonate_subject",loftImpersonateJoinedGroupIdentifier:"loft_impersonate_joined_group"};function h(o){return o||[]}var Q={ManagementV1AgentAuditEvent:{group:"management.loft.sh",version:"v1",resource:"agentauditevents",subResource:"",namespaced:!1,kind:"AgentAuditEvent"},ManagementV1Announcement:{group:"management.loft.sh",version:"v1",resource:"announcements",subResource:"",namespaced:!1,kind:"Announcement"},ManagementV1App:{group:"management.loft.sh",version:"v1",resource:"apps",subResource:"",namespaced:!1,kind:"App"},ManagementV1AppCredentials:{group:"management.loft.sh",version:"v1",resource:"apps",subResource:"credentials",namespaced:!1,kind:"AppCredentials"},ManagementV1Backup:{group:"management.loft.sh",version:"v1",resource:"backups",subResource:"",namespaced:!1,kind:"Backup"},ManagementV1BackupApply:{group:"management.loft.sh",version:"v1",resource:"backups",subResource:"apply",namespaced:!1,kind:"BackupApply"},ManagementV1Cluster:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"",namespaced:!1,kind:"Cluster"},ManagementV1ClusterAccess:{group:"management.loft.sh",version:"v1",resource:"clusteraccesses",subResource:"",namespaced:!1,kind:"ClusterAccess"},ManagementV1ClusterAccessKey:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"accesskey",namespaced:!1,kind:"ClusterAccessKey"},ManagementV1ClusterAgentConfig:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"agentconfig",namespaced:!1,kind:"ClusterAgentConfig"},ManagementV1ClusterCharts:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"charts",namespaced:!1,kind:"ClusterCharts"},ManagementV1ClusterDomain:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"domain",namespaced:!1,kind:"ClusterDomain"},ManagementV1ClusterMemberAccess:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"memberaccess",namespaced:!1,kind:"ClusterMemberAccess"},ManagementV1ClusterMembers:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"members",namespaced:!1,kind:"ClusterMembers"},ManagementV1ClusterReset:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"reset",namespaced:!1,kind:"ClusterReset"},ManagementV1ClusterRoleTemplate:{group:"management.loft.sh",version:"v1",resource:"clusterroletemplates",subResource:"",namespaced:!1,kind:"ClusterRoleTemplate"},ManagementV1ClusterVirtualClusterDefaults:{group:"management.loft.sh",version:"v1",resource:"clusters",subResource:"virtualclusterdefaults",namespaced:!1,kind:"ClusterVirtualClusterDefaults"},ManagementV1Config:{group:"management.loft.sh",version:"v1",resource:"configs",subResource:"",namespaced:!1,kind:"Config"},ManagementV1ConvertVirtualClusterConfig:{group:"management.loft.sh",version:"v1",resource:"convertvirtualclusterconfig",subResource:"",namespaced:!1,kind:"ConvertVirtualClusterConfig"},ManagementV1DevPodWorkspaceInstance:{group:"management.loft.sh",version:"v1",resource:"devpodworkspaceinstances",subResource:"",namespaced:!0,kind:"DevPodWorkspaceInstance"},ManagementV1DevPodWorkspaceInstanceState:{group:"management.loft.sh",version:"v1",resource:"devpodworkspaceinstances",subResource:"state",namespaced:!0,kind:"DevPodWorkspaceInstanceState"},ManagementV1DevPodWorkspaceTemplate:{group:"management.loft.sh",version:"v1",resource:"devpodworkspacetemplates",subResource:"",namespaced:!1,kind:"DevPodWorkspaceTemplate"},ManagementV1DirectClusterEndpointToken:{group:"management.loft.sh",version:"v1",resource:"directclusterendpointtokens",subResource:"",namespaced:!1,kind:"DirectClusterEndpointToken"},ManagementV1Event:{group:"management.loft.sh",version:"v1",resource:"events",subResource:"",namespaced:!1,kind:"Event"},ManagementV1Feature:{group:"management.loft.sh",version:"v1",resource:"features",subResource:"",namespaced:!1,kind:"Feature"},ManagementV1IngressAuthToken:{group:"management.loft.sh",version:"v1",resource:"ingressauthtokens",subResource:"",namespaced:!1,kind:"IngressAuthToken"},ManagementV1Kiosk:{group:"management.loft.sh",version:"v1",resource:"kiosk",subResource:"",namespaced:!1,kind:"Kiosk"},ManagementV1License:{group:"management.loft.sh",version:"v1",resource:"licenses",subResource:"",namespaced:!1,kind:"License"},ManagementV1LicenseRequest:{group:"management.loft.sh",version:"v1",resource:"licenses",subResource:"request",namespaced:!1,kind:"LicenseRequest"},ManagementV1LicenseToken:{group:"management.loft.sh",version:"v1",resource:"licensetokens",subResource:"",namespaced:!1,kind:"LicenseToken"},ManagementV1LoftUpgrade:{group:"management.loft.sh",version:"v1",resource:"loftupgrades",subResource:"",namespaced:!1,kind:"LoftUpgrade"},ManagementV1OIDCClient:{group:"management.loft.sh",version:"v1",resource:"oidcclients",subResource:"",namespaced:!0,kind:"OIDCClient"},ManagementV1OwnedAccessKey:{group:"management.loft.sh",version:"v1",resource:"ownedaccesskeys",subResource:"",namespaced:!1,kind:"OwnedAccessKey"},ManagementV1Project:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"",namespaced:!1,kind:"Project"},ManagementV1ProjectChartInfo:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"chartinfo",namespaced:!1,kind:"ProjectChartInfo"},ManagementV1ProjectCharts:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"charts",namespaced:!1,kind:"ProjectCharts"},ManagementV1ProjectClusters:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"clusters",namespaced:!1,kind:"ProjectClusters"},ManagementV1ProjectImportSpace:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"importspace",namespaced:!1,kind:"ProjectImportSpace"},ManagementV1ProjectMembers:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"members",namespaced:!1,kind:"ProjectMembers"},ManagementV1ProjectMigrateSpaceInstance:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"migratespaceinstance",namespaced:!1,kind:"ProjectMigrateSpaceInstance"},ManagementV1ProjectMigrateVirtualClusterInstance:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"migratevirtualclusterinstance",namespaced:!1,kind:"ProjectMigrateVirtualClusterInstance"},ManagementV1ProjectSecret:{group:"management.loft.sh",version:"v1",resource:"projectsecrets",subResource:"",namespaced:!0,kind:"ProjectSecret"},ManagementV1ProjectTemplates:{group:"management.loft.sh",version:"v1",resource:"projects",subResource:"templates",namespaced:!1,kind:"ProjectTemplates"},ManagementV1RedirectToken:{group:"management.loft.sh",version:"v1",resource:"redirecttokens",subResource:"",namespaced:!1,kind:"RedirectToken"},ManagementV1RegisterVirtualCluster:{group:"management.loft.sh",version:"v1",resource:"registervirtualclusters",subResource:"",namespaced:!1,kind:"RegisterVirtualCluster"},ManagementV1ResetAccessKey:{group:"management.loft.sh",version:"v1",resource:"resetaccesskeys",subResource:"",namespaced:!1,kind:"ResetAccessKey"},ManagementV1Runner:{group:"management.loft.sh",version:"v1",resource:"runners",subResource:"",namespaced:!1,kind:"Runner"},ManagementV1RunnerAccessKey:{group:"management.loft.sh",version:"v1",resource:"runners",subResource:"accesskey",namespaced:!1,kind:"RunnerAccessKey"},ManagementV1RunnerConfig:{group:"management.loft.sh",version:"v1",resource:"runners",subResource:"config",namespaced:!1,kind:"RunnerConfig"},ManagementV1Self:{group:"management.loft.sh",version:"v1",resource:"selves",subResource:"",namespaced:!1,kind:"Self"},ManagementV1SelfSubjectAccessReview:{group:"management.loft.sh",version:"v1",resource:"selfsubjectaccessreviews",subResource:"",namespaced:!1,kind:"SelfSubjectAccessReview"},ManagementV1SharedSecret:{group:"management.loft.sh",version:"v1",resource:"sharedsecrets",subResource:"",namespaced:!0,kind:"SharedSecret"},ManagementV1SpaceInstance:{group:"management.loft.sh",version:"v1",resource:"spaceinstances",subResource:"",namespaced:!0,kind:"SpaceInstance"},ManagementV1SpaceTemplate:{group:"management.loft.sh",version:"v1",resource:"spacetemplates",subResource:"",namespaced:!1,kind:"SpaceTemplate"},ManagementV1SubjectAccessReview:{group:"management.loft.sh",version:"v1",resource:"subjectaccessreviews",subResource:"",namespaced:!1,kind:"SubjectAccessReview"},ManagementV1Task:{group:"management.loft.sh",version:"v1",resource:"tasks",subResource:"",namespaced:!1,kind:"Task"},ManagementV1TaskLog:{group:"management.loft.sh",version:"v1",resource:"tasks",subResource:"log",namespaced:!1,kind:"TaskLog"},ManagementV1Team:{group:"management.loft.sh",version:"v1",resource:"teams",subResource:"",namespaced:!1,kind:"Team"},ManagementV1TeamAccessKeys:{group:"management.loft.sh",version:"v1",resource:"teams",subResource:"accesskeys",namespaced:!1,kind:"TeamAccessKeys"},ManagementV1TeamClusters:{group:"management.loft.sh",version:"v1",resource:"teams",subResource:"clusters",namespaced:!1,kind:"TeamClusters"},ManagementV1TranslateVClusterResourceName:{group:"management.loft.sh",version:"v1",resource:"translatevclusterresourcenames",subResource:"",namespaced:!1,kind:"TranslateVClusterResourceName"},ManagementV1User:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"",namespaced:!1,kind:"User"},ManagementV1UserAccessKeys:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"accesskeys",namespaced:!1,kind:"UserAccessKeys"},ManagementV1UserClusters:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"clusters",namespaced:!1,kind:"UserClusters"},ManagementV1UserPermissions:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"permissions",namespaced:!1,kind:"UserPermissions"},ManagementV1UserProfile:{group:"management.loft.sh",version:"v1",resource:"users",subResource:"profile",namespaced:!1,kind:"UserProfile"},ManagementV1VirtualClusterAccessKey:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"accesskey",namespaced:!0,kind:"VirtualClusterAccessKey"},ManagementV1VirtualClusterInstance:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"",namespaced:!0,kind:"VirtualClusterInstance"},ManagementV1VirtualClusterInstanceKubeConfig:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"kubeconfig",namespaced:!0,kind:"VirtualClusterInstanceKubeConfig"},ManagementV1VirtualClusterInstanceLog:{group:"management.loft.sh",version:"v1",resource:"virtualclusterinstances",subResource:"log",namespaced:!0,kind:"VirtualClusterInstanceLog"},ManagementV1VirtualClusterTemplate:{group:"management.loft.sh",version:"v1",resource:"virtualclustertemplates",subResource:"",namespaced:!1,kind:"VirtualClusterTemplate"}};var N="virtualcluster.loft.sh",q="v1",fe="virtualcluster.loft.sh/v1",C="cluster.loft.sh",k="v1",he="cluster.loft.sh/v1",Re="management.loft.sh",F="v1",ve="management.loft.sh/v1",Me="storage.loft.sh",be="v1",Ce="storage.loft.sh/v1",B="apiextensions.k8s.io",H="v1",ke="apiextensions.k8s.io/v1",U=class{};var c={...Q,ClusterV1SleepModeConfig:{group:C,version:k,resource:"sleepmodeconfigs",kind:"SleepModeConfig",namespaced:!0},ClusterV1HelmRelease:{group:C,version:k,resource:"helmreleases",kind:"HelmRelease",namespaced:!0},ClusterV1ChartInfo:{group:C,version:k,resource:"chartinfos",kind:"ChartInfo"},VirtualclusterV1HelmRelease:{group:N,version:q,resource:"helmreleases",kind:"HelmRelease",namespaced:!0},CustomResourceDefinition:{group:B,version:H,resource:"customresourcedefinitions",kind:"CustomResourceDefinition"},StorageV1ClusterQuota:{group:"storage.loft.sh",version:F,resource:"clusterquotas",kind:"ClusterQuota"},NetworkingV1Ingress:{group:"networking.k8s.io",version:"v1",resource:"ingresses",kind:"Ingress",namespaced:!0},V1StatefulSet:{group:"apps",version:"v1",resource:"statefulsets",kind:"StatefulSet",namespaced:!0},V1Deployment:{group:"apps",version:"v1",resource:"deployments",kind:"Deployment",namespaced:!0},V1Event:{group:"",version:"v1",resource:"events",kind:"Event",namespaced:!0},V1Pod:{group:"",version:"v1",resource:"pods",kind:"Pod",namespaced:!0},V1Node:{group:"",version:"v1",resource:"nodes",kind:"Node"},V1Namespace:{group:"",version:"v1",resource:"namespaces",kind:"Namespace"},V1SelfSubjectAccessReview:{group:"authorization.k8s.io",version:"v1",resource:"selfsubjectaccessreviews",kind:"SelfSubjectAccessReview"},V1ClusterRole:{group:"rbac.authorization.k8s.io",version:"v1",resource:"clusterroles",kind:"ClusterRole"},V1ClusterRoleBinding:{group:"rbac.authorization.k8s.io",version:"v1",resource:"clusterrolebindings",kind:"ClusterRoleBinding"},V1Role:{group:"rbac.authorization.k8s.io",version:"v1",resource:"roles",kind:"Role",namespaced:!0},V1RoleBinding:{group:"rbac.authorization.k8s.io",version:"v1",resource:"rolebindings",kind:"RoleBinding",namespaced:!0},V1Secret:{group:"",version:"v1",resource:"secrets",kind:"Secret",namespaced:!0},V1ConfigMap:{group:"",version:"v1",resource:"configmaps",kind:"ConfigMap",namespaced:!0},V1Service:{group:"",version:"v1",resource:"services",kind:"Service",namespaced:!0},V1User:{group:"",version:"v1",resource:"users",kind:"User",namespaced:!1},V1StorageClassList:{group:"storage.k8s.io",version:"v1",resource:"storageclasses",kind:"StorageClass",namespaced:!1},V1Beta1PodMetrics:{group:"metrics.k8s.io",version:"v1beta1",resource:"pods",kind:"PodMetrics",namespaced:!0}};function d(o,e,s){return{apiVersion:o.group?o.group+"/"+o.version:o.version,kind:o.kind,metadata:{name:e},...s}}var y=class{constructor(e,s=void 0){this.val=e;this.extra=s;this.ok=!1;this.err=!0}},S=class{constructor(e,s=void 0){this.val=e;this.extra=s;this.ok=!0;this.err=!1}};function ye(o){return"ok"in o&&typeof o.ok=="boolean"&&"err"in o&&typeof o.err=="boolean"}var x="",E="Network",X="Forbidden",Y="BadRequest",O="NotFound",L="Unauthorized",Z="AlreadyExists",ee="InternalServerError",se="NotImplemented",te="BadGateway",T="ServiceUnavailable",re="GatewayTimeout",R=o=>{switch(o){case 400:return Y;case 401:return L;case 403:return X;case 404:return O;case 409:return Z;case 500:return ee;case 501:return se;case 502:return te;case 503:return T;case 504:return re}return x},a=class{static Ok(){return new S(void 0)}static Value(e){return new S(e)}static Failed(e,s="",t=x,r=void 0){return new y(new G(e,t,s),r)}static Error(e){return new y(e)}static WithExtra(e,s=void 0){return e.extra=s,e}},G=class{constructor(e,s=x,t=""){this.message=e;this.type=s;this.reason=t}};var P={secure:!0,expires:365*10,sameSite:"strict"},V=j.loftAccessKeyIdentifier,v=j.loftImpersonateSubjectIdentifier,w=j.loftImpersonateJoinedGroupIdentifier,Se=["v4.channel.k8s.io","v3.channel.k8s.io","v2.channel.k8s.io","channel.k8s.io"];function ie(){return typeof window<"u"&&window.location.href.startsWith("http://localhost:3000")?"https://localhost:9898":""}function Te(){return typeof window>"u"||window.location.host==="localhost:3000"?"wss://localhost:8080":`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}`}function ne(o){return[o.virtualCluster?"loft:vcluster:main":`loft:space:${o.project}:${o.space}`]}var W="/kubernetes/management",A="/kubernetes/cluster/",$="/kubernetes/virtualcluster/",_="/kubernetes/project/";function Pe(o,e){return o?e&&e.endsWith("-")?`${e}${o}`:e===""?`${o}`:e?`${e}-${o}`:`p-${o}`:"p-"}function we(o,e){if(o)return e?e.endsWith("-")?o.replace(new RegExp(`^${e}`),""):o.replace(new RegExp(`^${e}-`),""):o.replace(/^p-/,"")}var b=class{constructor(e,s,t){this.apiHost="";this.wsHost="";this.accessKey="";this.managementNonResource=()=>new l(this,{basePath:W,headers:this.impersonationHeaders()});this.cluster=(e,s)=>new l(this,{basePath:A+e,groupVersionResource:s,headers:this.impersonationHeaders()});this.clusterNonResource=e=>new l(this,{basePath:A+e,headers:this.impersonationHeaders()});this.project=(e,s)=>new l(this,{basePath:_+e.project+"/"+(e.space?"space/"+e.space:"virtualcluster/"+e.virtualCluster),groupVersionResource:s,project:e,headers:this.impersonationHeaders(ne(e))});this.projectNonResource=e=>new l(this,{basePath:_+e.project+"/"+(e.space?"space/"+e.space:"virtualcluster/"+e.virtualCluster),project:e,headers:this.impersonationHeaders(ne(e))});this.apiHost=s||ie(),this.wsHost=t||Te(),this.accessKey=e||b.getAccessKey()}static getAccessKey(){return localStorage.getItem(V)}static tryCastToStatus(e){if(e.kind){if(e.kind!=="Status"||e.apiVersion!=="v1")return a.Value(null)}else return a.Value(null);return a.Value(e)}async getUser(){let e=await this.management(c.ManagementV1Self).Create(d(c.ManagementV1Self));return e.err?e:e.val.status?.user?(typeof window<"u"&&(window.loft||(window.loft={}),window.loft.instanceID=e.val.status.instanceID,window.loft.chatAuthToken=e.val.status.chatAuthToken,window.loft.user=e.val.status.user),a.Value(e.val.status.user.name)):a.Failed("no user found")}getAccessKey(){return this.accessKey}async loftVersion(e){try{let s=this.apiHost+"/version";e&&(s+="?refresh=true");let r=await(await fetch(s)).json();return a.Value(r)}catch(s){return console.error(s),a.Failed("error during version retrieval")}}impersonatedUser(){try{let e=localStorage.getItem(v);if(e)return JSON.parse(e)}catch(e){console.error(e)}}impersonate(e,s,t){s?(localStorage.setItem(v,JSON.stringify({name:e,subject:s,groups:t})),s&&p.default.set(v,s,P),t?.forEach(r=>{let n=p.default.get(w);n?(n+=", "+r,p.default.set(w,n,P)):p.default.set(w,r,P)})):(localStorage.removeItem(v),p.default.remove(v),p.default.remove(w))}async login(e,s){let t=await this.request("/auth/password/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:e,password:s})});if(t.err)return t;let r=t.val;return this.setAccessKey(r.accessKey),a.Ok()}async loginWithAccessKey(e){this.isLoggedIn()&&await this.logout(),this.accessKey=e;let s=await this.management(c.ManagementV1Self).Create(d(c.ManagementV1Self));return s.err?(this.clearStorage(),s):(this.setAccessKey(e),a.Ok())}isLoggedIn(){return!!this.accessKey}setAccessKey(e){this.accessKey=e,localStorage.setItem(V,e),p.default.set(V,e,P)}async stream(e,s){try{let t=await fetch(this.apiHost+e,s);return t.status>=400||!t.body?await this.parseResponse(e,t):a.Value(t.body.getReader())}catch(t){return a.Failed(t+"","NetworkError",E)}}async request(e,s){try{let t=await fetch(this.apiHost+e,{...s,credentials:"same-origin"});return await this.parseResponse(e,t)}catch(t){return a.Failed(t+"","NetworkError",E)}}async socket(e,s){return this.refreshCookie(),new Promise((t,r)=>{let n=new WebSocket(`${this.wsHost}${e}`,s),u=!1;n.onopen=()=>{u=!0,t(n)},n.onerror=i=>{if(!u){let m=p.default.get(V)!="";r(m?i:new Error("Web socket is not authenticated. Please log in again"))}}})}async parseResponse(e,s){let t=await s.text(),r;try{r=JSON.parse(t)}catch{if(s.status===404)return a.Failed("page not found","NotFound",O);if(s.status===503){if(e.includes("kiosk.sh")||e.includes("cluster.loft.sh")){let i=e.split("/");return i.length>=4&&i[0]===""&&i[1]==="kubernetes"&&i[2]==="cluster"?a.Failed(`Agent seems to be currently unavailable, it is maybe just starting up. Click here for more information`,"LoftAgentUnavailable",T):a.Failed("Agent seems to be currently unavailable, it is maybe just starting up","LoftAgentUnavailable",T)}}else if(s.status===200)return a.Value(t);return console.info("Unexpected Server Response",t),a.Failed("Unexpected server response",R(s.status),R(s.status))}let n=b.tryCastToStatus(r);return n.err?n:n.val!==null&&n.val.status==="Failure"?n.val.code===500&&(n.val.message?.indexOf("vcluster secret not found")!==-1||n.val.message.indexOf("no ready pod for virtual cluster")!==-1)?a.Failed("vcluster seems to be not ready. Please refresh in a second",n.val.reason,R(n.val.code)):a.Failed(n.val.message,n.val.reason,R(n.val.code)):s.status>=400?a.Failed("unknown error","Unknown",R(s.status)):a.Value(r)}management(e){return new l(this,{basePath:W,groupVersionResource:e,headers:this.impersonationHeaders()})}vCluster(e,s){return new l(this,{basePath:$+e.cluster+"/"+e.namespace+"/"+e.name,groupVersionResource:s,vCluster:e,headers:this.impersonationHeaders()})}vClusterNonResource(e){return new l(this,{basePath:$+e.cluster+"/"+e.namespace+"/"+e.name,vCluster:e,headers:this.impersonationHeaders()})}auto(e,s,t,r){return t?this.project(t,r):s?this.vCluster(s,r):e?this.cluster(e,r):this.management(r)}autoNonResource(e,s,t){return t?this.projectNonResource(t):s?this.vClusterNonResource(s):e?this.clusterNonResource(e):this.managementNonResource()}async doRawSocket(e,s){try{return a.Value(await this.socket(e,s))}catch(t){return console.error(t),a.Failed(t.message||JSON.stringify(t))}}async doRawStream(e,s,t){return this.doRawInternal(e,s,t,!0)}async doRaw(e,s,t){return this.doRawInternal(e,s,t)}async doRawInternal(e,s,t,r){let n=this.accessKey,u=n?new Headers({...t,Authorization:"bearer "+n,"X-Sleep-Mode-Ignore":"true","X-Platform-Client":"true"}):new Headers({...t,"X-Sleep-Mode-Ignore":"true","X-Platform-Client":"true"}),i=r?await this.stream(e,{...s,headers:u}):await this.request(e,{...s,headers:u});return i.err&&i.val.type===L&&(i.val.message==="Access key not found. Please login again"||i.val.message==="invalid bearer token")&&(this.clearStorage(),typeof window<"u"&&(window.location.href="/"),await new Promise(()=>{})),i}impersonationHeaders(e){let s=this.impersonatedUser(),t={};return s&&(s.subject&&(t["Impersonate-User"]=s.subject),[...h(s.groups),...h(e)].forEach(r=>{t["Impersonate-Joined-Group"]?t["Impersonate-Joined-Group"]+=", "+r:t["Impersonate-Joined-Group"]=r})),t}clearStorage(){this.accessKey=null,localStorage.removeItem(V),localStorage.removeItem(v),p.default.remove(V,{secure:!0}),p.default.remove(v,{secure:!0}),p.default.remove(w,{secure:!0})}refreshCookie(){let e=this.accessKey||localStorage.getItem(V),s=p.default.get(V);e&&e!=s&&p.default.set(V,e,P)}async logout(){let e=await this.management(c.ManagementV1Self).Create(d(c.ManagementV1Self));if(e.err)return this.clearStorage(),e;if(!e.val.status?.accessKey)return this.clearStorage(),a.Ok();let s=await this.management(c.ManagementV1OwnedAccessKey).Delete(e.val.status.accessKey);return s.err?(this.clearStorage(),s):(this.clearStorage(),a.Ok())}},l=class{constructor(e,s){this.client=e,this.options=s}Name(e){return new l(this.client,{...this.options,name:e})}Namespace(e){return e?new l(this.client,{...this.options,namespace:e}):new l(this.client,{...this.options})}Resource(e){return new l(this.client,{...this.options,groupVersionResource:e})}buildPath(e){if(this.options.groupVersionResource)if(this.options.basePath){if(!this.options.name&&this.options.groupVersionResource.subResource)return a.Failed("resource name required when subresource is used")}else return a.Failed("basePath is missing");else return a.Failed("groupVersionResource is missing");let s=[this.options.basePath];this.options.groupVersionResource.group?s.push("apis",this.options.groupVersionResource.group):s.push("api"),s.push(this.options.groupVersionResource.version),this.options.namespace&&s.push("namespaces",this.options.namespace),s.push(this.options.groupVersionResource.resource),this.options.name&&s.push(this.options.name),this.options.groupVersionResource.subResource&&s.push(this.options.groupVersionResource.subResource);let t="";if(e){let r=[];for(let n of Object.keys(e))e[n]&&(Array.isArray(e[n])?e[n].forEach(u=>{r.push(n+"="+encodeURIComponent(u))}):r.push(n+"="+encodeURIComponent(e[n])));r.length>0&&(t="?"+r.join("&"))}else t="?timeout=180s";return a.Value(s.join("/")+t)}parseResourceList(e,s,t,r,n,u){for(let i=0;i1||n&&r.find(M=>M.group===e&&M.resource===f)||r.push({resource:f,subResource:g.length>1?g[1]:void 0,group:e,version:s,kind:m.kind,namespaced:m.namespaced,verbs:m.verbs})}}async ApiResources(e,s){let t=[],r=await this.client.doRaw([this.options.basePath,"api"].join("/"));if(r.err)return r;let n=[];for(let i=0;i{let g=r.val.versions[m];if(g===void 0)return;let f=await this.client.doRaw([this.options.basePath,"api",g].join("/"));if(f.err){console.error(f.val.message);return}this.parseResourceList("",g,f.val,t,e,s)})(i)),n.length>20&&(await Promise.all(n),n=[]);n.length>0&&(await Promise.all(n),n=[]);let u=await this.client.doRaw([this.options.basePath,"apis"].join("/"));if(u.err)return u;for(let i=0;i{let K=M.versions[f];if(K===void 0)return;let D=await this.client.doRaw([this.options.basePath,"apis",M.name,K.version].join("/"));if(D.err){console.error(D.val.message);return}this.parseResourceList(M.name,K.version,D.val,t,e,s)})(g,m)),n.length>20&&(await Promise.all(n),n=[])}return n.length>0&&await Promise.all(n),a.Value(t)}async Version(){let e=[this.options.basePath,"version"];return await this.client.doRaw(e.join("/"))}async VirtualClusterInstanceLogs(e,s,t){let r=[this.options.basePath,`apis/management.loft.sh/v1/namespaces/${e}/virtualclusterinstances/${s}/log`].join("/"),n=[];if(t)for(let u of Object.keys(t))n.push(`${u}=${encodeURIComponent(t[u])}`);return n.length>0&&(r+="?"+n.join("&")),await this.client.doRawStream(r,void 0,this.options.headers)}async TaskLogs(e,s){let t=[this.options.basePath,`apis/management.loft.sh/v1/tasks/${e}/log`].join("/"),r=[];if(s)for(let n of Object.keys(s))r.push(`${n}=${encodeURIComponent(s[n])}`);return r.length>0&&(t+="?"+r.join("&")),await this.client.doRawStream(t,void 0,this.options.headers)}async Logs(e,s,t){let r=[this.options.basePath,`api/v1/namespaces/${e}/pods/${s}/log`].join("/"),n=oe(t);return n.length>0&&(r+="?"+n),await this.client.doRawStream(r,void 0,this.options.headers)}async Exec(e,s,t){let r=[this.options.basePath,`api/v1/namespaces/${e}/pods/${s}/exec`].join("/"),n=oe(t);return n.length>0&&(r+="?"+n),await this.client.doRawSocket(r,Se)}async Path(e,s,t){let r=[this.options.basePath,e];return await this.client.doRaw(r.join("/"),s,{...t,...this.options.headers})}ResolvePath(e){return e&&(this.options.name=e),this.buildPath()}async Get(e,s){this.options.name=e;let t=this.buildPath(s);return t.err?t:a.WithExtra(await this.client.doRaw(t.val,void 0,this.options.headers),this.options)}async List(e){if(this.options.name)return a.Failed("name is set on a list request");let s=this.buildPath(e);return s.err?s:a.WithExtra(await this.client.doRaw(s.val,void 0,this.options.headers),this.options)}async ListTable(e){if(this.options.name)return a.Failed("name is set on a list request");let s=this.buildPath(e);return s.err?s:a.WithExtra(await this.client.doRaw(s.val,void 0,{...this.options.headers,Accept:"application/json;as=Table;v=v1;g=meta.k8s.io,application/json;as=Table;v=v1beta1;g=meta.k8s.io,application/json"}),this.options)}async Create(e,s){let t=this.buildPath(s);return t.err?t:a.WithExtra(await this.client.doRaw(t.val,{method:"POST",body:JSON.stringify(e)},{...this.options.headers,"Content-Type":"application/json"}),this.options)}async PatchObject(e,s,t,r){let n=ae.default.generate(e,s);return this.Patch(s.metadata?.name,n,t,r)}async Patch(e,s,t,r){this.options.name=e;let n=this.buildPath(r);return n.err?n:a.WithExtra(await this.client.doRaw(n.val,{method:"PATCH",body:JSON.stringify(s,function(u,i){return i===void 0?null:i})},{...this.options.headers,"Content-Type":t||"application/merge-patch+json"}),this.options)}async Update(e,s,t){this.options.name=e;let r=this.buildPath(t);return r.err?r:a.WithExtra(await this.client.doRaw(r.val,{method:"PUT",body:JSON.stringify(s)},{...this.options.headers,"Content-Type":"application/json"}),this.options)}async Delete(e,s){this.options.name=e;let t=this.buildPath(s);return t.err?t:a.WithExtra(await this.client.doRaw(t.val,{method:"DELETE"},this.options.headers),this.options)}async CanI(e){let s=this.options.groupVersionResource,t=this.options.basePath?.indexOf(A)===0?this.options.basePath.substring(A.length):void 0,r,n;this.options.project?(r=this.client.project(this.options.project,c.V1SelfSubjectAccessReview),n=d(c.V1SelfSubjectAccessReview)):this.options.vCluster?(r=this.client.vCluster(this.options.vCluster,c.V1SelfSubjectAccessReview),n=d(c.V1SelfSubjectAccessReview)):t?(r=this.client.cluster(t,c.V1SelfSubjectAccessReview),n=d(c.V1SelfSubjectAccessReview)):(r=this.client.management(c.ManagementV1SelfSubjectAccessReview),n=d(c.ManagementV1SelfSubjectAccessReview)),n.spec={resourceAttributes:{verb:e,name:this.options.name,namespace:this.options.namespace,group:s.group,version:s.version,resource:s.resource,subresource:s.subResource}};let u=await r.Create(n);return u.err?u:a.Value(!!(u.val.status?.allowed&&!u.val.status.denied))}};function oe(o){let e=new URLSearchParams;for(let[s,t]of Object.entries(o))Array.isArray(t)?t.forEach(r=>{e.append(s,r)}):e.append(s,t);return e.toString()}var ue=b;0&&(module.exports={APIExtensionsGroup,APIExtensionsGroupVersion,APIExtensionsVersion,Client,ClusterBasePath,Err,ErrorTypeAlreadyExists,ErrorTypeBadGateway,ErrorTypeBadRequest,ErrorTypeForbidden,ErrorTypeGatewayTimeout,ErrorTypeInternalError,ErrorTypeNetwork,ErrorTypeNotFound,ErrorTypeNotImplemented,ErrorTypeServiceUnavailable,ErrorTypeUnauthorized,ErrorTypeUnknown,Failed,List,LoftSchemeGroup,LoftSchemeGroupCluster,LoftSchemeGroupStorage,LoftSchemeGroupVersion,LoftSchemeGroupVersionCluster,LoftSchemeGroupVersionStorage,LoftSchemeGroupVersionVirtualCluster,LoftSchemeGroupVirtualCluster,LoftSchemeVersion,LoftSchemeVersionCluster,LoftSchemeVersionStorage,LoftSchemeVersionVirtualCluster,ManagementBasePath,MapErrorCode,NewResource,Ok,ProjectBasePath,Resources,Return,VClusterBasePath,getApiHost,getProjectFromNamespace,getProjectNamespace,isResult});