@webority/web-core 0.149.0 → 0.152.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 +114 -6
- package/dist/api/baseUrl.js +1 -1
- package/dist/api/blobErrorBody.js +1 -0
- package/dist/api/contractCaller.js +1 -0
- package/dist/api/crossTabRefreshLock.js +1 -1
- package/dist/api/designSample.js +1 -1
- package/dist/api/downloadFile.js +1 -0
- package/dist/api/idempotencyKey.js +1 -0
- package/dist/api/index.js +1 -1
- package/dist/api/minAppVersion.js +1 -1
- package/dist/api/requestDefaults.js +1 -1
- package/dist/api/retry.js +1 -1
- package/dist/api/tokenRefresh.js +1 -1
- package/dist/api/userClient.js +1 -1
- package/dist/api/workspaceChanged.js +1 -1
- package/dist/api-contract/dist/call.js +1 -0
- package/dist/appInsights/appInsights.js +1 -0
- package/dist/appInsights/index.js +1 -0
- package/dist/auth/authStore.js +1 -1
- package/dist/auth/jwt.js +1 -1
- package/dist/errors/extractApiError.js +2 -2
- package/dist/errors/index.js +1 -1
- package/dist/errors/parseResponse.js +1 -0
- package/dist/errors/requestPlatform.js +1 -0
- package/dist/formatters/currency.js +1 -1
- package/dist/formatters/formatConfig.js +1 -1
- package/dist/formatters/house.js +1 -1
- package/dist/index.js +1 -1
- package/dist/india/gstStates.js +1 -0
- package/dist/india/index.js +1 -1
- package/dist/logger/logger.js +2 -2
- package/dist/logger/redact.js +1 -1
- package/dist/network/networkStatus.js +1 -1
- package/dist/query/apiBaseQuery.js +1 -1
- package/dist/query/createAppApi.js +1 -1
- package/dist/query/dataState.js +1 -0
- package/dist/query/entityVersion.js +1 -0
- package/dist/query/index.js +1 -1
- package/dist/query/listQuery.js +1 -1
- package/dist/query/paging.js +1 -1
- package/dist/query/tags.js +1 -1
- package/dist/query/useListQuery.js +1 -1
- package/dist/redux/errorToastMiddleware.js +1 -1
- package/dist/redux/rootReducer.js +1 -1
- package/dist/router/chunkReload.js +1 -1
- package/dist/router/index.js +1 -1
- package/dist/router/returnTo.js +1 -1
- package/dist/router/routeTable.js +1 -0
- package/dist/storage/index.js +1 -1
- package/dist/types/api/blobErrorBody.d.ts +9 -0
- package/dist/types/api/contractCaller.d.ts +11 -0
- package/dist/types/api/downloadFile.d.ts +19 -0
- package/dist/types/api/idempotencyKey.d.ts +1 -0
- package/dist/types/api/index.d.ts +7 -0
- package/dist/types/api/tokenRefresh.d.ts +2 -1
- package/dist/types/appInsights/appInsights.d.ts +33 -0
- package/dist/types/appInsights/index.d.ts +3 -0
- package/dist/types/auth/authStore.d.ts +2 -1
- package/dist/types/auth/jwt.d.ts +11 -8
- package/dist/types/errors/extractApiError.d.ts +6 -15
- package/dist/types/errors/index.d.ts +2 -0
- package/dist/types/errors/parseResponse.d.ts +19 -0
- package/dist/types/errors/requestPlatform.d.ts +5 -0
- package/dist/types/formatters/formatConfig.d.ts +8 -6
- package/dist/types/formatters/house.d.ts +19 -20
- package/dist/types/formatters/intlCache.d.ts +1 -3
- package/dist/types/india/gstStates.d.ts +7 -0
- package/dist/types/india/gstStates.g.d.ts +1 -1
- package/dist/types/india/index.d.ts +1 -0
- package/dist/types/initUserAuth.d.ts +2 -1
- package/dist/types/logger/redact.d.ts +3 -1
- package/dist/types/query/apiBaseQuery.d.ts +10 -1
- package/dist/types/query/dataState.d.ts +81 -0
- package/dist/types/query/entityVersion.d.ts +46 -0
- package/dist/types/query/index.d.ts +4 -0
- package/dist/types/query/listQuery.d.ts +3 -3
- package/dist/types/query/paging.d.ts +3 -1
- package/dist/types/query/useListQuery.d.ts +10 -6
- package/dist/types/redux/index.d.ts +1 -1
- package/dist/types/redux/rootReducer.d.ts +7 -2
- package/dist/types/router/chunkReload.d.ts +5 -2
- package/dist/types/router/index.d.ts +2 -0
- package/dist/types/router/routeTable.d.ts +66 -0
- package/dist/types/storage/index.d.ts +10 -8
- package/dist/versionCheck/deployedBuild.js +1 -1
- package/dist/vite/index.js +1 -1
- package/package.json +21 -5
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type GstState } from "./gstStates.g";
|
|
2
|
+
/** The current state a valid GSTIN belongs to: a retired code resolves to its replacement, or null when the GSTIN is not valid. */
|
|
3
|
+
export declare const currentStateForGstin: (value: unknown) => GstState | null;
|
|
4
|
+
/** The state a stored place of supply names, in the printed form "Karnataka (29)" or a bare name, or null. */
|
|
5
|
+
export declare const gstStateFromPlaceOfSupply: (value: unknown) => GstState | null;
|
|
6
|
+
/** How the place of supply prints on a tax document, such as "Karnataka (29)". */
|
|
7
|
+
export declare const placeOfSupplyLabel: (state: GstState) => string;
|
|
@@ -3,6 +3,7 @@ export type { FinancialYear } from "./financialYear";
|
|
|
3
3
|
export { currentFinancialYear, financialYearLabel, financialYearOf, parseFinancialYear, recentFinancialYears } from "./financialYear";
|
|
4
4
|
export type { GstinProblem } from "./gstin";
|
|
5
5
|
export { gstinHolderPan, gstinProblem, gstinState, gstinStateCode, isGstin, normalizeGstin, sanitizeGstinInput } from "./gstin";
|
|
6
|
+
export { currentStateForGstin, gstStateFromPlaceOfSupply, placeOfSupplyLabel } from "./gstStates";
|
|
6
7
|
export type { GstState, GstStateStatus } from "./gstStates.g";
|
|
7
8
|
export { isIfsc, normalizeIfsc } from "./ifsc";
|
|
8
9
|
export { formatIndianMobile, isIndianMobile, normalizeIndianMobile } from "./indianMobile";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AccountIdProvider } from "./api/clientHeaders";
|
|
2
|
+
import type { RefreshableStore } from "./api/tokenRefresh";
|
|
2
3
|
import { type LegacyTokenKeys } from "./auth/authStore";
|
|
3
4
|
/** The tokens a refresh response carries, with their expiry timestamps. */
|
|
4
5
|
export interface TokenRefreshResult {
|
|
@@ -65,4 +66,4 @@ export interface UserAuthOptions {
|
|
|
65
66
|
* @example
|
|
66
67
|
* initUserAuth(store, { logout, refresh: { path: '/Account/RefreshToken' } });
|
|
67
68
|
*/
|
|
68
|
-
export declare const initUserAuth:
|
|
69
|
+
export declare const initUserAuth: (store: RefreshableStore, options: UserAuthOptions) => void;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const redactString: (input: string) => string;
|
|
2
2
|
/** Returns a copy with secrets masked. An Error comes back as its summary, never as the Error itself. */
|
|
3
|
-
export declare const redact:
|
|
3
|
+
export declare const redact: (value: unknown) => unknown;
|
|
4
|
+
/** `redact` for a plain object: a record always comes back as one, so anything else is a defect and throws. */
|
|
5
|
+
export declare const redactRecord: (value: Readonly<Record<string, unknown>>) => Record<string, unknown>;
|
|
4
6
|
/** An Error safe to hand to a sink: the original name and stack, a redacted message, and no request data. */
|
|
5
7
|
export declare const redactError: (input: unknown) => Error;
|
|
@@ -22,13 +22,17 @@ export interface ApiRequest {
|
|
|
22
22
|
/** Query string values; build list queries with `buildListQuery`. */
|
|
23
23
|
params?: Record<string, unknown>;
|
|
24
24
|
headers?: Record<string, string>;
|
|
25
|
-
/** Only JSON-safe types belong in the store; a
|
|
25
|
+
/** Only JSON-safe types belong in the store; a file download is a service call through `downloadFile`. */
|
|
26
26
|
responseType?: Extract<ResponseType, "json" | "text">;
|
|
27
27
|
timeout?: number;
|
|
28
28
|
silent?: boolean;
|
|
29
29
|
expectedStatuses?: number[];
|
|
30
30
|
paramsFormat?: ParamsFormat;
|
|
31
31
|
public?: boolean;
|
|
32
|
+
/** Sent as `If-Match: "<value>"`; the version read from `meta.entityTag`. */
|
|
33
|
+
ifMatch?: string;
|
|
34
|
+
/** Sent as `Idempotency-Key`; from `AppForm`'s submit context. */
|
|
35
|
+
idempotencyKey?: string;
|
|
32
36
|
}
|
|
33
37
|
export type ApiQueryArgs = string | ApiRequest;
|
|
34
38
|
/** Per-endpoint options, set as the endpoint's `extraOptions`. */
|
|
@@ -37,6 +41,9 @@ export interface ApiExtraOptions {
|
|
|
37
41
|
expectedStatuses?: number[];
|
|
38
42
|
paramsFormat?: ParamsFormat;
|
|
39
43
|
}
|
|
44
|
+
export declare const strongEntityTag: (value: unknown) => string | undefined;
|
|
45
|
+
/** The `If-Match` header value for a version: the version in quotes, as an ETag is sent. */
|
|
46
|
+
export declare const ifMatchValue: (version: string) => string;
|
|
40
47
|
/**
|
|
41
48
|
* Returned as the base query's `meta`, which RTK Query copies onto the
|
|
42
49
|
* fulfilled and rejected actions as `action.meta.baseQueryMeta`. The toast
|
|
@@ -49,6 +56,8 @@ export interface ApiBaseQueryMeta {
|
|
|
49
56
|
expectedStatuses?: number[];
|
|
50
57
|
/** The HTTP status, or 0 when no response arrived. */
|
|
51
58
|
status: number;
|
|
59
|
+
/** The strong ETag of the response, without quotes; undefined when none was sent. */
|
|
60
|
+
entityTag?: string;
|
|
52
61
|
}
|
|
53
62
|
export interface ApiBaseQueryOptions {
|
|
54
63
|
/** The signed-in client every call uses by default (`userClient`). */
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type ApiError } from "../errors";
|
|
2
|
+
import type { PagedDataObject } from "./paging";
|
|
3
|
+
/** What a screen can be showing for one request. A closed set: the block draws every member. */
|
|
4
|
+
export type DataState<T> = {
|
|
5
|
+
readonly status: "idle";
|
|
6
|
+
} | {
|
|
7
|
+
readonly status: "loading";
|
|
8
|
+
} | {
|
|
9
|
+
readonly status: "error";
|
|
10
|
+
readonly error: ApiError;
|
|
11
|
+
readonly retry: () => void;
|
|
12
|
+
} | {
|
|
13
|
+
readonly status: "empty";
|
|
14
|
+
readonly refreshing: boolean;
|
|
15
|
+
readonly refresh: () => void;
|
|
16
|
+
readonly fulfilledTimeStamp?: number | undefined;
|
|
17
|
+
} | {
|
|
18
|
+
readonly status: "data";
|
|
19
|
+
readonly data: T;
|
|
20
|
+
readonly refreshing: boolean;
|
|
21
|
+
readonly refresh: () => void;
|
|
22
|
+
readonly fulfilledTimeStamp?: number | undefined;
|
|
23
|
+
};
|
|
24
|
+
/** The members of an RTK Query hook result that useDataState reads. */
|
|
25
|
+
export interface QueryResultLike<T> {
|
|
26
|
+
readonly currentData?: T | undefined;
|
|
27
|
+
/** The last result for any arguments; read only with keepPreviousData. */
|
|
28
|
+
readonly data?: T | undefined;
|
|
29
|
+
readonly error?: unknown;
|
|
30
|
+
readonly isFetching: boolean;
|
|
31
|
+
/** True while the query has never started, which for an RTK Query hook means it is skipped. */
|
|
32
|
+
readonly isUninitialized?: boolean | undefined;
|
|
33
|
+
readonly fulfilledTimeStamp?: number | undefined;
|
|
34
|
+
readonly refetch: () => unknown;
|
|
35
|
+
}
|
|
36
|
+
export interface DataStateOptions<T> {
|
|
37
|
+
/** Default: an array of length 0, or a PagedDataObject whose items has length 0. Anything else is never empty. */
|
|
38
|
+
readonly isEmpty?: (data: T) => boolean;
|
|
39
|
+
/** Default false. True keeps the last result on screen, refreshing, while a query with new arguments loads. */
|
|
40
|
+
readonly keepPreviousData?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Rules, in order:
|
|
44
|
+
* 1. currentData is not undefined: "empty" when isEmpty says so, else "data"; refreshing is isFetching; refresh is refetch;
|
|
45
|
+
* fulfilledTimeStamp is passed through.
|
|
46
|
+
* A failed refetch that still holds currentData stays here (the toast middleware reports it).
|
|
47
|
+
* 2. error is set: "error", with error passed through extractApiError and retry calling refetch.
|
|
48
|
+
* It wins over a kept previous result, so a failed new query never shows the old arguments' rows as its answer.
|
|
49
|
+
* 3. isUninitialized is true: "idle", the query is skipped and the block draws nothing.
|
|
50
|
+
* 4. keepPreviousData is on and data is not undefined: rule 1 applied to data, with refreshing true while isFetching.
|
|
51
|
+
* 5. otherwise "loading" (first load, an argument that changed).
|
|
52
|
+
* The returned object is memoized on its inputs.
|
|
53
|
+
*/
|
|
54
|
+
export declare function useDataState<T>(result: QueryResultLike<T>, options?: DataStateOptions<T>): DataState<T>;
|
|
55
|
+
export interface PagedListPaging {
|
|
56
|
+
hasMore: boolean;
|
|
57
|
+
loadingMore: boolean;
|
|
58
|
+
errorMore: ApiError | null;
|
|
59
|
+
loadMore: () => void;
|
|
60
|
+
retryMore: () => void;
|
|
61
|
+
}
|
|
62
|
+
export interface InfiniteQueryResultLike<T> {
|
|
63
|
+
readonly currentData?: {
|
|
64
|
+
readonly pages: readonly PagedDataObject<T>[];
|
|
65
|
+
} | undefined;
|
|
66
|
+
readonly error?: unknown;
|
|
67
|
+
readonly isFetching: boolean;
|
|
68
|
+
readonly isFetchingNextPage: boolean;
|
|
69
|
+
readonly hasNextPage: boolean;
|
|
70
|
+
readonly isError: boolean;
|
|
71
|
+
/** True while the query has never started, which for an RTK Query hook means it is skipped. */
|
|
72
|
+
readonly isUninitialized?: boolean | undefined;
|
|
73
|
+
readonly fulfilledTimeStamp?: number | undefined;
|
|
74
|
+
readonly refetch: () => unknown;
|
|
75
|
+
readonly fetchNextPage: () => unknown;
|
|
76
|
+
}
|
|
77
|
+
/** state: every loaded page's items in order, "empty" when there are none. paging: what the paged list footer reads. */
|
|
78
|
+
export declare function useInfiniteDataState<T>(result: InfiniteQueryResultLike<T>): {
|
|
79
|
+
readonly state: DataState<readonly T[]>;
|
|
80
|
+
readonly paging: PagedListPaging;
|
|
81
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from "axios";
|
|
2
|
+
import { type ApiError } from "../errors";
|
|
3
|
+
/**
|
|
4
|
+
* The version a write sends back as `If-Match`: the record's own `version` string (a list item, or the
|
|
5
|
+
* body of a single record), else the strong ETag of the read that loaded it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const versionOf: (record: unknown, entityTag?: string | undefined) => string | undefined;
|
|
8
|
+
/** A copy of `cfg` that sends `version` as `If-Match`, replacing an `If-Match` under any casing; `cfg` itself is not changed. */
|
|
9
|
+
export declare const withIfMatch: (version: string, cfg?: AxiosRequestConfig) => AxiosRequestConfig;
|
|
10
|
+
/** The strong ETag of a response's `etag` header, without quotes; undefined when there is none or it is weak. */
|
|
11
|
+
export declare const entityTagOf: (response: {
|
|
12
|
+
headers: unknown;
|
|
13
|
+
}) => string | undefined;
|
|
14
|
+
/** A record as the server holds it now, with the ETag of the read that returned it when the caller has one. */
|
|
15
|
+
export interface VersionedRead<R> {
|
|
16
|
+
record: R;
|
|
17
|
+
entityTag?: string | undefined;
|
|
18
|
+
}
|
|
19
|
+
export interface SaveWithVersionOptions<R, F> {
|
|
20
|
+
/** The record the form opened with. */
|
|
21
|
+
record: R;
|
|
22
|
+
/** Its ETag, when the screen read it from the response meta. */
|
|
23
|
+
entityTag?: string | undefined;
|
|
24
|
+
/** The values the form holds now. */
|
|
25
|
+
form: F;
|
|
26
|
+
/** The fields the form shows and sends, read from a record. */
|
|
27
|
+
toForm: (record: R) => F;
|
|
28
|
+
/** Reads the record as the server holds it now. */
|
|
29
|
+
read: () => Promise<VersionedRead<R>>;
|
|
30
|
+
/** Sends `form` with `version` as If-Match. Rejects with the ApiError of a failed reply. */
|
|
31
|
+
save: (form: F, version: string) => Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export type SaveWithVersionResult<R> = {
|
|
34
|
+
saved: true;
|
|
35
|
+
} | {
|
|
36
|
+
saved: false;
|
|
37
|
+
error: ApiError;
|
|
38
|
+
fresh: R;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Saves a record guarded by its version. A 412 re-reads the record once. When the fields the form covers
|
|
42
|
+
* are unchanged on the server, it saves the form again with the fresh version and reports success. Otherwise
|
|
43
|
+
* it returns the stale error and the fresh record: the caller shows the message and resets the form to
|
|
44
|
+
* `toForm(fresh)`. A second 412 is returned, never retried. Any other failure is rethrown.
|
|
45
|
+
*/
|
|
46
|
+
export declare const saveWithVersion: <R, F>({ record, entityTag, form, toForm, read, save, }: SaveWithVersionOptions<R, F>) => Promise<SaveWithVersionResult<R>>;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export type { ApiBaseQuery, ApiBaseQueryMeta, ApiBaseQueryOptions, ApiExtraOptions, ApiQueryArgs, ApiRequest, } from "./apiBaseQuery";
|
|
2
2
|
export { createApiBaseQuery } from "./apiBaseQuery";
|
|
3
3
|
export { APP_API_DEFAULTS, createAppApi } from "./createAppApi";
|
|
4
|
+
export type { DataState, DataStateOptions, InfiniteQueryResultLike, PagedListPaging, QueryResultLike } from "./dataState";
|
|
5
|
+
export { useDataState, useInfiniteDataState } from "./dataState";
|
|
6
|
+
export type { SaveWithVersionOptions, SaveWithVersionResult, VersionedRead } from "./entityVersion";
|
|
7
|
+
export { entityTagOf, saveWithVersion, versionOf, withIfMatch } from "./entityVersion";
|
|
4
8
|
export { setupApiListeners } from "./listeners";
|
|
5
9
|
export type { Facet, FacetKey, FacetType, ListQueryInput, ParsedListQuery, ParseListQueryOptions } from "./listQuery";
|
|
6
10
|
export { buildListQuery, emptyFacetValue, isFacetActive, LIST_QUERY_RESERVED, listQueryParamNames, parseListQuery, SEARCH_PARAM, } from "./listQuery";
|
|
@@ -7,7 +7,7 @@ export interface Facet {
|
|
|
7
7
|
options?: {
|
|
8
8
|
value: string;
|
|
9
9
|
label: string;
|
|
10
|
-
}[];
|
|
10
|
+
}[] | undefined;
|
|
11
11
|
}
|
|
12
12
|
/** The part of a facet the URL needs; a full Facet is assignable. */
|
|
13
13
|
export type FacetKey = Pick<Facet, "key" | "type">;
|
|
@@ -25,7 +25,7 @@ export interface ParsedListQuery {
|
|
|
25
25
|
sortBy: string | undefined;
|
|
26
26
|
sortOrder: SortOrder;
|
|
27
27
|
search: string;
|
|
28
|
-
filters: Record<string,
|
|
28
|
+
filters: Record<string, ListFilterValue>;
|
|
29
29
|
}
|
|
30
30
|
export interface ParseListQueryOptions {
|
|
31
31
|
facets?: readonly FacetKey[];
|
|
@@ -34,7 +34,7 @@ export interface ParseListQueryOptions {
|
|
|
34
34
|
pageSize?: number;
|
|
35
35
|
sortBy?: string;
|
|
36
36
|
sortOrder?: SortOrder;
|
|
37
|
-
filters?: Record<string,
|
|
37
|
+
filters?: Record<string, ListFilterValue>;
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
/** The list-query params the table itself owns; every other param is a filter. */
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* `PagedListRequest` (`page` 1-based, `pageSize`, `sortBy`, `sortOrder`, `search`)
|
|
4
4
|
* plus the endpoint's filters, and the response is `PagedDataObject<T>`. The
|
|
5
5
|
* server defaults a missing page to 1 and a missing size to 20, and cuts a size
|
|
6
|
-
* over 100 to 100.
|
|
6
|
+
* over 100 to 100. A capped answer carries the cap as `totalCount`.
|
|
7
7
|
*/
|
|
8
8
|
export interface PagedDataObject<T> {
|
|
9
9
|
items: T[];
|
|
@@ -11,6 +11,8 @@ export interface PagedDataObject<T> {
|
|
|
11
11
|
pageSize: number;
|
|
12
12
|
totalCount: number;
|
|
13
13
|
totalPages: number;
|
|
14
|
+
/** True when `totalCount` is the server's cap, so the real total is at least that. */
|
|
15
|
+
totalCountCapped: boolean;
|
|
14
16
|
}
|
|
15
17
|
export type SortOrder = "asc" | "desc";
|
|
16
18
|
export interface PagedListRequest {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { type ApiError } from "../errors";
|
|
2
|
+
import type { DataState } from "./dataState";
|
|
1
3
|
import { type Facet } from "./listQuery";
|
|
2
|
-
import type { PagedDataObject, SortOrder } from "./paging";
|
|
4
|
+
import type { ListFilterValue, PagedDataObject, SortOrder } from "./paging";
|
|
3
5
|
export interface ListQueryState {
|
|
4
6
|
page: number;
|
|
5
7
|
pageSize?: number;
|
|
6
8
|
sortBy?: string;
|
|
7
9
|
sortOrder: SortOrder;
|
|
8
10
|
search: string;
|
|
9
|
-
filters: Record<string,
|
|
11
|
+
filters: Record<string, ListFilterValue>;
|
|
10
12
|
}
|
|
11
13
|
export interface UseListQueryOptions<TRow> {
|
|
12
14
|
fetchPage: (query: ListQueryState, options: {
|
|
@@ -16,21 +18,23 @@ export interface UseListQueryOptions<TRow> {
|
|
|
16
18
|
defaults?: Partial<ListQueryState>;
|
|
17
19
|
/** Milliseconds a typed search or text filter waits before the list refetches. */
|
|
18
20
|
debounceMs?: number;
|
|
21
|
+
/** Called when a refresh fails while rows are shown; the rows stay. */
|
|
22
|
+
onRefreshError?: (error: ApiError) => void;
|
|
19
23
|
}
|
|
20
24
|
export interface UseListQueryResult<TRow> {
|
|
21
25
|
query: ListQueryState;
|
|
22
26
|
rows: TRow[];
|
|
23
|
-
|
|
24
|
-
error: unknown;
|
|
27
|
+
state: DataState<PagedDataObject<TRow>>;
|
|
25
28
|
totalCount: number;
|
|
26
29
|
totalPages: number;
|
|
27
|
-
|
|
30
|
+
/** True when totalCount is the server's cap: show it with a trailing plus. */
|
|
31
|
+
totalCountCapped: boolean;
|
|
32
|
+
setFilter(key: string, value: ListFilterValue): void;
|
|
28
33
|
setSearch(text: string): void;
|
|
29
34
|
setSort(sortBy: string, sortOrder?: SortOrder): void;
|
|
30
35
|
setPage(page: number): void;
|
|
31
36
|
setPageSize(pageSize: number): void;
|
|
32
37
|
reset(): void;
|
|
33
|
-
refetch(): void;
|
|
34
38
|
tableProps: {
|
|
35
39
|
rows: TRow[];
|
|
36
40
|
sort?: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { ErrorToastOptions, OnRejected, RejectionDecision, ShowErrorToast } from "./errorToastMiddleware";
|
|
2
2
|
export { errorToastMiddleware, isSilentRejection } from "./errorToastMiddleware";
|
|
3
|
-
export type { RootReducerOptions } from "./rootReducer";
|
|
3
|
+
export type { ResetStateOptions, RootReducerOptions } from "./rootReducer";
|
|
4
4
|
export { createRootReducer, resetState } from "./rootReducer";
|
|
5
5
|
export { SERIALIZABLE_IGNORED_ACTION_PATHS } from "./serializableCheck";
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { type ActionFromReducersMapObject, type Reducer, type ReducersMapObject, type StateFromReducersMapObject } from "@reduxjs/toolkit";
|
|
2
|
+
export interface ResetStateOptions {
|
|
3
|
+
/** Slices this reset keeps on top of the reducer's preserve list (a workspace switch keeps the session and the API cache). */
|
|
4
|
+
keep?: readonly string[] | undefined;
|
|
5
|
+
}
|
|
2
6
|
/**
|
|
3
7
|
* Clears every slice, the RTK Query cache included, in one dispatch. Dispatch it on logout
|
|
4
8
|
* (decision 22). Not a tidy-up: a slice left behind paints the previous user's data on the
|
|
5
|
-
* next sign-in before fresh fetches land, which on a shared device is a data leak.
|
|
9
|
+
* next sign-in before fresh fetches land, which on a shared device is a data leak. Pass `{ keep }`
|
|
10
|
+
* to keep named slices for this one reset, such as the session and the API cache on a workspace switch.
|
|
6
11
|
*/
|
|
7
|
-
export declare const resetState: import("@reduxjs/toolkit").
|
|
12
|
+
export declare const resetState: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[options?: ResetStateOptions | undefined], ResetStateOptions, "app/resetState", never, never>;
|
|
8
13
|
export interface RootReducerOptions<K extends string> {
|
|
9
14
|
/** Slices that survive a reset because they belong to the device, not the user (theme, onboarding seen). */
|
|
10
15
|
preserve?: readonly K[];
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { type ComponentType, type LazyExoticComponent } from "react";
|
|
1
|
+
import { type ComponentType, type LazyExoticComponent, lazy } from "react";
|
|
2
2
|
/** Whether `error` is a lazy chunk that failed to load, the signature of a tab older than the deploy. */
|
|
3
3
|
export declare const isChunkLoadError: (error: unknown) => boolean;
|
|
4
|
+
/** Any component `React.lazy` accepts, taken from React's own declaration. */
|
|
5
|
+
type LazyComponent = Awaited<ReturnType<Parameters<typeof lazy>[0]>>["default"];
|
|
4
6
|
/**
|
|
5
7
|
* Whether a recovery reload of the current page (path, query and hash) was claimed inside the
|
|
6
8
|
* window (60 s). An app's own error boundary asks this before reloading for a chunk error, so the
|
|
@@ -37,6 +39,7 @@ export declare const importWithReload: <T extends object>(importFn: () => Promis
|
|
|
37
39
|
* `React.lazy` with the same one reload: a lazy screen that recovers a tab opened before a deploy.
|
|
38
40
|
* It renders after the navigation has committed, so the reload is of the page it is on.
|
|
39
41
|
*/
|
|
40
|
-
export declare const lazyWithReload: <C extends
|
|
42
|
+
export declare const lazyWithReload: <C extends LazyComponent>(importFn: () => Promise<{
|
|
41
43
|
default: C;
|
|
42
44
|
}>) => LazyExoticComponent<C>;
|
|
45
|
+
export {};
|
|
@@ -11,3 +11,5 @@ export type { ReturnToSource } from "./returnTo";
|
|
|
11
11
|
export { buildLoginPath, getReturnTo, RETURN_TO_PARAM, toSafeReturnTo } from "./returnTo";
|
|
12
12
|
export type { RouteErrorKind, RouteErrorReport } from "./routeError";
|
|
13
13
|
export { classifyRouteError, useRouteErrorReport } from "./routeError";
|
|
14
|
+
export type { RouteTableEntry, RouteTablePages } from "./routeTable";
|
|
15
|
+
export { defineRouteTable } from "./routeTable";
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { PathParam } from "react-router";
|
|
2
|
+
/** One route as a portal's table declares it: a literal path or an index route, and its children. Other RouteObject keys pass through untouched. */
|
|
3
|
+
export type RouteTableEntry = {
|
|
4
|
+
readonly path?: string;
|
|
5
|
+
readonly index?: boolean;
|
|
6
|
+
readonly children?: readonly RouteTableEntry[];
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The full path of every entry, parent and child segments joined, as React Router's Register["pages"]: each path maps to its params.
|
|
10
|
+
* A child path that starts with "/" stands alone. A table whose paths lost their literal types (a plain `string`) resolves to a
|
|
11
|
+
* single `RouteTableNeedsLiteralPaths` key instead, so every `href` call against it fails rather than every path being accepted.
|
|
12
|
+
*/
|
|
13
|
+
export type RouteTablePages<T extends readonly RouteTableEntry[]> = true extends HasWidePath<T> ? {
|
|
14
|
+
RouteTableNeedsLiteralPaths: never;
|
|
15
|
+
} : {
|
|
16
|
+
[P in FullPaths<T, "">]: {
|
|
17
|
+
params: PathParams<P>;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/** A `:name` segment is required, a `:name?` segment is optional and a trailing `*` is the splat key, as `href` takes them. */
|
|
21
|
+
type PathParams<P extends string> = Flatten<{
|
|
22
|
+
[K in PathParam<P> as K extends OptionalNames<P> ? never : K]: string;
|
|
23
|
+
} & {
|
|
24
|
+
[K in PathParam<P> as K extends OptionalNames<P> ? K : never]?: string;
|
|
25
|
+
}>;
|
|
26
|
+
type Flatten<T> = {
|
|
27
|
+
[K in keyof T]: T[K];
|
|
28
|
+
} & {};
|
|
29
|
+
type Segments<P extends string> = P extends `${infer Head}/${infer Rest}` ? Head | Segments<Rest> : P;
|
|
30
|
+
type OptionalName<S extends string> = S extends `:${infer Name}?${string}` ? Name : never;
|
|
31
|
+
type OptionalNames<P extends string> = OptionalName<Segments<P>>;
|
|
32
|
+
/** Parent joined with a child path: an absolute child stands alone, and a root parent adds no second slash. */
|
|
33
|
+
type Join<Parent extends string, Child extends string> = Child extends `/${string}` ? Child : Child extends "" ? Parent extends "" ? "/" : Parent : Parent extends "" | "/" ? `/${Child}` : Parent extends `${infer Base}/` ? `${Base}/${Child}` : `${Parent}/${Child}`;
|
|
34
|
+
/** The full path an entry itself answers on: its joined path, or the parent's path for an index route, or none for a layout. */
|
|
35
|
+
type OwnPath<E extends RouteTableEntry, Parent extends string> = E extends {
|
|
36
|
+
readonly path: infer P extends string;
|
|
37
|
+
} ? Join<Parent, P> : E extends {
|
|
38
|
+
readonly index: true;
|
|
39
|
+
} ? Parent extends "" ? "/" : Parent : never;
|
|
40
|
+
/** The path children of an entry resolve against: a layout route (no path, no index) passes its parent's path on. */
|
|
41
|
+
type ChildParent<E extends RouteTableEntry, Parent extends string> = E extends {
|
|
42
|
+
readonly path: infer P extends string;
|
|
43
|
+
} ? Join<Parent, P> : Parent;
|
|
44
|
+
type EntryPaths<E extends RouteTableEntry, Parent extends string> = E extends RouteTableEntry ? OwnPath<E, Parent> | ChildPaths<E, ChildParent<E, Parent>> : never;
|
|
45
|
+
type ChildPaths<E extends RouteTableEntry, Parent extends string> = E extends {
|
|
46
|
+
readonly children: infer C extends readonly RouteTableEntry[];
|
|
47
|
+
} ? FullPaths<C, Parent> : never;
|
|
48
|
+
type FullPaths<T extends readonly RouteTableEntry[], Parent extends string> = EntryPaths<T[number], Parent>;
|
|
49
|
+
/** Whether any entry, at any depth, has a path typed as plain `string` (or optional), which no literal list can come from. */
|
|
50
|
+
type HasWidePath<T extends readonly RouteTableEntry[]> = WidePath<T[number]>;
|
|
51
|
+
type WidePath<E extends RouteTableEntry> = E extends RouteTableEntry ? (string extends E["path" & keyof E] ? true : never) | WideChildren<E> : never;
|
|
52
|
+
type WideChildren<E extends RouteTableEntry> = E extends {
|
|
53
|
+
readonly children: infer C extends readonly RouteTableEntry[];
|
|
54
|
+
} ? WidePath<C[number]> : never;
|
|
55
|
+
/** The table with every list made mutable at each depth, so React Router's RouteObject[] takes it as it is; paths keep their literal types. */
|
|
56
|
+
type MutableRoutes<T extends readonly RouteTableEntry[]> = {
|
|
57
|
+
-readonly [I in keyof T]: MutableRoute<T[I]>;
|
|
58
|
+
};
|
|
59
|
+
type MutableRoute<E> = E extends {
|
|
60
|
+
readonly children: infer C extends readonly RouteTableEntry[];
|
|
61
|
+
} ? Omit<E, "children"> & {
|
|
62
|
+
children: MutableRoutes<C>;
|
|
63
|
+
} : E;
|
|
64
|
+
/** Returns the table unchanged, keeping each path's literal type for RouteTablePages and passing straight to createBrowserRouter. */
|
|
65
|
+
export declare function defineRouteTable<const T extends readonly RouteTableEntry[]>(routes: T): MutableRoutes<T>;
|
|
66
|
+
export {};
|
|
@@ -33,7 +33,7 @@ export interface StorageApi {
|
|
|
33
33
|
getItem: (key: string) => Promise<string | null>;
|
|
34
34
|
setItem: (key: string, value: string) => Promise<boolean>;
|
|
35
35
|
removeItem: (key: string) => Promise<boolean>;
|
|
36
|
-
getJson: <T>(key: string) => Promise<T | null>;
|
|
36
|
+
getJson: <T>(key: string, parse: (value: unknown) => T) => Promise<T | null>;
|
|
37
37
|
setJson: <T>(key: string, value: T) => Promise<boolean>;
|
|
38
38
|
multiGet: (keys: readonly string[]) => Promise<Record<string, string | null>>;
|
|
39
39
|
multiSet: (entries: Record<string, string>) => Promise<boolean>;
|
|
@@ -53,20 +53,22 @@ export interface StorageApi {
|
|
|
53
53
|
*/
|
|
54
54
|
export declare const Storage: StorageApi;
|
|
55
55
|
/**
|
|
56
|
-
* Synchronous
|
|
57
|
-
* sidebar, a table's sort
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
56
|
+
* Synchronous browser storage for reads a first render cannot wait for: a theme, a collapsed
|
|
57
|
+
* sidebar, a table's sort (`syncStorage`, over localStorage), or state that ends with the tab
|
|
58
|
+
* (`syncSessionStorage`, over sessionStorage). Web only; mobile-core has no synchronous store
|
|
59
|
+
* (its backends are asynchronous), so code shared with an app uses `Storage`. Like `Storage`,
|
|
60
|
+
* nothing here throws: a blocked or full store reads as empty and a write reports `false`.
|
|
61
|
+
* Not for tokens.
|
|
61
62
|
*/
|
|
62
63
|
export interface SyncStorageApi {
|
|
63
64
|
getItem: (key: string) => string | null;
|
|
64
65
|
setItem: (key: string, value: string) => boolean;
|
|
65
66
|
removeItem: (key: string) => boolean;
|
|
66
|
-
/** The
|
|
67
|
-
getJson: <T>(key: string) => T | null;
|
|
67
|
+
/** The value parse builds, or null when nothing is stored or it is not JSON. A throw from parse propagates. */
|
|
68
|
+
getJson: <T>(key: string, parse: (value: unknown) => T) => T | null;
|
|
68
69
|
/** False when the value cannot be serialised or the write is refused. */
|
|
69
70
|
setJson: <T>(key: string, value: T) => boolean;
|
|
70
71
|
}
|
|
71
72
|
export declare const syncStorage: SyncStorageApi;
|
|
73
|
+
export declare const syncSessionStorage: SyncStorageApi;
|
|
72
74
|
export type { AsyncStorageLike };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getConfigValue as e}from"../config/index.js";import{Logger as t}from"../logger/logger.js";var n=null,r=/* @__PURE__ */ new Set,i=null,a=()=>void 0,o=()=>n,s=e=>(r.add(e),()=>{r.delete(e)}),c=()=>{for(let e of[...r])try{e()}catch(e){t.error(`[VersionCheck] a deployed-build listener threw`,e)}},l=()=>{if(typeof window>`u`)return a;if(i!==null)return i;let r=e(`buildId`);if(!r)return t.warn(`[VersionCheck] buildId is not configured; call setConfig({ buildId }) with the marker the build stamps`),i=a,a;let o=e(`versionUrl`),s=e(`buildCheckIntervalMs`),l=!1,u=async()=>{if(!l){l=!0;try{let e=await fetch(o,{cache:`no-store`});if(!e.ok)return;let t=
|
|
1
|
+
import{getConfigValue as e}from"../config/index.js";import{Logger as t}from"../logger/logger.js";var n=null,r=/* @__PURE__ */ new Set,i=null,a=()=>void 0,o=()=>n,s=e=>(r.add(e),()=>{r.delete(e)}),c=()=>{for(let e of[...r])try{e()}catch(e){t.error(`[VersionCheck] a deployed-build listener threw`,e)}},l=()=>{if(typeof window>`u`)return a;if(i!==null)return i;let r=e(`buildId`);if(!r)return t.warn(`[VersionCheck] buildId is not configured; call setConfig({ buildId }) with the marker the build stamps`),i=a,a;let o=e(`versionUrl`),s=e(`buildCheckIntervalMs`),l=!1,u=async()=>{if(!l){l=!0;try{let e=await fetch(o,{cache:`no-store`});if(!e.ok)return;let t=await e.json(),i=typeof t==`object`&&t&&`version`in t?t.version:void 0,a=typeof i==`string`?i.trim():``;a!==``&&a!==r&&(n=a,c(),p())}catch(e){t.debug(`[VersionCheck] the deployed-build check failed`,e)}finally{l=!1}}},d=()=>{document.visibilityState===`visible`&&u()},f=setInterval(()=>void u(),s),p=()=>{clearInterval(f),document.removeEventListener(`visibilitychange`,d)};return document.addEventListener(`visibilitychange`,d),i=p,p};export{s as addDeployedBuildListener,o as getNewerDeployedBuild,l as startDeployedBuildCheck};
|
package/dist/vite/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as e,readFileSync as t}from"node:fs";import{basename as n,dirname as r,join as i,resolve as a}from"node:path";var o=`virtual:webority-static-assets`,s=`\0${o}`,c=i(`.webority`,`infra`,`deployables.json`),l=/^https:\/\/[a-z0-9.-]+(:\d+)?$/,u=/^[0-9a-f]{64}$/,d=12,f=`export default null;`;function p(e,t){let n=t?.trim();if(!n)return null;if(n!==`/`&&!l.test(n))throw Error(`weborityStatic: ${e} must be "/" or an https origin with no path and no trailing slash, got "${n}".`);return n}function m(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function h(t){let n=i(t,c);if(e(n))return n;let a=r(t);return a===t?null:h(a)}function g(e){let n;try{n=JSON.parse(t(e,`utf8`))}catch(t){throw Error(`weborityStatic: cannot read ${e}: ${t instanceof Error?t.message:String(t)}`)}let r=m(n)?n.deployables:void 0;if(!m(r))throw Error(`weborityStatic: ${e} has no "deployables" object.`);let i=Object.entries(r).filter(
|
|
1
|
+
import{existsSync as e,readFileSync as t}from"node:fs";import{basename as n,dirname as r,join as i,resolve as a}from"node:path";var o=`virtual:webority-static-assets`,s=`\0${o}`,c=i(`.webority`,`infra`,`deployables.json`),l=/^https:\/\/[a-z0-9.-]+(:\d+)?$/,u=/^[0-9a-f]{64}$/,d=12,f=`export default null;`;function p(e,t){let n=t?.trim();if(!n)return null;if(n!==`/`&&!l.test(n))throw Error(`weborityStatic: ${e} must be "/" or an https origin with no path and no trailing slash, got "${n}".`);return n}function m(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function h(t){let n=i(t,c);if(e(n))return n;let a=r(t);return a===t?null:h(a)}function g(e){let n;try{n=JSON.parse(t(e,`utf8`))}catch(t){throw Error(`weborityStatic: cannot read ${e}: ${t instanceof Error?t.message:String(t)}`)}let r=m(n)?n.deployables:void 0;if(!m(r))throw Error(`weborityStatic: ${e} has no "deployables" object.`);let i=Object.entries(r).filter(e=>m(e[1])&&`staticAssets`in e[1]);if(i.length===0)return null;if(i.length>1)throw Error(`weborityStatic: ${e} must have exactly one deployable with "staticAssets"; it has ${i.length}.`);let[a]=i;if(a===void 0)throw Error(`weborityStatic: ${e} lost its carrier deployable.`);let[o,s]=a,c=s.staticAssets,l=m(c)?c.assets:void 0;if(!m(l))throw Error(`weborityStatic: ${e}: deployable '${o}' has no "staticAssets.assets" object.`);let f={};for(let[t,n]of Object.entries(l)){let r=m(n)?n.sha256:void 0;if(typeof r!=`string`||!u.test(r))throw Error(`weborityStatic: ${e} asset "${t}" needs a sha256 of 64 lowercase hex characters.`);f[t]=r.slice(0,d)}return{carrier:o,versions:f}}function _(e={}){let t=p(`authoredOrigin`,e.authoredOrigin),r=p(`buildOrigin`,e.buildOrigin),i=``,o=f;return{name:`webority-static`,enforce:`pre`,config(e,t){if(r===null||t.command!==`build`)return;let n=r===`/`?``:r;return{experimental:{renderBuiltUrl:(e,t)=>t.type===`public`?void 0:`${n}/_static/${i}/${e.replace(/^\/+/,``)}`}}},configResolved(s){let c=a(s.root);if(i=n(c).toLowerCase().replaceAll(`.`,`-`),r!==null&&i===``)throw Error(`weborityStatic: cannot name the head from the Vite root "${c}".`);let l=e.manifest?a(c,e.manifest):h(c),u=l===null?null:g(l);if(u===null){if(t!==null)throw Error(`weborityStatic: authoredOrigin is set but ${l??`no .webority/infra/deployables.json above the Vite root`} has no deployable carrying "staticAssets".`);o=f}else{if(t===null)throw Error(`weborityStatic: ${l} has a deployable carrying staticAssets, so authoredOrigin is required ("/" or an https origin).`);o=`export default ${JSON.stringify({authoredOrigin:t,versions:u.versions})};`}},resolveId(e){return e===`virtual:webority-static-assets`?s:null},load(e){return e===s?o:null}}}export{o as STATIC_ASSETS_MODULE_ID,_ as weborityStatic};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/web-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.152.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",
|
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
"types": "./dist/types/api/index.d.ts",
|
|
27
27
|
"default": "./dist/api/index.js"
|
|
28
28
|
},
|
|
29
|
+
"./appInsights": {
|
|
30
|
+
"types": "./dist/types/appInsights/index.d.ts",
|
|
31
|
+
"default": "./dist/appInsights/index.js"
|
|
32
|
+
},
|
|
29
33
|
"./auth": {
|
|
30
34
|
"types": "./dist/types/auth/index.d.ts",
|
|
31
35
|
"default": "./dist/auth/index.js"
|
|
@@ -93,24 +97,36 @@
|
|
|
93
97
|
"./package.json": "./package.json"
|
|
94
98
|
},
|
|
95
99
|
"sideEffects": false,
|
|
100
|
+
"dependencies": {
|
|
101
|
+
"@webority/api-contract": "0.152.0"
|
|
102
|
+
},
|
|
96
103
|
"peerDependencies": {
|
|
104
|
+
"@microsoft/applicationinsights-web": "^3.4.5",
|
|
97
105
|
"@reduxjs/toolkit": "^2.12.0",
|
|
98
106
|
"axios": "^1.18.0",
|
|
99
|
-
"react": "^19.
|
|
107
|
+
"react": "^19.2.7",
|
|
100
108
|
"react-redux": "^9.3.0",
|
|
101
|
-
"react-router": "^
|
|
109
|
+
"react-router": "^8.5.1"
|
|
110
|
+
},
|
|
111
|
+
"peerDependenciesMeta": {
|
|
112
|
+
"@microsoft/applicationinsights-web": {
|
|
113
|
+
"optional": true
|
|
114
|
+
}
|
|
102
115
|
},
|
|
103
116
|
"devDependencies": {
|
|
117
|
+
"@microsoft/applicationinsights-web": "^3.4.5",
|
|
104
118
|
"@reduxjs/toolkit": "^2.14.0",
|
|
105
119
|
"@testing-library/react": "^16.3.0",
|
|
106
|
-
"@types/
|
|
120
|
+
"@types/node": "25.6.0",
|
|
121
|
+
"@types/react": "^19.3.0",
|
|
107
122
|
"@vitest/coverage-v8": "5.1.0",
|
|
123
|
+
"@webority/biome-config": "0.152.0",
|
|
108
124
|
"axios": "^1.18.0",
|
|
109
125
|
"jsdom": "30.1.1",
|
|
110
126
|
"react": "^19.3.1",
|
|
111
127
|
"react-dom": "^19.3.1",
|
|
112
128
|
"react-redux": "^9.3.0",
|
|
113
|
-
"react-router": "^
|
|
129
|
+
"react-router": "^8.5.1",
|
|
114
130
|
"typescript": "^7.0.2",
|
|
115
131
|
"vite": "^8.3.6",
|
|
116
132
|
"vitest": "5.1.0"
|