@onlineapps/cookbook-template-helpers 1.0.14 → 2.0.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 +34 -24
- package/package.json +2 -2
- package/src/helpers/fileHelpers.js +25 -2
package/README.md
CHANGED
|
@@ -49,6 +49,15 @@ Převede file/inline descriptor na string (přes ContentResolver). File stáhne
|
|
|
49
49
|
async function file2string(descriptor, context)
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
### Helper context — logger
|
|
53
|
+
|
|
54
|
+
Oba descriptor helpery si staví `ContentResolver`, pokud jim v kontextu nepředáš
|
|
55
|
+
hotový `context.contentResolver`. V tom případě je `context.logger` **povinný** a
|
|
56
|
+
musí mít všechny čtyři metody: `info()`, `warn()`, `error()`, `debug()` — přesně
|
|
57
|
+
to, co vyžaduje `@onlineapps/content-resolver` a za ním `@onlineapps/conn-base-storage`.
|
|
58
|
+
Chybějící logger i logger neúplný padají hned v `getContentResolver()` a hláška
|
|
59
|
+
jmenuje chybějící metodu; žádný `console` fallback neexistuje.
|
|
60
|
+
|
|
52
61
|
## Usage in Cookbook
|
|
53
62
|
|
|
54
63
|
Helpers jsou k dispozici při resolvování template proměnných:
|
|
@@ -65,38 +74,39 @@ Helpers jsou k dispozici při resolvování template proměnných:
|
|
|
65
74
|
|
|
66
75
|
## Integration
|
|
67
76
|
|
|
68
|
-
|
|
69
|
-
|
|
77
|
+
Tenhle balíček se do běhu nezapojuje sám a nikdo ho v běhové cestě nevyžaduje
|
|
78
|
+
přímo. Cesta je tříčlánková a jde vždy stejně:
|
|
79
|
+
|
|
80
|
+
1. balíček je závislostí `@onlineapps/conn-orch-cookbook`, který ho re-exportuje
|
|
81
|
+
jako plochý klíč `templateHelpers`
|
|
82
|
+
(`shared/connector/conn-orch-cookbook/src/index.js`);
|
|
83
|
+
2. `ServiceWrapper` injektuje **celý modul** `conn-orch-cookbook` do
|
|
84
|
+
orchestrátoru jako `config.cookbook`
|
|
85
|
+
(`shared/connector/service-wrapper/src/ServiceWrapper.js:1818`);
|
|
86
|
+
3. `WorkflowOrchestrator` si helper vyzvedne při rozvíjení `{{helper(...)}}`
|
|
87
|
+
ve vstupu kroku:
|
|
70
88
|
|
|
71
89
|
```javascript
|
|
72
|
-
|
|
90
|
+
// shared/connector/conn-orch-orchestrator/src/WorkflowOrchestrator.js:786
|
|
91
|
+
const helpers = this.cookbook?.templateHelpers || {};
|
|
92
|
+
const helperFn = helpers[helperName];
|
|
73
93
|
|
|
74
|
-
|
|
75
|
-
|
|
94
|
+
if (typeof helperFn !== 'function') {
|
|
95
|
+
throw new Error(`[WorkflowOrchestrator] Unknown template helper '${helperName}' - Expected helper to exist in cookbook.templateHelpers`);
|
|
96
|
+
}
|
|
76
97
|
```
|
|
77
98
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
`const helpers = options.helpers || templateHelpers`). Pokud chceš výchozí helpery
|
|
81
|
-
zachovat a jen přidat vlastní, musíš je do override sady zahrnout — viz níže.
|
|
99
|
+
Žádná volba `helpers` a žádný override neexistují: platí přesně to, co tenhle
|
|
100
|
+
balíček exportuje. Neznámý helper je tvrdá chyba, ne prázdná hodnota.
|
|
82
101
|
|
|
83
|
-
|
|
102
|
+
Živý cookbook, který touhle cestou prochází:
|
|
103
|
+
[`infra/api_doorman/cookbooks/tester-helpers.json`](../../../infra/api_doorman/cookbooks/tester-helpers.json)
|
|
104
|
+
— volá `normalizeString`, `webalizeString`, `string2file` i `file2string`.
|
|
84
105
|
|
|
85
|
-
|
|
106
|
+
## Adding a Helper
|
|
86
107
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const customHelpers = require('./customHelpers');
|
|
90
|
-
|
|
91
|
-
const allHelpers = {
|
|
92
|
-
...templateHelpers,
|
|
93
|
-
...customHelpers
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const executor = new CookbookExecutor(cookbook, {
|
|
97
|
-
helpers: allHelpers
|
|
98
|
-
});
|
|
99
|
-
```
|
|
108
|
+
Nový helper se přidá **do tohoto balíčku** (a vydá se nová verze) — jinak se
|
|
109
|
+
k orchestrátoru nedostane, protože ten čte výhradně `cookbook.templateHelpers`.
|
|
100
110
|
|
|
101
111
|
## Helper Function Requirements
|
|
102
112
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onlineapps/cookbook-template-helpers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Template helper functions for cookbook variable resolution - string2file, file2string, and more",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"author": "OnlineApps",
|
|
20
20
|
"license": "PROPRIETARY",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@onlineapps/content-resolver": "
|
|
22
|
+
"@onlineapps/content-resolver": "3.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"jest": "29.7.0"
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
const ContentResolver = require('@onlineapps/content-resolver');
|
|
9
9
|
|
|
10
|
+
// The logger methods `ContentResolver` requires of the object this module hands
|
|
11
|
+
// it — the order is the order the error message lists them in.
|
|
12
|
+
const LOGGER_METHODS = ['info', 'warn', 'error', 'debug'];
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* Normalize string: remove control/unsafe chars, keep letters (incl. diacritics), numbers,
|
|
12
16
|
* whitespace and basic punctuation .,!?;:-_
|
|
@@ -66,8 +70,27 @@ function getContentResolver(helperContext) {
|
|
|
66
70
|
helperContext.data?.step_id ||
|
|
67
71
|
null;
|
|
68
72
|
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
// The logger goes straight into `ContentResolver`, which demands all four
|
|
74
|
+
// methods (content-resolver src/index.js; conn-base-storage 3.0.0 behind it).
|
|
75
|
+
// Until 2026-09-03 only `warn()` was checked here, so a three-method logger
|
|
76
|
+
// passed this gate and failed one frame down — delayed validation, forbidden
|
|
77
|
+
// by architecture-principles.md §4. Owner confirmation:
|
|
78
|
+
// api/docs/governance/confirmations/connector-logger-contract.md 001.
|
|
79
|
+
if (!helperContext.logger) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
'[cookbook-template-helpers] logger is required - Expected: a logger with info/warn/error/debug, '
|
|
82
|
+
+ 'so the resolver this helper builds writes where the service writes. '
|
|
83
|
+
+ 'Fix: pass context.logger (e.g. the logger your service already built).'
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const missing = LOGGER_METHODS.filter((method) => typeof helperContext.logger[method] !== 'function');
|
|
88
|
+
if (missing.length > 0) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
'[cookbook-template-helpers] logger is incomplete - Expected: info, warn, error, debug as functions; '
|
|
91
|
+
+ `missing: ${missing.join(', ')}. `
|
|
92
|
+
+ 'Fix: pass a logger implementing all four.'
|
|
93
|
+
);
|
|
71
94
|
}
|
|
72
95
|
|
|
73
96
|
return new ContentResolver({
|