@superwall/paywalls-react 0.2.0 → 0.2.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.
- package/dist/SuperwallPaywall.d.ts +28 -0
- package/dist/SuperwallPaywall.js +50 -0
- package/dist/hooks.d.ts +108 -0
- package/dist/hooks.js +231 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +9 -0
- package/dist/provider.d.ts +9 -0
- package/dist/provider.js +65 -0
- package/package.json +14 -5
- package/.turbo/turbo-build.log +0 -3
- package/.turbo/turbo-test.log +0 -249
- package/.turbo/turbo-typecheck.log +0 -11
- package/src/SuperwallPaywall.tsx +0 -94
- package/src/hooks.test.tsx +0 -483
- package/src/hooks.ts +0 -368
- package/src/index.test.ts +0 -7
- package/src/index.ts +0 -36
- package/src/provider.test.tsx +0 -102
- package/src/provider.tsx +0 -99
- package/test-setup-dom.ts +0 -11
- package/tsconfig.json +0 -9
package/.turbo/turbo-test.log
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
$ bun test
|
|
2
|
-
bun test v1.3.11 (af24e281)
|
|
3
|
-
|
|
4
|
-
src/index.test.ts:
|
|
5
|
-
(pass) re-exports SDK_VERSION from @superwall/paywalls-js [0.96ms]
|
|
6
|
-
|
|
7
|
-
src/hooks.test.tsx:
|
|
8
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
9
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
10
|
-
244 | }, !keepOpen)
|
|
11
|
-
245 | handleResponse();
|
|
12
|
-
246 | onEnd();
|
|
13
|
-
247 | }), !softFail)
|
|
14
|
-
248 | this[kFetchRequest].catch((err) => {
|
|
15
|
-
249 | err = Error("ECONNREFUSED"), err.code = "ECONNREFUSED";
|
|
16
|
-
^
|
|
17
|
-
error: ECONNREFUSED
|
|
18
|
-
code: "ECONNREFUSED"
|
|
19
|
-
|
|
20
|
-
at <anonymous> (node:_http_client:249:24)
|
|
21
|
-
|
|
22
|
-
535 | * @param error Error.
|
|
23
|
-
536 | */
|
|
24
|
-
537 | onError(error) {
|
|
25
|
-
538 | this.finalizeRequest();
|
|
26
|
-
539 | this.#browserFrame.page.console.error(error);
|
|
27
|
-
540 | this.reject(new this.#window.DOMException(`Failed to execute "fetch()" on "Window" with URL "${this.request.url}": ${error.message}`, DOMExceptionNameEnum.networkError));
|
|
28
|
-
^
|
|
29
|
-
NetworkError: Failed to execute "fetch()" on "Window" with URL "https://paywalls.test/pw_default?platform=web&transport=web&debug=false": ECONNREFUSED
|
|
30
|
-
at onError (/Users/ianrumac/Workspace/Superwall/Superwall-Web/node_modules/.bun/happy-dom@20.9.0/node_modules/happy-dom/lib/fetch/Fetch.js:540:21)
|
|
31
|
-
at emitError (node:events:43:23)
|
|
32
|
-
at <anonymous> (node:_http_client:253:22)
|
|
33
|
-
|
|
34
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
35
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
36
|
-
(pass) useSignal returns the current value and re-renders on change [217.28ms]
|
|
37
|
-
error: Was there a typo in the url or port?
|
|
38
|
-
path: "https://paywalls.test/pw_default?platform=web&transport=web&debug=false",
|
|
39
|
-
errno: 0,
|
|
40
|
-
code: "FailedToOpenSocket"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
535 | * @param error Error.
|
|
44
|
-
536 | */
|
|
45
|
-
537 | onError(error) {
|
|
46
|
-
538 | this.finalizeRequest();
|
|
47
|
-
539 | this.#browserFrame.page.console.error(error);
|
|
48
|
-
540 | this.reject(new this.#window.DOMException(`Failed to execute "fetch()" on "Window" with URL "${this.request.url}": ${error.message}`, DOMExceptionNameEnum.networkError));
|
|
49
|
-
^
|
|
50
|
-
NetworkError: Failed to execute "fetch()" on "Window" with URL "https://paywalls.test/pw_default?platform=web&transport=web&debug=false": Was there a typo in the url or port?
|
|
51
|
-
at onError (/Users/ianrumac/Workspace/Superwall/Superwall-Web/node_modules/.bun/happy-dom@20.9.0/node_modules/happy-dom/lib/fetch/Fetch.js:540:21)
|
|
52
|
-
at emitError (node:events:43:23)
|
|
53
|
-
at <anonymous> (node:_http_client:253:22)
|
|
54
|
-
|
|
55
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
56
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
57
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
58
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
59
|
-
(pass) useUser exposes id/aliasId/effectiveId/isLoggedIn and updates on identify/signOut [66.09ms]
|
|
60
|
-
244 | }, !keepOpen)
|
|
61
|
-
245 | handleResponse();
|
|
62
|
-
246 | onEnd();
|
|
63
|
-
247 | }), !softFail)
|
|
64
|
-
248 | this[kFetchRequest].catch((err) => {
|
|
65
|
-
249 | err = Error("ECONNREFUSED"), err.code = "ECONNREFUSED";
|
|
66
|
-
^
|
|
67
|
-
error: ECONNREFUSED
|
|
68
|
-
code: "ECONNREFUSED"
|
|
69
|
-
|
|
70
|
-
at <anonymous> (node:_http_client:249:24)
|
|
71
|
-
|
|
72
|
-
535 | * @param error Error.
|
|
73
|
-
536 | */
|
|
74
|
-
537 | onError(error) {
|
|
75
|
-
538 | this.finalizeRequest();
|
|
76
|
-
539 | this.#browserFrame.page.console.error(error);
|
|
77
|
-
540 | this.reject(new this.#window.DOMException(`Failed to execute "fetch()" on "Window" with URL "${this.request.url}": ${error.message}`, DOMExceptionNameEnum.networkError));
|
|
78
|
-
^
|
|
79
|
-
NetworkError: Failed to execute "fetch()" on "Window" with URL "https://paywalls.test/pw_default?platform=web&transport=web&debug=false": ECONNREFUSED
|
|
80
|
-
at onError (/Users/ianrumac/Workspace/Superwall/Superwall-Web/node_modules/.bun/happy-dom@20.9.0/node_modules/happy-dom/lib/fetch/Fetch.js:540:21)
|
|
81
|
-
at emitError (node:events:43:23)
|
|
82
|
-
at <anonymous> (node:_http_client:253:22)
|
|
83
|
-
|
|
84
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
85
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
86
|
-
(pass) useUser.subscriptionStatus + entitlements update after setSubscriptionStatus [71.45ms]
|
|
87
|
-
error: Was there a typo in the url or port?
|
|
88
|
-
path: "https://paywalls.test/pw_default?platform=web&transport=web&debug=false",
|
|
89
|
-
errno: 0,
|
|
90
|
-
code: "FailedToOpenSocket"
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
535 | * @param error Error.
|
|
94
|
-
536 | */
|
|
95
|
-
537 | onError(error) {
|
|
96
|
-
538 | this.finalizeRequest();
|
|
97
|
-
539 | this.#browserFrame.page.console.error(error);
|
|
98
|
-
540 | this.reject(new this.#window.DOMException(`Failed to execute "fetch()" on "Window" with URL "${this.request.url}": ${error.message}`, DOMExceptionNameEnum.networkError));
|
|
99
|
-
^
|
|
100
|
-
NetworkError: Failed to execute "fetch()" on "Window" with URL "https://paywalls.test/pw_default?platform=web&transport=web&debug=false": Was there a typo in the url or port?
|
|
101
|
-
at onError (/Users/ianrumac/Workspace/Superwall/Superwall-Web/node_modules/.bun/happy-dom@20.9.0/node_modules/happy-dom/lib/fetch/Fetch.js:540:21)
|
|
102
|
-
at emitError (node:events:43:23)
|
|
103
|
-
at <anonymous> (node:_http_client:253:22)
|
|
104
|
-
|
|
105
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
106
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
107
|
-
(pass) usePlacement reflects presented + dismissed state and routes handler callbacks [68.23ms]
|
|
108
|
-
244 | }, !keepOpen)
|
|
109
|
-
245 | handleResponse();
|
|
110
|
-
246 | onEnd();
|
|
111
|
-
247 | }), !softFail)
|
|
112
|
-
248 | this[kFetchRequest].catch((err) => {
|
|
113
|
-
249 | err = Error("ECONNREFUSED"), err.code = "ECONNREFUSED";
|
|
114
|
-
^
|
|
115
|
-
error: ECONNREFUSED
|
|
116
|
-
code: "ECONNREFUSED"
|
|
117
|
-
|
|
118
|
-
at <anonymous> (node:_http_client:249:24)
|
|
119
|
-
|
|
120
|
-
535 | * @param error Error.
|
|
121
|
-
536 | */
|
|
122
|
-
537 | onError(error) {
|
|
123
|
-
538 | this.finalizeRequest();
|
|
124
|
-
539 | this.#browserFrame.page.console.error(error);
|
|
125
|
-
540 | this.reject(new this.#window.DOMException(`Failed to execute "fetch()" on "Window" with URL "${this.request.url}": ${error.message}`, DOMExceptionNameEnum.networkError));
|
|
126
|
-
^
|
|
127
|
-
NetworkError: Failed to execute "fetch()" on "Window" with URL "https://paywalls.test/pw_default?platform=web&transport=web&debug=false": ECONNREFUSED
|
|
128
|
-
at onError (/Users/ianrumac/Workspace/Superwall/Superwall-Web/node_modules/.bun/happy-dom@20.9.0/node_modules/happy-dom/lib/fetch/Fetch.js:540:21)
|
|
129
|
-
at emitError (node:events:43:23)
|
|
130
|
-
at <anonymous> (node:_http_client:253:22)
|
|
131
|
-
|
|
132
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
133
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
134
|
-
(pass) usePlacement: ACTIVE subscription → register returns skipped(userSubscribed) [43.31ms]
|
|
135
|
-
error: Was there a typo in the url or port?
|
|
136
|
-
path: "https://paywalls.test/pw_default?platform=web&transport=web&debug=false",
|
|
137
|
-
errno: 0,
|
|
138
|
-
code: "FailedToOpenSocket"
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
535 | * @param error Error.
|
|
142
|
-
536 | */
|
|
143
|
-
537 | onError(error) {
|
|
144
|
-
538 | this.finalizeRequest();
|
|
145
|
-
539 | this.#browserFrame.page.console.error(error);
|
|
146
|
-
540 | this.reject(new this.#window.DOMException(`Failed to execute "fetch()" on "Window" with URL "${this.request.url}": ${error.message}`, DOMExceptionNameEnum.networkError));
|
|
147
|
-
^
|
|
148
|
-
NetworkError: Failed to execute "fetch()" on "Window" with URL "https://paywalls.test/pw_default?platform=web&transport=web&debug=false": Was there a typo in the url or port?
|
|
149
|
-
at onError (/Users/ianrumac/Workspace/Superwall/Superwall-Web/node_modules/.bun/happy-dom@20.9.0/node_modules/happy-dom/lib/fetch/Fetch.js:540:21)
|
|
150
|
-
at emitError (node:events:43:23)
|
|
151
|
-
at <anonymous> (node:_http_client:253:22)
|
|
152
|
-
|
|
153
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
154
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
155
|
-
(pass) useSuperwallEvent attaches a typed listener and auto-detaches on unmount [37.92ms]
|
|
156
|
-
244 | }, !keepOpen)
|
|
157
|
-
245 | handleResponse();
|
|
158
|
-
246 | onEnd();
|
|
159
|
-
247 | }), !softFail)
|
|
160
|
-
248 | this[kFetchRequest].catch((err) => {
|
|
161
|
-
249 | err = Error("ECONNREFUSED"), err.code = "ECONNREFUSED";
|
|
162
|
-
^
|
|
163
|
-
error: ECONNREFUSED
|
|
164
|
-
code: "ECONNREFUSED"
|
|
165
|
-
|
|
166
|
-
at <anonymous> (node:_http_client:249:24)
|
|
167
|
-
|
|
168
|
-
535 | * @param error Error.
|
|
169
|
-
536 | */
|
|
170
|
-
537 | onError(error) {
|
|
171
|
-
538 | this.finalizeRequest();
|
|
172
|
-
539 | this.#browserFrame.page.console.error(error);
|
|
173
|
-
540 | this.reject(new this.#window.DOMException(`Failed to execute "fetch()" on "Window" with URL "${this.request.url}": ${error.message}`, DOMExceptionNameEnum.networkError));
|
|
174
|
-
^
|
|
175
|
-
NetworkError: Failed to execute "fetch()" on "Window" with URL "https://paywalls.test/pw_default?platform=web&transport=web&debug=false": ECONNREFUSED
|
|
176
|
-
at onError (/Users/ianrumac/Workspace/Superwall/Superwall-Web/node_modules/.bun/happy-dom@20.9.0/node_modules/happy-dom/lib/fetch/Fetch.js:540:21)
|
|
177
|
-
at emitError (node:events:43:23)
|
|
178
|
-
at <anonymous> (node:_http_client:253:22)
|
|
179
|
-
|
|
180
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
181
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
182
|
-
(pass) useDelegate installs a delegate for the lifetime of the component [41.24ms]
|
|
183
|
-
error: Was there a typo in the url or port?
|
|
184
|
-
path: "https://paywalls.test/pw_default?platform=web&transport=web&debug=false",
|
|
185
|
-
errno: 0,
|
|
186
|
-
code: "FailedToOpenSocket"
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
535 | * @param error Error.
|
|
190
|
-
536 | */
|
|
191
|
-
537 | onError(error) {
|
|
192
|
-
538 | this.finalizeRequest();
|
|
193
|
-
539 | this.#browserFrame.page.console.error(error);
|
|
194
|
-
540 | this.reject(new this.#window.DOMException(`Failed to execute "fetch()" on "Window" with URL "${this.request.url}": ${error.message}`, DOMExceptionNameEnum.networkError));
|
|
195
|
-
^
|
|
196
|
-
NetworkError: Failed to execute "fetch()" on "Window" with URL "https://paywalls.test/pw_default?platform=web&transport=web&debug=false": Was there a typo in the url or port?
|
|
197
|
-
at onError (/Users/ianrumac/Workspace/Superwall/Superwall-Web/node_modules/.bun/happy-dom@20.9.0/node_modules/happy-dom/lib/fetch/Fetch.js:540:21)
|
|
198
|
-
at emitError (node:events:43:23)
|
|
199
|
-
at <anonymous> (node:_http_client:253:22)
|
|
200
|
-
|
|
201
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
202
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
203
|
-
(pass) useSignal: unstable signal identity per render doesn't trigger infinite re-render [38.58ms]
|
|
204
|
-
244 | }, !keepOpen)
|
|
205
|
-
245 | handleResponse();
|
|
206
|
-
246 | onEnd();
|
|
207
|
-
247 | }), !softFail)
|
|
208
|
-
248 | this[kFetchRequest].catch((err) => {
|
|
209
|
-
249 | err = Error("ECONNREFUSED"), err.code = "ECONNREFUSED";
|
|
210
|
-
^
|
|
211
|
-
error: ECONNREFUSED
|
|
212
|
-
code: "ECONNREFUSED"
|
|
213
|
-
|
|
214
|
-
at <anonymous> (node:_http_client:249:24)
|
|
215
|
-
|
|
216
|
-
535 | * @param error Error.
|
|
217
|
-
536 | */
|
|
218
|
-
537 | onError(error) {
|
|
219
|
-
538 | this.finalizeRequest();
|
|
220
|
-
539 | this.#browserFrame.page.console.error(error);
|
|
221
|
-
540 | this.reject(new this.#window.DOMException(`Failed to execute "fetch()" on "Window" with URL "${this.request.url}": ${error.message}`, DOMExceptionNameEnum.networkError));
|
|
222
|
-
^
|
|
223
|
-
NetworkError: Failed to execute "fetch()" on "Window" with URL "https://paywalls.test/pw_default?platform=web&transport=web&debug=false": ECONNREFUSED
|
|
224
|
-
at onError (/Users/ianrumac/Workspace/Superwall/Superwall-Web/node_modules/.bun/happy-dom@20.9.0/node_modules/happy-dom/lib/fetch/Fetch.js:540:21)
|
|
225
|
-
at emitError (node:events:43:23)
|
|
226
|
-
at <anonymous> (node:_http_client:253:22)
|
|
227
|
-
|
|
228
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
229
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
230
|
-
(pass) useDelegate: unmounting one of two stacked hooks leaves the other installed [43.98ms]
|
|
231
|
-
|
|
232
|
-
src/provider.test.tsx:
|
|
233
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
234
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
235
|
-
(pass) SuperwallProvider provides a Superwall instance via context [22.84ms]
|
|
236
|
-
(pass) useSuperwall outside <SuperwallProvider> throws a clear error [16.59ms]
|
|
237
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
238
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
239
|
-
(pass) registry reuses the instance across re-mounts with the same apiKey (HMR) [34.67ms]
|
|
240
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
241
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
242
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
243
|
-
[Superwall:transactions] entitlements GET failed NetworkDecodingError: entitlements JSON decode failed: JSON Parse error: Unexpected EOF
|
|
244
|
-
(pass) different apiKeys produce different instances [23.18ms]
|
|
245
|
-
|
|
246
|
-
14 pass
|
|
247
|
-
0 fail
|
|
248
|
-
40 expect() calls
|
|
249
|
-
Ran 14 tests across 3 files. [972.00ms]
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
$ tsc --noEmit
|
|
2
|
-
src/hooks.test.tsx(417,26): error TS2345: Argument of type '{ readonly value: string; subscribe: (run: () => void) => () => void; }' is not assignable to parameter of type 'Readable<string>'.
|
|
3
|
-
Types of property 'subscribe' are incompatible.
|
|
4
|
-
Type '(run: () => void) => () => void' is not assignable to type '(run: (value: string) => void) => () => void'.
|
|
5
|
-
Types of parameters 'run' and 'run' are incompatible.
|
|
6
|
-
Target signature provides too few arguments. Expected 1 or more, but got 0.
|
|
7
|
-
src/hooks.ts(185,11): error TS2367: This comparison appears to be unintentional because the types '"error" | "presented" | "skipped"' and '"entitled"' have no overlap.
|
|
8
|
-
src/SuperwallPaywall.tsx(42,17): error TS2379: Argument of type '{ placement: string; params: PlacementParams | undefined; feature: () => void; handler: { onPresent: (info: PaywallInfo) => void | undefined; onDismiss: (info: PaywallInfo, result: PaywallResult) => void | undefined; onSkip: (reason: PaywallSkippedReason) => void | undefined; onError: (error: Error) => void | undefi...' is not assignable to parameter of type 'RegisterPlacementArgs' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
|
|
9
|
-
Types of property 'params' are incompatible.
|
|
10
|
-
Type 'PlacementParams | undefined' is not assignable to type 'PlacementParams'.
|
|
11
|
-
Type 'undefined' is not assignable to type 'PlacementParams'.
|
package/src/SuperwallPaywall.tsx
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { type ReactNode, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
import type { PlacementParams } from "@superwall/paywalls-js";
|
|
3
|
-
import { createBrowserPresenter } from "@superwall/paywalls-js/browser";
|
|
4
|
-
import type { PaywallPresentationHandlerHooks } from "./hooks.ts";
|
|
5
|
-
import { useSuperwall } from "./hooks.ts";
|
|
6
|
-
|
|
7
|
-
export interface SuperwallPaywallProps extends PaywallPresentationHandlerHooks {
|
|
8
|
-
placement: string;
|
|
9
|
-
params?: PlacementParams;
|
|
10
|
-
/** Rendered when the user is entitled — i.e. the feature block fires. */
|
|
11
|
-
children?: ReactNode;
|
|
12
|
-
/** Rendered while the paywall is loading. Swapped out the moment the paywall presents. */
|
|
13
|
-
loading?: ReactNode;
|
|
14
|
-
/**
|
|
15
|
-
* When true the paywall iframe is mounted inside this component instead of
|
|
16
|
-
* as a full-viewport overlay. Default: false.
|
|
17
|
-
*/
|
|
18
|
-
inline?: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Declarative feature gate. Calls `register()` on mount and renders
|
|
23
|
-
* `children` when the user is entitled (already subscribed, purchased
|
|
24
|
-
* through the paywall, or the placement has no audience match).
|
|
25
|
-
*
|
|
26
|
-
* ```tsx
|
|
27
|
-
* <SuperwallPaywall placement="campaign_trigger" loading={<Spinner />}>
|
|
28
|
-
* <ProContent />
|
|
29
|
-
* </SuperwallPaywall>
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export function SuperwallPaywall({
|
|
33
|
-
placement,
|
|
34
|
-
params,
|
|
35
|
-
children,
|
|
36
|
-
loading = null,
|
|
37
|
-
inline = false,
|
|
38
|
-
onPresent,
|
|
39
|
-
onDismiss,
|
|
40
|
-
onSkip,
|
|
41
|
-
onError,
|
|
42
|
-
}: SuperwallPaywallProps) {
|
|
43
|
-
const sw = useSuperwall();
|
|
44
|
-
const [unlocked, setUnlocked] = useState(false);
|
|
45
|
-
const [presenting, setPresenting] = useState(false);
|
|
46
|
-
const containerRef = useRef<HTMLDivElement>(null);
|
|
47
|
-
|
|
48
|
-
const handlersRef = useRef({ onPresent, onDismiss, onSkip, onError });
|
|
49
|
-
handlersRef.current = { onPresent, onDismiss, onSkip, onError };
|
|
50
|
-
|
|
51
|
-
const presenter = useMemo(
|
|
52
|
-
() =>
|
|
53
|
-
inline
|
|
54
|
-
? createBrowserPresenter({ container: () => containerRef.current ?? document.body, inline: true })
|
|
55
|
-
: undefined,
|
|
56
|
-
[inline],
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
let cancelled = false;
|
|
61
|
-
sw.register({
|
|
62
|
-
placement,
|
|
63
|
-
params,
|
|
64
|
-
feature: () => { if (!cancelled) setUnlocked(true); },
|
|
65
|
-
...(presenter && { presenter }),
|
|
66
|
-
handler: {
|
|
67
|
-
onPresent: (info) => { if (!cancelled) setPresenting(true); handlersRef.current.onPresent?.(info); },
|
|
68
|
-
onDismiss: (info, result) => { handlersRef.current.onDismiss?.(info, result); },
|
|
69
|
-
onSkip: (reason) => { handlersRef.current.onSkip?.(reason); },
|
|
70
|
-
onError: (error) => { handlersRef.current.onError?.(error); },
|
|
71
|
-
},
|
|
72
|
-
}).catch(() => {});
|
|
73
|
-
return () => { cancelled = true; };
|
|
74
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
|
-
}, [placement, params, presenter]);
|
|
76
|
-
|
|
77
|
-
if (unlocked) return <>{children}</>;
|
|
78
|
-
|
|
79
|
-
// Container always stays in the DOM so the presenter can append the iframe
|
|
80
|
-
// before onPresent fires. We swap loading ↔ iframe via display:none.
|
|
81
|
-
return (
|
|
82
|
-
<div style={{ position: "relative", width: "100%", height: "100%" }}>
|
|
83
|
-
<div
|
|
84
|
-
ref={containerRef}
|
|
85
|
-
style={{ display: presenting ? "block" : "none", width: "100%", height: "100%" }}
|
|
86
|
-
/>
|
|
87
|
-
{!presenting && (
|
|
88
|
-
<div style={{ position: "absolute", inset: 0 }}>
|
|
89
|
-
{loading}
|
|
90
|
-
</div>
|
|
91
|
-
)}
|
|
92
|
-
</div>
|
|
93
|
-
);
|
|
94
|
-
}
|