@adobe-commerce/aio-toolkit 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1490,6 +1490,23 @@ var _RuntimeAction = class _RuntimeAction {
1490
1490
  static getActionType() {
1491
1491
  return _RuntimeAction.actionType;
1492
1492
  }
1493
+ /**
1494
+ * Sets the action type name for the next action execution
1495
+ * This is used for logging to identify different action types
1496
+ * (runtime-action, webhook-action, event-consumer-action, etc.)
1497
+ *
1498
+ * @param name - The action type name identifier
1499
+ */
1500
+ static setActionTypeName(name) {
1501
+ _RuntimeAction.actionTypeName = name;
1502
+ }
1503
+ /**
1504
+ * Gets the current action type name
1505
+ * @returns The current action type name identifier
1506
+ */
1507
+ static getActionTypeName() {
1508
+ return _RuntimeAction.actionTypeName;
1509
+ }
1493
1510
  /**
1494
1511
  * Creates a runtime action handler with validation, logging, and telemetry
1495
1512
  *
@@ -1550,17 +1567,20 @@ var _RuntimeAction = class _RuntimeAction {
1550
1567
  const logger = telemetry_default.createLogger(name, params);
1551
1568
  try {
1552
1569
  logger.debug({
1553
- message: `${name}-started`,
1554
- action_name: name
1555
- });
1556
- logger.debug({
1557
- message: `${name}-headers`,
1558
- headers: params.__ow_headers || {}
1559
- });
1560
- logger.debug({
1561
- message: `${name}-body`,
1562
- body: params.__ow_body || {}
1570
+ message: `${_RuntimeAction.getActionTypeName()} execution started`
1563
1571
  });
1572
+ logger.debug(
1573
+ JSON.stringify({
1574
+ message: `${_RuntimeAction.getActionTypeName()} headers received`,
1575
+ headers: params.__ow_headers || {}
1576
+ })
1577
+ );
1578
+ logger.debug(
1579
+ JSON.stringify({
1580
+ message: `${_RuntimeAction.getActionTypeName()} body received`,
1581
+ body: params.__ow_body || {}
1582
+ })
1583
+ );
1564
1584
  const validationError = _RuntimeAction.validateRequest(
1565
1585
  params,
1566
1586
  requiredParams,
@@ -1573,21 +1593,23 @@ var _RuntimeAction = class _RuntimeAction {
1573
1593
  return validationError;
1574
1594
  }
1575
1595
  const result = await action(params, { logger, headers: params.__ow_headers || {} });
1576
- logger.debug({
1577
- message: `${name}-completed`,
1578
- result
1579
- });
1596
+ logger.debug(
1597
+ JSON.stringify({
1598
+ message: `${_RuntimeAction.getActionTypeName()} execution completed`,
1599
+ result
1600
+ })
1601
+ );
1580
1602
  return result;
1581
1603
  } catch (error) {
1582
1604
  if (error instanceof Error) {
1583
1605
  logger.error({
1584
- message: `${name}-failed`,
1606
+ message: `${_RuntimeAction.getActionTypeName()} execution failed`,
1585
1607
  error: error.message,
1586
1608
  stack: error.stack
1587
1609
  });
1588
1610
  } else {
1589
1611
  logger.error({
1590
- message: `${name}-failed`,
1612
+ message: `${_RuntimeAction.getActionTypeName()} execution failed`,
1591
1613
  error
1592
1614
  });
1593
1615
  }
@@ -1629,11 +1651,11 @@ var _RuntimeAction = class _RuntimeAction {
1629
1651
  * }
1630
1652
  * ```
1631
1653
  */
1632
- static validateRequest(params, requiredParams, requiredHeaders, httpMethods, logger, name) {
1654
+ static validateRequest(params, requiredParams, requiredHeaders, httpMethods, logger, _name) {
1633
1655
  const errorMessage = validator_default.checkMissingRequestInputs(params, requiredParams, requiredHeaders) ?? "";
1634
1656
  if (errorMessage) {
1635
1657
  logger.error({
1636
- message: `${name}-validation-failed`,
1658
+ message: `${_RuntimeAction.getActionTypeName()} validation failed`,
1637
1659
  error: errorMessage
1638
1660
  });
1639
1661
  return response_default.error(400 /* BAD_REQUEST */, errorMessage);
@@ -1642,7 +1664,7 @@ var _RuntimeAction = class _RuntimeAction {
1642
1664
  if (httpMethods.length > 0 && !httpMethods.includes(requestMethod)) {
1643
1665
  const errorMessage2 = `Invalid HTTP method: ${params.__ow_method}. Allowed methods are: ${httpMethods.join(", ")}`;
1644
1666
  logger.error({
1645
- message: `${name}-validation-failed`,
1667
+ message: `${_RuntimeAction.getActionTypeName()} validation failed`,
1646
1668
  error: errorMessage2
1647
1669
  });
1648
1670
  return response_default.error(405 /* METHOD_NOT_ALLOWED */, errorMessage2);
@@ -1656,6 +1678,11 @@ __name(_RuntimeAction, "RuntimeAction");
1656
1678
  * Can be set using setActionType() before calling execute()
1657
1679
  */
1658
1680
  _RuntimeAction.actionType = "runtime-action";
1681
+ /**
1682
+ * Private static property to store the action type name for logging
1683
+ * Can be set using setActionTypeName() before calling execute()
1684
+ */
1685
+ _RuntimeAction.actionTypeName = "Runtime action";
1659
1686
  var RuntimeAction = _RuntimeAction;
1660
1687
  var runtime_action_default = RuntimeAction;
1661
1688
 
@@ -1723,28 +1750,27 @@ var _EventConsumerAction = class _EventConsumerAction {
1723
1750
  const logger = telemetry_default.createLogger(name, params);
1724
1751
  try {
1725
1752
  logger.debug({
1726
- message: `${name}-started`,
1727
- action_name: name
1753
+ message: "Event consumer action execution started"
1728
1754
  });
1729
1755
  logger.debug({
1730
- message: `${name}-headers`,
1756
+ message: "Event consumer action headers received",
1731
1757
  headers: params.__ow_headers || {}
1732
1758
  });
1733
1759
  logger.debug({
1734
- message: `${name}-parameters`,
1760
+ message: "Event consumer action parameters received",
1735
1761
  parameters: params
1736
1762
  });
1737
1763
  const errorMessage = validator_default.checkMissingRequestInputs(params, requiredParams, requiredHeaders) || "";
1738
1764
  if (errorMessage) {
1739
1765
  logger.error({
1740
- message: `${name}-validation-failed`,
1766
+ message: "Event consumer action validation failed",
1741
1767
  error: errorMessage
1742
1768
  });
1743
1769
  return response_default.error(400 /* BAD_REQUEST */, errorMessage);
1744
1770
  }
1745
1771
  const result = await action(params, { logger, headers: params.__ow_headers || {} });
1746
1772
  logger.debug({
1747
- message: `${name}-completed`,
1773
+ message: "Event consumer action execution completed",
1748
1774
  result
1749
1775
  });
1750
1776
  return result;
@@ -1779,65 +1805,91 @@ var _GraphQlAction = class _GraphQlAction {
1779
1805
  hello: /* @__PURE__ */ __name(() => "Hello World!", "hello")
1780
1806
  };
1781
1807
  }, name = "main", disableIntrospection = false) {
1782
- return runtime_action_default.execute(
1783
- `graphql-${name}`,
1784
- ["GET" /* GET */, "POST" /* POST */],
1785
- ["query"],
1786
- [],
1787
- async (params, ctx) => {
1788
- let graphqlSchema;
1789
- try {
1790
- graphqlSchema = buildSchema(schema);
1791
- } catch (error) {
1792
- return response_default.error(400 /* BAD_REQUEST */, error.message);
1808
+ runtime_action_default.setActionType("graphql-action");
1809
+ runtime_action_default.setActionTypeName("GraphQL action");
1810
+ const callback = /* @__PURE__ */ __name(async (params, ctx) => {
1811
+ const { logger } = ctx;
1812
+ let graphqlSchema;
1813
+ try {
1814
+ graphqlSchema = buildSchema(schema);
1815
+ } catch (error) {
1816
+ return response_default.error(400 /* BAD_REQUEST */, error.message);
1817
+ }
1818
+ const graphqlResolvers = await resolvers({
1819
+ ...ctx,
1820
+ ...{
1821
+ params
1793
1822
  }
1794
- const graphqlResolvers = await resolvers({
1795
- ...ctx,
1796
- ...{
1797
- params
1798
- }
1823
+ });
1824
+ const context2 = {};
1825
+ const query = params.query;
1826
+ let parsedQuery;
1827
+ try {
1828
+ parsedQuery = parse(query);
1829
+ } catch (error) {
1830
+ return response_default.error(400 /* BAD_REQUEST */, error.message);
1831
+ }
1832
+ logger.debug(
1833
+ JSON.stringify({
1834
+ message: "GraphQL action query parsed",
1835
+ query: parsedQuery
1836
+ })
1837
+ );
1838
+ const validationErrors = validate(graphqlSchema, parsedQuery);
1839
+ if (validationErrors.length) {
1840
+ logger.error({
1841
+ message: "GraphQL action query validation failed",
1842
+ errors: validationErrors
1799
1843
  });
1800
- const context2 = {};
1801
- const query = params.query;
1802
- let parsedQuery;
1803
- try {
1804
- parsedQuery = parse(query);
1805
- } catch (error) {
1806
- return response_default.error(400 /* BAD_REQUEST */, error.message);
1807
- }
1808
- const validationErrors = validate(graphqlSchema, parsedQuery);
1809
- if (validationErrors.length) {
1844
+ return response_default.error(
1845
+ 400 /* BAD_REQUEST */,
1846
+ validationErrors.map((err) => err.message).join(", ")
1847
+ );
1848
+ }
1849
+ if (disableIntrospection) {
1850
+ logger.debug({
1851
+ message: "GraphQL action introspection check disabled"
1852
+ });
1853
+ const isIntrospectionQuery = parsedQuery.definitions.some(
1854
+ (definition) => definition.selectionSet.selections.some(
1855
+ (selection) => selection.name.value.startsWith("__")
1856
+ )
1857
+ );
1858
+ if (isIntrospectionQuery) {
1859
+ logger.error({
1860
+ message: "GraphQL action introspection query detected",
1861
+ query: parsedQuery
1862
+ });
1810
1863
  return response_default.error(
1811
1864
  400 /* BAD_REQUEST */,
1812
- validationErrors.map((err) => err.message).join(", ")
1865
+ "Introspection is disabled for security reasons."
1813
1866
  );
1814
1867
  }
1815
- if (disableIntrospection) {
1816
- const isIntrospectionQuery = parsedQuery.definitions.some(
1817
- (definition) => definition.selectionSet.selections.some(
1818
- (selection) => selection.name.value.startsWith("__")
1819
- )
1820
- );
1821
- if (isIntrospectionQuery) {
1822
- return response_default.error(
1823
- 400 /* BAD_REQUEST */,
1824
- "Introspection is disabled for security reasons."
1825
- );
1826
- }
1827
- }
1828
- const variables = typeof params.variables === "string" ? JSON.parse(params.variables) : params.variables;
1829
- return response_default.success(
1830
- await graphql({
1831
- schema: graphqlSchema,
1832
- source: query,
1833
- rootValue: graphqlResolvers,
1834
- contextValue: context2,
1835
- variableValues: variables,
1836
- operationName: params.operationName
1837
- })
1838
- );
1839
1868
  }
1869
+ const variables = typeof params.variables === "string" ? JSON.parse(params.variables) : params.variables;
1870
+ logger.debug({
1871
+ message: "GraphQL action variables parsed",
1872
+ variables
1873
+ });
1874
+ return response_default.success(
1875
+ await graphql({
1876
+ schema: graphqlSchema,
1877
+ source: query,
1878
+ rootValue: graphqlResolvers,
1879
+ contextValue: context2,
1880
+ variableValues: variables,
1881
+ operationName: params.operationName
1882
+ })
1883
+ );
1884
+ }, "callback");
1885
+ const graphqlAction = runtime_action_default.execute(
1886
+ `graphql-${name}`,
1887
+ ["GET" /* GET */, "POST" /* POST */],
1888
+ ["query"],
1889
+ [],
1890
+ callback
1840
1891
  );
1892
+ return telemetry_default.initialize(graphqlAction);
1841
1893
  }
1842
1894
  };
1843
1895
  __name(_GraphQlAction, "GraphQlAction");
@@ -1855,14 +1907,19 @@ var _Openwhisk = class _Openwhisk {
1855
1907
  this.openwhiskClient = openwhisk({ apihost: host, api_key: apiKey });
1856
1908
  }
1857
1909
  /**
1858
- * @param action
1859
- * @param params
1860
- * @returns {Promise<Activation<Dict>>}
1910
+ * Execute an OpenWhisk action
1911
+ *
1912
+ * @param action - Name of the action to execute
1913
+ * @param params - Parameters to pass to the action
1914
+ * @param config - Configuration options for execution
1915
+ * @param config.blocking - Whether to wait for action completion (default: true)
1916
+ * @returns {Promise<Activation<Dict>>} Action activation result
1861
1917
  */
1862
- async execute(action, params) {
1918
+ async execute(action, params, config = {}) {
1919
+ const { blocking = true } = config;
1863
1920
  return await this.openwhiskClient.actions.invoke({
1864
1921
  name: action,
1865
- blocking: true,
1922
+ blocking,
1866
1923
  params
1867
1924
  });
1868
1925
  }
@@ -1919,29 +1976,28 @@ var _OpenwhiskAction = class _OpenwhiskAction {
1919
1976
  const logger = telemetry_default.createLogger(name, params);
1920
1977
  try {
1921
1978
  logger.debug({
1922
- message: `${name}-started`,
1923
- action_name: name
1979
+ message: "OpenWhisk action execution started"
1924
1980
  });
1925
1981
  logger.debug({
1926
- message: `${name}-params`,
1982
+ message: "OpenWhisk action parameters received",
1927
1983
  params
1928
1984
  });
1929
1985
  const result = await action(params, { logger, headers: params.__ow_headers || {} });
1930
1986
  logger.debug({
1931
- message: `${name}-completed`,
1987
+ message: "OpenWhisk action execution completed",
1932
1988
  result
1933
1989
  });
1934
1990
  return result;
1935
1991
  } catch (error) {
1936
1992
  if (error instanceof Error) {
1937
1993
  logger.error({
1938
- message: `${name}-failed`,
1994
+ message: "OpenWhisk action execution failed",
1939
1995
  error: error.message,
1940
1996
  stack: error.stack
1941
1997
  });
1942
1998
  } else {
1943
1999
  logger.error({
1944
- message: `${name}-failed`,
2000
+ message: "OpenWhisk action execution failed",
1945
2001
  error
1946
2002
  });
1947
2003
  }
@@ -2506,7 +2562,7 @@ var _WebhookAction = class _WebhookAction {
2506
2562
  const verificationErrorMessage = await verifySignature(params);
2507
2563
  if (verificationErrorMessage) {
2508
2564
  logger.error({
2509
- message: `${name}-signature-verification-failed`,
2565
+ message: "Webhook actionsignature verification failed",
2510
2566
  error: verificationErrorMessage
2511
2567
  });
2512
2568
  const verificationErrorResponse = response_default2.exception(verificationErrorMessage);
@@ -2520,7 +2576,7 @@ var _WebhookAction = class _WebhookAction {
2520
2576
  const errorMessage = validator_default.checkMissingRequestInputs(params, requiredParams, requiredHeaders) ?? "";
2521
2577
  if (errorMessage) {
2522
2578
  logger.error({
2523
- message: `${name}-validation-failed`,
2579
+ message: "Webhook action validation failed",
2524
2580
  error: errorMessage
2525
2581
  });
2526
2582
  const errorMessageResponse = response_default2.exception(errorMessage);
@@ -2530,6 +2586,7 @@ var _WebhookAction = class _WebhookAction {
2530
2586
  return response_default.success(JSON.stringify(response));
2531
2587
  }, "callback");
2532
2588
  runtime_action_default.setActionType("webhook-action");
2589
+ runtime_action_default.setActionTypeName("Webhook action");
2533
2590
  return runtime_action_default.execute(name, httpMethods, [], [], callback);
2534
2591
  }
2535
2592
  };