@topol.io/editor 2.0.0-alpha.1 → 2.0.0-alpha.2
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 +29 -3
- package/dist/topol-plugin.es.js +15 -15
- package/dist/topol-plugin.umd.cjs +1 -1
- package/dist/types/src/main.d.ts +1 -0
- package/dist/types/types/Auth/INonceAuthCallbacks.d.ts +9 -0
- package/dist/types/types/Callbacks/IEmailCallbacks.d.ts +2 -1
- package/dist/types/types/Cloud/ICloudOptions.d.ts +1 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,6 +30,31 @@ Every `init` creates an independent instance. Host methods return promises, incl
|
|
|
30
30
|
`setSavedSections`, `refreshSyncedSections`, `setMergeTags`, `translateLanguage(code,
|
|
31
31
|
sourceCode?)`, `translateAllLanguages`, and other editor actions.
|
|
32
32
|
|
|
33
|
+
## Nonce authentication
|
|
34
|
+
|
|
35
|
+
Passing a `getNonce` callback switches authentication from the public key alone to
|
|
36
|
+
short-lived `nc_` nonces minted on your backend from the `sk_` secret. Nothing else
|
|
37
|
+
changes: templates, autosaves, images, comments and sections keep using your own
|
|
38
|
+
`api.*` endpoints and callbacks. There is no separate option; the presence of the
|
|
39
|
+
callback enables it. Topol Cloud is built on top of it and requires the callback.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const editor = await EmailEditor.init({
|
|
43
|
+
config: { authorize: { apiKey: "pk_your-public-key", userId: "user-123" } },
|
|
44
|
+
async getNonce() {
|
|
45
|
+
// Your backend calls Topol's POST /auth/nonce with the sk_ secret and this userId.
|
|
46
|
+
const response = await fetch("/api/topol/nonce", { method: "POST" });
|
|
47
|
+
if (!response.ok) throw new Error("Could not mint a Topol nonce");
|
|
48
|
+
return (await response.json()).nonce; // A fresh nc_ token.
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The editor refreshes the nonce before it expires and retries once on a rejected
|
|
54
|
+
nonce. A first nonce that cannot be obtained, or `cloud.enabled` without `getNonce`,
|
|
55
|
+
reports `onEditorError` with `source: "authorize"`; a later refresh failure reports
|
|
56
|
+
`source: "nonceAuth"` while the editor keeps working on the last valid nonce.
|
|
57
|
+
|
|
33
58
|
## Topol Cloud
|
|
34
59
|
|
|
35
60
|
```ts
|
|
@@ -57,9 +82,10 @@ await editor.render("#editor");
|
|
|
57
82
|
|
|
58
83
|
Enabling Cloud activates templates, autosaves, images, comments, sections,
|
|
59
84
|
multilanguage, and test-send. Set a feature to `false` to use external behavior.
|
|
60
|
-
Omit `cloud.templateId` to start in the Cloud template browser.
|
|
61
|
-
|
|
62
|
-
|
|
85
|
+
Omit `cloud.templateId` to start in the Cloud template browser. Cloud requires the
|
|
86
|
+
`getNonce` callback from nonce authentication above; `init` rejects without it. The
|
|
87
|
+
editor handles nonce refresh, persistence, and its Cloud recovery UI; this package
|
|
88
|
+
supplies the host bridge.
|
|
63
89
|
|
|
64
90
|
## Loader selection
|
|
65
91
|
|
package/dist/topol-plugin.es.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
function P(e) {
|
|
2
2
|
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
3
3
|
}
|
|
4
|
-
var
|
|
4
|
+
var b = function(o, t, r) {
|
|
5
5
|
var n = document.head || document.getElementsByTagName("head")[0], i = document.createElement("script");
|
|
6
6
|
typeof t == "function" && (r = t, t = {}), t = t || {}, r = r || function() {
|
|
7
|
-
}, i.type = t.type || "text/javascript", i.charset = t.charset || "utf8", i.async = "async" in t ? !!t.async : !0, i.src = o, t.attrs &&
|
|
8
|
-
var a = "onload" in i ? g :
|
|
7
|
+
}, i.type = t.type || "text/javascript", i.charset = t.charset || "utf8", i.async = "async" in t ? !!t.async : !0, i.src = o, t.attrs && I(i, t.attrs), t.text && (i.text = "" + t.text);
|
|
8
|
+
var a = "onload" in i ? g : T;
|
|
9
9
|
a(i, r), i.onload || g(i, r), n.appendChild(i);
|
|
10
10
|
};
|
|
11
|
-
function
|
|
11
|
+
function I(e, o) {
|
|
12
12
|
for (var t in o)
|
|
13
13
|
e.setAttribute(t, o[t]);
|
|
14
14
|
}
|
|
@@ -19,12 +19,12 @@ function g(e, o) {
|
|
|
19
19
|
this.onerror = this.onload = null, o(new Error("Failed to load " + this.src), e);
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function T(e, o) {
|
|
23
23
|
e.onreadystatechange = function() {
|
|
24
24
|
this.readyState != "complete" && this.readyState != "loaded" || (this.onreadystatechange = null, o(null, e));
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
const _ = /* @__PURE__ */ P(
|
|
27
|
+
const _ = /* @__PURE__ */ P(b), f = /* @__PURE__ */ new Map();
|
|
28
28
|
function U(e, o) {
|
|
29
29
|
if (o())
|
|
30
30
|
return Promise.resolve();
|
|
@@ -111,25 +111,25 @@ async function v(e) {
|
|
|
111
111
|
const r = window.TopolEmailEditor;
|
|
112
112
|
return s = { urls: /* @__PURE__ */ new Set([o]), factory: r }, r;
|
|
113
113
|
}
|
|
114
|
-
const
|
|
114
|
+
const N = {
|
|
115
115
|
async init(e, o) {
|
|
116
|
-
var
|
|
116
|
+
var E, m;
|
|
117
117
|
if (typeof window > "u" || typeof document > "u")
|
|
118
118
|
throw new Error("[@topol.io/editor] EmailEditor.init requires a browser. Call it after mounting.");
|
|
119
|
-
if (!((
|
|
119
|
+
if (!((E = e == null ? void 0 : e.config) != null && E.authorize))
|
|
120
120
|
throw new Error("[@topol.io/editor] Editor v4 requires { config: { authorize, ... }, onSave, ... }. See the v2 migration guide.");
|
|
121
121
|
const t = e.config.authorize.userId;
|
|
122
122
|
if (typeof t == "string" ? !/^[A-Za-z0-9_-]+$/.test(t) : !Number.isInteger(t) || t < 0)
|
|
123
123
|
throw new Error("[@topol.io/editor] authorize.userId must be a URL-safe string or a non-negative integer.");
|
|
124
|
-
if ((
|
|
125
|
-
throw new Error("[@topol.io/editor]
|
|
124
|
+
if ((m = e.config.cloud) != null && m.enabled && typeof e.getNonce != "function")
|
|
125
|
+
throw new Error("[@topol.io/editor] cloud.enabled requires nonce authentication: pass a top-level getNonce callback returning Promise<string>.");
|
|
126
126
|
const r = S(o), n = (o == null ? void 0 : o.loaderUrl) === void 0 && r !== u.production ? u.production : void 0, i = await O(r, n), { onClose: a, onError: l, ...d } = e, c = i(d);
|
|
127
127
|
let L;
|
|
128
128
|
return Object.assign(c, {
|
|
129
129
|
destroy: () => L ?? (L = Promise.resolve().then(() => c.close()))
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
|
-
},
|
|
132
|
+
}, C = "https://v1.page-assets.topol.io/topol-lpe.js";
|
|
133
133
|
function R() {
|
|
134
134
|
return typeof window < "u" && typeof window.LandingPageEditor == "function";
|
|
135
135
|
}
|
|
@@ -143,14 +143,14 @@ const j = {
|
|
|
143
143
|
*/
|
|
144
144
|
init: async (e, o) => {
|
|
145
145
|
var a;
|
|
146
|
-
if (await U(
|
|
146
|
+
if (await U(C, R), !R())
|
|
147
147
|
throw new Error("[@topol.io/editor] topol-lpe.js loaded but window.LandingPageEditor is not defined.");
|
|
148
148
|
const { onClose: t, ...r } = e, n = window.LandingPageEditor(r), i = ((a = n.destroy) == null ? void 0 : a.bind(n)) ?? (() => n.close());
|
|
149
149
|
return n.destroy = () => i(), n;
|
|
150
150
|
}
|
|
151
|
-
}, D =
|
|
151
|
+
}, D = N;
|
|
152
152
|
export {
|
|
153
|
-
|
|
153
|
+
N as EmailEditor,
|
|
154
154
|
j as LandingPageEditor,
|
|
155
155
|
D as TopolPlugin,
|
|
156
156
|
D as default
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(a,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(a=typeof globalThis<"u"?globalThis:a||self,u(a.TopolPlugin={}))})(this,function(a){"use strict";function u(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var _=function(o,t,n){var r=document.head||document.getElementsByTagName("head")[0],i=document.createElement("script");typeof t=="function"&&(n=t,t={}),t=t||{},n=n||function(){},i.type=t.type||"text/javascript",i.charset=t.charset||"utf8",i.async="async"in t?!!t.async:!0,i.src=o,t.attrs&&I(i,t.attrs),t.text&&(i.text=""+t.text);var d="onload"in i?g:S;d(i,n),i.onload||g(i,n),r.appendChild(i)};function I(e,o){for(var t in o)e.setAttribute(t,o[t])}function g(e,o){e.onload=function(){this.onerror=this.onload=null,o(null,e)},e.onerror=function(){this.onerror=this.onload=null,o(new Error("Failed to load "+this.src),e)}}function S(e,o){e.onreadystatechange=function(){this.readyState!="complete"&&this.readyState!="loaded"||(this.onreadystatechange=null,o(null,e))}}const A=u(_),
|
|
1
|
+
(function(a,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(a=typeof globalThis<"u"?globalThis:a||self,u(a.TopolPlugin={}))})(this,function(a){"use strict";function u(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var _=function(o,t,n){var r=document.head||document.getElementsByTagName("head")[0],i=document.createElement("script");typeof t=="function"&&(n=t,t={}),t=t||{},n=n||function(){},i.type=t.type||"text/javascript",i.charset=t.charset||"utf8",i.async="async"in t?!!t.async:!0,i.src=o,t.attrs&&I(i,t.attrs),t.text&&(i.text=""+t.text);var d="onload"in i?g:S;d(i,n),i.onload||g(i,n),r.appendChild(i)};function I(e,o){for(var t in o)e.setAttribute(t,o[t])}function g(e,o){e.onload=function(){this.onerror=this.onload=null,o(null,e)},e.onerror=function(){this.onerror=this.onload=null,o(new Error("Failed to load "+this.src),e)}}function S(e,o){e.onreadystatechange=function(){this.readyState!="complete"&&this.readyState!="loaded"||(this.onreadystatechange=null,o(null,e))}}const A=u(_),h=new Map;function p(e,o){if(o())return Promise.resolve();const t=h.get(e);if(t)return t;const n=new Promise((r,i)=>{const d=typeof document<"u"?y(e):null;if(d){const c=()=>{f(),r()},l=()=>{f(),d.remove(),i(new Error(`Failed to load script: ${e}`))},f=()=>{d.removeEventListener("load",c),d.removeEventListener("error",l)};d.addEventListener("load",c),d.addEventListener("error",l);return}A(e,c=>{var l;c!==null?((l=y(e))==null||l.remove(),i(c)):r()})}).finally(()=>{h.delete(e)});return h.set(e,n),n}function y(e){const o=document.getElementsByTagName("script");for(let t=0;t<o.length;t++)if(o[t].src===new URL(e,document.baseURI).href)return o[t];return null}const m="https://v4.email-assets.topol.io/loader/build.js",w={production:m,dev:m,staging:m},O="https://d10h8ga60f7b91.cloudfront.net/preview-app-{stage}/loader/build.js";class E extends Error{}let s,v=Promise.resolve();function j(e){if((e==null?void 0:e.loaderUrl)!==void 0){if(!e.loaderUrl.trim())throw new Error("[@topol.io/editor] loaderUrl must not be empty.");return e.loaderUrl}const o=(e==null?void 0:e.stage)??"production",n=typeof o=="number"||/^\d+$/.test(o)?O.replace("{stage}",String(o)):w[o];if(!n)throw new Error(`[@topol.io/editor] Unsupported stage "${o}". Use a supported stage or loaderUrl.`);return n}function N(e,o){const t=v.then(async()=>{try{return await R(e)}catch(n){if(n instanceof E||o===void 0)throw n;const r=await R(o);return s==null||s.urls.add(new URL(e,document.baseURI).href),r}});return v=t.catch(()=>{}),t}async function R(e){const o=new URL(e,document.baseURI).href;if(s){if(s.urls.has(o))return s.factory;throw new E("[@topol.io/editor] Editor v4 supports one loader URL per page. Reload the page to switch environments.")}const t=o===new URL(w.production,document.baseURI).href&&typeof window.TopolEmailEditor=="function";if(!t&&(typeof window.TopolEmailEditor=="function"||Array.from(document.scripts).some(r=>r.src===o)))throw new E("[@topol.io/editor] Cannot initialize from a host-provided loader with unknown lifecycle. Remove the script, reload the page, and let EmailEditor.init load the requested URL.");if(await p(e,()=>t),typeof window.TopolEmailEditor!="function"){for(const r of Array.from(document.scripts))r.src===o&&r.remove();throw new Error("[@topol.io/editor] The loader did not define window.TopolEmailEditor. Use an editor v4 loader.")}const n=window.TopolEmailEditor;return s={urls:new Set([o]),factory:n},n}const U={async init(e,o){var T,b;if(typeof window>"u"||typeof document>"u")throw new Error("[@topol.io/editor] EmailEditor.init requires a browser. Call it after mounting.");if(!((T=e==null?void 0:e.config)!=null&&T.authorize))throw new Error("[@topol.io/editor] Editor v4 requires { config: { authorize, ... }, onSave, ... }. See the v2 migration guide.");const t=e.config.authorize.userId;if(typeof t=="string"?!/^[A-Za-z0-9_-]+$/.test(t):!Number.isInteger(t)||t<0)throw new Error("[@topol.io/editor] authorize.userId must be a URL-safe string or a non-negative integer.");if((b=e.config.cloud)!=null&&b.enabled&&typeof e.getNonce!="function")throw new Error("[@topol.io/editor] cloud.enabled requires nonce authentication: pass a top-level getNonce callback returning Promise<string>.");const n=j(o),r=(o==null?void 0:o.loaderUrl)===void 0&&n!==w.production?w.production:void 0,i=await N(n,r),{onClose:d,onError:c,...l}=e,f=i(l);let z;return Object.assign(f,{destroy:()=>z??(z=Promise.resolve().then(()=>f.close()))})}},C="https://v1.page-assets.topol.io/topol-lpe.js";function L(){return typeof window<"u"&&typeof window.LandingPageEditor=="function"}const D={init:async(e,o)=>{var d;if(await p(C,L),!L())throw new Error("[@topol.io/editor] topol-lpe.js loaded but window.LandingPageEditor is not defined.");const{onClose:t,...n}=e,r=window.LandingPageEditor(n),i=((d=r.destroy)==null?void 0:d.bind(r))??(()=>r.close());return r.destroy=()=>i(),r}},P=U;a.EmailEditor=U,a.LandingPageEditor=D,a.TopolPlugin=P,a.default=P,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/types/src/main.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export type { ILandingPageOptions, ILandingPageCallbacks, ILandingPageEditorInst
|
|
|
40
40
|
export type { default as IEmailConfig } from "../types/IEmailConfig";
|
|
41
41
|
export type { default as IEmailEditorInstance, IUpdateTemplateOptions } from "../types/IEmailEditorInstance";
|
|
42
42
|
export type { IEmailEditorPluginOptions } from "./email-editor";
|
|
43
|
+
export type { INonceAuthCallbacks } from "../types/Auth/INonceAuthCallbacks";
|
|
43
44
|
export type { ICloudFeatures, ICloudOptions, ICloudCallbacks, ICloudSavePayload, ICloudTemplateChangePayload } from "../types/Cloud/ICloudOptions";
|
|
44
45
|
export type { ISavedSection, IPremadeSection, IPremadeSections, ILegacyPremadeSections, IPremadeSectionsOptions } from "../types/Sections/ISections";
|
|
45
46
|
export type { ILanguageMutation, ILanguageChangePayload, IEmailDeletedItem } from "../types/Callbacks/ICallbackPayloads";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nonce authentication. Passing `getNonce` switches the editor from the legacy
|
|
3
|
+
* public-key authorize call to short-lived `nc_` nonces minted on your backend.
|
|
4
|
+
* Works on its own (every feature stays external) and is required by Topol Cloud.
|
|
5
|
+
*/
|
|
6
|
+
export interface INonceAuthCallbacks {
|
|
7
|
+
/** Fetch a fresh nc_ nonce from your authenticated backend. Never expose an sk_ secret in the browser. */
|
|
8
|
+
getNonce?(): Promise<string>;
|
|
9
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type INotification from "../Notification/INotification";
|
|
2
2
|
import type { ISavedSection } from "../Sections/ISections";
|
|
3
3
|
import type { ICloudCallbacks } from "../Cloud/ICloudOptions";
|
|
4
|
+
import type { INonceAuthCallbacks } from "../Auth/INonceAuthCallbacks";
|
|
4
5
|
import type { ISaveData, ISendTestData, IErrorData, ILanguageChangePayload, ILanguageMutation, IEmailDeletedItem } from "./ICallbackPayloads";
|
|
5
6
|
/** v4 host callbacks. Return save promises so the editor can await persistence. */
|
|
6
|
-
export default interface IEmailCallbacks extends ICloudCallbacks {
|
|
7
|
+
export default interface IEmailCallbacks extends INonceAuthCallbacks, ICloudCallbacks {
|
|
7
8
|
onSave?(payload: ISaveData): void | Promise<void>;
|
|
8
9
|
onSaveAndClose?(payload: ISaveData): void | Promise<void>;
|
|
9
10
|
onTestSend?(payload: ISendTestData): void;
|
|
@@ -25,9 +25,8 @@ export interface ICloudTemplateChangePayload {
|
|
|
25
25
|
name?: string;
|
|
26
26
|
folderId?: number | null;
|
|
27
27
|
}
|
|
28
|
+
/** Cloud-scoped callbacks. Cloud also requires `getNonce` from INonceAuthCallbacks. */
|
|
28
29
|
export interface ICloudCallbacks {
|
|
29
|
-
/** Fetch a fresh nc_ nonce from your authenticated backend. Never expose an sk_ secret in the browser. */
|
|
30
|
-
getNonce?(): Promise<string>;
|
|
31
30
|
onCloudSave?(payload: ICloudSavePayload): void;
|
|
32
31
|
onCloudTemplateChange?(payload: ICloudTemplateChangePayload): void;
|
|
33
32
|
}
|