@manablox/media 0.2.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.
@@ -1,37 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { signTransform, transformPath, verifyTransform } from '../src/signing.js';
3
-
4
- const SECRET = 'a-signing-secret';
5
- const request = { assetId: 'asset-1', preset: 'thumb', format: 'webp' };
6
-
7
- describe('transform signing', () => {
8
- it('verifies a signature it produced', () => {
9
- expect(verifyTransform(SECRET, request, signTransform(SECRET, request))).toBe(true);
10
- });
11
-
12
- /**
13
- * Without a signature, `/media/:id/:preset` is a resize amplifier: a caller can force
14
- * an unbounded number of distinct decodes. Each component is bound into the MAC.
15
- */
16
- it('rejects a signature bound to a different asset, preset or format', () => {
17
- const signature = signTransform(SECRET, request);
18
- expect(verifyTransform(SECRET, { ...request, assetId: 'asset-2' }, signature)).toBe(false);
19
- expect(verifyTransform(SECRET, { ...request, preset: 'hero' }, signature)).toBe(false);
20
- expect(verifyTransform(SECRET, { ...request, format: 'avif' }, signature)).toBe(false);
21
- });
22
-
23
- it('rejects a signature made with another secret', () => {
24
- expect(verifyTransform(SECRET, request, signTransform('other', request))).toBe(false);
25
- });
26
-
27
- it('rejects malformed signatures without throwing', () => {
28
- for (const value of ['', 'x', 'x'.repeat(200)]) {
29
- expect(verifyTransform(SECRET, request, value)).toBe(false);
30
- }
31
- });
32
-
33
- it('builds a path carrying the signature', () => {
34
- const signature = signTransform(SECRET, request);
35
- expect(transformPath(request, signature)).toBe(`/media/asset-1/thumb.webp?s=${signature}`);
36
- });
37
- });
package/test/urls.test.ts DELETED
@@ -1,39 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { absoluteMediaUrl } from '../src/urls.js';
3
-
4
- /**
5
- * A relative `/media/…` resolves against whatever origin the *browser* is on, which for
6
- * a delivery consumer is the frontend, not the API. Found by driving `example-plain`
7
- * against a public instance on another port: every `<img>` 404ed.
8
- */
9
- describe('absoluteMediaUrl', () => {
10
- it('prefixes a root-relative path with the public origin', () => {
11
- expect(absoluteMediaUrl('/media/a1/original', 'https://cms.example.com')).toBe(
12
- 'https://cms.example.com/media/a1/original',
13
- );
14
- });
15
-
16
- it('does not double a trailing slash on the base', () => {
17
- expect(absoluteMediaUrl('/media/a1/original', 'https://cms.example.com/')).toBe(
18
- 'https://cms.example.com/media/a1/original',
19
- );
20
- });
21
-
22
- it('leaves an absolute URL alone, so an S3 or CDN URL survives', () => {
23
- const cdn = 'https://cdn.example.com/uploads/a1.jpg';
24
- expect(absoluteMediaUrl(cdn, 'https://cms.example.com')).toBe(cdn);
25
- expect(absoluteMediaUrl('//cdn.example.com/a1.jpg', 'https://cms.example.com')).toBe(
26
- '//cdn.example.com/a1.jpg',
27
- );
28
- });
29
-
30
- it('leaves the URL alone when no public origin is configured', () => {
31
- expect(absoluteMediaUrl('/media/a1/original', undefined)).toBe('/media/a1/original');
32
- });
33
-
34
- it('preserves a signed transform query', () => {
35
- expect(absoluteMediaUrl('/media/a1/card.webp?s=abc', 'https://cms.example.com')).toBe(
36
- 'https://cms.example.com/media/a1/card.webp?s=abc',
37
- );
38
- });
39
- });
package/tsconfig.json DELETED
@@ -1 +0,0 @@
1
- { "extends": "@manablox/config-typescript/library.json", "include": ["src", "test"] }
package/vitest.config.ts DELETED
@@ -1,2 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
- export default defineConfig({ test: { environment: 'node', include: ['test/**/*.test.ts'] } });