@degallery/node 0.3.0 → 0.4.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 +7 -7
- package/dist/lib/node.d.ts +9 -4
- package/dist/lib/node.d.ts.map +1 -1
- package/dist/lib/node.js +37 -2
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -25,10 +25,7 @@ pnpm add @degallery/node
|
|
|
25
25
|
The package re-exports `GalleryClient` and selected public SDK types:
|
|
26
26
|
|
|
27
27
|
```ts
|
|
28
|
-
import {
|
|
29
|
-
GalleryClient,
|
|
30
|
-
type GallerySummary,
|
|
31
|
-
} from '@degallery/node';
|
|
28
|
+
import { GalleryClient, type GallerySummary } from '@degallery/node';
|
|
32
29
|
```
|
|
33
30
|
|
|
34
31
|
## Configure a server client
|
|
@@ -57,16 +54,19 @@ import { createDeliveryToken } from '@degallery/node';
|
|
|
57
54
|
|
|
58
55
|
const token = createDeliveryToken(
|
|
59
56
|
{
|
|
60
|
-
|
|
61
|
-
environmentId: '
|
|
57
|
+
organizationId: 'organization-id',
|
|
58
|
+
environmentId: 'environment-id',
|
|
59
|
+
resource: 'asset-id',
|
|
60
|
+
revision: 3,
|
|
62
61
|
preset: 'large',
|
|
63
62
|
expiresAt: Math.floor(Date.now() / 1000) + 300,
|
|
63
|
+
keyId: 'v1',
|
|
64
64
|
},
|
|
65
65
|
process.env.DEGALLERY_DELIVERY_SECRET!,
|
|
66
66
|
);
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
The helper signs the
|
|
69
|
+
The helper signs the Worker-compatible claims (`iss`, `aud`, `org`, `env`, `resource`, `revision`, `preset`, `iat`, `exp`, and `kid`) with HMAC-SHA256. `expiresAt` is a Unix timestamp in seconds and the lifetime cannot exceed 15 minutes. The token is not an authorization policy by itself: validate ownership, visibility, expiry, and requested transformations before issuing it. Never issue a private delivery token in browser code.
|
|
70
70
|
|
|
71
71
|
## What this package exports
|
|
72
72
|
|
package/dist/lib/node.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
export { GalleryClient } from '@degallery/sdk';
|
|
2
2
|
export type { Asset, GalleryDetail, GalleryLinkPayload, GallerySummary, } from '@degallery/sdk';
|
|
3
3
|
export declare function node(): string;
|
|
4
|
-
export
|
|
5
|
-
|
|
4
|
+
export type DeliveryTokenInput = Readonly<{
|
|
5
|
+
organizationId: string;
|
|
6
6
|
environmentId: string;
|
|
7
|
-
|
|
7
|
+
resource: string;
|
|
8
|
+
revision: number;
|
|
9
|
+
preset: 'original' | 'thumbnail' | 'large';
|
|
8
10
|
expiresAt: number;
|
|
9
|
-
|
|
11
|
+
issuedAt?: number;
|
|
12
|
+
keyId?: string;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function createDeliveryToken(input: DeliveryTokenInput, secret: string): string;
|
|
10
15
|
//# sourceMappingURL=node.d.ts.map
|
package/dist/lib/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/lib/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,YAAY,EACV,KAAK,EACL,aAAa,EACb,kBAAkB,EAClB,cAAc,GACf,MAAM,gBAAgB,CAAC;AAExB,wBAAgB,IAAI,IAAI,MAAM,CAE7B;AAED,
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/lib/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,YAAY,EACV,KAAK,EACL,aAAa,EACb,kBAAkB,EAClB,cAAc,GACf,MAAM,gBAAgB,CAAC;AAExB,wBAAgB,IAAI,IAAI,MAAM,CAE7B;AAED,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC;AAEH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,UA0C5E"}
|
package/dist/lib/node.js
CHANGED
|
@@ -10,6 +10,41 @@ function node() {
|
|
|
10
10
|
return 'node';
|
|
11
11
|
}
|
|
12
12
|
function createDeliveryToken(input, secret) {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
if (!secret)
|
|
14
|
+
throw new TypeError('A delivery signing secret is required.');
|
|
15
|
+
const issuedAt = input.issuedAt ?? Math.floor(Date.now() / 1000);
|
|
16
|
+
const lifetime = input.expiresAt - issuedAt;
|
|
17
|
+
const keyId = input.keyId ?? 'v1';
|
|
18
|
+
if (!input.organizationId ||
|
|
19
|
+
input.organizationId.length > 128 ||
|
|
20
|
+
!input.environmentId ||
|
|
21
|
+
input.environmentId.length > 128 ||
|
|
22
|
+
!input.resource ||
|
|
23
|
+
input.resource.length > 128 ||
|
|
24
|
+
!Number.isSafeInteger(input.revision) ||
|
|
25
|
+
input.revision < 1 ||
|
|
26
|
+
!['original', 'thumbnail', 'large'].includes(input.preset) ||
|
|
27
|
+
!Number.isSafeInteger(issuedAt) ||
|
|
28
|
+
!Number.isSafeInteger(input.expiresAt) ||
|
|
29
|
+
!keyId ||
|
|
30
|
+
keyId.length > 128 ||
|
|
31
|
+
lifetime < 1 ||
|
|
32
|
+
lifetime > 900)
|
|
33
|
+
throw new TypeError('Delivery token claims are invalid.');
|
|
34
|
+
const payload = Buffer.from(JSON.stringify({
|
|
35
|
+
iss: 'thegallery',
|
|
36
|
+
aud: 'media-delivery',
|
|
37
|
+
org: input.organizationId,
|
|
38
|
+
env: input.environmentId,
|
|
39
|
+
resource: input.resource,
|
|
40
|
+
revision: input.revision,
|
|
41
|
+
preset: input.preset,
|
|
42
|
+
iat: issuedAt,
|
|
43
|
+
exp: input.expiresAt,
|
|
44
|
+
kid: keyId,
|
|
45
|
+
})).toString('base64url');
|
|
46
|
+
const signature = (0, node_crypto_1.createHmac)('sha256', secret)
|
|
47
|
+
.update(payload)
|
|
48
|
+
.digest('base64url');
|
|
49
|
+
return `${payload}.${signature}`;
|
|
15
50
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@degallery/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"lib:publish": "npm publish --access public"
|
|
9
|
-
},
|
|
10
7
|
"exports": {
|
|
11
8
|
"./package.json": "./package.json",
|
|
12
9
|
".": {
|
|
@@ -22,6 +19,9 @@
|
|
|
22
19
|
],
|
|
23
20
|
"dependencies": {
|
|
24
21
|
"tslib": "^2.3.0",
|
|
25
|
-
"@degallery/sdk": "
|
|
22
|
+
"@degallery/sdk": "0.4.0"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"lib:publish": "pnpm publish --access public"
|
|
26
26
|
}
|
|
27
|
-
}
|
|
27
|
+
}
|