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