Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .fern/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cliVersion": "4.86.1",
"cliVersion": "5.16.0",
"generatorName": "fernapi/fern-typescript-node-sdk",
"generatorVersion": "3.54.0",
"generatorConfig": {
Expand All @@ -15,7 +15,9 @@
},
"packageJson": {
"scripts": {
"test:integration": "vitest --config vitest.integration.config.mts"
"test:integration": "pnpm test:integration:main && pnpm test:integration:empty-state",
"test:integration:main": "vitest run --config vitest.integration.config.mts --project integration",
"test:integration:empty-state": "vitest run --config vitest.integration.config.mts --project integration-empty-state"
},
"exports": {
"./utils": {
Expand All @@ -32,6 +34,6 @@
}
}
},
"originGitCommit": "23bce53307f0836f2dcd50e82ef0aba136e7ec2f",
"originGitCommit": "33e722748626b7bb941efe15e18e21a5af94081e",
"sdkVersion": "0.0.0-dev"
}
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/api/errors/UnprocessableEntityError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import type * as core from "../../core/index.js";
import * as errors from "../../errors/index.js";
import type * as Corti from "../index.js";

export class UnprocessableEntityError extends errors.CortiError {
constructor(body: Corti.AgentsValidationErrorResponse, rawResponse?: core.RawResponse) {
constructor(body?: unknown, rawResponse?: core.RawResponse) {
super({
message: "UnprocessableEntityError",
statusCode: 422,
Expand Down
44 changes: 4 additions & 40 deletions src/api/resources/agents/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,7 @@ export class AgentsClient {
case 401:
throw new Corti.UnauthorizedError(_response.error.body, _response.rawResponse);
case 422:
throw new Corti.UnprocessableEntityError(
serializers.AgentsValidationErrorResponse.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
throw new Corti.UnprocessableEntityError(_response.error.body, _response.rawResponse);
default:
throw new errors.CortiError({
statusCode: _response.error.statusCode,
Expand Down Expand Up @@ -429,16 +420,7 @@ export class AgentsClient {
case 404:
throw new Corti.NotFoundError(_response.error.body, _response.rawResponse);
case 422:
throw new Corti.UnprocessableEntityError(
serializers.AgentsValidationErrorResponse.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
throw new Corti.UnprocessableEntityError(_response.error.body, _response.rawResponse);
default:
throw new errors.CortiError({
statusCode: _response.error.statusCode,
Expand Down Expand Up @@ -621,16 +603,7 @@ export class AgentsClient {
case 404:
throw new Corti.NotFoundError(_response.error.body, _response.rawResponse);
case 422:
throw new Corti.UnprocessableEntityError(
serializers.AgentsValidationErrorResponse.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
throw new Corti.UnprocessableEntityError(_response.error.body, _response.rawResponse);
default:
throw new errors.CortiError({
statusCode: _response.error.statusCode,
Expand Down Expand Up @@ -909,16 +882,7 @@ export class AgentsClient {
case 401:
throw new Corti.UnauthorizedError(_response.error.body, _response.rawResponse);
case 422:
throw new Corti.UnprocessableEntityError(
serializers.AgentsValidationErrorResponse.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
throw new Corti.UnprocessableEntityError(_response.error.body, _response.rawResponse);
default:
throw new errors.CortiError({
statusCode: _response.error.statusCode,
Expand Down
116 changes: 116 additions & 0 deletions src/api/resources/documents/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCode
import * as errors from "../../../../errors/index.js";
import * as serializers from "../../../../serialization/index.js";
import * as Corti from "../../../index.js";
import { SectionsClient } from "../resources/sections/client/Client.js";
import { TemplatesClient } from "../resources/templates/client/Client.js";

export declare namespace DocumentsClient {
export type Options = BaseClientOptions;
Expand All @@ -17,11 +19,21 @@ export declare namespace DocumentsClient {

export class DocumentsClient {
protected readonly _options: NormalizedClientOptionsWithAuth<DocumentsClient.Options>;
protected _templates: TemplatesClient | undefined;
protected _sections: SectionsClient | undefined;

constructor(options: DocumentsClient.Options) {
this._options = normalizeClientOptionsWithAuth(options);
}

public get templates(): TemplatesClient {
return (this._templates ??= new TemplatesClient(this._options));
}

public get sections(): SectionsClient {
return (this._sections ??= new SectionsClient(this._options));
}

/**
* List Documents
*
Expand Down Expand Up @@ -564,4 +576,108 @@ export class DocumentsClient {
"/interactions/{id}/documents/{documentId}",
);
}

/**
* Generates a structured document using one of four template-supply paths: a stored template reference (optionally with runtime overrides), an ad-hoc assembly of stored sections, or a fully inline dynamic template. Exactly one of `templateRef`, `assemblyTemplate`, or `dynamicTemplate` must be provided.
*
* With the exception of the plain `templateRef` path (no overrides), every call persists a new auto-generated template aggregate that snapshots the resolved content. The snapshot is drift-proof: subsequent edits to base templates or sections do not affect previously generated documents.
*
* @param {Corti.GuidedDocumentRequest} request
* @param {DocumentsClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Corti.BadRequestError}
* @throws {@link Corti.NotFoundError}
* @throws {@link Corti.UnprocessableEntityError}
* @throws {@link Corti.BadGatewayError}
*
* @example
* await client.documents.generate({
* templateRef: {
* templateId: "templateId"
* },
* outputLanguage: "outputLanguage"
* })
*/
public generate(
request: Corti.GuidedDocumentRequest,
requestOptions?: DocumentsClient.RequestOptions,
): core.HttpResponsePromise<Corti.GuidedDocumentResponse> {
return core.HttpResponsePromise.fromPromise(this.__generate(request, requestOptions));
}

private async __generate(
request: Corti.GuidedDocumentRequest,
requestOptions?: DocumentsClient.RequestOptions,
): Promise<core.WithRawResponse<Corti.GuidedDocumentResponse>> {
const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
_authRequest.headers,
this._options?.headers,
mergeOnlyDefinedHeaders({ "Tenant-Name": requestOptions?.tenantName ?? this._options?.tenantName }),
requestOptions?.headers,
);
const _response = await core.fetcher({
url: core.url.join(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)).base,
"documents/",
),
method: "POST",
headers: _headers,
contentType: "application/json",
queryParameters: requestOptions?.queryParams,
requestType: "json",
body: serializers.GuidedDocumentRequest.jsonOrThrow(request, {
unrecognizedObjectKeys: "strip",
omitUndefined: true,
}),
timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
data: serializers.GuidedDocumentResponse.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
rawResponse: _response.rawResponse,
};
}

if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new Corti.BadRequestError(_response.error.body, _response.rawResponse);
case 404:
throw new Corti.NotFoundError(_response.error.body, _response.rawResponse);
case 422:
throw new Corti.UnprocessableEntityError(_response.error.body, _response.rawResponse);
case 502:
throw new Corti.BadGatewayError(
serializers.ErrorResponse.parseOrThrow(_response.error.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
skipValidation: true,
breadcrumbsPrefix: ["response"],
}),
_response.rawResponse,
);
default:
throw new errors.CortiError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}

return handleNonStatusCodeError(_response.error, _response.rawResponse, "POST", "/documents/");
}
}
1 change: 1 addition & 0 deletions src/api/resources/documents/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./client/index.js";
export * from "./resources/index.js";
4 changes: 4 additions & 0 deletions src/api/resources/documents/resources/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from "./sections/client/requests/index.js";
export * as sections from "./sections/index.js";
export * from "./templates/client/requests/index.js";
export * as templates from "./templates/index.js";
Loading
Loading