Skip to content

Commit 2bccd03

Browse files
committed
Refactor SMS sender related extensions
1 parent c9ae6c1 commit 2bccd03

File tree

10 files changed

+205
-239
lines changed

10 files changed

+205
-239
lines changed

features/admin.connections.v1/api/connections.ts

-30
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { IdentityAppsApiException } from "@wso2is/core/exceptions";
2828
import { HttpMethods } from "@wso2is/core/models";
2929
import { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios";
3030
import { ConnectionUIConstants } from "../constants/connection-ui-constants";
31-
import { NotificationSenderSMSInterface } from "../models/authenticators";
3231
import {
3332
ApplicationBasicInterface,
3433
ConnectedAppsInterface,
@@ -1071,35 +1070,6 @@ export const updateImplicitAssociationConfig = (
10711070
});
10721071
};
10731072

1074-
/**
1075-
* Hook to get all sms notification senders with name SMSPublisher.
1076-
*
1077-
* @returns A promise containing the response.
1078-
*/
1079-
export const useSMSNotificationSenders = <Data = NotificationSenderSMSInterface[], Error = RequestErrorInterface>():
1080-
RequestResultInterface<Data, Error> => {
1081-
const { resourceEndpoints } = useResourceEndpoints();
1082-
1083-
const requestConfig: RequestConfigInterface = {
1084-
headers: {
1085-
"Accept": "application/json",
1086-
"Content-Type": "application/json"
1087-
},
1088-
method: HttpMethods.GET,
1089-
url: resourceEndpoints.notificationSendersEndPoint + "/sms"
1090-
};
1091-
1092-
const { data, error, isValidating, mutate } = useRequest<Data, Error>(requestConfig);
1093-
1094-
return {
1095-
data,
1096-
error: error,
1097-
isLoading: !error && !data,
1098-
isValidating,
1099-
mutate: mutate
1100-
};
1101-
};
1102-
11031073
/**
11041074
* Get connection groups list.
11051075
*

features/admin.connections.v1/models/authenticators.ts

-14
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,3 @@ export type CommonAuthenticatorFormPropertyInterface = CommonPluggableComponentP
193193
export interface CommonAuthenticatorFormFieldInterface extends CommonAuthenticatorFormPropertyInterface {
194194
meta: CommonPluggableComponentMetaPropertyInterface;
195195
}
196-
197-
/**
198-
* Interface for SMS Notification Sender Details.
199-
**/
200-
export interface NotificationSenderSMSInterface {
201-
name: string;
202-
provider: string;
203-
providerURL: string;
204-
contentType: string;
205-
properties?: {
206-
key: string;
207-
value: string;
208-
}[];
209-
}

features/admin.extensions.v1/components/identity-providers/api/identity-provider.ts

-160
This file was deleted.

features/admin.extensions.v1/components/identity-providers/api/index.ts

-19
This file was deleted.

features/admin.extensions.v1/components/identity-providers/constants/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@
1717
*/
1818

1919
export * from "./swe-constants";
20-
export * from "./sms-otp-constants";

features/admin.extensions.v1/components/identity-providers/models/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
*/
1818

1919
export * from "./swe";
20-
export * from "./sms-otp";
20+
export * from "@wso2is/admin.sms-providers.v1/models/sms-otp";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* Copyright (c) 2022, WSO2 LLC. (https://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
import { AsgardeoSPAClient, HttpClientInstance } from "@asgardeo/auth-react";
20+
import { store } from "@wso2is/admin.core.v1";
21+
import { RequestConfigInterface } from "@wso2is/admin.core.v1/hooks/use-request";
22+
import { IdentityAppsApiException } from "@wso2is/core/exceptions";
23+
import { HttpMethods } from "@wso2is/core/models";
24+
import { AxiosError, AxiosResponse } from "axios";
25+
import SMSSenderConstants from "../constants/sms-sender-constants";
26+
import { NotificationSenderSMSInterface } from "../models/sms-senders";
27+
28+
const httpClient: HttpClientInstance = AsgardeoSPAClient.getInstance().httpRequest
29+
.bind(AsgardeoSPAClient.getInstance());
30+
31+
/**
32+
* Add sms notification senders with name SMSPublisher.
33+
*
34+
* @returns A promise containing the response.
35+
*/
36+
const addSMSPublisher = (): Promise<NotificationSenderSMSInterface> => {
37+
//SMS Notification sender with name SMSPublisher.
38+
const smsProvider: NotificationSenderSMSInterface = {
39+
contentType: "FORM",
40+
name: "SMSPublisher",
41+
properties: [
42+
{
43+
key: "channel.type",
44+
value: "choreo"
45+
}
46+
],
47+
provider: "choreo",
48+
providerURL: "https://console.choreo.dev/"
49+
};
50+
51+
const requestConfig: RequestConfigInterface = {
52+
data: smsProvider,
53+
headers: {
54+
"Accept": "application/json",
55+
"Access-Control-Allow-Origin": store.getState().config.deployment.clientHost,
56+
"Content-Type": "application/json"
57+
},
58+
method: HttpMethods.POST,
59+
url: store.getState().config.endpoints.notificationSendersEndPoint + "/sms"
60+
};
61+
62+
return httpClient(requestConfig)
63+
.then((response: AxiosResponse<NotificationSenderSMSInterface>) => {
64+
if (response.status !== 201) {
65+
throw new IdentityAppsApiException(
66+
SMSSenderConstants.ERROR_IN_CREATING_SMS_NOTIFICATION_SENDER,
67+
null,
68+
response.status,
69+
response.request,
70+
response,
71+
response.config);
72+
}
73+
74+
return Promise.resolve(response.data as NotificationSenderSMSInterface);
75+
}).catch((error: AxiosError) => {
76+
throw new IdentityAppsApiException(
77+
SMSSenderConstants.ERROR_IN_CREATING_SMS_NOTIFICATION_SENDER,
78+
error.stack,
79+
error.code,
80+
error.request,
81+
error.response,
82+
error.config);
83+
});
84+
};
85+
86+
export default addSMSPublisher;

0 commit comments

Comments
 (0)