-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathresolveConfig.ts
More file actions
47 lines (41 loc) · 1.11 KB
/
resolveConfig.ts
File metadata and controls
47 lines (41 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { Amplify } from '@aws-amplify/core';
import {
AnalyticsValidationErrorCode,
assertValidationError,
} from '../../../errors';
import {
DEFAULT_PERSONALIZE_CONFIG,
PERSONALIZE_FLUSH_SIZE_MAX,
} from './constants';
export const resolveConfig = () => {
Amplify.assertConfigured();
const config = Amplify.getConfig().Analytics?.Personalize;
const {
region,
trackingId,
flushSize = DEFAULT_PERSONALIZE_CONFIG.flushSize,
flushInterval = DEFAULT_PERSONALIZE_CONFIG.flushInterval,
} = {
...DEFAULT_PERSONALIZE_CONFIG,
...config,
};
assertValidationError(!!region, AnalyticsValidationErrorCode.NoRegion);
assertValidationError(
!!trackingId,
AnalyticsValidationErrorCode.NoTrackingId,
);
assertValidationError(
flushSize <= PERSONALIZE_FLUSH_SIZE_MAX,
AnalyticsValidationErrorCode.InvalidFlushSize,
`FlushSize for Personalize should be less or equal than ${PERSONALIZE_FLUSH_SIZE_MAX}`,
);
return {
region,
trackingId,
bufferSize: flushSize + 1,
flushSize,
flushInterval,
};
};