@azure-tools/communication-domain-verification
Version:
SDK for Azure Communication Domain Verification
561 lines (543 loc) • 18 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var communicationCommon = require('@azure/communication-common');
var coreAuth = require('@azure/core-auth');
var logger$1 = require('@azure/logger');
var coreClient = require('@azure/core-client');
var coreTracing = require('@azure/core-tracing');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var coreClient__namespace = /*#__PURE__*/_interopNamespace(coreClient);
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
function ConvertToDomainOwnership(verifyDomainOwnershipResponse) {
const result = {
status: verifyDomainOwnershipResponse.status,
};
return result;
}
// Copyright (c) Microsoft Corporation.
/**
* The \@azure\/logger configuration for this package.
*/
const logger = logger$1.createClientLogger("communication-domain-verification");
// Copyright (c) Microsoft Corporation.
const tracingClient = coreTracing.createTracingClient({
namespace: "Microsoft.Communication",
packageName: "@azure/communication-phone-numbers",
packageVersion: "1.0.0-beta.1",
});
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
/** Known values of {@link ChallengeType} that the service accepts. */
var KnownChallengeType;
(function (KnownChallengeType) {
/** Indicates DNS record type TXT */
KnownChallengeType["TXT"] = "TXT";
})(KnownChallengeType || (KnownChallengeType = {}));
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
const CreateDomainOwnershipVerificationChallengeRequest = {
type: {
name: "Composite",
className: "CreateDomainOwnershipVerificationChallengeRequest",
modelProperties: {
domain: {
serializedName: "domain",
required: true,
type: {
name: "String"
}
}
}
}
};
const DomainOwnershipChallenge = {
type: {
name: "Composite",
className: "DomainOwnershipChallenge",
modelProperties: {
value: {
serializedName: "value",
required: true,
type: {
name: "String"
}
}
}
}
};
const CommunicationErrorResponse = {
type: {
name: "Composite",
className: "CommunicationErrorResponse",
modelProperties: {
error: {
serializedName: "error",
type: {
name: "Composite",
className: "CommunicationError"
}
}
}
}
};
const CommunicationError = {
type: {
name: "Composite",
className: "CommunicationError",
modelProperties: {
code: {
serializedName: "code",
required: true,
type: {
name: "String"
}
},
message: {
serializedName: "message",
required: true,
type: {
name: "String"
}
},
target: {
serializedName: "target",
readOnly: true,
type: {
name: "String"
}
},
details: {
serializedName: "details",
readOnly: true,
type: {
name: "Sequence",
element: {
type: {
name: "Composite",
className: "CommunicationError"
}
}
}
},
innerError: {
serializedName: "innererror",
type: {
name: "Composite",
className: "CommunicationError"
}
}
}
}
};
const DomainOwnershipVerificationRequest = {
type: {
name: "Composite",
className: "DomainOwnershipVerificationRequest",
modelProperties: {
domain: {
serializedName: "domain",
required: true,
type: {
name: "String"
}
},
challengeType: {
serializedName: "challengeType",
required: true,
type: {
name: "String"
}
}
}
}
};
const DomainOwnership = {
type: {
name: "Composite",
className: "DomainOwnership",
modelProperties: {
status: {
serializedName: "status",
required: true,
type: {
name: "String"
}
}
}
}
};
const CreateDomainOwnershipChallengePostHeaders = {
type: {
name: "Composite",
className: "CreateDomainOwnershipChallengePostHeaders",
modelProperties: {
xMsRequestId: {
serializedName: "x-ms-request-id",
type: {
name: "String"
}
}
}
}
};
const CreateDomainOwnershipChallengePostExceptionHeaders = {
type: {
name: "Composite",
className: "CreateDomainOwnershipChallengePostExceptionHeaders",
modelProperties: {
xMsErrorCode: {
serializedName: "x-ms-error-code",
type: {
name: "String"
}
}
}
}
};
const VerifyDomainOwnershipPostHeaders = {
type: {
name: "Composite",
className: "VerifyDomainOwnershipPostHeaders",
modelProperties: {
xMsRequestId: {
serializedName: "x-ms-request-id",
type: {
name: "String"
}
}
}
}
};
const VerifyDomainOwnershipPostExceptionHeaders = {
type: {
name: "Composite",
className: "VerifyDomainOwnershipPostExceptionHeaders",
modelProperties: {
xMsErrorCode: {
serializedName: "x-ms-error-code",
type: {
name: "String"
}
}
}
}
};
var Mappers = /*#__PURE__*/Object.freeze({
__proto__: null,
CreateDomainOwnershipVerificationChallengeRequest: CreateDomainOwnershipVerificationChallengeRequest,
DomainOwnershipChallenge: DomainOwnershipChallenge,
CommunicationErrorResponse: CommunicationErrorResponse,
CommunicationError: CommunicationError,
DomainOwnershipVerificationRequest: DomainOwnershipVerificationRequest,
DomainOwnership: DomainOwnership,
CreateDomainOwnershipChallengePostHeaders: CreateDomainOwnershipChallengePostHeaders,
CreateDomainOwnershipChallengePostExceptionHeaders: CreateDomainOwnershipChallengePostExceptionHeaders,
VerifyDomainOwnershipPostHeaders: VerifyDomainOwnershipPostHeaders,
VerifyDomainOwnershipPostExceptionHeaders: VerifyDomainOwnershipPostExceptionHeaders
});
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
const contentType = {
parameterPath: ["options", "contentType"],
mapper: {
defaultValue: "application/json",
isConstant: true,
serializedName: "Content-Type",
type: {
name: "String"
}
}
};
const accept = {
parameterPath: "accept",
mapper: {
defaultValue: "application/json",
isConstant: true,
serializedName: "Accept",
type: {
name: "String"
}
}
};
const $host = {
parameterPath: "$host",
mapper: {
serializedName: "$host",
required: true,
type: {
name: "String"
}
},
skipEncoding: true
};
const apiVersion = {
parameterPath: "apiVersion",
mapper: {
defaultValue: "2022-09-01-preview",
isConstant: true,
serializedName: "api-version",
type: {
name: "String"
}
}
};
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
/** Class containing CreateDomainOwnershipChallenge operations. */
class CreateDomainOwnershipChallengeImpl {
/**
* Initialize a new instance of the class CreateDomainOwnershipChallenge class.
* @param client Reference to the service client
*/
constructor(client) {
this.client = client;
}
/**
* Creates domain ownership verification challenge
* @param domain Verified Domain
* @param options The options parameters.
*/
post(domain, options) {
return this.client.sendOperationRequest({ domain, options }, postOperationSpec$1);
}
}
// Operation Specifications
const serializer$1 = coreClient__namespace.createSerializer(Mappers, /* isXml */ false);
const postOperationSpec$1 = {
path: "/sip:createDomainOwnershipChallenge",
httpMethod: "POST",
responses: {
200: {
bodyMapper: DomainOwnershipChallenge,
headersMapper: CreateDomainOwnershipChallengePostHeaders
},
default: {
bodyMapper: CommunicationErrorResponse,
headersMapper: CreateDomainOwnershipChallengePostExceptionHeaders
}
},
requestBody: {
parameterPath: { domain: ["domain"] },
mapper: Object.assign(Object.assign({}, CreateDomainOwnershipVerificationChallengeRequest), { required: true })
},
queryParameters: [apiVersion],
urlParameters: [$host],
headerParameters: [contentType, accept],
mediaType: "json",
serializer: serializer$1
};
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
/** Class containing VerifyDomainOwnership operations. */
class VerifyDomainOwnershipImpl {
/**
* Initialize a new instance of the class VerifyDomainOwnership class.
* @param client Reference to the service client
*/
constructor(client) {
this.client = client;
}
/**
* Verify domain by testing the challenge for given domain
* @param domain Verified Domain
* @param challengeType Type of domain verification challenge
* @param options The options parameters.
*/
post(domain, challengeType, options) {
return this.client.sendOperationRequest({ domain, challengeType, options }, postOperationSpec);
}
}
// Operation Specifications
const serializer = coreClient__namespace.createSerializer(Mappers, /* isXml */ false);
const postOperationSpec = {
path: "/sip:verifyDomainOwnership",
httpMethod: "POST",
responses: {
200: {
bodyMapper: DomainOwnership,
headersMapper: VerifyDomainOwnershipPostHeaders
},
default: {
bodyMapper: CommunicationErrorResponse,
headersMapper: VerifyDomainOwnershipPostExceptionHeaders
}
},
requestBody: {
parameterPath: { domain: ["domain"], challengeType: ["challengeType"] },
mapper: Object.assign(Object.assign({}, DomainOwnershipVerificationRequest), { required: true })
},
queryParameters: [apiVersion],
urlParameters: [$host],
headerParameters: [contentType, accept],
mediaType: "json",
serializer
};
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
class DomainVerificationClientContext extends coreClient__namespace.ServiceClient {
/**
* Initializes a new instance of the DomainVerificationClientContext class.
* @param $host server parameter
* @param options The parameter options
*/
constructor($host, options) {
if ($host === undefined) {
throw new Error("'$host' cannot be null");
}
// Initializing default values for options
if (!options) {
options = {};
}
const defaults = {
requestContentType: "application/json; charset=utf-8"
};
const packageDetails = `azsdk-js-communication-domain-verification/1.0.0-alpha.20230310.1`;
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
: `${packageDetails}`;
const optionsWithDefaults = Object.assign(Object.assign(Object.assign({}, defaults), options), { userAgentOptions: {
userAgentPrefix
}, baseUri: options.endpoint || "{$host}" });
super(optionsWithDefaults);
// Parameter assignments
this.$host = $host;
// Assigning values to Constant parameters
this.apiVersion = options.apiVersion || "2022-09-01-preview";
}
}
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
class DomainVerificationClient$1 extends DomainVerificationClientContext {
/**
* Initializes a new instance of the DomainVerificationClient class.
* @param $host server parameter
* @param options The parameter options
*/
constructor($host, options) {
super($host, options);
this.createDomainOwnershipChallenge = new CreateDomainOwnershipChallengeImpl(this);
this.verifyDomainOwnership = new VerifyDomainOwnershipImpl(this);
}
}
// Copyright (c) Microsoft Corporation.
/**
* Checks whether the type of a value is DomainVerificationClientOptions or not.
*
* @param options - The value being checked.
* @returns
*/
const isDomainVerificationClientOptions = (options) => options && !communicationCommon.isKeyCredential(options) && !coreAuth.isTokenCredential(options);
/**
* A DomainVerificationClient represents a Client to the Azure Communication Domain Verification service allowing you
* to verify domain.
*/
class DomainVerificationClient {
constructor(connectionStringOrUrl, credentialOrOptions, maybeOptions = {}) {
const { url, credential } = communicationCommon.parseClientArguments(connectionStringOrUrl, credentialOrOptions);
const options = isDomainVerificationClientOptions(credentialOrOptions)
? credentialOrOptions
: maybeOptions;
const internalPipelineOptions = Object.assign(Object.assign({}, options), {
loggingOptions: {
logger: logger.info,
},
});
this.client = new DomainVerificationClient$1(url, internalPipelineOptions);
const authPolicy = communicationCommon.createCommunicationAuthPolicy(credential);
this.client.pipeline.addPolicy(authPolicy);
}
/**
* Create Domain ownership challenge
* @param domain - Domain uri (ex: contoso.com)
* @param options - Additional request options
* @returns - Returns challenge value of DNS record as string (ex: MS12345)
*/
async createDomainOwnershipChallenge(domain, options = {}) {
return tracingClient.withSpan("DomainVerificationClient-createDomainOwnershipChallenge", options, async (updatedOptions) => {
try {
return await this.client.createDomainOwnershipChallenge.post(domain, updatedOptions);
}
catch (e) {
throw {
code: e.code,
message: e.message,
};
}
});
}
/**
* Verify domain ownership
* @param domain - Domain uri (ex: contoso.com)
* @param challengeType - Type of DNS record, now only TXT is supported
* @param options - Additional request options
* @returns - Returns Status of verification (ex: Verified | NotVerified | VerificationPending)
*/
async verifyDomainOwnership(domain, options = {}) {
return tracingClient.withSpan("DomainVerificationClient-verifyDomainOwnership", options, async (updatedOptions) => {
try {
const result = await this.client.verifyDomainOwnership.post(domain, KnownChallengeType.TXT, updatedOptions);
return ConvertToDomainOwnership(result);
}
catch (e) {
throw {
code: e.code,
message: e.message,
};
}
});
}
}
exports.DomainVerificationClient = DomainVerificationClient;
//# sourceMappingURL=index.js.map