Skip to content

Commit 438161b

Browse files
File stash downloads and stricter prop values (#173)
* Add new API to download files from a file stash * Specify the possible prop values (instead of `unknown`) --------- Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Co-authored-by: Jay Vercellone <jay@pipedream.com>
1 parent fe894b0 commit 438161b

File tree

15 files changed

+223
-33
lines changed

15 files changed

+223
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/sdk",
3-
"version": "2.0.5",
3+
"version": "2.0.6",
44
"private": false,
55
"repository": "github:PipedreamHQ/pipedream-sdk-typescript",
66
"type": "commonjs",
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
import * as environments from "../../../../environments.js";
6+
import * as core from "../../../../core/index.js";
7+
import * as Pipedream from "../../../index.js";
8+
import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.js";
9+
import * as errors from "../../../../errors/index.js";
10+
11+
export declare namespace FileStash {
12+
export interface Options {
13+
environment?: core.Supplier<environments.PipedreamEnvironment | string>;
14+
/** Specify a custom URL to connect the client to. */
15+
baseUrl?: core.Supplier<string>;
16+
projectId: string;
17+
token?: core.Supplier<core.BearerToken | undefined>;
18+
/** Override the x-pd-environment header */
19+
projectEnvironment?: core.Supplier<Pipedream.ProjectEnvironment | undefined>;
20+
/** Additional headers to include in requests. */
21+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
22+
}
23+
24+
export interface RequestOptions {
25+
/** The maximum time to wait for a response in seconds. */
26+
timeoutInSeconds?: number;
27+
/** The number of times to retry the request. Defaults to 2. */
28+
maxRetries?: number;
29+
/** A hook to abort the request. */
30+
abortSignal?: AbortSignal;
31+
/** Override the x-pd-environment header */
32+
projectEnvironment?: Pipedream.ProjectEnvironment | undefined;
33+
/** Additional query string parameters to include in the request. */
34+
queryParams?: Record<string, unknown>;
35+
/** Additional headers to include in the request. */
36+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
37+
}
38+
}
39+
40+
export class FileStash {
41+
protected readonly _options: FileStash.Options;
42+
43+
constructor(_options: FileStash.Options) {
44+
this._options = _options;
45+
}
46+
47+
/**
48+
* Download a file from File Stash
49+
*
50+
* @param {Pipedream.FileStashDownloadFileRequest} request
51+
* @param {FileStash.RequestOptions} requestOptions - Request-specific configuration.
52+
*
53+
* @throws {@link Pipedream.TooManyRequestsError}
54+
*
55+
* @example
56+
* await client.fileStash.downloadFile({
57+
* s3Key: "s3_key"
58+
* })
59+
*/
60+
public downloadFile(
61+
request: Pipedream.FileStashDownloadFileRequest,
62+
requestOptions?: FileStash.RequestOptions,
63+
): core.HttpResponsePromise<void> {
64+
return core.HttpResponsePromise.fromPromise(this.__downloadFile(request, requestOptions));
65+
}
66+
67+
private async __downloadFile(
68+
request: Pipedream.FileStashDownloadFileRequest,
69+
requestOptions?: FileStash.RequestOptions,
70+
): Promise<core.WithRawResponse<void>> {
71+
const { s3Key } = request;
72+
const _queryParams: Record<string, string | string[] | object | object[] | null> = {};
73+
_queryParams["s3_key"] = s3Key;
74+
let _headers: core.Fetcher.Args["headers"] = mergeHeaders(
75+
this._options?.headers,
76+
mergeOnlyDefinedHeaders({
77+
Authorization: await this._getAuthorizationHeader(),
78+
"x-pd-environment": requestOptions?.projectEnvironment ?? this._options?.projectEnvironment,
79+
}),
80+
requestOptions?.headers,
81+
);
82+
const _response = await core.fetcher({
83+
url: core.url.join(
84+
(await core.Supplier.get(this._options.baseUrl)) ??
85+
(await core.Supplier.get(this._options.environment)) ??
86+
environments.PipedreamEnvironment.Prod,
87+
`v1/connect/${encodeURIComponent(this._options.projectId)}/file_stash/download`,
88+
),
89+
method: "GET",
90+
headers: _headers,
91+
queryParameters: { ..._queryParams, ...requestOptions?.queryParams },
92+
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
93+
maxRetries: requestOptions?.maxRetries,
94+
abortSignal: requestOptions?.abortSignal,
95+
});
96+
if (_response.ok) {
97+
return { data: undefined, rawResponse: _response.rawResponse };
98+
}
99+
100+
if (_response.error.reason === "status-code") {
101+
switch (_response.error.statusCode) {
102+
case 429:
103+
throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse);
104+
default:
105+
throw new errors.PipedreamError({
106+
statusCode: _response.error.statusCode,
107+
body: _response.error.body,
108+
rawResponse: _response.rawResponse,
109+
});
110+
}
111+
}
112+
113+
switch (_response.error.reason) {
114+
case "non-json":
115+
throw new errors.PipedreamError({
116+
statusCode: _response.error.statusCode,
117+
body: _response.error.rawBody,
118+
rawResponse: _response.rawResponse,
119+
});
120+
case "timeout":
121+
throw new errors.PipedreamTimeoutError(
122+
"Timeout exceeded when calling GET /v1/connect/{project_id}/file_stash/download.",
123+
);
124+
case "unknown":
125+
throw new errors.PipedreamError({
126+
message: _response.error.errorMessage,
127+
rawResponse: _response.rawResponse,
128+
});
129+
}
130+
}
131+
132+
protected async _getAuthorizationHeader(): Promise<string | undefined> {
133+
const bearer = await core.Supplier.get(this._options.token);
134+
if (bearer != null) {
135+
return `Bearer ${bearer}`;
136+
}
137+
138+
return undefined;
139+
}
140+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export {};
2+
export * from "./requests/index.js";
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
/**
6+
* @example
7+
* {
8+
* s3Key: "s3_key"
9+
* }
10+
*/
11+
export interface FileStashDownloadFileRequest {
12+
s3Key: string;
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { type FileStashDownloadFileRequest } from "./FileStashDownloadFileRequest.js";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./client/index.js";

src/api/resources/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export * as components from "./components/index.js";
77
export * as actions from "./actions/index.js";
88
export * as triggers from "./triggers/index.js";
99
export * as deployedTriggers from "./deployedTriggers/index.js";
10+
export * as fileStash from "./fileStash/index.js";
1011
export * as projects from "./projects/index.js";
1112
export * as proxy from "./proxy/index.js";
1213
export * as tokens from "./tokens/index.js";
@@ -18,6 +19,7 @@ export * from "./components/client/requests/index.js";
1819
export * from "./actions/client/requests/index.js";
1920
export * from "./triggers/client/requests/index.js";
2021
export * from "./deployedTriggers/client/requests/index.js";
22+
export * from "./fileStash/client/requests/index.js";
2123
export * from "./proxy/client/requests/index.js";
2224
export * from "./tokens/client/requests/index.js";
2325
export * from "./oauthTokens/client/requests/index.js";

src/api/types/PropOption.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
* This file was auto-generated by Fern from our API Definition.
33
*/
44

5+
import * as Pipedream from "../index.js";
6+
57
/**
68
* A configuration option for a component's prop
79
*/
810
export interface PropOption {
911
/** The human-readable label for the option */
1012
label: string;
11-
value?: unknown;
13+
value?: Pipedream.PropOptionValue;
1214
}

src/api/types/PropOptionValue.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
/**
6+
* The value of a prop option
7+
*/
8+
export type PropOptionValue = string | number | boolean;

src/api/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export * from "./ProjectEnvironment.js";
8181
export * from "./ProjectInfoResponse.js";
8282
export * from "./ProjectInfoResponseApp.js";
8383
export * from "./PropOption.js";
84+
export * from "./PropOptionValue.js";
8485
export * from "./PropOptionNested.js";
8586
export * from "./ProxyResponse.js";
8687
export * from "./ReloadPropsOpts.js";

0 commit comments

Comments
 (0)