@contractspec/lib.files 1.44.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/LICENSE +21 -0
- package/README.md +197 -0
- package/dist/contracts/index.d.ts +1140 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +856 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/docs/files.docblock.d.ts +1 -0
- package/dist/docs/files.docblock.js +71 -0
- package/dist/docs/files.docblock.js.map +1 -0
- package/dist/docs/index.d.ts +1 -0
- package/dist/docs/index.js +1 -0
- package/dist/entities/index.d.ts +169 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +265 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/events.d.ts +468 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +403 -0
- package/dist/events.js.map +1 -0
- package/dist/files.feature.d.ts +12 -0
- package/dist/files.feature.d.ts.map +1 -0
- package/dist/files.feature.js +126 -0
- package/dist/files.feature.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -0
- package/dist/storage/index.d.ts +201 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +269 -0
- package/dist/storage/index.js.map +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chaman Ventures, SASU
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# @contractspec/lib.files
|
|
2
|
+
|
|
3
|
+
Website: https://contractspec.io/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
Files, documents, and attachments module for ContractSpec applications.
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
This module provides a reusable file management system that can be used across all ContractSpec applications. It supports:
|
|
11
|
+
|
|
12
|
+
- **File Storage**: Upload and manage files with multiple storage backends
|
|
13
|
+
- **Document Versioning**: Track file versions over time
|
|
14
|
+
- **Polymorphic Attachments**: Attach files to any entity type
|
|
15
|
+
- **Access Control**: Control who can upload, view, and delete files
|
|
16
|
+
- **Presigned URLs**: Direct uploads to storage backends
|
|
17
|
+
|
|
18
|
+
## Entities
|
|
19
|
+
|
|
20
|
+
### File
|
|
21
|
+
|
|
22
|
+
Core file record.
|
|
23
|
+
|
|
24
|
+
| Field | Type | Description |
|
|
25
|
+
|-------|------|-------------|
|
|
26
|
+
| id | string | Unique identifier |
|
|
27
|
+
| name | string | Original file name |
|
|
28
|
+
| mimeType | string | MIME type |
|
|
29
|
+
| size | int | File size in bytes |
|
|
30
|
+
| storageProvider | enum | Storage backend (local, s3, etc.) |
|
|
31
|
+
| storagePath | string | Path in storage backend |
|
|
32
|
+
| checksum | string | File checksum (SHA-256) |
|
|
33
|
+
| ownerId | string | User who uploaded |
|
|
34
|
+
| orgId | string | Organization scope |
|
|
35
|
+
| isPublic | boolean | Whether file is publicly accessible |
|
|
36
|
+
| metadata | json | Additional metadata |
|
|
37
|
+
| createdAt | datetime | Upload timestamp |
|
|
38
|
+
| updatedAt | datetime | Last update timestamp |
|
|
39
|
+
|
|
40
|
+
### FileVersion
|
|
41
|
+
|
|
42
|
+
Version history for documents.
|
|
43
|
+
|
|
44
|
+
| Field | Type | Description |
|
|
45
|
+
|-------|------|-------------|
|
|
46
|
+
| id | string | Unique identifier |
|
|
47
|
+
| fileId | string | Parent file |
|
|
48
|
+
| version | int | Version number |
|
|
49
|
+
| size | int | Version size in bytes |
|
|
50
|
+
| storagePath | string | Path in storage |
|
|
51
|
+
| checksum | string | Version checksum |
|
|
52
|
+
| createdBy | string | User who created version |
|
|
53
|
+
| createdAt | datetime | Version timestamp |
|
|
54
|
+
| comment | string | Version comment |
|
|
55
|
+
|
|
56
|
+
### Attachment
|
|
57
|
+
|
|
58
|
+
Polymorphic link between files and entities.
|
|
59
|
+
|
|
60
|
+
| Field | Type | Description |
|
|
61
|
+
|-------|------|-------------|
|
|
62
|
+
| id | string | Unique identifier |
|
|
63
|
+
| fileId | string | Attached file |
|
|
64
|
+
| entityType | string | Target entity type |
|
|
65
|
+
| entityId | string | Target entity ID |
|
|
66
|
+
| attachmentType | string | Type of attachment (document, image, etc.) |
|
|
67
|
+
| order | int | Display order |
|
|
68
|
+
| metadata | json | Attachment-specific metadata |
|
|
69
|
+
| createdAt | datetime | Attachment timestamp |
|
|
70
|
+
|
|
71
|
+
## Contracts
|
|
72
|
+
|
|
73
|
+
### Commands
|
|
74
|
+
|
|
75
|
+
- `file.upload` - Upload a new file
|
|
76
|
+
- `file.update` - Update file metadata
|
|
77
|
+
- `file.delete` - Delete a file
|
|
78
|
+
- `file.createVersion` - Create a new version
|
|
79
|
+
- `attachment.attach` - Attach file to entity
|
|
80
|
+
- `attachment.detach` - Remove attachment
|
|
81
|
+
- `presignedUrl.create` - Get presigned upload URL
|
|
82
|
+
|
|
83
|
+
### Queries
|
|
84
|
+
|
|
85
|
+
- `file.get` - Get file by ID
|
|
86
|
+
- `file.list` - List files with filtering
|
|
87
|
+
- `file.getVersions` - Get file version history
|
|
88
|
+
- `file.download` - Get download URL
|
|
89
|
+
- `attachment.list` - List attachments for entity
|
|
90
|
+
|
|
91
|
+
## Events
|
|
92
|
+
|
|
93
|
+
- `file.uploaded` - File was uploaded
|
|
94
|
+
- `file.updated` - File metadata changed
|
|
95
|
+
- `file.deleted` - File was deleted
|
|
96
|
+
- `file.version_created` - New version created
|
|
97
|
+
- `attachment.attached` - File attached to entity
|
|
98
|
+
- `attachment.detached` - File detached from entity
|
|
99
|
+
|
|
100
|
+
## Storage Adapters
|
|
101
|
+
|
|
102
|
+
### LocalStorageAdapter
|
|
103
|
+
|
|
104
|
+
For development and testing. Stores files on the local filesystem.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { LocalStorageAdapter } from '@contractspec/lib.files/storage';
|
|
108
|
+
|
|
109
|
+
const storage = new LocalStorageAdapter({
|
|
110
|
+
basePath: './uploads',
|
|
111
|
+
baseUrl: 'http://localhost:3000/uploads',
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### S3StorageAdapter
|
|
116
|
+
|
|
117
|
+
For production use with AWS S3 or compatible services.
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { S3StorageAdapter } from '@contractspec/lib.files/storage';
|
|
121
|
+
|
|
122
|
+
const storage = new S3StorageAdapter({
|
|
123
|
+
bucket: 'my-bucket',
|
|
124
|
+
region: 'us-east-1',
|
|
125
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
126
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Usage
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import {
|
|
134
|
+
FileEntity,
|
|
135
|
+
UploadFileContract,
|
|
136
|
+
LocalStorageAdapter
|
|
137
|
+
} from '@contractspec/lib.files';
|
|
138
|
+
|
|
139
|
+
// Upload a file
|
|
140
|
+
const file = await fileService.upload({
|
|
141
|
+
name: 'document.pdf',
|
|
142
|
+
mimeType: 'application/pdf',
|
|
143
|
+
size: 1024,
|
|
144
|
+
content: buffer,
|
|
145
|
+
orgId: 'org-123',
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Attach to an entity
|
|
149
|
+
await attachmentService.attach({
|
|
150
|
+
fileId: file.id,
|
|
151
|
+
entityType: 'deal',
|
|
152
|
+
entityId: 'deal-456',
|
|
153
|
+
attachmentType: 'contract',
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// List attachments
|
|
157
|
+
const attachments = await attachmentService.list({
|
|
158
|
+
entityType: 'deal',
|
|
159
|
+
entityId: 'deal-456',
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Integration
|
|
164
|
+
|
|
165
|
+
This module integrates with:
|
|
166
|
+
|
|
167
|
+
- `@contractspec/lib.identity-rbac` - Access control
|
|
168
|
+
- `@contractspec/module.audit-trail` - File operations audit
|
|
169
|
+
|
|
170
|
+
## Schema Contribution
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { filesSchemaContribution } from '@contractspec/lib.files';
|
|
174
|
+
|
|
175
|
+
export const schemaComposition = {
|
|
176
|
+
modules: [
|
|
177
|
+
filesSchemaContribution,
|
|
178
|
+
// ... other modules
|
|
179
|
+
],
|
|
180
|
+
};
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|