@sesamy/sesamy-js 1.21.4 → 1.21.5

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
@@ -90,6 +90,7 @@ The library can trigger actions based on query parameters. The following query p
90
90
  - `sesamy-user`. If present, the library will validate that the user is authenticated with the correct email. If not, the user will be logged out and a new login with be initiated.
91
91
  - `sesamy-login`. If present, the library will validate that the user is authenticated. If not, the user will be logged out and a new login with be initiated.
92
92
  - `sesamy-purchase`. Triggers a sesamyJsPurchase event.
93
+ - `sesamy-token`. If present, the library parse the token and add any content permissions that the token grants.
93
94
 
94
95
  # Hash triggers
95
96
 
@@ -270,6 +271,133 @@ setToken(accessToken, expiresIn)
270
271
  });
271
272
  ```
272
273
 
274
+ # Entitlements API
275
+
276
+ ## `entitlements.get(entitlementId: string)`
277
+
278
+ Fetches a specific entitlement by its ID.
279
+
280
+ ### Parameters
281
+
282
+ - `entitlementId` (string): The ID of the entitlement to retrieve.
283
+
284
+ ### Returns
285
+
286
+ - `Promise<Entitlement | undefined>`: The entitlement object if found, otherwise `undefined`.
287
+
288
+ ### Example
289
+
290
+ ```javascript
291
+ // Fetch a specific entitlement by its ID
292
+ window.sesamy.entitlements
293
+ .get('entitlement-id')
294
+ .then(entitlement => {
295
+ if (entitlement) {
296
+ console.log('Entitlement:', entitlement);
297
+ } else {
298
+ console.log('Entitlement not found');
299
+ }
300
+ })
301
+ .catch(error => {
302
+ console.error('Error fetching entitlement:', error);
303
+ });
304
+ ```
305
+
306
+ ---
307
+
308
+ ## `entitlements.list(params: GetEntitlementsOptions)`
309
+
310
+ Fetches the list of entitlements, with optional filters and inclusion of signed links.
311
+
312
+ ### Parameters
313
+
314
+ - `params` (GetEntitlementsOptions): Optional parameters for fetching entitlements.
315
+ - `includeSignedLinks` (boolean, optional): Whether to include signed links. Default is `true`.
316
+ - `waitForEntitlementAfter` (Date, optional): If provided, waits for an entitlement that is available after the given date.
317
+
318
+ ### Returns
319
+
320
+ - `Promise<Entitlement[]>`: An array of entitlements.
321
+
322
+ ### Example
323
+
324
+ ```javascript
325
+ // Fetch all entitlements, including signed links
326
+ window.sesamy.entitlements
327
+ .list({ includeSignedLinks: true })
328
+ .then(entitlements => {
329
+ console.log('Entitlements:', entitlements);
330
+ })
331
+ .catch(error => {
332
+ console.error('Error fetching entitlements:', error);
333
+ });
334
+ ```
335
+
336
+ ---
337
+
338
+ ## `entitlements.access(entitlementId: string)`
339
+
340
+ Fetches the access details for a specific entitlement by its ID.
341
+
342
+ ### Parameters
343
+
344
+ - `entitlementId` (string): The ID of the entitlement to access.
345
+
346
+ ### Returns
347
+
348
+ - `Promise<Access>`: The access details for the given entitlement.
349
+
350
+ ### Example
351
+
352
+ ```javascript
353
+ // Fetch access details for a specific entitlement
354
+ window.sesamy.entitlements
355
+ .access('entitlement-id')
356
+ .then(access => {
357
+ console.log('Access details:', access);
358
+ })
359
+ .catch(error => {
360
+ console.error('Error fetching entitlement access:', error);
361
+ });
362
+ ```
363
+
364
+ ---
365
+
366
+ ## `entitlements.signedLinks()`
367
+
368
+ Fetches signed links for the current session's entitlements.
369
+
370
+ ### Parameters
371
+
372
+ None.
373
+
374
+ ### Returns
375
+
376
+ - `SignedLink[]`: An array of signed links for the current entitlements.
377
+
378
+ ### Example
379
+
380
+ ```javascript
381
+ // Fetch signed links for the current entitlements
382
+ const signedLinks = window.sesamy.entitlements.signedLinks();
383
+ console.log('Signed links:', signedLinks);
384
+ ```
385
+
386
+ ---
387
+
388
+ ### Types
389
+
390
+ - **GetEntitlementsOptions**: An object containing optional parameters for fetching entitlements.
391
+
392
+ - `includeSignedLinks` (boolean, optional): Whether to include signed links. Defaults to `true`.
393
+ - `waitForEntitlementAfter` (Date, optional): A date to filter entitlements that are available after the given date.
394
+
395
+ - **Entitlement**: Represents an entitlement object.
396
+
397
+ - **Access**: Represents the access details for an entitlement.
398
+
399
+ - **SignedLink**: Represents a signed link for accessing an entitlement.
400
+
273
401
  # Services
274
402
 
275
403
  ## `getProfile()`