Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
1 change: 0 additions & 1 deletion .github/workflows/common-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: '20.x'
registry-url: "https://registry.npmjs.org"

- name: Install Packages
run: npm install
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "skyflow-node",
"version": "2.2.1-beta.1",
"version": "2.2.1-beta.1-dev.4b3b288",
"description": "Skyflow SDK for Node.js",
"main": "./lib/index.js",
"module": "./lib/index.js",
Expand Down
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
1 change: 1 addition & 0 deletions src/error/codes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ const SKYFLOW_ERROR_CODE = {
INVALID_ALLOW_REGEX_LIST: { http_code: 400, message: errorMessages.INVALID_ALLOW_REGEX_LIST },
INVALID_RESTRICT_REGEX_LIST: { http_code: 400, message: errorMessages.INVALID_RESTRICT_REGEX_LIST },
INVALID_TOKEN_FORMAT: { http_code: 400, message: errorMessages.INVALID_TOKEN_FORMAT },
TOKEN_FORMAT_NOT_ALLOWED: { http_code: 400, message: errorMessages.VAULT_TOKEN_FORMAT_NOT_ALLOWED_FOR_DEIDENTIFY_FILES},
INVALID_TRANSFORMATIONS: { http_code: 400, message: errorMessages.INVALID_TRANSFORMATIONS },

INVALID_TEXT_IN_REIDENTIFY: { http_code: 400, message: errorMessages.INVALID_TEXT_IN_REIDENTIFY },
Expand Down
1 change: 1 addition & 0 deletions src/error/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const errorMessages = {
INVALID_RESTRICT_REGEX_LIST: `${errorPrefix} Validation error. The restrictRegexList field must be an array of strings. Specify a valid restrictRegexList.`,
INVALID_TOKEN_FORMAT: `${errorPrefix} Validation error. The tokenFormat key must be an instance of TokenFormat. Specify a valid token format.`,
INVALID_TRANSFORMATIONS: `${errorPrefix} Validation error. The transformations key must be an instance of Transformations. Specify a valid transformations.`,
VAULT_TOKEN_FORMAT_NOT_ALLOWED_FOR_DEIDENTIFY_FILES: `${errorPrefix} Validation error. Vault token format is not allowed for deidentify file request.`,

INVALID_TEXT_IN_REIDENTIFY: `${errorPrefix} Validation error. The text field is required and must be a non-empty string. Specify a valid text.`,
INVALID_REDACTED_ENTITIES_IN_REIDENTIFY: `${errorPrefix} Validation error. The redactedEntities field must be an array of DetectEntities enums. Specify a valid redactedEntities.`,
Expand Down
Loading