@webority/web-core 0.165.0 → 0.167.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.
@@ -1 +1 @@
1
- import{extractApiError as e}from"../errors/extractApiError.js";import{Logger as t}from"../logger/logger.js";import n from"axios";var r=(e,t)=>{if(typeof t!=`number`||!Number.isInteger(t)||t<0)throw Error(`createApiBaseQuery: "${e}" sets extraOptions.maxRetries to ${String(t)}; it must be a whole number of 0 or more.`);return t},i=e=>e instanceof Date?encodeURIComponent(e.toISOString()):encodeURIComponent(typeof e==`object`?JSON.stringify(e):String(e)),a=e=>{if(!(typeof e!=`string`||e.startsWith(`W/`)))return/^"([^"]*)"$/.exec(e)?.[1]},o=e=>`"${e}"`,s=e=>{let t={};if(e.ifMatch&&(t[`If-Match`]=o(e.ifMatch)),e.idempotencyKey&&(t[`Idempotency-Key`]=e.idempotencyKey),Object.keys(t).length===0)return e.headers;let n=Object.keys(t).map(e=>e.toLowerCase()),r=Object.entries(e.headers??{}).filter(([e])=>!n.includes(e.toLowerCase()));return{...Object.fromEntries(r),...t}},c=`precondition_failed`,l=e=>e.status===412?{...e,code:c}:e,u=e=>t=>{let n=[];for(let[r,a]of Object.entries(t)){if(a==null)continue;let t=encodeURIComponent(r);if(!Array.isArray(a))n.push(`${t}=${i(a)}`);else if(e===`comma`)n.push(`${t}=${a.map(i).join(`,`)}`);else{let r=e===`brackets`?`${t}[]`:t;for(let e of a)n.push(`${r}=${i(e)}`)}}return n.join(`&`)},d=({client:i,publicClient:o})=>async(c,{signal:d},f)=>{let p=typeof c==`string`?{url:c}:c,m=p.silent??f?.silent??!1,h=p.expectedStatuses??f?.expectedStatuses,g=p.paramsFormat??f?.paramsFormat,_=f?.maxRetries===void 0?void 0:r(p.url,f.maxRetries),v=p.public?o:i;if(!v)throw Error(`createApiBaseQuery: "${p.url}" is marked public but no publicClient was passed.`);let y=s(p),b={url:p.url,method:p.method??`GET`,data:p.data,params:p.params,...g&&{paramsSerializer:u(g)},...y!==void 0&&{headers:y},...p.responseType!==void 0&&{responseType:p.responseType},...p.timeout!==void 0&&{timeout:p.timeout},..._!==void 0&&{retry:{retries:_}},signal:d,skipErrorLog:!0};try{let e=await v.request(b),t=a(e.headers?.etag);return{data:e.data,meta:{silent:m,status:e.status,...t!==void 0&&{entityTag:t}}}}catch(r){let i=l(e(r)),o=n.isCancel(r);o||t.requestFailed(r,{...h&&{expectedStatuses:h}});let s=n.isAxiosError(r)?a(r.response?.headers?.etag):void 0;return{error:i,meta:{silent:m||o,status:i.status,...h&&{expectedStatuses:h},...s!==void 0&&{entityTag:s}}}}};export{d as createApiBaseQuery,o as ifMatchValue,a as strongEntityTag};
1
+ import{extractApiError as e}from"../errors/extractApiError.js";import{Logger as t}from"../logger/logger.js";import n from"axios";var r=(e,t)=>{if(typeof t!=`number`||!Number.isInteger(t)||t<0)throw Error(`createApiBaseQuery: "${e}" sets extraOptions.maxRetries to ${String(t)}; it must be a whole number of 0 or more.`);return t},i=e=>e instanceof Date?encodeURIComponent(e.toISOString()):encodeURIComponent(typeof e==`object`?JSON.stringify(e):String(e)),a=e=>{if(!(typeof e!=`string`||e.startsWith(`W/`)))return/^"([^"]*)"$/.exec(e)?.[1]},o=e=>{if(typeof e!=`string`||e.trim()===``)throw Error(`web-core: the record version is missing, so the update cannot be sent with If-Match. Read the record first and pass its version.`);return`"${e}"`},s=e=>{let t={};if(e.ifMatch!==void 0&&(t[`If-Match`]=o(e.ifMatch)),e.idempotencyKey&&(t[`Idempotency-Key`]=e.idempotencyKey),Object.keys(t).length===0)return e.headers;let n=Object.keys(t).map(e=>e.toLowerCase()),r=Object.entries(e.headers??{}).filter(([e])=>!n.includes(e.toLowerCase()));return{...Object.fromEntries(r),...t}},c=`precondition_failed`,l=e=>e.status===412?{...e,code:c}:e,u=e=>t=>{let n=[];for(let[r,a]of Object.entries(t)){if(a==null)continue;let t=encodeURIComponent(r);if(!Array.isArray(a))n.push(`${t}=${i(a)}`);else if(e===`comma`)n.push(`${t}=${a.map(i).join(`,`)}`);else{let r=e===`brackets`?`${t}[]`:t;for(let e of a)n.push(`${r}=${i(e)}`)}}return n.join(`&`)},d=({client:i,publicClient:o})=>async(c,{signal:d},f)=>{let p=typeof c==`string`?{url:c}:c,m=p.silent??f?.silent??!1,h=p.expectedStatuses??f?.expectedStatuses,g=p.paramsFormat??f?.paramsFormat,_=f?.maxRetries===void 0?void 0:r(p.url,f.maxRetries),v=p.public?o:i;if(!v)throw Error(`createApiBaseQuery: "${p.url}" is marked public but no publicClient was passed.`);let y=s(p),b={url:p.url,method:p.method??`GET`,data:p.data,params:p.params,...g&&{paramsSerializer:u(g)},...y!==void 0&&{headers:y},...p.responseType!==void 0&&{responseType:p.responseType},...p.timeout!==void 0&&{timeout:p.timeout},..._!==void 0&&{retry:{retries:_}},signal:d,skipErrorLog:!0};try{let e=await v.request(b),t=a(e.headers?.etag);return{data:e.data,meta:{silent:m,status:e.status,...t!==void 0&&{entityTag:t}}}}catch(r){let i=l(e(r)),o=n.isCancel(r);o||t.requestFailed(r,{...h&&{expectedStatuses:h}});let s=n.isAxiosError(r)?a(r.response?.headers?.etag):void 0;return{error:i,meta:{silent:m||o,status:i.status,...h&&{expectedStatuses:h},...s!==void 0&&{entityTag:s}}}}};export{d as createApiBaseQuery,o as ifMatchValue,a as strongEntityTag};
@@ -47,8 +47,11 @@ export interface ApiExtraOptions {
47
47
  maxRetries?: number;
48
48
  }
49
49
  export declare const strongEntityTag: (value: unknown) => string | undefined;
50
- /** The `If-Match` header value for a version: the version in quotes, as an ETag is sent. */
51
- export declare const ifMatchValue: (version: string) => string;
50
+ /**
51
+ * The `If-Match` header value for a version: the version in quotes, as an ETag is sent. A missing or blank
52
+ * version throws here, before any request is sent, so a write never goes out with no version to guard it.
53
+ */
54
+ export declare const ifMatchValue: (version: string | null | undefined) => string;
52
55
  /**
53
56
  * Returned as the base query's `meta`, which RTK Query copies onto the
54
57
  * fulfilled and rejected actions as `action.meta.baseQueryMeta`. The toast
@@ -64,11 +67,13 @@ export interface ApiBaseQueryMeta {
64
67
  /** The strong ETag of the response, without quotes; undefined when none was sent. */
65
68
  entityTag?: string;
66
69
  }
70
+ /** The base query only sends requests, so any client with axios's `request` fits, as `contractCaller` takes. */
71
+ export type ApiRequestClient = Pick<AxiosInstance, "request">;
67
72
  export interface ApiBaseQueryOptions {
68
73
  /** The signed-in client every call uses by default (`userClient`). */
69
- client: AxiosInstance;
74
+ client: ApiRequestClient;
70
75
  /** The anonymous client for calls marked `public: true` (`publicClient`). */
71
- publicClient?: AxiosInstance;
76
+ publicClient?: ApiRequestClient;
72
77
  }
73
78
  export type ApiBaseQuery = BaseQueryFn<ApiQueryArgs, unknown, ApiError, ApiExtraOptions, ApiBaseQueryMeta>;
74
79
  /**
@@ -64,9 +64,10 @@ export interface PagedListPaging {
64
64
  loadMore: () => void;
65
65
  retryMore: () => void;
66
66
  }
67
- export interface InfiniteQueryResultLike<T> {
67
+ export type PageItem<P extends PagedDataObject<unknown>> = P["items"][number];
68
+ export interface InfiniteQueryResultLike<P extends PagedDataObject<unknown>> {
68
69
  readonly currentData?: {
69
- readonly pages: readonly PagedDataObject<T>[];
70
+ readonly pages: readonly P[];
70
71
  } | undefined;
71
72
  readonly error?: unknown;
72
73
  readonly isFetching: boolean;
@@ -85,7 +86,7 @@ export interface InfiniteQueryResultLike<T> {
85
86
  readonly fetchNextPage: () => unknown;
86
87
  }
87
88
  /** state: every loaded page's items in order, "empty" when there are none. paging: what the paged list footer reads. */
88
- export declare function useInfiniteDataState<T>(result: InfiniteQueryResultLike<T>): {
89
- readonly state: DataState<readonly T[]>;
89
+ export declare function useInfiniteDataState<P extends PagedDataObject<unknown>>(result: InfiniteQueryResultLike<P>): {
90
+ readonly state: DataState<readonly PageItem<P>[]>;
90
91
  readonly paging: PagedListPaging;
91
92
  };
@@ -3,7 +3,7 @@ export { createApiBaseQuery } from "./apiBaseQuery";
3
3
  export type { ContractQuery, ContractQueryOptions, ContractResponse } from "./contractQuery";
4
4
  export { createContractQuery } from "./contractQuery";
5
5
  export { APP_API_DEFAULTS, createAppApi } from "./createAppApi";
6
- export type { DataState, DataStateOptions, InfiniteQueryResultLike, PagedListPaging, QueryResultLike } from "./dataState";
6
+ export type { DataState, DataStateOptions, InfiniteQueryResultLike, PagedListPaging, PageItem, QueryResultLike } from "./dataState";
7
7
  export { useDataState, useInfiniteDataState } from "./dataState";
8
8
  export type { SaveWithVersionOptions, SaveWithVersionResult, VersionedRead } from "./entityVersion";
9
9
  export { entityTagOf, saveWithVersion, versionOf, withIfMatch } from "./entityVersion";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/web-core",
3
- "version": "0.165.0",
3
+ "version": "0.167.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",
@@ -102,7 +102,7 @@
102
102
  },
103
103
  "sideEffects": false,
104
104
  "dependencies": {
105
- "@webority/api-contract": "0.165.0"
105
+ "@webority/api-contract": "0.167.0"
106
106
  },
107
107
  "peerDependencies": {
108
108
  "@microsoft/applicationinsights-web": "^3.4.5",
@@ -124,7 +124,7 @@
124
124
  "@types/node": "25.6.0",
125
125
  "@types/react": "^19.3.0",
126
126
  "@vitest/coverage-v8": "5.1.0",
127
- "@webority/biome-config": "0.165.0",
127
+ "@webority/biome-config": "0.167.0",
128
128
  "axios": "^1.18.0",
129
129
  "jsdom": "30.1.1",
130
130
  "react": "^19.3.1",