import {z} from 'zod' export type Unit = {quantity?: number | undefined, unit?: string | undefined}; export type CustomPriceType = 'RESELLER_PURCHASE_PRICE' | 'MARKETPLACE_RESELLER_PURCHASE_PRICE'; export type PricingStrategy = 'FREE' | 'FLAT' | 'UNIT' | 'TIERED' | 'VOLUME' | 'VARIABLE_PRICE_STRATEGIES' | 'UNLIMITED' | 'CUSTOM'; export type PriceRange = {min: number, max?: number | undefined, price: number, salePrice?: unknown | undefined, wholesalePrice?: unknown | undefined}; export type Definition = {price?: number | undefined, priceRanges?: Array | undefined}; export type CustomPrice = {costId: string, priceType?: CustomPriceType | undefined, pricingStrategy?: PricingStrategy | undefined, definition?: Definition | undefined}; export type MinimumServiceLengthUnit = 'DAILY' | 'MONTHLY' | 'QUARTERLY' | 'SIX_MONTHS' | 'YEARLY' | 'TWO_YEARS' | 'THREE_YEARS'; export type RenewalConfiguration = 'MONTH_TO_MONTH' | 'AUTO_RENEW' | 'CANCEL_SUBSCRIPTION'; export type FeeType = 'NONE' | 'PERCENTAGE' | 'FIXED'; export type TerminationFeeAS = {feeType?: FeeType | undefined, amount?: number | undefined, description?: string | undefined}; export type TerminationFeeGracePeriodUnit = 'NONE' | 'DAY' | 'MONTH'; export type GracePeriodUnit = 'NONE' | 'INFINITY' | 'DAY' | 'MONTH'; export type CancellationPeriodUnit = 'NONE' | 'DAY'; export type UnitContractTerms = {blockContractIncrease?: boolean | undefined, blockContractDecrease?: boolean | undefined, blockOriginalContractDecrease?: boolean | undefined}; export type ContractConfiguration = {minimumServiceLength?: number | undefined, minimumServiceLengthUnit?: MinimumServiceLengthUnit | undefined, renewalConfiguration?: RenewalConfiguration | undefined, terminationFee?: TerminationFeeAS | undefined, terminationFeeGracePeriod?: number | undefined, terminationFeeGracePeriodUnit?: TerminationFeeGracePeriodUnit | undefined, endOfContractGracePeriod?: number | undefined, endOfContractGracePeriodUnit?: GracePeriodUnit | undefined, contractCancellationPeriodLimit?: number | undefined, contractCancellationPeriodUnit?: CancellationPeriodUnit | undefined, unitTerms?: ({default?: string | undefined} | {[key: string]: UnitContractTerms}) | undefined, blockContractUpgrades?: boolean | undefined, blockContractDowngrades?: boolean | undefined, blockSwitchToShorterContract?: boolean | undefined, keepContractDateOnPlanChange?: boolean | undefined, isDefault?: boolean | undefined}; export type ProvisioningStrategy = 'CUSTOM' | 'IMMEDIATELY'; export type ProvisioningConfiguration = {date?: number | undefined, strategy?: ProvisioningStrategy | undefined}; export type BillingStrategy = 'CUSTOM' | 'NEXT_BILLING_CYCLE' | 'UPON_SERVICE_ACTIVATION'; export type BillingConfiguration = {date?: number | undefined, strategy?: BillingStrategy | undefined}; export type CustomAttribute = {[key: string]: Array}; export type OpportunityItemUpdateRequest = {id?: string | undefined, pricingPlanId: string, units?: Array | undefined, customPrices?: Array | undefined, contractConfiguration?: ContractConfiguration | undefined, provisioningConfiguration?: ProvisioningConfiguration | undefined, billingConfiguration?: BillingConfiguration | undefined, subscriptionCustomAttributes?: CustomAttribute | undefined, vendorRequiredFields?: CustomAttribute | undefined}; export type UpdateApiAssistedSalesV1OpportunitiesOpportunityIdItemsItemIdArgs = {opportunityId: string, itemId: string, body: OpportunityItemUpdateRequest}; export type UpdateApiAssistedSalesV1OpportunitiesOpportunityIdItemsItemIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const unit = z.object({quantity: z.number().optional(), unit: z.string().optional()}); export const costTypeCategory = z.enum(["RECURRING", "ONE_TIME"]); export const costType = z.enum(["RECURRING_FLAT", "ONE_TIME_FLAT", "INCLUDED", "SETUP_PER_UNIT", "RECURRING_PER_UNIT", "ONE_TIME_PER_UNIT", "SETUP_FEE", "CONTRACT_FEE", "DISCOUNT_PER_UNIT", "DISCOUNT_FLAT", "METERED_USAGE"]); export const pricingPeriod = z.enum(["ONE_TIME", "DAILY", "MONTHLY", "QUARTERLY", "SIX_MONTHS", "YEARLY", "TWO_YEARS", "THREE_YEARS"]); export const opportunityPricingStrategy = z.enum(["FREE", "FLAT", "UNIT", "VOLUME", "TIERED", "UNLIMITED", "CUSTOM"]); export const priceRangeItem = z.object({min: z.string().optional(), max: z.string().optional()}); export const opportunityPricing = z.object({costId: z.string().optional(), costTypeCategory: costTypeCategory, costType: costType, frequency: pricingPeriod.optional(), pricingStrategy: opportunityPricingStrategy, priceRanges: z.array(priceRangeItem).optional(), description: z.string().optional(), unit: z.string().optional(), quantity: z.string().optional(), salePrice: z.string(), wholesalePrice: z.string(), totalSalePrice: z.string()}); export const minimumServiceLengthUnit = z.enum(["DAILY", "MONTHLY", "QUARTERLY", "SIX_MONTHS", "YEARLY", "TWO_YEARS", "THREE_YEARS"]); export const renewalConfiguration = z.enum(["MONTH_TO_MONTH", "AUTO_RENEW", "CANCEL_SUBSCRIPTION"]); export const feeType = z.enum(["NONE", "PERCENTAGE", "FIXED"]); export const terminationFeeAS = z.object({feeType: feeType.optional(), amount: z.number().optional(), description: z.string().optional()}); export const terminationFeeGracePeriodUnit = z.enum(["NONE", "DAY", "MONTH"]); export const gracePeriodUnit = z.enum(["NONE", "INFINITY", "DAY", "MONTH"]); export const cancellationPeriodUnit = z.enum(["NONE", "DAY"]); export const unitContractTerms = z.object({blockContractIncrease: z.boolean().optional(), blockContractDecrease: z.boolean().optional(), blockOriginalContractDecrease: z.boolean().optional()}); export const provisioningStrategy = z.enum(["CUSTOM", "IMMEDIATELY"]); export const billingStrategy = z.enum(["CUSTOM", "NEXT_BILLING_CYCLE", "UPON_SERVICE_ACTIVATION"]); export const opportunityItemDetail = z.object({id: z.string().optional(), product: z.object({id: z.string().optional(), name: z.string().optional(), type: z.string().optional(), logo: z.string().optional()}).optional(), pricingPlan: z.object({id: z.string().optional(), name: z.string().optional()}).optional(), units: z.array(unit).optional(), pricing: z.array(opportunityPricing).optional(), contractConfiguration: z.object({minimumServiceLength: z.number().int().optional(), minimumServiceLengthUnit: minimumServiceLengthUnit.optional(), renewalConfiguration: renewalConfiguration.optional(), terminationFee: terminationFeeAS.optional(), terminationFeeGracePeriod: z.number().int().optional(), terminationFeeGracePeriodUnit: terminationFeeGracePeriodUnit.optional(), endOfContractGracePeriod: z.number().int().optional(), endOfContractGracePeriodUnit: gracePeriodUnit.optional(), contractCancellationPeriodLimit: z.number().int().optional(), contractCancellationPeriodUnit: cancellationPeriodUnit.optional(), unitTerms: z.object({default: z.string().optional()}).and(z.record(z.string(), unitContractTerms)).optional(), blockContractUpgrades: z.boolean().optional(), blockContractDowngrades: z.boolean().optional(), blockSwitchToShorterContract: z.boolean().optional(), keepContractDateOnPlanChange: z.boolean().optional(), isDefault: z.boolean().optional()}).optional(), provisioningConfiguration: z.object({date: z.number().optional(), strategy: provisioningStrategy.optional()}).optional(), billingConfiguration: z.object({date: z.number().optional(), strategy: billingStrategy.optional()}).optional(), subscriptionCustomAttributes: z.record(z.string(), z.array(z.string())).optional(), vendorRequiredFields: z.record(z.string(), z.array(z.string())).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Edit item * * PUT /assistedSales/v1/opportunities/{opportunityId}/items/{itemId} */ export const updateApiAssistedSalesV1OpportunitiesOpportunityIdItemsItemId = async (args: UpdateApiAssistedSalesV1OpportunitiesOpportunityIdItemsItemIdArgs, options?: UpdateApiAssistedSalesV1OpportunitiesOpportunityIdItemsItemIdOptions) => { const {baseUrl = "https://marketplace.appdirect.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/assistedSales/v1/opportunities/${encodeURIComponent(String(args.opportunityId))}/items/${encodeURIComponent(String(args.itemId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(opportunityItemDetail, await res.json()) };