Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
404 changes: 105 additions & 299 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 16 additions & 8 deletions packages/cname-prefix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/esm/index.browser.mjs",
"require": "./dist/cjs/index.browser.cjs"
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./async": {
"import": "./dist/async.js",
"require": "./dist/async.cjs"
},
"./sync": {
"import": "./dist/sync.js",
"require": "./dist/sync.cjs"
}
},
"sideEffects": false,
Expand All @@ -24,9 +32,7 @@
"test": "npx playwright install-deps chromium && vitest --run --coverage",
"test:watch": "npx playwright install-deps chromium && vitest",
"prebuild": "npm run clean",
"build": "npm run build:types && npm run build:compile",
"build:types": "dts-bundle-generator --project tsconfig.dts.json -o dist/index.d.ts src/index.ts",
"build:compile": "rollup -c"
"build": "tsc && vite build"
},
"repository": {
"type": "git",
Expand All @@ -46,8 +52,10 @@
"signature"
],
"devDependencies": {
"@vitest/browser": "^3.2.3",
"@vitest/coverage-v8": "^3.2.3",
"vitest": "^3.2.3"
"@vitest/browser": "^3.2.4",
"@vitest/coverage-v8": "^3.2.4",
"vite": "^7.0.0",
"vite-plugin-dts": "^4.5.4",
"vitest": "^3.2.4"
}
}
12 changes: 0 additions & 12 deletions packages/cname-prefix/rollup.config.js

This file was deleted.

9 changes: 9 additions & 0 deletions packages/cname-prefix/src/async/getCnamePrefix.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getCnamePrefixAsync } from './getCnamePrefixAsync'
import { describe, it, expect } from 'vitest'

describe('getCnamePrefixAsync', () => {
it('should generate a CNAME prefix from a public key', async () => {
expect(await getCnamePrefixAsync('demopublickey')).toBe('1s4oyld5dc')
expect(await getCnamePrefixAsync('c8c237984266090ff9b8')).toBe('127mbvwq3b')
})
})
10 changes: 10 additions & 0 deletions packages/cname-prefix/src/async/getCnamePrefixAsync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { base36Encode } from '../common/base36Encode'
import { sha256EncodeAsync } from './sha256EncodeAsync'

const CNAME_PREFIX_LEN = 10

export const getCnamePrefixAsync = async (publicKey: string) => {
const sha256HexInt = await sha256EncodeAsync(publicKey)
const base36 = base36Encode(sha256HexInt)
return base36.slice(0, CNAME_PREFIX_LEN)
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { getPrefixedCdnBase } from './getPrefixedCdnBase'
import { getPrefixedCdnBaseAsync } from './getPrefixedCdnBaseAsync'
import { describe, it, expect } from 'vitest'

describe('getPrefixedCdnBase', () => {
describe('getPrefixedCdnBaseAsync', () => {
it('should return the prefixed CDN base URL', async () => {
const publicKey = 'demopublickey'
const cdnBase = 'https://ucarecdn.com'
const expected = 'https://1s4oyld5dc.ucarecdn.com'

const result = await getPrefixedCdnBase(publicKey, cdnBase)
const result = await getPrefixedCdnBaseAsync(publicKey, cdnBase)
expect(result).toBe(expected)
})
})
10 changes: 10 additions & 0 deletions packages/cname-prefix/src/async/getPrefixedCdnBaseAsync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { addPrefixToCdnBase } from '../common/addPrefixToCdnBase'
import { getCnamePrefixAsync } from './getCnamePrefixAsync'

export const getPrefixedCdnBaseAsync = async (
publicKey: string,
cdnBase: string
) => {
const prefix = await getCnamePrefixAsync(publicKey)
return addPrefixToCdnBase(prefix, cdnBase)
}
1 change: 1 addition & 0 deletions packages/cname-prefix/src/async/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { getPrefixedCdnBaseAsync } from './getPrefixedCdnBaseAsync'
8 changes: 8 additions & 0 deletions packages/cname-prefix/src/async/sha256EncodeAsync.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { sha256EncodeAsync } from './sha256EncodeAsync'
import { describe, it, expect } from 'vitest'

describe('sha256EncodeAsync', () => {
it('should encode a string to a SHA-256 hash and return it as an base 16 integer', async () => {
expect(await sha256EncodeAsync('demopublickey')).toBe(3.2328368644851214e76)
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const sha256Encode = async (data: string): Promise<number> => {
export const sha256EncodeAsync = async (data: string): Promise<number> => {
const msgUint8 = new TextEncoder().encode(data)
const hashBuffer = await window.crypto.subtle.digest('SHA-256', msgUint8)
const hashArray = Array.from(new Uint8Array(hashBuffer))
Expand Down
9 changes: 0 additions & 9 deletions packages/cname-prefix/src/getCnamePrefix.test.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/cname-prefix/src/getCnamePrefix.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/cname-prefix/src/getPrefixedCdnBase.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/cname-prefix/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { getPrefixedCdnBase } from './getPrefixedCdnBase'
export { getPrefixedCdnBaseAsync } from './async'
export { getPrefixedCdnBaseSync } from './sync'
8 changes: 0 additions & 8 deletions packages/cname-prefix/src/sha256Encode.test.ts

This file was deleted.

Loading