@qmuse/appwrite-runtime-sdk 1.0.2 → 1.0.3
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/README.md +15 -0
- package/dist/index.d.ts +1 -1
- package/dist/runtime/AppwriteSessionCoordinator.d.ts +29 -0
- package/dist/runtime/AppwriteSessionCoordinator.js +647 -0
- package/dist/runtime/MutationAuditReporter.d.ts +18 -0
- package/dist/runtime/MutationAuditReporter.js +110 -0
- package/dist/runtime/QmuseAppwriteRuntime.d.ts +22 -0
- package/dist/runtime/QmuseAppwriteRuntime.js +321 -0
- package/dist/runtime/rowData.d.ts +3 -0
- package/dist/runtime/rowData.js +60 -0
- package/dist/runtime/utils.d.ts +11 -0
- package/dist/runtime/utils.js +68 -0
- package/dist/runtime.d.ts +2 -31
- package/dist/runtime.js +2 -996
- package/dist/types.d.ts +32 -0
- package/package.json +1 -1
package/dist/runtime.js
CHANGED
|
@@ -1,998 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
3
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
5
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
6
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
7
|
-
import { ID, Permission, Query, Role } from 'appwrite';
|
|
8
|
-
var BLOCKED_MUTATION_FIELDS = new Set(['code', 'creatorId', 'modifierId', 'gmtCreate', 'gmtModified']);
|
|
9
|
-
var SENSITIVE_AUDIT_FIELD_PATTERN = /(?:password|passwd|secret|token|authorization|cookie|api[-_]?key|access[-_]?key|private[-_]?key)/i;
|
|
10
|
-
var REDACTED_AUDIT_VALUE = '[REDACTED]';
|
|
11
|
-
var MAX_AUDIT_DEPTH = 5;
|
|
12
|
-
var MAX_AUDIT_KEYS = 100;
|
|
13
|
-
var MAX_AUDIT_ARRAY_ITEMS = 100;
|
|
14
|
-
var MAX_AUDIT_STRING_LENGTH = 2048;
|
|
15
|
-
function isRecord(value) {
|
|
16
|
-
return Boolean(value) && _typeof(value) === 'object' && !Array.isArray(value);
|
|
17
|
-
}
|
|
18
|
-
function getErrorCode(error) {
|
|
19
|
-
if (!isRecord(error)) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
var code = Number(error.code);
|
|
23
|
-
return Number.isFinite(code) ? code : null;
|
|
24
|
-
}
|
|
25
|
-
function createResponseError(_ref) {
|
|
26
|
-
var _payload$code, _payload$type;
|
|
27
|
-
var payload = _ref.payload,
|
|
28
|
-
status = _ref.status,
|
|
29
|
-
fallbackMessage = _ref.fallbackMessage,
|
|
30
|
-
fallbackType = _ref.fallbackType;
|
|
31
|
-
var error = new Error(typeof (payload === null || payload === void 0 ? void 0 : payload.message) === 'string' && payload.message ? payload.message : fallbackMessage);
|
|
32
|
-
Object.assign(error, {
|
|
33
|
-
code: (_payload$code = payload === null || payload === void 0 ? void 0 : payload.code) !== null && _payload$code !== void 0 ? _payload$code : status,
|
|
34
|
-
type: (_payload$type = payload === null || payload === void 0 ? void 0 : payload.type) !== null && _payload$type !== void 0 ? _payload$type : fallbackType
|
|
35
|
-
});
|
|
36
|
-
return error;
|
|
37
|
-
}
|
|
38
|
-
function readResponsePayload(_x) {
|
|
39
|
-
return _readResponsePayload.apply(this, arguments);
|
|
40
|
-
}
|
|
41
|
-
function _readResponsePayload() {
|
|
42
|
-
_readResponsePayload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(response) {
|
|
43
|
-
var payload;
|
|
44
|
-
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
45
|
-
while (1) switch (_context21.prev = _context21.next) {
|
|
46
|
-
case 0:
|
|
47
|
-
_context21.next = 2;
|
|
48
|
-
return response.json().catch(function () {
|
|
49
|
-
return null;
|
|
50
|
-
});
|
|
51
|
-
case 2:
|
|
52
|
-
payload = _context21.sent;
|
|
53
|
-
return _context21.abrupt("return", isRecord(payload) ? payload : null);
|
|
54
|
-
case 4:
|
|
55
|
-
case "end":
|
|
56
|
-
return _context21.stop();
|
|
57
|
-
}
|
|
58
|
-
}, _callee21);
|
|
59
|
-
}));
|
|
60
|
-
return _readResponsePayload.apply(this, arguments);
|
|
61
|
-
}
|
|
62
|
-
function sanitizeBusinessRowData(data) {
|
|
63
|
-
return Object.fromEntries(Object.entries(data).filter(function (_ref2) {
|
|
64
|
-
var _ref3 = _slicedToArray(_ref2, 1),
|
|
65
|
-
key = _ref3[0];
|
|
66
|
-
return !key.startsWith('$') && !BLOCKED_MUTATION_FIELDS.has(key);
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
69
|
-
function sanitizeAuditValue(value, depth, ancestors) {
|
|
70
|
-
if (typeof value === 'string') {
|
|
71
|
-
return value.length > MAX_AUDIT_STRING_LENGTH ? "".concat(value.slice(0, MAX_AUDIT_STRING_LENGTH), "[TRUNCATED]") : value;
|
|
72
|
-
}
|
|
73
|
-
if (depth >= MAX_AUDIT_DEPTH && (Array.isArray(value) || isRecord(value))) {
|
|
74
|
-
return '[MAX_DEPTH]';
|
|
75
|
-
}
|
|
76
|
-
if (Array.isArray(value)) {
|
|
77
|
-
if (ancestors.has(value)) {
|
|
78
|
-
return '[CIRCULAR]';
|
|
79
|
-
}
|
|
80
|
-
ancestors.add(value);
|
|
81
|
-
var _result = value.slice(0, MAX_AUDIT_ARRAY_ITEMS).map(function (item) {
|
|
82
|
-
return sanitizeAuditValue(item, depth + 1, ancestors);
|
|
83
|
-
});
|
|
84
|
-
ancestors.delete(value);
|
|
85
|
-
if (value.length > MAX_AUDIT_ARRAY_ITEMS) {
|
|
86
|
-
_result.push('[TRUNCATED]');
|
|
87
|
-
}
|
|
88
|
-
return _result;
|
|
89
|
-
}
|
|
90
|
-
if (!isRecord(value)) {
|
|
91
|
-
return value;
|
|
92
|
-
}
|
|
93
|
-
if (ancestors.has(value)) {
|
|
94
|
-
return '[CIRCULAR]';
|
|
95
|
-
}
|
|
96
|
-
ancestors.add(value);
|
|
97
|
-
var entries = Object.entries(value).slice(0, MAX_AUDIT_KEYS);
|
|
98
|
-
var result = Object.fromEntries(entries.map(function (_ref4) {
|
|
99
|
-
var _ref5 = _slicedToArray(_ref4, 2),
|
|
100
|
-
key = _ref5[0],
|
|
101
|
-
childValue = _ref5[1];
|
|
102
|
-
return [key, SENSITIVE_AUDIT_FIELD_PATTERN.test(key) ? REDACTED_AUDIT_VALUE : sanitizeAuditValue(childValue, depth + 1, ancestors)];
|
|
103
|
-
}));
|
|
104
|
-
ancestors.delete(value);
|
|
105
|
-
if (Object.keys(value).length > MAX_AUDIT_KEYS) {
|
|
106
|
-
result.__auditTruncated = true;
|
|
107
|
-
}
|
|
108
|
-
return result;
|
|
109
|
-
}
|
|
110
|
-
function sanitizeMutationAuditData(data) {
|
|
111
|
-
return sanitizeAuditValue(data, 0, new WeakSet());
|
|
112
|
-
}
|
|
1
|
+
import { QmuseAppwriteRuntime } from "./runtime/QmuseAppwriteRuntime";
|
|
113
2
|
export function createQmuseAppwriteRuntime(options) {
|
|
114
|
-
|
|
115
|
-
var client = options.client,
|
|
116
|
-
account = options.account,
|
|
117
|
-
tablesDB = options.tablesDB;
|
|
118
|
-
var request = (_options$fetch = options.fetch) !== null && _options$fetch !== void 0 ? _options$fetch : globalThis.fetch;
|
|
119
|
-
if (!request) {
|
|
120
|
-
throw new Error('A fetch implementation is required');
|
|
121
|
-
}
|
|
122
|
-
var state = {
|
|
123
|
-
runtimeConfig: null,
|
|
124
|
-
currentUser: null,
|
|
125
|
-
currentSessionProvider: null,
|
|
126
|
-
confirmedQmuseUserId: null
|
|
127
|
-
};
|
|
128
|
-
var initPromise = null;
|
|
129
|
-
var sessionSyncPromise = null;
|
|
130
|
-
var refreshPromise = null;
|
|
131
|
-
function getMuseRuntime() {
|
|
132
|
-
var runtime = options.getMuseRuntime();
|
|
133
|
-
if (!runtime || runtime.env !== 'dev' && runtime.env !== 'prod') {
|
|
134
|
-
throw new Error('QMuse runtime env must be dev or prod');
|
|
135
|
-
}
|
|
136
|
-
return runtime;
|
|
137
|
-
}
|
|
138
|
-
function getRuntimeConfig() {
|
|
139
|
-
if (!state.runtimeConfig) {
|
|
140
|
-
throw new Error('Appwrite is not initialized');
|
|
141
|
-
}
|
|
142
|
-
return state.runtimeConfig;
|
|
143
|
-
}
|
|
144
|
-
function clearCurrentSession() {
|
|
145
|
-
state.currentUser = null;
|
|
146
|
-
state.currentSessionProvider = null;
|
|
147
|
-
state.confirmedQmuseUserId = null;
|
|
148
|
-
}
|
|
149
|
-
function loadAppwriteRuntimeConfig() {
|
|
150
|
-
return _loadAppwriteRuntimeConfig.apply(this, arguments);
|
|
151
|
-
}
|
|
152
|
-
function _loadAppwriteRuntimeConfig() {
|
|
153
|
-
_loadAppwriteRuntimeConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
154
|
-
var runtime, response, payload, data, config;
|
|
155
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
156
|
-
while (1) switch (_context.prev = _context.next) {
|
|
157
|
-
case 0:
|
|
158
|
-
runtime = getMuseRuntime();
|
|
159
|
-
_context.next = 3;
|
|
160
|
-
return request(new URL('/runtime/appwrite/config', runtime.domain).toString(), {
|
|
161
|
-
method: 'POST',
|
|
162
|
-
credentials: 'include',
|
|
163
|
-
headers: {
|
|
164
|
-
'Content-Type': 'application/json'
|
|
165
|
-
},
|
|
166
|
-
body: JSON.stringify({
|
|
167
|
-
appId: runtime.appId,
|
|
168
|
-
env: runtime.env
|
|
169
|
-
})
|
|
170
|
-
});
|
|
171
|
-
case 3:
|
|
172
|
-
response = _context.sent;
|
|
173
|
-
_context.next = 6;
|
|
174
|
-
return readResponsePayload(response);
|
|
175
|
-
case 6:
|
|
176
|
-
payload = _context.sent;
|
|
177
|
-
data = isRecord(payload === null || payload === void 0 ? void 0 : payload.data) ? payload.data : null;
|
|
178
|
-
if (!(!response.ok || (payload === null || payload === void 0 ? void 0 : payload.success) !== true || !data)) {
|
|
179
|
-
_context.next = 10;
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
throw createResponseError({
|
|
183
|
-
payload: payload,
|
|
184
|
-
status: response.status,
|
|
185
|
-
fallbackMessage: "Appwrite config request failed: ".concat(response.status),
|
|
186
|
-
fallbackType: 'appwrite_config_error'
|
|
187
|
-
});
|
|
188
|
-
case 10:
|
|
189
|
-
config = {
|
|
190
|
-
endpoint: data.endpoint,
|
|
191
|
-
projectId: data.projectId,
|
|
192
|
-
databaseId: data.databaseId,
|
|
193
|
-
authTokenEndpoint: data.authTokenEndpoint
|
|
194
|
-
};
|
|
195
|
-
if (!(typeof config.endpoint !== 'string' || !config.endpoint || typeof config.projectId !== 'string' || !config.projectId || typeof config.databaseId !== 'string' || !config.databaseId || typeof config.authTokenEndpoint !== 'string' || !config.authTokenEndpoint)) {
|
|
196
|
-
_context.next = 13;
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
throw new Error('Appwrite runtime config is incomplete');
|
|
200
|
-
case 13:
|
|
201
|
-
return _context.abrupt("return", config);
|
|
202
|
-
case 14:
|
|
203
|
-
case "end":
|
|
204
|
-
return _context.stop();
|
|
205
|
-
}
|
|
206
|
-
}, _callee);
|
|
207
|
-
}));
|
|
208
|
-
return _loadAppwriteRuntimeConfig.apply(this, arguments);
|
|
209
|
-
}
|
|
210
|
-
function cacheCurrentSession() {
|
|
211
|
-
return _cacheCurrentSession.apply(this, arguments);
|
|
212
|
-
}
|
|
213
|
-
function _cacheCurrentSession() {
|
|
214
|
-
_cacheCurrentSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
215
|
-
var _yield$Promise$all, _yield$Promise$all2, user, session;
|
|
216
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
217
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
218
|
-
case 0:
|
|
219
|
-
_context2.next = 2;
|
|
220
|
-
return Promise.all([account.get(), account.getSession({
|
|
221
|
-
sessionId: 'current'
|
|
222
|
-
})]);
|
|
223
|
-
case 2:
|
|
224
|
-
_yield$Promise$all = _context2.sent;
|
|
225
|
-
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
226
|
-
user = _yield$Promise$all2[0];
|
|
227
|
-
session = _yield$Promise$all2[1];
|
|
228
|
-
state.currentUser = user;
|
|
229
|
-
state.currentSessionProvider = session.provider;
|
|
230
|
-
case 8:
|
|
231
|
-
case "end":
|
|
232
|
-
return _context2.stop();
|
|
233
|
-
}
|
|
234
|
-
}, _callee2);
|
|
235
|
-
}));
|
|
236
|
-
return _cacheCurrentSession.apply(this, arguments);
|
|
237
|
-
}
|
|
238
|
-
function tryCacheCurrentSession() {
|
|
239
|
-
return _tryCacheCurrentSession.apply(this, arguments);
|
|
240
|
-
}
|
|
241
|
-
function _tryCacheCurrentSession() {
|
|
242
|
-
_tryCacheCurrentSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
243
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
244
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
245
|
-
case 0:
|
|
246
|
-
_context3.prev = 0;
|
|
247
|
-
_context3.next = 3;
|
|
248
|
-
return cacheCurrentSession();
|
|
249
|
-
case 3:
|
|
250
|
-
return _context3.abrupt("return", true);
|
|
251
|
-
case 6:
|
|
252
|
-
_context3.prev = 6;
|
|
253
|
-
_context3.t0 = _context3["catch"](0);
|
|
254
|
-
if (!(getErrorCode(_context3.t0) !== 401)) {
|
|
255
|
-
_context3.next = 10;
|
|
256
|
-
break;
|
|
257
|
-
}
|
|
258
|
-
throw _context3.t0;
|
|
259
|
-
case 10:
|
|
260
|
-
clearCurrentSession();
|
|
261
|
-
return _context3.abrupt("return", false);
|
|
262
|
-
case 12:
|
|
263
|
-
case "end":
|
|
264
|
-
return _context3.stop();
|
|
265
|
-
}
|
|
266
|
-
}, _callee3, null, [[0, 6]]);
|
|
267
|
-
}));
|
|
268
|
-
return _tryCacheCurrentSession.apply(this, arguments);
|
|
269
|
-
}
|
|
270
|
-
function deleteCurrentSession() {
|
|
271
|
-
return _deleteCurrentSession.apply(this, arguments);
|
|
272
|
-
}
|
|
273
|
-
function _deleteCurrentSession() {
|
|
274
|
-
_deleteCurrentSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
275
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
276
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
277
|
-
case 0:
|
|
278
|
-
if (state.currentUser) {
|
|
279
|
-
_context4.next = 2;
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
return _context4.abrupt("return");
|
|
283
|
-
case 2:
|
|
284
|
-
_context4.prev = 2;
|
|
285
|
-
_context4.next = 5;
|
|
286
|
-
return account.deleteSession({
|
|
287
|
-
sessionId: 'current'
|
|
288
|
-
});
|
|
289
|
-
case 5:
|
|
290
|
-
_context4.next = 11;
|
|
291
|
-
break;
|
|
292
|
-
case 7:
|
|
293
|
-
_context4.prev = 7;
|
|
294
|
-
_context4.t0 = _context4["catch"](2);
|
|
295
|
-
if (!(getErrorCode(_context4.t0) !== 401)) {
|
|
296
|
-
_context4.next = 11;
|
|
297
|
-
break;
|
|
298
|
-
}
|
|
299
|
-
throw _context4.t0;
|
|
300
|
-
case 11:
|
|
301
|
-
_context4.prev = 11;
|
|
302
|
-
clearCurrentSession();
|
|
303
|
-
return _context4.finish(11);
|
|
304
|
-
case 14:
|
|
305
|
-
case "end":
|
|
306
|
-
return _context4.stop();
|
|
307
|
-
}
|
|
308
|
-
}, _callee4, null, [[2, 7, 11, 14]]);
|
|
309
|
-
}));
|
|
310
|
-
return _deleteCurrentSession.apply(this, arguments);
|
|
311
|
-
}
|
|
312
|
-
function ensureAnonymousSession() {
|
|
313
|
-
return _ensureAnonymousSession.apply(this, arguments);
|
|
314
|
-
}
|
|
315
|
-
function _ensureAnonymousSession() {
|
|
316
|
-
_ensureAnonymousSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
317
|
-
var forceReplace,
|
|
318
|
-
_args5 = arguments;
|
|
319
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
320
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
321
|
-
case 0:
|
|
322
|
-
forceReplace = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : false;
|
|
323
|
-
if (state.currentUser) {
|
|
324
|
-
_context5.next = 4;
|
|
325
|
-
break;
|
|
326
|
-
}
|
|
327
|
-
_context5.next = 4;
|
|
328
|
-
return tryCacheCurrentSession();
|
|
329
|
-
case 4:
|
|
330
|
-
if (!(!forceReplace && state.currentUser && state.currentSessionProvider === 'anonymous')) {
|
|
331
|
-
_context5.next = 7;
|
|
332
|
-
break;
|
|
333
|
-
}
|
|
334
|
-
state.confirmedQmuseUserId = null;
|
|
335
|
-
return _context5.abrupt("return");
|
|
336
|
-
case 7:
|
|
337
|
-
_context5.next = 9;
|
|
338
|
-
return deleteCurrentSession();
|
|
339
|
-
case 9:
|
|
340
|
-
_context5.next = 11;
|
|
341
|
-
return account.createAnonymousSession();
|
|
342
|
-
case 11:
|
|
343
|
-
_context5.next = 13;
|
|
344
|
-
return cacheCurrentSession();
|
|
345
|
-
case 13:
|
|
346
|
-
state.confirmedQmuseUserId = null;
|
|
347
|
-
case 14:
|
|
348
|
-
case "end":
|
|
349
|
-
return _context5.stop();
|
|
350
|
-
}
|
|
351
|
-
}, _callee5);
|
|
352
|
-
}));
|
|
353
|
-
return _ensureAnonymousSession.apply(this, arguments);
|
|
354
|
-
}
|
|
355
|
-
function requestCustomToken() {
|
|
356
|
-
return _requestCustomToken.apply(this, arguments);
|
|
357
|
-
}
|
|
358
|
-
function _requestCustomToken() {
|
|
359
|
-
_requestCustomToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
360
|
-
var runtime, config, response, payload, data;
|
|
361
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
362
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
363
|
-
case 0:
|
|
364
|
-
runtime = getMuseRuntime();
|
|
365
|
-
config = getRuntimeConfig();
|
|
366
|
-
_context6.next = 4;
|
|
367
|
-
return request(new URL(config.authTokenEndpoint, runtime.domain).toString(), {
|
|
368
|
-
method: 'POST',
|
|
369
|
-
credentials: 'include',
|
|
370
|
-
headers: {
|
|
371
|
-
'Content-Type': 'application/json'
|
|
372
|
-
},
|
|
373
|
-
body: JSON.stringify({
|
|
374
|
-
appId: runtime.appId,
|
|
375
|
-
appVersionId: runtime.appVersionId,
|
|
376
|
-
env: runtime.env,
|
|
377
|
-
projectId: config.projectId
|
|
378
|
-
})
|
|
379
|
-
});
|
|
380
|
-
case 4:
|
|
381
|
-
response = _context6.sent;
|
|
382
|
-
if (!(response.status === 401)) {
|
|
383
|
-
_context6.next = 7;
|
|
384
|
-
break;
|
|
385
|
-
}
|
|
386
|
-
return _context6.abrupt("return", null);
|
|
387
|
-
case 7:
|
|
388
|
-
_context6.next = 9;
|
|
389
|
-
return readResponsePayload(response);
|
|
390
|
-
case 9:
|
|
391
|
-
payload = _context6.sent;
|
|
392
|
-
data = isRecord(payload === null || payload === void 0 ? void 0 : payload.data) ? payload.data : null;
|
|
393
|
-
if (!(!response.ok || (payload === null || payload === void 0 ? void 0 : payload.success) !== true || !data)) {
|
|
394
|
-
_context6.next = 13;
|
|
395
|
-
break;
|
|
396
|
-
}
|
|
397
|
-
throw createResponseError({
|
|
398
|
-
payload: payload,
|
|
399
|
-
status: response.status,
|
|
400
|
-
fallbackMessage: "Custom token request failed: ".concat(response.status),
|
|
401
|
-
fallbackType: 'custom_token_error'
|
|
402
|
-
});
|
|
403
|
-
case 13:
|
|
404
|
-
if (!(typeof data.userId !== 'string' || !data.userId || typeof data.secret !== 'string' || !data.secret)) {
|
|
405
|
-
_context6.next = 15;
|
|
406
|
-
break;
|
|
407
|
-
}
|
|
408
|
-
throw new Error('Custom token response is incomplete');
|
|
409
|
-
case 15:
|
|
410
|
-
return _context6.abrupt("return", {
|
|
411
|
-
userId: data.userId,
|
|
412
|
-
secret: data.secret
|
|
413
|
-
});
|
|
414
|
-
case 16:
|
|
415
|
-
case "end":
|
|
416
|
-
return _context6.stop();
|
|
417
|
-
}
|
|
418
|
-
}, _callee6);
|
|
419
|
-
}));
|
|
420
|
-
return _requestCustomToken.apply(this, arguments);
|
|
421
|
-
}
|
|
422
|
-
function ensureAuthenticatedSession(_x2) {
|
|
423
|
-
return _ensureAuthenticatedSession.apply(this, arguments);
|
|
424
|
-
}
|
|
425
|
-
function _ensureAuthenticatedSession() {
|
|
426
|
-
_ensureAuthenticatedSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref6) {
|
|
427
|
-
var qmuseUserId, userId, secret, _ref6$forceReplace, forceReplace;
|
|
428
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
429
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
430
|
-
case 0:
|
|
431
|
-
qmuseUserId = _ref6.qmuseUserId, userId = _ref6.userId, secret = _ref6.secret, _ref6$forceReplace = _ref6.forceReplace, forceReplace = _ref6$forceReplace === void 0 ? false : _ref6$forceReplace;
|
|
432
|
-
if (state.currentUser) {
|
|
433
|
-
_context7.next = 4;
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
436
|
-
_context7.next = 4;
|
|
437
|
-
return tryCacheCurrentSession();
|
|
438
|
-
case 4:
|
|
439
|
-
if (!(!forceReplace && state.currentUser && state.currentSessionProvider !== 'anonymous' && state.currentUser.$id === userId)) {
|
|
440
|
-
_context7.next = 7;
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
state.confirmedQmuseUserId = qmuseUserId;
|
|
444
|
-
return _context7.abrupt("return");
|
|
445
|
-
case 7:
|
|
446
|
-
_context7.next = 9;
|
|
447
|
-
return deleteCurrentSession();
|
|
448
|
-
case 9:
|
|
449
|
-
_context7.next = 11;
|
|
450
|
-
return account.createSession({
|
|
451
|
-
userId: userId,
|
|
452
|
-
secret: secret
|
|
453
|
-
});
|
|
454
|
-
case 11:
|
|
455
|
-
_context7.next = 13;
|
|
456
|
-
return cacheCurrentSession();
|
|
457
|
-
case 13:
|
|
458
|
-
state.confirmedQmuseUserId = qmuseUserId;
|
|
459
|
-
case 14:
|
|
460
|
-
case "end":
|
|
461
|
-
return _context7.stop();
|
|
462
|
-
}
|
|
463
|
-
}, _callee7);
|
|
464
|
-
}));
|
|
465
|
-
return _ensureAuthenticatedSession.apply(this, arguments);
|
|
466
|
-
}
|
|
467
|
-
function coordinateAppwriteSession() {
|
|
468
|
-
return _coordinateAppwriteSession.apply(this, arguments);
|
|
469
|
-
}
|
|
470
|
-
function _coordinateAppwriteSession() {
|
|
471
|
-
_coordinateAppwriteSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
472
|
-
var force,
|
|
473
|
-
qmuseUserId,
|
|
474
|
-
sessionMatchesRuntime,
|
|
475
|
-
token,
|
|
476
|
-
_args8 = arguments;
|
|
477
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
478
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
479
|
-
case 0:
|
|
480
|
-
force = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : false;
|
|
481
|
-
qmuseUserId = options.getQmuseLoginUserId();
|
|
482
|
-
sessionMatchesRuntime = state.currentUser !== null && (qmuseUserId ? state.currentSessionProvider !== 'anonymous' && state.confirmedQmuseUserId === qmuseUserId : state.currentSessionProvider === 'anonymous' && state.confirmedQmuseUserId === null);
|
|
483
|
-
if (!(!force && sessionMatchesRuntime)) {
|
|
484
|
-
_context8.next = 5;
|
|
485
|
-
break;
|
|
486
|
-
}
|
|
487
|
-
return _context8.abrupt("return");
|
|
488
|
-
case 5:
|
|
489
|
-
if (state.currentUser) {
|
|
490
|
-
_context8.next = 8;
|
|
491
|
-
break;
|
|
492
|
-
}
|
|
493
|
-
_context8.next = 8;
|
|
494
|
-
return tryCacheCurrentSession();
|
|
495
|
-
case 8:
|
|
496
|
-
if (qmuseUserId) {
|
|
497
|
-
_context8.next = 12;
|
|
498
|
-
break;
|
|
499
|
-
}
|
|
500
|
-
_context8.next = 11;
|
|
501
|
-
return ensureAnonymousSession(force);
|
|
502
|
-
case 11:
|
|
503
|
-
return _context8.abrupt("return");
|
|
504
|
-
case 12:
|
|
505
|
-
if (!(!force && state.currentUser && state.currentSessionProvider !== 'anonymous' && state.confirmedQmuseUserId === qmuseUserId)) {
|
|
506
|
-
_context8.next = 14;
|
|
507
|
-
break;
|
|
508
|
-
}
|
|
509
|
-
return _context8.abrupt("return");
|
|
510
|
-
case 14:
|
|
511
|
-
_context8.next = 16;
|
|
512
|
-
return requestCustomToken();
|
|
513
|
-
case 16:
|
|
514
|
-
token = _context8.sent;
|
|
515
|
-
if (token) {
|
|
516
|
-
_context8.next = 21;
|
|
517
|
-
break;
|
|
518
|
-
}
|
|
519
|
-
_context8.next = 20;
|
|
520
|
-
return ensureAnonymousSession(force);
|
|
521
|
-
case 20:
|
|
522
|
-
return _context8.abrupt("return");
|
|
523
|
-
case 21:
|
|
524
|
-
_context8.next = 23;
|
|
525
|
-
return ensureAuthenticatedSession(_objectSpread(_objectSpread({
|
|
526
|
-
qmuseUserId: qmuseUserId
|
|
527
|
-
}, token), {}, {
|
|
528
|
-
forceReplace: force
|
|
529
|
-
}));
|
|
530
|
-
case 23:
|
|
531
|
-
case "end":
|
|
532
|
-
return _context8.stop();
|
|
533
|
-
}
|
|
534
|
-
}, _callee8);
|
|
535
|
-
}));
|
|
536
|
-
return _coordinateAppwriteSession.apply(this, arguments);
|
|
537
|
-
}
|
|
538
|
-
function synchronizeAppwriteSession() {
|
|
539
|
-
return _synchronizeAppwriteSession.apply(this, arguments);
|
|
540
|
-
}
|
|
541
|
-
function _synchronizeAppwriteSession() {
|
|
542
|
-
_synchronizeAppwriteSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
543
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
544
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
545
|
-
case 0:
|
|
546
|
-
if (!sessionSyncPromise) {
|
|
547
|
-
sessionSyncPromise = coordinateAppwriteSession().finally(function () {
|
|
548
|
-
sessionSyncPromise = null;
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
return _context9.abrupt("return", sessionSyncPromise);
|
|
552
|
-
case 2:
|
|
553
|
-
case "end":
|
|
554
|
-
return _context9.stop();
|
|
555
|
-
}
|
|
556
|
-
}, _callee9);
|
|
557
|
-
}));
|
|
558
|
-
return _synchronizeAppwriteSession.apply(this, arguments);
|
|
559
|
-
}
|
|
560
|
-
function initializeAppwrite() {
|
|
561
|
-
return _initializeAppwrite.apply(this, arguments);
|
|
562
|
-
}
|
|
563
|
-
function _initializeAppwrite() {
|
|
564
|
-
_initializeAppwrite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
565
|
-
var config;
|
|
566
|
-
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
567
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
568
|
-
case 0:
|
|
569
|
-
_context10.next = 2;
|
|
570
|
-
return loadAppwriteRuntimeConfig();
|
|
571
|
-
case 2:
|
|
572
|
-
config = _context10.sent;
|
|
573
|
-
client.setEndpoint(config.endpoint).setProject(config.projectId);
|
|
574
|
-
state.runtimeConfig = config;
|
|
575
|
-
_context10.next = 7;
|
|
576
|
-
return synchronizeAppwriteSession();
|
|
577
|
-
case 7:
|
|
578
|
-
case "end":
|
|
579
|
-
return _context10.stop();
|
|
580
|
-
}
|
|
581
|
-
}, _callee10);
|
|
582
|
-
}));
|
|
583
|
-
return _initializeAppwrite.apply(this, arguments);
|
|
584
|
-
}
|
|
585
|
-
function init() {
|
|
586
|
-
if (!initPromise) {
|
|
587
|
-
initPromise = initializeAppwrite().catch(function (error) {
|
|
588
|
-
initPromise = null;
|
|
589
|
-
state.runtimeConfig = null;
|
|
590
|
-
clearCurrentSession();
|
|
591
|
-
throw error;
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
return initPromise;
|
|
595
|
-
}
|
|
596
|
-
function getClients() {
|
|
597
|
-
return _getClients.apply(this, arguments);
|
|
598
|
-
}
|
|
599
|
-
function _getClients() {
|
|
600
|
-
_getClients = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
|
601
|
-
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
602
|
-
while (1) switch (_context11.prev = _context11.next) {
|
|
603
|
-
case 0:
|
|
604
|
-
_context11.next = 2;
|
|
605
|
-
return init();
|
|
606
|
-
case 2:
|
|
607
|
-
return _context11.abrupt("return", {
|
|
608
|
-
client: client,
|
|
609
|
-
account: account,
|
|
610
|
-
tablesDB: tablesDB,
|
|
611
|
-
databaseId: getRuntimeConfig().databaseId
|
|
612
|
-
});
|
|
613
|
-
case 3:
|
|
614
|
-
case "end":
|
|
615
|
-
return _context11.stop();
|
|
616
|
-
}
|
|
617
|
-
}, _callee11);
|
|
618
|
-
}));
|
|
619
|
-
return _getClients.apply(this, arguments);
|
|
620
|
-
}
|
|
621
|
-
function getCurrentUser() {
|
|
622
|
-
if (!state.currentUser) {
|
|
623
|
-
throw new Error('Appwrite user is not authenticated');
|
|
624
|
-
}
|
|
625
|
-
return state.currentUser;
|
|
626
|
-
}
|
|
627
|
-
function refreshSession() {
|
|
628
|
-
return _refreshSession.apply(this, arguments);
|
|
629
|
-
}
|
|
630
|
-
function _refreshSession() {
|
|
631
|
-
_refreshSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
|
632
|
-
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
633
|
-
while (1) switch (_context13.prev = _context13.next) {
|
|
634
|
-
case 0:
|
|
635
|
-
_context13.next = 2;
|
|
636
|
-
return init();
|
|
637
|
-
case 2:
|
|
638
|
-
if (!refreshPromise) {
|
|
639
|
-
refreshPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
|
640
|
-
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
641
|
-
while (1) switch (_context12.prev = _context12.next) {
|
|
642
|
-
case 0:
|
|
643
|
-
if (!sessionSyncPromise) {
|
|
644
|
-
_context12.next = 3;
|
|
645
|
-
break;
|
|
646
|
-
}
|
|
647
|
-
_context12.next = 3;
|
|
648
|
-
return sessionSyncPromise;
|
|
649
|
-
case 3:
|
|
650
|
-
_context12.next = 5;
|
|
651
|
-
return coordinateAppwriteSession(true);
|
|
652
|
-
case 5:
|
|
653
|
-
case "end":
|
|
654
|
-
return _context12.stop();
|
|
655
|
-
}
|
|
656
|
-
}, _callee12);
|
|
657
|
-
}))().finally(function () {
|
|
658
|
-
refreshPromise = null;
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
|
-
return _context13.abrupt("return", refreshPromise);
|
|
662
|
-
case 4:
|
|
663
|
-
case "end":
|
|
664
|
-
return _context13.stop();
|
|
665
|
-
}
|
|
666
|
-
}, _callee13);
|
|
667
|
-
}));
|
|
668
|
-
return _refreshSession.apply(this, arguments);
|
|
669
|
-
}
|
|
670
|
-
function withSessionRetry(_x3) {
|
|
671
|
-
return _withSessionRetry.apply(this, arguments);
|
|
672
|
-
}
|
|
673
|
-
function _withSessionRetry() {
|
|
674
|
-
_withSessionRetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(operation) {
|
|
675
|
-
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
676
|
-
while (1) switch (_context14.prev = _context14.next) {
|
|
677
|
-
case 0:
|
|
678
|
-
_context14.next = 2;
|
|
679
|
-
return init();
|
|
680
|
-
case 2:
|
|
681
|
-
_context14.next = 4;
|
|
682
|
-
return synchronizeAppwriteSession();
|
|
683
|
-
case 4:
|
|
684
|
-
_context14.prev = 4;
|
|
685
|
-
_context14.next = 7;
|
|
686
|
-
return operation();
|
|
687
|
-
case 7:
|
|
688
|
-
return _context14.abrupt("return", _context14.sent);
|
|
689
|
-
case 10:
|
|
690
|
-
_context14.prev = 10;
|
|
691
|
-
_context14.t0 = _context14["catch"](4);
|
|
692
|
-
if (!(getErrorCode(_context14.t0) !== 401)) {
|
|
693
|
-
_context14.next = 14;
|
|
694
|
-
break;
|
|
695
|
-
}
|
|
696
|
-
throw _context14.t0;
|
|
697
|
-
case 14:
|
|
698
|
-
_context14.next = 16;
|
|
699
|
-
return refreshSession();
|
|
700
|
-
case 16:
|
|
701
|
-
return _context14.abrupt("return", operation());
|
|
702
|
-
case 17:
|
|
703
|
-
case "end":
|
|
704
|
-
return _context14.stop();
|
|
705
|
-
}
|
|
706
|
-
}, _callee14, null, [[4, 10]]);
|
|
707
|
-
}));
|
|
708
|
-
return _withSessionRetry.apply(this, arguments);
|
|
709
|
-
}
|
|
710
|
-
function scheduleMutationAudit(_ref7) {
|
|
711
|
-
var operation = _ref7.operation,
|
|
712
|
-
tableId = _ref7.tableId,
|
|
713
|
-
rowId = _ref7.rowId,
|
|
714
|
-
outcome = _ref7.outcome,
|
|
715
|
-
durationMs = _ref7.durationMs,
|
|
716
|
-
errorCode = _ref7.errorCode,
|
|
717
|
-
mutationData = _ref7.mutationData;
|
|
718
|
-
var runtime = getMuseRuntime();
|
|
719
|
-
globalThis.setTimeout(function () {
|
|
720
|
-
try {
|
|
721
|
-
void Promise.resolve(request(new URL('/api/runtime/appwrite/mutation-events', runtime.domain).toString(), {
|
|
722
|
-
method: 'POST',
|
|
723
|
-
credentials: 'include',
|
|
724
|
-
keepalive: true,
|
|
725
|
-
headers: {
|
|
726
|
-
'Content-Type': 'application/json'
|
|
727
|
-
},
|
|
728
|
-
body: JSON.stringify(_objectSpread(_objectSpread({
|
|
729
|
-
schemaVersion: 1,
|
|
730
|
-
operation: operation,
|
|
731
|
-
outcome: outcome,
|
|
732
|
-
appId: runtime.appId,
|
|
733
|
-
env: runtime.env,
|
|
734
|
-
tableId: tableId,
|
|
735
|
-
rowId: rowId,
|
|
736
|
-
durationMs: durationMs
|
|
737
|
-
}, errorCode === undefined ? {} : {
|
|
738
|
-
errorCode: errorCode
|
|
739
|
-
}), mutationData === undefined ? {} : {
|
|
740
|
-
mutationData: mutationData
|
|
741
|
-
}))
|
|
742
|
-
})).catch(function () {
|
|
743
|
-
return undefined;
|
|
744
|
-
});
|
|
745
|
-
} catch (_unused) {
|
|
746
|
-
// Security telemetry is best-effort and cannot alter mutation semantics.
|
|
747
|
-
}
|
|
748
|
-
}, 0);
|
|
749
|
-
}
|
|
750
|
-
function observeMutation(_x4) {
|
|
751
|
-
return _observeMutation.apply(this, arguments);
|
|
752
|
-
}
|
|
753
|
-
function _observeMutation() {
|
|
754
|
-
_observeMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(_ref8) {
|
|
755
|
-
var operation, tableId, rowId, mutationData, task, startedAt, result, _getErrorCode;
|
|
756
|
-
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
757
|
-
while (1) switch (_context15.prev = _context15.next) {
|
|
758
|
-
case 0:
|
|
759
|
-
operation = _ref8.operation, tableId = _ref8.tableId, rowId = _ref8.rowId, mutationData = _ref8.mutationData, task = _ref8.task;
|
|
760
|
-
startedAt = Date.now();
|
|
761
|
-
_context15.prev = 2;
|
|
762
|
-
_context15.next = 5;
|
|
763
|
-
return task();
|
|
764
|
-
case 5:
|
|
765
|
-
result = _context15.sent;
|
|
766
|
-
scheduleMutationAudit({
|
|
767
|
-
operation: operation,
|
|
768
|
-
tableId: tableId,
|
|
769
|
-
rowId: rowId,
|
|
770
|
-
outcome: 'success',
|
|
771
|
-
durationMs: Date.now() - startedAt,
|
|
772
|
-
mutationData: mutationData
|
|
773
|
-
});
|
|
774
|
-
return _context15.abrupt("return", result);
|
|
775
|
-
case 10:
|
|
776
|
-
_context15.prev = 10;
|
|
777
|
-
_context15.t0 = _context15["catch"](2);
|
|
778
|
-
scheduleMutationAudit({
|
|
779
|
-
operation: operation,
|
|
780
|
-
tableId: tableId,
|
|
781
|
-
rowId: rowId,
|
|
782
|
-
outcome: 'failure',
|
|
783
|
-
durationMs: Date.now() - startedAt,
|
|
784
|
-
errorCode: (_getErrorCode = getErrorCode(_context15.t0)) !== null && _getErrorCode !== void 0 ? _getErrorCode : undefined,
|
|
785
|
-
mutationData: mutationData
|
|
786
|
-
});
|
|
787
|
-
throw _context15.t0;
|
|
788
|
-
case 14:
|
|
789
|
-
case "end":
|
|
790
|
-
return _context15.stop();
|
|
791
|
-
}
|
|
792
|
-
}, _callee15, null, [[2, 10]]);
|
|
793
|
-
}));
|
|
794
|
-
return _observeMutation.apply(this, arguments);
|
|
795
|
-
}
|
|
796
|
-
function listRows(_x5) {
|
|
797
|
-
return _listRows.apply(this, arguments);
|
|
798
|
-
}
|
|
799
|
-
function _listRows() {
|
|
800
|
-
_listRows = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(_ref9) {
|
|
801
|
-
var tableId, _ref9$queries, queries, _ref9$limit, limit, cursor, _yield$getClients, databaseId;
|
|
802
|
-
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
803
|
-
while (1) switch (_context16.prev = _context16.next) {
|
|
804
|
-
case 0:
|
|
805
|
-
tableId = _ref9.tableId, _ref9$queries = _ref9.queries, queries = _ref9$queries === void 0 ? [] : _ref9$queries, _ref9$limit = _ref9.limit, limit = _ref9$limit === void 0 ? 20 : _ref9$limit, cursor = _ref9.cursor;
|
|
806
|
-
if (!(!Number.isInteger(limit) || limit < 1 || limit > 20)) {
|
|
807
|
-
_context16.next = 3;
|
|
808
|
-
break;
|
|
809
|
-
}
|
|
810
|
-
throw new RangeError('listRows limit must be an integer from 1 to 20');
|
|
811
|
-
case 3:
|
|
812
|
-
_context16.next = 5;
|
|
813
|
-
return getClients();
|
|
814
|
-
case 5:
|
|
815
|
-
_yield$getClients = _context16.sent;
|
|
816
|
-
databaseId = _yield$getClients.databaseId;
|
|
817
|
-
return _context16.abrupt("return", withSessionRetry(function () {
|
|
818
|
-
return tablesDB.listRows({
|
|
819
|
-
databaseId: databaseId,
|
|
820
|
-
tableId: tableId,
|
|
821
|
-
queries: [Query.orderDesc('$createdAt')].concat(_toConsumableArray(queries), [Query.limit(limit)], _toConsumableArray(cursor ? [Query.cursorAfter(cursor)] : []))
|
|
822
|
-
});
|
|
823
|
-
}));
|
|
824
|
-
case 8:
|
|
825
|
-
case "end":
|
|
826
|
-
return _context16.stop();
|
|
827
|
-
}
|
|
828
|
-
}, _callee16);
|
|
829
|
-
}));
|
|
830
|
-
return _listRows.apply(this, arguments);
|
|
831
|
-
}
|
|
832
|
-
function getRow(_x6) {
|
|
833
|
-
return _getRow.apply(this, arguments);
|
|
834
|
-
}
|
|
835
|
-
function _getRow() {
|
|
836
|
-
_getRow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(_ref10) {
|
|
837
|
-
var tableId, rowId, _yield$getClients2, databaseId;
|
|
838
|
-
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
839
|
-
while (1) switch (_context17.prev = _context17.next) {
|
|
840
|
-
case 0:
|
|
841
|
-
tableId = _ref10.tableId, rowId = _ref10.rowId;
|
|
842
|
-
_context17.next = 3;
|
|
843
|
-
return getClients();
|
|
844
|
-
case 3:
|
|
845
|
-
_yield$getClients2 = _context17.sent;
|
|
846
|
-
databaseId = _yield$getClients2.databaseId;
|
|
847
|
-
return _context17.abrupt("return", withSessionRetry(function () {
|
|
848
|
-
return tablesDB.getRow({
|
|
849
|
-
databaseId: databaseId,
|
|
850
|
-
tableId: tableId,
|
|
851
|
-
rowId: rowId
|
|
852
|
-
});
|
|
853
|
-
}));
|
|
854
|
-
case 6:
|
|
855
|
-
case "end":
|
|
856
|
-
return _context17.stop();
|
|
857
|
-
}
|
|
858
|
-
}, _callee17);
|
|
859
|
-
}));
|
|
860
|
-
return _getRow.apply(this, arguments);
|
|
861
|
-
}
|
|
862
|
-
function createRow(_x7) {
|
|
863
|
-
return _createRow.apply(this, arguments);
|
|
864
|
-
}
|
|
865
|
-
function _createRow() {
|
|
866
|
-
_createRow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(_ref11) {
|
|
867
|
-
var tableId, data, _ref11$rowId, rowId, _yield$getClients3, databaseId, mutationData;
|
|
868
|
-
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
869
|
-
while (1) switch (_context18.prev = _context18.next) {
|
|
870
|
-
case 0:
|
|
871
|
-
tableId = _ref11.tableId, data = _ref11.data, _ref11$rowId = _ref11.rowId, rowId = _ref11$rowId === void 0 ? ID.unique() : _ref11$rowId;
|
|
872
|
-
_context18.next = 3;
|
|
873
|
-
return getClients();
|
|
874
|
-
case 3:
|
|
875
|
-
_yield$getClients3 = _context18.sent;
|
|
876
|
-
databaseId = _yield$getClients3.databaseId;
|
|
877
|
-
mutationData = sanitizeBusinessRowData(data);
|
|
878
|
-
return _context18.abrupt("return", observeMutation({
|
|
879
|
-
operation: 'create',
|
|
880
|
-
tableId: tableId,
|
|
881
|
-
rowId: rowId,
|
|
882
|
-
mutationData: sanitizeMutationAuditData(mutationData),
|
|
883
|
-
task: function task() {
|
|
884
|
-
return withSessionRetry(function () {
|
|
885
|
-
var currentUserId = getCurrentUser().$id;
|
|
886
|
-
var owner = Role.user(currentUserId);
|
|
887
|
-
return tablesDB.createRow({
|
|
888
|
-
databaseId: databaseId,
|
|
889
|
-
tableId: tableId,
|
|
890
|
-
rowId: rowId,
|
|
891
|
-
data: _objectSpread(_objectSpread({}, mutationData), {}, {
|
|
892
|
-
creatorId: currentUserId,
|
|
893
|
-
modifierId: currentUserId
|
|
894
|
-
}),
|
|
895
|
-
permissions: [Permission.read(owner), Permission.update(owner), Permission.delete(owner)]
|
|
896
|
-
});
|
|
897
|
-
});
|
|
898
|
-
}
|
|
899
|
-
}));
|
|
900
|
-
case 7:
|
|
901
|
-
case "end":
|
|
902
|
-
return _context18.stop();
|
|
903
|
-
}
|
|
904
|
-
}, _callee18);
|
|
905
|
-
}));
|
|
906
|
-
return _createRow.apply(this, arguments);
|
|
907
|
-
}
|
|
908
|
-
function updateRow(_x8) {
|
|
909
|
-
return _updateRow.apply(this, arguments);
|
|
910
|
-
}
|
|
911
|
-
function _updateRow() {
|
|
912
|
-
_updateRow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(_ref12) {
|
|
913
|
-
var tableId, rowId, data, _yield$getClients4, databaseId, mutationData;
|
|
914
|
-
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
915
|
-
while (1) switch (_context19.prev = _context19.next) {
|
|
916
|
-
case 0:
|
|
917
|
-
tableId = _ref12.tableId, rowId = _ref12.rowId, data = _ref12.data;
|
|
918
|
-
_context19.next = 3;
|
|
919
|
-
return getClients();
|
|
920
|
-
case 3:
|
|
921
|
-
_yield$getClients4 = _context19.sent;
|
|
922
|
-
databaseId = _yield$getClients4.databaseId;
|
|
923
|
-
mutationData = sanitizeBusinessRowData(data);
|
|
924
|
-
return _context19.abrupt("return", observeMutation({
|
|
925
|
-
operation: 'update',
|
|
926
|
-
tableId: tableId,
|
|
927
|
-
rowId: rowId,
|
|
928
|
-
mutationData: sanitizeMutationAuditData(mutationData),
|
|
929
|
-
task: function task() {
|
|
930
|
-
return withSessionRetry(function () {
|
|
931
|
-
return tablesDB.updateRow({
|
|
932
|
-
databaseId: databaseId,
|
|
933
|
-
tableId: tableId,
|
|
934
|
-
rowId: rowId,
|
|
935
|
-
data: _objectSpread(_objectSpread({}, mutationData), {}, {
|
|
936
|
-
modifierId: getCurrentUser().$id
|
|
937
|
-
})
|
|
938
|
-
});
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
}));
|
|
942
|
-
case 7:
|
|
943
|
-
case "end":
|
|
944
|
-
return _context19.stop();
|
|
945
|
-
}
|
|
946
|
-
}, _callee19);
|
|
947
|
-
}));
|
|
948
|
-
return _updateRow.apply(this, arguments);
|
|
949
|
-
}
|
|
950
|
-
function deleteRow(_x9) {
|
|
951
|
-
return _deleteRow.apply(this, arguments);
|
|
952
|
-
}
|
|
953
|
-
function _deleteRow() {
|
|
954
|
-
_deleteRow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(_ref13) {
|
|
955
|
-
var tableId, rowId, _yield$getClients5, databaseId;
|
|
956
|
-
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
957
|
-
while (1) switch (_context20.prev = _context20.next) {
|
|
958
|
-
case 0:
|
|
959
|
-
tableId = _ref13.tableId, rowId = _ref13.rowId;
|
|
960
|
-
_context20.next = 3;
|
|
961
|
-
return getClients();
|
|
962
|
-
case 3:
|
|
963
|
-
_yield$getClients5 = _context20.sent;
|
|
964
|
-
databaseId = _yield$getClients5.databaseId;
|
|
965
|
-
return _context20.abrupt("return", observeMutation({
|
|
966
|
-
operation: 'delete',
|
|
967
|
-
tableId: tableId,
|
|
968
|
-
rowId: rowId,
|
|
969
|
-
task: function task() {
|
|
970
|
-
return withSessionRetry(function () {
|
|
971
|
-
return tablesDB.deleteRow({
|
|
972
|
-
databaseId: databaseId,
|
|
973
|
-
tableId: tableId,
|
|
974
|
-
rowId: rowId
|
|
975
|
-
});
|
|
976
|
-
});
|
|
977
|
-
}
|
|
978
|
-
}));
|
|
979
|
-
case 6:
|
|
980
|
-
case "end":
|
|
981
|
-
return _context20.stop();
|
|
982
|
-
}
|
|
983
|
-
}, _callee20);
|
|
984
|
-
}));
|
|
985
|
-
return _deleteRow.apply(this, arguments);
|
|
986
|
-
}
|
|
987
|
-
return {
|
|
988
|
-
init: init,
|
|
989
|
-
getClients: getClients,
|
|
990
|
-
getCurrentUser: getCurrentUser,
|
|
991
|
-
refreshSession: refreshSession,
|
|
992
|
-
listRows: listRows,
|
|
993
|
-
getRow: getRow,
|
|
994
|
-
createRow: createRow,
|
|
995
|
-
updateRow: updateRow,
|
|
996
|
-
deleteRow: deleteRow
|
|
997
|
-
};
|
|
3
|
+
return new QmuseAppwriteRuntime(options);
|
|
998
4
|
}
|