@qmuse/appwrite-runtime-sdk 1.0.1 → 1.0.2
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/runtime.js +92 -33
- package/package.json +1 -1
package/dist/runtime.js
CHANGED
|
@@ -6,6 +6,12 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
|
6
6
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
7
7
|
import { ID, Permission, Query, Role } from 'appwrite';
|
|
8
8
|
var BLOCKED_MUTATION_FIELDS = new Set(['code', 'creatorId', 'modifierId', 'gmtCreate', 'gmtModified']);
|
|
9
|
+
var SENSITIVE_AUDIT_FIELD_PATTERN = /(?:password|passwd|secret|token|authorization|cookie|api[-_]?key|access[-_]?key|private[-_]?key)/i;
|
|
10
|
+
var REDACTED_AUDIT_VALUE = '[REDACTED]';
|
|
11
|
+
var MAX_AUDIT_DEPTH = 5;
|
|
12
|
+
var MAX_AUDIT_KEYS = 100;
|
|
13
|
+
var MAX_AUDIT_ARRAY_ITEMS = 100;
|
|
14
|
+
var MAX_AUDIT_STRING_LENGTH = 2048;
|
|
9
15
|
function isRecord(value) {
|
|
10
16
|
return Boolean(value) && _typeof(value) === 'object' && !Array.isArray(value);
|
|
11
17
|
}
|
|
@@ -60,6 +66,50 @@ function sanitizeBusinessRowData(data) {
|
|
|
60
66
|
return !key.startsWith('$') && !BLOCKED_MUTATION_FIELDS.has(key);
|
|
61
67
|
}));
|
|
62
68
|
}
|
|
69
|
+
function sanitizeAuditValue(value, depth, ancestors) {
|
|
70
|
+
if (typeof value === 'string') {
|
|
71
|
+
return value.length > MAX_AUDIT_STRING_LENGTH ? "".concat(value.slice(0, MAX_AUDIT_STRING_LENGTH), "[TRUNCATED]") : value;
|
|
72
|
+
}
|
|
73
|
+
if (depth >= MAX_AUDIT_DEPTH && (Array.isArray(value) || isRecord(value))) {
|
|
74
|
+
return '[MAX_DEPTH]';
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(value)) {
|
|
77
|
+
if (ancestors.has(value)) {
|
|
78
|
+
return '[CIRCULAR]';
|
|
79
|
+
}
|
|
80
|
+
ancestors.add(value);
|
|
81
|
+
var _result = value.slice(0, MAX_AUDIT_ARRAY_ITEMS).map(function (item) {
|
|
82
|
+
return sanitizeAuditValue(item, depth + 1, ancestors);
|
|
83
|
+
});
|
|
84
|
+
ancestors.delete(value);
|
|
85
|
+
if (value.length > MAX_AUDIT_ARRAY_ITEMS) {
|
|
86
|
+
_result.push('[TRUNCATED]');
|
|
87
|
+
}
|
|
88
|
+
return _result;
|
|
89
|
+
}
|
|
90
|
+
if (!isRecord(value)) {
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
if (ancestors.has(value)) {
|
|
94
|
+
return '[CIRCULAR]';
|
|
95
|
+
}
|
|
96
|
+
ancestors.add(value);
|
|
97
|
+
var entries = Object.entries(value).slice(0, MAX_AUDIT_KEYS);
|
|
98
|
+
var result = Object.fromEntries(entries.map(function (_ref4) {
|
|
99
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
100
|
+
key = _ref5[0],
|
|
101
|
+
childValue = _ref5[1];
|
|
102
|
+
return [key, SENSITIVE_AUDIT_FIELD_PATTERN.test(key) ? REDACTED_AUDIT_VALUE : sanitizeAuditValue(childValue, depth + 1, ancestors)];
|
|
103
|
+
}));
|
|
104
|
+
ancestors.delete(value);
|
|
105
|
+
if (Object.keys(value).length > MAX_AUDIT_KEYS) {
|
|
106
|
+
result.__auditTruncated = true;
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
function sanitizeMutationAuditData(data) {
|
|
111
|
+
return sanitizeAuditValue(data, 0, new WeakSet());
|
|
112
|
+
}
|
|
63
113
|
export function createQmuseAppwriteRuntime(options) {
|
|
64
114
|
var _options$fetch;
|
|
65
115
|
var client = options.client,
|
|
@@ -373,12 +423,12 @@ export function createQmuseAppwriteRuntime(options) {
|
|
|
373
423
|
return _ensureAuthenticatedSession.apply(this, arguments);
|
|
374
424
|
}
|
|
375
425
|
function _ensureAuthenticatedSession() {
|
|
376
|
-
_ensureAuthenticatedSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(
|
|
377
|
-
var qmuseUserId, userId, secret,
|
|
426
|
+
_ensureAuthenticatedSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref6) {
|
|
427
|
+
var qmuseUserId, userId, secret, _ref6$forceReplace, forceReplace;
|
|
378
428
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
379
429
|
while (1) switch (_context7.prev = _context7.next) {
|
|
380
430
|
case 0:
|
|
381
|
-
qmuseUserId =
|
|
431
|
+
qmuseUserId = _ref6.qmuseUserId, userId = _ref6.userId, secret = _ref6.secret, _ref6$forceReplace = _ref6.forceReplace, forceReplace = _ref6$forceReplace === void 0 ? false : _ref6$forceReplace;
|
|
382
432
|
if (state.currentUser) {
|
|
383
433
|
_context7.next = 4;
|
|
384
434
|
break;
|
|
@@ -657,13 +707,14 @@ export function createQmuseAppwriteRuntime(options) {
|
|
|
657
707
|
}));
|
|
658
708
|
return _withSessionRetry.apply(this, arguments);
|
|
659
709
|
}
|
|
660
|
-
function scheduleMutationAudit(
|
|
661
|
-
var operation =
|
|
662
|
-
tableId =
|
|
663
|
-
rowId =
|
|
664
|
-
outcome =
|
|
665
|
-
durationMs =
|
|
666
|
-
errorCode =
|
|
710
|
+
function scheduleMutationAudit(_ref7) {
|
|
711
|
+
var operation = _ref7.operation,
|
|
712
|
+
tableId = _ref7.tableId,
|
|
713
|
+
rowId = _ref7.rowId,
|
|
714
|
+
outcome = _ref7.outcome,
|
|
715
|
+
durationMs = _ref7.durationMs,
|
|
716
|
+
errorCode = _ref7.errorCode,
|
|
717
|
+
mutationData = _ref7.mutationData;
|
|
667
718
|
var runtime = getMuseRuntime();
|
|
668
719
|
globalThis.setTimeout(function () {
|
|
669
720
|
try {
|
|
@@ -674,7 +725,7 @@ export function createQmuseAppwriteRuntime(options) {
|
|
|
674
725
|
headers: {
|
|
675
726
|
'Content-Type': 'application/json'
|
|
676
727
|
},
|
|
677
|
-
body: JSON.stringify(_objectSpread({
|
|
728
|
+
body: JSON.stringify(_objectSpread(_objectSpread({
|
|
678
729
|
schemaVersion: 1,
|
|
679
730
|
operation: operation,
|
|
680
731
|
outcome: outcome,
|
|
@@ -685,6 +736,8 @@ export function createQmuseAppwriteRuntime(options) {
|
|
|
685
736
|
durationMs: durationMs
|
|
686
737
|
}, errorCode === undefined ? {} : {
|
|
687
738
|
errorCode: errorCode
|
|
739
|
+
}), mutationData === undefined ? {} : {
|
|
740
|
+
mutationData: mutationData
|
|
688
741
|
}))
|
|
689
742
|
})).catch(function () {
|
|
690
743
|
return undefined;
|
|
@@ -698,12 +751,12 @@ export function createQmuseAppwriteRuntime(options) {
|
|
|
698
751
|
return _observeMutation.apply(this, arguments);
|
|
699
752
|
}
|
|
700
753
|
function _observeMutation() {
|
|
701
|
-
_observeMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(
|
|
702
|
-
var operation, tableId, rowId, task, startedAt, result, _getErrorCode;
|
|
754
|
+
_observeMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(_ref8) {
|
|
755
|
+
var operation, tableId, rowId, mutationData, task, startedAt, result, _getErrorCode;
|
|
703
756
|
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
704
757
|
while (1) switch (_context15.prev = _context15.next) {
|
|
705
758
|
case 0:
|
|
706
|
-
operation =
|
|
759
|
+
operation = _ref8.operation, tableId = _ref8.tableId, rowId = _ref8.rowId, mutationData = _ref8.mutationData, task = _ref8.task;
|
|
707
760
|
startedAt = Date.now();
|
|
708
761
|
_context15.prev = 2;
|
|
709
762
|
_context15.next = 5;
|
|
@@ -715,7 +768,8 @@ export function createQmuseAppwriteRuntime(options) {
|
|
|
715
768
|
tableId: tableId,
|
|
716
769
|
rowId: rowId,
|
|
717
770
|
outcome: 'success',
|
|
718
|
-
durationMs: Date.now() - startedAt
|
|
771
|
+
durationMs: Date.now() - startedAt,
|
|
772
|
+
mutationData: mutationData
|
|
719
773
|
});
|
|
720
774
|
return _context15.abrupt("return", result);
|
|
721
775
|
case 10:
|
|
@@ -727,7 +781,8 @@ export function createQmuseAppwriteRuntime(options) {
|
|
|
727
781
|
rowId: rowId,
|
|
728
782
|
outcome: 'failure',
|
|
729
783
|
durationMs: Date.now() - startedAt,
|
|
730
|
-
errorCode: (_getErrorCode = getErrorCode(_context15.t0)) !== null && _getErrorCode !== void 0 ? _getErrorCode : undefined
|
|
784
|
+
errorCode: (_getErrorCode = getErrorCode(_context15.t0)) !== null && _getErrorCode !== void 0 ? _getErrorCode : undefined,
|
|
785
|
+
mutationData: mutationData
|
|
731
786
|
});
|
|
732
787
|
throw _context15.t0;
|
|
733
788
|
case 14:
|
|
@@ -742,12 +797,12 @@ export function createQmuseAppwriteRuntime(options) {
|
|
|
742
797
|
return _listRows.apply(this, arguments);
|
|
743
798
|
}
|
|
744
799
|
function _listRows() {
|
|
745
|
-
_listRows = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(
|
|
746
|
-
var tableId,
|
|
800
|
+
_listRows = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(_ref9) {
|
|
801
|
+
var tableId, _ref9$queries, queries, _ref9$limit, limit, cursor, _yield$getClients, databaseId;
|
|
747
802
|
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
748
803
|
while (1) switch (_context16.prev = _context16.next) {
|
|
749
804
|
case 0:
|
|
750
|
-
tableId =
|
|
805
|
+
tableId = _ref9.tableId, _ref9$queries = _ref9.queries, queries = _ref9$queries === void 0 ? [] : _ref9$queries, _ref9$limit = _ref9.limit, limit = _ref9$limit === void 0 ? 20 : _ref9$limit, cursor = _ref9.cursor;
|
|
751
806
|
if (!(!Number.isInteger(limit) || limit < 1 || limit > 20)) {
|
|
752
807
|
_context16.next = 3;
|
|
753
808
|
break;
|
|
@@ -778,12 +833,12 @@ export function createQmuseAppwriteRuntime(options) {
|
|
|
778
833
|
return _getRow.apply(this, arguments);
|
|
779
834
|
}
|
|
780
835
|
function _getRow() {
|
|
781
|
-
_getRow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(
|
|
836
|
+
_getRow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(_ref10) {
|
|
782
837
|
var tableId, rowId, _yield$getClients2, databaseId;
|
|
783
838
|
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
784
839
|
while (1) switch (_context17.prev = _context17.next) {
|
|
785
840
|
case 0:
|
|
786
|
-
tableId =
|
|
841
|
+
tableId = _ref10.tableId, rowId = _ref10.rowId;
|
|
787
842
|
_context17.next = 3;
|
|
788
843
|
return getClients();
|
|
789
844
|
case 3:
|
|
@@ -808,21 +863,23 @@ export function createQmuseAppwriteRuntime(options) {
|
|
|
808
863
|
return _createRow.apply(this, arguments);
|
|
809
864
|
}
|
|
810
865
|
function _createRow() {
|
|
811
|
-
_createRow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(
|
|
812
|
-
var tableId, data,
|
|
866
|
+
_createRow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(_ref11) {
|
|
867
|
+
var tableId, data, _ref11$rowId, rowId, _yield$getClients3, databaseId, mutationData;
|
|
813
868
|
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
814
869
|
while (1) switch (_context18.prev = _context18.next) {
|
|
815
870
|
case 0:
|
|
816
|
-
tableId =
|
|
871
|
+
tableId = _ref11.tableId, data = _ref11.data, _ref11$rowId = _ref11.rowId, rowId = _ref11$rowId === void 0 ? ID.unique() : _ref11$rowId;
|
|
817
872
|
_context18.next = 3;
|
|
818
873
|
return getClients();
|
|
819
874
|
case 3:
|
|
820
875
|
_yield$getClients3 = _context18.sent;
|
|
821
876
|
databaseId = _yield$getClients3.databaseId;
|
|
877
|
+
mutationData = sanitizeBusinessRowData(data);
|
|
822
878
|
return _context18.abrupt("return", observeMutation({
|
|
823
879
|
operation: 'create',
|
|
824
880
|
tableId: tableId,
|
|
825
881
|
rowId: rowId,
|
|
882
|
+
mutationData: sanitizeMutationAuditData(mutationData),
|
|
826
883
|
task: function task() {
|
|
827
884
|
return withSessionRetry(function () {
|
|
828
885
|
var currentUserId = getCurrentUser().$id;
|
|
@@ -831,7 +888,7 @@ export function createQmuseAppwriteRuntime(options) {
|
|
|
831
888
|
databaseId: databaseId,
|
|
832
889
|
tableId: tableId,
|
|
833
890
|
rowId: rowId,
|
|
834
|
-
data: _objectSpread(_objectSpread({},
|
|
891
|
+
data: _objectSpread(_objectSpread({}, mutationData), {}, {
|
|
835
892
|
creatorId: currentUserId,
|
|
836
893
|
modifierId: currentUserId
|
|
837
894
|
}),
|
|
@@ -840,7 +897,7 @@ export function createQmuseAppwriteRuntime(options) {
|
|
|
840
897
|
});
|
|
841
898
|
}
|
|
842
899
|
}));
|
|
843
|
-
case
|
|
900
|
+
case 7:
|
|
844
901
|
case "end":
|
|
845
902
|
return _context18.stop();
|
|
846
903
|
}
|
|
@@ -852,35 +909,37 @@ export function createQmuseAppwriteRuntime(options) {
|
|
|
852
909
|
return _updateRow.apply(this, arguments);
|
|
853
910
|
}
|
|
854
911
|
function _updateRow() {
|
|
855
|
-
_updateRow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(
|
|
856
|
-
var tableId, rowId, data, _yield$getClients4, databaseId;
|
|
912
|
+
_updateRow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(_ref12) {
|
|
913
|
+
var tableId, rowId, data, _yield$getClients4, databaseId, mutationData;
|
|
857
914
|
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
858
915
|
while (1) switch (_context19.prev = _context19.next) {
|
|
859
916
|
case 0:
|
|
860
|
-
tableId =
|
|
917
|
+
tableId = _ref12.tableId, rowId = _ref12.rowId, data = _ref12.data;
|
|
861
918
|
_context19.next = 3;
|
|
862
919
|
return getClients();
|
|
863
920
|
case 3:
|
|
864
921
|
_yield$getClients4 = _context19.sent;
|
|
865
922
|
databaseId = _yield$getClients4.databaseId;
|
|
923
|
+
mutationData = sanitizeBusinessRowData(data);
|
|
866
924
|
return _context19.abrupt("return", observeMutation({
|
|
867
925
|
operation: 'update',
|
|
868
926
|
tableId: tableId,
|
|
869
927
|
rowId: rowId,
|
|
928
|
+
mutationData: sanitizeMutationAuditData(mutationData),
|
|
870
929
|
task: function task() {
|
|
871
930
|
return withSessionRetry(function () {
|
|
872
931
|
return tablesDB.updateRow({
|
|
873
932
|
databaseId: databaseId,
|
|
874
933
|
tableId: tableId,
|
|
875
934
|
rowId: rowId,
|
|
876
|
-
data: _objectSpread(_objectSpread({},
|
|
935
|
+
data: _objectSpread(_objectSpread({}, mutationData), {}, {
|
|
877
936
|
modifierId: getCurrentUser().$id
|
|
878
937
|
})
|
|
879
938
|
});
|
|
880
939
|
});
|
|
881
940
|
}
|
|
882
941
|
}));
|
|
883
|
-
case
|
|
942
|
+
case 7:
|
|
884
943
|
case "end":
|
|
885
944
|
return _context19.stop();
|
|
886
945
|
}
|
|
@@ -892,12 +951,12 @@ export function createQmuseAppwriteRuntime(options) {
|
|
|
892
951
|
return _deleteRow.apply(this, arguments);
|
|
893
952
|
}
|
|
894
953
|
function _deleteRow() {
|
|
895
|
-
_deleteRow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(
|
|
954
|
+
_deleteRow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(_ref13) {
|
|
896
955
|
var tableId, rowId, _yield$getClients5, databaseId;
|
|
897
956
|
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
898
957
|
while (1) switch (_context20.prev = _context20.next) {
|
|
899
958
|
case 0:
|
|
900
|
-
tableId =
|
|
959
|
+
tableId = _ref13.tableId, rowId = _ref13.rowId;
|
|
901
960
|
_context20.next = 3;
|
|
902
961
|
return getClients();
|
|
903
962
|
case 3:
|