@geins/crm 0.1.1-canary
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +1 -0
- package/__tests__/GeinsCRM.auth.test.ts +284 -0
- package/__tests__/GeinsCRM.user.test.ts +109 -0
- package/dist/auth/authClient.d.ts +41 -0
- package/dist/auth/authClientDirect.d.ts +11 -0
- package/dist/auth/authClientProxy.d.ts +12 -0
- package/dist/auth/authHelpers.d.ts +5 -0
- package/dist/auth/authService.d.ts +17 -0
- package/dist/auth/authServiceClient.d.ts +20 -0
- package/dist/auth/index.d.ts +6 -0
- package/dist/geinsCRM.d.ts +34 -0
- package/dist/graphql/index.d.ts +1 -0
- package/dist/graphql/queries.d.ts +12 -0
- package/dist/index.cjs +24358 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +24346 -0
- package/dist/parsers/shared.d.ts +2 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/pwResetService.d.ts +6 -0
- package/dist/services/userOrdersService.d.ts +9 -0
- package/dist/services/userService.d.ts +13 -0
- package/dist/types/crmTypes.d.ts +36 -0
- package/dist/types/index.d.ts +1 -0
- package/eslint.config.js +3 -0
- package/jest.config.js +8 -0
- package/package.json +30 -0
- package/rollup.config.js +26 -0
- package/src/auth/authClient.ts +318 -0
- package/src/auth/authClientDirect.ts +31 -0
- package/src/auth/authClientProxy.ts +82 -0
- package/src/auth/authHelpers.ts +65 -0
- package/src/auth/authService.ts +175 -0
- package/src/auth/authServiceClient.ts +267 -0
- package/src/auth/index.ts +6 -0
- package/src/geinsCRM.ts +306 -0
- package/src/graphql/auth/pw-reset-commit.gql +15 -0
- package/src/graphql/auth/pw-reset-request.gql +13 -0
- package/src/graphql/fragments/address.gql +16 -0
- package/src/graphql/fragments/balances.gql +5 -0
- package/src/graphql/fragments/campaign.gql +4 -0
- package/src/graphql/fragments/cart.gql +101 -0
- package/src/graphql/fragments/price.gql +13 -0
- package/src/graphql/fragments/stock.gql +7 -0
- package/src/graphql/fragments/user.gql +16 -0
- package/src/graphql/graphql.d.ts +9 -0
- package/src/graphql/index.ts +1 -0
- package/src/graphql/order/orders.gql +39 -0
- package/src/graphql/queries.ts +21 -0
- package/src/graphql/user/delete.gql +3 -0
- package/src/graphql/user/get.gql +6 -0
- package/src/graphql/user/register.gql +15 -0
- package/src/graphql/user/update.gql +16 -0
- package/src/index.ts +2 -0
- package/src/parsers/index.ts +0 -0
- package/src/parsers/shared.ts +23 -0
- package/src/services/index.ts +3 -0
- package/src/services/pwResetService.ts +30 -0
- package/src/services/userOrdersService.ts +34 -0
- package/src/services/userService.ts +83 -0
- package/src/types/crmTypes.ts +46 -0
- package/src/types/index.ts +1 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { GeinsSettings, GeinsUserOrdersType } from '@geins/types';
|
|
2
|
+
import { BaseApiService, logWrite } from '@geins/core';
|
|
3
|
+
import { queries } from '../graphql';
|
|
4
|
+
export class UserOrdersService extends BaseApiService {
|
|
5
|
+
constructor(apiClient: any, geinsSettings: GeinsSettings) {
|
|
6
|
+
super(apiClient, geinsSettings);
|
|
7
|
+
}
|
|
8
|
+
private async generateVars(variables: any) {
|
|
9
|
+
return this.createVariables(variables);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async getRaw(variables: any): Promise<any> {
|
|
13
|
+
const options = {
|
|
14
|
+
query: queries.userOrders,
|
|
15
|
+
variables: await this.generateVars(variables),
|
|
16
|
+
};
|
|
17
|
+
return this.runQuery(options);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async get(): Promise<GeinsUserOrdersType | undefined> {
|
|
21
|
+
const options = {
|
|
22
|
+
query: queries.userOrders,
|
|
23
|
+
variables: await this.generateVars({}),
|
|
24
|
+
};
|
|
25
|
+
return await this.runQueryParsed<GeinsUserOrdersType>(options);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
protected parseResult(result: any): GeinsUserOrdersType | undefined {
|
|
29
|
+
if (!result || !result.data || !result.data.getOrders) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return result.data.getOrders as GeinsUserOrdersType;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { GeinsUserType, GeinsSettings } from '@geins/types';
|
|
2
|
+
import { BaseApiService, GeinsUserInputTypeType } from '@geins/core';
|
|
3
|
+
import { queries, mutations } from '../graphql';
|
|
4
|
+
export class UserService extends BaseApiService {
|
|
5
|
+
constructor(apiClient: any, geinsSettings: GeinsSettings) {
|
|
6
|
+
super(apiClient, geinsSettings);
|
|
7
|
+
}
|
|
8
|
+
private async generateVars(variables: any) {
|
|
9
|
+
return this.createVariables(variables);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
private async generateMutationVars(variables: any) {
|
|
13
|
+
if (variables.user && variables.user.entityId) {
|
|
14
|
+
variables.user.personalId = variables.user.entityId;
|
|
15
|
+
delete variables.user.entityId;
|
|
16
|
+
}
|
|
17
|
+
if (variables.user) {
|
|
18
|
+
const newsletter = !!(variables.user.newsletter === 'true');
|
|
19
|
+
variables.user.newsletter = newsletter;
|
|
20
|
+
}
|
|
21
|
+
return this.createVariables(variables);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async getRaw(): Promise<any> {
|
|
25
|
+
const vars = await this.generateVars({});
|
|
26
|
+
const options = {
|
|
27
|
+
query: queries.userGet,
|
|
28
|
+
variables: vars,
|
|
29
|
+
};
|
|
30
|
+
return this.runQuery(options);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async get(): Promise<GeinsUserType | undefined> {
|
|
34
|
+
const options = {
|
|
35
|
+
query: queries.userGet,
|
|
36
|
+
variables: await this.generateVars({}),
|
|
37
|
+
};
|
|
38
|
+
const user = await this.runQueryParsed<GeinsUserType>(options);
|
|
39
|
+
|
|
40
|
+
return user;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async create(user: GeinsUserInputTypeType): Promise<any> {
|
|
44
|
+
const options = {
|
|
45
|
+
query: mutations.userRegister,
|
|
46
|
+
variables: await this.generateMutationVars({ user }),
|
|
47
|
+
};
|
|
48
|
+
const result = this.runMutation(options);
|
|
49
|
+
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async update(user: GeinsUserInputTypeType): Promise<GeinsUserType> {
|
|
54
|
+
const options = {
|
|
55
|
+
query: mutations.userUpdate,
|
|
56
|
+
variables: await this.generateMutationVars({ user }),
|
|
57
|
+
};
|
|
58
|
+
const result = await this.runMutation(options);
|
|
59
|
+
return this.parseResult(result) as GeinsUserType;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async delete(): Promise<any> {
|
|
63
|
+
const options = {
|
|
64
|
+
query: mutations.userDelete,
|
|
65
|
+
variables: await this.generateVars({}),
|
|
66
|
+
};
|
|
67
|
+
const result = await this.runMutation(options);
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
protected parseResult(data: any): GeinsUserType | undefined {
|
|
72
|
+
if (!data || !data.data) {
|
|
73
|
+
throw new Error('Invalid user data');
|
|
74
|
+
}
|
|
75
|
+
if (data.data.getUser) {
|
|
76
|
+
return data.data.getUser as GeinsUserType;
|
|
77
|
+
}
|
|
78
|
+
if (data.data.updateUser) {
|
|
79
|
+
return this.cleanObject(data.data.updateUser) as GeinsUserType;
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthCredentials,
|
|
3
|
+
AuthResponse,
|
|
4
|
+
GeinsUserInputTypeType,
|
|
5
|
+
GeinsUserType,
|
|
6
|
+
GeinsUserOrdersType,
|
|
7
|
+
} from '@geins/types';
|
|
8
|
+
|
|
9
|
+
export interface AuthInterface {
|
|
10
|
+
get(refreshToken?: string, userToken?: string): Promise<AuthResponse | undefined>;
|
|
11
|
+
login(credentials: AuthCredentials): Promise<AuthResponse | undefined>;
|
|
12
|
+
logout(): Promise<AuthResponse | undefined>;
|
|
13
|
+
refresh(refreshToken?: string): Promise<AuthResponse | undefined>;
|
|
14
|
+
authorized(refreshToken?: string): Promise<boolean>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* User interface
|
|
19
|
+
* This interface is used to define the user service
|
|
20
|
+
*/
|
|
21
|
+
export interface UserInterface {
|
|
22
|
+
get(): Promise<GeinsUserType | undefined>;
|
|
23
|
+
update(user: GeinsUserInputTypeType): Promise<any>;
|
|
24
|
+
create(credentials: AuthCredentials, user?: GeinsUserInputTypeType): Promise<AuthResponse | undefined>;
|
|
25
|
+
remove(): Promise<any>;
|
|
26
|
+
password: UserPasswordInterface;
|
|
27
|
+
orders: UserOrdersInterface;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* User password interface
|
|
32
|
+
* This interface is used to define the user password service
|
|
33
|
+
*/
|
|
34
|
+
export interface UserPasswordInterface {
|
|
35
|
+
change(credentials: AuthCredentials): Promise<AuthResponse | undefined>;
|
|
36
|
+
requestReset(email: string): Promise<any>;
|
|
37
|
+
commitReset(resetKey: string, password: string): Promise<any>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* User orders interface
|
|
42
|
+
* This interface is used to define the user orders service
|
|
43
|
+
*/
|
|
44
|
+
export interface UserOrdersInterface {
|
|
45
|
+
get(): Promise<GeinsUserOrdersType | undefined>;
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './crmTypes';
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES5",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"resolveJsonModule": true
|
|
13
|
+
},
|
|
14
|
+
"include": [
|
|
15
|
+
"src/**/*.ts",
|
|
16
|
+
"src/**/*.d.ts",
|
|
17
|
+
"src/**/*.gql"
|
|
18
|
+
]
|
|
19
|
+
}
|