@amedia/user 0.14.96 → 0.14.97

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/README.md CHANGED
@@ -278,6 +278,7 @@ To unlock the paywall, you first need to create a new `PaywallUnlockRequest`. On
278
278
  - `withAccessFeatures(accessFeatures: string[])`: Specify what access features will give access to the current content.
279
279
  The default is [`newspaper`].
280
280
  - `withSiteDomain(domain: string)`: Specify which site we to attempt activation against. The default is the current domain. This is mostly useful for direktesport.no which often knows what domain the user came from.
281
+ - **DEPRECATED**: This will fail if you attempt to unlock a paywall on a page without a paywall or its own access features. Feature will be removed in the next major release. Use [SiteAccessRequest](#activating-subscriptions--finding-upgrade-path) instead.
281
282
 
282
283
  More details about the access model can be found here: [Access model](https://amedia.slite.com/app/channels/hOlqx3Miez/notes/nhG2Ok39BN)
283
284
 
@@ -328,6 +329,56 @@ new PaywallUnlockRequest()
328
329
 
329
330
  Note that this _might result in redirects/reloads_ if the user is not already logged in. In that case you will end up here again if logging in did not result in access.
330
331
 
332
+ ## Activating subscriptions / finding upgrade path
333
+
334
+ Check the current users access on a specific site. If you're on a site that has its own access features (e.g. has a paywall), you should use PaywallUnlockRequest instead. This will set cookies as well.
335
+
336
+ - `withSiteDomain(siteDomain: string)` The domain you with to check access for / attempt activation against.
337
+ - `withAccessFeatures(accessFeatures: Array<string>)` Which access features do you require in order to consider access is granted.
338
+
339
+ Once your options have been set up, you can call `requestAccess()`. This is when all the magic happens. It will try to auto login the user on the current domain, check access, activate subscriptions in the subscription systems, check for stuff like IP based access etc. When this is done, it will resolve the `Promise` that was returned.
340
+
341
+ The resolved promise contains the following:
342
+
343
+ - isLoggedIn: True if the user is logged in, false otherwise. Useful if you want to show a login button (see [goToLoginPage(...)](#gotologinpagerequestedurl-string-context-string-void)).
344
+ - hasAccess: True if the user has access that fulfils your `withAccessFeatures`-requirements.
345
+ - accessFeatures: List of access features the user actually has at this time. Empty list if user is logged out or has no access. This list is useful if you want to upgrade from 'newspaper' to 'plussalt' for instance. You might want to give a different user experience to users with some access than users with no access.
346
+ - primarySite: Best guess of where the user may attain the access you requested.
347
+
348
+ Full usage example:
349
+
350
+ ```ts
351
+ import { SiteAccessRequest } from '@amedia/user';
352
+ import { SiteAccessResolverError } from './SiteAccessRequest';
353
+
354
+ new SiteAccessRequest()
355
+ .withSiteDomain('www.direktesport.no')
356
+ .withAccessFeatures(['sport_premium'])
357
+ .requestAccess()
358
+ .then(({ isLoggedIn, hasAccess, primarySite, accessFeatures }) => {
359
+ console.log({ isLoggedIn, hasAccess, primarySite, accessFeatures });
360
+ })
361
+ .catch((error) => {
362
+ // Known potential errors are:
363
+
364
+ // You would have to show some error / try again mechanic etc here.
365
+ SiteAccessRequestError(
366
+ 'Unable to resolve access for site (www.direktesport.no)'
367
+ );
368
+
369
+ // If you attempt this on localhost
370
+ Error(
371
+ `@amedia/user cannot request site access for (www.direktesport.no) on localhost`
372
+ );
373
+ });
374
+ ```
375
+
376
+ Note that this might result in redirects/reloads if the user is not already logged in. In that case you will end up here again if logging in did not result in access.
377
+
378
+ ### Known limitations
379
+
380
+ Subscription activation can only happen against the subscription system related to the `withSiteDomain`. #team-abo will need to look into activation across all subscription systems to improve this behavior.
381
+
331
382
  ## Performance
332
383
 
333
384
  This app aims to be able to deliver a lot of data fast. Still, we might need to call several services in order to get what you need. We do try to cache whenever this makes sense, but please don't ask for data you don't need.
package/dist/user.d.ts CHANGED
@@ -76,12 +76,21 @@ declare const PrimarySiteSchema: rt.Record<{
76
76
  }, false>;
77
77
  type PrimarySite = rt.Static<typeof PrimarySiteSchema>;
78
78
 
79
- type PaywallUnlockResponse = {
79
+ type SiteAccessResponse = {
80
80
  isLoggedIn: boolean;
81
81
  hasAccess: boolean;
82
82
  primarySite?: null | PrimarySite;
83
83
  accessFeatures: string[];
84
84
  };
85
+ declare class SiteAccessRequest {
86
+ private siteDomain;
87
+ private requiredAccessFeatures;
88
+ withSiteDomain(siteDomain: string): this;
89
+ withAccessFeatures(accessFeatures: Array<string>): this;
90
+ requestAccess(): Promise<SiteAccessResponse>;
91
+ }
92
+
93
+ type PaywallUnlockResponse = SiteAccessResponse;
85
94
  declare class PaywallUnlockRequest {
86
95
  private requestedAccessFeatures;
87
96
  private reload;
@@ -140,4 +149,4 @@ declare const aidUrls: {
140
149
  sites: URL;
141
150
  };
142
151
 
143
- export { FetchTimeoutError, PaywallError, PaywallUnlockRequest, PaywallUnlockResponse, PrivacyPreferences, State, UserAttributes, UserDataRequest, aidUrls, getLoginUrl, goToLoginPage, logout, requestDataRefresh, saveStorage, updateStorage };
152
+ export { FetchTimeoutError, PaywallError, PaywallUnlockRequest, PaywallUnlockResponse, PrivacyPreferences, SiteAccessRequest, SiteAccessResponse, State, UserAttributes, UserDataRequest, aidUrls, getLoginUrl, goToLoginPage, logout, requestDataRefresh, saveStorage, updateStorage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amedia/user",
3
- "version": "0.14.96",
3
+ "version": "0.14.97",
4
4
  "description": "Client lib for working with aID user and associated data",
5
5
  "repository": "https://github.com/amedia/amedia-user-js",
6
6
  "author": "Amedia Utvikling (ID og data)",