Skip to content

Commit 85ced84

Browse files
author
Kamil Sobol
authored
Client config extension (#978)
* ability to add client config values in backend definition * this works * refactor types * this is better * api * revert that * updates * fix api * merge objects * merging v2 * lint * some test * introduce error type * pretty * pretty * fix bug * tests * tests * tests * tests * pr feedback * rename error type * add unit test
1 parent 84818e3 commit 85ced84

34 files changed

+839
-25
lines changed

.changeset/mean-spies-listen.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@aws-amplify/backend-output-schemas': minor
3+
'@aws-amplify/backend-output-storage': minor
4+
'@aws-amplify/client-config': minor
5+
'@aws-amplify/plugin-types': minor
6+
'@aws-amplify/backend': minor
7+
'@aws-amplify/backend-storage': patch
8+
'@aws-amplify/auth-construct-alpha': patch
9+
---
10+
11+
Add ability to add custom outputs

package-lock.json

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend-output-schemas/API.md

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ export const backendOutputStackMetadataSchema: z.ZodRecord<z.ZodString, z.ZodObj
4848
stackOutputs: string[];
4949
}>>;
5050

51+
// @public (undocumented)
52+
export type CustomOutput = z.infer<typeof versionedCustomOutputSchema>;
53+
54+
// @public
55+
export const customOutputKey = "AWS::Amplify::Custom";
56+
5157
// @public (undocumented)
5258
export type GraphqlOutput = z.infer<typeof versionedGraphqlOutputSchema>;
5359

@@ -114,9 +120,7 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
114120
verificationMechanisms: z.ZodOptional<z.ZodString>;
115121
socialProviders: z.ZodOptional<z.ZodString>;
116122
oauthDomain: z.ZodOptional<z.ZodString>;
117-
oauthScope: z.ZodOptional<z.ZodString>; /**
118-
* re-export the storage output schema
119-
*/
123+
oauthScope: z.ZodOptional<z.ZodString>;
120124
oauthRedirectSignIn: z.ZodOptional<z.ZodString>;
121125
oauthRedirectSignOut: z.ZodOptional<z.ZodString>;
122126
oauthClientId: z.ZodOptional<z.ZodString>;
@@ -305,6 +309,26 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
305309
storageRegion: string;
306310
};
307311
}>]>>;
312+
"AWS::Amplify::Custom": z.ZodOptional<z.ZodDiscriminatedUnion<"version", [z.ZodObject<{
313+
version: z.ZodLiteral<"1">;
314+
payload: z.ZodObject<{
315+
customOutputs: z.ZodString;
316+
}, "strip", z.ZodTypeAny, {
317+
customOutputs: string;
318+
}, {
319+
customOutputs: string;
320+
}>;
321+
}, "strip", z.ZodTypeAny, {
322+
version: "1";
323+
payload: {
324+
customOutputs: string;
325+
};
326+
}, {
327+
version: "1";
328+
payload: {
329+
customOutputs: string;
330+
};
331+
}>]>>;
308332
}, "strip", z.ZodTypeAny, {
309333
"AWS::Amplify::Platform"?: {
310334
version: "1";
@@ -361,6 +385,12 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
361385
storageRegion: string;
362386
};
363387
} | undefined;
388+
"AWS::Amplify::Custom"?: {
389+
version: "1";
390+
payload: {
391+
customOutputs: string;
392+
};
393+
} | undefined;
364394
}, {
365395
"AWS::Amplify::Platform"?: {
366396
version: "1";
@@ -417,6 +447,12 @@ export const unifiedBackendOutputSchema: z.ZodObject<{
417447
storageRegion: string;
418448
};
419449
} | undefined;
450+
"AWS::Amplify::Custom"?: {
451+
version: "1";
452+
payload: {
453+
customOutputs: string;
454+
};
455+
} | undefined;
420456
}>;
421457

422458
// @public (undocumented)
@@ -551,6 +587,28 @@ export const versionedAuthOutputSchema: z.ZodDiscriminatedUnion<"version", [z.Zo
551587
};
552588
}>]>;
553589

590+
// @public (undocumented)
591+
export const versionedCustomOutputSchema: z.ZodDiscriminatedUnion<"version", [z.ZodObject<{
592+
version: z.ZodLiteral<"1">;
593+
payload: z.ZodObject<{
594+
customOutputs: z.ZodString;
595+
}, "strip", z.ZodTypeAny, {
596+
customOutputs: string;
597+
}, {
598+
customOutputs: string;
599+
}>;
600+
}, "strip", z.ZodTypeAny, {
601+
version: "1";
602+
payload: {
603+
customOutputs: string;
604+
};
605+
}, {
606+
version: "1";
607+
payload: {
608+
customOutputs: string;
609+
};
610+
}>]>;
611+
554612
// @public (undocumented)
555613
export const versionedGraphqlOutputSchema: z.ZodDiscriminatedUnion<"version", [z.ZodObject<{
556614
version: z.ZodLiteral<"1">;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { z } from 'zod';
2+
import { customOutputSchema as customOutputSchemaV1 } from './v1.js';
3+
4+
export const versionedCustomOutputSchema = z.discriminatedUnion('version', [
5+
customOutputSchemaV1,
6+
// this is where additional custom major version schemas would go
7+
]);
8+
9+
export type CustomOutput = z.infer<typeof versionedCustomOutputSchema>;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { z } from 'zod';
2+
3+
export const customOutputSchema = z.object({
4+
version: z.literal('1'),
5+
payload: z.object({
6+
customOutputs: z.string(), // serialized Partial<ClientConfig>
7+
}),
8+
});

packages/backend-output-schemas/src/index.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { versionedAuthOutputSchema } from './auth/index.js';
33
import { versionedGraphqlOutputSchema } from './graphql/index.js';
44
import { versionedStorageOutputSchema } from './storage/index.js';
55
import { versionedStackOutputSchema } from './stack/index.js';
6+
import { versionedCustomOutputSchema } from './custom';
67

78
/**
89
* The auth, graphql and storage exports here are duplicated from the submodule exports in the package.json file
@@ -11,11 +12,25 @@ import { versionedStackOutputSchema } from './stack/index.js';
1112
*/
1213

1314
/**
14-
* ---------- Auth exports ----------
15+
* ---------- Platform exports ----------
1516
*/
1617

1718
export const platformOutputKey = 'AWS::Amplify::Platform';
1819

20+
export * from './platform/index.js';
21+
22+
/**
23+
* ---------- Custom exports ----------
24+
*/
25+
26+
export const customOutputKey = 'AWS::Amplify::Custom';
27+
28+
export * from './custom/index.js';
29+
30+
/**
31+
* ---------- Auth exports ----------
32+
*/
33+
1934
/**
2035
* re-export the auth output schema
2136
*/
@@ -67,15 +82,10 @@ export const unifiedBackendOutputSchema = z.object({
6782
[authOutputKey]: versionedAuthOutputSchema.optional(),
6883
[graphqlOutputKey]: versionedGraphqlOutputSchema.optional(),
6984
[storageOutputKey]: versionedStorageOutputSchema.optional(),
85+
[customOutputKey]: versionedCustomOutputSchema.optional(),
7086
});
7187
/**
7288
* This type is a subset of the BackendOutput type that is exposed by the platform.
7389
* It represents BackendOutput that has been validated against the schema of known output values
7490
*/
7591
export type UnifiedBackendOutput = z.infer<typeof unifiedBackendOutputSchema>;
76-
77-
/**
78-
* ---------- Platform exports ----------
79-
*/
80-
81-
export * from './platform/index.js';

packages/backend-output-storage/src/stack_metadata_output_storage_strategy.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ export class StackMetadataBackendOutputStorageStrategy
1818
constructor(private readonly stack: Stack) {}
1919

2020
/**
21-
* Store construct output as stack output and add pending metadata to the metadata object.
22-
*
23-
* Metadata is not written to the stack until flush() is called
21+
* Store construct output as stack output and add metadata to the metadata object.
2422
*/
2523
addBackendOutputEntry = (
2624
keyName: string,

packages/backend/API.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { a } from '@aws-amplify/data-schema';
88
import { BackendSecret } from '@aws-amplify/plugin-types';
9+
import { ClientConfig } from '@aws-amplify/client-config';
910
import { ClientSchema } from '@aws-amplify/data-schema';
1011
import { ConstructFactory } from '@aws-amplify/plugin-types';
1112
import { defineAuth } from '@aws-amplify/backend-auth';
@@ -25,6 +26,7 @@ export type Backend<T extends DefineBackendProps> = BackendBase & {
2526
// @public (undocumented)
2627
export type BackendBase = {
2728
createStack: (name: string) => Stack;
29+
addOutput: (clientConfigPart: Partial<ClientConfig>) => void;
2830
};
2931

3032
export { ClientSchema }

packages/backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@aws-amplify/backend-output-storage": "^0.2.11",
3030
"@aws-amplify/backend-secret": "^0.4.3",
3131
"@aws-amplify/backend-storage": "^0.4.4",
32+
"@aws-amplify/client-config": "^0.6.0",
3233
"@aws-amplify/platform-core": "^0.4.3",
3334
"@aws-amplify/plugin-types": "^0.7.1",
3435
"@aws-sdk/client-amplify": "^3.465.0"

packages/backend/src/backend.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { ConstructFactory, ResourceProvider } from '@aws-amplify/plugin-types';
22
import { Stack } from 'aws-cdk-lib';
3+
import { ClientConfig } from '@aws-amplify/client-config';
34

45
export type BackendBase = {
56
createStack: (name: string) => Stack;
7+
addOutput: (clientConfigPart: Partial<ClientConfig>) => void;
68
};
79

810
// Type that allows construct factories to be defined using any keys except those used in BackendHelpers

0 commit comments

Comments
 (0)