"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.UserPoolDomain=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),core_1=require("../../core"),custom_resources_1=require("../../custom-resources"),cognito_generated_1=require("./cognito.generated");class UserPoolDomain extends core_1.Resource{constructor(scope,id,props){var _b,_c,_d,_e;super(scope,id);if(jsiiDeprecationWarnings.aws_cdk_lib_aws_cognito_UserPoolDomainProps(props),!!props.customDomain==!!props.cognitoDomain)throw new Error("One of, and only one of, cognitoDomain or customDomain must be specified");if(((_b=props.cognitoDomain)===null||_b===void 0?void 0:_b.domainPrefix)&&!core_1.Token.isUnresolved((_c=props.cognitoDomain)===null||_c===void 0?void 0:_c.domainPrefix)&&!/^[a-z0-9-]+$/.test(props.cognitoDomain.domainPrefix))throw new Error("domainPrefix for cognitoDomain can contain only lowercase alphabets, numbers and hyphens");this.isCognitoDomain=!!props.cognitoDomain;const domainName=((_d=props.cognitoDomain)===null||_d===void 0?void 0:_d.domainPrefix)||((_e=props.customDomain)===null||_e===void 0?void 0:_e.domainName),resource=new cognito_generated_1.CfnUserPoolDomain(this,"Resource",{userPoolId:props.userPool.userPoolId,domain:domainName,customDomainConfig:props.customDomain?{certificateArn:props.customDomain.certificate.certificateArn}:void 0});this.domainName=resource.ref}static fromDomainName(scope,id,userPoolDomainName){class Import extends core_1.Resource{constructor(){super(...arguments);this.domainName=userPoolDomainName}}return new Import(scope,id)}get cloudFrontDomainName(){if(!this.cloudFrontCustomResource){const sdkCall={service:"CognitoIdentityServiceProvider",action:"describeUserPoolDomain",parameters:{Domain:this.domainName},physicalResourceId:custom_resources_1.PhysicalResourceId.of(this.domainName)};this.cloudFrontCustomResource=new custom_resources_1.AwsCustomResource(this,"CloudFrontDomainName",{resourceType:"Custom::UserPoolCloudFrontDomainName",onCreate:sdkCall,onUpdate:sdkCall,policy:custom_resources_1.AwsCustomResourcePolicy.fromSdkCalls({resources:["*"]})})}return this.cloudFrontCustomResource.getResponseField("DomainDescription.CloudFrontDistribution")}baseUrl(){return this.isCognitoDomain?`https://${this.domainName}.auth.${core_1.Stack.of(this).region}.amazoncognito.com`:`https://${this.domainName}`}signInUrl(client,options){var _b;jsiiDeprecationWarnings.aws_cdk_lib_aws_cognito_UserPoolClient(client),jsiiDeprecationWarnings.aws_cdk_lib_aws_cognito_SignInUrlOptions(options);let responseType;if(client.oAuthFlows.authorizationCodeGrant)responseType="code";else if(client.oAuthFlows.implicitCodeGrant)responseType="token";else throw new Error("signInUrl is not supported for clients without authorizationCodeGrant or implicitCodeGrant flow enabled");const path=(_b=options.signInPath)!==null&&_b!==void 0?_b:"/login";return`${this.baseUrl()}${path}?client_id=${client.userPoolClientId}&response_type=${responseType}&redirect_uri=${options.redirectUri}`}}exports.UserPoolDomain=UserPoolDomain,_a=JSII_RTTI_SYMBOL_1,UserPoolDomain[_a]={fqn:"aws-cdk-lib.aws_cognito.UserPoolDomain",version:"2.13.0"};
//# sourceMappingURL=user-pool-domain.js.map
