@adobe-commerce/aio-toolkit 1.0.8 → 1.0.10
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 +171 -0
- package/README.md +220 -33
- package/dist/index.d.mts +47 -10
- package/dist/index.d.ts +47 -10
- package/dist/index.js +1406 -155
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1417 -151
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,646 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __esm = (fn, res) => function __init() {
|
|
5
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
};
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// node_modules/tsup/assets/esm_shims.js
|
|
13
|
+
import path from "path";
|
|
14
|
+
import { fileURLToPath } from "url";
|
|
15
|
+
var init_esm_shims = __esm({
|
|
16
|
+
"node_modules/tsup/assets/esm_shims.js"() {
|
|
17
|
+
"use strict";
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// src/framework/telemetry/helpers/input-error/index.ts
|
|
22
|
+
var _TelemetryInputError, TelemetryInputError;
|
|
23
|
+
var init_input_error = __esm({
|
|
24
|
+
"src/framework/telemetry/helpers/input-error/index.ts"() {
|
|
25
|
+
"use strict";
|
|
26
|
+
init_esm_shims();
|
|
27
|
+
_TelemetryInputError = class _TelemetryInputError extends Error {
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new TelemetryInputError
|
|
30
|
+
*
|
|
31
|
+
* @param message - Descriptive error message explaining the validation failure
|
|
32
|
+
*/
|
|
33
|
+
constructor(message) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.name = "TelemetryInputError";
|
|
36
|
+
if (Error.captureStackTrace) {
|
|
37
|
+
Error.captureStackTrace(this, _TelemetryInputError);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
__name(_TelemetryInputError, "TelemetryInputError");
|
|
42
|
+
TelemetryInputError = _TelemetryInputError;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// src/framework/telemetry/new-relic/validator/index.ts
|
|
47
|
+
var _NewRelicTelemetryValidator, NewRelicTelemetryValidator;
|
|
48
|
+
var init_validator = __esm({
|
|
49
|
+
"src/framework/telemetry/new-relic/validator/index.ts"() {
|
|
50
|
+
"use strict";
|
|
51
|
+
init_esm_shims();
|
|
52
|
+
init_input_error();
|
|
53
|
+
_NewRelicTelemetryValidator = class _NewRelicTelemetryValidator {
|
|
54
|
+
/**
|
|
55
|
+
* Checks if New Relic telemetry is configured
|
|
56
|
+
*
|
|
57
|
+
* Returns true if:
|
|
58
|
+
* - ENABLE_TELEMETRY is explicitly set to true
|
|
59
|
+
* - NEW_RELIC_TELEMETRY is explicitly set to true
|
|
60
|
+
*
|
|
61
|
+
* This method does NOT validate the completeness of configuration,
|
|
62
|
+
* it only checks if the provider is enabled.
|
|
63
|
+
*
|
|
64
|
+
* @param params - Runtime parameters to check
|
|
65
|
+
* @returns true if New Relic telemetry is enabled, false otherwise
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const validator = new NewRelicTelemetryValidator();
|
|
70
|
+
* const params = { ENABLE_TELEMETRY: true, NEW_RELIC_TELEMETRY: true };
|
|
71
|
+
* if (validator.isConfigured(params)) {
|
|
72
|
+
* // New Relic is enabled, proceed with initialization
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
isConfigured(params) {
|
|
77
|
+
return params.ENABLE_TELEMETRY === true && params.NEW_RELIC_TELEMETRY === true;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Validates New Relic specific parameters
|
|
81
|
+
*
|
|
82
|
+
* IMPORTANT: Only call this method after checking isConfigured() returns true.
|
|
83
|
+
* This method assumes New Relic telemetry is enabled and validates that
|
|
84
|
+
* all required parameters are present.
|
|
85
|
+
*
|
|
86
|
+
* Required parameters when New Relic is enabled:
|
|
87
|
+
* - NEW_RELIC_SERVICE_NAME must be provided
|
|
88
|
+
* - NEW_RELIC_LICENSE_KEY must be provided
|
|
89
|
+
*
|
|
90
|
+
* @param params - Runtime parameters to validate
|
|
91
|
+
* @throws {TelemetryInputError} If NEW_RELIC_SERVICE_NAME is missing
|
|
92
|
+
* @throws {TelemetryInputError} If NEW_RELIC_LICENSE_KEY is missing
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const validator = new NewRelicTelemetryValidator();
|
|
97
|
+
* const params = {
|
|
98
|
+
* ENABLE_TELEMETRY: true,
|
|
99
|
+
* NEW_RELIC_TELEMETRY: true,
|
|
100
|
+
* NEW_RELIC_SERVICE_NAME: "my-service",
|
|
101
|
+
* NEW_RELIC_LICENSE_KEY: "license-key"
|
|
102
|
+
* };
|
|
103
|
+
*
|
|
104
|
+
* if (validator.isConfigured(params)) {
|
|
105
|
+
* validator.validateConfiguration(params); // Validates required fields
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
validateConfiguration(params) {
|
|
110
|
+
if (params.NEW_RELIC_SERVICE_NAME === void 0 || params.NEW_RELIC_SERVICE_NAME === null || params.NEW_RELIC_SERVICE_NAME === "") {
|
|
111
|
+
throw new TelemetryInputError("NEW_RELIC_SERVICE_NAME is required");
|
|
112
|
+
}
|
|
113
|
+
if (params.NEW_RELIC_LICENSE_KEY === void 0 || params.NEW_RELIC_LICENSE_KEY === null || params.NEW_RELIC_LICENSE_KEY === "") {
|
|
114
|
+
throw new TelemetryInputError("NEW_RELIC_LICENSE_KEY is required");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
__name(_NewRelicTelemetryValidator, "NewRelicTelemetryValidator");
|
|
119
|
+
NewRelicTelemetryValidator = _NewRelicTelemetryValidator;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// src/framework/telemetry/helpers/resource-factory/index.ts
|
|
124
|
+
import { getAioRuntimeResource } from "@adobe/aio-lib-telemetry";
|
|
125
|
+
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
126
|
+
var _ResourceFactory, ResourceFactory;
|
|
127
|
+
var init_resource_factory = __esm({
|
|
128
|
+
"src/framework/telemetry/helpers/resource-factory/index.ts"() {
|
|
129
|
+
"use strict";
|
|
130
|
+
init_esm_shims();
|
|
131
|
+
_ResourceFactory = class _ResourceFactory {
|
|
132
|
+
/**
|
|
133
|
+
* Creates a resource with custom environment attributes
|
|
134
|
+
*
|
|
135
|
+
* Starts with the base Adobe I/O Runtime resource and optionally
|
|
136
|
+
* merges environment attributes. These attributes are useful for
|
|
137
|
+
* filtering and correlating telemetry data by deployment environment.
|
|
138
|
+
*
|
|
139
|
+
* Note: Request-specific data (like request IDs) should NOT be added to
|
|
140
|
+
* Resources as they are created once and reused across all requests.
|
|
141
|
+
* Use log attributes or span attributes for request-specific data.
|
|
142
|
+
*
|
|
143
|
+
* @param params - Runtime parameters containing optional ENVIRONMENT
|
|
144
|
+
* @param params.ENVIRONMENT - Environment name (e.g., "dev", "stage", "prod")
|
|
145
|
+
* @returns OpenTelemetry Resource with custom attributes if provided
|
|
146
|
+
*
|
|
147
|
+
* @example Without custom attributes
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const factory = new ResourceFactory();
|
|
150
|
+
* const resource = factory.createWithEnvironment({});
|
|
151
|
+
* // Returns base Adobe I/O Runtime resource
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @example With environment
|
|
155
|
+
* ```typescript
|
|
156
|
+
* const factory = new ResourceFactory();
|
|
157
|
+
* const params = { ENVIRONMENT: "production" };
|
|
158
|
+
* const resource = factory.createWithEnvironment(params);
|
|
159
|
+
* // Returns resource with environment="production" attribute
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
createWithEnvironment(params) {
|
|
163
|
+
const baseResource = getAioRuntimeResource();
|
|
164
|
+
const customAttributes = {};
|
|
165
|
+
if (params.ENVIRONMENT) {
|
|
166
|
+
customAttributes.environment = params.ENVIRONMENT;
|
|
167
|
+
}
|
|
168
|
+
if (Object.keys(customAttributes).length === 0) {
|
|
169
|
+
return baseResource;
|
|
170
|
+
}
|
|
171
|
+
const customResource = resourceFromAttributes(
|
|
172
|
+
customAttributes
|
|
173
|
+
);
|
|
174
|
+
return baseResource.merge(customResource);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
__name(_ResourceFactory, "ResourceFactory");
|
|
178
|
+
ResourceFactory = _ResourceFactory;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// src/framework/telemetry/helpers/success-checker/index.ts
|
|
183
|
+
var _SuccessChecker, SuccessChecker;
|
|
184
|
+
var init_success_checker = __esm({
|
|
185
|
+
"src/framework/telemetry/helpers/success-checker/index.ts"() {
|
|
186
|
+
"use strict";
|
|
187
|
+
init_esm_shims();
|
|
188
|
+
_SuccessChecker = class _SuccessChecker {
|
|
189
|
+
/**
|
|
190
|
+
* Determines if an action execution was successful
|
|
191
|
+
*
|
|
192
|
+
* Success criteria:
|
|
193
|
+
* - Response has statusCode 200
|
|
194
|
+
* - Body does not contain an exception operation
|
|
195
|
+
*
|
|
196
|
+
* @param result - The action execution result
|
|
197
|
+
* @returns true if successful, false otherwise
|
|
198
|
+
*
|
|
199
|
+
* @example Success case
|
|
200
|
+
* ```typescript
|
|
201
|
+
* const checker = new SuccessChecker();
|
|
202
|
+
* const result = { statusCode: 200, body: { data: 'success' } };
|
|
203
|
+
* checker.execute(result); // true
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* @example Failure case - wrong status code
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const checker = new SuccessChecker();
|
|
209
|
+
* const result = { statusCode: 500, body: { error: 'Internal error' } };
|
|
210
|
+
* checker.execute(result); // false
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* @example Failure case - exception in body
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const checker = new SuccessChecker();
|
|
216
|
+
* const result = { statusCode: 200, body: { op: 'exception', message: 'Error' } };
|
|
217
|
+
* checker.execute(result); // false
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
execute(result) {
|
|
221
|
+
if (!result || typeof result !== "object") {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
const actionResult = result;
|
|
225
|
+
if (actionResult.statusCode !== 200) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
if (actionResult.body && typeof actionResult.body === "object") {
|
|
229
|
+
return actionResult.body.op !== "exception";
|
|
230
|
+
}
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
__name(_SuccessChecker, "SuccessChecker");
|
|
235
|
+
SuccessChecker = _SuccessChecker;
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// src/framework/telemetry/helpers/json-message-processor/index.ts
|
|
240
|
+
var _JsonMessageProcessor, JsonMessageProcessor;
|
|
241
|
+
var init_json_message_processor = __esm({
|
|
242
|
+
"src/framework/telemetry/helpers/json-message-processor/index.ts"() {
|
|
243
|
+
"use strict";
|
|
244
|
+
init_esm_shims();
|
|
245
|
+
_JsonMessageProcessor = class _JsonMessageProcessor {
|
|
246
|
+
/**
|
|
247
|
+
* Creates a new JsonMessageProcessor
|
|
248
|
+
*
|
|
249
|
+
* @param wrappedProcessor - The log processor to wrap and enhance
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* const exporter = new OTLPLogExporterProto({
|
|
254
|
+
* url: "https://otlp.nr-data.net/v1/logs",
|
|
255
|
+
* headers: { "api-key": licenseKey }
|
|
256
|
+
* });
|
|
257
|
+
* const baseProcessor = new SimpleLogRecordProcessor(exporter);
|
|
258
|
+
* const processor = new JsonMessageProcessor(baseProcessor);
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
constructor(wrappedProcessor) {
|
|
262
|
+
this.wrappedProcessor = wrappedProcessor;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Parse JavaScript object notation and convert to proper object
|
|
266
|
+
*
|
|
267
|
+
* Handles Winston's util.inspect format which produces JavaScript
|
|
268
|
+
* object literals instead of JSON strings.
|
|
269
|
+
*
|
|
270
|
+
* Examples:
|
|
271
|
+
* - { key: 'value' } → {"key":"value"}
|
|
272
|
+
* - { 'accept-encoding': 'gzip' } → {"accept-encoding":"gzip"}
|
|
273
|
+
*
|
|
274
|
+
* @param str - JavaScript object notation string
|
|
275
|
+
* @returns Parsed object
|
|
276
|
+
* @throws Error if parsing fails
|
|
277
|
+
* @private
|
|
278
|
+
*/
|
|
279
|
+
parseJavaScriptObjectNotation(str) {
|
|
280
|
+
const func = new Function("return (" + str + ")");
|
|
281
|
+
return func();
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Flatten nested objects into dot-notation keys
|
|
285
|
+
*
|
|
286
|
+
* Converts nested structures like:
|
|
287
|
+
* { headers: { accept: '*' } }
|
|
288
|
+
*
|
|
289
|
+
* Into flat structure:
|
|
290
|
+
* { 'headers.accept': '*' }
|
|
291
|
+
*
|
|
292
|
+
* This makes all attributes searchable in observability platforms.
|
|
293
|
+
*
|
|
294
|
+
* @param obj - Object to flatten
|
|
295
|
+
* @param prefix - Current key prefix (used in recursion)
|
|
296
|
+
* @returns Flattened object with dot-notation keys
|
|
297
|
+
* @private
|
|
298
|
+
*/
|
|
299
|
+
flattenObject(obj, prefix = "") {
|
|
300
|
+
const flattened = {};
|
|
301
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
302
|
+
const newKey = prefix ? `${prefix}.${key}` : key;
|
|
303
|
+
if (value === null || value === void 0) {
|
|
304
|
+
flattened[newKey] = value;
|
|
305
|
+
} else if (Array.isArray(value)) {
|
|
306
|
+
flattened[newKey] = JSON.stringify(value);
|
|
307
|
+
} else if (typeof value === "object") {
|
|
308
|
+
if (Object.keys(value).length === 0) {
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const nested = this.flattenObject(value, newKey);
|
|
312
|
+
Object.assign(flattened, nested);
|
|
313
|
+
} else {
|
|
314
|
+
flattened[newKey] = value;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return flattened;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Processes a log record by parsing JSON messages and extracting attributes
|
|
321
|
+
*
|
|
322
|
+
* This method intercepts log records, attempts to parse structured data
|
|
323
|
+
* from the message body, and merges extracted properties as attributes.
|
|
324
|
+
* Additionally, it extracts the log level from the severity information
|
|
325
|
+
* and adds it as a 'level' attribute for easier querying.
|
|
326
|
+
*
|
|
327
|
+
* The enhanced log record is then passed to the wrapped processor.
|
|
328
|
+
*
|
|
329
|
+
* @param logRecord - The log record to process
|
|
330
|
+
*
|
|
331
|
+
* @remarks
|
|
332
|
+
* Processing steps:
|
|
333
|
+
* 1. Extract log level from severityText or severityNumber
|
|
334
|
+
* 2. Add 'level' attribute (debug, info, warn, error, etc.)
|
|
335
|
+
* 3. Parse JSON bodies that start with '{'
|
|
336
|
+
* 4. Extract properties as individual attributes
|
|
337
|
+
* 5. Preserve 'message' field as primary log body
|
|
338
|
+
*
|
|
339
|
+
* Error handling:
|
|
340
|
+
* - Silently handles parsing errors to avoid breaking the logging pipeline
|
|
341
|
+
* - Failed parsing results in unmodified log record
|
|
342
|
+
*/
|
|
343
|
+
onEmit(logRecord) {
|
|
344
|
+
try {
|
|
345
|
+
if (logRecord.severityText) {
|
|
346
|
+
logRecord.setAttribute("level", logRecord.severityText.toLowerCase());
|
|
347
|
+
} else if (logRecord.severityNumber !== void 0) {
|
|
348
|
+
const levelName = this.mapSeverityNumberToLevel(logRecord.severityNumber);
|
|
349
|
+
if (levelName) {
|
|
350
|
+
logRecord.setAttribute("level", levelName);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
const body = logRecord.body;
|
|
354
|
+
if (typeof body === "string" && body.trim().startsWith("{")) {
|
|
355
|
+
let parsed = null;
|
|
356
|
+
try {
|
|
357
|
+
parsed = JSON.parse(body);
|
|
358
|
+
} catch {
|
|
359
|
+
try {
|
|
360
|
+
parsed = this.parseJavaScriptObjectNotation(body);
|
|
361
|
+
} catch {
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
365
|
+
const messageValue = parsed.message;
|
|
366
|
+
const { message, ...attributesObj } = parsed;
|
|
367
|
+
const flattenedAttributes = this.flattenObject(attributesObj);
|
|
368
|
+
Object.entries(flattenedAttributes).forEach(([key, value]) => {
|
|
369
|
+
if (value !== void 0 && value !== null) {
|
|
370
|
+
logRecord.setAttribute(key, value);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
if (messageValue) {
|
|
374
|
+
logRecord.body = messageValue;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
} catch {
|
|
379
|
+
}
|
|
380
|
+
this.wrappedProcessor.onEmit(logRecord);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Maps OpenTelemetry severity number to log level name
|
|
384
|
+
*
|
|
385
|
+
* OpenTelemetry defines severity numbers from 1-24:
|
|
386
|
+
* - 1-4: TRACE
|
|
387
|
+
* - 5-8: DEBUG
|
|
388
|
+
* - 9-12: INFO
|
|
389
|
+
* - 13-16: WARN
|
|
390
|
+
* - 17-20: ERROR
|
|
391
|
+
* - 21-24: FATAL
|
|
392
|
+
*
|
|
393
|
+
* @param severityNumber - OpenTelemetry severity number
|
|
394
|
+
* @returns Log level name (trace, debug, info, warn, error, fatal) or null
|
|
395
|
+
* @private
|
|
396
|
+
*/
|
|
397
|
+
mapSeverityNumberToLevel(severityNumber) {
|
|
398
|
+
if (severityNumber >= 1 && severityNumber <= 4) return "trace";
|
|
399
|
+
if (severityNumber >= 5 && severityNumber <= 8) return "debug";
|
|
400
|
+
if (severityNumber >= 9 && severityNumber <= 12) return "info";
|
|
401
|
+
if (severityNumber >= 13 && severityNumber <= 16) return "warn";
|
|
402
|
+
if (severityNumber >= 17 && severityNumber <= 20) return "error";
|
|
403
|
+
if (severityNumber >= 21 && severityNumber <= 24) return "fatal";
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Forces the processor to flush any pending log records
|
|
408
|
+
*
|
|
409
|
+
* Delegates to the wrapped processor's forceFlush method.
|
|
410
|
+
* Useful for ensuring logs are sent before application shutdown.
|
|
411
|
+
*
|
|
412
|
+
* @returns Promise that resolves when flush is complete
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```typescript
|
|
416
|
+
* await processor.forceFlush();
|
|
417
|
+
* console.log("All logs have been sent");
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
async forceFlush() {
|
|
421
|
+
return this.wrappedProcessor.forceFlush();
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Shuts down the processor and releases resources
|
|
425
|
+
*
|
|
426
|
+
* Delegates to the wrapped processor's shutdown method.
|
|
427
|
+
* Should be called when the application is terminating.
|
|
428
|
+
*
|
|
429
|
+
* @returns Promise that resolves when shutdown is complete
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```typescript
|
|
433
|
+
* await processor.shutdown();
|
|
434
|
+
* console.log("Processor has been shut down");
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
async shutdown() {
|
|
438
|
+
return this.wrappedProcessor.shutdown();
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
__name(_JsonMessageProcessor, "JsonMessageProcessor");
|
|
442
|
+
JsonMessageProcessor = _JsonMessageProcessor;
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
// src/framework/telemetry/new-relic/index.ts
|
|
447
|
+
var new_relic_exports = {};
|
|
448
|
+
__export(new_relic_exports, {
|
|
449
|
+
default: () => new_relic_default
|
|
450
|
+
});
|
|
451
|
+
import {
|
|
452
|
+
defineTelemetryConfig,
|
|
453
|
+
getPresetInstrumentations,
|
|
454
|
+
instrumentEntrypoint
|
|
455
|
+
} from "@adobe/aio-lib-telemetry";
|
|
456
|
+
import {
|
|
457
|
+
OTLPLogExporterProto,
|
|
458
|
+
OTLPMetricExporterProto,
|
|
459
|
+
OTLPTraceExporterProto,
|
|
460
|
+
PeriodicExportingMetricReader,
|
|
461
|
+
SimpleLogRecordProcessor
|
|
462
|
+
} from "@adobe/aio-lib-telemetry/otel";
|
|
463
|
+
var _NewRelicTelemetry, NewRelicTelemetry, new_relic_default;
|
|
464
|
+
var init_new_relic = __esm({
|
|
465
|
+
"src/framework/telemetry/new-relic/index.ts"() {
|
|
466
|
+
"use strict";
|
|
467
|
+
init_esm_shims();
|
|
468
|
+
init_validator();
|
|
469
|
+
init_resource_factory();
|
|
470
|
+
init_success_checker();
|
|
471
|
+
init_json_message_processor();
|
|
472
|
+
_NewRelicTelemetry = class _NewRelicTelemetry {
|
|
473
|
+
/**
|
|
474
|
+
* Constructor for New Relic telemetry
|
|
475
|
+
*
|
|
476
|
+
* @description Constructor for New Relic telemetry
|
|
477
|
+
* @example
|
|
478
|
+
* ```typescript
|
|
479
|
+
* const telemetry = new NewRelicTelemetry();
|
|
480
|
+
* ```
|
|
481
|
+
*/
|
|
482
|
+
constructor() {
|
|
483
|
+
this.validator = new NewRelicTelemetryValidator();
|
|
484
|
+
this.successChecker = new SuccessChecker();
|
|
485
|
+
this.resourceFactory = new ResourceFactory();
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Checks if New Relic telemetry can be initialized
|
|
489
|
+
*
|
|
490
|
+
* Determines if New Relic telemetry is properly configured without actually
|
|
491
|
+
* attempting initialization. Useful for provider chain fallback logic.
|
|
492
|
+
*
|
|
493
|
+
* @param params - Runtime parameters to check
|
|
494
|
+
* @returns true if New Relic is configured and can be initialized
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```typescript
|
|
498
|
+
* const telemetry = new NewRelicTelemetry();
|
|
499
|
+
* if (telemetry.canInitialize(params)) {
|
|
500
|
+
* // New Relic is configured, use it
|
|
501
|
+
* } else {
|
|
502
|
+
* // Try next provider
|
|
503
|
+
* }
|
|
504
|
+
* ```
|
|
505
|
+
*/
|
|
506
|
+
canInitialize(params) {
|
|
507
|
+
return this.validator.isConfigured(params);
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Get the OpenTelemetry instrumentation configuration for New Relic
|
|
511
|
+
*
|
|
512
|
+
* Builds and returns the complete instrumentation configuration including:
|
|
513
|
+
* - Service name and preset instrumentations
|
|
514
|
+
* - Custom resource attributes (environment)
|
|
515
|
+
* - OTLP exporters for traces, metrics, and logs
|
|
516
|
+
* - Success/failure detection for actions
|
|
517
|
+
*
|
|
518
|
+
* This method is called internally by `instrumentEntrypoint` to configure
|
|
519
|
+
* telemetry before wrapping the action.
|
|
520
|
+
*
|
|
521
|
+
* @returns Complete entrypoint instrumentation configuration
|
|
522
|
+
* @throws {TelemetryInputError} If required parameters are missing (service name, license key)
|
|
523
|
+
*
|
|
524
|
+
* @example
|
|
525
|
+
* ```typescript
|
|
526
|
+
* const telemetry = new NewRelicTelemetry();
|
|
527
|
+
* const config = telemetry.getConfig();
|
|
528
|
+
* // Returns configuration with exporters, instrumentations, and resource attributes
|
|
529
|
+
* ```
|
|
530
|
+
*/
|
|
531
|
+
getConfig() {
|
|
532
|
+
return {
|
|
533
|
+
...defineTelemetryConfig((params) => {
|
|
534
|
+
if (!this.validator.isConfigured(params)) {
|
|
535
|
+
throw new Error("New Relic telemetry is not configured");
|
|
536
|
+
}
|
|
537
|
+
this.validator.validateConfiguration(params);
|
|
538
|
+
const serviceName = params.NEW_RELIC_SERVICE_NAME;
|
|
539
|
+
return {
|
|
540
|
+
sdkConfig: {
|
|
541
|
+
serviceName,
|
|
542
|
+
instrumentations: getPresetInstrumentations("simple"),
|
|
543
|
+
resource: this.resourceFactory.createWithEnvironment(params),
|
|
544
|
+
...this.getExportersConfig(params)
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
}),
|
|
548
|
+
isSuccessful: this.successChecker.execute.bind(this.successChecker)
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Configure New Relic exporters for traces, metrics, and logs
|
|
553
|
+
*
|
|
554
|
+
* Creates OTLP exporters for all three signal types (traces, metrics, logs)
|
|
555
|
+
* and configures them to send data to New Relic. Log processors are wrapped
|
|
556
|
+
* with JsonMessageProcessor for better attribute extraction.
|
|
557
|
+
*
|
|
558
|
+
* @param params - Runtime parameters containing NEW_RELIC_LICENSE_KEY and optional NEW_RELIC_URL
|
|
559
|
+
* @returns Configuration object with traceExporter, metricReaders, and logRecordProcessors
|
|
560
|
+
* @private
|
|
561
|
+
*/
|
|
562
|
+
getExportersConfig(params) {
|
|
563
|
+
const licenseKey = params.NEW_RELIC_LICENSE_KEY;
|
|
564
|
+
const newRelicUrl = params.NEW_RELIC_URL || "https://otlp.nr-data.net";
|
|
565
|
+
const makeExporterConfig = /* @__PURE__ */ __name((endpoint) => {
|
|
566
|
+
return {
|
|
567
|
+
url: `${newRelicUrl}/${endpoint}`,
|
|
568
|
+
headers: {
|
|
569
|
+
"api-key": licenseKey
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
}, "makeExporterConfig");
|
|
573
|
+
return {
|
|
574
|
+
traceExporter: new OTLPTraceExporterProto(makeExporterConfig("v1/traces")),
|
|
575
|
+
metricReaders: [
|
|
576
|
+
new PeriodicExportingMetricReader({
|
|
577
|
+
exporter: new OTLPMetricExporterProto(makeExporterConfig("v1/metrics"))
|
|
578
|
+
})
|
|
579
|
+
],
|
|
580
|
+
logRecordProcessors: [
|
|
581
|
+
new JsonMessageProcessor(
|
|
582
|
+
new SimpleLogRecordProcessor(new OTLPLogExporterProto(makeExporterConfig("v1/logs")))
|
|
583
|
+
)
|
|
584
|
+
]
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Initialize telemetry instrumentation for a runtime action
|
|
589
|
+
*
|
|
590
|
+
* Wraps the provided action with OpenTelemetry instrumentation using
|
|
591
|
+
* New Relic as the backend. The instrumented action will automatically:
|
|
592
|
+
* - Create spans for the action execution
|
|
593
|
+
* - Export metrics during runtime
|
|
594
|
+
* - Forward logs to New Relic
|
|
595
|
+
* - Track success/failure status
|
|
596
|
+
*
|
|
597
|
+
* This method delegates to `instrumentEntrypoint` from `@adobe/aio-lib-telemetry`,
|
|
598
|
+
* passing the action and New Relic specific configuration.
|
|
599
|
+
*
|
|
600
|
+
* @param action - The runtime action function to instrument
|
|
601
|
+
* @returns The instrumented action function with telemetry enabled
|
|
602
|
+
* @throws {TelemetryInputError} If required configuration is missing
|
|
603
|
+
*
|
|
604
|
+
* @example
|
|
605
|
+
* ```typescript
|
|
606
|
+
* async function myAction(params: Record<string, unknown>) {
|
|
607
|
+
* const logger = Telemetry.createLogger("my-action", params);
|
|
608
|
+
* logger.info("Processing request");
|
|
609
|
+
*
|
|
610
|
+
* return { statusCode: 200, body: { success: true } };
|
|
611
|
+
* }
|
|
612
|
+
*
|
|
613
|
+
* const telemetry = new NewRelicTelemetry();
|
|
614
|
+
* const instrumentedAction = telemetry.initialize(myAction);
|
|
615
|
+
*
|
|
616
|
+
* // instrumentedAction now sends traces, metrics, and logs to New Relic
|
|
617
|
+
* export const main = instrumentedAction;
|
|
618
|
+
* ```
|
|
619
|
+
*/
|
|
620
|
+
initialize(action) {
|
|
621
|
+
return instrumentEntrypoint(action, this.getConfig());
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
__name(_NewRelicTelemetry, "NewRelicTelemetry");
|
|
625
|
+
NewRelicTelemetry = _NewRelicTelemetry;
|
|
626
|
+
new_relic_default = NewRelicTelemetry;
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
// src/index.ts
|
|
631
|
+
init_esm_shims();
|
|
632
|
+
|
|
633
|
+
// src/framework/index.ts
|
|
634
|
+
init_esm_shims();
|
|
3
635
|
|
|
4
636
|
// src/framework/runtime-action/index.ts
|
|
5
|
-
|
|
637
|
+
init_esm_shims();
|
|
638
|
+
|
|
639
|
+
// src/framework/runtime-action/response/index.ts
|
|
640
|
+
init_esm_shims();
|
|
6
641
|
|
|
7
642
|
// src/framework/runtime-action/types.ts
|
|
643
|
+
init_esm_shims();
|
|
8
644
|
var HttpStatus = /* @__PURE__ */ ((HttpStatus2) => {
|
|
9
645
|
HttpStatus2[HttpStatus2["OK"] = 200] = "OK";
|
|
10
646
|
HttpStatus2[HttpStatus2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
@@ -66,29 +702,8 @@ __name(_RuntimeActionResponse, "RuntimeActionResponse");
|
|
|
66
702
|
var RuntimeActionResponse = _RuntimeActionResponse;
|
|
67
703
|
var response_default = RuntimeActionResponse;
|
|
68
704
|
|
|
69
|
-
// src/framework/runtime-action/parameters/index.ts
|
|
70
|
-
var _Parameters = class _Parameters {
|
|
71
|
-
/**
|
|
72
|
-
* Returns a log-ready string of the action input parameters.
|
|
73
|
-
* The `Authorization` header content will be replaced by '<hidden>'.
|
|
74
|
-
*
|
|
75
|
-
* @param params action input parameters.
|
|
76
|
-
*
|
|
77
|
-
* @returns string
|
|
78
|
-
*/
|
|
79
|
-
static stringify(params) {
|
|
80
|
-
let headers = params.__ow_headers || {};
|
|
81
|
-
if (headers.authorization) {
|
|
82
|
-
headers = { ...headers, authorization: "<hidden>" };
|
|
83
|
-
}
|
|
84
|
-
return JSON.stringify({ ...params, __ow_headers: headers });
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
__name(_Parameters, "Parameters");
|
|
88
|
-
var Parameters = _Parameters;
|
|
89
|
-
var parameters_default = Parameters;
|
|
90
|
-
|
|
91
705
|
// src/framework/runtime-action/validator/index.ts
|
|
706
|
+
init_esm_shims();
|
|
92
707
|
var _Validator = class _Validator {
|
|
93
708
|
/**
|
|
94
709
|
* Returns the list of missing keys given an object and its required keys.
|
|
@@ -153,91 +768,582 @@ __name(_Validator, "Validator");
|
|
|
153
768
|
var Validator = _Validator;
|
|
154
769
|
var validator_default = Validator;
|
|
155
770
|
|
|
771
|
+
// src/framework/telemetry/index.ts
|
|
772
|
+
init_esm_shims();
|
|
773
|
+
import { Core } from "@adobe/aio-sdk";
|
|
774
|
+
var _Telemetry = class _Telemetry {
|
|
775
|
+
/**
|
|
776
|
+
* Create a logger with standard configuration and automatic metadata injection.
|
|
777
|
+
*
|
|
778
|
+
* This method creates a structured logger and wraps it to automatically add
|
|
779
|
+
* contextual metadata to all log calls:
|
|
780
|
+
* - `x-adobe-commerce-request-id`: Extracted from `__ow_headers` (when present)
|
|
781
|
+
* - `action.type`: Extracted from `params.action_type` (when present)
|
|
782
|
+
*
|
|
783
|
+
* If ENABLE_TELEMETRY is true, uses OpenTelemetry logger (lazy-loaded); otherwise uses Core.Logger.
|
|
784
|
+
* The environment from params.ENVIRONMENT is set at the resource level and will
|
|
785
|
+
* automatically appear in all logs sent to New Relic if ENABLE_TELEMETRY is true.
|
|
786
|
+
*
|
|
787
|
+
* @param name - Logger name (typically action name)
|
|
788
|
+
* @param params - Runtime parameters containing LOG_LEVEL, optional ENABLE_TELEMETRY, ENVIRONMENT, action_type, and __ow_headers
|
|
789
|
+
* @returns Configured logger instance with automatic metadata injection
|
|
790
|
+
*
|
|
791
|
+
* @example Basic string message
|
|
792
|
+
* ```typescript
|
|
793
|
+
* const logger = Telemetry.createLogger("my-action", params);
|
|
794
|
+
* logger.info("Processing started");
|
|
795
|
+
* // Logs: "Processing started"
|
|
796
|
+
* ```
|
|
797
|
+
*
|
|
798
|
+
* @example JSON object message with automatic metadata
|
|
799
|
+
* ```typescript
|
|
800
|
+
* const logger = Telemetry.createLogger("my-action", {
|
|
801
|
+
* ...params,
|
|
802
|
+
* action_type: "webhook",
|
|
803
|
+
* __ow_headers: { 'x-adobe-commerce-request-id': 'req-123' }
|
|
804
|
+
* });
|
|
805
|
+
* logger.info({
|
|
806
|
+
* message: "User action completed",
|
|
807
|
+
* user_id: "123"
|
|
808
|
+
* });
|
|
809
|
+
* // In New Relic: {
|
|
810
|
+
* // message: "User action completed",
|
|
811
|
+
* // user_id: "123",
|
|
812
|
+
* // "x-adobe-commerce-request-id": "req-123",
|
|
813
|
+
* // "action.type": "webhook",
|
|
814
|
+
* // environment: "development",
|
|
815
|
+
* // ...
|
|
816
|
+
* // }
|
|
817
|
+
* ```
|
|
818
|
+
*/
|
|
819
|
+
static createLogger(name, params) {
|
|
820
|
+
const logLevel = params.LOG_LEVEL || "info";
|
|
821
|
+
if (!params.ENABLE_TELEMETRY) {
|
|
822
|
+
const baseLogger = Core.Logger(name, { level: logLevel });
|
|
823
|
+
return _Telemetry.wrapLogger(baseLogger, params);
|
|
824
|
+
}
|
|
825
|
+
let telemetryLogger = null;
|
|
826
|
+
let loadingPromise = null;
|
|
827
|
+
const fallbackLogger = Core.Logger(name, { level: logLevel });
|
|
828
|
+
const loadTelemetryLogger = /* @__PURE__ */ __name(async () => {
|
|
829
|
+
if (telemetryLogger || loadingPromise) {
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
loadingPromise = (async () => {
|
|
833
|
+
try {
|
|
834
|
+
const { getLogger } = await import("@adobe/aio-lib-telemetry");
|
|
835
|
+
telemetryLogger = getLogger(name, { level: logLevel });
|
|
836
|
+
} catch (error) {
|
|
837
|
+
telemetryLogger = fallbackLogger;
|
|
838
|
+
}
|
|
839
|
+
})();
|
|
840
|
+
await loadingPromise;
|
|
841
|
+
}, "loadTelemetryLogger");
|
|
842
|
+
loadTelemetryLogger().catch(() => {
|
|
843
|
+
});
|
|
844
|
+
const proxyLogger = {
|
|
845
|
+
debug: /* @__PURE__ */ __name((message) => {
|
|
846
|
+
const logger = telemetryLogger || fallbackLogger;
|
|
847
|
+
logger.debug(message);
|
|
848
|
+
}, "debug"),
|
|
849
|
+
info: /* @__PURE__ */ __name((message) => {
|
|
850
|
+
const logger = telemetryLogger || fallbackLogger;
|
|
851
|
+
logger.info(message);
|
|
852
|
+
}, "info"),
|
|
853
|
+
warn: /* @__PURE__ */ __name((message) => {
|
|
854
|
+
const logger = telemetryLogger || fallbackLogger;
|
|
855
|
+
logger.warn(message);
|
|
856
|
+
}, "warn"),
|
|
857
|
+
error: /* @__PURE__ */ __name((message) => {
|
|
858
|
+
const logger = telemetryLogger || fallbackLogger;
|
|
859
|
+
logger.error(message);
|
|
860
|
+
}, "error")
|
|
861
|
+
};
|
|
862
|
+
return _Telemetry.wrapLogger(proxyLogger, params);
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Wrap a logger with automatic metadata injection
|
|
866
|
+
*
|
|
867
|
+
* @private
|
|
868
|
+
* @param baseLogger - The base logger to wrap
|
|
869
|
+
* @param params - Runtime parameters containing optional metadata
|
|
870
|
+
* @returns Wrapped logger with metadata injection
|
|
871
|
+
*/
|
|
872
|
+
static wrapLogger(baseLogger, params) {
|
|
873
|
+
const metadata = {};
|
|
874
|
+
const headers = params.__ow_headers;
|
|
875
|
+
const requestId = headers?.["x-adobe-commerce-request-id"];
|
|
876
|
+
if (requestId && requestId !== "") {
|
|
877
|
+
metadata["x-adobe-commerce-request-id"] = requestId;
|
|
878
|
+
}
|
|
879
|
+
const actionType = params.action_type;
|
|
880
|
+
if (actionType && actionType !== "") {
|
|
881
|
+
metadata["action.type"] = actionType;
|
|
882
|
+
}
|
|
883
|
+
if (Object.keys(metadata).length === 0) {
|
|
884
|
+
return baseLogger;
|
|
885
|
+
}
|
|
886
|
+
const wrapper = {
|
|
887
|
+
debug: /* @__PURE__ */ __name((message) => {
|
|
888
|
+
if (typeof message === "object" && message !== null) {
|
|
889
|
+
baseLogger.debug({ ...metadata, ...message });
|
|
890
|
+
} else {
|
|
891
|
+
baseLogger.debug(message);
|
|
892
|
+
}
|
|
893
|
+
}, "debug"),
|
|
894
|
+
info: /* @__PURE__ */ __name((message) => {
|
|
895
|
+
if (typeof message === "object" && message !== null) {
|
|
896
|
+
baseLogger.info({ ...metadata, ...message });
|
|
897
|
+
} else {
|
|
898
|
+
baseLogger.info(message);
|
|
899
|
+
}
|
|
900
|
+
}, "info"),
|
|
901
|
+
warn: /* @__PURE__ */ __name((message) => {
|
|
902
|
+
if (typeof message === "object" && message !== null) {
|
|
903
|
+
baseLogger.warn({ ...metadata, ...message });
|
|
904
|
+
} else {
|
|
905
|
+
baseLogger.warn(message);
|
|
906
|
+
}
|
|
907
|
+
}, "warn"),
|
|
908
|
+
error: /* @__PURE__ */ __name((message) => {
|
|
909
|
+
if (typeof message === "object" && message !== null) {
|
|
910
|
+
baseLogger.error({ ...metadata, ...message });
|
|
911
|
+
} else {
|
|
912
|
+
baseLogger.error(message);
|
|
913
|
+
}
|
|
914
|
+
}, "error")
|
|
915
|
+
};
|
|
916
|
+
return {
|
|
917
|
+
...baseLogger,
|
|
918
|
+
...wrapper
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Extract structured error information for logging
|
|
923
|
+
*
|
|
924
|
+
* Converts Error objects into a structured format suitable for logging
|
|
925
|
+
* and telemetry systems like New Relic.
|
|
926
|
+
*
|
|
927
|
+
* @param error - Error object or unknown error value
|
|
928
|
+
* @returns Structured error object with name, message, and stack trace
|
|
929
|
+
*
|
|
930
|
+
* @example
|
|
931
|
+
* ```typescript
|
|
932
|
+
* try {
|
|
933
|
+
* // some operation
|
|
934
|
+
* } catch (error) {
|
|
935
|
+
* logger.error("Operation failed", Telemetry.formatError(error));
|
|
936
|
+
* }
|
|
937
|
+
* ```
|
|
938
|
+
*/
|
|
939
|
+
static formatError(error) {
|
|
940
|
+
if (error instanceof Error) {
|
|
941
|
+
return {
|
|
942
|
+
error_name: error.name,
|
|
943
|
+
error_message: error.message,
|
|
944
|
+
error_stack: error.stack
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
return { error: String(error) };
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Initialize telemetry for a runtime action with provider fallback chain
|
|
951
|
+
*
|
|
952
|
+
* Attempts to initialize telemetry providers in the following order:
|
|
953
|
+
* 1. New Relic (if NEW_RELIC_TELEMETRY=true)
|
|
954
|
+
* 2. Grafana (if GRAFANA_TELEMETRY=true) - Future support
|
|
955
|
+
* 3. Original action (no telemetry)
|
|
956
|
+
*
|
|
957
|
+
* Telemetry initialization is deferred to runtime when params are available.
|
|
958
|
+
* This allows proper configuration detection and graceful fallback to the
|
|
959
|
+
* next provider in the chain.
|
|
960
|
+
*
|
|
961
|
+
* **IMPORTANT**: If a provider is explicitly enabled (e.g., NEW_RELIC_TELEMETRY=true)
|
|
962
|
+
* but has invalid configuration (missing API key, service name), a 500 error response
|
|
963
|
+
* is returned to alert you of the misconfiguration. This prevents silently running
|
|
964
|
+
* without telemetry when you expect it to be working.
|
|
965
|
+
*
|
|
966
|
+
* Environment Configuration:
|
|
967
|
+
* Pass params.ENVIRONMENT to set the environment field in all logs.
|
|
968
|
+
* This can be set via environment variables in your action configuration.
|
|
969
|
+
*
|
|
970
|
+
* @param action - The runtime action function to instrument
|
|
971
|
+
* @returns The instrumented action ready for export
|
|
972
|
+
*
|
|
973
|
+
* @example Single provider (New Relic) - Valid configuration
|
|
974
|
+
* ```typescript
|
|
975
|
+
* // Environment:
|
|
976
|
+
* // ENABLE_TELEMETRY=true
|
|
977
|
+
* // NEW_RELIC_TELEMETRY=true
|
|
978
|
+
* // NEW_RELIC_SERVICE_NAME=my-service
|
|
979
|
+
* // NEW_RELIC_LICENSE_KEY=xxxxx
|
|
980
|
+
*
|
|
981
|
+
* export const main = Telemetry.initialize(myAction);
|
|
982
|
+
* // ✅ Uses New Relic telemetry
|
|
983
|
+
* ```
|
|
984
|
+
*
|
|
985
|
+
* @example New Relic enabled but misconfigured - Returns error response
|
|
986
|
+
* ```typescript
|
|
987
|
+
* // Environment:
|
|
988
|
+
* // ENABLE_TELEMETRY=true
|
|
989
|
+
* // NEW_RELIC_TELEMETRY=true
|
|
990
|
+
* // NEW_RELIC_SERVICE_NAME=my-service
|
|
991
|
+
* // Missing NEW_RELIC_LICENSE_KEY!
|
|
992
|
+
*
|
|
993
|
+
* export const main = Telemetry.initialize(myAction);
|
|
994
|
+
* // ❌ Returns { error: { statusCode: 500, body: { error: "Telemetry configuration error: NEW_RELIC_LICENSE_KEY is required" } } }
|
|
995
|
+
* // This is intentional - you want to know your telemetry config is broken!
|
|
996
|
+
* ```
|
|
997
|
+
*
|
|
998
|
+
* @example Multi-provider fallback
|
|
999
|
+
* ```typescript
|
|
1000
|
+
* // Environment:
|
|
1001
|
+
* // ENABLE_TELEMETRY=true
|
|
1002
|
+
* // NEW_RELIC_TELEMETRY=false // Skip New Relic
|
|
1003
|
+
* // GRAFANA_TELEMETRY=true // Use Grafana instead
|
|
1004
|
+
*
|
|
1005
|
+
* export const main = Telemetry.initialize(myAction);
|
|
1006
|
+
* // ✅ Skips New Relic, tries Grafana (when implemented)
|
|
1007
|
+
* ```
|
|
1008
|
+
*
|
|
1009
|
+
* @example No telemetry
|
|
1010
|
+
* ```typescript
|
|
1011
|
+
* // Environment:
|
|
1012
|
+
* // ENABLE_TELEMETRY=false (or not set)
|
|
1013
|
+
*
|
|
1014
|
+
* export const main = Telemetry.initialize(myAction);
|
|
1015
|
+
* // ✅ Returns original action without instrumentation
|
|
1016
|
+
* ```
|
|
1017
|
+
*/
|
|
1018
|
+
static initialize(action) {
|
|
1019
|
+
return async (params) => {
|
|
1020
|
+
if (params.ENABLE_TELEMETRY && params.NEW_RELIC_TELEMETRY) {
|
|
1021
|
+
try {
|
|
1022
|
+
const { default: NewRelicTelemetry2 } = await Promise.resolve().then(() => (init_new_relic(), new_relic_exports));
|
|
1023
|
+
const newRelicTelemetry = new NewRelicTelemetry2();
|
|
1024
|
+
if (newRelicTelemetry.canInitialize(params)) {
|
|
1025
|
+
try {
|
|
1026
|
+
const instrumentedAction = newRelicTelemetry.initialize(action);
|
|
1027
|
+
return await instrumentedAction(params);
|
|
1028
|
+
} catch (error) {
|
|
1029
|
+
const errorMessage = error instanceof Error ? error.message : "Telemetry initialization failed";
|
|
1030
|
+
return response_default.error(
|
|
1031
|
+
500 /* INTERNAL_ERROR */,
|
|
1032
|
+
`Telemetry configuration error: ${errorMessage}`
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
} catch (error) {
|
|
1037
|
+
const errorMessage = error instanceof Error ? error.message : "Failed to load telemetry module";
|
|
1038
|
+
return response_default.error(
|
|
1039
|
+
500 /* INTERNAL_ERROR */,
|
|
1040
|
+
`Telemetry module error: ${errorMessage}`
|
|
1041
|
+
);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
return action(params);
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
__name(_Telemetry, "Telemetry");
|
|
1049
|
+
var Telemetry = _Telemetry;
|
|
1050
|
+
var telemetry_default = Telemetry;
|
|
1051
|
+
|
|
156
1052
|
// src/framework/runtime-action/index.ts
|
|
157
1053
|
var _RuntimeAction = class _RuntimeAction {
|
|
158
1054
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* @param action
|
|
164
|
-
|
|
1055
|
+
* Sets the action type for the next action execution
|
|
1056
|
+
* This is used for logging to identify different action types
|
|
1057
|
+
* (runtime-action, webhook-action, event-consumer-action, etc.)
|
|
1058
|
+
*
|
|
1059
|
+
* @param type - The action type identifier
|
|
1060
|
+
*/
|
|
1061
|
+
static setActionType(type) {
|
|
1062
|
+
_RuntimeAction.actionType = type;
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Gets the current action type
|
|
1066
|
+
* @returns The current action type identifier
|
|
1067
|
+
*/
|
|
1068
|
+
static getActionType() {
|
|
1069
|
+
return _RuntimeAction.actionType;
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Creates a runtime action handler with validation, logging, and telemetry
|
|
1073
|
+
*
|
|
1074
|
+
* Wraps a user-defined action function with standardized runtime functionality:
|
|
1075
|
+
* 1. Creates a structured logger with telemetry integration
|
|
1076
|
+
* 2. Logs action start, headers, and body at debug level
|
|
1077
|
+
* 3. Validates required parameters, headers, and HTTP methods
|
|
1078
|
+
* 4. Executes the user action with logger and headers context
|
|
1079
|
+
* 5. Logs the result and handles errors with appropriate status codes
|
|
1080
|
+
* 6. Integrates with OpenTelemetry for distributed tracing
|
|
1081
|
+
*
|
|
1082
|
+
* @param name - Action name used for logging and telemetry spans (default: 'main')
|
|
1083
|
+
* @param httpMethods - Allowed HTTP methods (GET, POST, etc.). Empty array allows all methods
|
|
1084
|
+
* @param requiredParams - Required parameter names in the request body
|
|
1085
|
+
* @param requiredHeaders - Required header names (case-insensitive)
|
|
1086
|
+
* @param action - User-defined action function that receives:
|
|
1087
|
+
* - params: All request parameters including __ow_* runtime parameters
|
|
1088
|
+
* - ctx: Context object with logger and headers
|
|
1089
|
+
* @returns Wrapped action function ready to be exported as Adobe I/O Runtime entrypoint
|
|
1090
|
+
*
|
|
1091
|
+
* @example With All Options
|
|
1092
|
+
* ```typescript
|
|
1093
|
+
* const handler = RuntimeAction.execute(
|
|
1094
|
+
* 'processOrder',
|
|
1095
|
+
* [HttpMethod.POST],
|
|
1096
|
+
* ['orderId', 'customerId'],
|
|
1097
|
+
* ['authorization', 'x-api-key'],
|
|
1098
|
+
* async (params, { logger, headers }) => {
|
|
1099
|
+
* const { orderId, customerId } = params;
|
|
1100
|
+
* logger.info({ message: 'Processing order', orderId, customerId });
|
|
1101
|
+
*
|
|
1102
|
+
* // Your business logic here
|
|
1103
|
+
* const result = await processOrderLogic(orderId, customerId);
|
|
1104
|
+
*
|
|
1105
|
+
* return {
|
|
1106
|
+
* statusCode: 200,
|
|
1107
|
+
* body: { orderId, status: 'processed', result }
|
|
1108
|
+
* };
|
|
1109
|
+
* }
|
|
1110
|
+
* );
|
|
1111
|
+
* ```
|
|
1112
|
+
*
|
|
1113
|
+
* @example Minimal Configuration
|
|
1114
|
+
* ```typescript
|
|
1115
|
+
* const handler = RuntimeAction.execute('simpleAction', [], [], [], async (params, { logger }) => {
|
|
1116
|
+
* logger.info('Simple action executed');
|
|
1117
|
+
* return { statusCode: 200, body: { message: 'Success' } };
|
|
1118
|
+
* });
|
|
1119
|
+
* ```
|
|
165
1120
|
*/
|
|
166
1121
|
static execute(name = "main", httpMethods = [], requiredParams = [], requiredHeaders = [], action = async (_params) => {
|
|
167
1122
|
return { statusCode: 200 /* OK */, body: {} };
|
|
168
1123
|
}) {
|
|
169
|
-
|
|
170
|
-
|
|
1124
|
+
const runtimeAction = /* @__PURE__ */ __name(async (params) => {
|
|
1125
|
+
if (!params.action_type) {
|
|
1126
|
+
params.action_type = _RuntimeAction.getActionType();
|
|
1127
|
+
}
|
|
1128
|
+
const logger = telemetry_default.createLogger(name, params);
|
|
171
1129
|
try {
|
|
172
|
-
logger.
|
|
173
|
-
|
|
1130
|
+
logger.debug({
|
|
1131
|
+
message: `${name}-started`,
|
|
1132
|
+
action_name: name
|
|
1133
|
+
});
|
|
1134
|
+
logger.debug({
|
|
1135
|
+
message: `${name}-headers`,
|
|
1136
|
+
headers: params.__ow_headers || {}
|
|
1137
|
+
});
|
|
1138
|
+
logger.debug({
|
|
1139
|
+
message: `${name}-body`,
|
|
1140
|
+
body: params.__ow_body || {}
|
|
1141
|
+
});
|
|
174
1142
|
const validationError = _RuntimeAction.validateRequest(
|
|
175
1143
|
params,
|
|
176
1144
|
requiredParams,
|
|
177
1145
|
requiredHeaders,
|
|
178
1146
|
httpMethods,
|
|
179
|
-
logger
|
|
1147
|
+
logger,
|
|
1148
|
+
name
|
|
180
1149
|
);
|
|
181
1150
|
if (validationError) {
|
|
182
1151
|
return validationError;
|
|
183
1152
|
}
|
|
184
1153
|
const result = await action(params, { logger, headers: params.__ow_headers || {} });
|
|
185
|
-
logger.
|
|
1154
|
+
logger.debug({
|
|
1155
|
+
message: `${name}-completed`,
|
|
1156
|
+
result
|
|
1157
|
+
});
|
|
186
1158
|
return result;
|
|
187
1159
|
} catch (error) {
|
|
188
|
-
|
|
1160
|
+
if (error instanceof Error) {
|
|
1161
|
+
logger.error({
|
|
1162
|
+
message: `${name}-failed`,
|
|
1163
|
+
error: error.message,
|
|
1164
|
+
stack: error.stack
|
|
1165
|
+
});
|
|
1166
|
+
} else {
|
|
1167
|
+
logger.error({
|
|
1168
|
+
message: `${name}-failed`,
|
|
1169
|
+
error
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
189
1172
|
return response_default.error(500 /* INTERNAL_ERROR */, "server error");
|
|
190
1173
|
}
|
|
191
|
-
};
|
|
1174
|
+
}, "runtimeAction");
|
|
1175
|
+
return telemetry_default.initialize(runtimeAction);
|
|
192
1176
|
}
|
|
193
|
-
|
|
1177
|
+
/**
|
|
1178
|
+
* Validates incoming request against required parameters, headers, and HTTP methods
|
|
1179
|
+
*
|
|
1180
|
+
* This private method performs comprehensive request validation:
|
|
1181
|
+
* 1. Checks for missing required parameters in the request body
|
|
1182
|
+
* 2. Checks for missing required headers (case-insensitive)
|
|
1183
|
+
* 3. Validates the HTTP method against allowed methods list
|
|
1184
|
+
*
|
|
1185
|
+
* @param params - Request parameters including __ow_* runtime parameters
|
|
1186
|
+
* @param requiredParams - List of required parameter names to validate
|
|
1187
|
+
* @param requiredHeaders - List of required header names to validate (case-insensitive)
|
|
1188
|
+
* @param httpMethods - Allowed HTTP methods. Empty array skips HTTP method validation
|
|
1189
|
+
* @param logger - Logger instance for error logging (child logger with request ID if present)
|
|
1190
|
+
* @param name - Action name for logging
|
|
1191
|
+
* @returns RuntimeActionResponseType with error details if validation fails, null if valid
|
|
1192
|
+
*
|
|
1193
|
+
* @private
|
|
1194
|
+
*
|
|
1195
|
+
* @example Validation Error Response
|
|
1196
|
+
* ```typescript
|
|
1197
|
+
* // Missing parameter returns:
|
|
1198
|
+
* {
|
|
1199
|
+
* statusCode: 400,
|
|
1200
|
+
* body: { error: 'Missing required parameter: userId' }
|
|
1201
|
+
* }
|
|
1202
|
+
*
|
|
1203
|
+
* // Invalid HTTP method returns:
|
|
1204
|
+
* {
|
|
1205
|
+
* statusCode: 405,
|
|
1206
|
+
* body: { error: 'Invalid HTTP method: DELETE. Allowed methods are: GET, POST' }
|
|
1207
|
+
* }
|
|
1208
|
+
* ```
|
|
1209
|
+
*/
|
|
1210
|
+
static validateRequest(params, requiredParams, requiredHeaders, httpMethods, logger, name) {
|
|
194
1211
|
const errorMessage = validator_default.checkMissingRequestInputs(params, requiredParams, requiredHeaders) ?? "";
|
|
195
1212
|
if (errorMessage) {
|
|
1213
|
+
logger.error({
|
|
1214
|
+
message: `${name}-validation-failed`,
|
|
1215
|
+
error: errorMessage
|
|
1216
|
+
});
|
|
196
1217
|
return response_default.error(400 /* BAD_REQUEST */, errorMessage);
|
|
197
1218
|
}
|
|
198
1219
|
const requestMethod = params.__ow_method?.toUpperCase();
|
|
199
1220
|
if (httpMethods.length > 0 && !httpMethods.includes(requestMethod)) {
|
|
200
1221
|
const errorMessage2 = `Invalid HTTP method: ${params.__ow_method}. Allowed methods are: ${httpMethods.join(", ")}`;
|
|
201
|
-
logger.error(
|
|
1222
|
+
logger.error({
|
|
1223
|
+
message: `${name}-validation-failed`,
|
|
1224
|
+
error: errorMessage2
|
|
1225
|
+
});
|
|
202
1226
|
return response_default.error(405 /* METHOD_NOT_ALLOWED */, errorMessage2);
|
|
203
1227
|
}
|
|
204
1228
|
return null;
|
|
205
1229
|
}
|
|
206
1230
|
};
|
|
207
1231
|
__name(_RuntimeAction, "RuntimeAction");
|
|
1232
|
+
/**
|
|
1233
|
+
* Private static property to store the action type for logging
|
|
1234
|
+
* Can be set using setActionType() before calling execute()
|
|
1235
|
+
*/
|
|
1236
|
+
_RuntimeAction.actionType = "runtime-action";
|
|
208
1237
|
var RuntimeAction = _RuntimeAction;
|
|
209
1238
|
var runtime_action_default = RuntimeAction;
|
|
210
1239
|
|
|
1240
|
+
// src/framework/runtime-action/response/types.ts
|
|
1241
|
+
init_esm_shims();
|
|
1242
|
+
|
|
1243
|
+
// src/framework/runtime-action/parameters/index.ts
|
|
1244
|
+
init_esm_shims();
|
|
1245
|
+
var _Parameters = class _Parameters {
|
|
1246
|
+
/**
|
|
1247
|
+
* Returns a log-ready string of the action input parameters.
|
|
1248
|
+
* The `Authorization` header content will be replaced by '<hidden>'.
|
|
1249
|
+
*
|
|
1250
|
+
* @param params action input parameters.
|
|
1251
|
+
*
|
|
1252
|
+
* @returns string
|
|
1253
|
+
*/
|
|
1254
|
+
static stringify(params) {
|
|
1255
|
+
let headers = params.__ow_headers || {};
|
|
1256
|
+
if (headers.authorization) {
|
|
1257
|
+
headers = { ...headers, authorization: "<hidden>" };
|
|
1258
|
+
}
|
|
1259
|
+
return JSON.stringify({ ...params, __ow_headers: headers });
|
|
1260
|
+
}
|
|
1261
|
+
};
|
|
1262
|
+
__name(_Parameters, "Parameters");
|
|
1263
|
+
var Parameters = _Parameters;
|
|
1264
|
+
var parameters_default = Parameters;
|
|
1265
|
+
|
|
211
1266
|
// src/framework/event-consumer-action/index.ts
|
|
212
|
-
|
|
1267
|
+
init_esm_shims();
|
|
213
1268
|
var _EventConsumerAction = class _EventConsumerAction {
|
|
214
1269
|
/**
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
1270
|
+
* Creates an event consumer action handler with telemetry integration
|
|
1271
|
+
*
|
|
1272
|
+
* This method wraps a user-defined action with:
|
|
1273
|
+
* - Structured logging (all logs automatically include x-adobe-commerce-request-id if present)
|
|
1274
|
+
* - Request validation for required parameters and headers
|
|
1275
|
+
* - OpenTelemetry instrumentation
|
|
1276
|
+
* - Standardized error handling
|
|
1277
|
+
*
|
|
1278
|
+
* @param name - Action name for logging and observability
|
|
1279
|
+
* @param requiredParams - List of required parameter names to validate
|
|
1280
|
+
* @param requiredHeaders - List of required header names to validate (case-insensitive)
|
|
1281
|
+
* @param action - User's event consumer function that receives params and context
|
|
1282
|
+
* @returns Wrapped action handler ready for OpenWhisk runtime
|
|
1283
|
+
*
|
|
1284
|
+
* @example
|
|
1285
|
+
* ```typescript
|
|
1286
|
+
* const handler = EventConsumerAction.execute(
|
|
1287
|
+
* 'webhook-processor',
|
|
1288
|
+
* ['eventType', 'eventData'],
|
|
1289
|
+
* ['x-webhook-signature'],
|
|
1290
|
+
* async (params, { logger, headers }) => {
|
|
1291
|
+
* logger.info({
|
|
1292
|
+
* message: 'Processing webhook',
|
|
1293
|
+
* eventType: params.eventType
|
|
1294
|
+
* });
|
|
1295
|
+
* // Process event...
|
|
1296
|
+
* return { statusCode: 200, body: { processed: true } };
|
|
1297
|
+
* }
|
|
1298
|
+
* );
|
|
1299
|
+
* ```
|
|
220
1300
|
*/
|
|
221
1301
|
static execute(name = "main", requiredParams = [], requiredHeaders = [], action = async (_params) => {
|
|
222
1302
|
return { statusCode: 200 /* OK */, body: {} };
|
|
223
1303
|
}) {
|
|
224
|
-
|
|
225
|
-
|
|
1304
|
+
const eventConsumerAction = /* @__PURE__ */ __name(async (params) => {
|
|
1305
|
+
params.action_type = "event-consumer-action";
|
|
1306
|
+
const logger = telemetry_default.createLogger(name, params);
|
|
226
1307
|
try {
|
|
227
|
-
logger.
|
|
228
|
-
|
|
1308
|
+
logger.debug({
|
|
1309
|
+
message: `${name}-started`,
|
|
1310
|
+
action_name: name
|
|
1311
|
+
});
|
|
1312
|
+
logger.debug({
|
|
1313
|
+
message: `${name}-headers`,
|
|
1314
|
+
headers: params.__ow_headers || {}
|
|
1315
|
+
});
|
|
1316
|
+
logger.debug({
|
|
1317
|
+
message: `${name}-parameters`,
|
|
1318
|
+
parameters: params
|
|
1319
|
+
});
|
|
229
1320
|
const errorMessage = validator_default.checkMissingRequestInputs(params, requiredParams, requiredHeaders) || "";
|
|
230
1321
|
if (errorMessage) {
|
|
1322
|
+
logger.error({
|
|
1323
|
+
message: `${name}-validation-failed`,
|
|
1324
|
+
error: errorMessage
|
|
1325
|
+
});
|
|
231
1326
|
return response_default.error(400 /* BAD_REQUEST */, errorMessage);
|
|
232
1327
|
}
|
|
233
1328
|
const result = await action(params, { logger, headers: params.__ow_headers || {} });
|
|
234
|
-
logger.
|
|
1329
|
+
logger.debug({
|
|
1330
|
+
message: `${name}-completed`,
|
|
1331
|
+
result
|
|
1332
|
+
});
|
|
235
1333
|
return result;
|
|
236
1334
|
} catch (error) {
|
|
237
|
-
|
|
1335
|
+
if (error instanceof Error) {
|
|
1336
|
+
logger.error({
|
|
1337
|
+
error: error.message,
|
|
1338
|
+
stack: error.stack
|
|
1339
|
+
});
|
|
1340
|
+
} else {
|
|
1341
|
+
logger.error({ error });
|
|
1342
|
+
}
|
|
238
1343
|
return response_default.error(500 /* INTERNAL_ERROR */, "server error");
|
|
239
1344
|
}
|
|
240
|
-
};
|
|
1345
|
+
}, "eventConsumerAction");
|
|
1346
|
+
return telemetry_default.initialize(eventConsumerAction);
|
|
241
1347
|
}
|
|
242
1348
|
};
|
|
243
1349
|
__name(_EventConsumerAction, "EventConsumerAction");
|
|
@@ -245,6 +1351,7 @@ var EventConsumerAction = _EventConsumerAction;
|
|
|
245
1351
|
var event_consumer_action_default = EventConsumerAction;
|
|
246
1352
|
|
|
247
1353
|
// src/framework/graphql-action/index.ts
|
|
1354
|
+
init_esm_shims();
|
|
248
1355
|
import { graphql, buildSchema, parse, validate } from "graphql";
|
|
249
1356
|
var _GraphQlAction = class _GraphQlAction {
|
|
250
1357
|
static execute(schema = `
|
|
@@ -322,6 +1429,7 @@ var GraphQlAction = _GraphQlAction;
|
|
|
322
1429
|
var graphql_action_default = GraphQlAction;
|
|
323
1430
|
|
|
324
1431
|
// src/framework/openwhisk/index.ts
|
|
1432
|
+
init_esm_shims();
|
|
325
1433
|
import openwhisk from "openwhisk";
|
|
326
1434
|
var _Openwhisk = class _Openwhisk {
|
|
327
1435
|
/**
|
|
@@ -349,29 +1457,84 @@ var Openwhisk = _Openwhisk;
|
|
|
349
1457
|
var openwhisk_default = Openwhisk;
|
|
350
1458
|
|
|
351
1459
|
// src/framework/openwhisk-action/index.ts
|
|
352
|
-
|
|
1460
|
+
init_esm_shims();
|
|
353
1461
|
var _OpenwhiskAction = class _OpenwhiskAction {
|
|
354
1462
|
/**
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
1463
|
+
* Creates an OpenWhisk webhook action handler with logging and telemetry
|
|
1464
|
+
*
|
|
1465
|
+
* Wraps a user-defined action function with standardized runtime functionality:
|
|
1466
|
+
* 1. Creates a structured logger with telemetry integration
|
|
1467
|
+
* 2. Logs action start with structured data
|
|
1468
|
+
* 3. Logs request parameters at debug level
|
|
1469
|
+
* 4. Executes the user action with logger and headers context
|
|
1470
|
+
* 5. Logs the result and handles errors with appropriate status codes
|
|
1471
|
+
* 6. Integrates with OpenTelemetry for distributed tracing
|
|
1472
|
+
*
|
|
1473
|
+
* The logger automatically includes x-adobe-commerce-request-id and action.type
|
|
1474
|
+
* (if present) in all log messages.
|
|
1475
|
+
*
|
|
1476
|
+
* @param name - Action name used for logging and telemetry spans (default: 'main')
|
|
1477
|
+
* @param action - User-defined action function that receives:
|
|
1478
|
+
* - params: All request parameters including __ow_* runtime parameters
|
|
1479
|
+
* - ctx: Context object with logger and headers
|
|
1480
|
+
* @returns Wrapped action function ready to be exported as Adobe I/O Runtime entrypoint
|
|
1481
|
+
*
|
|
1482
|
+
* @example Complete Example
|
|
1483
|
+
* ```typescript
|
|
1484
|
+
* const handler = OpenwhiskAction.execute(
|
|
1485
|
+
* 'processWebhook',
|
|
1486
|
+
* async (params, { logger, headers }) => {
|
|
1487
|
+
* logger.info({ message: 'Webhook received', event: params.event });
|
|
1488
|
+
*
|
|
1489
|
+
* // Your webhook processing logic here
|
|
1490
|
+
* const result = await processWebhookData(params);
|
|
1491
|
+
*
|
|
1492
|
+
* return {
|
|
1493
|
+
* statusCode: 200,
|
|
1494
|
+
* body: { status: 'processed', result }
|
|
1495
|
+
* };
|
|
1496
|
+
* }
|
|
1497
|
+
* );
|
|
1498
|
+
* ```
|
|
358
1499
|
*/
|
|
359
1500
|
static execute(name = "main", action = async (_params) => {
|
|
360
1501
|
return { statusCode: 200 /* OK */, body: {} };
|
|
361
1502
|
}) {
|
|
362
|
-
|
|
363
|
-
|
|
1503
|
+
const openwhiskAction = /* @__PURE__ */ __name(async (params) => {
|
|
1504
|
+
params.action_type = "openwhisk-action";
|
|
1505
|
+
const logger = telemetry_default.createLogger(name, params);
|
|
364
1506
|
try {
|
|
365
|
-
logger.
|
|
366
|
-
|
|
1507
|
+
logger.debug({
|
|
1508
|
+
message: `${name}-started`,
|
|
1509
|
+
action_name: name
|
|
1510
|
+
});
|
|
1511
|
+
logger.debug({
|
|
1512
|
+
message: `${name}-params`,
|
|
1513
|
+
params
|
|
1514
|
+
});
|
|
367
1515
|
const result = await action(params, { logger, headers: params.__ow_headers || {} });
|
|
368
|
-
logger.
|
|
1516
|
+
logger.debug({
|
|
1517
|
+
message: `${name}-completed`,
|
|
1518
|
+
result
|
|
1519
|
+
});
|
|
369
1520
|
return result;
|
|
370
1521
|
} catch (error) {
|
|
371
|
-
|
|
1522
|
+
if (error instanceof Error) {
|
|
1523
|
+
logger.error({
|
|
1524
|
+
message: `${name}-failed`,
|
|
1525
|
+
error: error.message,
|
|
1526
|
+
stack: error.stack
|
|
1527
|
+
});
|
|
1528
|
+
} else {
|
|
1529
|
+
logger.error({
|
|
1530
|
+
message: `${name}-failed`,
|
|
1531
|
+
error
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
372
1534
|
return response_default.error(500 /* INTERNAL_ERROR */, "server error");
|
|
373
1535
|
}
|
|
374
|
-
};
|
|
1536
|
+
}, "openwhiskAction");
|
|
1537
|
+
return telemetry_default.initialize(openwhiskAction);
|
|
375
1538
|
}
|
|
376
1539
|
};
|
|
377
1540
|
__name(_OpenwhiskAction, "OpenwhiskAction");
|
|
@@ -379,6 +1542,7 @@ var OpenwhiskAction = _OpenwhiskAction;
|
|
|
379
1542
|
var openwhisk_action_default = OpenwhiskAction;
|
|
380
1543
|
|
|
381
1544
|
// src/framework/repository/file-repository/index.ts
|
|
1545
|
+
init_esm_shims();
|
|
382
1546
|
import { Files } from "@adobe/aio-sdk";
|
|
383
1547
|
var _FileRepository = class _FileRepository {
|
|
384
1548
|
/**
|
|
@@ -535,12 +1699,17 @@ __name(_FileRepository, "FileRepository");
|
|
|
535
1699
|
var FileRepository = _FileRepository;
|
|
536
1700
|
var file_repository_default = FileRepository;
|
|
537
1701
|
|
|
1702
|
+
// src/framework/repository/file-repository/types.ts
|
|
1703
|
+
init_esm_shims();
|
|
1704
|
+
|
|
538
1705
|
// src/framework/publish-event/index.ts
|
|
1706
|
+
init_esm_shims();
|
|
539
1707
|
import { Events } from "@adobe/aio-sdk";
|
|
540
1708
|
import { CloudEvent } from "cloudevents";
|
|
541
1709
|
import { v4 as uuidv4 } from "uuid";
|
|
542
1710
|
|
|
543
1711
|
// src/framework/custom-logger/index.ts
|
|
1712
|
+
init_esm_shims();
|
|
544
1713
|
var _CustomLogger = class _CustomLogger {
|
|
545
1714
|
/**
|
|
546
1715
|
* @param logger - External logger instance (can be null)
|
|
@@ -675,7 +1844,17 @@ __name(_PublishEvent, "PublishEvent");
|
|
|
675
1844
|
var PublishEvent = _PublishEvent;
|
|
676
1845
|
var publish_event_default = PublishEvent;
|
|
677
1846
|
|
|
1847
|
+
// src/framework/publish-event/types.ts
|
|
1848
|
+
init_esm_shims();
|
|
1849
|
+
|
|
1850
|
+
// src/framework/webhook-action/index.ts
|
|
1851
|
+
init_esm_shims();
|
|
1852
|
+
|
|
1853
|
+
// src/framework/webhook-action/response/index.ts
|
|
1854
|
+
init_esm_shims();
|
|
1855
|
+
|
|
678
1856
|
// src/framework/webhook-action/response/types.ts
|
|
1857
|
+
init_esm_shims();
|
|
679
1858
|
var WebhookActionOperation = /* @__PURE__ */ ((WebhookActionOperation2) => {
|
|
680
1859
|
WebhookActionOperation2["SUCCESS"] = "success";
|
|
681
1860
|
WebhookActionOperation2["EXCEPTION"] = "exception";
|
|
@@ -782,10 +1961,10 @@ var _WebhookActionResponse = class _WebhookActionResponse {
|
|
|
782
1961
|
* });
|
|
783
1962
|
* ```
|
|
784
1963
|
*/
|
|
785
|
-
static add(
|
|
1964
|
+
static add(path2, value, instance) {
|
|
786
1965
|
const response = {
|
|
787
1966
|
op: "add" /* ADD */,
|
|
788
|
-
path,
|
|
1967
|
+
path: path2,
|
|
789
1968
|
value
|
|
790
1969
|
};
|
|
791
1970
|
if (instance !== void 0) {
|
|
@@ -821,10 +2000,10 @@ var _WebhookActionResponse = class _WebhookActionResponse {
|
|
|
821
2000
|
* });
|
|
822
2001
|
* ```
|
|
823
2002
|
*/
|
|
824
|
-
static replace(
|
|
2003
|
+
static replace(path2, value, instance) {
|
|
825
2004
|
const response = {
|
|
826
2005
|
op: "replace" /* REPLACE */,
|
|
827
|
-
path,
|
|
2006
|
+
path: path2,
|
|
828
2007
|
value
|
|
829
2008
|
};
|
|
830
2009
|
if (instance !== void 0) {
|
|
@@ -862,10 +2041,10 @@ var _WebhookActionResponse = class _WebhookActionResponse {
|
|
|
862
2041
|
* };
|
|
863
2042
|
* ```
|
|
864
2043
|
*/
|
|
865
|
-
static remove(
|
|
2044
|
+
static remove(path2) {
|
|
866
2045
|
return {
|
|
867
2046
|
op: "remove" /* REMOVE */,
|
|
868
|
-
path
|
|
2047
|
+
path: path2
|
|
869
2048
|
};
|
|
870
2049
|
}
|
|
871
2050
|
};
|
|
@@ -874,6 +2053,7 @@ var WebhookActionResponse = _WebhookActionResponse;
|
|
|
874
2053
|
var response_default2 = WebhookActionResponse;
|
|
875
2054
|
|
|
876
2055
|
// src/framework/webhook-action/types.ts
|
|
2056
|
+
init_esm_shims();
|
|
877
2057
|
var SignatureVerification = /* @__PURE__ */ ((SignatureVerification2) => {
|
|
878
2058
|
SignatureVerification2["ENABLED"] = "enabled";
|
|
879
2059
|
SignatureVerification2["DISABLED"] = "disabled";
|
|
@@ -924,9 +2104,14 @@ var _WebhookAction = class _WebhookAction {
|
|
|
924
2104
|
return null;
|
|
925
2105
|
}, "verifySignature");
|
|
926
2106
|
const callback = /* @__PURE__ */ __name(async (params, ctx) => {
|
|
2107
|
+
const { logger } = ctx;
|
|
927
2108
|
if (signatureVerification === "enabled" /* ENABLED */) {
|
|
928
2109
|
const verificationErrorMessage = await verifySignature(params);
|
|
929
2110
|
if (verificationErrorMessage) {
|
|
2111
|
+
logger.error({
|
|
2112
|
+
message: `${name}-signature-verification-failed`,
|
|
2113
|
+
error: verificationErrorMessage
|
|
2114
|
+
});
|
|
930
2115
|
const verificationErrorResponse = response_default2.exception(verificationErrorMessage);
|
|
931
2116
|
return response_default.success(JSON.stringify(verificationErrorResponse));
|
|
932
2117
|
}
|
|
@@ -937,12 +2122,17 @@ var _WebhookAction = class _WebhookAction {
|
|
|
937
2122
|
}
|
|
938
2123
|
const errorMessage = validator_default.checkMissingRequestInputs(params, requiredParams, requiredHeaders) ?? "";
|
|
939
2124
|
if (errorMessage) {
|
|
2125
|
+
logger.error({
|
|
2126
|
+
message: `${name}-validation-failed`,
|
|
2127
|
+
error: errorMessage
|
|
2128
|
+
});
|
|
940
2129
|
const errorMessageResponse = response_default2.exception(errorMessage);
|
|
941
2130
|
return response_default.success(JSON.stringify(errorMessageResponse));
|
|
942
2131
|
}
|
|
943
2132
|
const response = await action(params, ctx);
|
|
944
2133
|
return response_default.success(JSON.stringify(response));
|
|
945
2134
|
}, "callback");
|
|
2135
|
+
runtime_action_default.setActionType("webhook-action");
|
|
946
2136
|
return runtime_action_default.execute(name, httpMethods, [], [], callback);
|
|
947
2137
|
}
|
|
948
2138
|
};
|
|
@@ -951,10 +2141,12 @@ var WebhookAction = _WebhookAction;
|
|
|
951
2141
|
var webhook_action_default = WebhookAction;
|
|
952
2142
|
|
|
953
2143
|
// src/framework/ims-token/index.ts
|
|
2144
|
+
init_esm_shims();
|
|
954
2145
|
import { State } from "@adobe/aio-sdk";
|
|
955
2146
|
|
|
956
2147
|
// src/commerce/adobe-auth/index.ts
|
|
957
|
-
|
|
2148
|
+
init_esm_shims();
|
|
2149
|
+
import * as aioLibIms from "@adobe/aio-lib-ims";
|
|
958
2150
|
var _AdobeAuth = class _AdobeAuth {
|
|
959
2151
|
/**
|
|
960
2152
|
* Retrieves an authentication token from Adobe IMS
|
|
@@ -987,9 +2179,9 @@ var _AdobeAuth = class _AdobeAuth {
|
|
|
987
2179
|
ims_org_id: imsOrgId,
|
|
988
2180
|
scopes
|
|
989
2181
|
};
|
|
990
|
-
await context.setCurrent(currentContext);
|
|
991
|
-
await context.set(currentContext, config);
|
|
992
|
-
return await getToken();
|
|
2182
|
+
await aioLibIms.context.setCurrent(currentContext);
|
|
2183
|
+
await aioLibIms.context.set(currentContext, config);
|
|
2184
|
+
return await aioLibIms.getToken();
|
|
993
2185
|
}
|
|
994
2186
|
};
|
|
995
2187
|
__name(_AdobeAuth, "AdobeAuth");
|
|
@@ -997,6 +2189,7 @@ var AdobeAuth = _AdobeAuth;
|
|
|
997
2189
|
var adobe_auth_default = AdobeAuth;
|
|
998
2190
|
|
|
999
2191
|
// src/integration/bearer-token/index.ts
|
|
2192
|
+
init_esm_shims();
|
|
1000
2193
|
var _BearerToken = class _BearerToken {
|
|
1001
2194
|
/**
|
|
1002
2195
|
* Extracts the Bearer token from HTTP request headers and returns detailed token information.
|
|
@@ -1145,6 +2338,9 @@ var _ImsToken = class _ImsToken {
|
|
|
1145
2338
|
/**
|
|
1146
2339
|
* Creates an instance of ImsToken
|
|
1147
2340
|
*
|
|
2341
|
+
* @deprecated Use `AdobeAuth.getToken()` directly and implement caching in your application.
|
|
2342
|
+
* See class documentation for migration examples.
|
|
2343
|
+
*
|
|
1148
2344
|
* @param clientId - OAuth client ID for Adobe IMS authentication
|
|
1149
2345
|
* @param clientSecret - OAuth client secret for Adobe IMS authentication
|
|
1150
2346
|
* @param technicalAccountId - Technical account ID for service-to-service authentication
|
|
@@ -1171,6 +2367,10 @@ var _ImsToken = class _ImsToken {
|
|
|
1171
2367
|
/**
|
|
1172
2368
|
* Executes IMS token generation or retrieves a cached token
|
|
1173
2369
|
*
|
|
2370
|
+
* @deprecated Use `AdobeAuth.getToken()` directly and implement caching in your application.
|
|
2371
|
+
* The built-in caching mechanism has reliability issues with the State API.
|
|
2372
|
+
* See class documentation for migration examples.
|
|
2373
|
+
*
|
|
1174
2374
|
* This method first checks for a cached token. If a valid cached token exists,
|
|
1175
2375
|
* it returns that. Otherwise, it generates a new token, caches it, and returns it.
|
|
1176
2376
|
*
|
|
@@ -1253,6 +2453,14 @@ var _ImsToken = class _ImsToken {
|
|
|
1253
2453
|
/**
|
|
1254
2454
|
* Caches the IMS token in the state store with TTL
|
|
1255
2455
|
*
|
|
2456
|
+
* @deprecated This method has issues with State API reliability. Use application-level caching instead.
|
|
2457
|
+
*
|
|
2458
|
+
* **Known Issues:**
|
|
2459
|
+
* - State API may not be available in all runtime environments
|
|
2460
|
+
* - Hard-coded 10-minute buffer may not suit all use cases
|
|
2461
|
+
* - Minimum 60-minute TTL is opinionated and inflexible
|
|
2462
|
+
* - No retry mechanism for State API failures
|
|
2463
|
+
*
|
|
1256
2464
|
* @param result - The token result containing the token and expiration time
|
|
1257
2465
|
* @returns A promise that resolves to true if caching succeeded, false otherwise
|
|
1258
2466
|
* @private
|
|
@@ -1278,6 +2486,13 @@ var _ImsToken = class _ImsToken {
|
|
|
1278
2486
|
/**
|
|
1279
2487
|
* Retrieves a cached IMS token from the state store
|
|
1280
2488
|
*
|
|
2489
|
+
* @deprecated This method has issues with State API reliability. Use application-level caching instead.
|
|
2490
|
+
*
|
|
2491
|
+
* **Known Issues:**
|
|
2492
|
+
* - State API may not be available in all runtime environments
|
|
2493
|
+
* - No validation of cached token expiry
|
|
2494
|
+
* - Silent failures may return null without proper error context
|
|
2495
|
+
*
|
|
1281
2496
|
* @returns A promise that resolves to the cached token string or null if not found
|
|
1282
2497
|
* @private
|
|
1283
2498
|
*/
|
|
@@ -1303,6 +2518,14 @@ var _ImsToken = class _ImsToken {
|
|
|
1303
2518
|
/**
|
|
1304
2519
|
* Initializes and returns the state store instance
|
|
1305
2520
|
*
|
|
2521
|
+
* @deprecated This method relies on State API which has reliability issues.
|
|
2522
|
+
* Use application-level caching instead.
|
|
2523
|
+
*
|
|
2524
|
+
* **Known Issues:**
|
|
2525
|
+
* - State API initialization may fail silently
|
|
2526
|
+
* - Not available outside Adobe I/O Runtime environments
|
|
2527
|
+
* - Caches the state instance which may become stale
|
|
2528
|
+
*
|
|
1306
2529
|
* @returns A promise that resolves to the state instance or null if initialization fails
|
|
1307
2530
|
* @private
|
|
1308
2531
|
*/
|
|
@@ -1323,7 +2546,14 @@ __name(_ImsToken, "ImsToken");
|
|
|
1323
2546
|
var ImsToken = _ImsToken;
|
|
1324
2547
|
var ims_token_default = ImsToken;
|
|
1325
2548
|
|
|
2549
|
+
// src/framework/ims-token/types.ts
|
|
2550
|
+
init_esm_shims();
|
|
2551
|
+
|
|
2552
|
+
// src/framework/runtime-api-gateway-service/index.ts
|
|
2553
|
+
init_esm_shims();
|
|
2554
|
+
|
|
1326
2555
|
// src/integration/rest-client/index.ts
|
|
2556
|
+
init_esm_shims();
|
|
1327
2557
|
import fetch from "node-fetch";
|
|
1328
2558
|
var _RestClient = class _RestClient {
|
|
1329
2559
|
/**
|
|
@@ -1500,44 +2730,26 @@ var _RuntimeApiGatewayService = class _RuntimeApiGatewayService {
|
|
|
1500
2730
|
/**
|
|
1501
2731
|
* Creates an instance of RuntimeApiGatewayService
|
|
1502
2732
|
*
|
|
1503
|
-
* @param clientId - OAuth client ID for Adobe IMS authentication
|
|
1504
|
-
* @param clientSecret - OAuth client secret for Adobe IMS authentication
|
|
1505
|
-
* @param technicalAccountId - Technical account ID for service-to-service authentication
|
|
1506
|
-
* @param technicalAccountEmail - Technical account email for service-to-service authentication
|
|
1507
|
-
* @param imsOrgId - IMS organization ID
|
|
1508
|
-
* @param scopes - Array of scopes required for the token
|
|
1509
2733
|
* @param namespace - The Adobe I/O Runtime namespace identifier
|
|
2734
|
+
* @param imsOrgId - IMS organization ID
|
|
2735
|
+
* @param imsToken - Bearer token string for authentication
|
|
1510
2736
|
* @param logger - Optional logger instance for logging operations
|
|
1511
2737
|
* @example
|
|
1512
2738
|
* ```typescript
|
|
1513
2739
|
* const service = new RuntimeApiGatewayService(
|
|
1514
|
-
* '
|
|
1515
|
-
* '
|
|
1516
|
-
* '
|
|
1517
|
-
*
|
|
1518
|
-
* 'org-id',
|
|
1519
|
-
* ['openid', 'AdobeID'],
|
|
1520
|
-
* 'my-namespace-12345',
|
|
1521
|
-
* logger // optional
|
|
2740
|
+
* 'test-namespace',
|
|
2741
|
+
* 'org-id@AdobeOrg',
|
|
2742
|
+
* 'bearer-token-string',
|
|
2743
|
+
* logger
|
|
1522
2744
|
* );
|
|
1523
2745
|
* ```
|
|
1524
2746
|
*/
|
|
1525
|
-
constructor(
|
|
2747
|
+
constructor(namespace, imsOrgId, imsToken, logger = null) {
|
|
1526
2748
|
this.namespace = namespace;
|
|
1527
2749
|
this.imsOrgId = imsOrgId;
|
|
1528
|
-
this.
|
|
1529
|
-
this.imsToken = new ims_token_default(
|
|
1530
|
-
clientId,
|
|
1531
|
-
clientSecret,
|
|
1532
|
-
technicalAccountId,
|
|
1533
|
-
technicalAccountEmail,
|
|
1534
|
-
imsOrgId,
|
|
1535
|
-
scopes,
|
|
1536
|
-
logger,
|
|
1537
|
-
"runtime_api_gateway_token",
|
|
1538
|
-
"runtime-api-gateway-context"
|
|
1539
|
-
);
|
|
2750
|
+
this.imsToken = imsToken;
|
|
1540
2751
|
this.restClient = new rest_client_default();
|
|
2752
|
+
this.customLogger = new custom_logger_default(logger);
|
|
1541
2753
|
}
|
|
1542
2754
|
/**
|
|
1543
2755
|
* Builds the complete API endpoint URL
|
|
@@ -1552,21 +2764,13 @@ var _RuntimeApiGatewayService = class _RuntimeApiGatewayService {
|
|
|
1552
2764
|
/**
|
|
1553
2765
|
* Gets the authenticated headers for API requests
|
|
1554
2766
|
*
|
|
1555
|
-
* @returns
|
|
1556
|
-
* @throws {Error} If token generation fails
|
|
2767
|
+
* @returns Headers object including authentication
|
|
1557
2768
|
* @private
|
|
1558
2769
|
*/
|
|
1559
|
-
|
|
1560
|
-
this.customLogger.debug("Generating authenticated headers for API request");
|
|
1561
|
-
const token = await this.imsToken.execute();
|
|
1562
|
-
if (!token) {
|
|
1563
|
-
this.customLogger.error("Failed to generate IMS token for authenticated headers");
|
|
1564
|
-
throw new Error("Failed to generate IMS token");
|
|
1565
|
-
}
|
|
1566
|
-
this.customLogger.debug("Successfully generated authenticated headers");
|
|
2770
|
+
getAuthenticatedHeaders() {
|
|
1567
2771
|
return {
|
|
1568
2772
|
"Content-Type": "application/json",
|
|
1569
|
-
Authorization: `Bearer ${
|
|
2773
|
+
Authorization: `Bearer ${this.imsToken}`,
|
|
1570
2774
|
"x-gw-ims-org-id": this.imsOrgId
|
|
1571
2775
|
};
|
|
1572
2776
|
}
|
|
@@ -1590,7 +2794,7 @@ var _RuntimeApiGatewayService = class _RuntimeApiGatewayService {
|
|
|
1590
2794
|
try {
|
|
1591
2795
|
const url = this.buildEndpoint(endpoint);
|
|
1592
2796
|
this.customLogger.info(`Performing GET request to: ${url}`);
|
|
1593
|
-
const headers = { ...
|
|
2797
|
+
const headers = { ...this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1594
2798
|
this.customLogger.debug(`GET headers: ${JSON.stringify(headers)}`);
|
|
1595
2799
|
const response = await this.restClient.get(url, headers, false);
|
|
1596
2800
|
this.customLogger.debug(`GET response: ${JSON.stringify(response)}`);
|
|
@@ -1624,7 +2828,7 @@ var _RuntimeApiGatewayService = class _RuntimeApiGatewayService {
|
|
|
1624
2828
|
const url = this.buildEndpoint(endpoint);
|
|
1625
2829
|
this.customLogger.info(`Performing POST request to: ${url}`);
|
|
1626
2830
|
this.customLogger.debug(`POST payload: ${JSON.stringify(payload)}`);
|
|
1627
|
-
const headers = { ...
|
|
2831
|
+
const headers = { ...this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1628
2832
|
this.customLogger.debug(`POST headers: ${JSON.stringify(headers)}`);
|
|
1629
2833
|
const response = await this.restClient.post(url, headers, payload, false);
|
|
1630
2834
|
this.customLogger.debug(`POST response: ${JSON.stringify(response)}`);
|
|
@@ -1658,7 +2862,7 @@ var _RuntimeApiGatewayService = class _RuntimeApiGatewayService {
|
|
|
1658
2862
|
const url = this.buildEndpoint(endpoint);
|
|
1659
2863
|
this.customLogger.info(`Performing PUT request to: ${url}`);
|
|
1660
2864
|
this.customLogger.debug(`PUT payload: ${JSON.stringify(payload)}`);
|
|
1661
|
-
const headers = { ...
|
|
2865
|
+
const headers = { ...this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1662
2866
|
this.customLogger.debug(`PUT headers: ${JSON.stringify(headers)}`);
|
|
1663
2867
|
const response = await this.restClient.put(url, headers, payload, false);
|
|
1664
2868
|
this.customLogger.debug(`PUT response: ${JSON.stringify(response)}`);
|
|
@@ -1690,7 +2894,7 @@ var _RuntimeApiGatewayService = class _RuntimeApiGatewayService {
|
|
|
1690
2894
|
try {
|
|
1691
2895
|
const url = this.buildEndpoint(endpoint);
|
|
1692
2896
|
this.customLogger.info(`Performing DELETE request to: ${url}`);
|
|
1693
|
-
const headers = { ...
|
|
2897
|
+
const headers = { ...this.getAuthenticatedHeaders(), ...additionalHeaders };
|
|
1694
2898
|
this.customLogger.debug(`DELETE headers: ${JSON.stringify(headers)}`);
|
|
1695
2899
|
const response = await this.restClient.delete(url, headers, false);
|
|
1696
2900
|
this.customLogger.debug(`DELETE response: ${JSON.stringify(response)}`);
|
|
@@ -1708,10 +2912,35 @@ __name(_RuntimeApiGatewayService, "RuntimeApiGatewayService");
|
|
|
1708
2912
|
_RuntimeApiGatewayService.BASE_URL = "https://adobeioruntime.net/apis";
|
|
1709
2913
|
var RuntimeApiGatewayService = _RuntimeApiGatewayService;
|
|
1710
2914
|
|
|
2915
|
+
// src/framework/telemetry/types.ts
|
|
2916
|
+
init_esm_shims();
|
|
2917
|
+
|
|
2918
|
+
// src/framework/index.ts
|
|
2919
|
+
init_input_error();
|
|
2920
|
+
init_success_checker();
|
|
2921
|
+
init_json_message_processor();
|
|
2922
|
+
|
|
2923
|
+
// src/integration/index.ts
|
|
2924
|
+
init_esm_shims();
|
|
2925
|
+
|
|
1711
2926
|
// src/integration/onboard-events/index.ts
|
|
1712
|
-
|
|
2927
|
+
init_esm_shims();
|
|
2928
|
+
import { Core as Core2 } from "@adobe/aio-sdk";
|
|
2929
|
+
|
|
2930
|
+
// src/integration/onboard-events/create-providers/index.ts
|
|
2931
|
+
init_esm_shims();
|
|
2932
|
+
|
|
2933
|
+
// src/io-events/index.ts
|
|
2934
|
+
init_esm_shims();
|
|
2935
|
+
|
|
2936
|
+
// src/io-events/provider/index.ts
|
|
2937
|
+
init_esm_shims();
|
|
2938
|
+
|
|
2939
|
+
// src/io-events/provider/list/index.ts
|
|
2940
|
+
init_esm_shims();
|
|
1713
2941
|
|
|
1714
2942
|
// src/io-events/types.ts
|
|
2943
|
+
init_esm_shims();
|
|
1715
2944
|
var IoEventsGlobals = {
|
|
1716
2945
|
BASE_URL: "https://api.adobe.io",
|
|
1717
2946
|
STATUS_CODES: {
|
|
@@ -1948,6 +3177,7 @@ var List = _List;
|
|
|
1948
3177
|
var list_default = List;
|
|
1949
3178
|
|
|
1950
3179
|
// src/io-events/provider/get/index.ts
|
|
3180
|
+
init_esm_shims();
|
|
1951
3181
|
var _Get = class _Get {
|
|
1952
3182
|
/**
|
|
1953
3183
|
* Constructor for Get provider service
|
|
@@ -2124,6 +3354,7 @@ var Get = _Get;
|
|
|
2124
3354
|
var get_default = Get;
|
|
2125
3355
|
|
|
2126
3356
|
// src/io-events/provider/create/index.ts
|
|
3357
|
+
init_esm_shims();
|
|
2127
3358
|
var _Create = class _Create {
|
|
2128
3359
|
/**
|
|
2129
3360
|
* Constructor for Create provider service
|
|
@@ -2291,6 +3522,7 @@ var Create = _Create;
|
|
|
2291
3522
|
var create_default = Create;
|
|
2292
3523
|
|
|
2293
3524
|
// src/io-events/provider/delete/index.ts
|
|
3525
|
+
init_esm_shims();
|
|
2294
3526
|
var _Delete = class _Delete {
|
|
2295
3527
|
/**
|
|
2296
3528
|
* Creates an instance of Delete service
|
|
@@ -2617,7 +3849,11 @@ __name(_ProviderManager, "ProviderManager");
|
|
|
2617
3849
|
var ProviderManager = _ProviderManager;
|
|
2618
3850
|
var provider_default = ProviderManager;
|
|
2619
3851
|
|
|
3852
|
+
// src/io-events/event-metadata/index.ts
|
|
3853
|
+
init_esm_shims();
|
|
3854
|
+
|
|
2620
3855
|
// src/io-events/event-metadata/list/index.ts
|
|
3856
|
+
init_esm_shims();
|
|
2621
3857
|
var _List2 = class _List2 {
|
|
2622
3858
|
/**
|
|
2623
3859
|
* Creates an instance of List service
|
|
@@ -2808,6 +4044,7 @@ __name(_List2, "List");
|
|
|
2808
4044
|
var List2 = _List2;
|
|
2809
4045
|
|
|
2810
4046
|
// src/io-events/event-metadata/get/index.ts
|
|
4047
|
+
init_esm_shims();
|
|
2811
4048
|
var _Get2 = class _Get2 {
|
|
2812
4049
|
/**
|
|
2813
4050
|
* Creates an instance of Get service
|
|
@@ -2978,6 +4215,7 @@ __name(_Get2, "Get");
|
|
|
2978
4215
|
var Get2 = _Get2;
|
|
2979
4216
|
|
|
2980
4217
|
// src/io-events/event-metadata/create/index.ts
|
|
4218
|
+
init_esm_shims();
|
|
2981
4219
|
var _Create2 = class _Create2 {
|
|
2982
4220
|
/**
|
|
2983
4221
|
* Constructor for Create event metadata service
|
|
@@ -3242,6 +4480,7 @@ var Create2 = _Create2;
|
|
|
3242
4480
|
var create_default2 = Create2;
|
|
3243
4481
|
|
|
3244
4482
|
// src/io-events/event-metadata/delete/index.ts
|
|
4483
|
+
init_esm_shims();
|
|
3245
4484
|
var _Delete2 = class _Delete2 {
|
|
3246
4485
|
/**
|
|
3247
4486
|
* Constructor for Delete event metadata service
|
|
@@ -3551,7 +4790,11 @@ __name(_EventMetadataManager, "EventMetadataManager");
|
|
|
3551
4790
|
var EventMetadataManager = _EventMetadataManager;
|
|
3552
4791
|
var event_metadata_default = EventMetadataManager;
|
|
3553
4792
|
|
|
4793
|
+
// src/io-events/registration/index.ts
|
|
4794
|
+
init_esm_shims();
|
|
4795
|
+
|
|
3554
4796
|
// src/io-events/registration/create/index.ts
|
|
4797
|
+
init_esm_shims();
|
|
3555
4798
|
var _Create3 = class _Create3 {
|
|
3556
4799
|
/**
|
|
3557
4800
|
* Initialize the Create service
|
|
@@ -3736,6 +4979,7 @@ var Create3 = _Create3;
|
|
|
3736
4979
|
var create_default3 = Create3;
|
|
3737
4980
|
|
|
3738
4981
|
// src/io-events/registration/delete/index.ts
|
|
4982
|
+
init_esm_shims();
|
|
3739
4983
|
var _Delete3 = class _Delete3 {
|
|
3740
4984
|
/**
|
|
3741
4985
|
* Initialize the Delete service
|
|
@@ -3854,6 +5098,7 @@ var Delete3 = _Delete3;
|
|
|
3854
5098
|
var delete_default2 = Delete3;
|
|
3855
5099
|
|
|
3856
5100
|
// src/io-events/registration/get/index.ts
|
|
5101
|
+
init_esm_shims();
|
|
3857
5102
|
var _Get3 = class _Get3 {
|
|
3858
5103
|
/**
|
|
3859
5104
|
* Initialize the Get service
|
|
@@ -3973,6 +5218,7 @@ var Get3 = _Get3;
|
|
|
3973
5218
|
var get_default2 = Get3;
|
|
3974
5219
|
|
|
3975
5220
|
// src/io-events/registration/list/index.ts
|
|
5221
|
+
init_esm_shims();
|
|
3976
5222
|
var _List3 = class _List3 {
|
|
3977
5223
|
/**
|
|
3978
5224
|
* Initialize the List service
|
|
@@ -4436,6 +5682,7 @@ var CreateProviders = _CreateProviders;
|
|
|
4436
5682
|
var create_providers_default = CreateProviders;
|
|
4437
5683
|
|
|
4438
5684
|
// src/integration/onboard-events/create-events/index.ts
|
|
5685
|
+
init_esm_shims();
|
|
4439
5686
|
var _CreateEvents = class _CreateEvents {
|
|
4440
5687
|
/**
|
|
4441
5688
|
* Creates a new CreateEvents instance
|
|
@@ -4651,6 +5898,7 @@ var CreateEvents = _CreateEvents;
|
|
|
4651
5898
|
var create_events_default = CreateEvents;
|
|
4652
5899
|
|
|
4653
5900
|
// src/integration/onboard-events/create-registrations/index.ts
|
|
5901
|
+
init_esm_shims();
|
|
4654
5902
|
var _CreateRegistrations = class _CreateRegistrations {
|
|
4655
5903
|
/**
|
|
4656
5904
|
* Creates a new CreateRegistrations instance
|
|
@@ -4924,6 +6172,7 @@ var CreateRegistrations = _CreateRegistrations;
|
|
|
4924
6172
|
var create_registrations_default = CreateRegistrations;
|
|
4925
6173
|
|
|
4926
6174
|
// src/integration/onboard-events/input-parser/index.ts
|
|
6175
|
+
init_esm_shims();
|
|
4927
6176
|
var _InputParser = class _InputParser {
|
|
4928
6177
|
constructor(input) {
|
|
4929
6178
|
this.entities = {
|
|
@@ -5022,7 +6271,7 @@ var _OnboardEvents = class _OnboardEvents {
|
|
|
5022
6271
|
throw new Error("Access token is required");
|
|
5023
6272
|
}
|
|
5024
6273
|
const loggerName = projectName.toLowerCase().replace(/[^a-z0-9\s-_]/g, "").replace(/\s+/g, "-").replace(/_{2,}/g, "_").replace(/-{2,}/g, "-").trim().concat("-onboard-events");
|
|
5025
|
-
this.logger =
|
|
6274
|
+
this.logger = Core2.Logger(loggerName, { level: "debug" });
|
|
5026
6275
|
this.createProviders = new create_providers_default(
|
|
5027
6276
|
consumerId,
|
|
5028
6277
|
projectId,
|
|
@@ -5218,7 +6467,8 @@ var OnboardEvents = _OnboardEvents;
|
|
|
5218
6467
|
var onboard_events_default = OnboardEvents;
|
|
5219
6468
|
|
|
5220
6469
|
// src/integration/infinite-loop-breaker/index.ts
|
|
5221
|
-
|
|
6470
|
+
init_esm_shims();
|
|
6471
|
+
import { Core as Core3, State as State2 } from "@adobe/aio-sdk";
|
|
5222
6472
|
import crypto2 from "crypto";
|
|
5223
6473
|
var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
5224
6474
|
// seconds
|
|
@@ -5236,7 +6486,7 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
|
|
|
5236
6486
|
event
|
|
5237
6487
|
}) {
|
|
5238
6488
|
const logLevel = process.env.LOG_LEVEL || "info";
|
|
5239
|
-
const logger =
|
|
6489
|
+
const logger = Core3.Logger("infiniteLoopBreaker", { level: logLevel });
|
|
5240
6490
|
logger.debug(`Checking for potential infinite loop for event: ${event}`);
|
|
5241
6491
|
if (!eventTypes.includes(event)) {
|
|
5242
6492
|
logger.debug(`Event type ${event} is not in the infinite loop event types list`);
|
|
@@ -5314,7 +6564,11 @@ _InfiniteLoopBreaker.DEFAULT_INFINITE_LOOP_BREAKER_TTL = 60;
|
|
|
5314
6564
|
var InfiniteLoopBreaker = _InfiniteLoopBreaker;
|
|
5315
6565
|
var infinite_loop_breaker_default = InfiniteLoopBreaker;
|
|
5316
6566
|
|
|
6567
|
+
// src/integration/onboard-commerce/index.ts
|
|
6568
|
+
init_esm_shims();
|
|
6569
|
+
|
|
5317
6570
|
// src/integration/onboard-commerce/configure-provider/index.ts
|
|
6571
|
+
init_esm_shims();
|
|
5318
6572
|
import {
|
|
5319
6573
|
EventConfigurationService,
|
|
5320
6574
|
EventProviderService
|
|
@@ -5847,7 +7101,11 @@ __name(_OnboardCommerce, "OnboardCommerce");
|
|
|
5847
7101
|
var OnboardCommerce = _OnboardCommerce;
|
|
5848
7102
|
var onboard_commerce_default = OnboardCommerce;
|
|
5849
7103
|
|
|
7104
|
+
// src/commerce/index.ts
|
|
7105
|
+
init_esm_shims();
|
|
7106
|
+
|
|
5850
7107
|
// src/commerce/adobe-commerce-client/index.ts
|
|
7108
|
+
init_esm_shims();
|
|
5851
7109
|
import got from "got";
|
|
5852
7110
|
var _AdobeCommerceClient = class _AdobeCommerceClient {
|
|
5853
7111
|
/**
|
|
@@ -5986,7 +7244,11 @@ __name(_AdobeCommerceClient, "AdobeCommerceClient");
|
|
|
5986
7244
|
var AdobeCommerceClient = _AdobeCommerceClient;
|
|
5987
7245
|
var adobe_commerce_client_default = AdobeCommerceClient;
|
|
5988
7246
|
|
|
7247
|
+
// src/commerce/adobe-commerce-client/basic-auth-connection/index.ts
|
|
7248
|
+
init_esm_shims();
|
|
7249
|
+
|
|
5989
7250
|
// src/commerce/adobe-commerce-client/basic-auth-connection/generate-basic-auth-token/index.ts
|
|
7251
|
+
init_esm_shims();
|
|
5990
7252
|
import { State as State3 } from "@adobe/aio-sdk";
|
|
5991
7253
|
var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
|
|
5992
7254
|
/**
|
|
@@ -6188,6 +7450,7 @@ var BasicAuthConnection = _BasicAuthConnection;
|
|
|
6188
7450
|
var basic_auth_connection_default = BasicAuthConnection;
|
|
6189
7451
|
|
|
6190
7452
|
// src/commerce/adobe-commerce-client/oauth1a-connection/index.ts
|
|
7453
|
+
init_esm_shims();
|
|
6191
7454
|
import Oauth1a from "oauth-1.0a";
|
|
6192
7455
|
import * as crypto3 from "crypto";
|
|
6193
7456
|
var _Oauth1aConnection = class _Oauth1aConnection {
|
|
@@ -6247,51 +7510,41 @@ var Oauth1aConnection = _Oauth1aConnection;
|
|
|
6247
7510
|
var oauth1a_connection_default = Oauth1aConnection;
|
|
6248
7511
|
|
|
6249
7512
|
// src/commerce/adobe-commerce-client/ims-connection/index.ts
|
|
7513
|
+
init_esm_shims();
|
|
6250
7514
|
var _ImsConnection = class _ImsConnection {
|
|
6251
7515
|
/**
|
|
6252
|
-
*
|
|
6253
|
-
*
|
|
6254
|
-
* @param
|
|
6255
|
-
* @param
|
|
6256
|
-
* @
|
|
6257
|
-
*
|
|
6258
|
-
*
|
|
7516
|
+
* Creates an instance of ImsConnection
|
|
7517
|
+
*
|
|
7518
|
+
* @param imsToken - Bearer token string for IMS authentication (generate using AdobeAuth)
|
|
7519
|
+
* @param logger - Optional logger instance for logging operations
|
|
7520
|
+
* @example
|
|
7521
|
+
* ```typescript
|
|
7522
|
+
* const token = await AdobeAuth.getToken(...);
|
|
7523
|
+
* const connection = new ImsConnection(token, logger);
|
|
7524
|
+
* ```
|
|
6259
7525
|
*/
|
|
6260
|
-
constructor(
|
|
6261
|
-
this.
|
|
6262
|
-
this.clientSecret = clientSecret;
|
|
6263
|
-
this.technicalAccountId = technicalAccountId;
|
|
6264
|
-
this.technicalAccountEmail = technicalAccountEmail;
|
|
6265
|
-
this.imsOrgId = imsOrgId;
|
|
6266
|
-
this.scopes = scopes;
|
|
7526
|
+
constructor(imsToken, logger = null) {
|
|
7527
|
+
this.imsToken = imsToken;
|
|
6267
7528
|
this.customLogger = new custom_logger_default(logger);
|
|
6268
7529
|
}
|
|
6269
7530
|
/**
|
|
6270
|
-
*
|
|
7531
|
+
* Extends the Commerce Got client with IMS authentication headers
|
|
7532
|
+
*
|
|
7533
|
+
* @param commerceGot - The Got instance to extend with authentication
|
|
7534
|
+
* @returns Promise<any> - Extended Got instance with authentication headers
|
|
7535
|
+
* @throws {Error} If token is invalid or empty
|
|
6271
7536
|
*/
|
|
6272
7537
|
async extend(commerceGot) {
|
|
6273
7538
|
this.customLogger.info("Using Commerce client with IMS authentication");
|
|
6274
|
-
|
|
6275
|
-
this.clientId,
|
|
6276
|
-
this.clientSecret,
|
|
6277
|
-
this.technicalAccountId,
|
|
6278
|
-
this.technicalAccountEmail,
|
|
6279
|
-
this.imsOrgId,
|
|
6280
|
-
this.scopes,
|
|
6281
|
-
this.customLogger.getLogger(),
|
|
6282
|
-
"adobe_commerce_ims_token",
|
|
6283
|
-
// Use specific cache key for commerce client
|
|
6284
|
-
"adobe-commerce-client"
|
|
6285
|
-
// Use adobe-commerce-client context for backward compatibility
|
|
6286
|
-
);
|
|
6287
|
-
const token = await tokenGenerator.execute();
|
|
6288
|
-
if (token === null) {
|
|
7539
|
+
if (!this.imsToken || this.imsToken.trim() === "") {
|
|
6289
7540
|
throw new Error("Failed to generate or retrieve IMS token");
|
|
6290
7541
|
}
|
|
6291
|
-
this.customLogger.info(
|
|
7542
|
+
this.customLogger.info(
|
|
7543
|
+
`IMS token being extended to header: ${this.imsToken.substring(0, 10)}...`
|
|
7544
|
+
);
|
|
6292
7545
|
return commerceGot.extend({
|
|
6293
7546
|
headers: {
|
|
6294
|
-
Authorization: `Bearer ${
|
|
7547
|
+
Authorization: `Bearer ${this.imsToken}`
|
|
6295
7548
|
}
|
|
6296
7549
|
});
|
|
6297
7550
|
}
|
|
@@ -6300,7 +7553,11 @@ __name(_ImsConnection, "ImsConnection");
|
|
|
6300
7553
|
var ImsConnection = _ImsConnection;
|
|
6301
7554
|
var ims_connection_default = ImsConnection;
|
|
6302
7555
|
|
|
7556
|
+
// src/commerce/shipping-carrier/index.ts
|
|
7557
|
+
init_esm_shims();
|
|
7558
|
+
|
|
6303
7559
|
// src/commerce/shipping-carrier/method/index.ts
|
|
7560
|
+
init_esm_shims();
|
|
6304
7561
|
var _ShippingCarrierMethod = class _ShippingCarrierMethod {
|
|
6305
7562
|
constructor(carrierCode, method) {
|
|
6306
7563
|
this.methodData = { carrier_code: carrierCode, method, additional_data: [] };
|
|
@@ -6651,6 +7908,7 @@ var ShippingCarrier = _ShippingCarrier;
|
|
|
6651
7908
|
var shipping_carrier_default = ShippingCarrier;
|
|
6652
7909
|
|
|
6653
7910
|
// src/commerce/shipping-carrier/response/index.ts
|
|
7911
|
+
init_esm_shims();
|
|
6654
7912
|
var _ShippingCarrierResponse = class _ShippingCarrierResponse {
|
|
6655
7913
|
constructor(carrier) {
|
|
6656
7914
|
this.carrier = carrier;
|
|
@@ -6684,7 +7942,11 @@ __name(_ShippingCarrierResponse, "ShippingCarrierResponse");
|
|
|
6684
7942
|
var ShippingCarrierResponse = _ShippingCarrierResponse;
|
|
6685
7943
|
var response_default3 = ShippingCarrierResponse;
|
|
6686
7944
|
|
|
7945
|
+
// src/experience/index.ts
|
|
7946
|
+
init_esm_shims();
|
|
7947
|
+
|
|
6687
7948
|
// src/experience/admin-ui-sdk/index.ts
|
|
7949
|
+
init_esm_shims();
|
|
6688
7950
|
var _AdminUiSdk = class _AdminUiSdk {
|
|
6689
7951
|
/**
|
|
6690
7952
|
* Creates a new AdminUiSdk instance
|
|
@@ -6863,6 +8125,7 @@ export {
|
|
|
6863
8125
|
ims_token_default as ImsToken,
|
|
6864
8126
|
infinite_loop_breaker_default as InfiniteLoopBreaker,
|
|
6865
8127
|
IoEventsGlobals,
|
|
8128
|
+
JsonMessageProcessor,
|
|
6866
8129
|
oauth1a_connection_default as Oauth1aConnection,
|
|
6867
8130
|
onboard_commerce_default as OnboardCommerce,
|
|
6868
8131
|
onboard_events_default as OnboardEvents,
|
|
@@ -6881,6 +8144,9 @@ export {
|
|
|
6881
8144
|
method_default as ShippingCarrierMethod,
|
|
6882
8145
|
response_default3 as ShippingCarrierResponse,
|
|
6883
8146
|
SignatureVerification,
|
|
8147
|
+
SuccessChecker,
|
|
8148
|
+
telemetry_default as Telemetry,
|
|
8149
|
+
TelemetryInputError,
|
|
6884
8150
|
validator_default as Validator,
|
|
6885
8151
|
webhook_action_default as WebhookAction,
|
|
6886
8152
|
WebhookActionOperation,
|