ask-smapi-sdk
Version:
Core package for SMAPI Skills Kit SDK
81 lines • 3.53 kB
JavaScript
"use strict";
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomSmapiClientBuilder = exports.StandardSmapiClientBuilder = void 0;
const ask_smapi_model_1 = require("ask-smapi-model");
var DefaultApiClient = ask_smapi_model_1.runtime.DefaultApiClient;
const AbstractSmapiClientBuilder_1 = require("./AbstractSmapiClientBuilder");
const DEFAULT_API_ENDPOINT = 'https://api.amazonalexa.com';
/**
* StandardSmapiClientBuilder class use default ApiClient and default ApiEndpoint
*/
class StandardSmapiClientBuilder extends AbstractSmapiClientBuilder_1.SmapiClientBuilder {
/**
* Funtion used to generate SkillManagementService instance.
*/
client() {
if (this.refreshTokenConfig || this.accessTokenConfig) {
const apiConfiguration = {
apiClient: new DefaultApiClient(),
apiEndpoint: DEFAULT_API_ENDPOINT,
authorizationValue: null,
};
const authenticationConfiguration = this.getAuthenticationConfiguration();
return new ask_smapi_model_1.services.skillManagement.SkillManagementServiceClient(apiConfiguration, authenticationConfiguration, this.customUserAgent);
}
throw new Error('Please provide accessToken or refreshToken Config to build smapi client');
}
}
exports.StandardSmapiClientBuilder = StandardSmapiClientBuilder;
/**
* CustomSmapiClientBuilder give user ability to configure ApiClient and ApiEndpoint
*/
class CustomSmapiClientBuilder extends StandardSmapiClientBuilder {
withApiEndpoint(apiEndpoint) {
this.apiEndpoint = apiEndpoint;
return this;
}
withAuthEndpoint(authEndpoint) {
this.authEndpoint = authEndpoint;
return this;
}
withApiClient(apiClient) {
this.apiClient = apiClient;
return this;
}
/**
* Function used to generate SkillManagementService instance.
*/
client() {
if (!this.apiEndpoint) {
this.apiEndpoint = DEFAULT_API_ENDPOINT;
}
if (!this.apiClient) {
this.apiClient = new DefaultApiClient();
}
if (this.refreshTokenConfig || this.accessTokenConfig) {
const apiConfiguration = {
apiClient: this.apiClient,
apiEndpoint: this.apiEndpoint,
authorizationValue: null,
};
const authenticationConfiguration = this.getAuthenticationConfiguration();
authenticationConfiguration.authEndpoint = this.authEndpoint;
return new ask_smapi_model_1.services.skillManagement.SkillManagementServiceClient(apiConfiguration, authenticationConfiguration, this.customUserAgent);
}
throw new Error('Please provide accessToken or refreshToken Config to build smapi client');
}
}
exports.CustomSmapiClientBuilder = CustomSmapiClientBuilder;
//# sourceMappingURL=SmapiClientBuilder.js.map