@23blocks/block-files 0.1.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/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/files.block.js +20 -0
- package/dist/lib/files.block.js.map +1 -0
- package/dist/lib/mappers/entity-file.mapper.js +25 -0
- package/dist/lib/mappers/entity-file.mapper.js.map +1 -0
- package/dist/lib/mappers/file-schema.mapper.js +22 -0
- package/dist/lib/mappers/file-schema.mapper.js.map +1 -0
- package/dist/lib/mappers/index.js +6 -0
- package/dist/lib/mappers/index.js.map +1 -0
- package/dist/lib/mappers/storage-file.mapper.js +30 -0
- package/dist/lib/mappers/storage-file.mapper.js.map +1 -0
- package/dist/lib/mappers/utils.js +75 -0
- package/dist/lib/mappers/utils.js.map +1 -0
- package/dist/lib/services/entity-files.service.js +86 -0
- package/dist/lib/services/entity-files.service.js.map +1 -0
- package/dist/lib/services/file-schemas.service.js +68 -0
- package/dist/lib/services/file-schemas.service.js.map +1 -0
- package/dist/lib/services/index.js +5 -0
- package/dist/lib/services/index.js.map +1 -0
- package/dist/lib/services/storage-files.service.js +111 -0
- package/dist/lib/services/storage-files.service.js.map +1 -0
- package/dist/lib/types/entity-file.js +3 -0
- package/dist/lib/types/entity-file.js.map +1 -0
- package/dist/lib/types/file-schema.js +3 -0
- package/dist/lib/types/file-schema.js.map +1 -0
- package/dist/lib/types/index.js +5 -0
- package/dist/lib/types/index.js.map +1 -0
- package/dist/lib/types/storage-file.js +3 -0
- package/dist/lib/types/storage-file.js.map +1 -0
- package/package.json +64 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Block factory and metadata
|
|
2
|
+
export { createFilesBlock, filesBlockMetadata } from './lib/files.block';
|
|
3
|
+
export { createStorageFilesService, createEntityFilesService, createFileSchemasService } from './lib/services';
|
|
4
|
+
// Mappers (for advanced use cases)
|
|
5
|
+
export { storageFileMapper, entityFileMapper, fileSchemaMapper } from './lib/mappers';
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Block factory and metadata\nexport { createFilesBlock, filesBlockMetadata } from './lib/files.block';\nexport type { FilesBlock, FilesBlockConfig } from './lib/files.block';\n\n// Types\nexport type {\n // Storage File types\n StorageFile,\n CreateStorageFileRequest,\n UpdateStorageFileRequest,\n ListStorageFilesParams,\n UploadFileRequest,\n // Entity File types\n EntityFile,\n AttachFileRequest,\n UpdateEntityFileRequest,\n ListEntityFilesParams,\n ReorderFilesRequest,\n // File Schema types\n FileSchema,\n CreateFileSchemaRequest,\n UpdateFileSchemaRequest,\n ListFileSchemasParams,\n} from './lib/types';\n\n// Services\nexport type {\n StorageFilesService,\n EntityFilesService,\n FileSchemasService,\n} from './lib/services';\n\nexport {\n createStorageFilesService,\n createEntityFilesService,\n createFileSchemasService,\n} from './lib/services';\n\n// Mappers (for advanced use cases)\nexport {\n storageFileMapper,\n entityFileMapper,\n fileSchemaMapper,\n} from './lib/mappers';\n"],"names":["createFilesBlock","filesBlockMetadata","createStorageFilesService","createEntityFilesService","createFileSchemasService","storageFileMapper","entityFileMapper","fileSchemaMapper"],"rangeMappings":";;;;","mappings":"AAAA,6BAA6B;AAC7B,SAASA,gBAAgB,EAAEC,kBAAkB,QAAQ,oBAAoB;AA+BzE,SACEC,yBAAyB,EACzBC,wBAAwB,EACxBC,wBAAwB,QACnB,iBAAiB;AAExB,mCAAmC;AACnC,SACEC,iBAAiB,EACjBC,gBAAgB,EAChBC,gBAAgB,QACX,gBAAgB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createStorageFilesService, createEntityFilesService, createFileSchemasService } from './services';
|
|
2
|
+
export function createFilesBlock(transport, config) {
|
|
3
|
+
return {
|
|
4
|
+
storageFiles: createStorageFilesService(transport, config),
|
|
5
|
+
entityFiles: createEntityFilesService(transport, config),
|
|
6
|
+
fileSchemas: createFileSchemasService(transport, config)
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export const filesBlockMetadata = {
|
|
10
|
+
name: 'files',
|
|
11
|
+
version: '0.1.0',
|
|
12
|
+
description: 'File storage, upload, download, and file management',
|
|
13
|
+
resourceTypes: [
|
|
14
|
+
'StorageFile',
|
|
15
|
+
'EntityFile',
|
|
16
|
+
'FileSchema'
|
|
17
|
+
]
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=files.block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/files.block.ts"],"sourcesContent":["import type { Transport, BlockConfig, BlockMetadata } from '@23blocks/contracts';\nimport {\n createStorageFilesService,\n createEntityFilesService,\n createFileSchemasService,\n type StorageFilesService,\n type EntityFilesService,\n type FileSchemasService,\n} from './services';\n\nexport interface FilesBlockConfig extends BlockConfig {\n appId: string;\n tenantId?: string;\n}\n\nexport interface FilesBlock {\n storageFiles: StorageFilesService;\n entityFiles: EntityFilesService;\n fileSchemas: FileSchemasService;\n}\n\nexport function createFilesBlock(\n transport: Transport,\n config: FilesBlockConfig\n): FilesBlock {\n return {\n storageFiles: createStorageFilesService(transport, config),\n entityFiles: createEntityFilesService(transport, config),\n fileSchemas: createFileSchemasService(transport, config),\n };\n}\n\nexport const filesBlockMetadata: BlockMetadata = {\n name: 'files',\n version: '0.1.0',\n description: 'File storage, upload, download, and file management',\n resourceTypes: [\n 'StorageFile',\n 'EntityFile',\n 'FileSchema',\n ],\n};\n"],"names":["createStorageFilesService","createEntityFilesService","createFileSchemasService","createFilesBlock","transport","config","storageFiles","entityFiles","fileSchemas","filesBlockMetadata","name","version","description","resourceTypes"],"rangeMappings":";;;;;;;;;;;;;;;;;","mappings":"AACA,SACEA,yBAAyB,EACzBC,wBAAwB,EACxBC,wBAAwB,QAInB,aAAa;AAapB,OAAO,SAASC,iBACdC,SAAoB,EACpBC,MAAwB;IAExB,OAAO;QACLC,cAAcN,0BAA0BI,WAAWC;QACnDE,aAAaN,yBAAyBG,WAAWC;QACjDG,aAAaN,yBAAyBE,WAAWC;IACnD;AACF;AAEA,OAAO,MAAMI,qBAAoC;IAC/CC,MAAM;IACNC,SAAS;IACTC,aAAa;IACbC,eAAe;QACb;QACA;QACA;KACD;AACH,EAAE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { parseString, parseDate, parseBoolean, parseOptionalNumber, parseStatus } from './utils';
|
|
2
|
+
export const entityFileMapper = {
|
|
3
|
+
type: 'EntityFile',
|
|
4
|
+
map: (resource)=>({
|
|
5
|
+
id: resource.id,
|
|
6
|
+
uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
|
|
7
|
+
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
8
|
+
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
9
|
+
entityUniqueId: parseString(resource.attributes['entity_unique_id']) || '',
|
|
10
|
+
entityType: parseString(resource.attributes['entity_type']) || '',
|
|
11
|
+
fileUniqueId: parseString(resource.attributes['file_unique_id']) || '',
|
|
12
|
+
fileName: parseString(resource.attributes['file_name']) || '',
|
|
13
|
+
fileType: parseString(resource.attributes['file_type']),
|
|
14
|
+
fileSize: parseOptionalNumber(resource.attributes['file_size']),
|
|
15
|
+
mimeType: parseString(resource.attributes['mime_type']),
|
|
16
|
+
contentUrl: parseString(resource.attributes['content_url']),
|
|
17
|
+
thumbnailUrl: parseString(resource.attributes['thumbnail_url']),
|
|
18
|
+
displayOrder: parseOptionalNumber(resource.attributes['display_order']),
|
|
19
|
+
status: parseStatus(resource.attributes['status']),
|
|
20
|
+
enabled: parseBoolean(resource.attributes['enabled']),
|
|
21
|
+
payload: resource.attributes['payload']
|
|
22
|
+
})
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=entity-file.mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/mappers/entity-file.mapper.ts"],"sourcesContent":["import type { ResourceMapper } from '@23blocks/jsonapi-codec';\nimport type { EntityFile } from '../types/entity-file';\nimport { parseString, parseDate, parseBoolean, parseOptionalNumber, parseStatus } from './utils';\n\nexport const entityFileMapper: ResourceMapper<EntityFile> = {\n type: 'EntityFile',\n map: (resource) => ({\n id: resource.id,\n uniqueId: parseString(resource.attributes['unique_id']) || resource.id,\n createdAt: parseDate(resource.attributes['created_at']) || new Date(),\n updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),\n\n entityUniqueId: parseString(resource.attributes['entity_unique_id']) || '',\n entityType: parseString(resource.attributes['entity_type']) || '',\n fileUniqueId: parseString(resource.attributes['file_unique_id']) || '',\n fileName: parseString(resource.attributes['file_name']) || '',\n fileType: parseString(resource.attributes['file_type']),\n fileSize: parseOptionalNumber(resource.attributes['file_size']),\n mimeType: parseString(resource.attributes['mime_type']),\n contentUrl: parseString(resource.attributes['content_url']),\n thumbnailUrl: parseString(resource.attributes['thumbnail_url']),\n displayOrder: parseOptionalNumber(resource.attributes['display_order']),\n status: parseStatus(resource.attributes['status']),\n enabled: parseBoolean(resource.attributes['enabled']),\n payload: resource.attributes['payload'] as Record<string, unknown> | undefined,\n }),\n};\n"],"names":["parseString","parseDate","parseBoolean","parseOptionalNumber","parseStatus","entityFileMapper","type","map","resource","id","uniqueId","attributes","createdAt","Date","updatedAt","entityUniqueId","entityType","fileUniqueId","fileName","fileType","fileSize","mimeType","contentUrl","thumbnailUrl","displayOrder","status","enabled","payload"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,WAAW,EAAEC,SAAS,EAAEC,YAAY,EAAEC,mBAAmB,EAAEC,WAAW,QAAQ,UAAU;AAEjG,OAAO,MAAMC,mBAA+C;IAC1DC,MAAM;IACNC,KAAK,CAACC,WAAc,CAAA;YAClBC,IAAID,SAASC,EAAE;YACfC,UAAUV,YAAYQ,SAASG,UAAU,CAAC,YAAY,KAAKH,SAASC,EAAE;YACtEG,WAAWX,UAAUO,SAASG,UAAU,CAAC,aAAa,KAAK,IAAIE;YAC/DC,WAAWb,UAAUO,SAASG,UAAU,CAAC,aAAa,KAAK,IAAIE;YAE/DE,gBAAgBf,YAAYQ,SAASG,UAAU,CAAC,mBAAmB,KAAK;YACxEK,YAAYhB,YAAYQ,SAASG,UAAU,CAAC,cAAc,KAAK;YAC/DM,cAAcjB,YAAYQ,SAASG,UAAU,CAAC,iBAAiB,KAAK;YACpEO,UAAUlB,YAAYQ,SAASG,UAAU,CAAC,YAAY,KAAK;YAC3DQ,UAAUnB,YAAYQ,SAASG,UAAU,CAAC,YAAY;YACtDS,UAAUjB,oBAAoBK,SAASG,UAAU,CAAC,YAAY;YAC9DU,UAAUrB,YAAYQ,SAASG,UAAU,CAAC,YAAY;YACtDW,YAAYtB,YAAYQ,SAASG,UAAU,CAAC,cAAc;YAC1DY,cAAcvB,YAAYQ,SAASG,UAAU,CAAC,gBAAgB;YAC9Da,cAAcrB,oBAAoBK,SAASG,UAAU,CAAC,gBAAgB;YACtEc,QAAQrB,YAAYI,SAASG,UAAU,CAAC,SAAS;YACjDe,SAASxB,aAAaM,SAASG,UAAU,CAAC,UAAU;YACpDgB,SAASnB,SAASG,UAAU,CAAC,UAAU;QACzC,CAAA;AACF,EAAE"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { parseString, parseDate, parseBoolean, parseOptionalNumber, parseStatus, parseStringArray } from './utils';
|
|
2
|
+
export const fileSchemaMapper = {
|
|
3
|
+
type: 'FileSchema',
|
|
4
|
+
map: (resource)=>({
|
|
5
|
+
id: resource.id,
|
|
6
|
+
uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
|
|
7
|
+
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
8
|
+
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
9
|
+
code: parseString(resource.attributes['code']) || '',
|
|
10
|
+
name: parseString(resource.attributes['name']) || '',
|
|
11
|
+
description: parseString(resource.attributes['description']),
|
|
12
|
+
allowedMimeTypes: parseStringArray(resource.attributes['allowed_mime_types']),
|
|
13
|
+
maxFileSize: parseOptionalNumber(resource.attributes['max_file_size']),
|
|
14
|
+
required: parseBoolean(resource.attributes['required']),
|
|
15
|
+
multiple: parseBoolean(resource.attributes['multiple']),
|
|
16
|
+
status: parseStatus(resource.attributes['status']),
|
|
17
|
+
enabled: parseBoolean(resource.attributes['enabled']),
|
|
18
|
+
payload: resource.attributes['payload']
|
|
19
|
+
})
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=file-schema.mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/mappers/file-schema.mapper.ts"],"sourcesContent":["import type { ResourceMapper } from '@23blocks/jsonapi-codec';\nimport type { FileSchema } from '../types/file-schema';\nimport { parseString, parseDate, parseBoolean, parseOptionalNumber, parseStatus, parseStringArray } from './utils';\n\nexport const fileSchemaMapper: ResourceMapper<FileSchema> = {\n type: 'FileSchema',\n map: (resource) => ({\n id: resource.id,\n uniqueId: parseString(resource.attributes['unique_id']) || resource.id,\n createdAt: parseDate(resource.attributes['created_at']) || new Date(),\n updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),\n\n code: parseString(resource.attributes['code']) || '',\n name: parseString(resource.attributes['name']) || '',\n description: parseString(resource.attributes['description']),\n allowedMimeTypes: parseStringArray(resource.attributes['allowed_mime_types']),\n maxFileSize: parseOptionalNumber(resource.attributes['max_file_size']),\n required: parseBoolean(resource.attributes['required']),\n multiple: parseBoolean(resource.attributes['multiple']),\n status: parseStatus(resource.attributes['status']),\n enabled: parseBoolean(resource.attributes['enabled']),\n payload: resource.attributes['payload'] as Record<string, unknown> | undefined,\n }),\n};\n"],"names":["parseString","parseDate","parseBoolean","parseOptionalNumber","parseStatus","parseStringArray","fileSchemaMapper","type","map","resource","id","uniqueId","attributes","createdAt","Date","updatedAt","code","name","description","allowedMimeTypes","maxFileSize","required","multiple","status","enabled","payload"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,WAAW,EAAEC,SAAS,EAAEC,YAAY,EAAEC,mBAAmB,EAAEC,WAAW,EAAEC,gBAAgB,QAAQ,UAAU;AAEnH,OAAO,MAAMC,mBAA+C;IAC1DC,MAAM;IACNC,KAAK,CAACC,WAAc,CAAA;YAClBC,IAAID,SAASC,EAAE;YACfC,UAAUX,YAAYS,SAASG,UAAU,CAAC,YAAY,KAAKH,SAASC,EAAE;YACtEG,WAAWZ,UAAUQ,SAASG,UAAU,CAAC,aAAa,KAAK,IAAIE;YAC/DC,WAAWd,UAAUQ,SAASG,UAAU,CAAC,aAAa,KAAK,IAAIE;YAE/DE,MAAMhB,YAAYS,SAASG,UAAU,CAAC,OAAO,KAAK;YAClDK,MAAMjB,YAAYS,SAASG,UAAU,CAAC,OAAO,KAAK;YAClDM,aAAalB,YAAYS,SAASG,UAAU,CAAC,cAAc;YAC3DO,kBAAkBd,iBAAiBI,SAASG,UAAU,CAAC,qBAAqB;YAC5EQ,aAAajB,oBAAoBM,SAASG,UAAU,CAAC,gBAAgB;YACrES,UAAUnB,aAAaO,SAASG,UAAU,CAAC,WAAW;YACtDU,UAAUpB,aAAaO,SAASG,UAAU,CAAC,WAAW;YACtDW,QAAQnB,YAAYK,SAASG,UAAU,CAAC,SAAS;YACjDY,SAAStB,aAAaO,SAASG,UAAU,CAAC,UAAU;YACpDa,SAAShB,SAASG,UAAU,CAAC,UAAU;QACzC,CAAA;AACF,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/mappers/index.ts"],"sourcesContent":["export * from './storage-file.mapper';\nexport * from './entity-file.mapper';\nexport * from './file-schema.mapper';\nexport * from './utils';\n"],"names":[],"rangeMappings":";;;","mappings":"AAAA,cAAc,wBAAwB;AACtC,cAAc,uBAAuB;AACrC,cAAc,uBAAuB;AACrC,cAAc,UAAU"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { parseString, parseDate, parseBoolean, parseOptionalNumber, parseStatus, parseStringArray } from './utils';
|
|
2
|
+
export const storageFileMapper = {
|
|
3
|
+
type: 'StorageFile',
|
|
4
|
+
map: (resource)=>({
|
|
5
|
+
id: resource.id,
|
|
6
|
+
uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
|
|
7
|
+
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
8
|
+
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
9
|
+
ownerUniqueId: parseString(resource.attributes['owner_unique_id']) || '',
|
|
10
|
+
ownerType: parseString(resource.attributes['owner_type']) || '',
|
|
11
|
+
fileName: parseString(resource.attributes['file_name']) || '',
|
|
12
|
+
fileType: parseString(resource.attributes['file_type']),
|
|
13
|
+
fileSize: parseOptionalNumber(resource.attributes['file_size']),
|
|
14
|
+
mimeType: parseString(resource.attributes['mime_type']),
|
|
15
|
+
contentUrl: parseString(resource.attributes['content_url']),
|
|
16
|
+
thumbnailUrl: parseString(resource.attributes['thumbnail_url']),
|
|
17
|
+
previewUrl: parseString(resource.attributes['preview_url']),
|
|
18
|
+
downloadUrl: parseString(resource.attributes['download_url']),
|
|
19
|
+
storagePath: parseString(resource.attributes['storage_path']),
|
|
20
|
+
storageProvider: parseString(resource.attributes['storage_provider']),
|
|
21
|
+
status: parseStatus(resource.attributes['status']),
|
|
22
|
+
enabled: parseBoolean(resource.attributes['enabled']),
|
|
23
|
+
payload: resource.attributes['payload'],
|
|
24
|
+
tags: parseStringArray(resource.attributes['tags']),
|
|
25
|
+
createdBy: parseString(resource.attributes['created_by']),
|
|
26
|
+
updatedBy: parseString(resource.attributes['updated_by'])
|
|
27
|
+
})
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=storage-file.mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/mappers/storage-file.mapper.ts"],"sourcesContent":["import type { ResourceMapper } from '@23blocks/jsonapi-codec';\nimport type { StorageFile } from '../types/storage-file';\nimport { parseString, parseDate, parseBoolean, parseOptionalNumber, parseStatus, parseStringArray } from './utils';\n\nexport const storageFileMapper: ResourceMapper<StorageFile> = {\n type: 'StorageFile',\n map: (resource) => ({\n id: resource.id,\n uniqueId: parseString(resource.attributes['unique_id']) || resource.id,\n createdAt: parseDate(resource.attributes['created_at']) || new Date(),\n updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),\n\n ownerUniqueId: parseString(resource.attributes['owner_unique_id']) || '',\n ownerType: parseString(resource.attributes['owner_type']) || '',\n fileName: parseString(resource.attributes['file_name']) || '',\n fileType: parseString(resource.attributes['file_type']),\n fileSize: parseOptionalNumber(resource.attributes['file_size']),\n mimeType: parseString(resource.attributes['mime_type']),\n contentUrl: parseString(resource.attributes['content_url']),\n thumbnailUrl: parseString(resource.attributes['thumbnail_url']),\n previewUrl: parseString(resource.attributes['preview_url']),\n downloadUrl: parseString(resource.attributes['download_url']),\n storagePath: parseString(resource.attributes['storage_path']),\n storageProvider: parseString(resource.attributes['storage_provider']),\n status: parseStatus(resource.attributes['status']),\n enabled: parseBoolean(resource.attributes['enabled']),\n payload: resource.attributes['payload'] as Record<string, unknown> | undefined,\n tags: parseStringArray(resource.attributes['tags']),\n createdBy: parseString(resource.attributes['created_by']),\n updatedBy: parseString(resource.attributes['updated_by']),\n }),\n};\n"],"names":["parseString","parseDate","parseBoolean","parseOptionalNumber","parseStatus","parseStringArray","storageFileMapper","type","map","resource","id","uniqueId","attributes","createdAt","Date","updatedAt","ownerUniqueId","ownerType","fileName","fileType","fileSize","mimeType","contentUrl","thumbnailUrl","previewUrl","downloadUrl","storagePath","storageProvider","status","enabled","payload","tags","createdBy","updatedBy"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,WAAW,EAAEC,SAAS,EAAEC,YAAY,EAAEC,mBAAmB,EAAEC,WAAW,EAAEC,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 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a string value, returning undefined for empty/undefined
|
|
3
|
+
*/ export function parseString(value) {
|
|
4
|
+
if (value === null || value === undefined) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
const str = String(value);
|
|
8
|
+
return str.length > 0 ? str : undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Parse a date value
|
|
12
|
+
*/ export function parseDate(value) {
|
|
13
|
+
if (value === null || value === undefined) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
if (value instanceof Date) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
20
|
+
const date = new Date(value);
|
|
21
|
+
return isNaN(date.getTime()) ? undefined : date;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parse a boolean value
|
|
27
|
+
*/ export function parseBoolean(value) {
|
|
28
|
+
if (typeof value === 'boolean') {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
if (value === 'true' || value === '1' || value === 1) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Parse an array of strings
|
|
38
|
+
*/ export function parseStringArray(value) {
|
|
39
|
+
if (value === null || value === undefined) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
return value.map(String);
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parse a number value
|
|
49
|
+
*/ export function parseNumber(value) {
|
|
50
|
+
if (value === null || value === undefined) {
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
const num = Number(value);
|
|
54
|
+
return isNaN(num) ? 0 : num;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Parse an optional number value
|
|
58
|
+
*/ export function parseOptionalNumber(value) {
|
|
59
|
+
if (value === null || value === undefined) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
const num = Number(value);
|
|
63
|
+
return isNaN(num) ? undefined : num;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Parse entity status
|
|
67
|
+
*/ export function parseStatus(value) {
|
|
68
|
+
const status = parseString(value);
|
|
69
|
+
if (status === 'active' || status === 'inactive' || status === 'pending' || status === 'archived' || status === 'deleted') {
|
|
70
|
+
return status;
|
|
71
|
+
}
|
|
72
|
+
return 'active';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/mappers/utils.ts"],"sourcesContent":["/**\n * Parse a string value, returning undefined for empty/undefined\n */\nexport function parseString(value: unknown): string | undefined {\n if (value === null || value === undefined) {\n return undefined;\n }\n const str = String(value);\n return str.length > 0 ? str : undefined;\n}\n\n/**\n * Parse a date value\n */\nexport function parseDate(value: unknown): Date | undefined {\n if (value === null || value === undefined) {\n return undefined;\n }\n\n if (value instanceof Date) {\n return value;\n }\n\n if (typeof value === 'string' || typeof value === 'number') {\n const date = new Date(value);\n return isNaN(date.getTime()) ? undefined : date;\n }\n\n return undefined;\n}\n\n/**\n * Parse a boolean value\n */\nexport function parseBoolean(value: unknown): boolean {\n if (typeof value === 'boolean') {\n return value;\n }\n if (value === 'true' || value === '1' || value === 1) {\n return true;\n }\n return false;\n}\n\n/**\n * Parse an array of strings\n */\nexport function parseStringArray(value: unknown): string[] | undefined {\n if (value === null || value === undefined) {\n return undefined;\n }\n if (Array.isArray(value)) {\n return value.map(String);\n }\n return undefined;\n}\n\n/**\n * Parse a number value\n */\nexport function parseNumber(value: unknown): number {\n if (value === null || value === undefined) {\n return 0;\n }\n const num = Number(value);\n return isNaN(num) ? 0 : num;\n}\n\n/**\n * Parse an optional number value\n */\nexport function parseOptionalNumber(value: unknown): number | undefined {\n if (value === null || value === undefined) {\n return undefined;\n }\n const num = Number(value);\n return isNaN(num) ? undefined : num;\n}\n\n/**\n * Parse entity status\n */\nexport function parseStatus(value: unknown): 'active' | 'inactive' | 'pending' | 'archived' | 'deleted' {\n const status = parseString(value);\n if (status === 'active' || status === 'inactive' || status === 'pending' || status === 'archived' || status === 'deleted') {\n return status;\n }\n return 'active';\n}\n"],"names":["parseString","value","undefined","str","String","length","parseDate","Date","date","isNaN","getTime","parseBoolean","parseStringArray","Array","isArray","map","parseNumber","num","Number","parseOptionalNumber","parseStatus","status"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;CAEC,GACD,OAAO,SAASA,YAAYC,KAAc;IACxC,IAAIA,UAAU,QAAQA,UAAUC,WAAW;QACzC,OAAOA;IACT;IACA,MAAMC,MAAMC,OAAOH;IACnB,OAAOE,IAAIE,MAAM,GAAG,IAAIF,MAAMD;AAChC;AAEA;;CAEC,GACD,OAAO,SAASI,UAAUL,KAAc;IACtC,IAAIA,UAAU,QAAQA,UAAUC,WAAW;QACzC,OAAOA;IACT;IAEA,IAAID,iBAAiBM,MAAM;QACzB,OAAON;IACT;IAEA,IAAI,OAAOA,UAAU,YAAY,OAAOA,UAAU,UAAU;QAC1D,MAAMO,OAAO,IAAID,KAAKN;QACtB,OAAOQ,MAAMD,KAAKE,OAAO,MAAMR,YAAYM;IAC7C;IAEA,OAAON;AACT;AAEA;;CAEC,GACD,OAAO,SAASS,aAAaV,KAAc;IACzC,IAAI,OAAOA,UAAU,WAAW;QAC9B,OAAOA;IACT;IACA,IAAIA,UAAU,UAAUA,UAAU,OAAOA,UAAU,GAAG;QACpD,OAAO;IACT;IACA,OAAO;AACT;AAEA;;CAEC,GACD,OAAO,SAASW,iBAAiBX,KAAc;IAC7C,IAAIA,UAAU,QAAQA,UAAUC,WAAW;QACzC,OAAOA;IACT;IACA,IAAIW,MAAMC,OAAO,CAACb,QAAQ;QACxB,OAAOA,MAAMc,GAAG,CAACX;IACnB;IACA,OAAOF;AACT;AAEA;;CAEC,GACD,OAAO,SAASc,YAAYf,KAAc;IACxC,IAAIA,UAAU,QAAQA,UAAUC,WAAW;QACzC,OAAO;IACT;IACA,MAAMe,MAAMC,OAAOjB;IACnB,OAAOQ,MAAMQ,OAAO,IAAIA;AAC1B;AAEA;;CAEC,GACD,OAAO,SAASE,oBAAoBlB,KAAc;IAChD,IAAIA,UAAU,QAAQA,UAAUC,WAAW;QACzC,OAAOA;IACT;IACA,MAAMe,MAAMC,OAAOjB;IACnB,OAAOQ,MAAMQ,OAAOf,YAAYe;AAClC;AAEA;;CAEC,GACD,OAAO,SAASG,YAAYnB,KAAc;IACxC,MAAMoB,SAASrB,YAAYC;IAC3B,IAAIoB,WAAW,YAAYA,WAAW,cAAcA,WAAW,aAAaA,WAAW,cAAcA,WAAW,WAAW;QACzH,OAAOA;IACT;IACA,OAAO;AACT"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { decodeOne, decodeMany, decodePageResult } from '@23blocks/jsonapi-codec';
|
|
2
|
+
import { entityFileMapper } from '../mappers/entity-file.mapper';
|
|
3
|
+
export function createEntityFilesService(transport, _config) {
|
|
4
|
+
return {
|
|
5
|
+
async list (params) {
|
|
6
|
+
const queryParams = {};
|
|
7
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
8
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
9
|
+
if (params == null ? void 0 : params.entityUniqueId) queryParams['entity_unique_id'] = params.entityUniqueId;
|
|
10
|
+
if (params == null ? void 0 : params.entityType) queryParams['entity_type'] = params.entityType;
|
|
11
|
+
if (params == null ? void 0 : params.fileType) queryParams['file_type'] = params.fileType;
|
|
12
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
13
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
14
|
+
const response = await transport.get('/entity_files', {
|
|
15
|
+
params: queryParams
|
|
16
|
+
});
|
|
17
|
+
return decodePageResult(response, entityFileMapper);
|
|
18
|
+
},
|
|
19
|
+
async get (uniqueId) {
|
|
20
|
+
const response = await transport.get(`/entity_files/${uniqueId}`);
|
|
21
|
+
return decodeOne(response, entityFileMapper);
|
|
22
|
+
},
|
|
23
|
+
async attach (data) {
|
|
24
|
+
const response = await transport.post('/entity_files', {
|
|
25
|
+
data: {
|
|
26
|
+
type: 'EntityFile',
|
|
27
|
+
attributes: {
|
|
28
|
+
entity_unique_id: data.entityUniqueId,
|
|
29
|
+
entity_type: data.entityType,
|
|
30
|
+
file_unique_id: data.fileUniqueId,
|
|
31
|
+
display_order: data.displayOrder,
|
|
32
|
+
payload: data.payload
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return decodeOne(response, entityFileMapper);
|
|
37
|
+
},
|
|
38
|
+
async detach (uniqueId) {
|
|
39
|
+
await transport.delete(`/entity_files/${uniqueId}`);
|
|
40
|
+
},
|
|
41
|
+
async update (uniqueId, data) {
|
|
42
|
+
const response = await transport.put(`/entity_files/${uniqueId}`, {
|
|
43
|
+
data: {
|
|
44
|
+
type: 'EntityFile',
|
|
45
|
+
attributes: {
|
|
46
|
+
display_order: data.displayOrder,
|
|
47
|
+
enabled: data.enabled,
|
|
48
|
+
status: data.status,
|
|
49
|
+
payload: data.payload
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return decodeOne(response, entityFileMapper);
|
|
54
|
+
},
|
|
55
|
+
async reorder (entityUniqueId, entityType, data) {
|
|
56
|
+
const response = await transport.put('/entity_files/reorder', {
|
|
57
|
+
data: {
|
|
58
|
+
type: 'EntityFile',
|
|
59
|
+
attributes: {
|
|
60
|
+
entity_unique_id: entityUniqueId,
|
|
61
|
+
entity_type: entityType,
|
|
62
|
+
file_orders: data.fileOrders
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return decodeMany(response, entityFileMapper);
|
|
67
|
+
},
|
|
68
|
+
async listByEntity (entityUniqueId, entityType, params) {
|
|
69
|
+
const queryParams = {
|
|
70
|
+
entity_unique_id: entityUniqueId,
|
|
71
|
+
entity_type: entityType
|
|
72
|
+
};
|
|
73
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
74
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
75
|
+
if (params == null ? void 0 : params.fileType) queryParams['file_type'] = params.fileType;
|
|
76
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
77
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
78
|
+
const response = await transport.get('/entity_files', {
|
|
79
|
+
params: queryParams
|
|
80
|
+
});
|
|
81
|
+
return decodePageResult(response, entityFileMapper);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=entity-files.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/services/entity-files.service.ts"],"sourcesContent":["import type { Transport, PageResult } from '@23blocks/contracts';\nimport { decodeOne, decodeMany, decodePageResult } from '@23blocks/jsonapi-codec';\nimport type {\n EntityFile,\n AttachFileRequest,\n UpdateEntityFileRequest,\n ListEntityFilesParams,\n ReorderFilesRequest,\n} from '../types/entity-file';\nimport { entityFileMapper } from '../mappers/entity-file.mapper';\n\nexport interface EntityFilesService {\n list(params?: ListEntityFilesParams): Promise<PageResult<EntityFile>>;\n get(uniqueId: string): Promise<EntityFile>;\n attach(data: AttachFileRequest): Promise<EntityFile>;\n detach(uniqueId: string): Promise<void>;\n update(uniqueId: string, data: UpdateEntityFileRequest): Promise<EntityFile>;\n reorder(entityUniqueId: string, entityType: string, data: ReorderFilesRequest): Promise<EntityFile[]>;\n listByEntity(entityUniqueId: string, entityType: string, params?: ListEntityFilesParams): Promise<PageResult<EntityFile>>;\n}\n\nexport function createEntityFilesService(transport: Transport, _config: { appId: string }): EntityFilesService {\n return {\n async list(params?: ListEntityFilesParams): Promise<PageResult<EntityFile>> {\n const queryParams: Record<string, string> = {};\n if (params?.page) queryParams['page'] = String(params.page);\n if (params?.perPage) queryParams['records'] = String(params.perPage);\n if (params?.entityUniqueId) queryParams['entity_unique_id'] = params.entityUniqueId;\n if (params?.entityType) queryParams['entity_type'] = params.entityType;\n if (params?.fileType) queryParams['file_type'] = params.fileType;\n if (params?.status) queryParams['status'] = params.status;\n if (params?.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;\n\n const response = await transport.get<unknown>('/entity_files', { params: queryParams });\n return decodePageResult(response, entityFileMapper);\n },\n\n async get(uniqueId: string): Promise<EntityFile> {\n const response = await transport.get<unknown>(`/entity_files/${uniqueId}`);\n return decodeOne(response, entityFileMapper);\n },\n\n async attach(data: AttachFileRequest): Promise<EntityFile> {\n const response = await transport.post<unknown>('/entity_files', {\n data: {\n type: 'EntityFile',\n attributes: {\n entity_unique_id: data.entityUniqueId,\n entity_type: data.entityType,\n file_unique_id: data.fileUniqueId,\n display_order: data.displayOrder,\n payload: data.payload,\n },\n },\n });\n return decodeOne(response, entityFileMapper);\n },\n\n async detach(uniqueId: string): Promise<void> {\n await transport.delete(`/entity_files/${uniqueId}`);\n },\n\n async update(uniqueId: string, data: UpdateEntityFileRequest): Promise<EntityFile> {\n const response = await transport.put<unknown>(`/entity_files/${uniqueId}`, {\n data: {\n type: 'EntityFile',\n attributes: {\n display_order: data.displayOrder,\n enabled: data.enabled,\n status: data.status,\n payload: data.payload,\n },\n },\n });\n return decodeOne(response, entityFileMapper);\n },\n\n async reorder(entityUniqueId: string, entityType: string, data: ReorderFilesRequest): Promise<EntityFile[]> {\n const response = await transport.put<unknown>('/entity_files/reorder', {\n data: {\n type: 'EntityFile',\n attributes: {\n entity_unique_id: entityUniqueId,\n entity_type: entityType,\n file_orders: data.fileOrders,\n },\n },\n });\n return decodeMany(response, entityFileMapper);\n },\n\n async listByEntity(entityUniqueId: string, entityType: string, params?: ListEntityFilesParams): Promise<PageResult<EntityFile>> {\n const queryParams: Record<string, string> = {\n entity_unique_id: entityUniqueId,\n entity_type: entityType,\n };\n if (params?.page) queryParams['page'] = String(params.page);\n if (params?.perPage) queryParams['records'] = String(params.perPage);\n if (params?.fileType) queryParams['file_type'] = params.fileType;\n if (params?.status) queryParams['status'] = params.status;\n if (params?.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;\n\n const response = await transport.get<unknown>('/entity_files', { params: queryParams });\n return decodePageResult(response, entityFileMapper);\n },\n };\n}\n"],"names":["decodeOne","decodeMany","decodePageResult","entityFileMapper","createEntityFilesService","transport","_config","list","params","queryParams","page","String","perPage","entityUniqueId","entityType","fileType","status","sortBy","sortOrder","response","get","uniqueId","attach","data","post","type","attributes","entity_unique_id","entity_type","file_unique_id","fileUniqueId","display_order","displayOrder","payload","detach","delete","update","put","enabled","reorder","file_orders","fileOrders","listByEntity"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,SAAS,EAAEC,UAAU,EAAEC,gBAAgB,QAAQ,0BAA0B;AAQlF,SAASC,gBAAgB,QAAQ,gCAAgC;AAYjE,OAAO,SAASC,yBAAyBC,SAAoB,EAAEC,OAA0B;IACvF,OAAO;QACL,MAAMC,MAAKC,MAA8B;YACvC,MAAMC,cAAsC,CAAC;YAC7C,IAAID,0BAAAA,OAAQE,IAAI,EAAED,WAAW,CAAC,OAAO,GAAGE,OAAOH,OA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AAEV,OAAOS,MAAM,CAAC,CAAC,GAAGT,OAAOS,MAAM;YAE3G,MAAME,WAAW,MAAMd,UAAUe,GAAG,CAAU,iBAAiB;gBAAEZ,QAAQC;YAAY;YACrF,OAAOP,iBAAiBiB,UAAUhB;QACpC;IACF;AACF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { decodeOne, decodePageResult } from '@23blocks/jsonapi-codec';
|
|
2
|
+
import { fileSchemaMapper } from '../mappers/file-schema.mapper';
|
|
3
|
+
export function createFileSchemasService(transport, _config) {
|
|
4
|
+
return {
|
|
5
|
+
async list (params) {
|
|
6
|
+
const queryParams = {};
|
|
7
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
8
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
9
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
10
|
+
if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
|
|
11
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
12
|
+
const response = await transport.get('/file_schemas', {
|
|
13
|
+
params: queryParams
|
|
14
|
+
});
|
|
15
|
+
return decodePageResult(response, fileSchemaMapper);
|
|
16
|
+
},
|
|
17
|
+
async get (uniqueId) {
|
|
18
|
+
const response = await transport.get(`/file_schemas/${uniqueId}`);
|
|
19
|
+
return decodeOne(response, fileSchemaMapper);
|
|
20
|
+
},
|
|
21
|
+
async getByCode (code) {
|
|
22
|
+
const response = await transport.get(`/file_schemas/code/${code}`);
|
|
23
|
+
return decodeOne(response, fileSchemaMapper);
|
|
24
|
+
},
|
|
25
|
+
async create (data) {
|
|
26
|
+
const response = await transport.post('/file_schemas', {
|
|
27
|
+
data: {
|
|
28
|
+
type: 'FileSchema',
|
|
29
|
+
attributes: {
|
|
30
|
+
code: data.code,
|
|
31
|
+
name: data.name,
|
|
32
|
+
description: data.description,
|
|
33
|
+
allowed_mime_types: data.allowedMimeTypes,
|
|
34
|
+
max_file_size: data.maxFileSize,
|
|
35
|
+
required: data.required,
|
|
36
|
+
multiple: data.multiple,
|
|
37
|
+
payload: data.payload
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return decodeOne(response, fileSchemaMapper);
|
|
42
|
+
},
|
|
43
|
+
async update (uniqueId, data) {
|
|
44
|
+
const response = await transport.put(`/file_schemas/${uniqueId}`, {
|
|
45
|
+
data: {
|
|
46
|
+
type: 'FileSchema',
|
|
47
|
+
attributes: {
|
|
48
|
+
name: data.name,
|
|
49
|
+
description: data.description,
|
|
50
|
+
allowed_mime_types: data.allowedMimeTypes,
|
|
51
|
+
max_file_size: data.maxFileSize,
|
|
52
|
+
required: data.required,
|
|
53
|
+
multiple: data.multiple,
|
|
54
|
+
enabled: data.enabled,
|
|
55
|
+
status: data.status,
|
|
56
|
+
payload: data.payload
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return decodeOne(response, fileSchemaMapper);
|
|
61
|
+
},
|
|
62
|
+
async delete (uniqueId) {
|
|
63
|
+
await transport.delete(`/file_schemas/${uniqueId}`);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=file-schemas.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/services/file-schemas.service.ts"],"sourcesContent":["import type { Transport, PageResult } from '@23blocks/contracts';\nimport { decodeOne, decodePageResult } from '@23blocks/jsonapi-codec';\nimport type {\n FileSchema,\n CreateFileSchemaRequest,\n UpdateFileSchemaRequest,\n ListFileSchemasParams,\n} from '../types/file-schema';\nimport { fileSchemaMapper } from '../mappers/file-schema.mapper';\n\nexport interface FileSchemasService {\n list(params?: ListFileSchemasParams): Promise<PageResult<FileSchema>>;\n get(uniqueId: string): Promise<FileSchema>;\n getByCode(code: string): Promise<FileSchema>;\n create(data: CreateFileSchemaRequest): Promise<FileSchema>;\n update(uniqueId: string, data: UpdateFileSchemaRequest): Promise<FileSchema>;\n delete(uniqueId: string): Promise<void>;\n}\n\nexport function createFileSchemasService(transport: Transport, _config: { appId: string }): FileSchemasService {\n return {\n async list(params?: ListFileSchemasParams): Promise<PageResult<FileSchema>> {\n const queryParams: Record<string, string> = {};\n if (params?.page) queryParams['page'] = String(params.page);\n if (params?.perPage) queryParams['records'] = String(params.perPage);\n if (params?.status) queryParams['status'] = params.status;\n if (params?.search) queryParams['search'] = params.search;\n if (params?.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;\n\n const response = await transport.get<unknown>('/file_schemas', { params: queryParams });\n return decodePageResult(response, fileSchemaMapper);\n },\n\n async get(uniqueId: string): Promise<FileSchema> {\n const response = await transport.get<unknown>(`/file_schemas/${uniqueId}`);\n return decodeOne(response, fileSchemaMapper);\n },\n\n async getByCode(code: string): Promise<FileSchema> {\n const response = await transport.get<unknown>(`/file_schemas/code/${code}`);\n return decodeOne(response, fileSchemaMapper);\n },\n\n async create(data: CreateFileSchemaRequest): Promise<FileSchema> {\n const response = await transport.post<unknown>('/file_schemas', {\n data: {\n type: 'FileSchema',\n attributes: {\n code: data.code,\n name: data.name,\n description: data.description,\n allowed_mime_types: data.allowedMimeTypes,\n max_file_size: data.maxFileSize,\n required: data.required,\n multiple: data.multiple,\n payload: data.payload,\n },\n },\n });\n return decodeOne(response, fileSchemaMapper);\n },\n\n async update(uniqueId: string, data: UpdateFileSchemaRequest): Promise<FileSchema> {\n const response = await transport.put<unknown>(`/file_schemas/${uniqueId}`, {\n data: {\n type: 'FileSchema',\n attributes: {\n name: data.name,\n description: data.description,\n allowed_mime_types: data.allowedMimeTypes,\n max_file_size: data.maxFileSize,\n required: data.required,\n multiple: data.multiple,\n enabled: data.enabled,\n status: data.status,\n payload: data.payload,\n },\n },\n });\n return decodeOne(response, fileSchemaMapper);\n },\n\n async delete(uniqueId: string): Promise<void> {\n await transport.delete(`/file_schemas/${uniqueId}`);\n },\n };\n}\n"],"names":["decodeOne","decodePageResult","fileSchemaMapper","createFileSchemasService","transport","_config","list","params","queryParams","page","String","perPage","status","search","sortBy","sortOrder","response","get","uniqueId","getByCode","code","create","data","post","type","attributes","name","description","allowed_mime_types","allowedMimeTypes","max_file_size","maxFileSize","required","multiple","payload","update","put","enabled","delete"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,SAAS,EAAEC,gBAAgB,QAAQ,0BAA0B;AAOtE,SAASC,gBAAgB,QAAQ,gCAAgC;AAWjE,OAAO,SAASC,yBAAyBC,SAAoB,EAAEC,OAA0B;IACvF,OAAO;QACL,MAAMC,MAAKC,MAA8B;YACvC,MAAMC,cAAsC,CAAC;YAC7C,IAAID,0BAAAA,OAAQE,IAAI,EAAED,WAAW,CAAC,OAAO,GAAGE,OAAOH,OAAOE,IAAI;YAC1D,IAAIF,0BAAAA,OAAQI,OAAO,EAAEH,WAAW,CAAC,UAAU,GAAGE,OAAOH,OAAOI,OAAO;YACnE,IAAIJ,0BAAAA,OAAQK,MAAM,EAAEJ,WAAW,CAAC,SAAS,GAAGD,OAAOK,MAAM;YACzD,IAAIL,0BAAAA,OAAQM,MAAM,EAAEL,WAAW,CAAC,SAAS,GAAGD,OAAOM,MAAM;YACzD,IAAIN,0BAAAA,OAAQO,MAAM,EAAEN,WAAW,CAAC,OAAO,GAAGD,OAAOQ,SAAS,KAAK,SAAS,CAAC,CAAC,EAAER,OAAOO,MAAM,CAAC,CAAC,GAAGP,OAAOO,MAAM;YAE3G,MAAME,WAAW,MAAMZ,UAAUa,GAAG,CAAU,iBAAiB;gBAAEV,QAAQC;YAAY;YACrF,OAAOP,iBAAiBe,UAAUd;QACpC;QAEA,MAAMe,KAAIC,QAAgB;YACxB,MAAMF,WAAW,MAAMZ,UAAUa,GAAG,CAA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QACpD;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/services/index.ts"],"sourcesContent":["export * from './storage-files.service';\nexport * from './entity-files.service';\nexport * from './file-schemas.service';\n"],"names":[],"rangeMappings":";;","mappings":"AAAA,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,yBAAyB"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { decodeOne, decodePageResult } from '@23blocks/jsonapi-codec';
|
|
2
|
+
import { storageFileMapper } from '../mappers/storage-file.mapper';
|
|
3
|
+
export function createStorageFilesService(transport, _config) {
|
|
4
|
+
return {
|
|
5
|
+
async list (params) {
|
|
6
|
+
const queryParams = {};
|
|
7
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
8
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
9
|
+
if (params == null ? void 0 : params.ownerUniqueId) queryParams['owner_unique_id'] = params.ownerUniqueId;
|
|
10
|
+
if (params == null ? void 0 : params.ownerType) queryParams['owner_type'] = params.ownerType;
|
|
11
|
+
if (params == null ? void 0 : params.fileType) queryParams['file_type'] = params.fileType;
|
|
12
|
+
if (params == null ? void 0 : params.mimeType) queryParams['mime_type'] = params.mimeType;
|
|
13
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
14
|
+
if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
|
|
15
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
16
|
+
const response = await transport.get('/storage_files', {
|
|
17
|
+
params: queryParams
|
|
18
|
+
});
|
|
19
|
+
return decodePageResult(response, storageFileMapper);
|
|
20
|
+
},
|
|
21
|
+
async get (uniqueId) {
|
|
22
|
+
const response = await transport.get(`/storage_files/${uniqueId}`);
|
|
23
|
+
return decodeOne(response, storageFileMapper);
|
|
24
|
+
},
|
|
25
|
+
async upload (data) {
|
|
26
|
+
const formData = new FormData();
|
|
27
|
+
formData.append('file', data.file, data.fileName);
|
|
28
|
+
formData.append('owner_unique_id', data.ownerUniqueId);
|
|
29
|
+
formData.append('owner_type', data.ownerType);
|
|
30
|
+
if (data.fileType) formData.append('file_type', data.fileType);
|
|
31
|
+
if (data.generateThumbnail !== undefined) formData.append('generate_thumbnail', String(data.generateThumbnail));
|
|
32
|
+
if (data.generatePreview !== undefined) formData.append('generate_preview', String(data.generatePreview));
|
|
33
|
+
if (data.payload) formData.append('payload', JSON.stringify(data.payload));
|
|
34
|
+
if (data.tags) formData.append('tags', JSON.stringify(data.tags));
|
|
35
|
+
const response = await transport.post('/storage_files/upload', formData, {
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': 'multipart/form-data'
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return decodeOne(response, storageFileMapper);
|
|
41
|
+
},
|
|
42
|
+
async create (data) {
|
|
43
|
+
const response = await transport.post('/storage_files', {
|
|
44
|
+
data: {
|
|
45
|
+
type: 'StorageFile',
|
|
46
|
+
attributes: {
|
|
47
|
+
owner_unique_id: data.ownerUniqueId,
|
|
48
|
+
owner_type: data.ownerType,
|
|
49
|
+
file_name: data.fileName,
|
|
50
|
+
file_type: data.fileType,
|
|
51
|
+
file_size: data.fileSize,
|
|
52
|
+
mime_type: data.mimeType,
|
|
53
|
+
content_url: data.contentUrl,
|
|
54
|
+
storage_path: data.storagePath,
|
|
55
|
+
storage_provider: data.storageProvider,
|
|
56
|
+
payload: data.payload,
|
|
57
|
+
tags: data.tags
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return decodeOne(response, storageFileMapper);
|
|
62
|
+
},
|
|
63
|
+
async update (uniqueId, data) {
|
|
64
|
+
const response = await transport.put(`/storage_files/${uniqueId}`, {
|
|
65
|
+
data: {
|
|
66
|
+
type: 'StorageFile',
|
|
67
|
+
attributes: {
|
|
68
|
+
file_name: data.fileName,
|
|
69
|
+
file_type: data.fileType,
|
|
70
|
+
content_url: data.contentUrl,
|
|
71
|
+
thumbnail_url: data.thumbnailUrl,
|
|
72
|
+
preview_url: data.previewUrl,
|
|
73
|
+
enabled: data.enabled,
|
|
74
|
+
status: data.status,
|
|
75
|
+
payload: data.payload,
|
|
76
|
+
tags: data.tags
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return decodeOne(response, storageFileMapper);
|
|
81
|
+
},
|
|
82
|
+
async delete (uniqueId) {
|
|
83
|
+
await transport.delete(`/storage_files/${uniqueId}`);
|
|
84
|
+
},
|
|
85
|
+
async download (uniqueId) {
|
|
86
|
+
const response = await transport.get(`/storage_files/${uniqueId}/download`, {
|
|
87
|
+
responseType: 'blob'
|
|
88
|
+
});
|
|
89
|
+
return response;
|
|
90
|
+
},
|
|
91
|
+
async listByOwner (ownerUniqueId, ownerType, params) {
|
|
92
|
+
const queryParams = {
|
|
93
|
+
owner_unique_id: ownerUniqueId,
|
|
94
|
+
owner_type: ownerType
|
|
95
|
+
};
|
|
96
|
+
if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
|
|
97
|
+
if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
|
|
98
|
+
if (params == null ? void 0 : params.fileType) queryParams['file_type'] = params.fileType;
|
|
99
|
+
if (params == null ? void 0 : params.mimeType) queryParams['mime_type'] = params.mimeType;
|
|
100
|
+
if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
|
|
101
|
+
if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
|
|
102
|
+
if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
|
|
103
|
+
const response = await transport.get('/storage_files', {
|
|
104
|
+
params: queryParams
|
|
105
|
+
});
|
|
106
|
+
return decodePageResult(response, storageFileMapper);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=storage-files.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/services/storage-files.service.ts"],"sourcesContent":["import type { Transport, PageResult } from '@23blocks/contracts';\nimport { decodeOne, decodeMany, decodePageResult } from '@23blocks/jsonapi-codec';\nimport type {\n StorageFile,\n CreateStorageFileRequest,\n UpdateStorageFileRequest,\n ListStorageFilesParams,\n UploadFileRequest,\n} from '../types/storage-file';\nimport { storageFileMapper } from '../mappers/storage-file.mapper';\n\nexport interface StorageFilesService {\n list(params?: ListStorageFilesParams): Promise<PageResult<StorageFile>>;\n get(uniqueId: string): Promise<StorageFile>;\n upload(data: UploadFileRequest): Promise<StorageFile>;\n create(data: CreateStorageFileRequest): Promise<StorageFile>;\n update(uniqueId: string, data: UpdateStorageFileRequest): Promise<StorageFile>;\n delete(uniqueId: string): Promise<void>;\n download(uniqueId: string): Promise<Blob>;\n listByOwner(ownerUniqueId: string, ownerType: string, params?: ListStorageFilesParams): Promise<PageResult<StorageFile>>;\n}\n\nexport function createStorageFilesService(transport: Transport, _config: { appId: string }): StorageFilesService {\n return {\n async list(params?: ListStorageFilesParams): Promise<PageResult<StorageFile>> {\n const queryParams: Record<string, string> = {};\n if (params?.page) queryParams['page'] = String(params.page);\n if (params?.perPage) queryParams['records'] = String(params.perPage);\n if (params?.ownerUniqueId) queryParams['owner_unique_id'] = params.ownerUniqueId;\n if (params?.ownerType) queryParams['owner_type'] = params.ownerType;\n if (params?.fileType) queryParams['file_type'] = params.fileType;\n if (params?.mimeType) queryParams['mime_type'] = params.mimeType;\n if (params?.status) queryParams['status'] = params.status;\n if (params?.search) queryParams['search'] = params.search;\n if (params?.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;\n\n const response = await transport.get<unknown>('/storage_files', { params: queryParams });\n return decodePageResult(response, storageFileMapper);\n },\n\n async get(uniqueId: string): Promise<StorageFile> {\n const response = await transport.get<unknown>(`/storage_files/${uniqueId}`);\n return decodeOne(response, storageFileMapper);\n },\n\n async upload(data: UploadFileRequest): Promise<StorageFile> {\n const formData = new FormData();\n formData.append('file', data.file, data.fileName);\n formData.append('owner_unique_id', data.ownerUniqueId);\n formData.append('owner_type', data.ownerType);\n\n if (data.fileType) formData.append('file_type', data.fileType);\n if (data.generateThumbnail !== undefined) formData.append('generate_thumbnail', String(data.generateThumbnail));\n if (data.generatePreview !== undefined) formData.append('generate_preview', String(data.generatePreview));\n if (data.payload) formData.append('payload', JSON.stringify(data.payload));\n if (data.tags) formData.append('tags', JSON.stringify(data.tags));\n\n const response = await transport.post<unknown>('/storage_files/upload', formData, {\n headers: {\n 'Content-Type': 'multipart/form-data',\n },\n });\n return decodeOne(response, storageFileMapper);\n },\n\n async create(data: CreateStorageFileRequest): Promise<StorageFile> {\n const response = await transport.post<unknown>('/storage_files', {\n data: {\n type: 'StorageFile',\n attributes: {\n owner_unique_id: data.ownerUniqueId,\n owner_type: data.ownerType,\n file_name: data.fileName,\n file_type: data.fileType,\n file_size: data.fileSize,\n mime_type: data.mimeType,\n content_url: data.contentUrl,\n storage_path: data.storagePath,\n storage_provider: data.storageProvider,\n payload: data.payload,\n tags: data.tags,\n },\n },\n });\n return decodeOne(response, storageFileMapper);\n },\n\n async update(uniqueId: string, data: UpdateStorageFileRequest): Promise<StorageFile> {\n const response = await transport.put<unknown>(`/storage_files/${uniqueId}`, {\n data: {\n type: 'StorageFile',\n attributes: {\n file_name: data.fileName,\n file_type: data.fileType,\n content_url: data.contentUrl,\n thumbnail_url: data.thumbnailUrl,\n preview_url: data.previewUrl,\n enabled: data.enabled,\n status: data.status,\n payload: data.payload,\n tags: data.tags,\n },\n },\n });\n return decodeOne(response, storageFileMapper);\n },\n\n async delete(uniqueId: string): Promise<void> {\n await transport.delete(`/storage_files/${uniqueId}`);\n },\n\n async download(uniqueId: string): Promise<Blob> {\n const response = await transport.get<Blob>(`/storage_files/${uniqueId}/download`, {\n responseType: 'blob',\n });\n return response;\n },\n\n async listByOwner(ownerUniqueId: string, ownerType: string, params?: ListStorageFilesParams): Promise<PageResult<StorageFile>> {\n const queryParams: Record<string, string> = {\n owner_unique_id: ownerUniqueId,\n owner_type: ownerType,\n };\n if (params?.page) queryParams['page'] = String(params.page);\n if (params?.perPage) queryParams['records'] = String(params.perPage);\n if (params?.fileType) queryParams['file_type'] = params.fileType;\n if (params?.mimeType) queryParams['mime_type'] = params.mimeType;\n if (params?.status) queryParams['status'] = params.status;\n if (params?.search) queryParams['search'] = params.search;\n if (params?.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;\n\n const response = await transport.get<unknown>('/storage_files', { params: queryParams });\n return decodePageResult(response, storageFileMapper);\n },\n };\n}\n"],"names":["decodeOne","decodePageResult","storageFileMapper","createStorageFilesService","transport","_config","list","params","queryParams","page","String","perPage","ownerUniqueId","ownerType","fileType","mimeType","status","search","sortBy","sortOrder","response","get","uniqueId","upload","data","formData","FormData","append","file","fileName","generateThumbnail","undefined","generatePreview","payload","JSON","stringify","tags","post","headers","create","type","attributes","owner_unique_id","owner_type","file_name","file_type","file_size","fileSize","mime_type","content_url","contentUrl","storage_path","storagePath","storage_provider","storageProvider","update","put","thumbnail_url","thumbnailUrl","preview_url","previewUrl","enabled","delete","download","responseType","listByOwner"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,SAAS,EAAcC,gBAAgB,QAAQ,0BAA0B;AAQlF,SAASC,iBAAiB,QAAQ,iCAAiC;AAanE,OAAO,SAASC,0BAA0BC,SAAoB,EAAEC,OAA0B;IACxF,OAAO;QACL,MAAMC,MAAKC,MAA+B;YACxC,MAAMC,cAAsC,CAAC;YAC7C,IAAID,0BAAAA,OAAQE,IAAI,EAAED,WAAW,CAAC,OAAO,GAAG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AM;YACzD,IAAIT,0BAAAA,OAAQU,MAAM,EAAET,WAAW,CAAC,SAAS,GAAGD,OAAOU,MAAM;YACzD,IAAIV,0BAAAA,OAAQW,MAAM,EAAEV,WAAW,CAAC,OAAO,GAAGD,OAAOY,SAAS,KAAK,SAAS,CAAC,CAAC,EAAEZ,OAAOW,MAAM,CAAC,CAAC,GAAGX,OAAOW,MAAM;YAE3G,MAAME,WAAW,MAAMhB,UAAUiB,GAAG,CAAU,kBAAkB;gBAAEd,QAAQC;YAAY;YACtF,OAAOP,iBAAiBmB,UAAUlB;QACpC;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/types/entity-file.ts"],"sourcesContent":["import type { IdentityCore, EntityStatus } from '@23blocks/contracts';\n\nexport interface EntityFile extends IdentityCore {\n entityUniqueId: string;\n entityType: string;\n fileUniqueId: string;\n fileName: string;\n fileType?: string;\n fileSize?: number;\n mimeType?: string;\n contentUrl?: string;\n thumbnailUrl?: string;\n displayOrder?: number;\n status: EntityStatus;\n enabled: boolean;\n payload?: Record<string, unknown>;\n}\n\nexport interface AttachFileRequest {\n entityUniqueId: string;\n entityType: string;\n fileUniqueId: string;\n displayOrder?: number;\n payload?: Record<string, unknown>;\n}\n\nexport interface UpdateEntityFileRequest {\n displayOrder?: number;\n enabled?: boolean;\n status?: EntityStatus;\n payload?: Record<string, unknown>;\n}\n\nexport interface ListEntityFilesParams {\n page?: number;\n perPage?: number;\n entityUniqueId?: string;\n entityType?: string;\n fileType?: string;\n status?: EntityStatus;\n sortBy?: string;\n sortOrder?: 'asc' | 'desc';\n}\n\nexport interface ReorderFilesRequest {\n fileOrders: Array<{\n uniqueId: string;\n displayOrder: number;\n }>;\n}\n"],"names":[],"rangeMappings":"","mappings":"AA4CA,WAKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/types/file-schema.ts"],"sourcesContent":["import type { IdentityCore, EntityStatus } from '@23blocks/contracts';\n\nexport interface FileSchema extends IdentityCore {\n code: string;\n name: string;\n description?: string;\n allowedMimeTypes?: string[];\n maxFileSize?: number;\n required?: boolean;\n multiple?: boolean;\n status: EntityStatus;\n enabled: boolean;\n payload?: Record<string, unknown>;\n}\n\nexport interface CreateFileSchemaRequest {\n code: string;\n name: string;\n description?: string;\n allowedMimeTypes?: string[];\n maxFileSize?: number;\n required?: boolean;\n multiple?: boolean;\n payload?: Record<string, unknown>;\n}\n\nexport interface UpdateFileSchemaRequest {\n name?: string;\n description?: string;\n allowedMimeTypes?: string[];\n maxFileSize?: number;\n required?: boolean;\n multiple?: boolean;\n enabled?: boolean;\n status?: EntityStatus;\n payload?: Record<string, unknown>;\n}\n\nexport interface ListFileSchemasParams {\n page?: number;\n perPage?: number;\n status?: EntityStatus;\n search?: string;\n sortBy?: string;\n sortOrder?: 'asc' | 'desc';\n}\n"],"names":[],"rangeMappings":"","mappings":"AAsCA,WAOC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/types/index.ts"],"sourcesContent":["export * from './storage-file';\nexport * from './entity-file';\nexport * from './file-schema';\n"],"names":[],"rangeMappings":";;","mappings":"AAAA,cAAc,iBAAiB;AAC/B,cAAc,gBAAgB;AAC9B,cAAc,gBAAgB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/types/storage-file.ts"],"sourcesContent":["import type { IdentityCore, EntityStatus } from '@23blocks/contracts';\n\nexport interface StorageFile extends IdentityCore {\n ownerUniqueId: string;\n ownerType: string;\n fileName: string;\n fileType?: string;\n fileSize?: number;\n mimeType?: string;\n contentUrl?: string;\n thumbnailUrl?: string;\n previewUrl?: string;\n downloadUrl?: string;\n storagePath?: string;\n storageProvider?: string;\n status: EntityStatus;\n enabled: boolean;\n payload?: Record<string, unknown>;\n tags?: string[];\n createdBy?: string;\n updatedBy?: string;\n}\n\nexport interface CreateStorageFileRequest {\n ownerUniqueId: string;\n ownerType: string;\n fileName: string;\n fileType?: string;\n fileSize?: number;\n mimeType?: string;\n contentUrl?: string;\n storagePath?: string;\n storageProvider?: string;\n payload?: Record<string, unknown>;\n tags?: string[];\n}\n\nexport interface UpdateStorageFileRequest {\n fileName?: string;\n fileType?: string;\n contentUrl?: string;\n thumbnailUrl?: string;\n previewUrl?: string;\n enabled?: boolean;\n status?: EntityStatus;\n payload?: Record<string, unknown>;\n tags?: string[];\n}\n\nexport interface ListStorageFilesParams {\n page?: number;\n perPage?: number;\n ownerUniqueId?: string;\n ownerType?: string;\n fileType?: string;\n mimeType?: string;\n status?: EntityStatus;\n search?: string;\n sortBy?: string;\n sortOrder?: 'asc' | 'desc';\n}\n\nexport interface UploadFileRequest {\n file: File | Blob;\n ownerUniqueId: string;\n ownerType: string;\n fileName?: string;\n fileType?: string;\n generateThumbnail?: boolean;\n generatePreview?: boolean;\n payload?: Record<string, unknown>;\n tags?: string[];\n}\n"],"names":[],"rangeMappings":"","mappings":"AA8DA,WAUC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@23blocks/block-files",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Files block for 23blocks SDK - storage, upload, download, file management",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "23blocks <hello@23blocks.com>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/23blocks-OS/frontend-sdk.git",
|
|
10
|
+
"directory": "packages/block-files"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/23blocks-OS/frontend-sdk/tree/main/packages/block-files",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/23blocks-OS/frontend-sdk/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"23blocks",
|
|
18
|
+
"sdk",
|
|
19
|
+
"files",
|
|
20
|
+
"storage",
|
|
21
|
+
"upload",
|
|
22
|
+
"download",
|
|
23
|
+
"file-management"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"module": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
"./package.json": "./package.json",
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"!**/*.tsbuildinfo"
|
|
40
|
+
],
|
|
41
|
+
"nx": {
|
|
42
|
+
"sourceRoot": "packages/block-files/src",
|
|
43
|
+
"targets": {
|
|
44
|
+
"build": {
|
|
45
|
+
"executor": "@nx/js:swc",
|
|
46
|
+
"outputs": [
|
|
47
|
+
"{options.outputPath}"
|
|
48
|
+
],
|
|
49
|
+
"options": {
|
|
50
|
+
"outputPath": "packages/block-files/dist",
|
|
51
|
+
"main": "packages/block-files/src/index.ts",
|
|
52
|
+
"tsConfig": "packages/block-files/tsconfig.lib.json",
|
|
53
|
+
"skipTypeCheck": true,
|
|
54
|
+
"stripLeadingPaths": true
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@23blocks/contracts": "*",
|
|
61
|
+
"@23blocks/jsonapi-codec": "*",
|
|
62
|
+
"@swc/helpers": "~0.5.11"
|
|
63
|
+
}
|
|
64
|
+
}
|