@cshah18/sdk 1.0.0 → 2.0.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/README.md +21 -0
- package/dist/cobuy-sdk.esm.js +8581 -697
- package/dist/cobuy-sdk.esm.js.map +1 -1
- package/dist/cobuy-sdk.umd.js +8589 -699
- package/dist/cobuy-sdk.umd.js.map +1 -1
- package/dist/types/core/api-client.d.ts +74 -5
- package/dist/types/core/auth-strategy.d.ts +55 -0
- package/dist/types/core/cobuy.d.ts +42 -1
- package/dist/types/core/endpoints.d.ts +7 -23
- package/dist/types/core/socket-client.d.ts +126 -0
- package/dist/types/core/socket.d.ts +51 -0
- package/dist/types/core/types.d.ts +301 -5
- package/dist/types/index.d.ts +2 -0
- package/dist/types/ui/group-list/group-list-modal.d.ts +61 -0
- package/dist/types/ui/lobby/lobby-modal.d.ts +257 -0
- package/dist/types/ui/widget/widget-root.d.ts +62 -22
- package/package.json +12 -2
|
@@ -16,7 +16,44 @@ export declare class WidgetRoot {
|
|
|
16
16
|
private currentProductId;
|
|
17
17
|
private currentContainer;
|
|
18
18
|
private debouncedCTAClick;
|
|
19
|
+
private currentGroupData;
|
|
20
|
+
private groupFulfilled;
|
|
21
|
+
private frozenReward;
|
|
22
|
+
private currentGroupId;
|
|
23
|
+
private currentSessionId;
|
|
24
|
+
private currentRewardData;
|
|
25
|
+
private currentOptions;
|
|
26
|
+
private socketListenerRegistered;
|
|
27
|
+
private realtimeRefreshInFlight;
|
|
28
|
+
private groupListModal;
|
|
29
|
+
private lastGroupDataRefreshTime;
|
|
30
|
+
private readonly GROUP_REFRESH_DEBOUNCE;
|
|
19
31
|
constructor(config: InternalConfig, apiClient: ApiClient | null, analyticsClient?: AnalyticsClient | null);
|
|
32
|
+
/** Subscribe once to backend socket events routed through the host page */
|
|
33
|
+
private subscribeToSocketEvents;
|
|
34
|
+
/** Handle backend fulfillment notifications */
|
|
35
|
+
private handleGroupFulfilledEvent;
|
|
36
|
+
/** Handle realtime group creation/join events by refreshing group UI */
|
|
37
|
+
private handleGroupUpdatedEvent;
|
|
38
|
+
/** Fetch latest group data and re-render containers */
|
|
39
|
+
private refreshGroupDataFromRealtime;
|
|
40
|
+
/** Update widget and any external containers after realtime refresh */
|
|
41
|
+
private refreshRenderedContainers;
|
|
42
|
+
/** Persist fulfilled state, emit callback, and refresh UI */
|
|
43
|
+
private processGroupFulfilled;
|
|
44
|
+
/** Re-render widget and external containers to reflect fulfillment */
|
|
45
|
+
private renderFulfilledState;
|
|
46
|
+
/** Render group info element with progress and countdown */
|
|
47
|
+
private renderGroupInfo;
|
|
48
|
+
/** Render fulfilled summary card when the group is complete */
|
|
49
|
+
private renderFulfilledSummary;
|
|
50
|
+
/** Update countdown text */
|
|
51
|
+
private updateTimer;
|
|
52
|
+
/** Build and attach the shared "View all Groups" link section */
|
|
53
|
+
/** Create inline View all Groups link for placement inside group container */
|
|
54
|
+
private createInlineViewAllLink;
|
|
55
|
+
/** Lazily create/reuse the group list modal instance */
|
|
56
|
+
private getGroupListModal;
|
|
20
57
|
/**
|
|
21
58
|
* Render the widget into the specified container
|
|
22
59
|
*/
|
|
@@ -29,35 +66,26 @@ export declare class WidgetRoot {
|
|
|
29
66
|
* Fetch reward data for a product
|
|
30
67
|
*/
|
|
31
68
|
private fetchReward;
|
|
32
|
-
/**
|
|
33
|
-
* Fetch widget configuration from API
|
|
34
|
-
*
|
|
35
|
-
* NOTE: This endpoint is currently NOT USED in the SDK implementation.
|
|
36
|
-
* It is reserved for future enhancements such as:
|
|
37
|
-
* - Server-side control of widget display settings (show/hide elements)
|
|
38
|
-
* - Per-merchant feature flags (enable/disable social sharing, group creation)
|
|
39
|
-
* - Group size requirements and timeout configurations
|
|
40
|
-
* - Modal layout and behavior customization
|
|
41
|
-
* - A/B testing and dynamic theming
|
|
42
|
-
*
|
|
43
|
-
* For now, widget behavior is controlled by:
|
|
44
|
-
* 1. Merchant's init() options (theme, debug)
|
|
45
|
-
* 2. Reward data from /v1/sdk/products/:productId/reward
|
|
46
|
-
*
|
|
47
|
-
* This method is kept for future integration when modal group lobby,
|
|
48
|
-
* social sharing, and advanced customization features are implemented.
|
|
49
|
-
*
|
|
50
|
-
* @future Will be activated in modal implementation (post-SCRUM-248)
|
|
51
|
-
*/
|
|
52
|
-
private fetchWidgetConfig;
|
|
53
69
|
/**
|
|
54
70
|
* Resolve container from string selector or HTMLElement
|
|
55
71
|
*/
|
|
56
72
|
private resolveContainer;
|
|
57
73
|
/**
|
|
58
|
-
* Render skeleton loading state with animated shimmer effect
|
|
74
|
+
* Render skeleton loading state with animated shimmer effect for widget
|
|
59
75
|
*/
|
|
60
76
|
private renderSkeleton;
|
|
77
|
+
/**
|
|
78
|
+
* Render skeleton loading state for group info in separate container
|
|
79
|
+
*/
|
|
80
|
+
private renderGroupSkeleton;
|
|
81
|
+
/**
|
|
82
|
+
* Render skeleton loading state for reward text in separate container
|
|
83
|
+
*/
|
|
84
|
+
private renderRewardSkeleton;
|
|
85
|
+
/**
|
|
86
|
+
* Fetch primary group info for a product
|
|
87
|
+
*/
|
|
88
|
+
private fetchPrimaryGroup;
|
|
61
89
|
/**
|
|
62
90
|
* Render error state with retry button
|
|
63
91
|
*/
|
|
@@ -75,5 +103,17 @@ export declare class WidgetRoot {
|
|
|
75
103
|
* Handle CTA button click with analytics and modal opening
|
|
76
104
|
*/
|
|
77
105
|
private handleCTAClick;
|
|
106
|
+
/**
|
|
107
|
+
* Emit checkout intent without performing navigation
|
|
108
|
+
*/
|
|
109
|
+
private handleContinueClick;
|
|
110
|
+
/**
|
|
111
|
+
* Set loading state on the CoBuy button
|
|
112
|
+
*/
|
|
113
|
+
private setButtonLoadingState;
|
|
78
114
|
private formatRewardText;
|
|
115
|
+
/**
|
|
116
|
+
* Format reward text for rendering in external container
|
|
117
|
+
*/
|
|
118
|
+
private formatRewardForContainer;
|
|
79
119
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cshah18/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "CoBuy Embedded SDK for browser JavaScript integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/cobuy-sdk.umd.js",
|
|
@@ -14,7 +14,11 @@
|
|
|
14
14
|
"build:watch": "rollup -c -w",
|
|
15
15
|
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
|
16
16
|
"lint:fix": "eslint \"src/**/*.{ts,tsx}\" --fix",
|
|
17
|
-
"check": "npm run lint && tsc --noEmit"
|
|
17
|
+
"check": "npm run lint && tsc --noEmit",
|
|
18
|
+
"version:patch": "grunt bump:patch",
|
|
19
|
+
"version:minor": "grunt bump:minor",
|
|
20
|
+
"version:major": "grunt bump:major",
|
|
21
|
+
"version:prerelease": "grunt bump:prerelease"
|
|
18
22
|
},
|
|
19
23
|
"keywords": [
|
|
20
24
|
"cobuy",
|
|
@@ -24,6 +28,9 @@
|
|
|
24
28
|
],
|
|
25
29
|
"author": "CoBuy",
|
|
26
30
|
"license": "MIT",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"socket.io-client": "^4.7.5"
|
|
33
|
+
},
|
|
27
34
|
"devDependencies": {
|
|
28
35
|
"@eslint/js": "^9.0.0",
|
|
29
36
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
@@ -34,8 +41,11 @@
|
|
|
34
41
|
"eslint": "^9.0.0",
|
|
35
42
|
"eslint-config-prettier": "^10.0.0",
|
|
36
43
|
"eslint-plugin-import": "^2.32.0",
|
|
44
|
+
"grunt": "^1.6.1",
|
|
45
|
+
"grunt-bump": "^0.8.0",
|
|
37
46
|
"prettier": "^3.7.4",
|
|
38
47
|
"rollup": "^4.9.4",
|
|
48
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
39
49
|
"tslib": "^2.6.2",
|
|
40
50
|
"typescript": "^5.3.3"
|
|
41
51
|
}
|