@smoothcdn/loader 1.0.2 → 1.0.3

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.
@@ -23,7 +23,7 @@ export function normalizeConfig(scdnConfig) {
23
23
  return {
24
24
  ...scdnConfig,
25
25
  cdnUrl: scdnConfig.cdnUrl || resolveCdnUrl(scdnConfig),
26
- version: scdnConfig.version || "latest",
26
+ version: normalizeOptionalString(scdnConfig.version),
27
27
  replacePath: scdnConfig.replacePath || scdnConfig.replacePaths,
28
28
  variants: scdnConfig.variants || [
29
29
  {
@@ -38,6 +38,13 @@ export function normalizeConfig(scdnConfig) {
38
38
  ]
39
39
  };
40
40
  }
41
+ const normalizeOptionalString = (value) => {
42
+ if (typeof value !== "string") {
43
+ return undefined;
44
+ }
45
+ const trimmedValue = value.trim();
46
+ return trimmedValue || undefined;
47
+ };
41
48
  const resolveCdnUrl = (scdnConfig) => {
42
49
  if (scdnConfig.customSubdomain) {
43
50
  return `https://${scdnConfig.customSubdomain}.smoothcdn.com`;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/core/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKlD;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAgBhG;AAED,wBAAgB,yBAAyB,IAAI,MAAM,CAKlD;AAED,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,oBAAoB,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,MAAM,CAuBnG"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/core/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKlD;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAgBhG;AAED,wBAAgB,yBAAyB,IAAI,MAAM,CAKlD;AAED,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,oBAAoB,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,MAAM,CA0BnG"}
@@ -35,12 +35,15 @@ export function buildUrl(assetPath, variantSlugOrOptions) {
35
35
  const options = typeof variantSlugOrOptions === "string"
36
36
  ? { variantSlug: variantSlugOrOptions }
37
37
  : variantSlugOrOptions || {};
38
- const variantSlug = options.variantSlug || resolveDefaultVariantSlug();
39
- const version = options.version ?? config.version ?? "latest";
38
+ const defaultVariantSlug = resolveDefaultVariantSlug();
39
+ const variantSlug = options.variantSlug && options.variantSlug !== defaultVariantSlug
40
+ ? options.variantSlug
41
+ : undefined;
42
+ const version = normalizeOptionalString(options.version ?? config.version);
40
43
  const normalizedAssetPath = normalizePath(applyReplacePath(assetPath, config.replacePath));
41
44
  const pathname = config.customSubdomain
42
- ? `/${normalizedAssetPath}`
43
- : `/${config.userSlug}/${config.projectSlug}/${version}/${variantSlug}/${normalizedAssetPath}`;
45
+ ? joinUrlPath(version, normalizedAssetPath)
46
+ : joinUrlPath(config.userSlug, config.projectSlug, version, variantSlug, normalizedAssetPath);
44
47
  const url = new URL(pathname, config.cdnUrl || "https://cdn.smoothcdn.com");
45
48
  return url.toString();
46
49
  }
@@ -48,3 +51,16 @@ const toLocalAssetPath = (assetPath) => {
48
51
  const normalizedAssetPath = normalizePath(assetPath);
49
52
  return `/${normalizedAssetPath.replace(/^public\//, "")}`;
50
53
  };
54
+ const normalizeOptionalString = (value) => {
55
+ if (typeof value !== "string") {
56
+ return value;
57
+ }
58
+ const trimmedValue = value.trim();
59
+ return trimmedValue || undefined;
60
+ };
61
+ const joinUrlPath = (...segments) => {
62
+ return `/${segments
63
+ .filter((segment) => typeof segment === "string" && segment.length > 0)
64
+ .map((segment) => normalizePath(segment))
65
+ .join("/")}`;
66
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothcdn/loader",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Smooth CDN framework-aware asset loader",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
package/readme.md CHANGED
@@ -62,7 +62,10 @@ URLs use the standard Smooth CDN path:
62
62
 
63
63
  ```ts
64
64
  buildUrl("/public/logo.svg");
65
- // https://cdn.smoothcdn.com/<userSlug>/<projectSlug>/<version>/<variant>/public/logo.svg
65
+ // https://cdn.smoothcdn.com/<userSlug>/<projectSlug>/<version>/public/logo.svg
66
+
67
+ // When version is not configured:
68
+ // https://cdn.smoothcdn.com/<userSlug>/<projectSlug>/public/logo.svg
66
69
  ```
67
70
 
68
71
  ## TypeScript Asset Typing