pulse-ts-sdk 0.0.53 → 0.0.55
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.
- package/README.md +44 -3
- package/dist/cjs/BaseClient.js +2 -2
- package/dist/cjs/Client.d.ts +8 -10
- package/dist/cjs/Client.js +113 -16
- package/dist/cjs/api/client/index.d.ts +1 -0
- package/dist/cjs/api/client/index.js +17 -0
- package/dist/{esm/api/types/ExtractJsonInput.d.mts → cjs/api/client/requests/ExtractAsyncRequest.d.ts} +13 -9
- package/dist/cjs/api/{types/ExtractMultipartInput.d.ts → client/requests/ExtractRequest.d.ts} +10 -8
- package/dist/cjs/api/client/requests/index.d.ts +2 -0
- package/dist/cjs/api/{types/JsonSource.js → client/requests/index.js} +0 -1
- package/dist/cjs/api/index.d.ts +1 -0
- package/dist/cjs/api/index.js +1 -0
- package/dist/cjs/api/types/ExtractInput.d.ts +63 -1
- package/dist/cjs/api/types/{MultipartSource.d.ts → ExtractSource.d.ts} +1 -1
- package/dist/cjs/api/types/index.d.ts +1 -5
- package/dist/cjs/api/types/index.js +1 -5
- package/dist/cjs/core/exports.d.ts +1 -0
- package/dist/cjs/core/exports.js +1 -0
- package/dist/cjs/core/file/exports.d.ts +1 -0
- package/dist/cjs/core/file/exports.js +2 -0
- package/dist/cjs/core/file/file.d.ts +10 -0
- package/dist/cjs/core/file/file.js +221 -0
- package/dist/cjs/core/file/index.d.ts +2 -0
- package/dist/cjs/core/file/index.js +18 -0
- package/dist/cjs/core/file/types.d.ts +66 -0
- package/dist/cjs/core/file/types.js +2 -0
- package/dist/cjs/core/form-data-utils/FormDataWrapper.d.ts +15 -0
- package/dist/cjs/core/form-data-utils/FormDataWrapper.js +185 -0
- package/dist/cjs/core/form-data-utils/encodeAsFormParameter.d.ts +1 -0
- package/dist/cjs/core/form-data-utils/encodeAsFormParameter.js +12 -0
- package/dist/cjs/core/form-data-utils/index.d.ts +2 -0
- package/dist/cjs/core/form-data-utils/index.js +20 -0
- package/dist/cjs/core/index.d.ts +2 -0
- package/dist/cjs/core/index.js +3 -1
- package/dist/cjs/environments.d.ts +1 -1
- package/dist/cjs/environments.js +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.mjs +2 -2
- package/dist/esm/Client.d.mts +8 -10
- package/dist/esm/Client.mjs +114 -17
- package/dist/esm/api/client/index.d.mts +1 -0
- package/dist/esm/api/client/index.mjs +1 -0
- package/dist/{cjs/api/types/ExtractJsonInput.d.ts → esm/api/client/requests/ExtractAsyncRequest.d.mts} +13 -9
- package/dist/esm/api/{types/ExtractMultipartInput.d.mts → client/requests/ExtractRequest.d.mts} +10 -8
- package/dist/esm/api/client/requests/index.d.mts +2 -0
- package/dist/esm/api/client/requests/index.mjs +1 -0
- package/dist/esm/api/index.d.mts +1 -0
- package/dist/esm/api/index.mjs +1 -0
- package/dist/esm/api/types/ExtractInput.d.mts +63 -1
- package/dist/esm/api/types/{MultipartSource.d.mts → ExtractSource.d.mts} +1 -1
- package/dist/esm/api/types/index.d.mts +1 -5
- package/dist/esm/api/types/index.mjs +1 -5
- package/dist/esm/core/exports.d.mts +1 -0
- package/dist/esm/core/exports.mjs +1 -0
- package/dist/esm/core/file/exports.d.mts +1 -0
- package/dist/esm/core/file/exports.mjs +1 -0
- package/dist/esm/core/file/file.d.mts +10 -0
- package/dist/esm/core/file/file.mjs +184 -0
- package/dist/esm/core/file/index.d.mts +2 -0
- package/dist/esm/core/file/index.mjs +2 -0
- package/dist/esm/core/file/types.d.mts +66 -0
- package/dist/esm/core/file/types.mjs +1 -0
- package/dist/esm/core/form-data-utils/FormDataWrapper.d.mts +15 -0
- package/dist/esm/core/form-data-utils/FormDataWrapper.mjs +147 -0
- package/dist/esm/core/form-data-utils/encodeAsFormParameter.d.mts +1 -0
- package/dist/esm/core/form-data-utils/encodeAsFormParameter.mjs +9 -0
- package/dist/esm/core/form-data-utils/index.d.mts +2 -0
- package/dist/esm/core/form-data-utils/index.mjs +2 -0
- package/dist/esm/core/index.d.mts +2 -0
- package/dist/esm/core/index.mjs +2 -0
- package/dist/esm/environments.d.mts +1 -1
- package/dist/esm/environments.mjs +1 -1
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
- package/reference.md +4 -8
- package/dist/cjs/api/types/ExtractAsyncInput.d.ts +0 -1
- package/dist/cjs/api/types/JsonSource.d.ts +0 -7
- package/dist/cjs/api/types/MultipartSource.js +0 -3
- package/dist/esm/api/types/ExtractAsyncInput.d.mts +0 -1
- package/dist/esm/api/types/JsonSource.d.mts +0 -7
- package/dist/esm/api/types/JsonSource.mjs +0 -2
- package/dist/esm/api/types/MultipartSource.mjs +0 -2
- /package/dist/cjs/api/{types/ExtractAsyncInput.js → client/requests/ExtractAsyncRequest.js} +0 -0
- /package/dist/cjs/api/{types/ExtractJsonInput.js → client/requests/ExtractRequest.js} +0 -0
- /package/dist/cjs/api/types/{ExtractMultipartInput.js → ExtractSource.js} +0 -0
- /package/dist/esm/api/{types/ExtractAsyncInput.mjs → client/requests/ExtractAsyncRequest.mjs} +0 -0
- /package/dist/esm/api/{types/ExtractJsonInput.mjs → client/requests/ExtractRequest.mjs} +0 -0
- /package/dist/esm/api/types/{ExtractMultipartInput.mjs → ExtractSource.mjs} +0 -0
|
@@ -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,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,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 {};
|
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
45
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
46
|
+
var m = o[Symbol.asyncIterator], i;
|
|
47
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
48
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
49
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
50
|
+
};
|
|
51
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
+
exports.FormDataWrapper = void 0;
|
|
53
|
+
exports.newFormData = newFormData;
|
|
54
|
+
const index_js_1 = require("../../core/file/index.js");
|
|
55
|
+
const json_js_1 = require("../../core/json.js");
|
|
56
|
+
const index_js_2 = require("../runtime/index.js");
|
|
57
|
+
function newFormData() {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
return new FormDataWrapper();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
class FormDataWrapper {
|
|
63
|
+
constructor() {
|
|
64
|
+
this.fd = new FormData();
|
|
65
|
+
}
|
|
66
|
+
setup() {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
// noop
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
append(key, value) {
|
|
72
|
+
this.fd.append(key, String(value));
|
|
73
|
+
}
|
|
74
|
+
appendFile(key, value) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const { data, filename, contentType } = yield (0, index_js_1.toMultipartDataPart)(value);
|
|
77
|
+
const blob = yield convertToBlob(data, contentType);
|
|
78
|
+
if (filename) {
|
|
79
|
+
this.fd.append(key, blob, filename);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
this.fd.append(key, blob);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
getRequest() {
|
|
87
|
+
return {
|
|
88
|
+
body: this.fd,
|
|
89
|
+
headers: {},
|
|
90
|
+
duplex: "half",
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.FormDataWrapper = FormDataWrapper;
|
|
95
|
+
function isStreamLike(value) {
|
|
96
|
+
return typeof value === "object" && value != null && ("read" in value || "pipe" in value);
|
|
97
|
+
}
|
|
98
|
+
function isReadableStream(value) {
|
|
99
|
+
return typeof value === "object" && value != null && "getReader" in value;
|
|
100
|
+
}
|
|
101
|
+
function isBuffer(value) {
|
|
102
|
+
return typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(value);
|
|
103
|
+
}
|
|
104
|
+
function isArrayBufferView(value) {
|
|
105
|
+
return ArrayBuffer.isView(value);
|
|
106
|
+
}
|
|
107
|
+
function streamToBuffer(stream) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
var _a, stream_1, stream_1_1;
|
|
110
|
+
var _b, e_1, _c, _d;
|
|
111
|
+
if (index_js_2.RUNTIME.type === "node") {
|
|
112
|
+
const { Readable } = yield Promise.resolve().then(() => __importStar(require("stream")));
|
|
113
|
+
if (stream instanceof Readable) {
|
|
114
|
+
const chunks = [];
|
|
115
|
+
try {
|
|
116
|
+
for (_a = true, stream_1 = __asyncValues(stream); stream_1_1 = yield stream_1.next(), _b = stream_1_1.done, !_b; _a = true) {
|
|
117
|
+
_d = stream_1_1.value;
|
|
118
|
+
_a = false;
|
|
119
|
+
const chunk = _d;
|
|
120
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
124
|
+
finally {
|
|
125
|
+
try {
|
|
126
|
+
if (!_a && !_b && (_c = stream_1.return)) yield _c.call(stream_1);
|
|
127
|
+
}
|
|
128
|
+
finally { if (e_1) throw e_1.error; }
|
|
129
|
+
}
|
|
130
|
+
return Buffer.concat(chunks);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (isReadableStream(stream)) {
|
|
134
|
+
const reader = stream.getReader();
|
|
135
|
+
const chunks = [];
|
|
136
|
+
try {
|
|
137
|
+
while (true) {
|
|
138
|
+
const { done, value } = yield reader.read();
|
|
139
|
+
if (done)
|
|
140
|
+
break;
|
|
141
|
+
chunks.push(value);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
reader.releaseLock();
|
|
146
|
+
}
|
|
147
|
+
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
148
|
+
const result = new Uint8Array(totalLength);
|
|
149
|
+
let offset = 0;
|
|
150
|
+
for (const chunk of chunks) {
|
|
151
|
+
result.set(chunk, offset);
|
|
152
|
+
offset += chunk.length;
|
|
153
|
+
}
|
|
154
|
+
return Buffer.from(result);
|
|
155
|
+
}
|
|
156
|
+
throw new Error(`Unsupported stream type: ${typeof stream}. Expected Node.js Readable stream or Web ReadableStream.`);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function convertToBlob(value, contentType) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
if (isStreamLike(value) || isReadableStream(value)) {
|
|
162
|
+
const buffer = yield streamToBuffer(value);
|
|
163
|
+
return new Blob([buffer], { type: contentType });
|
|
164
|
+
}
|
|
165
|
+
if (value instanceof Blob) {
|
|
166
|
+
return value;
|
|
167
|
+
}
|
|
168
|
+
if (isBuffer(value)) {
|
|
169
|
+
return new Blob([value], { type: contentType });
|
|
170
|
+
}
|
|
171
|
+
if (value instanceof ArrayBuffer) {
|
|
172
|
+
return new Blob([value], { type: contentType });
|
|
173
|
+
}
|
|
174
|
+
if (isArrayBufferView(value)) {
|
|
175
|
+
return new Blob([value], { type: contentType });
|
|
176
|
+
}
|
|
177
|
+
if (typeof value === "string") {
|
|
178
|
+
return new Blob([value], { type: contentType });
|
|
179
|
+
}
|
|
180
|
+
if (typeof value === "object" && value !== null) {
|
|
181
|
+
return new Blob([(0, json_js_1.toJson)(value)], { type: contentType !== null && contentType !== void 0 ? contentType : "application/json" });
|
|
182
|
+
}
|
|
183
|
+
return new Blob([String(value)], { type: contentType });
|
|
184
|
+
});
|
|
185
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function encodeAsFormParameter(value: unknown): Record<string, string>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeAsFormParameter = encodeAsFormParameter;
|
|
4
|
+
const qs_js_1 = require("../url/qs.js");
|
|
5
|
+
function encodeAsFormParameter(value) {
|
|
6
|
+
const stringified = (0, qs_js_1.toQueryString)(value, { encode: false });
|
|
7
|
+
const keyValuePairs = stringified.split("&").map((pair) => {
|
|
8
|
+
const [key, value] = pair.split("=");
|
|
9
|
+
return [key, value];
|
|
10
|
+
});
|
|
11
|
+
return Object.fromEntries(keyValuePairs);
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
exports.encodeAsFormParameter = void 0;
|
|
18
|
+
var encodeAsFormParameter_js_1 = require("./encodeAsFormParameter.js");
|
|
19
|
+
Object.defineProperty(exports, "encodeAsFormParameter", { enumerable: true, get: function () { return encodeAsFormParameter_js_1.encodeAsFormParameter; } });
|
|
20
|
+
__exportStar(require("./FormDataWrapper.js"), exports);
|
package/dist/cjs/core/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "./auth/index.js";
|
|
2
2
|
export * from "./base64.js";
|
|
3
3
|
export * from "./fetcher/index.js";
|
|
4
|
+
export * as file from "./file/index.js";
|
|
5
|
+
export * from "./form-data-utils/index.js";
|
|
4
6
|
export * as logging from "./logging/index.js";
|
|
5
7
|
export * from "./runtime/index.js";
|
|
6
8
|
export * as url from "./url/index.js";
|
package/dist/cjs/core/index.js
CHANGED
|
@@ -36,10 +36,12 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
};
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.url = exports.logging = void 0;
|
|
39
|
+
exports.url = exports.logging = exports.file = void 0;
|
|
40
40
|
__exportStar(require("./auth/index.js"), exports);
|
|
41
41
|
__exportStar(require("./base64.js"), exports);
|
|
42
42
|
__exportStar(require("./fetcher/index.js"), exports);
|
|
43
|
+
exports.file = __importStar(require("./file/index.js"));
|
|
44
|
+
__exportStar(require("./form-data-utils/index.js"), exports);
|
|
43
45
|
exports.logging = __importStar(require("./logging/index.js"));
|
|
44
46
|
__exportStar(require("./runtime/index.js"), exports);
|
|
45
47
|
exports.url = __importStar(require("./url/index.js"));
|
package/dist/cjs/environments.js
CHANGED
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.0.
|
|
1
|
+
export declare const SDK_VERSION = "0.0.55";
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/BaseClient.mjs
CHANGED
|
@@ -6,8 +6,8 @@ export function normalizeClientOptions(options) {
|
|
|
6
6
|
const headers = mergeHeaders({
|
|
7
7
|
"X-Fern-Language": "JavaScript",
|
|
8
8
|
"X-Fern-SDK-Name": "pulse-ts-sdk",
|
|
9
|
-
"X-Fern-SDK-Version": "0.0.
|
|
10
|
-
"User-Agent": "pulse-ts-sdk/0.0.
|
|
9
|
+
"X-Fern-SDK-Version": "0.0.55",
|
|
10
|
+
"User-Agent": "pulse-ts-sdk/0.0.55",
|
|
11
11
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
12
12
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
13
13
|
}, options === null || options === void 0 ? void 0 : options.headers);
|
package/dist/esm/Client.d.mts
CHANGED
|
@@ -21,7 +21,7 @@ export declare class PulseClient {
|
|
|
21
21
|
* file URLs and returns rich markdown content with optional structured data
|
|
22
22
|
* extraction based on user-provided schemas and extraction options.
|
|
23
23
|
*
|
|
24
|
-
* @param {Pulse.
|
|
24
|
+
* @param {Pulse.ExtractRequest} request
|
|
25
25
|
* @param {PulseClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
26
26
|
*
|
|
27
27
|
* @throws {@link Pulse.BadRequestError}
|
|
@@ -29,18 +29,17 @@ export declare class PulseClient {
|
|
|
29
29
|
* @throws {@link Pulse.TooManyRequestsError}
|
|
30
30
|
*
|
|
31
31
|
* @example
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* })
|
|
32
|
+
* import { createReadStream } from "fs";
|
|
33
|
+
* await client.extract({})
|
|
35
34
|
*/
|
|
36
|
-
extract(request: Pulse.
|
|
35
|
+
extract(request: Pulse.ExtractRequest, requestOptions?: PulseClient.RequestOptions): core.HttpResponsePromise<Pulse.ExtractResponse>;
|
|
37
36
|
private __extract;
|
|
38
37
|
/**
|
|
39
38
|
* Starts an asynchronous extraction job. The request mirrors the
|
|
40
39
|
* synchronous options but returns immediately with a job identifier that
|
|
41
40
|
* clients can poll for completion status.
|
|
42
41
|
*
|
|
43
|
-
* @param {Pulse.
|
|
42
|
+
* @param {Pulse.ExtractAsyncRequest} request
|
|
44
43
|
* @param {PulseClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
45
44
|
*
|
|
46
45
|
* @throws {@link Pulse.BadRequestError}
|
|
@@ -48,10 +47,9 @@ export declare class PulseClient {
|
|
|
48
47
|
* @throws {@link Pulse.TooManyRequestsError}
|
|
49
48
|
*
|
|
50
49
|
* @example
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* })
|
|
50
|
+
* import { createReadStream } from "fs";
|
|
51
|
+
* await client.extractAsync({})
|
|
54
52
|
*/
|
|
55
|
-
extractAsync(request: Pulse.
|
|
53
|
+
extractAsync(request: Pulse.ExtractAsyncRequest, requestOptions?: PulseClient.RequestOptions): core.HttpResponsePromise<Pulse.ExtractAsyncResponse>;
|
|
56
54
|
private __extractAsync;
|
|
57
55
|
}
|