@credal/sdk 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/cjs/Client.js +2 -2
  2. package/dist/cjs/api/resources/documentCatalog/client/Client.d.ts +8 -0
  3. package/dist/cjs/api/resources/documentCatalog/client/Client.js +84 -0
  4. package/dist/cjs/api/resources/documentCatalog/client/requests/UploadFileRequest.d.ts +27 -0
  5. package/dist/cjs/api/resources/documentCatalog/client/requests/UploadFileRequest.js +3 -0
  6. package/dist/cjs/api/resources/documentCatalog/client/requests/index.d.ts +1 -0
  7. package/dist/cjs/core/exports.d.ts +1 -0
  8. package/dist/cjs/core/exports.js +17 -0
  9. package/dist/cjs/core/file/exports.d.ts +1 -0
  10. package/dist/cjs/core/file/exports.js +2 -0
  11. package/dist/cjs/core/file/file.d.ts +10 -0
  12. package/dist/cjs/core/file/file.js +221 -0
  13. package/dist/cjs/core/file/index.d.ts +2 -0
  14. package/dist/cjs/core/file/index.js +18 -0
  15. package/dist/cjs/core/file/types.d.ts +66 -0
  16. package/dist/cjs/core/file/types.js +2 -0
  17. package/dist/cjs/core/form-data-utils/FormDataWrapper.d.ts +15 -0
  18. package/dist/cjs/core/form-data-utils/FormDataWrapper.js +185 -0
  19. package/dist/cjs/core/form-data-utils/encodeAsFormParameter.d.ts +1 -0
  20. package/dist/cjs/core/form-data-utils/encodeAsFormParameter.js +12 -0
  21. package/dist/cjs/core/form-data-utils/index.d.ts +2 -0
  22. package/dist/cjs/core/form-data-utils/index.js +20 -0
  23. package/dist/cjs/core/index.d.ts +2 -0
  24. package/dist/cjs/core/index.js +3 -1
  25. package/dist/cjs/exports.d.ts +1 -0
  26. package/dist/cjs/exports.js +17 -0
  27. package/dist/cjs/index.d.ts +1 -0
  28. package/dist/cjs/index.js +4 -0
  29. package/dist/cjs/version.d.ts +1 -1
  30. package/dist/cjs/version.js +1 -1
  31. package/dist/esm/Client.mjs +2 -2
  32. package/dist/esm/api/resources/documentCatalog/client/Client.d.mts +8 -0
  33. package/dist/esm/api/resources/documentCatalog/client/Client.mjs +84 -0
  34. package/dist/esm/api/resources/documentCatalog/client/requests/UploadFileRequest.d.mts +27 -0
  35. package/dist/esm/api/resources/documentCatalog/client/requests/UploadFileRequest.mjs +2 -0
  36. package/dist/esm/api/resources/documentCatalog/client/requests/index.d.mts +1 -0
  37. package/dist/esm/core/exports.d.mts +1 -0
  38. package/dist/esm/core/exports.mjs +1 -0
  39. package/dist/esm/core/file/exports.d.mts +1 -0
  40. package/dist/esm/core/file/exports.mjs +1 -0
  41. package/dist/esm/core/file/file.d.mts +10 -0
  42. package/dist/esm/core/file/file.mjs +184 -0
  43. package/dist/esm/core/file/index.d.mts +2 -0
  44. package/dist/esm/core/file/index.mjs +2 -0
  45. package/dist/esm/core/file/types.d.mts +66 -0
  46. package/dist/esm/core/file/types.mjs +1 -0
  47. package/dist/esm/core/form-data-utils/FormDataWrapper.d.mts +15 -0
  48. package/dist/esm/core/form-data-utils/FormDataWrapper.mjs +147 -0
  49. package/dist/esm/core/form-data-utils/encodeAsFormParameter.d.mts +1 -0
  50. package/dist/esm/core/form-data-utils/encodeAsFormParameter.mjs +9 -0
  51. package/dist/esm/core/form-data-utils/index.d.mts +2 -0
  52. package/dist/esm/core/form-data-utils/index.mjs +2 -0
  53. package/dist/esm/core/index.d.mts +2 -0
  54. package/dist/esm/core/index.mjs +2 -0
  55. package/dist/esm/exports.d.mts +1 -0
  56. package/dist/esm/exports.mjs +1 -0
  57. package/dist/esm/index.d.mts +1 -0
  58. package/dist/esm/index.mjs +1 -0
  59. package/dist/esm/version.d.mts +1 -1
  60. package/dist/esm/version.mjs +1 -1
  61. package/package.json +1 -1
@@ -47,8 +47,8 @@ class CredalClient {
47
47
  this._options = Object.assign(Object.assign({}, _options), { headers: (0, headers_js_1.mergeHeaders)({
48
48
  "X-Fern-Language": "JavaScript",
49
49
  "X-Fern-SDK-Name": "@credal/sdk",
50
- "X-Fern-SDK-Version": "0.1.9",
51
- "User-Agent": "@credal/sdk/0.1.9",
50
+ "X-Fern-SDK-Version": "0.1.10",
51
+ "User-Agent": "@credal/sdk/0.1.10",
52
52
  "X-Fern-Runtime": core.RUNTIME.type,
53
53
  "X-Fern-Runtime-Version": core.RUNTIME.version,
54
54
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -25,6 +25,14 @@ export declare class DocumentCatalog {
25
25
  */
26
26
  uploadDocumentContents(request: Credal.UploadDocumentContentsRequest, requestOptions?: DocumentCatalog.RequestOptions): core.HttpResponsePromise<Credal.UploadDocumentResponse>;
27
27
  private __uploadDocumentContents;
28
+ /**
29
+ * Upload a file (PDF, Word, Excel, CSV, PowerPoint) to Credal. Unlike uploadDocumentContents which requires pre-parsed text, this endpoint accepts actual file uploads and automatically parses them using Credal's parsing service.
30
+ *
31
+ * @param {Credal.UploadFileRequest} request
32
+ * @param {DocumentCatalog.RequestOptions} requestOptions - Request-specific configuration.
33
+ */
34
+ uploadFile(request: Credal.UploadFileRequest, requestOptions?: DocumentCatalog.RequestOptions): core.HttpResponsePromise<Credal.UploadDocumentResponse>;
35
+ private __uploadFile;
28
36
  /**
29
37
  * Sync a document from a source URL. Does not support recursive web search. Reach out to a Credal representative for access.
30
38
  *
@@ -111,6 +111,90 @@ class DocumentCatalog {
111
111
  }
112
112
  });
113
113
  }
114
+ /**
115
+ * Upload a file (PDF, Word, Excel, CSV, PowerPoint) to Credal. Unlike uploadDocumentContents which requires pre-parsed text, this endpoint accepts actual file uploads and automatically parses them using Credal's parsing service.
116
+ *
117
+ * @param {Credal.UploadFileRequest} request
118
+ * @param {DocumentCatalog.RequestOptions} requestOptions - Request-specific configuration.
119
+ */
120
+ uploadFile(request, requestOptions) {
121
+ return core.HttpResponsePromise.fromPromise(this.__uploadFile(request, requestOptions));
122
+ }
123
+ __uploadFile(request, requestOptions) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
126
+ const _request = yield core.newFormData();
127
+ yield _request.appendFile("file", request.file);
128
+ if (request.documentName != null) {
129
+ _request.append("documentName", request.documentName);
130
+ }
131
+ _request.append("uploadAsUserEmail", request.uploadAsUserEmail);
132
+ _request.append("documentExternalId", request.documentExternalId);
133
+ if (request.allowedUsersEmailAddresses != null) {
134
+ _request.append("allowedUsersEmailAddresses", request.allowedUsersEmailAddresses);
135
+ }
136
+ if (request.documentExternalUrl != null) {
137
+ _request.append("documentExternalUrl", request.documentExternalUrl);
138
+ }
139
+ if (request.customMetadata != null) {
140
+ _request.append("customMetadata", request.customMetadata);
141
+ }
142
+ if (request.collectionId != null) {
143
+ _request.append("collectionId", request.collectionId);
144
+ }
145
+ if (request.forceUpdate != null) {
146
+ _request.append("forceUpdate", request.forceUpdate);
147
+ }
148
+ if (request.internalPublic != null) {
149
+ _request.append("internalPublic", request.internalPublic);
150
+ }
151
+ if (request.sourceSystemUpdated != null) {
152
+ _request.append("sourceSystemUpdated", request.sourceSystemUpdated);
153
+ }
154
+ if (request.awaitVectorStoreSync != null) {
155
+ _request.append("awaitVectorStoreSync", request.awaitVectorStoreSync);
156
+ }
157
+ const _maybeEncodedRequest = yield _request.getRequest();
158
+ const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)(Object.assign({ Authorization: yield this._getAuthorizationHeader() }, _maybeEncodedRequest.headers)), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
159
+ const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
160
+ url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/catalog/uploadFile"),
161
+ method: "POST",
162
+ headers: _headers,
163
+ queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
164
+ requestType: "file",
165
+ duplex: _maybeEncodedRequest.duplex,
166
+ body: _maybeEncodedRequest.body,
167
+ timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
168
+ maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
169
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
170
+ });
171
+ if (_response.ok) {
172
+ return { data: _response.body, rawResponse: _response.rawResponse };
173
+ }
174
+ if (_response.error.reason === "status-code") {
175
+ throw new errors.CredalError({
176
+ statusCode: _response.error.statusCode,
177
+ body: _response.error.body,
178
+ rawResponse: _response.rawResponse,
179
+ });
180
+ }
181
+ switch (_response.error.reason) {
182
+ case "non-json":
183
+ throw new errors.CredalError({
184
+ statusCode: _response.error.statusCode,
185
+ body: _response.error.rawBody,
186
+ rawResponse: _response.rawResponse,
187
+ });
188
+ case "timeout":
189
+ throw new errors.CredalTimeoutError("Timeout exceeded when calling POST /v0/catalog/uploadFile.");
190
+ case "unknown":
191
+ throw new errors.CredalError({
192
+ message: _response.error.errorMessage,
193
+ rawResponse: _response.rawResponse,
194
+ });
195
+ }
196
+ });
197
+ }
114
198
  /**
115
199
  * Sync a document from a source URL. Does not support recursive web search. Reach out to a Credal representative for access.
116
200
  *
@@ -0,0 +1,27 @@
1
+ import type * as core from "../../../../../core/index.js";
2
+ export interface UploadFileRequest {
3
+ /** The file to upload. Supported formats: PDF (.pdf), Word (.docx), Excel (.xlsx, .xls), PowerPoint (.pptx, .ppt), CSV (.csv), and text files. */
4
+ file: core.file.Uploadable;
5
+ /** The name of the document you want to upload. If not provided, the original filename will be used. */
6
+ documentName?: string;
7
+ /** [Legacy] The user on behalf of whom the document should be uploaded. In most cases, this can simply be the email of the developer making the API call. This field will be removed in the future in favor of purely specifying permissions via allowedUsersEmailAddresses. */
8
+ uploadAsUserEmail: string;
9
+ /** The external ID of the document. This is typically the ID as it exists in its original external system. Uploads to the same external ID will update the document in Credal. */
10
+ documentExternalId: string;
11
+ /** Users allowed to access the document. Can be provided as a JSON array string (e.g., ["user1@example.com","user2@example.com"]) or comma-separated list (e.g., "user1@example.com,user2@example.com"). Unlike Credal's out of the box connectors which reconcile various permissions models from 3rd party software, for custom uploads the caller is responsible for specifying who can access the document and currently flattening groups if applicable. Documents can also be marked as internal public. */
12
+ allowedUsersEmailAddresses?: string;
13
+ /** The external URL of the document you want to upload. If provided Credal will link to this URL. */
14
+ documentExternalUrl?: string;
15
+ /** Optional JSON string representing any custom metadata for this document (e.g., '{"key1":"value1","key2":"value2"}'). */
16
+ customMetadata?: string;
17
+ /** If specified, the document will also be added to the provided document collection. This operation is eventually consistent, meaning the document does not immediately start appearing in searches of that collection due to an asynchronous embedding process. To achieve strong consistency use the `awaitVectorStoreSync` parameter. */
18
+ collectionId?: string;
19
+ /** If set to "true", document contents will be re-uploaded and re-embedded even if the document already exists in Credal. */
20
+ forceUpdate?: string;
21
+ /** If set to "true", document will be accessible to everyone within the organization of the uploader. */
22
+ internalPublic?: string;
23
+ /** ISO 8601 date string indicating when the document was last updated in the source system (e.g., "2025-11-03T21:15:00Z"). */
24
+ sourceSystemUpdated?: string;
25
+ /** Document uploads are eventually consistent by default. If set to "true" the API will wait for the vector store to be updated before returning. This is useful if you want to ensure that the document is immediately searchable after this call returns. */
26
+ awaitVectorStoreSync?: string;
27
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // This file was auto-generated by Fern from our API Definition.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
1
  export type { UploadDocumentContentsRequest } from "./UploadDocumentContentsRequest.js";
2
+ export type { UploadFileRequest } from "./UploadFileRequest.js";
@@ -0,0 +1 @@
1
+ export * from "./file/exports.js";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./file/exports.js"), exports);
@@ -0,0 +1 @@
1
+ export type { Uploadable } from "./types.js";
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import type { Uploadable } from "./types.js";
2
+ export declare function toBinaryUploadRequest(file: Uploadable): Promise<{
3
+ body: Uploadable.FileLike;
4
+ headers?: Record<string, string>;
5
+ }>;
6
+ export declare function toMultipartDataPart(file: Uploadable): Promise<{
7
+ data: Uploadable.FileLike;
8
+ filename?: string;
9
+ contentType?: string;
10
+ }>;
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.toBinaryUploadRequest = toBinaryUploadRequest;
46
+ exports.toMultipartDataPart = toMultipartDataPart;
47
+ function toBinaryUploadRequest(file) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const { data, filename, contentLength, contentType } = yield getFileWithMetadata(file);
50
+ const request = {
51
+ body: data,
52
+ headers: {},
53
+ };
54
+ if (filename) {
55
+ request.headers["Content-Disposition"] = `attachment; filename="${filename}"`;
56
+ }
57
+ if (contentType) {
58
+ request.headers["Content-Type"] = contentType;
59
+ }
60
+ if (contentLength != null) {
61
+ request.headers["Content-Length"] = contentLength.toString();
62
+ }
63
+ return request;
64
+ });
65
+ }
66
+ function toMultipartDataPart(file) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ const { data, filename, contentType } = yield getFileWithMetadata(file, {
69
+ noSniffFileSize: true,
70
+ });
71
+ return {
72
+ data,
73
+ filename,
74
+ contentType,
75
+ };
76
+ });
77
+ }
78
+ function getFileWithMetadata(file_1) {
79
+ return __awaiter(this, arguments, void 0, function* (file, { noSniffFileSize } = {}) {
80
+ var _a, _b, _c, _d, _e;
81
+ if (isFileLike(file)) {
82
+ return getFileWithMetadata({
83
+ data: file,
84
+ }, { noSniffFileSize });
85
+ }
86
+ if ("path" in file) {
87
+ const fs = yield Promise.resolve().then(() => __importStar(require("fs")));
88
+ if (!fs || !fs.createReadStream) {
89
+ throw new Error("File path uploads are not supported in this environment.");
90
+ }
91
+ const data = fs.createReadStream(file.path);
92
+ const contentLength = (_a = file.contentLength) !== null && _a !== void 0 ? _a : (noSniffFileSize === true ? undefined : yield tryGetFileSizeFromPath(file.path));
93
+ const filename = (_b = file.filename) !== null && _b !== void 0 ? _b : getNameFromPath(file.path);
94
+ return {
95
+ data,
96
+ filename,
97
+ contentType: file.contentType,
98
+ contentLength,
99
+ };
100
+ }
101
+ if ("data" in file) {
102
+ const data = file.data;
103
+ const contentLength = (_c = file.contentLength) !== null && _c !== void 0 ? _c : (yield tryGetContentLengthFromFileLike(data, {
104
+ noSniffFileSize,
105
+ }));
106
+ const filename = (_d = file.filename) !== null && _d !== void 0 ? _d : tryGetNameFromFileLike(data);
107
+ return {
108
+ data,
109
+ filename,
110
+ contentType: (_e = file.contentType) !== null && _e !== void 0 ? _e : tryGetContentTypeFromFileLike(data),
111
+ contentLength,
112
+ };
113
+ }
114
+ throw new Error(`Invalid FileUpload of type ${typeof file}: ${JSON.stringify(file)}`);
115
+ });
116
+ }
117
+ function isFileLike(value) {
118
+ return (isBuffer(value) ||
119
+ isArrayBufferView(value) ||
120
+ isArrayBuffer(value) ||
121
+ isUint8Array(value) ||
122
+ isBlob(value) ||
123
+ isFile(value) ||
124
+ isStreamLike(value) ||
125
+ isReadableStream(value));
126
+ }
127
+ function tryGetFileSizeFromPath(path) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ try {
130
+ const fs = yield Promise.resolve().then(() => __importStar(require("fs")));
131
+ if (!fs || !fs.promises || !fs.promises.stat) {
132
+ return undefined;
133
+ }
134
+ const fileStat = yield fs.promises.stat(path);
135
+ return fileStat.size;
136
+ }
137
+ catch (_fallbackError) {
138
+ return undefined;
139
+ }
140
+ });
141
+ }
142
+ function tryGetNameFromFileLike(data) {
143
+ if (isNamedValue(data)) {
144
+ return data.name;
145
+ }
146
+ if (isPathedValue(data)) {
147
+ return getNameFromPath(data.path.toString());
148
+ }
149
+ return undefined;
150
+ }
151
+ function tryGetContentLengthFromFileLike(data_1) {
152
+ return __awaiter(this, arguments, void 0, function* (data, { noSniffFileSize } = {}) {
153
+ if (isBuffer(data)) {
154
+ return data.length;
155
+ }
156
+ if (isArrayBufferView(data)) {
157
+ return data.byteLength;
158
+ }
159
+ if (isArrayBuffer(data)) {
160
+ return data.byteLength;
161
+ }
162
+ if (isBlob(data)) {
163
+ return data.size;
164
+ }
165
+ if (isFile(data)) {
166
+ return data.size;
167
+ }
168
+ if (noSniffFileSize === true) {
169
+ return undefined;
170
+ }
171
+ if (isPathedValue(data)) {
172
+ return yield tryGetFileSizeFromPath(data.path.toString());
173
+ }
174
+ return undefined;
175
+ });
176
+ }
177
+ function tryGetContentTypeFromFileLike(data) {
178
+ if (isBlob(data)) {
179
+ return data.type;
180
+ }
181
+ if (isFile(data)) {
182
+ return data.type;
183
+ }
184
+ return undefined;
185
+ }
186
+ function getNameFromPath(path) {
187
+ const lastForwardSlash = path.lastIndexOf("/");
188
+ const lastBackSlash = path.lastIndexOf("\\");
189
+ const lastSlashIndex = Math.max(lastForwardSlash, lastBackSlash);
190
+ return lastSlashIndex >= 0 ? path.substring(lastSlashIndex + 1) : path;
191
+ }
192
+ function isNamedValue(value) {
193
+ return typeof value === "object" && value != null && "name" in value;
194
+ }
195
+ function isPathedValue(value) {
196
+ return typeof value === "object" && value != null && "path" in value;
197
+ }
198
+ function isStreamLike(value) {
199
+ return typeof value === "object" && value != null && ("read" in value || "pipe" in value);
200
+ }
201
+ function isReadableStream(value) {
202
+ return typeof value === "object" && value != null && "getReader" in value;
203
+ }
204
+ function isBuffer(value) {
205
+ return typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(value);
206
+ }
207
+ function isArrayBufferView(value) {
208
+ return typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(value);
209
+ }
210
+ function isArrayBuffer(value) {
211
+ return typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer;
212
+ }
213
+ function isUint8Array(value) {
214
+ return typeof Uint8Array !== "undefined" && value instanceof Uint8Array;
215
+ }
216
+ function isBlob(value) {
217
+ return typeof Blob !== "undefined" && value instanceof Blob;
218
+ }
219
+ function isFile(value) {
220
+ return typeof File !== "undefined" && value instanceof File;
221
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./file.js";
2
+ export * from "./types.js";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./file.js"), exports);
18
+ __exportStar(require("./types.js"), exports);
@@ -0,0 +1,66 @@
1
+ /**
2
+ * A file that can be uploaded. Can be a file-like object (stream, buffer, blob, etc.),
3
+ * a path to a file, or an object with a file-like object and metadata.
4
+ */
5
+ export type Uploadable = Uploadable.FileLike | Uploadable.FromPath | Uploadable.WithMetadata;
6
+ export declare namespace Uploadable {
7
+ /**
8
+ * Various file-like objects that can be used to upload a file.
9
+ */
10
+ type FileLike = ArrayBuffer | ArrayBufferLike | ArrayBufferView | Uint8Array | import("buffer").Buffer | import("buffer").Blob | import("buffer").File | import("stream").Readable | import("stream/web").ReadableStream | globalThis.Blob | globalThis.File | ReadableStream;
11
+ /**
12
+ * A file path with optional metadata, used for uploading a file from the file system.
13
+ */
14
+ type FromPath = {
15
+ /** The path to the file to upload */
16
+ path: string;
17
+ /**
18
+ * Optional override for the file name (defaults to basename of path).
19
+ * This is used to set the `Content-Disposition` header in upload requests.
20
+ */
21
+ filename?: string;
22
+ /**
23
+ * Optional MIME type of the file (e.g., 'image/jpeg', 'text/plain').
24
+ * This is used to set the `Content-Type` header in upload requests.
25
+ */
26
+ contentType?: string;
27
+ /**
28
+ * Optional file size in bytes.
29
+ * If not provided, the file size will be determined from the file system.
30
+ * The content length is used to set the `Content-Length` header in upload requests.
31
+ */
32
+ contentLength?: number;
33
+ };
34
+ /**
35
+ * A file-like object with metadata, used for uploading files.
36
+ */
37
+ type WithMetadata = {
38
+ /** The file data */
39
+ data: FileLike;
40
+ /**
41
+ * Optional override for the file name (defaults to basename of path).
42
+ * This is used to set the `Content-Disposition` header in upload requests.
43
+ */
44
+ filename?: string;
45
+ /**
46
+ * Optional MIME type of the file (e.g., 'image/jpeg', 'text/plain').
47
+ * This is used to set the `Content-Type` header in upload requests.
48
+ *
49
+ * If not provided, the content type may be determined from the data itself.
50
+ * * If the data is a `File`, `Blob`, or similar, the content type will be determined from the file itself, if the type is set.
51
+ * * Any other data type will not have a content type set, and the upload request will use `Content-Type: application/octet-stream` instead.
52
+ */
53
+ contentType?: string;
54
+ /**
55
+ * Optional file size in bytes.
56
+ * The content length is used to set the `Content-Length` header in upload requests.
57
+ * If the content length is not provided and cannot be determined, the upload request will not include the `Content-Length` header, but will use `Transfer-Encoding: chunked` instead.
58
+ *
59
+ * If not provided, the file size will be determined depending on the data type.
60
+ * * If the data is of type `fs.ReadStream` (`createReadStream`), the size will be determined from the file system.
61
+ * * If the data is a `Buffer`, `ArrayBuffer`, `Uint8Array`, `Blob`, `File`, or similar, the size will be determined from the data itself.
62
+ * * If the data is a `Readable` or `ReadableStream`, the size will not be determined.
63
+ */
64
+ contentLength?: number;
65
+ };
66
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ import { type Uploadable } from "../../core/file/index.js";
2
+ interface FormDataRequest<Body> {
3
+ body: Body;
4
+ headers: Record<string, string>;
5
+ duplex?: "half";
6
+ }
7
+ export declare function newFormData(): Promise<FormDataWrapper>;
8
+ export declare class FormDataWrapper {
9
+ private fd;
10
+ setup(): Promise<void>;
11
+ append(key: string, value: unknown): void;
12
+ appendFile(key: string, value: Uploadable): Promise<void>;
13
+ getRequest(): FormDataRequest<FormData>;
14
+ }
15
+ export {};