npm.io
6.19.0 • Published 4 weeks ago

@uploadcare/cname-prefix

Licence
MIT
Version
6.19.0
Deps
0
Size
21 kB
Vulns
0
Weekly
0
Stars
63

Uploadcare CNAME Prefix

This package provides a helper for working with Uploadcare CDN CNAME prefixes.

API Reference

Build Status NPM version GitHub release Uploadcare stack on StackShare

Install

npm install @uploadcare/cname-prefix

Usage

The package builds a subdomain-based (prefixed) CDN base from your public key. Two variants are available with identical output:

  • getPrefixedCdnBaseAsync uses the Web Crypto API (window.crypto.subtle), returns a Promise, and works in browsers in a secure context (HTTPS or localhost). It is not available in Node.js or non-secure contexts.
  • getPrefixedCdnBaseSync ships its own SHA-256, runs synchronously, and works anywhere: browsers (any context), Node.js, web workers, and edge runtimes.
import { getPrefixedCdnBaseAsync, getPrefixedCdnBaseSync } from '@uploadcare/cname-prefix'

await getPrefixedCdnBaseAsync('demopublickey', 'https://ucarecd.net')
// 'https://1s4oyld5dc.ucarecd.net'

getPrefixedCdnBaseSync('demopublickey', 'https://ucarecd.net')
// 'https://1s4oyld5dc.ucarecd.net'

Import from @uploadcare/cname-prefix/async or /sync to include just one variant. Use isPrefixedCdnBase(cdnBase, base) to check whether a CDN base is already prefixed.

Security issues

If you think you ran into something in Uploadcare libraries that might have security implications, please hit us up at bugbounty@uploadcare.com or Hackerone.

We'll contact you personally in a short time to fix an issue through co-op and prior to any public disclosure.

Feedback

Issues and PRs are welcome. You can provide your feedback or drop us a support request at hello@uploadcare.com.

Keywords