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