@amedia/user 0.1.0 → 0.1.1

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 (40) hide show
  1. package/dist/index.d.ts +206 -20
  2. package/dist/index.js +493 -40
  3. package/package.json +1 -1
  4. package/src/services/mercury.spec.ts +4 -1
  5. package/src/services/mercury.ts +2 -5
  6. package/src/services/pluto.spec.ts +38 -0
  7. package/src/services/pluto.ts +11 -0
  8. package/tsconfig.json +4 -4
  9. package/dist/lib/authentication.d.ts +0 -20
  10. package/dist/lib/authentication.js +0 -78
  11. package/dist/lib/authorization.d.ts +0 -15
  12. package/dist/lib/authorization.js +0 -55
  13. package/dist/lib/cache/db.d.ts +0 -6
  14. package/dist/lib/cache/db.js +0 -13
  15. package/dist/lib/cache/global.d.ts +0 -9
  16. package/dist/lib/cache/global.js +0 -16
  17. package/dist/lib/cache/types.d.ts +0 -5
  18. package/dist/lib/cache/types.js +0 -2
  19. package/dist/lib/dataOrganizer.d.ts +0 -9
  20. package/dist/lib/dataOrganizer.js +0 -14
  21. package/dist/lib/eventHandler.d.ts +0 -3
  22. package/dist/lib/eventHandler.js +0 -11
  23. package/dist/lib/queue.d.ts +0 -5
  24. package/dist/lib/queue.js +0 -17
  25. package/dist/lib/tools.d.ts +0 -1
  26. package/dist/lib/tools.js +0 -2
  27. package/dist/lib/types.d.ts +0 -7
  28. package/dist/lib/types.js +0 -2
  29. package/dist/lib/user.d.ts +0 -2
  30. package/dist/lib/user.js +0 -5
  31. package/dist/lib/userAttributes.d.ts +0 -12
  32. package/dist/lib/userAttributes.js +0 -18
  33. package/dist/services/cache.d.ts +0 -9
  34. package/dist/services/cache.js +0 -34
  35. package/dist/services/jupiter.d.ts +0 -29
  36. package/dist/services/jupiter.js +0 -74
  37. package/dist/services/mercury.d.ts +0 -15
  38. package/dist/services/mercury.js +0 -32
  39. package/dist/services/pluto.d.ts +0 -12
  40. package/dist/services/pluto.js +0 -40
package/dist/index.d.ts CHANGED
@@ -1,20 +1,206 @@
1
- import { UserAttributes } from './lib/types';
2
- /**
3
- * Enables you to subscribe to the user attributes you care about and
4
- * get notified when something changes
5
- *
6
- * If you're wondering about the typing mechanism, here's a good article:
7
- * https://dev.to/shakyshane/2-ways-to-create-a-union-from-an-array-in-typescript-1kd6
8
- *
9
- * @todo We should discuss whether we should support to stop subscribing
10
- * @todo or resubscribe with different attributes.
11
- * @param attributes
12
- * @param onUserUpdated
13
- */
14
- export declare const subscribeToUserUpdates: <T extends (keyof UserAttributes)[]>(attributes: T, onUserUpdated: (attributes: Pick<UserAttributes, "isLoggedIn" | T[number]>) => void) => void;
15
- /**
16
- * This will, if necessary, trigger a redirect to www.aid.no and return
17
- * to the requestedUrl if supplied or the current url before redirecting away if not.
18
- * @param requestedUrl
19
- */
20
- export declare const requestLogin: (requestedUrl?: string | undefined) => void;
1
+ declare module "lib/cache/global" {
2
+ export const get: (key: string) => Promise<unknown>;
3
+ export const set: (key: string, data: unknown, expires: number) => Promise<void>;
4
+ export const remove: (key: string) => Promise<void>;
5
+ const _default: {
6
+ get: (key: string) => Promise<unknown>;
7
+ set: (key: string, data: unknown, expires: number) => Promise<void>;
8
+ remove: (key: string) => Promise<void>;
9
+ };
10
+ export default _default;
11
+ }
12
+ declare module "lib/cache/types" {
13
+ export type Engine = {
14
+ get: (key: string) => Promise<unknown>;
15
+ set: (key: string, data: unknown, expires: number) => Promise<void>;
16
+ remove: (key: string) => Promise<void>;
17
+ };
18
+ }
19
+ declare module "services/cache" {
20
+ import { Record, Static } from 'runtypes';
21
+ import { Engine } from "lib/cache/types";
22
+ export const setCacheEngine: (engine: Engine) => void;
23
+ const _default_1: {
24
+ get: <T extends Record<any, any>>(key: string, validator: T) => Promise<void | Static<T>>;
25
+ set: (key: string, value: unknown, expires: number) => Promise<void>;
26
+ remove: (key: string) => Promise<void>;
27
+ };
28
+ export default _default_1;
29
+ }
30
+ declare module "services/pluto" {
31
+ import { Optional, Record, Static, String } from 'runtypes';
32
+ export const SessionSchema: Record<{
33
+ created_at: String;
34
+ updated_at: String;
35
+ user_uuid: String;
36
+ user_name: String;
37
+ tracking_key: String;
38
+ user_agent: Optional<String>;
39
+ user_key: Optional<String>;
40
+ }, false>;
41
+ export type Session = Static<typeof SessionSchema>;
42
+ export const getCurrentSession: () => Promise<Session>;
43
+ export const removeSession: (domain: string) => Promise<void>;
44
+ }
45
+ declare module "lib/eventHandler" {
46
+ export const setRootElement: (element: any) => void;
47
+ export const listen: <T extends keyof WindowEventMap>(type: T, listener: (this: Window, ev: WindowEventMap[T]) => void) => void;
48
+ export const dispatch: <T extends Event>(event: T) => void;
49
+ }
50
+ declare module "lib/authentication" {
51
+ import { Session } from "services/pluto";
52
+ export enum AuthenticationEvents {
53
+ REQUEST_LOGIN = "amedia_user.authentication.request_login",
54
+ REQUEST_LOGOUT = "amedia_user.authentication.request_logout",
55
+ REQUEST_AUTH_STATE = "amedia_user.authentication.request_auth_state",
56
+ ON_AUTH_STATE_UPDATED = "amedia_user.authentication.on_auth_state_updated"
57
+ }
58
+ global {
59
+ interface WindowEventMap {
60
+ [AuthenticationEvents.REQUEST_LOGIN]: CustomEvent<{
61
+ requestedUrl?: string;
62
+ }>;
63
+ [AuthenticationEvents.REQUEST_LOGOUT]: CustomEvent<{
64
+ requestedUrl?: string;
65
+ }>;
66
+ [AuthenticationEvents.REQUEST_AUTH_STATE]: CustomEvent<Session>;
67
+ [AuthenticationEvents.ON_AUTH_STATE_UPDATED]: CustomEvent<Session>;
68
+ }
69
+ }
70
+ export const listenForAuthenticationRequests: () => void;
71
+ }
72
+ declare module "lib/types" {
73
+ export type UserAttributes = {
74
+ isLoggedIn?: boolean;
75
+ name?: string;
76
+ email?: string;
77
+ phone?: string;
78
+ trackingKey?: string;
79
+ };
80
+ }
81
+ declare module "lib/dataOrganizer" {
82
+ import { UserAttributes } from "lib/types";
83
+ /**
84
+ * Jeg tror ikke vi burde gjøre det slik som dette.
85
+ * Denne funksjonen var hentet ut fra userAttribute kun for å
86
+ * kunne mocke implementasjonen så jeg kunne teste event-callback mekanismen.
87
+ *
88
+ * En implementasjon som dette vil gjøre det vanskelig svare etterhvert som vi får data.
89
+ */
90
+ export const fetchDataBasedOnAttributes: (attributes: (keyof UserAttributes)[]) => UserAttributes;
91
+ }
92
+ declare module "lib/userAttributes" {
93
+ import { UserAttributes } from "lib/types";
94
+ export enum AmediaUserEvents {
95
+ REQUEST_USER_ATTRIBUTES = "amedia-user.request-user-attributes",
96
+ ON_USER_ATTRIBUTES_UPDATED = "amedia-user.on-user-attributes-updated"
97
+ }
98
+ global {
99
+ interface WindowEventMap {
100
+ [AmediaUserEvents.REQUEST_USER_ATTRIBUTES]: CustomEvent<Array<keyof UserAttributes>>;
101
+ [AmediaUserEvents.ON_USER_ATTRIBUTES_UPDATED]: CustomEvent<UserAttributes>;
102
+ }
103
+ }
104
+ export const listenForUserAttributeRequests: () => void;
105
+ }
106
+ declare module "index" {
107
+ import { UserAttributes } from "lib/types";
108
+ /**
109
+ * Enables you to subscribe to the user attributes you care about and
110
+ * get notified when something changes
111
+ *
112
+ * If you're wondering about the typing mechanism, here's a good article:
113
+ * https://dev.to/shakyshane/2-ways-to-create-a-union-from-an-array-in-typescript-1kd6
114
+ *
115
+ * @todo We should discuss whether we should support to stop subscribing
116
+ * @todo or resubscribe with different attributes.
117
+ * @param attributes
118
+ * @param onUserUpdated
119
+ */
120
+ export const subscribeToUserUpdates: <T extends (keyof UserAttributes)[]>(attributes: T, onUserUpdated: (attributes: Pick<UserAttributes, "isLoggedIn" | T[number]>) => void) => void;
121
+ /**
122
+ * This will, if necessary, trigger a redirect to www.aid.no and return
123
+ * to the requestedUrl if supplied or the current url before redirecting away if not.
124
+ * @param requestedUrl
125
+ */
126
+ export const requestLogin: (requestedUrl?: string | undefined) => void;
127
+ }
128
+ declare module "services/jupiter" {
129
+ import { Array, Literal, Record, Static, String, Number, Union } from 'runtypes';
130
+ export type AccessFeatures = string[];
131
+ export const CheckAccessForPaperSchema: Record<{
132
+ status: Literal<"success">;
133
+ access: Union<[Literal<"granted">, Literal<"denied">]>;
134
+ publication: Record<{
135
+ id: Number;
136
+ domain: String;
137
+ }, false>;
138
+ access_features: Array<String, false>;
139
+ }, false>;
140
+ export type CheckAccessForPaper = Static<typeof CheckAccessForPaperSchema>;
141
+ const GetVstokenSchema: Record<{
142
+ status: Literal<"success">;
143
+ cookie: String;
144
+ access_features: Array<String, false>;
145
+ }, false>;
146
+ export type GetVstoken = Static<typeof GetVstokenSchema>;
147
+ const GetNonUserAccessSchema: Record<{
148
+ status: Literal<"success">;
149
+ vstoken_cookie: String;
150
+ uuid: String;
151
+ access_features: Array<String, false>;
152
+ }, false>;
153
+ export type GetNonUserAccess = Static<typeof GetNonUserAccessSchema>;
154
+ export const checkForAccess: (publicationDomain: string, accessFeatures: AccessFeatures) => Promise<CheckAccessForPaper>;
155
+ export const getVstoken: (publicationDomain: string) => Promise<GetVstoken>;
156
+ export const getNonUserAccess: (publicationDomain: string) => Promise<GetNonUserAccess>;
157
+ }
158
+ declare module "lib/authorization" {
159
+ import { AccessFeatures, CheckAccessForPaper } from "services/jupiter";
160
+ export enum AuthorizationEvents {
161
+ REQUEST_PUBLICATION_ACCESS_STATE_CHECK = "amedia_user.authorization.request_publication_access_state_check",
162
+ ON_PUBLICATION_ACCESS_STATE_UPDATED = "amedia_user.authorization.on_publication_access_state_updated"
163
+ }
164
+ global {
165
+ interface WindowEventMap {
166
+ [AuthorizationEvents.REQUEST_PUBLICATION_ACCESS_STATE_CHECK]: CustomEvent<{
167
+ publicationDomain: string;
168
+ accessFeatures: AccessFeatures;
169
+ }>;
170
+ [AuthorizationEvents.ON_PUBLICATION_ACCESS_STATE_UPDATED]: CustomEvent<CheckAccessForPaper>;
171
+ }
172
+ }
173
+ export const listenForAuthorizationRequests: () => void;
174
+ }
175
+ declare module "lib/queue" {
176
+ const _default_2: {
177
+ add: (key: string, data: unknown) => void;
178
+ getAll: (key: string) => unknown[];
179
+ };
180
+ export default _default_2;
181
+ }
182
+ declare module "lib/cache/db" {
183
+ import { Engine } from "lib/cache/types";
184
+ export const get: (key: string) => Promise<unknown>;
185
+ export const set: (key: string, data: unknown, expires: number) => Promise<void>;
186
+ export const remove: (key: string) => Promise<void>;
187
+ const _default_3: Engine;
188
+ export default _default_3;
189
+ }
190
+ declare module "services/mercury" {
191
+ const log: {
192
+ error: (message: string, context: {
193
+ [index: string]: any;
194
+ }) => void;
195
+ warn: (message: string, context: {
196
+ [index: string]: any;
197
+ }) => void;
198
+ info: (message: string, context: {
199
+ [index: string]: any;
200
+ }) => void;
201
+ debug: (message: string, context: {
202
+ [index: string]: any;
203
+ }) => void;
204
+ };
205
+ export default log;
206
+ }