@credal/sdk 0.1.9 → 0.1.11
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/dist/cjs/BaseClient.d.ts +4 -0
- package/dist/cjs/Client.js +3 -3
- package/dist/cjs/api/resources/copilots/client/Client.js +27 -9
- package/dist/cjs/api/resources/documentCatalog/client/Client.d.ts +8 -0
- package/dist/cjs/api/resources/documentCatalog/client/Client.js +95 -3
- package/dist/cjs/api/resources/documentCatalog/client/requests/UploadFileRequest.d.ts +27 -0
- package/dist/cjs/api/resources/documentCatalog/client/requests/UploadFileRequest.js +3 -0
- package/dist/cjs/api/resources/documentCatalog/client/requests/index.d.ts +1 -0
- package/dist/cjs/api/resources/documentCollections/client/Client.js +21 -7
- package/dist/cjs/api/resources/search/client/Client.js +3 -1
- package/dist/cjs/api/resources/users/client/Client.js +3 -1
- package/dist/cjs/core/exports.d.ts +2 -0
- package/dist/cjs/core/exports.js +18 -0
- package/dist/cjs/core/fetcher/Fetcher.d.ts +4 -1
- package/dist/cjs/core/fetcher/Fetcher.js +202 -9
- package/dist/cjs/core/fetcher/getRequestBody.d.ts +1 -1
- package/dist/cjs/core/fetcher/getRequestBody.js +4 -0
- package/dist/cjs/core/fetcher/makeRequest.d.ts +1 -1
- package/dist/cjs/core/fetcher/makeRequest.js +0 -2
- package/dist/cjs/core/fetcher/requestWithRetries.js +0 -9
- package/dist/cjs/core/fetcher/signals.d.ts +0 -6
- package/dist/cjs/core/fetcher/signals.js +0 -12
- 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/headers.js +6 -4
- package/dist/cjs/core/index.d.ts +3 -0
- package/dist/cjs/core/index.js +4 -1
- package/dist/cjs/core/logging/exports.d.ts +18 -0
- package/dist/cjs/core/logging/exports.js +45 -0
- package/dist/cjs/core/logging/index.d.ts +1 -0
- package/dist/cjs/core/logging/index.js +17 -0
- package/dist/cjs/core/logging/logger.d.ts +126 -0
- package/dist/cjs/core/logging/logger.js +144 -0
- package/dist/cjs/core/url/join.js +0 -1
- package/dist/cjs/exports.d.ts +1 -0
- package/dist/cjs/exports.js +17 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.d.mts +4 -0
- package/dist/esm/Client.mjs +3 -3
- package/dist/esm/api/resources/copilots/client/Client.mjs +27 -9
- package/dist/esm/api/resources/documentCatalog/client/Client.d.mts +8 -0
- package/dist/esm/api/resources/documentCatalog/client/Client.mjs +95 -3
- package/dist/esm/api/resources/documentCatalog/client/requests/UploadFileRequest.d.mts +27 -0
- package/dist/esm/api/resources/documentCatalog/client/requests/UploadFileRequest.mjs +2 -0
- package/dist/esm/api/resources/documentCatalog/client/requests/index.d.mts +1 -0
- package/dist/esm/api/resources/documentCollections/client/Client.mjs +21 -7
- package/dist/esm/api/resources/search/client/Client.mjs +3 -1
- package/dist/esm/api/resources/users/client/Client.mjs +3 -1
- package/dist/esm/core/exports.d.mts +2 -0
- package/dist/esm/core/exports.mjs +2 -0
- package/dist/esm/core/fetcher/Fetcher.d.mts +4 -1
- package/dist/esm/core/fetcher/Fetcher.mjs +202 -9
- package/dist/esm/core/fetcher/getRequestBody.d.mts +1 -1
- package/dist/esm/core/fetcher/getRequestBody.mjs +4 -0
- package/dist/esm/core/fetcher/makeRequest.d.mts +1 -1
- package/dist/esm/core/fetcher/makeRequest.mjs +0 -2
- package/dist/esm/core/fetcher/requestWithRetries.mjs +0 -9
- package/dist/esm/core/fetcher/signals.d.mts +0 -6
- package/dist/esm/core/fetcher/signals.mjs +0 -12
- 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/headers.mjs +6 -4
- package/dist/esm/core/index.d.mts +3 -0
- package/dist/esm/core/index.mjs +3 -0
- package/dist/esm/core/logging/exports.d.mts +18 -0
- package/dist/esm/core/logging/exports.mjs +9 -0
- package/dist/esm/core/logging/index.d.mts +1 -0
- package/dist/esm/core/logging/index.mjs +1 -0
- package/dist/esm/core/logging/logger.d.mts +126 -0
- package/dist/esm/core/logging/logger.mjs +138 -0
- package/dist/esm/core/url/join.mjs +0 -1
- package/dist/esm/exports.d.mts +1 -0
- package/dist/esm/exports.mjs +1 -0
- package/dist/esm/index.d.mts +1 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export function toBinaryUploadRequest(file) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
const { data, filename, contentLength, contentType } = yield getFileWithMetadata(file);
|
|
13
|
+
const request = {
|
|
14
|
+
body: data,
|
|
15
|
+
headers: {},
|
|
16
|
+
};
|
|
17
|
+
if (filename) {
|
|
18
|
+
request.headers["Content-Disposition"] = `attachment; filename="${filename}"`;
|
|
19
|
+
}
|
|
20
|
+
if (contentType) {
|
|
21
|
+
request.headers["Content-Type"] = contentType;
|
|
22
|
+
}
|
|
23
|
+
if (contentLength != null) {
|
|
24
|
+
request.headers["Content-Length"] = contentLength.toString();
|
|
25
|
+
}
|
|
26
|
+
return request;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export function toMultipartDataPart(file) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const { data, filename, contentType } = yield getFileWithMetadata(file, {
|
|
32
|
+
noSniffFileSize: true,
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
data,
|
|
36
|
+
filename,
|
|
37
|
+
contentType,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function getFileWithMetadata(file_1) {
|
|
42
|
+
return __awaiter(this, arguments, void 0, function* (file, { noSniffFileSize } = {}) {
|
|
43
|
+
var _a, _b, _c, _d, _e;
|
|
44
|
+
if (isFileLike(file)) {
|
|
45
|
+
return getFileWithMetadata({
|
|
46
|
+
data: file,
|
|
47
|
+
}, { noSniffFileSize });
|
|
48
|
+
}
|
|
49
|
+
if ("path" in file) {
|
|
50
|
+
const fs = yield import("fs");
|
|
51
|
+
if (!fs || !fs.createReadStream) {
|
|
52
|
+
throw new Error("File path uploads are not supported in this environment.");
|
|
53
|
+
}
|
|
54
|
+
const data = fs.createReadStream(file.path);
|
|
55
|
+
const contentLength = (_a = file.contentLength) !== null && _a !== void 0 ? _a : (noSniffFileSize === true ? undefined : yield tryGetFileSizeFromPath(file.path));
|
|
56
|
+
const filename = (_b = file.filename) !== null && _b !== void 0 ? _b : getNameFromPath(file.path);
|
|
57
|
+
return {
|
|
58
|
+
data,
|
|
59
|
+
filename,
|
|
60
|
+
contentType: file.contentType,
|
|
61
|
+
contentLength,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if ("data" in file) {
|
|
65
|
+
const data = file.data;
|
|
66
|
+
const contentLength = (_c = file.contentLength) !== null && _c !== void 0 ? _c : (yield tryGetContentLengthFromFileLike(data, {
|
|
67
|
+
noSniffFileSize,
|
|
68
|
+
}));
|
|
69
|
+
const filename = (_d = file.filename) !== null && _d !== void 0 ? _d : tryGetNameFromFileLike(data);
|
|
70
|
+
return {
|
|
71
|
+
data,
|
|
72
|
+
filename,
|
|
73
|
+
contentType: (_e = file.contentType) !== null && _e !== void 0 ? _e : tryGetContentTypeFromFileLike(data),
|
|
74
|
+
contentLength,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`Invalid FileUpload of type ${typeof file}: ${JSON.stringify(file)}`);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function isFileLike(value) {
|
|
81
|
+
return (isBuffer(value) ||
|
|
82
|
+
isArrayBufferView(value) ||
|
|
83
|
+
isArrayBuffer(value) ||
|
|
84
|
+
isUint8Array(value) ||
|
|
85
|
+
isBlob(value) ||
|
|
86
|
+
isFile(value) ||
|
|
87
|
+
isStreamLike(value) ||
|
|
88
|
+
isReadableStream(value));
|
|
89
|
+
}
|
|
90
|
+
function tryGetFileSizeFromPath(path) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
try {
|
|
93
|
+
const fs = yield import("fs");
|
|
94
|
+
if (!fs || !fs.promises || !fs.promises.stat) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
const fileStat = yield fs.promises.stat(path);
|
|
98
|
+
return fileStat.size;
|
|
99
|
+
}
|
|
100
|
+
catch (_fallbackError) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function tryGetNameFromFileLike(data) {
|
|
106
|
+
if (isNamedValue(data)) {
|
|
107
|
+
return data.name;
|
|
108
|
+
}
|
|
109
|
+
if (isPathedValue(data)) {
|
|
110
|
+
return getNameFromPath(data.path.toString());
|
|
111
|
+
}
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
function tryGetContentLengthFromFileLike(data_1) {
|
|
115
|
+
return __awaiter(this, arguments, void 0, function* (data, { noSniffFileSize } = {}) {
|
|
116
|
+
if (isBuffer(data)) {
|
|
117
|
+
return data.length;
|
|
118
|
+
}
|
|
119
|
+
if (isArrayBufferView(data)) {
|
|
120
|
+
return data.byteLength;
|
|
121
|
+
}
|
|
122
|
+
if (isArrayBuffer(data)) {
|
|
123
|
+
return data.byteLength;
|
|
124
|
+
}
|
|
125
|
+
if (isBlob(data)) {
|
|
126
|
+
return data.size;
|
|
127
|
+
}
|
|
128
|
+
if (isFile(data)) {
|
|
129
|
+
return data.size;
|
|
130
|
+
}
|
|
131
|
+
if (noSniffFileSize === true) {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
if (isPathedValue(data)) {
|
|
135
|
+
return yield tryGetFileSizeFromPath(data.path.toString());
|
|
136
|
+
}
|
|
137
|
+
return undefined;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function tryGetContentTypeFromFileLike(data) {
|
|
141
|
+
if (isBlob(data)) {
|
|
142
|
+
return data.type;
|
|
143
|
+
}
|
|
144
|
+
if (isFile(data)) {
|
|
145
|
+
return data.type;
|
|
146
|
+
}
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
function getNameFromPath(path) {
|
|
150
|
+
const lastForwardSlash = path.lastIndexOf("/");
|
|
151
|
+
const lastBackSlash = path.lastIndexOf("\\");
|
|
152
|
+
const lastSlashIndex = Math.max(lastForwardSlash, lastBackSlash);
|
|
153
|
+
return lastSlashIndex >= 0 ? path.substring(lastSlashIndex + 1) : path;
|
|
154
|
+
}
|
|
155
|
+
function isNamedValue(value) {
|
|
156
|
+
return typeof value === "object" && value != null && "name" in value;
|
|
157
|
+
}
|
|
158
|
+
function isPathedValue(value) {
|
|
159
|
+
return typeof value === "object" && value != null && "path" in value;
|
|
160
|
+
}
|
|
161
|
+
function isStreamLike(value) {
|
|
162
|
+
return typeof value === "object" && value != null && ("read" in value || "pipe" in value);
|
|
163
|
+
}
|
|
164
|
+
function isReadableStream(value) {
|
|
165
|
+
return typeof value === "object" && value != null && "getReader" in value;
|
|
166
|
+
}
|
|
167
|
+
function isBuffer(value) {
|
|
168
|
+
return typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(value);
|
|
169
|
+
}
|
|
170
|
+
function isArrayBufferView(value) {
|
|
171
|
+
return typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(value);
|
|
172
|
+
}
|
|
173
|
+
function isArrayBuffer(value) {
|
|
174
|
+
return typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer;
|
|
175
|
+
}
|
|
176
|
+
function isUint8Array(value) {
|
|
177
|
+
return typeof Uint8Array !== "undefined" && value instanceof Uint8Array;
|
|
178
|
+
}
|
|
179
|
+
function isBlob(value) {
|
|
180
|
+
return typeof Blob !== "undefined" && value instanceof Blob;
|
|
181
|
+
}
|
|
182
|
+
function isFile(value) {
|
|
183
|
+
return typeof File !== "undefined" && value instanceof File;
|
|
184
|
+
}
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Uploadable } from "../../core/file/index.mjs";
|
|
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,147 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
11
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
12
|
+
var m = o[Symbol.asyncIterator], i;
|
|
13
|
+
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);
|
|
14
|
+
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); }); }; }
|
|
15
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
16
|
+
};
|
|
17
|
+
import { toMultipartDataPart } from "../../core/file/index.mjs";
|
|
18
|
+
import { toJson } from "../../core/json.mjs";
|
|
19
|
+
import { RUNTIME } from "../runtime/index.mjs";
|
|
20
|
+
export function newFormData() {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
return new FormDataWrapper();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export class FormDataWrapper {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.fd = new FormData();
|
|
28
|
+
}
|
|
29
|
+
setup() {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
// noop
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
append(key, value) {
|
|
35
|
+
this.fd.append(key, String(value));
|
|
36
|
+
}
|
|
37
|
+
appendFile(key, value) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const { data, filename, contentType } = yield toMultipartDataPart(value);
|
|
40
|
+
const blob = yield convertToBlob(data, contentType);
|
|
41
|
+
if (filename) {
|
|
42
|
+
this.fd.append(key, blob, filename);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.fd.append(key, blob);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
getRequest() {
|
|
50
|
+
return {
|
|
51
|
+
body: this.fd,
|
|
52
|
+
headers: {},
|
|
53
|
+
duplex: "half",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function isStreamLike(value) {
|
|
58
|
+
return typeof value === "object" && value != null && ("read" in value || "pipe" in value);
|
|
59
|
+
}
|
|
60
|
+
function isReadableStream(value) {
|
|
61
|
+
return typeof value === "object" && value != null && "getReader" in value;
|
|
62
|
+
}
|
|
63
|
+
function isBuffer(value) {
|
|
64
|
+
return typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(value);
|
|
65
|
+
}
|
|
66
|
+
function isArrayBufferView(value) {
|
|
67
|
+
return ArrayBuffer.isView(value);
|
|
68
|
+
}
|
|
69
|
+
function streamToBuffer(stream) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
var _a, stream_1, stream_1_1;
|
|
72
|
+
var _b, e_1, _c, _d;
|
|
73
|
+
if (RUNTIME.type === "node") {
|
|
74
|
+
const { Readable } = yield import("stream");
|
|
75
|
+
if (stream instanceof Readable) {
|
|
76
|
+
const chunks = [];
|
|
77
|
+
try {
|
|
78
|
+
for (_a = true, stream_1 = __asyncValues(stream); stream_1_1 = yield stream_1.next(), _b = stream_1_1.done, !_b; _a = true) {
|
|
79
|
+
_d = stream_1_1.value;
|
|
80
|
+
_a = false;
|
|
81
|
+
const chunk = _d;
|
|
82
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
86
|
+
finally {
|
|
87
|
+
try {
|
|
88
|
+
if (!_a && !_b && (_c = stream_1.return)) yield _c.call(stream_1);
|
|
89
|
+
}
|
|
90
|
+
finally { if (e_1) throw e_1.error; }
|
|
91
|
+
}
|
|
92
|
+
return Buffer.concat(chunks);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (isReadableStream(stream)) {
|
|
96
|
+
const reader = stream.getReader();
|
|
97
|
+
const chunks = [];
|
|
98
|
+
try {
|
|
99
|
+
while (true) {
|
|
100
|
+
const { done, value } = yield reader.read();
|
|
101
|
+
if (done)
|
|
102
|
+
break;
|
|
103
|
+
chunks.push(value);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
reader.releaseLock();
|
|
108
|
+
}
|
|
109
|
+
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
110
|
+
const result = new Uint8Array(totalLength);
|
|
111
|
+
let offset = 0;
|
|
112
|
+
for (const chunk of chunks) {
|
|
113
|
+
result.set(chunk, offset);
|
|
114
|
+
offset += chunk.length;
|
|
115
|
+
}
|
|
116
|
+
return Buffer.from(result);
|
|
117
|
+
}
|
|
118
|
+
throw new Error(`Unsupported stream type: ${typeof stream}. Expected Node.js Readable stream or Web ReadableStream.`);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function convertToBlob(value, contentType) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
if (isStreamLike(value) || isReadableStream(value)) {
|
|
124
|
+
const buffer = yield streamToBuffer(value);
|
|
125
|
+
return new Blob([buffer], { type: contentType });
|
|
126
|
+
}
|
|
127
|
+
if (value instanceof Blob) {
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
if (isBuffer(value)) {
|
|
131
|
+
return new Blob([value], { type: contentType });
|
|
132
|
+
}
|
|
133
|
+
if (value instanceof ArrayBuffer) {
|
|
134
|
+
return new Blob([value], { type: contentType });
|
|
135
|
+
}
|
|
136
|
+
if (isArrayBufferView(value)) {
|
|
137
|
+
return new Blob([value], { type: contentType });
|
|
138
|
+
}
|
|
139
|
+
if (typeof value === "string") {
|
|
140
|
+
return new Blob([value], { type: contentType });
|
|
141
|
+
}
|
|
142
|
+
if (typeof value === "object" && value !== null) {
|
|
143
|
+
return new Blob([toJson(value)], { type: contentType !== null && contentType !== void 0 ? contentType : "application/json" });
|
|
144
|
+
}
|
|
145
|
+
return new Blob([String(value)], { type: contentType });
|
|
146
|
+
});
|
|
147
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function encodeAsFormParameter(value: unknown): Record<string, string>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { toQueryString } from "../url/qs.mjs";
|
|
2
|
+
export function encodeAsFormParameter(value) {
|
|
3
|
+
const stringified = toQueryString(value, { encode: false });
|
|
4
|
+
const keyValuePairs = stringified.split("&").map((pair) => {
|
|
5
|
+
const [key, value] = pair.split("=");
|
|
6
|
+
return [key, value];
|
|
7
|
+
});
|
|
8
|
+
return Object.fromEntries(keyValuePairs);
|
|
9
|
+
}
|
|
@@ -3,11 +3,12 @@ export function mergeHeaders(...headersArray) {
|
|
|
3
3
|
for (const [key, value] of headersArray
|
|
4
4
|
.filter((headers) => headers != null)
|
|
5
5
|
.flatMap((headers) => Object.entries(headers))) {
|
|
6
|
+
const insensitiveKey = key.toLowerCase();
|
|
6
7
|
if (value != null) {
|
|
7
|
-
result[
|
|
8
|
+
result[insensitiveKey] = value;
|
|
8
9
|
}
|
|
9
|
-
else if (
|
|
10
|
-
delete result[
|
|
10
|
+
else if (insensitiveKey in result) {
|
|
11
|
+
delete result[insensitiveKey];
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
return result;
|
|
@@ -17,8 +18,9 @@ export function mergeOnlyDefinedHeaders(...headersArray) {
|
|
|
17
18
|
for (const [key, value] of headersArray
|
|
18
19
|
.filter((headers) => headers != null)
|
|
19
20
|
.flatMap((headers) => Object.entries(headers))) {
|
|
21
|
+
const insensitiveKey = key.toLowerCase();
|
|
20
22
|
if (value != null) {
|
|
21
|
-
result[
|
|
23
|
+
result[insensitiveKey] = value;
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
return result;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from "./auth/index.mjs";
|
|
2
2
|
export * from "./base64.mjs";
|
|
3
3
|
export * from "./fetcher/index.mjs";
|
|
4
|
+
export * as file from "./file/index.mjs";
|
|
5
|
+
export * from "./form-data-utils/index.mjs";
|
|
6
|
+
export * as logging from "./logging/index.mjs";
|
|
4
7
|
export * from "./runtime/index.mjs";
|
|
5
8
|
export * from "./stream/index.mjs";
|
|
6
9
|
export * as url from "./url/index.mjs";
|
package/dist/esm/core/index.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from "./auth/index.mjs";
|
|
2
2
|
export * from "./base64.mjs";
|
|
3
3
|
export * from "./fetcher/index.mjs";
|
|
4
|
+
export * as file from "./file/index.mjs";
|
|
5
|
+
export * from "./form-data-utils/index.mjs";
|
|
6
|
+
export * as logging from "./logging/index.mjs";
|
|
4
7
|
export * from "./runtime/index.mjs";
|
|
5
8
|
export * from "./stream/index.mjs";
|
|
6
9
|
export * as url from "./url/index.mjs";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as logger from "./logger.mjs";
|
|
2
|
+
export declare namespace logging {
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for logger instances.
|
|
5
|
+
*/
|
|
6
|
+
type LogConfig = logger.LogConfig;
|
|
7
|
+
type LogLevel = logger.LogLevel;
|
|
8
|
+
const LogLevel: typeof logger.LogLevel;
|
|
9
|
+
type ILogger = logger.ILogger;
|
|
10
|
+
/**
|
|
11
|
+
* Console logger implementation that outputs to the console.
|
|
12
|
+
*/
|
|
13
|
+
type ConsoleLogger = logger.ConsoleLogger;
|
|
14
|
+
/**
|
|
15
|
+
* Console logger implementation that outputs to the console.
|
|
16
|
+
*/
|
|
17
|
+
const ConsoleLogger: typeof logger.ConsoleLogger;
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as logger from "./logger.mjs";
|
|
2
|
+
export var logging;
|
|
3
|
+
(function (logging) {
|
|
4
|
+
logging.LogLevel = logger.LogLevel;
|
|
5
|
+
/**
|
|
6
|
+
* Console logger implementation that outputs to the console.
|
|
7
|
+
*/
|
|
8
|
+
logging.ConsoleLogger = logger.ConsoleLogger;
|
|
9
|
+
})(logging || (logging = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./logger.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./logger.mjs";
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
export declare const LogLevel: {
|
|
2
|
+
readonly Debug: "debug";
|
|
3
|
+
readonly Info: "info";
|
|
4
|
+
readonly Warn: "warn";
|
|
5
|
+
readonly Error: "error";
|
|
6
|
+
};
|
|
7
|
+
export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
|
|
8
|
+
export interface ILogger {
|
|
9
|
+
/**
|
|
10
|
+
* Logs a debug message.
|
|
11
|
+
* @param message - The message to log
|
|
12
|
+
* @param args - Additional arguments to log
|
|
13
|
+
*/
|
|
14
|
+
debug(message: string, ...args: unknown[]): void;
|
|
15
|
+
/**
|
|
16
|
+
* Logs an info message.
|
|
17
|
+
* @param message - The message to log
|
|
18
|
+
* @param args - Additional arguments to log
|
|
19
|
+
*/
|
|
20
|
+
info(message: string, ...args: unknown[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Logs a warning message.
|
|
23
|
+
* @param message - The message to log
|
|
24
|
+
* @param args - Additional arguments to log
|
|
25
|
+
*/
|
|
26
|
+
warn(message: string, ...args: unknown[]): void;
|
|
27
|
+
/**
|
|
28
|
+
* Logs an error message.
|
|
29
|
+
* @param message - The message to log
|
|
30
|
+
* @param args - Additional arguments to log
|
|
31
|
+
*/
|
|
32
|
+
error(message: string, ...args: unknown[]): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Configuration for logger initialization.
|
|
36
|
+
*/
|
|
37
|
+
export interface LogConfig {
|
|
38
|
+
/**
|
|
39
|
+
* Minimum log level to output.
|
|
40
|
+
* @default LogLevel.Info
|
|
41
|
+
*/
|
|
42
|
+
level?: LogLevel;
|
|
43
|
+
/**
|
|
44
|
+
* Logger implementation to use.
|
|
45
|
+
* @default new ConsoleLogger()
|
|
46
|
+
*/
|
|
47
|
+
logger?: ILogger;
|
|
48
|
+
/**
|
|
49
|
+
* Whether logging should be silenced.
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
silent?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Default console-based logger implementation.
|
|
56
|
+
*/
|
|
57
|
+
export declare class ConsoleLogger implements ILogger {
|
|
58
|
+
debug(message: string, ...args: unknown[]): void;
|
|
59
|
+
info(message: string, ...args: unknown[]): void;
|
|
60
|
+
warn(message: string, ...args: unknown[]): void;
|
|
61
|
+
error(message: string, ...args: unknown[]): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Logger class that provides level-based logging functionality.
|
|
65
|
+
*/
|
|
66
|
+
export declare class Logger {
|
|
67
|
+
private readonly level;
|
|
68
|
+
private readonly logger;
|
|
69
|
+
private readonly silent;
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new logger instance.
|
|
72
|
+
* @param config - Logger configuration
|
|
73
|
+
*/
|
|
74
|
+
constructor(config: Required<LogConfig>);
|
|
75
|
+
/**
|
|
76
|
+
* Checks if a log level should be output based on configuration.
|
|
77
|
+
* @param level - The log level to check
|
|
78
|
+
* @returns True if the level should be logged
|
|
79
|
+
*/
|
|
80
|
+
shouldLog(level: LogLevel): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Checks if debug logging is enabled.
|
|
83
|
+
* @returns True if debug logs should be output
|
|
84
|
+
*/
|
|
85
|
+
isDebug(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Logs a debug message if debug logging is enabled.
|
|
88
|
+
* @param message - The message to log
|
|
89
|
+
* @param args - Additional arguments to log
|
|
90
|
+
*/
|
|
91
|
+
debug(message: string, ...args: unknown[]): void;
|
|
92
|
+
/**
|
|
93
|
+
* Checks if info logging is enabled.
|
|
94
|
+
* @returns True if info logs should be output
|
|
95
|
+
*/
|
|
96
|
+
isInfo(): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Logs an info message if info logging is enabled.
|
|
99
|
+
* @param message - The message to log
|
|
100
|
+
* @param args - Additional arguments to log
|
|
101
|
+
*/
|
|
102
|
+
info(message: string, ...args: unknown[]): void;
|
|
103
|
+
/**
|
|
104
|
+
* Checks if warning logging is enabled.
|
|
105
|
+
* @returns True if warning logs should be output
|
|
106
|
+
*/
|
|
107
|
+
isWarn(): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Logs a warning message if warning logging is enabled.
|
|
110
|
+
* @param message - The message to log
|
|
111
|
+
* @param args - Additional arguments to log
|
|
112
|
+
*/
|
|
113
|
+
warn(message: string, ...args: unknown[]): void;
|
|
114
|
+
/**
|
|
115
|
+
* Checks if error logging is enabled.
|
|
116
|
+
* @returns True if error logs should be output
|
|
117
|
+
*/
|
|
118
|
+
isError(): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Logs an error message if error logging is enabled.
|
|
121
|
+
* @param message - The message to log
|
|
122
|
+
* @param args - Additional arguments to log
|
|
123
|
+
*/
|
|
124
|
+
error(message: string, ...args: unknown[]): void;
|
|
125
|
+
}
|
|
126
|
+
export declare function createLogger(config?: LogConfig | Logger): Logger;
|