Skip to content

Commit

Permalink
Refactor SMS sender related extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
brionmario committed Sep 10, 2024
1 parent c9ae6c1 commit 2bccd03
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 239 deletions.
30 changes: 0 additions & 30 deletions features/admin.connections.v1/api/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { IdentityAppsApiException } from "@wso2is/core/exceptions";
import { HttpMethods } from "@wso2is/core/models";
import { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios";
import { ConnectionUIConstants } from "../constants/connection-ui-constants";
import { NotificationSenderSMSInterface } from "../models/authenticators";
import {
ApplicationBasicInterface,
ConnectedAppsInterface,
Expand Down Expand Up @@ -1071,35 +1070,6 @@ export const updateImplicitAssociationConfig = (
});
};

/**
* Hook to get all sms notification senders with name SMSPublisher.
*
* @returns A promise containing the response.
*/
export const useSMSNotificationSenders = <Data = NotificationSenderSMSInterface[], Error = RequestErrorInterface>():
RequestResultInterface<Data, Error> => {
const { resourceEndpoints } = useResourceEndpoints();

const requestConfig: RequestConfigInterface = {
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
method: HttpMethods.GET,
url: resourceEndpoints.notificationSendersEndPoint + "/sms"
};

const { data, error, isValidating, mutate } = useRequest<Data, Error>(requestConfig);

return {
data,
error: error,
isLoading: !error && !data,
isValidating,
mutate: mutate
};
};

/**
* Get connection groups list.
*
Expand Down
14 changes: 0 additions & 14 deletions features/admin.connections.v1/models/authenticators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,3 @@ export type CommonAuthenticatorFormPropertyInterface = CommonPluggableComponentP
export interface CommonAuthenticatorFormFieldInterface extends CommonAuthenticatorFormPropertyInterface {
meta: CommonPluggableComponentMetaPropertyInterface;
}

/**
* Interface for SMS Notification Sender Details.
**/
export interface NotificationSenderSMSInterface {
name: string;
provider: string;
providerURL: string;
contentType: string;
properties?: {
key: string;
value: string;
}[];
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@
*/

export * from "./swe-constants";

Check warning on line 19 in features/admin.extensions.v1/components/identity-providers/constants/index.ts

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

incorrect header
export * from "./sms-otp-constants";
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
*/

export * from "./swe";

Check warning on line 19 in features/admin.extensions.v1/components/identity-providers/models/index.ts

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

incorrect header
export * from "./sms-otp";
export * from "@wso2is/admin.sms-providers.v1/models/sms-otp";
86 changes: 86 additions & 0 deletions features/admin.sms-providers.v1/api/add-sms-publisher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Copyright (c) 2022, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License 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.
*/

import { AsgardeoSPAClient, HttpClientInstance } from "@asgardeo/auth-react";
import { store } from "@wso2is/admin.core.v1";
import { RequestConfigInterface } from "@wso2is/admin.core.v1/hooks/use-request";
import { IdentityAppsApiException } from "@wso2is/core/exceptions";
import { HttpMethods } from "@wso2is/core/models";
import { AxiosError, AxiosResponse } from "axios";
import SMSSenderConstants from "../constants/sms-sender-constants";
import { NotificationSenderSMSInterface } from "../models/sms-senders";

const httpClient: HttpClientInstance = AsgardeoSPAClient.getInstance().httpRequest
.bind(AsgardeoSPAClient.getInstance());

/**
* Add sms notification senders with name SMSPublisher.
*
* @returns A promise containing the response.
*/
const addSMSPublisher = (): Promise<NotificationSenderSMSInterface> => {
//SMS Notification sender with name SMSPublisher.
const smsProvider: NotificationSenderSMSInterface = {
contentType: "FORM",
name: "SMSPublisher",
properties: [
{
key: "channel.type",
value: "choreo"
}
],
provider: "choreo",
providerURL: "https://console.choreo.dev/"
};

const requestConfig: RequestConfigInterface = {
data: smsProvider,
headers: {
"Accept": "application/json",
"Access-Control-Allow-Origin": store.getState().config.deployment.clientHost,
"Content-Type": "application/json"
},
method: HttpMethods.POST,
url: store.getState().config.endpoints.notificationSendersEndPoint + "/sms"
};

return httpClient(requestConfig)
.then((response: AxiosResponse<NotificationSenderSMSInterface>) => {
if (response.status !== 201) {
throw new IdentityAppsApiException(
SMSSenderConstants.ERROR_IN_CREATING_SMS_NOTIFICATION_SENDER,
null,
response.status,
response.request,
response,
response.config);
}

return Promise.resolve(response.data as NotificationSenderSMSInterface);
}).catch((error: AxiosError) => {
throw new IdentityAppsApiException(
SMSSenderConstants.ERROR_IN_CREATING_SMS_NOTIFICATION_SENDER,
error.stack,
error.code,
error.request,
error.response,
error.config);
});
};

export default addSMSPublisher;
Loading

0 comments on commit 2bccd03

Please sign in to comment.