@infoxchange/make-it-so 2.11.0-internal-testing-vdt-199-add-auth-token-verify-function-2.5 → 2.11.0-internal-testing-vdt-199-add-auth-token-verify-function-2.7

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.
@@ -87,7 +87,24 @@ function _sign(input, key, method) {
87
87
  return crypto.createHmac(method, key).update(input).digest("base64url");
88
88
  }
89
89
  function _base64urlDecode(str) {
90
- return Buffer.from(str, "base64url").toString();
90
+ str = str.replace(/-/g, '+').replace(/_/g, '/');
91
+ while (str.length % 4)
92
+ str += '=';
93
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
94
+ let output = '';
95
+ let bc = 0, bs = 0, buffer, i = 0;
96
+ for (; i < str.length; i++) {
97
+ buffer = chars.indexOf(str.charAt(i));
98
+ if (buffer === -1)
99
+ continue;
100
+ bs = (bs << 6) | buffer;
101
+ bc += 6;
102
+ if (bc >= 8) {
103
+ bc -= 8;
104
+ output += String.fromCharCode((bs >> bc) & 0xFF);
105
+ }
106
+ }
107
+ return output;
91
108
  }
92
109
  const jwtToken = request.cookies["auth-token"] && request.cookies["auth-token"].value;
93
110
  if (!jwtToken) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cdk-constructs/SiteOidcAuth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,UAAU,MAAM,4BAA4B,CAAC;AACpD,OAAO,GAAG,MAAM,aAAa,CAAC;AAE9B,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AAOtC,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,2BAA2B,CAAC;AAEnC,KAAK,cAAc,GAAG,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE,KAAK,WAAW,GAA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AE,SAAS,EACpB,EAAE,MAA+B,EAAE,GAAE,cAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAuC1D,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,sBAAsB;IAgC9B,OAAO,CAAC,2BAA2B;IAoBnC,OAAO,CAAC,yCAAyC;IAiBjD,OAAO,CAAC,sBAAsB;CAkF/B"}
@@ -72,7 +72,7 @@ export class SiteOidcAuth extends Construct {
72
72
  const jwtSecret = this.createJwtSecret();
73
73
  updatedSiteProps.cdk.transform = (plan) => {
74
74
  siteProps?.cdk?.transform?.(plan);
75
- plan.cloudFrontFunctions?.serverCfFunction.injections.push(this.getAuthCheckHandlerBodyCode(jwtSecret, prefix));
75
+ plan.cloudFrontFunctions?.serverCfFunction.injections.push(this.convertToCloudFrontFunctionCompatibleCode(this.getAuthCheckHandlerBodyCode(jwtSecret, prefix)));
76
76
  };
77
77
  updatedSiteProps.cdk.distribution.additionalBehaviors[behaviourName] =
78
78
  this.getAuthBehaviorOptions(scope, jwtSecret, prefix);
@@ -100,7 +100,7 @@ export class SiteOidcAuth extends Construct {
100
100
  var request = event.request;
101
101
  ${this.getAuthCheckHandlerBodyCode(jwtSecret, authRoutePrefix)}
102
102
  return request;
103
- }`)),
103
+ }`, { minify: true })),
104
104
  // We could specify the JS v2.0 runtime here but for SSR sites SST does the function creation and that currently
105
105
  // uses JS v1.0 so no point using v2.0 here as the code has to be compatible with v1.0 anyway.
106
106
  });
@@ -115,12 +115,12 @@ export class SiteOidcAuth extends Construct {
115
115
  .readFileSync(path.join(import.meta.dirname, "auth-check-handler-body.js"), "utf8")
116
116
  .replace("__placeholder-for-jwt-secret__", jwtSecret.secretValue.toString())
117
117
  .replace("__placeholder-for-auth-route-prefix__", authRoutePrefix)
118
- // When typescript builds the make-it-so code including it may add an "export {}" at the end to make it a module.
119
- // This will cause a syntax error in CloudFront Functions so remove it here.
118
+ // When typescript builds the make-it-so code including "auth-check-handler-body.ts" it will add "export {}" to
119
+ // the end of the file if it's not already a module. This will cause a syntax error in CloudFront Functions so we
120
+ // remove it here.
120
121
  .replace(/export {};\s*$/g, "");
121
- ;
122
122
  }
123
- convertToCloudFrontFunctionCompatibleCode(sourceCode) {
123
+ convertToCloudFrontFunctionCompatibleCode(sourceCode, esbuildOptions) {
124
124
  // ESBuild doesn't currently support transforming const/let to var, which is required for CloudFront Functions
125
125
  // JS runtime 1.0.
126
126
  sourceCode = sourceCode
@@ -128,8 +128,8 @@ export class SiteOidcAuth extends Construct {
128
128
  .replaceAll(/let /g, "var ");
129
129
  console.log("---- 3", sourceCode);
130
130
  return transformSync(sourceCode, {
131
- minify: true,
132
131
  target: "es5",
132
+ ...esbuildOptions,
133
133
  }).code;
134
134
  }
135
135
  // Get the behavior options for the auth route
@@ -161,7 +161,7 @@ export class SiteOidcAuth extends Construct {
161
161
  const request = event.request;
162
162
  request.headers["x-forwarded-host"] = { value: request.headers.host.value };
163
163
  return request;
164
- }`)),
164
+ }`, { minify: true })),
165
165
  runtime: CloudFront.FunctionRuntime.JS_2_0,
166
166
  });
167
167
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infoxchange/make-it-so",
3
- "version": "2.11.0-internal-testing-vdt-199-add-auth-token-verify-function-2.5",
3
+ "version": "2.11.0-internal-testing-vdt-199-add-auth-token-verify-function-2.7",
4
4
  "description": "Makes deploying services to IX infra easy",
5
5
  "repository": "github:infoxchange/make-it-so",
6
6
  "type": "module",
@@ -116,7 +116,27 @@ function _sign(input: string, key: string, method: string) {
116
116
  }
117
117
 
118
118
  function _base64urlDecode(str: string) {
119
- return Buffer.from(str, "base64url").toString();
119
+ str = str.replace(/-/g, '+').replace(/_/g, '/');
120
+ while (str.length % 4) str += '=';
121
+
122
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
123
+ let output = '';
124
+
125
+ let bc = 0, bs = 0, buffer, i = 0;
126
+ for (; i < str.length; i++) {
127
+ buffer = chars.indexOf(str.charAt(i));
128
+ if (buffer === -1) continue;
129
+
130
+ bs = (bs << 6) | buffer;
131
+ bc += 6;
132
+
133
+ if (bc >= 8) {
134
+ bc -= 8;
135
+ output += String.fromCharCode((bs >> bc) & 0xFF);
136
+ }
137
+ }
138
+
139
+ return output;
120
140
  }
121
141
 
122
142
  const jwtToken =
@@ -9,7 +9,7 @@ import { Config as SSTInternalConfig } from "sst/config.js";
9
9
  import CloudFrontOrigins from "aws-cdk-lib/aws-cloudfront-origins";
10
10
  import path from "node:path";
11
11
  import fs from "node:fs";
12
- import { transformSync } from "esbuild";
12
+ import { TransformOptions, transformSync } from "esbuild";
13
13
  import type {
14
14
  ExtendedNextjsSiteProps,
15
15
  ExtendedStaticSiteProps,
@@ -118,7 +118,9 @@ export class SiteOidcAuth extends Construct {
118
118
  siteProps?.cdk?.transform?.(plan);
119
119
 
120
120
  plan.cloudFrontFunctions?.serverCfFunction.injections.push(
121
- this.getAuthCheckHandlerBodyCode(jwtSecret, prefix),
121
+ this.convertToCloudFrontFunctionCompatibleCode(
122
+ this.getAuthCheckHandlerBodyCode(jwtSecret, prefix),
123
+ ),
122
124
  );
123
125
  };
124
126
 
@@ -161,6 +163,7 @@ export class SiteOidcAuth extends Construct {
161
163
  ${this.getAuthCheckHandlerBodyCode(jwtSecret, authRoutePrefix)}
162
164
  return request;
163
165
  }`,
166
+ { minify: true },
164
167
  ),
165
168
  ),
166
169
  // We could specify the JS v2.0 runtime here but for SSR sites SST does the function creation and that currently
@@ -189,13 +192,15 @@ export class SiteOidcAuth extends Construct {
189
192
  jwtSecret.secretValue.toString(),
190
193
  )
191
194
  .replace("__placeholder-for-auth-route-prefix__", authRoutePrefix)
192
- // When typescript builds the make-it-so code including it may add an "export {}" at the end to make it a module.
193
- // This will cause a syntax error in CloudFront Functions so remove it here.
194
- .replace(/export {};\s*$/g, "");;
195
+ // When typescript builds the make-it-so code including "auth-check-handler-body.ts" it will add "export {}" to
196
+ // the end of the file if it's not already a module. This will cause a syntax error in CloudFront Functions so we
197
+ // remove it here.
198
+ .replace(/export {};\s*$/g, "");
195
199
  }
196
200
 
197
201
  private convertToCloudFrontFunctionCompatibleCode(
198
202
  sourceCode: string,
203
+ esbuildOptions?: TransformOptions,
199
204
  ): string {
200
205
  // ESBuild doesn't currently support transforming const/let to var, which is required for CloudFront Functions
201
206
  // JS runtime 1.0.
@@ -204,8 +209,8 @@ export class SiteOidcAuth extends Construct {
204
209
  .replaceAll(/let /g, "var ");
205
210
  console.log("---- 3", sourceCode)
206
211
  return transformSync(sourceCode, {
207
- minify: true,
208
212
  target: "es5",
213
+ ...esbuildOptions,
209
214
  }).code;
210
215
  }
211
216
 
@@ -254,6 +259,7 @@ export class SiteOidcAuth extends Construct {
254
259
  request.headers["x-forwarded-host"] = { value: request.headers.host.value };
255
260
  return request;
256
261
  }`,
262
+ { minify: true },
257
263
  ),
258
264
  ),
259
265
  runtime: CloudFront.FunctionRuntime.JS_2_0,