@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,168 @@
|
|
|
1
|
+
import { Result } from "../../Result.js";
|
|
2
|
+
import { getFileSize } from "./utils/fileTypeDetection.js";
|
|
3
|
+
import { buildFieldsSelection } from "./buildFieldsSelection.js";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new file in the file manager.
|
|
6
|
+
* If a file is provided, it will be uploaded to S3 first, then the record is created.
|
|
7
|
+
* If no file is provided, only the metadata record is created.
|
|
8
|
+
*
|
|
9
|
+
* @param config - SDK configuration
|
|
10
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
11
|
+
* @param params - Parameters for creating the file
|
|
12
|
+
* @param params.file - Optional: The actual file content to upload
|
|
13
|
+
* @param params.data - The file metadata
|
|
14
|
+
* @param params.onProgress - Optional: Progress callback
|
|
15
|
+
* @param params.multiPartThreshold - Optional: Threshold in MB for multi-part upload (default: 100)
|
|
16
|
+
* @param params.signal - Optional: AbortSignal for cancellation
|
|
17
|
+
* @returns Result containing the created file data or an error
|
|
18
|
+
*/
|
|
19
|
+
export async function createFile(config, fetchFn, params) {
|
|
20
|
+
const {
|
|
21
|
+
file,
|
|
22
|
+
data,
|
|
23
|
+
fields,
|
|
24
|
+
onProgress,
|
|
25
|
+
multiPartThreshold = 100,
|
|
26
|
+
signal
|
|
27
|
+
} = params;
|
|
28
|
+
|
|
29
|
+
// If no file provided, just create metadata record (existing behavior).
|
|
30
|
+
if (!file) {
|
|
31
|
+
return createFileRecord(config, fetchFn, data, fields);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// File upload flow.
|
|
35
|
+
try {
|
|
36
|
+
const fileSize = getFileSize(file);
|
|
37
|
+
const thresholdBytes = multiPartThreshold * 1024 * 1024;
|
|
38
|
+
|
|
39
|
+
// Ensure we have required metadata for upload.
|
|
40
|
+
if (!data.name || !data.type) {
|
|
41
|
+
return Result.fail(new Error("File name and type are required for upload"));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Decide upload strategy based on file size.
|
|
45
|
+
if (fileSize < thresholdBytes) {
|
|
46
|
+
// Simple upload.
|
|
47
|
+
return await uploadSmallFile(config, fetchFn, file, data, fields, onProgress, signal);
|
|
48
|
+
} else {
|
|
49
|
+
// Multi-part upload.
|
|
50
|
+
return await uploadLargeFileWrapper(config, fetchFn, file, data, fields, onProgress, signal);
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return Result.fail(error);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Uploads a small file using simple presigned POST.
|
|
59
|
+
*/
|
|
60
|
+
async function uploadSmallFile(config, fetchFn, file, data, fields, onProgress, signal) {
|
|
61
|
+
// 1. Get presigned POST payload.
|
|
62
|
+
const {
|
|
63
|
+
getPresignedPostPayload
|
|
64
|
+
} = await import("./getPresignedPostPayload.js");
|
|
65
|
+
const presignedResult = await getPresignedPostPayload(config, fetchFn, {
|
|
66
|
+
name: data.name,
|
|
67
|
+
type: data.type,
|
|
68
|
+
size: getFileSize(file),
|
|
69
|
+
key: data.key,
|
|
70
|
+
keyPrefix: data.keyPrefix
|
|
71
|
+
});
|
|
72
|
+
if (presignedResult.isFail()) {
|
|
73
|
+
return Result.fail(presignedResult.error);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 2. Upload to S3.
|
|
77
|
+
const {
|
|
78
|
+
uploadToS3
|
|
79
|
+
} = await import("./utils/uploadToS3.js");
|
|
80
|
+
await uploadToS3(file, presignedResult.value.data, {
|
|
81
|
+
onProgress,
|
|
82
|
+
signal
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// 3. Create file record with S3 key from presigned response.
|
|
86
|
+
const fileMetadata = {
|
|
87
|
+
...data,
|
|
88
|
+
id: presignedResult.value.file.id,
|
|
89
|
+
key: presignedResult.value.file.key,
|
|
90
|
+
size: presignedResult.value.file.size
|
|
91
|
+
};
|
|
92
|
+
return createFileRecord(config, fetchFn, fileMetadata, fields);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Uploads a large file using multi-part upload.
|
|
97
|
+
*/
|
|
98
|
+
async function uploadLargeFileWrapper(config, fetchFn, file, data, fields, onProgress, signal) {
|
|
99
|
+
try {
|
|
100
|
+
const {
|
|
101
|
+
uploadLargeFile
|
|
102
|
+
} = await import("./utils/uploadLargeFile.js");
|
|
103
|
+
const uploadedFile = await uploadLargeFile(file, {
|
|
104
|
+
name: data.name,
|
|
105
|
+
type: data.type,
|
|
106
|
+
size: getFileSize(file),
|
|
107
|
+
key: data.key,
|
|
108
|
+
keyPrefix: data.keyPrefix
|
|
109
|
+
}, config, fetchFn, {
|
|
110
|
+
onProgress,
|
|
111
|
+
signal,
|
|
112
|
+
chunkSize: 50,
|
|
113
|
+
parallelUploads: 5
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Create file record with uploaded metadata.
|
|
117
|
+
const fileMetadata = {
|
|
118
|
+
...data,
|
|
119
|
+
id: uploadedFile.id,
|
|
120
|
+
key: uploadedFile.key,
|
|
121
|
+
size: uploadedFile.size
|
|
122
|
+
};
|
|
123
|
+
return createFileRecord(config, fetchFn, fileMetadata, fields);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
return Result.fail(error);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Creates a file record via GraphQL (metadata only).
|
|
131
|
+
*/
|
|
132
|
+
async function createFileRecord(config, fetchFn, data, fields) {
|
|
133
|
+
const {
|
|
134
|
+
executeGraphQL
|
|
135
|
+
} = await import("../executeGraphQL.js");
|
|
136
|
+
const fieldsSelection = buildFieldsSelection(fields);
|
|
137
|
+
const query = `
|
|
138
|
+
mutation CreateFile($data: FmFileCreateInput!) {
|
|
139
|
+
fileManager {
|
|
140
|
+
createFile(data: $data) {
|
|
141
|
+
data {
|
|
142
|
+
${fieldsSelection}
|
|
143
|
+
}
|
|
144
|
+
error {
|
|
145
|
+
message
|
|
146
|
+
code
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
`;
|
|
152
|
+
const result = await executeGraphQL(config, fetchFn, query, {
|
|
153
|
+
data
|
|
154
|
+
});
|
|
155
|
+
if (result.isFail()) {
|
|
156
|
+
return Result.fail(result.error);
|
|
157
|
+
}
|
|
158
|
+
const responseData = result.value;
|
|
159
|
+
if (responseData.fileManager.createFile.error) {
|
|
160
|
+
const {
|
|
161
|
+
GraphQLError
|
|
162
|
+
} = await import("../../errors.js");
|
|
163
|
+
return Result.fail(new GraphQLError(responseData.fileManager.createFile.error.message, responseData.fileManager.createFile.error.code));
|
|
164
|
+
}
|
|
165
|
+
return Result.ok(responseData.fileManager.createFile.data);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
//# sourceMappingURL=createFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","getFileSize","buildFieldsSelection","createFile","config","fetchFn","params","file","data","fields","onProgress","multiPartThreshold","signal","createFileRecord","fileSize","thresholdBytes","name","type","fail","Error","uploadSmallFile","uploadLargeFileWrapper","error","getPresignedPostPayload","presignedResult","size","key","keyPrefix","isFail","uploadToS3","value","fileMetadata","id","uploadLargeFile","uploadedFile","chunkSize","parallelUploads","executeGraphQL","fieldsSelection","query","result","responseData","fileManager","GraphQLError","message","code","ok"],"sources":["createFile.ts"],"sourcesContent":["import type { WebinyConfig } from \"../../types.js\";\nimport { Result } from \"../../Result.js\";\nimport type { HttpError, GraphQLError, NetworkError } from \"../../errors.js\";\nimport type { FmFile, FmIdentity, FmLocationInput, UploadProgress } from \"./fileManagerTypes.js\";\nimport { getFileSize } from \"./utils/fileTypeDetection.js\";\nimport { buildFieldsSelection } from \"./buildFieldsSelection.js\";\n\nexport interface CreateFileData {\n id?: string;\n createdOn?: Date | string;\n modifiedOn?: Date | string;\n savedOn?: Date | string;\n createdBy?: FmIdentity;\n modifiedBy?: FmIdentity;\n savedBy?: FmIdentity;\n location?: FmLocationInput;\n name?: string;\n key?: string;\n keyPrefix?: string;\n type?: string;\n size?: number;\n tags?: string[];\n [key: string]: any;\n}\n\nexport interface CreateFileParams {\n file?: Buffer | Blob | File;\n data: CreateFileData;\n fields: string[];\n onProgress?: (progress: UploadProgress) => void;\n multiPartThreshold?: number;\n signal?: AbortSignal;\n}\n\n/**\n * Creates a new file in the file manager.\n * If a file is provided, it will be uploaded to S3 first, then the record is created.\n * If no file is provided, only the metadata record is created.\n *\n * @param config - SDK configuration\n * @param fetchFn - Fetch function to use for HTTP requests\n * @param params - Parameters for creating the file\n * @param params.file - Optional: The actual file content to upload\n * @param params.data - The file metadata\n * @param params.onProgress - Optional: Progress callback\n * @param params.multiPartThreshold - Optional: Threshold in MB for multi-part upload (default: 100)\n * @param params.signal - Optional: AbortSignal for cancellation\n * @returns Result containing the created file data or an error\n */\nexport async function createFile(\n config: WebinyConfig,\n fetchFn: typeof fetch,\n params: CreateFileParams\n): Promise<Result<FmFile, HttpError | GraphQLError | NetworkError>> {\n const { file, data, fields, onProgress, multiPartThreshold = 100, signal } = params;\n\n // If no file provided, just create metadata record (existing behavior).\n if (!file) {\n return createFileRecord(config, fetchFn, data, fields);\n }\n\n // File upload flow.\n try {\n const fileSize = getFileSize(file);\n const thresholdBytes = multiPartThreshold * 1024 * 1024;\n\n // Ensure we have required metadata for upload.\n if (!data.name || !data.type) {\n return Result.fail(new Error(\"File name and type are required for upload\") as any);\n }\n\n // Decide upload strategy based on file size.\n if (fileSize < thresholdBytes) {\n // Simple upload.\n return await uploadSmallFile(config, fetchFn, file, data, fields, onProgress, signal);\n } else {\n // Multi-part upload.\n return await uploadLargeFileWrapper(\n config,\n fetchFn,\n file,\n data,\n fields,\n onProgress,\n signal\n );\n }\n } catch (error) {\n return Result.fail(error as any);\n }\n}\n\n/**\n * Uploads a small file using simple presigned POST.\n */\nasync function uploadSmallFile(\n config: WebinyConfig,\n fetchFn: typeof fetch,\n file: Buffer | Blob | File,\n data: CreateFileData,\n fields: string[],\n onProgress?: (progress: UploadProgress) => void,\n signal?: AbortSignal\n): Promise<Result<FmFile, HttpError | GraphQLError | NetworkError>> {\n // 1. Get presigned POST payload.\n const { getPresignedPostPayload } = await import(\"./getPresignedPostPayload.js\");\n const presignedResult = await getPresignedPostPayload(config, fetchFn, {\n name: data.name!,\n type: data.type!,\n size: getFileSize(file),\n key: data.key,\n keyPrefix: data.keyPrefix\n });\n\n if (presignedResult.isFail()) {\n return Result.fail(presignedResult.error);\n }\n\n // 2. Upload to S3.\n const { uploadToS3 } = await import(\"./utils/uploadToS3.js\");\n await uploadToS3(file, presignedResult.value.data, { onProgress, signal });\n\n // 3. Create file record with S3 key from presigned response.\n const fileMetadata: CreateFileData = {\n ...data,\n id: presignedResult.value.file.id,\n key: presignedResult.value.file.key,\n size: presignedResult.value.file.size\n };\n\n return createFileRecord(config, fetchFn, fileMetadata, fields);\n}\n\n/**\n * Uploads a large file using multi-part upload.\n */\nasync function uploadLargeFileWrapper(\n config: WebinyConfig,\n fetchFn: typeof fetch,\n file: Buffer | Blob | File,\n data: CreateFileData,\n fields: string[],\n onProgress?: (progress: UploadProgress) => void,\n signal?: AbortSignal\n): Promise<Result<FmFile, HttpError | GraphQLError | NetworkError>> {\n try {\n const { uploadLargeFile } = await import(\"./utils/uploadLargeFile.js\");\n const uploadedFile = await uploadLargeFile(\n file,\n {\n name: data.name!,\n type: data.type!,\n size: getFileSize(file),\n key: data.key,\n keyPrefix: data.keyPrefix\n },\n config,\n fetchFn,\n { onProgress, signal, chunkSize: 50, parallelUploads: 5 }\n );\n\n // Create file record with uploaded metadata.\n const fileMetadata: CreateFileData = {\n ...data,\n id: uploadedFile.id,\n key: uploadedFile.key,\n size: uploadedFile.size\n };\n\n return createFileRecord(config, fetchFn, fileMetadata, fields);\n } catch (error) {\n return Result.fail(error as any);\n }\n}\n\n/**\n * Creates a file record via GraphQL (metadata only).\n */\nasync function createFileRecord(\n config: WebinyConfig,\n fetchFn: typeof fetch,\n data: CreateFileData,\n fields: string[]\n): Promise<Result<FmFile, HttpError | GraphQLError | NetworkError>> {\n const { executeGraphQL } = await import(\"../executeGraphQL.js\");\n\n const fieldsSelection = buildFieldsSelection(fields);\n\n const query = `\n mutation CreateFile($data: FmFileCreateInput!) {\n fileManager {\n createFile(data: $data) {\n data {\n${fieldsSelection}\n }\n error {\n message\n code\n }\n }\n }\n }\n `;\n\n const result = await executeGraphQL(config, fetchFn, query, { data });\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const responseData = result.value;\n\n if (responseData.fileManager.createFile.error) {\n const { GraphQLError } = await import(\"../../errors.js\");\n return Result.fail(\n new GraphQLError(\n responseData.fileManager.createFile.error.message,\n responseData.fileManager.createFile.error.code\n )\n );\n }\n\n return Result.ok(responseData.fileManager.createFile.data);\n}\n"],"mappings":"AACA,SAASA,MAAM;AAGf,SAASC,WAAW;AACpB,SAASC,oBAAoB;AA6B7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,UAAUA,CAC5BC,MAAoB,EACpBC,OAAqB,EACrBC,MAAwB,EACwC;EAChE,MAAM;IAAEC,IAAI;IAAEC,IAAI;IAAEC,MAAM;IAAEC,UAAU;IAAEC,kBAAkB,GAAG,GAAG;IAAEC;EAAO,CAAC,GAAGN,MAAM;;EAEnF;EACA,IAAI,CAACC,IAAI,EAAE;IACP,OAAOM,gBAAgB,CAACT,MAAM,EAAEC,OAAO,EAAEG,IAAI,EAAEC,MAA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vC,UAAU,CAACmB,KAAK,CAACsB,OAAO,EACjDH,YAAY,CAACC,WAAW,CAACvC,UAAU,CAACmB,KAAK,CAACuB,IAC9C,CACJ,CAAC;EACL;EAEA,OAAO7C,MAAM,CAAC8C,EAAE,CAACL,YAAY,CAACC,WAAW,CAACvC,UAAU,CAACK,IAAI,CAAC;AAC9D","ignoreList":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 { FmFile, UploadProgress, BatchUploadStrategy } from "./fileManagerTypes.js";
|
|
5
|
+
import type { CreateFileData } from "./createFile.js";
|
|
6
|
+
export interface CreateFilesParams {
|
|
7
|
+
files: Array<{
|
|
8
|
+
file?: Buffer | Blob | File;
|
|
9
|
+
data: CreateFileData;
|
|
10
|
+
fields: string[];
|
|
11
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
12
|
+
}>;
|
|
13
|
+
multiPartThreshold?: number;
|
|
14
|
+
concurrency?: number;
|
|
15
|
+
strategy?: BatchUploadStrategy;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}
|
|
18
|
+
export interface CreateFilesResult {
|
|
19
|
+
successful: FmFile[];
|
|
20
|
+
failed: Array<{
|
|
21
|
+
data: CreateFileData;
|
|
22
|
+
error: Error;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates multiple files in the file manager.
|
|
27
|
+
* If files are provided, they will be uploaded to S3 first, then records are created.
|
|
28
|
+
* If no files are provided, only metadata records are created.
|
|
29
|
+
*
|
|
30
|
+
* @param config - SDK configuration
|
|
31
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
32
|
+
* @param params - Parameters for creating the files
|
|
33
|
+
* @param params.files - Array of files with their data
|
|
34
|
+
* @param params.multiPartThreshold - Optional: Threshold in MB for multi-part upload (default: 100)
|
|
35
|
+
* @param params.concurrency - Optional: Number of concurrent uploads (default: 5)
|
|
36
|
+
* @param params.strategy - Optional: Batch upload strategy (default: FAIL_FAST)
|
|
37
|
+
* @param params.signal - Optional: AbortSignal for cancellation
|
|
38
|
+
* @returns Result containing the created files or an error
|
|
39
|
+
*/
|
|
40
|
+
export declare function createFiles(config: WebinyConfig, fetchFn: typeof fetch, params: CreateFilesParams): Promise<Result<CreateFilesResult, HttpError | GraphQLError | NetworkError>>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Result } from "../../Result.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates multiple files in the file manager.
|
|
4
|
+
* If files are provided, they will be uploaded to S3 first, then records are created.
|
|
5
|
+
* If no files are provided, only metadata records are created.
|
|
6
|
+
*
|
|
7
|
+
* @param config - SDK configuration
|
|
8
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
9
|
+
* @param params - Parameters for creating the files
|
|
10
|
+
* @param params.files - Array of files with their data
|
|
11
|
+
* @param params.multiPartThreshold - Optional: Threshold in MB for multi-part upload (default: 100)
|
|
12
|
+
* @param params.concurrency - Optional: Number of concurrent uploads (default: 5)
|
|
13
|
+
* @param params.strategy - Optional: Batch upload strategy (default: FAIL_FAST)
|
|
14
|
+
* @param params.signal - Optional: AbortSignal for cancellation
|
|
15
|
+
* @returns Result containing the created files or an error
|
|
16
|
+
*/
|
|
17
|
+
export async function createFiles(config, fetchFn, params) {
|
|
18
|
+
const {
|
|
19
|
+
files,
|
|
20
|
+
multiPartThreshold = 100,
|
|
21
|
+
concurrency = 5,
|
|
22
|
+
strategy = "fail-fast",
|
|
23
|
+
signal
|
|
24
|
+
} = params;
|
|
25
|
+
const successful = [];
|
|
26
|
+
const failed = [];
|
|
27
|
+
|
|
28
|
+
// Use p-map for controlled concurrency.
|
|
29
|
+
const pMap = (await import("p-map")).default;
|
|
30
|
+
try {
|
|
31
|
+
await pMap(files, async fileItem => {
|
|
32
|
+
try {
|
|
33
|
+
// Check abort signal.
|
|
34
|
+
if (signal?.aborted) {
|
|
35
|
+
throw new Error("Upload aborted");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Upload single file.
|
|
39
|
+
const {
|
|
40
|
+
createFile
|
|
41
|
+
} = await import("./createFile.js");
|
|
42
|
+
const result = await createFile(config, fetchFn, {
|
|
43
|
+
file: fileItem.file,
|
|
44
|
+
data: fileItem.data,
|
|
45
|
+
fields: fileItem.fields,
|
|
46
|
+
onProgress: fileItem.onProgress,
|
|
47
|
+
multiPartThreshold,
|
|
48
|
+
signal
|
|
49
|
+
});
|
|
50
|
+
if (result.isOk()) {
|
|
51
|
+
successful.push(result.value);
|
|
52
|
+
} else {
|
|
53
|
+
if (strategy === "fail-fast") {
|
|
54
|
+
throw result.error;
|
|
55
|
+
}
|
|
56
|
+
failed.push({
|
|
57
|
+
data: fileItem.data,
|
|
58
|
+
error: result.error
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (strategy === "fail-fast") {
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
failed.push({
|
|
66
|
+
data: fileItem.data,
|
|
67
|
+
error: error
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
concurrency
|
|
72
|
+
});
|
|
73
|
+
return Result.ok({
|
|
74
|
+
successful,
|
|
75
|
+
failed
|
|
76
|
+
});
|
|
77
|
+
} catch (error) {
|
|
78
|
+
// Fail-fast: Return error immediately.
|
|
79
|
+
return Result.fail(error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=createFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","createFiles","config","fetchFn","params","files","multiPartThreshold","concurrency","strategy","signal","successful","failed","pMap","default","fileItem","aborted","Error","createFile","result","file","data","fields","onProgress","isOk","push","value","error","ok","fail"],"sources":["createFiles.ts"],"sourcesContent":["import type { WebinyConfig } from \"../../types.js\";\nimport { Result } from \"../../Result.js\";\nimport type { HttpError, GraphQLError, NetworkError } from \"../../errors.js\";\nimport type { FmFile, UploadProgress, BatchUploadStrategy } from \"./fileManagerTypes.js\";\nimport type { CreateFileData } from \"./createFile.js\";\n\nexport interface CreateFilesParams {\n files: Array<{\n file?: Buffer | Blob | File;\n data: CreateFileData;\n fields: string[];\n onProgress?: (progress: UploadProgress) => void;\n }>;\n multiPartThreshold?: number;\n concurrency?: number;\n strategy?: BatchUploadStrategy;\n signal?: AbortSignal;\n}\n\nexport interface CreateFilesResult {\n successful: FmFile[];\n failed: Array<{\n data: CreateFileData;\n error: Error;\n }>;\n}\n\n/**\n * Creates multiple files in the file manager.\n * If files are provided, they will be uploaded to S3 first, then records are created.\n * If no files are provided, only metadata records are created.\n *\n * @param config - SDK configuration\n * @param fetchFn - Fetch function to use for HTTP requests\n * @param params - Parameters for creating the files\n * @param params.files - Array of files with their data\n * @param params.multiPartThreshold - Optional: Threshold in MB for multi-part upload (default: 100)\n * @param params.concurrency - Optional: Number of concurrent uploads (default: 5)\n * @param params.strategy - Optional: Batch upload strategy (default: FAIL_FAST)\n * @param params.signal - Optional: AbortSignal for cancellation\n * @returns Result containing the created files or an error\n */\nexport async function createFiles(\n config: WebinyConfig,\n fetchFn: typeof fetch,\n params: CreateFilesParams\n): Promise<Result<CreateFilesResult, HttpError | GraphQLError | NetworkError>> {\n const {\n files,\n multiPartThreshold = 100,\n concurrency = 5,\n strategy = \"fail-fast\" as BatchUploadStrategy,\n signal\n } = params;\n\n const successful: FmFile[] = [];\n const failed: Array<{ data: CreateFileData; error: Error }> = [];\n\n // Use p-map for controlled concurrency.\n const pMap = (await import(\"p-map\")).default;\n\n try {\n await pMap(\n files,\n async fileItem => {\n try {\n // Check abort signal.\n if (signal?.aborted) {\n throw new Error(\"Upload aborted\");\n }\n\n // Upload single file.\n const { createFile } = await import(\"./createFile.js\");\n const result = await createFile(config, fetchFn, {\n file: fileItem.file,\n data: fileItem.data,\n fields: fileItem.fields,\n onProgress: fileItem.onProgress,\n multiPartThreshold,\n signal\n });\n\n if (result.isOk()) {\n successful.push(result.value);\n } else {\n if (strategy === \"fail-fast\") {\n throw result.error;\n }\n failed.push({ data: fileItem.data, error: result.error as Error });\n }\n } catch (error) {\n if (strategy === \"fail-fast\") {\n throw error;\n }\n failed.push({ data: fileItem.data, error: error as Error });\n }\n },\n { concurrency }\n );\n\n return Result.ok({ successful, failed });\n } catch (error) {\n // Fail-fast: Return error immediately.\n return Result.fail(error as any);\n }\n}\n"],"mappings":"AACA,SAASA,MAAM;AA0Bf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,WAAWA,CAC7BC,MAAoB,EACpBC,OAAqB,EACrBC,MAAyB,EACkD;EAC3E,MAAM;IACFC,KAAK;IACLC,kBAAkB,GAAG,GAAG;IACxBC,WAAW,GAAG,CAAC;IACfC,QAAQ,GAAG,WAAkC;IAC7CC;EACJ,CAAC,GAAGL,MAAM;EAEV,MAAMM,UAAoB,GAAG,EAAE;EAC/B,MAAMC,MAAqD,GAAG,EAAE;;EAEhE;EACA,MAAMC,IAAI,GAAG,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,EAAEC,OAAO;EAE5C,IAAI;IACA,MAAMD,IAAI,CACNP,KAAK,EACL,MAAMS,QAAQ,IAAI;MACd,IAAI;QACA;QACA,IAAIL,MAAM,EAAEM,OAAO,EAAE;UACjB,MAAM,IAAIC,KAAK,CAAC,gBAAgB,CAAC;QACrC;;QAEA;QACA,MAAM;UAAEC;QAAW,CAAC,GAAG,MAAM,MAAM,kBAAkB,CAAC;QACtD,MAAMC,MAAM,GAAG,MAAMD,UAAU,CAACf,MAAM,EAAEC,OAAO,EAAE;UAC7CgB,IAAI,EAAEL,QAAQ,CAACK,IAAI;UACnBC,IAAI,EAAEN,QAAQ,CAACM,IAAI;UACnBC,MAAM,EAAEP,QAAQ,CAACO,MAAM;UACvBC,UAAU,EAAER,QAAQ,CAACQ,UAAU;UAC/BhB,kBAAkB;UAClBG;QACJ,CAAC,CAAC;QAEF,IAAIS,MAAM,CAACK,IAAI,CAAC,CAAC,EAAE;UACfb,UAAU,CAACc,IAAI,CAACN,MAAM,CAACO,KAAK,CAAC;QACjC,CAAC,MAAM;UACH,IAAIjB,QAAQ,KAAK,WAAW,EAAE;YAC1B,MAAMU,MAAM,CAACQ,KAAK;UACtB;UACAf,MAAM,CAACa,IAAI,CAAC;YAAEJ,IAAI,EAAEN,QAAQ,CAACM,IAAI;YAAEM,KAAK,EAAER,MAAM,CAACQ;UAAe,CAAC,CAAC;QACtE;MACJ,CAAC,CAAC,OAAOA,KAAK,EAAE;QACZ,IAAIlB,QAAQ,KAAK,WAAW,EAAE;UAC1B,MAAMkB,KAAK;QACf;QACAf,MAAM,CAACa,IAAI,CAAC;UAAEJ,IAAI,EAAEN,QAAQ,CAACM,IAAI;UAAEM,KAAK,EAAEA;QAAe,CAAC,CAAC;MAC/D;IACJ,CAAC,EACD;MAAEnB;IAAY,CAClB,CAAC;IAED,OAAOP,MAAM,CAAC2B,EAAE,CAAC;MAAEjB,UAAU;MAAEC;IAAO,CAAC,CAAC;EAC5C,CAAC,CAAC,OAAOe,KAAK,EAAE;IACZ;IACA,OAAO1B,MAAM,CAAC4B,IAAI,CAACF,KAAY,CAAC;EACpC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 CreateMultiPartUploadParams {
|
|
5
|
+
data: {
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
size: number;
|
|
9
|
+
key?: string;
|
|
10
|
+
keyPrefix?: string;
|
|
11
|
+
};
|
|
12
|
+
numberOfParts: number;
|
|
13
|
+
}
|
|
14
|
+
export interface MultiPartUploadResponse {
|
|
15
|
+
uploadId: string;
|
|
16
|
+
file: {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
type: string;
|
|
20
|
+
size: number;
|
|
21
|
+
key: string;
|
|
22
|
+
};
|
|
23
|
+
parts: Array<{
|
|
24
|
+
partNumber: number;
|
|
25
|
+
url: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates a multi-part upload for a large file.
|
|
30
|
+
*
|
|
31
|
+
* @param config - SDK configuration
|
|
32
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
33
|
+
* @param params - Parameters for creating the multi-part upload
|
|
34
|
+
* @param params.data - File metadata
|
|
35
|
+
* @param params.numberOfParts - Number of parts to split the file into
|
|
36
|
+
* @returns Result containing the multi-part upload data or an error
|
|
37
|
+
*/
|
|
38
|
+
export declare function createMultiPartUpload(config: WebinyConfig, fetchFn: typeof fetch, params: CreateMultiPartUploadParams): Promise<Result<MultiPartUploadResponse, HttpError | GraphQLError | NetworkError>>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Result } from "../../Result.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a multi-part upload for a large file.
|
|
4
|
+
*
|
|
5
|
+
* @param config - SDK configuration
|
|
6
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
7
|
+
* @param params - Parameters for creating the multi-part upload
|
|
8
|
+
* @param params.data - File metadata
|
|
9
|
+
* @param params.numberOfParts - Number of parts to split the file into
|
|
10
|
+
* @returns Result containing the multi-part upload data or an error
|
|
11
|
+
*/
|
|
12
|
+
export async function createMultiPartUpload(config, fetchFn, params) {
|
|
13
|
+
const {
|
|
14
|
+
data,
|
|
15
|
+
numberOfParts
|
|
16
|
+
} = params;
|
|
17
|
+
const {
|
|
18
|
+
executeGraphQL
|
|
19
|
+
} = await import("../executeGraphQL.js");
|
|
20
|
+
const query = `
|
|
21
|
+
mutation CreateMultiPartUpload($data: PreSignedPostPayloadInput!, $numberOfParts: Number!) {
|
|
22
|
+
fileManager {
|
|
23
|
+
createMultiPartUpload(data: $data, numberOfParts: $numberOfParts) {
|
|
24
|
+
data {
|
|
25
|
+
uploadId
|
|
26
|
+
file {
|
|
27
|
+
id
|
|
28
|
+
name
|
|
29
|
+
type
|
|
30
|
+
size
|
|
31
|
+
key
|
|
32
|
+
}
|
|
33
|
+
parts {
|
|
34
|
+
partNumber
|
|
35
|
+
url
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
error {
|
|
39
|
+
message
|
|
40
|
+
code
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
const result = await executeGraphQL(config, fetchFn, query, {
|
|
47
|
+
data,
|
|
48
|
+
numberOfParts
|
|
49
|
+
});
|
|
50
|
+
if (result.isFail()) {
|
|
51
|
+
return Result.fail(result.error);
|
|
52
|
+
}
|
|
53
|
+
const responseData = result.value;
|
|
54
|
+
if (responseData.fileManager.createMultiPartUpload.error) {
|
|
55
|
+
const {
|
|
56
|
+
GraphQLError
|
|
57
|
+
} = await import("../../errors.js");
|
|
58
|
+
return Result.fail(new GraphQLError(responseData.fileManager.createMultiPartUpload.error.message, responseData.fileManager.createMultiPartUpload.error.code));
|
|
59
|
+
}
|
|
60
|
+
return Result.ok(responseData.fileManager.createMultiPartUpload.data);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=createMultiPartUpload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","createMultiPartUpload","config","fetchFn","params","data","numberOfParts","executeGraphQL","query","result","isFail","fail","error","responseData","value","fileManager","GraphQLError","message","code","ok"],"sources":["createMultiPartUpload.ts"],"sourcesContent":["import type { WebinyConfig } from \"../../types.js\";\nimport { Result } from \"../../Result.js\";\nimport type { HttpError, GraphQLError, NetworkError } from \"../../errors.js\";\n\nexport interface CreateMultiPartUploadParams {\n data: {\n name: string;\n type: string;\n size: number;\n key?: string;\n keyPrefix?: string;\n };\n numberOfParts: number;\n}\n\nexport interface MultiPartUploadResponse {\n uploadId: string;\n file: {\n id: string;\n name: string;\n type: string;\n size: number;\n key: string;\n };\n parts: Array<{\n partNumber: number;\n url: string;\n }>;\n}\n\n/**\n * Creates a multi-part upload for a large file.\n *\n * @param config - SDK configuration\n * @param fetchFn - Fetch function to use for HTTP requests\n * @param params - Parameters for creating the multi-part upload\n * @param params.data - File metadata\n * @param params.numberOfParts - Number of parts to split the file into\n * @returns Result containing the multi-part upload data or an error\n */\nexport async function createMultiPartUpload(\n config: WebinyConfig,\n fetchFn: typeof fetch,\n params: CreateMultiPartUploadParams\n): Promise<Result<MultiPartUploadResponse, HttpError | GraphQLError | NetworkError>> {\n const { data, numberOfParts } = params;\n\n const { executeGraphQL } = await import(\"../executeGraphQL.js\");\n\n const query = `\n mutation CreateMultiPartUpload($data: PreSignedPostPayloadInput!, $numberOfParts: Number!) {\n fileManager {\n createMultiPartUpload(data: $data, numberOfParts: $numberOfParts) {\n data {\n uploadId\n file {\n id\n name\n type\n size\n key\n }\n parts {\n partNumber\n url\n }\n }\n error {\n message\n code\n }\n }\n }\n }\n `;\n\n const result = await executeGraphQL(config, fetchFn, query, { data, numberOfParts });\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const responseData = result.value;\n\n if (responseData.fileManager.createMultiPartUpload.error) {\n const { GraphQLError } = await import(\"../../errors.js\");\n return Result.fail(\n new GraphQLError(\n responseData.fileManager.createMultiPartUpload.error.message,\n responseData.fileManager.createMultiPartUpload.error.code\n )\n );\n }\n\n return Result.ok(responseData.fileManager.createMultiPartUpload.data);\n}\n"],"mappings":"AACA,SAASA,MAAM;AA6Bf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,qBAAqBA,CACvCC,MAAoB,EACpBC,OAAqB,EACrBC,MAAmC,EAC8C;EACjF,MAAM;IAAEC,IAAI;IAAEC;EAAc,CAAC,GAAGF,MAAM;EAEtC,MAAM;IAAEG;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;EAED,MAAMC,MAAM,GAAG,MAAMF,cAAc,CAACL,MAAM,EAAEC,OAAO,EAAEK,KAAK,EAAE;IAAEH,IAAI;IAAEC;EAAc,CAAC,CAAC;EAEpF,IAAIG,MAAM,CAACC,MAAM,CAAC,CAAC,EAAE;IACjB,OAAOV,MAAM,CAACW,IAAI,CAACF,MAAM,CAACG,KAAK,CAAC;EACpC;EAEA,MAAMC,YAAY,GAAGJ,MAAM,CAACK,KAAK;EAEjC,IAAID,YAAY,CAACE,WAAW,CAACd,qBAAqB,CAACW,KAAK,EAAE;IACtD,MAAM;MAAEI;IAAa,CAAC,GAAG,MAAM,MAAM,kBAAkB,CAAC;IACxD,OAAOhB,MAAM,CAACW,IAAI,CACd,IAAIK,YAAY,CACZH,YAAY,CAACE,WAAW,CAACd,qBAAqB,CAACW,KAAK,CAACK,OAAO,EAC5DJ,YAAY,CAACE,WAAW,CAACd,qBAAqB,CAACW,KAAK,CAACM,IACzD,CACJ,CAAC;EACL;EAEA,OAAOlB,MAAM,CAACmB,EAAE,CAACN,YAAY,CAACE,WAAW,CAACd,qBAAqB,CAACI,IAAI,CAAC;AACzE","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 DeleteFileParams {
|
|
5
|
+
id: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Deletes a file from the file manager.
|
|
9
|
+
*
|
|
10
|
+
* @param config - SDK configuration
|
|
11
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
12
|
+
* @param params - Parameters for deleting the file
|
|
13
|
+
* @param params.id - ID of the file to delete
|
|
14
|
+
* @returns Result containing true on success or an error
|
|
15
|
+
*/
|
|
16
|
+
export declare function deleteFile(config: WebinyConfig, fetchFn: typeof fetch, params: DeleteFileParams): Promise<Result<boolean, HttpError | GraphQLError | NetworkError>>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Result } from "../../Result.js";
|
|
2
|
+
/**
|
|
3
|
+
* Deletes a file from the file manager.
|
|
4
|
+
*
|
|
5
|
+
* @param config - SDK configuration
|
|
6
|
+
* @param fetchFn - Fetch function to use for HTTP requests
|
|
7
|
+
* @param params - Parameters for deleting the file
|
|
8
|
+
* @param params.id - ID of the file to delete
|
|
9
|
+
* @returns Result containing true on success or an error
|
|
10
|
+
*/
|
|
11
|
+
export async function deleteFile(config, fetchFn, params) {
|
|
12
|
+
const {
|
|
13
|
+
id
|
|
14
|
+
} = params;
|
|
15
|
+
const {
|
|
16
|
+
executeGraphQL
|
|
17
|
+
} = await import("../executeGraphQL.js");
|
|
18
|
+
const query = `
|
|
19
|
+
mutation DeleteFile($id: ID!) {
|
|
20
|
+
fileManager {
|
|
21
|
+
deleteFile(id: $id) {
|
|
22
|
+
data
|
|
23
|
+
error {
|
|
24
|
+
message
|
|
25
|
+
code
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
const result = await executeGraphQL(config, fetchFn, query, {
|
|
32
|
+
id
|
|
33
|
+
});
|
|
34
|
+
if (result.isFail()) {
|
|
35
|
+
return Result.fail(result.error);
|
|
36
|
+
}
|
|
37
|
+
const responseData = result.value;
|
|
38
|
+
if (responseData.fileManager.deleteFile.error) {
|
|
39
|
+
const {
|
|
40
|
+
GraphQLError
|
|
41
|
+
} = await import("../../errors.js");
|
|
42
|
+
return Result.fail(new GraphQLError(responseData.fileManager.deleteFile.error.message, responseData.fileManager.deleteFile.error.code));
|
|
43
|
+
}
|
|
44
|
+
return Result.ok(responseData.fileManager.deleteFile.data);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=deleteFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","deleteFile","config","fetchFn","params","id","executeGraphQL","query","result","isFail","fail","error","responseData","value","fileManager","GraphQLError","message","code","ok","data"],"sources":["deleteFile.ts"],"sourcesContent":["import type { WebinyConfig } from \"../../types.js\";\nimport { Result } from \"../../Result.js\";\nimport type { HttpError, GraphQLError, NetworkError } from \"../../errors.js\";\n\nexport interface DeleteFileParams {\n id: string;\n}\n\n/**\n * Deletes a file from the file manager.\n *\n * @param config - SDK configuration\n * @param fetchFn - Fetch function to use for HTTP requests\n * @param params - Parameters for deleting the file\n * @param params.id - ID of the file to delete\n * @returns Result containing true on success or an error\n */\nexport async function deleteFile(\n config: WebinyConfig,\n fetchFn: typeof fetch,\n params: DeleteFileParams\n): Promise<Result<boolean, HttpError | GraphQLError | NetworkError>> {\n const { id } = params;\n\n const { executeGraphQL } = await import(\"../executeGraphQL.js\");\n\n const query = `\n mutation DeleteFile($id: ID!) {\n fileManager {\n deleteFile(id: $id) {\n data\n error {\n message\n code\n }\n }\n }\n }\n `;\n\n const result = await executeGraphQL(config, fetchFn, query, { id });\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const responseData = result.value;\n\n if (responseData.fileManager.deleteFile.error) {\n const { GraphQLError } = await import(\"../../errors.js\");\n return Result.fail(\n new GraphQLError(\n responseData.fileManager.deleteFile.error.message,\n responseData.fileManager.deleteFile.error.code\n )\n );\n }\n\n return Result.ok(responseData.fileManager.deleteFile.data);\n}\n"],"mappings":"AACA,SAASA,MAAM;AAOf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,UAAUA,CAC5BC,MAAoB,EACpBC,OAAqB,EACrBC,MAAwB,EACyC;EACjE,MAAM;IAAEC;EAAG,CAAC,GAAGD,MAAM;EAErB,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;EAAG,CAAC,CAAC;EAEnE,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,WAAW,CAACb,UAAU,CAACU,KAAK,EAAE;IAC3C,MAAM;MAAEI;IAAa,CAAC,GAAG,MAAM,MAAM,kBAAkB,CAAC;IACxD,OAAOf,MAAM,CAACU,IAAI,CACd,IAAIK,YAAY,CACZH,YAAY,CAACE,WAAW,CAACb,UAAU,CAACU,KAAK,CAACK,OAAO,EACjDJ,YAAY,CAACE,WAAW,CAACb,UAAU,CAACU,KAAK,CAACM,IAC9C,CACJ,CAAC;EACL;EAEA,OAAOjB,MAAM,CAACkB,EAAE,CAACN,YAAY,CAACE,WAAW,CAACb,UAAU,CAACkB,IAAI,CAAC;AAC9D","ignoreList":[]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export interface FmIdentity {
|
|
2
|
+
id: string;
|
|
3
|
+
displayName: string;
|
|
4
|
+
type: string;
|
|
5
|
+
}
|
|
6
|
+
export interface FmLocation {
|
|
7
|
+
folderId: string;
|
|
8
|
+
}
|
|
9
|
+
export interface FmFile_Metadata {
|
|
10
|
+
image?: {
|
|
11
|
+
width?: number;
|
|
12
|
+
height?: number;
|
|
13
|
+
format?: string;
|
|
14
|
+
orientation?: number;
|
|
15
|
+
};
|
|
16
|
+
exif?: Record<string, any>;
|
|
17
|
+
iptc?: Record<string, any>;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}
|
|
20
|
+
export type FmFile_AccessControl = {
|
|
21
|
+
type: "public" | "private-authenticated";
|
|
22
|
+
};
|
|
23
|
+
export interface FmFile {
|
|
24
|
+
id: string;
|
|
25
|
+
createdOn: Date | string;
|
|
26
|
+
modifiedOn?: Date | string;
|
|
27
|
+
savedOn: Date | string;
|
|
28
|
+
createdBy: FmIdentity;
|
|
29
|
+
modifiedBy?: FmIdentity;
|
|
30
|
+
savedBy: FmIdentity;
|
|
31
|
+
location: FmLocation;
|
|
32
|
+
src?: string;
|
|
33
|
+
name?: string;
|
|
34
|
+
key?: string;
|
|
35
|
+
type?: string;
|
|
36
|
+
size?: number;
|
|
37
|
+
metadata?: FmFile_Metadata;
|
|
38
|
+
tags?: string[];
|
|
39
|
+
accessControl?: FmFile_AccessControl;
|
|
40
|
+
[key: string]: any;
|
|
41
|
+
}
|
|
42
|
+
export interface FmTag {
|
|
43
|
+
tag: string;
|
|
44
|
+
count: number;
|
|
45
|
+
}
|
|
46
|
+
export interface FmListMeta {
|
|
47
|
+
cursor: string | null;
|
|
48
|
+
hasMoreItems: boolean;
|
|
49
|
+
totalCount: number;
|
|
50
|
+
}
|
|
51
|
+
export interface FmLocationInput {
|
|
52
|
+
folderId: string;
|
|
53
|
+
}
|
|
54
|
+
export interface FmLocationWhereInput {
|
|
55
|
+
folderId?: string;
|
|
56
|
+
folderId_in?: string[];
|
|
57
|
+
folderId_not?: string;
|
|
58
|
+
folderId_not_in?: string[];
|
|
59
|
+
}
|
|
60
|
+
export interface FmFileListWhereInput {
|
|
61
|
+
location?: FmLocationWhereInput;
|
|
62
|
+
name?: string;
|
|
63
|
+
name_contains?: string;
|
|
64
|
+
name_not_contains?: string;
|
|
65
|
+
type?: string;
|
|
66
|
+
type_in?: string[];
|
|
67
|
+
type_not?: string;
|
|
68
|
+
type_not_in?: string[];
|
|
69
|
+
tags?: string[];
|
|
70
|
+
tags_in?: string[];
|
|
71
|
+
tags_not?: string;
|
|
72
|
+
tags_not_in?: string[];
|
|
73
|
+
AND?: FmFileListWhereInput[];
|
|
74
|
+
OR?: FmFileListWhereInput[];
|
|
75
|
+
}
|
|
76
|
+
export declare enum FmFileListSorter {
|
|
77
|
+
SAVED_ON_ASC = "savedOn_ASC",
|
|
78
|
+
SAVED_ON_DESC = "savedOn_DESC",
|
|
79
|
+
CREATED_ON_ASC = "createdOn_ASC",
|
|
80
|
+
CREATED_ON_DESC = "createdOn_DESC",
|
|
81
|
+
NAME_ASC = "name_ASC",
|
|
82
|
+
NAME_DESC = "name_DESC",
|
|
83
|
+
KEY_ASC = "key_ASC",
|
|
84
|
+
KEY_DESC = "key_DESC",
|
|
85
|
+
TYPE_ASC = "type_ASC",
|
|
86
|
+
TYPE_DESC = "type_DESC",
|
|
87
|
+
SIZE_ASC = "size_ASC",
|
|
88
|
+
SIZE_DESC = "size_DESC"
|
|
89
|
+
}
|
|
90
|
+
export interface FmTagsListWhereInput {
|
|
91
|
+
createdBy?: string;
|
|
92
|
+
tags_startsWith?: string;
|
|
93
|
+
tags_not_startsWith?: string;
|
|
94
|
+
}
|
|
95
|
+
export interface UploadProgress {
|
|
96
|
+
sent: number;
|
|
97
|
+
total: number;
|
|
98
|
+
percentage: number;
|
|
99
|
+
}
|
|
100
|
+
export interface PresignedPostPayload {
|
|
101
|
+
url: string;
|
|
102
|
+
fields: Record<string, string>;
|
|
103
|
+
}
|
|
104
|
+
export interface PresignedPostPayloadResponse {
|
|
105
|
+
data: PresignedPostPayload;
|
|
106
|
+
file: {
|
|
107
|
+
id: string;
|
|
108
|
+
name: string;
|
|
109
|
+
type: string;
|
|
110
|
+
size: number;
|
|
111
|
+
key: string;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export declare enum BatchUploadStrategy {
|
|
115
|
+
FAIL_FAST = "fail-fast",
|
|
116
|
+
CONTINUE = "continue"
|
|
117
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export let FmFileListSorter = /*#__PURE__*/function (FmFileListSorter) {
|
|
2
|
+
FmFileListSorter["SAVED_ON_ASC"] = "savedOn_ASC";
|
|
3
|
+
FmFileListSorter["SAVED_ON_DESC"] = "savedOn_DESC";
|
|
4
|
+
FmFileListSorter["CREATED_ON_ASC"] = "createdOn_ASC";
|
|
5
|
+
FmFileListSorter["CREATED_ON_DESC"] = "createdOn_DESC";
|
|
6
|
+
FmFileListSorter["NAME_ASC"] = "name_ASC";
|
|
7
|
+
FmFileListSorter["NAME_DESC"] = "name_DESC";
|
|
8
|
+
FmFileListSorter["KEY_ASC"] = "key_ASC";
|
|
9
|
+
FmFileListSorter["KEY_DESC"] = "key_DESC";
|
|
10
|
+
FmFileListSorter["TYPE_ASC"] = "type_ASC";
|
|
11
|
+
FmFileListSorter["TYPE_DESC"] = "type_DESC";
|
|
12
|
+
FmFileListSorter["SIZE_ASC"] = "size_ASC";
|
|
13
|
+
FmFileListSorter["SIZE_DESC"] = "size_DESC";
|
|
14
|
+
return FmFileListSorter;
|
|
15
|
+
}({});
|
|
16
|
+
export let BatchUploadStrategy = /*#__PURE__*/function (BatchUploadStrategy) {
|
|
17
|
+
BatchUploadStrategy["FAIL_FAST"] = "fail-fast";
|
|
18
|
+
BatchUploadStrategy["CONTINUE"] = "continue";
|
|
19
|
+
return BatchUploadStrategy;
|
|
20
|
+
}({});
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=fileManagerTypes.js.map
|