Skip to content

Commit 6ea2a92

Browse files
committed
implement projectId usage for requests
1 parent 62c740a commit 6ea2a92

File tree

8 files changed

+25
-49
lines changed

8 files changed

+25
-49
lines changed

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { useInitiate } from "@commt/rn-sdk/hooks";
5151
5252
const ClientConfig = {
5353
apiKey: "123456789?",
54-
subscriptionKey: "0987654321?",
54+
projectId: "0987654321?",
5555
secret: "123456789018A_7JzPo?23F+4y#erPL" // This is just and example you don't have to add secret here for initialization
5656
};
5757

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@commt/rn-sdk",
3-
"version": "0.0.3",
3+
"version": "0.1.0",
44
"description": "Ultimate chat plugin for react native applications",
55
"main": "src/index.tsx",
66
"scripts": {

src/components/Chat/index.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const Chat = ({
4747
rooms,
4848
messages,
4949
app: {
50-
configs: { indicators, tenantId, apiKey, subscriptionKey, projectName },
50+
configs: { indicators, tenantId, apiKey, projectId },
5151
},
5252
},
5353
dispatch,
@@ -94,8 +94,7 @@ const Chat = ({
9494
//handle Log params
9595
{
9696
apiKey,
97-
subscriptionKey,
98-
projectName,
97+
projectId,
9998
chatAuthId: selfUser!.chatAuthId,
10099
},
101100
);
@@ -114,8 +113,7 @@ const Chat = ({
114113
//handle Log params
115114
{
116115
apiKey,
117-
subscriptionKey,
118-
projectName,
116+
projectId,
119117
chatAuthId: selfUser!.chatAuthId,
120118
},
121119
);
@@ -208,8 +206,7 @@ const Chat = ({
208206
//handle Log params
209207
{
210208
apiKey,
211-
subscriptionKey,
212-
projectName,
209+
projectId,
213210
chatAuthId: selfUser!.chatAuthId,
214211
},
215212
);

src/context/reducers/appReducer.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ export type ConfigsProps = {
1414
indicators: IndicatorProps[];
1515
tenantId: string;
1616
apiKey: string;
17-
subscriptionKey: string;
1817
secretKey: string;
19-
projectName: string;
18+
projectId: string;
2019
};
2120

2221
export type AppState = {
@@ -34,9 +33,8 @@ export const AppValues: AppState = {
3433
indicators: [],
3534
tenantId: "",
3635
apiKey: "",
37-
subscriptionKey: "",
3836
secretKey: "",
39-
projectName: "",
37+
projectId: "",
4038
},
4139
};
4240

src/hooks/useSendMessage.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const useSendMessage = () => {
1818
users: { selfUser, users },
1919
rooms,
2020
app: {
21-
configs: { secretKey, apiKey, subscriptionKey, projectName, e2e },
21+
configs: { secretKey, apiKey, projectId, e2e },
2222
},
2323
},
2424
dispatch,
@@ -89,8 +89,7 @@ const useSendMessage = () => {
8989
//handle Log params
9090
{
9191
apiKey,
92-
subscriptionKey,
93-
projectName,
92+
projectId,
9493
chatAuthId: selfUser!.chatAuthId,
9594
chatRoomAuthId,
9695
},

src/hooks/useSetRooms.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const useSetRooms = () => {
1010
state: {
1111
users: { selfUser },
1212
app: {
13-
configs: { apiKey, subscriptionKey, indicators, projectName },
13+
configs: { apiKey, indicators, projectId },
1414
},
1515
},
1616
dispatch,
@@ -21,8 +21,7 @@ const useSetRooms = () => {
2121
const activeRooms = await getRoomsReadToken({
2222
roomIds: rooms.map((room) => room.chatRoomAuthId).join(","),
2323
apiKey,
24-
subscriptionKey,
25-
projectName,
24+
projectId,
2625
chatAuthId: selfUser!.chatAuthId,
2726
});
2827

src/hooks/useSetUsers.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const useSetUsers = () => {
1010
state: {
1111
users: { selfUser },
1212
app: {
13-
configs: { apiKey, subscriptionKey, indicators, projectName },
13+
configs: { apiKey, indicators, projectId },
1414
},
1515
},
1616
dispatch,
@@ -26,8 +26,7 @@ const useSetUsers = () => {
2626
const activeUsers = await getUsersOnlineInfo({
2727
userIds,
2828
apiKey,
29-
subscriptionKey,
30-
projectName,
29+
projectId,
3130
chatAuthId: selfUser!.chatAuthId,
3231
});
3332

src/service/index.ts

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import * as events from "../utils/events";
77

88
export interface InitiateProps {
99
apiKey: string;
10-
subscriptionKey: string;
11-
projectName: string;
10+
projectId: string;
1211
}
1312

1413
interface OnlineInfoProps extends InitiateProps {
@@ -46,19 +45,17 @@ const project = {
4645
};
4746

4847
export const initiate = async (props: InitiateProps) => {
49-
const { apiKey, subscriptionKey, projectName } = props;
48+
const { apiKey, projectId } = props;
5049

5150
try {
52-
const response = await axios.get<ConfigsProps>(`/api/v1/tenant/config/`, {
51+
const response = await axios.get<ConfigsProps>(`/api/v1/project/config/`, {
5352
params: {
54-
plugin: true, // This is for backend compatibility
5553
SDK: project.SDK, // This is for backend compatibility & analytics
5654
version: project.version, // This is for backend compatibility & analytics
57-
name: projectName, // This is for backend compatibility & analytics
55+
projectId, // This is for backend compatibility & analytics
5856
},
5957
headers: {
6058
apiKey,
61-
subscriptionKey,
6259
},
6360
});
6461

@@ -71,8 +68,7 @@ export const initiate = async (props: InitiateProps) => {
7168
// Log error to service
7269
handleLogger({
7370
apiKey,
74-
subscriptionKey,
75-
projectName,
71+
projectId,
7672
error: {
7773
error,
7874
event: events.INITIATE_TENANT_CONFIGS,
@@ -82,7 +78,7 @@ export const initiate = async (props: InitiateProps) => {
8278
};
8379

8480
export const getUsersOnlineInfo = async (props: OnlineInfoProps) => {
85-
const { userIds, apiKey, subscriptionKey, projectName, chatAuthId } = props;
81+
const { userIds, apiKey, projectId, chatAuthId } = props;
8682

8783
try {
8884
const response = await axios.get<OnlineInfoReturnProps[]>(
@@ -93,7 +89,6 @@ export const getUsersOnlineInfo = async (props: OnlineInfoProps) => {
9389
},
9490
headers: {
9591
apiKey,
96-
subscriptionKey,
9792
},
9893
},
9994
);
@@ -103,8 +98,7 @@ export const getUsersOnlineInfo = async (props: OnlineInfoProps) => {
10398
// Log error to service
10499
handleLogger({
105100
apiKey,
106-
subscriptionKey,
107-
projectName,
101+
projectId,
108102
error: {
109103
error,
110104
event: events.GET_USERS_ONLINE_INFO,
@@ -115,7 +109,7 @@ export const getUsersOnlineInfo = async (props: OnlineInfoProps) => {
115109
};
116110

117111
export const getRoomsReadToken = async (props: ReadTokenProps) => {
118-
const { roomIds, apiKey, subscriptionKey, projectName, chatAuthId } = props;
112+
const { roomIds, apiKey, projectId, chatAuthId } = props;
119113

120114
try {
121115
const response = await axios.get<ReadTokenReturnProps[]>(
@@ -126,7 +120,6 @@ export const getRoomsReadToken = async (props: ReadTokenProps) => {
126120
},
127121
headers: {
128122
apiKey,
129-
subscriptionKey,
130123
},
131124
},
132125
);
@@ -135,8 +128,7 @@ export const getRoomsReadToken = async (props: ReadTokenProps) => {
135128
// TODO: Log error
136129
handleLogger({
137130
apiKey,
138-
subscriptionKey,
139-
projectName,
131+
projectId,
140132
error: {
141133
error,
142134
event: events.GET_ROOMS_READ_TOKEN,
@@ -147,17 +139,10 @@ export const getRoomsReadToken = async (props: ReadTokenProps) => {
147139
};
148140

149141
export const handleLogger = async (props: HandleLoggerProps) => {
150-
const {
151-
apiKey,
152-
subscriptionKey,
153-
projectName,
154-
error,
155-
chatAuthId,
156-
chatRoomAuthId,
157-
} = props;
142+
const { apiKey, projectId, error, chatAuthId, chatRoomAuthId } = props;
158143

159144
const logObject = {
160-
projectName,
145+
projectId,
161146
SDK: project.SDK,
162147
version: project.version,
163148
error,
@@ -169,7 +154,6 @@ export const handleLogger = async (props: HandleLoggerProps) => {
169154
axios.post("/system/logger", logObject, {
170155
headers: {
171156
apiKey,
172-
subscriptionKey,
173157
},
174158
});
175159
} catch (error_) {

0 commit comments

Comments
 (0)