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