@aws-amplify/datastore 4.7.5 → 5.0.1-console-preview.4208d73.0
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 +4 -0
- package/lib/authModeStrategies/defaultAuthStrategy.js +3 -2
- package/lib/authModeStrategies/index.js +3 -3
- package/lib/authModeStrategies/multiAuthStrategy.js +81 -24
- package/lib/datastore/datastore.d.ts +3 -4
- package/lib/datastore/datastore.js +361 -227
- package/lib/index.d.ts +1 -1
- package/lib/index.js +25 -12
- package/lib/predicates/index.js +46 -12
- package/lib/predicates/next.d.ts +2 -2
- package/lib/predicates/next.js +172 -74
- package/lib/predicates/sort.js +3 -4
- package/lib/ssr/index.js +1 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js +240 -128
- package/lib/storage/adapter/AsyncStorageDatabase.js +100 -39
- package/lib/storage/adapter/InMemoryStore.js +68 -17
- package/lib/storage/adapter/InMemoryStore.native.js +5 -3
- package/lib/storage/adapter/IndexedDBAdapter.js +355 -199
- package/lib/storage/adapter/StorageAdapterBase.js +154 -85
- package/lib/storage/adapter/getDefaultAdapter/index.js +8 -9
- package/lib/storage/adapter/getDefaultAdapter/index.native.js +4 -3
- package/lib/storage/adapter/index.js +0 -1
- package/lib/storage/relationship.js +31 -21
- package/lib/storage/storage.d.ts +3 -3
- package/lib/storage/storage.js +143 -61
- package/lib/sync/datastoreConnectivity.d.ts +1 -1
- package/lib/sync/datastoreConnectivity.js +57 -9
- package/lib/sync/datastoreReachability/index.js +3 -3
- package/lib/sync/datastoreReachability/index.native.js +7 -5
- package/lib/sync/index.d.ts +1 -1
- package/lib/sync/index.js +193 -125
- package/lib/sync/merger.js +81 -10
- package/lib/sync/outbox.js +101 -30
- package/lib/sync/processors/errorMaps.d.ts +1 -1
- package/lib/sync/processors/errorMaps.js +41 -6
- package/lib/sync/processors/mutation.d.ts +1 -1
- package/lib/sync/processors/mutation.js +192 -101
- package/lib/sync/processors/subscription.d.ts +4 -1
- package/lib/sync/processors/subscription.js +190 -178
- package/lib/sync/processors/sync.d.ts +1 -1
- package/lib/sync/processors/sync.js +113 -47
- package/lib/sync/utils.d.ts +4 -4
- package/lib/sync/utils.js +162 -81
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types.d.ts +138 -140
- package/lib/types.js +40 -5
- package/lib/util.d.ts +9 -17
- package/lib/util.js +216 -100
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js +0 -1
- package/lib-esm/authModeStrategies/index.js +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +76 -21
- package/lib-esm/datastore/datastore.d.ts +3 -4
- package/lib-esm/datastore/datastore.js +206 -77
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +0 -1
- package/lib-esm/predicates/index.js +40 -7
- package/lib-esm/predicates/next.d.ts +2 -2
- package/lib-esm/predicates/next.js +148 -52
- package/lib-esm/predicates/sort.js +2 -4
- package/lib-esm/ssr/index.js +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js +203 -95
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js +66 -5
- package/lib-esm/storage/adapter/InMemoryStore.js +52 -2
- package/lib-esm/storage/adapter/InMemoryStore.native.js +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +271 -138
- package/lib-esm/storage/adapter/StorageAdapterBase.js +130 -62
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js +2 -5
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js +0 -1
- package/lib-esm/storage/adapter/index.js +1 -1
- package/lib-esm/storage/relationship.js +27 -18
- package/lib-esm/storage/storage.d.ts +3 -3
- package/lib-esm/storage/storage.js +87 -9
- package/lib-esm/sync/datastoreConnectivity.d.ts +1 -1
- package/lib-esm/sync/datastoreConnectivity.js +48 -3
- package/lib-esm/sync/datastoreReachability/index.js +1 -2
- package/lib-esm/sync/datastoreReachability/index.native.js +1 -2
- package/lib-esm/sync/index.d.ts +1 -1
- package/lib-esm/sync/index.js +136 -72
- package/lib-esm/sync/merger.js +73 -3
- package/lib-esm/sync/outbox.js +75 -5
- package/lib-esm/sync/processors/errorMaps.d.ts +1 -1
- package/lib-esm/sync/processors/errorMaps.js +39 -5
- package/lib-esm/sync/processors/mutation.d.ts +1 -1
- package/lib-esm/sync/processors/mutation.js +130 -44
- package/lib-esm/sync/processors/subscription.d.ts +4 -1
- package/lib-esm/sync/processors/subscription.js +134 -126
- package/lib-esm/sync/processors/sync.d.ts +1 -1
- package/lib-esm/sync/processors/sync.js +74 -12
- package/lib-esm/sync/utils.d.ts +4 -4
- package/lib-esm/sync/utils.js +135 -55
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types.d.ts +138 -140
- package/lib-esm/types.js +36 -2
- package/lib-esm/util.d.ts +9 -17
- package/lib-esm/util.js +96 -16
- package/package.json +139 -132
- package/src/authModeStrategies/multiAuthStrategy.ts +11 -12
- package/src/datastore/datastore.ts +32 -25
- package/src/predicates/sort.ts +3 -1
- package/src/storage/adapter/InMemoryStore.ts +1 -1
- package/src/storage/adapter/IndexedDBAdapter.ts +1 -1
- package/src/storage/adapter/StorageAdapterBase.ts +1 -1
- package/src/storage/adapter/getDefaultAdapter/index.ts +2 -3
- package/src/storage/storage.ts +1 -1
- package/src/sync/datastoreConnectivity.ts +2 -2
- package/src/sync/datastoreReachability/index.native.ts +1 -1
- package/src/sync/datastoreReachability/index.ts +1 -1
- package/src/sync/index.ts +69 -78
- package/src/sync/processors/mutation.ts +16 -10
- package/src/sync/processors/subscription.ts +55 -127
- package/src/sync/processors/sync.ts +8 -4
- package/src/sync/utils.ts +7 -8
- package/src/types.ts +4 -8
- package/src/util.ts +5 -6
- package/lib/.tsbuildinfo +0 -3
- package/lib/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib/authModeStrategies/index.js.map +0 -1
- package/lib/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib/datastore/datastore.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/predicates/index.js.map +0 -1
- package/lib/predicates/next.js.map +0 -1
- package/lib/predicates/sort.js.map +0 -1
- package/lib/ssr/index.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib/storage/adapter/index.js.map +0 -1
- package/lib/storage/relationship.js.map +0 -1
- package/lib/storage/storage.js.map +0 -1
- package/lib/sync/datastoreConnectivity.js.map +0 -1
- package/lib/sync/datastoreReachability/index.js.map +0 -1
- package/lib/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib/sync/index.js.map +0 -1
- package/lib/sync/merger.js.map +0 -1
- package/lib/sync/outbox.js.map +0 -1
- package/lib/sync/processors/errorMaps.js.map +0 -1
- package/lib/sync/processors/mutation.js.map +0 -1
- package/lib/sync/processors/subscription.js.map +0 -1
- package/lib/sync/processors/sync.js.map +0 -1
- package/lib/sync/utils.js.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/util.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/authModeStrategies/defaultAuthStrategy.js.map +0 -1
- package/lib-esm/authModeStrategies/index.js.map +0 -1
- package/lib-esm/authModeStrategies/multiAuthStrategy.js.map +0 -1
- package/lib-esm/datastore/datastore.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/predicates/index.js.map +0 -1
- package/lib-esm/predicates/next.js.map +0 -1
- package/lib-esm/predicates/sort.js.map +0 -1
- package/lib-esm/ssr/index.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/AsyncStorageDatabase.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.js.map +0 -1
- package/lib-esm/storage/adapter/InMemoryStore.native.js.map +0 -1
- package/lib-esm/storage/adapter/IndexedDBAdapter.js.map +0 -1
- package/lib-esm/storage/adapter/StorageAdapterBase.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.js.map +0 -1
- package/lib-esm/storage/adapter/getDefaultAdapter/index.native.js.map +0 -1
- package/lib-esm/storage/adapter/index.js.map +0 -1
- package/lib-esm/storage/relationship.js.map +0 -1
- package/lib-esm/storage/storage.js.map +0 -1
- package/lib-esm/sync/datastoreConnectivity.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.js.map +0 -1
- package/lib-esm/sync/datastoreReachability/index.native.js.map +0 -1
- package/lib-esm/sync/index.js.map +0 -1
- package/lib-esm/sync/merger.js.map +0 -1
- package/lib-esm/sync/outbox.js.map +0 -1
- package/lib-esm/sync/processors/errorMaps.js.map +0 -1
- package/lib-esm/sync/processors/mutation.js.map +0 -1
- package/lib-esm/sync/processors/subscription.js.map +0 -1
- package/lib-esm/sync/processors/sync.js.map +0 -1
- package/lib-esm/sync/utils.js.map +0 -1
- package/lib-esm/types.js.map +0 -1
- package/lib-esm/util.js.map +0 -1
|
@@ -1,18 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
49
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
50
|
+
if (!m) return o;
|
|
51
|
+
var i = m.call(o), r, ar = [], e;
|
|
52
|
+
try {
|
|
53
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
54
|
+
}
|
|
55
|
+
catch (error) { e = { error: error }; }
|
|
56
|
+
finally {
|
|
57
|
+
try {
|
|
58
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
59
|
+
}
|
|
60
|
+
finally { if (e) throw e.error; }
|
|
61
|
+
}
|
|
62
|
+
return ar;
|
|
63
|
+
};
|
|
64
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
65
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
66
|
+
if (ar || !(i in from)) {
|
|
67
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
68
|
+
ar[i] = from[i];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
72
|
+
};
|
|
5
73
|
import { InternalAPI } from '@aws-amplify/api/internals';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { Category, ConsoleLogger as Logger, DataStoreAction, Hub, BackgroundProcessManager, } from '@aws-amplify/core';
|
|
9
|
-
import { CONTROL_MSG as PUBSUB_CONTROL_MSG } from '@aws-amplify/pubsub';
|
|
74
|
+
import { Hub, fetchAuthSession } from '@aws-amplify/core';
|
|
75
|
+
import { Category, Logger, DataStoreAction, BackgroundProcessManager, } from '@aws-amplify/core/internals/utils';
|
|
10
76
|
import Observable from 'zen-observable-ts';
|
|
11
77
|
import { ProcessName, } from '../../types';
|
|
12
78
|
import { buildSubscriptionGraphQLOperation, getAuthorizationRules, getModelAuthModes, getUserGroupsFromToken, TransformerMutationType, getTokenForCustomAuth, predicateToGraphQLFilter, RTFError, generateRTFRemediation, } from '../utils';
|
|
13
79
|
import { ModelPredicateCreator } from '../../predicates';
|
|
14
80
|
import { validatePredicate } from '../../util';
|
|
15
81
|
import { getSubscriptionErrorType } from './errorMaps';
|
|
82
|
+
import { CONTROL_MSG as PUBSUB_CONTROL_MSG } from '@aws-amplify/api-graphql';
|
|
16
83
|
var logger = new Logger('DataStore');
|
|
17
84
|
export var CONTROL_MSG;
|
|
18
85
|
(function (CONTROL_MSG) {
|
|
@@ -28,9 +95,7 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
28
95
|
function SubscriptionProcessor(schema, syncPredicates, amplifyConfig, authModeStrategy, errorHandler, amplifyContext) {
|
|
29
96
|
if (amplifyConfig === void 0) { amplifyConfig = {}; }
|
|
30
97
|
if (amplifyContext === void 0) { amplifyContext = {
|
|
31
|
-
Auth: Auth,
|
|
32
98
|
InternalAPI: InternalAPI,
|
|
33
|
-
Cache: Cache,
|
|
34
99
|
}; }
|
|
35
100
|
this.schema = schema;
|
|
36
101
|
this.syncPredicates = syncPredicates;
|
|
@@ -42,19 +107,17 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
42
107
|
this.buffer = [];
|
|
43
108
|
this.runningProcesses = new BackgroundProcessManager();
|
|
44
109
|
}
|
|
45
|
-
SubscriptionProcessor.prototype.buildSubscription = function (namespace, model, transformerMutationType, userCredentials,
|
|
110
|
+
SubscriptionProcessor.prototype.buildSubscription = function (namespace, model, transformerMutationType, userCredentials, oidcTokenPayload, authMode, filterArg) {
|
|
46
111
|
if (filterArg === void 0) { filterArg = false; }
|
|
47
112
|
var aws_appsync_authenticationType = this.amplifyConfig.aws_appsync_authenticationType;
|
|
48
|
-
var _a = this.getAuthorizationInfo(model, userCredentials, aws_appsync_authenticationType,
|
|
113
|
+
var _a = this.getAuthorizationInfo(model, userCredentials, aws_appsync_authenticationType, oidcTokenPayload, authMode) || {}, isOwner = _a.isOwner, ownerField = _a.ownerField, ownerValue = _a.ownerValue;
|
|
49
114
|
var _b = __read(buildSubscriptionGraphQLOperation(namespace, model, transformerMutationType, isOwner, ownerField, filterArg), 3), opType = _b[0], opName = _b[1], query = _b[2];
|
|
50
115
|
return { authMode: authMode, opType: opType, opName: opName, query: query, isOwner: isOwner, ownerField: ownerField, ownerValue: ownerValue };
|
|
51
116
|
};
|
|
52
|
-
SubscriptionProcessor.prototype.getAuthorizationInfo = function (model, userCredentials, defaultAuthType,
|
|
53
|
-
if (cognitoTokenPayload === void 0) { cognitoTokenPayload = {}; }
|
|
54
|
-
if (oidcTokenPayload === void 0) { oidcTokenPayload = {}; }
|
|
117
|
+
SubscriptionProcessor.prototype.getAuthorizationInfo = function (model, userCredentials, defaultAuthType, oidcTokenPayload, authMode) {
|
|
55
118
|
var rules = getAuthorizationRules(model);
|
|
56
119
|
// Return null if user doesn't have proper credentials for private API with IAM auth
|
|
57
|
-
var iamPrivateAuth = authMode ===
|
|
120
|
+
var iamPrivateAuth = authMode === 'iam' &&
|
|
58
121
|
rules.find(function (rule) { return rule.authStrategy === 'private' && rule.provider === 'iam'; });
|
|
59
122
|
if (iamPrivateAuth && userCredentials === USER_CREDENTIALS.unauth) {
|
|
60
123
|
return null;
|
|
@@ -67,15 +130,15 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
67
130
|
return rule.authStrategy === 'groups' &&
|
|
68
131
|
['userPools', 'oidc'].includes(rule.provider);
|
|
69
132
|
});
|
|
70
|
-
var validGroup =
|
|
71
|
-
authMode === GRAPHQL_AUTH_MODE.OPENID_CONNECT) &&
|
|
133
|
+
var validGroup = authMode === 'jwt' &&
|
|
72
134
|
groupAuthRules.find(function (groupAuthRule) {
|
|
73
135
|
// validate token against groupClaim
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
136
|
+
if (oidcTokenPayload) {
|
|
137
|
+
var oidcUserGroups = getUserGroupsFromToken(oidcTokenPayload, groupAuthRule);
|
|
138
|
+
return __spreadArray([], __read(oidcUserGroups), false).find(function (userGroup) {
|
|
139
|
+
return groupAuthRule.groups.find(function (group) { return group === userGroup; });
|
|
140
|
+
});
|
|
141
|
+
}
|
|
79
142
|
});
|
|
80
143
|
if (validGroup) {
|
|
81
144
|
return {
|
|
@@ -83,40 +146,18 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
83
146
|
isOwner: false,
|
|
84
147
|
};
|
|
85
148
|
}
|
|
86
|
-
// Owner auth needs additional values to be returned in order to create the subscription with
|
|
87
|
-
// the correct parameters so we are getting the owner value from the Cognito token via the
|
|
88
|
-
// identityClaim from the auth rule.
|
|
89
|
-
var cognitoOwnerAuthRules = authMode === GRAPHQL_AUTH_MODE.AMAZON_COGNITO_USER_POOLS
|
|
90
|
-
? rules.filter(function (rule) {
|
|
91
|
-
return rule.authStrategy === 'owner' && rule.provider === 'userPools';
|
|
92
|
-
})
|
|
93
|
-
: [];
|
|
94
149
|
var ownerAuthInfo;
|
|
95
|
-
cognitoOwnerAuthRules.forEach(function (ownerAuthRule) {
|
|
96
|
-
var _a;
|
|
97
|
-
var ownerValue = cognitoTokenPayload[ownerAuthRule.identityClaim];
|
|
98
|
-
// AuthZ for "list of owners" is handled dynamically in the subscription auth request
|
|
99
|
-
// resolver. It doesn't rely on a subscription arg.
|
|
100
|
-
// Only pass a subscription arg for single owner auth
|
|
101
|
-
var singleOwner = ((_a = model.fields[ownerAuthRule.ownerField]) === null || _a === void 0 ? void 0 : _a.isArray) !== true;
|
|
102
|
-
var isOwnerArgRequired = singleOwner && !ownerAuthRule.areSubscriptionsPublic;
|
|
103
|
-
if (ownerValue) {
|
|
104
|
-
ownerAuthInfo = {
|
|
105
|
-
authMode: GRAPHQL_AUTH_MODE.AMAZON_COGNITO_USER_POOLS,
|
|
106
|
-
isOwner: isOwnerArgRequired,
|
|
107
|
-
ownerField: ownerAuthRule.ownerField,
|
|
108
|
-
ownerValue: ownerValue,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
150
|
if (ownerAuthInfo) {
|
|
113
151
|
return ownerAuthInfo;
|
|
114
152
|
}
|
|
115
153
|
// Owner auth needs additional values to be returned in order to create the subscription with
|
|
116
154
|
// the correct parameters so we are getting the owner value from the OIDC token via the
|
|
117
155
|
// identityClaim from the auth rule.
|
|
118
|
-
var oidcOwnerAuthRules = authMode ===
|
|
119
|
-
? rules.filter(function (rule) {
|
|
156
|
+
var oidcOwnerAuthRules = authMode === 'jwt'
|
|
157
|
+
? rules.filter(function (rule) {
|
|
158
|
+
return rule.authStrategy === 'owner' &&
|
|
159
|
+
(rule.provider === 'oidc' || rule.provider === 'userPools');
|
|
160
|
+
})
|
|
120
161
|
: [];
|
|
121
162
|
oidcOwnerAuthRules.forEach(function (ownerAuthRule) {
|
|
122
163
|
var _a;
|
|
@@ -125,10 +166,10 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
125
166
|
var isOwnerArgRequired = singleOwner && !ownerAuthRule.areSubscriptionsPublic;
|
|
126
167
|
if (ownerValue) {
|
|
127
168
|
ownerAuthInfo = {
|
|
128
|
-
authMode:
|
|
169
|
+
authMode: 'jwt',
|
|
129
170
|
isOwner: isOwnerArgRequired,
|
|
130
171
|
ownerField: ownerAuthRule.ownerField,
|
|
131
|
-
ownerValue: ownerValue,
|
|
172
|
+
ownerValue: String(ownerValue),
|
|
132
173
|
};
|
|
133
174
|
}
|
|
134
175
|
});
|
|
@@ -156,66 +197,38 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
156
197
|
// Creating subs for each model/operation combo so they can be unsubscribed
|
|
157
198
|
// independently, since the auth retry behavior is asynchronous.
|
|
158
199
|
var subscriptions = {};
|
|
159
|
-
var
|
|
200
|
+
var oidcTokenPayload;
|
|
160
201
|
var userCredentials = USER_CREDENTIALS.none;
|
|
161
202
|
_this.runningProcesses.add(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
162
|
-
var credentials, err_1, session, err_2
|
|
203
|
+
var credentials, err_1, session, err_2;
|
|
163
204
|
var _this = this;
|
|
164
|
-
|
|
165
|
-
|
|
205
|
+
var _a, _b, _c;
|
|
206
|
+
return __generator(this, function (_d) {
|
|
207
|
+
switch (_d.label) {
|
|
166
208
|
case 0:
|
|
167
|
-
|
|
168
|
-
return [4 /*yield*/,
|
|
209
|
+
_d.trys.push([0, 2, , 3]);
|
|
210
|
+
return [4 /*yield*/, fetchAuthSession()];
|
|
169
211
|
case 1:
|
|
170
|
-
credentials =
|
|
171
|
-
userCredentials = credentials
|
|
212
|
+
credentials = (_a = (_d.sent()).tokens) === null || _a === void 0 ? void 0 : _a.accessToken;
|
|
213
|
+
userCredentials = credentials
|
|
172
214
|
? USER_CREDENTIALS.auth
|
|
173
215
|
: USER_CREDENTIALS.unauth;
|
|
174
216
|
return [3 /*break*/, 3];
|
|
175
217
|
case 2:
|
|
176
|
-
err_1 =
|
|
218
|
+
err_1 = _d.sent();
|
|
177
219
|
return [3 /*break*/, 3];
|
|
178
220
|
case 3:
|
|
179
|
-
|
|
180
|
-
return [4 /*yield*/,
|
|
181
|
-
case 4:
|
|
182
|
-
session = _b.sent();
|
|
183
|
-
cognitoTokenPayload = session.getIdToken().decodePayload();
|
|
184
|
-
return [3 /*break*/, 6];
|
|
221
|
+
_d.trys.push([3, 6, , 7]);
|
|
222
|
+
return [4 /*yield*/, fetchAuthSession()];
|
|
223
|
+
case 4: return [4 /*yield*/, _d.sent()];
|
|
185
224
|
case 5:
|
|
186
|
-
|
|
187
|
-
|
|
225
|
+
session = _d.sent();
|
|
226
|
+
oidcTokenPayload = (_c = (_b = session.tokens) === null || _b === void 0 ? void 0 : _b.idToken) === null || _c === void 0 ? void 0 : _c.payload;
|
|
227
|
+
return [3 /*break*/, 7];
|
|
188
228
|
case 6:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (!aws_cognito_region || (AuthConfig && !AuthConfig.region)) {
|
|
192
|
-
throw 'Auth is not configured';
|
|
193
|
-
}
|
|
194
|
-
token = void 0;
|
|
195
|
-
return [4 /*yield*/, this.amplifyContext.Cache.getItem('federatedInfo')];
|
|
229
|
+
err_2 = _d.sent();
|
|
230
|
+
return [3 /*break*/, 7];
|
|
196
231
|
case 7:
|
|
197
|
-
federatedInfo = _b.sent();
|
|
198
|
-
if (!federatedInfo) return [3 /*break*/, 8];
|
|
199
|
-
token = federatedInfo.token;
|
|
200
|
-
return [3 /*break*/, 10];
|
|
201
|
-
case 8: return [4 /*yield*/, this.amplifyContext.Auth.currentAuthenticatedUser()];
|
|
202
|
-
case 9:
|
|
203
|
-
currentUser = _b.sent();
|
|
204
|
-
if (currentUser) {
|
|
205
|
-
token = currentUser.token;
|
|
206
|
-
}
|
|
207
|
-
_b.label = 10;
|
|
208
|
-
case 10:
|
|
209
|
-
if (token) {
|
|
210
|
-
payload = token.split('.')[1];
|
|
211
|
-
oidcTokenPayload = JSON.parse(Buffer.from(payload, 'base64').toString('utf8'));
|
|
212
|
-
}
|
|
213
|
-
return [3 /*break*/, 12];
|
|
214
|
-
case 11:
|
|
215
|
-
err_3 = _b.sent();
|
|
216
|
-
logger.debug('error getting OIDC JWT', err_3);
|
|
217
|
-
return [3 /*break*/, 12];
|
|
218
|
-
case 12:
|
|
219
232
|
Object.values(this.schema.namespaces).forEach(function (namespace) {
|
|
220
233
|
Object.values(namespace.models)
|
|
221
234
|
.filter(function (_a) {
|
|
@@ -264,7 +277,7 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
264
277
|
return __generator(this, function (_b) {
|
|
265
278
|
switch (_b.label) {
|
|
266
279
|
case 0:
|
|
267
|
-
_a = this.buildSubscription(namespace, modelDefinition, operation, userCredentials,
|
|
280
|
+
_a = this.buildSubscription(namespace, modelDefinition, operation, userCredentials, oidcTokenPayload, readAuthModes[operationAuthModeAttempts[operation]], addFilter), transformerMutationType = _a.opType, opName = _a.opName, query = _a.query, isOwner = _a.isOwner, ownerField = _a.ownerField, ownerValue = _a.ownerValue, authMode = _a.authMode;
|
|
268
281
|
return [4 /*yield*/, getTokenForCustomAuth(authMode, this.amplifyConfig)];
|
|
269
282
|
case 1:
|
|
270
283
|
authToken = _b.sent();
|
|
@@ -284,30 +297,26 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
284
297
|
}
|
|
285
298
|
variables[ownerField] = ownerValue;
|
|
286
299
|
}
|
|
287
|
-
logger.debug("Attempting "
|
|
288
|
-
queryObservable = this.amplifyContext.InternalAPI.graphql(__assign(__assign({ query: query,
|
|
289
|
-
variables: variables }, { authMode: authMode }), { authToken: authToken }), undefined, customUserAgentDetails);
|
|
300
|
+
logger.debug("Attempting ".concat(operation, " subscription with authMode: ").concat(readAuthModes[operationAuthModeAttempts[operation]]));
|
|
301
|
+
queryObservable = this.amplifyContext.InternalAPI.graphql(__assign(__assign({ query: query, variables: variables }, { authMode: authMode }), { authToken: authToken }), undefined, customUserAgentDetails);
|
|
290
302
|
// TODO: consider onTerminate.then(() => API.cancel(...))
|
|
291
303
|
subscriptions[modelDefinition.name][transformerMutationType].push(queryObservable
|
|
292
|
-
.
|
|
293
|
-
var value = _a.value;
|
|
294
|
-
return value;
|
|
295
|
-
})
|
|
304
|
+
.filter(function () { return true; }) // to make change more readable
|
|
296
305
|
.subscribe({
|
|
297
|
-
next: function (
|
|
298
|
-
var data =
|
|
306
|
+
next: function (result) {
|
|
307
|
+
var data = result.data, errors = result.errors;
|
|
299
308
|
if (Array.isArray(errors) && errors.length > 0) {
|
|
300
309
|
var messages = errors.map(function (_a) {
|
|
301
310
|
var message = _a.message;
|
|
302
311
|
return message;
|
|
303
312
|
});
|
|
304
|
-
logger.warn("Skipping incoming subscription. Messages: "
|
|
313
|
+
logger.warn("Skipping incoming subscription. Messages: ".concat(messages.join('\n')));
|
|
305
314
|
_this.drainBuffer();
|
|
306
315
|
return;
|
|
307
316
|
}
|
|
308
317
|
var predicatesGroup = ModelPredicateCreator.getPredicates(_this.syncPredicates.get(modelDefinition), false);
|
|
309
318
|
// @ts-ignore
|
|
310
|
-
var
|
|
319
|
+
var _a = data, _b = opName, record = _a[_b];
|
|
311
320
|
// checking incoming subscription against syncPredicate.
|
|
312
321
|
// once AppSync implements filters on subscriptions, we'll be
|
|
313
322
|
// able to set these when establishing the subscription instead.
|
|
@@ -318,13 +327,13 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
318
327
|
_this.drainBuffer();
|
|
319
328
|
},
|
|
320
329
|
error: function (subscriptionError) { return __awaiter(_this, void 0, void 0, function () {
|
|
321
|
-
var _a, _b, _c, _d, message, isRTFError, e_1;
|
|
322
|
-
return __generator(this, function (
|
|
323
|
-
switch (
|
|
330
|
+
var _a, _b, _c, _d, _e, _f, message, isRTFError, e_1;
|
|
331
|
+
return __generator(this, function (_g) {
|
|
332
|
+
switch (_g.label) {
|
|
324
333
|
case 0:
|
|
325
|
-
_a = subscriptionError.error, _b =
|
|
334
|
+
_a = subscriptionError.error, _b = _a === void 0 ? {
|
|
326
335
|
errors: [],
|
|
327
|
-
} : _a
|
|
336
|
+
} : _a, _c = __read(_b.errors, 1), _d = _c[0], _e = _d === void 0 ? {} : _d, _f = _e.message, message = _f === void 0 ? '' : _f;
|
|
328
337
|
isRTFError =
|
|
329
338
|
// only attempt catch if a filter variable was added to the subscription query
|
|
330
339
|
addFilter &&
|
|
@@ -351,20 +360,20 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
351
360
|
if (operationAuthModeAttempts[operation] >=
|
|
352
361
|
readAuthModes.length) {
|
|
353
362
|
// last auth mode retry. Continue with error
|
|
354
|
-
logger.debug(operation
|
|
363
|
+
logger.debug("".concat(operation, " subscription failed with authMode: ").concat(readAuthModes[operationAuthModeAttempts[operation] - 1]));
|
|
355
364
|
}
|
|
356
365
|
else {
|
|
357
366
|
// retry with different auth mode. Do not trigger
|
|
358
367
|
// observer error or error handler
|
|
359
|
-
logger.debug(operation
|
|
368
|
+
logger.debug("".concat(operation, " subscription failed with authMode: ").concat(readAuthModes[operationAuthModeAttempts[operation] - 1], ". Retrying with authMode: ").concat(readAuthModes[operationAuthModeAttempts[operation]]));
|
|
360
369
|
subscriptionRetry(operation);
|
|
361
370
|
return [2 /*return*/];
|
|
362
371
|
}
|
|
363
372
|
}
|
|
364
373
|
logger.warn('subscriptionError', message);
|
|
365
|
-
|
|
374
|
+
_g.label = 1;
|
|
366
375
|
case 1:
|
|
367
|
-
|
|
376
|
+
_g.trys.push([1, 3, , 4]);
|
|
368
377
|
return [4 /*yield*/, this.errorHandler({
|
|
369
378
|
recoverySuggestion: 'Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues',
|
|
370
379
|
localModel: null,
|
|
@@ -377,10 +386,10 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
377
386
|
cause: subscriptionError,
|
|
378
387
|
})];
|
|
379
388
|
case 2:
|
|
380
|
-
|
|
389
|
+
_g.sent();
|
|
381
390
|
return [3 /*break*/, 4];
|
|
382
391
|
case 3:
|
|
383
|
-
e_1 =
|
|
392
|
+
e_1 = _g.sent();
|
|
384
393
|
logger.error('Subscription error handler failed with:', e_1);
|
|
385
394
|
return [3 /*break*/, 4];
|
|
386
395
|
case 4:
|
|
@@ -398,18 +407,18 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
398
407
|
}); },
|
|
399
408
|
}));
|
|
400
409
|
promises.push((function () { return __awaiter(_this, void 0, void 0, function () {
|
|
401
|
-
var boundFunction;
|
|
410
|
+
var boundFunction, removeBoundFunctionListener;
|
|
402
411
|
var _this = this;
|
|
403
412
|
return __generator(this, function (_a) {
|
|
404
413
|
switch (_a.label) {
|
|
405
414
|
case 0: return [4 /*yield*/, new Promise(function (res) {
|
|
406
415
|
subscriptionReadyCallback = res;
|
|
407
416
|
boundFunction = _this.hubQueryCompletionListener.bind(_this, res);
|
|
408
|
-
Hub.listen('api', boundFunction);
|
|
417
|
+
removeBoundFunctionListener = Hub.listen('api', boundFunction);
|
|
409
418
|
})];
|
|
410
419
|
case 1:
|
|
411
420
|
_a.sent();
|
|
412
|
-
|
|
421
|
+
removeBoundFunctionListener();
|
|
413
422
|
return [2 /*return*/];
|
|
414
423
|
}
|
|
415
424
|
});
|
|
@@ -513,7 +522,7 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
513
522
|
}) || [], 2), _errorMsg = _a[0], errorType = _a[1];
|
|
514
523
|
if (errorType !== undefined) {
|
|
515
524
|
var remediationMessage = generateRTFRemediation(errorType, modelDefinition, predicatesGroup);
|
|
516
|
-
logger.warn(header
|
|
525
|
+
logger.warn("".concat(header, "\n").concat(message, "\n").concat(remediationMessage));
|
|
517
526
|
return true;
|
|
518
527
|
}
|
|
519
528
|
return false;
|
|
@@ -521,4 +530,3 @@ var SubscriptionProcessor = /** @class */ (function () {
|
|
|
521
530
|
return SubscriptionProcessor;
|
|
522
531
|
}());
|
|
523
532
|
export { SubscriptionProcessor };
|
|
524
|
-
//# sourceMappingURL=subscription.js.map
|
|
@@ -17,7 +17,7 @@ declare class SyncProcessor {
|
|
|
17
17
|
start(typesLastSync: Map<SchemaModel, [string, number]>): Observable<SyncModelPage>;
|
|
18
18
|
stop(): Promise<void>;
|
|
19
19
|
}
|
|
20
|
-
export
|
|
20
|
+
export type SyncModelPage = {
|
|
21
21
|
namespace: string;
|
|
22
22
|
modelDefinition: SchemaModel;
|
|
23
23
|
items: ModelInstanceMetadata[];
|
|
@@ -1,9 +1,72 @@
|
|
|
1
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
38
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
39
|
+
if (!m) return o;
|
|
40
|
+
var i = m.call(o), r, ar = [], e;
|
|
41
|
+
try {
|
|
42
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
43
|
+
}
|
|
44
|
+
catch (error) { e = { error: error }; }
|
|
45
|
+
finally {
|
|
46
|
+
try {
|
|
47
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
48
|
+
}
|
|
49
|
+
finally { if (e) throw e.error; }
|
|
50
|
+
}
|
|
51
|
+
return ar;
|
|
52
|
+
};
|
|
53
|
+
var __values = (this && this.__values) || function(o) {
|
|
54
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
55
|
+
if (m) return m.call(o);
|
|
56
|
+
if (o && typeof o.length === "number") return {
|
|
57
|
+
next: function () {
|
|
58
|
+
if (o && i >= o.length) o = void 0;
|
|
59
|
+
return { value: o && o[i++], done: !o };
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
63
|
+
};
|
|
2
64
|
import { InternalAPI } from '@aws-amplify/api/internals';
|
|
3
65
|
import Observable from 'zen-observable-ts';
|
|
4
66
|
import { ProcessName, } from '../../types';
|
|
5
67
|
import { buildGraphQLOperation, getModelAuthModes, getClientSideAuthError, getForbiddenError, predicateToGraphQLFilter, getTokenForCustomAuth, } from '../utils';
|
|
6
|
-
import { jitteredExponentialRetry, Category, ConsoleLogger as Logger, DataStoreAction,
|
|
68
|
+
import { jitteredExponentialRetry, Category, ConsoleLogger as Logger, DataStoreAction, NonRetryableError, BackgroundProcessManager, } from '@aws-amplify/core/internals/utils';
|
|
69
|
+
import { Hub } from '@aws-amplify/core';
|
|
7
70
|
import { ModelPredicateCreator } from '../../predicates';
|
|
8
71
|
import { getSyncErrorType } from './errorMaps';
|
|
9
72
|
var opResultDefaults = {
|
|
@@ -87,7 +150,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
87
150
|
_b.label = 1;
|
|
88
151
|
case 1:
|
|
89
152
|
_b.trys.push([1, 3, , 5]);
|
|
90
|
-
logger.debug("Attempting sync with authMode: "
|
|
153
|
+
logger.debug("Attempting sync with authMode: ".concat(readAuthModes[authModeAttempts]));
|
|
91
154
|
return [4 /*yield*/, this.jitteredRetry({
|
|
92
155
|
query: query,
|
|
93
156
|
variables: variables,
|
|
@@ -98,17 +161,17 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
98
161
|
})];
|
|
99
162
|
case 2:
|
|
100
163
|
response = _b.sent();
|
|
101
|
-
logger.debug("Sync successful with authMode: "
|
|
164
|
+
logger.debug("Sync successful with authMode: ".concat(readAuthModes[authModeAttempts]));
|
|
102
165
|
return [2 /*return*/, response];
|
|
103
166
|
case 3:
|
|
104
167
|
error_1 = _b.sent();
|
|
105
168
|
authModeAttempts++;
|
|
106
169
|
if (authModeAttempts >= readAuthModes.length) {
|
|
107
170
|
authMode = readAuthModes[authModeAttempts - 1];
|
|
108
|
-
logger.debug("Sync failed with authMode: "
|
|
171
|
+
logger.debug("Sync failed with authMode: ".concat(authMode), error_1);
|
|
109
172
|
if (getClientSideAuthError(error_1) || getForbiddenError(error_1)) {
|
|
110
173
|
// return empty list of data so DataStore will continue to sync other models
|
|
111
|
-
logger.warn("User is unauthorized to query "
|
|
174
|
+
logger.warn("User is unauthorized to query ".concat(opName, " with auth mode ").concat(authMode, ". No data could be returned."));
|
|
112
175
|
return [2 /*return*/, {
|
|
113
176
|
data: (_a = {},
|
|
114
177
|
_a[opName] = opResultDefaults,
|
|
@@ -117,7 +180,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
117
180
|
}
|
|
118
181
|
throw error_1;
|
|
119
182
|
}
|
|
120
|
-
logger.debug("Sync failed with authMode: "
|
|
183
|
+
logger.debug("Sync failed with authMode: ".concat(readAuthModes[authModeAttempts - 1], ". Retrying with authMode: ").concat(readAuthModes[authModeAttempts]));
|
|
121
184
|
return [4 /*yield*/, authModeRetry()];
|
|
122
185
|
case 4: return [2 /*return*/, _b.sent()];
|
|
123
186
|
case 5: return [2 /*return*/];
|
|
@@ -318,7 +381,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
318
381
|
filter = this.graphqlFilterFromPredicate(modelDefinition);
|
|
319
382
|
parents = this.schema.namespaces[namespace].modelTopologicalOrdering.get(modelDefinition.name);
|
|
320
383
|
promises = parents.map(function (parent) {
|
|
321
|
-
return parentPromises.get(namespace
|
|
384
|
+
return parentPromises.get("".concat(namespace, "_").concat(parent));
|
|
322
385
|
});
|
|
323
386
|
promise = new Promise(function (res) { return __awaiter(_this, void 0, void 0, function () {
|
|
324
387
|
var limit, error_3, e_3;
|
|
@@ -336,7 +399,7 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
336
399
|
* finished terminating and/or waiting for its background processes to complete.
|
|
337
400
|
*/
|
|
338
401
|
if (!this.runningProcesses.isOpen) {
|
|
339
|
-
logger.debug("Sync processor has been stopped, terminating sync for "
|
|
402
|
+
logger.debug("Sync processor has been stopped, terminating sync for ".concat(modelDefinition.name));
|
|
340
403
|
return [2 /*return*/, res()];
|
|
341
404
|
}
|
|
342
405
|
limit = Math.min(maxRecordsToSync - recordsReceived, syncPageSize);
|
|
@@ -403,14 +466,14 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
403
466
|
}
|
|
404
467
|
});
|
|
405
468
|
}); });
|
|
406
|
-
parentPromises.set(namespace
|
|
469
|
+
parentPromises.set("".concat(namespace, "_").concat(modelDefinition.name), promise);
|
|
407
470
|
return [4 /*yield*/, promise];
|
|
408
471
|
case 1:
|
|
409
472
|
_a.sent();
|
|
410
473
|
return [2 /*return*/];
|
|
411
474
|
}
|
|
412
475
|
});
|
|
413
|
-
}); }, "adding model "
|
|
476
|
+
}); }, "adding model ".concat(modelDefinition.name));
|
|
414
477
|
});
|
|
415
478
|
Promise.all(allModelsReady).then(function () {
|
|
416
479
|
observer.complete();
|
|
@@ -439,4 +502,3 @@ var SyncProcessor = /** @class */ (function () {
|
|
|
439
502
|
return SyncProcessor;
|
|
440
503
|
}());
|
|
441
504
|
export { SyncProcessor };
|
|
442
|
-
//# sourceMappingURL=sync.js.map
|