@infoxchange/make-it-so 2.13.0-internal-testing-add-import-time-setup-proxy-globally.2 → 2.13.0-internal-testing-randomise-subnet.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -302,31 +302,6 @@ const vpcDetails = new IxVpcDetails(scope, "VpcDetails");
302
302
 
303
303
  </details>
304
304
 
305
- ### Configuring Clients To Use the HTTP Proxy
306
-
307
- It's not always foolproof due to the lack of standardisation around how http proxy support can be configured at a global
308
- level but importing the following should hopefully means that any http requests are sent via the proxy:
309
-
310
- ```typescript
311
- import "@infoxchange/make-it-so/proxy/setup-globally";
312
- ```
313
-
314
- Or if you don't want/need proxy details to be configured before other imports you can use:
315
-
316
- ```typescript
317
- import { setupProxyGlobally } from "@infoxchange/make-it-so/proxy";
318
-
319
- setupProxyGlobally();
320
- ```
321
-
322
- You can also get local fetch instance that's configured to use the proxy:
323
-
324
- ```typescript
325
- import { getProxiedFetch } from "@infoxchange/make-it-so/proxy";
326
-
327
- const httpProxiedFetch = getProxiedFetch();
328
- ```
329
-
330
305
  ## Example App Using Make It So
331
306
 
332
307
  To deploy a Next.js based site you would include a `sst.config.ts` file at the root of repo with contents like this:
@@ -1 +1 @@
1
- {"version":3,"file":"IxVpcDetails.d.ts","sourceRoot":"","sources":["../../src/cdk-constructs/IxVpcDetails.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAO,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAGhD,KAAK,cAAc,GAAG,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE,KAAK,WAAW,GAAG,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9D,qBAAa,YAAa,SAAQ,SAAS;IAClC,GAAG,EAAE,IAAI,CAAC;gBAEL,KAAK,EAAE,cAAc,EAAE,EAAE,EAAE,WAAW;IAKlD,OAAO,CAAC,MAAM;IAad,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC;CAQ7D"}
1
+ {"version":3,"file":"IxVpcDetails.d.ts","sourceRoot":"","sources":["../../src/cdk-constructs/IxVpcDetails.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAO,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAGhD,KAAK,cAAc,GAAG,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE,KAAK,WAAW,GAAG,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9D,qBAAa,YAAa,SAAQ,SAAS;IAClC,GAAG,EAAE,IAAI,CAAC;gBAEL,KAAK,EAAE,cAAc,EAAE,EAAE,EAAE,WAAW;IAKlD,OAAO,CAAC,MAAM;IAad,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC;CAmB7D"}
@@ -21,6 +21,17 @@ export class IxVpcDetails extends Construct {
21
21
  });
22
22
  }
23
23
  static getVpcSubnetIds(scope) {
24
- return [1, 2, 3].map((subnetNum) => StringParameter.valueForStringParameter(scope, `/vpc/subnet/private-${ixDeployConfig.workloadGroup}/${subnetNum}/id`));
24
+ const { workloadGroup, appName } = ixDeployConfig;
25
+ let suffix = "";
26
+ if (workloadGroup === "ds") {
27
+ const possibleSuffixes = ["", "-2"];
28
+ // Randomly select a suffix to spread workload's IP usage across both sets of subnets. Use the app name as a seed
29
+ // to ensure consistent selection on redeploys.
30
+ const hash = appName
31
+ .split("")
32
+ .reduce((acc, char) => acc + char.charCodeAt(0), 0);
33
+ suffix = possibleSuffixes[hash % possibleSuffixes.length];
34
+ }
35
+ return [1, 2, 3].map((subnetNum) => StringParameter.valueForStringParameter(scope, `/vpc/subnet/private-${workloadGroup}${suffix}/${subnetNum}/id`));
25
36
  }
26
37
  }
@@ -165,7 +165,7 @@ export class SiteOidcAuth extends Construct {
165
165
  origin: new CloudFrontOrigins.HttpOrigin(CDK.Fn.parseDomainName(authRouteFunctionUrl.url)),
166
166
  allowedMethods: CloudFront.AllowedMethods.ALLOW_ALL,
167
167
  cachePolicy: new CloudFront.CachePolicy(scope, `${this.id}AllowAllCookiesPolicy`, {
168
- cachePolicyName: `${this.id}-AllowAllCookiesPolicy`,
168
+ cachePolicyName: `${CDK.Stack.of(scope).stackName}-${this.id}-AllowAllCookiesPolicy`,
169
169
  comment: "Cache policy that forwards all cookies",
170
170
  defaultTtl: CDK.Duration.seconds(1),
171
171
  minTtl: CDK.Duration.seconds(1),
@@ -1,4 +1,4 @@
1
1
  import { fetch as undiciFetch } from "undici";
2
2
  export declare function setupProxyGlobally(): void;
3
3
  export declare function getProxiedFetch(): typeof undiciFetch;
4
- //# sourceMappingURL=request-client-setup.d.ts.map
4
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/lib/proxy/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,IAAI,WAAW,EACrB,MAAM,QAAQ,CAAC;AAGhB,wBAAgB,kBAAkB,SAmBjC;AAED,wBAAgB,eAAe,uBAW9B"}
@@ -4,7 +4,7 @@ export function setupProxyGlobally() {
4
4
  // Make operation idempotent
5
5
  if (getGlobalDispatcher() instanceof EnvHttpProxyAgent)
6
6
  return;
7
- if (!process.env.HTTP_PROXY && !process.env.HTTPS_PROXY)
7
+ if (!process.env.HTTP_PROXY || !process.env.HTTPS_PROXY)
8
8
  return;
9
9
  // To cover libraries that use fetch
10
10
  // See https://nodejs.org/api/globals.html#custom-dispatcher
@@ -1,2 +1,2 @@
1
- export * from "./request-client-setup.js";
1
+ export * from "./fetch.js";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/proxy/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/proxy/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
@@ -1 +1 @@
1
- export * from "./request-client-setup.js";
1
+ export * from "./fetch.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infoxchange/make-it-so",
3
- "version": "2.13.0-internal-testing-add-import-time-setup-proxy-globally.2",
3
+ "version": "2.13.0-internal-testing-randomise-subnet.2",
4
4
  "description": "Makes deploying services to IX infra easy",
5
5
  "repository": "github:infoxchange/make-it-so",
6
6
  "type": "module",
@@ -18,8 +18,7 @@
18
18
  "./cdk-constructs": "./dist/cdk-constructs/index.js",
19
19
  "./deployConfig": "./dist/deployConfig.js",
20
20
  "./auth": "./dist/lib/auth/index.js",
21
- "./proxy": "./dist/lib/proxy/index.js",
22
- "./proxy/setup-globally": "./dist/lib/proxy/request-client-global-setup-on-import.js"
21
+ "./proxy": "./dist/lib/proxy/index.js"
23
22
  },
24
23
  "lint-staged": {
25
24
  "**/*": [
@@ -28,10 +28,21 @@ export class IxVpcDetails extends Construct {
28
28
  }
29
29
 
30
30
  static getVpcSubnetIds(scope: ConstructScope): Array<string> {
31
+ const { workloadGroup, appName } = ixDeployConfig;
32
+ let suffix = "";
33
+ if (workloadGroup === "ds") {
34
+ const possibleSuffixes = ["", "-2"];
35
+ // Randomly select a suffix to spread workload's IP usage across both sets of subnets. Use the app name as a seed
36
+ // to ensure consistent selection on redeploys.
37
+ const hash = appName
38
+ .split("")
39
+ .reduce((acc, char) => acc + char.charCodeAt(0), 0);
40
+ suffix = possibleSuffixes[hash % possibleSuffixes.length];
41
+ }
31
42
  return [1, 2, 3].map((subnetNum) =>
32
43
  StringParameter.valueForStringParameter(
33
44
  scope,
34
- `/vpc/subnet/private-${ixDeployConfig.workloadGroup}/${subnetNum}/id`,
45
+ `/vpc/subnet/private-${workloadGroup}${suffix}/${subnetNum}/id`,
35
46
  ),
36
47
  );
37
48
  }
@@ -274,7 +274,7 @@ export class SiteOidcAuth extends Construct {
274
274
  scope,
275
275
  `${this.id}AllowAllCookiesPolicy`,
276
276
  {
277
- cachePolicyName: `${this.id}-AllowAllCookiesPolicy`,
277
+ cachePolicyName: `${CDK.Stack.of(scope).stackName}-${this.id}-AllowAllCookiesPolicy`,
278
278
  comment: "Cache policy that forwards all cookies",
279
279
  defaultTtl: CDK.Duration.seconds(1),
280
280
  minTtl: CDK.Duration.seconds(1),
@@ -10,7 +10,7 @@ export function setupProxyGlobally() {
10
10
  // Make operation idempotent
11
11
  if (getGlobalDispatcher() instanceof EnvHttpProxyAgent) return;
12
12
 
13
- if (!process.env.HTTP_PROXY && !process.env.HTTPS_PROXY) return;
13
+ if (!process.env.HTTP_PROXY || !process.env.HTTPS_PROXY) return;
14
14
 
15
15
  // To cover libraries that use fetch
16
16
  // See https://nodejs.org/api/globals.html#custom-dispatcher
@@ -1 +1 @@
1
- export * from "./request-client-setup.js";
1
+ export * from "./fetch.js";
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=request-client-global-setup-on-import.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"request-client-global-setup-on-import.d.ts","sourceRoot":"","sources":["../../../src/lib/proxy/request-client-global-setup-on-import.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- import { setupProxyGlobally } from "./request-client-setup.js";
2
- setupProxyGlobally();
@@ -1 +0,0 @@
1
- {"version":3,"file":"request-client-setup.d.ts","sourceRoot":"","sources":["../../../src/lib/proxy/request-client-setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,IAAI,WAAW,EACrB,MAAM,QAAQ,CAAC;AAGhB,wBAAgB,kBAAkB,SAmBjC;AAED,wBAAgB,eAAe,uBAW9B"}
@@ -1,3 +0,0 @@
1
- import { setupProxyGlobally } from "./request-client-setup.js";
2
-
3
- setupProxyGlobally();