@encorekit/web-sdk 0.1.1 → 0.1.7

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 (134) hide show
  1. package/README.md +94 -9
  2. package/dist/cjs/index.cjs +1 -1
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/esm/index.js +1 -1
  5. package/dist/esm/index.js.map +1 -1
  6. package/dist/umd/encore.min.js +1 -1
  7. package/dist/umd/encore.min.js.map +1 -1
  8. package/embed/README.md +409 -0
  9. package/embed/index.html +57 -0
  10. package/embed/styles.css +154 -0
  11. package/examples/README.md +149 -0
  12. package/examples/angular/README.md +210 -0
  13. package/examples/angular/angular.json +73 -0
  14. package/examples/angular/package.json +32 -0
  15. package/examples/angular/src/app/app.component.html +56 -0
  16. package/examples/angular/src/app/app.component.ts +114 -0
  17. package/examples/angular/src/app/encore.service.ts +83 -0
  18. package/examples/angular/src/index.html +13 -0
  19. package/examples/angular/src/main.ts +7 -0
  20. package/examples/angular/src/styles.css +225 -0
  21. package/examples/angular/tsconfig.json +33 -0
  22. package/examples/ios-webview/EncoreURLBuilder.swift +87 -0
  23. package/examples/ios-webview/EncoreWebViewBridge.swift +426 -0
  24. package/examples/ios-webview/ExampleViewController.swift +233 -0
  25. package/examples/ios-webview/README.md +416 -0
  26. package/examples/ios-webview/SimpleEncoreView.swift +94 -0
  27. package/examples/ios-webview/SimpleExample.swift +131 -0
  28. package/examples/react/README.md +186 -0
  29. package/examples/react/index.html +13 -0
  30. package/examples/react/package.json +24 -0
  31. package/examples/react/src/App.tsx +173 -0
  32. package/examples/react/src/index.css +227 -0
  33. package/examples/react/src/main.tsx +11 -0
  34. package/examples/react/src/vite-env.d.ts +2 -0
  35. package/examples/react/tsconfig.json +25 -0
  36. package/examples/react/vite.config.ts +8 -0
  37. package/examples/svelte/README.md +233 -0
  38. package/examples/svelte/index.html +13 -0
  39. package/examples/svelte/package.json +25 -0
  40. package/examples/svelte/src/App.svelte +164 -0
  41. package/examples/svelte/src/app.css +224 -0
  42. package/examples/svelte/src/main.ts +9 -0
  43. package/examples/svelte/src/vite-env.d.ts +3 -0
  44. package/examples/svelte/svelte.config.js +8 -0
  45. package/examples/svelte/tsconfig.json +16 -0
  46. package/examples/svelte/tsconfig.node.json +11 -0
  47. package/examples/svelte/vite.config.ts +8 -0
  48. package/examples/vanilla-js/README.md +271 -0
  49. package/examples/vanilla-js/index.html +421 -0
  50. package/examples/vue/README.md +212 -0
  51. package/examples/vue/index.html +13 -0
  52. package/examples/vue/package.json +22 -0
  53. package/examples/vue/src/App.vue +170 -0
  54. package/examples/vue/src/main.ts +6 -0
  55. package/examples/vue/src/style.css +224 -0
  56. package/examples/vue/src/vite-env.d.ts +2 -0
  57. package/examples/vue/tsconfig.json +25 -0
  58. package/examples/vue/vite.config.ts +8 -0
  59. package/package.json +22 -3
  60. package/types/analytics/AnalyticsClient.d.ts +14 -0
  61. package/types/analytics/AnalyticsClient.d.ts.map +1 -0
  62. package/types/analytics/events.d.ts +63 -0
  63. package/types/analytics/events.d.ts.map +1 -0
  64. package/types/analytics/models.d.ts +17 -0
  65. package/types/analytics/models.d.ts.map +1 -0
  66. package/types/api/APIClient.d.ts +44 -8
  67. package/types/api/APIClient.d.ts.map +1 -1
  68. package/types/api/endpoints.d.ts +11 -7
  69. package/types/api/endpoints.d.ts.map +1 -1
  70. package/types/api/models.d.ts +134 -68
  71. package/types/api/models.d.ts.map +1 -1
  72. package/types/core/Configuration.d.ts +4 -0
  73. package/types/core/Configuration.d.ts.map +1 -1
  74. package/types/core/Encore.d.ts +16 -12
  75. package/types/core/Encore.d.ts.map +1 -1
  76. package/types/core/EntitlementManager.d.ts +9 -0
  77. package/types/core/EntitlementManager.d.ts.map +1 -1
  78. package/types/core/OfferManager.d.ts +27 -7
  79. package/types/core/OfferManager.d.ts.map +1 -1
  80. package/types/types.d.ts +1 -1
  81. package/types/types.d.ts.map +1 -1
  82. package/types/ui/OfferCard.d.ts.map +1 -1
  83. package/types/ui/OfferCarousel.d.ts.map +1 -1
  84. package/types/ui/Tooltip.d.ts +22 -0
  85. package/types/ui/Tooltip.d.ts.map +1 -0
  86. package/types/ui/styles.d.ts.map +1 -1
  87. package/dist/cjs/index.js +0 -2
  88. package/dist/cjs/index.js.map +0 -1
  89. package/types/src/api/APIClient.d.ts +0 -63
  90. package/types/src/api/APIClient.d.ts.map +0 -1
  91. package/types/src/api/endpoints.d.ts +0 -35
  92. package/types/src/api/endpoints.d.ts.map +0 -1
  93. package/types/src/api/models.d.ts +0 -156
  94. package/types/src/api/models.d.ts.map +0 -1
  95. package/types/src/core/Configuration.d.ts +0 -42
  96. package/types/src/core/Configuration.d.ts.map +0 -1
  97. package/types/src/core/Encore.d.ts +0 -81
  98. package/types/src/core/Encore.d.ts.map +0 -1
  99. package/types/src/core/EntitlementManager.d.ts +0 -65
  100. package/types/src/core/EntitlementManager.d.ts.map +0 -1
  101. package/types/src/core/OfferManager.d.ts +0 -35
  102. package/types/src/core/OfferManager.d.ts.map +0 -1
  103. package/types/src/core/PlacementBuilder.d.ts +0 -27
  104. package/types/src/core/PlacementBuilder.d.ts.map +0 -1
  105. package/types/src/core/SignalManager.d.ts +0 -51
  106. package/types/src/core/SignalManager.d.ts.map +0 -1
  107. package/types/src/core/StorageManager.d.ts +0 -34
  108. package/types/src/core/StorageManager.d.ts.map +0 -1
  109. package/types/src/core/VerificationPoller.d.ts +0 -27
  110. package/types/src/core/VerificationPoller.d.ts.map +0 -1
  111. package/types/src/index.d.ts +0 -7
  112. package/types/src/index.d.ts.map +0 -1
  113. package/types/src/types.d.ts +0 -156
  114. package/types/src/types.d.ts.map +0 -1
  115. package/types/src/ui/OfferCard.d.ts +0 -29
  116. package/types/src/ui/OfferCard.d.ts.map +0 -1
  117. package/types/src/ui/OfferCarousel.d.ts +0 -55
  118. package/types/src/ui/OfferCarousel.d.ts.map +0 -1
  119. package/types/src/ui/OfferModal.d.ts +0 -41
  120. package/types/src/ui/OfferModal.d.ts.map +0 -1
  121. package/types/src/ui/SuccessScreen.d.ts +0 -33
  122. package/types/src/ui/SuccessScreen.d.ts.map +0 -1
  123. package/types/src/ui/styles.d.ts +0 -44
  124. package/types/src/ui/styles.d.ts.map +0 -1
  125. package/types/src/utils/eventEmitter.d.ts +0 -50
  126. package/types/src/utils/eventEmitter.d.ts.map +0 -1
  127. package/types/src/utils/focusDetection.d.ts +0 -21
  128. package/types/src/utils/focusDetection.d.ts.map +0 -1
  129. package/types/src/utils/logger.d.ts +0 -21
  130. package/types/src/utils/logger.d.ts.map +0 -1
  131. package/types/src/utils/network.d.ts +0 -57
  132. package/types/src/utils/network.d.ts.map +0 -1
  133. package/types/src/utils/uuid.d.ts +0 -10
  134. package/types/src/utils/uuid.d.ts.map +0 -1
@@ -0,0 +1,83 @@
1
+ import { Injectable } from '@angular/core';
2
+ import Encore from '@encorekit/web-sdk';
3
+
4
+ @Injectable({
5
+ providedIn: 'root'
6
+ })
7
+ export class EncoreService {
8
+ private isInitialized = false;
9
+
10
+ constructor() {}
11
+
12
+ /**
13
+ * Generate or retrieve user ID from storage
14
+ */
15
+ private generateUserId(): string {
16
+ const storageKey = 'encore_user_id';
17
+ let userId = localStorage.getItem(storageKey);
18
+
19
+ if (!userId) {
20
+ userId = 'user_' + Math.random().toString(36).substring(2, 15);
21
+ localStorage.setItem(storageKey, userId);
22
+ }
23
+
24
+ return userId;
25
+ }
26
+
27
+ /**
28
+ * Initialize the Encore SDK with specific user ID
29
+ */
30
+ initialize(apiKey: string, environment: 'production' | 'development' = 'production'): void {
31
+ try {
32
+ Encore.configure({
33
+ userId: 'test-angular',
34
+ apiKey,
35
+ environment,
36
+ logLevel: 'debug',
37
+ });
38
+ this.isInitialized = true;
39
+ } catch (error) {
40
+ console.error('Failed to initialize Encore SDK:', error);
41
+ throw error;
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Get current user ID
47
+ */
48
+ getCurrentUserId(): string | null {
49
+ if (!this.isInitialized) {
50
+ console.warn('Encore SDK not initialized');
51
+ return null;
52
+ }
53
+ return Encore.getCurrentUserId();
54
+ }
55
+
56
+ /**
57
+ * Identify user with custom ID and attributes
58
+ */
59
+ identify(userId: string, attributes?: Record<string, any>): void {
60
+ if (!this.isInitialized) {
61
+ throw new Error('Encore SDK not initialized');
62
+ }
63
+ Encore.identify(userId, attributes);
64
+ }
65
+
66
+ /**
67
+ * Present an offer to the user
68
+ */
69
+ async presentOffer(): Promise<any> {
70
+ if (!this.isInitialized) {
71
+ throw new Error('Encore SDK not initialized');
72
+ }
73
+ return await Encore.presentOffer();
74
+ }
75
+
76
+ /**
77
+ * Check if SDK is initialized
78
+ */
79
+ getIsInitialized(): boolean {
80
+ return this.isInitialized;
81
+ }
82
+ }
83
+
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Encore SDK - Angular Example</title>
6
+ <base href="/">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1">
8
+ </head>
9
+ <body>
10
+ <app-root></app-root>
11
+ </body>
12
+ </html>
13
+
@@ -0,0 +1,7 @@
1
+ import 'zone.js';
2
+ import { bootstrapApplication } from '@angular/platform-browser';
3
+ import { AppComponent } from './app/app.component';
4
+
5
+ bootstrapApplication(AppComponent)
6
+ .catch((err) => console.error(err));
7
+
@@ -0,0 +1,225 @@
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-root {
31
+ width: 100%;
32
+ max-width: 1280px;
33
+ margin: 0 auto;
34
+ padding: 2rem;
35
+ display: block;
36
+ text-align: center;
37
+ }
38
+
39
+ h1 {
40
+ font-size: 3.2em;
41
+ line-height: 1.1;
42
+ margin-bottom: 1rem;
43
+ }
44
+
45
+ h2 {
46
+ font-size: 1.8em;
47
+ margin-top: 2rem;
48
+ margin-bottom: 1rem;
49
+ }
50
+
51
+ .card {
52
+ padding: 2em;
53
+ background-color: #1a1a1a;
54
+ border-radius: 8px;
55
+ margin-bottom: 2rem;
56
+ }
57
+
58
+ .user-info {
59
+ margin: 1.5rem 0;
60
+ padding: 1rem;
61
+ background-color: #2a2a2a;
62
+ border-radius: 4px;
63
+ font-family: monospace;
64
+ }
65
+
66
+ .user-info strong {
67
+ color: #dd0031;
68
+ }
69
+
70
+ .button-group {
71
+ display: flex;
72
+ gap: 1rem;
73
+ justify-content: center;
74
+ flex-wrap: wrap;
75
+ margin: 1.5rem 0;
76
+ }
77
+
78
+ button {
79
+ border-radius: 8px;
80
+ border: 1px solid transparent;
81
+ padding: 0.6em 1.2em;
82
+ font-size: 1em;
83
+ font-weight: 500;
84
+ font-family: inherit;
85
+ background-color: #1a1a1a;
86
+ cursor: pointer;
87
+ transition: border-color 0.25s;
88
+ }
89
+
90
+ button:hover {
91
+ border-color: #dd0031;
92
+ }
93
+
94
+ button:focus,
95
+ button:focus-visible {
96
+ outline: 4px auto -webkit-focus-ring-color;
97
+ }
98
+
99
+ button:disabled {
100
+ opacity: 0.5;
101
+ cursor: not-allowed;
102
+ }
103
+
104
+ button:disabled:hover {
105
+ border-color: transparent;
106
+ }
107
+
108
+ .primary {
109
+ background-color: #dd0031;
110
+ color: white;
111
+ }
112
+
113
+ .primary:hover {
114
+ background-color: #c3002f;
115
+ border-color: #c3002f;
116
+ }
117
+
118
+ .success {
119
+ background-color: #059669;
120
+ color: white;
121
+ }
122
+
123
+ .success:hover {
124
+ background-color: #047857;
125
+ border-color: #047857;
126
+ }
127
+
128
+ .status {
129
+ margin: 1rem 0;
130
+ padding: 0.8rem;
131
+ border-radius: 4px;
132
+ font-size: 0.9em;
133
+ }
134
+
135
+ .status.info {
136
+ background-color: #1e40af;
137
+ color: white;
138
+ }
139
+
140
+ .status.success {
141
+ background-color: #059669;
142
+ color: white;
143
+ }
144
+
145
+ .status.error {
146
+ background-color: #dc2626;
147
+ color: white;
148
+ }
149
+
150
+ .input-group {
151
+ margin: 1rem 0;
152
+ text-align: left;
153
+ }
154
+
155
+ .input-group label {
156
+ display: block;
157
+ margin-bottom: 0.5rem;
158
+ font-weight: 500;
159
+ }
160
+
161
+ .input-group input {
162
+ width: 100%;
163
+ padding: 0.6em;
164
+ border-radius: 4px;
165
+ border: 1px solid #444;
166
+ background-color: #1a1a1a;
167
+ color: inherit;
168
+ font-size: 1em;
169
+ font-family: inherit;
170
+ }
171
+
172
+ .input-group input:focus {
173
+ outline: 2px solid #dd0031;
174
+ border-color: #dd0031;
175
+ }
176
+
177
+ code {
178
+ background-color: #2a2a2a;
179
+ padding: 0.2em 0.4em;
180
+ border-radius: 3px;
181
+ font-family: monospace;
182
+ font-size: 0.9em;
183
+ }
184
+
185
+ pre {
186
+ text-align: left;
187
+ background-color: #1a1a1a;
188
+ padding: 1rem;
189
+ border-radius: 4px;
190
+ overflow-x: auto;
191
+ margin: 1rem 0;
192
+ }
193
+
194
+ @media (prefers-color-scheme: light) {
195
+ :root {
196
+ color: #213547;
197
+ background-color: #ffffff;
198
+ }
199
+
200
+ button {
201
+ background-color: #f9f9f9;
202
+ }
203
+
204
+ .card {
205
+ background-color: #f9f9f9;
206
+ }
207
+
208
+ .user-info {
209
+ background-color: #efefef;
210
+ }
211
+
212
+ .input-group input {
213
+ background-color: #ffffff;
214
+ border-color: #ccc;
215
+ }
216
+
217
+ code {
218
+ background-color: #efefef;
219
+ }
220
+
221
+ pre {
222
+ background-color: #f5f5f5;
223
+ }
224
+ }
225
+
@@ -0,0 +1,33 @@
1
+ {
2
+ "compileOnSave": false,
3
+ "compilerOptions": {
4
+ "outDir": "./dist/out-tsc",
5
+ "forceConsistentCasingInFileNames": true,
6
+ "strict": true,
7
+ "noImplicitOverride": true,
8
+ "noPropertyAccessFromIndexSignature": true,
9
+ "noImplicitReturns": true,
10
+ "noFallthroughCasesInSwitch": true,
11
+ "skipLibCheck": true,
12
+ "esModuleInterop": true,
13
+ "sourceMap": true,
14
+ "declaration": false,
15
+ "experimentalDecorators": true,
16
+ "moduleResolution": "node",
17
+ "importHelpers": true,
18
+ "target": "ES2022",
19
+ "module": "ES2022",
20
+ "useDefineForClassFields": false,
21
+ "lib": [
22
+ "ES2022",
23
+ "dom"
24
+ ]
25
+ },
26
+ "angularCompilerOptions": {
27
+ "enableI18nLegacyMessageIdFormat": false,
28
+ "strictInjectionParameters": true,
29
+ "strictInputAccessModifiers": true,
30
+ "strictTemplates": true
31
+ }
32
+ }
33
+
@@ -0,0 +1,87 @@
1
+ //
2
+ // EncoreURLBuilder.swift
3
+ // Encore iOS Simple Integration
4
+ //
5
+ // Dead simple: Build a URL, open it in WKWebView. That's it.
6
+ //
7
+
8
+ import Foundation
9
+
10
+ /// Build Encore embed URLs with your configuration
11
+ public struct EncoreURL {
12
+
13
+ /// Build an Encore embed URL
14
+ /// - Parameters:
15
+ /// - apiKey: Your Encore API key
16
+ /// - userId: User identifier (optional)
17
+ /// - environment: "production" or "localhost" (default: "production")
18
+ /// - attributes: User attributes for targeting (optional)
19
+ /// - debug: Enable debug mode (default: false)
20
+ /// - Returns: URL to load in WKWebView
21
+ public static func build(
22
+ apiKey: String,
23
+ userId: String? = nil,
24
+ environment: String = "production",
25
+ attributes: [String: String]? = nil,
26
+ debug: Bool = false
27
+ ) -> URL? {
28
+ guard var components = URLComponents(string: "https://encorekit.com/embed/") else {
29
+ return nil
30
+ }
31
+
32
+ var queryItems: [URLQueryItem] = [
33
+ URLQueryItem(name: "apiKey", value: apiKey),
34
+ URLQueryItem(name: "environment", value: environment)
35
+ ]
36
+
37
+ if let userId = userId {
38
+ queryItems.append(URLQueryItem(name: "userId", value: userId))
39
+ }
40
+
41
+ if let attributes = attributes, !attributes.isEmpty {
42
+ // Encode attributes as JSON string
43
+ if let jsonData = try? JSONSerialization.data(withJSONObject: attributes),
44
+ let jsonString = String(data: jsonData, encoding: .utf8) {
45
+ queryItems.append(URLQueryItem(name: "attributes", value: jsonString))
46
+ }
47
+ }
48
+
49
+ if debug {
50
+ queryItems.append(URLQueryItem(name: "debug", value: "true"))
51
+ }
52
+
53
+ components.queryItems = queryItems
54
+ return components.url
55
+ }
56
+
57
+ /// Build URL for localhost testing
58
+ public static func buildLocal(
59
+ apiKey: String,
60
+ userId: String? = nil,
61
+ port: Int = 3001,
62
+ attributes: [String: String]? = nil
63
+ ) -> URL? {
64
+ var components = URLComponents(string: "http://localhost:\(port)/embed/")!
65
+
66
+ var queryItems: [URLQueryItem] = [
67
+ URLQueryItem(name: "apiKey", value: apiKey),
68
+ URLQueryItem(name: "environment", value: "localhost"),
69
+ URLQueryItem(name: "debug", value: "true")
70
+ ]
71
+
72
+ if let userId = userId {
73
+ queryItems.append(URLQueryItem(name: "userId", value: userId))
74
+ }
75
+
76
+ if let attributes = attributes, !attributes.isEmpty {
77
+ if let jsonData = try? JSONSerialization.data(withJSONObject: attributes),
78
+ let jsonString = String(data: jsonData, encoding: .utf8) {
79
+ queryItems.append(URLQueryItem(name: "attributes", value: jsonString))
80
+ }
81
+ }
82
+
83
+ components.queryItems = queryItems
84
+ return components.url
85
+ }
86
+ }
87
+