@monetize.software/sdk-react 3.0.0-alpha.2 → 3.0.0-alpha.20
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 +76 -40
- package/dist/PaywallProvider.d.ts +1 -1
- package/dist/components/PaywallButton.d.ts +24 -3
- package/dist/components/PaywallButton.d.ts.map +1 -1
- package/dist/components/PaywallGate.d.ts +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/hooks/usePaywall.d.ts +1 -1
- package/dist/hooks/usePaywallAccess.d.ts +1 -1
- package/dist/hooks/usePaywallEvent.d.ts +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/usePaywallPrices.d.ts +1 -1
- package/dist/hooks/usePaywallState.d.ts +1 -1
- package/dist/hooks/usePaywallState.d.ts.map +1 -1
- package/dist/hooks/usePaywallTrial.d.ts +1 -1
- package/dist/hooks/usePaywallUser.d.ts +41 -21
- package/dist/hooks/usePaywallUser.d.ts.map +1 -1
- package/dist/hooks/usePaywallVisibility.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +228 -146
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,237 +1,319 @@
|
|
|
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
|
-
|
|
13
|
+
return p(() => {
|
|
14
|
+
if (e) {
|
|
15
|
+
s(e);
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
if (!t) return;
|
|
19
|
-
const
|
|
20
|
-
return l
|
|
21
|
-
|
|
19
|
+
const l = new N(t);
|
|
20
|
+
return s(l), () => {
|
|
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
|
|
27
|
-
if (!
|
|
25
|
+
function c() {
|
|
26
|
+
const n = T(O), e = T(x);
|
|
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
|
-
|
|
36
|
-
|
|
33
|
+
const _ = {
|
|
34
|
+
open: !1,
|
|
35
|
+
view: null,
|
|
36
|
+
error: null,
|
|
37
|
+
processing: !1
|
|
38
|
+
};
|
|
39
|
+
function G() {
|
|
40
|
+
const n = c(), e = y(
|
|
41
|
+
(r) => n ? n.onStateChange(r, { immediate: "none" }) : () => {
|
|
37
42
|
},
|
|
38
|
-
[
|
|
39
|
-
), t =
|
|
40
|
-
return
|
|
43
|
+
[n]
|
|
44
|
+
), t = y(() => n ? n.getState() : _, [n]);
|
|
45
|
+
return C(e, t, () => _);
|
|
41
46
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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(
|
|
50
|
+
(s) => {
|
|
51
|
+
if (!n) return () => {
|
|
52
|
+
};
|
|
53
|
+
const l = n.on("userChange", () => s()), a = n.auth ? n.on("authChange", () => s()) : null;
|
|
54
|
+
return () => {
|
|
55
|
+
l(), a?.();
|
|
56
|
+
};
|
|
45
57
|
},
|
|
46
|
-
[
|
|
47
|
-
),
|
|
48
|
-
|
|
58
|
+
[n]
|
|
59
|
+
), r = y(() => {
|
|
60
|
+
if (!n)
|
|
61
|
+
return e.current = S, S;
|
|
62
|
+
const s = n.billing.getCachedUser();
|
|
63
|
+
if (n.auth) {
|
|
64
|
+
const l = n.auth.getCachedSession();
|
|
65
|
+
if (!l)
|
|
66
|
+
return e.current = b, b;
|
|
67
|
+
const a = e.current;
|
|
68
|
+
if (a.status === "signed_in" && a.user === s && a.session === l)
|
|
69
|
+
return a;
|
|
70
|
+
const o = { status: "signed_in", user: s, session: l };
|
|
71
|
+
return e.current = o, o;
|
|
72
|
+
}
|
|
73
|
+
if (s) {
|
|
74
|
+
const l = e.current;
|
|
75
|
+
if (l.status === "signed_in" && l.user === s && l.session === null)
|
|
76
|
+
return l;
|
|
77
|
+
const a = {
|
|
78
|
+
status: "signed_in",
|
|
79
|
+
user: s,
|
|
80
|
+
session: null
|
|
81
|
+
};
|
|
82
|
+
return e.current = a, a;
|
|
83
|
+
}
|
|
84
|
+
return e.current = b, b;
|
|
85
|
+
}, [n]);
|
|
86
|
+
return C(t, r, F);
|
|
49
87
|
}
|
|
50
|
-
function
|
|
51
|
-
return
|
|
88
|
+
function F() {
|
|
89
|
+
return S;
|
|
52
90
|
}
|
|
53
|
-
function
|
|
54
|
-
const t =
|
|
55
|
-
r.current =
|
|
91
|
+
function J(n, e) {
|
|
92
|
+
const t = c(), r = m(e);
|
|
93
|
+
r.current = e, p(() => {
|
|
56
94
|
if (t)
|
|
57
|
-
return t.on(
|
|
58
|
-
r.current(
|
|
95
|
+
return t.on(n, (s) => {
|
|
96
|
+
r.current(s);
|
|
59
97
|
});
|
|
60
|
-
}, [t,
|
|
98
|
+
}, [t, n]);
|
|
61
99
|
}
|
|
62
|
-
const
|
|
63
|
-
function
|
|
64
|
-
const
|
|
65
|
-
return
|
|
66
|
-
if (!
|
|
67
|
-
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);
|
|
68
106
|
return;
|
|
69
107
|
}
|
|
70
|
-
const
|
|
71
|
-
let
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
108
|
+
const a = new AbortController();
|
|
109
|
+
let o = !1;
|
|
110
|
+
const u = () => {
|
|
111
|
+
e.getAccess({ skipTrial: s, skipVisibility: l, signal: a.signal }).then((h) => {
|
|
112
|
+
o || a.signal.aborted || r({ status: "ready", result: h });
|
|
75
113
|
}).catch(() => {
|
|
76
114
|
});
|
|
77
115
|
};
|
|
78
|
-
|
|
79
|
-
const
|
|
116
|
+
u();
|
|
117
|
+
const i = e.on("userChange", u), f = e.on("purchase_completed", u);
|
|
80
118
|
return () => {
|
|
81
|
-
|
|
119
|
+
o = !0, a.abort(), i(), f();
|
|
82
120
|
};
|
|
83
|
-
}, [
|
|
121
|
+
}, [e, s, l]), t;
|
|
84
122
|
}
|
|
85
|
-
function
|
|
86
|
-
const
|
|
87
|
-
prices:
|
|
123
|
+
function K() {
|
|
124
|
+
const n = c(), [e, t] = g(() => ({
|
|
125
|
+
prices: n?.getCachedPrices() ?? null,
|
|
88
126
|
loading: !0,
|
|
89
127
|
error: null
|
|
90
128
|
}));
|
|
91
|
-
return
|
|
92
|
-
if (!
|
|
129
|
+
return p(() => {
|
|
130
|
+
if (!n) {
|
|
93
131
|
t({ prices: null, loading: !0, error: null });
|
|
94
132
|
return;
|
|
95
133
|
}
|
|
96
|
-
const r =
|
|
134
|
+
const r = n.getCachedPrices();
|
|
97
135
|
t({ prices: r, loading: r === null, error: null });
|
|
98
|
-
const
|
|
99
|
-
let
|
|
136
|
+
const s = new AbortController();
|
|
137
|
+
let l = !1;
|
|
100
138
|
(() => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}).catch((
|
|
104
|
-
|
|
105
|
-
prices:
|
|
139
|
+
n.getPrices({ signal: s.signal }).then((u) => {
|
|
140
|
+
l || t({ prices: u, loading: !1, error: null });
|
|
141
|
+
}).catch((u) => {
|
|
142
|
+
l || s.signal.aborted || t((i) => ({
|
|
143
|
+
prices: i.prices,
|
|
106
144
|
loading: !1,
|
|
107
|
-
error:
|
|
145
|
+
error: u instanceof Error ? u : new Error(String(u))
|
|
108
146
|
}));
|
|
109
147
|
});
|
|
110
148
|
})();
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
|
|
149
|
+
const o = n.on("ready", () => {
|
|
150
|
+
const u = n.getCachedPrices();
|
|
151
|
+
u && t({ prices: u, loading: !1, error: null });
|
|
114
152
|
});
|
|
115
153
|
return () => {
|
|
116
|
-
|
|
154
|
+
l = !0, s.abort(), o();
|
|
117
155
|
};
|
|
118
|
-
}, [
|
|
156
|
+
}, [n]), e;
|
|
119
157
|
}
|
|
120
|
-
function
|
|
121
|
-
const e =
|
|
122
|
-
() => e
|
|
123
|
-
),
|
|
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(() => {
|
|
124
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(
|
|
195
|
+
() => n?.getTrialStatus() ?? null
|
|
196
|
+
), r = y(() => {
|
|
197
|
+
if (!n) {
|
|
125
198
|
t(null);
|
|
126
199
|
return;
|
|
127
200
|
}
|
|
128
|
-
t(
|
|
129
|
-
}, [
|
|
130
|
-
return
|
|
131
|
-
if (!
|
|
201
|
+
t(n.getTrialStatus());
|
|
202
|
+
}, [n]);
|
|
203
|
+
return p(() => {
|
|
204
|
+
if (!n) {
|
|
132
205
|
t(null);
|
|
133
206
|
return;
|
|
134
207
|
}
|
|
135
208
|
r();
|
|
136
|
-
const
|
|
209
|
+
const s = n.on("trial_blocked", r), l = n.on("trial_expired", r);
|
|
137
210
|
return () => {
|
|
138
|
-
|
|
211
|
+
s(), l();
|
|
139
212
|
};
|
|
140
|
-
}, [
|
|
213
|
+
}, [n, r]), e;
|
|
141
214
|
}
|
|
142
|
-
function
|
|
143
|
-
const
|
|
144
|
-
() =>
|
|
145
|
-
), r =
|
|
146
|
-
if (!
|
|
215
|
+
function Z() {
|
|
216
|
+
const n = c(), [e, t] = g(
|
|
217
|
+
() => n?.getVisibility() ?? null
|
|
218
|
+
), r = y(() => {
|
|
219
|
+
if (!n) {
|
|
147
220
|
t(null);
|
|
148
221
|
return;
|
|
149
222
|
}
|
|
150
|
-
t(
|
|
151
|
-
}, [
|
|
152
|
-
return
|
|
153
|
-
if (!
|
|
223
|
+
t(n.getVisibility());
|
|
224
|
+
}, [n]);
|
|
225
|
+
return p(() => {
|
|
226
|
+
if (!n) {
|
|
154
227
|
t(null);
|
|
155
228
|
return;
|
|
156
229
|
}
|
|
157
230
|
r();
|
|
158
|
-
const
|
|
231
|
+
const s = n.on("ready", r), l = n.on("visibility_blocked", r);
|
|
159
232
|
return () => {
|
|
160
|
-
|
|
233
|
+
s(), l();
|
|
161
234
|
};
|
|
162
|
-
}, [
|
|
235
|
+
}, [n, r]), e;
|
|
163
236
|
}
|
|
164
|
-
function
|
|
165
|
-
const
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
}, [
|
|
169
|
-
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 });
|
|
170
243
|
if (t.result.access === "granted")
|
|
171
|
-
return /* @__PURE__ */
|
|
172
|
-
const
|
|
173
|
-
return typeof
|
|
244
|
+
return /* @__PURE__ */ d(P, { children: n.children });
|
|
245
|
+
const l = n.fallback;
|
|
246
|
+
return typeof l == "function" ? /* @__PURE__ */ d(P, { children: l({
|
|
174
247
|
result: t.result,
|
|
175
|
-
open: () =>
|
|
176
|
-
}) }) : /* @__PURE__ */
|
|
248
|
+
open: () => e?.open()
|
|
249
|
+
}) }) : /* @__PURE__ */ d(P, { children: l ?? null });
|
|
177
250
|
}
|
|
178
|
-
const
|
|
179
|
-
function(
|
|
180
|
-
const r =
|
|
251
|
+
const j = R(
|
|
252
|
+
function(e, t) {
|
|
253
|
+
const r = c(), s = G(), {
|
|
181
254
|
mode: l = "paywall",
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
+
}
|
|
192
270
|
switch (l) {
|
|
193
271
|
case "support":
|
|
194
272
|
r.openSupport(w);
|
|
195
273
|
return;
|
|
196
274
|
case "auth":
|
|
197
|
-
|
|
275
|
+
case "signin":
|
|
276
|
+
r.openSignin(w);
|
|
198
277
|
return;
|
|
199
|
-
case "
|
|
200
|
-
r.
|
|
278
|
+
case "signup":
|
|
279
|
+
r.openSignup(w);
|
|
201
280
|
return;
|
|
202
281
|
default:
|
|
203
282
|
r.open(w);
|
|
204
283
|
}
|
|
284
|
+
}
|
|
205
285
|
};
|
|
206
|
-
return
|
|
286
|
+
return h ? h({ open: A, ready: v, processing: k }) : /* @__PURE__ */ d(
|
|
207
287
|
"button",
|
|
208
288
|
{
|
|
209
289
|
ref: t,
|
|
210
290
|
type: "button",
|
|
211
|
-
disabled:
|
|
212
|
-
"aria-busy":
|
|
213
|
-
onClick: (
|
|
214
|
-
|
|
291
|
+
disabled: I || !v || k,
|
|
292
|
+
"aria-busy": !v || k ? !0 : void 0,
|
|
293
|
+
onClick: (M) => {
|
|
294
|
+
A(), V?.(M);
|
|
215
295
|
},
|
|
216
|
-
...
|
|
296
|
+
...U
|
|
217
297
|
}
|
|
218
298
|
);
|
|
219
299
|
}
|
|
220
|
-
),
|
|
221
|
-
return /* @__PURE__ */
|
|
300
|
+
), en = R(function(e, t) {
|
|
301
|
+
return /* @__PURE__ */ d(j, { ...e, mode: "support", ref: t });
|
|
222
302
|
});
|
|
223
303
|
export {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
|
236
318
|
};
|
|
237
319
|
//# sourceMappingURL=index.js.map
|