@adobe-commerce/aio-toolkit 1.0.4 → 1.0.5

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 CHANGED
@@ -5,6 +5,51 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.5] - 2025-11-03
9
+
10
+ ### 🚀 API Enhancements, Security & Developer Experience Improvements
11
+
12
+ This release focuses on improving security testing capabilities, refactoring
13
+ logging for consistency, enhancing repository metadata, and improving the
14
+ ShippingCarrier API for better developer experience and safety. All changes
15
+ maintain backward compatibility except for the ShippingCarrier reset() method
16
+ removal.
17
+
18
+ #### 🔧 Commerce Components
19
+
20
+ - **AdobeCommerceClient** `[Enhanced]` - HTTPS configuration support for
21
+ testing
22
+ - Added optional `httpsOptions` parameter to constructor
23
+ - Support for `rejectUnauthorized: false` for self-signed certificates
24
+ - Enables testing against local/staging environments with insecure SSL
25
+ - Options passed directly to `got` library's https configuration
26
+ - Fully backward compatible - parameter is optional
27
+
28
+ - **AdobeCommerceClient, BasicAuthConnection, Oauth1aConnection** `[Refactored]`
29
+ - Logger initialization refactored to use CustomLogger
30
+ - Consistent null-safe logging across all commerce client classes
31
+ - Removed direct dependency on Core.Logger from @adobe/aio-sdk
32
+ - Simplified constructor logic with centralized logging
33
+ - Enhanced CustomLogger with variadic argument support for logging methods
34
+
35
+ - **ShippingCarrier** `[Breaking Change]` - Removed reset() method and
36
+ immutable code property
37
+ - **BREAKING**: Removed `reset()` method - users should create new
38
+ ShippingCarrier instances
39
+ - Made `code` property immutable in `setData()` method
40
+ - Code is now preserved across all `setData()` calls
41
+ - Prevents accidental override of carrier identity
42
+ - Added `getAddedMethods()` public getter method
43
+ - Added `getRemovedMethods()` public getter method
44
+ - Better encapsulation with controlled access to method tracking arrays
45
+
46
+ #### 🛠️ Framework Components
47
+
48
+ - **CustomLogger** `[Enhanced]` - Variadic argument support
49
+ - Updated `debug()`, `info()`, and `error()` methods to accept variadic args
50
+ - Supports modern logging patterns like `logger.debug('User %s logged in', userId)`
51
+ - Full backward compatibility maintained
52
+
8
53
  ## [1.0.4] - 2025-10-29
9
54
 
10
55
  ### 🚀 Major Feature Release: Webhook Components & Shipping Carrier Builder
package/README.md CHANGED
@@ -624,13 +624,18 @@ const carrier = new ShippingCarrier('fedex', (carrier) => {
624
624
  const carrierData = carrier.getData();
625
625
  console.log(carrierData);
626
626
 
627
+ // Access added and removed methods
628
+ const addedMethods = carrier.getAddedMethods(); // ['standard', 'express']
629
+ const removedMethods = carrier.getRemovedMethods(); // ['overnight']
630
+
627
631
  // Generate webhook response operations
628
632
  const response = new ShippingCarrierResponse(carrier);
629
633
  const operations = response.generate();
630
634
  return operations; // Use in webhook action
631
635
 
636
+ // Update carrier data (code is immutable)
632
637
  carrier.setData({
633
- code: 'dps',
638
+ code: 'ups', // This will be ignored - code remains 'fedex'
634
639
  title: 'Demo Postal Service',
635
640
  stores: ['default'],
636
641
  countries: ['US', 'CA'],
@@ -640,8 +645,8 @@ carrier.setData({
640
645
  shipping_labels_available: true
641
646
  });
642
647
 
643
- // Reset carrier with new code
644
- carrier.reset('ups', (c) => {
648
+ // Code property is immutable - create new instance if you need different code
649
+ const newCarrier = new ShippingCarrier('ups', (c) => {
645
650
  c.addMethod('ground', (m) => {
646
651
  m.setMethodTitle('UPS Ground').setPrice(12.99);
647
652
  });
@@ -653,6 +658,8 @@ carrier.reset('ups', (c) => {
653
658
  - Validation for carrier and method codes (alphanumeric and underscores only)
654
659
  - Add and remove shipping methods dynamically
655
660
  - Configure carrier properties (title, stores, countries, sort order, etc.)
661
+ - **Immutable code property** - prevents accidental carrier identity changes
662
+ - Public getter methods: `getAddedMethods()` and `getRemovedMethods()`
656
663
  - Generate webhook response operations
657
664
  - Type-safe TypeScript interfaces
658
665
 
@@ -660,6 +667,7 @@ carrier.reset('ups', (c) => {
660
667
  - Carrier and method codes must contain only alphanumeric characters and underscores
661
668
  - No spaces, hyphens, dots, or special characters allowed
662
669
  - Empty or whitespace-only codes throw errors
670
+ - Code property cannot be changed after initialization
663
671
 
664
672
  ### 🎨 Experience Components
665
673
 
package/dist/index.d.mts CHANGED
@@ -453,12 +453,17 @@ interface Connection {
453
453
  interface ExtendedRequestError extends RequestError {
454
454
  responseBody?: any;
455
455
  }
456
+ interface HttpsOptions {
457
+ rejectUnauthorized?: boolean;
458
+ [key: string]: any;
459
+ }
456
460
 
457
461
  declare class AdobeCommerceClient {
458
462
  private baseUrl;
459
463
  private connection;
460
464
  private logger;
461
- constructor(baseUrl: string, connection: Connection, logger?: any);
465
+ private httpsOptions;
466
+ constructor(baseUrl: string, connection: Connection, logger?: any, httpsOptions?: HttpsOptions);
462
467
  get(endpoint: string, headers?: Record<string, string>): Promise<any>;
463
468
  post(endpoint: string, headers?: Record<string, string>, payload?: any): Promise<any>;
464
469
  put(endpoint: string, headers?: Record<string, string>, payload?: any): Promise<any>;
@@ -521,17 +526,6 @@ declare class GenerateBasicAuthToken {
521
526
  getState(): Promise<any>;
522
527
  }
523
528
 
524
- interface ShippingCarrierData {
525
- code: string;
526
- title?: string;
527
- stores?: string[];
528
- countries?: string[];
529
- sort_order?: number;
530
- active?: boolean;
531
- tracking_available?: boolean;
532
- shipping_labels_available?: boolean;
533
- }
534
-
535
529
  interface ShippingCarrierMethodAdditionalData {
536
530
  key: string;
537
531
  value: any;
@@ -545,6 +539,17 @@ interface ShippingCarrierMethodData {
545
539
  additional_data: ShippingCarrierMethodAdditionalData[];
546
540
  }
547
541
 
542
+ interface ShippingCarrierData {
543
+ code: string;
544
+ title?: string;
545
+ stores?: string[];
546
+ countries?: string[];
547
+ sort_order?: number;
548
+ active?: boolean;
549
+ tracking_available?: boolean;
550
+ shipping_labels_available?: boolean;
551
+ }
552
+
548
553
  declare class ShippingCarrierMethod {
549
554
  private methodData;
550
555
  constructor(carrierCode: string, method: string);
@@ -572,8 +577,9 @@ declare class ShippingCarrier {
572
577
  setData(carrierData: ShippingCarrierData): this;
573
578
  addMethod(method: string, callback?: (builder: ShippingCarrierMethod) => void): this;
574
579
  removeMethod(method: string): this;
575
- reset(code: string, callback?: (builder: ShippingCarrier) => void): this;
576
580
  getData(): ShippingCarrierData;
581
+ getAddedMethods(): ShippingCarrierMethodData[];
582
+ getRemovedMethods(): string[];
577
583
  }
578
584
 
579
585
  declare class ShippingCarrierResponse {
package/dist/index.d.ts CHANGED
@@ -453,12 +453,17 @@ interface Connection {
453
453
  interface ExtendedRequestError extends RequestError {
454
454
  responseBody?: any;
455
455
  }
456
+ interface HttpsOptions {
457
+ rejectUnauthorized?: boolean;
458
+ [key: string]: any;
459
+ }
456
460
 
457
461
  declare class AdobeCommerceClient {
458
462
  private baseUrl;
459
463
  private connection;
460
464
  private logger;
461
- constructor(baseUrl: string, connection: Connection, logger?: any);
465
+ private httpsOptions;
466
+ constructor(baseUrl: string, connection: Connection, logger?: any, httpsOptions?: HttpsOptions);
462
467
  get(endpoint: string, headers?: Record<string, string>): Promise<any>;
463
468
  post(endpoint: string, headers?: Record<string, string>, payload?: any): Promise<any>;
464
469
  put(endpoint: string, headers?: Record<string, string>, payload?: any): Promise<any>;
@@ -521,17 +526,6 @@ declare class GenerateBasicAuthToken {
521
526
  getState(): Promise<any>;
522
527
  }
523
528
 
524
- interface ShippingCarrierData {
525
- code: string;
526
- title?: string;
527
- stores?: string[];
528
- countries?: string[];
529
- sort_order?: number;
530
- active?: boolean;
531
- tracking_available?: boolean;
532
- shipping_labels_available?: boolean;
533
- }
534
-
535
529
  interface ShippingCarrierMethodAdditionalData {
536
530
  key: string;
537
531
  value: any;
@@ -545,6 +539,17 @@ interface ShippingCarrierMethodData {
545
539
  additional_data: ShippingCarrierMethodAdditionalData[];
546
540
  }
547
541
 
542
+ interface ShippingCarrierData {
543
+ code: string;
544
+ title?: string;
545
+ stores?: string[];
546
+ countries?: string[];
547
+ sort_order?: number;
548
+ active?: boolean;
549
+ tracking_available?: boolean;
550
+ shipping_labels_available?: boolean;
551
+ }
552
+
548
553
  declare class ShippingCarrierMethod {
549
554
  private methodData;
550
555
  constructor(carrierCode: string, method: string);
@@ -572,8 +577,9 @@ declare class ShippingCarrier {
572
577
  setData(carrierData: ShippingCarrierData): this;
573
578
  addMethod(method: string, callback?: (builder: ShippingCarrierMethod) => void): this;
574
579
  removeMethod(method: string): this;
575
- reset(code: string, callback?: (builder: ShippingCarrier) => void): this;
576
580
  getData(): ShippingCarrierData;
581
+ getAddedMethods(): ShippingCarrierMethodData[];
582
+ getRemovedMethods(): string[];
577
583
  }
578
584
 
579
585
  declare class ShippingCarrierResponse {
package/dist/index.js CHANGED
@@ -622,28 +622,31 @@ var _CustomLogger = class _CustomLogger {
622
622
  /**
623
623
  * Log debug message if logger is available
624
624
  * @param message - Debug message to log
625
+ * @param args - Additional arguments to pass to logger
625
626
  */
626
- debug(message) {
627
+ debug(message, ...args) {
627
628
  if (this.logger && typeof this.logger.debug === "function") {
628
- this.logger.debug(message);
629
+ this.logger.debug(message, ...args);
629
630
  }
630
631
  }
631
632
  /**
632
633
  * Log info message if logger is available
633
634
  * @param message - Info message to log
635
+ * @param args - Additional arguments to pass to logger
634
636
  */
635
- info(message) {
637
+ info(message, ...args) {
636
638
  if (this.logger && typeof this.logger.info === "function") {
637
- this.logger.info(message);
639
+ this.logger.info(message, ...args);
638
640
  }
639
641
  }
640
642
  /**
641
643
  * Log error message if logger is available
642
644
  * @param message - Error message to log
645
+ * @param args - Additional arguments to pass to logger
643
646
  */
644
- error(message) {
647
+ error(message, ...args) {
645
648
  if (this.logger && typeof this.logger.error === "function") {
646
- this.logger.error(message);
649
+ this.logger.error(message, ...args);
647
650
  }
648
651
  }
649
652
  /**
@@ -4986,26 +4989,22 @@ var AdobeAuth = _AdobeAuth;
4986
4989
  var adobe_auth_default = AdobeAuth;
4987
4990
 
4988
4991
  // src/commerce/adobe-commerce-client/index.ts
4989
- var import_aio_sdk8 = require("@adobe/aio-sdk");
4990
4992
  var import_got = __toESM(require("got"));
4991
4993
  var _AdobeCommerceClient = class _AdobeCommerceClient {
4992
4994
  /**
4993
4995
  * @param baseUrl
4994
4996
  * @param connection
4995
4997
  * @param logger
4998
+ * @param httpsOptions
4996
4999
  */
4997
- constructor(baseUrl, connection, logger = null) {
5000
+ constructor(baseUrl, connection, logger = null, httpsOptions) {
4998
5001
  if (!baseUrl) {
4999
5002
  throw new Error("Commerce URL must be provided");
5000
5003
  }
5001
5004
  this.baseUrl = baseUrl;
5002
5005
  this.connection = connection;
5003
- if (logger === null) {
5004
- logger = import_aio_sdk8.Core.Logger("adobe-commerce-client", {
5005
- level: "debug"
5006
- });
5007
- }
5008
- this.logger = logger;
5006
+ this.httpsOptions = httpsOptions;
5007
+ this.logger = new custom_logger_default(logger);
5009
5008
  }
5010
5009
  /**
5011
5010
  * @param endpoint
@@ -5092,6 +5091,7 @@ var _AdobeCommerceClient = class _AdobeCommerceClient {
5092
5091
  headers: {
5093
5092
  "Content-Type": "application/json"
5094
5093
  },
5094
+ ...this.httpsOptions && { https: this.httpsOptions },
5095
5095
  hooks: {
5096
5096
  beforeRequest: [
5097
5097
  (options) => this.logger.debug(`Request [${options.method}] ${options.url}`)
@@ -5127,11 +5127,8 @@ __name(_AdobeCommerceClient, "AdobeCommerceClient");
5127
5127
  var AdobeCommerceClient = _AdobeCommerceClient;
5128
5128
  var adobe_commerce_client_default = AdobeCommerceClient;
5129
5129
 
5130
- // src/commerce/adobe-commerce-client/basic-auth-connection/index.ts
5131
- var import_aio_sdk10 = require("@adobe/aio-sdk");
5132
-
5133
5130
  // src/commerce/adobe-commerce-client/basic-auth-connection/generate-basic-auth-token/index.ts
5134
- var import_aio_sdk9 = require("@adobe/aio-sdk");
5131
+ var import_aio_sdk8 = require("@adobe/aio-sdk");
5135
5132
  var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
5136
5133
  /**
5137
5134
  * @param baseUrl
@@ -5144,12 +5141,7 @@ var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
5144
5141
  this.username = username;
5145
5142
  this.password = password;
5146
5143
  this.key = "adobe_commerce_basic_auth_token";
5147
- if (logger === null) {
5148
- logger = import_aio_sdk9.Core.Logger("adobe-commerce-client", {
5149
- level: "debug"
5150
- });
5151
- }
5152
- this.logger = logger;
5144
+ this.logger = new custom_logger_default(logger);
5153
5145
  }
5154
5146
  /**
5155
5147
  * @return string | null
@@ -5286,7 +5278,7 @@ var _GenerateBasicAuthToken = class _GenerateBasicAuthToken {
5286
5278
  async getState() {
5287
5279
  if (this.state === void 0) {
5288
5280
  try {
5289
- this.state = await import_aio_sdk9.State.init();
5281
+ this.state = await import_aio_sdk8.State.init();
5290
5282
  } catch (error) {
5291
5283
  this.logger.debug("State API initialization failed, running without caching");
5292
5284
  this.state = null;
@@ -5311,12 +5303,7 @@ var _BasicAuthConnection = class _BasicAuthConnection {
5311
5303
  this.baseUrl = baseUrl;
5312
5304
  this.username = username;
5313
5305
  this.password = password;
5314
- if (logger === null) {
5315
- logger = import_aio_sdk10.Core.Logger("adobe-commerce-client", {
5316
- level: "debug"
5317
- });
5318
- }
5319
- this.logger = logger;
5306
+ this.logger = new custom_logger_default(logger);
5320
5307
  }
5321
5308
  /**
5322
5309
  * @param commerceGot
@@ -5327,7 +5314,7 @@ var _BasicAuthConnection = class _BasicAuthConnection {
5327
5314
  this.baseUrl,
5328
5315
  this.username,
5329
5316
  this.password,
5330
- this.logger
5317
+ this.logger.getLogger()
5331
5318
  );
5332
5319
  const token = await generateToken.execute();
5333
5320
  return commerceGot.extend({
@@ -5342,7 +5329,6 @@ var BasicAuthConnection = _BasicAuthConnection;
5342
5329
  var basic_auth_connection_default = BasicAuthConnection;
5343
5330
 
5344
5331
  // src/commerce/adobe-commerce-client/oauth1a-connection/index.ts
5345
- var import_aio_sdk11 = require("@adobe/aio-sdk");
5346
5332
  var import_oauth_1 = __toESM(require("oauth-1.0a"));
5347
5333
  var crypto3 = __toESM(require("crypto"));
5348
5334
  var _Oauth1aConnection = class _Oauth1aConnection {
@@ -5358,12 +5344,7 @@ var _Oauth1aConnection = class _Oauth1aConnection {
5358
5344
  this.consumerSecret = consumerSecret;
5359
5345
  this.accessToken = accessToken;
5360
5346
  this.accessTokenSecret = accessTokenSecret;
5361
- if (logger === null) {
5362
- logger = import_aio_sdk11.Core.Logger("adobe-commerce-client", {
5363
- level: "debug"
5364
- });
5365
- }
5366
- this.logger = logger;
5347
+ this.logger = new custom_logger_default(logger);
5367
5348
  }
5368
5349
  /**
5369
5350
  * @param commerceGot
@@ -5407,7 +5388,7 @@ var Oauth1aConnection = _Oauth1aConnection;
5407
5388
  var oauth1a_connection_default = Oauth1aConnection;
5408
5389
 
5409
5390
  // src/commerce/adobe-commerce-client/ims-connection/generate-ims-token/index.ts
5410
- var import_aio_sdk12 = require("@adobe/aio-sdk");
5391
+ var import_aio_sdk9 = require("@adobe/aio-sdk");
5411
5392
  var _GenerateImsToken = class _GenerateImsToken {
5412
5393
  /**
5413
5394
  * @param clientId
@@ -5547,7 +5528,7 @@ var _GenerateImsToken = class _GenerateImsToken {
5547
5528
  if (this.state === void 0) {
5548
5529
  try {
5549
5530
  this.customLogger.debug("Initializing State API for token caching");
5550
- this.state = await import_aio_sdk12.State.init();
5531
+ this.state = await import_aio_sdk9.State.init();
5551
5532
  } catch (error) {
5552
5533
  this.customLogger.error(`Failed to initialize State API: ${error.message}`);
5553
5534
  this.state = null;
@@ -5834,6 +5815,7 @@ var _ShippingCarrier = class _ShippingCarrier {
5834
5815
  }
5835
5816
  /**
5836
5817
  * Sets the carrier data from a ShippingCarrierData object
5818
+ * Note: The code property cannot be changed once set in the constructor
5837
5819
  *
5838
5820
  * @param carrierData - Carrier data object
5839
5821
  * @returns The builder instance for method chaining
@@ -5853,8 +5835,11 @@ var _ShippingCarrier = class _ShippingCarrier {
5853
5835
  * ```
5854
5836
  */
5855
5837
  setData(carrierData) {
5856
- this.validateCarrierCode(carrierData.code);
5857
- this.carrierData = { ...carrierData };
5838
+ const originalCode = this.carrierData.code;
5839
+ if (carrierData.code !== void 0) {
5840
+ this.validateCarrierCode(carrierData.code);
5841
+ }
5842
+ this.carrierData = { ...carrierData, code: originalCode };
5858
5843
  return this;
5859
5844
  }
5860
5845
  /**
@@ -5899,37 +5884,6 @@ var _ShippingCarrier = class _ShippingCarrier {
5899
5884
  this.removedMethods.push(method);
5900
5885
  return this;
5901
5886
  }
5902
- /**
5903
- * Resets the carrier and re-initializes it with new code and optional callback
5904
- *
5905
- * @param code - Carrier code
5906
- * @param callback - Optional callback function to configure the carrier
5907
- * @returns The builder instance for method chaining
5908
- *
5909
- * @example
5910
- * ```typescript
5911
- * carrier.reset('ups', (carrier) => {
5912
- * carrier.addMethod('ground', (method) => {
5913
- * method.setMethodTitle('UPS Ground').setPrice(12.99).setCost(8.00);
5914
- * });
5915
- * });
5916
- * ```
5917
- */
5918
- reset(code, callback) {
5919
- this.validateCarrierCode(code);
5920
- this.carrierData = {
5921
- code,
5922
- active: true,
5923
- tracking_available: true,
5924
- shipping_labels_available: true
5925
- };
5926
- this.addedMethods = [];
5927
- this.removedMethods = [];
5928
- if (callback) {
5929
- callback(this);
5930
- }
5931
- return this;
5932
- }
5933
5887
  /**
5934
5888
  * Gets and returns the shipping carrier data as a JSON object
5935
5889
  *
@@ -5954,6 +5908,34 @@ var _ShippingCarrier = class _ShippingCarrier {
5954
5908
  getData() {
5955
5909
  return this.carrierData;
5956
5910
  }
5911
+ /**
5912
+ * Gets the list of methods that have been added to the carrier
5913
+ *
5914
+ * @returns Array of added shipping carrier methods
5915
+ *
5916
+ * @example
5917
+ * ```typescript
5918
+ * const addedMethods = carrier.getAddedMethods();
5919
+ * // Returns: [{ carrier_code: 'fedex', method: 'standard', ... }, ...]
5920
+ * ```
5921
+ */
5922
+ getAddedMethods() {
5923
+ return this.addedMethods;
5924
+ }
5925
+ /**
5926
+ * Gets the list of method codes that have been marked for removal
5927
+ *
5928
+ * @returns Array of method codes to be removed
5929
+ *
5930
+ * @example
5931
+ * ```typescript
5932
+ * const removedMethods = carrier.getRemovedMethods();
5933
+ * // Returns: ['overnight', 'express']
5934
+ * ```
5935
+ */
5936
+ getRemovedMethods() {
5937
+ return this.removedMethods;
5938
+ }
5957
5939
  };
5958
5940
  __name(_ShippingCarrier, "ShippingCarrier");
5959
5941
  var ShippingCarrier = _ShippingCarrier;