Skip to content

Commit fc8609d

Browse files
committed
Merge branch 'main' of github.com:bakaphp/kanvas-core-js into messages-types
2 parents 77b1a9c + ab021b1 commit fc8609d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2176
-219
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
3-
"version": "0.0.63",
2+
"version": "0.0.73",
43
"license": "MIT",
54
"main": "dist/index.js",
65
"typings": "dist/index.d.ts",
@@ -56,7 +55,9 @@
5655
},
5756
"dependencies": {
5857
"@apollo/client": "^3.7.10",
58+
"axios": "^1.6.2",
59+
"form-data": "^4.0.0",
5960
"graphql": "^16.6.0",
6061
"typescript-transform-paths": "^3.4.6"
6162
}
62-
}
63+
}

src/index.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import {
66
RequestHandler,
77
NormalizedCacheObject,
88
} from '@apollo/client/core';
9+
910
import {
1011
App,
1112
Auth,
1213
Users,
1314
CustomFields,
1415
Locations,
16+
Companies,
17+
CompaniesBranches,
1518
Leads,
1619
Inventory,
1720
Agents,
@@ -22,6 +25,11 @@ import {
2225
Messages,
2326
Roles,
2427
MessagesTypes,
28+
FileSystem,
29+
Topics,
30+
SystemModules,
31+
Follow,
32+
People,
2533
} from './modules';
2634

2735
import { setContext } from '@apollo/client/link/context';
@@ -40,6 +48,7 @@ interface Options {
4048
key: string;
4149
middlewares?: Middleware[];
4250
adminKey?: string;
51+
authAxiosMiddleware?: any;
4352
}
4453

4554
export function genericAuthMiddleware(
@@ -71,7 +80,14 @@ export function locationMiddleware(
7180
return { headers };
7281
});
7382
}
74-
83+
export async function authAxiosMiddleware(
84+
fn: () => Promise<string | null | undefined>
85+
) {
86+
const key = await fn();
87+
return {
88+
Authorization: key ? `Bearer ${key}` : '',
89+
};
90+
}
7591
export default class KanvasCore {
7692
public client: ClientType;
7793
public auth: Auth;
@@ -90,6 +106,15 @@ export default class KanvasCore {
90106
public messages: Messages;
91107
public roles: Roles;
92108
public messagesTypes: MessagesTypes;
109+
public filesystem: FileSystem;
110+
public topics: Topics;
111+
public systemModules: SystemModules;
112+
113+
public companies: Companies;
114+
public companiesBranches: CompaniesBranches;
115+
public follow: Follow;
116+
public people: People;
117+
93118
constructor(protected options: Options) {
94119
this.client = new ApolloClient({
95120
link: this.generateLink(),
@@ -113,8 +138,14 @@ export default class KanvasCore {
113138
this.messages = new Messages(this.client);
114139
this.roles = new Roles(this.client);
115140
this.messagesTypes = new MessagesTypes(this.client);
141+
this.filesystem = new FileSystem(this.client, this.options);
142+
this.topics = new Topics(this.client);
143+
this.systemModules = new SystemModules(this.client);
144+
this.companies = new Companies(this.client);
145+
this.companiesBranches = new CompaniesBranches(this.client);
146+
this.follow = new Follow(this.client);
147+
this.people = new People(this.client);
116148
}
117-
118149
protected generateURL() {
119150
return new HttpLink({ uri: this.options.url });
120151
}

src/modules/app/index.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { AppUserInterface, AppUpdatePasswordInterface, WhereCondition, AllAppUsersInterface, OrderBy, AppCreateUserParams, CreatedAppCreateUser, AppActivateUser, AppDeactiveUser, } from '../../types';
2-
import { APP_ACTIVE_USER, APP_CREATE_USER, APP_DEACTIVE_USER, USER_UPDATE_PASSWORD_MUTATION } from '../../mutations';
3-
import { GET_APP_USERS } from '../../queries';
1+
import type { AppUserInterface, AppUpdatePasswordInterface, WhereCondition, AllAppUsersInterface, OrderBy, AppCreateUserParams, CreatedAppCreateUser, AppActivateUser, AppDeactiveUser, AppWithAccessResponse, CreateAppInput, CreateAppResponse, } from '../../types';
2+
import { APP_ACTIVE_USER, APP_CREATE_USER, APP_DEACTIVE_USER, CREATE_APP, USER_UPDATE_PASSWORD_MUTATION } from '../../mutations';
3+
import { GET_APPS_WITH_ACCESS, GET_APP_USERS } from '../../queries';
44
import type { ClientType } from '../../index';
55

66
class Users {
@@ -38,12 +38,13 @@ class Users {
3838
const response = await this.client.query({
3939
query: GET_APP_USERS,
4040
variables: {
41-
first: 1,
42-
where: {
41+
whereCondition: {
4342
column: 'EMAIL',
4443
operator: 'EQ',
4544
value: email,
4645
},
46+
fetchPolicy: 'network-only',
47+
partialRefetch: true,
4748
},
4849
});
4950

@@ -113,4 +114,24 @@ export class App {
113114
this.users = new Users(this.client);
114115

115116
}
117+
118+
public async createApp(input: CreateAppInput): Promise<CreateAppResponse> {
119+
const response = await this.client.mutate({
120+
mutation: CREATE_APP,
121+
variables: {
122+
input
123+
},
124+
fetchPolicy: 'network-only',
125+
})
126+
return response.data
127+
}
128+
129+
public async getAppsWithAccess(): Promise<AppWithAccessResponse> {
130+
const response = await this.client.query({
131+
query: GET_APPS_WITH_ACCESS,
132+
fetchPolicy: 'network-only',
133+
partialRefetch: true,
134+
})
135+
return response.data
136+
}
116137
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { ClientType } from 'index';
2+
3+
import {
4+
CREATE_COMPANY_BRANCH,
5+
UPDATE_COMPANY_BRANCH,
6+
DELETE_COMPANY_BRANCH,
7+
ADD_USER_TO_BRANCH,
8+
REMOVE_USER_FROM_BRANCH,
9+
} from '../../mutations';
10+
import {
11+
UserInterface,
12+
CompanyBranchInput,
13+
CompanyBranchInterface,
14+
QueryBranchesOrderByOrderByClause,
15+
WhereCondition
16+
} from '../../types';
17+
import {
18+
COMPANIES_BRANCHES_QUERY,
19+
COMPANIES_BRANCHES_USER_QUERY,
20+
} from '../../queries';
21+
22+
export class CompaniesBranches {
23+
constructor(protected client: ClientType) {}
24+
25+
public async getCompanyBranches(
26+
where: WhereCondition,
27+
orderBy: QueryBranchesOrderByOrderByClause,
28+
first?: number,
29+
page?: number
30+
): Promise<CompanyBranchInterface> {
31+
const response = await this.client.query({
32+
query: COMPANIES_BRANCHES_QUERY,
33+
variables: { where, orderBy, first, page },
34+
});
35+
return response.data as CompanyBranchInterface;
36+
}
37+
38+
public async getCompanyBranchUsers(
39+
where: WhereCondition,
40+
first?: number,
41+
page?: number
42+
): Promise<UserInterface> {
43+
const response = await this.client.query({
44+
query: COMPANIES_BRANCHES_USER_QUERY,
45+
variables: { where, first, page },
46+
});
47+
return response.data as UserInterface;
48+
}
49+
50+
public async createCompanyBranch(
51+
input: CompanyBranchInput
52+
): Promise<CompanyBranchInterface> {
53+
const response = await this.client.mutate({
54+
mutation: CREATE_COMPANY_BRANCH,
55+
variables: { input },
56+
});
57+
return response.data.createCompanyBranch as CompanyBranchInterface;
58+
}
59+
60+
public async updateCompanyBranch(
61+
id: string,
62+
input: CompanyBranchInput
63+
): Promise<CompanyBranchInterface> {
64+
const response = await this.client.mutate({
65+
mutation: UPDATE_COMPANY_BRANCH,
66+
variables: { id: id, input: input },
67+
});
68+
return response.data.updateCompanyBranch as CompanyBranchInterface;
69+
}
70+
71+
public async deleteCompanyBranch(id: string): Promise<Boolean> {
72+
const response = await this.client.mutate({
73+
mutation: DELETE_COMPANY_BRANCH,
74+
variables: { id: id },
75+
});
76+
return response.data.deleteCompanyBranch as Boolean;
77+
}
78+
79+
public async addUserToBranch(id: string, user_id: string): Promise<Boolean> {
80+
const response = await this.client.mutate({
81+
mutation: ADD_USER_TO_BRANCH,
82+
variables: { id: id, user_id: user_id },
83+
});
84+
return response.data.addUserToBranch as Boolean;
85+
}
86+
87+
public async removeUserFromBranch(
88+
id: string,
89+
user_id: string
90+
): Promise<Boolean> {
91+
const response = await this.client.mutate({
92+
mutation: REMOVE_USER_FROM_BRANCH,
93+
variables: { id: id, user_id: user_id },
94+
});
95+
return response.data.removeUserFromBranch as Boolean;
96+
}
97+
}

src/modules/companies/index.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { ClientType } from '../../index';
2+
import {
3+
CREATE_COMPANY_MUTATION,
4+
UPDATE_COMPANY_MUTATION,
5+
DELETE_COMPANY_MUTATION,
6+
ADD_USER_TO_COMPANY,
7+
REMOVE_USER_FROM_COMPANY,
8+
} from '../../mutations';
9+
import {
10+
COMPANIES_QUERY,
11+
COMPANY_USERS_QUERY,
12+
COMPANY_SETTINGS_QUERY,
13+
} from '../../queries';
14+
15+
import {
16+
UserInterface,
17+
CompanyInput,
18+
CompanyInterface,
19+
CompanySettings,
20+
WhereCondition
21+
} from '../../types';
22+
23+
export class Companies {
24+
constructor(protected client: ClientType) {}
25+
26+
public async getCompanies(
27+
where: WhereCondition,
28+
first?: number,
29+
page?: number
30+
): Promise<CompanyInterface> {
31+
const response = await this.client.query({
32+
query: COMPANIES_QUERY,
33+
variables: { where, first, page },
34+
});
35+
return response.data as CompanyInterface;
36+
}
37+
38+
public async getCompanyUsers(
39+
where: WhereCondition,
40+
first?: number,
41+
page?: number
42+
): Promise<UserInterface> {
43+
const response = await this.client.query({
44+
query: COMPANY_USERS_QUERY,
45+
variables: { where, first, page },
46+
});
47+
return response.data as UserInterface;
48+
}
49+
50+
public async getCompanySettings(): Promise<CompanySettings> {
51+
const response = await this.client.query({
52+
query: COMPANY_SETTINGS_QUERY,
53+
});
54+
return response.data as CompanySettings;
55+
}
56+
57+
public async createCompany(input: CompanyInput): Promise<CompanyInterface> {
58+
const response = await this.client.mutate({
59+
mutation: CREATE_COMPANY_MUTATION,
60+
variables: { input },
61+
});
62+
return response.data.createCompany as CompanyInterface;
63+
}
64+
65+
public async updateCompany(
66+
id: string,
67+
input: CompanyInput
68+
): Promise<CompanyInterface> {
69+
const response = await this.client.mutate({
70+
mutation: UPDATE_COMPANY_MUTATION,
71+
variables: { id: id, input: input },
72+
});
73+
return response.data.updateCompany as CompanyInterface;
74+
}
75+
76+
public async deleteCompany(id: string): Promise<Boolean> {
77+
const response = await this.client.mutate({
78+
mutation: DELETE_COMPANY_MUTATION,
79+
variables: { id: id },
80+
});
81+
return response.data.deleteCompany as Boolean;
82+
}
83+
84+
public async addUserToCompany(id: string, user_id: string): Promise<Boolean> {
85+
const response = await this.client.mutate({
86+
mutation: ADD_USER_TO_COMPANY,
87+
variables: { id: id, user_id: user_id },
88+
});
89+
return response.data.addUserToCompany as Boolean;
90+
}
91+
92+
public async removeUserFromCompany(
93+
id: string,
94+
user_id: string
95+
): Promise<Boolean> {
96+
const response = await this.client.mutate({
97+
mutation: REMOVE_USER_FROM_COMPANY,
98+
variables: { id: id, user_id: user_id },
99+
});
100+
return response.data.removeUserFromCompany as Boolean;
101+
}
102+
}

0 commit comments

Comments
 (0)