@syntaxcircus/cmsify-client 0.2.4 → 0.3.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/dist/index.cjs +14 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -4942,6 +4942,25 @@ declare function getFormatHint(fieldConfig: unknown): TextFormatHint;
|
|
|
4942
4942
|
*/
|
|
4943
4943
|
declare function isProseHint(hint: TextFormatHint): boolean;
|
|
4944
4944
|
|
|
4945
|
+
/**
|
|
4946
|
+
* Renders `${{name}}` placeholder tokens in Cmsify content field text against a caller-supplied
|
|
4947
|
+
* variable dictionary. This is purely a client-side string transform -- the Cmsify server has no
|
|
4948
|
+
* concept of variables and never sees or stores rendered output. Content authors write literal
|
|
4949
|
+
* `${{name}}` tokens into Text/Markdown fields, and each consuming application decides what
|
|
4950
|
+
* values to supply at read time (e.g. from its own configuration).
|
|
4951
|
+
*
|
|
4952
|
+
* A variable name present in `variables` with a `null`/`undefined` value renders as an empty
|
|
4953
|
+
* string -- an explicit "blank this out." A variable name *not* present in `variables` at all is
|
|
4954
|
+
* left untouched in the output as the literal `${{name}}` token. This is deliberate: a typo'd
|
|
4955
|
+
* variable name (e.g. `${{supprtEmail}}`) should be visibly wrong on the rendered page, not
|
|
4956
|
+
* silently disappear.
|
|
4957
|
+
*/
|
|
4958
|
+
/**
|
|
4959
|
+
* Replaces every recognized `${{name}}` token in `template` with the corresponding value from
|
|
4960
|
+
* `variables`. Tokens whose name is not a key in `variables` are left untouched.
|
|
4961
|
+
*/
|
|
4962
|
+
declare function renderCmsifyTemplate(template: string, variables: Record<string, string | null | undefined>): string;
|
|
4963
|
+
|
|
4945
4964
|
declare const createCmsifyFetchClient: (baseUrl: string, fetchImpl?: typeof fetch) => openapi_fetch.Client<paths, `${string}/${string}`>;
|
|
4946
4965
|
|
|
4947
|
-
export { CmsifyApiError, CmsifyClient, type CmsifyClientOptions, CmsifyTimeoutError, type ContentItem, type ContentListItem, type ContentListOptions, type Delay, ETagStore, type MediaAsset, type PageOptions, type PageResult, type PagedResult, type ProblemDetails, type RequestOptions, TEXT_FORMAT_HINTS, type Template, type TemplateListItem, type TextFormatHint, type TextFormatHintConfig, type Workspace, type components, createCmsifyFetchClient, schema as generated, getFormatHint, isProseHint, listAll, type paths, toMimeType };
|
|
4966
|
+
export { CmsifyApiError, CmsifyClient, type CmsifyClientOptions, CmsifyTimeoutError, type ContentItem, type ContentListItem, type ContentListOptions, type Delay, ETagStore, type MediaAsset, type PageOptions, type PageResult, type PagedResult, type ProblemDetails, type RequestOptions, TEXT_FORMAT_HINTS, type Template, type TemplateListItem, type TextFormatHint, type TextFormatHintConfig, type Workspace, type components, createCmsifyFetchClient, schema as generated, getFormatHint, isProseHint, listAll, type paths, renderCmsifyTemplate, toMimeType };
|
package/dist/index.d.ts
CHANGED
|
@@ -4942,6 +4942,25 @@ declare function getFormatHint(fieldConfig: unknown): TextFormatHint;
|
|
|
4942
4942
|
*/
|
|
4943
4943
|
declare function isProseHint(hint: TextFormatHint): boolean;
|
|
4944
4944
|
|
|
4945
|
+
/**
|
|
4946
|
+
* Renders `${{name}}` placeholder tokens in Cmsify content field text against a caller-supplied
|
|
4947
|
+
* variable dictionary. This is purely a client-side string transform -- the Cmsify server has no
|
|
4948
|
+
* concept of variables and never sees or stores rendered output. Content authors write literal
|
|
4949
|
+
* `${{name}}` tokens into Text/Markdown fields, and each consuming application decides what
|
|
4950
|
+
* values to supply at read time (e.g. from its own configuration).
|
|
4951
|
+
*
|
|
4952
|
+
* A variable name present in `variables` with a `null`/`undefined` value renders as an empty
|
|
4953
|
+
* string -- an explicit "blank this out." A variable name *not* present in `variables` at all is
|
|
4954
|
+
* left untouched in the output as the literal `${{name}}` token. This is deliberate: a typo'd
|
|
4955
|
+
* variable name (e.g. `${{supprtEmail}}`) should be visibly wrong on the rendered page, not
|
|
4956
|
+
* silently disappear.
|
|
4957
|
+
*/
|
|
4958
|
+
/**
|
|
4959
|
+
* Replaces every recognized `${{name}}` token in `template` with the corresponding value from
|
|
4960
|
+
* `variables`. Tokens whose name is not a key in `variables` are left untouched.
|
|
4961
|
+
*/
|
|
4962
|
+
declare function renderCmsifyTemplate(template: string, variables: Record<string, string | null | undefined>): string;
|
|
4963
|
+
|
|
4945
4964
|
declare const createCmsifyFetchClient: (baseUrl: string, fetchImpl?: typeof fetch) => openapi_fetch.Client<paths, `${string}/${string}`>;
|
|
4946
4965
|
|
|
4947
|
-
export { CmsifyApiError, CmsifyClient, type CmsifyClientOptions, CmsifyTimeoutError, type ContentItem, type ContentListItem, type ContentListOptions, type Delay, ETagStore, type MediaAsset, type PageOptions, type PageResult, type PagedResult, type ProblemDetails, type RequestOptions, TEXT_FORMAT_HINTS, type Template, type TemplateListItem, type TextFormatHint, type TextFormatHintConfig, type Workspace, type components, createCmsifyFetchClient, schema as generated, getFormatHint, isProseHint, listAll, type paths, toMimeType };
|
|
4966
|
+
export { CmsifyApiError, CmsifyClient, type CmsifyClientOptions, CmsifyTimeoutError, type ContentItem, type ContentListItem, type ContentListOptions, type Delay, ETagStore, type MediaAsset, type PageOptions, type PageResult, type PagedResult, type ProblemDetails, type RequestOptions, TEXT_FORMAT_HINTS, type Template, type TemplateListItem, type TextFormatHint, type TextFormatHintConfig, type Workspace, type components, createCmsifyFetchClient, schema as generated, getFormatHint, isProseHint, listAll, type paths, renderCmsifyTemplate, toMimeType };
|
package/dist/index.js
CHANGED
|
@@ -264,6 +264,18 @@ function isProseHint(hint) {
|
|
|
264
264
|
return hint === "plaintext" || hint === "markdown" || hint === "html";
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
+
// src/templating.ts
|
|
268
|
+
var TOKEN_PATTERN = /\$\{\{\s*([A-Za-z][A-Za-z0-9_.-]*)\s*\}\}/g;
|
|
269
|
+
function renderCmsifyTemplate(template, variables) {
|
|
270
|
+
if (!template.includes("${{")) {
|
|
271
|
+
return template;
|
|
272
|
+
}
|
|
273
|
+
return template.replace(
|
|
274
|
+
TOKEN_PATTERN,
|
|
275
|
+
(full, name) => Object.prototype.hasOwnProperty.call(variables, name) ? variables[name] ?? "" : full
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
267
279
|
// src/generated/schema.ts
|
|
268
280
|
var schema_exports = {};
|
|
269
281
|
|
|
@@ -281,6 +293,7 @@ export {
|
|
|
281
293
|
getFormatHint,
|
|
282
294
|
isProseHint,
|
|
283
295
|
listAll,
|
|
296
|
+
renderCmsifyTemplate,
|
|
284
297
|
toMimeType
|
|
285
298
|
};
|
|
286
299
|
//# sourceMappingURL=index.js.map
|