@encorekit/web-sdk 0.1.0 → 0.1.5
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 +16 -9
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/umd/encore.min.js +1 -1
- package/dist/umd/encore.min.js.map +1 -1
- package/examples/README.md +149 -0
- package/examples/angular/README.md +210 -0
- package/examples/angular/angular.json +73 -0
- package/examples/angular/package.json +32 -0
- package/examples/angular/src/app/app.component.html +56 -0
- package/examples/angular/src/app/app.component.ts +114 -0
- package/examples/angular/src/app/encore.service.ts +83 -0
- package/examples/angular/src/index.html +13 -0
- package/examples/angular/src/main.ts +7 -0
- package/examples/angular/src/styles.css +225 -0
- package/examples/angular/tsconfig.json +33 -0
- package/examples/react/README.md +186 -0
- package/examples/react/index.html +13 -0
- package/examples/react/package.json +24 -0
- package/examples/react/src/App.tsx +173 -0
- package/examples/react/src/index.css +227 -0
- package/examples/react/src/main.tsx +11 -0
- package/examples/react/src/vite-env.d.ts +2 -0
- package/examples/react/tsconfig.json +25 -0
- package/examples/react/vite.config.ts +8 -0
- package/examples/svelte/README.md +233 -0
- package/examples/svelte/index.html +13 -0
- package/examples/svelte/package.json +25 -0
- package/examples/svelte/src/App.svelte +164 -0
- package/examples/svelte/src/app.css +224 -0
- package/examples/svelte/src/main.ts +9 -0
- package/examples/svelte/src/vite-env.d.ts +3 -0
- package/examples/svelte/svelte.config.js +8 -0
- package/examples/svelte/tsconfig.json +16 -0
- package/examples/svelte/tsconfig.node.json +11 -0
- package/examples/svelte/vite.config.ts +8 -0
- package/examples/vanilla-js/README.md +271 -0
- package/examples/vanilla-js/index.html +421 -0
- package/examples/vue/README.md +212 -0
- package/examples/vue/index.html +13 -0
- package/examples/vue/package.json +22 -0
- package/examples/vue/src/App.vue +170 -0
- package/examples/vue/src/main.ts +6 -0
- package/examples/vue/src/style.css +224 -0
- package/examples/vue/src/vite-env.d.ts +2 -0
- package/examples/vue/tsconfig.json +25 -0
- package/examples/vue/vite.config.ts +8 -0
- package/package.json +15 -2
- package/types/api/APIClient.d.ts.map +1 -1
- package/types/api/models.d.ts +6 -4
- package/types/api/models.d.ts.map +1 -1
- package/types/core/Encore.d.ts +12 -12
- package/types/core/Encore.d.ts.map +1 -1
- package/types/core/EntitlementManager.d.ts +9 -0
- package/types/core/EntitlementManager.d.ts.map +1 -1
- package/types/types.d.ts.map +1 -1
- package/types/ui/OfferCard.d.ts.map +1 -1
- package/types/ui/OfferCarousel.d.ts.map +1 -1
- package/types/ui/Tooltip.d.ts +22 -0
- package/types/ui/Tooltip.d.ts.map +1 -0
- package/types/ui/styles.d.ts.map +1 -1
- package/dist/cjs/index.js +0 -2
- package/dist/cjs/index.js.map +0 -1
- package/types/src/api/APIClient.d.ts +0 -63
- package/types/src/api/APIClient.d.ts.map +0 -1
- package/types/src/api/endpoints.d.ts +0 -35
- package/types/src/api/endpoints.d.ts.map +0 -1
- package/types/src/api/models.d.ts +0 -156
- package/types/src/api/models.d.ts.map +0 -1
- package/types/src/core/Configuration.d.ts +0 -42
- package/types/src/core/Configuration.d.ts.map +0 -1
- package/types/src/core/Encore.d.ts +0 -81
- package/types/src/core/Encore.d.ts.map +0 -1
- package/types/src/core/EntitlementManager.d.ts +0 -65
- package/types/src/core/EntitlementManager.d.ts.map +0 -1
- package/types/src/core/OfferManager.d.ts +0 -35
- package/types/src/core/OfferManager.d.ts.map +0 -1
- package/types/src/core/PlacementBuilder.d.ts +0 -27
- package/types/src/core/PlacementBuilder.d.ts.map +0 -1
- package/types/src/core/SignalManager.d.ts +0 -51
- package/types/src/core/SignalManager.d.ts.map +0 -1
- package/types/src/core/StorageManager.d.ts +0 -34
- package/types/src/core/StorageManager.d.ts.map +0 -1
- package/types/src/core/VerificationPoller.d.ts +0 -27
- package/types/src/core/VerificationPoller.d.ts.map +0 -1
- package/types/src/index.d.ts +0 -7
- package/types/src/index.d.ts.map +0 -1
- package/types/src/types.d.ts +0 -156
- package/types/src/types.d.ts.map +0 -1
- package/types/src/ui/OfferCard.d.ts +0 -29
- package/types/src/ui/OfferCard.d.ts.map +0 -1
- package/types/src/ui/OfferCarousel.d.ts +0 -55
- package/types/src/ui/OfferCarousel.d.ts.map +0 -1
- package/types/src/ui/OfferModal.d.ts +0 -41
- package/types/src/ui/OfferModal.d.ts.map +0 -1
- package/types/src/ui/SuccessScreen.d.ts +0 -33
- package/types/src/ui/SuccessScreen.d.ts.map +0 -1
- package/types/src/ui/styles.d.ts +0 -44
- package/types/src/ui/styles.d.ts.map +0 -1
- package/types/src/utils/eventEmitter.d.ts +0 -50
- package/types/src/utils/eventEmitter.d.ts.map +0 -1
- package/types/src/utils/focusDetection.d.ts +0 -21
- package/types/src/utils/focusDetection.d.ts.map +0 -1
- package/types/src/utils/logger.d.ts +0 -21
- package/types/src/utils/logger.d.ts.map +0 -1
- package/types/src/utils/network.d.ts +0 -57
- package/types/src/utils/network.d.ts.map +0 -1
- package/types/src/utils/uuid.d.ts +0 -10
- package/types/src/utils/uuid.d.ts.map +0 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# Encore SDK - Svelte Example
|
|
2
|
+
|
|
3
|
+
This example demonstrates how to integrate the Encore Web SDK into a Svelte 4 application using Vite and TypeScript.
|
|
4
|
+
|
|
5
|
+
## 🚀 Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install dependencies
|
|
9
|
+
npm install
|
|
10
|
+
|
|
11
|
+
# Start development server
|
|
12
|
+
npm run dev
|
|
13
|
+
|
|
14
|
+
# Build for production
|
|
15
|
+
npm run build
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The app will be available at `http://localhost:5173`
|
|
19
|
+
|
|
20
|
+
## 📁 Project Structure
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
svelte/
|
|
24
|
+
├── src/
|
|
25
|
+
│ ├── App.svelte # Main application component
|
|
26
|
+
│ ├── main.ts # Application entry point
|
|
27
|
+
│ ├── app.css # Global styles
|
|
28
|
+
│ └── vite-env.d.ts # Vite type definitions
|
|
29
|
+
├── index.html # HTML template
|
|
30
|
+
├── package.json # Dependencies and scripts
|
|
31
|
+
├── tsconfig.json # TypeScript configuration
|
|
32
|
+
├── svelte.config.js # Svelte configuration
|
|
33
|
+
└── vite.config.ts # Vite configuration
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 🔑 Configuration
|
|
37
|
+
|
|
38
|
+
Before running the example, replace `'YOUR_API_KEY_HERE'` in `src/App.svelte` with your actual Encore API key:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
Encore.configure({
|
|
42
|
+
apiKey: 'YOUR_API_KEY_HERE', // Get this from dashboard.encorekit.com
|
|
43
|
+
environment: 'production',
|
|
44
|
+
logLevel: 'debug',
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 🎯 Features Demonstrated
|
|
49
|
+
|
|
50
|
+
### 1. SDK Initialization
|
|
51
|
+
The SDK is initialized when the component mounts using `onMount`:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { onMount } from 'svelte';
|
|
55
|
+
import Encore from '@encorekit/web-sdk';
|
|
56
|
+
|
|
57
|
+
onMount(() => {
|
|
58
|
+
Encore.configure({
|
|
59
|
+
apiKey: 'YOUR_API_KEY_HERE',
|
|
60
|
+
environment: 'production',
|
|
61
|
+
logLevel: 'debug',
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const currentUserId = Encore.getCurrentUserId();
|
|
65
|
+
userId = currentUserId || '';
|
|
66
|
+
isInitialized = true;
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 2. Reactive Variables
|
|
71
|
+
Svelte's reactive declarations automatically update the UI:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
let isInitialized = false;
|
|
75
|
+
let userId = '';
|
|
76
|
+
let customUserId = '';
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 3. Two-Way Data Binding
|
|
80
|
+
Svelte's `bind:value` directive:
|
|
81
|
+
|
|
82
|
+
```svelte
|
|
83
|
+
<input bind:value={customUserId} />
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 4. User Identification
|
|
87
|
+
Users can be identified with custom IDs and attributes:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
function handleIdentifyUser() {
|
|
91
|
+
Encore.identify(customUserId, {
|
|
92
|
+
email: 'user@example.com',
|
|
93
|
+
});
|
|
94
|
+
userId = customUserId;
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 5. Presenting Offers
|
|
99
|
+
Display targeted offers to users:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
async function handlePresentOffer() {
|
|
103
|
+
const result = await Encore.presentOffer();
|
|
104
|
+
|
|
105
|
+
if (result.granted) {
|
|
106
|
+
console.log('Offer granted!');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## 🏗️ Svelte Patterns
|
|
112
|
+
|
|
113
|
+
This example uses Svelte best practices:
|
|
114
|
+
|
|
115
|
+
- **Reactive Declarations** - Automatic UI updates when variables change
|
|
116
|
+
- **Lifecycle Hooks** - `onMount()` for initialization
|
|
117
|
+
- **Event Handlers** - `on:click` for user interactions
|
|
118
|
+
- **Conditional Rendering** - `{#if}` blocks for conditional display
|
|
119
|
+
- **Two-Way Binding** - `bind:value` for form inputs
|
|
120
|
+
- **TypeScript** - Full type safety with TypeScript
|
|
121
|
+
|
|
122
|
+
## 📦 Dependencies
|
|
123
|
+
|
|
124
|
+
- `svelte` ^4.2.12 - Svelte framework
|
|
125
|
+
- `@encorekit/web-sdk` ^0.2.0 - Encore Web SDK
|
|
126
|
+
- `vite` ^5.4.1 - Build tool and dev server
|
|
127
|
+
- `typescript` ^5.5.3 - TypeScript compiler
|
|
128
|
+
- `@sveltejs/vite-plugin-svelte` ^3.0.2 - Svelte plugin for Vite
|
|
129
|
+
|
|
130
|
+
## 🔧 Available Scripts
|
|
131
|
+
|
|
132
|
+
- `npm run dev` - Start development server with hot reload
|
|
133
|
+
- `npm run build` - Build for production
|
|
134
|
+
- `npm run preview` - Preview production build locally
|
|
135
|
+
- `npm run check` - Run Svelte type checking
|
|
136
|
+
|
|
137
|
+
## 💡 Best Practices
|
|
138
|
+
|
|
139
|
+
1. **Initialize Once** - Initialize the SDK in `onMount` lifecycle hook
|
|
140
|
+
2. **Error Handling** - Always wrap SDK calls in try-catch blocks
|
|
141
|
+
3. **Reactive State** - Use Svelte's reactive declarations for state management
|
|
142
|
+
4. **User Feedback** - Provide clear feedback for all SDK operations
|
|
143
|
+
5. **Environment Variables** - In production, use environment variables for the API key
|
|
144
|
+
6. **Type Safety** - Use TypeScript for better developer experience
|
|
145
|
+
|
|
146
|
+
## 🎨 Customization
|
|
147
|
+
|
|
148
|
+
### Using Environment Variables
|
|
149
|
+
|
|
150
|
+
Create a `.env` file:
|
|
151
|
+
|
|
152
|
+
```env
|
|
153
|
+
VITE_ENCORE_API_KEY=your-api-key-here
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Update `App.svelte`:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
Encore.configure({
|
|
160
|
+
apiKey: import.meta.env.VITE_ENCORE_API_KEY,
|
|
161
|
+
environment: 'production',
|
|
162
|
+
})
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Creating a Store
|
|
166
|
+
|
|
167
|
+
For better state management, create a Svelte store:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
// stores/encore.ts
|
|
171
|
+
import { writable } from 'svelte/store';
|
|
172
|
+
import Encore from '@encorekit/web-sdk';
|
|
173
|
+
|
|
174
|
+
function createEncoreStore() {
|
|
175
|
+
const { subscribe, set, update } = writable({
|
|
176
|
+
isInitialized: false,
|
|
177
|
+
userId: '',
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
subscribe,
|
|
182
|
+
initialize: (apiKey: string) => {
|
|
183
|
+
Encore.configure({ apiKey });
|
|
184
|
+
const userId = Encore.getCurrentUserId() || '';
|
|
185
|
+
set({ isInitialized: true, userId });
|
|
186
|
+
},
|
|
187
|
+
identify: (userId: string, attributes?: Record<string, any>) => {
|
|
188
|
+
Encore.identify(userId, attributes);
|
|
189
|
+
update(state => ({ ...state, userId }));
|
|
190
|
+
},
|
|
191
|
+
presentOffer: async () => {
|
|
192
|
+
return await Encore.presentOffer();
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export const encoreStore = createEncoreStore();
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Usage in component:
|
|
201
|
+
|
|
202
|
+
```svelte
|
|
203
|
+
<script lang="ts">
|
|
204
|
+
import { onMount } from 'svelte';
|
|
205
|
+
import { encoreStore } from './stores/encore';
|
|
206
|
+
|
|
207
|
+
onMount(() => {
|
|
208
|
+
encoreStore.initialize('YOUR_API_KEY');
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
async function handlePresentOffer() {
|
|
212
|
+
const result = await encoreStore.presentOffer();
|
|
213
|
+
}
|
|
214
|
+
</script>
|
|
215
|
+
|
|
216
|
+
<div>
|
|
217
|
+
User ID: {$encoreStore.userId}
|
|
218
|
+
</div>
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## 📚 Learn More
|
|
222
|
+
|
|
223
|
+
- [Encore SDK Documentation](https://docs.encorekit.com)
|
|
224
|
+
- [Svelte Documentation](https://svelte.dev)
|
|
225
|
+
- [SvelteKit Documentation](https://kit.svelte.dev)
|
|
226
|
+
- [Vite Documentation](https://vitejs.dev)
|
|
227
|
+
|
|
228
|
+
## 🆘 Support
|
|
229
|
+
|
|
230
|
+
- 📧 Email: admin@encorekit.com
|
|
231
|
+
- 📖 Docs: https://docs.encorekit.com
|
|
232
|
+
|
|
233
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Encore SDK - Svelte Example</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="app"></div>
|
|
10
|
+
<script type="module" src="/src/main.ts"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
13
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "encore-sdk-svelte-example",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Svelte example for Encore Web SDK",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"check": "svelte-check --tsconfig ./tsconfig.json"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@sveltejs/vite-plugin-svelte": "^3.0.2",
|
|
14
|
+
"@tsconfig/svelte": "^5.0.2",
|
|
15
|
+
"svelte": "^4.2.12",
|
|
16
|
+
"svelte-check": "^3.6.7",
|
|
17
|
+
"tslib": "^2.6.2",
|
|
18
|
+
"typescript": "^5.5.3",
|
|
19
|
+
"vite": "^5.4.1"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@encorekit/web-sdk": "^0.1.1"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from 'svelte';
|
|
3
|
+
import Encore from '@encorekit/web-sdk';
|
|
4
|
+
|
|
5
|
+
let isInitialized = false;
|
|
6
|
+
let userId = '';
|
|
7
|
+
let customUserId = '';
|
|
8
|
+
let status: { message: string; type: 'info' | 'success' | 'error' } | null = null;
|
|
9
|
+
|
|
10
|
+
const codeExample = `// Initialize SDK
|
|
11
|
+
Encore.configure({
|
|
12
|
+
apiKey: 'your-api-key',
|
|
13
|
+
userId: 'user-123',
|
|
14
|
+
environment: 'production',
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// Identify user
|
|
18
|
+
Encore.identify('user-123', {
|
|
19
|
+
email: 'user@example.com'
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
// Present offer
|
|
23
|
+
const result = await Encore.presentOffer()
|
|
24
|
+
if (result.granted) {
|
|
25
|
+
console.log('Offer granted!')
|
|
26
|
+
}`;
|
|
27
|
+
|
|
28
|
+
onMount(() => {
|
|
29
|
+
try {
|
|
30
|
+
Encore.configure({
|
|
31
|
+
apiKey: 'ENCORE_PUBLIC_API_KEY', // Replace with your actual API key
|
|
32
|
+
userId: 'test-svelte',
|
|
33
|
+
environment: 'production',
|
|
34
|
+
logLevel: 'debug',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const currentUserId = Encore.getCurrentUserId();
|
|
38
|
+
userId = currentUserId || '';
|
|
39
|
+
isInitialized = true;
|
|
40
|
+
status = {
|
|
41
|
+
message: 'Encore SDK initialized successfully!',
|
|
42
|
+
type: 'success',
|
|
43
|
+
};
|
|
44
|
+
} catch (error) {
|
|
45
|
+
status = {
|
|
46
|
+
message: `Failed to initialize SDK: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
47
|
+
type: 'error',
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function handleIdentifyUser() {
|
|
53
|
+
if (!customUserId.trim()) {
|
|
54
|
+
status = {
|
|
55
|
+
message: 'Please enter a user ID',
|
|
56
|
+
type: 'error',
|
|
57
|
+
};
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
Encore.identify(customUserId, {
|
|
63
|
+
email: 'user@example.com',
|
|
64
|
+
});
|
|
65
|
+
userId = customUserId;
|
|
66
|
+
status = {
|
|
67
|
+
message: `User identified as: ${customUserId}`,
|
|
68
|
+
type: 'success',
|
|
69
|
+
};
|
|
70
|
+
} catch (error) {
|
|
71
|
+
status = {
|
|
72
|
+
message: `Failed to identify user: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
73
|
+
type: 'error',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function handlePresentOffer() {
|
|
79
|
+
status = {
|
|
80
|
+
message: 'Presenting offer...',
|
|
81
|
+
type: 'info',
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const result = await Encore.presentOffer();
|
|
86
|
+
|
|
87
|
+
if (result.granted) {
|
|
88
|
+
status = {
|
|
89
|
+
message: 'Offer granted successfully!',
|
|
90
|
+
type: 'success',
|
|
91
|
+
};
|
|
92
|
+
} else {
|
|
93
|
+
status = {
|
|
94
|
+
message: `Offer not granted: ${JSON.stringify(result.reason)}`,
|
|
95
|
+
type: 'info',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
} catch (error) {
|
|
99
|
+
status = {
|
|
100
|
+
message: `Failed to present offer: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
101
|
+
type: 'error',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
</script>
|
|
106
|
+
|
|
107
|
+
<div class="app">
|
|
108
|
+
<h1>🎯 Encore SDK</h1>
|
|
109
|
+
<p>Svelte Example</p>
|
|
110
|
+
|
|
111
|
+
<div class="card">
|
|
112
|
+
<h2>SDK Status</h2>
|
|
113
|
+
<div class="user-info">
|
|
114
|
+
<strong>Status:</strong> {isInitialized ? '✓ Initialized' : '✗ Not Initialized'}
|
|
115
|
+
<br />
|
|
116
|
+
<strong>User ID:</strong> {userId || 'Not set'}
|
|
117
|
+
</div>
|
|
118
|
+
|
|
119
|
+
{#if status}
|
|
120
|
+
<div class="status {status.type}">
|
|
121
|
+
{status.message}
|
|
122
|
+
</div>
|
|
123
|
+
{/if}
|
|
124
|
+
</div>
|
|
125
|
+
|
|
126
|
+
<div class="card">
|
|
127
|
+
<h2>User Identification</h2>
|
|
128
|
+
<div class="input-group">
|
|
129
|
+
<label for="userId">Custom User ID:</label>
|
|
130
|
+
<input
|
|
131
|
+
id="userId"
|
|
132
|
+
type="text"
|
|
133
|
+
placeholder="Enter user ID (e.g., user-123)"
|
|
134
|
+
bind:value={customUserId}
|
|
135
|
+
disabled={!isInitialized}
|
|
136
|
+
/>
|
|
137
|
+
</div>
|
|
138
|
+
<button
|
|
139
|
+
on:click={handleIdentifyUser}
|
|
140
|
+
disabled={!isInitialized}
|
|
141
|
+
class="primary"
|
|
142
|
+
>
|
|
143
|
+
Identify User
|
|
144
|
+
</button>
|
|
145
|
+
</div>
|
|
146
|
+
|
|
147
|
+
<div class="card">
|
|
148
|
+
<h2>Present Offer</h2>
|
|
149
|
+
<p>Click the button below to display an offer to the user.</p>
|
|
150
|
+
<button
|
|
151
|
+
on:click={handlePresentOffer}
|
|
152
|
+
disabled={!isInitialized}
|
|
153
|
+
class="success"
|
|
154
|
+
>
|
|
155
|
+
🎁 Present Offer
|
|
156
|
+
</button>
|
|
157
|
+
</div>
|
|
158
|
+
|
|
159
|
+
<div class="card">
|
|
160
|
+
<h2>Code Example</h2>
|
|
161
|
+
<pre>{codeExample}</pre>
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
3
|
+
line-height: 1.5;
|
|
4
|
+
font-weight: 400;
|
|
5
|
+
|
|
6
|
+
color-scheme: light dark;
|
|
7
|
+
color: rgba(255, 255, 255, 0.87);
|
|
8
|
+
background-color: #242424;
|
|
9
|
+
|
|
10
|
+
font-synthesis: none;
|
|
11
|
+
text-rendering: optimizeLegibility;
|
|
12
|
+
-webkit-font-smoothing: antialiased;
|
|
13
|
+
-moz-osx-font-smoothing: grayscale;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
* {
|
|
17
|
+
margin: 0;
|
|
18
|
+
padding: 0;
|
|
19
|
+
box-sizing: border-box;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
body {
|
|
23
|
+
margin: 0;
|
|
24
|
+
display: flex;
|
|
25
|
+
place-items: center;
|
|
26
|
+
min-width: 320px;
|
|
27
|
+
min-height: 100vh;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#app {
|
|
31
|
+
width: 100%;
|
|
32
|
+
max-width: 1280px;
|
|
33
|
+
margin: 0 auto;
|
|
34
|
+
padding: 2rem;
|
|
35
|
+
text-align: center;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
h1 {
|
|
39
|
+
font-size: 3.2em;
|
|
40
|
+
line-height: 1.1;
|
|
41
|
+
margin-bottom: 1rem;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
h2 {
|
|
45
|
+
font-size: 1.8em;
|
|
46
|
+
margin-top: 2rem;
|
|
47
|
+
margin-bottom: 1rem;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.card {
|
|
51
|
+
padding: 2em;
|
|
52
|
+
background-color: #1a1a1a;
|
|
53
|
+
border-radius: 8px;
|
|
54
|
+
margin-bottom: 2rem;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.user-info {
|
|
58
|
+
margin: 1.5rem 0;
|
|
59
|
+
padding: 1rem;
|
|
60
|
+
background-color: #2a2a2a;
|
|
61
|
+
border-radius: 4px;
|
|
62
|
+
font-family: monospace;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.user-info strong {
|
|
66
|
+
color: #ff3e00;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.button-group {
|
|
70
|
+
display: flex;
|
|
71
|
+
gap: 1rem;
|
|
72
|
+
justify-content: center;
|
|
73
|
+
flex-wrap: wrap;
|
|
74
|
+
margin: 1.5rem 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
button {
|
|
78
|
+
border-radius: 8px;
|
|
79
|
+
border: 1px solid transparent;
|
|
80
|
+
padding: 0.6em 1.2em;
|
|
81
|
+
font-size: 1em;
|
|
82
|
+
font-weight: 500;
|
|
83
|
+
font-family: inherit;
|
|
84
|
+
background-color: #1a1a1a;
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
transition: border-color 0.25s;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
button:hover {
|
|
90
|
+
border-color: #ff3e00;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
button:focus,
|
|
94
|
+
button:focus-visible {
|
|
95
|
+
outline: 4px auto -webkit-focus-ring-color;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
button:disabled {
|
|
99
|
+
opacity: 0.5;
|
|
100
|
+
cursor: not-allowed;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
button:disabled:hover {
|
|
104
|
+
border-color: transparent;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.primary {
|
|
108
|
+
background-color: #ff3e00;
|
|
109
|
+
color: white;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.primary:hover {
|
|
113
|
+
background-color: #e63900;
|
|
114
|
+
border-color: #e63900;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.success {
|
|
118
|
+
background-color: #059669;
|
|
119
|
+
color: white;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.success:hover {
|
|
123
|
+
background-color: #047857;
|
|
124
|
+
border-color: #047857;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.status {
|
|
128
|
+
margin: 1rem 0;
|
|
129
|
+
padding: 0.8rem;
|
|
130
|
+
border-radius: 4px;
|
|
131
|
+
font-size: 0.9em;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.status.info {
|
|
135
|
+
background-color: #1e40af;
|
|
136
|
+
color: white;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.status.success {
|
|
140
|
+
background-color: #059669;
|
|
141
|
+
color: white;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.status.error {
|
|
145
|
+
background-color: #dc2626;
|
|
146
|
+
color: white;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.input-group {
|
|
150
|
+
margin: 1rem 0;
|
|
151
|
+
text-align: left;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.input-group label {
|
|
155
|
+
display: block;
|
|
156
|
+
margin-bottom: 0.5rem;
|
|
157
|
+
font-weight: 500;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.input-group input {
|
|
161
|
+
width: 100%;
|
|
162
|
+
padding: 0.6em;
|
|
163
|
+
border-radius: 4px;
|
|
164
|
+
border: 1px solid #444;
|
|
165
|
+
background-color: #1a1a1a;
|
|
166
|
+
color: inherit;
|
|
167
|
+
font-size: 1em;
|
|
168
|
+
font-family: inherit;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.input-group input:focus {
|
|
172
|
+
outline: 2px solid #ff3e00;
|
|
173
|
+
border-color: #ff3e00;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
code {
|
|
177
|
+
background-color: #2a2a2a;
|
|
178
|
+
padding: 0.2em 0.4em;
|
|
179
|
+
border-radius: 3px;
|
|
180
|
+
font-family: monospace;
|
|
181
|
+
font-size: 0.9em;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
pre {
|
|
185
|
+
text-align: left;
|
|
186
|
+
background-color: #1a1a1a;
|
|
187
|
+
padding: 1rem;
|
|
188
|
+
border-radius: 4px;
|
|
189
|
+
overflow-x: auto;
|
|
190
|
+
margin: 1rem 0;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@media (prefers-color-scheme: light) {
|
|
194
|
+
:root {
|
|
195
|
+
color: #213547;
|
|
196
|
+
background-color: #ffffff;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
button {
|
|
200
|
+
background-color: #f9f9f9;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.card {
|
|
204
|
+
background-color: #f9f9f9;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.user-info {
|
|
208
|
+
background-color: #efefef;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.input-group input {
|
|
212
|
+
background-color: #ffffff;
|
|
213
|
+
border-color: #ccc;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
code {
|
|
217
|
+
background-color: #efefef;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
pre {
|
|
221
|
+
background-color: #f5f5f5;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@tsconfig/svelte/tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"useDefineForClassFields": true,
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"resolveJsonModule": true,
|
|
8
|
+
"allowJs": true,
|
|
9
|
+
"checkJs": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"moduleDetection": "force"
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
|
|
14
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
15
|
+
}
|
|
16
|
+
|