@katlux/providers 0.1.1-alpha.119 → 0.1.1-alpha.121
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.cjs +151 -38
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +151 -38
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -816,7 +816,31 @@ class AEncryptionProvider {
|
|
|
816
816
|
return this.encryptValue(data, options);
|
|
817
817
|
}
|
|
818
818
|
if (Array.isArray(data)) {
|
|
819
|
-
if (
|
|
819
|
+
if (data.length === 0) return data;
|
|
820
|
+
if (options?.fields && options.fields.length > 0) {
|
|
821
|
+
const fields = options.fields;
|
|
822
|
+
let hasUnencrypted = false;
|
|
823
|
+
for (let i = 0; i < data.length; i++) {
|
|
824
|
+
const item = data[i];
|
|
825
|
+
if (item && typeof item === "object") {
|
|
826
|
+
for (let f = 0; f < fields.length; f++) {
|
|
827
|
+
const val = item[fields[f]];
|
|
828
|
+
if (val !== void 0 && val !== null && !this.isEncrypted(val)) {
|
|
829
|
+
hasUnencrypted = true;
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
if (hasUnencrypted) break;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
if (!hasUnencrypted) {
|
|
837
|
+
return data;
|
|
838
|
+
}
|
|
839
|
+
await this.warmupKey(options);
|
|
840
|
+
const itemOptions = { ...options, _warmed: true };
|
|
841
|
+
return Promise.all(data.map((item) => this.encrypt(item, itemOptions)));
|
|
842
|
+
}
|
|
843
|
+
if (options?.valueEncryption === true) {
|
|
820
844
|
await this.warmupKey(options);
|
|
821
845
|
const itemOptions = { ...options, _warmed: true };
|
|
822
846
|
return Promise.all(data.map((item) => this.encrypt(item, itemOptions)));
|
|
@@ -829,7 +853,7 @@ class AEncryptionProvider {
|
|
|
829
853
|
(field) => Object.prototype.hasOwnProperty.call(data, field) && data[field] !== void 0 && data[field] !== null && !this.isEncrypted(data[field])
|
|
830
854
|
);
|
|
831
855
|
if (fieldsToEncrypt.length === 0) {
|
|
832
|
-
return
|
|
856
|
+
return data;
|
|
833
857
|
}
|
|
834
858
|
if (!options?._warmed) {
|
|
835
859
|
await this.warmupKey(options);
|
|
@@ -887,12 +911,13 @@ class AEncryptionProvider {
|
|
|
887
911
|
return Promise.all(payload.map((item) => this.decrypt(item, options)));
|
|
888
912
|
}
|
|
889
913
|
if (typeof payload === "object" && !ArrayBuffer.isView(payload) && !(payload instanceof ArrayBuffer)) {
|
|
890
|
-
const
|
|
891
|
-
const
|
|
892
|
-
const keysToDecrypt = targetKeys.filter((key) => this.isEncrypted(result[key]));
|
|
914
|
+
const targetKeys = options?.fields && options.fields.length > 0 ? options.fields.filter((f) => Object.prototype.hasOwnProperty.call(payload, f)) : Object.keys(payload);
|
|
915
|
+
const keysToDecrypt = targetKeys.filter((key) => this.isEncrypted(payload[key]));
|
|
893
916
|
if (keysToDecrypt.length === 0) {
|
|
894
917
|
return payload;
|
|
895
918
|
}
|
|
919
|
+
const proto = Object.getPrototypeOf(payload);
|
|
920
|
+
const result = proto && proto !== Object.prototype ? Object.assign(Object.create(proto), payload) : { ...payload };
|
|
896
921
|
const entries = await Promise.all(
|
|
897
922
|
keysToDecrypt.map(async (key) => {
|
|
898
923
|
const boundOptions = this._bindFieldAad(payload, key, options);
|
|
@@ -1758,16 +1783,15 @@ class CWebCryptoEncryptionProvider extends AEncryptionProvider {
|
|
|
1758
1783
|
};
|
|
1759
1784
|
const aad = this._resolveEffectiveAad(options, true);
|
|
1760
1785
|
let hasAad = false;
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
}
|
|
1768
|
-
} else if (payload.aad) {
|
|
1769
|
-
throw new Error("[CWebCryptoEncryptionProvider] Payload requires Authenticated Additional Data (AAD) for decryption, but none was provided.");
|
|
1786
|
+
const shouldApplyAad = payload.aad === true || payload.aad === void 0 && (options?.bindRequestContextAad === true || options?.aad !== void 0);
|
|
1787
|
+
if (shouldApplyAad && aad) {
|
|
1788
|
+
const aadBytes = typeof aad === "string" ? textEncoder$1.encode(aad) : aad instanceof Uint8Array ? aad : new Uint8Array(aad);
|
|
1789
|
+
if (aadBytes.byteLength > 0) {
|
|
1790
|
+
decryptParams.additionalData = aadBytes;
|
|
1791
|
+
hasAad = true;
|
|
1770
1792
|
}
|
|
1793
|
+
} else if (payload.aad && !aad) {
|
|
1794
|
+
throw new Error("[CWebCryptoEncryptionProvider] Payload requires Authenticated Additional Data (AAD) for decryption, but none was provided.");
|
|
1771
1795
|
}
|
|
1772
1796
|
let decryptedBuffer;
|
|
1773
1797
|
try {
|
|
@@ -3917,6 +3941,26 @@ async function encryptRows(rows, encryption, apiUrl, idKey) {
|
|
|
3917
3941
|
if (!cipherProvider) {
|
|
3918
3942
|
return rows;
|
|
3919
3943
|
}
|
|
3944
|
+
if (encryption.fields && encryption.fields.length > 0) {
|
|
3945
|
+
let allEncrypted = true;
|
|
3946
|
+
const fields = encryption.fields;
|
|
3947
|
+
for (let i = 0; i < rows.length; i++) {
|
|
3948
|
+
const item = rows[i];
|
|
3949
|
+
if (item && typeof item === "object") {
|
|
3950
|
+
for (let f = 0; f < fields.length; f++) {
|
|
3951
|
+
const val = item[fields[f]];
|
|
3952
|
+
if (val !== void 0 && val !== null && !cipherProvider.isEncrypted(val)) {
|
|
3953
|
+
allEncrypted = false;
|
|
3954
|
+
break;
|
|
3955
|
+
}
|
|
3956
|
+
}
|
|
3957
|
+
if (!allEncrypted) break;
|
|
3958
|
+
}
|
|
3959
|
+
}
|
|
3960
|
+
if (allEncrypted) {
|
|
3961
|
+
return rows;
|
|
3962
|
+
}
|
|
3963
|
+
}
|
|
3920
3964
|
const ctx = buildEncryptionContext(encryption, apiUrl);
|
|
3921
3965
|
if (typeof cipherProvider.warmupKey === "function") {
|
|
3922
3966
|
await cipherProvider.warmupKey(ctx);
|
|
@@ -3933,6 +3977,27 @@ async function encryptRowsChunked(rows, encryption, options, apiUrl, idKey, onCh
|
|
|
3933
3977
|
options?.onProgress?.({ processed: rows.length, total: rows.length, percent: 100 });
|
|
3934
3978
|
return rows;
|
|
3935
3979
|
}
|
|
3980
|
+
if (!onChunkEncrypted && encryption.fields && encryption.fields.length > 0) {
|
|
3981
|
+
let allEncrypted = true;
|
|
3982
|
+
const fields = encryption.fields;
|
|
3983
|
+
for (let i = 0; i < rows.length; i++) {
|
|
3984
|
+
const item = rows[i];
|
|
3985
|
+
if (item && typeof item === "object") {
|
|
3986
|
+
for (let f = 0; f < fields.length; f++) {
|
|
3987
|
+
const val = item[fields[f]];
|
|
3988
|
+
if (val !== void 0 && val !== null && !cipherProvider.isEncrypted(val)) {
|
|
3989
|
+
allEncrypted = false;
|
|
3990
|
+
break;
|
|
3991
|
+
}
|
|
3992
|
+
}
|
|
3993
|
+
if (!allEncrypted) break;
|
|
3994
|
+
}
|
|
3995
|
+
}
|
|
3996
|
+
if (allEncrypted) {
|
|
3997
|
+
options?.onProgress?.({ processed: rows.length, total: rows.length, percent: 100 });
|
|
3998
|
+
return rows;
|
|
3999
|
+
}
|
|
4000
|
+
}
|
|
3936
4001
|
const ctx = buildEncryptionContext(encryption, apiUrl);
|
|
3937
4002
|
if (typeof cipherProvider.warmupKey === "function") {
|
|
3938
4003
|
await cipherProvider.warmupKey(ctx);
|
|
@@ -4296,7 +4361,8 @@ class AEncryptedClientProvider extends ADataProvider {
|
|
|
4296
4361
|
if (!this.isEncryptionEnabled || !rows || rows.length === 0) {
|
|
4297
4362
|
return { rows, decrypted: false };
|
|
4298
4363
|
}
|
|
4299
|
-
|
|
4364
|
+
const url = this.apiUrl || void 0;
|
|
4365
|
+
return await decryptPageRows(rows, this.encryption, url, this.idKey);
|
|
4300
4366
|
}
|
|
4301
4367
|
async setDataChunked(data, options) {
|
|
4302
4368
|
const ret = this.setData(data);
|
|
@@ -4645,6 +4711,11 @@ class CFlatClientDataProvider extends AEncryptedClientProvider {
|
|
|
4645
4711
|
this._sortDirty = true;
|
|
4646
4712
|
super.setSortList(sortList, immediate);
|
|
4647
4713
|
}
|
|
4714
|
+
clearEncryption() {
|
|
4715
|
+
super.clearEncryption();
|
|
4716
|
+
this._filterDirty = true;
|
|
4717
|
+
this._sortDirty = true;
|
|
4718
|
+
}
|
|
4648
4719
|
/**
|
|
4649
4720
|
* Explicitly rebuilds the reference map array if row properties inside allData were mutated in-place.
|
|
4650
4721
|
*/
|
|
@@ -4675,7 +4746,7 @@ class CFlatClientDataProvider extends AEncryptedClientProvider {
|
|
|
4675
4746
|
if (this.sortList.length > 0) {
|
|
4676
4747
|
this._sortDirty = true;
|
|
4677
4748
|
} else {
|
|
4678
|
-
this._rowMap = this.filteredData;
|
|
4749
|
+
this._rowMap = this.isEncryptionEnabled ? [...this.filteredData] : this.filteredData;
|
|
4679
4750
|
this._sortDirty = false;
|
|
4680
4751
|
}
|
|
4681
4752
|
}
|
|
@@ -4683,7 +4754,7 @@ class CFlatClientDataProvider extends AEncryptedClientProvider {
|
|
|
4683
4754
|
if (this.sortList.length > 0) {
|
|
4684
4755
|
this._rowMap = sortData(this.sortList, this.filteredData);
|
|
4685
4756
|
} else {
|
|
4686
|
-
this._rowMap = this.filteredData;
|
|
4757
|
+
this._rowMap = this.isEncryptionEnabled ? [...this.filteredData] : this.filteredData;
|
|
4687
4758
|
}
|
|
4688
4759
|
this._sortDirty = false;
|
|
4689
4760
|
}
|
|
@@ -4726,19 +4797,16 @@ class CFlatClientDataProvider extends AEncryptedClientProvider {
|
|
|
4726
4797
|
this.error = null;
|
|
4727
4798
|
try {
|
|
4728
4799
|
this._computeFilteredAndSorted();
|
|
4729
|
-
if (this.
|
|
4730
|
-
const { rows, decrypted } = await this.decryptRows(this.
|
|
4800
|
+
if (this.pageData && this.pageData.length > 0) {
|
|
4801
|
+
const { rows, decrypted } = await this.decryptRows(this.pageData);
|
|
4731
4802
|
if (decrypted) {
|
|
4732
|
-
this.
|
|
4803
|
+
this.pageData = rows;
|
|
4804
|
+
const startIndex = this.pageSize <= 0 ? 0 : (this.currentPage - 1) * this.pageSize;
|
|
4805
|
+
for (let i = 0; i < rows.length; i++) {
|
|
4806
|
+
this._rowMap[startIndex + i] = rows[i];
|
|
4807
|
+
}
|
|
4733
4808
|
}
|
|
4734
4809
|
}
|
|
4735
|
-
if (this.pageSize <= 0) {
|
|
4736
|
-
this.pageData = this._rowMap;
|
|
4737
|
-
} else {
|
|
4738
|
-
const startIndex = (this.currentPage - 1) * this.pageSize;
|
|
4739
|
-
const endIndex = startIndex + this.pageSize;
|
|
4740
|
-
this.pageData = this._rowMap.slice(startIndex, endIndex);
|
|
4741
|
-
}
|
|
4742
4810
|
} catch (err) {
|
|
4743
4811
|
this.error = err;
|
|
4744
4812
|
console.warn("[Katlux Providers] CFlatClientDataProvider loadPageData error", err);
|
|
@@ -7102,8 +7170,13 @@ class CFlatServerDataProvider extends ADataProvider {
|
|
|
7102
7170
|
const normalized = normalizeDataResult(result);
|
|
7103
7171
|
if (normalized) {
|
|
7104
7172
|
if (requestId !== this.latestRequestId) return;
|
|
7173
|
+
let rows = normalized.rows;
|
|
7174
|
+
if (this.encryption?.enabled && rows && rows.length > 0) {
|
|
7175
|
+
const { rows: decRows, decrypted } = await decryptPageRows(rows, this.encryption, void 0, this.idKey);
|
|
7176
|
+
if (decrypted) rows = decRows;
|
|
7177
|
+
}
|
|
7105
7178
|
this.batchUpdates(() => {
|
|
7106
|
-
this.pageData =
|
|
7179
|
+
this.pageData = rows;
|
|
7107
7180
|
this.rowCount = normalized.rowCount;
|
|
7108
7181
|
this.initialLoad = false;
|
|
7109
7182
|
});
|
|
@@ -7115,8 +7188,13 @@ class CFlatServerDataProvider extends ADataProvider {
|
|
|
7115
7188
|
const normalized = normalizeDataResult(result);
|
|
7116
7189
|
if (normalized) {
|
|
7117
7190
|
if (requestId !== this.latestRequestId) return;
|
|
7191
|
+
let rows = normalized.rows;
|
|
7192
|
+
if (this.encryption?.enabled && rows && rows.length > 0) {
|
|
7193
|
+
const { rows: decRows, decrypted } = await decryptPageRows(rows, this.encryption, void 0, this.idKey);
|
|
7194
|
+
if (decrypted) rows = decRows;
|
|
7195
|
+
}
|
|
7118
7196
|
this.batchUpdates(() => {
|
|
7119
|
-
this.pageData =
|
|
7197
|
+
this.pageData = rows;
|
|
7120
7198
|
this.rowCount = normalized.rowCount;
|
|
7121
7199
|
this.initialLoad = false;
|
|
7122
7200
|
});
|
|
@@ -7186,10 +7264,15 @@ class CAPIFlatServerDataProvider extends CFlatServerDataProvider {
|
|
|
7186
7264
|
this.encryption = options.encryption;
|
|
7187
7265
|
this.requestProvider.setEncryption(options.encryption);
|
|
7188
7266
|
}
|
|
7189
|
-
this.requestProvider.onDataReceived((data, generation) => {
|
|
7267
|
+
this.requestProvider.onDataReceived(async (data, generation) => {
|
|
7190
7268
|
if (generation !== void 0 && generation !== this._requestGeneration) return;
|
|
7191
7269
|
if (data) {
|
|
7192
|
-
|
|
7270
|
+
let rows = data.rows || data;
|
|
7271
|
+
if (this.encryption?.enabled && Array.isArray(rows) && rows.length > 0) {
|
|
7272
|
+
const { rows: decRows, decrypted } = await decryptPageRows(rows, this.encryption, void 0, this.idKey);
|
|
7273
|
+
if (decrypted) rows = decRows;
|
|
7274
|
+
}
|
|
7275
|
+
this.pageData = rows;
|
|
7193
7276
|
if (data.rowCount !== void 0) {
|
|
7194
7277
|
this.rowCount = data.rowCount;
|
|
7195
7278
|
}
|
|
@@ -7744,8 +7827,11 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7744
7827
|
const { rows, decrypted } = await this.decryptRows(this.pageData);
|
|
7745
7828
|
if (decrypted) {
|
|
7746
7829
|
this.pageData = rows;
|
|
7747
|
-
|
|
7748
|
-
|
|
7830
|
+
const startIndex = this.pageSize <= 0 ? 0 : (this.currentPage - 1) * this.pageSize;
|
|
7831
|
+
if (this._allVisibleRowsCache) {
|
|
7832
|
+
for (let i = 0; i < rows.length; i++) {
|
|
7833
|
+
this._allVisibleRowsCache[startIndex + i] = rows[i];
|
|
7834
|
+
}
|
|
7749
7835
|
}
|
|
7750
7836
|
}
|
|
7751
7837
|
}
|
|
@@ -7758,6 +7844,13 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7758
7844
|
}
|
|
7759
7845
|
});
|
|
7760
7846
|
}
|
|
7847
|
+
clearEncryption() {
|
|
7848
|
+
super.clearEncryption();
|
|
7849
|
+
this._filterDirty = true;
|
|
7850
|
+
this._sortDirty = true;
|
|
7851
|
+
this._filteredNodesCache = null;
|
|
7852
|
+
this._allVisibleRowsCache = null;
|
|
7853
|
+
}
|
|
7761
7854
|
// Public Tree API
|
|
7762
7855
|
get treeNodes() {
|
|
7763
7856
|
return this._staticNodes.map((node) => ({
|
|
@@ -7798,6 +7891,12 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7798
7891
|
...node,
|
|
7799
7892
|
__treeNode: node
|
|
7800
7893
|
}));
|
|
7894
|
+
if (this.isEncryptionEnabled && this.pageData && this.pageData.length > 0) {
|
|
7895
|
+
const startIndex = this.pageSize <= 0 ? 0 : (this.currentPage - 1) * this.pageSize;
|
|
7896
|
+
for (let i = 0; i < this.pageData.length; i++) {
|
|
7897
|
+
this._allVisibleRowsCache[startIndex + i] = this.pageData[i];
|
|
7898
|
+
}
|
|
7899
|
+
}
|
|
7801
7900
|
}
|
|
7802
7901
|
return this._allVisibleRowsCache;
|
|
7803
7902
|
}
|
|
@@ -8262,8 +8361,13 @@ class CTreeServerDataProvider extends ADataProvider {
|
|
|
8262
8361
|
const normalized = normalizeDataResult(result);
|
|
8263
8362
|
if (normalized) {
|
|
8264
8363
|
if (requestId !== this.latestRequestId) return;
|
|
8364
|
+
let rows = normalized.rows;
|
|
8365
|
+
if (this.encryption?.enabled && rows && rows.length > 0) {
|
|
8366
|
+
const { rows: decRows, decrypted } = await decryptPageRows(rows, this.encryption, void 0, this.idKey);
|
|
8367
|
+
if (decrypted) rows = decRows;
|
|
8368
|
+
}
|
|
8265
8369
|
this.batchUpdates(() => {
|
|
8266
|
-
this.pageData =
|
|
8370
|
+
this.pageData = rows;
|
|
8267
8371
|
this.rowCount = normalized.rowCount;
|
|
8268
8372
|
this.initialLoad = false;
|
|
8269
8373
|
});
|
|
@@ -8275,8 +8379,13 @@ class CTreeServerDataProvider extends ADataProvider {
|
|
|
8275
8379
|
const normalized = normalizeDataResult(result);
|
|
8276
8380
|
if (normalized) {
|
|
8277
8381
|
if (requestId !== this.latestRequestId) return;
|
|
8382
|
+
let rows = normalized.rows;
|
|
8383
|
+
if (this.encryption?.enabled && rows && rows.length > 0) {
|
|
8384
|
+
const { rows: decRows, decrypted } = await decryptPageRows(rows, this.encryption, void 0, this.idKey);
|
|
8385
|
+
if (decrypted) rows = decRows;
|
|
8386
|
+
}
|
|
8278
8387
|
this.batchUpdates(() => {
|
|
8279
|
-
this.pageData =
|
|
8388
|
+
this.pageData = rows;
|
|
8280
8389
|
this.rowCount = normalized.rowCount;
|
|
8281
8390
|
this.initialLoad = false;
|
|
8282
8391
|
});
|
|
@@ -8389,14 +8498,18 @@ class CAPITreeServerDataProvider extends CTreeServerDataProvider {
|
|
|
8389
8498
|
this.encryption = options.encryption;
|
|
8390
8499
|
this.requestProvider.setEncryption(options.encryption);
|
|
8391
8500
|
}
|
|
8392
|
-
this.requestProvider.onDataReceived((data, generation) => {
|
|
8501
|
+
this.requestProvider.onDataReceived(async (data, generation) => {
|
|
8393
8502
|
if (generation !== void 0 && generation !== this._requestGeneration) return;
|
|
8394
8503
|
if (data) {
|
|
8395
|
-
|
|
8504
|
+
let rows = data.rows || data;
|
|
8505
|
+
if (this.encryption?.enabled && Array.isArray(rows) && rows.length > 0) {
|
|
8506
|
+
const { rows: decRows, decrypted } = await decryptPageRows(rows, this.encryption, void 0, this.idKey);
|
|
8507
|
+
if (decrypted) rows = decRows;
|
|
8508
|
+
}
|
|
8509
|
+
this.pageData = rows;
|
|
8396
8510
|
if (data.rowCount !== void 0) {
|
|
8397
8511
|
this.rowCount = data.rowCount;
|
|
8398
8512
|
}
|
|
8399
|
-
this.notify();
|
|
8400
8513
|
}
|
|
8401
8514
|
});
|
|
8402
8515
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -633,6 +633,7 @@ declare class CFlatClientDataProvider<TRow = TDataRow> extends AEncryptedClientP
|
|
|
633
633
|
protected onSortUpdated(): void;
|
|
634
634
|
setFilter(filter: IDataFilter | null, immediate?: boolean): void;
|
|
635
635
|
setSortList(sortList: IDataSort[], immediate?: boolean): void;
|
|
636
|
+
clearEncryption(): void;
|
|
636
637
|
/**
|
|
637
638
|
* Explicitly rebuilds the reference map array if row properties inside allData were mutated in-place.
|
|
638
639
|
*/
|
|
@@ -821,6 +822,7 @@ declare class CTreeClientDataProvider<TRow extends TDataRow = TDataRow> extends
|
|
|
821
822
|
private paginateNodes;
|
|
822
823
|
private updatePageData;
|
|
823
824
|
loadPageData(): Promise<void>;
|
|
825
|
+
clearEncryption(): void;
|
|
824
826
|
get treeNodes(): ITreeNode<TRow>[];
|
|
825
827
|
get allVisibleNodes(): ITreeNode<TRow>[];
|
|
826
828
|
get rowMap(): readonly (TRow & ITreeNode<TRow> & {
|
package/dist/index.d.mts
CHANGED
|
@@ -633,6 +633,7 @@ declare class CFlatClientDataProvider<TRow = TDataRow> extends AEncryptedClientP
|
|
|
633
633
|
protected onSortUpdated(): void;
|
|
634
634
|
setFilter(filter: IDataFilter | null, immediate?: boolean): void;
|
|
635
635
|
setSortList(sortList: IDataSort[], immediate?: boolean): void;
|
|
636
|
+
clearEncryption(): void;
|
|
636
637
|
/**
|
|
637
638
|
* Explicitly rebuilds the reference map array if row properties inside allData were mutated in-place.
|
|
638
639
|
*/
|
|
@@ -821,6 +822,7 @@ declare class CTreeClientDataProvider<TRow extends TDataRow = TDataRow> extends
|
|
|
821
822
|
private paginateNodes;
|
|
822
823
|
private updatePageData;
|
|
823
824
|
loadPageData(): Promise<void>;
|
|
825
|
+
clearEncryption(): void;
|
|
824
826
|
get treeNodes(): ITreeNode<TRow>[];
|
|
825
827
|
get allVisibleNodes(): ITreeNode<TRow>[];
|
|
826
828
|
get rowMap(): readonly (TRow & ITreeNode<TRow> & {
|
package/dist/index.d.ts
CHANGED
|
@@ -633,6 +633,7 @@ declare class CFlatClientDataProvider<TRow = TDataRow> extends AEncryptedClientP
|
|
|
633
633
|
protected onSortUpdated(): void;
|
|
634
634
|
setFilter(filter: IDataFilter | null, immediate?: boolean): void;
|
|
635
635
|
setSortList(sortList: IDataSort[], immediate?: boolean): void;
|
|
636
|
+
clearEncryption(): void;
|
|
636
637
|
/**
|
|
637
638
|
* Explicitly rebuilds the reference map array if row properties inside allData were mutated in-place.
|
|
638
639
|
*/
|
|
@@ -821,6 +822,7 @@ declare class CTreeClientDataProvider<TRow extends TDataRow = TDataRow> extends
|
|
|
821
822
|
private paginateNodes;
|
|
822
823
|
private updatePageData;
|
|
823
824
|
loadPageData(): Promise<void>;
|
|
825
|
+
clearEncryption(): void;
|
|
824
826
|
get treeNodes(): ITreeNode<TRow>[];
|
|
825
827
|
get allVisibleNodes(): ITreeNode<TRow>[];
|
|
826
828
|
get rowMap(): readonly (TRow & ITreeNode<TRow> & {
|
package/dist/index.mjs
CHANGED
|
@@ -799,7 +799,31 @@ class AEncryptionProvider {
|
|
|
799
799
|
return this.encryptValue(data, options);
|
|
800
800
|
}
|
|
801
801
|
if (Array.isArray(data)) {
|
|
802
|
-
if (
|
|
802
|
+
if (data.length === 0) return data;
|
|
803
|
+
if (options?.fields && options.fields.length > 0) {
|
|
804
|
+
const fields = options.fields;
|
|
805
|
+
let hasUnencrypted = false;
|
|
806
|
+
for (let i = 0; i < data.length; i++) {
|
|
807
|
+
const item = data[i];
|
|
808
|
+
if (item && typeof item === "object") {
|
|
809
|
+
for (let f = 0; f < fields.length; f++) {
|
|
810
|
+
const val = item[fields[f]];
|
|
811
|
+
if (val !== void 0 && val !== null && !this.isEncrypted(val)) {
|
|
812
|
+
hasUnencrypted = true;
|
|
813
|
+
break;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (hasUnencrypted) break;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
if (!hasUnencrypted) {
|
|
820
|
+
return data;
|
|
821
|
+
}
|
|
822
|
+
await this.warmupKey(options);
|
|
823
|
+
const itemOptions = { ...options, _warmed: true };
|
|
824
|
+
return Promise.all(data.map((item) => this.encrypt(item, itemOptions)));
|
|
825
|
+
}
|
|
826
|
+
if (options?.valueEncryption === true) {
|
|
803
827
|
await this.warmupKey(options);
|
|
804
828
|
const itemOptions = { ...options, _warmed: true };
|
|
805
829
|
return Promise.all(data.map((item) => this.encrypt(item, itemOptions)));
|
|
@@ -812,7 +836,7 @@ class AEncryptionProvider {
|
|
|
812
836
|
(field) => Object.prototype.hasOwnProperty.call(data, field) && data[field] !== void 0 && data[field] !== null && !this.isEncrypted(data[field])
|
|
813
837
|
);
|
|
814
838
|
if (fieldsToEncrypt.length === 0) {
|
|
815
|
-
return
|
|
839
|
+
return data;
|
|
816
840
|
}
|
|
817
841
|
if (!options?._warmed) {
|
|
818
842
|
await this.warmupKey(options);
|
|
@@ -870,12 +894,13 @@ class AEncryptionProvider {
|
|
|
870
894
|
return Promise.all(payload.map((item) => this.decrypt(item, options)));
|
|
871
895
|
}
|
|
872
896
|
if (typeof payload === "object" && !ArrayBuffer.isView(payload) && !(payload instanceof ArrayBuffer)) {
|
|
873
|
-
const
|
|
874
|
-
const
|
|
875
|
-
const keysToDecrypt = targetKeys.filter((key) => this.isEncrypted(result[key]));
|
|
897
|
+
const targetKeys = options?.fields && options.fields.length > 0 ? options.fields.filter((f) => Object.prototype.hasOwnProperty.call(payload, f)) : Object.keys(payload);
|
|
898
|
+
const keysToDecrypt = targetKeys.filter((key) => this.isEncrypted(payload[key]));
|
|
876
899
|
if (keysToDecrypt.length === 0) {
|
|
877
900
|
return payload;
|
|
878
901
|
}
|
|
902
|
+
const proto = Object.getPrototypeOf(payload);
|
|
903
|
+
const result = proto && proto !== Object.prototype ? Object.assign(Object.create(proto), payload) : { ...payload };
|
|
879
904
|
const entries = await Promise.all(
|
|
880
905
|
keysToDecrypt.map(async (key) => {
|
|
881
906
|
const boundOptions = this._bindFieldAad(payload, key, options);
|
|
@@ -1741,16 +1766,15 @@ class CWebCryptoEncryptionProvider extends AEncryptionProvider {
|
|
|
1741
1766
|
};
|
|
1742
1767
|
const aad = this._resolveEffectiveAad(options, true);
|
|
1743
1768
|
let hasAad = false;
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
}
|
|
1751
|
-
} else if (payload.aad) {
|
|
1752
|
-
throw new Error("[CWebCryptoEncryptionProvider] Payload requires Authenticated Additional Data (AAD) for decryption, but none was provided.");
|
|
1769
|
+
const shouldApplyAad = payload.aad === true || payload.aad === void 0 && (options?.bindRequestContextAad === true || options?.aad !== void 0);
|
|
1770
|
+
if (shouldApplyAad && aad) {
|
|
1771
|
+
const aadBytes = typeof aad === "string" ? textEncoder$1.encode(aad) : aad instanceof Uint8Array ? aad : new Uint8Array(aad);
|
|
1772
|
+
if (aadBytes.byteLength > 0) {
|
|
1773
|
+
decryptParams.additionalData = aadBytes;
|
|
1774
|
+
hasAad = true;
|
|
1753
1775
|
}
|
|
1776
|
+
} else if (payload.aad && !aad) {
|
|
1777
|
+
throw new Error("[CWebCryptoEncryptionProvider] Payload requires Authenticated Additional Data (AAD) for decryption, but none was provided.");
|
|
1754
1778
|
}
|
|
1755
1779
|
let decryptedBuffer;
|
|
1756
1780
|
try {
|
|
@@ -3900,6 +3924,26 @@ async function encryptRows(rows, encryption, apiUrl, idKey) {
|
|
|
3900
3924
|
if (!cipherProvider) {
|
|
3901
3925
|
return rows;
|
|
3902
3926
|
}
|
|
3927
|
+
if (encryption.fields && encryption.fields.length > 0) {
|
|
3928
|
+
let allEncrypted = true;
|
|
3929
|
+
const fields = encryption.fields;
|
|
3930
|
+
for (let i = 0; i < rows.length; i++) {
|
|
3931
|
+
const item = rows[i];
|
|
3932
|
+
if (item && typeof item === "object") {
|
|
3933
|
+
for (let f = 0; f < fields.length; f++) {
|
|
3934
|
+
const val = item[fields[f]];
|
|
3935
|
+
if (val !== void 0 && val !== null && !cipherProvider.isEncrypted(val)) {
|
|
3936
|
+
allEncrypted = false;
|
|
3937
|
+
break;
|
|
3938
|
+
}
|
|
3939
|
+
}
|
|
3940
|
+
if (!allEncrypted) break;
|
|
3941
|
+
}
|
|
3942
|
+
}
|
|
3943
|
+
if (allEncrypted) {
|
|
3944
|
+
return rows;
|
|
3945
|
+
}
|
|
3946
|
+
}
|
|
3903
3947
|
const ctx = buildEncryptionContext(encryption, apiUrl);
|
|
3904
3948
|
if (typeof cipherProvider.warmupKey === "function") {
|
|
3905
3949
|
await cipherProvider.warmupKey(ctx);
|
|
@@ -3916,6 +3960,27 @@ async function encryptRowsChunked(rows, encryption, options, apiUrl, idKey, onCh
|
|
|
3916
3960
|
options?.onProgress?.({ processed: rows.length, total: rows.length, percent: 100 });
|
|
3917
3961
|
return rows;
|
|
3918
3962
|
}
|
|
3963
|
+
if (!onChunkEncrypted && encryption.fields && encryption.fields.length > 0) {
|
|
3964
|
+
let allEncrypted = true;
|
|
3965
|
+
const fields = encryption.fields;
|
|
3966
|
+
for (let i = 0; i < rows.length; i++) {
|
|
3967
|
+
const item = rows[i];
|
|
3968
|
+
if (item && typeof item === "object") {
|
|
3969
|
+
for (let f = 0; f < fields.length; f++) {
|
|
3970
|
+
const val = item[fields[f]];
|
|
3971
|
+
if (val !== void 0 && val !== null && !cipherProvider.isEncrypted(val)) {
|
|
3972
|
+
allEncrypted = false;
|
|
3973
|
+
break;
|
|
3974
|
+
}
|
|
3975
|
+
}
|
|
3976
|
+
if (!allEncrypted) break;
|
|
3977
|
+
}
|
|
3978
|
+
}
|
|
3979
|
+
if (allEncrypted) {
|
|
3980
|
+
options?.onProgress?.({ processed: rows.length, total: rows.length, percent: 100 });
|
|
3981
|
+
return rows;
|
|
3982
|
+
}
|
|
3983
|
+
}
|
|
3919
3984
|
const ctx = buildEncryptionContext(encryption, apiUrl);
|
|
3920
3985
|
if (typeof cipherProvider.warmupKey === "function") {
|
|
3921
3986
|
await cipherProvider.warmupKey(ctx);
|
|
@@ -4279,7 +4344,8 @@ class AEncryptedClientProvider extends ADataProvider {
|
|
|
4279
4344
|
if (!this.isEncryptionEnabled || !rows || rows.length === 0) {
|
|
4280
4345
|
return { rows, decrypted: false };
|
|
4281
4346
|
}
|
|
4282
|
-
|
|
4347
|
+
const url = this.apiUrl || void 0;
|
|
4348
|
+
return await decryptPageRows(rows, this.encryption, url, this.idKey);
|
|
4283
4349
|
}
|
|
4284
4350
|
async setDataChunked(data, options) {
|
|
4285
4351
|
const ret = this.setData(data);
|
|
@@ -4628,6 +4694,11 @@ class CFlatClientDataProvider extends AEncryptedClientProvider {
|
|
|
4628
4694
|
this._sortDirty = true;
|
|
4629
4695
|
super.setSortList(sortList, immediate);
|
|
4630
4696
|
}
|
|
4697
|
+
clearEncryption() {
|
|
4698
|
+
super.clearEncryption();
|
|
4699
|
+
this._filterDirty = true;
|
|
4700
|
+
this._sortDirty = true;
|
|
4701
|
+
}
|
|
4631
4702
|
/**
|
|
4632
4703
|
* Explicitly rebuilds the reference map array if row properties inside allData were mutated in-place.
|
|
4633
4704
|
*/
|
|
@@ -4658,7 +4729,7 @@ class CFlatClientDataProvider extends AEncryptedClientProvider {
|
|
|
4658
4729
|
if (this.sortList.length > 0) {
|
|
4659
4730
|
this._sortDirty = true;
|
|
4660
4731
|
} else {
|
|
4661
|
-
this._rowMap = this.filteredData;
|
|
4732
|
+
this._rowMap = this.isEncryptionEnabled ? [...this.filteredData] : this.filteredData;
|
|
4662
4733
|
this._sortDirty = false;
|
|
4663
4734
|
}
|
|
4664
4735
|
}
|
|
@@ -4666,7 +4737,7 @@ class CFlatClientDataProvider extends AEncryptedClientProvider {
|
|
|
4666
4737
|
if (this.sortList.length > 0) {
|
|
4667
4738
|
this._rowMap = sortData(this.sortList, this.filteredData);
|
|
4668
4739
|
} else {
|
|
4669
|
-
this._rowMap = this.filteredData;
|
|
4740
|
+
this._rowMap = this.isEncryptionEnabled ? [...this.filteredData] : this.filteredData;
|
|
4670
4741
|
}
|
|
4671
4742
|
this._sortDirty = false;
|
|
4672
4743
|
}
|
|
@@ -4709,19 +4780,16 @@ class CFlatClientDataProvider extends AEncryptedClientProvider {
|
|
|
4709
4780
|
this.error = null;
|
|
4710
4781
|
try {
|
|
4711
4782
|
this._computeFilteredAndSorted();
|
|
4712
|
-
if (this.
|
|
4713
|
-
const { rows, decrypted } = await this.decryptRows(this.
|
|
4783
|
+
if (this.pageData && this.pageData.length > 0) {
|
|
4784
|
+
const { rows, decrypted } = await this.decryptRows(this.pageData);
|
|
4714
4785
|
if (decrypted) {
|
|
4715
|
-
this.
|
|
4786
|
+
this.pageData = rows;
|
|
4787
|
+
const startIndex = this.pageSize <= 0 ? 0 : (this.currentPage - 1) * this.pageSize;
|
|
4788
|
+
for (let i = 0; i < rows.length; i++) {
|
|
4789
|
+
this._rowMap[startIndex + i] = rows[i];
|
|
4790
|
+
}
|
|
4716
4791
|
}
|
|
4717
4792
|
}
|
|
4718
|
-
if (this.pageSize <= 0) {
|
|
4719
|
-
this.pageData = this._rowMap;
|
|
4720
|
-
} else {
|
|
4721
|
-
const startIndex = (this.currentPage - 1) * this.pageSize;
|
|
4722
|
-
const endIndex = startIndex + this.pageSize;
|
|
4723
|
-
this.pageData = this._rowMap.slice(startIndex, endIndex);
|
|
4724
|
-
}
|
|
4725
4793
|
} catch (err) {
|
|
4726
4794
|
this.error = err;
|
|
4727
4795
|
console.warn("[Katlux Providers] CFlatClientDataProvider loadPageData error", err);
|
|
@@ -7085,8 +7153,13 @@ class CFlatServerDataProvider extends ADataProvider {
|
|
|
7085
7153
|
const normalized = normalizeDataResult(result);
|
|
7086
7154
|
if (normalized) {
|
|
7087
7155
|
if (requestId !== this.latestRequestId) return;
|
|
7156
|
+
let rows = normalized.rows;
|
|
7157
|
+
if (this.encryption?.enabled && rows && rows.length > 0) {
|
|
7158
|
+
const { rows: decRows, decrypted } = await decryptPageRows(rows, this.encryption, void 0, this.idKey);
|
|
7159
|
+
if (decrypted) rows = decRows;
|
|
7160
|
+
}
|
|
7088
7161
|
this.batchUpdates(() => {
|
|
7089
|
-
this.pageData =
|
|
7162
|
+
this.pageData = rows;
|
|
7090
7163
|
this.rowCount = normalized.rowCount;
|
|
7091
7164
|
this.initialLoad = false;
|
|
7092
7165
|
});
|
|
@@ -7098,8 +7171,13 @@ class CFlatServerDataProvider extends ADataProvider {
|
|
|
7098
7171
|
const normalized = normalizeDataResult(result);
|
|
7099
7172
|
if (normalized) {
|
|
7100
7173
|
if (requestId !== this.latestRequestId) return;
|
|
7174
|
+
let rows = normalized.rows;
|
|
7175
|
+
if (this.encryption?.enabled && rows && rows.length > 0) {
|
|
7176
|
+
const { rows: decRows, decrypted } = await decryptPageRows(rows, this.encryption, void 0, this.idKey);
|
|
7177
|
+
if (decrypted) rows = decRows;
|
|
7178
|
+
}
|
|
7101
7179
|
this.batchUpdates(() => {
|
|
7102
|
-
this.pageData =
|
|
7180
|
+
this.pageData = rows;
|
|
7103
7181
|
this.rowCount = normalized.rowCount;
|
|
7104
7182
|
this.initialLoad = false;
|
|
7105
7183
|
});
|
|
@@ -7169,10 +7247,15 @@ class CAPIFlatServerDataProvider extends CFlatServerDataProvider {
|
|
|
7169
7247
|
this.encryption = options.encryption;
|
|
7170
7248
|
this.requestProvider.setEncryption(options.encryption);
|
|
7171
7249
|
}
|
|
7172
|
-
this.requestProvider.onDataReceived((data, generation) => {
|
|
7250
|
+
this.requestProvider.onDataReceived(async (data, generation) => {
|
|
7173
7251
|
if (generation !== void 0 && generation !== this._requestGeneration) return;
|
|
7174
7252
|
if (data) {
|
|
7175
|
-
|
|
7253
|
+
let rows = data.rows || data;
|
|
7254
|
+
if (this.encryption?.enabled && Array.isArray(rows) && rows.length > 0) {
|
|
7255
|
+
const { rows: decRows, decrypted } = await decryptPageRows(rows, this.encryption, void 0, this.idKey);
|
|
7256
|
+
if (decrypted) rows = decRows;
|
|
7257
|
+
}
|
|
7258
|
+
this.pageData = rows;
|
|
7176
7259
|
if (data.rowCount !== void 0) {
|
|
7177
7260
|
this.rowCount = data.rowCount;
|
|
7178
7261
|
}
|
|
@@ -7727,8 +7810,11 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7727
7810
|
const { rows, decrypted } = await this.decryptRows(this.pageData);
|
|
7728
7811
|
if (decrypted) {
|
|
7729
7812
|
this.pageData = rows;
|
|
7730
|
-
|
|
7731
|
-
|
|
7813
|
+
const startIndex = this.pageSize <= 0 ? 0 : (this.currentPage - 1) * this.pageSize;
|
|
7814
|
+
if (this._allVisibleRowsCache) {
|
|
7815
|
+
for (let i = 0; i < rows.length; i++) {
|
|
7816
|
+
this._allVisibleRowsCache[startIndex + i] = rows[i];
|
|
7817
|
+
}
|
|
7732
7818
|
}
|
|
7733
7819
|
}
|
|
7734
7820
|
}
|
|
@@ -7741,6 +7827,13 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7741
7827
|
}
|
|
7742
7828
|
});
|
|
7743
7829
|
}
|
|
7830
|
+
clearEncryption() {
|
|
7831
|
+
super.clearEncryption();
|
|
7832
|
+
this._filterDirty = true;
|
|
7833
|
+
this._sortDirty = true;
|
|
7834
|
+
this._filteredNodesCache = null;
|
|
7835
|
+
this._allVisibleRowsCache = null;
|
|
7836
|
+
}
|
|
7744
7837
|
// Public Tree API
|
|
7745
7838
|
get treeNodes() {
|
|
7746
7839
|
return this._staticNodes.map((node) => ({
|
|
@@ -7781,6 +7874,12 @@ class CTreeClientDataProvider extends CFlatClientDataProvider {
|
|
|
7781
7874
|
...node,
|
|
7782
7875
|
__treeNode: node
|
|
7783
7876
|
}));
|
|
7877
|
+
if (this.isEncryptionEnabled && this.pageData && this.pageData.length > 0) {
|
|
7878
|
+
const startIndex = this.pageSize <= 0 ? 0 : (this.currentPage - 1) * this.pageSize;
|
|
7879
|
+
for (let i = 0; i < this.pageData.length; i++) {
|
|
7880
|
+
this._allVisibleRowsCache[startIndex + i] = this.pageData[i];
|
|
7881
|
+
}
|
|
7882
|
+
}
|
|
7784
7883
|
}
|
|
7785
7884
|
return this._allVisibleRowsCache;
|
|
7786
7885
|
}
|
|
@@ -8245,8 +8344,13 @@ class CTreeServerDataProvider extends ADataProvider {
|
|
|
8245
8344
|
const normalized = normalizeDataResult(result);
|
|
8246
8345
|
if (normalized) {
|
|
8247
8346
|
if (requestId !== this.latestRequestId) return;
|
|
8347
|
+
let rows = normalized.rows;
|
|
8348
|
+
if (this.encryption?.enabled && rows && rows.length > 0) {
|
|
8349
|
+
const { rows: decRows, decrypted } = await decryptPageRows(rows, this.encryption, void 0, this.idKey);
|
|
8350
|
+
if (decrypted) rows = decRows;
|
|
8351
|
+
}
|
|
8248
8352
|
this.batchUpdates(() => {
|
|
8249
|
-
this.pageData =
|
|
8353
|
+
this.pageData = rows;
|
|
8250
8354
|
this.rowCount = normalized.rowCount;
|
|
8251
8355
|
this.initialLoad = false;
|
|
8252
8356
|
});
|
|
@@ -8258,8 +8362,13 @@ class CTreeServerDataProvider extends ADataProvider {
|
|
|
8258
8362
|
const normalized = normalizeDataResult(result);
|
|
8259
8363
|
if (normalized) {
|
|
8260
8364
|
if (requestId !== this.latestRequestId) return;
|
|
8365
|
+
let rows = normalized.rows;
|
|
8366
|
+
if (this.encryption?.enabled && rows && rows.length > 0) {
|
|
8367
|
+
const { rows: decRows, decrypted } = await decryptPageRows(rows, this.encryption, void 0, this.idKey);
|
|
8368
|
+
if (decrypted) rows = decRows;
|
|
8369
|
+
}
|
|
8261
8370
|
this.batchUpdates(() => {
|
|
8262
|
-
this.pageData =
|
|
8371
|
+
this.pageData = rows;
|
|
8263
8372
|
this.rowCount = normalized.rowCount;
|
|
8264
8373
|
this.initialLoad = false;
|
|
8265
8374
|
});
|
|
@@ -8372,14 +8481,18 @@ class CAPITreeServerDataProvider extends CTreeServerDataProvider {
|
|
|
8372
8481
|
this.encryption = options.encryption;
|
|
8373
8482
|
this.requestProvider.setEncryption(options.encryption);
|
|
8374
8483
|
}
|
|
8375
|
-
this.requestProvider.onDataReceived((data, generation) => {
|
|
8484
|
+
this.requestProvider.onDataReceived(async (data, generation) => {
|
|
8376
8485
|
if (generation !== void 0 && generation !== this._requestGeneration) return;
|
|
8377
8486
|
if (data) {
|
|
8378
|
-
|
|
8487
|
+
let rows = data.rows || data;
|
|
8488
|
+
if (this.encryption?.enabled && Array.isArray(rows) && rows.length > 0) {
|
|
8489
|
+
const { rows: decRows, decrypted } = await decryptPageRows(rows, this.encryption, void 0, this.idKey);
|
|
8490
|
+
if (decrypted) rows = decRows;
|
|
8491
|
+
}
|
|
8492
|
+
this.pageData = rows;
|
|
8379
8493
|
if (data.rowCount !== void 0) {
|
|
8380
8494
|
this.rowCount = data.rowCount;
|
|
8381
8495
|
}
|
|
8382
|
-
this.notify();
|
|
8383
8496
|
}
|
|
8384
8497
|
});
|
|
8385
8498
|
}
|