@cshah18/sdk 1.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.
@@ -0,0 +1,79 @@
1
+ import { InternalConfig, RenderWidgetOptions } from "../../core/types";
2
+ import { ApiClient } from "../../core/api-client";
3
+ import { AnalyticsClient } from "../../core/analytics";
4
+ /**
5
+ * WidgetRoot handles rendering of the CoBuy widget into a DOM container
6
+ */
7
+ export declare class WidgetRoot {
8
+ private logger;
9
+ private apiClient;
10
+ private analyticsClient;
11
+ private config;
12
+ private events?;
13
+ private state;
14
+ private retryCount;
15
+ private readonly MAX_RETRIES;
16
+ private currentProductId;
17
+ private currentContainer;
18
+ private debouncedCTAClick;
19
+ constructor(config: InternalConfig, apiClient: ApiClient | null, analyticsClient?: AnalyticsClient | null);
20
+ /**
21
+ * Render the widget into the specified container
22
+ */
23
+ render(options: RenderWidgetOptions): Promise<void>;
24
+ /**
25
+ * Fetch reward data with automatic retry on failure
26
+ */
27
+ private fetchRewardWithRetry;
28
+ /**
29
+ * Fetch reward data for a product
30
+ */
31
+ 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
+ /**
54
+ * Resolve container from string selector or HTMLElement
55
+ */
56
+ private resolveContainer;
57
+ /**
58
+ * Render skeleton loading state with animated shimmer effect
59
+ */
60
+ private renderSkeleton;
61
+ /**
62
+ * Render error state with retry button
63
+ */
64
+ private renderError;
65
+ /**
66
+ * Handle retry button click - reset retry count and re-fetch
67
+ */
68
+ private handleRetry;
69
+ private createWidget;
70
+ /**
71
+ * Inject base layout styles for responsive widget rendering
72
+ */
73
+ private injectBaseStyles;
74
+ /**
75
+ * Handle CTA button click with analytics and modal opening
76
+ */
77
+ private handleCTAClick;
78
+ private formatRewardText;
79
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@cshah18/sdk",
3
+ "version": "1.0.0",
4
+ "description": "CoBuy Embedded SDK for browser JavaScript integration",
5
+ "type": "module",
6
+ "main": "dist/cobuy-sdk.umd.js",
7
+ "module": "dist/cobuy-sdk.esm.js",
8
+ "types": "dist/types/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "rollup -c",
14
+ "build:watch": "rollup -c -w",
15
+ "lint": "eslint \"src/**/*.{ts,tsx}\"",
16
+ "lint:fix": "eslint \"src/**/*.{ts,tsx}\" --fix",
17
+ "check": "npm run lint && tsc --noEmit"
18
+ },
19
+ "keywords": [
20
+ "cobuy",
21
+ "sdk",
22
+ "browser",
23
+ "embedded"
24
+ ],
25
+ "author": "CoBuy",
26
+ "license": "MIT",
27
+ "devDependencies": {
28
+ "@eslint/js": "^9.0.0",
29
+ "@rollup/plugin-commonjs": "^25.0.7",
30
+ "@rollup/plugin-node-resolve": "^15.2.3",
31
+ "@rollup/plugin-typescript": "^11.1.6",
32
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
33
+ "@typescript-eslint/parser": "^8.0.0",
34
+ "eslint": "^9.0.0",
35
+ "eslint-config-prettier": "^10.0.0",
36
+ "eslint-plugin-import": "^2.32.0",
37
+ "prettier": "^3.7.4",
38
+ "rollup": "^4.9.4",
39
+ "tslib": "^2.6.2",
40
+ "typescript": "^5.3.3"
41
+ }
42
+ }