diff --git a/API.md b/API.md
index 75c4ae0..9596e87 100644
--- a/API.md
+++ b/API.md
@@ -3,34 +3,34 @@
## Structs
-### NamedEnv
+### NamedEnv
-#### Initializer
+#### Initializer
```typescript
-import { environments } from '@time-loop/cdk-named-environments'
+import { NamedEnv } from '@time-loop/cdk-named-environments'
-const namedEnv: environments.NamedEnv = { ... }
+const namedEnv: NamedEnv = { ... }
```
#### Properties
| **Name** | **Type** | **Description** |
| --- | --- | --- |
-| account | string | The AWS account ID for this environment. |
-| region | string | The AWS region for this environment. |
-| defaultRegion | string | If a region isn't specified, where should we default to. |
-| name | string | The proper name of the environment in kebab-format. |
-| organizationalUnit | string | What kind of an account is this? |
-| regionDetails | {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} | A map of region => { asn, cidr }, for each region of the environment. |
-| shard | IShard | The shard within a region. |
-| zoneName | string | The DNS zone into which services should be deployed. |
-| ssoRegion | string | In which region does SSO live in? |
-| ssoStartUrl | string | Is this an SSO accessible account? |
+| account | string | The AWS account ID for this environment. |
+| region | string | The AWS region for this environment. |
+| defaultRegion | string | If a region isn't specified, where should we default to. |
+| name | string | The proper name of the environment in kebab-format. |
+| organizationalUnit | string | What kind of an account is this? |
+| regionDetails | {[ key: string ]: RegionalDetails} | A map of region => { asn, cidr }, for each region of the environment. |
+| zoneName | string | The DNS zone into which services should be deployed. |
+| ssoRegion | string | In which region does SSO live in? |
+| ssoStartUrl | string | Is this an SSO accessible account? |
+| shard | IShard | The shard within a region. |
---
-##### `account`Optional
+##### `account`Optional
```typescript
public readonly account: string;
@@ -50,7 +50,7 @@ will cause this stack to emit synthesis errors.
---
-##### `region`Optional
+##### `region`Optional
```typescript
public readonly region: string;
@@ -70,7 +70,7 @@ will cause this stack to emit synthesis errors.
---
-##### `defaultRegion`Required
+##### `defaultRegion`Required
```typescript
public readonly defaultRegion: string;
@@ -84,7 +84,7 @@ Also considered for centralized resources.
---
-##### `name`Required
+##### `name`Required
```typescript
public readonly name: string;
@@ -96,7 +96,7 @@ The proper name of the environment in kebab-format.
---
-##### `organizationalUnit`Required
+##### `organizationalUnit`Required
```typescript
public readonly organizationalUnit: string;
@@ -108,19 +108,57 @@ What kind of an account is this?
---
-##### `regionDetails`Required
+##### `regionDetails`Required
```typescript
public readonly regionDetails: {[ key: string ]: RegionalDetails};
```
-- *Type:* {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails}
+- *Type:* {[ key: string ]: RegionalDetails}
A map of region => { asn, cidr }, for each region of the environment.
---
-##### `shard`Required
+##### `zoneName`Required
+
+```typescript
+public readonly zoneName: string;
+```
+
+- *Type:* string
+
+The DNS zone into which services should be deployed.
+
+---
+
+##### `ssoRegion`Optional
+
+```typescript
+public readonly ssoRegion: string;
+```
+
+- *Type:* string
+
+In which region does SSO live in?
+
+---
+
+##### `ssoStartUrl`Optional
+
+```typescript
+public readonly ssoStartUrl: string;
+```
+
+- *Type:* string
+
+Is this an SSO accessible account?
+
+If so, what's the start url?
+
+---
+
+##### `shard`Required
```typescript
public readonly shard: IShard;
@@ -132,7 +170,81 @@ The shard within a region.
---
-##### `zoneName`Required
+### NamedEnvCommonProps
+
+#### Initializer
+
+```typescript
+import { NamedEnvCommonProps } from '@time-loop/cdk-named-environments'
+
+const namedEnvCommonProps: NamedEnvCommonProps = { ... }
+```
+
+#### Properties
+
+| **Name** | **Type** | **Description** |
+| --- | --- | --- |
+| defaultRegion | string | If a region isn't specified, where should we default to. |
+| name | string | The proper name of the environment in kebab-format. |
+| organizationalUnit | string | What kind of an account is this? |
+| regionDetails | {[ key: string ]: RegionalDetails} | A map of region => { asn, cidr }, for each region of the environment. |
+| zoneName | string | The DNS zone into which services should be deployed. |
+| ssoRegion | string | In which region does SSO live in? |
+| ssoStartUrl | string | Is this an SSO accessible account? |
+
+---
+
+##### `defaultRegion`Required
+
+```typescript
+public readonly defaultRegion: string;
+```
+
+- *Type:* string
+
+If a region isn't specified, where should we default to.
+
+Also considered for centralized resources.
+
+---
+
+##### `name`Required
+
+```typescript
+public readonly name: string;
+```
+
+- *Type:* string
+
+The proper name of the environment in kebab-format.
+
+---
+
+##### `organizationalUnit`Required
+
+```typescript
+public readonly organizationalUnit: string;
+```
+
+- *Type:* string
+
+What kind of an account is this?
+
+---
+
+##### `regionDetails`Required
+
+```typescript
+public readonly regionDetails: {[ key: string ]: RegionalDetails};
+```
+
+- *Type:* {[ key: string ]: RegionalDetails}
+
+A map of region => { asn, cidr }, for each region of the environment.
+
+---
+
+##### `zoneName`Required
```typescript
public readonly zoneName: string;
@@ -144,7 +256,7 @@ The DNS zone into which services should be deployed.
---
-##### `ssoRegion`Optional
+##### `ssoRegion`Optional
```typescript
public readonly ssoRegion: string;
@@ -156,7 +268,7 @@ In which region does SSO live in?
---
-##### `ssoStartUrl`Optional
+##### `ssoStartUrl`Optional
```typescript
public readonly ssoStartUrl: string;
@@ -170,26 +282,26 @@ If so, what's the start url?
---
-### NamedEnvFactory
+### NamedEnvFactory
-#### Initializer
+#### Initializer
```typescript
-import { environments } from '@time-loop/cdk-named-environments'
+import { NamedEnvFactory } from '@time-loop/cdk-named-environments'
-const namedEnvFactory: environments.NamedEnvFactory = { ... }
+const namedEnvFactory: NamedEnvFactory = { ... }
```
#### Properties
| **Name** | **Type** | **Description** |
| --- | --- | --- |
-| environmentName | string | *No description.* |
-| regionDetails | {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} | *No description.* |
+| environmentName | string | *No description.* |
+| regionDetails | {[ key: string ]: RegionalDetails} | *No description.* |
---
-##### `environmentName`Required
+##### `environmentName`Required
```typescript
public readonly environmentName: string;
@@ -199,58 +311,46 @@ public readonly environmentName: string;
---
-##### `regionDetails`Required
+##### `regionDetails`Required
```typescript
public readonly regionDetails: {[ key: string ]: RegionalDetails};
```
-- *Type:* {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails}
+- *Type:* {[ key: string ]: RegionalDetails}
---
-### NamedEnvironmentProps
+### NamedEnvironmentProps
Used by newNamedEnvFactory.
Is it used elsewhere?
-#### Initializer
+#### Initializer
```typescript
-import { environments } from '@time-loop/cdk-named-environments'
+import { NamedEnvironmentProps } from '@time-loop/cdk-named-environments'
-const namedEnvironmentProps: environments.NamedEnvironmentProps = { ... }
+const namedEnvironmentProps: NamedEnvironmentProps = { ... }
```
#### Properties
| **Name** | **Type** | **Description** |
| --- | --- | --- |
-| account | string | The numeric account id as used by cdk.Environment.account. |
-| defaultRegion | string | If a region isn't specified, where should we default to. |
-| name | string | The proper name of the environment in kebab-format. |
-| organizationalUnit | string | What kind of an account is this? |
-| regionDetails | {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} | A map of region => { asn, cidr }, for each region of the environment. |
-| zoneName | string | The DNS zone into which services should be deployed. |
-| ssoRegion | string | In which region does SSO live in? |
-| ssoStartUrl | string | Is this an SSO accessible account? |
-
----
-
-##### `account`Required
-
-```typescript
-public readonly account: string;
-```
-
-- *Type:* string
-
-The numeric account id as used by cdk.Environment.account.
+| defaultRegion | string | If a region isn't specified, where should we default to. |
+| name | string | The proper name of the environment in kebab-format. |
+| organizationalUnit | string | What kind of an account is this? |
+| regionDetails | {[ key: string ]: RegionalDetails} | A map of region => { asn, cidr }, for each region of the environment. |
+| zoneName | string | The DNS zone into which services should be deployed. |
+| ssoRegion | string | In which region does SSO live in? |
+| ssoStartUrl | string | Is this an SSO accessible account? |
+| account | string | The numeric account id as used by cdk.Environment.account. |
---
-##### `defaultRegion`Required
+##### `defaultRegion`Required
```typescript
public readonly defaultRegion: string;
@@ -264,7 +364,7 @@ Also considered for centralized resources.
---
-##### `name`Required
+##### `name`Required
```typescript
public readonly name: string;
@@ -276,7 +376,7 @@ The proper name of the environment in kebab-format.
---
-##### `organizationalUnit`Required
+##### `organizationalUnit`Required
```typescript
public readonly organizationalUnit: string;
@@ -288,19 +388,19 @@ What kind of an account is this?
---
-##### `regionDetails`Required
+##### `regionDetails`Required
```typescript
public readonly regionDetails: {[ key: string ]: RegionalDetails};
```
-- *Type:* {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails}
+- *Type:* {[ key: string ]: RegionalDetails}
A map of region => { asn, cidr }, for each region of the environment.
---
-##### `zoneName`Required
+##### `zoneName`Required
```typescript
public readonly zoneName: string;
@@ -312,7 +412,7 @@ The DNS zone into which services should be deployed.
---
-##### `ssoRegion`Optional
+##### `ssoRegion`Optional
```typescript
public readonly ssoRegion: string;
@@ -324,7 +424,7 @@ In which region does SSO live in?
---
-##### `ssoStartUrl`Optional
+##### `ssoStartUrl`Optional
```typescript
public readonly ssoStartUrl: string;
@@ -338,26 +438,38 @@ If so, what's the start url?
---
-### RegionalDetails
+##### `account`Required
+
+```typescript
+public readonly account: string;
+```
+
+- *Type:* string
+
+The numeric account id as used by cdk.Environment.account.
+
+---
+
+### RegionalDetails
-#### Initializer
+#### Initializer
```typescript
-import { environments } from '@time-loop/cdk-named-environments'
+import { RegionalDetails } from '@time-loop/cdk-named-environments'
-const regionalDetails: environments.RegionalDetails = { ... }
+const regionalDetails: RegionalDetails = { ... }
```
#### Properties
| **Name** | **Type** | **Description** |
| --- | --- | --- |
-| asn | number | *No description.* |
-| cidr | string | *No description.* |
+| asn | number | *No description.* |
+| cidr | string | *No description.* |
---
-##### `asn`Required
+##### `asn`Required
```typescript
public readonly asn: number;
@@ -367,7 +479,7 @@ public readonly asn: number;
---
-##### ~~`cidr`~~Required
+##### ~~`cidr`~~Required
- *Deprecated:* you should probably be using the shard's cidr.
diff --git a/src/NamedEnv.ts b/src/NamedEnv.ts
index 2f1fe5b..3e6c448 100644
--- a/src/NamedEnv.ts
+++ b/src/NamedEnv.ts
@@ -1,94 +1,92 @@
import { Environment } from 'aws-cdk-lib';
import { IShard } from './Shard';
-export module environments {
- export interface RegionalDetails {
- readonly asn: number;
- /**
- * @deprecated you should probably be using the shard's cidr.
- */
- readonly cidr: string; // in '0.0.0.0/32' format
- }
-
- interface NamedEnvCommonProps {
- /**
- * If a region isn't specified, where should we default to.
- * Also considered for centralized resources.
- */
- readonly defaultRegion: string;
- /**
- * A map of region => { asn, cidr }, for each region of the environment.
- */
- readonly regionDetails: Record;
- /**
- * The proper name of the environment in kebab-format.
- */
- readonly name: string;
- /**
- * What kind of an account is this?
- */
- readonly organizationalUnit: string;
- /**
- * In which region does SSO live in?
- */
- readonly ssoRegion?: string;
- /**
- * Is this an SSO accessible account? If so, what's the start url?
- */
- readonly ssoStartUrl?: string;
- /**
- * The DNS zone into which services should be deployed.
- */
- readonly zoneName: string;
- }
-
- export interface NamedEnv extends Environment, NamedEnvCommonProps {
- /**
- * The shard within a region.
- */
- readonly shard: IShard;
- }
+export interface RegionalDetails {
+ readonly asn: number;
+ /**
+ * @deprecated you should probably be using the shard's cidr.
+ */
+ readonly cidr: string; // in '0.0.0.0/32' format
+}
+export interface NamedEnvCommonProps {
/**
- * Used by newNamedEnvFactory. Is it used elsewhere?
+ * If a region isn't specified, where should we default to.
+ * Also considered for centralized resources.
*/
- export interface NamedEnvironmentProps extends NamedEnvCommonProps {
- /**
- * The numeric account id as used by cdk.Environment.account
- */
- readonly account: string;
- }
+ readonly defaultRegion: string;
+ /**
+ * A map of region => { asn, cidr }, for each region of the environment.
+ */
+ readonly regionDetails: Record;
+ /**
+ * The proper name of the environment in kebab-format.
+ */
+ readonly name: string;
+ /**
+ * What kind of an account is this?
+ */
+ readonly organizationalUnit: string;
+ /**
+ * In which region does SSO live in?
+ */
+ readonly ssoRegion?: string;
+ /**
+ * Is this an SSO accessible account? If so, what's the start url?
+ */
+ readonly ssoStartUrl?: string;
+ /**
+ * The DNS zone into which services should be deployed.
+ */
+ readonly zoneName: string;
+}
- export interface NamedEnvFactory {
- // TODO: should we add shardDetails here?
- readonly environmentName: string;
- readonly regionDetails: Record;
- (shard: IShard): NamedEnv;
- }
+export interface NamedEnv extends Environment, NamedEnvCommonProps {
+ /**
+ * The shard within a region.
+ */
+ readonly shard: IShard;
+}
+/**
+ * Used by newNamedEnvFactory. Is it used elsewhere?
+ */
+export interface NamedEnvironmentProps extends NamedEnvCommonProps {
/**
- * Generates a function which creates a NamedEnv when given a region
- * @param props
- * @returns NamedEnv
+ * The numeric account id as used by cdk.Environment.account
*/
- export function newNamedEnvFactory(props: NamedEnvironmentProps): NamedEnvFactory {
- if ((props.ssoStartUrl || props.ssoRegion) && !(props.ssoStartUrl && props.ssoRegion)) {
- console.warn(
- `Something is wrong for ${props.name}: ssoStartUrl = ${JSON.stringify(props.ssoStartUrl)} and ssoRegion = ${
- props.ssoRegion
- }, but either both or neither of these should be set.`,
- );
- }
+ readonly account: string;
+}
- const namedEnvFactory = function (shard: IShard): NamedEnv {
- return {
- ...props,
- shard,
- region: shard.region,
- };
- };
- namedEnvFactory.environmentName = props.name;
- namedEnvFactory.regionDetails = props.regionDetails;
- return namedEnvFactory;
+export interface NamedEnvFactory {
+ // TODO: should we add shardDetails here?
+ readonly environmentName: string;
+ readonly regionDetails: Record;
+ (shard: IShard): NamedEnv;
+}
+
+/**
+ * Generates a function which creates a NamedEnv when given a region
+ * @param props
+ * @returns NamedEnv
+ */
+export function newNamedEnvFactory(props: NamedEnvironmentProps): NamedEnvFactory {
+ if ((props.ssoStartUrl || props.ssoRegion) && !(props.ssoStartUrl && props.ssoRegion)) {
+ console.warn(
+ `Something is wrong for ${props.name}: ssoStartUrl = ${JSON.stringify(props.ssoStartUrl)} and ssoRegion = ${
+ props.ssoRegion
+ }, but either both or neither of these should be set.`,
+ );
}
+
+ const namedEnvFactory = function (shard: IShard): NamedEnv {
+ return {
+ ...props,
+ shard,
+ region: shard.region,
+ };
+ };
+ namedEnvFactory.environmentName = props.name;
+ namedEnvFactory.regionDetails = props.regionDetails;
+ return namedEnvFactory;
}
diff --git a/test/NamedEnv.test.ts b/test/NamedEnv.test.ts
index 55b34f0..c3074d3 100644
--- a/test/NamedEnv.test.ts
+++ b/test/NamedEnv.test.ts
@@ -1,12 +1,12 @@
import 'process';
import { IShard } from '../src';
-import { environments } from '../src/NamedEnv';
+import { newNamedEnvFactory, NamedEnvFactory, NamedEnvironmentProps } from '../src/NamedEnv';
enum TestOrganizationalUnit {
Test = 'dev',
}
-let fakeEnvProps: environments.NamedEnvironmentProps;
+let fakeEnvProps: NamedEnvironmentProps;
describe('NamedEnv', () => {
describe('functionality', () => {
@@ -23,7 +23,7 @@ describe('NamedEnv', () => {
it('warns when has ssoStartUrl, but not ssoRegion', () => {
const fakeWarn = jest.spyOn(global.console, 'warn').mockImplementation(() => {});
- environments.newNamedEnvFactory({ ...fakeEnvProps, ssoStartUrl: 'fakeStartUrl' });
+ newNamedEnvFactory({ ...fakeEnvProps, ssoStartUrl: 'fakeStartUrl' });
expect(fakeWarn).toHaveBeenCalledTimes(1);
expect(fakeWarn).toHaveBeenCalledWith(
'Something is wrong for sandbox: ssoStartUrl = "fakeStartUrl" and ssoRegion = undefined, but either both or neither of these should be set.',
@@ -31,7 +31,7 @@ describe('NamedEnv', () => {
});
it('throws when has ssoRegion, but not ssoStartUrl', () => {
const fakeWarn = jest.spyOn(global.console, 'warn').mockImplementation(() => {});
- environments.newNamedEnvFactory({ ...fakeEnvProps, ssoRegion: 'fakeSsoRegion' });
+ newNamedEnvFactory({ ...fakeEnvProps, ssoRegion: 'fakeSsoRegion' });
expect(fakeWarn).toHaveBeenCalledTimes(1);
expect(fakeWarn).toHaveBeenCalledWith(
'Something is wrong for sandbox: ssoStartUrl = undefined and ssoRegion = fakeSsoRegion, but either both or neither of these should be set.',
@@ -39,7 +39,7 @@ describe('NamedEnv', () => {
});
describe('namedEnvFactory', () => {
let shard: IShard;
- let factory: environments.NamedEnvFactory;
+ let factory: NamedEnvFactory;
beforeEach(() => {
fakeEnvProps = {
name: 'sandbox',
@@ -56,7 +56,7 @@ describe('NamedEnv', () => {
name: 'TestShard',
number: 1,
};
- factory = environments.newNamedEnvFactory(fakeEnvProps);
+ factory = newNamedEnvFactory(fakeEnvProps);
});
it('takes a shard as input', () => {
const testEnv = factory(shard);