@webiny/sdk 6.0.0-rc.7 → 6.1.0-beta.0
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/FileManagerSdk.d.ts +31 -0
- package/FileManagerSdk.js +52 -0
- package/FileManagerSdk.js.map +1 -0
- package/TenantManagerSdk.d.ts +18 -0
- package/TenantManagerSdk.js +28 -0
- package/TenantManagerSdk.js.map +1 -0
- package/Webiny.d.ts +4 -0
- package/Webiny.js +10 -0
- package/Webiny.js.map +1 -1
- package/index.d.ts +19 -0
- package/index.js +10 -0
- package/index.js.map +1 -1
- package/methods/cms/listEntries.d.ts +2 -0
- package/methods/cms/listEntries.js +5 -0
- package/methods/cms/listEntries.js.map +1 -1
- package/methods/fileManager/buildFieldsSelection.d.ts +22 -0
- package/methods/fileManager/buildFieldsSelection.js +71 -0
- package/methods/fileManager/buildFieldsSelection.js.map +1 -0
- package/methods/fileManager/completeMultiPartUpload.d.ts +18 -0
- package/methods/fileManager/completeMultiPartUpload.js +50 -0
- package/methods/fileManager/completeMultiPartUpload.js.map +1 -0
- package/methods/fileManager/createFile.d.ts +45 -0
- package/methods/fileManager/createFile.js +168 -0
- package/methods/fileManager/createFile.js.map +1 -0
- package/methods/fileManager/createFiles.d.ts +40 -0
- package/methods/fileManager/createFiles.js +83 -0
- package/methods/fileManager/createFiles.js.map +1 -0
- package/methods/fileManager/createMultiPartUpload.d.ts +38 -0
- package/methods/fileManager/createMultiPartUpload.js +63 -0
- package/methods/fileManager/createMultiPartUpload.js.map +1 -0
- package/methods/fileManager/deleteFile.d.ts +16 -0
- package/methods/fileManager/deleteFile.js +47 -0
- package/methods/fileManager/deleteFile.js.map +1 -0
- package/methods/fileManager/fileManagerTypes.d.ts +117 -0
- package/methods/fileManager/fileManagerTypes.js +22 -0
- package/methods/fileManager/fileManagerTypes.js.map +1 -0
- package/methods/fileManager/getFile.d.ts +18 -0
- package/methods/fileManager/getFile.js +52 -0
- package/methods/fileManager/getFile.js.map +1 -0
- package/methods/fileManager/getPresignedPostPayload.d.ts +25 -0
- package/methods/fileManager/getPresignedPostPayload.js +70 -0
- package/methods/fileManager/getPresignedPostPayload.js.map +1 -0
- package/methods/fileManager/getPresignedPostPayloads.d.ts +18 -0
- package/methods/fileManager/getPresignedPostPayloads.js +62 -0
- package/methods/fileManager/getPresignedPostPayloads.js.map +1 -0
- package/methods/fileManager/listFiles.d.ts +30 -0
- package/methods/fileManager/listFiles.js +72 -0
- package/methods/fileManager/listFiles.js.map +1 -0
- package/methods/fileManager/listTags.d.ts +17 -0
- package/methods/fileManager/listTags.js +50 -0
- package/methods/fileManager/listTags.js.map +1 -0
- package/methods/fileManager/updateFile.d.ts +35 -0
- package/methods/fileManager/updateFile.js +55 -0
- package/methods/fileManager/updateFile.js.map +1 -0
- package/methods/fileManager/utils/fileTypeDetection.d.ts +4 -0
- package/methods/fileManager/utils/fileTypeDetection.js +19 -0
- package/methods/fileManager/utils/fileTypeDetection.js.map +1 -0
- package/methods/fileManager/utils/uploadLargeFile.d.ts +25 -0
- package/methods/fileManager/utils/uploadLargeFile.js +187 -0
- package/methods/fileManager/utils/uploadLargeFile.js.map +1 -0
- package/methods/fileManager/utils/uploadToS3.d.ts +14 -0
- package/methods/fileManager/utils/uploadToS3.js +105 -0
- package/methods/fileManager/utils/uploadToS3.js.map +1 -0
- package/methods/tenantManager/createTenant.d.ts +17 -0
- package/methods/tenantManager/createTenant.js +47 -0
- package/methods/tenantManager/createTenant.js.map +1 -0
- package/methods/tenantManager/disableTenant.d.ts +16 -0
- package/methods/tenantManager/disableTenant.js +47 -0
- package/methods/tenantManager/disableTenant.js.map +1 -0
- package/methods/tenantManager/enableTenant.d.ts +16 -0
- package/methods/tenantManager/enableTenant.js +47 -0
- package/methods/tenantManager/enableTenant.js.map +1 -0
- package/methods/tenantManager/getCurrentTenant.d.ts +15 -0
- package/methods/tenantManager/getCurrentTenant.js +43 -0
- package/methods/tenantManager/getCurrentTenant.js.map +1 -0
- package/methods/tenantManager/installTenant.d.ts +16 -0
- package/methods/tenantManager/installTenant.js +47 -0
- package/methods/tenantManager/installTenant.js.map +1 -0
- package/methods/tenantManager/tenantManagerTypes.d.ts +5 -0
- package/methods/tenantManager/tenantManagerTypes.js +3 -0
- package/methods/tenantManager/tenantManagerTypes.js.map +1 -0
- package/package.json +4 -4
- package/utils/platform.d.ts +2 -0
- package/utils/platform.js +4 -0
- package/utils/platform.js.map +1 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { isBrowser } from "../../../utils/platform.js";
|
|
2
|
+
import { isBuffer, isFile, getFileSize } from "./fileTypeDetection.js";
|
|
3
|
+
/**
|
|
4
|
+
* Uploads a large file to S3 using multi-part upload.
|
|
5
|
+
*
|
|
6
|
+
* @param file - The file to upload (Buffer, Blob, or File)
|
|
7
|
+
* @param fileData - File metadata
|
|
8
|
+
* @param config - SDK configuration
|
|
9
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
10
|
+
* @param options - Upload options
|
|
11
|
+
* @returns Promise that resolves with the uploaded file metadata
|
|
12
|
+
*/
|
|
13
|
+
export async function uploadLargeFile(file, fileData, config, fetchFn, options = {}) {
|
|
14
|
+
const {
|
|
15
|
+
onProgress,
|
|
16
|
+
signal,
|
|
17
|
+
chunkSize = 50,
|
|
18
|
+
parallelUploads = 5
|
|
19
|
+
} = options;
|
|
20
|
+
const fileSize = getFileSize(file);
|
|
21
|
+
const chunkSizeBytes = Math.max(chunkSize * 1024 * 1024, 5 * 1024 * 1024);
|
|
22
|
+
const numberOfParts = Math.ceil(fileSize / chunkSizeBytes);
|
|
23
|
+
|
|
24
|
+
// 1. Create multi-part upload.
|
|
25
|
+
const {
|
|
26
|
+
createMultiPartUpload
|
|
27
|
+
} = await import("../createMultiPartUpload.js");
|
|
28
|
+
const createResult = await createMultiPartUpload(config, fetchFn, {
|
|
29
|
+
data: fileData,
|
|
30
|
+
numberOfParts
|
|
31
|
+
});
|
|
32
|
+
if (createResult.isFail()) {
|
|
33
|
+
throw createResult.error;
|
|
34
|
+
}
|
|
35
|
+
const uploadData = createResult.value;
|
|
36
|
+
const progressTracker = new Map();
|
|
37
|
+
|
|
38
|
+
// Helper to track progress.
|
|
39
|
+
const updateProgress = () => {
|
|
40
|
+
if (!onProgress) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const uploaded = Array.from(progressTracker.values()).reduce((sum, value) => sum + value, 0);
|
|
44
|
+
const uploadedSize = Math.min(uploaded, fileSize);
|
|
45
|
+
onProgress({
|
|
46
|
+
sent: uploadedSize,
|
|
47
|
+
total: fileSize,
|
|
48
|
+
percentage: Math.round(uploadedSize / fileSize * 100)
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// 2. Upload parts in parallel.
|
|
53
|
+
const pMap = (await import("p-map")).default;
|
|
54
|
+
const pRetry = (await import("p-retry")).default;
|
|
55
|
+
await pMap(uploadData.parts, async part => {
|
|
56
|
+
// Check abort signal.
|
|
57
|
+
if (signal?.aborted) {
|
|
58
|
+
throw new Error("Upload aborted");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Upload part with retry.
|
|
62
|
+
await pRetry(async () => {
|
|
63
|
+
const chunk = await getFileChunk(file, part.partNumber, chunkSizeBytes, fileData.type);
|
|
64
|
+
await uploadPart(part.url, chunk, loaded => {
|
|
65
|
+
progressTracker.set(part.partNumber, loaded);
|
|
66
|
+
updateProgress();
|
|
67
|
+
}, signal);
|
|
68
|
+
}, {
|
|
69
|
+
retries: 5,
|
|
70
|
+
minTimeout: 1500,
|
|
71
|
+
maxTimeout: 30000,
|
|
72
|
+
maxRetryTime: 300000
|
|
73
|
+
});
|
|
74
|
+
}, {
|
|
75
|
+
concurrency: Math.min(numberOfParts, parallelUploads)
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// 3. Complete multi-part upload.
|
|
79
|
+
const {
|
|
80
|
+
completeMultiPartUpload
|
|
81
|
+
} = await import("../completeMultiPartUpload.js");
|
|
82
|
+
const completeResult = await completeMultiPartUpload(config, fetchFn, {
|
|
83
|
+
fileKey: uploadData.file.key,
|
|
84
|
+
uploadId: uploadData.uploadId
|
|
85
|
+
});
|
|
86
|
+
if (completeResult.isFail()) {
|
|
87
|
+
throw completeResult.error;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Return the file metadata.
|
|
91
|
+
return uploadData.file;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Gets a chunk of the file for a specific part number.
|
|
96
|
+
*/
|
|
97
|
+
async function getFileChunk(file, partNumber, chunkSize, fileType) {
|
|
98
|
+
const start = (partNumber - 1) * chunkSize;
|
|
99
|
+
const end = Math.min(start + chunkSize, getFileSize(file));
|
|
100
|
+
if (isBuffer(file)) {
|
|
101
|
+
return file.slice(start, end);
|
|
102
|
+
}
|
|
103
|
+
if (isFile(file) || file instanceof Blob) {
|
|
104
|
+
return file.slice(start, end, fileType);
|
|
105
|
+
}
|
|
106
|
+
throw new Error("Unsupported file type");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Uploads a single part to S3.
|
|
111
|
+
*/
|
|
112
|
+
async function uploadPart(url, chunk, onProgress, signal) {
|
|
113
|
+
if (isBrowser && typeof XMLHttpRequest !== "undefined") {
|
|
114
|
+
return uploadPartWithXHR(url, chunk, onProgress, signal);
|
|
115
|
+
}
|
|
116
|
+
return uploadPartWithFetch(url, chunk, signal);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Upload part using XMLHttpRequest (browser only, supports progress).
|
|
121
|
+
*/
|
|
122
|
+
function uploadPartWithXHR(url, chunk, onProgress, signal) {
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
const xhr = new XMLHttpRequest();
|
|
125
|
+
|
|
126
|
+
// Handle abort signal.
|
|
127
|
+
if (signal) {
|
|
128
|
+
signal.addEventListener("abort", () => xhr.abort());
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Track upload progress.
|
|
132
|
+
xhr.upload.addEventListener("progress", event => {
|
|
133
|
+
if (event.lengthComputable) {
|
|
134
|
+
onProgress(event.loaded);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Handle completion.
|
|
139
|
+
xhr.addEventListener("readystatechange", () => {
|
|
140
|
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
|
141
|
+
resolve();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// Handle errors.
|
|
146
|
+
xhr.addEventListener("error", () => {
|
|
147
|
+
reject(new Error("Part upload failed due to network error"));
|
|
148
|
+
});
|
|
149
|
+
xhr.addEventListener("abort", () => {
|
|
150
|
+
reject(new Error("Part upload aborted"));
|
|
151
|
+
});
|
|
152
|
+
xhr.addEventListener("timeout", () => {
|
|
153
|
+
reject(new Error("Part upload timed out"));
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Convert Buffer to Blob if needed.
|
|
157
|
+
let body;
|
|
158
|
+
if (isBuffer(chunk)) {
|
|
159
|
+
// Buffer is a Uint8Array, so we can pass it to Blob.
|
|
160
|
+
// Use 'as any' to work around TypeScript's strict type checking for ArrayBufferLike.
|
|
161
|
+
body = new Blob([chunk]);
|
|
162
|
+
} else {
|
|
163
|
+
body = chunk;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Send request.
|
|
167
|
+
xhr.open("PUT", url);
|
|
168
|
+
xhr.send(body);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Upload part using fetch (Node.js and browser).
|
|
174
|
+
*/
|
|
175
|
+
async function uploadPartWithFetch(url, chunk, signal) {
|
|
176
|
+
const response = await fetch(url, {
|
|
177
|
+
method: "PUT",
|
|
178
|
+
body: chunk,
|
|
179
|
+
signal
|
|
180
|
+
});
|
|
181
|
+
if (response.status !== 200) {
|
|
182
|
+
const text = await response.text();
|
|
183
|
+
throw new Error(`Part upload failed with status ${response.status}: ${text}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
//# sourceMappingURL=uploadLargeFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isBrowser","isBuffer","isFile","getFileSize","uploadLargeFile","file","fileData","config","fetchFn","options","onProgress","signal","chunkSize","parallelUploads","fileSize","chunkSizeBytes","Math","max","numberOfParts","ceil","createMultiPartUpload","createResult","data","isFail","error","uploadData","value","progressTracker","Map","updateProgress","uploaded","Array","from","values","reduce","sum","uploadedSize","min","sent","total","percentage","round","pMap","default","pRetry","parts","part","aborted","Error","chunk","getFileChunk","partNumber","type","uploadPart","url","loaded","set","retries","minTimeout","maxTimeout","maxRetryTime","concurrency","completeMultiPartUpload","completeResult","fileKey","key","uploadId","fileType","start","end","slice","Blob","XMLHttpRequest","uploadPartWithXHR","uploadPartWithFetch","Promise","resolve","reject","xhr","addEventListener","abort","upload","event","lengthComputable","readyState","status","body","open","send","response","fetch","method","text"],"sources":["uploadLargeFile.ts"],"sourcesContent":["import type { WebinyConfig } from \"../../../types.js\";\nimport type { FmFile, UploadProgress } from \"../fileManagerTypes.js\";\nimport { isBrowser } from \"../../../utils/platform.js\";\nimport { isBuffer, isFile, getFileSize } from \"./fileTypeDetection.js\";\n\nexport interface UploadLargeFileOptions {\n onProgress?: (progress: UploadProgress) => void;\n signal?: AbortSignal;\n chunkSize?: number;\n parallelUploads?: number;\n}\n\n/**\n * Uploads a large file to S3 using multi-part upload.\n *\n * @param file - The file to upload (Buffer, Blob, or File)\n * @param fileData - File metadata\n * @param config - SDK configuration\n * @param fetchFn - Fetch function to use for HTTP requests\n * @param options - Upload options\n * @returns Promise that resolves with the uploaded file metadata\n */\nexport async function uploadLargeFile(\n file: Buffer | Blob | File,\n fileData: { name: string; type: string; size: number; key?: string; keyPrefix?: string },\n config: WebinyConfig,\n fetchFn: typeof fetch,\n options: UploadLargeFileOptions = {}\n): Promise<FmFile> {\n const { onProgress, signal, chunkSize = 50, parallelUploads = 5 } = options;\n\n const fileSize = getFileSize(file);\n const chunkSizeBytes = Math.max(chunkSize * 1024 * 1024, 5 * 1024 * 1024);\n const numberOfParts = Math.ceil(fileSize / chunkSizeBytes);\n\n // 1. Create multi-part upload.\n const { createMultiPartUpload } = await import(\"../createMultiPartUpload.js\");\n const createResult = await createMultiPartUpload(config, fetchFn, {\n data: fileData,\n numberOfParts\n });\n\n if (createResult.isFail()) {\n throw createResult.error;\n }\n\n const uploadData = createResult.value;\n const progressTracker = new Map<number, number>();\n\n // Helper to track progress.\n const updateProgress = () => {\n if (!onProgress) {\n return;\n }\n\n const uploaded = Array.from(progressTracker.values()).reduce(\n (sum, value) => sum + value,\n 0\n );\n const uploadedSize = Math.min(uploaded, fileSize);\n\n onProgress({\n sent: uploadedSize,\n total: fileSize,\n percentage: Math.round((uploadedSize / fileSize) * 100)\n });\n };\n\n // 2. Upload parts in parallel.\n const pMap = (await import(\"p-map\")).default;\n const pRetry = (await import(\"p-retry\")).default;\n\n await pMap(\n uploadData.parts,\n async (part: { partNumber: number; url: string }) => {\n // Check abort signal.\n if (signal?.aborted) {\n throw new Error(\"Upload aborted\");\n }\n\n // Upload part with retry.\n await pRetry(\n async () => {\n const chunk = await getFileChunk(\n file,\n part.partNumber,\n chunkSizeBytes,\n fileData.type\n );\n\n await uploadPart(\n part.url,\n chunk,\n loaded => {\n progressTracker.set(part.partNumber, loaded);\n updateProgress();\n },\n signal\n );\n },\n {\n retries: 5,\n minTimeout: 1500,\n maxTimeout: 30000,\n maxRetryTime: 300000\n }\n );\n },\n { concurrency: Math.min(numberOfParts, parallelUploads) }\n );\n\n // 3. Complete multi-part upload.\n const { completeMultiPartUpload } = await import(\"../completeMultiPartUpload.js\");\n const completeResult = await completeMultiPartUpload(config, fetchFn, {\n fileKey: uploadData.file.key,\n uploadId: uploadData.uploadId\n });\n\n if (completeResult.isFail()) {\n throw completeResult.error;\n }\n\n // Return the file metadata.\n return uploadData.file as FmFile;\n}\n\n/**\n * Gets a chunk of the file for a specific part number.\n */\nasync function getFileChunk(\n file: Buffer | Blob | File,\n partNumber: number,\n chunkSize: number,\n fileType: string\n): Promise<Blob | Buffer> {\n const start = (partNumber - 1) * chunkSize;\n const end = Math.min(start + chunkSize, getFileSize(file));\n\n if (isBuffer(file)) {\n return file.slice(start, end);\n }\n\n if (isFile(file) || file instanceof Blob) {\n return file.slice(start, end, fileType);\n }\n\n throw new Error(\"Unsupported file type\");\n}\n\n/**\n * Uploads a single part to S3.\n */\nasync function uploadPart(\n url: string,\n chunk: Blob | Buffer,\n onProgress: (loaded: number) => void,\n signal?: AbortSignal\n): Promise<void> {\n if (isBrowser && typeof XMLHttpRequest !== \"undefined\") {\n return uploadPartWithXHR(url, chunk, onProgress, signal);\n }\n\n return uploadPartWithFetch(url, chunk, signal);\n}\n\n/**\n * Upload part using XMLHttpRequest (browser only, supports progress).\n */\nfunction uploadPartWithXHR(\n url: string,\n chunk: Blob | Buffer,\n onProgress: (loaded: number) => void,\n signal?: AbortSignal\n): Promise<void> {\n return new Promise((resolve, reject) => {\n const xhr = new XMLHttpRequest();\n\n // Handle abort signal.\n if (signal) {\n signal.addEventListener(\"abort\", () => xhr.abort());\n }\n\n // Track upload progress.\n xhr.upload.addEventListener(\"progress\", (event: ProgressEvent) => {\n if (event.lengthComputable) {\n onProgress(event.loaded);\n }\n });\n\n // Handle completion.\n xhr.addEventListener(\"readystatechange\", () => {\n if (xhr.readyState === 4 && xhr.status === 200) {\n resolve();\n }\n });\n\n // Handle errors.\n xhr.addEventListener(\"error\", () => {\n reject(new Error(\"Part upload failed due to network error\"));\n });\n\n xhr.addEventListener(\"abort\", () => {\n reject(new Error(\"Part upload aborted\"));\n });\n\n xhr.addEventListener(\"timeout\", () => {\n reject(new Error(\"Part upload timed out\"));\n });\n\n // Convert Buffer to Blob if needed.\n let body: Blob;\n if (isBuffer(chunk)) {\n // Buffer is a Uint8Array, so we can pass it to Blob.\n // Use 'as any' to work around TypeScript's strict type checking for ArrayBufferLike.\n body = new Blob([chunk as any]);\n } else {\n body = chunk;\n }\n\n // Send request.\n xhr.open(\"PUT\", url);\n xhr.send(body);\n });\n}\n\n/**\n * Upload part using fetch (Node.js and browser).\n */\nasync function uploadPartWithFetch(\n url: string,\n chunk: Blob | Buffer,\n signal?: AbortSignal\n): Promise<void> {\n const response = await fetch(url, {\n method: \"PUT\",\n body: chunk as any,\n signal\n });\n\n if (response.status !== 200) {\n const text = await response.text();\n throw new Error(`Part upload failed with status ${response.status}: ${text}`);\n }\n}\n"],"mappings":"AAEA,SAASA,SAAS;AAClB,SAASC,QAAQ,EAAEC,MAAM,EAAEC,WAAW;AAStC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,eAAeA,CACjCC,IAA0B,EAC1BC,QAAwF,EACxFC,MAAoB,EACpBC,OAAqB,EACrBC,OAA+B,GAAG,CAAC,CAAC,EACrB;EACf,MAAM;IAAEC,UAAU;IAAEC,MAAM;IAAEC,SAAS,GAAG,EAAE;IAAEC,eAAe,GAAG;EAAE,CAAC,GAAGJ,OAAO;EAE3E,MAAMK,QAAQ,GAAGX,WAAW,CAACE,IAAI,CAAC;EAClC,MAAMU,cAAc,GAAGC,IAAI,CAACC,GAAG,CAACL,SAAS,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;EACzE,MAAMM,aAAa,GAAGF,IAAI,CAACG,IAAI,CAACL,QAAQ,GAAGC,cAAc,CAAC;;EAE1D;EACA,MAAM;IAAEK;EAAsB,CAAC,GAAG,MAAM,MAAM,8BAA8B,CAAC;EAC7E,MAAMC,YAAY,GAAG,MAAMD,qBAAqB,CAACb,MAAM,EAAEC,OAAO,EAAE;IAC9Dc,IAAI,EAAEhB,QAAQ;IACdY;EACJ,CAAC,CAAC;EAEF,IAAIG,YAAY,CAACE,MAAM,CAAC,CAAC,EAAE;I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export interface UploadToS3Options {
|
|
3
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Uploads a file to S3 using a presigned POST payload.
|
|
8
|
+
*
|
|
9
|
+
* @param file - The file to upload (Buffer, Blob, or File)
|
|
10
|
+
* @param presignedPost - The presigned POST payload from S3
|
|
11
|
+
* @param options - Upload options (progress callback, abort signal)
|
|
12
|
+
* @returns Promise that resolves when upload is complete
|
|
13
|
+
*/
|
|
14
|
+
export declare function uploadToS3(file: Buffer | Blob | File, presignedPost: PresignedPostPayload, options?: UploadToS3Options): Promise<void>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { isBrowser } from "../../../utils/platform.js";
|
|
2
|
+
import { isBuffer } from "./fileTypeDetection.js";
|
|
3
|
+
/**
|
|
4
|
+
* Uploads a file to S3 using a presigned POST payload.
|
|
5
|
+
*
|
|
6
|
+
* @param file - The file to upload (Buffer, Blob, or File)
|
|
7
|
+
* @param presignedPost - The presigned POST payload from S3
|
|
8
|
+
* @param options - Upload options (progress callback, abort signal)
|
|
9
|
+
* @returns Promise that resolves when upload is complete
|
|
10
|
+
*/
|
|
11
|
+
export async function uploadToS3(file, presignedPost, options = {}) {
|
|
12
|
+
const {
|
|
13
|
+
onProgress,
|
|
14
|
+
signal
|
|
15
|
+
} = options;
|
|
16
|
+
|
|
17
|
+
// Build FormData.
|
|
18
|
+
const formData = new FormData();
|
|
19
|
+
|
|
20
|
+
// Append all presigned POST fields.
|
|
21
|
+
for (const [key, value] of Object.entries(presignedPost.fields)) {
|
|
22
|
+
formData.append(key, value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Append the file.
|
|
26
|
+
if (isBuffer(file)) {
|
|
27
|
+
// Convert Buffer to Blob for FormData.
|
|
28
|
+
// Buffer is a Uint8Array, so we can pass it to Blob.
|
|
29
|
+
// Use 'as any' to work around TypeScript's strict type checking for ArrayBufferLike.
|
|
30
|
+
formData.append("file", new Blob([file]));
|
|
31
|
+
} else {
|
|
32
|
+
formData.append("file", file);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Use XMLHttpRequest in browser for progress tracking.
|
|
36
|
+
if (isBrowser && onProgress) {
|
|
37
|
+
return uploadWithXHR(presignedPost.url, formData, onProgress, signal);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Use fetch in Node.js or browser without progress.
|
|
41
|
+
return uploadWithFetch(presignedPost.url, formData, signal);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Upload using XMLHttpRequest (browser only, supports progress).
|
|
46
|
+
*/
|
|
47
|
+
function uploadWithXHR(url, formData, onProgress, signal) {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const xhr = new XMLHttpRequest();
|
|
50
|
+
|
|
51
|
+
// Handle abort signal.
|
|
52
|
+
if (signal) {
|
|
53
|
+
signal.addEventListener("abort", () => xhr.abort());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Track upload progress.
|
|
57
|
+
xhr.upload.addEventListener("progress", event => {
|
|
58
|
+
if (event.lengthComputable) {
|
|
59
|
+
onProgress({
|
|
60
|
+
sent: event.loaded,
|
|
61
|
+
total: event.total,
|
|
62
|
+
percentage: Math.round(event.loaded / event.total * 100)
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Handle completion.
|
|
68
|
+
xhr.addEventListener("load", () => {
|
|
69
|
+
if (xhr.status === 204) {
|
|
70
|
+
resolve();
|
|
71
|
+
} else {
|
|
72
|
+
reject(new Error(`Upload failed with status ${xhr.status}: ${xhr.responseText}`));
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Handle errors.
|
|
77
|
+
xhr.addEventListener("error", () => {
|
|
78
|
+
reject(new Error("Upload failed due to network error"));
|
|
79
|
+
});
|
|
80
|
+
xhr.addEventListener("abort", () => {
|
|
81
|
+
reject(new Error("Upload aborted"));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Send request.
|
|
85
|
+
xhr.open("POST", url, true);
|
|
86
|
+
xhr.send(formData);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Upload using fetch (Node.js and browser).
|
|
92
|
+
*/
|
|
93
|
+
async function uploadWithFetch(url, formData, signal) {
|
|
94
|
+
const response = await fetch(url, {
|
|
95
|
+
method: "POST",
|
|
96
|
+
body: formData,
|
|
97
|
+
signal
|
|
98
|
+
});
|
|
99
|
+
if (response.status !== 204) {
|
|
100
|
+
const text = await response.text();
|
|
101
|
+
throw new Error(`Upload failed with status ${response.status}: ${text}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=uploadToS3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isBrowser","isBuffer","uploadToS3","file","presignedPost","options","onProgress","signal","formData","FormData","key","value","Object","entries","fields","append","Blob","uploadWithXHR","url","uploadWithFetch","Promise","resolve","reject","xhr","XMLHttpRequest","addEventListener","abort","upload","event","lengthComputable","sent","loaded","total","percentage","Math","round","status","Error","responseText","open","send","response","fetch","method","body","text"],"sources":["uploadToS3.ts"],"sourcesContent":["import type { PresignedPostPayload, UploadProgress } from \"../fileManagerTypes.js\";\nimport { isBrowser } from \"../../../utils/platform.js\";\nimport { isBuffer } from \"./fileTypeDetection.js\";\n\nexport interface UploadToS3Options {\n onProgress?: (progress: UploadProgress) => void;\n signal?: AbortSignal;\n}\n\n/**\n * Uploads a file to S3 using a presigned POST payload.\n *\n * @param file - The file to upload (Buffer, Blob, or File)\n * @param presignedPost - The presigned POST payload from S3\n * @param options - Upload options (progress callback, abort signal)\n * @returns Promise that resolves when upload is complete\n */\nexport async function uploadToS3(\n file: Buffer | Blob | File,\n presignedPost: PresignedPostPayload,\n options: UploadToS3Options = {}\n): Promise<void> {\n const { onProgress, signal } = options;\n\n // Build FormData.\n const formData = new FormData();\n\n // Append all presigned POST fields.\n for (const [key, value] of Object.entries(presignedPost.fields)) {\n formData.append(key, value);\n }\n\n // Append the file.\n if (isBuffer(file)) {\n // Convert Buffer to Blob for FormData.\n // Buffer is a Uint8Array, so we can pass it to Blob.\n // Use 'as any' to work around TypeScript's strict type checking for ArrayBufferLike.\n formData.append(\"file\", new Blob([file as any]));\n } else {\n formData.append(\"file\", file);\n }\n\n // Use XMLHttpRequest in browser for progress tracking.\n if (isBrowser && onProgress) {\n return uploadWithXHR(presignedPost.url, formData, onProgress, signal);\n }\n\n // Use fetch in Node.js or browser without progress.\n return uploadWithFetch(presignedPost.url, formData, signal);\n}\n\n/**\n * Upload using XMLHttpRequest (browser only, supports progress).\n */\nfunction uploadWithXHR(\n url: string,\n formData: FormData,\n onProgress: (progress: UploadProgress) => void,\n signal?: AbortSignal\n): Promise<void> {\n return new Promise((resolve, reject) => {\n const xhr = new XMLHttpRequest();\n\n // Handle abort signal.\n if (signal) {\n signal.addEventListener(\"abort\", () => xhr.abort());\n }\n\n // Track upload progress.\n xhr.upload.addEventListener(\"progress\", (event: ProgressEvent) => {\n if (event.lengthComputable) {\n onProgress({\n sent: event.loaded,\n total: event.total,\n percentage: Math.round((event.loaded / event.total) * 100)\n });\n }\n });\n\n // Handle completion.\n xhr.addEventListener(\"load\", () => {\n if (xhr.status === 204) {\n resolve();\n } else {\n reject(new Error(`Upload failed with status ${xhr.status}: ${xhr.responseText}`));\n }\n });\n\n // Handle errors.\n xhr.addEventListener(\"error\", () => {\n reject(new Error(\"Upload failed due to network error\"));\n });\n\n xhr.addEventListener(\"abort\", () => {\n reject(new Error(\"Upload aborted\"));\n });\n\n // Send request.\n xhr.open(\"POST\", url, true);\n xhr.send(formData);\n });\n}\n\n/**\n * Upload using fetch (Node.js and browser).\n */\nasync function uploadWithFetch(\n url: string,\n formData: FormData,\n signal?: AbortSignal\n): Promise<void> {\n const response = await fetch(url, {\n method: \"POST\",\n body: formData,\n signal\n });\n\n if (response.status !== 204) {\n const text = await response.text();\n throw new Error(`Upload failed with status ${response.status}: ${text}`);\n }\n}\n"],"mappings":"AACA,SAASA,SAAS;AAClB,SAASC,QAAQ;AAOjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,UAAUA,CAC5BC,IAA0B,EAC1BC,aAAmC,EACnCC,OAA0B,GAAG,CAAC,CAAC,EAClB;EACb,MAAM;IAAEC,UAAU;IAAEC;EAAO,CAAC,GAAGF,OAAO;;EAEtC;EACA,MAAMG,QAAQ,GAAG,IAAIC,QAAQ,CAAC,CAAC;;EAE/B;EACA,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACT,aAAa,CAACU,MAAM,CAAC,EAAE;IAC7DN,QAAQ,CAACO,MAAM,CAACL,GAAG,EAAEC,KAAK,CAAC;EAC/B;;EAEA;EACA,IAAIV,QAAQ,CAACE,IAAI,CAAC,EAAE;IAChB;IACA;IACA;IACAK,QAAQ,CAACO,MAAM,CAAC,MAAM,EAAE,IAAIC,IAAI,CAAC,CAACb,IAAI,CAAQ,CAAC,CAAC;EACpD,CAAC,MAAM;IACHK,QAAQ,CAACO,MAAM,CAAC,MAAM,EAAEZ,IAAI,CAAC;EACjC;;EAEA;EACA,IAAIH,SAAS,IAAIM,UAAU,EAAE;IACzB,OAAOW,aAAa,CAACb,aAAa,CAACc,GAAG,EAAEV,QAAQ,EAAEF,UAAU,EAAEC,MAAM,CAAC;EACzE;;EAEA;EACA,OAAOY,eAAe,CAACf,aAAa,CAACc,GAAG,EAAEV,QAAQ,EAAED,MAAM,CAAC;AAC/D;;AAEA;AACA;AACA;AACA,SAASU,aAAaA,CAClBC,GAAW,EACXV,QAAkB,EAClBF,UAA8C,EAC9CC,MAAoB,EACP;EACb,OAAO,IAAIa,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACpC,M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EA;AACA;AACA;AACA,eAAeW,eAAeA,CAC1BD,GAAW,EACXV,QAAkB,EAClBD,MAAoB,EACP;EACb,MAAMkC,QAAQ,GAAG,MAAMC,KAAK,CAACxB,GAAG,EAAE;IAC9ByB,MAAM,EAAE,MAAM;IACdC,IAAI,EAAEpC,QAAQ;IACdD;EACJ,CAAC,CAAC;EAEF,IAAIkC,QAAQ,CAACL,MAAM,KAAK,GAAG,EAAE;IACzB,MAAMS,IAAI,GAAG,MAAMJ,QAAQ,CAACI,IAAI,CAAC,CAAC;IAClC,MAAM,IAAIR,KAAK,CAAC,6BAA6BI,QAAQ,CAACL,MAAM,KAAKS,IAAI,EAAE,CAAC;EAC5E;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { WebinyConfig } from "../../types.js";
|
|
2
|
+
import { Result } from "../../Result.js";
|
|
3
|
+
import type { HttpError, GraphQLError, NetworkError } from "../../errors.js";
|
|
4
|
+
import type { CreateTenantInput } from "./tenantManagerTypes.js";
|
|
5
|
+
export interface CreateTenantParams {
|
|
6
|
+
data: CreateTenantInput;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new tenant in the system.
|
|
10
|
+
*
|
|
11
|
+
* @param config - SDK configuration
|
|
12
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
13
|
+
* @param params - Parameters for creating the tenant
|
|
14
|
+
* @param params.data - The tenant data to create
|
|
15
|
+
* @returns Result containing true on success or an error
|
|
16
|
+
*/
|
|
17
|
+
export declare function createTenant(config: WebinyConfig, fetchFn: typeof fetch, params: CreateTenantParams): Promise<Result<boolean, HttpError | GraphQLError | NetworkError>>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Result } from "../../Result.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new tenant in the system.
|
|
4
|
+
*
|
|
5
|
+
* @param config - SDK configuration
|
|
6
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
7
|
+
* @param params - Parameters for creating the tenant
|
|
8
|
+
* @param params.data - The tenant data to create
|
|
9
|
+
* @returns Result containing true on success or an error
|
|
10
|
+
*/
|
|
11
|
+
export async function createTenant(config, fetchFn, params) {
|
|
12
|
+
const {
|
|
13
|
+
data
|
|
14
|
+
} = params;
|
|
15
|
+
const {
|
|
16
|
+
executeGraphQL
|
|
17
|
+
} = await import("../executeGraphQL.js");
|
|
18
|
+
const query = `
|
|
19
|
+
mutation CreateTenant($input: CreateTenantInput!) {
|
|
20
|
+
tenantManager {
|
|
21
|
+
createTenant(input: $input) {
|
|
22
|
+
data
|
|
23
|
+
error {
|
|
24
|
+
message
|
|
25
|
+
code
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
const result = await executeGraphQL(config, fetchFn, query, {
|
|
32
|
+
input: data
|
|
33
|
+
});
|
|
34
|
+
if (result.isFail()) {
|
|
35
|
+
return Result.fail(result.error);
|
|
36
|
+
}
|
|
37
|
+
const responseData = result.value;
|
|
38
|
+
if (responseData.tenantManager.createTenant.error) {
|
|
39
|
+
const {
|
|
40
|
+
GraphQLError
|
|
41
|
+
} = await import("../../errors.js");
|
|
42
|
+
return Result.fail(new GraphQLError(responseData.tenantManager.createTenant.error.message, responseData.tenantManager.createTenant.error.code));
|
|
43
|
+
}
|
|
44
|
+
return Result.ok(responseData.tenantManager.createTenant.data);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=createTenant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","createTenant","config","fetchFn","params","data","executeGraphQL","query","result","input","isFail","fail","error","responseData","value","tenantManager","GraphQLError","message","code","ok"],"sources":["createTenant.ts"],"sourcesContent":["import type { WebinyConfig } from \"../../types.js\";\nimport { Result } from \"../../Result.js\";\nimport type { HttpError, GraphQLError, NetworkError } from \"../../errors.js\";\nimport type { CreateTenantInput } from \"./tenantManagerTypes.js\";\n\nexport interface CreateTenantParams {\n data: CreateTenantInput;\n}\n\n/**\n * Creates a new tenant in the system.\n *\n * @param config - SDK configuration\n * @param fetchFn - Fetch function to use for HTTP requests\n * @param params - Parameters for creating the tenant\n * @param params.data - The tenant data to create\n * @returns Result containing true on success or an error\n */\nexport async function createTenant(\n config: WebinyConfig,\n fetchFn: typeof fetch,\n params: CreateTenantParams\n): Promise<Result<boolean, HttpError | GraphQLError | NetworkError>> {\n const { data } = params;\n\n const { executeGraphQL } = await import(\"../executeGraphQL.js\");\n\n const query = `\n mutation CreateTenant($input: CreateTenantInput!) {\n tenantManager {\n createTenant(input: $input) {\n data\n error {\n message\n code\n }\n }\n }\n }\n `;\n\n const result = await executeGraphQL(config, fetchFn, query, { input: data });\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const responseData = result.value;\n\n if (responseData.tenantManager.createTenant.error) {\n const { GraphQLError } = await import(\"../../errors.js\");\n return Result.fail(\n new GraphQLError(\n responseData.tenantManager.createTenant.error.message,\n responseData.tenantManager.createTenant.error.code\n )\n );\n }\n\n return Result.ok(responseData.tenantManager.createTenant.data);\n}\n"],"mappings":"AACA,SAASA,MAAM;AAQf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,YAAYA,CAC9BC,MAAoB,EACpBC,OAAqB,EACrBC,MAA0B,EACuC;EACjE,MAAM;IAAEC;EAAK,CAAC,GAAGD,MAAM;EAEvB,MAAM;IAAEE;EAAe,CAAC,GAAG,MAAM,MAAM,uBAAuB,CAAC;EAE/D,MAAMC,KAAK,GAAG;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;EAED,MAAMC,MAAM,GAAG,MAAMF,cAAc,CAACJ,MAAM,EAAEC,OAAO,EAAEI,KAAK,EAAE;IAAEE,KAAK,EAAEJ;EAAK,CAAC,CAAC;EAE5E,IAAIG,MAAM,CAACE,MAAM,CAAC,CAAC,EAAE;IACjB,OAAOV,MAAM,CAACW,IAAI,CAACH,MAAM,CAACI,KAAK,CAAC;EACpC;EAEA,MAAMC,YAAY,GAAGL,MAAM,CAACM,KAAK;EAEjC,IAAID,YAAY,CAACE,aAAa,CAACd,YAAY,CAACW,KAAK,EAAE;IAC/C,MAAM;MAAEI;IAAa,CAAC,GAAG,MAAM,MAAM,kBAAkB,CAAC;IACxD,OAAOhB,MAAM,CAACW,IAAI,CACd,IAAIK,YAAY,CACZH,YAAY,CAACE,aAAa,CAACd,YAAY,CAACW,KAAK,CAACK,OAAO,EACrDJ,YAAY,CAACE,aAAa,CAACd,YAAY,CAACW,KAAK,CAACM,IAClD,CACJ,CAAC;EACL;EAEA,OAAOlB,MAAM,CAACmB,EAAE,CAACN,YAAY,CAACE,aAAa,CAACd,YAAY,CAACI,IAAI,CAAC;AAClE","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { WebinyConfig } from "../../types.js";
|
|
2
|
+
import { Result } from "../../Result.js";
|
|
3
|
+
import type { HttpError, GraphQLError, NetworkError } from "../../errors.js";
|
|
4
|
+
export interface DisableTenantParams {
|
|
5
|
+
tenantId: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Disables a tenant, preventing access to its resources.
|
|
9
|
+
*
|
|
10
|
+
* @param config - SDK configuration
|
|
11
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
12
|
+
* @param params - Parameters for disabling the tenant
|
|
13
|
+
* @param params.tenantId - ID of the tenant to disable
|
|
14
|
+
* @returns Result containing true on success or an error
|
|
15
|
+
*/
|
|
16
|
+
export declare function disableTenant(config: WebinyConfig, fetchFn: typeof fetch, params: DisableTenantParams): Promise<Result<boolean, HttpError | GraphQLError | NetworkError>>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Result } from "../../Result.js";
|
|
2
|
+
/**
|
|
3
|
+
* Disables a tenant, preventing access to its resources.
|
|
4
|
+
*
|
|
5
|
+
* @param config - SDK configuration
|
|
6
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
7
|
+
* @param params - Parameters for disabling the tenant
|
|
8
|
+
* @param params.tenantId - ID of the tenant to disable
|
|
9
|
+
* @returns Result containing true on success or an error
|
|
10
|
+
*/
|
|
11
|
+
export async function disableTenant(config, fetchFn, params) {
|
|
12
|
+
const {
|
|
13
|
+
tenantId
|
|
14
|
+
} = params;
|
|
15
|
+
const {
|
|
16
|
+
executeGraphQL
|
|
17
|
+
} = await import("../executeGraphQL.js");
|
|
18
|
+
const query = `
|
|
19
|
+
mutation DisableTenant($tenantId: ID!) {
|
|
20
|
+
tenantManager {
|
|
21
|
+
disableTenant(tenantId: $tenantId) {
|
|
22
|
+
data
|
|
23
|
+
error {
|
|
24
|
+
message
|
|
25
|
+
code
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
const result = await executeGraphQL(config, fetchFn, query, {
|
|
32
|
+
tenantId
|
|
33
|
+
});
|
|
34
|
+
if (result.isFail()) {
|
|
35
|
+
return Result.fail(result.error);
|
|
36
|
+
}
|
|
37
|
+
const responseData = result.value;
|
|
38
|
+
if (responseData.tenantManager.disableTenant.error) {
|
|
39
|
+
const {
|
|
40
|
+
GraphQLError
|
|
41
|
+
} = await import("../../errors.js");
|
|
42
|
+
return Result.fail(new GraphQLError(responseData.tenantManager.disableTenant.error.message, responseData.tenantManager.disableTenant.error.code));
|
|
43
|
+
}
|
|
44
|
+
return Result.ok(responseData.tenantManager.disableTenant.data);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=disableTenant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","disableTenant","config","fetchFn","params","tenantId","executeGraphQL","query","result","isFail","fail","error","responseData","value","tenantManager","GraphQLError","message","code","ok","data"],"sources":["disableTenant.ts"],"sourcesContent":["import type { WebinyConfig } from \"../../types.js\";\nimport { Result } from \"../../Result.js\";\nimport type { HttpError, GraphQLError, NetworkError } from \"../../errors.js\";\n\nexport interface DisableTenantParams {\n tenantId: string;\n}\n\n/**\n * Disables a tenant, preventing access to its resources.\n *\n * @param config - SDK configuration\n * @param fetchFn - Fetch function to use for HTTP requests\n * @param params - Parameters for disabling the tenant\n * @param params.tenantId - ID of the tenant to disable\n * @returns Result containing true on success or an error\n */\nexport async function disableTenant(\n config: WebinyConfig,\n fetchFn: typeof fetch,\n params: DisableTenantParams\n): Promise<Result<boolean, HttpError | GraphQLError | NetworkError>> {\n const { tenantId } = params;\n\n const { executeGraphQL } = await import(\"../executeGraphQL.js\");\n\n const query = `\n mutation DisableTenant($tenantId: ID!) {\n tenantManager {\n disableTenant(tenantId: $tenantId) {\n data\n error {\n message\n code\n }\n }\n }\n }\n `;\n\n const result = await executeGraphQL(config, fetchFn, query, { tenantId });\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const responseData = result.value;\n\n if (responseData.tenantManager.disableTenant.error) {\n const { GraphQLError } = await import(\"../../errors.js\");\n return Result.fail(\n new GraphQLError(\n responseData.tenantManager.disableTenant.error.message,\n responseData.tenantManager.disableTenant.error.code\n )\n );\n }\n\n return Result.ok(responseData.tenantManager.disableTenant.data);\n}\n"],"mappings":"AACA,SAASA,MAAM;AAOf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,aAAaA,CAC/BC,MAAoB,EACpBC,OAAqB,EACrBC,MAA2B,EACsC;EACjE,MAAM;IAAEC;EAAS,CAAC,GAAGD,MAAM;EAE3B,MAAM;IAAEE;EAAe,CAAC,GAAG,MAAM,MAAM,uBAAuB,CAAC;EAE/D,MAAMC,KAAK,GAAG;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;EAED,MAAMC,MAAM,GAAG,MAAMF,cAAc,CAACJ,MAAM,EAAEC,OAAO,EAAEI,KAAK,EAAE;IAAEF;EAAS,CAAC,CAAC;EAEzE,IAAIG,MAAM,CAACC,MAAM,CAAC,CAAC,EAAE;IACjB,OAAOT,MAAM,CAACU,IAAI,CAACF,MAAM,CAACG,KAAK,CAAC;EACpC;EAEA,MAAMC,YAAY,GAAGJ,MAAM,CAACK,KAAK;EAEjC,IAAID,YAAY,CAACE,aAAa,CAACb,aAAa,CAACU,KAAK,EAAE;IAChD,MAAM;MAAEI;IAAa,CAAC,GAAG,MAAM,MAAM,kBAAkB,CAAC;IACxD,OAAOf,MAAM,CAACU,IAAI,CACd,IAAIK,YAAY,CACZH,YAAY,CAACE,aAAa,CAACb,aAAa,CAACU,KAAK,CAACK,OAAO,EACtDJ,YAAY,CAACE,aAAa,CAACb,aAAa,CAACU,KAAK,CAACM,IACnD,CACJ,CAAC;EACL;EAEA,OAAOjB,MAAM,CAACkB,EAAE,CAACN,YAAY,CAACE,aAAa,CAACb,aAAa,CAACkB,IAAI,CAAC;AACnE","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { WebinyConfig } from "../../types.js";
|
|
2
|
+
import { Result } from "../../Result.js";
|
|
3
|
+
import type { HttpError, GraphQLError, NetworkError } from "../../errors.js";
|
|
4
|
+
export interface EnableTenantParams {
|
|
5
|
+
tenantId: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Re-enables a previously disabled tenant.
|
|
9
|
+
*
|
|
10
|
+
* @param config - SDK configuration
|
|
11
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
12
|
+
* @param params - Parameters for enabling the tenant
|
|
13
|
+
* @param params.tenantId - ID of the tenant to enable
|
|
14
|
+
* @returns Result containing true on success or an error
|
|
15
|
+
*/
|
|
16
|
+
export declare function enableTenant(config: WebinyConfig, fetchFn: typeof fetch, params: EnableTenantParams): Promise<Result<boolean, HttpError | GraphQLError | NetworkError>>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Result } from "../../Result.js";
|
|
2
|
+
/**
|
|
3
|
+
* Re-enables a previously disabled tenant.
|
|
4
|
+
*
|
|
5
|
+
* @param config - SDK configuration
|
|
6
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
7
|
+
* @param params - Parameters for enabling the tenant
|
|
8
|
+
* @param params.tenantId - ID of the tenant to enable
|
|
9
|
+
* @returns Result containing true on success or an error
|
|
10
|
+
*/
|
|
11
|
+
export async function enableTenant(config, fetchFn, params) {
|
|
12
|
+
const {
|
|
13
|
+
tenantId
|
|
14
|
+
} = params;
|
|
15
|
+
const {
|
|
16
|
+
executeGraphQL
|
|
17
|
+
} = await import("../executeGraphQL.js");
|
|
18
|
+
const query = `
|
|
19
|
+
mutation EnableTenant($tenantId: ID!) {
|
|
20
|
+
tenantManager {
|
|
21
|
+
enableTenant(tenantId: $tenantId) {
|
|
22
|
+
data
|
|
23
|
+
error {
|
|
24
|
+
message
|
|
25
|
+
code
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
const result = await executeGraphQL(config, fetchFn, query, {
|
|
32
|
+
tenantId
|
|
33
|
+
});
|
|
34
|
+
if (result.isFail()) {
|
|
35
|
+
return Result.fail(result.error);
|
|
36
|
+
}
|
|
37
|
+
const responseData = result.value;
|
|
38
|
+
if (responseData.tenantManager.enableTenant.error) {
|
|
39
|
+
const {
|
|
40
|
+
GraphQLError
|
|
41
|
+
} = await import("../../errors.js");
|
|
42
|
+
return Result.fail(new GraphQLError(responseData.tenantManager.enableTenant.error.message, responseData.tenantManager.enableTenant.error.code));
|
|
43
|
+
}
|
|
44
|
+
return Result.ok(responseData.tenantManager.enableTenant.data);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=enableTenant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","enableTenant","config","fetchFn","params","tenantId","executeGraphQL","query","result","isFail","fail","error","responseData","value","tenantManager","GraphQLError","message","code","ok","data"],"sources":["enableTenant.ts"],"sourcesContent":["import type { WebinyConfig } from \"../../types.js\";\nimport { Result } from \"../../Result.js\";\nimport type { HttpError, GraphQLError, NetworkError } from \"../../errors.js\";\n\nexport interface EnableTenantParams {\n tenantId: string;\n}\n\n/**\n * Re-enables a previously disabled tenant.\n *\n * @param config - SDK configuration\n * @param fetchFn - Fetch function to use for HTTP requests\n * @param params - Parameters for enabling the tenant\n * @param params.tenantId - ID of the tenant to enable\n * @returns Result containing true on success or an error\n */\nexport async function enableTenant(\n config: WebinyConfig,\n fetchFn: typeof fetch,\n params: EnableTenantParams\n): Promise<Result<boolean, HttpError | GraphQLError | NetworkError>> {\n const { tenantId } = params;\n\n const { executeGraphQL } = await import(\"../executeGraphQL.js\");\n\n const query = `\n mutation EnableTenant($tenantId: ID!) {\n tenantManager {\n enableTenant(tenantId: $tenantId) {\n data\n error {\n message\n code\n }\n }\n }\n }\n `;\n\n const result = await executeGraphQL(config, fetchFn, query, { tenantId });\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const responseData = result.value;\n\n if (responseData.tenantManager.enableTenant.error) {\n const { GraphQLError } = await import(\"../../errors.js\");\n return Result.fail(\n new GraphQLError(\n responseData.tenantManager.enableTenant.error.message,\n responseData.tenantManager.enableTenant.error.code\n )\n );\n }\n\n return Result.ok(responseData.tenantManager.enableTenant.data);\n}\n"],"mappings":"AACA,SAASA,MAAM;AAOf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,YAAYA,CAC9BC,MAAoB,EACpBC,OAAqB,EACrBC,MAA0B,EACuC;EACjE,MAAM;IAAEC;EAAS,CAAC,GAAGD,MAAM;EAE3B,MAAM;IAAEE;EAAe,CAAC,GAAG,MAAM,MAAM,uBAAuB,CAAC;EAE/D,MAAMC,KAAK,GAAG;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;EAED,MAAMC,MAAM,GAAG,MAAMF,cAAc,CAACJ,MAAM,EAAEC,OAAO,EAAEI,KAAK,EAAE;IAAEF;EAAS,CAAC,CAAC;EAEzE,IAAIG,MAAM,CAACC,MAAM,CAAC,CAAC,EAAE;IACjB,OAAOT,MAAM,CAACU,IAAI,CAACF,MAAM,CAACG,KAAK,CAAC;EACpC;EAEA,MAAMC,YAAY,GAAGJ,MAAM,CAACK,KAAK;EAEjC,IAAID,YAAY,CAACE,aAAa,CAACb,YAAY,CAACU,KAAK,EAAE;IAC/C,MAAM;MAAEI;IAAa,CAAC,GAAG,MAAM,MAAM,kBAAkB,CAAC;IACxD,OAAOf,MAAM,CAACU,IAAI,CACd,IAAIK,YAAY,CACZH,YAAY,CAACE,aAAa,CAACb,YAAY,CAACU,KAAK,CAACK,OAAO,EACrDJ,YAAY,CAACE,aAAa,CAACb,YAAY,CAACU,KAAK,CAACM,IAClD,CACJ,CAAC;EACL;EAEA,OAAOjB,MAAM,CAACkB,EAAE,CAACN,YAAY,CAACE,aAAa,CAACb,YAAY,CAACkB,IAAI,CAAC;AAClE","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { WebinyConfig } from "../../types.js";
|
|
2
|
+
import { Result } from "../../Result.js";
|
|
3
|
+
import type { HttpError, GraphQLError, NetworkError } from "../../errors.js";
|
|
4
|
+
export interface Tenant {
|
|
5
|
+
id: string;
|
|
6
|
+
values: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Returns the current tenant for the authenticated context.
|
|
10
|
+
*
|
|
11
|
+
* @param config - SDK configuration
|
|
12
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
13
|
+
* @returns Result containing the current tenant or an error
|
|
14
|
+
*/
|
|
15
|
+
export declare function getCurrentTenant(config: WebinyConfig, fetchFn: typeof fetch): Promise<Result<Tenant, HttpError | GraphQLError | NetworkError>>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Result } from "../../Result.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the current tenant for the authenticated context.
|
|
4
|
+
*
|
|
5
|
+
* @param config - SDK configuration
|
|
6
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
7
|
+
* @returns Result containing the current tenant or an error
|
|
8
|
+
*/
|
|
9
|
+
export async function getCurrentTenant(config, fetchFn) {
|
|
10
|
+
const {
|
|
11
|
+
executeGraphQL
|
|
12
|
+
} = await import("../executeGraphQL.js");
|
|
13
|
+
const query = `
|
|
14
|
+
query GetCurrentTenant {
|
|
15
|
+
tenantManager {
|
|
16
|
+
getCurrentTenant {
|
|
17
|
+
data {
|
|
18
|
+
id
|
|
19
|
+
values
|
|
20
|
+
}
|
|
21
|
+
error {
|
|
22
|
+
message
|
|
23
|
+
code
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
const result = await executeGraphQL(config, fetchFn, query, {});
|
|
30
|
+
if (result.isFail()) {
|
|
31
|
+
return Result.fail(result.error);
|
|
32
|
+
}
|
|
33
|
+
const responseData = result.value;
|
|
34
|
+
if (responseData.tenantManager.getCurrentTenant.error) {
|
|
35
|
+
const {
|
|
36
|
+
GraphQLError
|
|
37
|
+
} = await import("../../errors.js");
|
|
38
|
+
return Result.fail(new GraphQLError(responseData.tenantManager.getCurrentTenant.error.message, responseData.tenantManager.getCurrentTenant.error.code));
|
|
39
|
+
}
|
|
40
|
+
return Result.ok(responseData.tenantManager.getCurrentTenant.data);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=getCurrentTenant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","getCurrentTenant","config","fetchFn","executeGraphQL","query","result","isFail","fail","error","responseData","value","tenantManager","GraphQLError","message","code","ok","data"],"sources":["getCurrentTenant.ts"],"sourcesContent":["import type { WebinyConfig } from \"../../types.js\";\nimport { Result } from \"../../Result.js\";\nimport type { HttpError, GraphQLError, NetworkError } from \"../../errors.js\";\n\nexport interface Tenant {\n id: string;\n values: Record<string, unknown>;\n}\n\n/**\n * Returns the current tenant for the authenticated context.\n *\n * @param config - SDK configuration\n * @param fetchFn - Fetch function to use for HTTP requests\n * @returns Result containing the current tenant or an error\n */\nexport async function getCurrentTenant(\n config: WebinyConfig,\n fetchFn: typeof fetch\n): Promise<Result<Tenant, HttpError | GraphQLError | NetworkError>> {\n const { executeGraphQL } = await import(\"../executeGraphQL.js\");\n\n const query = `\n query GetCurrentTenant {\n tenantManager {\n getCurrentTenant {\n data {\n id\n values\n }\n error {\n message\n code\n }\n }\n }\n }\n `;\n\n const result = await executeGraphQL(config, fetchFn, query, {});\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const responseData = result.value;\n\n if (responseData.tenantManager.getCurrentTenant.error) {\n const { GraphQLError } = await import(\"../../errors.js\");\n return Result.fail(\n new GraphQLError(\n responseData.tenantManager.getCurrentTenant.error.message,\n responseData.tenantManager.getCurrentTenant.error.code\n )\n );\n }\n\n return Result.ok(responseData.tenantManager.getCurrentTenant.data);\n}\n"],"mappings":"AACA,SAASA,MAAM;AAQf;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,gBAAgBA,CAClCC,MAAoB,EACpBC,OAAqB,EAC2C;EAChE,MAAM;IAAEC;EAAe,CAAC,GAAG,MAAM,MAAM,uBAAuB,CAAC;EAE/D,MAAMC,KAAK,GAAG;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;EAED,MAAMC,MAAM,GAAG,MAAMF,cAAc,CAACF,MAAM,EAAEC,OAAO,EAAEE,KAAK,EAAE,CAAC,CAAC,CAAC;EAE/D,IAAIC,MAAM,CAACC,MAAM,CAAC,CAAC,EAAE;IACjB,OAAOP,MAAM,CAACQ,IAAI,CAACF,MAAM,CAACG,KAAK,CAAC;EACpC;EAEA,MAAMC,YAAY,GAAGJ,MAAM,CAACK,KAAK;EAEjC,IAAID,YAAY,CAACE,aAAa,CAACX,gBAAgB,CAACQ,KAAK,EAAE;IACnD,MAAM;MAAEI;IAAa,CAAC,GAAG,MAAM,MAAM,kBAAkB,CAAC;IACxD,OAAOb,MAAM,CAACQ,IAAI,CACd,IAAIK,YAAY,CACZH,YAAY,CAACE,aAAa,CAACX,gBAAgB,CAACQ,KAAK,CAACK,OAAO,EACzDJ,YAAY,CAACE,aAAa,CAACX,gBAAgB,CAACQ,KAAK,CAACM,IACtD,CACJ,CAAC;EACL;EAEA,OAAOf,MAAM,CAACgB,EAAE,CAACN,YAAY,CAACE,aAAa,CAACX,gBAAgB,CAACgB,IAAI,CAAC;AACtE","ignoreList":[]}
|