@qmuse/appwrite-runtime-sdk 1.0.1 → 1.0.3-dev.1

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.
@@ -0,0 +1,647 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
4
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
6
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
7
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
+ import { createResponseError, getErrorCode, isRecord, readResponsePayload } from "./utils";
9
+ export var AppwriteSessionCoordinator = /*#__PURE__*/function () {
10
+ function AppwriteSessionCoordinator(options, request) {
11
+ _classCallCheck(this, AppwriteSessionCoordinator);
12
+ _defineProperty(this, "state", {
13
+ runtimeConfig: null,
14
+ currentUser: null,
15
+ currentSessionProvider: null,
16
+ confirmedQmuseUserId: null
17
+ });
18
+ _defineProperty(this, "initPromise", null);
19
+ _defineProperty(this, "sessionSyncPromise", null);
20
+ _defineProperty(this, "refreshPromise", null);
21
+ this.options = options;
22
+ this.request = request;
23
+ }
24
+ _createClass(AppwriteSessionCoordinator, [{
25
+ key: "init",
26
+ value: function init() {
27
+ var _this = this;
28
+ if (!this.initPromise) {
29
+ this.initPromise = this.initialize().catch(function (error) {
30
+ _this.initPromise = null;
31
+ _this.state.runtimeConfig = null;
32
+ _this.clearCurrentSession();
33
+ throw error;
34
+ });
35
+ }
36
+ return this.initPromise;
37
+ }
38
+ }, {
39
+ key: "getDatabaseId",
40
+ value: function () {
41
+ var _getDatabaseId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
42
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
43
+ while (1) switch (_context.prev = _context.next) {
44
+ case 0:
45
+ _context.next = 2;
46
+ return this.init();
47
+ case 2:
48
+ return _context.abrupt("return", this.requireRuntimeConfig().databaseId);
49
+ case 3:
50
+ case "end":
51
+ return _context.stop();
52
+ }
53
+ }, _callee, this);
54
+ }));
55
+ function getDatabaseId() {
56
+ return _getDatabaseId.apply(this, arguments);
57
+ }
58
+ return getDatabaseId;
59
+ }()
60
+ }, {
61
+ key: "getCurrentUser",
62
+ value: function () {
63
+ var _getCurrentUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
64
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
65
+ while (1) switch (_context2.prev = _context2.next) {
66
+ case 0:
67
+ _context2.next = 2;
68
+ return this.init();
69
+ case 2:
70
+ return _context2.abrupt("return", this.requireCurrentUser());
71
+ case 3:
72
+ case "end":
73
+ return _context2.stop();
74
+ }
75
+ }, _callee2, this);
76
+ }));
77
+ function getCurrentUser() {
78
+ return _getCurrentUser.apply(this, arguments);
79
+ }
80
+ return getCurrentUser;
81
+ }()
82
+ }, {
83
+ key: "requireCurrentUser",
84
+ value: function requireCurrentUser() {
85
+ if (!this.state.currentUser) {
86
+ throw new Error('Appwrite user is not authenticated');
87
+ }
88
+ return this.state.currentUser;
89
+ }
90
+ }, {
91
+ key: "refreshSession",
92
+ value: function () {
93
+ var _refreshSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
94
+ var _this2 = this;
95
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
96
+ while (1) switch (_context4.prev = _context4.next) {
97
+ case 0:
98
+ _context4.next = 2;
99
+ return this.init();
100
+ case 2:
101
+ if (!this.refreshPromise) {
102
+ this.refreshPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
103
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
104
+ while (1) switch (_context3.prev = _context3.next) {
105
+ case 0:
106
+ if (!_this2.sessionSyncPromise) {
107
+ _context3.next = 3;
108
+ break;
109
+ }
110
+ _context3.next = 3;
111
+ return _this2.sessionSyncPromise;
112
+ case 3:
113
+ _context3.next = 5;
114
+ return _this2.coordinateSession(true);
115
+ case 5:
116
+ case "end":
117
+ return _context3.stop();
118
+ }
119
+ }, _callee3);
120
+ }))().finally(function () {
121
+ _this2.refreshPromise = null;
122
+ });
123
+ }
124
+ return _context4.abrupt("return", this.refreshPromise);
125
+ case 4:
126
+ case "end":
127
+ return _context4.stop();
128
+ }
129
+ }, _callee4, this);
130
+ }));
131
+ function refreshSession() {
132
+ return _refreshSession.apply(this, arguments);
133
+ }
134
+ return refreshSession;
135
+ }()
136
+ }, {
137
+ key: "withSessionRetry",
138
+ value: function () {
139
+ var _withSessionRetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(operation) {
140
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
141
+ while (1) switch (_context5.prev = _context5.next) {
142
+ case 0:
143
+ _context5.next = 2;
144
+ return this.init();
145
+ case 2:
146
+ _context5.next = 4;
147
+ return this.synchronizeSession();
148
+ case 4:
149
+ _context5.prev = 4;
150
+ _context5.next = 7;
151
+ return operation();
152
+ case 7:
153
+ return _context5.abrupt("return", _context5.sent);
154
+ case 10:
155
+ _context5.prev = 10;
156
+ _context5.t0 = _context5["catch"](4);
157
+ if (!(getErrorCode(_context5.t0) !== 401)) {
158
+ _context5.next = 14;
159
+ break;
160
+ }
161
+ throw _context5.t0;
162
+ case 14:
163
+ _context5.next = 16;
164
+ return this.refreshSession();
165
+ case 16:
166
+ return _context5.abrupt("return", operation());
167
+ case 17:
168
+ case "end":
169
+ return _context5.stop();
170
+ }
171
+ }, _callee5, this, [[4, 10]]);
172
+ }));
173
+ function withSessionRetry(_x) {
174
+ return _withSessionRetry.apply(this, arguments);
175
+ }
176
+ return withSessionRetry;
177
+ }()
178
+ }, {
179
+ key: "getMuseRuntime",
180
+ value: function getMuseRuntime() {
181
+ var runtime = this.options.getMuseRuntime();
182
+ if (!runtime || runtime.env !== 'dev' && runtime.env !== 'prod') {
183
+ throw new Error('QMuse runtime env must be dev or prod');
184
+ }
185
+ return runtime;
186
+ }
187
+ }, {
188
+ key: "requireRuntimeConfig",
189
+ value: function requireRuntimeConfig() {
190
+ if (!this.state.runtimeConfig) {
191
+ throw new Error('Appwrite is not initialized');
192
+ }
193
+ return this.state.runtimeConfig;
194
+ }
195
+ }, {
196
+ key: "clearCurrentSession",
197
+ value: function clearCurrentSession() {
198
+ this.state.currentUser = null;
199
+ this.state.currentSessionProvider = null;
200
+ this.state.confirmedQmuseUserId = null;
201
+ }
202
+ }, {
203
+ key: "loadRuntimeConfig",
204
+ value: function () {
205
+ var _loadRuntimeConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
206
+ var runtime, response, payload, data, config;
207
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
208
+ while (1) switch (_context6.prev = _context6.next) {
209
+ case 0:
210
+ runtime = this.getMuseRuntime();
211
+ _context6.next = 3;
212
+ return this.request(new URL('/runtime/appwrite/config', runtime.domain).toString(), {
213
+ method: 'POST',
214
+ credentials: 'include',
215
+ headers: {
216
+ 'Content-Type': 'application/json'
217
+ },
218
+ body: JSON.stringify({
219
+ appId: runtime.appId,
220
+ env: runtime.env
221
+ })
222
+ });
223
+ case 3:
224
+ response = _context6.sent;
225
+ _context6.next = 6;
226
+ return readResponsePayload(response);
227
+ case 6:
228
+ payload = _context6.sent;
229
+ data = isRecord(payload === null || payload === void 0 ? void 0 : payload.data) ? payload.data : null;
230
+ if (!(!response.ok || (payload === null || payload === void 0 ? void 0 : payload.success) !== true || !data)) {
231
+ _context6.next = 10;
232
+ break;
233
+ }
234
+ throw createResponseError({
235
+ payload: payload,
236
+ status: response.status,
237
+ fallbackMessage: "Appwrite config request failed: ".concat(response.status),
238
+ fallbackType: 'appwrite_config_error'
239
+ });
240
+ case 10:
241
+ config = {
242
+ endpoint: data.endpoint,
243
+ projectId: data.projectId,
244
+ databaseId: data.databaseId,
245
+ authTokenEndpoint: data.authTokenEndpoint
246
+ };
247
+ 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)) {
248
+ _context6.next = 13;
249
+ break;
250
+ }
251
+ throw new Error('Appwrite runtime config is incomplete');
252
+ case 13:
253
+ return _context6.abrupt("return", config);
254
+ case 14:
255
+ case "end":
256
+ return _context6.stop();
257
+ }
258
+ }, _callee6, this);
259
+ }));
260
+ function loadRuntimeConfig() {
261
+ return _loadRuntimeConfig.apply(this, arguments);
262
+ }
263
+ return loadRuntimeConfig;
264
+ }()
265
+ }, {
266
+ key: "cacheCurrentSession",
267
+ value: function () {
268
+ var _cacheCurrentSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
269
+ var _yield$Promise$all, _yield$Promise$all2, user, session;
270
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
271
+ while (1) switch (_context7.prev = _context7.next) {
272
+ case 0:
273
+ _context7.next = 2;
274
+ return Promise.all([this.options.account.get(), this.options.account.getSession({
275
+ sessionId: 'current'
276
+ })]);
277
+ case 2:
278
+ _yield$Promise$all = _context7.sent;
279
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
280
+ user = _yield$Promise$all2[0];
281
+ session = _yield$Promise$all2[1];
282
+ this.state.currentUser = user;
283
+ this.state.currentSessionProvider = session.provider;
284
+ case 8:
285
+ case "end":
286
+ return _context7.stop();
287
+ }
288
+ }, _callee7, this);
289
+ }));
290
+ function cacheCurrentSession() {
291
+ return _cacheCurrentSession.apply(this, arguments);
292
+ }
293
+ return cacheCurrentSession;
294
+ }()
295
+ }, {
296
+ key: "tryCacheCurrentSession",
297
+ value: function () {
298
+ var _tryCacheCurrentSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
299
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
300
+ while (1) switch (_context8.prev = _context8.next) {
301
+ case 0:
302
+ _context8.prev = 0;
303
+ _context8.next = 3;
304
+ return this.cacheCurrentSession();
305
+ case 3:
306
+ return _context8.abrupt("return", true);
307
+ case 6:
308
+ _context8.prev = 6;
309
+ _context8.t0 = _context8["catch"](0);
310
+ if (!(getErrorCode(_context8.t0) !== 401)) {
311
+ _context8.next = 10;
312
+ break;
313
+ }
314
+ throw _context8.t0;
315
+ case 10:
316
+ this.clearCurrentSession();
317
+ return _context8.abrupt("return", false);
318
+ case 12:
319
+ case "end":
320
+ return _context8.stop();
321
+ }
322
+ }, _callee8, this, [[0, 6]]);
323
+ }));
324
+ function tryCacheCurrentSession() {
325
+ return _tryCacheCurrentSession.apply(this, arguments);
326
+ }
327
+ return tryCacheCurrentSession;
328
+ }()
329
+ }, {
330
+ key: "deleteCurrentSession",
331
+ value: function () {
332
+ var _deleteCurrentSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
333
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
334
+ while (1) switch (_context9.prev = _context9.next) {
335
+ case 0:
336
+ if (this.state.currentUser) {
337
+ _context9.next = 2;
338
+ break;
339
+ }
340
+ return _context9.abrupt("return");
341
+ case 2:
342
+ _context9.prev = 2;
343
+ _context9.next = 5;
344
+ return this.options.account.deleteSession({
345
+ sessionId: 'current'
346
+ });
347
+ case 5:
348
+ _context9.next = 11;
349
+ break;
350
+ case 7:
351
+ _context9.prev = 7;
352
+ _context9.t0 = _context9["catch"](2);
353
+ if (!(getErrorCode(_context9.t0) !== 401)) {
354
+ _context9.next = 11;
355
+ break;
356
+ }
357
+ throw _context9.t0;
358
+ case 11:
359
+ _context9.prev = 11;
360
+ this.clearCurrentSession();
361
+ return _context9.finish(11);
362
+ case 14:
363
+ case "end":
364
+ return _context9.stop();
365
+ }
366
+ }, _callee9, this, [[2, 7, 11, 14]]);
367
+ }));
368
+ function deleteCurrentSession() {
369
+ return _deleteCurrentSession.apply(this, arguments);
370
+ }
371
+ return deleteCurrentSession;
372
+ }()
373
+ }, {
374
+ key: "ensureAnonymousSession",
375
+ value: function () {
376
+ var _ensureAnonymousSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
377
+ var forceReplace,
378
+ _args10 = arguments;
379
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
380
+ while (1) switch (_context10.prev = _context10.next) {
381
+ case 0:
382
+ forceReplace = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : false;
383
+ if (this.state.currentUser) {
384
+ _context10.next = 4;
385
+ break;
386
+ }
387
+ _context10.next = 4;
388
+ return this.tryCacheCurrentSession();
389
+ case 4:
390
+ if (!(!forceReplace && this.state.currentUser && this.state.currentSessionProvider === 'anonymous')) {
391
+ _context10.next = 7;
392
+ break;
393
+ }
394
+ this.state.confirmedQmuseUserId = null;
395
+ return _context10.abrupt("return");
396
+ case 7:
397
+ _context10.next = 9;
398
+ return this.deleteCurrentSession();
399
+ case 9:
400
+ _context10.next = 11;
401
+ return this.options.account.createAnonymousSession();
402
+ case 11:
403
+ _context10.next = 13;
404
+ return this.cacheCurrentSession();
405
+ case 13:
406
+ this.state.confirmedQmuseUserId = null;
407
+ case 14:
408
+ case "end":
409
+ return _context10.stop();
410
+ }
411
+ }, _callee10, this);
412
+ }));
413
+ function ensureAnonymousSession() {
414
+ return _ensureAnonymousSession.apply(this, arguments);
415
+ }
416
+ return ensureAnonymousSession;
417
+ }()
418
+ }, {
419
+ key: "requestCustomToken",
420
+ value: function () {
421
+ var _requestCustomToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
422
+ var runtime, config, response, payload, data;
423
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
424
+ while (1) switch (_context11.prev = _context11.next) {
425
+ case 0:
426
+ runtime = this.getMuseRuntime();
427
+ config = this.requireRuntimeConfig();
428
+ _context11.next = 4;
429
+ return this.request(new URL(config.authTokenEndpoint, runtime.domain).toString(), {
430
+ method: 'POST',
431
+ credentials: 'include',
432
+ headers: {
433
+ 'Content-Type': 'application/json'
434
+ },
435
+ body: JSON.stringify({
436
+ appId: runtime.appId,
437
+ appVersionId: runtime.appVersionId,
438
+ env: runtime.env,
439
+ projectId: config.projectId
440
+ })
441
+ });
442
+ case 4:
443
+ response = _context11.sent;
444
+ if (!(response.status === 401)) {
445
+ _context11.next = 7;
446
+ break;
447
+ }
448
+ return _context11.abrupt("return", null);
449
+ case 7:
450
+ _context11.next = 9;
451
+ return readResponsePayload(response);
452
+ case 9:
453
+ payload = _context11.sent;
454
+ data = isRecord(payload === null || payload === void 0 ? void 0 : payload.data) ? payload.data : null;
455
+ if (!(!response.ok || (payload === null || payload === void 0 ? void 0 : payload.success) !== true || !data)) {
456
+ _context11.next = 13;
457
+ break;
458
+ }
459
+ throw createResponseError({
460
+ payload: payload,
461
+ status: response.status,
462
+ fallbackMessage: "Custom token request failed: ".concat(response.status),
463
+ fallbackType: 'custom_token_error'
464
+ });
465
+ case 13:
466
+ if (!(typeof data.userId !== 'string' || !data.userId || typeof data.secret !== 'string' || !data.secret)) {
467
+ _context11.next = 15;
468
+ break;
469
+ }
470
+ throw new Error('Custom token response is incomplete');
471
+ case 15:
472
+ return _context11.abrupt("return", {
473
+ userId: data.userId,
474
+ secret: data.secret
475
+ });
476
+ case 16:
477
+ case "end":
478
+ return _context11.stop();
479
+ }
480
+ }, _callee11, this);
481
+ }));
482
+ function requestCustomToken() {
483
+ return _requestCustomToken.apply(this, arguments);
484
+ }
485
+ return requestCustomToken;
486
+ }()
487
+ }, {
488
+ key: "ensureAuthenticatedSession",
489
+ value: function () {
490
+ var _ensureAuthenticatedSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(_ref2) {
491
+ var qmuseUserId, userId, secret, _ref2$forceReplace, forceReplace;
492
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
493
+ while (1) switch (_context12.prev = _context12.next) {
494
+ case 0:
495
+ qmuseUserId = _ref2.qmuseUserId, userId = _ref2.userId, secret = _ref2.secret, _ref2$forceReplace = _ref2.forceReplace, forceReplace = _ref2$forceReplace === void 0 ? false : _ref2$forceReplace;
496
+ if (this.state.currentUser) {
497
+ _context12.next = 4;
498
+ break;
499
+ }
500
+ _context12.next = 4;
501
+ return this.tryCacheCurrentSession();
502
+ case 4:
503
+ if (!(!forceReplace && this.state.currentUser && this.state.currentSessionProvider !== 'anonymous' && this.state.currentUser.$id === userId)) {
504
+ _context12.next = 7;
505
+ break;
506
+ }
507
+ this.state.confirmedQmuseUserId = qmuseUserId;
508
+ return _context12.abrupt("return");
509
+ case 7:
510
+ _context12.next = 9;
511
+ return this.deleteCurrentSession();
512
+ case 9:
513
+ _context12.next = 11;
514
+ return this.options.account.createSession({
515
+ userId: userId,
516
+ secret: secret
517
+ });
518
+ case 11:
519
+ _context12.next = 13;
520
+ return this.cacheCurrentSession();
521
+ case 13:
522
+ this.state.confirmedQmuseUserId = qmuseUserId;
523
+ case 14:
524
+ case "end":
525
+ return _context12.stop();
526
+ }
527
+ }, _callee12, this);
528
+ }));
529
+ function ensureAuthenticatedSession(_x2) {
530
+ return _ensureAuthenticatedSession.apply(this, arguments);
531
+ }
532
+ return ensureAuthenticatedSession;
533
+ }()
534
+ }, {
535
+ key: "coordinateSession",
536
+ value: function () {
537
+ var _coordinateSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
538
+ var force,
539
+ qmuseUserId,
540
+ sessionMatchesRuntime,
541
+ token,
542
+ _args13 = arguments;
543
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
544
+ while (1) switch (_context13.prev = _context13.next) {
545
+ case 0:
546
+ force = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : false;
547
+ qmuseUserId = this.options.getQmuseLoginUserId();
548
+ sessionMatchesRuntime = this.state.currentUser !== null && (qmuseUserId ? this.state.currentSessionProvider !== 'anonymous' && this.state.confirmedQmuseUserId === qmuseUserId : this.state.currentSessionProvider === 'anonymous' && this.state.confirmedQmuseUserId === null);
549
+ if (!(!force && sessionMatchesRuntime)) {
550
+ _context13.next = 5;
551
+ break;
552
+ }
553
+ return _context13.abrupt("return");
554
+ case 5:
555
+ if (this.state.currentUser) {
556
+ _context13.next = 8;
557
+ break;
558
+ }
559
+ _context13.next = 8;
560
+ return this.tryCacheCurrentSession();
561
+ case 8:
562
+ if (qmuseUserId) {
563
+ _context13.next = 12;
564
+ break;
565
+ }
566
+ _context13.next = 11;
567
+ return this.ensureAnonymousSession(force);
568
+ case 11:
569
+ return _context13.abrupt("return");
570
+ case 12:
571
+ if (!(!force && this.state.currentUser && this.state.currentSessionProvider !== 'anonymous' && this.state.confirmedQmuseUserId === qmuseUserId)) {
572
+ _context13.next = 14;
573
+ break;
574
+ }
575
+ return _context13.abrupt("return");
576
+ case 14:
577
+ _context13.next = 16;
578
+ return this.requestCustomToken();
579
+ case 16:
580
+ token = _context13.sent;
581
+ if (token) {
582
+ _context13.next = 21;
583
+ break;
584
+ }
585
+ _context13.next = 20;
586
+ return this.ensureAnonymousSession(force);
587
+ case 20:
588
+ return _context13.abrupt("return");
589
+ case 21:
590
+ _context13.next = 23;
591
+ return this.ensureAuthenticatedSession(_objectSpread(_objectSpread({
592
+ qmuseUserId: qmuseUserId
593
+ }, token), {}, {
594
+ forceReplace: force
595
+ }));
596
+ case 23:
597
+ case "end":
598
+ return _context13.stop();
599
+ }
600
+ }, _callee13, this);
601
+ }));
602
+ function coordinateSession() {
603
+ return _coordinateSession.apply(this, arguments);
604
+ }
605
+ return coordinateSession;
606
+ }()
607
+ }, {
608
+ key: "synchronizeSession",
609
+ value: function synchronizeSession() {
610
+ var _this3 = this;
611
+ if (!this.sessionSyncPromise) {
612
+ this.sessionSyncPromise = this.coordinateSession().finally(function () {
613
+ _this3.sessionSyncPromise = null;
614
+ });
615
+ }
616
+ return this.sessionSyncPromise;
617
+ }
618
+ }, {
619
+ key: "initialize",
620
+ value: function () {
621
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
622
+ var config;
623
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
624
+ while (1) switch (_context14.prev = _context14.next) {
625
+ case 0:
626
+ _context14.next = 2;
627
+ return this.loadRuntimeConfig();
628
+ case 2:
629
+ config = _context14.sent;
630
+ this.options.client.setEndpoint(config.endpoint).setProject(config.projectId);
631
+ this.state.runtimeConfig = config;
632
+ _context14.next = 7;
633
+ return this.synchronizeSession();
634
+ case 7:
635
+ case "end":
636
+ return _context14.stop();
637
+ }
638
+ }, _callee14, this);
639
+ }));
640
+ function initialize() {
641
+ return _initialize.apply(this, arguments);
642
+ }
643
+ return initialize;
644
+ }()
645
+ }]);
646
+ return AppwriteSessionCoordinator;
647
+ }();
@@ -0,0 +1,18 @@
1
+ import type { BusinessRowData, QmuseRuntimeContext } from '../types';
2
+ type MutationOperation = 'create' | 'update' | 'delete';
3
+ interface MutationContext {
4
+ operation: MutationOperation;
5
+ tableId: string;
6
+ rowId: string;
7
+ mutationData?: BusinessRowData;
8
+ }
9
+ export declare class MutationAuditReporter {
10
+ private readonly request;
11
+ private readonly getMuseRuntime;
12
+ constructor(request: typeof globalThis.fetch, getMuseRuntime: () => QmuseRuntimeContext);
13
+ observe<T>({ operation, tableId, rowId, mutationData, task, }: MutationContext & {
14
+ task: () => Promise<T>;
15
+ }): Promise<T>;
16
+ private schedule;
17
+ }
18
+ export {};