@teleporthq/teleport-shared 0.43.67 → 0.43.69
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/__tests__/_helpers/embed-runtime-emitter.ts +197 -0
- package/__tests__/utils/discount-engine.ts +1548 -0
- package/__tests__/utils/product-options.ts +2458 -0
- package/__tests__/utils/rich-text-embeds-runtime-module.ts +34 -0
- package/__tests__/utils/subscription-access.ts +37 -0
- package/dist/cjs/index.d.ts +9 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +17 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/utils/cart-currency.d.ts +27 -0
- package/dist/cjs/utils/cart-currency.d.ts.map +1 -0
- package/dist/cjs/utils/cart-currency.js +31 -0
- package/dist/cjs/utils/cart-currency.js.map +1 -0
- package/dist/cjs/utils/cart-line-pricing.d.ts +25 -0
- package/dist/cjs/utils/cart-line-pricing.d.ts.map +1 -0
- package/dist/cjs/utils/cart-line-pricing.js +29 -0
- package/dist/cjs/utils/cart-line-pricing.js.map +1 -0
- package/dist/cjs/utils/discount-engine.d.ts +74 -0
- package/dist/cjs/utils/discount-engine.d.ts.map +1 -0
- package/dist/cjs/utils/discount-engine.js +435 -0
- package/dist/cjs/utils/discount-engine.js.map +1 -0
- package/dist/cjs/utils/product-options.d.ts +25 -0
- package/dist/cjs/utils/product-options.d.ts.map +1 -0
- package/dist/cjs/utils/product-options.js +1155 -0
- package/dist/cjs/utils/product-options.js.map +1 -0
- package/dist/cjs/utils/rich-text-embeds-codegen.d.ts +13 -0
- package/dist/cjs/utils/rich-text-embeds-codegen.d.ts.map +1 -1
- package/dist/cjs/utils/rich-text-embeds-codegen.js +15 -104
- package/dist/cjs/utils/rich-text-embeds-codegen.js.map +1 -1
- package/dist/cjs/utils/rich-text-embeds-runtime-source.d.ts +2 -0
- package/dist/cjs/utils/rich-text-embeds-runtime-source.d.ts.map +1 -0
- package/dist/cjs/utils/rich-text-embeds-runtime-source.js +409 -0
- package/dist/cjs/utils/rich-text-embeds-runtime-source.js.map +1 -0
- package/dist/cjs/utils/session-cookie-resolver.d.ts +85 -0
- package/dist/cjs/utils/session-cookie-resolver.d.ts.map +1 -0
- package/dist/cjs/utils/session-cookie-resolver.js +108 -0
- package/dist/cjs/utils/session-cookie-resolver.js.map +1 -0
- package/dist/cjs/utils/subscription-access.d.ts +36 -0
- package/dist/cjs/utils/subscription-access.d.ts.map +1 -0
- package/dist/cjs/utils/subscription-access.js +61 -0
- package/dist/cjs/utils/subscription-access.js.map +1 -0
- package/dist/cjs/utils/table-access.d.ts +114 -0
- package/dist/cjs/utils/table-access.d.ts.map +1 -0
- package/dist/cjs/utils/table-access.js +238 -0
- package/dist/cjs/utils/table-access.js.map +1 -0
- package/dist/cjs/utils/web-push.d.ts +43 -0
- package/dist/cjs/utils/web-push.d.ts.map +1 -0
- package/dist/cjs/utils/web-push.js +62 -0
- package/dist/cjs/utils/web-push.js.map +1 -0
- package/dist/esm/index.d.ts +9 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +9 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/utils/cart-currency.d.ts +27 -0
- package/dist/esm/utils/cart-currency.d.ts.map +1 -0
- package/dist/esm/utils/cart-currency.js +27 -0
- package/dist/esm/utils/cart-currency.js.map +1 -0
- package/dist/esm/utils/cart-line-pricing.d.ts +25 -0
- package/dist/esm/utils/cart-line-pricing.d.ts.map +1 -0
- package/dist/esm/utils/cart-line-pricing.js +25 -0
- package/dist/esm/utils/cart-line-pricing.js.map +1 -0
- package/dist/esm/utils/discount-engine.d.ts +74 -0
- package/dist/esm/utils/discount-engine.d.ts.map +1 -0
- package/dist/esm/utils/discount-engine.js +431 -0
- package/dist/esm/utils/discount-engine.js.map +1 -0
- package/dist/esm/utils/product-options.d.ts +25 -0
- package/dist/esm/utils/product-options.d.ts.map +1 -0
- package/dist/esm/utils/product-options.js +1151 -0
- package/dist/esm/utils/product-options.js.map +1 -0
- package/dist/esm/utils/rich-text-embeds-codegen.d.ts +13 -0
- package/dist/esm/utils/rich-text-embeds-codegen.d.ts.map +1 -1
- package/dist/esm/utils/rich-text-embeds-codegen.js +16 -105
- package/dist/esm/utils/rich-text-embeds-codegen.js.map +1 -1
- package/dist/esm/utils/rich-text-embeds-runtime-source.d.ts +2 -0
- package/dist/esm/utils/rich-text-embeds-runtime-source.d.ts.map +1 -0
- package/dist/esm/utils/rich-text-embeds-runtime-source.js +406 -0
- package/dist/esm/utils/rich-text-embeds-runtime-source.js.map +1 -0
- package/dist/esm/utils/session-cookie-resolver.d.ts +85 -0
- package/dist/esm/utils/session-cookie-resolver.d.ts.map +1 -0
- package/dist/esm/utils/session-cookie-resolver.js +103 -0
- package/dist/esm/utils/session-cookie-resolver.js.map +1 -0
- package/dist/esm/utils/subscription-access.d.ts +36 -0
- package/dist/esm/utils/subscription-access.d.ts.map +1 -0
- package/dist/esm/utils/subscription-access.js +57 -0
- package/dist/esm/utils/subscription-access.js.map +1 -0
- package/dist/esm/utils/table-access.d.ts +114 -0
- package/dist/esm/utils/table-access.d.ts.map +1 -0
- package/dist/esm/utils/table-access.js +233 -0
- package/dist/esm/utils/table-access.js.map +1 -0
- package/dist/esm/utils/web-push.d.ts +43 -0
- package/dist/esm/utils/web-push.d.ts.map +1 -0
- package/dist/esm/utils/web-push.js +59 -0
- package/dist/esm/utils/web-push.js.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +16 -0
- package/src/utils/cart-currency.ts +76 -0
- package/src/utils/cart-line-pricing.ts +151 -0
- package/src/utils/discount-engine.ts +437 -0
- package/src/utils/product-options.ts +1150 -0
- package/src/utils/rich-text-embeds-codegen.ts +16 -183
- package/src/utils/rich-text-embeds-runtime-source.ts +405 -0
- package/src/utils/session-cookie-resolver.ts +305 -0
- package/src/utils/subscription-access.ts +59 -0
- package/src/utils/table-access.ts +516 -0
- package/src/utils/web-push.ts +61 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prints `components/embed-runtime.js` from the live functions in
|
|
3
|
+
* `src/utils/rich-text-embeds.ts`. Test-only: the shipped generator returns the
|
|
4
|
+
* committed string in `src/utils/rich-text-embeds-runtime-source.ts`, because
|
|
5
|
+
* `Function.prototype.toString` reads whatever a consumer's minifier left —
|
|
6
|
+
* teleport-gui packs projects in a minified browser bundle, where every
|
|
7
|
+
* function below is renamed and the generated project imported names that no
|
|
8
|
+
* longer existed (`parseEmbedHeightMessage is not a function` on every page).
|
|
9
|
+
* `__tests__/utils/rich-text-embeds-runtime-module.ts` compares the two and
|
|
10
|
+
* rewrites the committed copy when run with UPDATE_EMBED_RUNTIME=1.
|
|
11
|
+
*/
|
|
12
|
+
import {
|
|
13
|
+
CUSTOM_EMBED_PROVIDER_ID,
|
|
14
|
+
DEFAULT_EMBED_ALIGN,
|
|
15
|
+
DEFAULT_EMBED_SANDBOX_LEVEL,
|
|
16
|
+
DEFAULT_EMBED_WIDTH,
|
|
17
|
+
EMBED_ALIGNMENTS,
|
|
18
|
+
EMBED_ATTR,
|
|
19
|
+
EMBED_BLOT_NAME,
|
|
20
|
+
EMBED_CAPTION_CLASS_NAME,
|
|
21
|
+
EMBED_CAPTION_STYLE,
|
|
22
|
+
EMBED_CLASS_NAME,
|
|
23
|
+
EMBED_FRAME_CLASS_NAME,
|
|
24
|
+
EMBED_HEIGHT_MESSAGE_TYPE,
|
|
25
|
+
EMBED_INITIAL_HEIGHT,
|
|
26
|
+
EMBED_MAX_HEIGHT,
|
|
27
|
+
EMBED_MIN_HEIGHT,
|
|
28
|
+
EMBED_SANDBOX_DOC_HEAD,
|
|
29
|
+
EMBED_SANDBOX_DOC_TAIL,
|
|
30
|
+
EMBED_SANDBOX_FLAGS_STRICT,
|
|
31
|
+
EMBED_SANDBOX_FLAGS_TRUSTED,
|
|
32
|
+
EMBED_TOKEN_PLACEHOLDER,
|
|
33
|
+
GENERIC_EMBED_PROVIDER_ID,
|
|
34
|
+
WIDESCREEN_EMBED_RATIO,
|
|
35
|
+
applyEmbedTemplate,
|
|
36
|
+
buildEmbedElementHtml,
|
|
37
|
+
buildEmbedFrameChildren,
|
|
38
|
+
buildEmbedHtmlFromUrl,
|
|
39
|
+
buildEmbedSandboxDocument,
|
|
40
|
+
clampEmbedWidth,
|
|
41
|
+
createEmbedToken,
|
|
42
|
+
createEmbedValue,
|
|
43
|
+
decodeEmbedCode,
|
|
44
|
+
embedBlockStyle,
|
|
45
|
+
embedFrameStyle,
|
|
46
|
+
encodeEmbedCode,
|
|
47
|
+
escapeEmbedAttribute,
|
|
48
|
+
escapeEmbedText,
|
|
49
|
+
findEmbedFrame,
|
|
50
|
+
isSafeEmbedUrl,
|
|
51
|
+
normalizeEmbedAlign,
|
|
52
|
+
normalizeEmbedsForStorage,
|
|
53
|
+
parseEmbedHeightMessage,
|
|
54
|
+
readEmbedValueFromElement,
|
|
55
|
+
readEncodedEmbedCode,
|
|
56
|
+
resolveEmbedMode,
|
|
57
|
+
resolveEmbedProvider,
|
|
58
|
+
resolveEmbedSandboxFlags,
|
|
59
|
+
} from '../../src/utils/rich-text-embeds'
|
|
60
|
+
import { serializeEmbedProvidersForRuntime } from '../../src/utils/rich-text-embeds-codegen'
|
|
61
|
+
|
|
62
|
+
/* ── The generated runtime module ───────────────────────────────────────────
|
|
63
|
+
*
|
|
64
|
+
* The exported project needs these same helpers at runtime: its rich-text
|
|
65
|
+
* editor builds embeds with them and its activator mounts them. Rather than
|
|
66
|
+
* hand-copying the logic into a code-generator template — where it would drift
|
|
67
|
+
* from `rich-text-embeds.ts` the first time a provider is added — the module is
|
|
68
|
+
* EMITTED from its very functions: the constants are serialized, the functions
|
|
69
|
+
* are printed with `Function.prototype.toString`, and the result is committed as
|
|
70
|
+
* the string the generator writes to `components/embed-runtime.js`.
|
|
71
|
+
*
|
|
72
|
+
* Two rules keep that safe, and `__tests__/utils/rich-text-embeds-runtime-module.ts`
|
|
73
|
+
* pins both:
|
|
74
|
+
* - every emitted function may only reference other emitted functions and the
|
|
75
|
+
* constants below, never a module-private helper or an import;
|
|
76
|
+
* - the emitted module must parse and behave identically to this one.
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Every function the generated editor and activator reach — the ones they
|
|
81
|
+
* import, plus everything those call in turn. Deliberately not the whole of
|
|
82
|
+
* `rich-text-embeds`: the editor overlay helpers belong to the studio, and an
|
|
83
|
+
* export nothing calls is dead weight in every generated project.
|
|
84
|
+
*/
|
|
85
|
+
const RUNTIME_EXPORTS: Array<(...args: never[]) => unknown> = [
|
|
86
|
+
isSafeEmbedUrl,
|
|
87
|
+
resolveEmbedProvider,
|
|
88
|
+
applyEmbedTemplate,
|
|
89
|
+
buildEmbedHtmlFromUrl,
|
|
90
|
+
resolveEmbedMode,
|
|
91
|
+
clampEmbedWidth,
|
|
92
|
+
normalizeEmbedAlign,
|
|
93
|
+
escapeEmbedAttribute,
|
|
94
|
+
escapeEmbedText,
|
|
95
|
+
encodeEmbedCode,
|
|
96
|
+
decodeEmbedCode,
|
|
97
|
+
createEmbedValue,
|
|
98
|
+
embedBlockStyle,
|
|
99
|
+
embedFrameStyle,
|
|
100
|
+
buildEmbedElementHtml,
|
|
101
|
+
buildEmbedFrameChildren,
|
|
102
|
+
findEmbedFrame,
|
|
103
|
+
readEmbedValueFromElement,
|
|
104
|
+
readEncodedEmbedCode,
|
|
105
|
+
normalizeEmbedsForStorage,
|
|
106
|
+
resolveEmbedSandboxFlags,
|
|
107
|
+
buildEmbedSandboxDocument,
|
|
108
|
+
parseEmbedHeightMessage,
|
|
109
|
+
createEmbedToken,
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
interface RuntimeConstant {
|
|
113
|
+
name: string
|
|
114
|
+
literal: string
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const runtimeConstant = (name: string, literal: string): RuntimeConstant => ({ name, literal })
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* TypeScript's CommonJS emit rewrites every reference to an exported CONSTANT
|
|
121
|
+
* as `exports.NAME` (exported functions keep their bare names, which is why
|
|
122
|
+
* they can call each other). The generator runs against that CommonJS build, so
|
|
123
|
+
* printed function bodies arrive carrying `exports.` prefixes that mean nothing
|
|
124
|
+
* in the emitted module — where each constant is re-declared as a plain
|
|
125
|
+
* top-level binding of the same name. Rewriting them back is therefore exact,
|
|
126
|
+
* not a heuristic: only names this module emits are rewritten, and
|
|
127
|
+
* `generateEmbedRuntimeModuleSource` asserts nothing module-scoped is left.
|
|
128
|
+
*/
|
|
129
|
+
const bindRuntimeConstantReferences = (source: string, names: string[]): string =>
|
|
130
|
+
names.reduce((acc, name) => acc.replace(new RegExp(`\\bexports\\.${name}\\b`, 'g'), name), source)
|
|
131
|
+
|
|
132
|
+
export function emitEmbedRuntimeModuleSourceFromFunctions(): string {
|
|
133
|
+
const constants: RuntimeConstant[] = [
|
|
134
|
+
runtimeConstant('EMBED_CLASS_NAME', JSON.stringify(EMBED_CLASS_NAME)),
|
|
135
|
+
runtimeConstant('EMBED_FRAME_CLASS_NAME', JSON.stringify(EMBED_FRAME_CLASS_NAME)),
|
|
136
|
+
runtimeConstant('EMBED_CAPTION_CLASS_NAME', JSON.stringify(EMBED_CAPTION_CLASS_NAME)),
|
|
137
|
+
runtimeConstant('EMBED_BLOT_NAME', JSON.stringify(EMBED_BLOT_NAME)),
|
|
138
|
+
runtimeConstant('EMBED_ATTR', JSON.stringify(EMBED_ATTR, null, 2)),
|
|
139
|
+
runtimeConstant('EMBED_ALIGNMENTS', JSON.stringify(EMBED_ALIGNMENTS)),
|
|
140
|
+
runtimeConstant('CUSTOM_EMBED_PROVIDER_ID', JSON.stringify(CUSTOM_EMBED_PROVIDER_ID)),
|
|
141
|
+
runtimeConstant('GENERIC_EMBED_PROVIDER_ID', JSON.stringify(GENERIC_EMBED_PROVIDER_ID)),
|
|
142
|
+
runtimeConstant('DEFAULT_EMBED_WIDTH', String(DEFAULT_EMBED_WIDTH)),
|
|
143
|
+
runtimeConstant('DEFAULT_EMBED_ALIGN', JSON.stringify(DEFAULT_EMBED_ALIGN)),
|
|
144
|
+
runtimeConstant('DEFAULT_EMBED_SANDBOX_LEVEL', JSON.stringify(DEFAULT_EMBED_SANDBOX_LEVEL)),
|
|
145
|
+
runtimeConstant('WIDESCREEN_EMBED_RATIO', String(WIDESCREEN_EMBED_RATIO)),
|
|
146
|
+
runtimeConstant('EMBED_CAPTION_STYLE', JSON.stringify(EMBED_CAPTION_STYLE)),
|
|
147
|
+
runtimeConstant('EMBED_PROVIDERS', serializeEmbedProvidersForRuntime()),
|
|
148
|
+
runtimeConstant('EMBED_SANDBOX_FLAGS_STRICT', JSON.stringify(EMBED_SANDBOX_FLAGS_STRICT)),
|
|
149
|
+
runtimeConstant('EMBED_SANDBOX_FLAGS_TRUSTED', JSON.stringify(EMBED_SANDBOX_FLAGS_TRUSTED)),
|
|
150
|
+
runtimeConstant('EMBED_HEIGHT_MESSAGE_TYPE', JSON.stringify(EMBED_HEIGHT_MESSAGE_TYPE)),
|
|
151
|
+
runtimeConstant('EMBED_TOKEN_PLACEHOLDER', JSON.stringify(EMBED_TOKEN_PLACEHOLDER)),
|
|
152
|
+
runtimeConstant('EMBED_MIN_HEIGHT', String(EMBED_MIN_HEIGHT)),
|
|
153
|
+
runtimeConstant('EMBED_MAX_HEIGHT', String(EMBED_MAX_HEIGHT)),
|
|
154
|
+
runtimeConstant('EMBED_INITIAL_HEIGHT', String(EMBED_INITIAL_HEIGHT)),
|
|
155
|
+
runtimeConstant('EMBED_SANDBOX_DOC_HEAD', JSON.stringify(EMBED_SANDBOX_DOC_HEAD)),
|
|
156
|
+
runtimeConstant('EMBED_SANDBOX_DOC_TAIL', JSON.stringify(EMBED_SANDBOX_DOC_TAIL)),
|
|
157
|
+
// `createEmbedToken` closes over this counter.
|
|
158
|
+
runtimeConstant('embedTokenCounter', '0'),
|
|
159
|
+
]
|
|
160
|
+
|
|
161
|
+
const names = constants.map((entry) => entry.name)
|
|
162
|
+
const declarations = constants.map((entry) => `export var ${entry.name} = ${entry.literal}`)
|
|
163
|
+
const functions = RUNTIME_EXPORTS.map(
|
|
164
|
+
(fn) => `export ${bindRuntimeConstantReferences(fn.toString(), names)}`
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
const source = `${RUNTIME_MODULE_HEADER}\n${declarations.join('\n\n')}\n\n${functions.join(
|
|
168
|
+
'\n\n'
|
|
169
|
+
)}\n`
|
|
170
|
+
|
|
171
|
+
// An `exports.` reference that survived means a function reached for a
|
|
172
|
+
// constant left off the list above. That crashes every generated project at
|
|
173
|
+
// runtime, so it fails here instead. (Import leakage is covered by the
|
|
174
|
+
// emitted module being evaluated in this package's tests — this module has
|
|
175
|
+
// no imports, and must not gain any.)
|
|
176
|
+
const leaked = source.match(/\bexports\.[A-Za-z_$][\w$]*/g)
|
|
177
|
+
if (leaked) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
`Embed runtime module cannot be emitted: unresolved module references ${leaked.join(', ')}`
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return source
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const RUNTIME_MODULE_HEADER = `/**
|
|
187
|
+
* Code embeds inside rich-text content — the shape the editor writes and the
|
|
188
|
+
* page reads back. Generated from @teleporthq/teleport-shared; edit it there.
|
|
189
|
+
*
|
|
190
|
+
* An embed is stored inside the content HTML as a <figure class="tq-embed">.
|
|
191
|
+
* Passive markup (a provider iframe) lives in the figure as real children, so
|
|
192
|
+
* it renders server-side with no JavaScript. Markup that can execute — a
|
|
193
|
+
* <script>, an on* handler, a javascript: URL — is base64-encoded onto the
|
|
194
|
+
* element instead, and mounted at runtime inside a sandboxed iframe so it can
|
|
195
|
+
* never reach this page.
|
|
196
|
+
*/
|
|
197
|
+
`
|