@katlux/providers 0.1.1-alpha.111 → 0.1.1-alpha.113

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/dist/index.d.ts CHANGED
@@ -21,6 +21,8 @@ interface IEncryptionContext {
21
21
  url?: string;
22
22
  method?: string;
23
23
  isServer?: boolean;
24
+ /** Whether to bind the request context (URL and method as `req:${method}:${url}`) into AEAD Authenticated Additional Data (AAD) */
25
+ bindRequestContextAad?: boolean;
24
26
  /** Whitelist of specific field names to encrypt/decrypt (e.g. ['name', 'surname']). Any unlisted field remains plaintext. */
25
27
  fields?: string[];
26
28
  key?: TKeyProvider | IKeyPair;
@@ -65,6 +67,12 @@ interface IProviderEncryptionOptions {
65
67
  keyId?: string;
66
68
  /** Authenticated Additional Data (AAD) bound to the ciphertext to prevent field/record swapping */
67
69
  aad?: string | Uint8Array | ArrayBuffer;
70
+ /**
71
+ * Whether to bind the request context (HTTP method and URL as `req:${method}:${url}`) into AEAD Authenticated Additional Data (AAD).
72
+ * Defaults to true when URL or method is provided in context, mitigating replay and cross-endpoint confusion attacks (BUG-015).
73
+ * Set to false to disable request context AAD binding.
74
+ */
75
+ bindRequestContextAad?: boolean;
68
76
  /**
69
77
  * Whether decryption is permitted during Server-Side Rendering (SSR).
70
78
  * In an End-to-End (E2E) zero-trust model, defaults to false to prevent
@@ -219,6 +227,22 @@ interface ICacheQuotaOptions {
219
227
  quotaThresholdRatio?: number;
220
228
  fallbackToMemory?: boolean;
221
229
  }
230
+ interface ICookieCacheOptions {
231
+ /** Default: 'lax'. */
232
+ sameSite?: 'strict' | 'lax' | 'none';
233
+ /**
234
+ * Adds the `Secure` flag. Default: auto-detected from the request protocol
235
+ * (https => true). Set explicitly to force it on or off.
236
+ */
237
+ secure?: boolean;
238
+ /**
239
+ * Default: true. Only effective for cookies written on the server: browsers
240
+ * do not allow `document.cookie` to set HttpOnly, so client writes ignore it.
241
+ */
242
+ httpOnly?: boolean;
243
+ /** Default: '/'. */
244
+ path?: string;
245
+ }
222
246
  interface IRequestOptions {
223
247
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
224
248
  body?: any;
@@ -240,6 +264,7 @@ interface IRequestOptions {
240
264
  encryption?: IProviderEncryptionOptions;
241
265
  /** If true, returns raw response without decrypting, useful for DataProvider lazy page-level decryption */
242
266
  skipDecryption?: boolean;
267
+ credentials?: RequestCredentials;
243
268
  }
244
269
  /** Queue persistence backend with automatic fallback: IndexedDB → LocalStorage → Memory */
245
270
  declare enum EQueueStorage {
@@ -324,8 +349,6 @@ interface IDataProviderState<TRow = TDataRow> {
324
349
  pageSize: number;
325
350
  filter: IDataFilter | null;
326
351
  sortList: IDataSort[];
327
- selectedRows: TRow[];
328
- selectAll: boolean;
329
352
  rowCount?: number;
330
353
  loading?: boolean;
331
354
  initialLoad?: boolean;
@@ -447,13 +470,6 @@ declare abstract class ADataProvider<TRow = TDataRow> {
447
470
  deduplicate: boolean;
448
471
  context: any;
449
472
  urlPageParam: string;
450
- protected _selectedRows: TRow[];
451
- get selectedRows(): TRow[];
452
- set selectedRows(val: TRow[]);
453
- protected _selectAll: boolean;
454
- get selectAll(): boolean;
455
- set selectAll(val: boolean);
456
- getSelectedRows(): TRow[];
457
473
  protected _currentPage: number;
458
474
  protected _pageSize: number;
459
475
  protected _filter: IDataFilter | null;
@@ -495,8 +511,6 @@ declare abstract class ADataProvider<TRow = TDataRow> {
495
511
  setSortList(sortList: IDataSort[], immediate?: boolean): void;
496
512
  setCurrentPage(currentPage: number): void;
497
513
  setPageSize(pageSize: number, resetPage?: boolean): void;
498
- setSelectedRows(rows: TRow[]): void;
499
- setSelectAll(val: boolean): void;
500
514
  abstract loadPageData(options?: {
501
515
  disableCache?: boolean;
502
516
  signal?: AbortSignal;
@@ -629,7 +643,6 @@ declare class CFlatClientDataProvider<TRow = TDataRow> extends AEncryptedClientP
629
643
  refresh(hardRefresh?: boolean): Promise<void>;
630
644
  private _computeFilteredAndSorted;
631
645
  loadPageData(): Promise<void>;
632
- getSelectedRows(): TRow[];
633
646
  }
634
647
 
635
648
  declare abstract class ACacheProvider {
@@ -1055,8 +1068,18 @@ declare class CCookieCache extends ACacheProvider {
1055
1068
  private static instance;
1056
1069
  static getInstance(): CCookieCache;
1057
1070
  type: string;
1058
- constructor();
1071
+ sameSite: 'strict' | 'lax' | 'none';
1072
+ secure: boolean | undefined;
1073
+ httpOnly: boolean;
1074
+ path: string;
1075
+ constructor(options?: ICookieCacheOptions);
1076
+ configure(options: ICookieCacheOptions): void;
1059
1077
  private getCookieKey;
1078
+ /**
1079
+ * Resolves the `Secure` flag: an explicit option wins, otherwise follow the
1080
+ * actual protocol so cookies are not silently dropped by browsers over plain HTTP.
1081
+ */
1082
+ private resolveSecure;
1060
1083
  private parseKeyFromCookieName;
1061
1084
  private isClient;
1062
1085
  getKeyList(context?: any): Promise<Array<string>>;
@@ -1267,6 +1290,7 @@ declare const SENSITIVE_HEADER_KEYS: string[];
1267
1290
  * RequestQueue.onDeadLetter((item, err) => toast.error(`Failed: ${item.label}`))
1268
1291
  * RequestQueue.onFlushComplete((tags) => console.log('Synced tags:', tags))
1269
1292
  * RequestQueue.onNetworkError((item) => toast.warn('Offline — will retry when back online'))
1293
+ * RequestQueue.onError((err) => toast.error(`Queue error: ${err.message}`))
1270
1294
  *
1271
1295
  * // Flush when back online
1272
1296
  * window.addEventListener('online', () => RequestQueue.flushAll())
@@ -1281,6 +1305,24 @@ declare class RequestQueue {
1281
1305
  static setMaxPayloadSize(bytes: number): void;
1282
1306
  static setMaxQueueSize(limit: number): void;
1283
1307
  static setMaxDeadLetterSize(limit: number): void;
1308
+ /**
1309
+ * Strips sensitive headers (e.g., authorization, cookie, x-csrf-token) before persisting
1310
+ * request options to persistent storage (IndexedDB / LocalStorage).
1311
+ * Sensitive credentials must never be stored in plaintext in browser storage, and are
1312
+ * instead regenerated dynamically at execution time.
1313
+ */
1314
+ /**
1315
+ * Adapts binary, multipart, and specialized payload types (FormData, Blob, File,
1316
+ * ArrayBuffer, TypedArrays, URLSearchParams) into JSON-serializable structures
1317
+ * to prevent silent payload loss (BUG-014) when persisting to offline storage.
1318
+ */
1319
+ static serializeBody(body: any): Promise<any>;
1320
+ private static serializeFieldValue;
1321
+ /**
1322
+ * Reconstitutes serialized offline request bodies back into their live runtime instances
1323
+ * (FormData, Blob, File, ArrayBuffer, Uint8Array, URLSearchParams) before network transmission.
1324
+ */
1325
+ static reconstituteBody(body: any): any;
1284
1326
  /**
1285
1327
  * Strips sensitive headers (e.g., authorization, cookie, x-csrf-token) before persisting
1286
1328
  * request options to persistent storage (IndexedDB / LocalStorage).
@@ -1297,6 +1339,7 @@ declare class RequestQueue {
1297
1339
  private static _onDeadLetter;
1298
1340
  private static _onFlushComplete;
1299
1341
  private static _onNetworkError;
1342
+ private static _onError;
1300
1343
  private static _headerProvider;
1301
1344
  static setHeaderProvider(provider: (() => Record<string, string> | Promise<Record<string, string>>) | null): void;
1302
1345
  /**
@@ -1312,6 +1355,8 @@ declare class RequestQueue {
1312
1355
  static onDeadLetter(cb: (item: IDeadLetterItem, error: Error) => void): void;
1313
1356
  static onFlushComplete(cb: (succeededTags: string[]) => void): void;
1314
1357
  static onNetworkError(cb: (item: IQueuedOperation) => void): void;
1358
+ static onError(cb: (error: Error) => void): void;
1359
+ static onQueueFatalError(cb: (error: Error) => void): void;
1315
1360
  /**
1316
1361
  * Add an operation to the pending queue and persist it.
1317
1362
  * Called internally by RequestProvider when queue: true.
@@ -1531,6 +1576,20 @@ declare abstract class AEncryptionProvider implements IEncryptionProvider {
1531
1576
  */
1532
1577
  [Symbol.dispose](): void;
1533
1578
  [Symbol.asyncDispose](): Promise<void>;
1579
+ /**
1580
+ * Resolves effective Authenticated Additional Data (AAD) for the operation:
1581
+ * 1. If options.bindRequestContextAad is explicitly false, returns options.aad directly without context binding.
1582
+ * 2. When encrypting (isDecrypt=false): binds request context `req:${method}:${url}` only if options.bindRequestContextAad === true.
1583
+ * 3. When decrypting (isDecrypt=true): derives request context `req:${method}:${url}` if url or method is provided.
1584
+ * 4. If explicit options.aad is provided: combines with request context if bound, or returns options.aad directly.
1585
+ * 5. Otherwise returns undefined.
1586
+ */
1587
+ protected _resolveEffectiveAad(options?: IEncryptionContext, isDecrypt?: boolean): string | Uint8Array | ArrayBuffer | undefined;
1588
+ /**
1589
+ * Helper to deterministically bind record ID and field name into the AAD
1590
+ * to prevent ciphertext swapping between fields or records.
1591
+ */
1592
+ protected _bindFieldAad(data: any, field: string, options?: IEncryptionContext): IEncryptionContext;
1534
1593
  /**
1535
1594
  * Encrypts a single value (string, object, primitive) into an IEncryptedPayload envelope.
1536
1595
  * Implemented by concrete cryptographic providers.
@@ -1654,7 +1713,7 @@ declare class CKeyManager {
1654
1713
  * Generates a high-entropy symmetric AES-GCM Account Data Encryption Key (ADEK).
1655
1714
  * Designed for multi-user table and field-level encryption.
1656
1715
  */
1657
- static generateAccountDataKey(length?: 128 | 192 | 256): Promise<CryptoKey>;
1716
+ static generateAccountDataKey(length?: 128 | 192 | 256, extractable?: boolean): Promise<CryptoKey>;
1658
1717
  /**
1659
1718
  * Wraps an Account Data Encryption Key (ADEK) for a specific user using the user's public key (RSA-OAEP).
1660
1719
  * Returns a Base64-encoded wrapped key string suitable for storage in role-map / access tables.
@@ -1664,7 +1723,7 @@ declare class CKeyManager {
1664
1723
  * Unwraps a Base64-encoded Account Data Encryption Key (ADEK) using the user's private key (RSA-OAEP).
1665
1724
  * Returns the restored AES-GCM CryptoKey ready for use in CWebCryptoEncryptionProvider.
1666
1725
  */
1667
- static unwrapAccountKeyForUser(wrappedKeyBase64: string, userPrivateKey: CryptoKey, unwrappedKeyAlgorithm?: any): Promise<CryptoKey>;
1726
+ static unwrapAccountKeyForUser(wrappedKeyBase64: string, userPrivateKey: CryptoKey, unwrappedKeyAlgorithm?: any, extractable?: boolean): Promise<CryptoKey>;
1668
1727
  /**
1669
1728
  * Derives a symmetric AES-GCM CryptoKey from a passphrase using PBKDF2 or HKDF.
1670
1729
  * Returns the derived CryptoKey and the base64-encoded salt.
@@ -1758,6 +1817,7 @@ declare class CWebCryptoAESCBCProvider extends AEncryptionProvider {
1758
1817
  private _cachedKdf?;
1759
1818
  private _cachedIter?;
1760
1819
  private _cachedHash?;
1820
+ private _cachedKeyId?;
1761
1821
  private _configuredKid?;
1762
1822
  private _kdfOptions?;
1763
1823
  private _decryptSaltCache;
@@ -1938,6 +1998,7 @@ declare class CNodeCryptoEncryptionProvider extends AEncryptionProvider {
1938
1998
  private _cachedKdf?;
1939
1999
  private _cachedIter?;
1940
2000
  private _cachedHash?;
2001
+ private _cachedKeyId?;
1941
2002
  private _configuredKid?;
1942
2003
  setDefaultKey(key: TKeyProvider): void;
1943
2004
  clearKeys(): void;
@@ -2034,11 +2095,17 @@ declare function getSafeKeyIdentifier(rawKey: any): string;
2034
2095
  * cross-tenant cache collisions and avoid storing secrets in heap Map keys.
2035
2096
  */
2036
2097
  declare function getKeyIdentifier(keyProvider?: any, defaultKey?: any): string;
2098
+ /**
2099
+ * Detects whether an error thrown during ciphertext decryption is an authentication failure
2100
+ * (e.g. tag mismatch, invalid AAD, corrupted ciphertext) across Web Crypto and Node.js runtimes.
2101
+ * Conforms to W3C Web Cryptography API specification (OperationError) and Node.js crypto error codes.
2102
+ */
2103
+ declare function isAuthOrDecryptionError(err: any): boolean;
2037
2104
 
2038
2105
  /**
2039
2106
  * Universal helper that verifies whether an arbitrary object is a Katlux encrypted payload envelope.
2040
2107
  */
2041
2108
  declare function isEncrypted(payload: any): boolean;
2042
2109
 
2043
- export { AAPIDataProvider, ADataProvider, AEncryptedClientProvider, AEncryptionProvider, CAPIFlatClientDataProvider, CAPIFlatServerDataProvider, CAPITreeClientDataProvider, CAPITreeServerDataProvider, CApplicationCache, CBrowserSessionCache, CCookieCache, CECDHEncryptionProvider, CFlatClientDataProvider, CFlatServerDataProvider, CIndexedDBCache, CKeyManager, CLocalStorageCache, CMemoryCache, CNodeCryptoEncryptionProvider, CRSAEncryptionProvider, CSearchIndex, CServerSessionCache, CTreeClientDataProvider, CTreeServerDataProvider, CWebCryptoAESCBCProvider, CWebCryptoEncryptionProvider, CacheProviderFactory, DefaultHydrationAdapter, ECacheStrategy, EDataFilterOperator, EQueueStorage, KatluxIndexedDB, QueueStorageFactory, RequestProvider, RequestProviderRegistry, RequestQueue, SENSITIVE_HEADER_KEYS, applyOperator, buildEncryptionContext, clearCachedCipherProvider, clearSSRData, compareAnd, compareEqual, compareIn, compareOr, compareValues, createEncryptionProvider, debounce, decryptPageRows, encryptRows, encryptRowsChunked, evaluateFilter, extractTrigrams, fastKeyHash, fetchWithSSR, filterData, filterTreeData, getAppRoute, getAppRouter, getCipherProvider, getHydrationAdapter, getKeyIdentifier, getPlatformApp, getRandomValues, getSSRData, getSSRPayload, getSafeKeyIdentifier, getSubtleCrypto, isDataEncrypted, isEncrypted, normalizeIndexTerm, onPlatformReady, resolveInfoBytes, safeSetProperty, setHydrationAdapter, sortData, textDecoder, textEncoder, toBase64, useDebounce, useFilterLogic, useSortLogic };
2044
- export type { CacheDriverLoader, ICNodeCryptoOptions, ICWebCryptoAESCBCOptions, ICWebCryptoOptions, ICacheEntry, ICacheQuotaOptions, IDataFilter, IDataProviderOptions, IDataProviderSetStateOptions, IDataProviderState, IDataResult, IDataSort, IDeadLetterItem, IDebouncedFunction, IEncryptedPayload, IEncryptionContext, IEncryptionProvider, IFlushOptions, IHKDFFromSecretOptions, IKDFOptions, IKDatatableAction, IKeyPair, IPlatformRouter, IProviderEncryptionOptions, IQueueStorageAdapter, IQueuedOperation, IRequestOptions, ISSRHydrationAdapter, ISearchIndexRowEntry, ISetDataChunkedOptions, ITreeDataProvider, ITreeDataProviderOptions, ITreeNode, ITreeNodeStatic, IVirtualScrollState, IWrappedKey, KProductItemData, KProductRowAction, TDataProviderListener, TDataProviderStateChangeListener, TDataRow, TECDHCurve, TKatluxStore, TKeyProvider, TPageDataHandler, TQueueItemStatus, TRawKey, TTreePageDataHandler, TTreeRow, TUnsubscribe, TreePaginationMode };
2110
+ export { AAPIDataProvider, ADataProvider, AEncryptedClientProvider, AEncryptionProvider, CAPIFlatClientDataProvider, CAPIFlatServerDataProvider, CAPITreeClientDataProvider, CAPITreeServerDataProvider, CApplicationCache, CBrowserSessionCache, CCookieCache, CECDHEncryptionProvider, CFlatClientDataProvider, CFlatServerDataProvider, CIndexedDBCache, CKeyManager, CLocalStorageCache, CMemoryCache, CNodeCryptoEncryptionProvider, CRSAEncryptionProvider, CSearchIndex, CServerSessionCache, CTreeClientDataProvider, CTreeServerDataProvider, CWebCryptoAESCBCProvider, CWebCryptoEncryptionProvider, CacheProviderFactory, DefaultHydrationAdapter, ECacheStrategy, EDataFilterOperator, EQueueStorage, KatluxIndexedDB, QueueStorageFactory, RequestProvider, RequestProviderRegistry, RequestQueue, SENSITIVE_HEADER_KEYS, applyOperator, buildEncryptionContext, clearCachedCipherProvider, clearSSRData, compareAnd, compareEqual, compareIn, compareOr, compareValues, createEncryptionProvider, debounce, decryptPageRows, encryptRows, encryptRowsChunked, evaluateFilter, extractTrigrams, fastKeyHash, fetchWithSSR, filterData, filterTreeData, getAppRoute, getAppRouter, getCipherProvider, getHydrationAdapter, getKeyIdentifier, getPlatformApp, getRandomValues, getSSRData, getSSRPayload, getSafeKeyIdentifier, getSubtleCrypto, isAuthOrDecryptionError, isDataEncrypted, isEncrypted, normalizeIndexTerm, onPlatformReady, resolveInfoBytes, safeSetProperty, setHydrationAdapter, sortData, textDecoder, textEncoder, toBase64, useDebounce, useFilterLogic, useSortLogic };
2111
+ export type { CacheDriverLoader, ICNodeCryptoOptions, ICWebCryptoAESCBCOptions, ICWebCryptoOptions, ICacheEntry, ICacheQuotaOptions, ICookieCacheOptions, IDataFilter, IDataProviderOptions, IDataProviderSetStateOptions, IDataProviderState, IDataResult, IDataSort, IDeadLetterItem, IDebouncedFunction, IEncryptedPayload, IEncryptionContext, IEncryptionProvider, IFlushOptions, IHKDFFromSecretOptions, IKDFOptions, IKDatatableAction, IKeyPair, IPlatformRouter, IProviderEncryptionOptions, IQueueStorageAdapter, IQueuedOperation, IRequestOptions, ISSRHydrationAdapter, ISearchIndexRowEntry, ISetDataChunkedOptions, ITreeDataProvider, ITreeDataProviderOptions, ITreeNode, ITreeNodeStatic, IVirtualScrollState, IWrappedKey, KProductItemData, KProductRowAction, TDataProviderListener, TDataProviderStateChangeListener, TDataRow, TECDHCurve, TKatluxStore, TKeyProvider, TPageDataHandler, TQueueItemStatus, TRawKey, TTreePageDataHandler, TTreeRow, TUnsubscribe, TreePaginationMode };