Skip to content

Commit

Permalink
fix(amplifyConfig): Amplify.configure.category should not allow empty…
Browse files Browse the repository at this point in the history
… object (#12540)

* chore(interactions analytics): move common type to parent

* chore(storage): add AtLeastOne type

* fix(api): Amplify.Configure.API should have atleast one key

* fix(geo): Amplify.Configure.Geo should have atleast one key

* fix(predictions): Amplify.Configure.Predictions should have atleast one key

* fix(notifications): Amplify.Configure.Notifications should have atleast one key

---------

Co-authored-by: Ashwin Kumar <[email protected]>
  • Loading branch information
ashwinkumar6 and Ashwin Kumar authored Nov 10, 2023
1 parent b778a9e commit 17ffbdd
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 32 deletions.
21 changes: 12 additions & 9 deletions packages/core/src/parseAWSExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,25 @@ export const parseAWSExports = (
// Notifications
const { InAppMessaging, Push } = Notifications ?? {};
if (InAppMessaging?.AWSPinpoint || Push?.AWSPinpoint) {
amplifyConfig.Notifications = {};
if (InAppMessaging?.AWSPinpoint) {
const { appId, region } = InAppMessaging.AWSPinpoint;
amplifyConfig.Notifications.InAppMessaging = {
Pinpoint: {
appId,
region,
amplifyConfig.Notifications = {
InAppMessaging: {
Pinpoint: {
appId,
region,
},
},
};
}
if (Push?.AWSPinpoint) {
const { appId, region } = Push.AWSPinpoint;
amplifyConfig.Notifications.PushNotification = {
Pinpoint: {
appId,
region,
amplifyConfig.Notifications = {
PushNotification: {
Pinpoint: {
appId,
region,
},
},
};
}
Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/singleton/API/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { Headers } from '../../clients';
import { AtLeastOne } from '../types';

export type LibraryAPIOptions = {
GraphQL?: {
Expand Down Expand Up @@ -66,11 +67,16 @@ type APIRestConfig = {
service?: string;
};

export type APIConfig = {
REST?: Record<string, APIRestConfig>;
GraphQL?: APIGraphQLConfig;
export type RESTProviderConfig = {
REST: Record<string, APIRestConfig>;
};

export type GraphQLProviderConfig = {
GraphQL: APIGraphQLConfig;
};

export type APIConfig = AtLeastOne<RESTProviderConfig & GraphQLProviderConfig>;

export type GraphQLAuthMode =
| 'apiKey'
| 'oidc'
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/singleton/Analytics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { PinpointProviderConfig } from '../../providers/pinpoint/types';
import { KinesisProviderConfig } from '../../providers/kinesis/types';
import { KinesisFirehoseProviderConfig } from '../../providers/kinesis-firehose/types';
import { PersonalizeProviderConfig } from '../../providers/personalize/types';

type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> &
U[keyof U];
import { AtLeastOne } from '../types';

export type AnalyticsConfig = AtLeastOne<
PinpointProviderConfig &
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/singleton/Geo/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

export interface GeoConfig {
LocationService?: {
import { AtLeastOne } from '../types';

export type LocationServiceConfig = {
LocationService: {
region: string;
maps?: {
items: {};
Expand All @@ -17,4 +19,6 @@ export interface GeoConfig {
default: string;
};
};
}
};

export type GeoConfig = AtLeastOne<LocationServiceConfig>;
5 changes: 2 additions & 3 deletions packages/core/src/singleton/Interactions/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { AtLeastOne } from '../types';

interface LexV1BotConfig {
alias: string;
region: string;
Expand All @@ -21,9 +23,6 @@ type InteractionsLexV2Config = {
LexV2: Record<string, LexV2BotConfig>;
};

type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> &
U[keyof U];

export type InteractionsConfig = AtLeastOne<
InteractionsLexV1Config & InteractionsLexV2Config
>;
14 changes: 11 additions & 3 deletions packages/core/src/singleton/Notifications/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@

import { InAppMessagingConfig } from './InAppMessaging/types';
import { PushNotificationConfig } from './PushNotification/types';
import { AtLeastOne } from '../types';

export type NotificationsConfig = {
InAppMessaging?: InAppMessagingConfig;
PushNotification?: PushNotificationConfig;
export type InAppMessagingProviderConfig = {
InAppMessaging: InAppMessagingConfig;
};

export type PushNotificationProviderConfig = {
PushNotification: PushNotificationConfig;
};

export type NotificationsConfig = AtLeastOne<
InAppMessagingProviderConfig & PushNotificationProviderConfig
>;
20 changes: 16 additions & 4 deletions packages/core/src/singleton/Predictions/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { AtLeastOne } from '../types';

// Defaults for ConvertConfig
type SpeechGeneratorDefaults = {
voiceId?: string;
Expand Down Expand Up @@ -54,8 +56,18 @@ export type PredictionsProviderConfig<T> = {
defaults?: T;
};

export type PredictionsConfig = {
convert?: ConvertConfig;
identify?: IdentifyConfig;
interpret?: InterpretConfig;
export type PredictionsConvertConfig = {
convert: ConvertConfig;
};
export type PredictionsIdentifyConfig = {
identify: IdentifyConfig;
};
export type PredictionsInterpretConfig = {
interpret: InterpretConfig;
};

export type PredictionsConfig = AtLeastOne<
PredictionsConvertConfig &
PredictionsIdentifyConfig &
PredictionsInterpretConfig
>;
8 changes: 6 additions & 2 deletions packages/core/src/singleton/Storage/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { AtLeastOne } from '../types';

export type StorageAccessLevel = 'guest' | 'protected' | 'private';

export interface StorageConfig {
export type S3ProviderConfig = {
S3: {
bucket?: string;
region?: string;
Expand All @@ -14,7 +16,9 @@ export interface StorageConfig {
*/
dangerouslyConnectToHttpEndpointForTesting?: string;
};
}
};

export type StorageConfig = AtLeastOne<S3ProviderConfig>;

type StoragePrefixResolver = (params: {
accessLevel: StorageAccessLevel;
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/singleton/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export type LegacyConfig = {
aws_project_region?: string;
};

export type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> &
U[keyof U];

export type ResourcesConfig = {
API?: APIConfig;
Analytics?: AnalyticsConfig;
Expand Down
4 changes: 2 additions & 2 deletions packages/geo/src/Geo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export class GeoClass {
/**
* @private
*/
private _config: GeoConfig;
private _config?: GeoConfig;
private _pluggables: GeoProvider[];

constructor() {
this._config = {};
this._config = undefined;
this._pluggables = [];

const amplifyConfig = Amplify.getConfig() ?? {};
Expand Down

0 comments on commit 17ffbdd

Please sign in to comment.