@amedia/user 0.5.3 → 0.6.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 (50) 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 -3
  6. package/dist/cache/index.d.ts +3 -2
  7. package/dist/clients/europa.d.ts +12 -0
  8. package/dist/clients/europa.spec.d.ts +1 -0
  9. package/dist/clients/jupiter.d.ts +29 -0
  10. package/dist/clients/jupiter.spec.d.ts +1 -0
  11. package/dist/clients/mercury.d.ts +18 -0
  12. package/dist/clients/mercury.spec.d.ts +4 -0
  13. package/dist/clients/nebula.d.ts +22 -0
  14. package/dist/clients/nebula.spec.d.ts +1 -0
  15. package/dist/clients/pluto.d.ts +8 -0
  16. package/dist/clients/pluto.spec.d.ts +1 -0
  17. package/dist/index.d.ts +2 -2
  18. package/dist/index.js +1 -1
  19. package/dist/lib/rpc.d.ts +6 -1
  20. package/dist/store/store.d.ts +13 -0
  21. package/dist/store/store.spec.d.ts +1 -0
  22. package/dist/types.d.ts +7 -0
  23. package/dist/utils/getOrUpdate.d.ts +3 -0
  24. package/package.json +4 -3
  25. package/src/actions/authentication.ts +2 -2
  26. package/src/actions/authorization.ts +4 -7
  27. package/src/actions/preferences.spec.ts +4 -5
  28. package/src/actions/preferences.ts +49 -47
  29. package/src/actions/userData.ts +2 -0
  30. package/src/cache/index.spec.ts +7 -2
  31. package/src/cache/index.ts +4 -3
  32. package/src/{services → clients}/europa.spec.ts +19 -20
  33. package/src/{services → clients}/europa.ts +8 -12
  34. package/src/{services → clients}/mercury.ts +0 -1
  35. package/src/index-authentcation.spec.ts +2 -2
  36. package/src/index-userdata.spec.ts +11 -11
  37. package/src/index.ts +4 -3
  38. package/src/lib/rpc.ts +9 -3
  39. package/src/store/store.spec.ts +34 -0
  40. package/src/store/store.ts +46 -0
  41. package/src/types.ts +8 -0
  42. package/src/utils/getOrUpdate.ts +41 -0
  43. package/src/utils/log.ts +2 -1
  44. /package/src/{services → clients}/jupiter.spec.ts +0 -0
  45. /package/src/{services → clients}/jupiter.ts +0 -0
  46. /package/src/{services → clients}/mercury.spec.ts +0 -0
  47. /package/src/{services → clients}/nebula.spec.ts +0 -0
  48. /package/src/{services → clients}/nebula.ts +0 -0
  49. /package/src/{services → clients}/pluto.spec.ts +0 -0
  50. /package/src/{services → clients}/pluto.ts +0 -0
package/README.md CHANGED
@@ -17,8 +17,8 @@ const onUserAttributesUpdated = (attributes) => {
17
17
  console.log(attributes);
18
18
  }
19
19
 
20
- const onStateUpdated = (state) => {
21
- console.log(state)
20
+ const onStateUpdated = (store) => {
21
+ console.log(store)
22
22
  }
23
23
 
24
24
  subscribeToUserUpdates(['name', 'email'], onUserAttributesUpdated, onStateUpdated);
@@ -0,0 +1,29 @@
1
+ {
2
+ "steps": [
3
+ {
4
+ "name": "eu.gcr.io/amedia-core/ci/images/npm:14.13.1",
5
+ "args": ["install"]
6
+ },
7
+ {
8
+ "name": "eu.gcr.io/amedia-core/ci/images/npm:14.13.1",
9
+ "args": ["run", "lint"]
10
+ },
11
+ {
12
+ "name": "eu.gcr.io/amedia-core/ci/images/npm:14.13.1",
13
+ "args": ["test"]
14
+ },
15
+ {
16
+ "name": "eu.gcr.io/amedia-core/ci/images/codeclimate-node:latest",
17
+ "env": [
18
+ "NODE_ENV=production",
19
+ "GIT_COMMIT_SHA=$COMMIT_SHA",
20
+ "GIT_BRANCH=$BRANCH_NAME",
21
+ "CC_TEST_REPORTER_ID=3bef6affe49c4a30d03c2acf478183da25266aace083a76157cb902c1348521a",
22
+ "COVERAGE_IN=/workspace/coverage/lcov.info",
23
+ "COVERAGE_OUT=/workspace/coverage/lcov.json",
24
+ "MODULE_PREFIX=/workspace"
25
+ ],
26
+ "dir": "${_DIR}"
27
+ }
28
+ ]
29
+ }
package/cop.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "cop.version": 1.0,
3
+ "ci": [
4
+ {
5
+ "buildfile": "cloudbuild.json"
6
+ }
7
+ ]
8
+ }
@@ -1,4 +1,4 @@
1
- import { Session } from '../services/pluto';
1
+ import { Session } from '../clients/pluto';
2
2
  export declare const login: (requestedUrl: string) => void;
3
3
  export declare const logout: () => Promise<void>;
4
4
  export declare const getSession: () => Promise<Session | null>;
@@ -1,3 +1,9 @@
1
- export declare const setIsCallingPrivacyPreferences: (value: boolean) => boolean;
2
- declare const privacyPreferences: () => Promise<unknown>;
3
- export default privacyPreferences;
1
+ import { Record, Boolean } from 'runtypes';
2
+ import { UserAttributes } from '../types';
3
+ export declare const PrivacyPreferencesSchema: Record<{
4
+ allowResearchUsage: Boolean;
5
+ connectWithSurveys: Boolean;
6
+ personalizedAds: Boolean;
7
+ personalizedContent: Boolean;
8
+ }, false>;
9
+ export declare const getPrivacyPreferences: () => Promise<UserAttributes>;
@@ -1,8 +1,9 @@
1
- import { Record, Static } from 'runtypes';
1
+ import { Static } from 'runtypes';
2
+ import { RuntypeBase } from 'runtypes/lib/runtype';
2
3
  import { Engine } from './types';
3
4
  export declare const setCacheEngine: (engine: Engine) => void;
4
5
  declare const _default: {
5
- get: <T extends Record<any, any>>(key: string, validator: T) => Promise<void | Static<T>>;
6
+ get: <T extends RuntypeBase<unknown>>(key: string, validator: T) => Promise<void | Static<T>>;
6
7
  set: (key: string, value: unknown, expires: number) => Promise<void>;
7
8
  remove: (key: string) => Promise<void>;
8
9
  clear: () => Promise<void>;
@@ -0,0 +1,12 @@
1
+ import { Record, Partial } from 'runtypes';
2
+ export declare const EuropaSchema: Record<{
3
+ namespaces: Partial<{}, false>;
4
+ }, false>;
5
+ export declare const clearLocalCache: () => Promise<void>;
6
+ export declare const updateNamespace: (namespace: string, data: Object) => Promise<void | {}>;
7
+ export declare const getNamespace: (namespace: string, options?: {
8
+ ignoreCache: boolean;
9
+ }) => Promise<any>;
10
+ export declare const saveNamespace: (namespace: string, data: Object) => Promise<any>;
11
+ export declare const getAllNamespaces: () => Promise<{}>;
12
+ export declare const deleteNamespaceKey: (namespace: string, key: string) => Promise<any>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ import { Array, Literal, Record, Static, String, Number, Union } from 'runtypes';
2
+ export declare type AccessFeatures = string[];
3
+ export declare const CheckAccessForPaperSchema: Record<{
4
+ status: Literal<"success">;
5
+ access: Union<[Literal<"granted">, Literal<"denied">]>;
6
+ publication: Record<{
7
+ id: Number;
8
+ domain: String;
9
+ }, false>;
10
+ access_features: Array<String, false>;
11
+ }, false>;
12
+ export declare type CheckAccessForPaper = Static<typeof CheckAccessForPaperSchema>;
13
+ declare const GetVstokenSchema: Record<{
14
+ status: Literal<"success">;
15
+ cookie: String;
16
+ access_features: Array<String, false>;
17
+ }, false>;
18
+ export declare type GetVstoken = Static<typeof GetVstokenSchema>;
19
+ declare const GetNonUserAccessSchema: Record<{
20
+ status: Literal<"success">;
21
+ vstoken_cookie: String;
22
+ uuid: String;
23
+ access_features: Array<String, false>;
24
+ }, false>;
25
+ export declare type GetNonUserAccess = Static<typeof GetNonUserAccessSchema>;
26
+ export declare const checkForAccess: (publicationDomain: string, accessFeatures: AccessFeatures) => Promise<CheckAccessForPaper>;
27
+ export declare const getVstoken: (publicationDomain: string) => Promise<GetVstoken>;
28
+ export declare const getNonUserAccess: (publicationDomain: string) => Promise<GetNonUserAccess>;
29
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ declare const log: {
2
+ error: (message: string, context: {
3
+ [index: string]: any;
4
+ }) => void;
5
+ warn: (message: string, context: {
6
+ [index: string]: any;
7
+ }) => void;
8
+ info: (message: string, context: {
9
+ [index: string]: any;
10
+ }) => void;
11
+ debug: (message: string, context: {
12
+ [index: string]: any;
13
+ }) => void;
14
+ };
15
+ export declare class UserDeactivatedError extends Error {
16
+ }
17
+ export declare const activateSubscription: (accessFeature: string) => Promise<boolean>;
18
+ export default log;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,22 @@
1
+ import { Static, Partial, Dictionary, Unknown, String, Number, Boolean } from 'runtypes';
2
+ declare const InfoSchema: import("runtypes").Intersect<[Dictionary<Unknown, string>, Partial<{
3
+ ad_segments: String;
4
+ ad_segments_user: String;
5
+ age: Number;
6
+ age_user: Number;
7
+ birth_year: String;
8
+ birth_year_user: String;
9
+ gender: String;
10
+ gender_user: String;
11
+ grunnkrets: String;
12
+ grunnkrets_user: String;
13
+ postcode: String;
14
+ postcode_user: String;
15
+ shared_account: Boolean;
16
+ shared_account_user: Boolean;
17
+ user_grouping_number: String;
18
+ user_grouping_number_user: String;
19
+ }, false>]>;
20
+ export declare type Info = Static<typeof InfoSchema>;
21
+ export declare const getInfo: (userKey: string, publicationDomain: string, browserId: string) => Promise<Info>;
22
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { Record, Static, String } from 'runtypes';
2
+ export declare const InternalSessionSchema: Record<{
3
+ name: String;
4
+ trackingKey: String;
5
+ }, false>;
6
+ export declare type Session = Static<typeof InternalSessionSchema>;
7
+ export declare const getCurrentSession: () => Promise<Session>;
8
+ export declare const removeSession: (domain: string) => Promise<void>;
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -4,13 +4,13 @@ import { State, UserAttributes } from './types';
4
4
  * Enables you to subscribe to the user attributes you care about and
5
5
  * get notified when something changes
6
6
  */
7
- export declare const subscribeToUserUpdates: <T extends (keyof UserAttributes)[]>(attributes: T, onUserUpdated: (attributes: Pick<UserAttributes, T[number]>) => void, onStateUpdated?: ((attributes: State) => void) | undefined) => void;
7
+ export declare const subscribeToUserAttributes: <T extends (keyof UserAttributes)[]>(attributes: T, onUserUpdated: (attributes: Pick<UserAttributes, T[number]>) => void, onStateUpdated?: ((attributes: State) => void) | undefined) => void;
8
8
  /**
9
9
  * This will, if necessary, trigger a redirect to www.aid.no and return
10
10
  * to the requestedUrl if supplied or the current url before redirecting away if not.
11
11
  * @param requestedUrl
12
12
  */
13
- export declare const login: (requestedUrl?: string | undefined) => void;
13
+ export declare const goToLoginPage: (requestedUrl?: string | undefined) => void;
14
14
  export declare const logout: () => Promise<void>;
15
15
  export declare const tryActivateSubscriptionAccess: (access: string) => Promise<{
16
16
  hasAccess: boolean;