@cshah18/sdk 3.0.0 → 3.0.2
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 +320 -40
- package/dist/cobuy-sdk.esm.js.map +1 -1
- package/dist/cobuy-sdk.umd.js +320 -40
- package/dist/cobuy-sdk.umd.js.map +1 -1
- package/dist/types/core/api-client.d.ts +36 -1
- package/dist/types/core/cobuy.d.ts +54 -1
- package/dist/types/core/endpoints.d.ts +3 -0
- package/dist/types/core/types.d.ts +43 -8
- package/dist/types/ui/lobby/lobby-modal.d.ts +1 -2
- package/dist/types/ui/widget/widget-root.d.ts +2 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiRequestOptions, ApiResponse, ApiClientConfig, ProductRewardData, ProductPrimaryGroupData, GroupJoinResponseData, GroupInviteResponseData, AuthStrategy, ShareChannel, Contact } from "./types";
|
|
1
|
+
import { ApiRequestOptions, ApiResponse, ApiClientConfig, ProductRewardData, ProductPrimaryGroupData, GroupJoinResponseData, GroupInviteResponseData, AuthStrategy, ShareChannel, Contact, CheckoutValidationData } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* HTTP client for communicating with CoBuy API
|
|
4
4
|
*
|
|
@@ -124,4 +124,39 @@ export declare class ApiClient {
|
|
|
124
124
|
* @returns Promise with success status
|
|
125
125
|
*/
|
|
126
126
|
setContact(contact: Contact): Promise<ApiResponse<void>>;
|
|
127
|
+
/**
|
|
128
|
+
* Prepare checkout for a group
|
|
129
|
+
*
|
|
130
|
+
* Signals the backend that the user is proceeding to checkout for a specific group.
|
|
131
|
+
* This allows the backend to prepare order data, lock pricing, and track conversion.
|
|
132
|
+
* Returns a checkout reference to be used in subsequent validate and confirm calls.
|
|
133
|
+
*
|
|
134
|
+
* @param groupId - The group ID to prepare checkout for
|
|
135
|
+
* @returns Promise with success status and checkout reference
|
|
136
|
+
*/
|
|
137
|
+
prepareCheckout(groupId: string): Promise<ApiResponse<{
|
|
138
|
+
checkout_ref: string;
|
|
139
|
+
}>>;
|
|
140
|
+
/**
|
|
141
|
+
* Validate checkout for a group
|
|
142
|
+
*
|
|
143
|
+
* Validates the checkout reference and confirms the order can proceed.
|
|
144
|
+
* This should be called after prepareCheckout to verify the checkout state.
|
|
145
|
+
*
|
|
146
|
+
* @param groupId - The group ID to validate checkout for
|
|
147
|
+
* @param checkoutRef - The checkout reference ID from the prepare step
|
|
148
|
+
* @returns Promise with success status
|
|
149
|
+
*/
|
|
150
|
+
validateCheckout(groupId: string, checkoutRef: string): Promise<ApiResponse<CheckoutValidationData>>;
|
|
151
|
+
/**
|
|
152
|
+
* Confirm checkout for a group
|
|
153
|
+
*
|
|
154
|
+
* Finalizes the checkout and confirms the order.
|
|
155
|
+
* This should be called after validateCheckout to complete the checkout process.
|
|
156
|
+
*
|
|
157
|
+
* @param groupId - The group ID to confirm checkout for
|
|
158
|
+
* @param checkoutRef - The checkout reference ID from the prepare step
|
|
159
|
+
* @returns Promise with success status
|
|
160
|
+
*/
|
|
161
|
+
confirmCheckout(groupId: string, checkoutRef: string): Promise<ApiResponse<void>>;
|
|
127
162
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoBuySDK, CoBuyInitOptions, RenderWidgetOptions, ModalOptions, Contact } from "./types";
|
|
1
|
+
import { CoBuySDK, CoBuyInitOptions, RenderWidgetOptions, ModalOptions, Contact, CheckoutValidationData } from "./types";
|
|
2
2
|
import { ApiClient } from "./api-client";
|
|
3
3
|
import { AnalyticsClient } from "./analytics";
|
|
4
4
|
import { SocketManager } from "./socket";
|
|
@@ -12,6 +12,7 @@ export declare class CoBuy implements CoBuySDK {
|
|
|
12
12
|
private analyticsClient;
|
|
13
13
|
private sessionId;
|
|
14
14
|
private readonly SESSION_STORAGE_KEY;
|
|
15
|
+
private readonly CHECKOUT_REF_PREFIX;
|
|
15
16
|
private lobbyModal;
|
|
16
17
|
private modals;
|
|
17
18
|
private socketManager;
|
|
@@ -24,10 +25,30 @@ export declare class CoBuy implements CoBuySDK {
|
|
|
24
25
|
* Generate UUID v4 compatible ID
|
|
25
26
|
*/
|
|
26
27
|
private generateUUID;
|
|
28
|
+
/**
|
|
29
|
+
* Store checkout reference for a product/group (session-level)
|
|
30
|
+
* Storage key format: cobuy_checkout_ref_<sessionId>_<productId>_<groupId>
|
|
31
|
+
*/
|
|
32
|
+
private storeCheckoutRef;
|
|
33
|
+
/**
|
|
34
|
+
* Retrieve checkout reference for a product/group (session-level)
|
|
35
|
+
* If groupId provided, try exact match first; otherwise fall back to any key for that product
|
|
36
|
+
* Returns both the matched storage key and the checkout reference value (or null if not found)
|
|
37
|
+
*/
|
|
38
|
+
getCheckoutRef(productId: string, groupId?: string): {
|
|
39
|
+
key: string | null;
|
|
40
|
+
checkoutRef: string | null;
|
|
41
|
+
groupId: string | null;
|
|
42
|
+
};
|
|
27
43
|
/**
|
|
28
44
|
* Get the current session ID (core SDK concept)
|
|
29
45
|
*/
|
|
30
46
|
getSessionId(): string;
|
|
47
|
+
/**
|
|
48
|
+
* Prepare checkout for a group if not already prepared
|
|
49
|
+
* Checks localStorage to prevent duplicate calls for the same product/group/session
|
|
50
|
+
*/
|
|
51
|
+
private prepareCheckoutIfNotDone;
|
|
31
52
|
/**
|
|
32
53
|
* Initialize the SDK with configuration
|
|
33
54
|
*/
|
|
@@ -73,6 +94,38 @@ export declare class CoBuy implements CoBuySDK {
|
|
|
73
94
|
* ```
|
|
74
95
|
*/
|
|
75
96
|
setContact(contact: Contact): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Validate checkout for a group
|
|
99
|
+
*
|
|
100
|
+
* Validates the checkout reference and confirms the order can proceed.
|
|
101
|
+
* Should be called after prepareCheckout to verify the checkout state.
|
|
102
|
+
*
|
|
103
|
+
* @param groupId - The group ID to validate checkout for
|
|
104
|
+
* @param checkoutRef - The checkout reference ID from the prepare step
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* // Validate checkout for a group
|
|
109
|
+
* await CoBuy.validateCheckout('fae238ae-7468-47e9-9eec-b6d52fe3b012', 'chk_9a6d8750-ed60-4795-a207-2abe955e8509');
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
validateCheckout(groupId: string, checkoutRef: string): Promise<CheckoutValidationData | null>;
|
|
113
|
+
/**
|
|
114
|
+
* Confirm checkout for a group
|
|
115
|
+
*
|
|
116
|
+
* Finalizes the checkout and confirms the order.
|
|
117
|
+
* Should be called after validateCheckout to complete the checkout process.
|
|
118
|
+
*
|
|
119
|
+
* @param groupId - The group ID to confirm checkout for
|
|
120
|
+
* @param checkoutRef - The checkout reference ID from the prepare step
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* // Confirm checkout for a group
|
|
125
|
+
* await CoBuy.confirmCheckout('fae238ae-7468-47e9-9eec-b6d52fe3b012', 'chk_9a6d8750-ed60-4795-a207-2abe955e8509');
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
confirmCheckout(groupId: string, checkoutRef: string): Promise<void>;
|
|
76
129
|
/**
|
|
77
130
|
* Get the initialized API client instance
|
|
78
131
|
*/
|
|
@@ -8,6 +8,9 @@ export declare const API_ENDPOINTS: {
|
|
|
8
8
|
readonly GROUP_CREATE_AND_JOIN: "/v1/sdk/groups/new/join";
|
|
9
9
|
readonly PRODUCT_ACTIVE_GROUPS: "/v1/sdk/products/:productId/groups/active";
|
|
10
10
|
readonly GROUP_INVITE: "/v1/sdk/groups/:groupId/invite";
|
|
11
|
+
readonly GROUP_CHECKOUT_PREPARE: "/v1/sdk/groups/:groupId/checkout/prepare";
|
|
12
|
+
readonly GROUP_CHECKOUT_VALIDATE: "/v1/sdk/groups/:groupId/checkout/validate";
|
|
13
|
+
readonly GROUP_CHECKOUT_CONFIRM: "/v1/sdk/groups/:groupId/checkout/confirm";
|
|
11
14
|
};
|
|
12
15
|
/**
|
|
13
16
|
* Build full API URL from base URL and endpoint path
|
|
@@ -146,6 +146,21 @@ export interface CheckoutData {
|
|
|
146
146
|
groupId: string;
|
|
147
147
|
productId: string;
|
|
148
148
|
}
|
|
149
|
+
export interface CheckoutValidationReward {
|
|
150
|
+
reward: Reward;
|
|
151
|
+
group_id: string;
|
|
152
|
+
product_id: string;
|
|
153
|
+
frozen_at?: string;
|
|
154
|
+
eligibility?: {
|
|
155
|
+
isEligible: boolean;
|
|
156
|
+
reason?: string;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export interface CheckoutValidationData {
|
|
160
|
+
approved: boolean;
|
|
161
|
+
reward?: CheckoutValidationReward;
|
|
162
|
+
message?: string;
|
|
163
|
+
}
|
|
149
164
|
/**
|
|
150
165
|
* Socket payload emitted when a group reaches fulfillment
|
|
151
166
|
*/
|
|
@@ -168,15 +183,10 @@ export interface GroupCreatedEvent {
|
|
|
168
183
|
}
|
|
169
184
|
/**
|
|
170
185
|
* Socket payload emitted when a member joins a group
|
|
186
|
+
* Matches the backend `group:member:joined` event structure.
|
|
187
|
+
* Reuses `GroupJoinResponseData` for strong typing.
|
|
171
188
|
*/
|
|
172
|
-
export
|
|
173
|
-
groupId: string;
|
|
174
|
-
productId: string;
|
|
175
|
-
memberId: string;
|
|
176
|
-
memberCount: number;
|
|
177
|
-
maxParticipants?: number;
|
|
178
|
-
timestamp?: string;
|
|
179
|
-
}
|
|
189
|
+
export type GroupMemberJoinedEvent = GroupJoinResponseData;
|
|
180
190
|
/**
|
|
181
191
|
* Payload emitted when shopper opts to continue to checkout
|
|
182
192
|
*/
|
|
@@ -510,6 +520,31 @@ export interface CoBuySDK {
|
|
|
510
520
|
* @param _contact Contact information (email or phone)
|
|
511
521
|
*/
|
|
512
522
|
setContact(_contact: Contact): Promise<void>;
|
|
523
|
+
/**
|
|
524
|
+
* Validate checkout for a group
|
|
525
|
+
* Validates the checkout reference and confirms the order can proceed
|
|
526
|
+
* @param _groupId The group ID to validate checkout for
|
|
527
|
+
* @param _checkoutRef The checkout reference ID from the prepare step
|
|
528
|
+
*/
|
|
529
|
+
validateCheckout(_groupId: string, _checkoutRef: string): Promise<CheckoutValidationData | null>;
|
|
530
|
+
/**
|
|
531
|
+
* Confirm checkout for a group
|
|
532
|
+
* Finalizes the checkout and confirms the order
|
|
533
|
+
* @param _groupId The group ID to confirm checkout for
|
|
534
|
+
* @param _checkoutRef The checkout reference ID from the prepare step
|
|
535
|
+
*/
|
|
536
|
+
confirmCheckout(_groupId: string, _checkoutRef: string): Promise<void>;
|
|
537
|
+
/**
|
|
538
|
+
* Retrieve stored checkout reference for a product in this session
|
|
539
|
+
* Returns both the storage key and value; key/value null if not found or storage unavailable
|
|
540
|
+
* @param _productId Product ID
|
|
541
|
+
* @param _groupId (optional) Group ID; exact match tried first, then product prefix fallback
|
|
542
|
+
*/
|
|
543
|
+
getCheckoutRef(_productId: string, _groupId?: string): {
|
|
544
|
+
key: string | null;
|
|
545
|
+
checkoutRef: string | null;
|
|
546
|
+
groupId: string | null;
|
|
547
|
+
};
|
|
513
548
|
/**
|
|
514
549
|
* SDK version
|
|
515
550
|
*/
|
|
@@ -235,9 +235,8 @@ export declare class LobbyModal {
|
|
|
235
235
|
*/
|
|
236
236
|
private subscribeToSocketEvents;
|
|
237
237
|
/**
|
|
238
|
-
* Unsubscribe from socket events
|
|
238
|
+
* Unsubscribe from socket events - testing out flow will remove once we have conviction
|
|
239
239
|
*/
|
|
240
|
-
private unsubscribeFromSocketEvents;
|
|
241
240
|
/**
|
|
242
241
|
* Handle socket group update events
|
|
243
242
|
*/
|
|
@@ -28,6 +28,7 @@ export declare class WidgetRoot {
|
|
|
28
28
|
private groupListModal;
|
|
29
29
|
private lastGroupDataRefreshTime;
|
|
30
30
|
private readonly GROUP_REFRESH_DEBOUNCE;
|
|
31
|
+
private groupExpiryRefreshTriggered;
|
|
31
32
|
constructor(config: InternalConfig, apiClient: ApiClient | null, analyticsClient?: AnalyticsClient | null);
|
|
32
33
|
/** Subscribe once to backend socket events routed through the host page */
|
|
33
34
|
private subscribeToSocketEvents;
|
|
@@ -47,7 +48,7 @@ export declare class WidgetRoot {
|
|
|
47
48
|
private renderGroupInfo;
|
|
48
49
|
/** Render fulfilled summary card when the group is complete */
|
|
49
50
|
private renderFulfilledSummary;
|
|
50
|
-
/** Update countdown text */
|
|
51
|
+
/** Update countdown text and trigger refresh when group expires */
|
|
51
52
|
private updateTimer;
|
|
52
53
|
/** Build and attach the shared "View all Groups" link section */
|
|
53
54
|
/** Create inline View all Groups link for placement inside group container */
|