/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod/v4-mini";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
CarrierAccountServiceLevel,
CarrierAccountServiceLevel$inboundSchema,
} from "./carrieraccountservicelevel.js";
import {
FedExConnectExistingOwnAccountParameters,
FedExConnectExistingOwnAccountParameters$inboundSchema,
} from "./fedexconnectexistingownaccountparameters.js";
import {
UPSConnectExistingOwnAccountParameters,
UPSConnectExistingOwnAccountParameters$inboundSchema,
} from "./upsconnectexistingownaccountparameters.js";
export type ParametersT =
| UPSConnectExistingOwnAccountParameters
| FedExConnectExistingOwnAccountParameters
| { [k: string]: any };
/**
* Authentication method used by this account.
*/
export const CarrierAccountWithExtraInfoType = {
Default: "default",
Oauth: "oauth",
} as const;
/**
* Authentication method used by this account.
*/
export type CarrierAccountWithExtraInfoType = ClosedEnum<
typeof CarrierAccountWithExtraInfoType
>;
/**
* Current authentication status. Possible values: 'disconnected' (authorization lost, reconnect needed), 'connected' (authorized and active), 'authorization_pending' (awaiting initial authorization flow).
*/
export const CarrierAccountWithExtraInfoStatus = {
Disconnected: "disconnected",
Connected: "connected",
AuthorizationPending: "authorization_pending",
} as const;
/**
* Current authentication status. Possible values: 'disconnected' (authorization lost, reconnect needed), 'connected' (authorized and active), 'authorization_pending' (awaiting initial authorization flow).
*/
export type CarrierAccountWithExtraInfoStatus = ClosedEnum<
typeof CarrierAccountWithExtraInfoStatus
>;
export type Authentication = {
/**
* Authentication method used by this account.
*/
type?: CarrierAccountWithExtraInfoType | undefined;
/**
* Current authentication status. Possible values: 'disconnected' (authorization lost, reconnect needed), 'connected' (authorized and active), 'authorization_pending' (awaiting initial authorization flow).
*/
status?: CarrierAccountWithExtraInfoStatus | undefined;
};
/**
* Holds internal state relevant to users.
*/
export type ObjectInfo = {
authentication?: Authentication | undefined;
};
export type CarrierAccountWithExtraInfo = {
/**
* Unique identifier of the account. Please check the carrier accounts tutorial
*
* @remarks
* page for the `account_id` per carrier.
* To protect account information, this field will be masked in any API response.
*/
accountId: string;
/**
* Determines whether the account is active. When creating a shipment, if no `carrier_accounts` are explicitly
*
* @remarks
* passed Shippo will query all carrier accounts that have this field set. By default, this is set to True.
*/
active?: boolean | undefined;
/**
* Carrier token, see Carriers
*
* @remarks
* Please check the carrier accounts tutorial page for all supported carriers.
*/
carrier: string;
parameters?:
| UPSConnectExistingOwnAccountParameters
| FedExConnectExistingOwnAccountParameters
| { [k: string]: any }
| undefined;
/**
* Carrier name, see Carriers
*/
carrierName?: any | undefined;
isShippoAccount?: boolean | undefined;
metadata?: string | undefined;
/**
* Unique identifier of the carrier account object.
*/
objectId?: string | undefined;
/**
* Username of the user who created the carrier account object.
*/
objectOwner?: string | undefined;
serviceLevels?: Array | undefined;
/**
* Indicates whether the object has been created in test mode.
*/
test?: boolean | undefined;
/**
* Holds internal state relevant to users.
*/
objectInfo?: ObjectInfo | undefined;
};
/** @internal */
export const ParametersT$inboundSchema: z.ZodMiniType = z
.union([
UPSConnectExistingOwnAccountParameters$inboundSchema,
FedExConnectExistingOwnAccountParameters$inboundSchema,
z.record(z.string(), z.any()),
]);
export function parametersFromJSON(
jsonString: string,
): SafeParseResult {
return safeParse(
jsonString,
(x) => ParametersT$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'ParametersT' from JSON`,
);
}
/** @internal */
export const CarrierAccountWithExtraInfoType$inboundSchema: z.ZodMiniEnum<
typeof CarrierAccountWithExtraInfoType
> = z.enum(CarrierAccountWithExtraInfoType);
/** @internal */
export const CarrierAccountWithExtraInfoStatus$inboundSchema: z.ZodMiniEnum<
typeof CarrierAccountWithExtraInfoStatus
> = z.enum(CarrierAccountWithExtraInfoStatus);
/** @internal */
export const Authentication$inboundSchema: z.ZodMiniType<
Authentication,
unknown
> = z.object({
type: z.optional(CarrierAccountWithExtraInfoType$inboundSchema),
status: z.optional(CarrierAccountWithExtraInfoStatus$inboundSchema),
});
export function authenticationFromJSON(
jsonString: string,
): SafeParseResult {
return safeParse(
jsonString,
(x) => Authentication$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Authentication' from JSON`,
);
}
/** @internal */
export const ObjectInfo$inboundSchema: z.ZodMiniType = z
.object({
authentication: z.optional(z.lazy(() => Authentication$inboundSchema)),
});
export function objectInfoFromJSON(
jsonString: string,
): SafeParseResult {
return safeParse(
jsonString,
(x) => ObjectInfo$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'ObjectInfo' from JSON`,
);
}
/** @internal */
export const CarrierAccountWithExtraInfo$inboundSchema: z.ZodMiniType<
CarrierAccountWithExtraInfo,
unknown
> = z.pipe(
z.object({
account_id: z.string(),
active: z.optional(z.boolean()),
carrier: z.string(),
parameters: z.optional(
z.union([
UPSConnectExistingOwnAccountParameters$inboundSchema,
FedExConnectExistingOwnAccountParameters$inboundSchema,
z.record(z.string(), z.any()),
]),
),
carrier_name: z.optional(z.any()),
is_shippo_account: z.optional(z.boolean()),
metadata: z.optional(z.string()),
object_id: z.optional(z.string()),
object_owner: z.optional(z.string()),
service_levels: z.optional(
z.array(CarrierAccountServiceLevel$inboundSchema),
),
test: z.optional(z.boolean()),
object_info: z.optional(z.lazy(() => ObjectInfo$inboundSchema)),
}),
z.transform((v) => {
return remap$(v, {
"account_id": "accountId",
"carrier_name": "carrierName",
"is_shippo_account": "isShippoAccount",
"object_id": "objectId",
"object_owner": "objectOwner",
"service_levels": "serviceLevels",
"object_info": "objectInfo",
});
}),
);
export function carrierAccountWithExtraInfoFromJSON(
jsonString: string,
): SafeParseResult {
return safeParse(
jsonString,
(x) => CarrierAccountWithExtraInfo$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'CarrierAccountWithExtraInfo' from JSON`,
);
}