@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.
Files changed (63) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -0
  3. package/__tests__/GeinsCRM.auth.test.ts +284 -0
  4. package/__tests__/GeinsCRM.user.test.ts +109 -0
  5. package/dist/auth/authClient.d.ts +41 -0
  6. package/dist/auth/authClientDirect.d.ts +11 -0
  7. package/dist/auth/authClientProxy.d.ts +12 -0
  8. package/dist/auth/authHelpers.d.ts +5 -0
  9. package/dist/auth/authService.d.ts +17 -0
  10. package/dist/auth/authServiceClient.d.ts +20 -0
  11. package/dist/auth/index.d.ts +6 -0
  12. package/dist/geinsCRM.d.ts +34 -0
  13. package/dist/graphql/index.d.ts +1 -0
  14. package/dist/graphql/queries.d.ts +12 -0
  15. package/dist/index.cjs +24358 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.esm.js +24346 -0
  18. package/dist/parsers/shared.d.ts +2 -0
  19. package/dist/services/index.d.ts +3 -0
  20. package/dist/services/pwResetService.d.ts +6 -0
  21. package/dist/services/userOrdersService.d.ts +9 -0
  22. package/dist/services/userService.d.ts +13 -0
  23. package/dist/types/crmTypes.d.ts +36 -0
  24. package/dist/types/index.d.ts +1 -0
  25. package/eslint.config.js +3 -0
  26. package/jest.config.js +8 -0
  27. package/package.json +30 -0
  28. package/rollup.config.js +26 -0
  29. package/src/auth/authClient.ts +318 -0
  30. package/src/auth/authClientDirect.ts +31 -0
  31. package/src/auth/authClientProxy.ts +82 -0
  32. package/src/auth/authHelpers.ts +65 -0
  33. package/src/auth/authService.ts +175 -0
  34. package/src/auth/authServiceClient.ts +267 -0
  35. package/src/auth/index.ts +6 -0
  36. package/src/geinsCRM.ts +306 -0
  37. package/src/graphql/auth/pw-reset-commit.gql +15 -0
  38. package/src/graphql/auth/pw-reset-request.gql +13 -0
  39. package/src/graphql/fragments/address.gql +16 -0
  40. package/src/graphql/fragments/balances.gql +5 -0
  41. package/src/graphql/fragments/campaign.gql +4 -0
  42. package/src/graphql/fragments/cart.gql +101 -0
  43. package/src/graphql/fragments/price.gql +13 -0
  44. package/src/graphql/fragments/stock.gql +7 -0
  45. package/src/graphql/fragments/user.gql +16 -0
  46. package/src/graphql/graphql.d.ts +9 -0
  47. package/src/graphql/index.ts +1 -0
  48. package/src/graphql/order/orders.gql +39 -0
  49. package/src/graphql/queries.ts +21 -0
  50. package/src/graphql/user/delete.gql +3 -0
  51. package/src/graphql/user/get.gql +6 -0
  52. package/src/graphql/user/register.gql +15 -0
  53. package/src/graphql/user/update.gql +16 -0
  54. package/src/index.ts +2 -0
  55. package/src/parsers/index.ts +0 -0
  56. package/src/parsers/shared.ts +23 -0
  57. package/src/services/index.ts +3 -0
  58. package/src/services/pwResetService.ts +30 -0
  59. package/src/services/userOrdersService.ts +34 -0
  60. package/src/services/userService.ts +83 -0
  61. package/src/types/crmTypes.ts +46 -0
  62. package/src/types/index.ts +1 -0
  63. package/tsconfig.json +19 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # @geins/crm
2
+
3
+ ## 0.1.1-canary
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @geins/core@0.1.1-canary
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # CRM
@@ -0,0 +1,284 @@
1
+ // /packages/sdk/crm/__tests__/GeinsCRM.auth.test.ts
2
+
3
+ import { GeinsCore, CookieService, AUTH_COOKIES } from '@geins/core';
4
+ import { AuthSettings, AuthCredentials } from '@geins/types';
5
+ import { GeinsCRM } from '../src/geinsCRM';
6
+ import { validSettings, validUserCredentials, expectedCookiesAuthAll } from '../../../../test/globalSettings';
7
+ import { setupMockFetchForInternalApi } from '../../../../test/setupAuthMockFetch';
8
+ import { randomString, randomUserData, cleanObject } from '../../../../test/dataMock';
9
+ import { AuthService } from '../src/auth/authService';
10
+
11
+ // Define type for test setup options
12
+ type TestSetupOptions = {
13
+ authSettings: AuthSettings;
14
+ useMockFetch?: boolean; // Flag to indicate if mock fetch should be used
15
+ };
16
+
17
+ /**
18
+ * Shared function to test GeinsCRM with different AuthSettings configurations.
19
+ * @param {TestSetupOptions} options - Contains the AuthSettings and other configuration flags.
20
+ */
21
+ function testGeinsCRM(options: TestSetupOptions) {
22
+ const { authSettings, useMockFetch } = options;
23
+
24
+ describe(`GeinsCRM Tests with AuthSettings - ${authSettings.clientConnectionMode}`, () => {
25
+ let setCookieSpy: jest.SpyInstance;
26
+ let removeCookieSpy: jest.SpyInstance;
27
+ let expectedMaxAge: number;
28
+
29
+ let geinsCRM: GeinsCRM;
30
+
31
+ beforeEach(() => {
32
+ setCookieSpy = jest.spyOn(CookieService.prototype, 'set');
33
+ removeCookieSpy = jest.spyOn(CookieService.prototype, 'remove');
34
+
35
+ validUserCredentials.rememberUser = true;
36
+ expectedMaxAge = validUserCredentials.rememberUser ? 604800 : 1800;
37
+
38
+ // Initialize GeinsCore and GeinsCRM instance before each test
39
+ const geinsCore = new GeinsCore(validSettings);
40
+ geinsCRM = new GeinsCRM(geinsCore, authSettings);
41
+
42
+ // If useMockFetch is true, set up mock fetch for internal API calls
43
+ if (useMockFetch) {
44
+ const authService = new AuthService(geinsCore.endpoints.authSign, geinsCore.endpoints.auth);
45
+ setupMockFetchForInternalApi(authService);
46
+ }
47
+ setCookieSpy.mockClear();
48
+ });
49
+
50
+ afterEach(() => {
51
+ // Clean up mocks after each test
52
+ jest.clearAllMocks();
53
+ setCookieSpy.mockClear();
54
+ });
55
+
56
+ it('should initialize GeinsCRM correctly', () => {
57
+ expect(geinsCRM).toBeDefined();
58
+ });
59
+
60
+ it('should login a user with valid credentials', async () => {
61
+ const credentials: AuthCredentials = {
62
+ username: validUserCredentials.username,
63
+ password: validUserCredentials.password,
64
+ rememberUser: validUserCredentials.rememberUser,
65
+ };
66
+
67
+ const loginResult = await geinsCRM.auth.login(credentials);
68
+
69
+ expect(loginResult).toBeDefined();
70
+ expect(loginResult).toHaveProperty('succeeded');
71
+ expect(loginResult).toHaveProperty('tokens');
72
+ expect(loginResult).toHaveProperty('user');
73
+ expect(loginResult!.succeeded).toBe(true);
74
+ expect(loginResult!.tokens).toBeDefined();
75
+ expect(loginResult!.user).toBeDefined();
76
+ expect(loginResult!.tokens).toHaveProperty('token');
77
+ expect(loginResult!.tokens).toHaveProperty('refreshToken');
78
+
79
+ // check cookie set calls
80
+ const setCalls = setCookieSpy.mock.calls.map(call => call[0]);
81
+ expectedCookiesAuthAll.forEach(expectedName => {
82
+ expect(setCalls).toContainEqual(expect.objectContaining({ name: expectedName }));
83
+ });
84
+ expect(setCookieSpy).toHaveBeenCalledTimes(expectedCookiesAuthAll.length);
85
+ // check remove calls
86
+ const removeCalls = removeCookieSpy.mock.calls.map(call => call[0]);
87
+ expect(removeCalls).toHaveLength(0);
88
+ });
89
+
90
+ it('should not login a user with invalid credentials', async () => {
91
+ const credentials: AuthCredentials = {
92
+ username: validUserCredentials.username,
93
+ password: validUserCredentials.password + '1',
94
+ };
95
+
96
+ const loginResult = await geinsCRM.auth.login(credentials);
97
+
98
+ expect(loginResult).toBeDefined();
99
+ expect(loginResult).toHaveProperty('succeeded');
100
+ expect(loginResult!.succeeded).toBe(false);
101
+
102
+ // check cookies
103
+ const setCalls = setCookieSpy.mock.calls.map(call => call[0]);
104
+ expect(setCalls).toHaveLength(0);
105
+ const removeCalls = removeCookieSpy.mock.calls.map(call => call[0]);
106
+ expect(removeCalls).toHaveLength(expectedCookiesAuthAll.length);
107
+ });
108
+
109
+ it('should register a user with credentials', async () => {
110
+ const randomUsername = `${randomString(10).toLowerCase()}@test-user.com`;
111
+ const randomPassword = randomString(10);
112
+
113
+ const result = await geinsCRM.user.create({
114
+ username: randomUsername,
115
+ password: randomPassword,
116
+ });
117
+
118
+ expect(result).toBeDefined();
119
+ expect(result).toHaveProperty('succeeded');
120
+ expect(result!.succeeded).toBe(true);
121
+ expect(result).toHaveProperty('tokens');
122
+ expect(result).toHaveProperty('user');
123
+ expect(result!.user).toBeDefined();
124
+ expect(result!.tokens).toBeDefined();
125
+ expect(result!.user).toHaveProperty('username');
126
+ expect(result!.user?.username).toBe(randomUsername);
127
+
128
+ // check cookies
129
+ const setCalls = setCookieSpy.mock.calls.map(call => call[0]);
130
+ expect(setCalls).toHaveLength(expectedCookiesAuthAll.length);
131
+ });
132
+
133
+ it('should login a user and update information', async () => {
134
+ const credentials: AuthCredentials = {
135
+ username: validUserCredentials.username,
136
+ password: validUserCredentials.password,
137
+ };
138
+
139
+ // create random user data
140
+ const changedUserInfo = randomUserData();
141
+
142
+ const loginResult = await geinsCRM.auth.login(credentials);
143
+ expect(loginResult).toBeDefined();
144
+ expect(loginResult!.succeeded).toBe(true);
145
+
146
+ // get user information
147
+ const user = await geinsCRM.user.get();
148
+ expect(user).toBeDefined();
149
+ expect(user).toHaveProperty('email');
150
+ expect(user).toHaveProperty('customerType');
151
+ expect(user).toHaveProperty('address');
152
+
153
+ // update user information
154
+ const updateResult = await geinsCRM.user.update(changedUserInfo);
155
+ expect(updateResult).toBeDefined();
156
+ expect(updateResult).toHaveProperty('email');
157
+ expect(updateResult).toHaveProperty('personalId');
158
+ expect(updateResult).toHaveProperty('gender');
159
+ expect(updateResult).toHaveProperty('customerType');
160
+ expect(updateResult).toHaveProperty('address');
161
+
162
+ // check so that the user information has been updated
163
+ expect(updateResult!.personalId).toBe(changedUserInfo.personalId);
164
+ expect(updateResult!.gender).toBe(changedUserInfo.gender);
165
+ expect(updateResult!.customerType).toBe(changedUserInfo.customerType);
166
+
167
+ // clean address object and compare
168
+ const cleanUpdateResult = cleanObject(updateResult);
169
+ expect(cleanUpdateResult!.address).toEqual(changedUserInfo.address);
170
+ });
171
+
172
+ it('should not return user with invalid user-token', async () => {
173
+ const invalidToken = 'invalidToken';
174
+
175
+ const isolatedCore = new GeinsCore(validSettings);
176
+ const isolatedCRM = new GeinsCRM(isolatedCore, authSettings);
177
+
178
+ const user = await isolatedCRM.auth.get(invalidToken);
179
+ expect(user).toBeDefined();
180
+ expect(user).toHaveProperty('succeeded');
181
+ expect(user!.succeeded).toBe(false);
182
+
183
+ const setCalls = setCookieSpy.mock.calls.map(call => call[0]);
184
+ expect(setCalls).toHaveLength(0);
185
+ });
186
+
187
+ it('should return user when use refresh-token to auth.get', async () => {
188
+ const credentials: AuthCredentials = {
189
+ username: validUserCredentials.username,
190
+ password: validUserCredentials.password,
191
+ };
192
+
193
+ const loginResult = await geinsCRM.auth.login(credentials);
194
+ expect(loginResult).toBeDefined();
195
+ expect(loginResult!.succeeded).toBe(true);
196
+ expect(loginResult!.tokens).toBeDefined();
197
+ expect(loginResult!.tokens?.token).toBeDefined();
198
+
199
+ const refreshToken = loginResult!.tokens?.refreshToken;
200
+ const validToken = loginResult!.tokens?.token;
201
+
202
+ const isolatedCore = new GeinsCore(validSettings);
203
+ const isolatedCRM = new GeinsCRM(isolatedCore, authSettings);
204
+
205
+ const authUser = await isolatedCRM.auth.get(refreshToken);
206
+ const latestRefreshToken = authUser?.tokens?.refreshToken;
207
+ expect(authUser).toBeDefined();
208
+
209
+ const setCalls = setCookieSpy.mock.calls.map(call => call[0]);
210
+ const lastAuthRefreshTokenCookie = setCalls
211
+ .reverse()
212
+ .find(item => item.name === AUTH_COOKIES.REFRESH_TOKEN);
213
+ const lastAuthRefreshToken = lastAuthRefreshTokenCookie?.payload;
214
+
215
+ expect(latestRefreshToken).toBe(lastAuthRefreshToken);
216
+
217
+ // no remove calls
218
+ const removeCalls = removeCookieSpy.mock.calls.map(call => call[0]);
219
+ expect(removeCalls).toHaveLength(0);
220
+ });
221
+
222
+ it('should return true for authorized when using valid refresh-token', async () => {
223
+ const credentials: AuthCredentials = {
224
+ username: validUserCredentials.username,
225
+ password: validUserCredentials.password,
226
+ };
227
+
228
+ const loginResult = await geinsCRM.auth.login(credentials);
229
+ expect(loginResult).toBeDefined();
230
+ expect(loginResult!.succeeded).toBe(true);
231
+
232
+ const refreshToken = loginResult!.tokens?.refreshToken;
233
+
234
+ const isolatedCore = new GeinsCore(validSettings);
235
+ const isolatedCRM = new GeinsCRM(isolatedCore, authSettings);
236
+
237
+ const authorized = await isolatedCRM.auth.authorized(refreshToken);
238
+ expect(authorized).toBe(true);
239
+
240
+ const setCalls = setCookieSpy.mock.calls.map(call => call[0]);
241
+ expectedCookiesAuthAll.forEach(expectedName => {
242
+ expect(setCalls).toContainEqual(expect.objectContaining({ name: expectedName }));
243
+ });
244
+ });
245
+
246
+ it('should return false and remove cookies for authorized when using invalid refresh-token', async () => {
247
+ const refreshToken = 'invalidtoken';
248
+
249
+ const isolatedCore = new GeinsCore(validSettings);
250
+ const isolatedCRM = new GeinsCRM(isolatedCore, authSettings);
251
+
252
+ const authorized = await isolatedCRM.auth.authorized(refreshToken);
253
+ expect(authorized).toBe(false);
254
+
255
+ const setCalls = setCookieSpy.mock.calls.map(call => call[0]);
256
+ expect(setCalls).toHaveLength(0);
257
+ const removeCalls = removeCookieSpy.mock.calls.map(call => call[0]);
258
+ expectedCookiesAuthAll.forEach(expectedName => {
259
+ expect(removeCalls).toContainEqual(expect.stringContaining(expectedName));
260
+ });
261
+ });
262
+ });
263
+ }
264
+
265
+ // Define different AuthSettings configurations to test with
266
+ const authSettingsVariations: TestSetupOptions[] = [
267
+ {
268
+ authSettings: {
269
+ clientConnectionMode: 'Direct',
270
+ },
271
+ },
272
+ {
273
+ authSettings: {
274
+ clientConnectionMode: 'Proxy',
275
+ proxyUrl: '/api/auth',
276
+ },
277
+ useMockFetch: true,
278
+ },
279
+ ];
280
+
281
+ // Use describe.each to run the test suite with different configurations
282
+ describe.each(authSettingsVariations)('GeinsCRM Auth', options => {
283
+ testGeinsCRM(options);
284
+ });
@@ -0,0 +1,109 @@
1
+ // /packages/sdk/crm/__tests__/GeinsCRM.auth.test.ts
2
+
3
+ import { GeinsCore, CookieService, AUTH_COOKIES } from '@geins/core';
4
+ import { AuthSettings, AuthCredentials } from '@geins/types';
5
+ import { GeinsCRM } from '../src/geinsCRM';
6
+ import { validSettings, validUserCredentials, expectedCookiesAuthAll } from '../../../../test/globalSettings';
7
+ import { setupMockFetchForInternalApi } from '../../../../test/setupAuthMockFetch';
8
+ import { randomString, randomUserData, cleanObject } from '../../../../test/dataMock';
9
+ import { AuthService } from '../src/auth/authService';
10
+
11
+ // Define type for test setup options
12
+ type TestSetupOptions = {
13
+ authSettings: AuthSettings;
14
+ useMockFetch?: boolean; // Flag to indicate if mock fetch should be used
15
+ };
16
+
17
+ /**
18
+ * Shared function to test GeinsCRM with different AuthSettings configurations.
19
+ * @param {TestSetupOptions} options - Contains the AuthSettings and other configuration flags.
20
+ */
21
+ function testGeinsCRM(options: TestSetupOptions) {
22
+ const { authSettings, useMockFetch } = options;
23
+
24
+ describe(`GeinsCRM User Tests with AuthSettings - ${authSettings.clientConnectionMode}`, () => {
25
+ let setCookieSpy: jest.SpyInstance;
26
+ let removeCookieSpy: jest.SpyInstance;
27
+ let expectedMaxAge: number;
28
+
29
+ let geinsCRM: GeinsCRM;
30
+
31
+ beforeEach(() => {
32
+ setCookieSpy = jest.spyOn(CookieService.prototype, 'set');
33
+ removeCookieSpy = jest.spyOn(CookieService.prototype, 'remove');
34
+
35
+ validUserCredentials.rememberUser = true;
36
+ expectedMaxAge = validUserCredentials.rememberUser ? 604800 : 1800;
37
+
38
+ // Initialize GeinsCore and GeinsCRM instance before each test
39
+ const geinsCore = new GeinsCore(validSettings);
40
+ geinsCRM = new GeinsCRM(geinsCore, authSettings);
41
+
42
+ // If useMockFetch is true, set up mock fetch for internal API calls
43
+ if (useMockFetch) {
44
+ const authService = new AuthService(geinsCore.endpoints.authSign, geinsCore.endpoints.auth);
45
+ setupMockFetchForInternalApi(authService);
46
+ }
47
+ setCookieSpy.mockClear();
48
+ });
49
+
50
+ afterEach(() => {
51
+ // Clean up mocks after each test
52
+ jest.clearAllMocks();
53
+ setCookieSpy.mockClear();
54
+ });
55
+
56
+ it('should login a user and update information', async () => {
57
+ const credentials: AuthCredentials = {
58
+ username: validUserCredentials.username,
59
+ password: validUserCredentials.password,
60
+ };
61
+
62
+ // create random user data
63
+ const changedUserInfo = randomUserData();
64
+
65
+ const loginResult = await geinsCRM.auth.login(credentials);
66
+ expect(loginResult).toBeDefined();
67
+ expect(loginResult!.succeeded).toBe(true);
68
+
69
+ // get user information
70
+ const user = await geinsCRM.user.get();
71
+ expect(user).toBeDefined();
72
+ expect(user).toHaveProperty('email');
73
+ expect(user).toHaveProperty('customerType');
74
+ expect(user).toHaveProperty('address');
75
+
76
+ // update user information
77
+ const updateResult = await geinsCRM.user.update(changedUserInfo);
78
+ expect(updateResult).toBeDefined();
79
+ expect(updateResult).toHaveProperty('email');
80
+ expect(updateResult).toHaveProperty('personalId');
81
+ expect(updateResult).toHaveProperty('gender');
82
+ expect(updateResult).toHaveProperty('customerType');
83
+ expect(updateResult).toHaveProperty('address');
84
+
85
+ // check so that the user information has been updated
86
+ expect(updateResult!.personalId).toBe(changedUserInfo.personalId);
87
+ expect(updateResult!.gender).toBe(changedUserInfo.gender);
88
+ expect(updateResult!.customerType).toBe(changedUserInfo.customerType);
89
+
90
+ // clean address object and compare
91
+ const cleanUpdateResult = cleanObject(updateResult);
92
+ expect(cleanUpdateResult!.address).toEqual(changedUserInfo.address);
93
+ });
94
+ });
95
+ }
96
+
97
+ // Define different AuthSettings configurations to test with
98
+ const authSettingsVariations: TestSetupOptions[] = [
99
+ {
100
+ authSettings: {
101
+ clientConnectionMode: 'Direct',
102
+ },
103
+ },
104
+ ];
105
+
106
+ // Use describe.each to run the test suite with different configurations
107
+ describe.each(authSettingsVariations)('GeinsCRM User', options => {
108
+ testGeinsCRM(options);
109
+ });
@@ -0,0 +1,41 @@
1
+ import { CookieService } from '@geins/core';
2
+ import type { AuthResponse, AuthCredentials, AuthTokens, AuthUser } from '@geins/types';
3
+ export declare abstract class AuthClient {
4
+ protected _cookieService: CookieService;
5
+ protected _refreshToken: string | undefined;
6
+ constructor();
7
+ protected abstract handleLogin(credentials: AuthCredentials): Promise<AuthResponse | undefined>;
8
+ protected abstract handleRefresh(refreshToken?: string): Promise<AuthResponse | undefined>;
9
+ protected abstract handleGetUser(refreshToken?: string, userToken?: string): Promise<AuthResponse | undefined>;
10
+ protected abstract handleChangePassword(credentials: AuthCredentials, refreshToken: string): Promise<AuthResponse | undefined>;
11
+ protected abstract handleRegister(credentials: AuthCredentials): Promise<AuthResponse | undefined>;
12
+ login(credentials: AuthCredentials): Promise<AuthResponse | undefined>;
13
+ refresh(refreshToken?: string): Promise<AuthResponse | undefined>;
14
+ getUser(refreshToken?: string, userToken?: string): Promise<AuthResponse | undefined>;
15
+ changePassword(credentials: AuthCredentials, refreshToken?: string): Promise<AuthResponse | undefined>;
16
+ register(credentials: AuthCredentials): Promise<AuthResponse | undefined>;
17
+ private handleUserTokenScenario;
18
+ private refreshUserTokens;
19
+ private handleRefreshTokenOnlyScenario;
20
+ logout(): Promise<AuthResponse | undefined>;
21
+ getUserFromCookie(token?: string, refreshToken?: string): AuthResponse | undefined;
22
+ getCookieTokens(): AuthTokens;
23
+ setRefreshToken(token: string): void;
24
+ protected getCookieUser(): string;
25
+ protected getCookieRefreshToken(): string;
26
+ protected getCookieUserToken(): string;
27
+ protected getCookieMaxAge(): number;
28
+ protected getCurrentTokens(refreshToken?: string, userToken?: string): {
29
+ refreshToken: string | undefined;
30
+ userToken: string | undefined;
31
+ };
32
+ protected setCookieRefreshToken(token: string, maxAge?: number): void;
33
+ protected setCookieUserToken(token: string, maxAge: number): void;
34
+ protected setCookiesTokens(tokens?: AuthTokens, maxAge?: number): void;
35
+ protected setCookiesUser(authUser?: AuthUser, maxAge?: number): void;
36
+ protected setCookiesLogin(authResponse: AuthResponse, rememberUser: boolean): void;
37
+ protected refreshLoginCookies(authResponse: AuthResponse): void;
38
+ clearAuth(): void;
39
+ clearAuthCookies(): void;
40
+ spoofPreviewUser(token: string): string;
41
+ }
@@ -0,0 +1,11 @@
1
+ import type { AuthResponse, AuthCredentials } from '@geins/types';
2
+ import { AuthClient } from './authClient';
3
+ export declare class AuthClientDirect extends AuthClient {
4
+ private _authService;
5
+ constructor(signEndpoint: string, authEndpoint: string);
6
+ protected handleLogin(credentials: AuthCredentials): Promise<AuthResponse | undefined>;
7
+ protected handleRefresh(refreshToken: string): Promise<AuthResponse | undefined>;
8
+ protected handleGetUser(refreshToken: string, userToken?: string): Promise<AuthResponse | undefined>;
9
+ protected handleChangePassword(credentials: AuthCredentials, refreshToken: string): Promise<AuthResponse | undefined>;
10
+ protected handleRegister(credentials: AuthCredentials): Promise<AuthResponse | undefined>;
11
+ }
@@ -0,0 +1,12 @@
1
+ import type { AuthResponse, AuthCredentials } from '@geins/types';
2
+ import { AuthClient } from './authClient';
3
+ export declare class AuthClientProxy extends AuthClient {
4
+ private _authEndpointApp;
5
+ constructor(authEndpointApp: string);
6
+ private request;
7
+ protected handleLogin(credentials: AuthCredentials): Promise<AuthResponse | undefined>;
8
+ protected handleRefresh(refreshToken: string): Promise<AuthResponse | undefined>;
9
+ protected handleGetUser(refreshToken: string, userToken?: string): Promise<AuthResponse | undefined>;
10
+ protected handleChangePassword(credentials: AuthCredentials, refreshToken: string): Promise<AuthResponse | undefined>;
11
+ protected handleRegister(credentials: AuthCredentials): Promise<AuthResponse | undefined>;
12
+ }
@@ -0,0 +1,5 @@
1
+ export declare function authClaimTokenParse(token: string): any;
2
+ export declare function authClaimsTokenSerialize(token: string): string | null;
3
+ export declare function authClaimsTokenSerializeToObject(token: string): Record<string, string> | null;
4
+ export declare function arrayBufferToBase64(buffer: ArrayBuffer): string;
5
+ export declare function digest(password: string): Promise<string>;
@@ -0,0 +1,17 @@
1
+ import type { AuthResponse, AuthCredentials } from '@geins/types';
2
+ export declare class AuthService {
3
+ private signEndpoint;
4
+ private authEndpoint;
5
+ private client;
6
+ private cookieService;
7
+ constructor(signEndpoint: string, authEndpoint: string);
8
+ private initClient;
9
+ private ensureClientInitialized;
10
+ login(credentials: AuthCredentials): Promise<AuthResponse>;
11
+ getUser(refreshToken: string, userToken?: string): Promise<AuthResponse>;
12
+ changePassword(credentials: AuthCredentials, refreshToken: string): Promise<AuthResponse>;
13
+ refresh(refreshToken: string): Promise<AuthResponse>;
14
+ register(credentials: AuthCredentials): Promise<AuthResponse>;
15
+ static getUserObjectFromToken(userToken: string, refreshToken?: string): AuthResponse;
16
+ private handleError;
17
+ }
@@ -0,0 +1,20 @@
1
+ import { type AuthCredentials, type AuthUserToken } from '@geins/core';
2
+ export declare class AuthServiceClient {
3
+ private authEndpoint;
4
+ private signEndpoint;
5
+ constructor(authEndpoint: string, signEndpoint: string);
6
+ private getAuthEndpointUrl;
7
+ private getSignEndpointUrl;
8
+ private extractRefreshTokenFromResponse;
9
+ private requestAuthChallenge;
10
+ private verifyAuthChallenge;
11
+ private fetchUserToken;
12
+ private fetchRefreshToken;
13
+ private performChangePassword;
14
+ private performUserRegister;
15
+ register(username: string, password: string): Promise<AuthUserToken>;
16
+ login(username: string, password: string, rememberUser?: boolean): Promise<AuthUserToken>;
17
+ renewRefreshtoken(refreshToken: string): Promise<AuthUserToken>;
18
+ changePassword(credentials: AuthCredentials, refreshToken: string): Promise<AuthUserToken>;
19
+ logout(refreshToken: string): Promise<boolean>;
20
+ }
@@ -0,0 +1,6 @@
1
+ export * from './authHelpers';
2
+ export * from './authClient';
3
+ export * from './authClientDirect';
4
+ export * from './authClientProxy';
5
+ export * from './authService';
6
+ export * from './authServiceClient';
@@ -0,0 +1,34 @@
1
+ import { GeinsCore, BasePackage } from '@geins/core';
2
+ import { AuthSettings, AuthTokens } from '@geins/types';
3
+ import type { AuthInterface, UserInterface } from './types';
4
+ declare class GeinsCRM extends BasePackage {
5
+ private _authClient;
6
+ private _userService;
7
+ private _passwordResetService;
8
+ private _userOrdersService;
9
+ constructor(core: GeinsCore, authSettings: AuthSettings);
10
+ private initUserService;
11
+ private initPasswordService;
12
+ private initUserOrderService;
13
+ setAuthTokens(tokens: AuthTokens): void;
14
+ clearAuthAndUser(): void;
15
+ spoofUser(token: string): string;
16
+ get auth(): AuthInterface;
17
+ private handleAuthResponse;
18
+ private authAuthorized;
19
+ private authLogin;
20
+ private authLogout;
21
+ private authRefresh;
22
+ private authGetUser;
23
+ get user(): UserInterface;
24
+ private userGet;
25
+ private userUpdate;
26
+ private userRegisterAndCreate;
27
+ private userCreate;
28
+ private userRemove;
29
+ private userOrders;
30
+ private userChangePassword;
31
+ private userPasswordResetRequest;
32
+ private userPasswordResetCommit;
33
+ }
34
+ export { GeinsCRM };
@@ -0,0 +1 @@
1
+ export * from './queries';
@@ -0,0 +1,12 @@
1
+ declare const queries: {
2
+ userGet: string;
3
+ userOrders: string;
4
+ };
5
+ declare const mutations: {
6
+ userRegister: string;
7
+ userUpdate: string;
8
+ userDelete: string;
9
+ pwResetRequest: string;
10
+ pwResetCommit: string;
11
+ };
12
+ export { queries, mutations };