@casual-simulation/aux-records 3.2.13 → 3.2.14-alpha.7890390188

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.
Files changed (46) hide show
  1. package/AIController.d.ts +7 -4
  2. package/AIController.js +11 -0
  3. package/AIController.js.map +1 -1
  4. package/AuthController.d.ts +2 -1
  5. package/AuthController.js +6 -3
  6. package/AuthController.js.map +1 -1
  7. package/AuthStore.d.ts +1 -21
  8. package/CachingPolicyStore.d.ts +16 -5
  9. package/CachingPolicyStore.js +66 -39
  10. package/CachingPolicyStore.js.map +1 -1
  11. package/DataRecordsController.d.ts +67 -5
  12. package/DataRecordsController.js +141 -78
  13. package/DataRecordsController.js.map +1 -1
  14. package/DataRecordsStore.d.ts +35 -1
  15. package/DataRecordsStore.js.map +1 -1
  16. package/EventRecordsController.d.ts +5 -5
  17. package/EventRecordsController.js +54 -35
  18. package/EventRecordsController.js.map +1 -1
  19. package/FileRecordsController.d.ts +6 -6
  20. package/FileRecordsController.js +142 -76
  21. package/FileRecordsController.js.map +1 -1
  22. package/MemoryStore.d.ts +28 -17
  23. package/MemoryStore.js +457 -110
  24. package/MemoryStore.js.map +1 -1
  25. package/PolicyController.d.ts +512 -677
  26. package/PolicyController.js +1196 -2934
  27. package/PolicyController.js.map +1 -1
  28. package/PolicyStore.d.ts +319 -90
  29. package/PolicyStore.js +125 -0
  30. package/PolicyStore.js.map +1 -1
  31. package/RecordsServer.d.ts +3 -4
  32. package/RecordsServer.js +88 -111
  33. package/RecordsServer.js.map +1 -1
  34. package/RecordsStore.d.ts +3 -0
  35. package/TestUtils.d.ts +1 -1
  36. package/TestUtils.js.map +1 -1
  37. package/Utils.d.ts +21 -3
  38. package/Utils.js +42 -3
  39. package/Utils.js.map +1 -1
  40. package/package.json +3 -3
  41. package/websockets/InstRecordsStore.d.ts +21 -0
  42. package/websockets/InstRecordsStore.js +43 -1
  43. package/websockets/InstRecordsStore.js.map +1 -1
  44. package/websockets/WebsocketController.d.ts +7 -7
  45. package/websockets/WebsocketController.js +153 -82
  46. package/websockets/WebsocketController.js.map +1 -1
package/RecordsServer.js CHANGED
@@ -22,7 +22,7 @@ import { getStatusCode, parseInstancesList, tryDecodeUriComponent, tryParseJson,
22
22
  import { INVALID_REQUEST_ERROR_MESSAGE, MAX_EMAIL_ADDRESS_LENGTH, MAX_SMS_ADDRESS_LENGTH, PRIVO_OPEN_ID_PROVIDER, } from './AuthController';
23
23
  import { parseSessionKey } from './AuthUtils';
24
24
  import { z } from 'zod';
25
- import { AVAILABLE_PERMISSIONS_VALIDATION } from '@casual-simulation/aux-common';
25
+ import { AVAILABLE_PERMISSIONS_VALIDATION, RESOURCE_KIND_VALIDATION, } from '@casual-simulation/aux-common';
26
26
  import { AI_CHAT_MESSAGE_SCHEMA } from './AIChatInterface';
27
27
  import { WebsocketEventTypes, websocketEventSchema, websocketRequestMessageSchema, } from '@casual-simulation/aux-common/websockets/WebsocketEvents';
28
28
  import { DEFAULT_BRANCH_NAME } from '@casual-simulation/aux-common';
@@ -127,22 +127,23 @@ const STUDIO_DISPLAY_NAME_VALIDATION = z
127
127
  })
128
128
  .min(1)
129
129
  .max(128);
130
- /**
131
- * The Zod validation for markers.
132
- */
133
- const MARKERS_VALIDATION = z
134
- .array(z
130
+ const MARKER_VALIDATION = z
135
131
  .string({
136
132
  invalid_type_error: 'individual markers must be strings.',
137
133
  required_error: 'invidiaul markers must not be null or empty.',
138
134
  })
139
- .min(1)
140
- .max(128), {
135
+ .nonempty('individual markers must not be null or empty.')
136
+ .max(100, 'individual markers must not be longer than 100 characters.');
137
+ /**
138
+ * The Zod validation for markers.
139
+ */
140
+ const MARKERS_VALIDATION = z
141
+ .array(MARKER_VALIDATION, {
141
142
  invalid_type_error: 'markers must be an array of strings.',
142
143
  required_error: 'markers is required.',
143
144
  })
144
145
  .nonempty('markers must not be empty.')
145
- .max(10, 'markers must not contain more than 10 markers.');
146
+ .max(10, 'markers lists must not contain more than 10 markers.');
146
147
  const NO_WHITESPACE_MESSAGE = 'The value cannot not contain spaces.';
147
148
  const NO_WHITESPACE_REGEX = /^\S*$/g;
148
149
  const NO_SPECIAL_CHARACTERS_MESSAGE = 'The value cannot not contain special characters.';
@@ -385,20 +386,16 @@ export class RecordsServer {
385
386
  return formatResponse(request, yield this._createRecordKey(request), this._allowedApiOrigins);
386
387
  }
387
388
  else if (request.method === 'POST' &&
388
- request.path === '/api/v2/records/policy/grantPermission') {
389
- return formatResponse(request, yield this._policyGrantPermission(request), this._allowedApiOrigins);
389
+ request.path === '/api/v2/records/permissions') {
390
+ return formatResponse(request, yield this._grantPermission(request), this._allowedApiOrigins);
390
391
  }
391
392
  else if (request.method === 'POST' &&
392
- request.path === '/api/v2/records/policy/revokePermission') {
393
- return formatResponse(request, yield this._policyRevokePermission(request), this._allowedApiOrigins);
393
+ request.path === '/api/v2/records/permissions/revoke') {
394
+ return formatResponse(request, yield this._revokePermission(request), this._allowedApiOrigins);
394
395
  }
395
396
  else if (request.method === 'GET' &&
396
- request.path === '/api/v2/records/policy') {
397
- return formatResponse(request, yield this._policyRead(request), this._allowedApiOrigins);
398
- }
399
- else if (request.method === 'GET' &&
400
- request.path === '/api/v2/records/policy/list') {
401
- return formatResponse(request, yield this._policyList(request), this._allowedApiOrigins);
397
+ request.path === '/api/v2/records/permissions/list') {
398
+ return formatResponse(request, yield this._listPermissions(request), this._allowedApiOrigins);
402
399
  }
403
400
  else if (request.method === 'GET' &&
404
401
  request.path === '/api/v2/records/role/user/list') {
@@ -893,7 +890,7 @@ export class RecordsServer {
893
890
  return returnResult(result);
894
891
  });
895
892
  }
896
- _policyGrantPermission(request) {
893
+ _grantPermission(request) {
897
894
  return __awaiter(this, void 0, void 0, function* () {
898
895
  if (!validateOrigin(request, this._allowedApiOrigins)) {
899
896
  return returnResult(INVALID_ORIGIN_RESULT);
@@ -907,12 +904,6 @@ export class RecordsServer {
907
904
  }
908
905
  const schema = z.object({
909
906
  recordName: RECORD_NAME_VALIDATION,
910
- marker: z
911
- .string({
912
- invalid_type_error: 'marker must be a string.',
913
- required_error: 'marker is required.',
914
- })
915
- .nonempty('marker must not be empty'),
916
907
  permission: AVAILABLE_PERMISSIONS_VALIDATION,
917
908
  instances: INSTANCES_ARRAY_VALIDATION.nonempty().optional(),
918
909
  });
@@ -920,20 +911,7 @@ export class RecordsServer {
920
911
  if (parseResult.success === false) {
921
912
  return returnZodError(parseResult.error);
922
913
  }
923
- const { recordName, marker, permission, instances } = parseResult.data;
924
- // const validation = ZOD_PERMISSION_MAP[permission.type as (keyof typeof ZOD_PERMISSION_MAP)];
925
- // if (!validation) {
926
- // const validPermissionTypes = Object.keys(ZOD_PERMISSION_MAP).sort();
927
- // return returnResult({
928
- // success: false,
929
- // errorCode: 'unacceptable_request',
930
- // errorMessage: `Permission type not found. type must be one of: ${validPermissionTypes.join(', ')}`,
931
- // });
932
- // }
933
- // const validationParseResult = validation.safeParse(permission);
934
- // if (validationParseResult.success === false) {
935
- // return returnZodError(validationParseResult.error);
936
- // }
914
+ const { recordName, permission, instances } = parseResult.data;
937
915
  const sessionKeyValidation = yield this._validateSessionKey(request);
938
916
  if (sessionKeyValidation.success === false) {
939
917
  if (sessionKeyValidation.errorCode === 'no_session_key') {
@@ -941,17 +919,33 @@ export class RecordsServer {
941
919
  }
942
920
  return returnResult(sessionKeyValidation);
943
921
  }
944
- const result = yield this._policyController.grantMarkerPermission({
945
- recordKeyOrRecordName: recordName,
946
- marker: marker,
947
- userId: sessionKeyValidation.userId,
948
- permission: permission,
949
- instances,
922
+ if (permission.marker) {
923
+ const result = yield this._policyController.grantMarkerPermission({
924
+ recordKeyOrRecordName: recordName,
925
+ marker: permission.marker,
926
+ userId: sessionKeyValidation.userId,
927
+ permission: permission,
928
+ instances,
929
+ });
930
+ return returnResult(result);
931
+ }
932
+ else if (permission.resourceKind && permission.resourceId) {
933
+ const result = yield this._policyController.grantResourcePermission({
934
+ recordKeyOrRecordName: recordName,
935
+ permission: permission,
936
+ userId: sessionKeyValidation.userId,
937
+ instances,
938
+ });
939
+ return returnResult(result);
940
+ }
941
+ return returnResult({
942
+ success: false,
943
+ errorCode: 'unacceptable_request',
944
+ errorMessage: 'The given permission must have either a marker or a resourceId.',
950
945
  });
951
- return returnResult(result);
952
946
  });
953
947
  }
954
- _policyRevokePermission(request) {
948
+ _revokePermission(request) {
955
949
  return __awaiter(this, void 0, void 0, function* () {
956
950
  if (!validateOrigin(request, this._allowedApiOrigins)) {
957
951
  return returnResult(INVALID_ORIGIN_RESULT);
@@ -964,21 +958,19 @@ export class RecordsServer {
964
958
  return returnResult(UNACCEPTABLE_REQUEST_RESULT_MUST_BE_JSON);
965
959
  }
966
960
  const schema = z.object({
967
- recordName: RECORD_NAME_VALIDATION,
968
- marker: z
961
+ permissionId: z
969
962
  .string({
970
- invalid_type_error: 'marker must be a string.',
971
- required_error: 'marker is required.',
963
+ invalid_type_error: 'permissionId must be a string.',
964
+ required_error: 'permissionId is required.',
972
965
  })
973
- .nonempty('marker must not be empty'),
974
- permission: AVAILABLE_PERMISSIONS_VALIDATION,
966
+ .nonempty('permissionId must not be empty'),
975
967
  instances: INSTANCES_ARRAY_VALIDATION.optional(),
976
968
  });
977
969
  const parseResult = schema.safeParse(jsonResult.value);
978
970
  if (parseResult.success === false) {
979
971
  return returnZodError(parseResult.error);
980
972
  }
981
- const { recordName, marker, permission, instances } = parseResult.data;
973
+ const { permissionId, instances } = parseResult.data;
982
974
  const sessionKeyValidation = yield this._validateSessionKey(request);
983
975
  if (sessionKeyValidation.success === false) {
984
976
  if (sessionKeyValidation.errorCode === 'no_session_key') {
@@ -986,35 +978,35 @@ export class RecordsServer {
986
978
  }
987
979
  return returnResult(sessionKeyValidation);
988
980
  }
989
- const result = yield this._policyController.revokeMarkerPermission({
990
- recordKeyOrRecordName: recordName,
991
- marker: marker,
981
+ const result = yield this._policyController.revokePermission({
982
+ permissionId,
992
983
  userId: sessionKeyValidation.userId,
993
- permission: permission,
994
984
  instances,
995
985
  });
996
986
  return returnResult(result);
997
987
  });
998
988
  }
999
- _policyRead(request) {
989
+ _listPermissions(request) {
1000
990
  return __awaiter(this, void 0, void 0, function* () {
1001
991
  if (!validateOrigin(request, this._allowedApiOrigins)) {
1002
992
  return returnResult(INVALID_ORIGIN_RESULT);
1003
993
  }
1004
994
  const schema = z.object({
1005
995
  recordName: RECORD_NAME_VALIDATION,
1006
- marker: z
996
+ marker: MARKER_VALIDATION.optional(),
997
+ resourceKind: RESOURCE_KIND_VALIDATION.optional(),
998
+ resourceId: z
1007
999
  .string({
1008
- invalid_type_error: 'marker must be a string.',
1009
- required_error: 'marker is required.',
1000
+ invalid_type_error: 'resourceId must be a string.',
1001
+ required_error: 'resourceId is required.',
1010
1002
  })
1011
- .nonempty('marker must not be empty'),
1003
+ .optional(),
1012
1004
  });
1013
1005
  const parseResult = schema.safeParse(request.query);
1014
1006
  if (parseResult.success === false) {
1015
1007
  return returnZodError(parseResult.error);
1016
1008
  }
1017
- const { recordName, marker } = parseResult.data;
1009
+ const { recordName, marker, resourceKind, resourceId } = parseResult.data;
1018
1010
  const sessionKeyValidation = yield this._validateSessionKey(request);
1019
1011
  if (sessionKeyValidation.success === false) {
1020
1012
  if (sessionKeyValidation.errorCode === 'no_session_key') {
@@ -1022,39 +1014,18 @@ export class RecordsServer {
1022
1014
  }
1023
1015
  return returnResult(sessionKeyValidation);
1024
1016
  }
1025
- const result = yield this._policyController.readUserPolicy(recordName, sessionKeyValidation.userId, marker);
1026
- return returnResult(result);
1027
- });
1028
- }
1029
- _policyList(request) {
1030
- return __awaiter(this, void 0, void 0, function* () {
1031
- if (!validateOrigin(request, this._allowedApiOrigins)) {
1032
- return returnResult(INVALID_ORIGIN_RESULT);
1017
+ if (resourceKind && resourceId) {
1018
+ const result = yield this._policyController.listPermissionsForResource(recordName, resourceKind, resourceId, sessionKeyValidation.userId);
1019
+ return returnResult(result);
1033
1020
  }
1034
- const schema = z.object({
1035
- recordName: RECORD_NAME_VALIDATION,
1036
- startingMarker: z
1037
- .string({
1038
- invalid_type_error: 'startingMarker must be a string.',
1039
- required_error: 'startingMarker is required.',
1040
- })
1041
- .nonempty('startingMarker must not be empty')
1042
- .optional(),
1043
- });
1044
- const parseResult = schema.safeParse(request.query);
1045
- if (parseResult.success === false) {
1046
- return returnZodError(parseResult.error);
1021
+ else if (marker) {
1022
+ const result = yield this._policyController.listPermissionsForMarker(recordName, marker, sessionKeyValidation.userId);
1023
+ return returnResult(result);
1047
1024
  }
1048
- const { recordName, startingMarker } = parseResult.data;
1049
- const sessionKeyValidation = yield this._validateSessionKey(request);
1050
- if (sessionKeyValidation.success === false) {
1051
- if (sessionKeyValidation.errorCode === 'no_session_key') {
1052
- return returnResult(NOT_LOGGED_IN_RESULT);
1053
- }
1054
- return returnResult(sessionKeyValidation);
1025
+ else {
1026
+ const result = yield this._policyController.listPermissions(recordName, sessionKeyValidation.userId);
1027
+ return returnResult(result);
1055
1028
  }
1056
- const result = yield this._policyController.listUserPolicies(recordName, sessionKeyValidation.userId, startingMarker);
1057
- return returnResult(result);
1058
1029
  });
1059
1030
  }
1060
1031
  _roleUserList(request) {
@@ -1821,13 +1792,17 @@ export class RecordsServer {
1821
1792
  const schema = z.object({
1822
1793
  recordName: RECORD_NAME_VALIDATION,
1823
1794
  address: ADDRESS_VALIDATION.nullable().optional(),
1795
+ marker: MARKER_VALIDATION.optional(),
1796
+ sort: z
1797
+ .union([z.literal('ascending'), z.literal('descending')])
1798
+ .optional(),
1824
1799
  instances: INSTANCES_QUERY_VALIDATION.optional(),
1825
1800
  });
1826
1801
  const parseResult = schema.safeParse(request.query || {});
1827
1802
  if (parseResult.success === false) {
1828
1803
  return returnZodError(parseResult.error);
1829
1804
  }
1830
- const { recordName, address, instances } = parseResult.data;
1805
+ const { recordName, address, instances, marker, sort } = parseResult.data;
1831
1806
  if (!recordName || typeof recordName !== 'string') {
1832
1807
  return returnResult({
1833
1808
  success: false,
@@ -1849,8 +1824,21 @@ export class RecordsServer {
1849
1824
  sessionKeyValidation.errorCode !== 'no_session_key') {
1850
1825
  return returnResult(sessionKeyValidation);
1851
1826
  }
1852
- const result = yield this._data.listData(recordName, address || null, sessionKeyValidation.userId, instances);
1853
- return returnResult(result);
1827
+ if (!marker) {
1828
+ const result = yield this._data.listData(recordName, address || null, sessionKeyValidation.userId, instances);
1829
+ return returnResult(result);
1830
+ }
1831
+ else {
1832
+ const result = yield this._data.listDataByMarker({
1833
+ recordKeyOrName: recordName,
1834
+ marker: marker,
1835
+ startingAddress: address,
1836
+ sort: sort,
1837
+ userId: sessionKeyValidation.userId,
1838
+ instances,
1839
+ });
1840
+ return returnResult(result);
1841
+ }
1854
1842
  });
1855
1843
  }
1856
1844
  _handleRecordFileOptions(request) {
@@ -1918,13 +1906,7 @@ export class RecordsServer {
1918
1906
  .min(1)
1919
1907
  .max(128)
1920
1908
  .optional(),
1921
- markers: z
1922
- .array(z.string(), {
1923
- invalid_type_error: 'markers must be an array of strings.',
1924
- required_error: 'markers is required.',
1925
- })
1926
- .nonempty('markers must be non-empty.')
1927
- .optional(),
1909
+ markers: MARKERS_VALIDATION.optional(),
1928
1910
  instances: INSTANCES_ARRAY_VALIDATION.optional(),
1929
1911
  });
1930
1912
  const parseResult = schema.safeParse(jsonResult.value);
@@ -2005,12 +1987,7 @@ export class RecordsServer {
2005
1987
  required_error: 'fileUrl is required.',
2006
1988
  })
2007
1989
  .nonempty('fileUrl must be non-empty.'),
2008
- markers: z
2009
- .array(z.string(), {
2010
- invalid_type_error: 'markers must be an array of strings.',
2011
- required_error: 'markers is required.',
2012
- })
2013
- .nonempty('markers must be non-empty.'),
1990
+ markers: MARKERS_VALIDATION,
2014
1991
  instances: INSTANCES_ARRAY_VALIDATION.optional(),
2015
1992
  });
2016
1993
  const parseResult = schema.safeParse(jsonResult.value);