Skip to content

Commit 5dbfbf3

Browse files
ashwinkumar6Ashwin Kumar
andauthored
fix(core): make AmplifyOutputs category types as unknown (#14153)
* fix(core): make AmplifyOutputs category types as unknown * chore: remove previously added path parsing logic for AmplifyOutputs * chore: remove previously added Partial on AmplifyOutputs * add adapter-core internals subpath * change AmplifyOutputs deprecation message wording * add type casting for categories with mandatory properties * fix linter issues * add back parsing logic to remove undefined paths --------- Co-authored-by: Ashwin Kumar <[email protected]>
1 parent 063a34e commit 5dbfbf3

File tree

10 files changed

+50
-22
lines changed

10 files changed

+50
-22
lines changed

packages/adapter-nextjs/src/types/NextServer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import { GetServerSidePropsContext as NextGetServerSidePropsContext } from 'next';
55
import { NextRequest, NextResponse } from 'next/server.js';
66
import { cookies } from 'next/headers.js';
7-
import { AmplifyOutputs, LegacyConfig } from 'aws-amplify/adapter-core';
87
import {
8+
AmplifyOutputsUnknown,
99
AmplifyServer,
1010
CookieStorage,
11+
LegacyConfig,
1112
} from 'aws-amplify/adapter-core/internals';
1213
import { ResourcesConfig } from 'aws-amplify';
1314

@@ -86,7 +87,7 @@ export declare namespace NextServer {
8687
}
8788

8889
export interface CreateServerRunnerInput {
89-
config: ResourcesConfig | LegacyConfig | AmplifyOutputs;
90+
config: ResourcesConfig | LegacyConfig | AmplifyOutputsUnknown;
9091
runtimeOptions?: CreateServerRunnerRuntimeOptions;
9192
}
9293

packages/aws-amplify/src/adapter-core/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export {
88
createUserPoolsTokenProvider,
99
} from './authProvidersFactories/cognito';
1010
export {
11+
/** @deprecated This type is deprecated and will be removed in future versions. */
1112
LegacyConfig,
13+
/** @deprecated This type is deprecated and will be removed in future versions. */
1214
AmplifyOutputs,
1315
} from '@aws-amplify/core/internals/utils';
1416
export {

packages/aws-amplify/src/adapter-core/internals.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ export {
1414
assertTokenProviderConfig,
1515
urlSafeEncode,
1616
decodeJWT,
17+
LegacyConfig,
18+
AmplifyOutputsUnknown,
1719
} from '@aws-amplify/core/internals/utils';

packages/aws-amplify/src/initSingleton.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
defaultStorage,
99
} from '@aws-amplify/core';
1010
import {
11-
AmplifyOutputs,
11+
AmplifyOutputsUnknown,
1212
LegacyConfig,
1313
parseAmplifyConfig,
1414
} from '@aws-amplify/core/internals/utils';
@@ -32,7 +32,7 @@ export const DefaultAmplify = {
3232
* Amplify.configure(config);
3333
*/
3434
configure(
35-
resourceConfig: ResourcesConfig | LegacyConfig | AmplifyOutputs,
35+
resourceConfig: ResourcesConfig | LegacyConfig | AmplifyOutputsUnknown,
3636
libraryOptions?: LibraryOptions,
3737
): void {
3838
const resolvedResourceConfig = parseAmplifyConfig(resourceConfig);

packages/core/src/libraryUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ export {
2424
export { parseAWSExports } from './parseAWSExports';
2525
export { isAmplifyOutputs, parseAmplifyOutputs } from './parseAmplifyOutputs';
2626
export { LegacyConfig } from './singleton/types';
27-
export { AmplifyOutputs } from './singleton/AmplifyOutputs/types';
27+
export {
28+
AmplifyOutputs,
29+
AmplifyOutputsUnknown,
30+
} from './singleton/AmplifyOutputs/types';
2831
export { ADD_OAUTH_LISTENER } from './singleton/constants';
2932
export { amplifyUuid } from './utils/amplifyUuid';
3033
export { AmplifyUrl, AmplifyUrlSearchParams } from './utils/amplifyUrl';

packages/core/src/parseAmplifyOutputs.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
} from './singleton/Auth/types';
2020
import { NotificationsConfig } from './singleton/Notifications/types';
2121
import {
22-
AmplifyOutputs,
2322
AmplifyOutputsAnalyticsProperties,
2423
AmplifyOutputsAuthProperties,
2524
AmplifyOutputsCustomProperties,
@@ -28,6 +27,7 @@ import {
2827
AmplifyOutputsNotificationsProperties,
2928
AmplifyOutputsStorageBucketProperties,
3029
AmplifyOutputsStorageProperties,
30+
AmplifyOutputsUnknown,
3131
} from './singleton/AmplifyOutputs/types';
3232
import {
3333
AnalyticsConfig,
@@ -40,10 +40,10 @@ import {
4040
} from './singleton/types';
4141

4242
export function isAmplifyOutputs(
43-
config: ResourcesConfig | LegacyConfig | AmplifyOutputs,
44-
): config is AmplifyOutputs {
43+
config: ResourcesConfig | LegacyConfig | AmplifyOutputsUnknown,
44+
): config is AmplifyOutputsUnknown {
4545
// version format initially will be '1' but is expected to be something like x.y where x is major and y minor version
46-
const { version } = config as AmplifyOutputs;
46+
const { version } = config as AmplifyOutputsUnknown;
4747

4848
if (!version) {
4949
return false;
@@ -291,28 +291,36 @@ function parseNotifications(
291291
}
292292

293293
export function parseAmplifyOutputs(
294-
amplifyOutputs: AmplifyOutputs,
294+
amplifyOutputs: AmplifyOutputsUnknown,
295295
): ResourcesConfig {
296296
const resourcesConfig: ResourcesConfig = {};
297297

298298
if (amplifyOutputs.storage) {
299-
resourcesConfig.Storage = parseStorage(amplifyOutputs.storage);
299+
resourcesConfig.Storage = parseStorage(
300+
amplifyOutputs.storage as AmplifyOutputsStorageProperties,
301+
);
300302
}
301303

302304
if (amplifyOutputs.auth) {
303-
resourcesConfig.Auth = parseAuth(amplifyOutputs.auth);
305+
resourcesConfig.Auth = parseAuth(
306+
amplifyOutputs.auth as AmplifyOutputsAuthProperties,
307+
);
304308
}
305309

306310
if (amplifyOutputs.analytics) {
307311
resourcesConfig.Analytics = parseAnalytics(amplifyOutputs.analytics);
308312
}
309313

310314
if (amplifyOutputs.geo) {
311-
resourcesConfig.Geo = parseGeo(amplifyOutputs.geo);
315+
resourcesConfig.Geo = parseGeo(
316+
amplifyOutputs.geo as AmplifyOutputsGeoProperties,
317+
);
312318
}
313319

314320
if (amplifyOutputs.data) {
315-
resourcesConfig.API = parseData(amplifyOutputs.data);
321+
resourcesConfig.API = parseData(
322+
amplifyOutputs.data as AmplifyOutputsDataProperties,
323+
);
316324
}
317325

318326
if (amplifyOutputs.custom) {
@@ -325,7 +333,7 @@ export function parseAmplifyOutputs(
325333

326334
if (amplifyOutputs.notifications) {
327335
resourcesConfig.Notifications = parseNotifications(
328-
amplifyOutputs.notifications,
336+
amplifyOutputs.notifications as AmplifyOutputsNotificationsProperties,
329337
);
330338
}
331339

packages/core/src/singleton/Amplify.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { deepFreeze } from '../utils';
55
import { parseAmplifyConfig } from '../libraryUtils';
66

77
import {
8-
AmplifyOutputs,
8+
AmplifyOutputsUnknown,
99
AuthConfig,
1010
LegacyConfig,
1111
LibraryOptions,
@@ -49,7 +49,7 @@ export class AmplifyClass {
4949
* @param libraryOptions - Additional options for customizing the behavior of the library.
5050
*/
5151
configure(
52-
resourcesConfig: ResourcesConfig | LegacyConfig | AmplifyOutputs,
52+
resourcesConfig: ResourcesConfig | LegacyConfig | AmplifyOutputsUnknown,
5353
libraryOptions?: LibraryOptions,
5454
): void {
5555
const resolvedResourceConfig = parseAmplifyConfig(resourcesConfig);

packages/core/src/singleton/AmplifyOutputs/types.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface AmplifyOutputsAuthProperties {
4242
unauthenticated_identities_enabled?: boolean;
4343
mfa_configuration?: string;
4444
mfa_methods?: string[];
45-
groups?: Partial<Record<UserGroupName, UserGroupPrecedence>>[];
45+
groups?: Record<UserGroupName, UserGroupPrecedence>[];
4646
}
4747

4848
export interface AmplifyOutputsStorageBucketProperties {
@@ -53,7 +53,7 @@ export interface AmplifyOutputsStorageBucketProperties {
5353
/** Region for the bucket */
5454
aws_region: string;
5555
/** Paths to object with access permissions */
56-
paths?: Partial<Record<string, Record<string, string[] | undefined>>>;
56+
paths?: Record<string, Record<string, string[] | undefined>>;
5757
}
5858
export interface AmplifyOutputsStorageProperties {
5959
/** Default region for Storage */
@@ -115,6 +115,7 @@ export interface AmplifyOutputsNotificationsProperties {
115115
channels: string[];
116116
}
117117

118+
/** @deprecated This type is deprecated and will be removed in future versions. */
118119
export interface AmplifyOutputs {
119120
version?: string;
120121
storage?: AmplifyOutputsStorageProperties;
@@ -125,3 +126,14 @@ export interface AmplifyOutputs {
125126
custom?: AmplifyOutputsCustomProperties;
126127
notifications?: AmplifyOutputsNotificationsProperties;
127128
}
129+
130+
export interface AmplifyOutputsUnknown {
131+
version?: string;
132+
storage?: unknown;
133+
auth?: unknown;
134+
analytics?: unknown;
135+
geo?: unknown;
136+
data?: unknown;
137+
custom?: unknown;
138+
notifications?: unknown;
139+
}

packages/core/src/singleton/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
import { NotificationsConfig } from './Notifications/types';
2828
import { InteractionsConfig } from './Interactions/types';
2929

30-
export { AmplifyOutputs } from './AmplifyOutputs/types';
30+
export { AmplifyOutputsUnknown } from './AmplifyOutputs/types';
3131

3232
/**
3333
* Compatibility type representing the Amplify Gen 1 configuration file schema. This type should not be used directly.

packages/core/src/utils/parseAmplifyConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { ResourcesConfig } from '../index';
5-
import { AmplifyOutputs } from '../singleton/AmplifyOutputs/types';
5+
import { AmplifyOutputsUnknown } from '../singleton/AmplifyOutputs/types';
66
import { LegacyConfig } from '../singleton/types';
77
import { parseAWSExports } from '../parseAWSExports';
88
import { isAmplifyOutputs, parseAmplifyOutputs } from '../parseAmplifyOutputs';
@@ -14,7 +14,7 @@ import { isAmplifyOutputs, parseAmplifyOutputs } from '../parseAmplifyOutputs';
1414
* @return A ResourcesConfig for the provided configuration object.
1515
*/
1616
export const parseAmplifyConfig = (
17-
amplifyConfig: ResourcesConfig | LegacyConfig | AmplifyOutputs,
17+
amplifyConfig: ResourcesConfig | LegacyConfig | AmplifyOutputsUnknown,
1818
): ResourcesConfig => {
1919
if (Object.keys(amplifyConfig).some(key => key.startsWith('aws_'))) {
2020
return parseAWSExports(amplifyConfig);

0 commit comments

Comments
 (0)