@webority/web-core 0.171.3 → 0.172.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/README.md +1 -1
- package/dist/api/downloadFile.js +1 -1
- package/dist/api/resumableDownload.js +1 -1
- package/dist/query/useListQuery.js +1 -1
- package/dist/types/api/downloadFile.d.ts +12 -2
- package/dist/types/api/resumableDownload.d.ts +1 -1
- package/dist/types/query/useListQuery.d.ts +4 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -343,7 +343,7 @@ const file = await downloadFileResumable(userClient, {
|
|
|
343
343
|
signal: controller.signal,
|
|
344
344
|
onProgress: (loaded, total) => setProgress(loaded, total),
|
|
345
345
|
});
|
|
346
|
-
// file.blob and file.
|
|
346
|
+
// file.blob, file.fileName and file.headers, as downloadFile returns
|
|
347
347
|
```
|
|
348
348
|
|
|
349
349
|
- Pass the same `resume` on every attempt: calling again after a failure or a cancel continues from
|
package/dist/api/downloadFile.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extractApiError as e}from"../errors/extractApiError.js";import{readBlobErrorBody as t}from"./blobErrorBody.js";var
|
|
1
|
+
import{extractApiError as e}from"../errors/extractApiError.js";import{readBlobErrorBody as t}from"./blobErrorBody.js";import{AxiosHeaders as n}from"axios";var r=/filename="((?:[^"\\]|\\.)*)"/i,i=/filename=([^;]+)/i,a=/filename\*=([^']*)'[^']*'([^;]+)/i,o=/%(?![0-9A-Fa-f]{2})/,s=/(?:%[0-9A-Fa-f]{2})+/g,c=e=>{if(o.test(e))return null;let t=!1,n=e.replace(s,e=>{let n=Uint8Array.from(e.slice(1).split(`%`),e=>Number.parseInt(e,16)),r=new TextDecoder(`utf-8`,{fatal:!1,ignoreBOM:!0}).decode(n);return new TextEncoder().encode(r).join(`,`)!==n.join(`,`)&&(t=!0),r});return t?null:n},l=e=>{let t=new Headers;if(typeof e!=`object`||!e)return t;let r=e instanceof n?e.toJSON():e;for(let[e,n]of Object.entries(r))if(Array.isArray(n))for(let r of n)t.append(e,String(r));else(typeof n==`string`||typeof n==`number`||typeof n==`boolean`)&&t.set(e,String(n));return t},u=e=>{let t=a.exec(e)?.[2]?.trim(),n=t?c(t):null;return n===null?(r.exec(e)?.[1]?.replace(/\\(.)/g,`$1`)??i.exec(e)?.[1]?.trim())||null:n},d=async(n,r)=>{let i,a;try{let e=await n.request({...r,responseType:`blob`});i=e.data,a=l(e.headers)}catch(n){throw await t(n),e(n)}if(!(i instanceof Blob))throw Error(`downloadFile: "${r.url??``}" answered without a file body.`);let o=a.get(`content-disposition`);return{blob:i,fileName:o===null?null:u(o),headers:a}};export{u as contentDispositionFileName,d as downloadFile,l as toHeaders};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extractApiError as e}from"../errors/extractApiError.js";import{readBlobErrorBody as t}from"./blobErrorBody.js";import{contentDispositionFileName as n}from"./downloadFile.js";import{isAxiosError as
|
|
1
|
+
import{extractApiError as e}from"../errors/extractApiError.js";import{readBlobErrorBody as t}from"./blobErrorBody.js";import{contentDispositionFileName as n,toHeaders as r}from"./downloadFile.js";import{isAxiosError as i}from"axios";var a=4194304,o=`download_range_invalid`,s=`The download could not be continued. Please try again.`,c=()=>({chunks:[],received:0,total:null,validator:null,fileName:null,contentType:``}),l=e=>{e.chunks=[],e.received=0,e.total=null,e.validator=null,e.fileName=null,e.contentType=``},u=(e,t)=>{if(typeof e==`object`&&e)return`get`in e&&typeof e.get==`function`?e.get.call(e,t):Reflect.get(e,t)},d=e=>({code:o,message:s,fieldErrors:{},status:0,offline:!1,traceId:null,diagnostic:e,extensions:{}}),f=/^bytes (\d+)-(\d+)\/(\d+)$/i,p=e=>{if(typeof e!=`string`)return null;let t=f.exec(e);if(t===null)return null;let n=Number(t[1]),r=Number(t[2]),i=Number(t[3]);return[n,r,i].every(e=>Number.isSafeInteger(e))?{start:n,end:r,total:i}:null},m=e=>{let t=u(e,`etag`);if(typeof t==`string`&&t!==``&&!t.startsWith(`W/`))return t;let n=u(e,`last-modified`);return typeof n==`string`&&n!==``?n:null},h=e=>{let t=u(e,`content-disposition`);return typeof t==`string`?n(t):null},g=async(n,o)=>{let{resume:s,chunkBytes:c=a,onProgress:f,signal:g,..._}=o;if(!Number.isSafeInteger(c)||c<1)throw RangeError(`downloadFileResumable: chunkBytes must be a positive integer.`);let v=new Headers;for(;s.total===null||s.received<s.total;){let a=s.received,o=a>0&&s.validator!==null?{"If-Range":s.validator}:{},y={..._.headers,Range:`bytes=${a}-${a+c-1}`,...o},b;try{b=await n.request({..._,headers:y,responseType:`blob`,...g===void 0?{}:{signal:g},...f===void 0?{}:{onDownloadProgress:e=>f(a+e.loaded,s.total)}})}catch(n){await t(n);let o=e(n),c=i(n)?n.response?.headers:void 0,d=u(c,`content-range`);if(o.status===416&&a===0&&typeof d==`string`&&/^bytes \*\/0$/i.test(d))return f?.(0,0),l(s),{blob:new Blob([],{type:``}),fileName:h(c),headers:r(c)};throw o.status===416&&l(s),o}let x=b.data;if(!(x instanceof Blob))throw d(`"${_.url??``}" answered without a file body.`);if(b.status===206){let e=p(u(b.headers,`content-range`));if(e===null)throw d(`Content-Range missing or unreadable (a cross-origin server must expose it).`);if(e.start!==a)throw d(`asked for byte ${a}, got ${e.start}.`);if(x.size===0)throw d(`an empty range answer.`);if(x.size!==e.end-e.start+1)throw d(`the body length does not match Content-Range.`);a===0&&(s.validator=m(b.headers),s.contentType=x.type,s.fileName=h(b.headers)),s.total=e.total,s.chunks.push(x),s.received+=x.size}else l(s),s.chunks.push(x),s.received=x.size,s.total=x.size,s.contentType=x.type,s.validator=m(b.headers),s.fileName=h(b.headers);v=r(b.headers),f?.(s.received,s.total)}let y={blob:new Blob(s.chunks,{type:s.contentType}),fileName:s.fileName,headers:v};return l(s),y};export{a as DEFAULT_DOWNLOAD_CHUNK_BYTES,o as DOWNLOAD_RANGE_INVALID_CODE,s as DOWNLOAD_RANGE_INVALID_MESSAGE,c as createDownloadResume,g as downloadFileResumable};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extractApiError as e}from"../errors/extractApiError.js";import{isFacetActive as t,listQueryParamNames as n,listQueryParams as r,parseListQuery as i}from"./listQuery.js";import{useCallback as a,useEffect as o,useMemo as s,useRef as c,useState as l}from"react";import{useSearchParams as
|
|
1
|
+
import{extractApiError as e}from"../errors/extractApiError.js";import{isFacetActive as t,listQueryParamNames as n,listQueryParams as r,parseListQuery as i}from"./listQuery.js";import{useCallback as a,useEffect as o,useMemo as s,useRef as c,useState as l}from"react";import{useSearchParams as ee}from"react-router";var te=300,ne=20,u=`No results match these filters.`,d=[];function f(e,t,r){let a=n(t),o=[...e.keys()].some(e=>a.has(e)),s=i(e,{facets:t,defaults:r});return{page:s.page,...s.pageSize!==void 0&&{pageSize:s.pageSize},...s.sortBy!==void 0&&{sortBy:s.sortBy},sortOrder:s.sortOrder,search:o?s.search:r.search??``,filters:s.filters}}function p(e,t){return e?`${e}.${t}`:t}function m(e,t){if(!t)return e;let n=new URLSearchParams,r=`${t}.`;for(let[t,i]of e)t.startsWith(r)&&n.append(t.slice(r.length),i);return n}function h(e,t,r,i){let a=new URLSearchParams(e);for(let e of n(r))a.delete(p(i,e));for(let[e,n]of t)a.append(p(i,e),n);return a}function g(e){return r({page:e.page,...e.pageSize!==void 0&&{pageSize:e.pageSize},...e.sortBy!==void 0&&{sortBy:e.sortBy},sortOrder:e.sortOrder,search:e.search,filters:e.filters})}function _(e){return{page:e.page,...e.pageSize!==void 0&&{pageSize:e.pageSize},...e.sortBy!==void 0&&{sortBy:e.sortBy},sortOrder:e.sortOrder,search:e.search,filters:e.filters}}function v(n){let{fetchPage:r,facets:i=[],defaults:p={},debounceMs:v=te,onRefreshError:y,paramPrefix:b}=n;if(b!==void 0&&!/^[A-Za-z][A-Za-z0-9]*$/.test(b))throw Error(`useListQuery: paramPrefix "${b}" must be letters and digits, starting with a letter.`);let[x,S]=ee(),C=f(m(x,b),i,p),[w,T]=l(C.search),[E,D]=l(),O=c(E);O.current=E;let[k,A]=l(),[j,M]=l(!0),[N,P]=l(0),F={...C,search:w},I=c(F);I.current=F;let L=c(r);L.current=r;let R=c(y);R.current=y;let z=`${g(F)}#${N}`,B=c(z);B.current=z,o(()=>{if(C.search===w)return;let e=setTimeout(()=>T(C.search),v);return()=>clearTimeout(e)},[C.search,w,v]),o(()=>{let t=new AbortController,n=()=>t.signal.aborted||B.current!==z;return M(!0),new Promise(e=>{e(L.current(_(I.current),{signal:t.signal}))}).then(e=>{n()||(D(e),A(void 0),M(!1))},t=>{n()||(O.current!==void 0&&R.current?.(e(t)),A({reason:t}),M(!1))}),()=>t.abort()},[z]);let V=(e,t)=>{S(t=>h(t,g(e),i,b),{replace:!0}),t&&T(e.search)},H=e=>V({...C,page:e},!0),U=e=>V({...C,pageSize:e},!0),W=e=>V({...C,page:1,search:e},!1),G=(e,t)=>V({...C,page:1,filters:{...C.filters,[e]:t}},!0),K=e=>V({...C,page:1,filters:{...C.filters,...e}},!0),q=(e,t=`asc`)=>V({...C,page:1,sortBy:e,sortOrder:t},!0),J=e=>q(e,e===C.sortBy&&C.sortOrder===`asc`?`desc`:`asc`),Y=()=>{let e=f(new URLSearchParams,i,p);S(e=>h(e,new URLSearchParams,i,b),{replace:!0}),T(e.search)},X=a(()=>P(e=>e+1),[]),Z=C.search!==``||i.some(e=>t(e,C.filters[e.key])),Q=E?.totalCount??0,$=E?.totalPages??0,re=E?.totalCountCapped===!0,ie=s(()=>E===void 0?k===void 0||j?{status:`loading`,refetch:X}:{status:`error`,error:e(k.reason),retry:X,refetch:X}:E.items.length===0?{status:`empty`,refreshing:j,refresh:X,refetch:X}:{status:`data`,data:E,refreshing:j,refresh:X,refetch:X},[E,k,j,X]);return{query:C,rows:E?.items??d,state:ie,totalCount:Q,totalPages:$,totalCountCapped:re,setFilter:G,setFilters:K,setSearch:W,setSort:q,setPage:H,setPageSize:U,reset:Y,tableProps:{rows:E?.items??d,...C.sortBy?{sort:{key:C.sortBy,dir:C.sortOrder}}:{},onSort:J,loading:j,...Z?{emptyFiltered:u}:{},sourceCount:Z?Math.max(Q,1):Q},paginationProps:{page:C.page,totalPages:$,pageSize:C.pageSize??E?.pageSize??ne,onPageChange:H,onPageSizeChange:U}}}export{v as useListQuery};
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
import type
|
|
2
|
-
/** A downloaded file: its bytes
|
|
1
|
+
import { type AxiosInstance, type AxiosRequestConfig } from "axios";
|
|
2
|
+
/** A downloaded file: its bytes, the name the server gave it, if any, and the response headers. */
|
|
3
3
|
export interface DownloadedFile {
|
|
4
4
|
blob: Blob;
|
|
5
5
|
/** From `Content-Disposition`; null when the server sent none or CORS does not expose the header. */
|
|
6
6
|
fileName: string | null;
|
|
7
|
+
/**
|
|
8
|
+
* The headers of the response that delivered the file, read case-insensitively with `get`. A cross-origin
|
|
9
|
+
* page sees only the CORS-safelisted headers and those the server lists in `Access-Control-Expose-Headers`.
|
|
10
|
+
*/
|
|
11
|
+
headers: Headers;
|
|
7
12
|
}
|
|
8
13
|
/** The request of a download: any axios option except `responseType`, which is always `"blob"`. */
|
|
9
14
|
export type DownloadRequest = Omit<AxiosRequestConfig, "responseType">;
|
|
15
|
+
/** Axios response headers as a Fetch `Headers`; a list value (`set-cookie`) is appended item by item. */
|
|
16
|
+
export declare const toHeaders: (source: unknown) => Headers;
|
|
10
17
|
/** The file name of a `Content-Disposition` header; `filename*` (RFC 6266, UTF-8) wins over `filename`. */
|
|
11
18
|
export declare const contentDispositionFileName: (header: string) => string | null;
|
|
12
19
|
/**
|
|
@@ -14,6 +21,9 @@ export declare const contentDispositionFileName: (header: string) => string | nu
|
|
|
14
21
|
* retry, the offline check and logging apply. A failure rejects with the same curated `ApiError`
|
|
15
22
|
* every other call gives, read from the server's problem body even though it arrived as a Blob.
|
|
16
23
|
*
|
|
24
|
+
* The result carries the response `headers`, so a screen can read a value the server sends beside the file,
|
|
25
|
+
* such as a count to warn about, with `file.headers.get("<Name>")`.
|
|
26
|
+
*
|
|
17
27
|
* Progress and cancel are plain request options: pass `onDownloadProgress` to read the bytes received as the transfer runs (`event.loaded`, and `event.total` only when the server sends `Content-Length`; a compressed or chunked reply has none), and pass an `AbortSignal` as `signal` to cancel. A cancelled download rejects with the `ApiError` code `request_canceled` and no Blob is created.
|
|
18
28
|
*
|
|
19
29
|
* @example
|
|
@@ -31,6 +31,6 @@ export type ResumableDownloadRequest = Omit<AxiosRequestConfig, "method" | "data
|
|
|
31
31
|
* Fetches a file in `Range` requests through the same API client, so refresh, retry and the offline
|
|
32
32
|
* check apply to every chunk. Calling again with the same `resume` continues from the last byte held.
|
|
33
33
|
* A server that ignores Range, or whose file changed (`If-Range` no longer matches), answers 200 with
|
|
34
|
-
* the whole file, which replaces the held chunks.
|
|
34
|
+
* the whole file, which replaces the held chunks. `headers` are those of the answer that delivered the last byte.
|
|
35
35
|
*/
|
|
36
36
|
export declare const downloadFileResumable: (client: AxiosInstance, request: ResumableDownloadRequest) => Promise<DownloadedFile>;
|
|
@@ -23,6 +23,8 @@ export interface UseListQueryOptions<TRow, TQuery = Record<string, unknown>> {
|
|
|
23
23
|
debounceMs?: number;
|
|
24
24
|
/** Called when a refresh fails while rows are shown; the rows stay. */
|
|
25
25
|
onRefreshError?: (error: ApiError) => void;
|
|
26
|
+
/** Scopes this list's address keys as `<paramPrefix>.<key>`, so two lists on one page keep separate state. Letters and digits only, starting with a letter. */
|
|
27
|
+
paramPrefix?: string;
|
|
26
28
|
}
|
|
27
29
|
export interface UseListQueryResult<TRow> {
|
|
28
30
|
query: ListQueryState;
|
|
@@ -61,6 +63,7 @@ export interface UseListQueryResult<TRow> {
|
|
|
61
63
|
/**
|
|
62
64
|
* URL state through the react-router `useSearchParams`, written with replace
|
|
63
65
|
* rather than push. A filter, search or sort change returns to page 1, and a new
|
|
64
|
-
* request aborts the one in flight.
|
|
66
|
+
* request aborts the one in flight. A write or reset changes only the params this
|
|
67
|
+
* list owns; every other address param is kept.
|
|
65
68
|
*/
|
|
66
69
|
export declare function useListQuery<TRow, TQuery = Record<string, unknown>>(options: UseListQueryOptions<TRow, TQuery>): UseListQueryResult<TRow>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/web-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.172.0",
|
|
4
4
|
"description": "Platform layer for Webority React web portals: HTTP clients with single-flight token refresh, auth store, API error extraction, RTK Query base query, logger, formatters, storage, version check and route guards. No UI.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
},
|
|
111
111
|
"sideEffects": false,
|
|
112
112
|
"dependencies": {
|
|
113
|
-
"@webority/api-contract": "0.
|
|
113
|
+
"@webority/api-contract": "0.172.0"
|
|
114
114
|
},
|
|
115
115
|
"peerDependencies": {
|
|
116
116
|
"@microsoft/applicationinsights-web": "^3.4.5",
|
|
@@ -137,7 +137,7 @@
|
|
|
137
137
|
"@types/node": "25.6.0",
|
|
138
138
|
"@types/react": "^19.3.0",
|
|
139
139
|
"@vitest/coverage-v8": "5.1.0",
|
|
140
|
-
"@webority/biome-config": "0.
|
|
140
|
+
"@webority/biome-config": "0.172.0",
|
|
141
141
|
"axios": "^1.18.0",
|
|
142
142
|
"jsdom": "30.1.1",
|
|
143
143
|
"react": "^19.3.1",
|