@darco2903/cdn-api 1.0.7-beta.0 → 1.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/README.md +49 -9
- package/dist/client.d.ts +1039 -0
- package/{src/client.ts → dist/client.js} +15 -18
- package/{src/common.ts → dist/common.d.ts} +4 -4
- package/dist/common.js +4 -0
- package/dist/consts.d.ts +5 -0
- package/{src/consts.ts → dist/consts.js} +4 -8
- package/dist/contract/auth.d.ts +35 -0
- package/{src/contract/auth.ts → dist/contract/auth.js} +18 -22
- package/dist/contract/endpoint.d.ts +396 -0
- package/{src/contract/endpoint.ts → dist/contract/endpoint.js} +42 -53
- package/dist/contract/index.d.ts +2039 -0
- package/{src/contract/index.ts → dist/contract/index.js} +22 -27
- package/dist/contract/key.d.ts +15 -0
- package/{src/contract/key.ts → dist/contract/key.js} +15 -19
- package/dist/contract/list.d.ts +134 -0
- package/{src/contract/list.ts → dist/contract/list.js} +28 -30
- package/dist/contract/record.d.ts +412 -0
- package/{src/contract/record.ts → dist/contract/record.js} +71 -82
- package/dist/contract/service.d.ts +240 -0
- package/{src/contract/service.ts → dist/contract/service.js} +33 -44
- package/dist/contract/stats.d.ts +32 -0
- package/{src/contract/stats.ts → dist/contract/stats.js} +34 -36
- package/dist/contract/upload.d.ts +790 -0
- package/{src/contract/upload.ts → dist/contract/upload.js} +78 -82
- package/{src/index.ts → dist/index.d.ts} +2 -2
- package/dist/index.js +2 -0
- package/dist/server.d.ts +10 -0
- package/dist/server.js +58 -0
- package/{src/socket/index.ts → dist/socket/index.d.ts} +2 -2
- package/dist/socket/index.js +2 -0
- package/dist/socket/interface/index.d.ts +5 -0
- package/dist/socket/interface/index.js +1 -0
- package/{src/socket/interface/template.ts → dist/socket/interface/template.d.ts} +6 -7
- package/dist/socket/interface/template.js +1 -0
- package/dist/socket/types.d.ts +3 -0
- package/dist/socket/types.js +1 -0
- package/dist/types/creds.d.ts +8 -0
- package/{src/types/creds.ts → dist/types/creds.js} +5 -7
- package/dist/types/endpoint.d.ts +25 -0
- package/{src/types/endpoint.ts → dist/types/endpoint.js} +12 -19
- package/{src/types/index.ts → dist/types/index.d.ts} +6 -6
- package/dist/types/index.js +6 -0
- package/dist/types/jwt.d.ts +128 -0
- package/dist/types/jwt.js +33 -0
- package/dist/types/record.d.ts +97 -0
- package/{src/types/record.ts → dist/types/record.js} +25 -35
- package/dist/types/stats.d.ts +15 -0
- package/{src/types/stats.ts → dist/types/stats.js} +6 -9
- package/dist/types/upload.d.ts +45 -0
- package/{src/types/upload.ts → dist/types/upload.js} +12 -18
- package/dist/types.d.ts +32 -0
- package/dist/types.js +27 -0
- package/dist/uploader.d.ts +1044 -0
- package/{src/uploader.ts → dist/uploader.js} +72 -99
- package/package.json +2 -2
- package/.gitattributes +0 -2
- package/.github/workflows/release.yml +0 -116
- package/TODO.md +0 -0
- package/prettier.config.js +0 -24
- package/src/server.ts +0 -89
- package/src/socket/interface/index.ts +0 -12
- package/src/socket/types.ts +0 -7
- package/src/types/jwt.ts +0 -78
- package/src/types.ts +0 -38
- package/tests/keys/private.pem +0 -5
- package/tests/keys/public.pem +0 -4
- package/tests/keys.ts +0 -11
- package/tests/tsconfig.json +0 -12
- package/tests/vitest/jwt.test.ts +0 -38
- package/tsconfig.json +0 -14
package/README.md
CHANGED
|
@@ -2,24 +2,64 @@
|
|
|
2
2
|
|
|
3
3
|
## Description
|
|
4
4
|
|
|
5
|
-
This API
|
|
5
|
+
This package provides an API for interacting with Darco2903's CDN service, including functionalities for uploading, managing, and retrieving media assets. It includes both client and server utilities to facilitate the integration of CDN functionalities across multiple applications.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install cdn-api
|
|
11
|
-
npm install @ts-rest/core zod@3.22.3
|
|
10
|
+
npm install @darco2903/cdn-api
|
|
12
11
|
```
|
|
13
12
|
|
|
14
13
|
## Usage
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
### Creating a client
|
|
17
16
|
|
|
18
17
|
```ts
|
|
19
|
-
import {
|
|
20
|
-
import { contract } from "cdn-api";
|
|
18
|
+
import { createClient } from "@darco2903/cdn-api/client";
|
|
21
19
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const SERVER_ORIGIN = "https://cdn.example.com";
|
|
21
|
+
const cdnApi = createClient(SERVER_ORIGIN);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Signing a JWT token
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { CdnAssetTokenData, JWTSign } from "@darco2903/cdn-api/server";
|
|
28
|
+
import { Hour } from "@darco2903/secondthought";
|
|
29
|
+
|
|
30
|
+
const JWT_PRIVATE_KEY = "..."; // Private key here
|
|
31
|
+
const tokenData: CdnAssetTokenData = {
|
|
32
|
+
user_public_id: "user_public_id",
|
|
33
|
+
endpoint: "/test",
|
|
34
|
+
service: "auth",
|
|
35
|
+
type: "avatar",
|
|
36
|
+
};
|
|
37
|
+
const expiresIn = new Hour(1); // Token expires in 1 hour. Also accepts a number of seconds (e.g., 3600).
|
|
38
|
+
|
|
39
|
+
await JWTSign(tokenData, JWT_PRIVATE_KEY, expiresIn).match(
|
|
40
|
+
(signedToken) => {
|
|
41
|
+
console.log("JWT signing successful:", signedToken);
|
|
42
|
+
},
|
|
43
|
+
(err) => {
|
|
44
|
+
console.error(`JWT signing failed: ${err.message}`);
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Verifying a JWT token
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { JWTVerify } from "@darco2903/cdn-api/server";
|
|
53
|
+
|
|
54
|
+
const JWT_PUBLIC_KEY = "..."; // Public key here
|
|
55
|
+
const accessToken = "..."; // JWT token here
|
|
56
|
+
|
|
57
|
+
await JWTVerify(accessToken, JWT_PUBLIC_KEY).match(
|
|
58
|
+
(decodedToken) => {
|
|
59
|
+
console.log("JWT verification successful:", decodedToken);
|
|
60
|
+
},
|
|
61
|
+
(err) => {
|
|
62
|
+
console.error(`JWT verification failed: ${err.message}`);
|
|
63
|
+
}
|
|
64
|
+
);
|
|
25
65
|
```
|