@adobe-commerce/aio-toolkit 1.0.3 → 1.0.4

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
@@ -60,7 +60,14 @@ __export(index_exports, {
60
60
  RestClient: () => rest_client_default,
61
61
  RuntimeAction: () => runtime_action_default,
62
62
  RuntimeActionResponse: () => response_default,
63
- Validator: () => validator_default
63
+ ShippingCarrier: () => shipping_carrier_default,
64
+ ShippingCarrierMethod: () => method_default,
65
+ ShippingCarrierResponse: () => response_default3,
66
+ SignatureVerification: () => SignatureVerification,
67
+ Validator: () => validator_default,
68
+ WebhookAction: () => webhook_action_default,
69
+ WebhookActionOperation: () => WebhookActionOperation,
70
+ WebhookActionResponse: () => response_default2
64
71
  });
65
72
  module.exports = __toCommonJS(index_exports);
66
73
 
@@ -459,15 +466,34 @@ var _FileRepository = class _FileRepository {
459
466
  async list() {
460
467
  const filesLib = await this.getFiles();
461
468
  const results = [];
462
- const existingFiles = await filesLib.list(`${this.filepath}/`);
469
+ const existingFiles = await this.metadata();
463
470
  if (existingFiles.length) {
464
- for (const { name } of existingFiles) {
465
- const buffer = await filesLib.read(`${name}`);
466
- results.push(JSON.parse(buffer.toString()));
471
+ for (const file of existingFiles) {
472
+ const buffer = await filesLib.read(`${file.name}`);
473
+ const data = JSON.parse(buffer.toString());
474
+ results.push({
475
+ ...data,
476
+ createdAt: file.creationTime.toISOString(),
477
+ updatedAt: file.lastModified.toISOString()
478
+ });
467
479
  }
468
480
  }
469
481
  return results;
470
482
  }
483
+ /**
484
+ * Lists file metadata without reading file contents
485
+ * Provides a lightweight alternative to list() for performance-critical operations
486
+ * @param id - Optional ID of a specific file to get metadata for
487
+ * @returns Promise<FileMetadata | FileMetadata[]> Single file metadata if id provided, array of all files otherwise
488
+ */
489
+ async metadata(id) {
490
+ const filesLib = await this.getFiles();
491
+ if (id) {
492
+ const filepath = `${this.filepath}/${id}.json`;
493
+ return await filesLib.getProperties(filepath);
494
+ }
495
+ return await filesLib.list(`${this.filepath}/`);
496
+ }
471
497
  /**
472
498
  * Loads a specific file by ID
473
499
  * @param id - The ID of the file to load
@@ -479,7 +505,13 @@ var _FileRepository = class _FileRepository {
479
505
  const existingFile = await filesLib.list(filepath);
480
506
  if (existingFile.length) {
481
507
  const buffer = await filesLib.read(filepath);
482
- return JSON.parse(buffer.toString());
508
+ const data = JSON.parse(buffer.toString());
509
+ const fileProps = await filesLib.getProperties(filepath);
510
+ return {
511
+ ...data,
512
+ createdAt: fileProps.creationTime.toISOString(),
513
+ updatedAt: fileProps.lastModified.toISOString()
514
+ };
483
515
  }
484
516
  return {};
485
517
  }
@@ -487,9 +519,12 @@ var _FileRepository = class _FileRepository {
487
519
  * Saves a file record to the repository
488
520
  * @param payload - The data to save
489
521
  * @param id - Optional ID for the file (sanitized to alphanumeric + underscore, takes precedence over payload.id)
522
+ * @param overwrite - Optional flag to control file write behavior:
523
+ * - true: Replace file entirely with payload (no merge)
524
+ * - false (default): Merge payload with existing file content
490
525
  * @returns Promise<string | null> The filename on success, null on failure
491
526
  */
492
- async save(payload = {}, id) {
527
+ async save(payload = {}, id, overwrite = false) {
493
528
  try {
494
529
  const filesLib = await this.getFiles();
495
530
  let fileId;
@@ -503,23 +538,26 @@ var _FileRepository = class _FileRepository {
503
538
  const filepath = `${this.filepath}/${fileId}.json`;
504
539
  const existingFile = await filesLib.list(filepath);
505
540
  if (existingFile.length) {
506
- const buffer = await filesLib.read(filepath);
507
- const existingData = JSON.parse(buffer.toString());
508
- payload = {
509
- ...payload,
510
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
511
- };
512
- payload = { ...existingData, ...payload };
541
+ if (overwrite) {
542
+ console.log(`Overwriting existing file: ${filepath}`);
543
+ payload = {
544
+ id: fileId,
545
+ ...payload
546
+ };
547
+ } else {
548
+ const buffer = await filesLib.read(filepath);
549
+ const existingData = JSON.parse(buffer.toString());
550
+ payload = { ...existingData, ...payload };
551
+ }
513
552
  await filesLib.delete(filepath);
514
553
  } else {
515
554
  payload = {
516
- ...payload,
517
555
  id: fileId,
518
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
519
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
556
+ ...payload
520
557
  };
521
558
  }
522
- await filesLib.write(filepath, JSON.stringify(payload));
559
+ const { createdAt, updatedAt, ...payloadWithoutTimestamps } = payload;
560
+ await filesLib.write(filepath, JSON.stringify(payloadWithoutTimestamps));
523
561
  return fileId;
524
562
  } catch (error) {
525
563
  console.error("Error saving file:", error);
@@ -705,6 +743,281 @@ __name(_PublishEvent, "PublishEvent");
705
743
  var PublishEvent = _PublishEvent;
706
744
  var publish_event_default = PublishEvent;
707
745
 
746
+ // src/framework/webhook-action/response/types.ts
747
+ var WebhookActionOperation = /* @__PURE__ */ ((WebhookActionOperation2) => {
748
+ WebhookActionOperation2["SUCCESS"] = "success";
749
+ WebhookActionOperation2["EXCEPTION"] = "exception";
750
+ WebhookActionOperation2["ADD"] = "add";
751
+ WebhookActionOperation2["REPLACE"] = "replace";
752
+ WebhookActionOperation2["REMOVE"] = "remove";
753
+ return WebhookActionOperation2;
754
+ })(WebhookActionOperation || {});
755
+
756
+ // src/framework/webhook-action/response/index.ts
757
+ var _WebhookActionResponse = class _WebhookActionResponse {
758
+ /**
759
+ * Creates a success response indicating the webhook was processed successfully.
760
+ *
761
+ * Use this method when the webhook has been processed without errors and
762
+ * no modifications to the payload are needed.
763
+ *
764
+ * @returns A success response object
765
+ *
766
+ * @example
767
+ * ```typescript
768
+ * const handler = WebhookAction.execute('process-order', [], [], async (params) => {
769
+ * // Process the order...
770
+ * await processOrder(params.order);
771
+ *
772
+ * // Return success
773
+ * return {
774
+ * statusCode: 200,
775
+ * body: WebhookActionResponse.success()
776
+ * };
777
+ * });
778
+ * ```
779
+ */
780
+ static success() {
781
+ return {
782
+ op: "success" /* SUCCESS */
783
+ };
784
+ }
785
+ /**
786
+ * Creates an exception response to report an error during webhook processing.
787
+ *
788
+ * Use this method to notify Adobe Commerce that an error occurred while
789
+ * processing the webhook. This helps with debugging and error tracking.
790
+ *
791
+ * @param message - Optional error message describing what went wrong
792
+ * @param exceptionClass - Optional exception class name for categorization (e.g., 'Magento\\Framework\\Exception\\LocalizedException')
793
+ * @returns An exception response object
794
+ *
795
+ * @example
796
+ * ```typescript
797
+ * const handler = WebhookAction.execute('validate-product', [], [], async (params) => {
798
+ * const product = await findProduct(params.sku);
799
+ *
800
+ * if (!product) {
801
+ * return {
802
+ * statusCode: 404,
803
+ * body: WebhookActionResponse.exception(
804
+ * `Product with SKU ${params.sku} not found`,
805
+ * 'Magento\\Framework\\Exception\\NoSuchEntityException'
806
+ * )
807
+ * };
808
+ * }
809
+ *
810
+ * return { statusCode: 200, body: WebhookActionResponse.success() };
811
+ * });
812
+ * ```
813
+ */
814
+ static exception(message, exceptionClass) {
815
+ const response = {
816
+ op: "exception" /* EXCEPTION */
817
+ };
818
+ if (message !== void 0) {
819
+ response.message = message;
820
+ }
821
+ if (exceptionClass !== void 0) {
822
+ response.class = exceptionClass;
823
+ }
824
+ return response;
825
+ }
826
+ /**
827
+ * Creates a response to add new data to the webhook payload.
828
+ *
829
+ * Use this method to inject additional data into the webhook payload that
830
+ * will be processed by Adobe Commerce. The data is added at the specified
831
+ * path using dot notation.
832
+ *
833
+ * @param path - Dot-notation path where the value should be added (e.g., 'order.items', 'customer.addresses')
834
+ * @param value - The value to add at the specified path
835
+ * @param instance - Optional instance identifier for tracking or reference purposes
836
+ * @returns An add response object
837
+ *
838
+ * @example
839
+ * ```typescript
840
+ * const handler = WebhookAction.execute('enrich-order', [], [], async (params) => {
841
+ * // Add loyalty points to the order
842
+ * return {
843
+ * statusCode: 200,
844
+ * body: WebhookActionResponse.add(
845
+ * 'order.loyalty',
846
+ * { points: 150, tier: 'gold' },
847
+ * params.order.id
848
+ * )
849
+ * };
850
+ * });
851
+ * ```
852
+ */
853
+ static add(path, value, instance) {
854
+ const response = {
855
+ op: "add" /* ADD */,
856
+ path,
857
+ value
858
+ };
859
+ if (instance !== void 0) {
860
+ response.instance = instance;
861
+ }
862
+ return response;
863
+ }
864
+ /**
865
+ * Creates a response to replace existing data in the webhook payload.
866
+ *
867
+ * Use this method to modify existing fields in the webhook payload.
868
+ * The existing value at the specified path will be replaced with the new value.
869
+ *
870
+ * @param path - Dot-notation path to the field that should be replaced (e.g., 'product.price', 'order.status')
871
+ * @param value - The new value to replace the existing value
872
+ * @param instance - Optional instance identifier for tracking or reference purposes
873
+ * @returns A replace response object
874
+ *
875
+ * @example
876
+ * ```typescript
877
+ * const handler = WebhookAction.execute('adjust-price', [], [], async (params) => {
878
+ * // Apply dynamic pricing
879
+ * const newPrice = await calculateDiscountedPrice(params.product.price);
880
+ *
881
+ * return {
882
+ * statusCode: 200,
883
+ * body: WebhookActionResponse.replace(
884
+ * 'product.price',
885
+ * newPrice,
886
+ * params.product.id
887
+ * )
888
+ * };
889
+ * });
890
+ * ```
891
+ */
892
+ static replace(path, value, instance) {
893
+ const response = {
894
+ op: "replace" /* REPLACE */,
895
+ path,
896
+ value
897
+ };
898
+ if (instance !== void 0) {
899
+ response.instance = instance;
900
+ }
901
+ return response;
902
+ }
903
+ /**
904
+ * Creates a response to remove data from the webhook payload.
905
+ *
906
+ * Use this method to remove fields from the webhook payload before it's
907
+ * processed by Adobe Commerce. This is useful for filtering sensitive data
908
+ * or removing unnecessary information.
909
+ *
910
+ * @param path - Dot-notation path to the field that should be removed (e.g., 'items.0', 'customer.internal_notes')
911
+ * @returns A remove response object
912
+ *
913
+ * @example
914
+ * ```typescript
915
+ * const handler = WebhookAction.execute('sanitize-customer', [], [], async (params) => {
916
+ * // Remove internal notes before processing
917
+ * return {
918
+ * statusCode: 200,
919
+ * body: WebhookActionResponse.remove('customer.internal_notes')
920
+ * };
921
+ * });
922
+ * ```
923
+ *
924
+ * @example
925
+ * ```typescript
926
+ * // Remove an item from an array
927
+ * return {
928
+ * statusCode: 200,
929
+ * body: WebhookActionResponse.remove('order.items.2')
930
+ * };
931
+ * ```
932
+ */
933
+ static remove(path) {
934
+ return {
935
+ op: "remove" /* REMOVE */,
936
+ path
937
+ };
938
+ }
939
+ };
940
+ __name(_WebhookActionResponse, "WebhookActionResponse");
941
+ var WebhookActionResponse = _WebhookActionResponse;
942
+ var response_default2 = WebhookActionResponse;
943
+
944
+ // src/framework/webhook-action/types.ts
945
+ var SignatureVerification = /* @__PURE__ */ ((SignatureVerification2) => {
946
+ SignatureVerification2["ENABLED"] = "enabled";
947
+ SignatureVerification2["DISABLED"] = "disabled";
948
+ return SignatureVerification2;
949
+ })(SignatureVerification || {});
950
+
951
+ // src/framework/webhook-action/index.ts
952
+ var import_crypto = __toESM(require("crypto"));
953
+ var _WebhookAction = class _WebhookAction {
954
+ /**
955
+ * Execute a webhook action with validation and response handling.
956
+ *
957
+ * @param name - Name of the webhook action
958
+ * @param requiredParams - Required parameters in the webhook payload
959
+ * @param requiredHeaders - Required headers (e.g., signature headers)
960
+ * @param signatureVerification - Enable/disable signature verification
961
+ * @param action - Webhook action function returning WebhookActionResponse
962
+ * @returns Function that handles the webhook HTTP request
963
+ */
964
+ static execute(name = "webhook", requiredParams = [], requiredHeaders = [], signatureVerification = "disabled" /* DISABLED */, action = async () => response_default2.success()) {
965
+ const httpMethods = ["POST" /* POST */];
966
+ const verifySignature = /* @__PURE__ */ __name(async (params) => {
967
+ const signature = params.__ow_headers["x-adobe-commerce-webhook-signature"] || "";
968
+ if (!signature) {
969
+ return "Header `x-adobe-commerce-webhook-signature` not found. Make sure Webhooks signature is enabled in the Commerce instance.";
970
+ }
971
+ const body = params.__ow_body;
972
+ if (!body) {
973
+ return "Request body not found. Make sure the action is configured with `raw-http: true`.";
974
+ }
975
+ let publicKey = params.PUBLIC_KEY;
976
+ if (!publicKey && params.PUBLIC_KEY_BASE64) {
977
+ publicKey = atob(params.PUBLIC_KEY_BASE64);
978
+ }
979
+ if (!publicKey) {
980
+ return "Public key not found. Make sure the action is configured with the input `PUBLIC_KEY` or `PUBLIC_KEY_BASE64` and it is defined in .env file.";
981
+ }
982
+ try {
983
+ const verifier = import_crypto.default.createVerify("SHA256");
984
+ verifier.update(body);
985
+ const isSignatureValid = verifier.verify(publicKey, signature, "base64");
986
+ if (!isSignatureValid) {
987
+ return "The signature is invalid.";
988
+ }
989
+ } catch (error) {
990
+ return "The signature is invalid.";
991
+ }
992
+ return null;
993
+ }, "verifySignature");
994
+ const callback = /* @__PURE__ */ __name(async (params, ctx) => {
995
+ if (signatureVerification === "enabled" /* ENABLED */) {
996
+ const verificationErrorMessage = await verifySignature(params);
997
+ if (verificationErrorMessage) {
998
+ const verificationErrorResponse = response_default2.exception(verificationErrorMessage);
999
+ return response_default.success(JSON.stringify(verificationErrorResponse));
1000
+ }
1001
+ params = {
1002
+ ...params,
1003
+ ...JSON.parse(atob(params.__ow_body))
1004
+ };
1005
+ }
1006
+ const errorMessage = validator_default.checkMissingRequestInputs(params, requiredParams, requiredHeaders) ?? "";
1007
+ if (errorMessage) {
1008
+ const errorMessageResponse = response_default2.exception(errorMessage);
1009
+ return response_default.success(JSON.stringify(errorMessageResponse));
1010
+ }
1011
+ const response = await action(params, ctx);
1012
+ return response_default.success(JSON.stringify(response));
1013
+ }, "callback");
1014
+ return runtime_action_default.execute(name, httpMethods, [], [], callback);
1015
+ }
1016
+ };
1017
+ __name(_WebhookAction, "WebhookAction");
1018
+ var WebhookAction = _WebhookAction;
1019
+ var webhook_action_default = WebhookAction;
1020
+
708
1021
  // src/integration/bearer-token/index.ts
709
1022
  var _BearerToken = class _BearerToken {
710
1023
  /**
@@ -3532,7 +3845,7 @@ var RegistrationManager = _RegistrationManager;
3532
3845
  var registration_default = RegistrationManager;
3533
3846
 
3534
3847
  // src/integration/onboard-events/create-providers/index.ts
3535
- var import_crypto = require("crypto");
3848
+ var import_crypto2 = require("crypto");
3536
3849
  var _CreateProviders = class _CreateProviders {
3537
3850
  /**
3538
3851
  * Creates a new CreateProviders instance
@@ -3728,7 +4041,7 @@ var _CreateProviders = class _CreateProviders {
3728
4041
  }
3729
4042
  if (this.isCommerceProvider(providerData)) {
3730
4043
  input.provider_metadata = "dx_commerce_events";
3731
- input.instance_id = (0, import_crypto.randomUUID)();
4044
+ input.instance_id = (0, import_crypto2.randomUUID)();
3732
4045
  }
3733
4046
  return input;
3734
4047
  }
@@ -4534,7 +4847,7 @@ var onboard_events_default = OnboardEvents;
4534
4847
 
4535
4848
  // src/integration/infinite-loop-breaker/index.ts
4536
4849
  var import_aio_sdk7 = require("@adobe/aio-sdk");
4537
- var import_crypto2 = __toESM(require("crypto"));
4850
+ var import_crypto3 = __toESM(require("crypto"));
4538
4851
  var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
4539
4852
  // seconds
4540
4853
  /**
@@ -4614,7 +4927,7 @@ var _InfiniteLoopBreaker = class _InfiniteLoopBreaker {
4614
4927
  * @returns The fingerprint
4615
4928
  */
4616
4929
  static fingerPrint(data) {
4617
- const hash = import_crypto2.default.createHash(_InfiniteLoopBreaker.FINGERPRINT_ALGORITHM);
4930
+ const hash = import_crypto3.default.createHash(_InfiniteLoopBreaker.FINGERPRINT_ALGORITHM);
4618
4931
  hash.update(JSON.stringify(data));
4619
4932
  return hash.digest(_InfiniteLoopBreaker.FINGERPRINT_ENCODING);
4620
4933
  }
@@ -5031,7 +5344,7 @@ var basic_auth_connection_default = BasicAuthConnection;
5031
5344
  // src/commerce/adobe-commerce-client/oauth1a-connection/index.ts
5032
5345
  var import_aio_sdk11 = require("@adobe/aio-sdk");
5033
5346
  var import_oauth_1 = __toESM(require("oauth-1.0a"));
5034
- var crypto2 = __toESM(require("crypto"));
5347
+ var crypto3 = __toESM(require("crypto"));
5035
5348
  var _Oauth1aConnection = class _Oauth1aConnection {
5036
5349
  /**
5037
5350
  * @param consumerKey
@@ -5080,7 +5393,7 @@ var _Oauth1aConnection = class _Oauth1aConnection {
5080
5393
  secret: this.consumerSecret
5081
5394
  },
5082
5395
  signature_method: "HMAC-SHA256",
5083
- hash_function: /* @__PURE__ */ __name((baseString, key) => crypto2.createHmac("sha256", key).update(baseString).digest("base64"), "hash_function")
5396
+ hash_function: /* @__PURE__ */ __name((baseString, key) => crypto3.createHmac("sha256", key).update(baseString).digest("base64"), "hash_function")
5084
5397
  });
5085
5398
  const oauthToken = {
5086
5399
  key: this.accessToken,
@@ -5297,6 +5610,389 @@ __name(_ImsConnection, "ImsConnection");
5297
5610
  var ImsConnection = _ImsConnection;
5298
5611
  var ims_connection_default = ImsConnection;
5299
5612
 
5613
+ // src/commerce/shipping-carrier/method/index.ts
5614
+ var _ShippingCarrierMethod = class _ShippingCarrierMethod {
5615
+ constructor(carrierCode, method) {
5616
+ this.methodData = { carrier_code: carrierCode, method, additional_data: [] };
5617
+ }
5618
+ /**
5619
+ * Sets the display name for the shipping method
5620
+ *
5621
+ * @param methodTitle - Display name for the shipping method
5622
+ * @returns The rate builder instance for method chaining
5623
+ */
5624
+ setMethodTitle(methodTitle) {
5625
+ this.methodData.method_title = methodTitle;
5626
+ return this;
5627
+ }
5628
+ /**
5629
+ * Sets the price charged to the customer
5630
+ *
5631
+ * @param price - Price charged to the customer
5632
+ * @returns The rate builder instance for method chaining
5633
+ */
5634
+ setPrice(price) {
5635
+ this.methodData.price = price;
5636
+ return this;
5637
+ }
5638
+ /**
5639
+ * Sets the cost to the merchant
5640
+ *
5641
+ * @param cost - Cost to the merchant
5642
+ * @returns The rate builder instance for method chaining
5643
+ */
5644
+ setCost(cost) {
5645
+ this.methodData.cost = cost;
5646
+ return this;
5647
+ }
5648
+ /**
5649
+ * Adds additional data to the shipping method
5650
+ *
5651
+ * @param key - Key for the additional data
5652
+ * @param value - Value for the additional data
5653
+ * @returns The rate builder instance for method chaining
5654
+ *
5655
+ * @example
5656
+ * ```typescript
5657
+ * rate.addAdditionalData('delivery_time', '3-5 business days')
5658
+ * .addAdditionalData('tracking_available', true);
5659
+ * ```
5660
+ */
5661
+ addAdditionalData(key, value) {
5662
+ const additionalDataItem = { key, value };
5663
+ this.methodData.additional_data?.push(additionalDataItem);
5664
+ return this;
5665
+ }
5666
+ /**
5667
+ * Gets and returns the shipping carrier method data
5668
+ *
5669
+ * @returns The shipping carrier method data
5670
+ */
5671
+ getData() {
5672
+ return this.methodData;
5673
+ }
5674
+ };
5675
+ __name(_ShippingCarrierMethod, "ShippingCarrierMethod");
5676
+ var ShippingCarrierMethod = _ShippingCarrierMethod;
5677
+ var method_default = ShippingCarrierMethod;
5678
+
5679
+ // src/commerce/shipping-carrier/index.ts
5680
+ var _ShippingCarrier = class _ShippingCarrier {
5681
+ constructor(code, callback) {
5682
+ this.addedMethods = [];
5683
+ this.removedMethods = [];
5684
+ this.validateCarrierCode(code);
5685
+ this.carrierData = {
5686
+ code,
5687
+ active: true,
5688
+ tracking_available: true,
5689
+ shipping_labels_available: true
5690
+ };
5691
+ this.addedMethods = [];
5692
+ this.removedMethods = [];
5693
+ if (callback) {
5694
+ callback(this);
5695
+ }
5696
+ }
5697
+ /**
5698
+ * Validates that the carrier code contains only alphanumeric characters and underscores
5699
+ *
5700
+ * @param code - Carrier code to validate
5701
+ * @throws Error if code is invalid
5702
+ */
5703
+ validateCarrierCode(code) {
5704
+ if (!code || code.trim() === "") {
5705
+ throw new Error("Carrier code cannot be empty");
5706
+ }
5707
+ const validPattern = /^[a-zA-Z0-9_]+$/;
5708
+ if (!validPattern.test(code)) {
5709
+ throw new Error("Carrier code must contain only alphanumeric characters and underscores");
5710
+ }
5711
+ }
5712
+ /**
5713
+ * Validates that the method code contains only alphanumeric characters and underscores
5714
+ *
5715
+ * @param method - Method code to validate
5716
+ * @throws Error if method code is invalid
5717
+ */
5718
+ validateMethodCode(method) {
5719
+ if (!method || method.trim() === "") {
5720
+ throw new Error("Method code cannot be empty");
5721
+ }
5722
+ const validPattern = /^[a-zA-Z0-9_]+$/;
5723
+ if (!validPattern.test(method)) {
5724
+ throw new Error("Method code must contain only alphanumeric characters and underscores");
5725
+ }
5726
+ }
5727
+ /**
5728
+ * Sets the title for the shipping carrier
5729
+ *
5730
+ * @param title - Display title for the carrier
5731
+ * @returns The builder instance for method chaining
5732
+ *
5733
+ * @example
5734
+ * ```typescript
5735
+ * carrier.setTitle('FedEx Express');
5736
+ * ```
5737
+ */
5738
+ setTitle(title) {
5739
+ this.carrierData.title = title;
5740
+ return this;
5741
+ }
5742
+ /**
5743
+ * Sets the stores for the shipping carrier
5744
+ *
5745
+ * @param stores - Array of store codes
5746
+ * @returns The builder instance for method chaining
5747
+ *
5748
+ * @example
5749
+ * ```typescript
5750
+ * carrier.setStores(['default', 'store1', 'store2']);
5751
+ * ```
5752
+ */
5753
+ setStores(stores) {
5754
+ this.carrierData.stores = stores;
5755
+ return this;
5756
+ }
5757
+ /**
5758
+ * Sets the countries for the shipping carrier
5759
+ *
5760
+ * @param countries - Array of country codes
5761
+ * @returns The builder instance for method chaining
5762
+ *
5763
+ * @example
5764
+ * ```typescript
5765
+ * carrier.setCountries(['US', 'CA', 'MX']);
5766
+ * ```
5767
+ */
5768
+ setCountries(countries) {
5769
+ this.carrierData.countries = countries;
5770
+ return this;
5771
+ }
5772
+ /**
5773
+ * Sets the sort order for the shipping carrier
5774
+ *
5775
+ * @param sortOrder - Sort order number
5776
+ * @returns The builder instance for method chaining
5777
+ *
5778
+ * @example
5779
+ * ```typescript
5780
+ * carrier.setSortOrder(10);
5781
+ * ```
5782
+ */
5783
+ setSortOrder(sortOrder) {
5784
+ this.carrierData.sort_order = sortOrder;
5785
+ return this;
5786
+ }
5787
+ /**
5788
+ * Sets the active status for the shipping carrier
5789
+ *
5790
+ * @param active - Active status
5791
+ * @returns The builder instance for method chaining
5792
+ *
5793
+ * @example
5794
+ * ```typescript
5795
+ * carrier.setActive(true);
5796
+ * carrier.setActive(false);
5797
+ * ```
5798
+ */
5799
+ setActive(active) {
5800
+ this.carrierData.active = active;
5801
+ return this;
5802
+ }
5803
+ /**
5804
+ * Sets the tracking availability for the shipping carrier
5805
+ *
5806
+ * @param trackingAvailable - Tracking availability status
5807
+ * @returns The builder instance for method chaining
5808
+ *
5809
+ * @example
5810
+ * ```typescript
5811
+ * carrier.setTrackingAvailable(true);
5812
+ * carrier.setTrackingAvailable(false);
5813
+ * ```
5814
+ */
5815
+ setTrackingAvailable(trackingAvailable) {
5816
+ this.carrierData.tracking_available = trackingAvailable;
5817
+ return this;
5818
+ }
5819
+ /**
5820
+ * Sets the shipping labels availability for the shipping carrier
5821
+ *
5822
+ * @param shippingLabelsAvailable - Shipping labels availability status
5823
+ * @returns The builder instance for method chaining
5824
+ *
5825
+ * @example
5826
+ * ```typescript
5827
+ * carrier.setShippingLabelsAvailable(true);
5828
+ * carrier.setShippingLabelsAvailable(false);
5829
+ * ```
5830
+ */
5831
+ setShippingLabelsAvailable(shippingLabelsAvailable) {
5832
+ this.carrierData.shipping_labels_available = shippingLabelsAvailable;
5833
+ return this;
5834
+ }
5835
+ /**
5836
+ * Sets the carrier data from a ShippingCarrierData object
5837
+ *
5838
+ * @param carrierData - Carrier data object
5839
+ * @returns The builder instance for method chaining
5840
+ *
5841
+ * @example
5842
+ * ```typescript
5843
+ * carrier.setData({
5844
+ * code: 'fedex',
5845
+ * title: 'FedEx Express',
5846
+ * stores: ['default'],
5847
+ * countries: ['US', 'CA'],
5848
+ * sort_order: 10,
5849
+ * active: true,
5850
+ * tracking_available: true,
5851
+ * shipping_labels_available: true
5852
+ * });
5853
+ * ```
5854
+ */
5855
+ setData(carrierData) {
5856
+ this.validateCarrierCode(carrierData.code);
5857
+ this.carrierData = { ...carrierData };
5858
+ return this;
5859
+ }
5860
+ /**
5861
+ * Adds a shipping method to the carrier using a callback pattern
5862
+ *
5863
+ * @param method - Unique method for the shipping rate
5864
+ * @param callback - Optional callback function to configure the method
5865
+ * @returns The builder instance for method chaining
5866
+ *
5867
+ * @example
5868
+ * ```typescript
5869
+ * builder.addMethod('standard', (method) => {
5870
+ * method.setMethodTitle('Standard Shipping')
5871
+ * .setPrice(9.99)
5872
+ * .setCost(5.00)
5873
+ * .addAdditionalData('delivery_time', '3-5 business days');
5874
+ * });
5875
+ * ```
5876
+ */
5877
+ addMethod(method, callback) {
5878
+ this.validateMethodCode(method);
5879
+ const methodBuilder = new method_default(this.carrierData.code, method);
5880
+ if (callback) {
5881
+ callback(methodBuilder);
5882
+ }
5883
+ this.addedMethods.push(methodBuilder.getData());
5884
+ return this;
5885
+ }
5886
+ /**
5887
+ * Removes a shipping method from the carrier
5888
+ *
5889
+ * @param method - Method code to remove
5890
+ * @returns The builder instance for method chaining
5891
+ *
5892
+ * @example
5893
+ * ```typescript
5894
+ * builder.removeMethod('express');
5895
+ * ```
5896
+ */
5897
+ removeMethod(method) {
5898
+ this.validateMethodCode(method);
5899
+ this.removedMethods.push(method);
5900
+ return this;
5901
+ }
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
+ /**
5934
+ * Gets and returns the shipping carrier data as a JSON object
5935
+ *
5936
+ * @returns The shipping carrier data
5937
+ *
5938
+ * @example
5939
+ * ```typescript
5940
+ * const carrierData = carrier.getData();
5941
+ * // Returns:
5942
+ * // {
5943
+ * // code: 'DPS',
5944
+ * // title: 'Demo Postal Service',
5945
+ * // stores: ['default'],
5946
+ * // countries: ['US', 'CA'],
5947
+ * // sort_order: 10,
5948
+ * // active: true,
5949
+ * // tracking_available: true,
5950
+ * // shipping_labels_available: true
5951
+ * // }
5952
+ * ```
5953
+ */
5954
+ getData() {
5955
+ return this.carrierData;
5956
+ }
5957
+ };
5958
+ __name(_ShippingCarrier, "ShippingCarrier");
5959
+ var ShippingCarrier = _ShippingCarrier;
5960
+ var shipping_carrier_default = ShippingCarrier;
5961
+
5962
+ // src/commerce/shipping-carrier/response/index.ts
5963
+ var _ShippingCarrierResponse = class _ShippingCarrierResponse {
5964
+ constructor(carrier) {
5965
+ this.carrier = carrier;
5966
+ }
5967
+ /**
5968
+ * Generates and returns an array of WebhookActionResponse operations
5969
+ *
5970
+ * @returns Array of WebhookActionResponse operations
5971
+ *
5972
+ * @example
5973
+ * ```typescript
5974
+ * const carrier = new ShippingCarrier('fedex');
5975
+ * const response = new ShippingCarrierResponse(carrier);
5976
+ * const operations = response.generate();
5977
+ * ```
5978
+ */
5979
+ generate() {
5980
+ const operations = [];
5981
+ const addedMethods = this.carrier["addedMethods"];
5982
+ for (const method of addedMethods) {
5983
+ operations.push(response_default2.add("result", method));
5984
+ }
5985
+ const removedMethods = this.carrier["removedMethods"];
5986
+ for (const method of removedMethods) {
5987
+ operations.push(response_default2.add("result", { method, remove: true }));
5988
+ }
5989
+ return operations;
5990
+ }
5991
+ };
5992
+ __name(_ShippingCarrierResponse, "ShippingCarrierResponse");
5993
+ var ShippingCarrierResponse = _ShippingCarrierResponse;
5994
+ var response_default3 = ShippingCarrierResponse;
5995
+
5300
5996
  // src/experience/admin-ui-sdk/index.ts
5301
5997
  var _AdminUiSdk = class _AdminUiSdk {
5302
5998
  /**
@@ -5487,6 +6183,13 @@ var AdminUiSdk = _AdminUiSdk;
5487
6183
  RestClient,
5488
6184
  RuntimeAction,
5489
6185
  RuntimeActionResponse,
5490
- Validator
6186
+ ShippingCarrier,
6187
+ ShippingCarrierMethod,
6188
+ ShippingCarrierResponse,
6189
+ SignatureVerification,
6190
+ Validator,
6191
+ WebhookAction,
6192
+ WebhookActionOperation,
6193
+ WebhookActionResponse
5491
6194
  });
5492
6195
  //# sourceMappingURL=index.js.map