/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod/v3";
import { remap as remap$ } from "../../lib/primitives.js";
import { lazySchema as lazySchema$, safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import * as types from "../../types/primitives.js";
import * as components from "../components/index.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
export type FileStorageFilesDownloadGlobals = {
/**
* ID of the consumer which you want to get or push data from
*/
consumerId?: string | undefined;
/**
* The ID of your Unify application
*/
appId?: string | undefined;
};
export type FileStorageFilesDownloadRequest = {
/**
* ID of the record you are acting upon.
*/
id: string;
/**
* ID of the consumer which you want to get or push data from
*/
consumerId?: string | undefined;
/**
* The ID of your Unify application
*/
appId?: string | undefined;
/**
* Provide the service id you want to call (e.g., pipedrive). Only needed when a consumer has activated multiple integrations for a Unified API.
*/
serviceId?: string | undefined;
/**
* The 'fields' parameter allows API users to specify the fields they want to include in the API response. If this parameter is not present, the API will return all available fields. If this parameter is present, only the fields specified in the comma-separated string will be included in the response. Nested properties can also be requested by using a dot notation.
Example: `fields=name,email,addresses.city`
In the example above, the response will only include the fields "name", "email" and "addresses.city". If any other fields are available, they will be excluded.
*/
fields?: string | null | undefined;
/**
* Set to `false` to opt out of the redirect to the presigned download URL. Instead of a `30x` response, you receive a `200` JSON body `{ url, expires_at }` containing the URL and its expiry, which you can fetch explicitly. Use this if your client automatically forwards the `Authorization` header onto redirects, since the downstream storage provider will reject that request. Any value other than `false` (or omitting the header) preserves the default redirect behavior.
*/
followRedirects?: boolean | undefined;
};
export type FileStorageFilesDownloadResponse = {
httpMeta: components.HTTPMetadata;
/**
* File Download. When the request includes `x-apideck-follow-redirects: false` and the download would otherwise redirect to a presigned URL, the response body is instead an `application/json` object `{ url, expires_at }` — fetch `url` explicitly (without the Authorization header) to retrieve the file.
*/
getFileDownloadResponse?: ReadableStream | undefined;
/**
* Unexpected error
*/
unexpectedErrorResponse?: components.UnexpectedErrorResponse | undefined;
};
/** @internal */
export type FileStorageFilesDownloadRequest$Outbound = {
id: string;
consumerId?: string | undefined;
appId?: string | undefined;
serviceId?: string | undefined;
fields?: string | null | undefined;
followRedirects: boolean;
};
/** @internal */
export const FileStorageFilesDownloadRequest$outboundSchema: z.ZodType<
FileStorageFilesDownloadRequest$Outbound,
z.ZodTypeDef,
FileStorageFilesDownloadRequest
> = /* @__PURE__ */ lazySchema$(() =>
z.object({
id: z.string(),
consumerId: z.string().optional(),
appId: z.string().optional(),
serviceId: z.string().optional(),
fields: z.nullable(z.string()).optional(),
followRedirects: z.boolean().default(true),
})
);
export function fileStorageFilesDownloadRequestToJSON(
fileStorageFilesDownloadRequest: FileStorageFilesDownloadRequest,
): string {
return JSON.stringify(
FileStorageFilesDownloadRequest$outboundSchema.parse(
fileStorageFilesDownloadRequest,
),
);
}
/** @internal */
export const FileStorageFilesDownloadResponse$inboundSchema: z.ZodType<
FileStorageFilesDownloadResponse,
z.ZodTypeDef,
unknown
> = /* @__PURE__ */ lazySchema$(() =>
z.object({
HttpMeta: components.HTTPMetadata$inboundSchema,
GetFileDownloadResponse: types.optional(
z.instanceof(ReadableStream),
),
UnexpectedErrorResponse: types.optional(
components.UnexpectedErrorResponse$inboundSchema,
),
}).transform((v) => {
return remap$(v, {
"HttpMeta": "httpMeta",
"GetFileDownloadResponse": "getFileDownloadResponse",
"UnexpectedErrorResponse": "unexpectedErrorResponse",
});
})
);
export function fileStorageFilesDownloadResponseFromJSON(
jsonString: string,
): SafeParseResult {
return safeParse(
jsonString,
(x) => FileStorageFilesDownloadResponse$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'FileStorageFilesDownloadResponse' from JSON`,
);
}