-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f7cb42
commit 289acca
Showing
28 changed files
with
354 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as errors from "../../errors/index"; | ||
import * as FileForge from "../index"; | ||
|
||
export class BadGatewayError extends errors.FileForgeError { | ||
constructor(body: FileForge.ErrorSchema) { | ||
super({ | ||
message: "BadGatewayError", | ||
statusCode: 502, | ||
body: body, | ||
}); | ||
Object.setPrototypeOf(this, BadGatewayError.prototype); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as errors from "../../errors/index"; | ||
import * as FileForge from "../index"; | ||
|
||
export class BadRequestError extends errors.FileForgeError { | ||
constructor(body: FileForge.ErrorSchema) { | ||
super({ | ||
message: "BadRequestError", | ||
statusCode: 400, | ||
body: body, | ||
}); | ||
Object.setPrototypeOf(this, BadRequestError.prototype); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as errors from "../../errors/index"; | ||
|
||
export class InternalServerError extends errors.FileForgeError { | ||
constructor(body?: unknown) { | ||
super({ | ||
message: "InternalServerError", | ||
statusCode: 500, | ||
body: body, | ||
}); | ||
Object.setPrototypeOf(this, InternalServerError.prototype); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as errors from "../../errors/index"; | ||
import * as FileForge from "../index"; | ||
|
||
export class UnauthorizedError extends errors.FileForgeError { | ||
constructor(body: FileForge.ErrorSchema) { | ||
super({ | ||
message: "UnauthorizedError", | ||
statusCode: 401, | ||
body: body, | ||
}); | ||
Object.setPrototypeOf(this, UnauthorizedError.prototype); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./BadRequestError"; | ||
export * from "./UnauthorizedError"; | ||
export * from "./InternalServerError"; | ||
export * from "./BadGatewayError"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from "./resources"; | ||
export * from "./types"; | ||
export * from "./errors"; | ||
export * from "./client"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * as pdf from "./pdf"; | ||
export * from "./pdf/types"; | ||
export * from "./pdf/client/requests"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as environments from "../../../../environments"; | ||
import * as core from "../../../../core"; | ||
import * as fs from "fs"; | ||
import * as FileForge from "../../../index"; | ||
import * as stream from "stream"; | ||
import { default as FormData } from "form-data"; | ||
import urlJoin from "url-join"; | ||
import * as errors from "../../../../errors/index"; | ||
import * as serializers from "../../../../serialization/index"; | ||
|
||
export declare namespace Pdf { | ||
interface Options { | ||
environment?: core.Supplier<environments.FileForgeEnvironment | string>; | ||
username: core.Supplier<string>; | ||
password: core.Supplier<string>; | ||
apiKey: core.Supplier<string>; | ||
} | ||
|
||
interface RequestOptions { | ||
timeoutInSeconds?: number; | ||
maxRetries?: number; | ||
} | ||
} | ||
|
||
export class Pdf { | ||
constructor(protected readonly _options: Pdf.Options) {} | ||
|
||
/** | ||
* @throws {@link FileForge.BadRequestError} | ||
* @throws {@link FileForge.UnauthorizedError} | ||
* @throws {@link FileForge.InternalServerError} | ||
*/ | ||
public async postPdfMerge( | ||
files: File[] | fs.ReadStream[], | ||
request: FileForge.PostPdfMergeRequest, | ||
requestOptions?: Pdf.RequestOptions | ||
): Promise<stream.Readable> { | ||
const _request = new FormData(); | ||
_request.append("options", JSON.stringify(request.options)); | ||
for (const _file of files) { | ||
_request.append("files", _file); | ||
} | ||
|
||
const _response = await core.fetcher<stream.Readable>({ | ||
url: urlJoin( | ||
(await core.Supplier.get(this._options.environment)) ?? environments.FileForgeEnvironment.Default, | ||
"pdf/merge/" | ||
), | ||
method: "POST", | ||
headers: { | ||
Authorization: await this._getAuthorizationHeader(), | ||
"X-API-Key": await core.Supplier.get(this._options.apiKey), | ||
"X-Fern-Language": "JavaScript", | ||
"X-Fern-SDK-Name": "fileforge", | ||
"X-Fern-SDK-Version": "0.0.0", | ||
"X-Fern-Runtime": core.RUNTIME.type, | ||
"X-Fern-Runtime-Version": core.RUNTIME.version, | ||
}, | ||
contentType: "multipart/form-data; boundary=" + _request.getBoundary(), | ||
body: _request, | ||
responseType: "streaming", | ||
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, | ||
maxRetries: requestOptions?.maxRetries, | ||
}); | ||
if (_response.ok) { | ||
return _response.body; | ||
} | ||
|
||
if (_response.error.reason === "status-code") { | ||
switch (_response.error.statusCode) { | ||
case 400: | ||
throw new FileForge.BadRequestError( | ||
await serializers.ErrorSchema.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case 401: | ||
throw new FileForge.UnauthorizedError( | ||
await serializers.ErrorSchema.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case 500: | ||
throw new FileForge.InternalServerError(_response.error.body); | ||
default: | ||
throw new errors.FileForgeError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.body, | ||
}); | ||
} | ||
} | ||
|
||
switch (_response.error.reason) { | ||
case "non-json": | ||
throw new errors.FileForgeError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.rawBody, | ||
}); | ||
case "timeout": | ||
throw new errors.FileForgeTimeoutError(); | ||
case "unknown": | ||
throw new errors.FileForgeError({ | ||
message: _response.error.errorMessage, | ||
}); | ||
} | ||
} | ||
|
||
protected async _getAuthorizationHeader(): Promise<string | undefined> { | ||
return core.BasicAuth.toAuthorizationHeader({ | ||
username: await core.Supplier.get(this._options.username), | ||
password: await core.Supplier.get(this._options.password), | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./requests"; |
13 changes: 13 additions & 0 deletions
13
src/api/resources/pdf/client/requests/PostPdfMergeRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as FileForge from "../../../../index"; | ||
|
||
/** | ||
* @example | ||
* {} | ||
*/ | ||
export interface PostPdfMergeRequest { | ||
options: FileForge.PostPdfMergeRequestOptions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { type PostPdfMergeRequest } from "./PostPdfMergeRequest"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./types"; | ||
export * from "./client"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
export interface PostPdfMergeRequestOptions {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./PostPdfMergeRequestOptions"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
/** | ||
* Generic error response schema | ||
*/ | ||
export interface ErrorSchema { | ||
/** The HTTP status code */ | ||
statusCode: number; | ||
/** A machine-readable error code */ | ||
code: string; | ||
/** A human-readable message */ | ||
message: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./GenerateRequestOptions"; | ||
export * from "./ErrorSchema"; |
Oops, something went wrong.