@nitida/asset-client 0.19.0 → 0.20.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/AGENTS.md CHANGED
@@ -117,5 +117,7 @@ was never renamed.
117
117
 
118
118
  ⚠️ `@aquienpz/asset-client` still exists on npm but is **frozen at 0.14.2 (2026-07-18)**. It
119
119
  predates `oext`, the `variants` array, and a `hasPreset` that does not claim an `original` the
120
- asset does not have. Install `@nitida/asset-client`. The `@aquienpz/tenant-config` and
121
- `@aquienpz/asset-uploader-*` packages are internal and are not on npm at all.
120
+ asset does not have. Install `@nitida/asset-client`. `@nitida/asset-uploader-web` and
121
+ `@nitida/asset-uploader-expo` ARE on npm since 2026-08-23 reach for one only
122
+ when you need an upload to survive a reload or a backgrounded app.
123
+ `@aquienpz/tenant-config` is still internal.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Espacio Futuro LTD
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -128,3 +128,13 @@ shape. `presets` is populated everywhere, on every version — so read existence
128
128
 
129
129
  Deeper guidance — including uploads, tenant onboarding and the CORS boundary — lives in
130
130
  `@nitida/sdk`'s `skills/nitida-sdk/SKILL.md`, which ships inside that package.
131
+
132
+ ## License
133
+
134
+ MIT — see [LICENSE](./LICENSE).
135
+
136
+ ⚠️ **The licence covers this client code, not the service.** MIT lets you use,
137
+ modify and redistribute the SDK; it does not grant access to nitida. The
138
+ service is governed by its own terms and plan tiers, and every call still needs
139
+ credentials issued to your project. Same shape as every other API client you
140
+ already depend on.
package/SECURITY.md ADDED
@@ -0,0 +1,56 @@
1
+ # Security
2
+
3
+ ## Reporting a vulnerability
4
+
5
+ Email **security@espaciofuturo.io**. Please do not open a public issue — a
6
+ public report is a disclosure, and it reaches attackers at the same moment it
7
+ reaches us.
8
+
9
+ Include what you have: the affected package and version, what you did, and what
10
+ happened. A URL that reproduces it is worth more than a paragraph describing
11
+ one. We will confirm receipt and tell you what we found.
12
+
13
+ ## What is in scope
14
+
15
+ The published client packages and the service they talk to:
16
+
17
+ - `@nitida/sdk`, `@nitida/asset-client`
18
+ - `@nitida/asset-compressor-web`, `@nitida/asset-compressor-native`
19
+ - `@nitida/asset-uploader-web`, `@nitida/asset-uploader-expo`
20
+ - the delivery edge (`8ok.uk`) and the API (`api.nitida.gofuture.space`)
21
+
22
+ ## Two behaviours that look like bugs and are not
23
+
24
+ Reported often enough to state up front, so a real report is not lost among
25
+ them:
26
+
27
+ **A 404 on a private asset is the feature.** An asset with
28
+ `visibility: "private"` answers 404 on every public URL — the raw path, every
29
+ stored variant, every `/t/` transform and every HLS segment. It is not a
30
+ missing file. Signed access lives at `/a/{tenant}/…?exp&sig`, minted on your
31
+ backend. See the SDK's `getPrivateAssetUrl`.
32
+
33
+ **A presigned upload URL is a bearer credential, on purpose.** The browser
34
+ uploader persists presigned R2 PUT URLs in IndexedDB, because that is what
35
+ resuming after a reload means. They are write-only, scoped to the parts of one
36
+ upload the holder started, expire in 60 minutes, and are deleted on complete
37
+ and on abort.
38
+
39
+ ## Credentials, and the one mistake that matters
40
+
41
+ An API key (`amk_rt_*`, `amk_ad_*`, `amk_ci_*`) is a **server-side** credential.
42
+ It must never reach a browser bundle, an `NEXT_PUBLIC_*` variable, or a mobile
43
+ app binary.
44
+
45
+ The same goes for a tenant's **URL signing key**: it mints signed URLs for
46
+ every private asset that tenant owns. Sign on your backend, or pre-sign at
47
+ build time.
48
+
49
+ The client packages are built so this is hard to get wrong — the web entrypoint
50
+ `@nitida/sdk/web` does not accept `apiKey` or `signingKey` at all; the types
51
+ reject them. If you find a path that leaks either one, that is exactly the
52
+ report we want.
53
+
54
+ If you believe a key has been exposed, email the address above and we will
55
+ rotate it. Rotating a signing key invalidates every URL already signed with it,
56
+ so tell us whether you have signed URLs in circulation.
package/dist/index.cjs CHANGED
@@ -616,8 +616,13 @@ function setTenantId(id) {
616
616
  function getTenantId() {
617
617
  return tenantId;
618
618
  }
619
- function variantPrefix() {
620
- return tenantId != null ? `${tenantId.toString(36)}/v/` : "";
619
+ function variantPrefix(caller) {
620
+ if (tenantId == null) {
621
+ throw new Error(
622
+ `${caller}: no tenant is configured, so every variant URL would 404. Call setTenantId(id) once at boot, or construct a NitidaClient with \`tenantId\` (it does this for you). The tenant is part of the CDN path (\`<cdn>/<tenantId base36>/v/<sha16>-<preset>.<ext>\`) and cannot be guessed from the asset.`
623
+ );
624
+ }
625
+ return `${tenantId.toString(36)}/v/`;
621
626
  }
622
627
  var ORIGINAL_EXT_BY_MIME = {
623
628
  "image/png": "png",
@@ -661,7 +666,7 @@ function getAssetUrl(asset, preset) {
661
666
  );
662
667
  const fallback = transformFallbackFor(asset, preset);
663
668
  if (fallback) return fallback;
664
- return buildPublicAssetUrl(asset, preset);
669
+ return buildPublicAssetUrl(asset, preset, "getAssetUrl");
665
670
  }
666
671
  function transformFallbackFor(asset, preset) {
667
672
  if (typeof asset.presets !== "string") return null;
@@ -670,23 +675,27 @@ function transformFallbackFor(asset, preset) {
670
675
  if (maxDim == null) return null;
671
676
  return `${cdnBaseUrl}/t/format=webp,width=${maxDim}/${asset.sha}.webp`;
672
677
  }
673
- function buildPublicAssetUrl(asset, preset) {
674
- assertSha(asset, "getPrivateAssetUrl");
678
+ function buildPublicAssetUrl(asset, preset, caller) {
679
+ assertSha(asset, caller);
675
680
  if (preset === "original") {
676
681
  const stored = asset.variants?.find((v) => v.preset === "original")?.url;
677
682
  if (stored) return stored;
678
683
  const ext = asset.oext || originalExtForMime(asset.mime);
679
- return `${cdnBaseUrl}/${variantPrefix()}${asset.sha}-${PRESET_SHORT.original}.${ext}`;
684
+ return `${cdnBaseUrl}/${variantPrefix(caller)}${asset.sha}-${PRESET_SHORT.original}.${ext}`;
680
685
  }
681
686
  if (preset === "hls") {
682
687
  const stored = asset.variants?.find((v) => v.preset === "hls")?.url;
683
688
  if (stored) return stored;
684
689
  return `${cdnBaseUrl}/t/format=hls/${asset.sha}.m3u8`;
685
690
  }
686
- return `${cdnBaseUrl}/${variantPrefix()}${asset.sha}-${PRESET_SHORT[preset]}.${PRESET_EXT[preset]}`;
691
+ return `${cdnBaseUrl}/${variantPrefix(caller)}${asset.sha}-${PRESET_SHORT[preset]}.${PRESET_EXT[preset]}`;
687
692
  }
688
693
  async function getPrivateAssetUrl(asset, preset, signingKey, opts) {
689
- return signAccessUrl(buildPublicAssetUrl(asset, preset), signingKey, opts);
694
+ return signAccessUrl(
695
+ buildPublicAssetUrl(asset, preset, "getPrivateAssetUrl"),
696
+ signingKey,
697
+ opts
698
+ );
690
699
  }
691
700
  async function getPrivateTransformUrl(asset, opts, signingKey, signOpts) {
692
701
  const url = buildTransformUrl(asset, opts);