Skip to content
Merged
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
127 changes: 124 additions & 3 deletions src/ _generated_/rest/api/resources/records/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,9 +850,12 @@ export class Records {
requestOptions?: Records.RequestOptions,
): Promise<core.WithRawResponse<Skyflow.V1UpdateRecordResponse>> {
const _request = await core.newFormData();
if (file != null && request.columnName != null) {
await _request.appendFile(request.columnName, file);

if (file != null) {
await _request.appendFile("file", file);
}

if (request.columnName != null) {
_request.append("columnName", request.columnName);
}

const _maybeEncodedRequest = await _request.getRequest();
Expand Down Expand Up @@ -1104,6 +1107,124 @@ export class Records {
}
}

/**
* Uploads the specified file to a record. If an existing record isn't specified, creates a new record and uploads the file to that record.
*
* @param {File | fs.ReadStream | Blob} file
* @param {string} vaultId
* @param {Skyflow.UploadFileV2Request} request
* @param {Records.RequestOptions} requestOptions - Request-specific configuration.
*
* @throws {@link Skyflow.BadRequestError}
* @throws {@link Skyflow.UnauthorizedError}
* @throws {@link Skyflow.NotFoundError}
* @throws {@link Skyflow.InternalServerError}
*
* @example
* await client.records.uploadFileV2(fs.createReadStream("/path/to/your/file"), "d4410ea01d83473ca09a24c6b03096d4", {
* tableName: "tableName",
* columnName: "columnName"
* })
*/
public uploadFileV2(
file: File | fs.ReadStream | Blob,
vaultId: string,
request: Skyflow.UploadFileV2Request,
requestOptions?: Records.RequestOptions,
): core.HttpResponsePromise<Skyflow.UploadFileV2Response> {
return core.HttpResponsePromise.fromPromise(this.__uploadFileV2(file, vaultId, request, requestOptions));
}

private async __uploadFileV2(
file: File | fs.ReadStream | Blob,
vaultId: string,
request: Skyflow.UploadFileV2Request,
requestOptions?: Records.RequestOptions,
): Promise<core.WithRawResponse<Skyflow.UploadFileV2Response>> {
const _request = await core.newFormData();
_request.append("tableName", request.tableName);
_request.append("columnName", request.columnName);
await _request.appendFile("file", file);
if (request.skyflowID != null) {
_request.append("skyflowID", request.skyflowID);
}

if (request.returnFileMetadata != null) {
_request.append("returnFileMetadata", request.returnFileMetadata.toString());
}

const _maybeEncodedRequest = await _request.getRequest();
const _response = await (this._options.fetcher ?? core.fetcher)({
url: urlJoin(
(await core.Supplier.get(this._options.baseUrl)) ??
(await core.Supplier.get(this._options.environment)) ??
environments.SkyflowEnvironment.Production,
`v2/vaults/${encodeURIComponent(vaultId)}/files/upload`,
),
method: "POST",
headers: {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "skyflow",
"X-Fern-SDK-Version": "1.0.21",
"User-Agent": "skyflow/1.0.21",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
..._maybeEncodedRequest.headers,
...requestOptions?.headers,
},
requestType: "file",
duplex: _maybeEncodedRequest.duplex,
body: _maybeEncodedRequest.body,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return { data: _response.body as Skyflow.UploadFileV2Response, rawResponse: _response.rawResponse };
}

if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new Skyflow.BadRequestError(_response.error.body as unknown, _response.rawResponse);
case 401:
throw new Skyflow.UnauthorizedError(_response.error.body as unknown, _response.rawResponse);
case 404:
throw new Skyflow.NotFoundError(_response.error.body as unknown, _response.rawResponse);
case 500:
throw new Skyflow.InternalServerError(
_response.error.body as Skyflow.ErrorResponse,
_response.rawResponse,
);
default:
throw new errors.SkyflowError({
statusCode: _response.error.statusCode,
body: _response.error.body,
rawResponse: _response.rawResponse,
});
}
}

switch (_response.error.reason) {
case "non-json":
throw new errors.SkyflowError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
rawResponse: _response.rawResponse,
});
case "timeout":
throw new errors.SkyflowTimeoutError(
"Timeout exceeded when calling POST /v2/vaults/{vaultID}/files/upload.",
);
case "unknown":
throw new errors.SkyflowError({
message: _response.error.errorMessage,
rawResponse: _response.rawResponse,
});
}
}

protected async _getAuthorizationHeader(): Promise<string> {
return `Bearer ${await core.Supplier.get(this._options.token)}`;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

/**
* @example
* {
* tableName: "tableName",
* columnName: "columnName"
* }
*/
export interface UploadFileV2Request {
/** Name of the table to upload the file to. */
tableName: string;
/** Name of the column to upload the file to. The column must have a `file` data type. */
columnName: string;
/** Skyflow ID of the record to upload the file to. If `skyflowID` isn't specified, a new record will be created. */
skyflowID?: string;
/** If `true`, returns metadata about the uploaded file. */
returnFileMetadata?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export { type RecordServiceBulkDeleteRecordBody } from "./RecordServiceBulkDelet
export { type RecordServiceGetRecordRequest } from "./RecordServiceGetRecordRequest";
export { type RecordServiceUpdateRecordBody } from "./RecordServiceUpdateRecordBody";
export { type FileServiceUploadFileRequest } from "./FileServiceUploadFileRequest";
export { type UploadFileV2Request } from "./UploadFileV2Request";
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface DeidentifyStatusResponse {
/** How the input file was specified. */
output: Skyflow.DeidentifyFileOutput[];
/** How the output file is specified. */
output_type?: Skyflow.DeidentifyStatusResponseOutputType;
output_type: Skyflow.DeidentifyStatusResponseOutputType;
/** Status details about the detect run. */
message: string;
/** Number of words in the processed text. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/**
* How the output file is specified.
*/
export type DeidentifyStatusResponseOutputType = "base64" | "efs_path";
export type DeidentifyStatusResponseOutputType = "BASE64" | "UNKNOWN";
export const DeidentifyStatusResponseOutputType = {
Base64: "base64",
EfsPath: "efs_path",
Base64: "BASE64",
Unknown: "UNKNOWN",
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
/**
* Status of the detect run.
*/
export type DeidentifyStatusResponseStatus = "failed" | "in_progress" | "success";
export type DeidentifyStatusResponseStatus = "FAILED" | "IN_PROGRESS" | "SUCCESS" | "UNKNOWN";
export const DeidentifyStatusResponseStatus = {
Failed: "failed",
InProgress: "in_progress",
Success: "success",
Failed: "FAILED",
InProgress: "IN_PROGRESS",
Success: "SUCCESS",
Unknown: "UNKNOWN",
} as const;
8 changes: 4 additions & 4 deletions src/ _generated_/rest/api/types/EntityType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export type EntityType =
| "credit_card_expiration"
| "cvv"
| "date"
| "day"
| "date_interval"
| "day"
| "dob"
| "dose"
| "driver_license"
Expand Down Expand Up @@ -60,10 +60,10 @@ export type EntityType =
| "passport_number"
| "password"
| "phone_number"
| "project"
| "physical_attribute"
| "political_affiliation"
| "product"
| "project"
| "religion"
| "routing_number"
| "sexuality"
Expand All @@ -88,8 +88,8 @@ export const EntityType = {
CreditCardExpiration: "credit_card_expiration",
Cvv: "cvv",
Date: "date",
Day: "day",
DateInterval: "date_interval",
Day: "day",
Dob: "dob",
Dose: "dose",
DriverLicense: "driver_license",
Expand Down Expand Up @@ -131,10 +131,10 @@ export const EntityType = {
PassportNumber: "passport_number",
Password: "password",
PhoneNumber: "phone_number",
Project: "project",
PhysicalAttribute: "physical_attribute",
PoliticalAffiliation: "political_affiliation",
Product: "product",
Project: "project",
Religion: "religion",
RoutingNumber: "routing_number",
Sexuality: "sexuality",
Expand Down
8 changes: 0 additions & 8 deletions src/ _generated_/rest/api/types/ErrorString.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/ _generated_/rest/api/types/ReidentifyFileResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export interface ReidentifyFileResponse {
/** Status of the re-identify operation. */
status: Skyflow.ReidentifyFileResponseStatus;
/** Format of the output file. */
output_type: "BASE64";
output_type: Skyflow.ReidentifyFileResponseOutputType;
output: Skyflow.ReidentifyFileResponseOutput;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

/**
* Format of the output file.
*/
export type ReidentifyFileResponseOutputType = "BASE64" | "UNKNOWN";
export const ReidentifyFileResponseOutputType = {
Base64: "BASE64",
Unknown: "UNKNOWN",
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
/**
* Status of the re-identify operation.
*/
export type ReidentifyFileResponseStatus = "failed" | "in_progress" | "success";
export type ReidentifyFileResponseStatus = "FAILED" | "IN_PROGRESS" | "SUCCESS" | "UNKNOWN";
export const ReidentifyFileResponseStatus = {
Failed: "failed",
InProgress: "in_progress",
Success: "success",
Failed: "FAILED",
InProgress: "IN_PROGRESS",
Success: "SUCCESS",
Unknown: "UNKNOWN",
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
*/
export interface ReidentifyStringResponse {
/** Re-identified text. */
processed_text?: string;
text?: string;
}
12 changes: 12 additions & 0 deletions src/ _generated_/rest/api/types/UploadFileV2Response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

/**
* Response schema for uploading a file, optionally creating a new record.
*/
export interface UploadFileV2Response {
/** Skyflow ID of the record the file was uploaded to. */
skyflowID?: string;
fileMetadata?: unknown;
}
3 changes: 2 additions & 1 deletion src/ _generated_/rest/api/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./UploadFileV2Response";
export * from "./AuditEventAuditResourceType";
export * from "./AuditEventContext";
export * from "./AuditEventData";
Expand Down Expand Up @@ -44,10 +45,10 @@ export * from "./V1VaultSchemaConfig";
export * from "./CheckGuardrailsResponseValidation";
export * from "./CheckGuardrailsResponse";
export * from "./EntityType";
export * from "./ErrorString";
export * from "./ErrorResponseError";
export * from "./ErrorResponse";
export * from "./ReidentifyFileResponseStatus";
export * from "./ReidentifyFileResponseOutputType";
export * from "./ReidentifyFileResponseOutput";
export * from "./ReidentifyFileResponse";
export * from "./DeidentifyStatusResponseStatus";
Expand Down
16 changes: 8 additions & 8 deletions src/vault/controller/detect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class DetectController {
}, waitTime * 1000);
}
} else if (response.status?.toUpperCase() === 'SUCCESS') {
resolve(response); // Resolve with the processed file response
resolve([response, runId]); // Resolve with the processed file response and runId
}
else if (response.status?.toUpperCase() === 'FAILED') {
reject(new SkyflowError(SKYFLOW_ERROR_CODE.INTERNAL_SERVER_ERROR, [response.message]));
Expand Down Expand Up @@ -475,7 +475,7 @@ class DetectController {
return new DeidentifyFileResponse({
fileBase64: base64String,
file: file,
type: data.output?.[0]?.processedFileType ?? '',
type: data.output?.[0]?.processedFileType ?? data.outputType ?? "",
extension: extension,
wordCount: data.wordCharacterCount?.wordCount ?? 0,
charCount: data.wordCharacterCount?.characterCount ?? 0,
Expand Down Expand Up @@ -606,7 +606,7 @@ class DetectController {
this.waitTime = options?.getWaitTime() ?? this.waitTime;

var reqType : DeidenitfyFileRequestTypes = this.getReqType(fileExtension);
var promiseReq: Promise<DeidentifyFileDetectRunResponse>;
var promiseReq: Promise<[DeidentifyFileDetectRunResponse, string]>;
switch (reqType){
case DeidenitfyFileRequestTypes.AUDIO:
promiseReq = this.buildAudioRequest(fileObj, options, fileExtension)
Expand Down Expand Up @@ -709,17 +709,17 @@ class DetectController {
break;
}

promiseReq.then(data => {
if(data.runId){
promiseReq.then(([data, runId]) => {
if(runId && data.status === "IN_PROGRESS") {
resolve(new DeidentifyFileResponse({
runId: data.runId,
status: 'IN_PROGRESS',
runId: runId,
status: data.status,
}));
}
if (options?.getOutputDirectory() && data.status === "SUCCESS") {
this.processDeidentifyFileResponse(data, options.getOutputDirectory() as string, fileBaseName);
}
const deidentifiedFileResponse = this.parseDeidentifyFileResponse(data, undefined, data.status);
const deidentifiedFileResponse = this.parseDeidentifyFileResponse(data, runId, data.status);
resolve(deidentifiedFileResponse);
}).catch(error => {
reject(error)
Expand Down
Loading