@amedia/user 0.5.2 → 0.6.0

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 (58) hide show
  1. package/README.md +2 -2
  2. package/cloudbuild.json +29 -0
  3. package/cop.json +8 -0
  4. package/dist/actions/authentication.d.ts +1 -1
  5. package/dist/actions/preferences.d.ts +9 -0
  6. package/dist/actions/preferences.spec.d.ts +1 -0
  7. package/dist/cache/index.d.ts +3 -2
  8. package/dist/clients/europa.d.ts +12 -0
  9. package/dist/clients/europa.spec.d.ts +1 -0
  10. package/dist/clients/jupiter.d.ts +29 -0
  11. package/dist/clients/jupiter.spec.d.ts +1 -0
  12. package/dist/clients/mercury.d.ts +18 -0
  13. package/dist/clients/mercury.spec.d.ts +4 -0
  14. package/dist/clients/nebula.d.ts +22 -0
  15. package/dist/clients/nebula.spec.d.ts +1 -0
  16. package/dist/clients/pluto.d.ts +8 -0
  17. package/dist/clients/pluto.spec.d.ts +1 -0
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.js +1 -1
  20. package/dist/lib/rpc.d.ts +6 -1
  21. package/dist/services/europa.d.ts +12 -0
  22. package/dist/services/europa.spec.d.ts +1 -0
  23. package/dist/services/nebula.d.ts +22 -0
  24. package/dist/services/nebula.spec.d.ts +1 -0
  25. package/dist/store/store.d.ts +13 -0
  26. package/dist/store/store.spec.d.ts +1 -0
  27. package/dist/types.d.ts +7 -0
  28. package/dist/utils/getOrUpdate.d.ts +3 -0
  29. package/package.json +4 -3
  30. package/src/actions/authentication.ts +2 -2
  31. package/src/actions/authorization.ts +4 -7
  32. package/src/actions/preferences.spec.ts +54 -0
  33. package/src/actions/preferences.ts +69 -0
  34. package/src/actions/userData.ts +2 -0
  35. package/src/cache/index.spec.ts +7 -2
  36. package/src/cache/index.ts +4 -3
  37. package/src/clients/europa.spec.ts +93 -0
  38. package/src/clients/europa.ts +126 -0
  39. package/src/clients/jupiter.spec.ts +154 -0
  40. package/src/{services → clients}/jupiter.ts +0 -1
  41. package/src/clients/mercury.spec.ts +70 -0
  42. package/src/clients/nebula.spec.ts +71 -0
  43. package/src/clients/nebula.ts +51 -0
  44. package/src/index-authentcation.spec.ts +2 -2
  45. package/src/index-userdata.spec.ts +11 -11
  46. package/src/index.ts +4 -3
  47. package/src/lib/rpc.ts +9 -3
  48. package/src/store/store.spec.ts +34 -0
  49. package/src/store/store.ts +46 -0
  50. package/src/types.ts +8 -0
  51. package/src/utils/getOrUpdate.ts +41 -0
  52. package/src/utils/log.ts +2 -1
  53. package/src/utils/queue.ts +0 -2
  54. package/src/services/jupiter.spec.ts +0 -150
  55. package/src/services/mercury.spec.ts +0 -30
  56. /package/src/{services → clients}/mercury.ts +0 -0
  57. /package/src/{services → clients}/pluto.spec.ts +0 -0
  58. /package/src/{services → clients}/pluto.ts +0 -0
@@ -1,150 +0,0 @@
1
- /* eslint-disable no-console */
2
- import fetch from 'jest-fetch-mock';
3
- import log from '../utils/log';
4
- import {
5
- checkForAccess,
6
- getVstoken,
7
- AccessFeatures,
8
- CheckAccessForPaper,
9
- GetVstoken,
10
- GetNonUserAccess,
11
- getNonUserAccess,
12
- } from './jupiter';
13
-
14
- beforeEach(() => {
15
- fetch.resetMocks();
16
- });
17
-
18
- describe('/check_access_for_paper', () => {
19
- const publicationDomain = 'www.rb.no';
20
- const accessFeatures: AccessFeatures = ['newspaper'];
21
-
22
- it('should check access for paper', async () => {
23
- const response: CheckAccessForPaper = {
24
- status: 'success',
25
- access: 'granted',
26
- publication: {
27
- domain: 'www.rb.no',
28
- id: 95,
29
- },
30
- access_features: ['amedia_staff', 'newspaper'],
31
- };
32
-
33
- fetch.mockResponseOnce(JSON.stringify(response));
34
-
35
- await expect(
36
- checkForAccess(publicationDomain, accessFeatures)
37
- ).resolves.toEqual(response);
38
- expect(fetch).toHaveBeenCalledWith(
39
- `/api/jupiter/v1/check_access_for_paper/${publicationDomain}/?require=any&access_features=${accessFeatures.join(
40
- ','
41
- )}`
42
- );
43
- });
44
-
45
- it('should deny access for user not logged in', async () => {
46
- fetch.mockResponseOnce(JSON.stringify({ status: 'no_session_found' }), {
47
- status: 400,
48
- });
49
-
50
- await expect(
51
- checkForAccess(publicationDomain, accessFeatures)
52
- ).rejects.toThrow('Request not ok (400: Bad Request).');
53
- });
54
-
55
- it('should fail on runtime validation', async () => {
56
- fetch.mockResponseOnce(JSON.stringify({ access_features: 'foo' }));
57
- log.error = jest.fn();
58
-
59
- await expect(
60
- checkForAccess(publicationDomain, accessFeatures)
61
- ).rejects.toThrow(
62
- 'Expected { status: "success"; access: "granted" | "denied"; publication: { id: number; domain: string; }; access_features: string[]; }, but was incompatible'
63
- );
64
- });
65
- });
66
-
67
- describe('/get_vstoken', () => {
68
- const publicationDomain = 'www.rb.no';
69
-
70
- it('should return vstoken', async () => {
71
- const response: GetVstoken = {
72
- status: 'success',
73
- cookie: 'ofofb:16187:amedia_staff,newspaper,plussalt:cc2c2c:rb:jupiter',
74
- access_features: ['newspaper', 'plussalt'],
75
- };
76
-
77
- fetch.mockResponseOnce(JSON.stringify(response));
78
-
79
- await expect(getVstoken(publicationDomain)).resolves.toEqual(response);
80
- expect(fetch).toHaveBeenCalledWith(
81
- `/api/jupiter/v1/get_vstoken/${publicationDomain}`,
82
- {
83
- method: 'post',
84
- }
85
- );
86
- });
87
-
88
- it('should deny access for user not logged in', async () => {
89
- fetch.mockResponseOnce(JSON.stringify({ status: 'no_session_found' }), {
90
- status: 400,
91
- });
92
-
93
- await expect(getVstoken(publicationDomain)).rejects.toThrow(
94
- 'Request not ok (400: Bad Request).'
95
- );
96
- });
97
-
98
- it('should fail on runtime validation', async () => {
99
- fetch.mockResponseOnce(JSON.stringify({ access_features: 'foo' }));
100
- log.error = jest.fn();
101
-
102
- await expect(getVstoken(publicationDomain)).rejects.toThrow(
103
- 'Expected { status: "success"; cookie: string; access_features: string[]; }, but was incompatible'
104
- );
105
- });
106
- });
107
-
108
- describe('/non_user_access', () => {
109
- const publicationDomain = 'www.rb.no';
110
-
111
- it('should return none user access', async () => {
112
- const response: GetNonUserAccess = {
113
- status: 'success',
114
- vstoken_cookie: 'd82ab3842a:2619693230:::rb:jupiter',
115
- uuid: '',
116
- access_features: [],
117
- };
118
-
119
- fetch.mockResponseOnce(JSON.stringify(response));
120
-
121
- await expect(getNonUserAccess(publicationDomain)).resolves.toEqual(
122
- response
123
- );
124
- expect(
125
- fetch
126
- ).toHaveBeenCalledWith(
127
- `/api/jupiter/v1/non_user_access/${publicationDomain}`,
128
- { method: 'post' }
129
- );
130
- });
131
-
132
- it('should deny access for user not logged in', async () => {
133
- fetch.mockResponseOnce(JSON.stringify({ status: 'no_session_found' }), {
134
- status: 400,
135
- });
136
-
137
- await expect(getNonUserAccess(publicationDomain)).rejects.toThrow(
138
- 'Request not ok (400: Bad Request).'
139
- );
140
- });
141
-
142
- it('should fail on runtime validation', async () => {
143
- fetch.mockResponseOnce(JSON.stringify({ vstoken_cookie: 3 }));
144
- log.error = jest.fn();
145
-
146
- await expect(getNonUserAccess(publicationDomain)).rejects.toThrow(
147
- 'Expected { status: "success"; vstoken_cookie: string; uuid: string; access_features: string[]; }, but was incompatible'
148
- );
149
- });
150
- });
@@ -1,30 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
- import fetch from 'jest-fetch-mock';
6
- import backendLog from './mercury';
7
-
8
- fetch.enableMocks();
9
-
10
- beforeEach(() => {
11
- fetch.resetMocks();
12
- });
13
-
14
- describe('Mercury backendlog', () => {
15
- it('should include level in url', () => {
16
- backendLog.error('jest message', {});
17
- expect(fetch).toHaveBeenCalledWith(
18
- expect.stringContaining('/error'),
19
- expect.anything()
20
- );
21
- expect(fetch).toHaveBeenCalledTimes(1);
22
- });
23
-
24
- it('should include additional context as query parameters', () => {
25
- backendLog.error('jest message', { referrer: 'https://www.rb.no/' });
26
- const formData = fetch.mock.calls[0][1]?.body as FormData;
27
-
28
- expect(formData?.get('referrer')).toEqual('https://www.rb.no/');
29
- });
30
- });
File without changes
File without changes
File without changes