@expofp/utils 3.0.0-alpha.9 → 3.0.1

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.
Files changed (30) hide show
  1. package/dist/index.d.ts +12 -12
  2. package/dist/index.js +12 -12
  3. package/dist/lib/{buildZipArchive.d.ts → build-zip-archive.d.ts} +1 -1
  4. package/dist/lib/{deepFreeze.d.ts → deep-freeze.d.ts} +1 -1
  5. package/dist/lib/{niceFetch.d.ts → fetch-with-retry.d.ts} +2 -2
  6. package/dist/lib/{niceFetch.js → fetch-with-retry.js} +3 -3
  7. package/dist/lib/{importFsPromises.d.ts → import-fs-promises.d.ts} +1 -1
  8. package/dist/lib/{importFsPromises.js → import-fs-promises.js} +1 -1
  9. package/dist/lib/{importJsonModule.d.ts → import-json.d.ts} +3 -3
  10. package/dist/lib/{importJsonModule.js → import-json.js} +6 -6
  11. package/dist/lib/{importNodeModule.d.ts → import-node-module.d.ts} +1 -1
  12. package/dist/lib/import-runtime-json.d.ts +2 -0
  13. package/dist/lib/{importRuntimeJsonModule.js → import-runtime-json.js} +4 -4
  14. package/dist/lib/{loadScript.d.ts → load-script.d.ts} +1 -1
  15. package/dist/lib/{loadScript.js → load-script.js} +2 -2
  16. package/dist/lib/{makeLocalPath.d.ts → make-local-path.d.ts} +1 -1
  17. package/dist/lib/{makeLocalPath.js → make-local-path.js} +8 -8
  18. package/dist/lib/{readFileFromUrl.d.ts → read-file-from-url.d.ts} +1 -1
  19. package/dist/lib/{readFileFromUrl.js → read-file-from-url.js} +3 -3
  20. package/dist/lib/safe-slugify.d.ts +7 -0
  21. package/dist/lib/{slugifyFilesystemUnique.js → safe-slugify.js} +1 -1
  22. package/dist/lib/short-hash.d.ts +2 -0
  23. package/dist/lib/{sha256Base62Truncated.js → short-hash.js} +1 -1
  24. package/package.json +2 -1
  25. package/dist/lib/importRuntimeJsonModule.d.ts +0 -2
  26. package/dist/lib/sha256Base62Truncated.d.ts +0 -2
  27. package/dist/lib/slugifyFilesystemUnique.d.ts +0 -7
  28. /package/dist/lib/{buildZipArchive.js → build-zip-archive.js} +0 -0
  29. /package/dist/lib/{deepFreeze.js → deep-freeze.js} +0 -0
  30. /package/dist/lib/{importNodeModule.js → import-node-module.js} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- export * from './lib/buildZipArchive.js';
1
+ export * from './lib/build-zip-archive.js';
2
2
  export * from './lib/clone.js';
3
- export * from './lib/deepFreeze.js';
4
- export * from './lib/importFsPromises.js';
5
- export * from './lib/importJsonModule.js';
6
- export * from './lib/importNodeModule.js';
7
- export * from './lib/importRuntimeJsonModule.js';
8
- export * from './lib/loadScript.js';
9
- export * from './lib/makeLocalPath.js';
10
- export * from './lib/niceFetch.js';
11
- export * from './lib/readFileFromUrl.js';
12
- export * from './lib/sha256Base62Truncated.js';
13
- export * from './lib/slugifyFilesystemUnique.js';
3
+ export * from './lib/deep-freeze.js';
4
+ export * from './lib/fetch-with-retry.js';
5
+ export * from './lib/import-fs-promises.js';
6
+ export * from './lib/import-json.js';
7
+ export * from './lib/import-node-module.js';
8
+ export * from './lib/import-runtime-json.js';
9
+ export * from './lib/load-script.js';
10
+ export * from './lib/make-local-path.js';
11
+ export * from './lib/read-file-from-url.js';
12
+ export * from './lib/safe-slugify.js';
13
+ export * from './lib/short-hash.js';
14
14
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
- export * from './lib/buildZipArchive.js';
1
+ export * from './lib/build-zip-archive.js';
2
2
  export * from './lib/clone.js';
3
- export * from './lib/deepFreeze.js';
4
- export * from './lib/importFsPromises.js';
5
- export * from './lib/importJsonModule.js';
6
- export * from './lib/importNodeModule.js';
7
- export * from './lib/importRuntimeJsonModule.js';
8
- export * from './lib/loadScript.js';
9
- export * from './lib/makeLocalPath.js';
10
- export * from './lib/niceFetch.js';
11
- export * from './lib/readFileFromUrl.js';
12
- export * from './lib/sha256Base62Truncated.js';
13
- export * from './lib/slugifyFilesystemUnique.js';
3
+ export * from './lib/deep-freeze.js';
4
+ export * from './lib/fetch-with-retry.js';
5
+ export * from './lib/import-fs-promises.js';
6
+ export * from './lib/import-json.js';
7
+ export * from './lib/import-node-module.js';
8
+ export * from './lib/import-runtime-json.js';
9
+ export * from './lib/load-script.js';
10
+ export * from './lib/make-local-path.js';
11
+ export * from './lib/read-file-from-url.js';
12
+ export * from './lib/safe-slugify.js';
13
+ export * from './lib/short-hash.js';
@@ -2,4 +2,4 @@ export declare function buildZipArchive(files: AsyncIterable<{
2
2
  path: string;
3
3
  data: Uint8Array;
4
4
  }>): Promise<Blob>;
5
- //# sourceMappingURL=buildZipArchive.d.ts.map
5
+ //# sourceMappingURL=build-zip-archive.d.ts.map
@@ -1,2 +1,2 @@
1
1
  export declare function deepFreeze<T>(obj: T): T;
2
- //# sourceMappingURL=deepFreeze.d.ts.map
2
+ //# sourceMappingURL=deep-freeze.d.ts.map
@@ -4,5 +4,5 @@
4
4
  * In Node.js environments, it uses the `fetch-retry` library to add retry capabilities.
5
5
  * Node.js are more prone to transient network errors, so retries can help improve reliability.
6
6
  */
7
- export declare const niceFetch: (...args: Parameters<typeof window.fetch>) => ReturnType<typeof window.fetch>;
8
- //# sourceMappingURL=niceFetch.d.ts.map
7
+ export declare const fetchWithRetry: (...args: Parameters<typeof window.fetch>) => ReturnType<typeof window.fetch>;
8
+ //# sourceMappingURL=fetch-with-retry.d.ts.map
@@ -6,15 +6,15 @@ let fn;
6
6
  * In Node.js environments, it uses the `fetch-retry` library to add retry capabilities.
7
7
  * Node.js are more prone to transient network errors, so retries can help improve reliability.
8
8
  */
9
- export const niceFetch = async function fetch(...args) {
9
+ export const fetchWithRetry = async function fetch(...args) {
10
10
  if (!fn) {
11
11
  if (typeof window !== 'undefined' && typeof document !== 'undefined') {
12
12
  fn = window.fetch.bind(window);
13
13
  }
14
14
  else {
15
15
  const fr = await import('fetch-retry');
16
- const fetchWithRetry = fr.default(globalThis.fetch);
17
- fn = fetchWithRetry;
16
+ const wrappedFetch = fr.default(globalThis.fetch);
17
+ fn = wrappedFetch;
18
18
  }
19
19
  }
20
20
  return fn(...args);
@@ -1,2 +1,2 @@
1
1
  export declare function importFsPromises(): Promise<typeof import("node:fs/promises")>;
2
- //# sourceMappingURL=importFsPromises.d.ts.map
2
+ //# sourceMappingURL=import-fs-promises.d.ts.map
@@ -1,4 +1,4 @@
1
- import { importNodeModule } from './importNodeModule.js';
1
+ import { importNodeModule } from './import-node-module.js';
2
2
  export async function importFsPromises() {
3
3
  return importNodeModule('node:fs/promises');
4
4
  }
@@ -1,4 +1,4 @@
1
- export interface ImportJsonModuleOptions {
1
+ export interface ImportJsonOptions {
2
2
  forceFetch?: boolean;
3
3
  fetchCache?: Map<string, Promise<unknown>>;
4
4
  /**
@@ -7,5 +7,5 @@ export interface ImportJsonModuleOptions {
7
7
  importCallback?: (url: string) => void;
8
8
  signal?: AbortSignal | null;
9
9
  }
10
- export declare function importJsonModule<T = unknown>(url: string, options?: ImportJsonModuleOptions): Promise<T>;
11
- //# sourceMappingURL=importJsonModule.d.ts.map
10
+ export declare function importJson<T = unknown>(url: string, options?: ImportJsonOptions): Promise<T>;
11
+ //# sourceMappingURL=import-json.d.ts.map
@@ -1,15 +1,15 @@
1
1
  import debug from 'debug';
2
- import { deepFreeze } from './deepFreeze.js';
3
- import { importFsPromises } from './importFsPromises.js';
4
- import { niceFetch } from './niceFetch.js';
5
- const log = debug('efp:utils:importJsonModule');
2
+ import { deepFreeze } from './deep-freeze.js';
3
+ import { fetchWithRetry } from './fetch-with-retry.js';
4
+ import { importFsPromises } from './import-fs-promises.js';
5
+ const log = debug('efp:utils:importJson');
6
6
  let importJsonNotAvailable;
7
7
  const jsonFrozen = new WeakSet();
8
8
  // ET: this is a workaround for Vite that analyzes dynamic imports and removes 'with' option
9
9
  // to be removed when Vite supports it properly
10
10
  // Cons: can have CSP issues in some environments
11
11
  const importJsonNative = new Function('url', 'return import(url, { with: { type: "json" } });');
12
- export async function importJsonModule(url, options) {
12
+ export async function importJson(url, options) {
13
13
  const opts = {
14
14
  forceFetch: options?.forceFetch || false,
15
15
  fetchCache: options?.fetchCache || new Map(),
@@ -59,7 +59,7 @@ async function loadJson(url, fetchCache, signal) {
59
59
  }
60
60
  const dataPromise = (async function loadJsonInner() {
61
61
  // in browser just use fetch, for node - fetch-retry
62
- const response = await niceFetch(url, { signal });
62
+ const response = await fetchWithRetry(url, { signal });
63
63
  if (!response.ok) {
64
64
  throw new Error(`Failed to fetch JSON from ${url}`);
65
65
  }
@@ -1,2 +1,2 @@
1
1
  export declare function importNodeModule<T>(moduleName: string): Promise<T>;
2
- //# sourceMappingURL=importNodeModule.d.ts.map
2
+ //# sourceMappingURL=import-node-module.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare function importRuntimeJson<T = unknown>(fileName: string): Promise<T>;
2
+ //# sourceMappingURL=import-runtime-json.d.ts.map
@@ -1,10 +1,10 @@
1
1
  import debug from 'debug';
2
- import { importJsonModule } from './importJsonModule.js';
3
- const log = debug('efp:utils:importRuntimeJsonModule');
4
- export async function importRuntimeJsonModule(fileName) {
2
+ import { importJson } from './import-json.js';
3
+ const log = debug('efp:utils:importRuntimeJson');
4
+ export async function importRuntimeJson(fileName) {
5
5
  // ignore because vite may rewrite '.' to data:...
6
6
  const baseUrl = new URL(/* @vite-ignore */ '.', import.meta.url).href;
7
7
  const url = new URL(fileName, baseUrl);
8
8
  log('Loading runtime JSON from', url.href);
9
- return await importJsonModule(url.href);
9
+ return await importJson(url.href);
10
10
  }
@@ -1,3 +1,3 @@
1
1
  /** @deprecated we should never load/eval scripts */
2
2
  export declare function loadScript(scriptUrl: string, signal?: AbortSignal): Promise<void>;
3
- //# sourceMappingURL=loadScript.d.ts.map
3
+ //# sourceMappingURL=load-script.d.ts.map
@@ -1,6 +1,6 @@
1
1
  /// <reference lib="dom" />
2
2
  import debug from 'debug';
3
- import { niceFetch } from './niceFetch.js';
3
+ import { fetchWithRetry } from './fetch-with-retry.js';
4
4
  const log = debug('efp:utils:loadScript');
5
5
  function isBrowser() {
6
6
  return typeof window !== 'undefined' && typeof document !== 'undefined';
@@ -59,7 +59,7 @@ async function loadInNode(scriptUrl, signal) {
59
59
  }
60
60
  let res;
61
61
  try {
62
- res = await niceFetch(scriptUrl, { signal });
62
+ res = await fetchWithRetry(scriptUrl, { signal });
63
63
  }
64
64
  catch (err) {
65
65
  // Node / WHATWG fetch uses AbortError on abort
@@ -34,4 +34,4 @@
34
34
  * ```
35
35
  */
36
36
  export declare function makeLocalPath(url: URL, filenameSuffix?: string): Promise<string>;
37
- //# sourceMappingURL=makeLocalPath.d.ts.map
37
+ //# sourceMappingURL=make-local-path.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import debug from 'debug';
2
- import { sha256Base62Truncated } from './sha256Base62Truncated.js';
3
- import { slugifyFilesystemUnique } from './slugifyFilesystemUnique.js';
2
+ import { safeSlugify } from './safe-slugify.js';
3
+ import { shortHash } from './short-hash.js';
4
4
  const log = debug('efp:utils:makeLocalPath');
5
5
  /**
6
6
  * Makes a local file path from a URL, preserving extension and automatically adding hash for files.
@@ -52,17 +52,17 @@ export async function makeLocalPath(url, filenameSuffix) {
52
52
  throw new Error('filenameSuffix is not allowed for directory paths');
53
53
  }
54
54
  // Create hash if requested (using full URL)
55
- const hash = addHash ? await sha256Base62Truncated(url.href) : null;
55
+ const hash = addHash ? await shortHash(url.href) : null;
56
56
  // Slugify protocol and domain (e.g., "http-demo-expofp-com")
57
- const protocol = slugifyFilesystemUnique(url.protocol.replace(':', ''));
58
- const domain = slugifyFilesystemUnique(url.hostname);
57
+ const protocol = safeSlugify(url.protocol.replace(':', ''));
58
+ const domain = safeSlugify(url.hostname);
59
59
  const port = url.port ? `-${url.port}` : '';
60
60
  const protocolDomain = `${protocol}-${domain}${port}`;
61
61
  // Parse the path
62
62
  const pathParts = url.pathname.split('/').filter(Boolean);
63
63
  if (isDirectory) {
64
64
  // For directories, all parts are directory parts
65
- const slugifiedDirs = pathParts.map((part) => slugifyFilesystemUnique(part));
65
+ const slugifiedDirs = pathParts.map((part) => safeSlugify(part));
66
66
  // Build the full local path with trailing /
67
67
  const pathSegments = hash
68
68
  ? [protocolDomain, ...slugifiedDirs, hash]
@@ -73,13 +73,13 @@ export async function makeLocalPath(url, filenameSuffix) {
73
73
  const filename = pathParts.pop() || '';
74
74
  const directoryParts = pathParts;
75
75
  // Slugify directory parts
76
- const slugifiedDirs = directoryParts.map((part) => slugifyFilesystemUnique(part));
76
+ const slugifiedDirs = directoryParts.map((part) => safeSlugify(part));
77
77
  // Extract extension and base filename
78
78
  const lastDotIndex = filename.lastIndexOf('.');
79
79
  const extension = lastDotIndex !== -1 ? filename.slice(lastDotIndex) : '';
80
80
  const baseFilename = lastDotIndex !== -1 ? filename.slice(0, lastDotIndex) : filename;
81
81
  // Slugify the base filename
82
- let slugifiedFilename = slugifyFilesystemUnique(baseFilename);
82
+ let slugifiedFilename = safeSlugify(baseFilename);
83
83
  // Ensure filename is max 50 characters (not including extension)
84
84
  const maxFilenameLength = 50;
85
85
  if (slugifiedFilename.length > maxFilenameLength) {
@@ -8,4 +8,4 @@ export declare function readFileFromUrl(url: URL, options?: {
8
8
  signal?: AbortSignal;
9
9
  }): Promise<ReadFileFromUrlResult>;
10
10
  export {};
11
- //# sourceMappingURL=readFileFromUrl.d.ts.map
11
+ //# sourceMappingURL=read-file-from-url.d.ts.map
@@ -1,5 +1,5 @@
1
- import { importFsPromises } from './importFsPromises.js';
2
- import { niceFetch } from './niceFetch.js';
1
+ import { fetchWithRetry } from './fetch-with-retry.js';
2
+ import { importFsPromises } from './import-fs-promises.js';
3
3
  export async function readFileFromUrl(url, options) {
4
4
  if (url.protocol === 'file:') {
5
5
  const { readFile } = await importFsPromises();
@@ -7,7 +7,7 @@ export async function readFileFromUrl(url, options) {
7
7
  return { ok: true, data };
8
8
  }
9
9
  else {
10
- const response = await niceFetch(url, { signal: options?.signal });
10
+ const response = await fetchWithRetry(url, { signal: options?.signal });
11
11
  if (!response.ok) {
12
12
  return { ok: false };
13
13
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Generates a filesystem-safe slug from input string, ensuring uniqueness.
3
+ * @param input
4
+ * @returns
5
+ */
6
+ export declare function safeSlugify(input: string): string;
7
+ //# sourceMappingURL=safe-slugify.d.ts.map
@@ -53,7 +53,7 @@ function makeBaseSlug(input) {
53
53
  * @param input
54
54
  * @returns
55
55
  */
56
- export function slugifyFilesystemUnique(input) {
56
+ export function safeSlugify(input) {
57
57
  // If we've seen this exact input before, return the same slug
58
58
  const existing = inputToSlug.get(input);
59
59
  if (existing)
@@ -0,0 +1,2 @@
1
+ export declare function shortHash(input: string, bytes?: number): Promise<string>;
2
+ //# sourceMappingURL=short-hash.d.ts.map
@@ -1,4 +1,4 @@
1
- export async function sha256Base62Truncated(input, bytes = 16) {
1
+ export async function shortHash(input, bytes = 16) {
2
2
  const data = new TextEncoder().encode(input);
3
3
  const digest = await crypto.subtle.digest('SHA-256', data);
4
4
  const full = new Uint8Array(digest);
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@expofp/utils",
3
- "version": "3.0.0-alpha.9",
3
+ "version": "3.0.1",
4
4
  "type": "module",
5
5
  "description": "ExpoFP SDK internal: shared utilities",
6
6
  "license": "MIT",
7
+ "sideEffects": false,
7
8
  "publishConfig": {
8
9
  "access": "public"
9
10
  },
@@ -1,2 +0,0 @@
1
- export declare function importRuntimeJsonModule<T = unknown>(fileName: string): Promise<T>;
2
- //# sourceMappingURL=importRuntimeJsonModule.d.ts.map
@@ -1,2 +0,0 @@
1
- export declare function sha256Base62Truncated(input: string, bytes?: number): Promise<string>;
2
- //# sourceMappingURL=sha256Base62Truncated.d.ts.map
@@ -1,7 +0,0 @@
1
- /**
2
- * Generates a filesystem-safe slug from input string, ensuring uniqueness.
3
- * @param input
4
- * @returns
5
- */
6
- export declare function slugifyFilesystemUnique(input: string): string;
7
- //# sourceMappingURL=slugifyFilesystemUnique.d.ts.map
File without changes