@adobe-commerce/aio-toolkit 1.0.2 → 1.0.3

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.js CHANGED
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  // src/index.ts
32
32
  var index_exports = {};
33
33
  __export(index_exports, {
34
+ AdminUiSdk: () => AdminUiSdk,
34
35
  AdobeAuth: () => adobe_auth_default,
35
36
  AdobeCommerceClient: () => adobe_commerce_client_default,
36
37
  BasicAuthConnection: () => basic_auth_connection_default,
@@ -54,6 +55,7 @@ __export(index_exports, {
54
55
  OpenwhiskAction: () => openwhisk_action_default,
55
56
  Parameters: () => parameters_default,
56
57
  ProviderManager: () => provider_default,
58
+ PublishEvent: () => publish_event_default,
57
59
  RegistrationManager: () => registration_default,
58
60
  RestClient: () => rest_client_default,
59
61
  RuntimeAction: () => runtime_action_default,
@@ -566,6 +568,143 @@ __name(_FileRepository, "FileRepository");
566
568
  var FileRepository = _FileRepository;
567
569
  var file_repository_default = FileRepository;
568
570
 
571
+ // src/framework/publish-event/index.ts
572
+ var import_aio_sdk5 = require("@adobe/aio-sdk");
573
+ var import_cloudevents = require("cloudevents");
574
+ var import_uuid = require("uuid");
575
+
576
+ // src/framework/custom-logger/index.ts
577
+ var _CustomLogger = class _CustomLogger {
578
+ /**
579
+ * @param logger - External logger instance (can be null)
580
+ */
581
+ constructor(logger = null) {
582
+ this.logger = logger;
583
+ }
584
+ /**
585
+ * Log debug message if logger is available
586
+ * @param message - Debug message to log
587
+ */
588
+ debug(message) {
589
+ if (this.logger && typeof this.logger.debug === "function") {
590
+ this.logger.debug(message);
591
+ }
592
+ }
593
+ /**
594
+ * Log info message if logger is available
595
+ * @param message - Info message to log
596
+ */
597
+ info(message) {
598
+ if (this.logger && typeof this.logger.info === "function") {
599
+ this.logger.info(message);
600
+ }
601
+ }
602
+ /**
603
+ * Log error message if logger is available
604
+ * @param message - Error message to log
605
+ */
606
+ error(message) {
607
+ if (this.logger && typeof this.logger.error === "function") {
608
+ this.logger.error(message);
609
+ }
610
+ }
611
+ /**
612
+ * Get the underlying logger instance
613
+ * @returns the logger instance or null
614
+ */
615
+ getLogger() {
616
+ return this.logger;
617
+ }
618
+ };
619
+ __name(_CustomLogger, "CustomLogger");
620
+ var CustomLogger = _CustomLogger;
621
+ var custom_logger_default = CustomLogger;
622
+
623
+ // src/framework/publish-event/index.ts
624
+ var _PublishEvent = class _PublishEvent {
625
+ /**
626
+ * Creates a new PublishEvent instance
627
+ *
628
+ * @param imsOrgId - Adobe IMS Organization ID
629
+ * @param apiKey - Adobe API Key (Client ID)
630
+ * @param accessToken - Adobe Access Token
631
+ * @param logger - Optional logger instance
632
+ */
633
+ constructor(imsOrgId, apiKey, accessToken, logger = null) {
634
+ if (!imsOrgId?.trim()) {
635
+ throw new Error("imsOrgId is required and cannot be empty");
636
+ }
637
+ if (!apiKey?.trim()) {
638
+ throw new Error("apiKey is required and cannot be empty");
639
+ }
640
+ if (!accessToken?.trim()) {
641
+ throw new Error("accessToken is required and cannot be empty");
642
+ }
643
+ this.imsOrgId = imsOrgId;
644
+ this.apiKey = apiKey;
645
+ this.accessToken = accessToken;
646
+ this.customLogger = new custom_logger_default(logger);
647
+ this.customLogger.debug("PublishEvent initialized with valid configuration");
648
+ }
649
+ /**
650
+ * Publishes a CloudEvent to Adobe I/O Events
651
+ *
652
+ * @param providerId - The Adobe I/O Events provider ID
653
+ * @param eventCode - The event type identifier (e.g., 'commerce.order.created')
654
+ * @param payload - The event payload data
655
+ * @param subject - Optional subject for the event
656
+ * @returns Promise<PublishEventResult> - The publish result
657
+ *
658
+ * @throws Error when providerId or eventCode is invalid or publishing fails
659
+ */
660
+ async execute(providerId, eventCode, payload, subject) {
661
+ try {
662
+ if (!providerId?.trim()) {
663
+ throw new Error("providerId is required and cannot be empty");
664
+ }
665
+ if (!eventCode?.trim()) {
666
+ throw new Error("eventCode is required and cannot be empty");
667
+ }
668
+ if (payload === null || payload === void 0) {
669
+ throw new Error("payload is required");
670
+ }
671
+ this.customLogger.info(`Publishing event to provider: ${providerId}`);
672
+ const eventId = (0, import_uuid.v4)();
673
+ const cloudEvent = new import_cloudevents.CloudEvent({
674
+ id: eventId,
675
+ source: `urn:uuid:${providerId}`,
676
+ datacontenttype: "application/json",
677
+ type: eventCode,
678
+ data: payload,
679
+ ...subject && { subject }
680
+ });
681
+ this.customLogger.debug(`Constructed CloudEvent with ID: ${eventId}`);
682
+ const eventsClient = await import_aio_sdk5.Events.init(this.imsOrgId, this.apiKey, this.accessToken);
683
+ this.customLogger.debug("Adobe I/O Events client initialized successfully");
684
+ await eventsClient.publishEvent(cloudEvent);
685
+ const publishedAt = (/* @__PURE__ */ new Date()).toISOString();
686
+ this.customLogger.info(`Event published successfully with ID: ${eventId}`);
687
+ return {
688
+ eventId,
689
+ status: "published",
690
+ publishedAt
691
+ };
692
+ } catch (error) {
693
+ this.customLogger.error(`Failed to publish event: ${error.message}`);
694
+ return {
695
+ eventId: (0, import_uuid.v4)(),
696
+ // Generate ID for tracking even failed events
697
+ status: "failed",
698
+ publishedAt: (/* @__PURE__ */ new Date()).toISOString(),
699
+ error: error.message
700
+ };
701
+ }
702
+ }
703
+ };
704
+ __name(_PublishEvent, "PublishEvent");
705
+ var PublishEvent = _PublishEvent;
706
+ var publish_event_default = PublishEvent;
707
+
569
708
  // src/integration/bearer-token/index.ts
570
709
  var _BearerToken = class _BearerToken {
571
710
  /**
@@ -883,7 +1022,7 @@ var RestClient = _RestClient;
883
1022
  var rest_client_default = RestClient;
884
1023
 
885
1024
  // src/integration/onboard-events/index.ts
886
- var import_aio_sdk5 = require("@adobe/aio-sdk");
1025
+ var import_aio_sdk6 = require("@adobe/aio-sdk");
887
1026
 
888
1027
  // src/io-events/types.ts
889
1028
  var IoEventsGlobals = {
@@ -4198,7 +4337,7 @@ var _OnboardEvents = class _OnboardEvents {
4198
4337
  throw new Error("Access token is required");
4199
4338
  }
4200
4339
  const loggerName = projectName.toLowerCase().replace(/[^a-z0-9\s-_]/g, "").replace(/\s+/g, "-").replace(/_{2,}/g, "_").replace(/-{2,}/g, "-").trim().concat("-onboard-events");
4201
- this.logger = import_aio_sdk5.Core.Logger(loggerName, { level: "debug" });
4340
+ this.logger = import_aio_sdk6.Core.Logger(loggerName, { level: "debug" });
4202
4341
  this.createProviders = new create_providers_default(
4203
4342
  consumerId,
4204
4343
  projectId,
@@ -4394,7 +4533,7 @@ var OnboardEvents = _OnboardEvents;
4394
4533
  var onboard_events_default = OnboardEvents;
4395
4534
 
4396
4535
  // src/integration/infinite-loop-breaker/index.ts
4397
- var import_aio_sdk6 = require("@adobe/aio-sdk");
4536
+ var import_aio_sdk7 = require("@adobe/aio-sdk");
4398
4537
  var import_crypto2 = __toESM(require("crypto"));
4399
4538
  var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
4400
4539
  // seconds
@@ -4412,7 +4551,7 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
4412
4551
  event
4413
4552
  }) {
4414
4553
  const logLevel = process.env.LOG_LEVEL || "info";
4415
- const logger = import_aio_sdk6.Core.Logger("infiniteLoopBreaker", { level: logLevel });
4554
+ const logger = import_aio_sdk7.Core.Logger("infiniteLoopBreaker", { level: logLevel });
4416
4555
  logger.debug(`Checking for potential infinite loop for event: ${event}`);
4417
4556
  if (!eventTypes.includes(event)) {
4418
4557
  logger.debug(`Event type ${event} is not in the infinite loop event types list`);
@@ -4420,7 +4559,7 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
4420
4559
  }
4421
4560
  const key = typeof keyFn === "function" ? keyFn() : keyFn;
4422
4561
  const data = typeof fingerprintFn === "function" ? fingerprintFn() : fingerprintFn;
4423
- const state = await import_aio_sdk6.State.init();
4562
+ const state = await import_aio_sdk7.State.init();
4424
4563
  const persistedFingerPrint = await state.get(key);
4425
4564
  if (!persistedFingerPrint) {
4426
4565
  logger.debug(`No persisted fingerprint found for key ${key}`);
@@ -4441,7 +4580,7 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
4441
4580
  static async storeFingerPrint(keyFn, fingerprintFn, ttl) {
4442
4581
  const key = typeof keyFn === "function" ? keyFn() : keyFn;
4443
4582
  const data = typeof fingerprintFn === "function" ? fingerprintFn() : fingerprintFn;
4444
- const state = await import_aio_sdk6.State.init();
4583
+ const state = await import_aio_sdk7.State.init();
4445
4584
  await state.put(key, _InfiniteLoopBreaker.fingerPrint(data), {
4446
4585
  ttl: ttl !== void 0 ? ttl : _InfiniteLoopBreaker.DEFAULT_INFINITE_LOOP_BREAKER_TTL
4447
4586
  });
@@ -4534,7 +4673,7 @@ var AdobeAuth = _AdobeAuth;
4534
4673
  var adobe_auth_default = AdobeAuth;
4535
4674
 
4536
4675
  // src/commerce/adobe-commerce-client/index.ts
4537
- var import_aio_sdk7 = require("@adobe/aio-sdk");
4676
+ var import_aio_sdk8 = require("@adobe/aio-sdk");
4538
4677
  var import_got = __toESM(require("got"));
4539
4678
  var _AdobeCommerceClient = class _AdobeCommerceClient {
4540
4679
  /**
@@ -4549,7 +4688,7 @@ var _AdobeCommerceClient = class _AdobeCommerceClient {
4549
4688
  this.baseUrl = baseUrl;
4550
4689
  this.connection = connection;
4551
4690
  if (logger === null) {
4552
- logger = import_aio_sdk7.Core.Logger("adobe-commerce-client", {
4691
+ logger = import_aio_sdk8.Core.Logger("adobe-commerce-client", {
4553
4692
  level: "debug"
4554
4693
  });
4555
4694
  }
@@ -4676,10 +4815,10 @@ var AdobeCommerceClient = _AdobeCommerceClient;
4676
4815
  var adobe_commerce_client_default = AdobeCommerceClient;
4677
4816
 
4678
4817
  // src/commerce/adobe-commerce-client/basic-auth-connection/index.ts
4679
- var import_aio_sdk9 = require("@adobe/aio-sdk");
4818
+ var import_aio_sdk10 = require("@adobe/aio-sdk");
4680
4819
 
4681
4820
  // src/commerce/adobe-commerce-client/basic-auth-connection/generate-basic-auth-token/index.ts
4682
- var import_aio_sdk8 = require("@adobe/aio-sdk");
4821
+ var import_aio_sdk9 = require("@adobe/aio-sdk");
4683
4822
  var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
4684
4823
  /**
4685
4824
  * @param baseUrl
@@ -4693,7 +4832,7 @@ var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
4693
4832
  this.password = password;
4694
4833
  this.key = "adobe_commerce_basic_auth_token";
4695
4834
  if (logger === null) {
4696
- logger = import_aio_sdk8.Core.Logger("adobe-commerce-client", {
4835
+ logger = import_aio_sdk9.Core.Logger("adobe-commerce-client", {
4697
4836
  level: "debug"
4698
4837
  });
4699
4838
  }
@@ -4725,7 +4864,7 @@ var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
4725
4864
  * @return TokenResult | null
4726
4865
  */
4727
4866
  async getCommerceToken() {
4728
- const endpoint = this.createEndpoint("rest/V1/integration/admin/token");
4867
+ const endpoint = this.createTokenEndpoint();
4729
4868
  this.logger.debug(`Endpoint: ${endpoint}`);
4730
4869
  try {
4731
4870
  const restClient = new rest_client_default();
@@ -4771,6 +4910,19 @@ var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
4771
4910
  return null;
4772
4911
  }
4773
4912
  }
4913
+ /**
4914
+ * Create the Adobe Commerce integration admin token endpoint.
4915
+ * Handles cases where baseUrl may or may not already include /rest.
4916
+ * @return string
4917
+ */
4918
+ createTokenEndpoint() {
4919
+ const normalizedBaseUrl = this.baseUrl.replace(/\/+$/, "");
4920
+ if (normalizedBaseUrl.endsWith("/rest")) {
4921
+ return `${normalizedBaseUrl}/V1/integration/admin/token`;
4922
+ } else {
4923
+ return `${normalizedBaseUrl}/rest/V1/integration/admin/token`;
4924
+ }
4925
+ }
4774
4926
  /**
4775
4927
  * @param endpoint
4776
4928
  * @return string
@@ -4821,7 +4973,7 @@ var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
4821
4973
  async getState() {
4822
4974
  if (this.state === void 0) {
4823
4975
  try {
4824
- this.state = await import_aio_sdk8.State.init();
4976
+ this.state = await import_aio_sdk9.State.init();
4825
4977
  } catch (error) {
4826
4978
  this.logger.debug("State API initialization failed, running without caching");
4827
4979
  this.state = null;
@@ -4847,7 +4999,7 @@ var _BasicAuthConnection = class _BasicAuthConnection {
4847
4999
  this.username = username;
4848
5000
  this.password = password;
4849
5001
  if (logger === null) {
4850
- logger = import_aio_sdk9.Core.Logger("adobe-commerce-client", {
5002
+ logger = import_aio_sdk10.Core.Logger("adobe-commerce-client", {
4851
5003
  level: "debug"
4852
5004
  });
4853
5005
  }
@@ -4877,7 +5029,7 @@ var BasicAuthConnection = _BasicAuthConnection;
4877
5029
  var basic_auth_connection_default = BasicAuthConnection;
4878
5030
 
4879
5031
  // src/commerce/adobe-commerce-client/oauth1a-connection/index.ts
4880
- var import_aio_sdk10 = require("@adobe/aio-sdk");
5032
+ var import_aio_sdk11 = require("@adobe/aio-sdk");
4881
5033
  var import_oauth_1 = __toESM(require("oauth-1.0a"));
4882
5034
  var crypto2 = __toESM(require("crypto"));
4883
5035
  var _Oauth1aConnection = class _Oauth1aConnection {
@@ -4894,7 +5046,7 @@ var _Oauth1aConnection = class _Oauth1aConnection {
4894
5046
  this.accessToken = accessToken;
4895
5047
  this.accessTokenSecret = accessTokenSecret;
4896
5048
  if (logger === null) {
4897
- logger = import_aio_sdk10.Core.Logger("adobe-commerce-client", {
5049
+ logger = import_aio_sdk11.Core.Logger("adobe-commerce-client", {
4898
5050
  level: "debug"
4899
5051
  });
4900
5052
  }
@@ -4941,8 +5093,161 @@ __name(_Oauth1aConnection, "Oauth1aConnection");
4941
5093
  var Oauth1aConnection = _Oauth1aConnection;
4942
5094
  var oauth1a_connection_default = Oauth1aConnection;
4943
5095
 
5096
+ // src/commerce/adobe-commerce-client/ims-connection/generate-ims-token/index.ts
5097
+ var import_aio_sdk12 = require("@adobe/aio-sdk");
5098
+ var _GenerateImsToken = class _GenerateImsToken {
5099
+ /**
5100
+ * @param clientId
5101
+ * @param clientSecret
5102
+ * @param technicalAccountId
5103
+ * @param technicalAccountEmail
5104
+ * @param imsOrgId
5105
+ * @param scopes
5106
+ * @param logger
5107
+ */
5108
+ constructor(clientId, clientSecret, technicalAccountId, technicalAccountEmail, imsOrgId, scopes, logger = null) {
5109
+ this.key = "adobe_ims_auth_token";
5110
+ this.tokenContext = "adobe-commerce-client";
5111
+ this.clientId = clientId;
5112
+ this.clientSecret = clientSecret;
5113
+ this.technicalAccountId = technicalAccountId;
5114
+ this.technicalAccountEmail = technicalAccountEmail;
5115
+ this.imsOrgId = imsOrgId;
5116
+ this.scopes = scopes;
5117
+ this.customLogger = new custom_logger_default(logger);
5118
+ }
5119
+ /**
5120
+ * @return string | null
5121
+ */
5122
+ async execute() {
5123
+ try {
5124
+ this.customLogger.info("Starting IMS token generation/retrieval process");
5125
+ const currentValue = await this.getValue();
5126
+ if (currentValue !== null) {
5127
+ this.customLogger.info("Found cached IMS token, returning cached value");
5128
+ return currentValue;
5129
+ }
5130
+ this.customLogger.info("No cached token found, generating new IMS token");
5131
+ let result = {
5132
+ token: null,
5133
+ expire_in: 86399
5134
+ // Default fallback, will be overridden by actual token expiry
5135
+ };
5136
+ const response = await this.getImsToken();
5137
+ if (response !== null) {
5138
+ result = response;
5139
+ }
5140
+ if (result.token !== null) {
5141
+ this.customLogger.info(`Generated new IMS token, caching for ${result.expire_in} seconds`);
5142
+ await this.setValue(result);
5143
+ }
5144
+ return result.token;
5145
+ } catch (error) {
5146
+ this.customLogger.error(`Failed to execute IMS token generation: ${error.message}`);
5147
+ return null;
5148
+ }
5149
+ }
5150
+ /**
5151
+ * @return ImsTokenResult | null
5152
+ */
5153
+ async getImsToken() {
5154
+ try {
5155
+ this.customLogger.debug(`Calling AdobeAuth.getToken with context: ${this.tokenContext}`);
5156
+ const token = await adobe_auth_default.getToken(
5157
+ this.clientId,
5158
+ this.clientSecret,
5159
+ this.technicalAccountId,
5160
+ this.technicalAccountEmail,
5161
+ this.imsOrgId,
5162
+ this.scopes,
5163
+ this.tokenContext
5164
+ );
5165
+ if (token !== null && token !== void 0) {
5166
+ this.customLogger.debug("Received token from AdobeAuth, parsing with BearerToken.info");
5167
+ const tokenInfo = bearer_token_default.info(token);
5168
+ if (!tokenInfo.isValid) {
5169
+ this.customLogger.error("Received invalid or expired token from IMS");
5170
+ return null;
5171
+ }
5172
+ const expireInSeconds = tokenInfo.timeUntilExpiry ? Math.floor(tokenInfo.timeUntilExpiry / 1e3) : 86399;
5173
+ this.customLogger.debug(`Token expires in ${expireInSeconds} seconds`);
5174
+ return {
5175
+ token,
5176
+ expire_in: expireInSeconds
5177
+ };
5178
+ }
5179
+ this.customLogger.error("Received null or undefined token from IMS");
5180
+ return null;
5181
+ } catch (error) {
5182
+ this.customLogger.error(`Failed to get IMS token: ${error.message}`);
5183
+ return null;
5184
+ }
5185
+ }
5186
+ /**
5187
+ * @param result
5188
+ * @return boolean
5189
+ */
5190
+ async setValue(result) {
5191
+ try {
5192
+ const state = await this.getState();
5193
+ if (state === null) {
5194
+ this.customLogger.info("State API not available, skipping token caching");
5195
+ return true;
5196
+ }
5197
+ const ttlWithBuffer = Math.max(result.expire_in - 300, 60);
5198
+ this.customLogger.debug(
5199
+ `Caching IMS token with TTL: ${ttlWithBuffer} seconds (original: ${result.expire_in})`
5200
+ );
5201
+ await state.put(this.key, result.token, { ttl: ttlWithBuffer });
5202
+ return true;
5203
+ } catch (error) {
5204
+ this.customLogger.error(`Failed to cache IMS token: ${error.message}`);
5205
+ return true;
5206
+ }
5207
+ }
5208
+ /**
5209
+ * @return string | null
5210
+ */
5211
+ async getValue() {
5212
+ try {
5213
+ this.customLogger.debug("Checking for cached IMS token");
5214
+ const state = await this.getState();
5215
+ if (state === null) {
5216
+ this.customLogger.debug("State API not available, cannot retrieve cached token");
5217
+ return null;
5218
+ }
5219
+ const value = await state.get(this.key);
5220
+ if (value !== void 0 && value.value) {
5221
+ this.customLogger.debug("Found cached IMS token");
5222
+ return value.value;
5223
+ }
5224
+ this.customLogger.debug("No cached IMS token found");
5225
+ } catch (error) {
5226
+ this.customLogger.error(`Failed to retrieve cached IMS token: ${error.message}`);
5227
+ }
5228
+ return null;
5229
+ }
5230
+ /**
5231
+ * @return any
5232
+ */
5233
+ async getState() {
5234
+ if (this.state === void 0) {
5235
+ try {
5236
+ this.customLogger.debug("Initializing State API for token caching");
5237
+ this.state = await import_aio_sdk12.State.init();
5238
+ } catch (error) {
5239
+ this.customLogger.error(`Failed to initialize State API: ${error.message}`);
5240
+ this.state = null;
5241
+ }
5242
+ }
5243
+ return this.state;
5244
+ }
5245
+ };
5246
+ __name(_GenerateImsToken, "GenerateImsToken");
5247
+ var GenerateImsToken = _GenerateImsToken;
5248
+ var generate_ims_token_default = GenerateImsToken;
5249
+
4944
5250
  // src/commerce/adobe-commerce-client/ims-connection/index.ts
4945
- var import_aio_sdk11 = require("@adobe/aio-sdk");
4946
5251
  var _ImsConnection = class _ImsConnection {
4947
5252
  /**
4948
5253
  * @param clientId
@@ -4952,38 +5257,35 @@ var _ImsConnection = class _ImsConnection {
4952
5257
  * @param imsOrgId
4953
5258
  * @param scopes
4954
5259
  * @param logger
4955
- * @param currentContext
4956
5260
  */
4957
- constructor(clientId, clientSecret, technicalAccountId, technicalAccountEmail, imsOrgId, scopes, logger = null, currentContext = "adobe-commerce-client") {
5261
+ constructor(clientId, clientSecret, technicalAccountId, technicalAccountEmail, imsOrgId, scopes, logger = null) {
4958
5262
  this.clientId = clientId;
4959
5263
  this.clientSecret = clientSecret;
4960
5264
  this.technicalAccountId = technicalAccountId;
4961
5265
  this.technicalAccountEmail = technicalAccountEmail;
4962
5266
  this.imsOrgId = imsOrgId;
4963
5267
  this.scopes = scopes;
4964
- this.currentContext = currentContext;
4965
- if (logger === null) {
4966
- logger = import_aio_sdk11.Core.Logger(currentContext, {
4967
- level: "debug"
4968
- });
4969
- }
4970
- this.logger = logger;
5268
+ this.customLogger = new custom_logger_default(logger);
4971
5269
  }
4972
5270
  /**
4973
5271
  * @param commerceGot
4974
5272
  */
4975
5273
  async extend(commerceGot) {
4976
- this.logger.debug("Using Commerce client with IMS authentication");
4977
- const token = await adobe_auth_default.getToken(
5274
+ this.customLogger.info("Using Commerce client with IMS authentication");
5275
+ const tokenGenerator = new generate_ims_token_default(
4978
5276
  this.clientId,
4979
5277
  this.clientSecret,
4980
5278
  this.technicalAccountId,
4981
5279
  this.technicalAccountEmail,
4982
5280
  this.imsOrgId,
4983
5281
  this.scopes,
4984
- this.currentContext
5282
+ this.customLogger.getLogger()
4985
5283
  );
4986
- this.logger.debug(`IMS token being extended to header: ${token}`);
5284
+ const token = await tokenGenerator.execute();
5285
+ if (token === null) {
5286
+ throw new Error("Failed to generate or retrieve IMS token");
5287
+ }
5288
+ this.customLogger.info(`IMS token being extended to header: ${token.substring(0, 10)}...`);
4987
5289
  return commerceGot.extend({
4988
5290
  headers: {
4989
5291
  Authorization: `Bearer ${token}`
@@ -4994,8 +5296,169 @@ var _ImsConnection = class _ImsConnection {
4994
5296
  __name(_ImsConnection, "ImsConnection");
4995
5297
  var ImsConnection = _ImsConnection;
4996
5298
  var ims_connection_default = ImsConnection;
5299
+
5300
+ // src/experience/admin-ui-sdk/index.ts
5301
+ var _AdminUiSdk = class _AdminUiSdk {
5302
+ /**
5303
+ * Creates a new AdminUiSdk instance
5304
+ * @param extensionId - Unique identifier for the extension
5305
+ * @throws {Error} If extensionId is empty or invalid
5306
+ */
5307
+ constructor(extensionId) {
5308
+ this.menuItems = [];
5309
+ if (!extensionId?.trim()) {
5310
+ throw new Error("Extension ID is required and cannot be empty");
5311
+ }
5312
+ const trimmedId = extensionId.trim();
5313
+ if (!this.isValidExtensionId(trimmedId)) {
5314
+ throw new Error(
5315
+ "Extension ID must be alphanumeric with underscores only (no spaces, hyphens, or special characters)"
5316
+ );
5317
+ }
5318
+ this.extensionId = trimmedId;
5319
+ }
5320
+ /**
5321
+ * Validates that an extension ID contains only alphanumeric characters and underscores
5322
+ * @param id - The extension ID to validate
5323
+ * @returns true if valid, false otherwise
5324
+ */
5325
+ isValidExtensionId(id) {
5326
+ return /^[a-zA-Z0-9_]+$/.test(id);
5327
+ }
5328
+ /**
5329
+ * Validates that a menu ID is valid (can contain :: separator for namespacing)
5330
+ * @param id - The menu ID to validate
5331
+ * @returns true if valid, false otherwise
5332
+ */
5333
+ isValidMenuId(id) {
5334
+ return /^[a-zA-Z0-9_:]+$/.test(id);
5335
+ }
5336
+ /**
5337
+ * Adds a menu item to the extension
5338
+ * @param id - Full identifier for the menu item (e.g., 'extensionId::menuItem')
5339
+ * @param title - Display title for the menu item
5340
+ * @param sortOrder - Sort order for menu positioning
5341
+ * @param parent - Parent menu identifier (optional, full ID like 'extensionId::parent')
5342
+ * @throws {Error} If parameters are invalid or ID already exists
5343
+ */
5344
+ addMenuItem(id, title, sortOrder, parent) {
5345
+ if (!id?.trim()) {
5346
+ throw new Error("Menu item ID is required and cannot be empty");
5347
+ }
5348
+ if (!this.isValidMenuId(id.trim())) {
5349
+ throw new Error(
5350
+ "Menu item ID must be alphanumeric with underscores and colons only (no spaces, hyphens, or other special characters)"
5351
+ );
5352
+ }
5353
+ if (!title?.trim()) {
5354
+ throw new Error("Menu item title is required and cannot be empty");
5355
+ }
5356
+ if (parent !== void 0 && !parent?.trim()) {
5357
+ throw new Error("Menu item parent cannot be empty if provided");
5358
+ }
5359
+ if (parent !== void 0 && !this.isValidMenuId(parent.trim())) {
5360
+ throw new Error(
5361
+ "Menu item parent must be alphanumeric with underscores and colons only (no spaces, hyphens, or other special characters)"
5362
+ );
5363
+ }
5364
+ if (typeof sortOrder !== "number" || sortOrder < 0) {
5365
+ throw new Error("Menu item sortOrder must be a non-negative number");
5366
+ }
5367
+ const trimmedId = id.trim();
5368
+ if (this.menuItems.some((item) => item.id === trimmedId)) {
5369
+ throw new Error(`Menu item with ID '${trimmedId}' already exists`);
5370
+ }
5371
+ const menuItem = {
5372
+ id: trimmedId,
5373
+ title: title.trim(),
5374
+ sortOrder
5375
+ };
5376
+ if (parent?.trim()) {
5377
+ menuItem.parent = parent.trim();
5378
+ }
5379
+ this.menuItems.push(menuItem);
5380
+ }
5381
+ /**
5382
+ * Adds a menu section to the extension
5383
+ * @param id - Full identifier for the menu section (e.g., 'extensionId::section')
5384
+ * @param title - Display title for the menu section
5385
+ * @param sortOrder - Sort order for section positioning
5386
+ * @param parent - Parent menu identifier (optional, full ID like 'Magento_Backend::system')
5387
+ * @throws {Error} If parameters are invalid or ID already exists
5388
+ */
5389
+ addMenuSection(id, title, sortOrder, parent) {
5390
+ if (!id?.trim()) {
5391
+ throw new Error("Menu section ID is required and cannot be empty");
5392
+ }
5393
+ if (!this.isValidMenuId(id.trim())) {
5394
+ throw new Error(
5395
+ "Menu section ID must be alphanumeric with underscores and colons only (no spaces, hyphens, or other special characters)"
5396
+ );
5397
+ }
5398
+ if (!title?.trim()) {
5399
+ throw new Error("Menu section title is required and cannot be empty");
5400
+ }
5401
+ if (parent !== void 0 && !parent?.trim()) {
5402
+ throw new Error("Menu section parent cannot be empty if provided");
5403
+ }
5404
+ if (parent !== void 0 && !this.isValidMenuId(parent.trim())) {
5405
+ throw new Error(
5406
+ "Menu section parent must be alphanumeric with underscores and colons only (no spaces, hyphens, or other special characters)"
5407
+ );
5408
+ }
5409
+ if (typeof sortOrder !== "number" || sortOrder < 0) {
5410
+ throw new Error("Menu section sortOrder must be a non-negative number");
5411
+ }
5412
+ const trimmedId = id.trim();
5413
+ if (this.menuItems.some((item) => item.id === trimmedId)) {
5414
+ throw new Error(`Menu item with ID '${trimmedId}' already exists`);
5415
+ }
5416
+ const menuSection = {
5417
+ id: trimmedId,
5418
+ title: title.trim(),
5419
+ sortOrder,
5420
+ isSection: true
5421
+ };
5422
+ if (parent?.trim()) {
5423
+ menuSection.parent = parent.trim();
5424
+ }
5425
+ this.menuItems.push(menuSection);
5426
+ }
5427
+ /**
5428
+ * Sets the page title for the extension
5429
+ * @param title - The page title
5430
+ * @throws {Error} If title is empty or invalid
5431
+ */
5432
+ addPage(title) {
5433
+ if (!title?.trim()) {
5434
+ throw new Error("Page title is required and cannot be empty");
5435
+ }
5436
+ this.pageTitle = title.trim();
5437
+ }
5438
+ /**
5439
+ * Gets the complete registration object for the extension
5440
+ * @returns The registration object with optional menu items and page configuration
5441
+ */
5442
+ getRegistration() {
5443
+ const registration = {};
5444
+ if (this.menuItems.length > 0) {
5445
+ registration.menuItems = [...this.menuItems];
5446
+ }
5447
+ if (this.pageTitle) {
5448
+ registration.page = {
5449
+ title: this.pageTitle
5450
+ };
5451
+ }
5452
+ return {
5453
+ registration
5454
+ };
5455
+ }
5456
+ };
5457
+ __name(_AdminUiSdk, "AdminUiSdk");
5458
+ var AdminUiSdk = _AdminUiSdk;
4997
5459
  // Annotate the CommonJS export names for ESM import in node:
4998
5460
  0 && (module.exports = {
5461
+ AdminUiSdk,
4999
5462
  AdobeAuth,
5000
5463
  AdobeCommerceClient,
5001
5464
  BasicAuthConnection,
@@ -5019,6 +5482,7 @@ var ims_connection_default = ImsConnection;
5019
5482
  OpenwhiskAction,
5020
5483
  Parameters,
5021
5484
  ProviderManager,
5485
+ PublishEvent,
5022
5486
  RegistrationManager,
5023
5487
  RestClient,
5024
5488
  RuntimeAction,