@aws-amplify/datastore 5.0.1-api-v6-models.8035dfc.0 → 5.0.1-api-v6-models.572a7b5.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/lib/authModeStrategies/multiAuthStrategy.js +6 -2
- package/lib/datastore/datastore.js +11 -10
- package/lib/storage/adapter/IndexedDBAdapter.js +2 -2
- package/lib/storage/adapter/StorageAdapterBase.js +2 -2
- package/lib/storage/storage.js +2 -1
- package/lib/sync/datastoreConnectivity.js +2 -2
- package/lib/sync/index.js +1 -1
- package/lib/sync/processors/errorMaps.js +5 -7
- package/lib/sync/processors/mutation.js +2 -1
- package/lib/sync/processors/subscription.js +10 -11
- package/lib/sync/processors/sync.js +11 -11
- package/lib/sync/utils.d.ts +1 -0
- package/lib/sync/utils.js +20 -9
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/util.js +4 -4
- package/lib-esm/authModeStrategies/multiAuthStrategy.js +6 -2
- package/lib-esm/datastore/datastore.js +7 -6
- package/lib-esm/storage/adapter/IndexedDBAdapter.js +2 -2
- package/lib-esm/storage/adapter/StorageAdapterBase.js +2 -2
- package/lib-esm/storage/storage.js +3 -2
- package/lib-esm/sync/datastoreConnectivity.js +2 -2
- package/lib-esm/sync/index.js +3 -3
- package/lib-esm/sync/processors/errorMaps.js +5 -7
- package/lib-esm/sync/processors/mutation.js +3 -2
- package/lib-esm/sync/processors/subscription.js +12 -13
- package/lib-esm/sync/processors/sync.js +13 -13
- package/lib-esm/sync/utils.d.ts +1 -0
- package/lib-esm/sync/utils.js +18 -8
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/util.js +4 -4
- package/package.json +9 -10
- package/src/authModeStrategies/multiAuthStrategy.ts +5 -1
- package/src/datastore/datastore.ts +7 -9
- package/src/storage/adapter/IndexedDBAdapter.ts +2 -2
- package/src/storage/adapter/StorageAdapterBase.ts +2 -2
- package/src/storage/storage.ts +3 -2
- package/src/sync/datastoreConnectivity.ts +2 -2
- package/src/sync/index.ts +4 -7
- package/src/sync/processors/errorMaps.ts +7 -7
- package/src/sync/processors/mutation.ts +2 -2
- package/src/sync/processors/subscription.ts +11 -7
- package/src/sync/processors/sync.ts +3 -4
- package/src/sync/utils.ts +24 -8
- package/src/util.ts +4 -4
package/lib-esm/util.js
CHANGED
|
@@ -84,7 +84,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
84
84
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
85
85
|
// SPDX-License-Identifier: Apache-2.0
|
|
86
86
|
import { monotonicFactory } from 'ulid';
|
|
87
|
-
import {
|
|
87
|
+
import { amplifyUuid, AmplifyUrl } from '@aws-amplify/core/internals/utils';
|
|
88
88
|
import { produce, applyPatches } from 'immer';
|
|
89
89
|
import { isPredicateGroup, isPredicateObj, SortDirection, isModelAttributeKey, isModelAttributePrimaryKey, isModelAttributeCompositeKey, LimitTimerRaceResolvedValues, } from './types';
|
|
90
90
|
import { ModelSortPredicateCreator } from './predicates';
|
|
@@ -226,7 +226,7 @@ export var traverseModel = function (srcModelName, instance, namespace, modelIns
|
|
|
226
226
|
var privateModeCheckResult;
|
|
227
227
|
export var isPrivateMode = function () {
|
|
228
228
|
return new Promise(function (resolve) {
|
|
229
|
-
var dbname =
|
|
229
|
+
var dbname = amplifyUuid();
|
|
230
230
|
var db;
|
|
231
231
|
var isPrivate = function () {
|
|
232
232
|
privateModeCheckResult = false;
|
|
@@ -279,7 +279,7 @@ export var isSafariCompatabilityMode = function () { return __awaiter(void 0, vo
|
|
|
279
279
|
switch (_c.label) {
|
|
280
280
|
case 0:
|
|
281
281
|
_c.trys.push([0, 6, , 7]);
|
|
282
|
-
dbName_1 =
|
|
282
|
+
dbName_1 = amplifyUuid();
|
|
283
283
|
storeName_1 = 'indexedDBFeatureProbeStore';
|
|
284
284
|
indexName_1 = 'idx';
|
|
285
285
|
if (indexedDB === null)
|
|
@@ -668,7 +668,7 @@ export var isAWSJSON = function (val) {
|
|
|
668
668
|
};
|
|
669
669
|
export var isAWSURL = function (val) {
|
|
670
670
|
try {
|
|
671
|
-
return !!new
|
|
671
|
+
return !!new AmplifyUrl(val);
|
|
672
672
|
}
|
|
673
673
|
catch (_c) {
|
|
674
674
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/datastore",
|
|
3
|
-
"version": "5.0.1-api-v6-models.
|
|
3
|
+
"version": "5.0.1-api-v6-models.572a7b5.0+572a7b5",
|
|
4
4
|
"description": "AppSyncLocal support for aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -47,26 +47,25 @@
|
|
|
47
47
|
"ssr"
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@aws-amplify/api": "6.0.1-api-v6-models.
|
|
51
|
-
"@aws-amplify/auth": "6.0.1-api-v6-models.
|
|
50
|
+
"@aws-amplify/api": "6.0.1-api-v6-models.572a7b5.0+572a7b5",
|
|
51
|
+
"@aws-amplify/auth": "6.0.1-api-v6-models.572a7b5.0+572a7b5",
|
|
52
52
|
"buffer": "4.9.2",
|
|
53
53
|
"idb": "5.0.6",
|
|
54
54
|
"immer": "9.0.6",
|
|
55
55
|
"rxjs": "^7.8.1",
|
|
56
|
-
"ulid": "^2.3.0"
|
|
57
|
-
"uuid": "^9.0.0"
|
|
56
|
+
"ulid": "^2.3.0"
|
|
58
57
|
},
|
|
59
58
|
"peerDependencies": {
|
|
60
|
-
"@aws-amplify/core": "6.0.1-api-v6-models.
|
|
59
|
+
"@aws-amplify/core": "6.0.1-api-v6-models.572a7b5.0+572a7b5"
|
|
61
60
|
},
|
|
62
61
|
"devDependencies": {
|
|
63
|
-
"@aws-amplify/core": "6.0.1-api-v6-models.
|
|
64
|
-
"@aws-amplify/react-native": "1.0.1-api-v6-models.
|
|
65
|
-
"@types/uuid": "^9.0.0",
|
|
62
|
+
"@aws-amplify/core": "6.0.1-api-v6-models.572a7b5.0+572a7b5",
|
|
63
|
+
"@aws-amplify/react-native": "1.0.1-api-v6-models.572a7b5.0+572a7b5",
|
|
66
64
|
"@types/uuid-validate": "^0.0.1",
|
|
67
65
|
"dexie": "3.2.2",
|
|
68
66
|
"dexie-export-import": "1.0.3",
|
|
69
67
|
"fake-indexeddb": "3.0.0",
|
|
68
|
+
"graphql": "15.8.0",
|
|
70
69
|
"typescript": "5.0.2"
|
|
71
70
|
},
|
|
72
71
|
"size-limit": [
|
|
@@ -136,5 +135,5 @@
|
|
|
136
135
|
"lib-esm"
|
|
137
136
|
]
|
|
138
137
|
},
|
|
139
|
-
"gitHead": "
|
|
138
|
+
"gitHead": "572a7b56d9e87ca779038254de3d68b5c607af07"
|
|
140
139
|
}
|
|
@@ -142,7 +142,11 @@ export const multiAuthStrategy: (
|
|
|
142
142
|
async ({ schema, modelName }) => {
|
|
143
143
|
let currentUser;
|
|
144
144
|
try {
|
|
145
|
-
|
|
145
|
+
const authSession = await fetchAuthSession();
|
|
146
|
+
if (authSession.tokens.accessToken) {
|
|
147
|
+
// the user is authenticated
|
|
148
|
+
currentUser = authSession;
|
|
149
|
+
}
|
|
146
150
|
} catch (e) {
|
|
147
151
|
// No current user
|
|
148
152
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { InternalAPI } from '@aws-amplify/api/internals';
|
|
4
|
-
import { Amplify, Hub, Cache } from '@aws-amplify/core';
|
|
4
|
+
import { Amplify, Hub, Cache, ConsoleLogger } from '@aws-amplify/core';
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
Draft,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
enablePatches,
|
|
12
12
|
Patch,
|
|
13
13
|
} from 'immer';
|
|
14
|
-
import {
|
|
14
|
+
import { amplifyUuid } from '@aws-amplify/core/internals/utils';
|
|
15
15
|
import { Observable, SubscriptionLike, filter } from 'rxjs';
|
|
16
16
|
import { defaultAuthStrategy, multiAuthStrategy } from '../authModeStrategies';
|
|
17
17
|
import {
|
|
@@ -103,15 +103,12 @@ import {
|
|
|
103
103
|
} from '../predicates/next';
|
|
104
104
|
import { getIdentifierValue } from '../sync/utils';
|
|
105
105
|
import DataStoreConnectivity from '../sync/datastoreConnectivity';
|
|
106
|
-
import {
|
|
107
|
-
BackgroundProcessManager,
|
|
108
|
-
Logger,
|
|
109
|
-
} from '@aws-amplify/core/internals/utils';
|
|
106
|
+
import { BackgroundProcessManager } from '@aws-amplify/core/internals/utils';
|
|
110
107
|
|
|
111
108
|
setAutoFreeze(true);
|
|
112
109
|
enablePatches();
|
|
113
110
|
|
|
114
|
-
const logger = new
|
|
111
|
+
const logger = new ConsoleLogger('DataStore');
|
|
115
112
|
|
|
116
113
|
const ulid = monotonicUlidFactory(Date.now());
|
|
117
114
|
|
|
@@ -838,13 +835,14 @@ const createModelClass = <T extends PersistentModel>(
|
|
|
838
835
|
const id = isInternalModel
|
|
839
836
|
? _id
|
|
840
837
|
: modelDefinition.syncable
|
|
841
|
-
?
|
|
838
|
+
? amplifyUuid()
|
|
842
839
|
: ulid();
|
|
843
840
|
|
|
844
841
|
(<ModelWithIDIdentifier>(<unknown>draft)).id = id;
|
|
845
842
|
} else if (isIdOptionallyManaged(modelDefinition)) {
|
|
846
843
|
// only auto-populate if the id was not provided
|
|
847
|
-
(<ModelWithIDIdentifier>(<unknown>draft)).id =
|
|
844
|
+
(<ModelWithIDIdentifier>(<unknown>draft)).id =
|
|
845
|
+
draft.id || amplifyUuid();
|
|
848
846
|
}
|
|
849
847
|
|
|
850
848
|
if (!isInternallyInitialized) {
|
|
@@ -24,9 +24,9 @@ import {
|
|
|
24
24
|
isSafariCompatabilityMode,
|
|
25
25
|
} from '../../util';
|
|
26
26
|
import { StorageAdapterBase } from './StorageAdapterBase';
|
|
27
|
-
import {
|
|
27
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
28
28
|
|
|
29
|
-
const logger = new
|
|
29
|
+
const logger = new ConsoleLogger('DataStore');
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* The point after which queries composed of multiple simple OR conditions
|
|
@@ -30,9 +30,9 @@ import {
|
|
|
30
30
|
import type { IDBPDatabase, IDBPObjectStore } from 'idb';
|
|
31
31
|
import type AsyncStorageDatabase from './AsyncStorageDatabase';
|
|
32
32
|
import { ModelRelationship } from '../relationship';
|
|
33
|
-
import {
|
|
33
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
34
34
|
|
|
35
|
-
const logger = new
|
|
35
|
+
const logger = new ConsoleLogger('DataStore');
|
|
36
36
|
const DB_NAME = 'amplify-datastore';
|
|
37
37
|
|
|
38
38
|
export abstract class StorageAdapterBase implements Adapter {
|
package/src/storage/storage.ts
CHANGED
|
@@ -30,7 +30,8 @@ import {
|
|
|
30
30
|
import { getIdentifierValue } from '../sync/utils';
|
|
31
31
|
import { Adapter } from './adapter';
|
|
32
32
|
import getDefaultAdapter from './adapter/getDefaultAdapter';
|
|
33
|
-
import {
|
|
33
|
+
import { Mutex } from '@aws-amplify/core/internals/utils';
|
|
34
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
34
35
|
|
|
35
36
|
export type StorageSubscriptionMessage<T extends PersistentModel> =
|
|
36
37
|
InternalSubscriptionMessage<T> & {
|
|
@@ -40,7 +41,7 @@ export type StorageSubscriptionMessage<T extends PersistentModel> =
|
|
|
40
41
|
export type StorageFacade = Omit<Adapter, 'setUp'>;
|
|
41
42
|
export type Storage = InstanceType<typeof StorageClass>;
|
|
42
43
|
|
|
43
|
-
const logger = new
|
|
44
|
+
const logger = new ConsoleLogger('DataStore');
|
|
44
45
|
class StorageClass implements StorageFacade {
|
|
45
46
|
private initialized: Promise<void> | undefined;
|
|
46
47
|
private readonly pushStream: Subject<
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { Observable, Observer, SubscriptionLike } from 'rxjs';
|
|
4
4
|
import { ReachabilityMonitor } from './datastoreReachability';
|
|
5
|
-
import {
|
|
5
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
6
6
|
|
|
7
|
-
const logger = new
|
|
7
|
+
const logger = new ConsoleLogger('DataStore');
|
|
8
8
|
|
|
9
9
|
const RECONNECTING_IN = 5000; // 5s this may be configurable in the future
|
|
10
10
|
|
package/src/sync/index.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
BackgroundProcessManager,
|
|
6
|
-
} from '@aws-amplify/core/internals/utils';
|
|
7
|
-
import { Hub } from '@aws-amplify/core';
|
|
3
|
+
import { BackgroundProcessManager } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
import { Hub, ConsoleLogger } from '@aws-amplify/core';
|
|
8
5
|
|
|
9
|
-
import { filter, Observable,
|
|
6
|
+
import { filter, Observable, of, SubscriptionLike } from 'rxjs';
|
|
10
7
|
import { ModelInstanceCreator } from '../datastore/datastore';
|
|
11
8
|
import { ModelPredicateCreator } from '../predicates';
|
|
12
9
|
import { ExclusiveStorage as Storage } from '../storage/storage';
|
|
@@ -54,7 +51,7 @@ import {
|
|
|
54
51
|
CONNECTION_STATE_CHANGE as PUBSUB_CONNECTION_STATE_CHANGE,
|
|
55
52
|
} from '@aws-amplify/api-graphql';
|
|
56
53
|
|
|
57
|
-
const logger = new
|
|
54
|
+
const logger = new ConsoleLogger('DataStore');
|
|
58
55
|
|
|
59
56
|
const ownSymbol = Symbol('sync');
|
|
60
57
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { ErrorType } from '../../types';
|
|
4
|
+
import { resolveServiceErrorStatusCode } from '../utils';
|
|
4
5
|
|
|
5
6
|
export type ErrorMap = Partial<{
|
|
6
7
|
[key in ErrorType]: (error: Error) => boolean;
|
|
@@ -9,8 +10,7 @@ export type ErrorMap = Partial<{
|
|
|
9
10
|
const connectionTimeout = error =>
|
|
10
11
|
/^Connection failed: Connection Timeout/.test(error.message);
|
|
11
12
|
|
|
12
|
-
const serverError = error =>
|
|
13
|
-
/^Error: Request failed with status code 5\d\d/.test(error.message);
|
|
13
|
+
const serverError = error => resolveServiceErrorStatusCode(error) >= 500;
|
|
14
14
|
|
|
15
15
|
export const mutationErrorMap: ErrorMap = {
|
|
16
16
|
BadModel: () => false,
|
|
@@ -25,7 +25,7 @@ export const mutationErrorMap: ErrorMap = {
|
|
|
25
25
|
Transient: error => connectionTimeout(error) || serverError(error),
|
|
26
26
|
Unauthorized: error =>
|
|
27
27
|
error.message === 'Unauthorized' ||
|
|
28
|
-
|
|
28
|
+
resolveServiceErrorStatusCode(error) === 401,
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
export const subscriptionErrorMap: ErrorMap = {
|
|
@@ -58,10 +58,10 @@ export const syncErrorMap: ErrorMap = {
|
|
|
58
58
|
*/
|
|
59
59
|
function unwrapObservableError(observableError: any) {
|
|
60
60
|
const {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} = observableError;
|
|
61
|
+
errors: [error],
|
|
62
|
+
} = ({
|
|
63
|
+
errors: [],
|
|
64
|
+
} = observableError);
|
|
65
65
|
|
|
66
66
|
return error;
|
|
67
67
|
}
|
|
@@ -4,7 +4,6 @@ import { GraphQLResult } from '@aws-amplify/api';
|
|
|
4
4
|
import { InternalAPI } from '@aws-amplify/api/internals';
|
|
5
5
|
import {
|
|
6
6
|
Category,
|
|
7
|
-
Logger,
|
|
8
7
|
CustomUserAgentDetails,
|
|
9
8
|
DataStoreAction,
|
|
10
9
|
jitteredBackoff,
|
|
@@ -14,6 +13,7 @@ import {
|
|
|
14
13
|
GraphQLAuthMode,
|
|
15
14
|
AmplifyError,
|
|
16
15
|
} from '@aws-amplify/core/internals/utils';
|
|
16
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
17
17
|
|
|
18
18
|
import { Observable, Observer } from 'rxjs';
|
|
19
19
|
import { MutationEvent } from '../';
|
|
@@ -50,7 +50,7 @@ import { getMutationErrorType } from './errorMaps';
|
|
|
50
50
|
|
|
51
51
|
const MAX_ATTEMPTS = 10;
|
|
52
52
|
|
|
53
|
-
const logger = new
|
|
53
|
+
const logger = new ConsoleLogger('DataStore');
|
|
54
54
|
|
|
55
55
|
type MutationProcessorEvent = {
|
|
56
56
|
operation: TransformerMutationType;
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { GraphQLResult } from '@aws-amplify/api';
|
|
4
4
|
import { InternalAPI } from '@aws-amplify/api/internals';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Hub,
|
|
7
|
+
HubCapsule,
|
|
8
|
+
fetchAuthSession,
|
|
9
|
+
ConsoleLogger,
|
|
10
|
+
} from '@aws-amplify/core';
|
|
6
11
|
import {
|
|
7
12
|
Category,
|
|
8
|
-
Logger,
|
|
9
13
|
CustomUserAgentDetails,
|
|
10
14
|
DataStoreAction,
|
|
11
15
|
BackgroundProcessManager,
|
|
@@ -47,7 +51,7 @@ import { validatePredicate } from '../../util';
|
|
|
47
51
|
import { getSubscriptionErrorType } from './errorMaps';
|
|
48
52
|
import { CONTROL_MSG as PUBSUB_CONTROL_MSG } from '@aws-amplify/api-graphql';
|
|
49
53
|
|
|
50
|
-
const logger = new
|
|
54
|
+
const logger = new ConsoleLogger('DataStore');
|
|
51
55
|
|
|
52
56
|
export enum CONTROL_MSG {
|
|
53
57
|
CONNECTED = 'CONNECTED',
|
|
@@ -455,10 +459,10 @@ class SubscriptionProcessor {
|
|
|
455
459
|
},
|
|
456
460
|
error: async subscriptionError => {
|
|
457
461
|
const {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
} = subscriptionError;
|
|
462
|
+
errors: [{ message = '' } = {}],
|
|
463
|
+
} = ({
|
|
464
|
+
errors: [],
|
|
465
|
+
} = subscriptionError);
|
|
462
466
|
|
|
463
467
|
const isRTFError =
|
|
464
468
|
// only attempt catch if a filter variable was added to the subscription query
|
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
import {
|
|
27
27
|
jitteredExponentialRetry,
|
|
28
28
|
Category,
|
|
29
|
-
ConsoleLogger as Logger,
|
|
30
29
|
CustomUserAgentDetails,
|
|
31
30
|
DataStoreAction,
|
|
32
31
|
NonRetryableError,
|
|
@@ -35,7 +34,7 @@ import {
|
|
|
35
34
|
AmplifyError,
|
|
36
35
|
} from '@aws-amplify/core/internals/utils';
|
|
37
36
|
|
|
38
|
-
import { Amplify, Hub } from '@aws-amplify/core';
|
|
37
|
+
import { Amplify, Hub, ConsoleLogger } from '@aws-amplify/core';
|
|
39
38
|
|
|
40
39
|
import { ModelPredicateCreator } from '../../predicates';
|
|
41
40
|
import { getSyncErrorType } from './errorMaps';
|
|
@@ -45,7 +44,7 @@ const opResultDefaults = {
|
|
|
45
44
|
startedAt: null,
|
|
46
45
|
};
|
|
47
46
|
|
|
48
|
-
const logger = new
|
|
47
|
+
const logger = new ConsoleLogger('DataStore');
|
|
49
48
|
|
|
50
49
|
class SyncProcessor {
|
|
51
50
|
private readonly typeQuery = new WeakMap<SchemaModel, [string, string]>();
|
|
@@ -342,7 +341,7 @@ class SyncProcessor {
|
|
|
342
341
|
throw new NonRetryableError(error);
|
|
343
342
|
}
|
|
344
343
|
|
|
345
|
-
if (result.data?.[opName]
|
|
344
|
+
if (result.data?.[opName]?.items?.length) {
|
|
346
345
|
return result;
|
|
347
346
|
}
|
|
348
347
|
|
package/src/sync/utils.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { GraphQLAuthError } from '@aws-amplify/api';
|
|
4
|
-
import {
|
|
4
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
5
|
+
import type { GraphQLError } from 'graphql';
|
|
6
|
+
import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
5
7
|
import { ModelInstanceCreator } from '../datastore/datastore';
|
|
6
8
|
import {
|
|
7
9
|
AuthorizationRule,
|
|
@@ -39,7 +41,7 @@ import {
|
|
|
39
41
|
} from '../util';
|
|
40
42
|
import { MutationEvent } from './';
|
|
41
43
|
|
|
42
|
-
const logger = new
|
|
44
|
+
const logger = new ConsoleLogger('DataStore');
|
|
43
45
|
|
|
44
46
|
enum GraphQLOperationType {
|
|
45
47
|
LIST = 'query',
|
|
@@ -863,25 +865,39 @@ export async function getModelAuthModes({
|
|
|
863
865
|
}
|
|
864
866
|
|
|
865
867
|
export function getForbiddenError(error) {
|
|
866
|
-
const
|
|
867
|
-
'Request failed with status code 401',
|
|
868
|
-
'Request failed with status code 403',
|
|
869
|
-
];
|
|
868
|
+
const forbiddenErrorCodes = [401, 403];
|
|
870
869
|
let forbiddenError;
|
|
871
870
|
if (error && error.errors) {
|
|
872
871
|
forbiddenError = (error.errors as [any]).find(err =>
|
|
873
|
-
|
|
872
|
+
forbiddenErrorCodes.includes(resolveServiceErrorStatusCode(err))
|
|
874
873
|
);
|
|
875
874
|
} else if (error && error.message) {
|
|
876
875
|
forbiddenError = error;
|
|
877
876
|
}
|
|
878
877
|
|
|
879
878
|
if (forbiddenError) {
|
|
880
|
-
return
|
|
879
|
+
return (
|
|
880
|
+
forbiddenError.message ??
|
|
881
|
+
`Request failed with status code ${resolveServiceErrorStatusCode(
|
|
882
|
+
forbiddenError
|
|
883
|
+
)}`
|
|
884
|
+
);
|
|
881
885
|
}
|
|
882
886
|
return null;
|
|
883
887
|
}
|
|
884
888
|
|
|
889
|
+
export function resolveServiceErrorStatusCode(error: unknown): number | null {
|
|
890
|
+
if (error?.['$metadata']?.['httpStatusCode']) {
|
|
891
|
+
return Number(error?.['$metadata']?.['httpStatusCode']);
|
|
892
|
+
} else if ((error as GraphQLError)?.originalError) {
|
|
893
|
+
return resolveServiceErrorStatusCode(
|
|
894
|
+
(error as GraphQLError)?.originalError
|
|
895
|
+
);
|
|
896
|
+
} else {
|
|
897
|
+
return null;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
|
|
885
901
|
export function getClientSideAuthError(error) {
|
|
886
902
|
const clientSideAuthErrors = Object.values(GraphQLAuthError);
|
|
887
903
|
const clientSideError =
|
package/src/util.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { monotonicFactory, ULID } from 'ulid';
|
|
4
|
-
import {
|
|
4
|
+
import { amplifyUuid, AmplifyUrl } from '@aws-amplify/core/internals/utils';
|
|
5
5
|
import { produce, applyPatches, Patch } from 'immer';
|
|
6
6
|
import { ModelInstanceCreator } from './datastore/datastore';
|
|
7
7
|
import {
|
|
@@ -246,7 +246,7 @@ let privateModeCheckResult;
|
|
|
246
246
|
|
|
247
247
|
export const isPrivateMode = () => {
|
|
248
248
|
return new Promise(resolve => {
|
|
249
|
-
const dbname =
|
|
249
|
+
const dbname = amplifyUuid();
|
|
250
250
|
let db;
|
|
251
251
|
|
|
252
252
|
const isPrivate = () => {
|
|
@@ -297,7 +297,7 @@ let safariCompatabilityModeResult;
|
|
|
297
297
|
*/
|
|
298
298
|
export const isSafariCompatabilityMode: () => Promise<boolean> = async () => {
|
|
299
299
|
try {
|
|
300
|
-
const dbName =
|
|
300
|
+
const dbName = amplifyUuid();
|
|
301
301
|
const storeName = 'indexedDBFeatureProbeStore';
|
|
302
302
|
const indexName = 'idx';
|
|
303
303
|
|
|
@@ -642,7 +642,7 @@ export const isAWSJSON = (val: string): boolean => {
|
|
|
642
642
|
|
|
643
643
|
export const isAWSURL = (val: string): boolean => {
|
|
644
644
|
try {
|
|
645
|
-
return !!new
|
|
645
|
+
return !!new AmplifyUrl(val);
|
|
646
646
|
} catch {
|
|
647
647
|
return false;
|
|
648
648
|
}
|