@casual-simulation/aux-records 3.4.6-alpha.14601027727 → 3.5.0-alpha.15117651144

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 (211) hide show
  1. package/AIController.js +835 -890
  2. package/AIController.js.map +1 -1
  3. package/AIHumeInterface.js +43 -54
  4. package/AIHumeInterface.js.map +1 -1
  5. package/AIOpenAIRealtimeInterface.js +60 -71
  6. package/AIOpenAIRealtimeInterface.js.map +1 -1
  7. package/AnthropicAIChatInterface.js +96 -142
  8. package/AnthropicAIChatInterface.js.map +1 -1
  9. package/AuthController.d.ts +3 -2
  10. package/AuthController.js +1907 -1933
  11. package/AuthController.js.map +1 -1
  12. package/AuthStore.d.ts +1 -10
  13. package/BlockadeLabsGenerateSkyboxInterface.js +57 -72
  14. package/BlockadeLabsGenerateSkyboxInterface.js.map +1 -1
  15. package/CachingConfigStore.js +30 -45
  16. package/CachingConfigStore.js.map +1 -1
  17. package/CachingPolicyStore.d.ts +8 -2
  18. package/CachingPolicyStore.js +108 -135
  19. package/CachingPolicyStore.js.map +1 -1
  20. package/ComIdConfig.d.ts +18 -18
  21. package/ComIdConfig.js.map +1 -1
  22. package/ConsoleAuthMessenger.js +7 -20
  23. package/ConsoleAuthMessenger.js.map +1 -1
  24. package/DataRecordsController.d.ts +2 -2
  25. package/DataRecordsController.js +369 -377
  26. package/DataRecordsController.js.map +1 -1
  27. package/DataRecordsStore.d.ts +1 -1
  28. package/DataRecordsStore.js +1 -1
  29. package/DataRecordsStore.js.map +1 -1
  30. package/EventRecordsController.js +226 -240
  31. package/EventRecordsController.js.map +1 -1
  32. package/FileRecordsController.d.ts +13 -2
  33. package/FileRecordsController.js +458 -450
  34. package/FileRecordsController.js.map +1 -1
  35. package/GoogleAIChatInterface.js +133 -179
  36. package/GoogleAIChatInterface.js.map +1 -1
  37. package/LivekitController.js +43 -54
  38. package/LivekitController.js.map +1 -1
  39. package/LoomController.js +64 -75
  40. package/LoomController.js.map +1 -1
  41. package/MemoryAuthMessenger.js +10 -23
  42. package/MemoryAuthMessenger.js.map +1 -1
  43. package/MemoryCache.js +18 -35
  44. package/MemoryCache.js.map +1 -1
  45. package/MemoryFileRecordsLookup.js +105 -125
  46. package/MemoryFileRecordsLookup.js.map +1 -1
  47. package/MemoryModerationJobProvider.js +17 -30
  48. package/MemoryModerationJobProvider.js.map +1 -1
  49. package/MemoryRateLimiter.js +12 -27
  50. package/MemoryRateLimiter.js.map +1 -1
  51. package/MemoryStore.d.ts +18 -6
  52. package/MemoryStore.js +1879 -1997
  53. package/MemoryStore.js.map +1 -1
  54. package/MetricsStore.d.ts +2 -2
  55. package/ModerationController.js +186 -200
  56. package/ModerationController.js.map +1 -1
  57. package/OpenAIChatInterface.js +105 -135
  58. package/OpenAIChatInterface.js.map +1 -1
  59. package/OpenAIImageInterface.js +57 -51
  60. package/OpenAIImageInterface.js.map +1 -1
  61. package/PolicyController.d.ts +150 -10
  62. package/PolicyController.js +1546 -1299
  63. package/PolicyController.js.map +1 -1
  64. package/PolicyStore.d.ts +110 -2
  65. package/PolicyStore.js +36 -1
  66. package/PolicyStore.js.map +1 -1
  67. package/PrivoClient.js +398 -435
  68. package/PrivoClient.js.map +1 -1
  69. package/RateLimitController.js +25 -36
  70. package/RateLimitController.js.map +1 -1
  71. package/RecordsClient.js +51 -74
  72. package/RecordsClient.js.map +1 -1
  73. package/RecordsController.d.ts +2 -42
  74. package/RecordsController.js +1026 -1182
  75. package/RecordsController.js.map +1 -1
  76. package/RecordsServer.d.ts +196 -27
  77. package/RecordsServer.js +1701 -1343
  78. package/RecordsServer.js.map +1 -1
  79. package/RecordsStore.d.ts +1 -10
  80. package/RecordsStore.js.map +1 -1
  81. package/ServerConfig.d.ts +339 -195
  82. package/ServerConfig.js +13 -0
  83. package/ServerConfig.js.map +1 -1
  84. package/SloydInterface.js +62 -75
  85. package/SloydInterface.js.map +1 -1
  86. package/StabilityAIImageInterface.js +150 -167
  87. package/StabilityAIImageInterface.js.map +1 -1
  88. package/SubscriptionConfigBuilder.d.ts +6 -1
  89. package/SubscriptionConfigBuilder.js +22 -0
  90. package/SubscriptionConfigBuilder.js.map +1 -1
  91. package/SubscriptionConfiguration.d.ts +266 -169
  92. package/SubscriptionConfiguration.js +101 -79
  93. package/SubscriptionConfiguration.js.map +1 -1
  94. package/SubscriptionController.d.ts +2 -1
  95. package/SubscriptionController.js +643 -650
  96. package/SubscriptionController.js.map +1 -1
  97. package/SystemNotificationMessenger.d.ts +21 -4
  98. package/SystemNotificationMessenger.js +36 -30
  99. package/SystemNotificationMessenger.js.map +1 -1
  100. package/TestUtils.d.ts +9 -1
  101. package/TestUtils.js +105 -129
  102. package/TestUtils.js.map +1 -1
  103. package/Utils.d.ts +2 -16
  104. package/Utils.js +21 -22
  105. package/Utils.js.map +1 -1
  106. package/crud/CrudHelpers.js +17 -26
  107. package/crud/CrudHelpers.js.map +1 -1
  108. package/crud/CrudRecordsController.d.ts +1 -1
  109. package/crud/CrudRecordsController.js +259 -267
  110. package/crud/CrudRecordsController.js.map +1 -1
  111. package/crud/CrudRecordsControllerTests.js +174 -185
  112. package/crud/CrudRecordsControllerTests.js.map +1 -1
  113. package/crud/CrudRecordsStore.d.ts +7 -3
  114. package/crud/MemoryCrudRecordsStore.d.ts +4 -4
  115. package/crud/MemoryCrudRecordsStore.js +98 -118
  116. package/crud/MemoryCrudRecordsStore.js.map +1 -1
  117. package/crud/sub/MemorySubCrudRecordsStore.d.ts +24 -0
  118. package/crud/sub/MemorySubCrudRecordsStore.js +146 -0
  119. package/crud/sub/MemorySubCrudRecordsStore.js.map +1 -0
  120. package/crud/sub/SubCrudRecordsController.d.ts +182 -0
  121. package/crud/sub/SubCrudRecordsController.js +360 -0
  122. package/crud/sub/SubCrudRecordsController.js.map +1 -0
  123. package/crud/sub/SubCrudRecordsControllerTests.d.ts +39 -0
  124. package/crud/sub/SubCrudRecordsControllerTests.js +821 -0
  125. package/crud/sub/SubCrudRecordsControllerTests.js.map +1 -0
  126. package/crud/sub/SubCrudRecordsStore.d.ts +95 -0
  127. package/{forms/index.js → crud/sub/SubCrudRecordsStore.js} +2 -2
  128. package/crud/sub/SubCrudRecordsStore.js.map +1 -0
  129. package/crud/sub/index.d.ts +3 -0
  130. package/crud/sub/index.js +20 -0
  131. package/{forms → crud/sub}/index.js.map +1 -1
  132. package/index.d.ts +1 -1
  133. package/index.js +1 -1
  134. package/index.js.map +1 -1
  135. package/notifications/MemoryNotificationRecordsStore.js +189 -198
  136. package/notifications/MemoryNotificationRecordsStore.js.map +1 -1
  137. package/notifications/NotificationRecordsController.js +438 -460
  138. package/notifications/NotificationRecordsController.js.map +1 -1
  139. package/notifications/NotificationRecordsStore.d.ts +2 -1
  140. package/notifications/WebPushInterface.d.ts +0 -1
  141. package/notifications/WebPushInterface.js +0 -1
  142. package/notifications/WebPushInterface.js.map +1 -1
  143. package/package.json +6 -6
  144. package/packages/MemoryPackageRecordsStore.d.ts +10 -0
  145. package/packages/MemoryPackageRecordsStore.js +38 -0
  146. package/packages/MemoryPackageRecordsStore.js.map +1 -0
  147. package/packages/PackageRecordsController.d.ts +26 -0
  148. package/packages/PackageRecordsController.js +49 -0
  149. package/packages/PackageRecordsController.js.map +1 -0
  150. package/packages/PackageRecordsStore.d.ts +32 -0
  151. package/packages/PackageRecordsStore.js +19 -0
  152. package/packages/PackageRecordsStore.js.map +1 -0
  153. package/packages/index.d.ts +4 -0
  154. package/packages/index.js +21 -0
  155. package/packages/index.js.map +1 -0
  156. package/packages/version/MemoryPackageVersionRecordsStore.d.ts +21 -0
  157. package/packages/version/MemoryPackageVersionRecordsStore.js +177 -0
  158. package/packages/version/MemoryPackageVersionRecordsStore.js.map +1 -0
  159. package/packages/version/PackageVersionRecordsController.d.ts +144 -0
  160. package/packages/version/PackageVersionRecordsController.js +656 -0
  161. package/packages/version/PackageVersionRecordsController.js.map +1 -0
  162. package/packages/version/PackageVersionRecordsStore.d.ts +342 -0
  163. package/packages/version/PackageVersionRecordsStore.js +126 -0
  164. package/packages/version/PackageVersionRecordsStore.js.map +1 -0
  165. package/packages/version/index.d.ts +4 -0
  166. package/packages/version/index.js +21 -0
  167. package/packages/version/index.js.map +1 -0
  168. package/tracing/TracingDecorators.js +31 -40
  169. package/tracing/TracingDecorators.js.map +1 -1
  170. package/webhooks/MemoryWebhookRecordsStore.js +56 -72
  171. package/webhooks/MemoryWebhookRecordsStore.js.map +1 -1
  172. package/webhooks/WebhookEnvironment.d.ts +3 -3
  173. package/webhooks/WebhookRecordsController.d.ts +2 -1
  174. package/webhooks/WebhookRecordsController.js +389 -382
  175. package/webhooks/WebhookRecordsController.js.map +1 -1
  176. package/webhooks/WebhookRecordsStore.d.ts +2 -1
  177. package/websockets/InstRecordsStore.d.ts +50 -0
  178. package/websockets/InstRecordsStore.js +17 -0
  179. package/websockets/InstRecordsStore.js.map +1 -1
  180. package/websockets/MemoryTempInstRecordsStore.d.ts +5 -0
  181. package/websockets/MemoryTempInstRecordsStore.js +168 -179
  182. package/websockets/MemoryTempInstRecordsStore.js.map +1 -1
  183. package/websockets/MemoryWebsocketConnectionStore.js +98 -135
  184. package/websockets/MemoryWebsocketConnectionStore.js.map +1 -1
  185. package/websockets/MemoryWebsocketMessenger.js +29 -48
  186. package/websockets/MemoryWebsocketMessenger.js.map +1 -1
  187. package/websockets/SplitInstRecordsStore.d.ts +4 -1
  188. package/websockets/SplitInstRecordsStore.js +167 -185
  189. package/websockets/SplitInstRecordsStore.js.map +1 -1
  190. package/websockets/TemporaryInstRecordsStore.d.ts +19 -1
  191. package/websockets/TemporaryInstRecordsStore.js +17 -0
  192. package/websockets/TemporaryInstRecordsStore.js.map +1 -1
  193. package/websockets/WebsocketController.d.ts +147 -3
  194. package/websockets/WebsocketController.js +1735 -1391
  195. package/websockets/WebsocketController.js.map +1 -1
  196. package/websockets/index.d.ts +0 -1
  197. package/websockets/index.js +0 -1
  198. package/websockets/index.js.map +1 -1
  199. package/AAGUID.d.ts +0 -11
  200. package/AAGUID.js +0 -116
  201. package/AAGUID.js.map +0 -1
  202. package/AuthUtils.d.ts +0 -162
  203. package/AuthUtils.js +0 -327
  204. package/AuthUtils.js.map +0 -1
  205. package/forms/FormError.d.ts +0 -43
  206. package/forms/FormError.js +0 -56
  207. package/forms/FormError.js.map +0 -1
  208. package/forms/index.d.ts +0 -2
  209. package/websockets/Utils.d.ts +0 -33
  210. package/websockets/Utils.js +0 -82
  211. package/websockets/Utils.js.map +0 -1
@@ -4,18 +4,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
7
  import { getExtension } from 'mime';
17
8
  import { getMarkerResourcesForCreation, getMarkerResourcesForUpdate, } from './PolicyController';
18
- import { ACCOUNT_MARKER, } from '@casual-simulation/aux-common';
9
+ import { ACCOUNT_MARKER } from '@casual-simulation/aux-common';
19
10
  import { getMarkersOrDefault, getRootMarkersOrDefault } from './Utils';
20
11
  import { getSubscriptionFeatures } from './SubscriptionConfiguration';
21
12
  import { traced } from './tracing/TracingDecorators';
@@ -36,196 +27,221 @@ export class FileRecordsController {
36
27
  * @param recordNameOrKey The name of the record or the record key of the record.
37
28
  * @param userId The ID of the user that is logged in. Should be null if the user is not logged in.
38
29
  * @param request The request.
30
+ * @param userRole the role of the user that is requesting the file.
39
31
  * @returns
40
32
  */
41
- recordFile(recordKeyOrRecordName, userId, request) {
33
+ async recordFile(recordKeyOrRecordName, userId, request) {
42
34
  var _a, _b;
43
- return __awaiter(this, void 0, void 0, function* () {
44
- try {
45
- const markers = getMarkersOrDefault(request.markers);
46
- const rootMarkers = getRootMarkersOrDefault(markers);
47
- const contextResult = yield this._policies.constructAuthorizationContext({
48
- recordKeyOrRecordName,
49
- userId,
50
- });
51
- if (contextResult.success === false) {
52
- return contextResult;
53
- }
54
- const extension = getExtension(request.fileMimeType);
55
- const fileName = extension
56
- ? `${request.fileSha256Hex}.${extension}`
57
- : request.fileSha256Hex;
58
- const authorization = yield this._policies.authorizeUserAndInstancesForResources(contextResult.context, {
59
- userId,
60
- instances: request.instances,
61
- resources: [
62
- {
63
- resourceKind: 'file',
64
- resourceId: fileName,
65
- action: 'create',
66
- markers: rootMarkers,
67
- },
68
- ...getMarkerResourcesForCreation(rootMarkers),
69
- ],
70
- });
71
- // const result = await this._policies.authorizeRequest({
72
- // action: 'file.create',
73
- // recordKeyOrRecordName: recordKeyOrRecordName,
74
- // userId,
75
- // resourceMarkers: markers,
76
- // fileSizeInBytes: request.fileByteLength,
77
- // fileMimeType: request.fileMimeType,
78
- // instances: request.instances,
79
- // });
80
- if (authorization.success === false) {
81
- return authorization;
82
- }
83
- const createAuthorization = authorization.results[0];
84
- for (let result of createAuthorization.results) {
85
- const options = result.permission.options;
86
- if ('maxFileSizeInBytes' in options &&
87
- options.maxFileSizeInBytes > 0) {
88
- if (request.fileByteLength > options.maxFileSizeInBytes) {
89
- return {
90
- success: false,
91
- errorCode: 'unacceptable_request',
92
- errorMessage: 'The file is too large.',
93
- };
94
- }
35
+ try {
36
+ let markers = getMarkersOrDefault(request.markers);
37
+ let rootMarkers = getRootMarkersOrDefault(markers);
38
+ const contextResult = await this._policies.constructAuthorizationContext({
39
+ recordKeyOrRecordName,
40
+ userId,
41
+ userRole: request.userRole,
42
+ });
43
+ if (contextResult.success === false) {
44
+ return contextResult;
45
+ }
46
+ const extension = getExtension(request.fileMimeType);
47
+ const fileName = extension
48
+ ? `${request.fileSha256Hex}.${extension}`
49
+ : request.fileSha256Hex;
50
+ const authorization = await this._policies.authorizeUserAndInstancesForResources(contextResult.context, {
51
+ userId,
52
+ instances: request.instances,
53
+ resources: [
54
+ {
55
+ resourceKind: 'file',
56
+ resourceId: fileName,
57
+ action: 'create',
58
+ markers: rootMarkers,
59
+ },
60
+ ...getMarkerResourcesForCreation(rootMarkers),
61
+ ],
62
+ });
63
+ // const result = await this._policies.authorizeRequest({
64
+ // action: 'file.create',
65
+ // recordKeyOrRecordName: recordKeyOrRecordName,
66
+ // userId,
67
+ // resourceMarkers: markers,
68
+ // fileSizeInBytes: request.fileByteLength,
69
+ // fileMimeType: request.fileMimeType,
70
+ // instances: request.instances,
71
+ // });
72
+ if (authorization.success === false) {
73
+ return authorization;
74
+ }
75
+ const createAuthorization = authorization.results[0];
76
+ for (let result of createAuthorization.results) {
77
+ const options = result.permission.options;
78
+ if ('maxFileSizeInBytes' in options &&
79
+ options.maxFileSizeInBytes > 0) {
80
+ if (request.fileByteLength > options.maxFileSizeInBytes) {
81
+ return {
82
+ success: false,
83
+ errorCode: 'unacceptable_request',
84
+ errorMessage: 'The file is too large.',
85
+ };
95
86
  }
96
- else if ('allowedMimeTypes' in options &&
97
- Array.isArray(options.allowedMimeTypes)) {
98
- if (!options.allowedMimeTypes.includes(request.fileMimeType)) {
99
- return {
100
- success: false,
101
- errorCode: 'unacceptable_request',
102
- errorMessage: 'The file type is not allowed.',
103
- };
104
- }
87
+ }
88
+ else if ('allowedMimeTypes' in options &&
89
+ Array.isArray(options.allowedMimeTypes)) {
90
+ if (!options.allowedMimeTypes.includes(request.fileMimeType)) {
91
+ return {
92
+ success: false,
93
+ errorCode: 'unacceptable_request',
94
+ errorMessage: 'The file type is not allowed.',
95
+ };
105
96
  }
106
97
  }
107
- const policy = contextResult.context.subjectPolicy;
108
- userId = contextResult.context.userId;
109
- if (!userId && policy !== 'subjectless') {
98
+ }
99
+ const policy = contextResult.context.subjectPolicy;
100
+ userId = contextResult.context.userId;
101
+ const userRole = contextResult.context.userRole;
102
+ if (!userId && userRole === 'none' && policy !== 'subjectless') {
103
+ return {
104
+ success: false,
105
+ errorCode: 'not_logged_in',
106
+ errorMessage: 'The user must be logged in in order to record files.',
107
+ };
108
+ }
109
+ if (policy === 'subjectless') {
110
+ userId = null;
111
+ }
112
+ const publisherId = (_b = (_a = contextResult.context.recordKeyCreatorId) !== null && _a !== void 0 ? _a : userId) !== null && _b !== void 0 ? _b : contextResult.context.recordOwnerId;
113
+ const recordName = authorization.recordName;
114
+ const subjectId = userId;
115
+ const metricsResult = await this._metrics.getSubscriptionFileMetricsByRecordName(recordName);
116
+ const config = await this._config.getSubscriptionConfiguration();
117
+ const features = getSubscriptionFeatures(config, metricsResult.subscriptionStatus, metricsResult.subscriptionId, metricsResult.ownerId ? 'user' : 'studio');
118
+ if (!features.files.allowed) {
119
+ return {
120
+ success: false,
121
+ errorCode: 'not_authorized',
122
+ errorMessage: 'The subscription does not permit the recording of files.',
123
+ };
124
+ }
125
+ if (features.files.maxBytesPerFile > 0) {
126
+ if (request.fileByteLength > features.files.maxBytesPerFile) {
110
127
  return {
111
128
  success: false,
112
- errorCode: 'not_logged_in',
113
- errorMessage: 'The user must be logged in in order to record files.',
129
+ errorCode: 'unacceptable_request',
130
+ errorMessage: 'The file is too large.',
114
131
  };
115
132
  }
116
- if (policy === 'subjectless') {
117
- userId = null;
133
+ }
134
+ if (features.files.maxBytesTotal > 0) {
135
+ const newSize = metricsResult.totalFileBytesReserved +
136
+ request.fileByteLength;
137
+ if (newSize > features.files.maxBytesTotal) {
138
+ return {
139
+ success: false,
140
+ errorCode: 'subscription_limit_reached',
141
+ errorMessage: 'The file storage limit has been reached for the subscription.',
142
+ };
118
143
  }
119
- const publisherId = (_b = (_a = contextResult.context.recordKeyCreatorId) !== null && _a !== void 0 ? _a : userId) !== null && _b !== void 0 ? _b : contextResult.context.recordOwnerId;
120
- const recordName = authorization.recordName;
121
- const subjectId = userId;
122
- const metricsResult = yield this._metrics.getSubscriptionFileMetricsByRecordName(recordName);
123
- const config = yield this._config.getSubscriptionConfiguration();
124
- const features = getSubscriptionFeatures(config, metricsResult.subscriptionStatus, metricsResult.subscriptionId, metricsResult.ownerId ? 'user' : 'studio');
125
- if (!features.files.allowed) {
144
+ }
145
+ if (features.files.maxFiles > 0) {
146
+ const newCount = metricsResult.totalFiles + 1;
147
+ if (newCount > features.files.maxFiles) {
126
148
  return {
127
149
  success: false,
128
- errorCode: 'not_authorized',
129
- errorMessage: 'The subscription does not permit the recording of files.',
150
+ errorCode: 'subscription_limit_reached',
151
+ errorMessage: 'The file count limit has been reached for the subscription.',
130
152
  };
131
153
  }
132
- if (features.files.maxBytesPerFile > 0) {
133
- if (request.fileByteLength > features.files.maxBytesPerFile) {
154
+ }
155
+ const addFileResult = await this._store.addFileRecord(recordName, fileName, publisherId, subjectId, request.fileByteLength, request.fileDescription, markers);
156
+ if (addFileResult.success === false) {
157
+ if (addFileResult.errorCode === 'file_already_exists') {
158
+ const fileResult = await this._store.getFileRecord(recordName, fileName);
159
+ if (fileResult.success === false) {
160
+ console.error('[FileRecordsController] Error getting file record even though it should exist:', fileResult);
134
161
  return {
135
162
  success: false,
136
- errorCode: 'unacceptable_request',
137
- errorMessage: 'The file is too large.',
163
+ errorCode: 'server_error',
164
+ errorMessage: fileResult.errorMessage,
138
165
  };
139
166
  }
140
- }
141
- if (features.files.maxBytesTotal > 0) {
142
- const newSize = metricsResult.totalFileBytesReserved +
143
- request.fileByteLength;
144
- if (newSize > features.files.maxBytesTotal) {
145
- return {
146
- success: false,
147
- errorCode: 'subscription_limit_reached',
148
- errorMessage: 'The file storage limit has been reached for the subscription.',
149
- };
167
+ if (!fileResult.uploaded) {
168
+ if (!fileResult.markers.some((m) => markers.includes(m))) {
169
+ // re-check permissions because none of the markers match up
170
+ // with the markers that the file actually has
171
+ markers = fileResult.markers;
172
+ rootMarkers = getRootMarkersOrDefault(markers);
173
+ const authorization = await this._policies.authorizeUserAndInstancesForResources(contextResult.context, {
174
+ userId: subjectId,
175
+ instances: request.instances,
176
+ resources: [
177
+ {
178
+ resourceKind: 'file',
179
+ resourceId: fileName,
180
+ action: 'create',
181
+ markers: markers,
182
+ },
183
+ ...getMarkerResourcesForCreation(markers),
184
+ ],
185
+ });
186
+ if (authorization.success === false) {
187
+ return authorization;
188
+ }
189
+ }
190
+ else {
191
+ // allow the request to be successful
192
+ // because at least one of the markers is the same
193
+ // we just need to grab the real markers from the file
194
+ markers = fileResult.markers;
195
+ rootMarkers = getRootMarkersOrDefault(markers);
196
+ }
150
197
  }
151
- }
152
- if (features.files.maxFiles > 0) {
153
- const newCount = metricsResult.totalFiles + 1;
154
- if (newCount > features.files.maxFiles) {
198
+ else {
155
199
  return {
156
200
  success: false,
157
- errorCode: 'subscription_limit_reached',
158
- errorMessage: 'The file count limit has been reached for the subscription.',
201
+ errorCode: 'file_already_exists',
202
+ errorMessage: 'The file has already been uploaded to ' +
203
+ fileResult.url,
204
+ existingFileUrl: fileResult.url,
205
+ existingFileName: fileResult.fileName,
159
206
  };
160
207
  }
161
208
  }
162
- const presignResult = yield this._store.presignFileUpload({
163
- recordName,
164
- fileName: fileName,
165
- fileSha256Hex: request.fileSha256Hex,
166
- fileMimeType: request.fileMimeType,
167
- fileByteLength: request.fileByteLength,
168
- markers: rootMarkers,
169
- headers: request.headers,
170
- });
171
- if (presignResult.success === false) {
172
- return presignResult;
173
- }
174
- const addFileResult = yield this._store.addFileRecord(recordName, fileName, publisherId, subjectId, request.fileByteLength, request.fileDescription, markers);
175
- if (addFileResult.success === false) {
176
- if (addFileResult.errorCode === 'file_already_exists') {
177
- const fileResult = yield this._store.getFileRecord(recordName, fileName);
178
- if (fileResult.success === false) {
179
- console.error('[FileRecordsController] Error getting file record even though it should exist:', fileResult);
180
- return {
181
- success: false,
182
- errorCode: 'server_error',
183
- errorMessage: fileResult.errorMessage,
184
- };
185
- }
186
- if (!fileResult.uploaded) {
187
- return {
188
- success: true,
189
- fileName,
190
- uploadUrl: presignResult.uploadUrl,
191
- uploadHeaders: presignResult.uploadHeaders,
192
- uploadMethod: presignResult.uploadMethod,
193
- markers,
194
- };
195
- }
196
- else {
197
- return {
198
- success: false,
199
- errorCode: 'file_already_exists',
200
- errorMessage: 'The file has already been uploaded to ' +
201
- fileResult.url,
202
- existingFileUrl: fileResult.url,
203
- };
204
- }
205
- }
209
+ else {
206
210
  return addFileResult;
207
211
  }
208
- return {
209
- success: true,
210
- fileName,
211
- uploadUrl: presignResult.uploadUrl,
212
- uploadHeaders: presignResult.uploadHeaders,
213
- uploadMethod: presignResult.uploadMethod,
214
- markers,
215
- };
216
212
  }
217
- catch (err) {
218
- const span = trace.getActiveSpan();
219
- span === null || span === void 0 ? void 0 : span.recordException(err);
220
- span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
221
- console.error('[FileRecordsController] An error occurred while recording a file:', err);
222
- return {
223
- success: false,
224
- errorCode: 'server_error',
225
- errorMessage: 'A server error occurred.',
226
- };
213
+ const presignResult = await this._store.presignFileUpload({
214
+ recordName,
215
+ fileName: fileName,
216
+ fileSha256Hex: request.fileSha256Hex,
217
+ fileMimeType: request.fileMimeType,
218
+ fileByteLength: request.fileByteLength,
219
+ markers: rootMarkers,
220
+ headers: request.headers,
221
+ });
222
+ if (presignResult.success === false) {
223
+ return presignResult;
227
224
  }
228
- });
225
+ return {
226
+ success: true,
227
+ fileName,
228
+ uploadUrl: presignResult.uploadUrl,
229
+ uploadHeaders: presignResult.uploadHeaders,
230
+ uploadMethod: presignResult.uploadMethod,
231
+ markers,
232
+ };
233
+ }
234
+ catch (err) {
235
+ const span = trace.getActiveSpan();
236
+ span === null || span === void 0 ? void 0 : span.recordException(err);
237
+ span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
238
+ console.error('[FileRecordsController] An error occurred while recording a file:', err);
239
+ return {
240
+ success: false,
241
+ errorCode: 'server_error',
242
+ errorMessage: 'A server error occurred.',
243
+ };
244
+ }
229
245
  }
230
246
  /**
231
247
  * Attempts to erase the given file using the given record key and subject.
@@ -234,80 +250,78 @@ export class FileRecordsController {
234
250
  * @param subjectId The ID of the user that is making this request. Null if the user is not logged in.
235
251
  * @param instances The instances that are loaded.
236
252
  */
237
- eraseFile(recordKeyOrRecordName, fileName, subjectId, instances) {
238
- return __awaiter(this, void 0, void 0, function* () {
239
- try {
240
- const baseRequest = {
241
- recordKeyOrRecordName,
242
- userId: subjectId,
243
- instances,
244
- };
245
- const context = yield this._policies.constructAuthorizationContext(baseRequest);
246
- if (context.success === false) {
247
- return context;
248
- }
249
- const fileResult = yield this._store.getFileRecord(context.context.recordName, fileName);
250
- if (fileResult.success === false) {
251
- return fileResult;
252
- }
253
- const markers = getRootMarkersOrDefault(fileResult.markers);
254
- const authorization = yield this._policies.authorizeUserAndInstances(context.context, {
255
- userId: subjectId,
256
- instances: instances,
257
- resourceKind: 'file',
258
- resourceId: fileName,
259
- action: 'delete',
260
- markers: markers,
261
- });
262
- // const result = await this._policies.authorizeRequestUsingContext(
263
- // context.context,
264
- // {
265
- // action: 'file.delete',
266
- // ...baseRequest,
267
- // fileSizeInBytes: fileResult.sizeInBytes,
268
- // fileMimeType: getType(fileResult.fileName),
269
- // resourceMarkers: markers,
270
- // }
271
- // );
272
- if (authorization.success === false) {
273
- return authorization;
274
- }
275
- const policy = context.context.subjectPolicy;
276
- subjectId = authorization.user.subjectId;
277
- if (!subjectId && policy !== 'subjectless') {
278
- return {
279
- success: false,
280
- errorCode: 'not_logged_in',
281
- errorMessage: 'The user must be logged in in order to erase files.',
282
- };
283
- }
284
- const recordName = authorization.recordName;
285
- const eraseResult = yield this._store.eraseFileRecord(recordName, fileName);
286
- if (eraseResult.success === false) {
287
- return {
288
- success: false,
289
- errorCode: eraseResult.errorCode,
290
- errorMessage: eraseResult.errorMessage,
291
- };
292
- }
253
+ async eraseFile(recordKeyOrRecordName, fileName, subjectId, instances) {
254
+ try {
255
+ const baseRequest = {
256
+ recordKeyOrRecordName,
257
+ userId: subjectId,
258
+ instances,
259
+ };
260
+ const context = await this._policies.constructAuthorizationContext(baseRequest);
261
+ if (context.success === false) {
262
+ return context;
263
+ }
264
+ const fileResult = await this._store.getFileRecord(context.context.recordName, fileName);
265
+ if (fileResult.success === false) {
266
+ return fileResult;
267
+ }
268
+ const markers = getRootMarkersOrDefault(fileResult.markers);
269
+ const authorization = await this._policies.authorizeUserAndInstances(context.context, {
270
+ userId: subjectId,
271
+ instances: instances,
272
+ resourceKind: 'file',
273
+ resourceId: fileName,
274
+ action: 'delete',
275
+ markers: markers,
276
+ });
277
+ // const result = await this._policies.authorizeRequestUsingContext(
278
+ // context.context,
279
+ // {
280
+ // action: 'file.delete',
281
+ // ...baseRequest,
282
+ // fileSizeInBytes: fileResult.sizeInBytes,
283
+ // fileMimeType: getType(fileResult.fileName),
284
+ // resourceMarkers: markers,
285
+ // }
286
+ // );
287
+ if (authorization.success === false) {
288
+ return authorization;
289
+ }
290
+ const policy = context.context.subjectPolicy;
291
+ subjectId = authorization.user.subjectId;
292
+ if (!subjectId && policy !== 'subjectless') {
293
293
  return {
294
- success: true,
295
- recordName,
296
- fileName,
294
+ success: false,
295
+ errorCode: 'not_logged_in',
296
+ errorMessage: 'The user must be logged in in order to erase files.',
297
297
  };
298
298
  }
299
- catch (err) {
300
- const span = trace.getActiveSpan();
301
- span === null || span === void 0 ? void 0 : span.recordException(err);
302
- span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
303
- console.error('[FileRecordsController] An error occurred while erasing a file:', err);
299
+ const recordName = authorization.recordName;
300
+ const eraseResult = await this._store.eraseFileRecord(recordName, fileName);
301
+ if (eraseResult.success === false) {
304
302
  return {
305
303
  success: false,
306
- errorCode: 'server_error',
307
- errorMessage: 'A server error occurred.',
304
+ errorCode: eraseResult.errorCode,
305
+ errorMessage: eraseResult.errorMessage,
308
306
  };
309
307
  }
310
- });
308
+ return {
309
+ success: true,
310
+ recordName,
311
+ fileName,
312
+ };
313
+ }
314
+ catch (err) {
315
+ const span = trace.getActiveSpan();
316
+ span === null || span === void 0 ? void 0 : span.recordException(err);
317
+ span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
318
+ console.error('[FileRecordsController] An error occurred while erasing a file:', err);
319
+ return {
320
+ success: false,
321
+ errorCode: 'server_error',
322
+ errorMessage: 'A server error occurred.',
323
+ };
324
+ }
311
325
  }
312
326
  /**
313
327
  * Attempts to retrieve a URL that allows the client to read the given file.
@@ -315,86 +329,88 @@ export class FileRecordsController {
315
329
  * @param fileName The name of the file.
316
330
  * @param subjectId The ID of the user that is making this request. Null if the user is not logged in.
317
331
  * @param instances The instances that are loaded.
332
+ * @param userRole The role of the user that is making the request.
318
333
  */
319
- readFile(recordKeyOrRecordName, fileName, subjectId, instances) {
320
- return __awaiter(this, void 0, void 0, function* () {
321
- try {
322
- const baseRequest = {
323
- recordKeyOrRecordName,
324
- userId: subjectId,
325
- instances,
326
- };
327
- const context = yield this._policies.constructAuthorizationContext(baseRequest);
328
- if (context.success === false) {
329
- return context;
330
- }
331
- const fileResult = yield this._store.getFileRecord(context.context.recordName, fileName);
332
- if (fileResult.success === false) {
333
- return fileResult;
334
- }
335
- const markers = getRootMarkersOrDefault(fileResult.markers);
336
- const result = yield this._policies.authorizeUserAndInstances(context.context, {
337
- userId: subjectId,
338
- instances: instances,
339
- resourceKind: 'file',
340
- resourceId: fileName,
341
- action: 'read',
342
- markers: markers,
343
- });
344
- // const result = await this._policies.authorizeRequestUsingContext(
345
- // context.context,
346
- // {
347
- // action: 'file.read',
348
- // ...baseRequest,
349
- // fileSizeInBytes: fileResult.sizeInBytes,
350
- // fileMimeType: getType(fileResult.fileName),
351
- // resourceMarkers: markers,
352
- // }
353
- // );
354
- if (result.success === false) {
355
- return result;
356
- }
357
- const policy = context.context.subjectPolicy;
358
- subjectId = result.user.subjectId;
359
- if (!subjectId && policy !== 'subjectless') {
360
- return {
361
- success: false,
362
- errorCode: 'not_logged_in',
363
- errorMessage: 'The user must be logged in in order to read files.',
364
- };
365
- }
366
- const recordName = result.recordName;
367
- const readResult = yield this._store.presignFileRead({
368
- recordName,
369
- fileName,
370
- headers: {},
371
- });
372
- if (readResult.success === false) {
373
- return {
374
- success: false,
375
- errorCode: readResult.errorCode,
376
- errorMessage: readResult.errorMessage,
377
- };
378
- }
334
+ async readFile(recordKeyOrRecordName, fileName, subjectId, instances, userRole) {
335
+ try {
336
+ const baseRequest = {
337
+ recordKeyOrRecordName,
338
+ userId: subjectId,
339
+ instances,
340
+ userRole,
341
+ };
342
+ const context = await this._policies.constructAuthorizationContext(baseRequest);
343
+ if (context.success === false) {
344
+ return context;
345
+ }
346
+ const fileResult = await this._store.getFileRecord(context.context.recordName, fileName);
347
+ if (fileResult.success === false) {
348
+ return fileResult;
349
+ }
350
+ const markers = getRootMarkersOrDefault(fileResult.markers);
351
+ const result = await this._policies.authorizeUserAndInstances(context.context, {
352
+ userId: subjectId,
353
+ instances: instances,
354
+ resourceKind: 'file',
355
+ resourceId: fileName,
356
+ action: 'read',
357
+ markers: markers,
358
+ });
359
+ // const result = await this._policies.authorizeRequestUsingContext(
360
+ // context.context,
361
+ // {
362
+ // action: 'file.read',
363
+ // ...baseRequest,
364
+ // fileSizeInBytes: fileResult.sizeInBytes,
365
+ // fileMimeType: getType(fileResult.fileName),
366
+ // resourceMarkers: markers,
367
+ // }
368
+ // );
369
+ if (result.success === false) {
370
+ return result;
371
+ }
372
+ const policy = context.context.subjectPolicy;
373
+ subjectId = result.user.subjectId;
374
+ if (!subjectId &&
375
+ context.context.userRole === 'none' &&
376
+ policy !== 'subjectless') {
379
377
  return {
380
- success: true,
381
- requestUrl: readResult.requestUrl,
382
- requestMethod: readResult.requestMethod,
383
- requestHeaders: readResult.requestHeaders,
378
+ success: false,
379
+ errorCode: 'not_logged_in',
380
+ errorMessage: 'The user must be logged in in order to read files.',
384
381
  };
385
382
  }
386
- catch (err) {
387
- const span = trace.getActiveSpan();
388
- span === null || span === void 0 ? void 0 : span.recordException(err);
389
- span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
390
- console.error('[FileRecordsController] An error occurred while reading a file:', err);
383
+ const recordName = result.recordName;
384
+ const readResult = await this._store.presignFileRead({
385
+ recordName,
386
+ fileName,
387
+ headers: {},
388
+ });
389
+ if (readResult.success === false) {
391
390
  return {
392
391
  success: false,
393
- errorCode: 'server_error',
394
- errorMessage: 'A server error occurred.',
392
+ errorCode: readResult.errorCode,
393
+ errorMessage: readResult.errorMessage,
395
394
  };
396
395
  }
397
- });
396
+ return {
397
+ success: true,
398
+ requestUrl: readResult.requestUrl,
399
+ requestMethod: readResult.requestMethod,
400
+ requestHeaders: readResult.requestHeaders,
401
+ };
402
+ }
403
+ catch (err) {
404
+ const span = trace.getActiveSpan();
405
+ span === null || span === void 0 ? void 0 : span.recordException(err);
406
+ span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
407
+ console.error('[FileRecordsController] An error occurred while reading a file:', err);
408
+ return {
409
+ success: false,
410
+ errorCode: 'server_error',
411
+ errorMessage: 'A server error occurred.',
412
+ };
413
+ }
398
414
  }
399
415
  /**
400
416
  * Attempts to list the files that are available in the given record.
@@ -403,160 +419,152 @@ export class FileRecordsController {
403
419
  * @param userId The ID of the user who is retrieving the data. If null, then it is assumed that the user is not logged in.
404
420
  * @param instances The instances that are loaded.
405
421
  */
406
- listFiles(recordKeyOrRecordName, fileName, userId, instances) {
407
- return __awaiter(this, void 0, void 0, function* () {
408
- try {
409
- if (!this._store.listUploadedFiles) {
410
- return {
411
- success: false,
412
- errorCode: 'not_supported',
413
- errorMessage: 'This operation is not supported.',
414
- };
415
- }
416
- const baseRequest = {
417
- recordKeyOrRecordName,
418
- userId: userId,
419
- instances,
420
- };
421
- const context = yield this._policies.constructAuthorizationContext(baseRequest);
422
- if (context.success === false) {
423
- return context;
424
- }
425
- const authorizeResult = yield this._policies.authorizeUserAndInstances(context.context, {
426
- userId: userId,
427
- instances,
428
- resourceKind: 'file',
429
- action: 'list',
430
- markers: [ACCOUNT_MARKER],
431
- });
432
- if (authorizeResult.success === false) {
433
- return authorizeResult;
434
- }
435
- const result2 = yield this._store.listUploadedFiles(context.context.recordName, fileName);
436
- if (result2.success === false) {
437
- return {
438
- success: false,
439
- errorCode: result2.errorCode,
440
- errorMessage: result2.errorMessage,
441
- };
442
- }
443
- return {
444
- success: true,
445
- recordName: context.context.recordName,
446
- files: result2.files,
447
- totalCount: result2.totalCount,
448
- };
449
- }
450
- catch (err) {
451
- const span = trace.getActiveSpan();
452
- span === null || span === void 0 ? void 0 : span.recordException(err);
453
- span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
454
- console.error('[FileRecordsController] An error occurred while listing files:', err);
422
+ async listFiles(recordKeyOrRecordName, fileName, userId, instances) {
423
+ try {
424
+ if (!this._store.listUploadedFiles) {
455
425
  return {
456
426
  success: false,
457
- errorCode: 'server_error',
458
- errorMessage: 'A server error occurred.',
427
+ errorCode: 'not_supported',
428
+ errorMessage: 'This operation is not supported.',
459
429
  };
460
430
  }
461
- });
462
- }
463
- updateFile(recordKeyOrRecordName, fileName, subjectId, markers, instances) {
464
- return __awaiter(this, void 0, void 0, function* () {
465
- try {
466
- const baseRequest = {
467
- recordKeyOrRecordName,
468
- userId: subjectId,
469
- instances,
470
- };
471
- const context = yield this._policies.constructAuthorizationContext(baseRequest);
472
- if (context.success === false) {
473
- return context;
474
- }
475
- const fileResult = yield this._store.getFileRecord(context.context.recordName, fileName);
476
- if (fileResult.success === false) {
477
- return fileResult;
478
- }
479
- const existingMarkers = getRootMarkersOrDefault(fileResult.markers);
480
- const resourceMarkers = markers !== null && markers !== void 0 ? markers : existingMarkers;
481
- const result = yield this._policies.authorizeUserAndInstancesForResources(context.context, {
482
- userId: subjectId,
483
- instances: instances,
484
- resources: [
485
- {
486
- resourceKind: 'file',
487
- resourceId: fileName,
488
- action: 'update',
489
- markers: resourceMarkers,
490
- },
491
- ...getMarkerResourcesForUpdate(existingMarkers, markers),
492
- ],
493
- });
494
- if (result.success === false) {
495
- return result;
496
- }
497
- subjectId = context.context.userId;
498
- const updateResult = yield this._store.updateFileRecord(result.recordName, fileName, resourceMarkers);
499
- if (updateResult.success === false) {
500
- return updateResult;
501
- }
502
- return {
503
- success: true,
504
- };
431
+ const baseRequest = {
432
+ recordKeyOrRecordName,
433
+ userId: userId,
434
+ instances,
435
+ };
436
+ const context = await this._policies.constructAuthorizationContext(baseRequest);
437
+ if (context.success === false) {
438
+ return context;
439
+ }
440
+ const authorizeResult = await this._policies.authorizeUserAndInstances(context.context, {
441
+ userId: userId,
442
+ instances,
443
+ resourceKind: 'file',
444
+ action: 'list',
445
+ markers: [ACCOUNT_MARKER],
446
+ });
447
+ if (authorizeResult.success === false) {
448
+ return authorizeResult;
505
449
  }
506
- catch (err) {
507
- const span = trace.getActiveSpan();
508
- span === null || span === void 0 ? void 0 : span.recordException(err);
509
- span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
510
- console.error('[FileRecordsController] An error occurred while reading a file:', err);
450
+ const result2 = await this._store.listUploadedFiles(context.context.recordName, fileName);
451
+ if (result2.success === false) {
511
452
  return {
512
453
  success: false,
513
- errorCode: 'server_error',
514
- errorMessage: 'A server error occurred.',
454
+ errorCode: result2.errorCode,
455
+ errorMessage: result2.errorMessage,
515
456
  };
516
457
  }
517
- });
458
+ return {
459
+ success: true,
460
+ recordName: context.context.recordName,
461
+ files: result2.files,
462
+ totalCount: result2.totalCount,
463
+ };
464
+ }
465
+ catch (err) {
466
+ const span = trace.getActiveSpan();
467
+ span === null || span === void 0 ? void 0 : span.recordException(err);
468
+ span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
469
+ console.error('[FileRecordsController] An error occurred while listing files:', err);
470
+ return {
471
+ success: false,
472
+ errorCode: 'server_error',
473
+ errorMessage: 'A server error occurred.',
474
+ };
475
+ }
518
476
  }
519
- markFileAsUploaded(recordName, fileName) {
520
- return __awaiter(this, void 0, void 0, function* () {
521
- try {
522
- const result = yield this._store.setFileRecordAsUploaded(recordName, fileName);
523
- if (result.success === false) {
524
- return result;
525
- }
526
- return {
527
- success: true,
528
- };
477
+ async updateFile(recordKeyOrRecordName, fileName, subjectId, markers, instances) {
478
+ try {
479
+ const baseRequest = {
480
+ recordKeyOrRecordName,
481
+ userId: subjectId,
482
+ instances,
483
+ };
484
+ const context = await this._policies.constructAuthorizationContext(baseRequest);
485
+ if (context.success === false) {
486
+ return context;
529
487
  }
530
- catch (err) {
531
- const span = trace.getActiveSpan();
532
- span === null || span === void 0 ? void 0 : span.recordException(err);
533
- span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
534
- console.error('[FileRecordsController] An error occurred while marking a file as uploaded:', err);
535
- return {
536
- success: false,
537
- errorCode: 'server_error',
538
- errorMessage: 'A server error occurred.',
539
- };
488
+ const fileResult = await this._store.getFileRecord(context.context.recordName, fileName);
489
+ if (fileResult.success === false) {
490
+ return fileResult;
540
491
  }
541
- });
542
- }
543
- getFileNameFromUrl(fileUrl) {
544
- return __awaiter(this, void 0, void 0, function* () {
545
- try {
546
- return yield this._store.getFileNameFromUrl(fileUrl);
492
+ const existingMarkers = getRootMarkersOrDefault(fileResult.markers);
493
+ const resourceMarkers = markers !== null && markers !== void 0 ? markers : existingMarkers;
494
+ const result = await this._policies.authorizeUserAndInstancesForResources(context.context, {
495
+ userId: subjectId,
496
+ instances: instances,
497
+ resources: [
498
+ {
499
+ resourceKind: 'file',
500
+ resourceId: fileName,
501
+ action: 'update',
502
+ markers: resourceMarkers,
503
+ },
504
+ ...getMarkerResourcesForUpdate(existingMarkers, markers),
505
+ ],
506
+ });
507
+ if (result.success === false) {
508
+ return result;
547
509
  }
548
- catch (err) {
549
- const span = trace.getActiveSpan();
550
- span === null || span === void 0 ? void 0 : span.recordException(err);
551
- span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
552
- console.error('[FileRecordsController] An error occurred while getting a file name:', err);
553
- return {
554
- success: false,
555
- errorCode: 'server_error',
556
- errorMessage: 'A server error occurred.',
557
- };
510
+ subjectId = context.context.userId;
511
+ const updateResult = await this._store.updateFileRecord(result.recordName, fileName, resourceMarkers);
512
+ if (updateResult.success === false) {
513
+ return updateResult;
558
514
  }
559
- });
515
+ return {
516
+ success: true,
517
+ };
518
+ }
519
+ catch (err) {
520
+ const span = trace.getActiveSpan();
521
+ span === null || span === void 0 ? void 0 : span.recordException(err);
522
+ span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
523
+ console.error('[FileRecordsController] An error occurred while reading a file:', err);
524
+ return {
525
+ success: false,
526
+ errorCode: 'server_error',
527
+ errorMessage: 'A server error occurred.',
528
+ };
529
+ }
530
+ }
531
+ async markFileAsUploaded(recordName, fileName) {
532
+ try {
533
+ const result = await this._store.setFileRecordAsUploaded(recordName, fileName);
534
+ if (result.success === false) {
535
+ return result;
536
+ }
537
+ return {
538
+ success: true,
539
+ };
540
+ }
541
+ catch (err) {
542
+ const span = trace.getActiveSpan();
543
+ span === null || span === void 0 ? void 0 : span.recordException(err);
544
+ span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
545
+ console.error('[FileRecordsController] An error occurred while marking a file as uploaded:', err);
546
+ return {
547
+ success: false,
548
+ errorCode: 'server_error',
549
+ errorMessage: 'A server error occurred.',
550
+ };
551
+ }
552
+ }
553
+ async getFileNameFromUrl(fileUrl) {
554
+ try {
555
+ return await this._store.getFileNameFromUrl(fileUrl);
556
+ }
557
+ catch (err) {
558
+ const span = trace.getActiveSpan();
559
+ span === null || span === void 0 ? void 0 : span.recordException(err);
560
+ span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
561
+ console.error('[FileRecordsController] An error occurred while getting a file name:', err);
562
+ return {
563
+ success: false,
564
+ errorCode: 'server_error',
565
+ errorMessage: 'A server error occurred.',
566
+ };
567
+ }
560
568
  }
561
569
  getAllowedUploadHeaders() {
562
570
  return this._store.getAllowedUploadHeaders();