diff --git a/create-customer/src/index.ts b/create-customer/src/index.ts index 89e9142..ff51df6 100644 --- a/create-customer/src/index.ts +++ b/create-customer/src/index.ts @@ -1,20 +1,21 @@ -import * as core from "@actions/core"; -import { VendorPortalApi, createCustomer } from "replicated-lib"; +import * as core from '@actions/core'; +import { VendorPortalApi, createCustomer } from 'replicated-lib'; -import { parse } from "yaml"; +import { parse } from 'yaml' async function run() { try { - const appSlug = core.getInput("app-slug"); - const apiToken = core.getInput("api-token"); - const name = core.getInput("customer-name"); - const email = core.getInput("customer-email"); - const licenseType = core.getInput("license-type"); - const channelSlug = core.getInput("channel-slug"); - const apiEndpoint = core.getInput("replicated-api-endpoint"); - const expiresInDays: number = +(core.getInput("expires-in") || 0); - const entitlements = core.getInput("entitlements"); - + const appSlug = core.getInput('app-slug'); + const apiToken = core.getInput('api-token') + const name = core.getInput('customer-name'); + const email = core.getInput('customer-email'); + const licenseType = core.getInput('license-type'); + const channelSlug = core.getInput('channel-slug'); + const apiEndpoint = core.getInput('replicated-api-endpoint') + const expiresInDays: number = +(core.getInput('expires-in') || 0); + const entitlements = core.getInput('entitlements'); + + // The default for isKotsInstallEnabled is undefined, which means it will not be set // As such we can not use core.getBooleanInput let isKotsInstallEnabled: boolean | undefined = undefined; @@ -22,30 +23,21 @@ async function run() { isKotsInstallEnabled = core.getInput("is-kots-install-enabled") === "true"; } - + const apiClient = new VendorPortalApi(); apiClient.apiToken = apiToken; if (apiEndpoint) { - apiClient.endpoint = apiEndpoint; + apiClient.endpoint = apiEndpoint } - const entitlementsArray = processEntitlements(entitlements); - const customer = await createCustomer( - apiClient, - appSlug, - name, - email, - licenseType, - channelSlug, - expiresInDays, - entitlementsArray, - isKotsInstallEnabled - ); + const entitlementsArray = processEntitlements(entitlements) + const customer = await createCustomer(apiClient, appSlug, name, email, licenseType, channelSlug, expiresInDays, entitlementsArray, isKotsInstallEnabled); + + core.setOutput('customer-id', customer.customerId); + core.setOutput('license-id', customer.licenseId); + core.setOutput('license-file', customer.license); - core.setOutput("customer-id", customer.customerId); - core.setOutput("license-id", customer.licenseId); - core.setOutput("license-file", customer.license); } catch (error) { core.setFailed(error.message); } @@ -53,15 +45,15 @@ async function run() { function processEntitlements(entitlements: string): [] | undefined { if (entitlements) { - const entitlementsYAML = parse(entitlements); - + const entitlementsYAML = parse(entitlements) + // for each entitlement in entitlementsYAML, convert to json and add to array const entitlementsArray = entitlementsYAML.map((entitlement: any) => { - return { name: entitlement.name, value: entitlement.value }; - }); - return entitlementsArray; + return {name: entitlement.name, value: entitlement.value} + }) + return entitlementsArray } - return undefined; + return undefined } -run(); +run() \ No newline at end of file