diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09b2e3b9..77ada265 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,20 +41,20 @@ jobs: - name: prepare run: npm run test -# - name: example project - npm pack -# run: npm pack -# -# - name: example project - npm ci -# working-directory: example -# run: npm ci -# -# - name: example project - npm install -# working-directory: example -# run: npm install --no-save ../liflig-cdk-cloudfront-auth-0.0.0-development.tgz -# -# - name: example project - npm test -# run: npm run test -# working-directory: example + - name: example project - npm pack + run: npm pack + + - name: example project - npm ci + working-directory: example + run: npm ci + + - name: example project - npm install + working-directory: example + run: npm install --no-save ../liflig-cdk-cloudfront-auth-0.0.0-development.tgz + + - name: example project - npm test + run: npm run test + working-directory: example - name: conditionally semantic release if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} diff --git a/example/lib/auth-lambdas-stack.ts b/example/lib/auth-lambdas-stack.ts index 431e50ef..1cc90629 100644 --- a/example/lib/auth-lambdas-stack.ts +++ b/example/lib/auth-lambdas-stack.ts @@ -1,15 +1,15 @@ -// import { AuthLambdas } from "@liflig/cdk-cloudfront-auth" -// import * as cdk from "aws-cdk-lib" -// import { Construct } from "constructs" -// -// export class AuthLambdasStack extends cdk.Stack { -// readonly authLambdas: AuthLambdas -// -// constructor(scope: Construct, id: string, props?: cdk.StackProps) { -// super(scope, id, props) -// -// this.authLambdas = new AuthLambdas(this, "AuthLambdas", { -// regions: ["eu-west-1"], -// }) -// } -// } +import { AuthLambdas } from "@liflig/cdk-cloudfront-auth" +import * as cdk from "aws-cdk-lib" +import { Construct } from "constructs" + +export class AuthLambdasStack extends cdk.Stack { + readonly authLambdas: AuthLambdas + + constructor(scope: Construct, id: string, props?: cdk.StackProps) { + super(scope, id, props) + + this.authLambdas = new AuthLambdas(this, "AuthLambdas", { + regions: ["eu-west-1"], + }) + } +} diff --git a/example/lib/main-stack.ts b/example/lib/main-stack.ts index 44e84061..e6cfe67a 100644 --- a/example/lib/main-stack.ts +++ b/example/lib/main-stack.ts @@ -1,81 +1,81 @@ -// import { AuthLambdas, CloudFrontAuth } from "@liflig/cdk-cloudfront-auth" -// import * as cdk from "aws-cdk-lib" -// import * as cloudfront from "aws-cdk-lib/aws-cloudfront" -// import * as origins from "aws-cdk-lib/aws-cloudfront-origins" -// import * as cognito from "aws-cdk-lib/aws-cognito" -// import * as s3 from "aws-cdk-lib/aws-s3" -// import * as s3Deployment from "aws-cdk-lib/aws-s3-deployment" -// import * as constructs from "constructs" -// import { CognitoUser } from "./cognito-user" -// -// interface Props extends cdk.StackProps { -// authLambdas: AuthLambdas -// } -// -// export class MainStack extends cdk.Stack { -// constructor(scope: constructs.Construct, id: string, props: Props) { -// super(scope, id, props) -// -// const bucket = new s3.Bucket(this, "Bucket") -// -// const userPool = new cognito.UserPool(this, "UserPool", { -// signInAliases: { -// email: true, -// }, -// passwordPolicy: { -// minLength: 6, -// requireSymbols: false, -// requireUppercase: false, -// }, -// signInCaseSensitive: false, -// }) -// -// const domainPrefix = `${this.account}-${this.stackName}` -// -// userPool.addDomain("UserPoolDomain", { -// cognitoDomain: { -// domainPrefix, -// }, -// }) -// -// const auth = new CloudFrontAuth(this, "Auth", { -// cognitoAuthDomain: `${domainPrefix}.auth.${this.region}.amazoncognito.com`, -// authLambdas: props.authLambdas, -// userPool, -// requireGroupAnyOf: ["test"], -// }) -// -// const origin = new origins.S3Origin(bucket) -// -// const distribution = new cloudfront.Distribution(this, "Distribution", { -// defaultBehavior: auth.createProtectedBehavior(origin), -// additionalBehaviors: auth.createAuthPagesBehaviors(origin), -// defaultRootObject: "index.html", -// }) -// -// auth.updateClient("ClientUpdate", { -// signOutUrl: `https://${distribution.distributionDomainName}${auth.signOutRedirectTo}`, -// callbackUrl: `https://${distribution.distributionDomainName}${auth.callbackPath}`, -// }) -// -// new s3Deployment.BucketDeployment(this, "BucketDeployment", { -// sources: [s3Deployment.Source.asset("./website")], -// destinationBucket: bucket, -// distribution, -// }) -// -// new CognitoUser(this, "User", { -// userPool, -// email: "example@example.com", -// password: "example", -// }) -// -// new cdk.CfnOutput(this, "UrlOutput", { -// value: `https://${distribution.domainName}`, -// }) -// -// new cdk.CfnOutput(this, "BucketNameOutput", { -// value: bucket.bucketName, -// }) -// } -// } +import { AuthLambdas, CloudFrontAuth } from "@liflig/cdk-cloudfront-auth" +import * as cdk from "aws-cdk-lib" +import * as cloudfront from "aws-cdk-lib/aws-cloudfront" +import * as origins from "aws-cdk-lib/aws-cloudfront-origins" +import * as cognito from "aws-cdk-lib/aws-cognito" +import * as s3 from "aws-cdk-lib/aws-s3" +import * as s3Deployment from "aws-cdk-lib/aws-s3-deployment" +import * as constructs from "constructs" +import { CognitoUser } from "./cognito-user" + +interface Props extends cdk.StackProps { + authLambdas: AuthLambdas +} + +export class MainStack extends cdk.Stack { + constructor(scope: constructs.Construct, id: string, props: Props) { + super(scope, id, props) + + const bucket = new s3.Bucket(this, "Bucket") + + const userPool = new cognito.UserPool(this, "UserPool", { + signInAliases: { + email: true, + }, + passwordPolicy: { + minLength: 6, + requireSymbols: false, + requireUppercase: false, + }, + signInCaseSensitive: false, + }) + + const domainPrefix = `${this.account}-${this.stackName}` + + userPool.addDomain("UserPoolDomain", { + cognitoDomain: { + domainPrefix, + }, + }) + + const auth = new CloudFrontAuth(this, "Auth", { + cognitoAuthDomain: `${domainPrefix}.auth.${this.region}.amazoncognito.com`, + authLambdas: props.authLambdas, + userPool, + requireGroupAnyOf: ["test"], + }) + + const origin = new origins.S3Origin(bucket) + + const distribution = new cloudfront.Distribution(this, "Distribution", { + defaultBehavior: auth.createProtectedBehavior(origin), + additionalBehaviors: auth.createAuthPagesBehaviors(origin), + defaultRootObject: "index.html", + }) + + auth.updateClient("ClientUpdate", { + signOutUrl: `https://${distribution.distributionDomainName}${auth.signOutRedirectTo}`, + callbackUrl: `https://${distribution.distributionDomainName}${auth.callbackPath}`, + }) + + new s3Deployment.BucketDeployment(this, "BucketDeployment", { + sources: [s3Deployment.Source.asset("./website")], + destinationBucket: bucket, + distribution, + }) + + new CognitoUser(this, "User", { + userPool, + email: "example@example.com", + password: "example", + }) + + new cdk.CfnOutput(this, "UrlOutput", { + value: `https://${distribution.domainName}`, + }) + + new cdk.CfnOutput(this, "BucketNameOutput", { + value: bucket.bucketName, + }) + } +} diff --git a/example/package-lock.json b/example/package-lock.json index 26d0e93d..eff1959d 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -8,7 +8,7 @@ "name": "example", "version": "0.0.0-development", "dependencies": { - "@henrist/cdk-cloudfront-auth": "^2", + "@liflig/cdk-cloudfront-auth": "1.0.0", "aws-cdk-lib": "^2", "source-map-support": "^0.5" }, @@ -46,18 +46,6 @@ "node": ">=12" } }, - "node_modules/@henrist/cdk-cloudfront-auth": { - "version": "2.1.41", - "resolved": "https://registry.npmjs.org/@henrist/cdk-cloudfront-auth/-/cdk-cloudfront-auth-2.1.41.tgz", - "integrity": "sha512-w7DJco7lZ4TgtprARiinh0Zet1UQbOGvNP5efRz9mYqCGOay539jnFpGLf/GAc2gWcb3+/BrTg1miKJgWh/PyQ==", - "dependencies": { - "@henrist/cdk-cross-region-params": "^2.0.0", - "@henrist/cdk-lambda-config": "^2.1.0" - }, - "peerDependencies": { - "aws-cdk-lib": "^2.0.0" - } - }, "node_modules/@henrist/cdk-cross-region-params": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@henrist/cdk-cross-region-params/-/cdk-cross-region-params-2.0.0.tgz", @@ -66,15 +54,6 @@ "aws-cdk-lib": "^2.0.0" } }, - "node_modules/@henrist/cdk-lambda-config": { - "version": "2.1.42", - "resolved": "https://registry.npmjs.org/@henrist/cdk-lambda-config/-/cdk-lambda-config-2.1.42.tgz", - "integrity": "sha512-1jWXTuJr9ShNnxFuW/FqrXdWbG34Q3tic/G5hk3BCCMJHhK0vUCEZOPAfNJ2tHGBeHJ14qOqOAscatNBVQ9l1Q==", - "peerDependencies": { - "aws-cdk-lib": "^2.0.0", - "constructs": "^10.0.0" - } - }, "node_modules/@jridgewell/resolve-uri": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", @@ -100,6 +79,27 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@liflig/cdk-cloudfront-auth": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@liflig/cdk-cloudfront-auth/-/cdk-cloudfront-auth-1.0.0.tgz", + "integrity": "sha512-jSlyNFJ4gKW6Tw/E6s/EfyvtYGcx9MYlVXl4DdBFSoaMatpKoJcBgRjL/1cfWLK5BVofwJFp2tV3AHAyHypnAw==", + "dependencies": { + "@henrist/cdk-cross-region-params": "^2.0.0", + "@liflig/cdk-lambda-config": "1.1.1" + }, + "peerDependencies": { + "aws-cdk-lib": "^2.0.0" + } + }, + "node_modules/@liflig/cdk-lambda-config": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@liflig/cdk-lambda-config/-/cdk-lambda-config-1.1.1.tgz", + "integrity": "sha512-BOKVjbZddFfkHalzA9wZnEgxZTsnrtOrX0MeFuFJqxO2Tg55a076BtMbAmNgGEsl/0esqmDYKOaX9h+Im+g5Uw==", + "peerDependencies": { + "aws-cdk-lib": "^2.0.0", + "constructs": "^10.0.0" + } + }, "node_modules/@tsconfig/node10": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", @@ -675,27 +675,12 @@ "@jridgewell/trace-mapping": "0.3.9" } }, - "@henrist/cdk-cloudfront-auth": { - "version": "2.1.41", - "resolved": "https://registry.npmjs.org/@henrist/cdk-cloudfront-auth/-/cdk-cloudfront-auth-2.1.41.tgz", - "integrity": "sha512-w7DJco7lZ4TgtprARiinh0Zet1UQbOGvNP5efRz9mYqCGOay539jnFpGLf/GAc2gWcb3+/BrTg1miKJgWh/PyQ==", - "requires": { - "@henrist/cdk-cross-region-params": "^2.0.0", - "@henrist/cdk-lambda-config": "^2.1.0" - } - }, "@henrist/cdk-cross-region-params": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@henrist/cdk-cross-region-params/-/cdk-cross-region-params-2.0.0.tgz", "integrity": "sha512-r/TWZt0ILAGPjUMu7ZOO4JYLuctUOQeM0hG9QKj/OyE1/hJ2dUhdXhMn2ZI95IcCldGuuyRg0uAEf4VZ36GcGQ==", "requires": {} }, - "@henrist/cdk-lambda-config": { - "version": "2.1.42", - "resolved": "https://registry.npmjs.org/@henrist/cdk-lambda-config/-/cdk-lambda-config-2.1.42.tgz", - "integrity": "sha512-1jWXTuJr9ShNnxFuW/FqrXdWbG34Q3tic/G5hk3BCCMJHhK0vUCEZOPAfNJ2tHGBeHJ14qOqOAscatNBVQ9l1Q==", - "requires": {} - }, "@jridgewell/resolve-uri": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", @@ -718,6 +703,21 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "@liflig/cdk-cloudfront-auth": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@liflig/cdk-cloudfront-auth/-/cdk-cloudfront-auth-1.0.0.tgz", + "integrity": "sha512-jSlyNFJ4gKW6Tw/E6s/EfyvtYGcx9MYlVXl4DdBFSoaMatpKoJcBgRjL/1cfWLK5BVofwJFp2tV3AHAyHypnAw==", + "requires": { + "@henrist/cdk-cross-region-params": "^2.0.0", + "@liflig/cdk-lambda-config": "1.1.1" + } + }, + "@liflig/cdk-lambda-config": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@liflig/cdk-lambda-config/-/cdk-lambda-config-1.1.1.tgz", + "integrity": "sha512-BOKVjbZddFfkHalzA9wZnEgxZTsnrtOrX0MeFuFJqxO2Tg55a076BtMbAmNgGEsl/0esqmDYKOaX9h+Im+g5Uw==", + "requires": {} + }, "@tsconfig/node10": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", diff --git a/example/package.json b/example/package.json index 0713f9d1..5ff8f353 100644 --- a/example/package.json +++ b/example/package.json @@ -12,7 +12,7 @@ "typescript": "4.9.5" }, "dependencies": { - "@liflig/cdk-cloudfront-auth": "^2", + "@liflig/cdk-cloudfront-auth": "1.0.0", "aws-cdk-lib": "^2", "source-map-support": "^0.5" }