@adobe-commerce/aio-toolkit 1.0.7 → 1.0.9
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/CHANGELOG.md +188 -0
- package/README.md +220 -33
- package/dist/index.d.mts +46 -10
- package/dist/index.d.ts +46 -10
- package/dist/index.js +1783 -216
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1784 -210
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,433 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2
4
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
var __esm = (fn, res) => function __init() {
|
|
6
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
7
|
+
};
|
|
8
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3
9
|
|
|
4
|
-
//
|
|
5
|
-
|
|
10
|
+
// node_modules/@opentelemetry/api/build/esm/platform/node/globalThis.js
|
|
11
|
+
var _globalThis;
|
|
12
|
+
var init_globalThis = __esm({
|
|
13
|
+
"node_modules/@opentelemetry/api/build/esm/platform/node/globalThis.js"() {
|
|
14
|
+
"use strict";
|
|
15
|
+
_globalThis = typeof globalThis === "object" ? globalThis : global;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// node_modules/@opentelemetry/api/build/esm/platform/node/index.js
|
|
20
|
+
var init_node = __esm({
|
|
21
|
+
"node_modules/@opentelemetry/api/build/esm/platform/node/index.js"() {
|
|
22
|
+
"use strict";
|
|
23
|
+
init_globalThis();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// node_modules/@opentelemetry/api/build/esm/platform/index.js
|
|
28
|
+
var init_platform = __esm({
|
|
29
|
+
"node_modules/@opentelemetry/api/build/esm/platform/index.js"() {
|
|
30
|
+
"use strict";
|
|
31
|
+
init_node();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// node_modules/@opentelemetry/api/build/esm/version.js
|
|
36
|
+
var VERSION;
|
|
37
|
+
var init_version = __esm({
|
|
38
|
+
"node_modules/@opentelemetry/api/build/esm/version.js"() {
|
|
39
|
+
"use strict";
|
|
40
|
+
VERSION = "1.9.0";
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// node_modules/@opentelemetry/api/build/esm/internal/semver.js
|
|
45
|
+
function _makeCompatibilityCheck(ownVersion) {
|
|
46
|
+
var acceptedVersions = /* @__PURE__ */ new Set([ownVersion]);
|
|
47
|
+
var rejectedVersions = /* @__PURE__ */ new Set();
|
|
48
|
+
var myVersionMatch = ownVersion.match(re);
|
|
49
|
+
if (!myVersionMatch) {
|
|
50
|
+
return function() {
|
|
51
|
+
return false;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
var ownVersionParsed = {
|
|
55
|
+
major: +myVersionMatch[1],
|
|
56
|
+
minor: +myVersionMatch[2],
|
|
57
|
+
patch: +myVersionMatch[3],
|
|
58
|
+
prerelease: myVersionMatch[4]
|
|
59
|
+
};
|
|
60
|
+
if (ownVersionParsed.prerelease != null) {
|
|
61
|
+
return /* @__PURE__ */ __name(function isExactmatch(globalVersion) {
|
|
62
|
+
return globalVersion === ownVersion;
|
|
63
|
+
}, "isExactmatch");
|
|
64
|
+
}
|
|
65
|
+
function _reject(v) {
|
|
66
|
+
rejectedVersions.add(v);
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
__name(_reject, "_reject");
|
|
70
|
+
function _accept(v) {
|
|
71
|
+
acceptedVersions.add(v);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
__name(_accept, "_accept");
|
|
75
|
+
return /* @__PURE__ */ __name(function isCompatible2(globalVersion) {
|
|
76
|
+
if (acceptedVersions.has(globalVersion)) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
if (rejectedVersions.has(globalVersion)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
var globalVersionMatch = globalVersion.match(re);
|
|
83
|
+
if (!globalVersionMatch) {
|
|
84
|
+
return _reject(globalVersion);
|
|
85
|
+
}
|
|
86
|
+
var globalVersionParsed = {
|
|
87
|
+
major: +globalVersionMatch[1],
|
|
88
|
+
minor: +globalVersionMatch[2],
|
|
89
|
+
patch: +globalVersionMatch[3],
|
|
90
|
+
prerelease: globalVersionMatch[4]
|
|
91
|
+
};
|
|
92
|
+
if (globalVersionParsed.prerelease != null) {
|
|
93
|
+
return _reject(globalVersion);
|
|
94
|
+
}
|
|
95
|
+
if (ownVersionParsed.major !== globalVersionParsed.major) {
|
|
96
|
+
return _reject(globalVersion);
|
|
97
|
+
}
|
|
98
|
+
if (ownVersionParsed.major === 0) {
|
|
99
|
+
if (ownVersionParsed.minor === globalVersionParsed.minor && ownVersionParsed.patch <= globalVersionParsed.patch) {
|
|
100
|
+
return _accept(globalVersion);
|
|
101
|
+
}
|
|
102
|
+
return _reject(globalVersion);
|
|
103
|
+
}
|
|
104
|
+
if (ownVersionParsed.minor <= globalVersionParsed.minor) {
|
|
105
|
+
return _accept(globalVersion);
|
|
106
|
+
}
|
|
107
|
+
return _reject(globalVersion);
|
|
108
|
+
}, "isCompatible");
|
|
109
|
+
}
|
|
110
|
+
var re, isCompatible;
|
|
111
|
+
var init_semver = __esm({
|
|
112
|
+
"node_modules/@opentelemetry/api/build/esm/internal/semver.js"() {
|
|
113
|
+
"use strict";
|
|
114
|
+
init_version();
|
|
115
|
+
re = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;
|
|
116
|
+
__name(_makeCompatibilityCheck, "_makeCompatibilityCheck");
|
|
117
|
+
isCompatible = _makeCompatibilityCheck(VERSION);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// node_modules/@opentelemetry/api/build/esm/internal/global-utils.js
|
|
122
|
+
function registerGlobal(type, instance, diag2, allowOverride) {
|
|
123
|
+
var _a;
|
|
124
|
+
if (allowOverride === void 0) {
|
|
125
|
+
allowOverride = false;
|
|
126
|
+
}
|
|
127
|
+
var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a !== void 0 ? _a : {
|
|
128
|
+
version: VERSION
|
|
129
|
+
};
|
|
130
|
+
if (!allowOverride && api[type]) {
|
|
131
|
+
var err = new Error("@opentelemetry/api: Attempted duplicate registration of API: " + type);
|
|
132
|
+
diag2.error(err.stack || err.message);
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
if (api.version !== VERSION) {
|
|
136
|
+
var err = new Error("@opentelemetry/api: Registration of version v" + api.version + " for " + type + " does not match previously registered API v" + VERSION);
|
|
137
|
+
diag2.error(err.stack || err.message);
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
api[type] = instance;
|
|
141
|
+
diag2.debug("@opentelemetry/api: Registered a global for " + type + " v" + VERSION + ".");
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
function getGlobal(type) {
|
|
145
|
+
var _a, _b;
|
|
146
|
+
var globalVersion = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a === void 0 ? void 0 : _a.version;
|
|
147
|
+
if (!globalVersion || !isCompatible(globalVersion)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
return (_b = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b === void 0 ? void 0 : _b[type];
|
|
151
|
+
}
|
|
152
|
+
function unregisterGlobal(type, diag2) {
|
|
153
|
+
diag2.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION + ".");
|
|
154
|
+
var api = _global[GLOBAL_OPENTELEMETRY_API_KEY];
|
|
155
|
+
if (api) {
|
|
156
|
+
delete api[type];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
var major, GLOBAL_OPENTELEMETRY_API_KEY, _global;
|
|
160
|
+
var init_global_utils = __esm({
|
|
161
|
+
"node_modules/@opentelemetry/api/build/esm/internal/global-utils.js"() {
|
|
162
|
+
"use strict";
|
|
163
|
+
init_platform();
|
|
164
|
+
init_version();
|
|
165
|
+
init_semver();
|
|
166
|
+
major = VERSION.split(".")[0];
|
|
167
|
+
GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for("opentelemetry.js.api." + major);
|
|
168
|
+
_global = _globalThis;
|
|
169
|
+
__name(registerGlobal, "registerGlobal");
|
|
170
|
+
__name(getGlobal, "getGlobal");
|
|
171
|
+
__name(unregisterGlobal, "unregisterGlobal");
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// node_modules/@opentelemetry/api/build/esm/diag/ComponentLogger.js
|
|
176
|
+
function logProxy(funcName, namespace, args) {
|
|
177
|
+
var logger = getGlobal("diag");
|
|
178
|
+
if (!logger) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
args.unshift(namespace);
|
|
182
|
+
return logger[funcName].apply(logger, __spreadArray([], __read(args), false));
|
|
183
|
+
}
|
|
184
|
+
var __read, __spreadArray, DiagComponentLogger;
|
|
185
|
+
var init_ComponentLogger = __esm({
|
|
186
|
+
"node_modules/@opentelemetry/api/build/esm/diag/ComponentLogger.js"() {
|
|
187
|
+
"use strict";
|
|
188
|
+
init_global_utils();
|
|
189
|
+
__read = function(o, n) {
|
|
190
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
191
|
+
if (!m) return o;
|
|
192
|
+
var i = m.call(o), r, ar = [], e;
|
|
193
|
+
try {
|
|
194
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
e = { error };
|
|
197
|
+
} finally {
|
|
198
|
+
try {
|
|
199
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
200
|
+
} finally {
|
|
201
|
+
if (e) throw e.error;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return ar;
|
|
205
|
+
};
|
|
206
|
+
__spreadArray = function(to, from, pack) {
|
|
207
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
208
|
+
if (ar || !(i in from)) {
|
|
209
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
210
|
+
ar[i] = from[i];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
214
|
+
};
|
|
215
|
+
DiagComponentLogger = /** @class */
|
|
216
|
+
(function() {
|
|
217
|
+
function DiagComponentLogger2(props) {
|
|
218
|
+
this._namespace = props.namespace || "DiagComponentLogger";
|
|
219
|
+
}
|
|
220
|
+
__name(DiagComponentLogger2, "DiagComponentLogger");
|
|
221
|
+
DiagComponentLogger2.prototype.debug = function() {
|
|
222
|
+
var args = [];
|
|
223
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
224
|
+
args[_i] = arguments[_i];
|
|
225
|
+
}
|
|
226
|
+
return logProxy("debug", this._namespace, args);
|
|
227
|
+
};
|
|
228
|
+
DiagComponentLogger2.prototype.error = function() {
|
|
229
|
+
var args = [];
|
|
230
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
231
|
+
args[_i] = arguments[_i];
|
|
232
|
+
}
|
|
233
|
+
return logProxy("error", this._namespace, args);
|
|
234
|
+
};
|
|
235
|
+
DiagComponentLogger2.prototype.info = function() {
|
|
236
|
+
var args = [];
|
|
237
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
238
|
+
args[_i] = arguments[_i];
|
|
239
|
+
}
|
|
240
|
+
return logProxy("info", this._namespace, args);
|
|
241
|
+
};
|
|
242
|
+
DiagComponentLogger2.prototype.warn = function() {
|
|
243
|
+
var args = [];
|
|
244
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
245
|
+
args[_i] = arguments[_i];
|
|
246
|
+
}
|
|
247
|
+
return logProxy("warn", this._namespace, args);
|
|
248
|
+
};
|
|
249
|
+
DiagComponentLogger2.prototype.verbose = function() {
|
|
250
|
+
var args = [];
|
|
251
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
252
|
+
args[_i] = arguments[_i];
|
|
253
|
+
}
|
|
254
|
+
return logProxy("verbose", this._namespace, args);
|
|
255
|
+
};
|
|
256
|
+
return DiagComponentLogger2;
|
|
257
|
+
})();
|
|
258
|
+
__name(logProxy, "logProxy");
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
// node_modules/@opentelemetry/api/build/esm/diag/types.js
|
|
263
|
+
var DiagLogLevel;
|
|
264
|
+
var init_types = __esm({
|
|
265
|
+
"node_modules/@opentelemetry/api/build/esm/diag/types.js"() {
|
|
266
|
+
"use strict";
|
|
267
|
+
(function(DiagLogLevel2) {
|
|
268
|
+
DiagLogLevel2[DiagLogLevel2["NONE"] = 0] = "NONE";
|
|
269
|
+
DiagLogLevel2[DiagLogLevel2["ERROR"] = 30] = "ERROR";
|
|
270
|
+
DiagLogLevel2[DiagLogLevel2["WARN"] = 50] = "WARN";
|
|
271
|
+
DiagLogLevel2[DiagLogLevel2["INFO"] = 60] = "INFO";
|
|
272
|
+
DiagLogLevel2[DiagLogLevel2["DEBUG"] = 70] = "DEBUG";
|
|
273
|
+
DiagLogLevel2[DiagLogLevel2["VERBOSE"] = 80] = "VERBOSE";
|
|
274
|
+
DiagLogLevel2[DiagLogLevel2["ALL"] = 9999] = "ALL";
|
|
275
|
+
})(DiagLogLevel || (DiagLogLevel = {}));
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// node_modules/@opentelemetry/api/build/esm/diag/internal/logLevelLogger.js
|
|
280
|
+
function createLogLevelDiagLogger(maxLevel, logger) {
|
|
281
|
+
if (maxLevel < DiagLogLevel.NONE) {
|
|
282
|
+
maxLevel = DiagLogLevel.NONE;
|
|
283
|
+
} else if (maxLevel > DiagLogLevel.ALL) {
|
|
284
|
+
maxLevel = DiagLogLevel.ALL;
|
|
285
|
+
}
|
|
286
|
+
logger = logger || {};
|
|
287
|
+
function _filterFunc(funcName, theLevel) {
|
|
288
|
+
var theFunc = logger[funcName];
|
|
289
|
+
if (typeof theFunc === "function" && maxLevel >= theLevel) {
|
|
290
|
+
return theFunc.bind(logger);
|
|
291
|
+
}
|
|
292
|
+
return function() {
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
__name(_filterFunc, "_filterFunc");
|
|
296
|
+
return {
|
|
297
|
+
error: _filterFunc("error", DiagLogLevel.ERROR),
|
|
298
|
+
warn: _filterFunc("warn", DiagLogLevel.WARN),
|
|
299
|
+
info: _filterFunc("info", DiagLogLevel.INFO),
|
|
300
|
+
debug: _filterFunc("debug", DiagLogLevel.DEBUG),
|
|
301
|
+
verbose: _filterFunc("verbose", DiagLogLevel.VERBOSE)
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
var init_logLevelLogger = __esm({
|
|
305
|
+
"node_modules/@opentelemetry/api/build/esm/diag/internal/logLevelLogger.js"() {
|
|
306
|
+
"use strict";
|
|
307
|
+
init_types();
|
|
308
|
+
__name(createLogLevelDiagLogger, "createLogLevelDiagLogger");
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
// node_modules/@opentelemetry/api/build/esm/api/diag.js
|
|
313
|
+
var __read2, __spreadArray2, API_NAME, DiagAPI;
|
|
314
|
+
var init_diag = __esm({
|
|
315
|
+
"node_modules/@opentelemetry/api/build/esm/api/diag.js"() {
|
|
316
|
+
"use strict";
|
|
317
|
+
init_ComponentLogger();
|
|
318
|
+
init_logLevelLogger();
|
|
319
|
+
init_types();
|
|
320
|
+
init_global_utils();
|
|
321
|
+
__read2 = function(o, n) {
|
|
322
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
323
|
+
if (!m) return o;
|
|
324
|
+
var i = m.call(o), r, ar = [], e;
|
|
325
|
+
try {
|
|
326
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
327
|
+
} catch (error) {
|
|
328
|
+
e = { error };
|
|
329
|
+
} finally {
|
|
330
|
+
try {
|
|
331
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
332
|
+
} finally {
|
|
333
|
+
if (e) throw e.error;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return ar;
|
|
337
|
+
};
|
|
338
|
+
__spreadArray2 = function(to, from, pack) {
|
|
339
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
340
|
+
if (ar || !(i in from)) {
|
|
341
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
342
|
+
ar[i] = from[i];
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
346
|
+
};
|
|
347
|
+
API_NAME = "diag";
|
|
348
|
+
DiagAPI = /** @class */
|
|
349
|
+
(function() {
|
|
350
|
+
function DiagAPI2() {
|
|
351
|
+
function _logProxy(funcName) {
|
|
352
|
+
return function() {
|
|
353
|
+
var args = [];
|
|
354
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
355
|
+
args[_i] = arguments[_i];
|
|
356
|
+
}
|
|
357
|
+
var logger = getGlobal("diag");
|
|
358
|
+
if (!logger)
|
|
359
|
+
return;
|
|
360
|
+
return logger[funcName].apply(logger, __spreadArray2([], __read2(args), false));
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
__name(_logProxy, "_logProxy");
|
|
364
|
+
var self = this;
|
|
365
|
+
var setLogger = /* @__PURE__ */ __name(function(logger, optionsOrLogLevel) {
|
|
366
|
+
var _a, _b, _c;
|
|
367
|
+
if (optionsOrLogLevel === void 0) {
|
|
368
|
+
optionsOrLogLevel = { logLevel: DiagLogLevel.INFO };
|
|
369
|
+
}
|
|
370
|
+
if (logger === self) {
|
|
371
|
+
var err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
|
|
372
|
+
self.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
if (typeof optionsOrLogLevel === "number") {
|
|
376
|
+
optionsOrLogLevel = {
|
|
377
|
+
logLevel: optionsOrLogLevel
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
var oldLogger = getGlobal("diag");
|
|
381
|
+
var newLogger = createLogLevelDiagLogger((_b = optionsOrLogLevel.logLevel) !== null && _b !== void 0 ? _b : DiagLogLevel.INFO, logger);
|
|
382
|
+
if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
|
|
383
|
+
var stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : "<failed to generate stacktrace>";
|
|
384
|
+
oldLogger.warn("Current logger will be overwritten from " + stack);
|
|
385
|
+
newLogger.warn("Current logger will overwrite one already registered from " + stack);
|
|
386
|
+
}
|
|
387
|
+
return registerGlobal("diag", newLogger, self, true);
|
|
388
|
+
}, "setLogger");
|
|
389
|
+
self.setLogger = setLogger;
|
|
390
|
+
self.disable = function() {
|
|
391
|
+
unregisterGlobal(API_NAME, self);
|
|
392
|
+
};
|
|
393
|
+
self.createComponentLogger = function(options) {
|
|
394
|
+
return new DiagComponentLogger(options);
|
|
395
|
+
};
|
|
396
|
+
self.verbose = _logProxy("verbose");
|
|
397
|
+
self.debug = _logProxy("debug");
|
|
398
|
+
self.info = _logProxy("info");
|
|
399
|
+
self.warn = _logProxy("warn");
|
|
400
|
+
self.error = _logProxy("error");
|
|
401
|
+
}
|
|
402
|
+
__name(DiagAPI2, "DiagAPI");
|
|
403
|
+
DiagAPI2.instance = function() {
|
|
404
|
+
if (!this._instance) {
|
|
405
|
+
this._instance = new DiagAPI2();
|
|
406
|
+
}
|
|
407
|
+
return this._instance;
|
|
408
|
+
};
|
|
409
|
+
return DiagAPI2;
|
|
410
|
+
})();
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// node_modules/@opentelemetry/api/build/esm/diag-api.js
|
|
415
|
+
var diag;
|
|
416
|
+
var init_diag_api = __esm({
|
|
417
|
+
"node_modules/@opentelemetry/api/build/esm/diag-api.js"() {
|
|
418
|
+
"use strict";
|
|
419
|
+
init_diag();
|
|
420
|
+
diag = DiagAPI.instance();
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
// node_modules/@opentelemetry/api/build/esm/index.js
|
|
425
|
+
var init_esm = __esm({
|
|
426
|
+
"node_modules/@opentelemetry/api/build/esm/index.js"() {
|
|
427
|
+
"use strict";
|
|
428
|
+
init_diag_api();
|
|
429
|
+
}
|
|
430
|
+
});
|
|
6
431
|
|
|
7
432
|
// src/framework/runtime-action/types.ts
|
|
8
433
|
var HttpStatus = /* @__PURE__ */ ((HttpStatus2) => {
|
|
@@ -61,183 +486,1281 @@ var _RuntimeActionResponse = class _RuntimeActionResponse {
|
|
|
61
486
|
}
|
|
62
487
|
};
|
|
63
488
|
}
|
|
64
|
-
};
|
|
65
|
-
__name(_RuntimeActionResponse, "RuntimeActionResponse");
|
|
66
|
-
var RuntimeActionResponse = _RuntimeActionResponse;
|
|
67
|
-
var response_default = RuntimeActionResponse;
|
|
68
|
-
|
|
69
|
-
// src/framework/runtime-action/
|
|
70
|
-
var
|
|
489
|
+
};
|
|
490
|
+
__name(_RuntimeActionResponse, "RuntimeActionResponse");
|
|
491
|
+
var RuntimeActionResponse = _RuntimeActionResponse;
|
|
492
|
+
var response_default = RuntimeActionResponse;
|
|
493
|
+
|
|
494
|
+
// src/framework/runtime-action/validator/index.ts
|
|
495
|
+
var _Validator = class _Validator {
|
|
496
|
+
/**
|
|
497
|
+
* Returns the list of missing keys given an object and its required keys.
|
|
498
|
+
* A parameter is missing if its value is undefined or ''.
|
|
499
|
+
* A value of 0 or null is not considered as missing.
|
|
500
|
+
*
|
|
501
|
+
* @param obj object to check.
|
|
502
|
+
* @param required list of required keys.
|
|
503
|
+
* Each element can be multi-level deep using a '.' separator e.g. 'myRequiredObj.myRequiredKey'
|
|
504
|
+
*
|
|
505
|
+
* @returns array
|
|
506
|
+
* @private
|
|
507
|
+
*/
|
|
508
|
+
static getMissingKeys(obj, required) {
|
|
509
|
+
return required.filter((r) => {
|
|
510
|
+
const splits = r.split(".");
|
|
511
|
+
const last = splits[splits.length - 1];
|
|
512
|
+
const traverse = splits.slice(0, -1).reduce((tObj, split) => tObj[split] || {}, obj);
|
|
513
|
+
return last && (traverse[last] === void 0 || traverse[last] === "");
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Returns the list of missing keys given an object and its required keys.
|
|
518
|
+
* A parameter is missing if its value is undefined or ''.
|
|
519
|
+
* A value of 0 or null is not considered as missing.
|
|
520
|
+
*
|
|
521
|
+
* @param params action input parameters.
|
|
522
|
+
* @param requiredHeaders list of required input headers.
|
|
523
|
+
* @param requiredParams list of required input parameters.
|
|
524
|
+
* Each element can be multi-level deep using a '.' separator e.g. 'myRequiredObj.myRequiredKey'.
|
|
525
|
+
*
|
|
526
|
+
* @returns string|null if the return value is not null, then it holds an error message describing the missing inputs.
|
|
527
|
+
*
|
|
528
|
+
*/
|
|
529
|
+
static checkMissingRequestInputs(params, requiredParams = [], requiredHeaders = []) {
|
|
530
|
+
let errorMessage = null;
|
|
531
|
+
requiredHeaders = requiredHeaders.map((h) => h.toLowerCase());
|
|
532
|
+
const normalizedHeaders = Object.keys(params.__ow_headers || {}).reduce(
|
|
533
|
+
(acc, key) => {
|
|
534
|
+
acc[key.toLowerCase()] = params.__ow_headers?.[key];
|
|
535
|
+
return acc;
|
|
536
|
+
},
|
|
537
|
+
{}
|
|
538
|
+
);
|
|
539
|
+
const missingHeaders = _Validator.getMissingKeys(normalizedHeaders, requiredHeaders);
|
|
540
|
+
if (missingHeaders.length > 0) {
|
|
541
|
+
errorMessage = `missing header(s) '${missingHeaders.join(", ")}'`;
|
|
542
|
+
}
|
|
543
|
+
const missingParams = _Validator.getMissingKeys(params, requiredParams);
|
|
544
|
+
if (missingParams.length > 0) {
|
|
545
|
+
if (errorMessage) {
|
|
546
|
+
errorMessage += " and ";
|
|
547
|
+
} else {
|
|
548
|
+
errorMessage = "";
|
|
549
|
+
}
|
|
550
|
+
errorMessage += `missing parameter(s) '${missingParams.join(", ")}'`;
|
|
551
|
+
}
|
|
552
|
+
return errorMessage;
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
__name(_Validator, "Validator");
|
|
556
|
+
var Validator = _Validator;
|
|
557
|
+
var validator_default = Validator;
|
|
558
|
+
|
|
559
|
+
// src/framework/telemetry/index.ts
|
|
560
|
+
import { Core } from "@adobe/aio-sdk";
|
|
561
|
+
import { getLogger } from "@adobe/aio-lib-telemetry";
|
|
562
|
+
|
|
563
|
+
// src/framework/telemetry/new-relic/index.ts
|
|
564
|
+
import {
|
|
565
|
+
defineTelemetryConfig,
|
|
566
|
+
getPresetInstrumentations,
|
|
567
|
+
instrumentEntrypoint
|
|
568
|
+
} from "@adobe/aio-lib-telemetry";
|
|
569
|
+
|
|
570
|
+
// src/framework/telemetry/helpers/input-error/index.ts
|
|
571
|
+
var _TelemetryInputError = class _TelemetryInputError extends Error {
|
|
572
|
+
/**
|
|
573
|
+
* Creates a new TelemetryInputError
|
|
574
|
+
*
|
|
575
|
+
* @param message - Descriptive error message explaining the validation failure
|
|
576
|
+
*/
|
|
577
|
+
constructor(message) {
|
|
578
|
+
super(message);
|
|
579
|
+
this.name = "TelemetryInputError";
|
|
580
|
+
if (Error.captureStackTrace) {
|
|
581
|
+
Error.captureStackTrace(this, _TelemetryInputError);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
__name(_TelemetryInputError, "TelemetryInputError");
|
|
586
|
+
var TelemetryInputError = _TelemetryInputError;
|
|
587
|
+
|
|
588
|
+
// src/framework/telemetry/new-relic/validator/index.ts
|
|
589
|
+
var _NewRelicTelemetryValidator = class _NewRelicTelemetryValidator {
|
|
590
|
+
/**
|
|
591
|
+
* Checks if New Relic telemetry is configured
|
|
592
|
+
*
|
|
593
|
+
* Returns true if:
|
|
594
|
+
* - ENABLE_TELEMETRY is explicitly set to true
|
|
595
|
+
* - NEW_RELIC_TELEMETRY is explicitly set to true
|
|
596
|
+
*
|
|
597
|
+
* This method does NOT validate the completeness of configuration,
|
|
598
|
+
* it only checks if the provider is enabled.
|
|
599
|
+
*
|
|
600
|
+
* @param params - Runtime parameters to check
|
|
601
|
+
* @returns true if New Relic telemetry is enabled, false otherwise
|
|
602
|
+
*
|
|
603
|
+
* @example
|
|
604
|
+
* ```typescript
|
|
605
|
+
* const validator = new NewRelicTelemetryValidator();
|
|
606
|
+
* const params = { ENABLE_TELEMETRY: true, NEW_RELIC_TELEMETRY: true };
|
|
607
|
+
* if (validator.isConfigured(params)) {
|
|
608
|
+
* // New Relic is enabled, proceed with initialization
|
|
609
|
+
* }
|
|
610
|
+
* ```
|
|
611
|
+
*/
|
|
612
|
+
isConfigured(params) {
|
|
613
|
+
return params.ENABLE_TELEMETRY === true && params.NEW_RELIC_TELEMETRY === true;
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Validates New Relic specific parameters
|
|
617
|
+
*
|
|
618
|
+
* IMPORTANT: Only call this method after checking isConfigured() returns true.
|
|
619
|
+
* This method assumes New Relic telemetry is enabled and validates that
|
|
620
|
+
* all required parameters are present.
|
|
621
|
+
*
|
|
622
|
+
* Required parameters when New Relic is enabled:
|
|
623
|
+
* - NEW_RELIC_SERVICE_NAME must be provided
|
|
624
|
+
* - NEW_RELIC_LICENSE_KEY must be provided
|
|
625
|
+
*
|
|
626
|
+
* @param params - Runtime parameters to validate
|
|
627
|
+
* @throws {TelemetryInputError} If NEW_RELIC_SERVICE_NAME is missing
|
|
628
|
+
* @throws {TelemetryInputError} If NEW_RELIC_LICENSE_KEY is missing
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```typescript
|
|
632
|
+
* const validator = new NewRelicTelemetryValidator();
|
|
633
|
+
* const params = {
|
|
634
|
+
* ENABLE_TELEMETRY: true,
|
|
635
|
+
* NEW_RELIC_TELEMETRY: true,
|
|
636
|
+
* NEW_RELIC_SERVICE_NAME: "my-service",
|
|
637
|
+
* NEW_RELIC_LICENSE_KEY: "license-key"
|
|
638
|
+
* };
|
|
639
|
+
*
|
|
640
|
+
* if (validator.isConfigured(params)) {
|
|
641
|
+
* validator.validateConfiguration(params); // Validates required fields
|
|
642
|
+
* }
|
|
643
|
+
* ```
|
|
644
|
+
*/
|
|
645
|
+
validateConfiguration(params) {
|
|
646
|
+
if (params.NEW_RELIC_SERVICE_NAME === void 0 || params.NEW_RELIC_SERVICE_NAME === null || params.NEW_RELIC_SERVICE_NAME === "") {
|
|
647
|
+
throw new TelemetryInputError("NEW_RELIC_SERVICE_NAME is required");
|
|
648
|
+
}
|
|
649
|
+
if (params.NEW_RELIC_LICENSE_KEY === void 0 || params.NEW_RELIC_LICENSE_KEY === null || params.NEW_RELIC_LICENSE_KEY === "") {
|
|
650
|
+
throw new TelemetryInputError("NEW_RELIC_LICENSE_KEY is required");
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
__name(_NewRelicTelemetryValidator, "NewRelicTelemetryValidator");
|
|
655
|
+
var NewRelicTelemetryValidator = _NewRelicTelemetryValidator;
|
|
656
|
+
|
|
657
|
+
// src/framework/telemetry/helpers/resource-factory/index.ts
|
|
658
|
+
import { getAioRuntimeResource } from "@adobe/aio-lib-telemetry";
|
|
659
|
+
|
|
660
|
+
// node_modules/@opentelemetry/resources/build/esm/ResourceImpl.js
|
|
661
|
+
init_esm();
|
|
662
|
+
|
|
663
|
+
// node_modules/@opentelemetry/resources/build/esm/utils.js
|
|
664
|
+
var isPromiseLike = /* @__PURE__ */ __name((val) => {
|
|
665
|
+
return val !== null && typeof val === "object" && typeof val.then === "function";
|
|
666
|
+
}, "isPromiseLike");
|
|
667
|
+
|
|
668
|
+
// node_modules/@opentelemetry/resources/build/esm/ResourceImpl.js
|
|
669
|
+
var _ResourceImpl = class _ResourceImpl {
|
|
670
|
+
constructor(resource, options) {
|
|
671
|
+
__publicField(this, "_rawAttributes");
|
|
672
|
+
__publicField(this, "_asyncAttributesPending", false);
|
|
673
|
+
__publicField(this, "_schemaUrl");
|
|
674
|
+
__publicField(this, "_memoizedAttributes");
|
|
675
|
+
const attributes = resource.attributes ?? {};
|
|
676
|
+
this._rawAttributes = Object.entries(attributes).map(([k, v]) => {
|
|
677
|
+
if (isPromiseLike(v)) {
|
|
678
|
+
this._asyncAttributesPending = true;
|
|
679
|
+
}
|
|
680
|
+
return [k, v];
|
|
681
|
+
});
|
|
682
|
+
this._rawAttributes = guardedRawAttributes(this._rawAttributes);
|
|
683
|
+
this._schemaUrl = validateSchemaUrl(options?.schemaUrl);
|
|
684
|
+
}
|
|
685
|
+
static FromAttributeList(attributes, options) {
|
|
686
|
+
const res = new _ResourceImpl({}, options);
|
|
687
|
+
res._rawAttributes = guardedRawAttributes(attributes);
|
|
688
|
+
res._asyncAttributesPending = attributes.filter(([_, val]) => isPromiseLike(val)).length > 0;
|
|
689
|
+
return res;
|
|
690
|
+
}
|
|
691
|
+
get asyncAttributesPending() {
|
|
692
|
+
return this._asyncAttributesPending;
|
|
693
|
+
}
|
|
694
|
+
async waitForAsyncAttributes() {
|
|
695
|
+
if (!this.asyncAttributesPending) {
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
for (let i = 0; i < this._rawAttributes.length; i++) {
|
|
699
|
+
const [k, v] = this._rawAttributes[i];
|
|
700
|
+
this._rawAttributes[i] = [k, isPromiseLike(v) ? await v : v];
|
|
701
|
+
}
|
|
702
|
+
this._asyncAttributesPending = false;
|
|
703
|
+
}
|
|
704
|
+
get attributes() {
|
|
705
|
+
if (this.asyncAttributesPending) {
|
|
706
|
+
diag.error("Accessing resource attributes before async attributes settled");
|
|
707
|
+
}
|
|
708
|
+
if (this._memoizedAttributes) {
|
|
709
|
+
return this._memoizedAttributes;
|
|
710
|
+
}
|
|
711
|
+
const attrs = {};
|
|
712
|
+
for (const [k, v] of this._rawAttributes) {
|
|
713
|
+
if (isPromiseLike(v)) {
|
|
714
|
+
diag.debug(`Unsettled resource attribute ${k} skipped`);
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
if (v != null) {
|
|
718
|
+
attrs[k] ?? (attrs[k] = v);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
if (!this._asyncAttributesPending) {
|
|
722
|
+
this._memoizedAttributes = attrs;
|
|
723
|
+
}
|
|
724
|
+
return attrs;
|
|
725
|
+
}
|
|
726
|
+
getRawAttributes() {
|
|
727
|
+
return this._rawAttributes;
|
|
728
|
+
}
|
|
729
|
+
get schemaUrl() {
|
|
730
|
+
return this._schemaUrl;
|
|
731
|
+
}
|
|
732
|
+
merge(resource) {
|
|
733
|
+
if (resource == null)
|
|
734
|
+
return this;
|
|
735
|
+
const mergedSchemaUrl = mergeSchemaUrl(this, resource);
|
|
736
|
+
const mergedOptions = mergedSchemaUrl ? { schemaUrl: mergedSchemaUrl } : void 0;
|
|
737
|
+
return _ResourceImpl.FromAttributeList([...resource.getRawAttributes(), ...this.getRawAttributes()], mergedOptions);
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
__name(_ResourceImpl, "ResourceImpl");
|
|
741
|
+
var ResourceImpl = _ResourceImpl;
|
|
742
|
+
function resourceFromAttributes(attributes, options) {
|
|
743
|
+
return ResourceImpl.FromAttributeList(Object.entries(attributes), options);
|
|
744
|
+
}
|
|
745
|
+
__name(resourceFromAttributes, "resourceFromAttributes");
|
|
746
|
+
function guardedRawAttributes(attributes) {
|
|
747
|
+
return attributes.map(([k, v]) => {
|
|
748
|
+
if (isPromiseLike(v)) {
|
|
749
|
+
return [
|
|
750
|
+
k,
|
|
751
|
+
v.catch((err) => {
|
|
752
|
+
diag.debug("promise rejection for resource attribute: %s - %s", k, err);
|
|
753
|
+
return void 0;
|
|
754
|
+
})
|
|
755
|
+
];
|
|
756
|
+
}
|
|
757
|
+
return [k, v];
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
__name(guardedRawAttributes, "guardedRawAttributes");
|
|
761
|
+
function validateSchemaUrl(schemaUrl) {
|
|
762
|
+
if (typeof schemaUrl === "string" || schemaUrl === void 0) {
|
|
763
|
+
return schemaUrl;
|
|
764
|
+
}
|
|
765
|
+
diag.warn("Schema URL must be string or undefined, got %s. Schema URL will be ignored.", schemaUrl);
|
|
766
|
+
return void 0;
|
|
767
|
+
}
|
|
768
|
+
__name(validateSchemaUrl, "validateSchemaUrl");
|
|
769
|
+
function mergeSchemaUrl(old, updating) {
|
|
770
|
+
const oldSchemaUrl = old?.schemaUrl;
|
|
771
|
+
const updatingSchemaUrl = updating?.schemaUrl;
|
|
772
|
+
const isOldEmpty = oldSchemaUrl === void 0 || oldSchemaUrl === "";
|
|
773
|
+
const isUpdatingEmpty = updatingSchemaUrl === void 0 || updatingSchemaUrl === "";
|
|
774
|
+
if (isOldEmpty) {
|
|
775
|
+
return updatingSchemaUrl;
|
|
776
|
+
}
|
|
777
|
+
if (isUpdatingEmpty) {
|
|
778
|
+
return oldSchemaUrl;
|
|
779
|
+
}
|
|
780
|
+
if (oldSchemaUrl === updatingSchemaUrl) {
|
|
781
|
+
return oldSchemaUrl;
|
|
782
|
+
}
|
|
783
|
+
diag.warn('Schema URL merge conflict: old resource has "%s", updating resource has "%s". Resulting resource will have undefined Schema URL.', oldSchemaUrl, updatingSchemaUrl);
|
|
784
|
+
return void 0;
|
|
785
|
+
}
|
|
786
|
+
__name(mergeSchemaUrl, "mergeSchemaUrl");
|
|
787
|
+
|
|
788
|
+
// src/framework/telemetry/helpers/resource-factory/index.ts
|
|
789
|
+
var _ResourceFactory = class _ResourceFactory {
|
|
790
|
+
/**
|
|
791
|
+
* Creates a resource with custom environment attributes
|
|
792
|
+
*
|
|
793
|
+
* Starts with the base Adobe I/O Runtime resource and optionally
|
|
794
|
+
* merges environment attributes. These attributes are useful for
|
|
795
|
+
* filtering and correlating telemetry data by deployment environment.
|
|
796
|
+
*
|
|
797
|
+
* Note: Request-specific data (like request IDs) should NOT be added to
|
|
798
|
+
* Resources as they are created once and reused across all requests.
|
|
799
|
+
* Use log attributes or span attributes for request-specific data.
|
|
800
|
+
*
|
|
801
|
+
* @param params - Runtime parameters containing optional ENVIRONMENT
|
|
802
|
+
* @param params.ENVIRONMENT - Environment name (e.g., "dev", "stage", "prod")
|
|
803
|
+
* @returns OpenTelemetry Resource with custom attributes if provided
|
|
804
|
+
*
|
|
805
|
+
* @example Without custom attributes
|
|
806
|
+
* ```typescript
|
|
807
|
+
* const factory = new ResourceFactory();
|
|
808
|
+
* const resource = factory.createWithEnvironment({});
|
|
809
|
+
* // Returns base Adobe I/O Runtime resource
|
|
810
|
+
* ```
|
|
811
|
+
*
|
|
812
|
+
* @example With environment
|
|
813
|
+
* ```typescript
|
|
814
|
+
* const factory = new ResourceFactory();
|
|
815
|
+
* const params = { ENVIRONMENT: "production" };
|
|
816
|
+
* const resource = factory.createWithEnvironment(params);
|
|
817
|
+
* // Returns resource with environment="production" attribute
|
|
818
|
+
* ```
|
|
819
|
+
*/
|
|
820
|
+
createWithEnvironment(params) {
|
|
821
|
+
const baseResource = getAioRuntimeResource();
|
|
822
|
+
const customAttributes = {};
|
|
823
|
+
if (params.ENVIRONMENT) {
|
|
824
|
+
customAttributes.environment = params.ENVIRONMENT;
|
|
825
|
+
}
|
|
826
|
+
if (Object.keys(customAttributes).length === 0) {
|
|
827
|
+
return baseResource;
|
|
828
|
+
}
|
|
829
|
+
const customResource = resourceFromAttributes(
|
|
830
|
+
customAttributes
|
|
831
|
+
);
|
|
832
|
+
return baseResource.merge(customResource);
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
__name(_ResourceFactory, "ResourceFactory");
|
|
836
|
+
var ResourceFactory = _ResourceFactory;
|
|
837
|
+
|
|
838
|
+
// src/framework/telemetry/helpers/success-checker/index.ts
|
|
839
|
+
var _SuccessChecker = class _SuccessChecker {
|
|
840
|
+
/**
|
|
841
|
+
* Determines if an action execution was successful
|
|
842
|
+
*
|
|
843
|
+
* Success criteria:
|
|
844
|
+
* - Response has statusCode 200
|
|
845
|
+
* - Body does not contain an exception operation
|
|
846
|
+
*
|
|
847
|
+
* @param result - The action execution result
|
|
848
|
+
* @returns true if successful, false otherwise
|
|
849
|
+
*
|
|
850
|
+
* @example Success case
|
|
851
|
+
* ```typescript
|
|
852
|
+
* const checker = new SuccessChecker();
|
|
853
|
+
* const result = { statusCode: 200, body: { data: 'success' } };
|
|
854
|
+
* checker.execute(result); // true
|
|
855
|
+
* ```
|
|
856
|
+
*
|
|
857
|
+
* @example Failure case - wrong status code
|
|
858
|
+
* ```typescript
|
|
859
|
+
* const checker = new SuccessChecker();
|
|
860
|
+
* const result = { statusCode: 500, body: { error: 'Internal error' } };
|
|
861
|
+
* checker.execute(result); // false
|
|
862
|
+
* ```
|
|
863
|
+
*
|
|
864
|
+
* @example Failure case - exception in body
|
|
865
|
+
* ```typescript
|
|
866
|
+
* const checker = new SuccessChecker();
|
|
867
|
+
* const result = { statusCode: 200, body: { op: 'exception', message: 'Error' } };
|
|
868
|
+
* checker.execute(result); // false
|
|
869
|
+
* ```
|
|
870
|
+
*/
|
|
871
|
+
execute(result) {
|
|
872
|
+
if (!result || typeof result !== "object") {
|
|
873
|
+
return false;
|
|
874
|
+
}
|
|
875
|
+
const actionResult = result;
|
|
876
|
+
if (actionResult.statusCode !== 200) {
|
|
877
|
+
return false;
|
|
878
|
+
}
|
|
879
|
+
if (actionResult.body && typeof actionResult.body === "object") {
|
|
880
|
+
return actionResult.body.op !== "exception";
|
|
881
|
+
}
|
|
882
|
+
return true;
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
__name(_SuccessChecker, "SuccessChecker");
|
|
886
|
+
var SuccessChecker = _SuccessChecker;
|
|
887
|
+
|
|
888
|
+
// src/framework/telemetry/new-relic/index.ts
|
|
889
|
+
import {
|
|
890
|
+
OTLPLogExporterProto,
|
|
891
|
+
OTLPMetricExporterProto,
|
|
892
|
+
OTLPTraceExporterProto,
|
|
893
|
+
PeriodicExportingMetricReader,
|
|
894
|
+
SimpleLogRecordProcessor
|
|
895
|
+
} from "@adobe/aio-lib-telemetry/otel";
|
|
896
|
+
|
|
897
|
+
// src/framework/telemetry/helpers/json-message-processor/index.ts
|
|
898
|
+
var _JsonMessageProcessor = class _JsonMessageProcessor {
|
|
899
|
+
/**
|
|
900
|
+
* Creates a new JsonMessageProcessor
|
|
901
|
+
*
|
|
902
|
+
* @param wrappedProcessor - The log processor to wrap and enhance
|
|
903
|
+
*
|
|
904
|
+
* @example
|
|
905
|
+
* ```typescript
|
|
906
|
+
* const exporter = new OTLPLogExporterProto({
|
|
907
|
+
* url: "https://otlp.nr-data.net/v1/logs",
|
|
908
|
+
* headers: { "api-key": licenseKey }
|
|
909
|
+
* });
|
|
910
|
+
* const baseProcessor = new SimpleLogRecordProcessor(exporter);
|
|
911
|
+
* const processor = new JsonMessageProcessor(baseProcessor);
|
|
912
|
+
* ```
|
|
913
|
+
*/
|
|
914
|
+
constructor(wrappedProcessor) {
|
|
915
|
+
this.wrappedProcessor = wrappedProcessor;
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Parse JavaScript object notation and convert to proper object
|
|
919
|
+
*
|
|
920
|
+
* Handles Winston's util.inspect format which produces JavaScript
|
|
921
|
+
* object literals instead of JSON strings.
|
|
922
|
+
*
|
|
923
|
+
* Examples:
|
|
924
|
+
* - { key: 'value' } → {"key":"value"}
|
|
925
|
+
* - { 'accept-encoding': 'gzip' } → {"accept-encoding":"gzip"}
|
|
926
|
+
*
|
|
927
|
+
* @param str - JavaScript object notation string
|
|
928
|
+
* @returns Parsed object
|
|
929
|
+
* @throws Error if parsing fails
|
|
930
|
+
* @private
|
|
931
|
+
*/
|
|
932
|
+
parseJavaScriptObjectNotation(str) {
|
|
933
|
+
const func = new Function("return (" + str + ")");
|
|
934
|
+
return func();
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Flatten nested objects into dot-notation keys
|
|
938
|
+
*
|
|
939
|
+
* Converts nested structures like:
|
|
940
|
+
* { headers: { accept: '*' } }
|
|
941
|
+
*
|
|
942
|
+
* Into flat structure:
|
|
943
|
+
* { 'headers.accept': '*' }
|
|
944
|
+
*
|
|
945
|
+
* This makes all attributes searchable in observability platforms.
|
|
946
|
+
*
|
|
947
|
+
* @param obj - Object to flatten
|
|
948
|
+
* @param prefix - Current key prefix (used in recursion)
|
|
949
|
+
* @returns Flattened object with dot-notation keys
|
|
950
|
+
* @private
|
|
951
|
+
*/
|
|
952
|
+
flattenObject(obj, prefix = "") {
|
|
953
|
+
const flattened = {};
|
|
954
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
955
|
+
const newKey = prefix ? `${prefix}.${key}` : key;
|
|
956
|
+
if (value === null || value === void 0) {
|
|
957
|
+
flattened[newKey] = value;
|
|
958
|
+
} else if (Array.isArray(value)) {
|
|
959
|
+
flattened[newKey] = JSON.stringify(value);
|
|
960
|
+
} else if (typeof value === "object") {
|
|
961
|
+
if (Object.keys(value).length === 0) {
|
|
962
|
+
continue;
|
|
963
|
+
}
|
|
964
|
+
const nested = this.flattenObject(value, newKey);
|
|
965
|
+
Object.assign(flattened, nested);
|
|
966
|
+
} else {
|
|
967
|
+
flattened[newKey] = value;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
return flattened;
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* Processes a log record by parsing JSON messages and extracting attributes
|
|
974
|
+
*
|
|
975
|
+
* This method intercepts log records, attempts to parse structured data
|
|
976
|
+
* from the message body, and merges extracted properties as attributes.
|
|
977
|
+
* Additionally, it extracts the log level from the severity information
|
|
978
|
+
* and adds it as a 'level' attribute for easier querying.
|
|
979
|
+
*
|
|
980
|
+
* The enhanced log record is then passed to the wrapped processor.
|
|
981
|
+
*
|
|
982
|
+
* @param logRecord - The log record to process
|
|
983
|
+
*
|
|
984
|
+
* @remarks
|
|
985
|
+
* Processing steps:
|
|
986
|
+
* 1. Extract log level from severityText or severityNumber
|
|
987
|
+
* 2. Add 'level' attribute (debug, info, warn, error, etc.)
|
|
988
|
+
* 3. Parse JSON bodies that start with '{'
|
|
989
|
+
* 4. Extract properties as individual attributes
|
|
990
|
+
* 5. Preserve 'message' field as primary log body
|
|
991
|
+
*
|
|
992
|
+
* Error handling:
|
|
993
|
+
* - Silently handles parsing errors to avoid breaking the logging pipeline
|
|
994
|
+
* - Failed parsing results in unmodified log record
|
|
995
|
+
*/
|
|
996
|
+
onEmit(logRecord) {
|
|
997
|
+
try {
|
|
998
|
+
if (logRecord.severityText) {
|
|
999
|
+
logRecord.setAttribute("level", logRecord.severityText.toLowerCase());
|
|
1000
|
+
} else if (logRecord.severityNumber !== void 0) {
|
|
1001
|
+
const levelName = this.mapSeverityNumberToLevel(logRecord.severityNumber);
|
|
1002
|
+
if (levelName) {
|
|
1003
|
+
logRecord.setAttribute("level", levelName);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
const body = logRecord.body;
|
|
1007
|
+
if (typeof body === "string" && body.trim().startsWith("{")) {
|
|
1008
|
+
let parsed = null;
|
|
1009
|
+
try {
|
|
1010
|
+
parsed = JSON.parse(body);
|
|
1011
|
+
} catch {
|
|
1012
|
+
try {
|
|
1013
|
+
parsed = this.parseJavaScriptObjectNotation(body);
|
|
1014
|
+
} catch {
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1018
|
+
const messageValue = parsed.message;
|
|
1019
|
+
const { message, ...attributesObj } = parsed;
|
|
1020
|
+
const flattenedAttributes = this.flattenObject(attributesObj);
|
|
1021
|
+
Object.entries(flattenedAttributes).forEach(([key, value]) => {
|
|
1022
|
+
if (value !== void 0 && value !== null) {
|
|
1023
|
+
logRecord.setAttribute(key, value);
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
1026
|
+
if (messageValue) {
|
|
1027
|
+
logRecord.body = messageValue;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
} catch {
|
|
1032
|
+
}
|
|
1033
|
+
this.wrappedProcessor.onEmit(logRecord);
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Maps OpenTelemetry severity number to log level name
|
|
1037
|
+
*
|
|
1038
|
+
* OpenTelemetry defines severity numbers from 1-24:
|
|
1039
|
+
* - 1-4: TRACE
|
|
1040
|
+
* - 5-8: DEBUG
|
|
1041
|
+
* - 9-12: INFO
|
|
1042
|
+
* - 13-16: WARN
|
|
1043
|
+
* - 17-20: ERROR
|
|
1044
|
+
* - 21-24: FATAL
|
|
1045
|
+
*
|
|
1046
|
+
* @param severityNumber - OpenTelemetry severity number
|
|
1047
|
+
* @returns Log level name (trace, debug, info, warn, error, fatal) or null
|
|
1048
|
+
* @private
|
|
1049
|
+
*/
|
|
1050
|
+
mapSeverityNumberToLevel(severityNumber) {
|
|
1051
|
+
if (severityNumber >= 1 && severityNumber <= 4) return "trace";
|
|
1052
|
+
if (severityNumber >= 5 && severityNumber <= 8) return "debug";
|
|
1053
|
+
if (severityNumber >= 9 && severityNumber <= 12) return "info";
|
|
1054
|
+
if (severityNumber >= 13 && severityNumber <= 16) return "warn";
|
|
1055
|
+
if (severityNumber >= 17 && severityNumber <= 20) return "error";
|
|
1056
|
+
if (severityNumber >= 21 && severityNumber <= 24) return "fatal";
|
|
1057
|
+
return null;
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* Forces the processor to flush any pending log records
|
|
1061
|
+
*
|
|
1062
|
+
* Delegates to the wrapped processor's forceFlush method.
|
|
1063
|
+
* Useful for ensuring logs are sent before application shutdown.
|
|
1064
|
+
*
|
|
1065
|
+
* @returns Promise that resolves when flush is complete
|
|
1066
|
+
*
|
|
1067
|
+
* @example
|
|
1068
|
+
* ```typescript
|
|
1069
|
+
* await processor.forceFlush();
|
|
1070
|
+
* console.log("All logs have been sent");
|
|
1071
|
+
* ```
|
|
1072
|
+
*/
|
|
1073
|
+
async forceFlush() {
|
|
1074
|
+
return this.wrappedProcessor.forceFlush();
|
|
1075
|
+
}
|
|
1076
|
+
/**
|
|
1077
|
+
* Shuts down the processor and releases resources
|
|
1078
|
+
*
|
|
1079
|
+
* Delegates to the wrapped processor's shutdown method.
|
|
1080
|
+
* Should be called when the application is terminating.
|
|
1081
|
+
*
|
|
1082
|
+
* @returns Promise that resolves when shutdown is complete
|
|
1083
|
+
*
|
|
1084
|
+
* @example
|
|
1085
|
+
* ```typescript
|
|
1086
|
+
* await processor.shutdown();
|
|
1087
|
+
* console.log("Processor has been shut down");
|
|
1088
|
+
* ```
|
|
1089
|
+
*/
|
|
1090
|
+
async shutdown() {
|
|
1091
|
+
return this.wrappedProcessor.shutdown();
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
__name(_JsonMessageProcessor, "JsonMessageProcessor");
|
|
1095
|
+
var JsonMessageProcessor = _JsonMessageProcessor;
|
|
1096
|
+
|
|
1097
|
+
// src/framework/telemetry/new-relic/index.ts
|
|
1098
|
+
var _NewRelicTelemetry = class _NewRelicTelemetry {
|
|
1099
|
+
/**
|
|
1100
|
+
* Constructor for New Relic telemetry
|
|
1101
|
+
*
|
|
1102
|
+
* @description Constructor for New Relic telemetry
|
|
1103
|
+
* @example
|
|
1104
|
+
* ```typescript
|
|
1105
|
+
* const telemetry = new NewRelicTelemetry();
|
|
1106
|
+
* ```
|
|
1107
|
+
*/
|
|
1108
|
+
constructor() {
|
|
1109
|
+
this.validator = new NewRelicTelemetryValidator();
|
|
1110
|
+
this.successChecker = new SuccessChecker();
|
|
1111
|
+
this.resourceFactory = new ResourceFactory();
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Checks if New Relic telemetry can be initialized
|
|
1115
|
+
*
|
|
1116
|
+
* Determines if New Relic telemetry is properly configured without actually
|
|
1117
|
+
* attempting initialization. Useful for provider chain fallback logic.
|
|
1118
|
+
*
|
|
1119
|
+
* @param params - Runtime parameters to check
|
|
1120
|
+
* @returns true if New Relic is configured and can be initialized
|
|
1121
|
+
*
|
|
1122
|
+
* @example
|
|
1123
|
+
* ```typescript
|
|
1124
|
+
* const telemetry = new NewRelicTelemetry();
|
|
1125
|
+
* if (telemetry.canInitialize(params)) {
|
|
1126
|
+
* // New Relic is configured, use it
|
|
1127
|
+
* } else {
|
|
1128
|
+
* // Try next provider
|
|
1129
|
+
* }
|
|
1130
|
+
* ```
|
|
1131
|
+
*/
|
|
1132
|
+
canInitialize(params) {
|
|
1133
|
+
return this.validator.isConfigured(params);
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Get the OpenTelemetry instrumentation configuration for New Relic
|
|
1137
|
+
*
|
|
1138
|
+
* Builds and returns the complete instrumentation configuration including:
|
|
1139
|
+
* - Service name and preset instrumentations
|
|
1140
|
+
* - Custom resource attributes (environment)
|
|
1141
|
+
* - OTLP exporters for traces, metrics, and logs
|
|
1142
|
+
* - Success/failure detection for actions
|
|
1143
|
+
*
|
|
1144
|
+
* This method is called internally by `instrumentEntrypoint` to configure
|
|
1145
|
+
* telemetry before wrapping the action.
|
|
1146
|
+
*
|
|
1147
|
+
* @returns Complete entrypoint instrumentation configuration
|
|
1148
|
+
* @throws {TelemetryInputError} If required parameters are missing (service name, license key)
|
|
1149
|
+
*
|
|
1150
|
+
* @example
|
|
1151
|
+
* ```typescript
|
|
1152
|
+
* const telemetry = new NewRelicTelemetry();
|
|
1153
|
+
* const config = telemetry.getConfig();
|
|
1154
|
+
* // Returns configuration with exporters, instrumentations, and resource attributes
|
|
1155
|
+
* ```
|
|
1156
|
+
*/
|
|
1157
|
+
getConfig() {
|
|
1158
|
+
return {
|
|
1159
|
+
...defineTelemetryConfig((params) => {
|
|
1160
|
+
if (!this.validator.isConfigured(params)) {
|
|
1161
|
+
throw new Error("New Relic telemetry is not configured");
|
|
1162
|
+
}
|
|
1163
|
+
this.validator.validateConfiguration(params);
|
|
1164
|
+
const serviceName = params.NEW_RELIC_SERVICE_NAME;
|
|
1165
|
+
return {
|
|
1166
|
+
sdkConfig: {
|
|
1167
|
+
serviceName,
|
|
1168
|
+
instrumentations: getPresetInstrumentations("simple"),
|
|
1169
|
+
resource: this.resourceFactory.createWithEnvironment(params),
|
|
1170
|
+
...this.getExportersConfig(params)
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
}),
|
|
1174
|
+
isSuccessful: this.successChecker.execute.bind(this.successChecker)
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Configure New Relic exporters for traces, metrics, and logs
|
|
1179
|
+
*
|
|
1180
|
+
* Creates OTLP exporters for all three signal types (traces, metrics, logs)
|
|
1181
|
+
* and configures them to send data to New Relic. Log processors are wrapped
|
|
1182
|
+
* with JsonMessageProcessor for better attribute extraction.
|
|
1183
|
+
*
|
|
1184
|
+
* @param params - Runtime parameters containing NEW_RELIC_LICENSE_KEY and optional NEW_RELIC_URL
|
|
1185
|
+
* @returns Configuration object with traceExporter, metricReaders, and logRecordProcessors
|
|
1186
|
+
* @private
|
|
1187
|
+
*/
|
|
1188
|
+
getExportersConfig(params) {
|
|
1189
|
+
const licenseKey = params.NEW_RELIC_LICENSE_KEY;
|
|
1190
|
+
const newRelicUrl = params.NEW_RELIC_URL || "https://otlp.nr-data.net";
|
|
1191
|
+
const makeExporterConfig = /* @__PURE__ */ __name((endpoint) => {
|
|
1192
|
+
return {
|
|
1193
|
+
url: `${newRelicUrl}/${endpoint}`,
|
|
1194
|
+
headers: {
|
|
1195
|
+
"api-key": licenseKey
|
|
1196
|
+
}
|
|
1197
|
+
};
|
|
1198
|
+
}, "makeExporterConfig");
|
|
1199
|
+
return {
|
|
1200
|
+
traceExporter: new OTLPTraceExporterProto(makeExporterConfig("v1/traces")),
|
|
1201
|
+
metricReaders: [
|
|
1202
|
+
new PeriodicExportingMetricReader({
|
|
1203
|
+
exporter: new OTLPMetricExporterProto(makeExporterConfig("v1/metrics"))
|
|
1204
|
+
})
|
|
1205
|
+
],
|
|
1206
|
+
logRecordProcessors: [
|
|
1207
|
+
new JsonMessageProcessor(
|
|
1208
|
+
new SimpleLogRecordProcessor(new OTLPLogExporterProto(makeExporterConfig("v1/logs")))
|
|
1209
|
+
)
|
|
1210
|
+
]
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
/**
|
|
1214
|
+
* Initialize telemetry instrumentation for a runtime action
|
|
1215
|
+
*
|
|
1216
|
+
* Wraps the provided action with OpenTelemetry instrumentation using
|
|
1217
|
+
* New Relic as the backend. The instrumented action will automatically:
|
|
1218
|
+
* - Create spans for the action execution
|
|
1219
|
+
* - Export metrics during runtime
|
|
1220
|
+
* - Forward logs to New Relic
|
|
1221
|
+
* - Track success/failure status
|
|
1222
|
+
*
|
|
1223
|
+
* This method delegates to `instrumentEntrypoint` from `@adobe/aio-lib-telemetry`,
|
|
1224
|
+
* passing the action and New Relic specific configuration.
|
|
1225
|
+
*
|
|
1226
|
+
* @param action - The runtime action function to instrument
|
|
1227
|
+
* @returns The instrumented action function with telemetry enabled
|
|
1228
|
+
* @throws {TelemetryInputError} If required configuration is missing
|
|
1229
|
+
*
|
|
1230
|
+
* @example
|
|
1231
|
+
* ```typescript
|
|
1232
|
+
* async function myAction(params: Record<string, unknown>) {
|
|
1233
|
+
* const logger = Telemetry.createLogger("my-action", params);
|
|
1234
|
+
* logger.info("Processing request");
|
|
1235
|
+
*
|
|
1236
|
+
* return { statusCode: 200, body: { success: true } };
|
|
1237
|
+
* }
|
|
1238
|
+
*
|
|
1239
|
+
* const telemetry = new NewRelicTelemetry();
|
|
1240
|
+
* const instrumentedAction = telemetry.initialize(myAction);
|
|
1241
|
+
*
|
|
1242
|
+
* // instrumentedAction now sends traces, metrics, and logs to New Relic
|
|
1243
|
+
* export const main = instrumentedAction;
|
|
1244
|
+
* ```
|
|
1245
|
+
*/
|
|
1246
|
+
initialize(action) {
|
|
1247
|
+
return instrumentEntrypoint(action, this.getConfig());
|
|
1248
|
+
}
|
|
1249
|
+
};
|
|
1250
|
+
__name(_NewRelicTelemetry, "NewRelicTelemetry");
|
|
1251
|
+
var NewRelicTelemetry = _NewRelicTelemetry;
|
|
1252
|
+
var new_relic_default = NewRelicTelemetry;
|
|
1253
|
+
|
|
1254
|
+
// src/framework/telemetry/index.ts
|
|
1255
|
+
var _Telemetry = class _Telemetry {
|
|
1256
|
+
/**
|
|
1257
|
+
* Create a logger with standard configuration and automatic metadata injection.
|
|
1258
|
+
*
|
|
1259
|
+
* This method creates a structured logger and wraps it to automatically add
|
|
1260
|
+
* contextual metadata to all log calls:
|
|
1261
|
+
* - `x-adobe-commerce-request-id`: Extracted from `__ow_headers` (when present)
|
|
1262
|
+
* - `action.type`: Extracted from `params.action_type` (when present)
|
|
1263
|
+
*
|
|
1264
|
+
* If ENABLE_TELEMETRY is true, uses OpenTelemetry logger; otherwise uses Core.Logger.
|
|
1265
|
+
* The environment from params.ENVIRONMENT is set at the resource level and will
|
|
1266
|
+
* automatically appear in all logs sent to New Relic if ENABLE_TELEMETRY is true.
|
|
1267
|
+
*
|
|
1268
|
+
* @param name - Logger name (typically action name)
|
|
1269
|
+
* @param params - Runtime parameters containing LOG_LEVEL, optional ENABLE_TELEMETRY, ENVIRONMENT, action_type, and __ow_headers
|
|
1270
|
+
* @returns Configured logger instance with automatic metadata injection
|
|
1271
|
+
*
|
|
1272
|
+
* @example Basic string message
|
|
1273
|
+
* ```typescript
|
|
1274
|
+
* const logger = Telemetry.createLogger("my-action", params);
|
|
1275
|
+
* logger.info("Processing started");
|
|
1276
|
+
* // Logs: "Processing started"
|
|
1277
|
+
* ```
|
|
1278
|
+
*
|
|
1279
|
+
* @example JSON object message with automatic metadata
|
|
1280
|
+
* ```typescript
|
|
1281
|
+
* const logger = Telemetry.createLogger("my-action", {
|
|
1282
|
+
* ...params,
|
|
1283
|
+
* action_type: "webhook",
|
|
1284
|
+
* __ow_headers: { 'x-adobe-commerce-request-id': 'req-123' }
|
|
1285
|
+
* });
|
|
1286
|
+
* logger.info({
|
|
1287
|
+
* message: "User action completed",
|
|
1288
|
+
* user_id: "123"
|
|
1289
|
+
* });
|
|
1290
|
+
* // In New Relic: {
|
|
1291
|
+
* // message: "User action completed",
|
|
1292
|
+
* // user_id: "123",
|
|
1293
|
+
* // "x-adobe-commerce-request-id": "req-123",
|
|
1294
|
+
* // "action.type": "webhook",
|
|
1295
|
+
* // environment: "development",
|
|
1296
|
+
* // ...
|
|
1297
|
+
* // }
|
|
1298
|
+
* ```
|
|
1299
|
+
*/
|
|
1300
|
+
static createLogger(name, params) {
|
|
1301
|
+
const baseLogger = !params.ENABLE_TELEMETRY ? Core.Logger(name, {
|
|
1302
|
+
level: params.LOG_LEVEL || "info"
|
|
1303
|
+
}) : getLogger(name, {
|
|
1304
|
+
level: params.LOG_LEVEL || "info"
|
|
1305
|
+
});
|
|
1306
|
+
const metadata = {};
|
|
1307
|
+
const headers = params.__ow_headers;
|
|
1308
|
+
const requestId = headers?.["x-adobe-commerce-request-id"];
|
|
1309
|
+
if (requestId && requestId !== "") {
|
|
1310
|
+
metadata["x-adobe-commerce-request-id"] = requestId;
|
|
1311
|
+
}
|
|
1312
|
+
const actionType = params.action_type;
|
|
1313
|
+
if (actionType && actionType !== "") {
|
|
1314
|
+
metadata["action.type"] = actionType;
|
|
1315
|
+
}
|
|
1316
|
+
if (Object.keys(metadata).length === 0) {
|
|
1317
|
+
return baseLogger;
|
|
1318
|
+
}
|
|
1319
|
+
const wrapper = {
|
|
1320
|
+
debug: /* @__PURE__ */ __name((message) => {
|
|
1321
|
+
if (typeof message === "object" && message !== null) {
|
|
1322
|
+
baseLogger.debug({ ...metadata, ...message });
|
|
1323
|
+
} else {
|
|
1324
|
+
baseLogger.debug(message);
|
|
1325
|
+
}
|
|
1326
|
+
}, "debug"),
|
|
1327
|
+
info: /* @__PURE__ */ __name((message) => {
|
|
1328
|
+
if (typeof message === "object" && message !== null) {
|
|
1329
|
+
baseLogger.info({ ...metadata, ...message });
|
|
1330
|
+
} else {
|
|
1331
|
+
baseLogger.info(message);
|
|
1332
|
+
}
|
|
1333
|
+
}, "info"),
|
|
1334
|
+
warn: /* @__PURE__ */ __name((message) => {
|
|
1335
|
+
if (typeof message === "object" && message !== null) {
|
|
1336
|
+
baseLogger.warn({ ...metadata, ...message });
|
|
1337
|
+
} else {
|
|
1338
|
+
baseLogger.warn(message);
|
|
1339
|
+
}
|
|
1340
|
+
}, "warn"),
|
|
1341
|
+
error: /* @__PURE__ */ __name((message) => {
|
|
1342
|
+
if (typeof message === "object" && message !== null) {
|
|
1343
|
+
baseLogger.error({ ...metadata, ...message });
|
|
1344
|
+
} else {
|
|
1345
|
+
baseLogger.error(message);
|
|
1346
|
+
}
|
|
1347
|
+
}, "error")
|
|
1348
|
+
};
|
|
1349
|
+
return {
|
|
1350
|
+
...baseLogger,
|
|
1351
|
+
...wrapper
|
|
1352
|
+
};
|
|
1353
|
+
}
|
|
71
1354
|
/**
|
|
72
|
-
*
|
|
73
|
-
* The `Authorization` header content will be replaced by '<hidden>'.
|
|
1355
|
+
* Extract structured error information for logging
|
|
74
1356
|
*
|
|
75
|
-
*
|
|
1357
|
+
* Converts Error objects into a structured format suitable for logging
|
|
1358
|
+
* and telemetry systems like New Relic.
|
|
76
1359
|
*
|
|
77
|
-
* @
|
|
1360
|
+
* @param error - Error object or unknown error value
|
|
1361
|
+
* @returns Structured error object with name, message, and stack trace
|
|
1362
|
+
*
|
|
1363
|
+
* @example
|
|
1364
|
+
* ```typescript
|
|
1365
|
+
* try {
|
|
1366
|
+
* // some operation
|
|
1367
|
+
* } catch (error) {
|
|
1368
|
+
* logger.error("Operation failed", Telemetry.formatError(error));
|
|
1369
|
+
* }
|
|
1370
|
+
* ```
|
|
78
1371
|
*/
|
|
79
|
-
static
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
1372
|
+
static formatError(error) {
|
|
1373
|
+
if (error instanceof Error) {
|
|
1374
|
+
return {
|
|
1375
|
+
error_name: error.name,
|
|
1376
|
+
error_message: error.message,
|
|
1377
|
+
error_stack: error.stack
|
|
1378
|
+
};
|
|
83
1379
|
}
|
|
84
|
-
return
|
|
1380
|
+
return { error: String(error) };
|
|
85
1381
|
}
|
|
86
|
-
};
|
|
87
|
-
__name(_Parameters, "Parameters");
|
|
88
|
-
var Parameters = _Parameters;
|
|
89
|
-
var parameters_default = Parameters;
|
|
90
|
-
|
|
91
|
-
// src/framework/runtime-action/validator/index.ts
|
|
92
|
-
var _Validator = class _Validator {
|
|
93
1382
|
/**
|
|
94
|
-
*
|
|
95
|
-
* A parameter is missing if its value is undefined or ''.
|
|
96
|
-
* A value of 0 or null is not considered as missing.
|
|
1383
|
+
* Initialize telemetry for a runtime action with provider fallback chain
|
|
97
1384
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
1385
|
+
* Attempts to initialize telemetry providers in the following order:
|
|
1386
|
+
* 1. New Relic (if NEW_RELIC_TELEMETRY=true)
|
|
1387
|
+
* 2. Grafana (if GRAFANA_TELEMETRY=true) - Future support
|
|
1388
|
+
* 3. Original action (no telemetry)
|
|
101
1389
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
|
|
105
|
-
static getMissingKeys(obj, required) {
|
|
106
|
-
return required.filter((r) => {
|
|
107
|
-
const splits = r.split(".");
|
|
108
|
-
const last = splits[splits.length - 1];
|
|
109
|
-
const traverse = splits.slice(0, -1).reduce((tObj, split) => tObj[split] || {}, obj);
|
|
110
|
-
return last && (traverse[last] === void 0 || traverse[last] === "");
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Returns the list of missing keys given an object and its required keys.
|
|
115
|
-
* A parameter is missing if its value is undefined or ''.
|
|
116
|
-
* A value of 0 or null is not considered as missing.
|
|
1390
|
+
* Telemetry initialization is deferred to runtime when params are available.
|
|
1391
|
+
* This allows proper configuration detection and graceful fallback to the
|
|
1392
|
+
* next provider in the chain.
|
|
117
1393
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
1394
|
+
* **IMPORTANT**: If a provider is explicitly enabled (e.g., NEW_RELIC_TELEMETRY=true)
|
|
1395
|
+
* but has invalid configuration (missing API key, service name), a 500 error response
|
|
1396
|
+
* is returned to alert you of the misconfiguration. This prevents silently running
|
|
1397
|
+
* without telemetry when you expect it to be working.
|
|
122
1398
|
*
|
|
123
|
-
*
|
|
1399
|
+
* Environment Configuration:
|
|
1400
|
+
* Pass params.ENVIRONMENT to set the environment field in all logs.
|
|
1401
|
+
* This can be set via environment variables in your action configuration.
|
|
1402
|
+
*
|
|
1403
|
+
* @param action - The runtime action function to instrument
|
|
1404
|
+
* @returns The instrumented action ready for export
|
|
1405
|
+
*
|
|
1406
|
+
* @example Single provider (New Relic) - Valid configuration
|
|
1407
|
+
* ```typescript
|
|
1408
|
+
* // Environment:
|
|
1409
|
+
* // ENABLE_TELEMETRY=true
|
|
1410
|
+
* // NEW_RELIC_TELEMETRY=true
|
|
1411
|
+
* // NEW_RELIC_SERVICE_NAME=my-service
|
|
1412
|
+
* // NEW_RELIC_LICENSE_KEY=xxxxx
|
|
1413
|
+
*
|
|
1414
|
+
* export const main = Telemetry.initialize(myAction);
|
|
1415
|
+
* // ✅ Uses New Relic telemetry
|
|
1416
|
+
* ```
|
|
1417
|
+
*
|
|
1418
|
+
* @example New Relic enabled but misconfigured - Returns error response
|
|
1419
|
+
* ```typescript
|
|
1420
|
+
* // Environment:
|
|
1421
|
+
* // ENABLE_TELEMETRY=true
|
|
1422
|
+
* // NEW_RELIC_TELEMETRY=true
|
|
1423
|
+
* // NEW_RELIC_SERVICE_NAME=my-service
|
|
1424
|
+
* // Missing NEW_RELIC_LICENSE_KEY!
|
|
1425
|
+
*
|
|
1426
|
+
* export const main = Telemetry.initialize(myAction);
|
|
1427
|
+
* // ❌ Returns { error: { statusCode: 500, body: { error: "Telemetry configuration error: NEW_RELIC_LICENSE_KEY is required" } } }
|
|
1428
|
+
* // This is intentional - you want to know your telemetry config is broken!
|
|
1429
|
+
* ```
|
|
124
1430
|
*
|
|
1431
|
+
* @example Multi-provider fallback
|
|
1432
|
+
* ```typescript
|
|
1433
|
+
* // Environment:
|
|
1434
|
+
* // ENABLE_TELEMETRY=true
|
|
1435
|
+
* // NEW_RELIC_TELEMETRY=false // Skip New Relic
|
|
1436
|
+
* // GRAFANA_TELEMETRY=true // Use Grafana instead
|
|
1437
|
+
*
|
|
1438
|
+
* export const main = Telemetry.initialize(myAction);
|
|
1439
|
+
* // ✅ Skips New Relic, tries Grafana (when implemented)
|
|
1440
|
+
* ```
|
|
1441
|
+
*
|
|
1442
|
+
* @example No telemetry
|
|
1443
|
+
* ```typescript
|
|
1444
|
+
* // Environment:
|
|
1445
|
+
* // ENABLE_TELEMETRY=false (or not set)
|
|
1446
|
+
*
|
|
1447
|
+
* export const main = Telemetry.initialize(myAction);
|
|
1448
|
+
* // ✅ Returns original action without instrumentation
|
|
1449
|
+
* ```
|
|
125
1450
|
*/
|
|
126
|
-
static
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const missingParams = _Validator.getMissingKeys(params, requiredParams);
|
|
141
|
-
if (missingParams.length > 0) {
|
|
142
|
-
if (errorMessage) {
|
|
143
|
-
errorMessage += " and ";
|
|
144
|
-
} else {
|
|
145
|
-
errorMessage = "";
|
|
1451
|
+
static initialize(action) {
|
|
1452
|
+
return async (params) => {
|
|
1453
|
+
const newRelicTelemetry = new new_relic_default();
|
|
1454
|
+
if (newRelicTelemetry.canInitialize(params)) {
|
|
1455
|
+
try {
|
|
1456
|
+
const instrumentedAction = newRelicTelemetry.initialize(action);
|
|
1457
|
+
return await instrumentedAction(params);
|
|
1458
|
+
} catch (error) {
|
|
1459
|
+
const errorMessage = error instanceof Error ? error.message : "Telemetry initialization failed";
|
|
1460
|
+
return response_default.error(
|
|
1461
|
+
500 /* INTERNAL_ERROR */,
|
|
1462
|
+
`Telemetry configuration error: ${errorMessage}`
|
|
1463
|
+
);
|
|
1464
|
+
}
|
|
146
1465
|
}
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
return errorMessage;
|
|
1466
|
+
return action(params);
|
|
1467
|
+
};
|
|
150
1468
|
}
|
|
151
1469
|
};
|
|
152
|
-
__name(
|
|
153
|
-
var
|
|
154
|
-
var
|
|
1470
|
+
__name(_Telemetry, "Telemetry");
|
|
1471
|
+
var Telemetry = _Telemetry;
|
|
1472
|
+
var telemetry_default = Telemetry;
|
|
155
1473
|
|
|
156
1474
|
// src/framework/runtime-action/index.ts
|
|
157
1475
|
var _RuntimeAction = class _RuntimeAction {
|
|
158
1476
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* @param action
|
|
164
|
-
|
|
1477
|
+
* Sets the action type for the next action execution
|
|
1478
|
+
* This is used for logging to identify different action types
|
|
1479
|
+
* (runtime-action, webhook-action, event-consumer-action, etc.)
|
|
1480
|
+
*
|
|
1481
|
+
* @param type - The action type identifier
|
|
1482
|
+
*/
|
|
1483
|
+
static setActionType(type) {
|
|
1484
|
+
_RuntimeAction.actionType = type;
|
|
1485
|
+
}
|
|
1486
|
+
/**
|
|
1487
|
+
* Gets the current action type
|
|
1488
|
+
* @returns The current action type identifier
|
|
1489
|
+
*/
|
|
1490
|
+
static getActionType() {
|
|
1491
|
+
return _RuntimeAction.actionType;
|
|
1492
|
+
}
|
|
1493
|
+
/**
|
|
1494
|
+
* Creates a runtime action handler with validation, logging, and telemetry
|
|
1495
|
+
*
|
|
1496
|
+
* Wraps a user-defined action function with standardized runtime functionality:
|
|
1497
|
+
* 1. Creates a structured logger with telemetry integration
|
|
1498
|
+
* 2. Logs action start, headers, and body at debug level
|
|
1499
|
+
* 3. Validates required parameters, headers, and HTTP methods
|
|
1500
|
+
* 4. Executes the user action with logger and headers context
|
|
1501
|
+
* 5. Logs the result and handles errors with appropriate status codes
|
|
1502
|
+
* 6. Integrates with OpenTelemetry for distributed tracing
|
|
1503
|
+
*
|
|
1504
|
+
* @param name - Action name used for logging and telemetry spans (default: 'main')
|
|
1505
|
+
* @param httpMethods - Allowed HTTP methods (GET, POST, etc.). Empty array allows all methods
|
|
1506
|
+
* @param requiredParams - Required parameter names in the request body
|
|
1507
|
+
* @param requiredHeaders - Required header names (case-insensitive)
|
|
1508
|
+
* @param action - User-defined action function that receives:
|
|
1509
|
+
* - params: All request parameters including __ow_* runtime parameters
|
|
1510
|
+
* - ctx: Context object with logger and headers
|
|
1511
|
+
* @returns Wrapped action function ready to be exported as Adobe I/O Runtime entrypoint
|
|
1512
|
+
*
|
|
1513
|
+
* @example With All Options
|
|
1514
|
+
* ```typescript
|
|
1515
|
+
* const handler = RuntimeAction.execute(
|
|
1516
|
+
* 'processOrder',
|
|
1517
|
+
* [HttpMethod.POST],
|
|
1518
|
+
* ['orderId', 'customerId'],
|
|
1519
|
+
* ['authorization', 'x-api-key'],
|
|
1520
|
+
* async (params, { logger, headers }) => {
|
|
1521
|
+
* const { orderId, customerId } = params;
|
|
1522
|
+
* logger.info({ message: 'Processing order', orderId, customerId });
|
|
1523
|
+
*
|
|
1524
|
+
* // Your business logic here
|
|
1525
|
+
* const result = await processOrderLogic(orderId, customerId);
|
|
1526
|
+
*
|
|
1527
|
+
* return {
|
|
1528
|
+
* statusCode: 200,
|
|
1529
|
+
* body: { orderId, status: 'processed', result }
|
|
1530
|
+
* };
|
|
1531
|
+
* }
|
|
1532
|
+
* );
|
|
1533
|
+
* ```
|
|
1534
|
+
*
|
|
1535
|
+
* @example Minimal Configuration
|
|
1536
|
+
* ```typescript
|
|
1537
|
+
* const handler = RuntimeAction.execute('simpleAction', [], [], [], async (params, { logger }) => {
|
|
1538
|
+
* logger.info('Simple action executed');
|
|
1539
|
+
* return { statusCode: 200, body: { message: 'Success' } };
|
|
1540
|
+
* });
|
|
1541
|
+
* ```
|
|
165
1542
|
*/
|
|
166
1543
|
static execute(name = "main", httpMethods = [], requiredParams = [], requiredHeaders = [], action = async (_params) => {
|
|
167
1544
|
return { statusCode: 200 /* OK */, body: {} };
|
|
168
1545
|
}) {
|
|
169
|
-
|
|
170
|
-
|
|
1546
|
+
const runtimeAction = /* @__PURE__ */ __name(async (params) => {
|
|
1547
|
+
if (!params.action_type) {
|
|
1548
|
+
params.action_type = _RuntimeAction.getActionType();
|
|
1549
|
+
}
|
|
1550
|
+
const logger = telemetry_default.createLogger(name, params);
|
|
171
1551
|
try {
|
|
172
|
-
logger.
|
|
173
|
-
|
|
1552
|
+
logger.debug({
|
|
1553
|
+
message: `${name}-started`,
|
|
1554
|
+
action_name: name
|
|
1555
|
+
});
|
|
1556
|
+
logger.debug({
|
|
1557
|
+
message: `${name}-headers`,
|
|
1558
|
+
headers: params.__ow_headers || {}
|
|
1559
|
+
});
|
|
1560
|
+
logger.debug({
|
|
1561
|
+
message: `${name}-body`,
|
|
1562
|
+
body: params.__ow_body || {}
|
|
1563
|
+
});
|
|
174
1564
|
const validationError = _RuntimeAction.validateRequest(
|
|
175
1565
|
params,
|
|
176
1566
|
requiredParams,
|
|
177
1567
|
requiredHeaders,
|
|
178
1568
|
httpMethods,
|
|
179
|
-
logger
|
|
1569
|
+
logger,
|
|
1570
|
+
name
|
|
180
1571
|
);
|
|
181
1572
|
if (validationError) {
|
|
182
1573
|
return validationError;
|
|
183
1574
|
}
|
|
184
1575
|
const result = await action(params, { logger, headers: params.__ow_headers || {} });
|
|
185
|
-
logger.
|
|
1576
|
+
logger.debug({
|
|
1577
|
+
message: `${name}-completed`,
|
|
1578
|
+
result
|
|
1579
|
+
});
|
|
186
1580
|
return result;
|
|
187
1581
|
} catch (error) {
|
|
188
|
-
|
|
1582
|
+
if (error instanceof Error) {
|
|
1583
|
+
logger.error({
|
|
1584
|
+
message: `${name}-failed`,
|
|
1585
|
+
error: error.message,
|
|
1586
|
+
stack: error.stack
|
|
1587
|
+
});
|
|
1588
|
+
} else {
|
|
1589
|
+
logger.error({
|
|
1590
|
+
message: `${name}-failed`,
|
|
1591
|
+
error
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
189
1594
|
return response_default.error(500 /* INTERNAL_ERROR */, "server error");
|
|
190
1595
|
}
|
|
191
|
-
};
|
|
1596
|
+
}, "runtimeAction");
|
|
1597
|
+
return telemetry_default.initialize(runtimeAction);
|
|
192
1598
|
}
|
|
193
|
-
|
|
1599
|
+
/**
|
|
1600
|
+
* Validates incoming request against required parameters, headers, and HTTP methods
|
|
1601
|
+
*
|
|
1602
|
+
* This private method performs comprehensive request validation:
|
|
1603
|
+
* 1. Checks for missing required parameters in the request body
|
|
1604
|
+
* 2. Checks for missing required headers (case-insensitive)
|
|
1605
|
+
* 3. Validates the HTTP method against allowed methods list
|
|
1606
|
+
*
|
|
1607
|
+
* @param params - Request parameters including __ow_* runtime parameters
|
|
1608
|
+
* @param requiredParams - List of required parameter names to validate
|
|
1609
|
+
* @param requiredHeaders - List of required header names to validate (case-insensitive)
|
|
1610
|
+
* @param httpMethods - Allowed HTTP methods. Empty array skips HTTP method validation
|
|
1611
|
+
* @param logger - Logger instance for error logging (child logger with request ID if present)
|
|
1612
|
+
* @param name - Action name for logging
|
|
1613
|
+
* @returns RuntimeActionResponseType with error details if validation fails, null if valid
|
|
1614
|
+
*
|
|
1615
|
+
* @private
|
|
1616
|
+
*
|
|
1617
|
+
* @example Validation Error Response
|
|
1618
|
+
* ```typescript
|
|
1619
|
+
* // Missing parameter returns:
|
|
1620
|
+
* {
|
|
1621
|
+
* statusCode: 400,
|
|
1622
|
+
* body: { error: 'Missing required parameter: userId' }
|
|
1623
|
+
* }
|
|
1624
|
+
*
|
|
1625
|
+
* // Invalid HTTP method returns:
|
|
1626
|
+
* {
|
|
1627
|
+
* statusCode: 405,
|
|
1628
|
+
* body: { error: 'Invalid HTTP method: DELETE. Allowed methods are: GET, POST' }
|
|
1629
|
+
* }
|
|
1630
|
+
* ```
|
|
1631
|
+
*/
|
|
1632
|
+
static validateRequest(params, requiredParams, requiredHeaders, httpMethods, logger, name) {
|
|
194
1633
|
const errorMessage = validator_default.checkMissingRequestInputs(params, requiredParams, requiredHeaders) ?? "";
|
|
195
1634
|
if (errorMessage) {
|
|
1635
|
+
logger.error({
|
|
1636
|
+
message: `${name}-validation-failed`,
|
|
1637
|
+
error: errorMessage
|
|
1638
|
+
});
|
|
196
1639
|
return response_default.error(400 /* BAD_REQUEST */, errorMessage);
|
|
197
1640
|
}
|
|
198
1641
|
const requestMethod = params.__ow_method?.toUpperCase();
|
|
199
1642
|
if (httpMethods.length > 0 && !httpMethods.includes(requestMethod)) {
|
|
200
1643
|
const errorMessage2 = `Invalid HTTP method: ${params.__ow_method}. Allowed methods are: ${httpMethods.join(", ")}`;
|
|
201
|
-
logger.error(
|
|
1644
|
+
logger.error({
|
|
1645
|
+
message: `${name}-validation-failed`,
|
|
1646
|
+
error: errorMessage2
|
|
1647
|
+
});
|
|
202
1648
|
return response_default.error(405 /* METHOD_NOT_ALLOWED */, errorMessage2);
|
|
203
1649
|
}
|
|
204
1650
|
return null;
|
|
205
1651
|
}
|
|
206
1652
|
};
|
|
207
1653
|
__name(_RuntimeAction, "RuntimeAction");
|
|
1654
|
+
/**
|
|
1655
|
+
* Private static property to store the action type for logging
|
|
1656
|
+
* Can be set using setActionType() before calling execute()
|
|
1657
|
+
*/
|
|
1658
|
+
_RuntimeAction.actionType = "runtime-action";
|
|
208
1659
|
var RuntimeAction = _RuntimeAction;
|
|
209
1660
|
var runtime_action_default = RuntimeAction;
|
|
210
1661
|
|
|
1662
|
+
// src/framework/runtime-action/parameters/index.ts
|
|
1663
|
+
var _Parameters = class _Parameters {
|
|
1664
|
+
/**
|
|
1665
|
+
* Returns a log-ready string of the action input parameters.
|
|
1666
|
+
* The `Authorization` header content will be replaced by '<hidden>'.
|
|
1667
|
+
*
|
|
1668
|
+
* @param params action input parameters.
|
|
1669
|
+
*
|
|
1670
|
+
* @returns string
|
|
1671
|
+
*/
|
|
1672
|
+
static stringify(params) {
|
|
1673
|
+
let headers = params.__ow_headers || {};
|
|
1674
|
+
if (headers.authorization) {
|
|
1675
|
+
headers = { ...headers, authorization: "<hidden>" };
|
|
1676
|
+
}
|
|
1677
|
+
return JSON.stringify({ ...params, __ow_headers: headers });
|
|
1678
|
+
}
|
|
1679
|
+
};
|
|
1680
|
+
__name(_Parameters, "Parameters");
|
|
1681
|
+
var Parameters = _Parameters;
|
|
1682
|
+
var parameters_default = Parameters;
|
|
1683
|
+
|
|
211
1684
|
// src/framework/event-consumer-action/index.ts
|
|
212
|
-
import { Core as Core2 } from "@adobe/aio-sdk";
|
|
213
1685
|
var _EventConsumerAction = class _EventConsumerAction {
|
|
214
1686
|
/**
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
1687
|
+
* Creates an event consumer action handler with telemetry integration
|
|
1688
|
+
*
|
|
1689
|
+
* This method wraps a user-defined action with:
|
|
1690
|
+
* - Structured logging (all logs automatically include x-adobe-commerce-request-id if present)
|
|
1691
|
+
* - Request validation for required parameters and headers
|
|
1692
|
+
* - OpenTelemetry instrumentation
|
|
1693
|
+
* - Standardized error handling
|
|
1694
|
+
*
|
|
1695
|
+
* @param name - Action name for logging and observability
|
|
1696
|
+
* @param requiredParams - List of required parameter names to validate
|
|
1697
|
+
* @param requiredHeaders - List of required header names to validate (case-insensitive)
|
|
1698
|
+
* @param action - User's event consumer function that receives params and context
|
|
1699
|
+
* @returns Wrapped action handler ready for OpenWhisk runtime
|
|
1700
|
+
*
|
|
1701
|
+
* @example
|
|
1702
|
+
* ```typescript
|
|
1703
|
+
* const handler = EventConsumerAction.execute(
|
|
1704
|
+
* 'webhook-processor',
|
|
1705
|
+
* ['eventType', 'eventData'],
|
|
1706
|
+
* ['x-webhook-signature'],
|
|
1707
|
+
* async (params, { logger, headers }) => {
|
|
1708
|
+
* logger.info({
|
|
1709
|
+
* message: 'Processing webhook',
|
|
1710
|
+
* eventType: params.eventType
|
|
1711
|
+
* });
|
|
1712
|
+
* // Process event...
|
|
1713
|
+
* return { statusCode: 200, body: { processed: true } };
|
|
1714
|
+
* }
|
|
1715
|
+
* );
|
|
1716
|
+
* ```
|
|
220
1717
|
*/
|
|
221
1718
|
static execute(name = "main", requiredParams = [], requiredHeaders = [], action = async (_params) => {
|
|
222
1719
|
return { statusCode: 200 /* OK */, body: {} };
|
|
223
1720
|
}) {
|
|
224
|
-
|
|
225
|
-
|
|
1721
|
+
const eventConsumerAction = /* @__PURE__ */ __name(async (params) => {
|
|
1722
|
+
params.action_type = "event-consumer-action";
|
|
1723
|
+
const logger = telemetry_default.createLogger(name, params);
|
|
226
1724
|
try {
|
|
227
|
-
logger.
|
|
228
|
-
|
|
1725
|
+
logger.debug({
|
|
1726
|
+
message: `${name}-started`,
|
|
1727
|
+
action_name: name
|
|
1728
|
+
});
|
|
1729
|
+
logger.debug({
|
|
1730
|
+
message: `${name}-headers`,
|
|
1731
|
+
headers: params.__ow_headers || {}
|
|
1732
|
+
});
|
|
1733
|
+
logger.debug({
|
|
1734
|
+
message: `${name}-parameters`,
|
|
1735
|
+
parameters: params
|
|
1736
|
+
});
|
|
229
1737
|
const errorMessage = validator_default.checkMissingRequestInputs(params, requiredParams, requiredHeaders) || "";
|
|
230
1738
|
if (errorMessage) {
|
|
1739
|
+
logger.error({
|
|
1740
|
+
message: `${name}-validation-failed`,
|
|
1741
|
+
error: errorMessage
|
|
1742
|
+
});
|
|
231
1743
|
return response_default.error(400 /* BAD_REQUEST */, errorMessage);
|
|
232
1744
|
}
|
|
233
1745
|
const result = await action(params, { logger, headers: params.__ow_headers || {} });
|
|
234
|
-
logger.
|
|
1746
|
+
logger.debug({
|
|
1747
|
+
message: `${name}-completed`,
|
|
1748
|
+
result
|
|
1749
|
+
});
|
|
235
1750
|
return result;
|
|
236
1751
|
} catch (error) {
|
|
237
|
-
|
|
1752
|
+
if (error instanceof Error) {
|
|
1753
|
+
logger.error({
|
|
1754
|
+
error: error.message,
|
|
1755
|
+
stack: error.stack
|
|
1756
|
+
});
|
|
1757
|
+
} else {
|
|
1758
|
+
logger.error({ error });
|
|
1759
|
+
}
|
|
238
1760
|
return response_default.error(500 /* INTERNAL_ERROR */, "server error");
|
|
239
1761
|
}
|
|
240
|
-
};
|
|
1762
|
+
}, "eventConsumerAction");
|
|
1763
|
+
return telemetry_default.initialize(eventConsumerAction);
|
|
241
1764
|
}
|
|
242
1765
|
};
|
|
243
1766
|
__name(_EventConsumerAction, "EventConsumerAction");
|
|
@@ -349,29 +1872,83 @@ var Openwhisk = _Openwhisk;
|
|
|
349
1872
|
var openwhisk_default = Openwhisk;
|
|
350
1873
|
|
|
351
1874
|
// src/framework/openwhisk-action/index.ts
|
|
352
|
-
import { Core as Core3 } from "@adobe/aio-sdk";
|
|
353
1875
|
var _OpenwhiskAction = class _OpenwhiskAction {
|
|
354
1876
|
/**
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
1877
|
+
* Creates an OpenWhisk webhook action handler with logging and telemetry
|
|
1878
|
+
*
|
|
1879
|
+
* Wraps a user-defined action function with standardized runtime functionality:
|
|
1880
|
+
* 1. Creates a structured logger with telemetry integration
|
|
1881
|
+
* 2. Logs action start with structured data
|
|
1882
|
+
* 3. Logs request parameters at debug level
|
|
1883
|
+
* 4. Executes the user action with logger and headers context
|
|
1884
|
+
* 5. Logs the result and handles errors with appropriate status codes
|
|
1885
|
+
* 6. Integrates with OpenTelemetry for distributed tracing
|
|
1886
|
+
*
|
|
1887
|
+
* The logger automatically includes x-adobe-commerce-request-id and action.type
|
|
1888
|
+
* (if present) in all log messages.
|
|
1889
|
+
*
|
|
1890
|
+
* @param name - Action name used for logging and telemetry spans (default: 'main')
|
|
1891
|
+
* @param action - User-defined action function that receives:
|
|
1892
|
+
* - params: All request parameters including __ow_* runtime parameters
|
|
1893
|
+
* - ctx: Context object with logger and headers
|
|
1894
|
+
* @returns Wrapped action function ready to be exported as Adobe I/O Runtime entrypoint
|
|
1895
|
+
*
|
|
1896
|
+
* @example Complete Example
|
|
1897
|
+
* ```typescript
|
|
1898
|
+
* const handler = OpenwhiskAction.execute(
|
|
1899
|
+
* 'processWebhook',
|
|
1900
|
+
* async (params, { logger, headers }) => {
|
|
1901
|
+
* logger.info({ message: 'Webhook received', event: params.event });
|
|
1902
|
+
*
|
|
1903
|
+
* // Your webhook processing logic here
|
|
1904
|
+
* const result = await processWebhookData(params);
|
|
1905
|
+
*
|
|
1906
|
+
* return {
|
|
1907
|
+
* statusCode: 200,
|
|
1908
|
+
* body: { status: 'processed', result }
|
|
1909
|
+
* };
|
|
1910
|
+
* }
|
|
1911
|
+
* );
|
|
1912
|
+
* ```
|
|
358
1913
|
*/
|
|
359
1914
|
static execute(name = "main", action = async (_params) => {
|
|
360
1915
|
return { statusCode: 200 /* OK */, body: {} };
|
|
361
1916
|
}) {
|
|
362
|
-
|
|
363
|
-
|
|
1917
|
+
const openwhiskAction = /* @__PURE__ */ __name(async (params) => {
|
|
1918
|
+
params.action_type = "openwhisk-action";
|
|
1919
|
+
const logger = telemetry_default.createLogger(name, params);
|
|
364
1920
|
try {
|
|
365
|
-
logger.
|
|
366
|
-
|
|
1921
|
+
logger.debug({
|
|
1922
|
+
message: `${name}-started`,
|
|
1923
|
+
action_name: name
|
|
1924
|
+
});
|
|
1925
|
+
logger.debug({
|
|
1926
|
+
message: `${name}-params`,
|
|
1927
|
+
params
|
|
1928
|
+
});
|
|
367
1929
|
const result = await action(params, { logger, headers: params.__ow_headers || {} });
|
|
368
|
-
logger.
|
|
1930
|
+
logger.debug({
|
|
1931
|
+
message: `${name}-completed`,
|
|
1932
|
+
result
|
|
1933
|
+
});
|
|
369
1934
|
return result;
|
|
370
1935
|
} catch (error) {
|
|
371
|
-
|
|
1936
|
+
if (error instanceof Error) {
|
|
1937
|
+
logger.error({
|
|
1938
|
+
message: `${name}-failed`,
|
|
1939
|
+
error: error.message,
|
|
1940
|
+
stack: error.stack
|
|
1941
|
+
});
|
|
1942
|
+
} else {
|
|
1943
|
+
logger.error({
|
|
1944
|
+
message: `${name}-failed`,
|
|
1945
|
+
error
|
|
1946
|
+
});
|
|
1947
|
+
}
|
|
372
1948
|
return response_default.error(500 /* INTERNAL_ERROR */, "server error");
|
|
373
1949
|
}
|
|
374
|
-
};
|
|
1950
|
+
}, "openwhiskAction");
|
|
1951
|
+
return telemetry_default.initialize(openwhiskAction);
|
|
375
1952
|
}
|
|
376
1953
|
};
|
|
377
1954
|
__name(_OpenwhiskAction, "OpenwhiskAction");
|
|
@@ -479,7 +2056,6 @@ var _FileRepository = class _FileRepository {
|
|
|
479
2056
|
const existingData = JSON.parse(buffer.toString());
|
|
480
2057
|
payload = { ...existingData, ...payload };
|
|
481
2058
|
}
|
|
482
|
-
await filesLib.delete(filepath);
|
|
483
2059
|
} else {
|
|
484
2060
|
payload = {
|
|
485
2061
|
id: fileId,
|
|
@@ -925,9 +2501,14 @@ var _WebhookAction = class _WebhookAction {
|
|
|
925
2501
|
return null;
|
|
926
2502
|
}, "verifySignature");
|
|
927
2503
|
const callback = /* @__PURE__ */ __name(async (params, ctx) => {
|
|
2504
|
+
const { logger } = ctx;
|
|
928
2505
|
if (signatureVerification === "enabled" /* ENABLED */) {
|
|
929
2506
|
const verificationErrorMessage = await verifySignature(params);
|
|
930
2507
|
if (verificationErrorMessage) {
|
|
2508
|
+
logger.error({
|
|
2509
|
+
message: `${name}-signature-verification-failed`,
|
|
2510
|
+
error: verificationErrorMessage
|
|
2511
|
+
});
|
|
931
2512
|
const verificationErrorResponse = response_default2.exception(verificationErrorMessage);
|
|
932
2513
|
return response_default.success(JSON.stringify(verificationErrorResponse));
|
|
933
2514
|
}
|
|
@@ -938,12 +2519,17 @@ var _WebhookAction = class _WebhookAction {
|
|
|
938
2519
|
}
|
|
939
2520
|
const errorMessage = validator_default.checkMissingRequestInputs(params, requiredParams, requiredHeaders) ?? "";
|
|
940
2521
|
if (errorMessage) {
|
|
2522
|
+
logger.error({
|
|
2523
|
+
message: `${name}-validation-failed`,
|
|
2524
|
+
error: errorMessage
|
|
2525
|
+
});
|
|
941
2526
|
const errorMessageResponse = response_default2.exception(errorMessage);
|
|
942
2527
|
return response_default.success(JSON.stringify(errorMessageResponse));
|
|
943
2528
|
}
|
|
944
2529
|
const response = await action(params, ctx);
|
|
945
2530
|
return response_default.success(JSON.stringify(response));
|
|
946
2531
|
}, "callback");
|
|
2532
|
+
runtime_action_default.setActionType("webhook-action");
|
|
947
2533
|
return runtime_action_default.execute(name, httpMethods, [], [], callback);
|
|
948
2534
|
}
|
|
949
2535
|
};
|
|
@@ -1146,6 +2732,9 @@ var _ImsToken = class _ImsToken {
|
|
|
1146
2732
|
/**
|
|
1147
2733
|
* Creates an instance of ImsToken
|
|
1148
2734
|
*
|
|
2735
|
+
* @deprecated Use `AdobeAuth.getToken()` directly and implement caching in your application.
|
|
2736
|
+
* See class documentation for migration examples.
|
|
2737
|
+
*
|
|
1149
2738
|
* @param clientId - OAuth client ID for Adobe IMS authentication
|
|
1150
2739
|
* @param clientSecret - OAuth client secret for Adobe IMS authentication
|
|
1151
2740
|
* @param technicalAccountId - Technical account ID for service-to-service authentication
|
|
@@ -1172,6 +2761,10 @@ var _ImsToken = class _ImsToken {
|
|
|
1172
2761
|
/**
|
|
1173
2762
|
* Executes IMS token generation or retrieves a cached token
|
|
1174
2763
|
*
|
|
2764
|
+
* @deprecated Use `AdobeAuth.getToken()` directly and implement caching in your application.
|
|
2765
|
+
* The built-in caching mechanism has reliability issues with the State API.
|
|
2766
|
+
* See class documentation for migration examples.
|
|
2767
|
+
*
|
|
1175
2768
|
* This method first checks for a cached token. If a valid cached token exists,
|
|
1176
2769
|
* it returns that. Otherwise, it generates a new token, caches it, and returns it.
|
|
1177
2770
|
*
|
|
@@ -1254,6 +2847,14 @@ var _ImsToken = class _ImsToken {
|
|
|
1254
2847
|
/**
|
|
1255
2848
|
* Caches the IMS token in the state store with TTL
|
|
1256
2849
|
*
|
|
2850
|
+
* @deprecated This method has issues with State API reliability. Use application-level caching instead.
|
|
2851
|
+
*
|
|
2852
|
+
* **Known Issues:**
|
|
2853
|
+
* - State API may not be available in all runtime environments
|
|
2854
|
+
* - Hard-coded 10-minute buffer may not suit all use cases
|
|
2855
|
+
* - Minimum 60-minute TTL is opinionated and inflexible
|
|
2856
|
+
* - No retry mechanism for State API failures
|
|
2857
|
+
*
|
|
1257
2858
|
* @param result - The token result containing the token and expiration time
|
|
1258
2859
|
* @returns A promise that resolves to true if caching succeeded, false otherwise
|
|
1259
2860
|
* @private
|
|
@@ -1279,6 +2880,13 @@ var _ImsToken = class _ImsToken {
|
|
|
1279
2880
|
/**
|
|
1280
2881
|
* Retrieves a cached IMS token from the state store
|
|
1281
2882
|
*
|
|
2883
|
+
* @deprecated This method has issues with State API reliability. Use application-level caching instead.
|
|
2884
|
+
*
|
|
2885
|
+
* **Known Issues:**
|
|
2886
|
+
* - State API may not be available in all runtime environments
|
|
2887
|
+
* - No validation of cached token expiry
|
|
2888
|
+
* - Silent failures may return null without proper error context
|
|
2889
|
+
*
|
|
1282
2890
|
* @returns A promise that resolves to the cached token string or null if not found
|
|
1283
2891
|
* @private
|
|
1284
2892
|
*/
|
|
@@ -1304,6 +2912,14 @@ var _ImsToken = class _ImsToken {
|
|
|
1304
2912
|
/**
|
|
1305
2913
|
* Initializes and returns the state store instance
|
|
1306
2914
|
*
|
|
2915
|
+
* @deprecated This method relies on State API which has reliability issues.
|
|
2916
|
+
* Use application-level caching instead.
|
|
2917
|
+
*
|
|
2918
|
+
* **Known Issues:**
|
|
2919
|
+
* - State API initialization may fail silently
|
|
2920
|
+
* - Not available outside Adobe I/O Runtime environments
|
|
2921
|
+
* - Caches the state instance which may become stale
|
|
2922
|
+
*
|
|
1307
2923
|
* @returns A promise that resolves to the state instance or null if initialization fails
|
|
1308
2924
|
* @private
|
|
1309
2925
|
*/
|
|
@@ -1501,44 +3117,26 @@ var _RuntimeApiGatewayService = class _RuntimeApiGatewayService {
|
|
|
1501
3117
|
/**
|
|
1502
3118
|
* Creates an instance of RuntimeApiGatewayService
|
|
1503
3119
|
*
|
|
1504
|
-
* @param clientId - OAuth client ID for Adobe IMS authentication
|
|
1505
|
-
* @param clientSecret - OAuth client secret for Adobe IMS authentication
|
|
1506
|
-
* @param technicalAccountId - Technical account ID for service-to-service authentication
|
|
1507
|
-
* @param technicalAccountEmail - Technical account email for service-to-service authentication
|
|
1508
|
-
* @param imsOrgId - IMS organization ID
|
|
1509
|
-
* @param scopes - Array of scopes required for the token
|
|
1510
3120
|
* @param namespace - The Adobe I/O Runtime namespace identifier
|
|
3121
|
+
* @param imsOrgId - IMS organization ID
|
|
3122
|
+
* @param imsToken - Bearer token string for authentication
|
|
1511
3123
|
* @param logger - Optional logger instance for logging operations
|
|
1512
3124
|
* @example
|
|
1513
3125
|
* ```typescript
|
|
1514
3126
|
* const service = new RuntimeApiGatewayService(
|
|
1515
|
-
* '
|
|
1516
|
-
* '
|
|
1517
|
-
* '
|
|
1518
|
-
*
|
|
1519
|
-
* 'org-id',
|
|
1520
|
-
* ['openid', 'AdobeID'],
|
|
1521
|
-
* 'my-namespace-12345',
|
|
1522
|
-
* logger // optional
|
|
3127
|
+
* 'test-namespace',
|
|
3128
|
+
* 'org-id@AdobeOrg',
|
|
3129
|
+
* 'bearer-token-string',
|
|
3130
|
+
* logger
|
|
1523
3131
|
* );
|
|
1524
3132
|
* ```
|
|
1525
3133
|
*/
|
|
1526
|
-
constructor(
|
|
3134
|
+
constructor(namespace, imsOrgId, imsToken, logger = null) {
|
|
1527
3135
|
this.namespace = namespace;
|
|
1528
3136
|
this.imsOrgId = imsOrgId;
|
|
1529
|
-
this.
|
|
1530
|
-
this.imsToken = new ims_token_default(
|
|
1531
|
-
clientId,
|
|
1532
|
-
clientSecret,
|
|
1533
|
-
technicalAccountId,
|
|
1534
|
-
technicalAccountEmail,
|
|
1535
|
-
imsOrgId,
|
|
1536
|
-
scopes,
|
|
1537
|
-
logger,
|
|
1538
|
-
"runtime_api_gateway_token",
|
|
1539
|
-
"runtime-api-gateway-context"
|
|
1540
|
-
);
|
|
3137
|
+
this.imsToken = imsToken;
|
|
1541
3138
|
this.restClient = new rest_client_default();
|
|
3139
|
+
this.customLogger = new custom_logger_default(logger);
|
|
1542
3140
|
}
|
|
1543
3141
|
/**
|
|
1544
3142
|
* Builds the complete API endpoint URL
|
|
@@ -1553,21 +3151,13 @@ var _RuntimeApiGatewayService = class _RuntimeApiGatewayService {
|
|
|
1553
3151
|
/**
|
|
1554
3152
|
* Gets the authenticated headers for API requests
|
|
1555
3153
|
*
|
|
1556
|
-
* @returns
|
|
1557
|
-
* @throws {Error} If token generation fails
|
|
3154
|
+
* @returns Headers object including authentication
|
|
1558
3155
|
* @private
|
|
1559
3156
|
*/
|
|
1560
|
-
|
|
1561
|
-
this.customLogger.debug("Generating authenticated headers for API request");
|
|
1562
|
-
const token = await this.imsToken.execute();
|
|
1563
|
-
if (!token) {
|
|
1564
|
-
this.customLogger.error("Failed to generate IMS token for authenticated headers");
|
|
1565
|
-
throw new Error("Failed to generate IMS token");
|
|
1566
|
-
}
|
|
1567
|
-
this.customLogger.debug("Successfully generated authenticated headers");
|
|
3157
|
+
getAuthenticatedHeaders() {
|
|
1568
3158
|
return {
|
|
1569
3159
|
"Content-Type": "application/json",
|
|
1570
|
-
Authorization: `Bearer ${
|
|
3160
|
+
Authorization: `Bearer ${this.imsToken}`,
|
|
1571
3161
|
"x-gw-ims-org-id": this.imsOrgId
|
|
1572
3162
|
};
|
|
1573
3163
|
}
|
|
@@ -1591,7 +3181,7 @@ var _RuntimeApiGatewayService = class _RuntimeApiGatewayService {
|
|
|
1591
3181
|
try {
|
|
1592
3182
|
const url = this.buildEndpoint(endpoint);
|
|
1593
3183
|
this.customLogger.info(`Performing GET request to: ${url}`);
|
|
1594
|
-
const headers = { ...
|
|
3184
|
+
const headers = { ...this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1595
3185
|
this.customLogger.debug(`GET headers: ${JSON.stringify(headers)}`);
|
|
1596
3186
|
const response = await this.restClient.get(url, headers, false);
|
|
1597
3187
|
this.customLogger.debug(`GET response: ${JSON.stringify(response)}`);
|
|
@@ -1625,7 +3215,7 @@ var _RuntimeApiGatewayService = class _RuntimeApiGatewayService {
|
|
|
1625
3215
|
const url = this.buildEndpoint(endpoint);
|
|
1626
3216
|
this.customLogger.info(`Performing POST request to: ${url}`);
|
|
1627
3217
|
this.customLogger.debug(`POST payload: ${JSON.stringify(payload)}`);
|
|
1628
|
-
const headers = { ...
|
|
3218
|
+
const headers = { ...this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1629
3219
|
this.customLogger.debug(`POST headers: ${JSON.stringify(headers)}`);
|
|
1630
3220
|
const response = await this.restClient.post(url, headers, payload, false);
|
|
1631
3221
|
this.customLogger.debug(`POST response: ${JSON.stringify(response)}`);
|
|
@@ -1659,7 +3249,7 @@ var _RuntimeApiGatewayService = class _RuntimeApiGatewayService {
|
|
|
1659
3249
|
const url = this.buildEndpoint(endpoint);
|
|
1660
3250
|
this.customLogger.info(`Performing PUT request to: ${url}`);
|
|
1661
3251
|
this.customLogger.debug(`PUT payload: ${JSON.stringify(payload)}`);
|
|
1662
|
-
const headers = { ...
|
|
3252
|
+
const headers = { ...this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1663
3253
|
this.customLogger.debug(`PUT headers: ${JSON.stringify(headers)}`);
|
|
1664
3254
|
const response = await this.restClient.put(url, headers, payload, false);
|
|
1665
3255
|
this.customLogger.debug(`PUT response: ${JSON.stringify(response)}`);
|
|
@@ -1691,7 +3281,7 @@ var _RuntimeApiGatewayService = class _RuntimeApiGatewayService {
|
|
|
1691
3281
|
try {
|
|
1692
3282
|
const url = this.buildEndpoint(endpoint);
|
|
1693
3283
|
this.customLogger.info(`Performing DELETE request to: ${url}`);
|
|
1694
|
-
const headers = { ...
|
|
3284
|
+
const headers = { ...this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1695
3285
|
this.customLogger.debug(`DELETE headers: ${JSON.stringify(headers)}`);
|
|
1696
3286
|
const response = await this.restClient.delete(url, headers, false);
|
|
1697
3287
|
this.customLogger.debug(`DELETE response: ${JSON.stringify(response)}`);
|
|
@@ -1710,7 +3300,7 @@ _RuntimeApiGatewayService.BASE_URL = "https://adobeioruntime.net/apis";
|
|
|
1710
3300
|
var RuntimeApiGatewayService = _RuntimeApiGatewayService;
|
|
1711
3301
|
|
|
1712
3302
|
// src/integration/onboard-events/index.ts
|
|
1713
|
-
import { Core as
|
|
3303
|
+
import { Core as Core2 } from "@adobe/aio-sdk";
|
|
1714
3304
|
|
|
1715
3305
|
// src/io-events/types.ts
|
|
1716
3306
|
var IoEventsGlobals = {
|
|
@@ -4360,9 +5950,7 @@ var _CreateProviders = class _CreateProviders {
|
|
|
4360
5950
|
}
|
|
4361
5951
|
try {
|
|
4362
5952
|
const providerInput = this.preparePayload(providerData, enhancedLabel);
|
|
4363
|
-
this.logger.debug(
|
|
4364
|
-
`[NEW] Creating new provider with payload: ${JSON.stringify(providerInput)}`
|
|
4365
|
-
);
|
|
5953
|
+
this.logger.debug(`[NEW] Creating new provider: ${enhancedLabel}`);
|
|
4366
5954
|
const createdProvider = await this.getProviderManager().create(providerInput);
|
|
4367
5955
|
this.logger.debug(
|
|
4368
5956
|
`[INFO] Provider created successfully! ID: ${createdProvider.id}, Instance ID: ${createdProvider.instance_id}`
|
|
@@ -4881,7 +6469,7 @@ var _CreateRegistrations = class _CreateRegistrations {
|
|
|
4881
6469
|
registrationName,
|
|
4882
6470
|
firstEvent
|
|
4883
6471
|
);
|
|
4884
|
-
this.logger.debug(`[INFO]
|
|
6472
|
+
this.logger.debug(`[INFO] Creating registration: ${registrationName}`);
|
|
4885
6473
|
const registrationSDK = this.getRegistrationManager();
|
|
4886
6474
|
const createdRegistration = await registrationSDK.create(registrationInput);
|
|
4887
6475
|
this.logger.debug("[SUCCESS] Registration created successfully!");
|
|
@@ -5025,7 +6613,7 @@ var _OnboardEvents = class _OnboardEvents {
|
|
|
5025
6613
|
throw new Error("Access token is required");
|
|
5026
6614
|
}
|
|
5027
6615
|
const loggerName = projectName.toLowerCase().replace(/[^a-z0-9\s-_]/g, "").replace(/\s+/g, "-").replace(/_{2,}/g, "_").replace(/-{2,}/g, "-").trim().concat("-onboard-events");
|
|
5028
|
-
this.logger =
|
|
6616
|
+
this.logger = Core2.Logger(loggerName, { level: "debug" });
|
|
5029
6617
|
this.createProviders = new create_providers_default(
|
|
5030
6618
|
consumerId,
|
|
5031
6619
|
projectId,
|
|
@@ -5221,7 +6809,7 @@ var OnboardEvents = _OnboardEvents;
|
|
|
5221
6809
|
var onboard_events_default = OnboardEvents;
|
|
5222
6810
|
|
|
5223
6811
|
// src/integration/infinite-loop-breaker/index.ts
|
|
5224
|
-
import { Core as
|
|
6812
|
+
import { Core as Core3, State as State2 } from "@adobe/aio-sdk";
|
|
5225
6813
|
import crypto2 from "crypto";
|
|
5226
6814
|
var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
5227
6815
|
// seconds
|
|
@@ -5239,7 +6827,7 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
|
5239
6827
|
event
|
|
5240
6828
|
}) {
|
|
5241
6829
|
const logLevel = process.env.LOG_LEVEL || "info";
|
|
5242
|
-
const logger =
|
|
6830
|
+
const logger = Core3.Logger("infiniteLoopBreaker", { level: logLevel });
|
|
5243
6831
|
logger.debug(`Checking for potential infinite loop for event: ${event}`);
|
|
5244
6832
|
if (!eventTypes.includes(event)) {
|
|
5245
6833
|
logger.debug(`Event type ${event} is not in the infinite loop event types list`);
|
|
@@ -5447,10 +7035,7 @@ var _ConfigureProvider = class _ConfigureProvider {
|
|
|
5447
7035
|
description: provider.description,
|
|
5448
7036
|
workspace_configuration: JSON.stringify(workspaceConfig)
|
|
5449
7037
|
};
|
|
5450
|
-
this.customLogger.debug(
|
|
5451
|
-
`[DEBUG] Creating event provider:
|
|
5452
|
-
${JSON.stringify(providerData, null, 2)}`
|
|
5453
|
-
);
|
|
7038
|
+
this.customLogger.debug(`[DEBUG] Creating event provider: ${provider.label} (${provider.id})`);
|
|
5454
7039
|
const createResult = await this.eventProviderService.create(providerData);
|
|
5455
7040
|
if (!createResult.success) {
|
|
5456
7041
|
const errorMsg = `Failed to create event provider: ${createResult.error}`;
|
|
@@ -5488,8 +7073,7 @@ ${JSON.stringify(providerData, null, 2)}`
|
|
|
5488
7073
|
workspace_configuration: JSON.stringify(workspaceConfig)
|
|
5489
7074
|
};
|
|
5490
7075
|
this.customLogger.debug(
|
|
5491
|
-
`[DEBUG] Updating configuration
|
|
5492
|
-
${JSON.stringify(updateConfigPayload, null, 2)}`
|
|
7076
|
+
`[DEBUG] Updating workspace configuration for merchant: ${this.merchantId}`
|
|
5493
7077
|
);
|
|
5494
7078
|
const updateResult = await this.eventConfigurationService.update(updateConfigPayload);
|
|
5495
7079
|
if (!updateResult.success) {
|
|
@@ -5667,10 +7251,7 @@ var _OnboardCommerce = class _OnboardCommerce {
|
|
|
5667
7251
|
for (const commerceEvent of needsSubscription) {
|
|
5668
7252
|
try {
|
|
5669
7253
|
const preparedEvent = this.prepareEventPayload(commerceEvent, provider.id);
|
|
5670
|
-
this.customLogger.debug(
|
|
5671
|
-
`[DEBUG] Subscribing to event with payload:
|
|
5672
|
-
${JSON.stringify(preparedEvent.event, null, 2)}`
|
|
5673
|
-
);
|
|
7254
|
+
this.customLogger.debug(`[DEBUG] Subscribing to event: ${commerceEvent.event.name}`);
|
|
5674
7255
|
const eventSubscribeResult = await this.eventSubscriptionService.create(
|
|
5675
7256
|
preparedEvent.event
|
|
5676
7257
|
);
|
|
@@ -6259,49 +7840,38 @@ var oauth1a_connection_default = Oauth1aConnection;
|
|
|
6259
7840
|
// src/commerce/adobe-commerce-client/ims-connection/index.ts
|
|
6260
7841
|
var _ImsConnection = class _ImsConnection {
|
|
6261
7842
|
/**
|
|
6262
|
-
*
|
|
6263
|
-
*
|
|
6264
|
-
* @param
|
|
6265
|
-
* @param
|
|
6266
|
-
* @
|
|
6267
|
-
*
|
|
6268
|
-
*
|
|
7843
|
+
* Creates an instance of ImsConnection
|
|
7844
|
+
*
|
|
7845
|
+
* @param imsToken - Bearer token string for IMS authentication (generate using AdobeAuth)
|
|
7846
|
+
* @param logger - Optional logger instance for logging operations
|
|
7847
|
+
* @example
|
|
7848
|
+
* ```typescript
|
|
7849
|
+
* const token = await AdobeAuth.getToken(...);
|
|
7850
|
+
* const connection = new ImsConnection(token, logger);
|
|
7851
|
+
* ```
|
|
6269
7852
|
*/
|
|
6270
|
-
constructor(
|
|
6271
|
-
this.
|
|
6272
|
-
this.clientSecret = clientSecret;
|
|
6273
|
-
this.technicalAccountId = technicalAccountId;
|
|
6274
|
-
this.technicalAccountEmail = technicalAccountEmail;
|
|
6275
|
-
this.imsOrgId = imsOrgId;
|
|
6276
|
-
this.scopes = scopes;
|
|
7853
|
+
constructor(imsToken, logger = null) {
|
|
7854
|
+
this.imsToken = imsToken;
|
|
6277
7855
|
this.customLogger = new custom_logger_default(logger);
|
|
6278
7856
|
}
|
|
6279
7857
|
/**
|
|
6280
|
-
*
|
|
7858
|
+
* Extends the Commerce Got client with IMS authentication headers
|
|
7859
|
+
*
|
|
7860
|
+
* @param commerceGot - The Got instance to extend with authentication
|
|
7861
|
+
* @returns Promise<any> - Extended Got instance with authentication headers
|
|
7862
|
+
* @throws {Error} If token is invalid or empty
|
|
6281
7863
|
*/
|
|
6282
7864
|
async extend(commerceGot) {
|
|
6283
7865
|
this.customLogger.info("Using Commerce client with IMS authentication");
|
|
6284
|
-
|
|
6285
|
-
this.clientId,
|
|
6286
|
-
this.clientSecret,
|
|
6287
|
-
this.technicalAccountId,
|
|
6288
|
-
this.technicalAccountEmail,
|
|
6289
|
-
this.imsOrgId,
|
|
6290
|
-
this.scopes,
|
|
6291
|
-
this.customLogger.getLogger(),
|
|
6292
|
-
"adobe_commerce_ims_token",
|
|
6293
|
-
// Use specific cache key for commerce client
|
|
6294
|
-
"adobe-commerce-client"
|
|
6295
|
-
// Use adobe-commerce-client context for backward compatibility
|
|
6296
|
-
);
|
|
6297
|
-
const token = await tokenGenerator.execute();
|
|
6298
|
-
if (token === null) {
|
|
7866
|
+
if (!this.imsToken || this.imsToken.trim() === "") {
|
|
6299
7867
|
throw new Error("Failed to generate or retrieve IMS token");
|
|
6300
7868
|
}
|
|
6301
|
-
this.customLogger.info(
|
|
7869
|
+
this.customLogger.info(
|
|
7870
|
+
`IMS token being extended to header: ${this.imsToken.substring(0, 10)}...`
|
|
7871
|
+
);
|
|
6302
7872
|
return commerceGot.extend({
|
|
6303
7873
|
headers: {
|
|
6304
|
-
Authorization: `Bearer ${
|
|
7874
|
+
Authorization: `Bearer ${this.imsToken}`
|
|
6305
7875
|
}
|
|
6306
7876
|
});
|
|
6307
7877
|
}
|
|
@@ -6873,6 +8443,7 @@ export {
|
|
|
6873
8443
|
ims_token_default as ImsToken,
|
|
6874
8444
|
infinite_loop_breaker_default as InfiniteLoopBreaker,
|
|
6875
8445
|
IoEventsGlobals,
|
|
8446
|
+
JsonMessageProcessor,
|
|
6876
8447
|
oauth1a_connection_default as Oauth1aConnection,
|
|
6877
8448
|
onboard_commerce_default as OnboardCommerce,
|
|
6878
8449
|
onboard_events_default as OnboardEvents,
|
|
@@ -6891,6 +8462,9 @@ export {
|
|
|
6891
8462
|
method_default as ShippingCarrierMethod,
|
|
6892
8463
|
response_default3 as ShippingCarrierResponse,
|
|
6893
8464
|
SignatureVerification,
|
|
8465
|
+
SuccessChecker,
|
|
8466
|
+
telemetry_default as Telemetry,
|
|
8467
|
+
TelemetryInputError,
|
|
6894
8468
|
validator_default as Validator,
|
|
6895
8469
|
webhook_action_default as WebhookAction,
|
|
6896
8470
|
WebhookActionOperation,
|