@sesamy/sesamy-js 1.14.0 → 1.15.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.
package/README.md CHANGED
@@ -118,6 +118,15 @@ These are the available configuration options, with their default values:
118
118
  endpoint: 'https://auth.sesamy.com',
119
119
  redirectUri: window.location.origin
120
120
  },
121
+ content: {
122
+ article: {
123
+ select: 'article'
124
+ }
125
+ },
126
+ tranforms: {
127
+ enabled: false,
128
+ rules: []
129
+ }
121
130
  }
122
131
  ```
123
132
 
@@ -316,3 +325,108 @@ generateLink(linkParams)
316
325
  console.error('Error generating link:', error);
317
326
  });
318
327
  ```
328
+
329
+ ## Transform
330
+
331
+ The transform module allows for dynamic content manipulation based on specified rules. This can include inserting, replacing, or removing elements on a webpage.
332
+
333
+ ### Configuration
334
+
335
+ The transform configuration is defined within the `Config` interface. The following properties are available:
336
+
337
+ - `enabled` (boolean, optional): Enables or disables the transform module.
338
+ - `rules` (array): An array of rule objects that define the transformations to apply.
339
+
340
+ Each rule object contains the following properties:
341
+
342
+ - `selector` (string): A CSS selector to target elements on the page.
343
+ - `transform` (string): The type of transformation to apply. Valid values are 'insert', 'replace', and 'remove'.
344
+ - `content` (string, optional): The content to insert or replace. Required for 'insert' and 'replace' transforms.
345
+ - `contentType` (string): Specifies the type of content. Valid values are 'html', 'selector', and 'url'.
346
+ - `path` (string, optional): A regular expression to match the URL path. If provided, the rule will only apply when the path matches the current URL.
347
+ - `entitlement` (string, optional): Specifies an entitlement required for the rule to apply.
348
+ - `authenticated` (boolean, optional): Specifies if the rule should only apply to authenticated users.
349
+
350
+ ### Example Configuration
351
+
352
+ Below is an example configuration for the transform module:
353
+
354
+ ```json
355
+ {
356
+ "transform": {
357
+ "enabled": true,
358
+ "rules": [
359
+ {
360
+ "selector": "#example",
361
+ "transform": "replace",
362
+ "content": "<p>New content</p>",
363
+ "contentType": "html"
364
+ },
365
+ {
366
+ "selector": ".ad-banner",
367
+ "transform": "remove"
368
+ },
369
+ {
370
+ "selector": ".insert-content",
371
+ "transform": "insert",
372
+ "content": "#source-element",
373
+ "contentType": "selector"
374
+ },
375
+ {
376
+ "selector": ".load-from-url",
377
+ "transform": "insert",
378
+ "content": "https://example.com/content",
379
+ "contentType": "url"
380
+ }
381
+ ]
382
+ }
383
+ }
384
+ ```
385
+
386
+ ### Usage
387
+
388
+ To use the transform module, include the configuration in your initialization script:
389
+
390
+ ```html
391
+ <script type="application/json" id="sesamy-js">
392
+ {
393
+ "clientId": "demo",
394
+ "transform": {
395
+ "enabled": true,
396
+ "rules": [
397
+ {
398
+ "selector": "#example",
399
+ "transform": "replace",
400
+ "content": "<p>New content</p>",
401
+ "contentType": "html"
402
+ },
403
+ {
404
+ "selector": ".ad-banner",
405
+ "transform": "remove"
406
+ },
407
+ {
408
+ "selector": ".insert-content",
409
+ "transform": "insert",
410
+ "content": "#source-element",
411
+ "contentType": "selector"
412
+ },
413
+ {
414
+ "selector": ".load-from-url",
415
+ "transform": "insert",
416
+ "content": "https://example.com/content",
417
+ "contentType": "url"
418
+ }
419
+ ]
420
+ }
421
+ }
422
+ </script>
423
+ ```
424
+
425
+ This configuration will replace the content of the element with the ID `example`, remove elements with the class `ad-banner`, insert the content of the element with the ID `source-element` into elements with the class `insert-content`, and load content from a URL into elements with the class `load-from-url`.
426
+
427
+ ### Notes
428
+
429
+ - The `content` property is required for 'insert' and 'replace' transforms.
430
+ - The `contentType` property specifies how to interpret the `content` property: as raw HTML, a CSS selector, or a URL to fetch content from.
431
+ - The `path` property can be used to apply rules conditionally based on the current URL.
432
+ - The `authenticated` property ensures that rules only apply to authenticated users if set to true.