@bagisto-native/core 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +156 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bagisto-native/core",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Hotwire Web Components for any JS framework (React, Next.js, Vue, etc.)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
package/readme.md ADDED
@@ -0,0 +1,156 @@
1
+ # @bagisto-native/core
2
+
3
+ `@bagisto-native/core` is the **foundation module for Bagisto Native**, enabling seamless communication between **web applications** and **native applications** using **Hotwire technology**.
4
+
5
+ It is built to work seamlessly with [**Open Source Headless eCommerce**](https://bagisto.com/en/headless-ecommerce/
6
+ ), and any React.js/Next.js setup allowing developers to connect a headless storefront with native mobile apps.
7
+
8
+ This module provides:
9
+
10
+ - Core **Web Components** for native interaction
11
+ - Hotwire **bridge bundle (`bundle.js`)**
12
+ - Utility functions for **web ↔ native communication**
13
+
14
+
15
+ > **Note:** To create **Bagisto Headless Commerce**, use the following command:
16
+ >
17
+ > ```bash
18
+ > npx -y @bagisto-headless/create your-storefront
19
+ > ```
20
+
21
+
22
+
23
+ ## 📦 Installation
24
+
25
+ Install the module via npm:
26
+
27
+ ```bash
28
+ npm install @bagisto-native/core
29
+ ```
30
+
31
+ > **Note:** This module must be used alongside `@bagisto-native/react` if you're using React/Next.js.
32
+
33
+
34
+ ## 🛠️ Setup
35
+
36
+ ### 1. Add the Hotwire Bridge Bundle
37
+
38
+ The Hotwire bridge bundle (`bundle.js`) is required for native communication.
39
+
40
+ **Steps:**
41
+
42
+ 1. Navigate to `node_modules/@bagisto-native/core/public`
43
+ 2. Copy `bundle.js`
44
+ 3. Paste it into your project's `public` directory
45
+ 4. Include it in your HTML:
46
+
47
+ ```html
48
+ <script src="/bundle.js"></script>
49
+ ```
50
+ 5. Or, include this as a static script in Next.js or similar frameworks.
51
+
52
+
53
+ ## 🌐 Web Components
54
+
55
+ `@bagisto-native/core` provides the following **Web Components**:
56
+
57
+ | Component | Description |
58
+ | -------------------- | ----------------------------------------------------------------- |
59
+ | `DynamicButton` | Handles native buttons for cart, share, barcode, and image search |
60
+ | `HotwireToast` | Trigger native toast messages |
61
+ | `HotwireSearch` | Trigger native search events |
62
+ | `HotwireLocation` | Auto-fill checkout address using native location |
63
+ | `HotwireHistorySync` | Send current page URL to native apps |
64
+ | `HotwireThemeMode` | Send current theme mode (light/dark) |
65
+
66
+ > These components are primarily used in web projects but are wrapped by React components in `@bagisto-native/react`.
67
+
68
+
69
+ ## ⚡ Utility Functions
70
+
71
+ `@bagisto-native/core` provides several **helper functions**:
72
+
73
+ ### `triggerHotwireNativeToast(message: string)`
74
+
75
+ Trigger a native toast message:
76
+
77
+ ```ts
78
+ import { triggerHotwireNativeToast } from "@bagisto-native/core";
79
+
80
+ triggerHotwireNativeToast("Hello World!");
81
+ ```
82
+
83
+
84
+ ### `triggerHistorySyncEvent(url: URL)`
85
+
86
+ Send the current URL to the native app:
87
+
88
+ ```ts
89
+ import { triggerHistorySyncEvent } from "@bagisto-native/core";
90
+
91
+ const url = new URL(window.location.href);
92
+ triggerHistorySyncEvent(url);
93
+ ```
94
+
95
+
96
+ ### `triggerThemeModeEvent(mode: "light" | "dark")`
97
+
98
+ Send the current theme mode:
99
+
100
+ ```ts
101
+ import { triggerThemeModeEvent } from "@bagisto-native/core";
102
+
103
+ triggerThemeModeEvent("light");
104
+ ```
105
+
106
+
107
+ ### `triggerCartCountValue(cartCount: number)`
108
+
109
+ Send the cart count to the native app:
110
+
111
+ ```ts
112
+ import { triggerCartCountValue } from "@bagisto-native/core";
113
+
114
+ triggerCartCountValue(3);
115
+ ```
116
+
117
+
118
+ ### `isTurboNativeUserAgent(userAgent?: string): boolean`
119
+
120
+ Check if the current environment is a Turbo Native app:
121
+
122
+ ```ts
123
+ import { isTurboNativeUserAgent } from "@bagisto-native/core";
124
+
125
+ // Client-side
126
+ if (isTurboNativeUserAgent()) {
127
+ console.log("Running in Turbo Native");
128
+ }
129
+
130
+ // Server-side
131
+ isTurboNativeUserAgent(req.headers['user-agent']);
132
+
133
+ ```
134
+
135
+ ## Build the Native iOS App
136
+
137
+ After completing the setup of **Bagisto Native**, you can proceed to build the native iOS application using the official open-source repository.
138
+
139
+ 🔗 Bagisto Native iOS App:
140
+ https://github.com/SocialMobikul/BagistoNative_iOS
141
+
142
+
143
+ ## 📋 Requirements
144
+
145
+ * Node.js >= 18
146
+ * Works with any web project; for React/Next.js, use `@bagisto-native/react` for wrappers
147
+
148
+
149
+ ## 🆘 Support
150
+
151
+ Open an issue or discussion in the repository if you need help.
152
+
153
+
154
+ ## 📄 License
155
+
156
+ MIT License