@postalsys/ee-client 1.7.1 → 1.8.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 +1 -0
- package/index.d.ts +2 -0
- package/index.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -126,6 +126,7 @@ new EmailEngineClient(options);
|
|
|
126
126
|
| `alertMethod` | `function` | browser `alert()` | Custom alert dialog, `(message, title, cancelText, okText)` where `cancelText` is `null`. |
|
|
127
127
|
| `darkMode` | `boolean` | stored preference | Initial dark mode. Overrides the preference stored by the builtin toggle. |
|
|
128
128
|
| `showDarkModeToggle` | `boolean` | `true` | Render the builtin dark mode toggle. Set `false` when the host application drives the mode through `client.setDarkMode(enabled)` (for example in sync with its own theme switch). |
|
|
129
|
+
| `styleNonce` | `string` | none | Nonce set on the `<style>` element the widget appends. Pass the page's Content-Security-Policy nonce when `style-src-elem` allows no inline stylesheet without one. |
|
|
129
130
|
|
|
130
131
|
UI rendering, the compose modal, and dark mode only activate when a `container` is supplied. In a non-browser environment the UI is skipped and the instance behaves as a plain API client.
|
|
131
132
|
|
package/index.d.ts
CHANGED
|
@@ -105,6 +105,8 @@ export interface EmailEngineClientOptions {
|
|
|
105
105
|
darkMode?: boolean;
|
|
106
106
|
/** Render the builtin dark mode toggle button (default true); set false when the host drives the mode through setDarkMode() */
|
|
107
107
|
showDarkModeToggle?: boolean;
|
|
108
|
+
/** CSP nonce set on the <style> element the widget appends, for a host page whose style-src-elem requires one */
|
|
109
|
+
styleNonce?: string;
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
export declare class EmailEngineClient {
|
package/index.js
CHANGED
|
@@ -52,6 +52,10 @@ export class EmailEngineClient {
|
|
|
52
52
|
}
|
|
53
53
|
this.showDarkModeToggle = options.showDarkModeToggle !== false;
|
|
54
54
|
|
|
55
|
+
// The nonce a Content-Security-Policy page hands the widget so the <style> element
|
|
56
|
+
// createStyles() appends passes a style-src-elem directive without 'unsafe-inline'
|
|
57
|
+
this.styleNonce = typeof options.styleNonce === 'string' && options.styleNonce ? options.styleNonce : null;
|
|
58
|
+
|
|
55
59
|
// Get page size from localStorage or options or default
|
|
56
60
|
const savedPageSize =
|
|
57
61
|
typeof window !== 'undefined' && window.localStorage ? localStorage.getItem('ee-client-page-size') : null;
|
|
@@ -671,6 +675,10 @@ export class EmailEngineClient {
|
|
|
671
675
|
}
|
|
672
676
|
|
|
673
677
|
const style = document.createElement('style');
|
|
678
|
+
if (this.styleNonce) {
|
|
679
|
+
// the IDL property, which is what the policy check reads on an element a script inserts
|
|
680
|
+
style.nonce = this.styleNonce;
|
|
681
|
+
}
|
|
674
682
|
style.textContent = `
|
|
675
683
|
.ee-client {
|
|
676
684
|
--ee-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|