@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.
- package/AIController.js +835 -890
- package/AIController.js.map +1 -1
- package/AIHumeInterface.js +43 -54
- package/AIHumeInterface.js.map +1 -1
- package/AIOpenAIRealtimeInterface.js +60 -71
- package/AIOpenAIRealtimeInterface.js.map +1 -1
- package/AnthropicAIChatInterface.js +96 -142
- package/AnthropicAIChatInterface.js.map +1 -1
- package/AuthController.d.ts +3 -2
- package/AuthController.js +1907 -1933
- package/AuthController.js.map +1 -1
- package/AuthStore.d.ts +1 -10
- package/BlockadeLabsGenerateSkyboxInterface.js +57 -72
- package/BlockadeLabsGenerateSkyboxInterface.js.map +1 -1
- package/CachingConfigStore.js +30 -45
- package/CachingConfigStore.js.map +1 -1
- package/CachingPolicyStore.d.ts +8 -2
- package/CachingPolicyStore.js +108 -135
- package/CachingPolicyStore.js.map +1 -1
- package/ComIdConfig.d.ts +18 -18
- package/ComIdConfig.js.map +1 -1
- package/ConsoleAuthMessenger.js +7 -20
- package/ConsoleAuthMessenger.js.map +1 -1
- package/DataRecordsController.d.ts +2 -2
- package/DataRecordsController.js +369 -377
- package/DataRecordsController.js.map +1 -1
- package/DataRecordsStore.d.ts +1 -1
- package/DataRecordsStore.js +1 -1
- package/DataRecordsStore.js.map +1 -1
- package/EventRecordsController.js +226 -240
- package/EventRecordsController.js.map +1 -1
- package/FileRecordsController.d.ts +13 -2
- package/FileRecordsController.js +458 -450
- package/FileRecordsController.js.map +1 -1
- package/GoogleAIChatInterface.js +133 -179
- package/GoogleAIChatInterface.js.map +1 -1
- package/LivekitController.js +43 -54
- package/LivekitController.js.map +1 -1
- package/LoomController.js +64 -75
- package/LoomController.js.map +1 -1
- package/MemoryAuthMessenger.js +10 -23
- package/MemoryAuthMessenger.js.map +1 -1
- package/MemoryCache.js +18 -35
- package/MemoryCache.js.map +1 -1
- package/MemoryFileRecordsLookup.js +105 -125
- package/MemoryFileRecordsLookup.js.map +1 -1
- package/MemoryModerationJobProvider.js +17 -30
- package/MemoryModerationJobProvider.js.map +1 -1
- package/MemoryRateLimiter.js +12 -27
- package/MemoryRateLimiter.js.map +1 -1
- package/MemoryStore.d.ts +18 -6
- package/MemoryStore.js +1879 -1997
- package/MemoryStore.js.map +1 -1
- package/MetricsStore.d.ts +2 -2
- package/ModerationController.js +186 -200
- package/ModerationController.js.map +1 -1
- package/OpenAIChatInterface.js +105 -135
- package/OpenAIChatInterface.js.map +1 -1
- package/OpenAIImageInterface.js +57 -51
- package/OpenAIImageInterface.js.map +1 -1
- package/PolicyController.d.ts +150 -10
- package/PolicyController.js +1546 -1299
- package/PolicyController.js.map +1 -1
- package/PolicyStore.d.ts +110 -2
- package/PolicyStore.js +36 -1
- package/PolicyStore.js.map +1 -1
- package/PrivoClient.js +398 -435
- package/PrivoClient.js.map +1 -1
- package/RateLimitController.js +25 -36
- package/RateLimitController.js.map +1 -1
- package/RecordsClient.js +51 -74
- package/RecordsClient.js.map +1 -1
- package/RecordsController.d.ts +2 -42
- package/RecordsController.js +1026 -1182
- package/RecordsController.js.map +1 -1
- package/RecordsServer.d.ts +196 -27
- package/RecordsServer.js +1701 -1343
- package/RecordsServer.js.map +1 -1
- package/RecordsStore.d.ts +1 -10
- package/RecordsStore.js.map +1 -1
- package/ServerConfig.d.ts +339 -195
- package/ServerConfig.js +13 -0
- package/ServerConfig.js.map +1 -1
- package/SloydInterface.js +62 -75
- package/SloydInterface.js.map +1 -1
- package/StabilityAIImageInterface.js +150 -167
- package/StabilityAIImageInterface.js.map +1 -1
- package/SubscriptionConfigBuilder.d.ts +6 -1
- package/SubscriptionConfigBuilder.js +22 -0
- package/SubscriptionConfigBuilder.js.map +1 -1
- package/SubscriptionConfiguration.d.ts +266 -169
- package/SubscriptionConfiguration.js +101 -79
- package/SubscriptionConfiguration.js.map +1 -1
- package/SubscriptionController.d.ts +2 -1
- package/SubscriptionController.js +643 -650
- package/SubscriptionController.js.map +1 -1
- package/SystemNotificationMessenger.d.ts +21 -4
- package/SystemNotificationMessenger.js +36 -30
- package/SystemNotificationMessenger.js.map +1 -1
- package/TestUtils.d.ts +9 -1
- package/TestUtils.js +105 -129
- package/TestUtils.js.map +1 -1
- package/Utils.d.ts +2 -16
- package/Utils.js +21 -22
- package/Utils.js.map +1 -1
- package/crud/CrudHelpers.js +17 -26
- package/crud/CrudHelpers.js.map +1 -1
- package/crud/CrudRecordsController.d.ts +1 -1
- package/crud/CrudRecordsController.js +259 -267
- package/crud/CrudRecordsController.js.map +1 -1
- package/crud/CrudRecordsControllerTests.js +174 -185
- package/crud/CrudRecordsControllerTests.js.map +1 -1
- package/crud/CrudRecordsStore.d.ts +7 -3
- package/crud/MemoryCrudRecordsStore.d.ts +4 -4
- package/crud/MemoryCrudRecordsStore.js +98 -118
- package/crud/MemoryCrudRecordsStore.js.map +1 -1
- package/crud/sub/MemorySubCrudRecordsStore.d.ts +24 -0
- package/crud/sub/MemorySubCrudRecordsStore.js +146 -0
- package/crud/sub/MemorySubCrudRecordsStore.js.map +1 -0
- package/crud/sub/SubCrudRecordsController.d.ts +182 -0
- package/crud/sub/SubCrudRecordsController.js +360 -0
- package/crud/sub/SubCrudRecordsController.js.map +1 -0
- package/crud/sub/SubCrudRecordsControllerTests.d.ts +39 -0
- package/crud/sub/SubCrudRecordsControllerTests.js +821 -0
- package/crud/sub/SubCrudRecordsControllerTests.js.map +1 -0
- package/crud/sub/SubCrudRecordsStore.d.ts +95 -0
- package/{forms/index.js → crud/sub/SubCrudRecordsStore.js} +2 -2
- package/crud/sub/SubCrudRecordsStore.js.map +1 -0
- package/crud/sub/index.d.ts +3 -0
- package/crud/sub/index.js +20 -0
- package/{forms → crud/sub}/index.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/notifications/MemoryNotificationRecordsStore.js +189 -198
- package/notifications/MemoryNotificationRecordsStore.js.map +1 -1
- package/notifications/NotificationRecordsController.js +438 -460
- package/notifications/NotificationRecordsController.js.map +1 -1
- package/notifications/NotificationRecordsStore.d.ts +2 -1
- package/notifications/WebPushInterface.d.ts +0 -1
- package/notifications/WebPushInterface.js +0 -1
- package/notifications/WebPushInterface.js.map +1 -1
- package/package.json +6 -6
- package/packages/MemoryPackageRecordsStore.d.ts +10 -0
- package/packages/MemoryPackageRecordsStore.js +38 -0
- package/packages/MemoryPackageRecordsStore.js.map +1 -0
- package/packages/PackageRecordsController.d.ts +26 -0
- package/packages/PackageRecordsController.js +49 -0
- package/packages/PackageRecordsController.js.map +1 -0
- package/packages/PackageRecordsStore.d.ts +32 -0
- package/packages/PackageRecordsStore.js +19 -0
- package/packages/PackageRecordsStore.js.map +1 -0
- package/packages/index.d.ts +4 -0
- package/packages/index.js +21 -0
- package/packages/index.js.map +1 -0
- package/packages/version/MemoryPackageVersionRecordsStore.d.ts +21 -0
- package/packages/version/MemoryPackageVersionRecordsStore.js +177 -0
- package/packages/version/MemoryPackageVersionRecordsStore.js.map +1 -0
- package/packages/version/PackageVersionRecordsController.d.ts +144 -0
- package/packages/version/PackageVersionRecordsController.js +656 -0
- package/packages/version/PackageVersionRecordsController.js.map +1 -0
- package/packages/version/PackageVersionRecordsStore.d.ts +342 -0
- package/packages/version/PackageVersionRecordsStore.js +126 -0
- package/packages/version/PackageVersionRecordsStore.js.map +1 -0
- package/packages/version/index.d.ts +4 -0
- package/packages/version/index.js +21 -0
- package/packages/version/index.js.map +1 -0
- package/tracing/TracingDecorators.js +31 -40
- package/tracing/TracingDecorators.js.map +1 -1
- package/webhooks/MemoryWebhookRecordsStore.js +56 -72
- package/webhooks/MemoryWebhookRecordsStore.js.map +1 -1
- package/webhooks/WebhookEnvironment.d.ts +3 -3
- package/webhooks/WebhookRecordsController.d.ts +2 -1
- package/webhooks/WebhookRecordsController.js +389 -382
- package/webhooks/WebhookRecordsController.js.map +1 -1
- package/webhooks/WebhookRecordsStore.d.ts +2 -1
- package/websockets/InstRecordsStore.d.ts +50 -0
- package/websockets/InstRecordsStore.js +17 -0
- package/websockets/InstRecordsStore.js.map +1 -1
- package/websockets/MemoryTempInstRecordsStore.d.ts +5 -0
- package/websockets/MemoryTempInstRecordsStore.js +168 -179
- package/websockets/MemoryTempInstRecordsStore.js.map +1 -1
- package/websockets/MemoryWebsocketConnectionStore.js +98 -135
- package/websockets/MemoryWebsocketConnectionStore.js.map +1 -1
- package/websockets/MemoryWebsocketMessenger.js +29 -48
- package/websockets/MemoryWebsocketMessenger.js.map +1 -1
- package/websockets/SplitInstRecordsStore.d.ts +4 -1
- package/websockets/SplitInstRecordsStore.js +167 -185
- package/websockets/SplitInstRecordsStore.js.map +1 -1
- package/websockets/TemporaryInstRecordsStore.d.ts +19 -1
- package/websockets/TemporaryInstRecordsStore.js +17 -0
- package/websockets/TemporaryInstRecordsStore.js.map +1 -1
- package/websockets/WebsocketController.d.ts +147 -3
- package/websockets/WebsocketController.js +1735 -1391
- package/websockets/WebsocketController.js.map +1 -1
- package/websockets/index.d.ts +0 -1
- package/websockets/index.js +0 -1
- package/websockets/index.js.map +1 -1
- package/AAGUID.d.ts +0 -11
- package/AAGUID.js +0 -116
- package/AAGUID.js.map +0 -1
- package/AuthUtils.d.ts +0 -162
- package/AuthUtils.js +0 -327
- package/AuthUtils.js.map +0 -1
- package/forms/FormError.d.ts +0 -43
- package/forms/FormError.js +0 -56
- package/forms/FormError.js.map +0 -1
- package/forms/index.d.ts +0 -2
- package/websockets/Utils.d.ts +0 -33
- package/websockets/Utils.js +0 -82
- package/websockets/Utils.js.map +0 -1
package/DataRecordsController.js
CHANGED
|
@@ -4,16 +4,7 @@ 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
|
-
|
|
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
|
-
import { doesSubjectMatchPolicy, isValidUserPolicy, } from './DataRecordsStore';
|
|
7
|
+
import { doesSubjectMatchPolicy, isValidUserPolicy } from './DataRecordsStore';
|
|
17
8
|
import { getMarkerResourcesForCreation, getMarkerResourcesForUpdate, } from './PolicyController';
|
|
18
9
|
import { ACCOUNT_MARKER, PUBLIC_READ_MARKER, hasValue, } from '@casual-simulation/aux-common';
|
|
19
10
|
import { getSubscriptionFeatures } from './SubscriptionConfiguration';
|
|
@@ -49,185 +40,186 @@ export class DataRecordsController {
|
|
|
49
40
|
* @param markers The list of markers that should be applied to the new record. If null, then the publicRead marker will be applied.
|
|
50
41
|
* @param instances The list of instances that are currently loaded.
|
|
51
42
|
*/
|
|
52
|
-
recordData(recordKeyOrRecordName, address, data, subjectId, updatePolicy, deletePolicy, markers = null, instances = null) {
|
|
43
|
+
async recordData(recordKeyOrRecordName, address, data, subjectId, updatePolicy, deletePolicy, markers = null, instances = null) {
|
|
53
44
|
var _a, _b, _c, _d;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
45
|
+
try {
|
|
46
|
+
const contextResult = await this._policies.constructAuthorizationContext({
|
|
47
|
+
recordKeyOrRecordName,
|
|
48
|
+
userId: subjectId,
|
|
49
|
+
});
|
|
50
|
+
if (contextResult.success === false) {
|
|
51
|
+
return contextResult;
|
|
52
|
+
}
|
|
53
|
+
const policy = contextResult.context.subjectPolicy;
|
|
54
|
+
if (!subjectId && policy !== 'subjectless') {
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
errorCode: 'not_logged_in',
|
|
58
|
+
errorMessage: 'The user must be logged in in order to record data.',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (policy === 'subjectless') {
|
|
62
|
+
subjectId = null;
|
|
63
|
+
}
|
|
64
|
+
if (!updatePolicy) {
|
|
65
|
+
updatePolicy = true;
|
|
66
|
+
}
|
|
67
|
+
if (!deletePolicy) {
|
|
68
|
+
deletePolicy = true;
|
|
69
|
+
}
|
|
70
|
+
if (!isValidUserPolicy(updatePolicy)) {
|
|
71
|
+
return {
|
|
72
|
+
success: false,
|
|
73
|
+
errorCode: 'invalid_update_policy',
|
|
74
|
+
errorMessage: 'The given updatePolicy is invalid or not supported.',
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (!isValidUserPolicy(deletePolicy)) {
|
|
78
|
+
return {
|
|
79
|
+
success: false,
|
|
80
|
+
errorCode: 'invalid_delete_policy',
|
|
81
|
+
errorMessage: 'The given deletePolicy is invalid or not supported.',
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (policy === 'subjectless') {
|
|
85
|
+
if (updatePolicy !== true) {
|
|
65
86
|
return {
|
|
66
87
|
success: false,
|
|
67
|
-
errorCode: '
|
|
68
|
-
errorMessage: '
|
|
88
|
+
errorCode: 'invalid_record_key',
|
|
89
|
+
errorMessage: 'It is not possible to set update policies using a subjectless key.',
|
|
69
90
|
};
|
|
70
91
|
}
|
|
71
|
-
if (
|
|
72
|
-
subjectId = null;
|
|
73
|
-
}
|
|
74
|
-
if (!updatePolicy) {
|
|
75
|
-
updatePolicy = true;
|
|
76
|
-
}
|
|
77
|
-
if (!deletePolicy) {
|
|
78
|
-
deletePolicy = true;
|
|
79
|
-
}
|
|
80
|
-
if (!isValidUserPolicy(updatePolicy)) {
|
|
92
|
+
if (deletePolicy !== true) {
|
|
81
93
|
return {
|
|
82
94
|
success: false,
|
|
83
|
-
errorCode: '
|
|
84
|
-
errorMessage: '
|
|
95
|
+
errorCode: 'invalid_record_key',
|
|
96
|
+
errorMessage: 'It is not possible to set delete policies using a subjectless key.',
|
|
85
97
|
};
|
|
86
98
|
}
|
|
87
|
-
|
|
99
|
+
}
|
|
100
|
+
const recordName = contextResult.context.recordName;
|
|
101
|
+
const existingRecord = await this._store.getData(recordName, address);
|
|
102
|
+
if (existingRecord.success) {
|
|
103
|
+
const existingUpdatePolicy = (_a = existingRecord.updatePolicy) !== null && _a !== void 0 ? _a : true;
|
|
104
|
+
if (!doesSubjectMatchPolicy(existingUpdatePolicy, subjectId)) {
|
|
88
105
|
return {
|
|
89
106
|
success: false,
|
|
90
|
-
errorCode: '
|
|
91
|
-
errorMessage: 'The
|
|
107
|
+
errorCode: 'not_authorized',
|
|
108
|
+
errorMessage: 'The updatePolicy does not permit this user to update the data record.',
|
|
92
109
|
};
|
|
93
110
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
success: false,
|
|
117
|
-
errorCode: 'not_authorized',
|
|
118
|
-
errorMessage: 'The updatePolicy does not permit this user to update the data record.',
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
let resourceMarkers;
|
|
123
|
-
if (existingRecord.success) {
|
|
124
|
-
const existingMarkers = (_b = existingRecord.markers) !== null && _b !== void 0 ? _b : [
|
|
125
|
-
PUBLIC_READ_MARKER,
|
|
126
|
-
];
|
|
127
|
-
resourceMarkers = markers !== null && markers !== void 0 ? markers : existingMarkers;
|
|
128
|
-
const authorization = yield this._policies.authorizeUserAndInstancesForResources(contextResult.context, {
|
|
129
|
-
userId: subjectId,
|
|
130
|
-
instances,
|
|
131
|
-
resources: [
|
|
132
|
-
{
|
|
133
|
-
resourceKind: 'data',
|
|
134
|
-
resourceId: address,
|
|
135
|
-
action: 'update',
|
|
136
|
-
markers: resourceMarkers,
|
|
137
|
-
},
|
|
138
|
-
...getMarkerResourcesForUpdate(existingMarkers, markers),
|
|
139
|
-
],
|
|
140
|
-
});
|
|
141
|
-
if (authorization.success === false) {
|
|
142
|
-
return authorization;
|
|
143
|
-
}
|
|
111
|
+
}
|
|
112
|
+
let resourceMarkers;
|
|
113
|
+
if (existingRecord.success) {
|
|
114
|
+
const existingMarkers = (_b = existingRecord.markers) !== null && _b !== void 0 ? _b : [
|
|
115
|
+
PUBLIC_READ_MARKER,
|
|
116
|
+
];
|
|
117
|
+
resourceMarkers = markers !== null && markers !== void 0 ? markers : existingMarkers;
|
|
118
|
+
const authorization = await this._policies.authorizeUserAndInstancesForResources(contextResult.context, {
|
|
119
|
+
userId: subjectId,
|
|
120
|
+
instances,
|
|
121
|
+
resources: [
|
|
122
|
+
{
|
|
123
|
+
resourceKind: 'data',
|
|
124
|
+
resourceId: address,
|
|
125
|
+
action: 'update',
|
|
126
|
+
markers: resourceMarkers,
|
|
127
|
+
},
|
|
128
|
+
...getMarkerResourcesForUpdate(existingMarkers, markers),
|
|
129
|
+
],
|
|
130
|
+
});
|
|
131
|
+
if (authorization.success === false) {
|
|
132
|
+
return authorization;
|
|
144
133
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
resourceMarkers = markers !== null && markers !== void 0 ? markers : [PUBLIC_READ_MARKER];
|
|
137
|
+
const authorization = await this._policies.authorizeUserAndInstancesForResources(contextResult.context, {
|
|
138
|
+
userId: subjectId,
|
|
139
|
+
instances,
|
|
140
|
+
resources: [
|
|
141
|
+
{
|
|
142
|
+
resourceKind: 'data',
|
|
143
|
+
resourceId: address,
|
|
144
|
+
action: 'create',
|
|
145
|
+
markers: resourceMarkers,
|
|
146
|
+
},
|
|
147
|
+
...getMarkerResourcesForCreation(resourceMarkers),
|
|
148
|
+
],
|
|
149
|
+
});
|
|
150
|
+
if (authorization.success === false) {
|
|
151
|
+
return authorization;
|
|
163
152
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
153
|
+
}
|
|
154
|
+
const metricsResult = await this._metrics.getSubscriptionDataMetricsByRecordName(recordName);
|
|
155
|
+
const config = await this._config.getSubscriptionConfiguration();
|
|
156
|
+
const features = getSubscriptionFeatures(config, metricsResult.subscriptionStatus, metricsResult.subscriptionId, metricsResult.ownerId ? 'user' : 'studio');
|
|
157
|
+
if (!features.data.allowed) {
|
|
158
|
+
return {
|
|
159
|
+
success: false,
|
|
160
|
+
errorCode: 'not_authorized',
|
|
161
|
+
errorMessage: 'The subscription does not permit the recording of data.',
|
|
162
|
+
errorReason: 'data_not_allowed',
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (hasValue(features.data.maxItemSizeInBytes)) {
|
|
166
|
+
const dataString = typeof data === 'string' ? data : stringify(data);
|
|
167
|
+
const size = byteLengthOfString(dataString);
|
|
168
|
+
const schema = z.number().max(features.data.maxItemSizeInBytes);
|
|
169
|
+
const result = schema.safeParse(size, {
|
|
170
|
+
path: ['data', 'sizeInBytes'],
|
|
171
|
+
});
|
|
172
|
+
if (result.success === false) {
|
|
168
173
|
return {
|
|
169
174
|
success: false,
|
|
170
|
-
errorCode: '
|
|
171
|
-
errorMessage: 'The
|
|
172
|
-
errorReason: '
|
|
175
|
+
errorCode: 'subscription_limit_reached',
|
|
176
|
+
errorMessage: 'The size of the item is larger than the subscription allows.',
|
|
177
|
+
errorReason: 'data_too_large',
|
|
178
|
+
issues: result.error.issues,
|
|
173
179
|
};
|
|
174
180
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
});
|
|
182
|
-
if (result.success === false) {
|
|
181
|
+
}
|
|
182
|
+
if (!existingRecord.success) {
|
|
183
|
+
// Check metrics
|
|
184
|
+
if (hasValue(features.data.maxItems) &&
|
|
185
|
+
features.data.maxItems > 0) {
|
|
186
|
+
if (metricsResult.totalItems >= features.data.maxItems) {
|
|
183
187
|
return {
|
|
184
188
|
success: false,
|
|
185
189
|
errorCode: 'subscription_limit_reached',
|
|
186
|
-
errorMessage: 'The
|
|
187
|
-
errorReason: '
|
|
188
|
-
issues: result.error.issues,
|
|
190
|
+
errorMessage: 'The maximum number of items has been reached for your subscription.',
|
|
191
|
+
errorReason: 'too_many_items',
|
|
189
192
|
};
|
|
190
193
|
}
|
|
191
194
|
}
|
|
192
|
-
if (!existingRecord.success) {
|
|
193
|
-
// Check metrics
|
|
194
|
-
if (features.data.maxItems > 0) {
|
|
195
|
-
if (metricsResult.totalItems >= features.data.maxItems) {
|
|
196
|
-
return {
|
|
197
|
-
success: false,
|
|
198
|
-
errorCode: 'subscription_limit_reached',
|
|
199
|
-
errorMessage: 'The maximum number of items has been reached for your subscription.',
|
|
200
|
-
errorReason: 'too_many_items',
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
const result2 = yield this._store.setData(recordName, address, data, (_d = (_c = contextResult.context.recordKeyCreatorId) !== null && _c !== void 0 ? _c : subjectId) !== null && _d !== void 0 ? _d : contextResult.context.recordOwnerId, subjectId, updatePolicy, deletePolicy, resourceMarkers);
|
|
206
|
-
if (result2.success === false) {
|
|
207
|
-
return {
|
|
208
|
-
success: false,
|
|
209
|
-
errorCode: result2.errorCode,
|
|
210
|
-
errorMessage: result2.errorMessage,
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
return {
|
|
214
|
-
success: true,
|
|
215
|
-
recordName: recordName,
|
|
216
|
-
address: address,
|
|
217
|
-
};
|
|
218
195
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
222
|
-
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
223
|
-
console.error(`[DataRecordsController] A server error occurred while recording data:`, err);
|
|
196
|
+
const result2 = await this._store.setData(recordName, address, data, (_d = (_c = contextResult.context.recordKeyCreatorId) !== null && _c !== void 0 ? _c : subjectId) !== null && _d !== void 0 ? _d : contextResult.context.recordOwnerId, subjectId, updatePolicy, deletePolicy, resourceMarkers);
|
|
197
|
+
if (result2.success === false) {
|
|
224
198
|
return {
|
|
225
199
|
success: false,
|
|
226
|
-
errorCode:
|
|
227
|
-
errorMessage:
|
|
200
|
+
errorCode: result2.errorCode,
|
|
201
|
+
errorMessage: result2.errorMessage,
|
|
228
202
|
};
|
|
229
203
|
}
|
|
230
|
-
|
|
204
|
+
return {
|
|
205
|
+
success: true,
|
|
206
|
+
recordName: recordName,
|
|
207
|
+
address: address,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
const span = trace.getActiveSpan();
|
|
212
|
+
if (err instanceof Error) {
|
|
213
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
214
|
+
}
|
|
215
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
216
|
+
console.error(`[DataRecordsController] A server error occurred while recording data:`, err);
|
|
217
|
+
return {
|
|
218
|
+
success: false,
|
|
219
|
+
errorCode: 'server_error',
|
|
220
|
+
errorMessage: 'A server error occurred.',
|
|
221
|
+
};
|
|
222
|
+
}
|
|
231
223
|
}
|
|
232
224
|
/**
|
|
233
225
|
* Gets the data that is stored in the given record at the given address.
|
|
@@ -236,62 +228,62 @@ export class DataRecordsController {
|
|
|
236
228
|
* @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.
|
|
237
229
|
* @param instances The list of instances that are loaded.
|
|
238
230
|
*/
|
|
239
|
-
getData(recordName, address, userId, instances) {
|
|
231
|
+
async getData(recordName, address, userId, instances) {
|
|
240
232
|
var _a, _b, _c;
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return context;
|
|
251
|
-
}
|
|
252
|
-
const result = yield this._store.getData(context.context.recordName, address);
|
|
253
|
-
if (result.success === false) {
|
|
254
|
-
return {
|
|
255
|
-
success: false,
|
|
256
|
-
errorCode: result.errorCode,
|
|
257
|
-
errorMessage: result.errorMessage,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
const markers = (_a = result.markers) !== null && _a !== void 0 ? _a : [PUBLIC_READ_MARKER];
|
|
261
|
-
const authorization = yield this._policies.authorizeUserAndInstances(context.context, {
|
|
262
|
-
userId: userId,
|
|
263
|
-
instances,
|
|
264
|
-
resourceKind: 'data',
|
|
265
|
-
resourceId: address,
|
|
266
|
-
action: 'read',
|
|
267
|
-
markers: markers,
|
|
268
|
-
});
|
|
269
|
-
if (authorization.success === false) {
|
|
270
|
-
return authorization;
|
|
271
|
-
}
|
|
272
|
-
return {
|
|
273
|
-
success: true,
|
|
274
|
-
data: result.data,
|
|
275
|
-
publisherId: result.publisherId,
|
|
276
|
-
subjectId: result.subjectId,
|
|
277
|
-
recordName,
|
|
278
|
-
updatePolicy: (_b = result.updatePolicy) !== null && _b !== void 0 ? _b : true,
|
|
279
|
-
deletePolicy: (_c = result.deletePolicy) !== null && _c !== void 0 ? _c : true,
|
|
280
|
-
markers: markers,
|
|
281
|
-
};
|
|
233
|
+
try {
|
|
234
|
+
const baseRequest = {
|
|
235
|
+
recordKeyOrRecordName: recordName,
|
|
236
|
+
userId,
|
|
237
|
+
instances,
|
|
238
|
+
};
|
|
239
|
+
const context = await this._policies.constructAuthorizationContext(baseRequest);
|
|
240
|
+
if (context.success === false) {
|
|
241
|
+
return context;
|
|
282
242
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
286
|
-
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
287
|
-
console.error('[DataRecordsController] An error occurred while getting data:', err);
|
|
243
|
+
const result = await this._store.getData(context.context.recordName, address);
|
|
244
|
+
if (result.success === false) {
|
|
288
245
|
return {
|
|
289
246
|
success: false,
|
|
290
|
-
errorCode:
|
|
291
|
-
errorMessage:
|
|
247
|
+
errorCode: result.errorCode,
|
|
248
|
+
errorMessage: result.errorMessage,
|
|
292
249
|
};
|
|
293
250
|
}
|
|
294
|
-
|
|
251
|
+
const markers = (_a = result.markers) !== null && _a !== void 0 ? _a : [PUBLIC_READ_MARKER];
|
|
252
|
+
const authorization = await this._policies.authorizeUserAndInstances(context.context, {
|
|
253
|
+
userId: userId,
|
|
254
|
+
instances,
|
|
255
|
+
resourceKind: 'data',
|
|
256
|
+
resourceId: address,
|
|
257
|
+
action: 'read',
|
|
258
|
+
markers: markers,
|
|
259
|
+
});
|
|
260
|
+
if (authorization.success === false) {
|
|
261
|
+
return authorization;
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
success: true,
|
|
265
|
+
data: result.data,
|
|
266
|
+
publisherId: result.publisherId,
|
|
267
|
+
subjectId: result.subjectId,
|
|
268
|
+
recordName,
|
|
269
|
+
updatePolicy: (_b = result.updatePolicy) !== null && _b !== void 0 ? _b : true,
|
|
270
|
+
deletePolicy: (_c = result.deletePolicy) !== null && _c !== void 0 ? _c : true,
|
|
271
|
+
markers: markers,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
catch (err) {
|
|
275
|
+
const span = trace.getActiveSpan();
|
|
276
|
+
if (err instanceof Error) {
|
|
277
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
278
|
+
}
|
|
279
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
280
|
+
console.error('[DataRecordsController] An error occurred while getting data:', err);
|
|
281
|
+
return {
|
|
282
|
+
success: false,
|
|
283
|
+
errorCode: 'server_error',
|
|
284
|
+
errorMessage: 'A server error occurred.',
|
|
285
|
+
};
|
|
286
|
+
}
|
|
295
287
|
}
|
|
296
288
|
/**
|
|
297
289
|
* Lists some data from the given record, starting after the given address.
|
|
@@ -300,114 +292,114 @@ export class DataRecordsController {
|
|
|
300
292
|
* @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.
|
|
301
293
|
* @param instances The instances that are loaded.
|
|
302
294
|
*/
|
|
303
|
-
listData(recordName, address, userId, instances) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
return context;
|
|
314
|
-
}
|
|
315
|
-
const authorization = yield this._policies.authorizeUserAndInstances(context.context, {
|
|
316
|
-
userId,
|
|
317
|
-
instances,
|
|
318
|
-
resourceKind: 'data',
|
|
319
|
-
action: 'list',
|
|
320
|
-
markers: [ACCOUNT_MARKER],
|
|
321
|
-
});
|
|
322
|
-
const result2 = yield this._store.listData(context.context.recordName, address);
|
|
323
|
-
if (result2.success === false) {
|
|
324
|
-
return {
|
|
325
|
-
success: false,
|
|
326
|
-
errorCode: result2.errorCode,
|
|
327
|
-
errorMessage: result2.errorMessage,
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
if (authorization.success === false) {
|
|
331
|
-
return authorization;
|
|
332
|
-
}
|
|
333
|
-
return {
|
|
334
|
-
success: true,
|
|
335
|
-
recordName: context.context.recordName,
|
|
336
|
-
items: result2.items,
|
|
337
|
-
totalCount: result2.totalCount,
|
|
338
|
-
};
|
|
295
|
+
async listData(recordName, address, userId, instances) {
|
|
296
|
+
try {
|
|
297
|
+
const baseRequest = {
|
|
298
|
+
recordKeyOrRecordName: recordName,
|
|
299
|
+
userId,
|
|
300
|
+
instances,
|
|
301
|
+
};
|
|
302
|
+
const context = await this._policies.constructAuthorizationContext(baseRequest);
|
|
303
|
+
if (context.success === false) {
|
|
304
|
+
return context;
|
|
339
305
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
306
|
+
const authorization = await this._policies.authorizeUserAndInstances(context.context, {
|
|
307
|
+
userId,
|
|
308
|
+
instances,
|
|
309
|
+
resourceKind: 'data',
|
|
310
|
+
action: 'list',
|
|
311
|
+
markers: [ACCOUNT_MARKER],
|
|
312
|
+
});
|
|
313
|
+
const result2 = await this._store.listData(context.context.recordName, address);
|
|
314
|
+
if (result2.success === false) {
|
|
345
315
|
return {
|
|
346
316
|
success: false,
|
|
347
|
-
errorCode:
|
|
348
|
-
errorMessage:
|
|
317
|
+
errorCode: result2.errorCode,
|
|
318
|
+
errorMessage: result2.errorMessage,
|
|
349
319
|
};
|
|
350
320
|
}
|
|
351
|
-
|
|
321
|
+
if (authorization.success === false) {
|
|
322
|
+
return authorization;
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
success: true,
|
|
326
|
+
recordName: context.context.recordName,
|
|
327
|
+
items: result2.items,
|
|
328
|
+
totalCount: result2.totalCount,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
catch (err) {
|
|
332
|
+
const span = trace.getActiveSpan();
|
|
333
|
+
if (err instanceof Error) {
|
|
334
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
335
|
+
}
|
|
336
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
337
|
+
console.error('[DataRecordsController] An error occurred while listing data:', err);
|
|
338
|
+
return {
|
|
339
|
+
success: false,
|
|
340
|
+
errorCode: 'server_error',
|
|
341
|
+
errorMessage: 'A server error occurred.',
|
|
342
|
+
};
|
|
343
|
+
}
|
|
352
344
|
}
|
|
353
345
|
/**
|
|
354
346
|
* Lists some data from the given record, filtered by the given marker and starting at the given address.
|
|
355
347
|
* @param request The request that should be used to list the data.
|
|
356
348
|
*/
|
|
357
|
-
listDataByMarker(request) {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
return context;
|
|
367
|
-
}
|
|
368
|
-
const authorization = yield this._policies.authorizeUserAndInstances(context.context, {
|
|
369
|
-
userId: context.context.userId,
|
|
370
|
-
instances: request.instances,
|
|
371
|
-
resourceKind: 'data',
|
|
372
|
-
action: 'list',
|
|
373
|
-
markers: [request.marker],
|
|
374
|
-
});
|
|
375
|
-
const result2 = yield this._store.listDataByMarker({
|
|
376
|
-
recordName: context.context.recordName,
|
|
377
|
-
marker: request.marker,
|
|
378
|
-
startingAddress: request.startingAddress,
|
|
379
|
-
sort: request.sort,
|
|
380
|
-
});
|
|
381
|
-
if (result2.success === false) {
|
|
382
|
-
return {
|
|
383
|
-
success: false,
|
|
384
|
-
errorCode: result2.errorCode,
|
|
385
|
-
errorMessage: result2.errorMessage,
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
if (authorization.success === false) {
|
|
389
|
-
return authorization;
|
|
390
|
-
}
|
|
391
|
-
return {
|
|
392
|
-
success: true,
|
|
393
|
-
recordName: context.context.recordName,
|
|
394
|
-
items: result2.items,
|
|
395
|
-
totalCount: result2.totalCount,
|
|
396
|
-
marker: result2.marker,
|
|
397
|
-
};
|
|
349
|
+
async listDataByMarker(request) {
|
|
350
|
+
try {
|
|
351
|
+
const baseRequest = {
|
|
352
|
+
recordKeyOrRecordName: request.recordKeyOrName,
|
|
353
|
+
userId: request.userId,
|
|
354
|
+
};
|
|
355
|
+
const context = await this._policies.constructAuthorizationContext(baseRequest);
|
|
356
|
+
if (context.success === false) {
|
|
357
|
+
return context;
|
|
398
358
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
359
|
+
const authorization = await this._policies.authorizeUserAndInstances(context.context, {
|
|
360
|
+
userId: context.context.userId,
|
|
361
|
+
instances: request.instances,
|
|
362
|
+
resourceKind: 'data',
|
|
363
|
+
action: 'list',
|
|
364
|
+
markers: [request.marker],
|
|
365
|
+
});
|
|
366
|
+
const result2 = await this._store.listDataByMarker({
|
|
367
|
+
recordName: context.context.recordName,
|
|
368
|
+
marker: request.marker,
|
|
369
|
+
startingAddress: request.startingAddress,
|
|
370
|
+
sort: request.sort,
|
|
371
|
+
});
|
|
372
|
+
if (result2.success === false) {
|
|
404
373
|
return {
|
|
405
374
|
success: false,
|
|
406
|
-
errorCode:
|
|
407
|
-
errorMessage:
|
|
375
|
+
errorCode: result2.errorCode,
|
|
376
|
+
errorMessage: result2.errorMessage,
|
|
408
377
|
};
|
|
409
378
|
}
|
|
410
|
-
|
|
379
|
+
if (authorization.success === false) {
|
|
380
|
+
return authorization;
|
|
381
|
+
}
|
|
382
|
+
return {
|
|
383
|
+
success: true,
|
|
384
|
+
recordName: context.context.recordName,
|
|
385
|
+
items: result2.items,
|
|
386
|
+
totalCount: result2.totalCount,
|
|
387
|
+
marker: result2.marker,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
catch (err) {
|
|
391
|
+
const span = trace.getActiveSpan();
|
|
392
|
+
if (err instanceof Error) {
|
|
393
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
394
|
+
}
|
|
395
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
396
|
+
console.error('[DataRecordsController] An error occurred while listing data by marker:', err);
|
|
397
|
+
return {
|
|
398
|
+
success: false,
|
|
399
|
+
errorCode: 'server_error',
|
|
400
|
+
errorMessage: 'A server error occurred.',
|
|
401
|
+
};
|
|
402
|
+
}
|
|
411
403
|
}
|
|
412
404
|
/**
|
|
413
405
|
* Erases the data in the given record and address.
|
|
@@ -417,91 +409,91 @@ export class DataRecordsController {
|
|
|
417
409
|
* @param subjectId The ID of the user that this request came from.
|
|
418
410
|
* @param instances The instances that are loaded.
|
|
419
411
|
*/
|
|
420
|
-
eraseData(recordKeyOrName, address, subjectId, instances) {
|
|
412
|
+
async eraseData(recordKeyOrName, address, subjectId, instances) {
|
|
421
413
|
var _a, _b;
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
!doesSubjectMatchPolicy(existingDeletePolicy, subjectId)) {
|
|
472
|
-
return {
|
|
473
|
-
success: false,
|
|
474
|
-
errorCode: 'not_authorized',
|
|
475
|
-
errorMessage: 'The deletePolicy does not permit this user to erase the data record.',
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
const result2 = yield this._store.eraseData(recordName, address);
|
|
480
|
-
if (result2.success === false) {
|
|
414
|
+
try {
|
|
415
|
+
const context = await this._policies.constructAuthorizationContext({
|
|
416
|
+
recordKeyOrRecordName: recordKeyOrName,
|
|
417
|
+
userId: subjectId,
|
|
418
|
+
});
|
|
419
|
+
if (context.success === false) {
|
|
420
|
+
return context;
|
|
421
|
+
}
|
|
422
|
+
const policy = context.context.subjectPolicy;
|
|
423
|
+
if (!subjectId && policy !== 'subjectless') {
|
|
424
|
+
return {
|
|
425
|
+
success: false,
|
|
426
|
+
errorCode: 'not_logged_in',
|
|
427
|
+
errorMessage: 'The user must be logged in in order to erase data using the provided record key.',
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
if (policy === 'subjectless') {
|
|
431
|
+
subjectId = null;
|
|
432
|
+
}
|
|
433
|
+
const recordName = context.context.recordName;
|
|
434
|
+
const existingRecord = await this._store.getData(recordName, address);
|
|
435
|
+
const markers = (_a = (existingRecord.success
|
|
436
|
+
? existingRecord.markers
|
|
437
|
+
: null)) !== null && _a !== void 0 ? _a : [PUBLIC_READ_MARKER];
|
|
438
|
+
const authorization = await this._policies.authorizeUserAndInstances(context.context, {
|
|
439
|
+
userId: subjectId,
|
|
440
|
+
instances,
|
|
441
|
+
resourceKind: 'data',
|
|
442
|
+
resourceId: address,
|
|
443
|
+
action: 'delete',
|
|
444
|
+
markers: markers,
|
|
445
|
+
});
|
|
446
|
+
// const authorization =
|
|
447
|
+
// await this._policies.authorizeRequestUsingContext(
|
|
448
|
+
// context.context,
|
|
449
|
+
// {
|
|
450
|
+
// action: 'data.delete',
|
|
451
|
+
// ...baseRequest,
|
|
452
|
+
// address,
|
|
453
|
+
// resourceMarkers: markers,
|
|
454
|
+
// }
|
|
455
|
+
// );
|
|
456
|
+
if (authorization.success === false) {
|
|
457
|
+
return authorization;
|
|
458
|
+
}
|
|
459
|
+
if (existingRecord.success) {
|
|
460
|
+
const existingDeletePolicy = (_b = existingRecord.deletePolicy) !== null && _b !== void 0 ? _b : true;
|
|
461
|
+
if (subjectId !== context.context.recordOwnerId &&
|
|
462
|
+
!doesSubjectMatchPolicy(existingDeletePolicy, subjectId)) {
|
|
481
463
|
return {
|
|
482
464
|
success: false,
|
|
483
|
-
errorCode:
|
|
484
|
-
errorMessage:
|
|
465
|
+
errorCode: 'not_authorized',
|
|
466
|
+
errorMessage: 'The deletePolicy does not permit this user to erase the data record.',
|
|
485
467
|
};
|
|
486
468
|
}
|
|
487
|
-
return {
|
|
488
|
-
success: true,
|
|
489
|
-
recordName,
|
|
490
|
-
address,
|
|
491
|
-
};
|
|
492
469
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
496
|
-
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
497
|
-
console.error(`[DataRecordsController] A server error occurred while erasing data:`, err);
|
|
470
|
+
const result2 = await this._store.eraseData(recordName, address);
|
|
471
|
+
if (result2.success === false) {
|
|
498
472
|
return {
|
|
499
473
|
success: false,
|
|
500
|
-
errorCode:
|
|
501
|
-
errorMessage:
|
|
474
|
+
errorCode: result2.errorCode,
|
|
475
|
+
errorMessage: result2.errorMessage,
|
|
502
476
|
};
|
|
503
477
|
}
|
|
504
|
-
|
|
478
|
+
return {
|
|
479
|
+
success: true,
|
|
480
|
+
recordName,
|
|
481
|
+
address,
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
catch (err) {
|
|
485
|
+
const span = trace.getActiveSpan();
|
|
486
|
+
if (err instanceof Error) {
|
|
487
|
+
span === null || span === void 0 ? void 0 : span.recordException(err);
|
|
488
|
+
}
|
|
489
|
+
span === null || span === void 0 ? void 0 : span.setStatus({ code: SpanStatusCode.ERROR });
|
|
490
|
+
console.error(`[DataRecordsController] A server error occurred while erasing data:`, err);
|
|
491
|
+
return {
|
|
492
|
+
success: false,
|
|
493
|
+
errorCode: 'server_error',
|
|
494
|
+
errorMessage: 'A server error occurred.',
|
|
495
|
+
};
|
|
496
|
+
}
|
|
505
497
|
}
|
|
506
498
|
}
|
|
507
499
|
__decorate([
|