@cshah18/sdk 4.11.0 → 4.13.0

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.
@@ -5998,6 +5998,8 @@ const API_ENDPOINTS = {
5998
5998
  GROUP_CHECKOUT_PREPARE: "/v1/sdk/groups/:groupId/checkout/prepare",
5999
5999
  GROUP_CHECKOUT_VALIDATE: "/v1/sdk/groups/:groupId/checkout/validate",
6000
6000
  GROUP_CHECKOUT_CONFIRM: "/v1/sdk/groups/:groupId/checkout/confirm",
6001
+ // Invite endpoints
6002
+ INVITE_RESOLVE: "/v1/sdk/invite/resolve",
6001
6003
  };
6002
6004
  /**
6003
6005
  * Build full API URL from base URL and endpoint path
@@ -6808,6 +6810,58 @@ class ApiClient {
6808
6810
  },
6809
6811
  };
6810
6812
  }
6813
+ /**
6814
+ * Resolve an invite token to get product and group information
6815
+ *
6816
+ * Resolves an invite link token (e.g., from https://brand.cobuyza.co.za/i/QMeHD7ew)
6817
+ * to get the associated product, group, and invite metadata.
6818
+ *
6819
+ * @param {string} inviteToken - The invite token from the URL
6820
+ * @returns {Promise<ApiResponse<InviteResolveResponseData>>} Product and group information
6821
+ *
6822
+ * @description
6823
+ * Features:
6824
+ * - Resolves invite tokens to product/group details
6825
+ * - Tracks invite click counts
6826
+ * - Returns invite metadata (shared_via, click_count)
6827
+ * - Used for invite link handling in applications
6828
+ *
6829
+ * @example
6830
+ * ```typescript
6831
+ * // Resolve invite token from URL
6832
+ * const response = await client.resolveInvite('QMeHD7ew');
6833
+ *
6834
+ * if (response.success) {
6835
+ * const productId = response.data.product.id;
6836
+ * const groupId = response.data.group.id;
6837
+ * // Navigate to product page
6838
+ * window.location.href = `/product/${productId}`;
6839
+ * }
6840
+ * ```
6841
+ */
6842
+ async resolveInvite(inviteToken) {
6843
+ const endpoint = buildApiUrl("", API_ENDPOINTS.INVITE_RESOLVE, undefined, {
6844
+ invite_token: inviteToken,
6845
+ });
6846
+ this.logger.info(`Resolving invite token: ${inviteToken}`);
6847
+ const response = await this.get(endpoint);
6848
+ if (response.success) {
6849
+ const payload = response.data;
6850
+ const inviteData = ((payload === null || payload === void 0 ? void 0 : payload.data) || response.data);
6851
+ this.logger.info(`Invite resolved successfully for product: ${inviteData.product.id}`);
6852
+ return {
6853
+ success: true,
6854
+ data: inviteData,
6855
+ };
6856
+ }
6857
+ return {
6858
+ success: false,
6859
+ error: response.error || {
6860
+ message: "Failed to resolve invite",
6861
+ code: "INVITE_RESOLVE_ERROR",
6862
+ },
6863
+ };
6864
+ }
6811
6865
  /**
6812
6866
  * Set or update contact information for the current session
6813
6867
  *
@@ -12914,6 +12968,63 @@ class CoBuy {
12914
12968
  this.logger.error("Error setting contact information", error);
12915
12969
  }
12916
12970
  }
12971
+ /**
12972
+ * Resolve an invite token to get product and group information
12973
+ *
12974
+ * Resolves an invite link token (e.g., from https://brand.cobuyza.co.za/i/QMeHD7ew)
12975
+ * to get the associated product, group, and invite metadata. Use this to handle
12976
+ * invite links in your application routing.
12977
+ *
12978
+ * @param inviteToken - The invite token from the URL
12979
+ * @returns Promise with invite resolution data or null if failed
12980
+ *
12981
+ * @example
12982
+ * ```typescript
12983
+ * // Extract token from URL path like /i/QMeHD7ew
12984
+ * const pathParts = window.location.pathname.split('/i/');
12985
+ * if (pathParts.length > 1) {
12986
+ * const inviteToken = pathParts[1];
12987
+ * const inviteData = await CoBuy.resolveInvite(inviteToken);
12988
+ *
12989
+ * if (inviteData) {
12990
+ * // Navigate to product page
12991
+ * window.location.href = `/product/${inviteData.product.id}`;
12992
+ * }
12993
+ * }
12994
+ * ```
12995
+ */
12996
+ async resolveInvite(inviteToken) {
12997
+ if (!this.configManager.isInitialized()) {
12998
+ this.logger.warn("SDK not initialized, cannot resolve invite");
12999
+ return null;
13000
+ }
13001
+ if (!this.apiClient) {
13002
+ this.logger.error("API client not available");
13003
+ return null;
13004
+ }
13005
+ if (!inviteToken || typeof inviteToken !== "string" || inviteToken.trim() === "") {
13006
+ this.logger.error("Invalid invite token provided");
13007
+ return null;
13008
+ }
13009
+ try {
13010
+ const response = await this.apiClient.resolveInvite(inviteToken.trim());
13011
+ if (response.success && response.data) {
13012
+ this.logger.info(`Invite resolved successfully: product=${response.data.product.id}, group=${response.data.group.id}`);
13013
+ return response.data;
13014
+ }
13015
+ else {
13016
+ if (this.handleFraudError(response.error, "resolveInvite")) {
13017
+ return null;
13018
+ }
13019
+ this.logger.error("Failed to resolve invite", response.error);
13020
+ return null;
13021
+ }
13022
+ }
13023
+ catch (error) {
13024
+ this.logger.error("Error resolving invite", error);
13025
+ return null;
13026
+ }
13027
+ }
12917
13028
  /**
12918
13029
  * Validate checkout for a group
12919
13030
  *