From b6bf19f4dc25817da9e6e284b8aa082e81f2d6cf Mon Sep 17 00:00:00 2001 From: Josh De Winne Date: Mon, 20 Apr 2026 09:40:23 -0700 Subject: [PATCH] Add missing customer create flags --- src/customers.spec.ts | 7 +++- src/customers.ts | 77 ++++++++++++++++++++++++++++++++++++++----- src/index.ts | 2 +- 3 files changed, 76 insertions(+), 10 deletions(-) diff --git a/src/customers.spec.ts b/src/customers.spec.ts index 2a38daa..bfd15ec 100644 --- a/src/customers.spec.ts +++ b/src/customers.spec.ts @@ -67,7 +67,12 @@ describe("Create Customer", () => { await mockServer.forPost("/customer").once().thenReply(201, JSON.stringify(customerResponse)); await mockServer.forGet("/app/1234abcd/customer/5678efgh/license-download").once().thenReply(403); - const customer: Customer = await createCustomer(apiClient, "app-1", "testing", "testing@replicated.com", "test", "", 0); + const customer: Customer = await createCustomer(apiClient, { + appSlug: "app-1", + name: "testing", + email: "testing@replicated.com", + licenseType: "test" + }); expect(customer.name).toEqual("testing"); expect(customer.customerId).toEqual("5678efgh"); expect(customer.licenseId).toEqual("1234abcd"); diff --git a/src/customers.ts b/src/customers.ts index a4dd3b3..83795c5 100644 --- a/src/customers.ts +++ b/src/customers.ts @@ -22,6 +22,30 @@ interface entitlementValue { value: string; } +export interface CreateCustomerOptions { + appSlug: string; + name: string; + licenseType: string; + email?: string; + channelSlug?: string; + expiresIn?: number; + entitlementValues?: entitlementValue[]; + customId?: string; + isKotsInstallEnabled?: boolean; + isDevModeEnabled?: boolean; + isAirgapEnabled?: boolean; + isGitopsSupported?: boolean; + isSnapshotSupported?: boolean; + isHelmInstallEnabled?: boolean; + isKurlInstallEnabled?: boolean; + isEmbeddedClusterDownloadEnabled?: boolean; + isEmbeddedClusterMultinodeEnabled?: boolean; + isGeoaxisSupported?: boolean; + isIdentityServiceSupported?: boolean; + isInstallerSupportEnabled?: boolean; + isSupportBundleUploadEnabled?: boolean; +} + export class KubernetesDistribution { k8sDistribution: string; k8sVersion: string; @@ -32,8 +56,9 @@ export class KubernetesDistribution { isAirgap: boolean; } -export async function createCustomer(vendorPortalApi: VendorPortalApi, appSlug: string, name: string, email: string, licenseType: string, channelSlug: string, expiresIn: number, entitlementValues?: entitlementValue[], isKotsInstallEnabled?: boolean, isDevModeEnabled?: boolean): Promise { +export async function createCustomer(vendorPortalApi: VendorPortalApi, options: CreateCustomerOptions): Promise { try { + const { appSlug, name, licenseType, email, channelSlug, expiresIn, entitlementValues } = options; const app = await getApplicationDetails(vendorPortalApi, appSlug); console.log("Creating customer on appId " + app.id); @@ -42,21 +67,18 @@ export async function createCustomer(vendorPortalApi: VendorPortalApi, appSlug: // 1. create the customer const createCustomerUri = `${vendorPortalApi.endpoint}/customer`; - let createCustomerReqBody = { + let createCustomerReqBody: Record = { name: name, email: email, type: licenseType, app_id: app.id }; - if (isKotsInstallEnabled !== undefined) { - createCustomerReqBody["is_kots_install_enabled"] = isKotsInstallEnabled; - } if (channelSlug) { const channel = await getChannelDetails(vendorPortalApi, appSlug, { slug: channelSlug }); createCustomerReqBody["channel_id"] = channel.id; } // expiresIn is in days, if it's 0 or less, ignore it - non-expiring license - if (expiresIn > 0) { + if (expiresIn !== undefined && expiresIn > 0) { const now = new Date(); const expiresAt = fromZonedTime(add(now, { days: expiresIn }), "UTC"); createCustomerReqBody["expires_at"] = expiresAt.toISOString(); @@ -64,8 +86,47 @@ export async function createCustomer(vendorPortalApi: VendorPortalApi, appSlug: if (entitlementValues) { createCustomerReqBody["entitlementValues"] = entitlementValues; } - if (isDevModeEnabled !== undefined) { - createCustomerReqBody["is_dev_mode_enabled"] = isDevModeEnabled; + if (options.customId !== undefined) { + createCustomerReqBody["custom_id"] = options.customId; + } + if (options.isKotsInstallEnabled !== undefined) { + createCustomerReqBody["is_kots_install_enabled"] = options.isKotsInstallEnabled; + } + if (options.isDevModeEnabled !== undefined) { + createCustomerReqBody["is_dev_mode_enabled"] = options.isDevModeEnabled; + } + if (options.isAirgapEnabled !== undefined) { + createCustomerReqBody["is_airgap_enabled"] = options.isAirgapEnabled; + } + if (options.isGitopsSupported !== undefined) { + createCustomerReqBody["is_gitops_supported"] = options.isGitopsSupported; + } + if (options.isSnapshotSupported !== undefined) { + createCustomerReqBody["is_snapshot_supported"] = options.isSnapshotSupported; + } + if (options.isHelmInstallEnabled !== undefined) { + createCustomerReqBody["is_helm_install_enabled"] = options.isHelmInstallEnabled; + } + if (options.isKurlInstallEnabled !== undefined) { + createCustomerReqBody["is_kurl_install_enabled"] = options.isKurlInstallEnabled; + } + if (options.isEmbeddedClusterDownloadEnabled !== undefined) { + createCustomerReqBody["is_embedded_cluster_download_enabled"] = options.isEmbeddedClusterDownloadEnabled; + } + if (options.isEmbeddedClusterMultinodeEnabled !== undefined) { + createCustomerReqBody["is_embedded_cluster_multinode_enabled"] = options.isEmbeddedClusterMultinodeEnabled; + } + if (options.isGeoaxisSupported !== undefined) { + createCustomerReqBody["is_geoaxis_supported"] = options.isGeoaxisSupported; + } + if (options.isIdentityServiceSupported !== undefined) { + createCustomerReqBody["is_identity_service_supported"] = options.isIdentityServiceSupported; + } + if (options.isInstallerSupportEnabled !== undefined) { + createCustomerReqBody["is_installer_support_enabled"] = options.isInstallerSupportEnabled; + } + if (options.isSupportBundleUploadEnabled !== undefined) { + createCustomerReqBody["is_support_bundle_upload_enabled"] = options.isSupportBundleUploadEnabled; } const createCustomerRes = await http.post(createCustomerUri, JSON.stringify(createCustomerReqBody)); diff --git a/src/index.ts b/src/index.ts index afb4942..2fc58e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,5 +2,5 @@ export { VendorPortalApi } from "./configuration"; export { getApplicationDetails } from "./applications"; export { Channel, createChannel, getChannelDetails, archiveChannel, pollForAirgapReleaseStatus, getDownloadUrlAirgapBuildRelease } from "./channels"; export { ClusterVersion, createCluster, createClusterWithLicense, pollForStatus, getKubeconfig, removeCluster, upgradeCluster, getClusterVersions, createAddonObjectStore, pollForAddonStatus, exposeClusterPort } from "./clusters"; -export { KubernetesDistribution, CustomerSummary, archiveCustomer, createCustomer, getUsedKubernetesDistributions, listCustomersByName, listCustomersByEmail } from "./customers"; +export { KubernetesDistribution, CustomerSummary, CreateCustomerOptions, archiveCustomer, createCustomer, getUsedKubernetesDistributions, listCustomersByName, listCustomersByEmail } from "./customers"; export { Release, CompatibilityResult, createRelease, createReleaseFromChart, promoteRelease, reportCompatibilityResult } from "./releases";