@encorekit/web-sdk 2.0.3 → 2.0.6
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 +112 -40
- 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/embed/README.md +82 -367
- package/examples/ios-webview/EncoreURLBuilder.swift +179 -61
- package/examples/ios-webview/README.md +75 -354
- package/examples/ios-webview/SimpleEncoreView.swift +49 -36
- package/examples/ios-webview/SimpleExample.swift +30 -86
- package/package.json +3 -7
- package/types/analytics/DiagnosticsOutbox.d.ts +22 -0
- package/types/analytics/DiagnosticsOutbox.d.ts.map +1 -0
- package/types/analytics/ReliableOutbox.d.ts +40 -0
- package/types/analytics/ReliableOutbox.d.ts.map +1 -0
- package/types/analytics/events.d.ts +100 -0
- package/types/analytics/events.d.ts.map +1 -1
- package/types/analytics/placementResolved.d.ts +150 -0
- package/types/analytics/placementResolved.d.ts.map +1 -0
- package/types/api/APIClient.d.ts +10 -2
- package/types/api/APIClient.d.ts.map +1 -1
- package/types/api/errorReportLimits.d.ts +50 -0
- package/types/api/errorReportLimits.d.ts.map +1 -0
- package/types/api/generated/types.d.ts +54 -7
- package/types/api/generated/types.d.ts.map +1 -1
- package/types/core/Configuration.d.ts +5 -0
- package/types/core/Configuration.d.ts.map +1 -1
- package/types/core/Encore.d.ts +61 -2
- package/types/core/Encore.d.ts.map +1 -1
- package/types/core/OfferManager.d.ts +29 -3
- package/types/core/OfferManager.d.ts.map +1 -1
- package/types/core/PlacementBuilder.d.ts +26 -2
- package/types/core/PlacementBuilder.d.ts.map +1 -1
- package/types/core/StrictUnlock.d.ts +20 -0
- package/types/core/StrictUnlock.d.ts.map +1 -0
- package/types/core/StrictUnlockReconciler.d.ts +94 -0
- package/types/core/StrictUnlockReconciler.d.ts.map +1 -0
- package/types/core/TransactionStore.d.ts +57 -13
- package/types/core/TransactionStore.d.ts.map +1 -1
- package/types/core/VerificationPoller.d.ts.map +1 -1
- package/types/core/claimBehavior.d.ts +28 -0
- package/types/core/claimBehavior.d.ts.map +1 -0
- package/types/core/errorContext.d.ts +18 -0
- package/types/core/errorContext.d.ts.map +1 -0
- package/types/core/errorType.d.ts +59 -0
- package/types/core/errorType.d.ts.map +1 -0
- package/types/core/hostDisplay.d.ts +50 -0
- package/types/core/hostDisplay.d.ts.map +1 -0
- package/types/core/useCase.d.ts +21 -0
- package/types/core/useCase.d.ts.map +1 -1
- package/types/core/version.d.ts +1 -1
- package/types/experiments/ExposureOutbox.d.ts +4 -28
- package/types/experiments/ExposureOutbox.d.ts.map +1 -1
- package/types/types.d.ts +188 -3
- package/types/types.d.ts.map +1 -1
- package/types/ui/OfferCard.d.ts +3 -1
- package/types/ui/OfferCard.d.ts.map +1 -1
- package/types/ui/OfferCarousel.d.ts +5 -0
- package/types/ui/OfferCarousel.d.ts.map +1 -1
- package/types/ui/OfferModal.d.ts +20 -0
- package/types/ui/OfferModal.d.ts.map +1 -1
- package/types/ui/PrimerScreen.d.ts +18 -11
- package/types/ui/PrimerScreen.d.ts.map +1 -1
- package/types/ui/RedemptionScreen.d.ts +15 -19
- package/types/ui/RedemptionScreen.d.ts.map +1 -1
- package/types/ui/RewardActions.d.ts +35 -0
- package/types/ui/RewardActions.d.ts.map +1 -1
- package/types/ui/appearance.d.ts +14 -0
- package/types/ui/appearance.d.ts.map +1 -1
- package/types/ui/brandComponents.d.ts.map +1 -1
- package/types/ui/styles.d.ts.map +1 -1
- package/types/utils/logger.d.ts +11 -1
- package/types/utils/logger.d.ts.map +1 -1
- package/embed/index.html +0 -57
- package/embed/styles.css +0 -154
- package/examples/ios-webview/EncoreWebViewBridge.swift +0 -419
- package/examples/ios-webview/ExampleViewController.swift +0 -233
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// ExampleViewController.swift
|
|
3
|
-
// Encore iOS WebView Example
|
|
4
|
-
//
|
|
5
|
-
// Example implementation showing how to integrate Encore via WKWebView
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import UIKit
|
|
9
|
-
import WebKit
|
|
10
|
-
|
|
11
|
-
class ExampleViewController: UIViewController {
|
|
12
|
-
|
|
13
|
-
// MARK: - Properties
|
|
14
|
-
|
|
15
|
-
private var encoreBridge: EncoreWebViewBridge!
|
|
16
|
-
private var webView: WKWebView!
|
|
17
|
-
|
|
18
|
-
// UI Elements
|
|
19
|
-
private let statusLabel: UILabel = {
|
|
20
|
-
let label = UILabel()
|
|
21
|
-
label.textAlignment = .center
|
|
22
|
-
label.numberOfLines = 0
|
|
23
|
-
label.font = .systemFont(ofSize: 14)
|
|
24
|
-
label.textColor = .secondaryLabel
|
|
25
|
-
label.text = "Initializing Encore..."
|
|
26
|
-
return label
|
|
27
|
-
}()
|
|
28
|
-
|
|
29
|
-
private let presentOfferButton: UIButton = {
|
|
30
|
-
let button = UIButton(type: .system)
|
|
31
|
-
button.setTitle("Present Offer", for: .normal)
|
|
32
|
-
button.titleLabel?.font = .systemFont(ofSize: 18, weight: .semibold)
|
|
33
|
-
button.backgroundColor = .systemBlue
|
|
34
|
-
button.setTitleColor(.white, for: .normal)
|
|
35
|
-
button.layer.cornerRadius = 12
|
|
36
|
-
button.isEnabled = false
|
|
37
|
-
return button
|
|
38
|
-
}()
|
|
39
|
-
|
|
40
|
-
private let resultLabel: UILabel = {
|
|
41
|
-
let label = UILabel()
|
|
42
|
-
label.textAlignment = .center
|
|
43
|
-
label.numberOfLines = 0
|
|
44
|
-
label.font = .systemFont(ofSize: 16, weight: .medium)
|
|
45
|
-
label.textColor = .label
|
|
46
|
-
label.text = ""
|
|
47
|
-
return label
|
|
48
|
-
}()
|
|
49
|
-
|
|
50
|
-
// MARK: - Lifecycle
|
|
51
|
-
|
|
52
|
-
override func viewDidLoad() {
|
|
53
|
-
super.viewDidLoad()
|
|
54
|
-
|
|
55
|
-
title = "Encore WebView Example"
|
|
56
|
-
view.backgroundColor = .systemBackground
|
|
57
|
-
|
|
58
|
-
setupEncoreBridge()
|
|
59
|
-
setupUI()
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// MARK: - Setup
|
|
63
|
-
|
|
64
|
-
private func setupEncoreBridge() {
|
|
65
|
-
// Create configuration
|
|
66
|
-
let config = EncoreConfiguration(
|
|
67
|
-
apiKey: "your_api_key_here", // Replace with your actual API key
|
|
68
|
-
environment: "production", // or "localhost" for testing
|
|
69
|
-
userId: "user_123", // Optional: your user's ID
|
|
70
|
-
attributes: [ // Optional: user attributes for targeting
|
|
71
|
-
"email": "user@example.com",
|
|
72
|
-
"subscriptionTier": "free"
|
|
73
|
-
]
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
// Initialize bridge
|
|
77
|
-
encoreBridge = EncoreWebViewBridge(configuration: config)
|
|
78
|
-
encoreBridge.delegate = self
|
|
79
|
-
|
|
80
|
-
// Setup webView
|
|
81
|
-
webView = encoreBridge.setupWebView()
|
|
82
|
-
|
|
83
|
-
// Add webView to view hierarchy (invisible)
|
|
84
|
-
webView.translatesAutoresizingMaskIntoConstraints = false
|
|
85
|
-
view.addSubview(webView)
|
|
86
|
-
|
|
87
|
-
NSLayoutConstraint.activate([
|
|
88
|
-
// Make webView fill the entire screen
|
|
89
|
-
webView.topAnchor.constraint(equalTo: view.topAnchor),
|
|
90
|
-
webView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
|
91
|
-
webView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
|
92
|
-
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
|
93
|
-
])
|
|
94
|
-
|
|
95
|
-
// Load the embed page
|
|
96
|
-
encoreBridge.loadEmbed()
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
private func setupUI() {
|
|
100
|
-
// Add UI elements on top of webView
|
|
101
|
-
let stackView = UIStackView(arrangedSubviews: [
|
|
102
|
-
statusLabel,
|
|
103
|
-
presentOfferButton,
|
|
104
|
-
resultLabel
|
|
105
|
-
])
|
|
106
|
-
stackView.axis = .vertical
|
|
107
|
-
stackView.spacing = 20
|
|
108
|
-
stackView.translatesAutoresizingMaskIntoConstraints = false
|
|
109
|
-
view.addSubview(stackView)
|
|
110
|
-
|
|
111
|
-
NSLayoutConstraint.activate([
|
|
112
|
-
stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
|
|
113
|
-
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 40),
|
|
114
|
-
stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -40),
|
|
115
|
-
|
|
116
|
-
presentOfferButton.heightAnchor.constraint(equalToConstant: 50)
|
|
117
|
-
])
|
|
118
|
-
|
|
119
|
-
presentOfferButton.addTarget(self, action: #selector(presentOfferTapped), for: .touchUpInside)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// MARK: - Actions
|
|
123
|
-
|
|
124
|
-
@objc private func presentOfferTapped() {
|
|
125
|
-
resultLabel.text = ""
|
|
126
|
-
encoreBridge.presentOffer()
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// MARK: - EncoreWebViewBridgeDelegate
|
|
131
|
-
|
|
132
|
-
extension ExampleViewController: EncoreWebViewBridgeDelegate {
|
|
133
|
-
|
|
134
|
-
func encoreBridgeDidBecomeReady(_ bridge: EncoreWebViewBridge) {
|
|
135
|
-
print("✅ Encore bridge is ready")
|
|
136
|
-
statusLabel.text = "Encore is ready"
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
func encoreBridge(_ bridge: EncoreWebViewBridge, didInitializeWithUserId userId: String) {
|
|
140
|
-
print("✅ Encore initialized with user ID: \(userId)")
|
|
141
|
-
statusLabel.text = "Initialized (User: \(userId))"
|
|
142
|
-
presentOfferButton.isEnabled = true
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
func encoreBridge(_ bridge: EncoreWebViewBridge, didGrantEntitlement entitlement: EncoreEntitlement) {
|
|
146
|
-
print("🎉 Entitlement granted: \(entitlement)")
|
|
147
|
-
|
|
148
|
-
// Handle the entitlement in your app
|
|
149
|
-
// For example, unlock premium features, apply discount, etc.
|
|
150
|
-
|
|
151
|
-
let message = "Entitlement Granted!\nType: \(entitlement.type)"
|
|
152
|
-
resultLabel.text = message
|
|
153
|
-
resultLabel.textColor = .systemGreen
|
|
154
|
-
|
|
155
|
-
// Show success alert
|
|
156
|
-
let alert = UIAlertController(
|
|
157
|
-
title: "Success!",
|
|
158
|
-
message: "You've earned a \(entitlement.type) entitlement!",
|
|
159
|
-
preferredStyle: .alert
|
|
160
|
-
)
|
|
161
|
-
alert.addAction(UIAlertAction(title: "OK", style: .default))
|
|
162
|
-
present(alert, animated: true)
|
|
163
|
-
|
|
164
|
-
// TODO: Implement your app's logic to apply the entitlement
|
|
165
|
-
// Examples:
|
|
166
|
-
// - Update user's subscription status
|
|
167
|
-
// - Apply discount to checkout
|
|
168
|
-
// - Grant access to premium content
|
|
169
|
-
// - Update UI to reflect new entitlement
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
func encoreBridge(_ bridge: EncoreWebViewBridge, userDeclinedWithReason reason: EncoreDeclineReason) {
|
|
173
|
-
print("ℹ️ User declined offer: \(reason.rawValue)")
|
|
174
|
-
|
|
175
|
-
let message = "Offer declined: \(reason.rawValue)"
|
|
176
|
-
resultLabel.text = message
|
|
177
|
-
resultLabel.textColor = .systemOrange
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
func encoreBridge(_ bridge: EncoreWebViewBridge, didEncounterError error: EncoreError) {
|
|
181
|
-
print("❌ Encore error: \(error.code) - \(error.message)")
|
|
182
|
-
|
|
183
|
-
let message = "Error: \(error.message)"
|
|
184
|
-
resultLabel.text = message
|
|
185
|
-
resultLabel.textColor = .systemRed
|
|
186
|
-
|
|
187
|
-
// Show error alert
|
|
188
|
-
let alert = UIAlertController(
|
|
189
|
-
title: "Error",
|
|
190
|
-
message: error.message,
|
|
191
|
-
preferredStyle: .alert
|
|
192
|
-
)
|
|
193
|
-
alert.addAction(UIAlertAction(title: "OK", style: .default))
|
|
194
|
-
present(alert, animated: true)
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// MARK: - Advanced Example: Cancellation Flow Integration
|
|
199
|
-
|
|
200
|
-
extension ExampleViewController {
|
|
201
|
-
|
|
202
|
-
/// Example: Present Encore offer during subscription cancellation
|
|
203
|
-
func handleSubscriptionCancellation() {
|
|
204
|
-
// User is trying to cancel their subscription
|
|
205
|
-
|
|
206
|
-
// First, present the Encore offer as a retention tool
|
|
207
|
-
encoreBridge.presentOffer()
|
|
208
|
-
|
|
209
|
-
// The delegate methods will be called:
|
|
210
|
-
// - If user completes offer: didGrantEntitlement() → Keep subscription active
|
|
211
|
-
// - If user declines: userDeclinedWithReason() → Proceed with cancellation
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/// Example: Check if user has active entitlements on app launch
|
|
215
|
-
func checkEntitlementsOnLaunch() {
|
|
216
|
-
// Note: Entitlement validation should be done server-side
|
|
217
|
-
// This is just for demonstration of the bridge API
|
|
218
|
-
|
|
219
|
-
encoreBridge.getState()
|
|
220
|
-
// Response will be logged in console
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/// Example: Update user attributes dynamically
|
|
224
|
-
func updateUserData() {
|
|
225
|
-
let newAttributes = [
|
|
226
|
-
"subscriptionTier": "premium",
|
|
227
|
-
"lastActiveDate": ISO8601DateFormatter().string(from: Date())
|
|
228
|
-
]
|
|
229
|
-
|
|
230
|
-
encoreBridge.setUserAttributes(newAttributes)
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|