@sarangkale66/pixxo-sdk-node 1.0.2 → 1.0.3
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/README.md +99 -99
- package/dist/pixxo.d.ts.map +1 -1
- package/dist/pixxo.js +1 -1
- package/dist/pixxo.js.map +1 -1
- package/dist/utils.d.ts +11 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +25 -0
- package/dist/utils.js.map +1 -1
- package/package.json +32 -32
package/README.md
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
# Pixxo Node.js SDK
|
|
2
|
-
|
|
3
|
-
> Drop-in replacement for the [ImageKit Node.js SDK](https://github.com/imagekit-developer/imagekit-nodejs). Swap `import ImageKit from 'imagekit'` with `import Pixxo from 'pixxo'` — zero refactor required.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install pixxo
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Quick Start
|
|
12
|
-
|
|
13
|
-
```ts
|
|
14
|
-
import Pixxo from "pixxo";
|
|
15
|
-
import fs from "fs";
|
|
16
|
-
|
|
17
|
-
const pixxo = new Pixxo({
|
|
18
|
-
email: "you@example.com",
|
|
19
|
-
password: "your-password",
|
|
20
|
-
});
|
|
21
|
-
|
|
1
|
+
# Pixxo Node.js SDK
|
|
2
|
+
|
|
3
|
+
> Drop-in replacement for the [ImageKit Node.js SDK](https://github.com/imagekit-developer/imagekit-nodejs). Swap `import ImageKit from 'imagekit'` with `import Pixxo from 'pixxo'` — zero refactor required.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install pixxo
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import Pixxo from "pixxo";
|
|
15
|
+
import fs from "fs";
|
|
16
|
+
|
|
17
|
+
const pixxo = new Pixxo({
|
|
18
|
+
email: "you@example.com",
|
|
19
|
+
password: "your-password",
|
|
20
|
+
});
|
|
21
|
+
|
|
22
22
|
const result = await pixxo.upload({
|
|
23
23
|
file: fs.readFileSync("receipt.pdf"),
|
|
24
24
|
fileName: "receipt.pdf",
|
|
25
25
|
folder: "/receipts",
|
|
26
26
|
});
|
|
27
|
-
|
|
28
|
-
console.log(result.url); // https://px.pixxo.io/…
|
|
27
|
+
|
|
28
|
+
console.log(result.url); // https://px.pixxo.io/…
|
|
29
29
|
console.log(result.fileId); // MongoDB ObjectId
|
|
30
30
|
console.log(result.name); // receipt.pdf
|
|
31
31
|
```
|
|
@@ -39,79 +39,79 @@ const result = await pixxo.upload({
|
|
|
39
39
|
folder: "/products/images",
|
|
40
40
|
});
|
|
41
41
|
```
|
|
42
|
-
|
|
43
|
-
## Constructor Options
|
|
44
|
-
|
|
45
|
-
| Option | Type | Required | Default | Description |
|
|
46
|
-
|---|---|---|---|---|
|
|
47
|
-
| `email` | `string` | ✅ | — | Pixxo account email |
|
|
48
|
-
| `password` | `string` | ✅ | — | Pixxo account password |
|
|
49
|
-
| `baseUrl` | `string` | — | `https://api.pixxo.io` | API base URL |
|
|
50
|
-
| `cdnDomain` | `string` | — | `px.pixxo.io` | CDN domain for returned URLs |
|
|
51
|
-
| `maxRetries` | `number` | — | `2` | Retry attempts for S3 upload failures |
|
|
52
|
-
| `publicKey` | `string` | — | — | *Ignored* (ImageKit compat) |
|
|
53
|
-
| `privateKey` | `string` | — | — | *Ignored* (ImageKit compat) |
|
|
54
|
-
| `urlEndpoint` | `string` | — | — | *Ignored* (ImageKit compat) |
|
|
55
|
-
|
|
56
|
-
## `upload(options)`
|
|
57
|
-
|
|
58
|
-
### Options
|
|
59
|
-
|
|
60
|
-
| Option | Type | Required | Description |
|
|
61
|
-
|---|---|---|---|
|
|
62
|
-
| `file` | `Buffer \| string` | ✅ | Buffer, base64 string, or file path |
|
|
63
|
-
| `fileName` | `string` | ✅ | File name with extension |
|
|
64
|
-
| `folder` | `string` | — | Destination folder (e.g. `"/receipts"`) |
|
|
65
|
-
| `useUniqueFileName` | `boolean` | — | Append unique suffix (default: `true`) |
|
|
66
|
-
|
|
67
|
-
### Response
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
{
|
|
71
|
-
url: string; // CDN URL
|
|
72
|
-
fileId: string; // Pixxo asset ID
|
|
73
|
-
name: string; // Stored file name
|
|
74
|
-
fileType: string; // MIME type
|
|
75
|
-
size: number; // Size in bytes
|
|
76
|
-
folderId: string | null;
|
|
77
|
-
s3Key: string;
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## Migration from ImageKit
|
|
82
|
-
|
|
83
|
-
```diff
|
|
84
|
-
- import ImageKit from "imagekit";
|
|
85
|
-
+ import Pixxo from "pixxo";
|
|
86
|
-
|
|
87
|
-
- const imagekit = new ImageKit({
|
|
88
|
-
- publicKey: "...",
|
|
89
|
-
- privateKey: "...",
|
|
90
|
-
- urlEndpoint: "...",
|
|
91
|
-
- });
|
|
92
|
-
+ const imagekit = new Pixxo({
|
|
93
|
-
+ email: "you@example.com",
|
|
94
|
-
+ password: "your-password",
|
|
95
|
-
+ });
|
|
96
|
-
|
|
97
|
-
// Everything else stays the same!
|
|
98
|
-
const result = await imagekit.upload({
|
|
99
|
-
file: buffer,
|
|
100
|
-
fileName: "photo.jpg",
|
|
101
|
-
folder: "/products",
|
|
102
|
-
});
|
|
103
|
-
console.log(result.url);
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Features
|
|
107
|
-
|
|
108
|
-
- **Token caching** — authenticates once, reuses token until expiry
|
|
109
|
-
- **Automatic retry** — exponential back-off for S3 upload failures
|
|
110
|
-
- **Recursive folder creation** — deeply nested paths just work
|
|
111
|
-
- **Multiple file input types** — Buffer, base64, file path
|
|
112
|
-
- **ImageKit-compatible response** — `url`, `fileId`, `name`
|
|
113
|
-
- **Zero dependencies** — uses native `fetch` (Node 18+)
|
|
114
|
-
|
|
115
|
-
## License
|
|
116
|
-
|
|
117
|
-
MIT
|
|
42
|
+
|
|
43
|
+
## Constructor Options
|
|
44
|
+
|
|
45
|
+
| Option | Type | Required | Default | Description |
|
|
46
|
+
|---|---|---|---|---|
|
|
47
|
+
| `email` | `string` | ✅ | — | Pixxo account email |
|
|
48
|
+
| `password` | `string` | ✅ | — | Pixxo account password |
|
|
49
|
+
| `baseUrl` | `string` | — | `https://api.pixxo.io` | API base URL |
|
|
50
|
+
| `cdnDomain` | `string` | — | `px.pixxo.io` | CDN domain for returned URLs |
|
|
51
|
+
| `maxRetries` | `number` | — | `2` | Retry attempts for S3 upload failures |
|
|
52
|
+
| `publicKey` | `string` | — | — | *Ignored* (ImageKit compat) |
|
|
53
|
+
| `privateKey` | `string` | — | — | *Ignored* (ImageKit compat) |
|
|
54
|
+
| `urlEndpoint` | `string` | — | — | *Ignored* (ImageKit compat) |
|
|
55
|
+
|
|
56
|
+
## `upload(options)`
|
|
57
|
+
|
|
58
|
+
### Options
|
|
59
|
+
|
|
60
|
+
| Option | Type | Required | Description |
|
|
61
|
+
|---|---|---|---|
|
|
62
|
+
| `file` | `Buffer \| string` | ✅ | Buffer, base64 string, or file path |
|
|
63
|
+
| `fileName` | `string` | ✅ | File name with extension |
|
|
64
|
+
| `folder` | `string` | — | Destination folder (e.g. `"/receipts"`) |
|
|
65
|
+
| `useUniqueFileName` | `boolean` | — | Append unique suffix (default: `true`) |
|
|
66
|
+
|
|
67
|
+
### Response
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
{
|
|
71
|
+
url: string; // CDN URL
|
|
72
|
+
fileId: string; // Pixxo asset ID
|
|
73
|
+
name: string; // Stored file name
|
|
74
|
+
fileType: string; // MIME type
|
|
75
|
+
size: number; // Size in bytes
|
|
76
|
+
folderId: string | null;
|
|
77
|
+
s3Key: string;
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Migration from ImageKit
|
|
82
|
+
|
|
83
|
+
```diff
|
|
84
|
+
- import ImageKit from "imagekit";
|
|
85
|
+
+ import Pixxo from "pixxo";
|
|
86
|
+
|
|
87
|
+
- const imagekit = new ImageKit({
|
|
88
|
+
- publicKey: "...",
|
|
89
|
+
- privateKey: "...",
|
|
90
|
+
- urlEndpoint: "...",
|
|
91
|
+
- });
|
|
92
|
+
+ const imagekit = new Pixxo({
|
|
93
|
+
+ email: "you@example.com",
|
|
94
|
+
+ password: "your-password",
|
|
95
|
+
+ });
|
|
96
|
+
|
|
97
|
+
// Everything else stays the same!
|
|
98
|
+
const result = await imagekit.upload({
|
|
99
|
+
file: buffer,
|
|
100
|
+
fileName: "photo.jpg",
|
|
101
|
+
folder: "/products",
|
|
102
|
+
});
|
|
103
|
+
console.log(result.url);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Features
|
|
107
|
+
|
|
108
|
+
- **Token caching** — authenticates once, reuses token until expiry
|
|
109
|
+
- **Automatic retry** — exponential back-off for S3 upload failures
|
|
110
|
+
- **Recursive folder creation** — deeply nested paths just work
|
|
111
|
+
- **Multiple file input types** — Buffer, base64, file path
|
|
112
|
+
- **ImageKit-compatible response** — `url`, `fileId`, `name`
|
|
113
|
+
- **Zero dependencies** — uses native `fetch` (Node 18+)
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
MIT
|
package/dist/pixxo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pixxo.d.ts","sourceRoot":"","sources":["../src/pixxo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pixxo.d.ts","sourceRoot":"","sources":["../src/pixxo.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAGV,WAAW,EACX,aAAa,EACb,cAAc,EAEf,MAAM,SAAS,CAAC;AAajB,cAAM,KAAK;IACT,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAEpC,uBAAuB;IACvB,OAAO,CAAC,KAAK,CAAuB;IACpC,mDAAmD;IACnD,OAAO,CAAC,WAAW,CAAa;gBAEpB,MAAM,EAAE,WAAW;IAa/B;;OAEG;YACW,QAAQ;IAuBtB;;;;;;;;;;;;;OAaG;IACG,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;YAoF/C,eAAe;IAyB7B;;OAEG;IACH,OAAO,CAAC,aAAa;IAIrB;;;OAGG;IACH,OAAO,CAAC,WAAW;CAGpB;AAED,SAAS,KAAK,CAAC"}
|
package/dist/pixxo.js
CHANGED
|
@@ -68,7 +68,7 @@ class Pixxo {
|
|
|
68
68
|
// ── Resolve file ─────────────────────────────────────────────────
|
|
69
69
|
const resolvedFile = (0, utils_1.resolveUploadFile)(options.file);
|
|
70
70
|
const buffer = resolvedFile.buffer;
|
|
71
|
-
const fileName = options.fileName;
|
|
71
|
+
const fileName = (0, utils_1.ensureFileExtension)(options.fileName, resolvedFile.extension);
|
|
72
72
|
const fileType = resolvedFile.mimeType || (0, utils_1.getMimeType)(fileName);
|
|
73
73
|
const fileSize = buffer.length;
|
|
74
74
|
// ── Normalise folder ─────────────────────────────────────────────
|
package/dist/pixxo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pixxo.js","sourceRoot":"","sources":["../src/pixxo.ts"],"names":[],"mappings":";AAAA,iCAAyC;AACzC,qCAAsC;AACtC,qCAA4C;AAC5C,
|
|
1
|
+
{"version":3,"file":"pixxo.js","sourceRoot":"","sources":["../src/pixxo.ts"],"names":[],"mappings":";AAAA,iCAAyC;AACzC,qCAAsC;AACtC,qCAA4C;AAC5C,mCAMiB;AAUjB,8EAA8E;AAE9E,MAAM,gBA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AAqB;QACzC,OAAO,aAAa,CAAC,OAAO,CAAC,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAClE,CAAC;IAED;;;OAGG;IACK,WAAW,CAAC,KAAa;QAC/B,OAAO,WAAW,IAAI,CAAC,SAAS,IAAI,KAAK,EAAE,CAAC;IAC9C,CAAC;CACF;AAED,iBAAS,KAAK,CAAC"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -31,6 +31,17 @@ export declare function resolveUploadFile(file: Buffer | string): ResolvedUpload
|
|
|
31
31
|
* - file path → read from disk
|
|
32
32
|
*/
|
|
33
33
|
export declare function resolveFileToBuffer(file: Buffer | string): Buffer;
|
|
34
|
+
/**
|
|
35
|
+
* Ensure `fileName` ends with the correct extension. If the name already
|
|
36
|
+
* has a recognised extension, it is left untouched. Otherwise, the
|
|
37
|
+
* detected extension (if any) is appended.
|
|
38
|
+
*
|
|
39
|
+
* ensureFileExtension("avatar", "png") -> "avatar.png"
|
|
40
|
+
* ensureFileExtension("avatar.jpg", "png") -> "avatar.jpg"
|
|
41
|
+
* ensureFileExtension("my.course", "png") -> "my.course.png"
|
|
42
|
+
* ensureFileExtension("avatar", undefined) -> "avatar"
|
|
43
|
+
*/
|
|
44
|
+
export declare function ensureFileExtension(fileName: string, detectedExtension?: string): string;
|
|
34
45
|
/**
|
|
35
46
|
* Convert ImageKit‑style folder (`/receipts`) to Pixxo style (`receipts`).
|
|
36
47
|
* Also trims trailing slashes and collapses duplicate slashes.
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AA6CA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGpD;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAuED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAeA;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,kBAAkB,CA+B3E;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAEjE;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,iBAAiB,CAAC,EAAE,MAAM,GACzB,MAAM,CAWR;AAID;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAM3D;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C"}
|
package/dist/utils.js
CHANGED
|
@@ -37,6 +37,7 @@ exports.getMimeType = getMimeType;
|
|
|
37
37
|
exports.decodeBase64Image = decodeBase64Image;
|
|
38
38
|
exports.resolveUploadFile = resolveUploadFile;
|
|
39
39
|
exports.resolveFileToBuffer = resolveFileToBuffer;
|
|
40
|
+
exports.ensureFileExtension = ensureFileExtension;
|
|
40
41
|
exports.normalizeFolderPath = normalizeFolderPath;
|
|
41
42
|
exports.sleep = sleep;
|
|
42
43
|
const fs = __importStar(require("fs"));
|
|
@@ -195,6 +196,30 @@ function resolveUploadFile(file) {
|
|
|
195
196
|
function resolveFileToBuffer(file) {
|
|
196
197
|
return resolveUploadFile(file).buffer;
|
|
197
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Ensure `fileName` ends with the correct extension. If the name already
|
|
201
|
+
* has a recognised extension, it is left untouched. Otherwise, the
|
|
202
|
+
* detected extension (if any) is appended.
|
|
203
|
+
*
|
|
204
|
+
* ensureFileExtension("avatar", "png") -> "avatar.png"
|
|
205
|
+
* ensureFileExtension("avatar.jpg", "png") -> "avatar.jpg"
|
|
206
|
+
* ensureFileExtension("my.course", "png") -> "my.course.png"
|
|
207
|
+
* ensureFileExtension("avatar", undefined) -> "avatar"
|
|
208
|
+
*/
|
|
209
|
+
function ensureFileExtension(fileName, detectedExtension) {
|
|
210
|
+
if (!fileName)
|
|
211
|
+
return fileName;
|
|
212
|
+
const existingExt = path.extname(fileName).toLowerCase();
|
|
213
|
+
// Only treat as "already has extension" if it's a known one
|
|
214
|
+
if (existingExt && MIME_MAP[existingExt])
|
|
215
|
+
return fileName;
|
|
216
|
+
if (!detectedExtension)
|
|
217
|
+
return fileName;
|
|
218
|
+
const ext = detectedExtension.replace(/^\.+/, "").toLowerCase();
|
|
219
|
+
if (!ext)
|
|
220
|
+
return fileName;
|
|
221
|
+
return `${fileName}.${ext}`;
|
|
222
|
+
}
|
|
198
223
|
// ─── Folder path normalisation ─────────────────────────────────────────────
|
|
199
224
|
/**
|
|
200
225
|
* Convert ImageKit‑style folder (`/receipts`) to Pixxo style (`receipts`).
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,kCAGC;AA6ED,8CAmBC;AAUD,8CA+BC;AAUD,kDAEC;AAYD,kDAcC;AAQD,kDAMC;AAKD,sBAEC;AAxPD,uCAAyB;AACzB,2CAA6B;AAE7B,8EAA8E;AAE9E,MAAM,QAAQ,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AE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@sarangkale66/pixxo-sdk-node",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Pixxo Node.js SDK — drop-in replacement for ImageKit SDK",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"prepublishOnly": "npm run build",
|
|
13
|
-
"typecheck": "tsc --noEmit"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"pixxo",
|
|
17
|
-
"imagekit",
|
|
18
|
-
"image",
|
|
19
|
-
"upload",
|
|
20
|
-
"cdn",
|
|
21
|
-
"asset-management",
|
|
22
|
-
"s3"
|
|
23
|
-
],
|
|
24
|
-
"author": "",
|
|
25
|
-
"license": "MIT",
|
|
26
|
-
"devDependencies": {
|
|
27
|
-
"@types/node": "^20.12.0",
|
|
28
|
-
"typescript": "^5.4.5"
|
|
29
|
-
},
|
|
30
|
-
"engines": {
|
|
31
|
-
"node": ">=18.0.0"
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@sarangkale66/pixxo-sdk-node",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Pixxo Node.js SDK — drop-in replacement for ImageKit SDK",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublishOnly": "npm run build",
|
|
13
|
+
"typecheck": "tsc --noEmit"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"pixxo",
|
|
17
|
+
"imagekit",
|
|
18
|
+
"image",
|
|
19
|
+
"upload",
|
|
20
|
+
"cdn",
|
|
21
|
+
"asset-management",
|
|
22
|
+
"s3"
|
|
23
|
+
],
|
|
24
|
+
"author": "",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^20.12.0",
|
|
28
|
+
"typescript": "^5.4.5"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18.0.0"
|
|
32
|
+
}
|
|
33
33
|
}
|