@ckbox/sdk-node 2.9.0-rc.1
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.md +7 -0
- package/README.md +118 -0
- package/dist/assets.d.ts +29 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +48 -0
- package/dist/assets.js.map +1 -0
- package/dist/ckbox.d.ts +16 -0
- package/dist/ckbox.d.ts.map +1 -0
- package/dist/ckbox.js +33 -0
- package/dist/ckbox.js.map +1 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +2 -0
- package/dist/constants.js.map +1 -0
- package/dist/error.d.ts +18 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +39 -0
- package/dist/error.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/token.d.ts +26 -0
- package/dist/token.d.ts.map +1 -0
- package/dist/token.js +20 -0
- package/dist/token.js.map +1 -0
- package/dist/types.d.ts +135 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/uploader.d.ts +63 -0
- package/dist/uploader.d.ts.map +1 -0
- package/dist/uploader.js +164 -0
- package/dist/uploader.js.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +5 -0
- package/dist/utils.js.map +1 -0
- package/package.json +36 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
**CKBox** (https://ckeditor.com/ckbox/)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2003-2025, [CKSource Holding sp. z o.o.](https://cksource.com/) All rights reserved.
|
|
4
|
+
**CKBox** is licensed under a commercial license and is protected by copyright law. For more details about available licensing options please contact us at [sales@cksource.com](mailto:sales@cksource.com).
|
|
5
|
+
|
|
6
|
+
Trademarks
|
|
7
|
+
**CKBox** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com/) All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
|
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# CKBox NodeJS SDK
|
|
2
|
+
|
|
3
|
+
A lightweight JavaScript SDK for interacting with the CKBox API. This package provides easy integration between NodeJS application and CKBox services.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Using npm
|
|
9
|
+
npm install @ckbox/sdk-node
|
|
10
|
+
|
|
11
|
+
# Using yarn
|
|
12
|
+
yarn add @ckbox/sdk-node
|
|
13
|
+
|
|
14
|
+
# Using pnpm
|
|
15
|
+
pnpm add @ckbox/sdk-node
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Getting Started
|
|
19
|
+
|
|
20
|
+
To use the CKBox SDK, you'll need to obtain API credentials from your Customer Portal dashboard:
|
|
21
|
+
|
|
22
|
+
### Initialize CKBox instance
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
import { CKBox } from '@ckbox/sdk-node';
|
|
26
|
+
|
|
27
|
+
// Configure CKBox
|
|
28
|
+
const config = {
|
|
29
|
+
accessKey: 'your-access-key',
|
|
30
|
+
environmentId: 'your-environment-id',
|
|
31
|
+
workspaceId: 'your-workspace-id', // Optional
|
|
32
|
+
userId: 'user-id', // Optional
|
|
33
|
+
userName: 'User Name', // Optional
|
|
34
|
+
role: 'user' // Optional, defaults to 'user'
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Initialize the CKBox wrapper
|
|
38
|
+
const { uploader, assets } = new CKBox(config);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Uploading Files
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
// Upload a file from a path
|
|
45
|
+
const uploadedFile = await uploader.uploadFile('/path/to/image.jpg', {
|
|
46
|
+
categoryId: 'category-id', // Optional
|
|
47
|
+
folderId: 'folder-id', // Optional
|
|
48
|
+
onProgress: (progress) => {
|
|
49
|
+
console.log(`Upload progress: ${progress.progress}%`);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Upload a buffer
|
|
54
|
+
const buffer = Buffer.from('file content');
|
|
55
|
+
const uploadedBuffer = await uploader.uploadBuffer(buffer, 'filename.txt', {
|
|
56
|
+
categoryId: 'category-id'
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Upload a stream
|
|
60
|
+
const fileStream = fs.createReadStream('/path/to/file.pdf');
|
|
61
|
+
const uploadedStream = await uploader.uploadStream(fileStream, 'file.pdf', fileSize, {
|
|
62
|
+
folderId: 'folder-id'
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Managing Assets
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
// Get a specific asset by ID
|
|
70
|
+
const asset = await assets.getAsset('asset-id');
|
|
71
|
+
|
|
72
|
+
// List assets with pagination
|
|
73
|
+
const assetsList = await assets.getAssets({
|
|
74
|
+
offset: 0,
|
|
75
|
+
limit: 50,
|
|
76
|
+
sortBy: 'uploadedAt',
|
|
77
|
+
order: 'desc',
|
|
78
|
+
categoryId: 'category-id' // Optional filter
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Features
|
|
83
|
+
|
|
84
|
+
- Simple and intuitive API for interacting with CKBox service
|
|
85
|
+
- Secure authentication using JWT tokens
|
|
86
|
+
- File upload functionality with progress tracking
|
|
87
|
+
- Asset management (fetching and listing assets)
|
|
88
|
+
- Comprehensive error handling
|
|
89
|
+
- TypeScript support with full type definitions
|
|
90
|
+
- Lightweight with minimal dependencies
|
|
91
|
+
|
|
92
|
+
## API Reference
|
|
93
|
+
|
|
94
|
+
### `CKBoxConfig`
|
|
95
|
+
|
|
96
|
+
Configuration object for CKBox SDK:
|
|
97
|
+
|
|
98
|
+
| Property | Type | Required | Description |
|
|
99
|
+
|----------|------|----------|-------------|
|
|
100
|
+
| accessKey | string | Yes | The access key available in the Customer Portal dashboard |
|
|
101
|
+
| environmentId | string | Yes | The environment ID for CKBox instance |
|
|
102
|
+
| workspaceId | string | No | The workspace ID for the user |
|
|
103
|
+
| role | 'user' \| 'admin' \| 'superadmin' | No | The role of the user (defaults to 'user') |
|
|
104
|
+
| userId | string | No | The user ID for the user |
|
|
105
|
+
| userName | string | No | The user name for the user |
|
|
106
|
+
| serviceOrigin | string | No | Base URL for the CKBox service (defaults to 'https://api.ckbox.io') |
|
|
107
|
+
|
|
108
|
+
## Documentation
|
|
109
|
+
|
|
110
|
+
For more detailed information and examples, please refer to the [CKBox documentation](https://ckeditor.com/docs/ckbox/latest/guides/index.html).
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
Copyright (c) 2003-2025, [CKSource Holding sp. z o.o.](https://cksource.com/) All rights reserved.
|
|
115
|
+
**CKBox** is licensed under a commercial license and is protected by copyright law. For more details about available licensing options please contact us at [sales@cksource.com](mailto:sales@cksource.com).
|
|
116
|
+
|
|
117
|
+
Trademarks
|
|
118
|
+
**CKBox** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com/) All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
|
package/dist/assets.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CKBoxAsset, IPaginationOptions, IAssetDestination, CKBoxAssetList } from './types.js';
|
|
2
|
+
export interface IAssetsConfig {
|
|
3
|
+
jwt: string;
|
|
4
|
+
serviceOrigin: string;
|
|
5
|
+
workspaceId?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class CKBoxAssets {
|
|
8
|
+
private readonly _config;
|
|
9
|
+
private readonly _api;
|
|
10
|
+
constructor(_config: IAssetsConfig);
|
|
11
|
+
/**
|
|
12
|
+
* Get a single asset by ID
|
|
13
|
+
* @param id - The ID of the asset to get
|
|
14
|
+
* @returns The asset
|
|
15
|
+
*/
|
|
16
|
+
getAsset(id: string): Promise<CKBoxAsset>;
|
|
17
|
+
/**
|
|
18
|
+
* Get a list of assets
|
|
19
|
+
* @param options - The options for the request
|
|
20
|
+
* @returns The list of assets
|
|
21
|
+
*/
|
|
22
|
+
getAssets(options: IPaginationOptions & IAssetDestination): Promise<CKBoxAssetList>;
|
|
23
|
+
/**
|
|
24
|
+
* Delete an asset by ID
|
|
25
|
+
* @param id - The ID of the asset to delete
|
|
26
|
+
*/
|
|
27
|
+
deleteAsset(id: string): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE/F,MAAM,WAAW,aAAa;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,WAAW;IAGJ,OAAO,CAAC,QAAQ,CAAC,OAAO;IAF3C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgB;gBAED,OAAO,EAAE,aAAa;IAY1D;;;;OAIG;IACU,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAMtD;;;;OAIG;IACU,SAAS,CACrB,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,GAC7C,OAAO,CAAC,cAAc,CAAC;IAM1B;;;OAGG;IACU,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGnD"}
|
package/dist/assets.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
export class CKBoxAssets {
|
|
4
|
+
constructor(_config) {
|
|
5
|
+
this._config = _config;
|
|
6
|
+
this._api = axios.create({
|
|
7
|
+
baseURL: this._config.serviceOrigin,
|
|
8
|
+
headers: {
|
|
9
|
+
Authorization: this._config.jwt,
|
|
10
|
+
},
|
|
11
|
+
params: {
|
|
12
|
+
workspaceId: this._config.workspaceId,
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get a single asset by ID
|
|
18
|
+
* @param id - The ID of the asset to get
|
|
19
|
+
* @returns The asset
|
|
20
|
+
*/
|
|
21
|
+
getAsset(id) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const response = yield this._api.get(`/assets/${id}`);
|
|
24
|
+
return response.data;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get a list of assets
|
|
29
|
+
* @param options - The options for the request
|
|
30
|
+
* @returns The list of assets
|
|
31
|
+
*/
|
|
32
|
+
getAssets(options) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const response = yield this._api.get('/assets', { params: options });
|
|
35
|
+
return response.data;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Delete an asset by ID
|
|
40
|
+
* @param id - The ID of the asset to delete
|
|
41
|
+
*/
|
|
42
|
+
deleteAsset(id) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
yield this._api.post(`/assets/trash`, [id]);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.js","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":";AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAU7C,MAAM,OAAO,WAAW;IAGvB,YAAoC,OAAsB;QAAtB,YAAO,GAAP,OAAO,CAAe;QACzD,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC;YACxB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa;YACnC,OAAO,EAAE;gBACR,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG;aAC/B;YACD,MAAM,EAAE;gBACP,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW;aACrC;SACD,CAAC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACU,QAAQ,CAAC,EAAU;;YAC/B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YAEtD,OAAO,QAAQ,CAAC,IAAI,CAAC;QACtB,CAAC;KAAA;IAED;;;;OAIG;IACU,SAAS,CACrB,OAA+C;;YAE/C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;YAErE,OAAO,QAAQ,CAAC,IAAI,CAAC;QACtB,CAAC;KAAA;IAED;;;OAGG;IACU,WAAW,CAAC,EAAU;;YAClC,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7C,CAAC;KAAA;CACD"}
|
package/dist/ckbox.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CKBoxConfig } from './types.js';
|
|
2
|
+
import { CKBoxAssets } from './assets.js';
|
|
3
|
+
import { CKBoxUploader } from './uploader.js';
|
|
4
|
+
/**
|
|
5
|
+
* CKBox SDK wrapper that provides unified access to assets and uploader functionality
|
|
6
|
+
*/
|
|
7
|
+
export default class CKBox {
|
|
8
|
+
readonly assets: CKBoxAssets;
|
|
9
|
+
readonly uploader: CKBoxUploader;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new CKBox instance with the provided configuration
|
|
12
|
+
* @param config - The configuration object for CKBox
|
|
13
|
+
*/
|
|
14
|
+
constructor(config: CKBoxConfig);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=ckbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ckbox.d.ts","sourceRoot":"","sources":["../src/ckbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG9C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IACzB,SAAgB,MAAM,EAAE,WAAW,CAAC;IACpC,SAAgB,QAAQ,EAAE,aAAa,CAAC;IAExC;;;OAGG;gBACgB,MAAM,EAAE,WAAW;CA+BtC"}
|
package/dist/ckbox.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CKBoxAssets } from './assets.js';
|
|
2
|
+
import { CKBoxUploader } from './uploader.js';
|
|
3
|
+
import CKBoxToken from './token.js';
|
|
4
|
+
/**
|
|
5
|
+
* CKBox SDK wrapper that provides unified access to assets and uploader functionality
|
|
6
|
+
*/
|
|
7
|
+
export default class CKBox {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new CKBox instance with the provided configuration
|
|
10
|
+
* @param config - The configuration object for CKBox
|
|
11
|
+
*/
|
|
12
|
+
constructor(config) {
|
|
13
|
+
const { accessKey, environmentId, workspaceId, role, userId, userName, serviceOrigin = 'https://api.ckbox.io', } = config;
|
|
14
|
+
const jwt = new CKBoxToken(accessKey).createToken({
|
|
15
|
+
environmentId,
|
|
16
|
+
workspaceId,
|
|
17
|
+
ckboxRole: role,
|
|
18
|
+
userId,
|
|
19
|
+
userName,
|
|
20
|
+
});
|
|
21
|
+
this.assets = new CKBoxAssets({
|
|
22
|
+
jwt,
|
|
23
|
+
serviceOrigin,
|
|
24
|
+
workspaceId,
|
|
25
|
+
});
|
|
26
|
+
this.uploader = new CKBoxUploader({
|
|
27
|
+
jwt,
|
|
28
|
+
serviceOrigin,
|
|
29
|
+
workspaceId,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=ckbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ckbox.js","sourceRoot":"","sources":["../src/ckbox.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IAIzB;;;OAGG;IACH,YAAmB,MAAmB;QACrC,MAAM,EACL,SAAS,EACT,aAAa,EACb,WAAW,EACX,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,aAAa,GAAG,sBAAsB,GACtC,GAAG,MAAM,CAAC;QAEX,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC;YACjD,aAAa;YACb,WAAW;YACX,SAAS,EAAE,IAAI;YACf,MAAM;YACN,QAAQ;SACR,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,CAAC;YAC7B,GAAG;YACH,aAAa;YACb,WAAW;SACX,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,GAAG,IAAI,aAAa,CAAC;YACjC,GAAG;YACH,aAAa;YACb,WAAW;SACX,CAAC,CAAC;IACJ,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC"}
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CKBoxError } from './types.js';
|
|
2
|
+
export default class CKBoxSDKError extends Error {
|
|
3
|
+
/**
|
|
4
|
+
* Error code
|
|
5
|
+
*/
|
|
6
|
+
code: string;
|
|
7
|
+
/**
|
|
8
|
+
* Additional error details
|
|
9
|
+
*/
|
|
10
|
+
details?: Record<string, any>;
|
|
11
|
+
constructor(error: CKBoxError | string);
|
|
12
|
+
/**
|
|
13
|
+
* Create an error from API response
|
|
14
|
+
*/
|
|
15
|
+
static fromApiResponse(response: any): CKBoxSDKError;
|
|
16
|
+
static fromError(error: any): CKBoxSDKError;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,KAAK;IAC/C;;OAEG;IACI,IAAI,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACI,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBAElB,KAAK,EAAE,UAAU,GAAG,MAAM;IAe7C;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,GAAG,GAAG,aAAa;IAYpD,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,GAAG,aAAa;CAa3C"}
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export default class CKBoxSDKError extends Error {
|
|
2
|
+
constructor(error) {
|
|
3
|
+
if (typeof error === 'string') {
|
|
4
|
+
super(error);
|
|
5
|
+
this.code = '500';
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
super(error.message);
|
|
9
|
+
this.code = error.code;
|
|
10
|
+
this.details = error.details;
|
|
11
|
+
}
|
|
12
|
+
this.name = 'CKBoxSDKError';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create an error from API response
|
|
16
|
+
*/
|
|
17
|
+
static fromApiResponse(response) {
|
|
18
|
+
if (response) {
|
|
19
|
+
return new CKBoxSDKError({
|
|
20
|
+
code: response.statusCode || '500',
|
|
21
|
+
message: response.message || 'An error occurred with the CKBox API',
|
|
22
|
+
details: response.data,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return new CKBoxSDKError('An unknown error occurred with the CKBox API');
|
|
26
|
+
}
|
|
27
|
+
static fromError(error) {
|
|
28
|
+
var _a;
|
|
29
|
+
if (error instanceof CKBoxSDKError) {
|
|
30
|
+
return error;
|
|
31
|
+
}
|
|
32
|
+
if ((error === null || error === void 0 ? void 0 : error.response) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data)) {
|
|
33
|
+
return CKBoxSDKError.fromApiResponse(error.response.data);
|
|
34
|
+
}
|
|
35
|
+
const message = (error === null || error === void 0 ? void 0 : error.message) || 'An unknown error occurred';
|
|
36
|
+
return new CKBoxSDKError(message);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,KAAK;IAW/C,YAAmB,KAA0B;QAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC/B,KAAK,CAAC,KAAK,CAAC,CAAC;YAEb,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QACnB,CAAC;aAAM,CAAC;YACP,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAErB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;YACvB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC9B,CAAC;QAED,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,QAAa;QACnC,IAAI,QAAQ,EAAE,CAAC;YACd,OAAO,IAAI,aAAa,CAAC;gBACxB,IAAI,EAAE,QAAQ,CAAC,UAAU,IAAI,KAAK;gBAClC,OAAO,EAAE,QAAQ,CAAC,OAAO,IAAI,sCAAsC;gBACnE,OAAO,EAAE,QAAQ,CAAC,IAAI;aACtB,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,aAAa,CAAC,8CAA8C,CAAC,CAAC;IAC1E,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,KAAU;;QAC1B,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACd,CAAC;QAED,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,MAAI,MAAA,KAAK,CAAC,QAAQ,0CAAE,IAAI,CAAA,EAAE,CAAC;YAC7C,OAAO,aAAa,CAAC,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC3D,CAAC;QAED,MAAM,OAAO,GAAG,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,KAAI,2BAA2B,CAAC;QAE9D,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;CACD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
package/dist/token.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface TokenOptions {
|
|
2
|
+
userId?: string;
|
|
3
|
+
userName?: string;
|
|
4
|
+
ckboxRole?: string;
|
|
5
|
+
environmentId?: string;
|
|
6
|
+
workspaceId?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface TokenPayload {
|
|
9
|
+
aud: string;
|
|
10
|
+
sub: string;
|
|
11
|
+
user: {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
14
|
+
auth: {
|
|
15
|
+
ckbox: {
|
|
16
|
+
role: string;
|
|
17
|
+
workspaces?: string[];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export default class CKBoxToken {
|
|
22
|
+
private readonly _accessKey;
|
|
23
|
+
constructor(_accessKey: string);
|
|
24
|
+
createToken(options: TokenOptions): string;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;KACb,CAAC;IACF,IAAI,EAAE;QACL,KAAK,EAAE;YACN,IAAI,EAAE,MAAM,CAAC;YACb,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;SACtB,CAAC;KACF,CAAC;CACF;AAED,MAAM,CAAC,OAAO,OAAO,UAAU;IACX,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,MAAM;IAEtD,WAAW,CAAC,OAAO,EAAE,YAAY;CAyBjC"}
|
package/dist/token.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import jwt from 'jsonwebtoken';
|
|
2
|
+
export default class CKBoxToken {
|
|
3
|
+
constructor(_accessKey) {
|
|
4
|
+
this._accessKey = _accessKey;
|
|
5
|
+
}
|
|
6
|
+
createToken(options) {
|
|
7
|
+
const { userId = 'sdk-user-id', userName = 'sdk-user-name', ckboxRole = 'user', environmentId, workspaceId, } = options;
|
|
8
|
+
const payload = {
|
|
9
|
+
aud: environmentId,
|
|
10
|
+
sub: userId,
|
|
11
|
+
user: { name: userName },
|
|
12
|
+
auth: {
|
|
13
|
+
ckbox: Object.assign({ role: ckboxRole !== null && ckboxRole !== void 0 ? ckboxRole : 'user' }, (workspaceId && { workspaces: [workspaceId] })),
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
const token = jwt.sign(payload, this._accessKey, { algorithm: 'HS256', expiresIn: 3600 });
|
|
17
|
+
return token;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,cAAc,CAAC;AAwB/B,MAAM,CAAC,OAAO,OAAO,UAAU;IAC9B,YAAoC,UAAkB;QAAlB,eAAU,GAAV,UAAU,CAAQ;IAAG,CAAC;IAE1D,WAAW,CAAC,OAAqB;QAChC,MAAM,EACL,MAAM,GAAG,aAAa,EACtB,QAAQ,GAAG,eAAe,EAC1B,SAAS,GAAG,MAAM,EAClB,aAAa,EACb,WAAW,GACX,GAAG,OAAO,CAAC;QAEZ,MAAM,OAAO,GAAG;YACf,GAAG,EAAE,aAAa;YAClB,GAAG,EAAE,MAAM;YACX,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACxB,IAAI,EAAE;gBACL,KAAK,kBACJ,IAAI,EAAE,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,MAAM,IACtB,CAAC,WAAW,IAAI,EAAE,UAAU,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CACjD;aACD;SACD,CAAC;QAEF,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAE1F,OAAO,KAAK,CAAC;IACd,CAAC;CACD"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
export interface CKBoxConfig {
|
|
2
|
+
/**
|
|
3
|
+
* The access key available in the Customer Portal dashboard
|
|
4
|
+
*/
|
|
5
|
+
accessKey: string;
|
|
6
|
+
/**
|
|
7
|
+
* The environment ID for CKBox instance
|
|
8
|
+
*/
|
|
9
|
+
environmentId: string;
|
|
10
|
+
/**
|
|
11
|
+
* The workspace ID for the user
|
|
12
|
+
*/
|
|
13
|
+
workspaceId?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The role of the user
|
|
16
|
+
*/
|
|
17
|
+
role?: 'user' | 'admin' | 'superadmin';
|
|
18
|
+
/**
|
|
19
|
+
* The user ID for the user
|
|
20
|
+
*/
|
|
21
|
+
userId?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The user name for the user
|
|
24
|
+
*/
|
|
25
|
+
userName?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Base URL for the CKBox service (optional)
|
|
28
|
+
* @default 'https://api.ckbox.io'
|
|
29
|
+
*/
|
|
30
|
+
serviceOrigin?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface UploadProgress {
|
|
33
|
+
/**
|
|
34
|
+
* Uploaded bytes
|
|
35
|
+
*/
|
|
36
|
+
loaded: number;
|
|
37
|
+
/**
|
|
38
|
+
* Total bytes to upload
|
|
39
|
+
*/
|
|
40
|
+
total: number;
|
|
41
|
+
/**
|
|
42
|
+
* Upload progress percentage (0-100)
|
|
43
|
+
*/
|
|
44
|
+
progress: number;
|
|
45
|
+
}
|
|
46
|
+
export interface UploadOptions {
|
|
47
|
+
/**
|
|
48
|
+
* Callback for progress updates
|
|
49
|
+
*/
|
|
50
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
51
|
+
/**
|
|
52
|
+
* The category ID for the file
|
|
53
|
+
*/
|
|
54
|
+
categoryId?: string;
|
|
55
|
+
/**
|
|
56
|
+
* The folder ID for the file
|
|
57
|
+
*/
|
|
58
|
+
folderId?: string;
|
|
59
|
+
/**
|
|
60
|
+
* The workspace ID for the file
|
|
61
|
+
*/
|
|
62
|
+
workspaceId?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface CKBoxError {
|
|
65
|
+
/**
|
|
66
|
+
* Error code
|
|
67
|
+
*/
|
|
68
|
+
code: string;
|
|
69
|
+
/**
|
|
70
|
+
* Error message
|
|
71
|
+
*/
|
|
72
|
+
message: string;
|
|
73
|
+
/**
|
|
74
|
+
* Additional error details
|
|
75
|
+
*/
|
|
76
|
+
details?: Record<string, any>;
|
|
77
|
+
}
|
|
78
|
+
export interface IPaginationOptions {
|
|
79
|
+
/**
|
|
80
|
+
* The offset of the first item to return
|
|
81
|
+
*/
|
|
82
|
+
offset?: number;
|
|
83
|
+
/**
|
|
84
|
+
* The number of items to return
|
|
85
|
+
* @default 10
|
|
86
|
+
*/
|
|
87
|
+
limit?: number;
|
|
88
|
+
/**
|
|
89
|
+
* The field to sort by
|
|
90
|
+
* @default 'uploadedAt'
|
|
91
|
+
*/
|
|
92
|
+
sortBy?: 'name' | 'size' | 'uploadedAt' | 'lastModifiedAt';
|
|
93
|
+
/**
|
|
94
|
+
* The order to sort by
|
|
95
|
+
* @default 'desc'
|
|
96
|
+
*/
|
|
97
|
+
order?: 'asc' | 'desc';
|
|
98
|
+
}
|
|
99
|
+
export interface IAssetDestination {
|
|
100
|
+
/**
|
|
101
|
+
* The category ID for the asset
|
|
102
|
+
*/
|
|
103
|
+
categoryId?: string;
|
|
104
|
+
/**
|
|
105
|
+
* The folder ID for the asset
|
|
106
|
+
*/
|
|
107
|
+
folderId?: string;
|
|
108
|
+
}
|
|
109
|
+
export interface CKBoxAsset {
|
|
110
|
+
id: string;
|
|
111
|
+
name: string;
|
|
112
|
+
categoryId: string;
|
|
113
|
+
folderId?: string;
|
|
114
|
+
imageUrls?: {
|
|
115
|
+
[key: string]: string;
|
|
116
|
+
};
|
|
117
|
+
url: string;
|
|
118
|
+
size: number;
|
|
119
|
+
lastUsedAt: string;
|
|
120
|
+
lastModifiedAt: string;
|
|
121
|
+
path: string;
|
|
122
|
+
tags: string[];
|
|
123
|
+
metadata?: {
|
|
124
|
+
width?: number;
|
|
125
|
+
height?: number;
|
|
126
|
+
metadataProcessingStatus?: string;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export interface CKBoxAssetList {
|
|
130
|
+
items: CKBoxAsset[];
|
|
131
|
+
totalCount: number;
|
|
132
|
+
offset: number;
|
|
133
|
+
limit: number;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC3B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,YAAY,CAAC;IAEvC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAA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,CAAC;IAClB,SAAS,CAAC,EAAE;QACX,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACtB,CAAC;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,CAAC,EAAE;QACV,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,wBAAwB,CAAC,EAAE,MAAM,CAAC;KAClC,CAAC;CACF;AAED,MAAM,WAAW,cAAc;IAC9B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACd"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import { CKBoxAsset, UploadOptions } from './types.js';
|
|
3
|
+
export interface IUploaderConfig {
|
|
4
|
+
jwt: string;
|
|
5
|
+
serviceOrigin: string;
|
|
6
|
+
workspaceId?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class CKBoxUploader {
|
|
9
|
+
private readonly _config;
|
|
10
|
+
private readonly _api;
|
|
11
|
+
private readonly _uploadQueue;
|
|
12
|
+
private _activeUploads;
|
|
13
|
+
private readonly _maxConcurrency;
|
|
14
|
+
constructor(_config: IUploaderConfig);
|
|
15
|
+
/**
|
|
16
|
+
* Uploads a file from a file path
|
|
17
|
+
*
|
|
18
|
+
* @param filePath - The path to the file to upload
|
|
19
|
+
* @param options - The options for the upload
|
|
20
|
+
* @returns The uploaded asset
|
|
21
|
+
*/
|
|
22
|
+
uploadFile(filePath: string, options?: UploadOptions): Promise<CKBoxAsset>;
|
|
23
|
+
/**
|
|
24
|
+
* Uploads a file from a buffer
|
|
25
|
+
*
|
|
26
|
+
* @param buffer - The buffer to upload
|
|
27
|
+
* @param fileName - The name of the file
|
|
28
|
+
* @param options - The options for the upload
|
|
29
|
+
* @returns The uploaded asset
|
|
30
|
+
*/
|
|
31
|
+
uploadBuffer(buffer: Buffer, fileName: string, options?: UploadOptions): Promise<CKBoxAsset>;
|
|
32
|
+
/**
|
|
33
|
+
* Uploads a file from a stream
|
|
34
|
+
*
|
|
35
|
+
* @param stream - The file stream to upload
|
|
36
|
+
* @param fileName - The name of the file
|
|
37
|
+
* @param fileSize - The size of the file
|
|
38
|
+
* @param options - The options for the upload
|
|
39
|
+
* @returns The uploaded asset
|
|
40
|
+
*/
|
|
41
|
+
uploadStream(stream: fs.ReadStream | Buffer, fileName: string, fileSize: number, options?: UploadOptions): Promise<CKBoxAsset>;
|
|
42
|
+
/**
|
|
43
|
+
* Internal method to perform the actual file upload
|
|
44
|
+
*/
|
|
45
|
+
private _uploadFile;
|
|
46
|
+
/**
|
|
47
|
+
* Internal method to perform the actual buffer upload
|
|
48
|
+
*/
|
|
49
|
+
private _uploadBuffer;
|
|
50
|
+
/**
|
|
51
|
+
* Internal method to perform the actual stream upload
|
|
52
|
+
*/
|
|
53
|
+
private _uploadStream;
|
|
54
|
+
/**
|
|
55
|
+
* Processes the upload queue with concurrency control
|
|
56
|
+
*/
|
|
57
|
+
private _processQueue;
|
|
58
|
+
/**
|
|
59
|
+
* Queues an upload task and processes it when a slot becomes available
|
|
60
|
+
*/
|
|
61
|
+
private _queueUpload;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=uploader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploader.d.ts","sourceRoot":"","sources":["../src/uploader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAK9B,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAKvD,MAAM,WAAW,eAAe;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,aAAa;IAYN,OAAO,CAAC,QAAQ,CAAC,OAAO;IAX3C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgB;IAErC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAIrB;IAER,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAmB;gBAEf,OAAO,EAAE,eAAe;IAS5D;;;;;;OAMG;IACI,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;IAIrF;;;;;;;OAOG;IACI,YAAY,CAClB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,aAAkB,GACzB,OAAO,CAAC,UAAU,CAAC;IAItB;;;;;;;;OAQG;IACI,YAAY,CAClB,MAAM,EAAE,EAAE,CAAC,UAAU,GAAG,MAAM,EAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,aAAkB,GACzB,OAAO,CAAC,UAAU,CAAC;IAItB;;OAEG;YACW,WAAW;IAiBzB;;OAEG;YACW,aAAa;IAQ3B;;OAEG;YACW,aAAa;IA4D3B;;OAEG;YACW,aAAa;IA2B3B;;OAEG;IACH,OAAO,CAAC,YAAY;CAOpB"}
|
package/dist/uploader.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import axios from 'axios';
|
|
5
|
+
import FormData from 'form-data';
|
|
6
|
+
import { _isReadableStreamOrBuffer } from './utils.js';
|
|
7
|
+
import { MAX_CONCURRENCY } from './constants.js';
|
|
8
|
+
import CKBoxSDKError from './error.js';
|
|
9
|
+
export class CKBoxUploader {
|
|
10
|
+
constructor(_config) {
|
|
11
|
+
this._config = _config;
|
|
12
|
+
this._uploadQueue = [];
|
|
13
|
+
this._activeUploads = 0;
|
|
14
|
+
this._maxConcurrency = MAX_CONCURRENCY;
|
|
15
|
+
this._api = axios.create({
|
|
16
|
+
baseURL: this._config.serviceOrigin,
|
|
17
|
+
params: {
|
|
18
|
+
workspaceId: this._config.workspaceId,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Uploads a file from a file path
|
|
24
|
+
*
|
|
25
|
+
* @param filePath - The path to the file to upload
|
|
26
|
+
* @param options - The options for the upload
|
|
27
|
+
* @returns The uploaded asset
|
|
28
|
+
*/
|
|
29
|
+
uploadFile(filePath, options = {}) {
|
|
30
|
+
return this._queueUpload(() => this._uploadFile(filePath, options));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Uploads a file from a buffer
|
|
34
|
+
*
|
|
35
|
+
* @param buffer - The buffer to upload
|
|
36
|
+
* @param fileName - The name of the file
|
|
37
|
+
* @param options - The options for the upload
|
|
38
|
+
* @returns The uploaded asset
|
|
39
|
+
*/
|
|
40
|
+
uploadBuffer(buffer, fileName, options = {}) {
|
|
41
|
+
return this._queueUpload(() => this._uploadBuffer(buffer, fileName, options));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Uploads a file from a stream
|
|
45
|
+
*
|
|
46
|
+
* @param stream - The file stream to upload
|
|
47
|
+
* @param fileName - The name of the file
|
|
48
|
+
* @param fileSize - The size of the file
|
|
49
|
+
* @param options - The options for the upload
|
|
50
|
+
* @returns The uploaded asset
|
|
51
|
+
*/
|
|
52
|
+
uploadStream(stream, fileName, fileSize, options = {}) {
|
|
53
|
+
return this._queueUpload(() => this._uploadStream(stream, fileName, fileSize, options));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Internal method to perform the actual file upload
|
|
57
|
+
*/
|
|
58
|
+
_uploadFile(filePath_1) {
|
|
59
|
+
return __awaiter(this, arguments, void 0, function* (filePath, options = {}) {
|
|
60
|
+
if (!fs.existsSync(filePath)) {
|
|
61
|
+
throw new CKBoxSDKError(`File not found: ${filePath}`);
|
|
62
|
+
}
|
|
63
|
+
const fileStats = fs.statSync(filePath);
|
|
64
|
+
if (!fileStats.isFile()) {
|
|
65
|
+
throw new CKBoxSDKError(`Not a file: ${filePath}`);
|
|
66
|
+
}
|
|
67
|
+
const fileName = path.basename(filePath);
|
|
68
|
+
const fileStream = fs.createReadStream(filePath);
|
|
69
|
+
return yield this._uploadStream(fileStream, fileName, fileStats.size, options);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Internal method to perform the actual buffer upload
|
|
74
|
+
*/
|
|
75
|
+
_uploadBuffer(buffer_1, fileName_1) {
|
|
76
|
+
return __awaiter(this, arguments, void 0, function* (buffer, fileName, options = {}) {
|
|
77
|
+
return yield this._uploadStream(buffer, fileName, buffer.length, options);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Internal method to perform the actual stream upload
|
|
82
|
+
*/
|
|
83
|
+
_uploadStream(stream_1, fileName_1, fileSize_1) {
|
|
84
|
+
return __awaiter(this, arguments, void 0, function* (stream, fileName, fileSize, options = {}) {
|
|
85
|
+
try {
|
|
86
|
+
const formData = new FormData();
|
|
87
|
+
if (options.categoryId && options.folderId) {
|
|
88
|
+
throw new CKBoxSDKError('Cannot specify both categoryId and folderId');
|
|
89
|
+
}
|
|
90
|
+
if (!_isReadableStreamOrBuffer(stream)) {
|
|
91
|
+
throw new CKBoxSDKError('Invalid stream. Stream must be a valid readable stream.');
|
|
92
|
+
}
|
|
93
|
+
if (!fileName) {
|
|
94
|
+
throw new CKBoxSDKError('Invalid file name. File name is required.');
|
|
95
|
+
}
|
|
96
|
+
if (options.categoryId) {
|
|
97
|
+
formData.append('categoryId', options.categoryId);
|
|
98
|
+
}
|
|
99
|
+
if (options.folderId) {
|
|
100
|
+
formData.append('folderId', options.folderId);
|
|
101
|
+
}
|
|
102
|
+
formData.append('file', stream, { filename: fileName });
|
|
103
|
+
const uploadOptions = {
|
|
104
|
+
headers: Object.assign(Object.assign({}, formData.getHeaders()), { Authorization: this._config.jwt }),
|
|
105
|
+
};
|
|
106
|
+
if (options.onProgress) {
|
|
107
|
+
uploadOptions.onUploadProgress = (progressEvent) => {
|
|
108
|
+
var _a;
|
|
109
|
+
const loaded = progressEvent.loaded;
|
|
110
|
+
const total = (_a = progressEvent.total) !== null && _a !== void 0 ? _a : fileSize;
|
|
111
|
+
const progress = Math.min(Math.round((loaded * 100) / total), 100);
|
|
112
|
+
options.onProgress({
|
|
113
|
+
loaded,
|
|
114
|
+
total,
|
|
115
|
+
progress,
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const response = yield this._api.post('/assets', formData, uploadOptions);
|
|
120
|
+
return response.data;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
throw CKBoxSDKError.fromError(error);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Processes the upload queue with concurrency control
|
|
129
|
+
*/
|
|
130
|
+
_processQueue() {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
if (this._activeUploads >= this._maxConcurrency || this._uploadQueue.length === 0) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const task = this._uploadQueue.shift();
|
|
136
|
+
if (!task) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
this._activeUploads++;
|
|
140
|
+
try {
|
|
141
|
+
const result = yield task.uploadFn();
|
|
142
|
+
task.resolve(result);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
task.reject(error);
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
this._activeUploads--;
|
|
149
|
+
// Process next task in queue
|
|
150
|
+
this._processQueue();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Queues an upload task and processes it when a slot becomes available
|
|
156
|
+
*/
|
|
157
|
+
_queueUpload(uploadFn) {
|
|
158
|
+
return new Promise((resolve, reject) => {
|
|
159
|
+
this._uploadQueue.push({ resolve, reject, uploadFn });
|
|
160
|
+
this._processQueue();
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=uploader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploader.js","sourceRoot":"","sources":["../src/uploader.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAA4C,MAAM,OAAO,CAAC;AACjE,OAAO,QAAQ,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,aAAa,MAAM,YAAY,CAAC;AAQvC,MAAM,OAAO,aAAa;IAYzB,YAAoC,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QAT3C,iBAAY,GAIxB,EAAE,CAAC;QAEA,mBAAc,GAAG,CAAC,CAAC;QACV,oBAAe,GAAG,eAAe,CAAC;QAGlD,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC;YACxB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa;YACnC,MAAM,EAAE;gBACP,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW;aACrC;SACD,CAAC,CAAC;IACJ,CAAC;IAED;;;;;;OAM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I,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACtB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;oBAAS,CAAC;gBACV,IAAI,CAAC,cAAc,EAAE,CAAC;gBAEtB,6BAA6B;gBAC7B,IAAI,CAAC,aAAa,EAAE,CAAC;YACtB,CAAC;QACF,CAAC;KAAA;IAED;;OAEG;IACK,YAAY,CAAC,QAAmC;QACvD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACtC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;YAEtD,IAAI,CAAC,aAAa,EAAE,CAAC;QACtB,CAAC,CAAC,CAAC;IACJ,CAAC;CACD"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,yBAAyB,GAAI,UAAU,GAAG,YAEtD,CAAC"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,QAAa,EAAE,EAAE;IAC1D,OAAO,CAAC,CAAC,QAAQ,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1E,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"homepage": "https://ckeditor.com/ckbox",
|
|
3
|
+
"keywords": [
|
|
4
|
+
"file manager",
|
|
5
|
+
"ckeditor",
|
|
6
|
+
"file upload",
|
|
7
|
+
"image upload",
|
|
8
|
+
"upload",
|
|
9
|
+
"files",
|
|
10
|
+
"drag and drop",
|
|
11
|
+
"multilingual",
|
|
12
|
+
"component",
|
|
13
|
+
"react",
|
|
14
|
+
"uploader",
|
|
15
|
+
"rescaling images",
|
|
16
|
+
"responsive images",
|
|
17
|
+
"webp",
|
|
18
|
+
"api",
|
|
19
|
+
"cross-domain",
|
|
20
|
+
"image editing",
|
|
21
|
+
"multi-tenant application"
|
|
22
|
+
],
|
|
23
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
24
|
+
"name": "@ckbox/sdk-node",
|
|
25
|
+
"version": "2.9.0-rc.1",
|
|
26
|
+
"description": "CKBox SDK",
|
|
27
|
+
"main": "dist/index.js",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"axios": "^1.9.0",
|
|
31
|
+
"form-data": "^4.0.2",
|
|
32
|
+
"jsonwebtoken": "^9.0.2",
|
|
33
|
+
"tslib": "^2.8.1",
|
|
34
|
+
"vitest": "^3.1.1"
|
|
35
|
+
}
|
|
36
|
+
}
|