@monetize.software/sdk-react 3.0.0-alpha.9 → 3.0.0-beta.0
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 +2 -0
- package/dist/components/PaywallButton.d.ts +18 -0
- package/dist/components/PaywallButton.d.ts.map +1 -1
- package/dist/hooks/usePaywallOffer.d.ts +42 -0
- package/dist/hooks/usePaywallOffer.d.ts.map +1 -0
- package/dist/hooks/usePaywallOffers.d.ts +16 -0
- package/dist/hooks/usePaywallOffers.d.ts.map +1 -0
- package/dist/hooks/usePaywallState.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +178 -130
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,47 +1,52 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { createContext as
|
|
4
|
-
import { PaywallUI as
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
const
|
|
11
|
-
|
|
2
|
+
import { jsx as d, Fragment as P } from "react/jsx-runtime";
|
|
3
|
+
import { createContext as B, useState as g, useEffect as p, useContext as T, useCallback as y, useSyncExternalStore as C, useRef as m, forwardRef as R } from "react";
|
|
4
|
+
import { PaywallUI as N } from "@monetize.software/sdk";
|
|
5
|
+
const x = B(null);
|
|
6
|
+
x.displayName = "PaywallContext";
|
|
7
|
+
const O = B(!1);
|
|
8
|
+
O.displayName = "PaywallProviderMarker";
|
|
9
|
+
function q(n) {
|
|
10
|
+
const e = "instance" in n ? n.instance : void 0, t = "options" in n ? n.options : void 0, [r, s] = g(
|
|
11
|
+
e ?? null
|
|
12
12
|
);
|
|
13
|
-
return
|
|
14
|
-
if (
|
|
15
|
-
s(
|
|
13
|
+
return p(() => {
|
|
14
|
+
if (e) {
|
|
15
|
+
s(e);
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
if (!
|
|
19
|
-
const l = new
|
|
18
|
+
if (!t) return;
|
|
19
|
+
const l = new N(t);
|
|
20
20
|
return s(l), () => {
|
|
21
21
|
l.destroy(), s(null);
|
|
22
22
|
};
|
|
23
|
-
}, [
|
|
23
|
+
}, [e]), /* @__PURE__ */ d(O.Provider, { value: !0, children: /* @__PURE__ */ d(x.Provider, { value: r, children: n.children }) });
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
const n =
|
|
25
|
+
function c() {
|
|
26
|
+
const n = T(O), e = T(x);
|
|
27
27
|
if (!n)
|
|
28
28
|
throw new Error(
|
|
29
29
|
"[sdk-react] usePaywall() called outside <PaywallProvider>. Wrap your tree with <PaywallProvider options={...}> or pass an externally-created instance via <PaywallProvider instance={paywall}>."
|
|
30
30
|
);
|
|
31
|
-
return
|
|
31
|
+
return e;
|
|
32
32
|
}
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
const _ = {
|
|
34
|
+
open: !1,
|
|
35
|
+
view: null,
|
|
36
|
+
error: null,
|
|
37
|
+
processing: !1
|
|
38
|
+
};
|
|
39
|
+
function G() {
|
|
40
|
+
const n = c(), e = y(
|
|
36
41
|
(r) => n ? n.onStateChange(r, { immediate: "none" }) : () => {
|
|
37
42
|
},
|
|
38
43
|
[n]
|
|
39
|
-
),
|
|
40
|
-
return
|
|
44
|
+
), t = y(() => n ? n.getState() : _, [n]);
|
|
45
|
+
return C(e, t, () => _);
|
|
41
46
|
}
|
|
42
|
-
const
|
|
43
|
-
function
|
|
44
|
-
const n =
|
|
47
|
+
const S = { status: "loading", user: null, session: null }, b = { status: "guest", user: null, session: null };
|
|
48
|
+
function z() {
|
|
49
|
+
const n = c(), e = m(S), t = y(
|
|
45
50
|
(s) => {
|
|
46
51
|
if (!n) return () => {
|
|
47
52
|
};
|
|
@@ -53,20 +58,20 @@ function H() {
|
|
|
53
58
|
[n]
|
|
54
59
|
), r = y(() => {
|
|
55
60
|
if (!n)
|
|
56
|
-
return
|
|
61
|
+
return e.current = S, S;
|
|
57
62
|
const s = n.billing.getCachedUser();
|
|
58
63
|
if (n.auth) {
|
|
59
64
|
const l = n.auth.getCachedSession();
|
|
60
65
|
if (!l)
|
|
61
|
-
return
|
|
62
|
-
const a =
|
|
66
|
+
return e.current = b, b;
|
|
67
|
+
const a = e.current;
|
|
63
68
|
if (a.status === "signed_in" && a.user === s && a.session === l)
|
|
64
69
|
return a;
|
|
65
70
|
const o = { status: "signed_in", user: s, session: l };
|
|
66
|
-
return
|
|
71
|
+
return e.current = o, o;
|
|
67
72
|
}
|
|
68
73
|
if (s) {
|
|
69
|
-
const l =
|
|
74
|
+
const l = e.current;
|
|
70
75
|
if (l.status === "signed_in" && l.user === s && l.session === null)
|
|
71
76
|
return l;
|
|
72
77
|
const a = {
|
|
@@ -74,68 +79,68 @@ function H() {
|
|
|
74
79
|
user: s,
|
|
75
80
|
session: null
|
|
76
81
|
};
|
|
77
|
-
return
|
|
82
|
+
return e.current = a, a;
|
|
78
83
|
}
|
|
79
|
-
return
|
|
84
|
+
return e.current = b, b;
|
|
80
85
|
}, [n]);
|
|
81
|
-
return
|
|
86
|
+
return C(t, r, F);
|
|
82
87
|
}
|
|
83
|
-
function
|
|
84
|
-
return
|
|
88
|
+
function F() {
|
|
89
|
+
return S;
|
|
85
90
|
}
|
|
86
|
-
function
|
|
87
|
-
const
|
|
88
|
-
r.current =
|
|
89
|
-
if (
|
|
90
|
-
return
|
|
91
|
+
function J(n, e) {
|
|
92
|
+
const t = c(), r = m(e);
|
|
93
|
+
r.current = e, p(() => {
|
|
94
|
+
if (t)
|
|
95
|
+
return t.on(n, (s) => {
|
|
91
96
|
r.current(s);
|
|
92
97
|
});
|
|
93
|
-
}, [
|
|
98
|
+
}, [t, n]);
|
|
94
99
|
}
|
|
95
|
-
const
|
|
96
|
-
function
|
|
97
|
-
const
|
|
98
|
-
return
|
|
99
|
-
if (!
|
|
100
|
-
r(
|
|
100
|
+
const E = { status: "loading", result: null };
|
|
101
|
+
function D(n = {}) {
|
|
102
|
+
const e = c(), [t, r] = g(E), s = n.skipTrial === !0, l = n.skipVisibility === !0;
|
|
103
|
+
return p(() => {
|
|
104
|
+
if (!e) {
|
|
105
|
+
r(E);
|
|
101
106
|
return;
|
|
102
107
|
}
|
|
103
108
|
const a = new AbortController();
|
|
104
109
|
let o = !1;
|
|
105
110
|
const u = () => {
|
|
106
|
-
|
|
107
|
-
o || a.signal.aborted || r({ status: "ready", result:
|
|
111
|
+
e.getAccess({ skipTrial: s, skipVisibility: l, signal: a.signal }).then((h) => {
|
|
112
|
+
o || a.signal.aborted || r({ status: "ready", result: h });
|
|
108
113
|
}).catch(() => {
|
|
109
114
|
});
|
|
110
115
|
};
|
|
111
116
|
u();
|
|
112
|
-
const
|
|
117
|
+
const i = e.on("userChange", u), f = e.on("purchase_completed", u);
|
|
113
118
|
return () => {
|
|
114
|
-
o = !0, a.abort(),
|
|
119
|
+
o = !0, a.abort(), i(), f();
|
|
115
120
|
};
|
|
116
|
-
}, [
|
|
121
|
+
}, [e, s, l]), t;
|
|
117
122
|
}
|
|
118
|
-
function
|
|
119
|
-
const n =
|
|
123
|
+
function K() {
|
|
124
|
+
const n = c(), [e, t] = g(() => ({
|
|
120
125
|
prices: n?.getCachedPrices() ?? null,
|
|
121
126
|
loading: !0,
|
|
122
127
|
error: null
|
|
123
128
|
}));
|
|
124
|
-
return
|
|
129
|
+
return p(() => {
|
|
125
130
|
if (!n) {
|
|
126
|
-
|
|
131
|
+
t({ prices: null, loading: !0, error: null });
|
|
127
132
|
return;
|
|
128
133
|
}
|
|
129
134
|
const r = n.getCachedPrices();
|
|
130
|
-
|
|
135
|
+
t({ prices: r, loading: r === null, error: null });
|
|
131
136
|
const s = new AbortController();
|
|
132
137
|
let l = !1;
|
|
133
138
|
(() => {
|
|
134
139
|
n.getPrices({ signal: s.signal }).then((u) => {
|
|
135
|
-
l ||
|
|
140
|
+
l || t({ prices: u, loading: !1, error: null });
|
|
136
141
|
}).catch((u) => {
|
|
137
|
-
l || s.signal.aborted ||
|
|
138
|
-
prices:
|
|
142
|
+
l || s.signal.aborted || t((i) => ({
|
|
143
|
+
prices: i.prices,
|
|
139
144
|
loading: !1,
|
|
140
145
|
error: u instanceof Error ? u : new Error(String(u))
|
|
141
146
|
}));
|
|
@@ -143,26 +148,61 @@ function q() {
|
|
|
143
148
|
})();
|
|
144
149
|
const o = n.on("ready", () => {
|
|
145
150
|
const u = n.getCachedPrices();
|
|
146
|
-
u &&
|
|
151
|
+
u && t({ prices: u, loading: !1, error: null });
|
|
147
152
|
});
|
|
148
153
|
return () => {
|
|
149
154
|
l = !0, s.abort(), o();
|
|
150
155
|
};
|
|
151
|
-
}, [n]),
|
|
156
|
+
}, [n]), e;
|
|
152
157
|
}
|
|
153
|
-
function
|
|
154
|
-
const
|
|
158
|
+
function Q(n) {
|
|
159
|
+
const e = c(), [t, r] = g(
|
|
160
|
+
() => e ? e.getOfferForPrice(n) : null
|
|
161
|
+
), s = m(n);
|
|
162
|
+
return s.current = n, p(() => {
|
|
163
|
+
if (!e) {
|
|
164
|
+
r(null);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
let l = !1;
|
|
168
|
+
const a = () => {
|
|
169
|
+
if (l) return;
|
|
170
|
+
const f = e.getOfferForPrice(s.current);
|
|
171
|
+
return r(f), f;
|
|
172
|
+
}, o = a(), u = e.on("ready", () => a());
|
|
173
|
+
let i = null;
|
|
174
|
+
return o && o.remainingMs !== null && (i = setInterval(() => {
|
|
175
|
+
const f = a();
|
|
176
|
+
(!f || f.remainingMs === null || f.remainingMs <= 0) && (i && clearInterval(i), i = null);
|
|
177
|
+
}, 1e3)), () => {
|
|
178
|
+
l = !0, u(), i && clearInterval(i);
|
|
179
|
+
};
|
|
180
|
+
}, [e, n]), t;
|
|
181
|
+
}
|
|
182
|
+
function X() {
|
|
183
|
+
const n = c(), e = y(
|
|
184
|
+
(r) => n ? n.on("ready", () => r()) : () => {
|
|
185
|
+
},
|
|
186
|
+
[n]
|
|
187
|
+
), t = y(() => n ? n.getCachedOffers() : null, [n]);
|
|
188
|
+
return C(e, t, L);
|
|
189
|
+
}
|
|
190
|
+
function L() {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
function Y() {
|
|
194
|
+
const n = c(), [e, t] = g(
|
|
155
195
|
() => n?.getTrialStatus() ?? null
|
|
156
196
|
), r = y(() => {
|
|
157
197
|
if (!n) {
|
|
158
|
-
|
|
198
|
+
t(null);
|
|
159
199
|
return;
|
|
160
200
|
}
|
|
161
|
-
|
|
201
|
+
t(n.getTrialStatus());
|
|
162
202
|
}, [n]);
|
|
163
|
-
return
|
|
203
|
+
return p(() => {
|
|
164
204
|
if (!n) {
|
|
165
|
-
|
|
205
|
+
t(null);
|
|
166
206
|
return;
|
|
167
207
|
}
|
|
168
208
|
r();
|
|
@@ -170,21 +210,21 @@ function z() {
|
|
|
170
210
|
return () => {
|
|
171
211
|
s(), l();
|
|
172
212
|
};
|
|
173
|
-
}, [n, r]),
|
|
213
|
+
}, [n, r]), e;
|
|
174
214
|
}
|
|
175
|
-
function
|
|
176
|
-
const n =
|
|
215
|
+
function Z() {
|
|
216
|
+
const n = c(), [e, t] = g(
|
|
177
217
|
() => n?.getVisibility() ?? null
|
|
178
218
|
), r = y(() => {
|
|
179
219
|
if (!n) {
|
|
180
|
-
|
|
220
|
+
t(null);
|
|
181
221
|
return;
|
|
182
222
|
}
|
|
183
|
-
|
|
223
|
+
t(n.getVisibility());
|
|
184
224
|
}, [n]);
|
|
185
|
-
return
|
|
225
|
+
return p(() => {
|
|
186
226
|
if (!n) {
|
|
187
|
-
|
|
227
|
+
t(null);
|
|
188
228
|
return;
|
|
189
229
|
}
|
|
190
230
|
r();
|
|
@@ -192,80 +232,88 @@ function J() {
|
|
|
192
232
|
return () => {
|
|
193
233
|
s(), l();
|
|
194
234
|
};
|
|
195
|
-
}, [n, r]),
|
|
235
|
+
}, [n, r]), e;
|
|
196
236
|
}
|
|
197
|
-
function
|
|
198
|
-
const
|
|
199
|
-
if (
|
|
200
|
-
s &&
|
|
201
|
-
}, [s,
|
|
202
|
-
return /* @__PURE__ */
|
|
203
|
-
if (
|
|
204
|
-
return /* @__PURE__ */
|
|
237
|
+
function nn(n) {
|
|
238
|
+
const e = c(), t = D(), r = t.status === "ready" && t.result.access === "blocked", s = n.openOnBlocked === !0 && r;
|
|
239
|
+
if (p(() => {
|
|
240
|
+
s && e && e.open();
|
|
241
|
+
}, [s, e]), t.status === "loading")
|
|
242
|
+
return /* @__PURE__ */ d(P, { children: n.loading ?? null });
|
|
243
|
+
if (t.result.access === "granted")
|
|
244
|
+
return /* @__PURE__ */ d(P, { children: n.children });
|
|
205
245
|
const l = n.fallback;
|
|
206
|
-
return typeof l == "function" ? /* @__PURE__ */
|
|
207
|
-
result:
|
|
208
|
-
open: () =>
|
|
209
|
-
}) }) : /* @__PURE__ */
|
|
246
|
+
return typeof l == "function" ? /* @__PURE__ */ d(P, { children: l({
|
|
247
|
+
result: t.result,
|
|
248
|
+
open: () => e?.open()
|
|
249
|
+
}) }) : /* @__PURE__ */ d(P, { children: l ?? null });
|
|
210
250
|
}
|
|
211
|
-
const
|
|
212
|
-
function(
|
|
213
|
-
const r =
|
|
214
|
-
mode:
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
251
|
+
const j = R(
|
|
252
|
+
function(e, t) {
|
|
253
|
+
const r = c(), s = G(), {
|
|
254
|
+
mode: l = "paywall",
|
|
255
|
+
priceId: a,
|
|
256
|
+
identity: o,
|
|
257
|
+
renew: u,
|
|
258
|
+
skipTrial: i,
|
|
259
|
+
skipVisibility: f,
|
|
260
|
+
render: h,
|
|
261
|
+
onClick: V,
|
|
262
|
+
disabled: I,
|
|
263
|
+
...U
|
|
264
|
+
} = e, v = r !== null, k = !!a && s.processing, w = { identity: o, renew: u, skipTrial: i, skipVisibility: f }, A = () => {
|
|
265
|
+
if (r) {
|
|
266
|
+
if (a) {
|
|
267
|
+
r.checkout(a, w);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
switch (l) {
|
|
226
271
|
case "support":
|
|
227
|
-
r.openSupport(
|
|
272
|
+
r.openSupport(w);
|
|
228
273
|
return;
|
|
229
274
|
case "auth":
|
|
230
275
|
case "signin":
|
|
231
|
-
r.openSignin(
|
|
276
|
+
r.openSignin(w);
|
|
232
277
|
return;
|
|
233
278
|
case "signup":
|
|
234
|
-
r.openSignup(
|
|
279
|
+
r.openSignup(w);
|
|
235
280
|
return;
|
|
236
281
|
default:
|
|
237
|
-
r.open(
|
|
282
|
+
r.open(w);
|
|
238
283
|
}
|
|
284
|
+
}
|
|
239
285
|
};
|
|
240
|
-
return
|
|
286
|
+
return h ? h({ open: A, ready: v, processing: k }) : /* @__PURE__ */ d(
|
|
241
287
|
"button",
|
|
242
288
|
{
|
|
243
|
-
ref:
|
|
289
|
+
ref: t,
|
|
244
290
|
type: "button",
|
|
245
|
-
disabled:
|
|
246
|
-
"aria-busy": k ?
|
|
247
|
-
onClick: (
|
|
248
|
-
|
|
291
|
+
disabled: I || !v || k,
|
|
292
|
+
"aria-busy": !v || k ? !0 : void 0,
|
|
293
|
+
onClick: (M) => {
|
|
294
|
+
A(), V?.(M);
|
|
249
295
|
},
|
|
250
|
-
...
|
|
296
|
+
...U
|
|
251
297
|
}
|
|
252
298
|
);
|
|
253
299
|
}
|
|
254
|
-
),
|
|
255
|
-
return /* @__PURE__ */
|
|
300
|
+
), en = R(function(e, t) {
|
|
301
|
+
return /* @__PURE__ */ d(j, { ...e, mode: "support", ref: t });
|
|
256
302
|
});
|
|
257
303
|
export {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
304
|
+
j as PaywallButton,
|
|
305
|
+
nn as PaywallGate,
|
|
306
|
+
q as PaywallProvider,
|
|
307
|
+
en as PaywallSupportButton,
|
|
308
|
+
c as usePaywall,
|
|
309
|
+
D as usePaywallAccess,
|
|
310
|
+
J as usePaywallEvent,
|
|
311
|
+
Q as usePaywallOffer,
|
|
312
|
+
X as usePaywallOffers,
|
|
313
|
+
K as usePaywallPrices,
|
|
314
|
+
G as usePaywallState,
|
|
315
|
+
Y as usePaywallTrial,
|
|
316
|
+
z as usePaywallUser,
|
|
317
|
+
Z as usePaywallVisibility
|
|
270
318
|
};
|
|
271
319
|
//# sourceMappingURL=index.js.map
|