@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
package/src/geinsCRM.ts
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { GeinsCore, BasePackage, buildEndpoints } from '@geins/core';
|
|
2
|
+
import {
|
|
3
|
+
AuthSettings,
|
|
4
|
+
AuthClientConnectionModes,
|
|
5
|
+
AuthCredentials,
|
|
6
|
+
AuthResponse,
|
|
7
|
+
AuthTokens,
|
|
8
|
+
GeinsUserInputTypeType,
|
|
9
|
+
GeinsUserOrdersType,
|
|
10
|
+
GeinsCustomerType,
|
|
11
|
+
GeinsEventType,
|
|
12
|
+
GeinsUserType,
|
|
13
|
+
} from '@geins/types';
|
|
14
|
+
import { AuthClientDirect, AuthClientProxy, AuthService } from './auth';
|
|
15
|
+
import type { AuthInterface, UserInterface } from './types';
|
|
16
|
+
import { UserService, UserOrdersService, PasswordResetService } from './services';
|
|
17
|
+
|
|
18
|
+
class GeinsCRM extends BasePackage {
|
|
19
|
+
private _authClient: AuthClientDirect | AuthClientProxy;
|
|
20
|
+
private _userService!: UserService;
|
|
21
|
+
private _passwordResetService!: PasswordResetService;
|
|
22
|
+
private _userOrdersService!: UserOrdersService;
|
|
23
|
+
|
|
24
|
+
constructor(core: GeinsCore, authSettings: AuthSettings) {
|
|
25
|
+
super(core);
|
|
26
|
+
const { geinsSettings } = core;
|
|
27
|
+
|
|
28
|
+
if (authSettings.clientConnectionMode === AuthClientConnectionModes.Proxy) {
|
|
29
|
+
const proxyUrl = authSettings.proxyUrl || '/api/auth';
|
|
30
|
+
this._authClient = new AuthClientProxy(proxyUrl);
|
|
31
|
+
} else if (authSettings.clientConnectionMode === AuthClientConnectionModes.Direct) {
|
|
32
|
+
const endpoints = buildEndpoints(
|
|
33
|
+
geinsSettings.apiKey,
|
|
34
|
+
geinsSettings.accountName,
|
|
35
|
+
geinsSettings.environment,
|
|
36
|
+
);
|
|
37
|
+
this._authClient = new AuthClientDirect(endpoints.authSign, endpoints.auth);
|
|
38
|
+
} else {
|
|
39
|
+
throw new Error('Invalid client connection mode');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private async initUserService(): Promise<void> {
|
|
44
|
+
this._userService = new UserService(() => this._apiClient(), this._geinsSettings);
|
|
45
|
+
|
|
46
|
+
if (!this._userService) {
|
|
47
|
+
throw new Error('Failed to initialize user service');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private async initPasswordService(): Promise<void> {
|
|
52
|
+
this._passwordResetService = new PasswordResetService(() => this._apiClient(), this._geinsSettings);
|
|
53
|
+
if (!this._passwordResetService) {
|
|
54
|
+
throw new Error('Failed to initialize password reset service');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private async initUserOrderService(): Promise<void> {
|
|
59
|
+
this._userOrdersService = new UserOrdersService(() => this._apiClient(), this._geinsSettings);
|
|
60
|
+
if (!this._userOrdersService) {
|
|
61
|
+
throw new Error('Failed to initialize user order service');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public setAuthTokens(tokens: AuthTokens): void {
|
|
66
|
+
if (tokens?.token) {
|
|
67
|
+
this.core.setUserToken(tokens?.token);
|
|
68
|
+
}
|
|
69
|
+
if (tokens?.refreshToken) {
|
|
70
|
+
this._authClient.setRefreshToken(tokens.refreshToken);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public clearAuthAndUser(): void {
|
|
75
|
+
this.core?.setUserToken(undefined);
|
|
76
|
+
this._authClient?.clearAuth();
|
|
77
|
+
this._apiClient()?.clearCacheAndRefetchQueries();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public spoofUser(token: string): string {
|
|
81
|
+
this._authClient.logout();
|
|
82
|
+
return this._authClient.spoofPreviewUser(token);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get auth(): AuthInterface {
|
|
86
|
+
if (!this._authClient) {
|
|
87
|
+
throw new Error('AuthClient is not initialized');
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
get: this.authGetUser.bind(this),
|
|
91
|
+
login: this.authLogin.bind(this),
|
|
92
|
+
logout: this.authLogout.bind(this),
|
|
93
|
+
refresh: this.authRefresh.bind(this),
|
|
94
|
+
authorized: this.authAuthorized.bind(this),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private handleAuthResponse(authResponse: AuthResponse | undefined, clearAuthOnFail: boolean = true): void {
|
|
99
|
+
if (authResponse?.succeeded && authResponse.tokens?.token) {
|
|
100
|
+
this.setAuthTokens(authResponse.tokens);
|
|
101
|
+
} else if (clearAuthOnFail) {
|
|
102
|
+
this.clearAuthAndUser();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private async authAuthorized(refreshToken?: string): Promise<boolean> {
|
|
107
|
+
// check if refreshToken is argument
|
|
108
|
+
if (refreshToken) {
|
|
109
|
+
this._authClient.setRefreshToken(refreshToken);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// try to to get user with refreshToken
|
|
113
|
+
const authResponse = await this._authClient.getUser(refreshToken);
|
|
114
|
+
this.handleAuthResponse(authResponse);
|
|
115
|
+
|
|
116
|
+
return authResponse?.succeeded ?? false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private async authLogin(credentials: AuthCredentials): Promise<AuthResponse | undefined> {
|
|
120
|
+
const authResponse = await this._authClient.login(credentials);
|
|
121
|
+
this.handleAuthResponse(authResponse);
|
|
122
|
+
|
|
123
|
+
if (authResponse?.succeeded) {
|
|
124
|
+
this._apiClient()?.clearCacheAndRefetchQueries();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
this.pushEvent(
|
|
129
|
+
{
|
|
130
|
+
subject: GeinsEventType.USER_LOGIN,
|
|
131
|
+
payload: {
|
|
132
|
+
success: authResponse?.succeeded,
|
|
133
|
+
user: credentials.username,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
GeinsEventType.USER_LOGIN,
|
|
137
|
+
);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.warn('Failed to push USER_LOGIN event:', error);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return authResponse;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private async authLogout(): Promise<AuthResponse | undefined> {
|
|
146
|
+
this.clearAuthAndUser();
|
|
147
|
+
try {
|
|
148
|
+
this.pushEvent({ subject: GeinsEventType.USER_LOGOUT, payload: {} }, GeinsEventType.USER_LOGOUT);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.warn('Failed to push USER_LOGOUT event:', error);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return this._authClient.logout();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private async authRefresh(refreshToken?: string): Promise<AuthResponse | undefined> {
|
|
157
|
+
const authResponse = await this._authClient.refresh(refreshToken);
|
|
158
|
+
this.handleAuthResponse(authResponse);
|
|
159
|
+
|
|
160
|
+
return authResponse;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private async authGetUser(refreshToken?: string, userToken?: string): Promise<AuthResponse | undefined> {
|
|
164
|
+
const authResponse = await this._authClient.getUser(refreshToken, userToken);
|
|
165
|
+
this.handleAuthResponse(authResponse);
|
|
166
|
+
|
|
167
|
+
return authResponse;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
get user(): UserInterface {
|
|
171
|
+
if (!this._authClient) {
|
|
172
|
+
throw new Error('AuthClient is not initialized');
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
get: this.userGet.bind(this),
|
|
176
|
+
update: this.userUpdate.bind(this),
|
|
177
|
+
create: this.userRegisterAndCreate.bind(this),
|
|
178
|
+
remove: this.userRemove.bind(this),
|
|
179
|
+
password: {
|
|
180
|
+
change: this.userChangePassword.bind(this),
|
|
181
|
+
requestReset: this.userPasswordResetRequest.bind(this),
|
|
182
|
+
commitReset: this.userPasswordResetCommit.bind(this),
|
|
183
|
+
},
|
|
184
|
+
orders: {
|
|
185
|
+
get: this.userOrders.bind(this),
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private async userGet(): Promise<GeinsUserType | undefined> {
|
|
191
|
+
if (!this._userService) {
|
|
192
|
+
await this.initUserService();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// check if core has token
|
|
196
|
+
const userTokenFromCore = this.getCore().getUserToken();
|
|
197
|
+
if (!userTokenFromCore) {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
return this._userService?.get();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private async userUpdate(user: GeinsUserInputTypeType): Promise<any> {
|
|
204
|
+
if (!this._userService) {
|
|
205
|
+
await this.initUserService();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Unwrap the Proxy
|
|
209
|
+
const unwrappedUser: GeinsUserInputTypeType = JSON.parse(JSON.stringify(user));
|
|
210
|
+
|
|
211
|
+
try {
|
|
212
|
+
this.pushEvent(
|
|
213
|
+
{ subject: GeinsEventType.USER_UPDATE, payload: unwrappedUser },
|
|
214
|
+
GeinsEventType.USER_UPDATE,
|
|
215
|
+
);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
console.warn('Failed to push USER_UPDATE event:', error);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return this._userService?.update(user);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private async userRegisterAndCreate(
|
|
224
|
+
credentials: AuthCredentials,
|
|
225
|
+
user?: GeinsUserInputTypeType,
|
|
226
|
+
): Promise<AuthResponse | undefined> {
|
|
227
|
+
// logout user if already logged in
|
|
228
|
+
await this.authLogout();
|
|
229
|
+
|
|
230
|
+
// user will be registered and logged in
|
|
231
|
+
const authResponse = await this._authClient.register(credentials);
|
|
232
|
+
this.handleAuthResponse(authResponse);
|
|
233
|
+
|
|
234
|
+
if (!authResponse?.succeeded) {
|
|
235
|
+
return authResponse;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (user) {
|
|
239
|
+
const userResult = await this.userUpdate(user);
|
|
240
|
+
if (!userResult) {
|
|
241
|
+
throw new Error('Failed to update user with information');
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
const registerUserAs: GeinsUserInputTypeType = {
|
|
245
|
+
newsletter: false,
|
|
246
|
+
customerType: GeinsCustomerType.PersonType,
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const userResult = await this.userCreate(registerUserAs);
|
|
250
|
+
|
|
251
|
+
if (!userResult) {
|
|
252
|
+
throw new Error('Failed to create user in MC');
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const { refreshToken, token } = authResponse?.tokens || {};
|
|
257
|
+
return this._authClient.getUser(refreshToken, token);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private async userCreate(user: GeinsUserInputTypeType): Promise<any> {
|
|
261
|
+
if (!this._userService) {
|
|
262
|
+
await this.initUserService();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return this._userService?.create(user);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
private async userRemove(): Promise<any> {
|
|
269
|
+
this.pushEvent({ subject: GeinsEventType.USER_DELETE, payload: {} }, GeinsEventType.USER_DELETE);
|
|
270
|
+
if (!this._userService) {
|
|
271
|
+
await this.initUserService();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return this._userService?.delete();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
private async userOrders(): Promise<GeinsUserOrdersType | undefined> {
|
|
278
|
+
if (!this._userOrdersService) {
|
|
279
|
+
await this.initUserOrderService();
|
|
280
|
+
}
|
|
281
|
+
return this._userOrdersService?.get();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
private async userChangePassword(credentials: AuthCredentials): Promise<AuthResponse | undefined> {
|
|
285
|
+
const authResponse = await this._authClient.changePassword(credentials);
|
|
286
|
+
this.handleAuthResponse(authResponse, false);
|
|
287
|
+
|
|
288
|
+
return authResponse;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private async userPasswordResetRequest(email: string): Promise<any> {
|
|
292
|
+
if (!this._passwordResetService) {
|
|
293
|
+
await this.initPasswordService();
|
|
294
|
+
}
|
|
295
|
+
return this._passwordResetService?.request(email);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private async userPasswordResetCommit(resetKey: string, password: string): Promise<any> {
|
|
299
|
+
if (!this._passwordResetService) {
|
|
300
|
+
await this.initPasswordService();
|
|
301
|
+
}
|
|
302
|
+
return this._passwordResetService?.commit(resetKey, password);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export { GeinsCRM };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
mutation UserPasswordResetCommit(
|
|
2
|
+
$resetKey: String!
|
|
3
|
+
$password: String!
|
|
4
|
+
$channelId: String
|
|
5
|
+
$languageId: String
|
|
6
|
+
$marketId: String
|
|
7
|
+
) {
|
|
8
|
+
commitReset(
|
|
9
|
+
resetKey: $resetKey
|
|
10
|
+
password: $password
|
|
11
|
+
channelId: $channelId
|
|
12
|
+
languageId: $languageId
|
|
13
|
+
marketId: $marketId
|
|
14
|
+
)
|
|
15
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#import "./price.gql"
|
|
2
|
+
#import "./stock.gql"
|
|
3
|
+
|
|
4
|
+
fragment Cart on CartType {
|
|
5
|
+
id
|
|
6
|
+
promoCode
|
|
7
|
+
appliedCampaigns {
|
|
8
|
+
name
|
|
9
|
+
hideTitle
|
|
10
|
+
}
|
|
11
|
+
items {
|
|
12
|
+
campaign {
|
|
13
|
+
appliedCampaigns {
|
|
14
|
+
name
|
|
15
|
+
hideTitle
|
|
16
|
+
}
|
|
17
|
+
prices {
|
|
18
|
+
price {
|
|
19
|
+
...Price
|
|
20
|
+
}
|
|
21
|
+
quantity
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
unitPrice {
|
|
25
|
+
...Price
|
|
26
|
+
}
|
|
27
|
+
product {
|
|
28
|
+
productId
|
|
29
|
+
articleNumber
|
|
30
|
+
brand {
|
|
31
|
+
name
|
|
32
|
+
}
|
|
33
|
+
name
|
|
34
|
+
productImages {
|
|
35
|
+
fileName
|
|
36
|
+
}
|
|
37
|
+
alias
|
|
38
|
+
canonicalUrl
|
|
39
|
+
primaryCategory {
|
|
40
|
+
name
|
|
41
|
+
}
|
|
42
|
+
skus {
|
|
43
|
+
skuId
|
|
44
|
+
name
|
|
45
|
+
stock {
|
|
46
|
+
...Stock
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
unitPrice {
|
|
50
|
+
...Price
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
quantity
|
|
54
|
+
skuId
|
|
55
|
+
totalPrice {
|
|
56
|
+
...Price
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
summary {
|
|
60
|
+
fixedAmountDiscountIncVat
|
|
61
|
+
fixedAmountDiscountExVat
|
|
62
|
+
balance {
|
|
63
|
+
pending
|
|
64
|
+
pendingFormatted
|
|
65
|
+
totalSellingPriceExBalanceExVat
|
|
66
|
+
totalSellingPriceExBalanceIncVat
|
|
67
|
+
totalSellingPriceExBalanceIncVatFormatted
|
|
68
|
+
}
|
|
69
|
+
subTotal {
|
|
70
|
+
regularPriceIncVatFormatted
|
|
71
|
+
regularPriceExVatFormatted
|
|
72
|
+
sellingPriceIncVatFormatted
|
|
73
|
+
sellingPriceExVatFormatted
|
|
74
|
+
sellingPriceExVat
|
|
75
|
+
sellingPriceIncVat
|
|
76
|
+
vat
|
|
77
|
+
}
|
|
78
|
+
shipping {
|
|
79
|
+
amountLeftToFreeShipping
|
|
80
|
+
amountLeftToFreeShippingFormatted
|
|
81
|
+
feeExVatFormatted
|
|
82
|
+
feeIncVatFormatted
|
|
83
|
+
feeIncVat
|
|
84
|
+
feeExVat
|
|
85
|
+
isDefault
|
|
86
|
+
}
|
|
87
|
+
total {
|
|
88
|
+
isDiscounted
|
|
89
|
+
sellingPriceIncVatFormatted
|
|
90
|
+
sellingPriceExVatFormatted
|
|
91
|
+
sellingPriceIncVat
|
|
92
|
+
sellingPriceExVat
|
|
93
|
+
discountIncVatFormatted
|
|
94
|
+
discountExVatFormatted
|
|
95
|
+
discountExVat
|
|
96
|
+
discountIncVat
|
|
97
|
+
vatFormatted
|
|
98
|
+
vat
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
fragment Price on PriceType {
|
|
2
|
+
isDiscounted
|
|
3
|
+
sellingPriceIncVat
|
|
4
|
+
sellingPriceExVat
|
|
5
|
+
regularPriceIncVat
|
|
6
|
+
regularPriceExVat
|
|
7
|
+
vat
|
|
8
|
+
discountPercentage
|
|
9
|
+
regularPriceIncVatFormatted
|
|
10
|
+
sellingPriceIncVatFormatted
|
|
11
|
+
regularPriceExVatFormatted
|
|
12
|
+
sellingPriceExVatFormatted
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './queries';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#import "../fragments/price.gql"
|
|
2
|
+
#import "../fragments/address.gql"
|
|
3
|
+
#import "../fragments/cart.gql"
|
|
4
|
+
|
|
5
|
+
query UserOrders($channelId: String, $languageId: String, $marketId: String) {
|
|
6
|
+
getOrders(
|
|
7
|
+
channelId: $channelId
|
|
8
|
+
languageId: $languageId
|
|
9
|
+
marketId: $marketId
|
|
10
|
+
) {
|
|
11
|
+
cart {
|
|
12
|
+
...Cart
|
|
13
|
+
}
|
|
14
|
+
billingAddress {
|
|
15
|
+
...Address
|
|
16
|
+
}
|
|
17
|
+
shippingAddress {
|
|
18
|
+
...Address
|
|
19
|
+
}
|
|
20
|
+
createdAt
|
|
21
|
+
id
|
|
22
|
+
status
|
|
23
|
+
shippingDetails {
|
|
24
|
+
name
|
|
25
|
+
trackingLink
|
|
26
|
+
}
|
|
27
|
+
paymentDetails {
|
|
28
|
+
displayName
|
|
29
|
+
}
|
|
30
|
+
refunds {
|
|
31
|
+
id
|
|
32
|
+
itemId
|
|
33
|
+
createdAt
|
|
34
|
+
reason
|
|
35
|
+
total
|
|
36
|
+
vat
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import userGet from './user/get.gql';
|
|
2
|
+
import userOrders from './order/orders.gql';
|
|
3
|
+
import userRegister from './user/register.gql';
|
|
4
|
+
import userUpdate from './user/update.gql';
|
|
5
|
+
import userDelete from './user/delete.gql';
|
|
6
|
+
import pwResetRequest from './auth/pw-reset-request.gql';
|
|
7
|
+
import pwResetCommit from './auth/pw-reset-commit.gql';
|
|
8
|
+
|
|
9
|
+
const queries = {
|
|
10
|
+
userGet,
|
|
11
|
+
userOrders,
|
|
12
|
+
};
|
|
13
|
+
const mutations = {
|
|
14
|
+
userRegister,
|
|
15
|
+
userUpdate,
|
|
16
|
+
userDelete,
|
|
17
|
+
pwResetRequest,
|
|
18
|
+
pwResetCommit,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { queries, mutations };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#import "../fragments/user.gql"
|
|
2
|
+
mutation UserUpdate(
|
|
3
|
+
$user: UserInputType!
|
|
4
|
+
$channelId: String
|
|
5
|
+
$languageId: String
|
|
6
|
+
$marketId: String
|
|
7
|
+
) {
|
|
8
|
+
updateUser(
|
|
9
|
+
user: $user
|
|
10
|
+
channelId: $channelId
|
|
11
|
+
languageId: $languageId
|
|
12
|
+
marketId: $marketId
|
|
13
|
+
) {
|
|
14
|
+
...User
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/index.ts
ADDED
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GeinsAddressTypeType } from '@geins/types';
|
|
2
|
+
|
|
3
|
+
export function parseAddress(data: any): GeinsAddressTypeType | undefined {
|
|
4
|
+
if (!data) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
return {
|
|
8
|
+
firstName: data.firstName,
|
|
9
|
+
lastName: data.lastName,
|
|
10
|
+
addressLine1: data.addressLine1,
|
|
11
|
+
addressLine2: data.addressLine2,
|
|
12
|
+
addressLine3: data.addressLine3,
|
|
13
|
+
entryCode: data.entryCode,
|
|
14
|
+
careOf: data.careOf,
|
|
15
|
+
city: data.city,
|
|
16
|
+
state: data.state,
|
|
17
|
+
country: data.country,
|
|
18
|
+
zip: data.zip,
|
|
19
|
+
company: data.company,
|
|
20
|
+
mobile: data.mobile,
|
|
21
|
+
phone: data.phone,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//import type { GeinsUserRequestPasswordResetType } from '@geins/types';
|
|
2
|
+
import { BaseApiService, logWrite, GeinsUserInputTypeType } from '@geins/core';
|
|
3
|
+
import { mutations } from '../graphql';
|
|
4
|
+
import { digest } from '../auth/authHelpers';
|
|
5
|
+
export class PasswordResetService extends BaseApiService {
|
|
6
|
+
private async generateVars(variables: any) {
|
|
7
|
+
return this.createVariables(variables);
|
|
8
|
+
}
|
|
9
|
+
async request(email: string): Promise<any> {
|
|
10
|
+
const variables = {
|
|
11
|
+
email,
|
|
12
|
+
};
|
|
13
|
+
const options = {
|
|
14
|
+
query: mutations.pwResetRequest,
|
|
15
|
+
variables: await this.generateVars(variables),
|
|
16
|
+
};
|
|
17
|
+
return this.runMutation(options);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async commit(resetKey: string, password: string): Promise<any> {
|
|
21
|
+
const pwd = await digest(password);
|
|
22
|
+
const variables = { resetKey, password: pwd };
|
|
23
|
+
const vars = await this.generateVars(variables);
|
|
24
|
+
const options = {
|
|
25
|
+
query: mutations.pwResetCommit,
|
|
26
|
+
variables: vars,
|
|
27
|
+
};
|
|
28
|
+
return this.runMutation(options);
|
|
29
|
+
}
|
|
30
|
+
}
|