azirid-react 0.9.8 → 0.10.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 +4 -2
- package/dist/index.cjs +81 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +81 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -738,9 +738,8 @@ declare global {
|
|
|
738
738
|
* Internal widget renderer — loads Payphone SDK and mounts PPaymentButtonBox.
|
|
739
739
|
* Used by usePayphoneCheckout, usePayButton hooks and PayphoneModal component.
|
|
740
740
|
*/
|
|
741
|
-
declare function PayphoneWidgetRenderer({ config,
|
|
741
|
+
declare function PayphoneWidgetRenderer({ config, containerId, onReady, onError, }: {
|
|
742
742
|
config: PayphoneWidgetConfig;
|
|
743
|
-
responseUrl: string;
|
|
744
743
|
containerId: string;
|
|
745
744
|
onReady?: () => void;
|
|
746
745
|
onError?: (error: Error) => void;
|
|
@@ -1952,7 +1951,6 @@ interface TransferModalProps {
|
|
|
1952
1951
|
|
|
1953
1952
|
interface PayphoneModalProps {
|
|
1954
1953
|
config: PayphoneWidgetConfig;
|
|
1955
|
-
successUrl: string;
|
|
1956
1954
|
onClose: () => void;
|
|
1957
1955
|
}
|
|
1958
1956
|
|
package/dist/index.d.ts
CHANGED
|
@@ -738,9 +738,8 @@ declare global {
|
|
|
738
738
|
* Internal widget renderer — loads Payphone SDK and mounts PPaymentButtonBox.
|
|
739
739
|
* Used by usePayphoneCheckout, usePayButton hooks and PayphoneModal component.
|
|
740
740
|
*/
|
|
741
|
-
declare function PayphoneWidgetRenderer({ config,
|
|
741
|
+
declare function PayphoneWidgetRenderer({ config, containerId, onReady, onError, }: {
|
|
742
742
|
config: PayphoneWidgetConfig;
|
|
743
|
-
responseUrl: string;
|
|
744
743
|
containerId: string;
|
|
745
744
|
onReady?: () => void;
|
|
746
745
|
onError?: (error: Error) => void;
|
|
@@ -1952,7 +1951,6 @@ interface TransferModalProps {
|
|
|
1952
1951
|
|
|
1953
1952
|
interface PayphoneModalProps {
|
|
1954
1953
|
config: PayphoneWidgetConfig;
|
|
1955
|
-
successUrl: string;
|
|
1956
1954
|
onClose: () => void;
|
|
1957
1955
|
}
|
|
1958
1956
|
|
package/dist/index.js
CHANGED
|
@@ -163,6 +163,31 @@ function createAccessClient(config, appContext) {
|
|
|
163
163
|
let refreshToken = ssGet(storageKeyRt);
|
|
164
164
|
let csrfToken = ssGet(storageKeyCsrf);
|
|
165
165
|
let refreshPromise = null;
|
|
166
|
+
let channel = null;
|
|
167
|
+
try {
|
|
168
|
+
if (typeof BroadcastChannel !== "undefined") {
|
|
169
|
+
channel = new BroadcastChannel("azirid-auth");
|
|
170
|
+
channel.onmessage = (event) => {
|
|
171
|
+
if (event.data?.type === "token-refreshed") {
|
|
172
|
+
accessToken = event.data.accessToken;
|
|
173
|
+
if (event.data.refreshToken) setRefreshToken(event.data.refreshToken);
|
|
174
|
+
if (event.data.csrfToken) setCsrfToken(event.data.csrfToken);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
} catch {
|
|
179
|
+
}
|
|
180
|
+
function broadcastTokens() {
|
|
181
|
+
try {
|
|
182
|
+
channel?.postMessage({
|
|
183
|
+
type: "token-refreshed",
|
|
184
|
+
accessToken,
|
|
185
|
+
refreshToken,
|
|
186
|
+
csrfToken
|
|
187
|
+
});
|
|
188
|
+
} catch {
|
|
189
|
+
}
|
|
190
|
+
}
|
|
166
191
|
function setAccessToken(token) {
|
|
167
192
|
accessToken = token;
|
|
168
193
|
}
|
|
@@ -224,6 +249,7 @@ function createAccessClient(config, appContext) {
|
|
|
224
249
|
const xc = json.xc ?? json.csrfToken;
|
|
225
250
|
if (rt) setRefreshToken(rt);
|
|
226
251
|
if (xc) setCsrfToken(xc);
|
|
252
|
+
broadcastTokens();
|
|
227
253
|
}
|
|
228
254
|
function refreshTokens(opts) {
|
|
229
255
|
if (opts?.tenantId) {
|
|
@@ -773,6 +799,27 @@ function AziridProviderInner({
|
|
|
773
799
|
}, [client, props.autoBootstrap, updateAccessToken, saveSessionTokens]);
|
|
774
800
|
const silentRefresh = useCallback(async () => {
|
|
775
801
|
if (!client.getAccessToken()) return;
|
|
802
|
+
if (typeof navigator !== "undefined" && "locks" in navigator) {
|
|
803
|
+
let acquired = false;
|
|
804
|
+
try {
|
|
805
|
+
await navigator.locks.request(
|
|
806
|
+
"azirid-token-refresh",
|
|
807
|
+
{ ifAvailable: true },
|
|
808
|
+
async (lock) => {
|
|
809
|
+
if (!lock) return;
|
|
810
|
+
acquired = true;
|
|
811
|
+
await client.refreshSession();
|
|
812
|
+
updateAccessToken(client.getAccessToken());
|
|
813
|
+
}
|
|
814
|
+
);
|
|
815
|
+
} catch (err) {
|
|
816
|
+
if (acquired && isAuthError(err)) {
|
|
817
|
+
clearSession();
|
|
818
|
+
props.onSessionExpired?.();
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
776
823
|
try {
|
|
777
824
|
await client.refreshSession();
|
|
778
825
|
updateAccessToken(client.getAccessToken());
|
|
@@ -783,6 +830,27 @@ function AziridProviderInner({
|
|
|
783
830
|
}
|
|
784
831
|
}
|
|
785
832
|
}, [client, updateAccessToken, clearSession, props]);
|
|
833
|
+
useEffect(() => {
|
|
834
|
+
let channel = null;
|
|
835
|
+
try {
|
|
836
|
+
if (typeof BroadcastChannel !== "undefined") {
|
|
837
|
+
channel = new BroadcastChannel("azirid-auth");
|
|
838
|
+
channel.onmessage = (event) => {
|
|
839
|
+
if (event.data?.type === "token-refreshed" && event.data.accessToken) {
|
|
840
|
+
client.setAccessToken(event.data.accessToken);
|
|
841
|
+
updateAccessToken(event.data.accessToken);
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
} catch {
|
|
846
|
+
}
|
|
847
|
+
return () => {
|
|
848
|
+
try {
|
|
849
|
+
channel?.close();
|
|
850
|
+
} catch {
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
}, [client, updateAccessToken]);
|
|
786
854
|
useEffect(() => {
|
|
787
855
|
const intervalMs = props.refreshInterval ?? 5e4;
|
|
788
856
|
if (intervalMs <= 0) return;
|
|
@@ -2295,7 +2363,6 @@ function loadPayphoneSdk() {
|
|
|
2295
2363
|
}
|
|
2296
2364
|
function PayphoneWidgetRenderer({
|
|
2297
2365
|
config,
|
|
2298
|
-
responseUrl,
|
|
2299
2366
|
containerId,
|
|
2300
2367
|
onReady,
|
|
2301
2368
|
onError
|
|
@@ -2317,18 +2384,17 @@ function PayphoneWidgetRenderer({
|
|
|
2317
2384
|
amountWithoutTax: config.amountWithoutTax,
|
|
2318
2385
|
currency: config.currency,
|
|
2319
2386
|
storeId: config.storeId,
|
|
2320
|
-
reference: config.reference
|
|
2321
|
-
responseUrl
|
|
2387
|
+
reference: config.reference
|
|
2322
2388
|
}).render(containerId);
|
|
2323
2389
|
onReady?.();
|
|
2324
2390
|
});
|
|
2325
2391
|
}).catch((err) => {
|
|
2326
2392
|
onError?.(new Error(err instanceof Error ? err.message : "Failed to load Payphone SDK"));
|
|
2327
2393
|
});
|
|
2328
|
-
}, [config,
|
|
2394
|
+
}, [config, containerId, onReady, onError]);
|
|
2329
2395
|
return /* @__PURE__ */ jsx("div", { id: containerId });
|
|
2330
2396
|
}
|
|
2331
|
-
function PayphoneModal({ config,
|
|
2397
|
+
function PayphoneModal({ config, onClose }) {
|
|
2332
2398
|
const [error, setError] = useState(null);
|
|
2333
2399
|
return /* @__PURE__ */ jsx("div", { style: overlayStyle, onClick: onClose, children: /* @__PURE__ */ jsxs("div", { style: cardStyle, onClick: (e) => e.stopPropagation(), children: [
|
|
2334
2400
|
/* @__PURE__ */ jsx("h2", { style: titleStyle, children: "Payphone" }),
|
|
@@ -2337,7 +2403,6 @@ function PayphoneModal({ config, successUrl, onClose }) {
|
|
|
2337
2403
|
PayphoneWidgetRenderer,
|
|
2338
2404
|
{
|
|
2339
2405
|
config,
|
|
2340
|
-
responseUrl: successUrl,
|
|
2341
2406
|
containerId: "pp-button-azirid",
|
|
2342
2407
|
onError: (err) => setError(err.message)
|
|
2343
2408
|
}
|
|
@@ -2862,7 +2927,6 @@ function PricingTable({
|
|
|
2862
2927
|
PayphoneModal,
|
|
2863
2928
|
{
|
|
2864
2929
|
config: payphoneData.widgetConfig,
|
|
2865
|
-
successUrl,
|
|
2866
2930
|
onClose: () => setPayphoneData(null)
|
|
2867
2931
|
}
|
|
2868
2932
|
)
|
|
@@ -2942,7 +3006,6 @@ function usePayButton({
|
|
|
2942
3006
|
const [payphoneConfig, setPayphoneConfig] = useState(null);
|
|
2943
3007
|
const [currentError, setCurrentError] = useState(null);
|
|
2944
3008
|
const payphoneConfirmTriggered = useRef(false);
|
|
2945
|
-
const responseUrl = typeof window !== "undefined" ? window.location.href.split("?")[0] : "";
|
|
2946
3009
|
const params = typeof window !== "undefined" ? new URLSearchParams(window.location.search) : new URLSearchParams();
|
|
2947
3010
|
const callbackId = params.get("id");
|
|
2948
3011
|
const callbackClientTxId = params.get("clientTransactionId");
|
|
@@ -2993,15 +3056,16 @@ function usePayButton({
|
|
|
2993
3056
|
setSelectedProvider(provider);
|
|
2994
3057
|
setStatus("processing");
|
|
2995
3058
|
setCurrentError(null);
|
|
3059
|
+
const currentUrl = typeof window !== "undefined" ? window.location.href.split("?")[0] : "";
|
|
2996
3060
|
doCheckout({
|
|
2997
3061
|
intentId,
|
|
2998
3062
|
planId,
|
|
2999
3063
|
provider,
|
|
3000
|
-
successUrl:
|
|
3001
|
-
cancelUrl:
|
|
3064
|
+
successUrl: currentUrl,
|
|
3065
|
+
cancelUrl: currentUrl
|
|
3002
3066
|
});
|
|
3003
3067
|
},
|
|
3004
|
-
[doCheckout, intentId, planId
|
|
3068
|
+
[doCheckout, intentId, planId]
|
|
3005
3069
|
);
|
|
3006
3070
|
const { mutate: confirmPayphone } = usePayphoneConfirm({
|
|
3007
3071
|
onSuccess: (data) => {
|
|
@@ -3148,12 +3212,11 @@ function usePayButton({
|
|
|
3148
3212
|
if (!payphoneConfig || isPayphoneCallback) return null;
|
|
3149
3213
|
return PayphoneWidgetRenderer({
|
|
3150
3214
|
config: payphoneConfig,
|
|
3151
|
-
responseUrl,
|
|
3152
3215
|
containerId: PP_CONTAINER_ID,
|
|
3153
3216
|
onError: handleSdkError
|
|
3154
3217
|
});
|
|
3155
3218
|
};
|
|
3156
|
-
}, [payphoneConfig,
|
|
3219
|
+
}, [payphoneConfig, isPayphoneCallback, handleSdkError]);
|
|
3157
3220
|
return {
|
|
3158
3221
|
providers,
|
|
3159
3222
|
checkout,
|
|
@@ -3452,7 +3515,6 @@ function PayButton({
|
|
|
3452
3515
|
PayphoneModal,
|
|
3453
3516
|
{
|
|
3454
3517
|
config: checkoutData.widgetConfig,
|
|
3455
|
-
successUrl,
|
|
3456
3518
|
onClose: () => {
|
|
3457
3519
|
onSuccess?.(checkoutData);
|
|
3458
3520
|
}
|
|
@@ -3976,7 +4038,6 @@ function usePayphoneCheckout({
|
|
|
3976
4038
|
const [currentError, setCurrentError] = useState(null);
|
|
3977
4039
|
const checkoutTriggered = useRef(false);
|
|
3978
4040
|
const confirmTriggered = useRef(false);
|
|
3979
|
-
const responseUrl = typeof window !== "undefined" ? window.location.href.split("?")[0] : "";
|
|
3980
4041
|
const params = typeof window !== "undefined" ? new URLSearchParams(window.location.search) : new URLSearchParams();
|
|
3981
4042
|
const callbackId = params.get("id");
|
|
3982
4043
|
const callbackClientTxId = params.get("clientTransactionId");
|
|
@@ -4002,10 +4063,10 @@ function usePayphoneCheckout({
|
|
|
4002
4063
|
checkout({
|
|
4003
4064
|
intentId,
|
|
4004
4065
|
provider: "PAYPHONE",
|
|
4005
|
-
successUrl:
|
|
4006
|
-
cancelUrl:
|
|
4066
|
+
successUrl: window.location.href,
|
|
4067
|
+
cancelUrl: window.location.href
|
|
4007
4068
|
});
|
|
4008
|
-
}, [checkout, intentId,
|
|
4069
|
+
}, [checkout, intentId, isCallback]);
|
|
4009
4070
|
const { mutate: confirm } = usePayphoneConfirm({
|
|
4010
4071
|
onSuccess: (data) => {
|
|
4011
4072
|
setStatus(data.status === "confirmed" || data.status === "already_confirmed" ? "confirmed" : "cancelled");
|
|
@@ -4036,12 +4097,11 @@ function usePayphoneCheckout({
|
|
|
4036
4097
|
if (!widgetConfig || isCallback) return null;
|
|
4037
4098
|
return PayphoneWidgetRenderer({
|
|
4038
4099
|
config: widgetConfig,
|
|
4039
|
-
responseUrl,
|
|
4040
4100
|
containerId: CONTAINER_ID,
|
|
4041
4101
|
onError: handleSdkError
|
|
4042
4102
|
});
|
|
4043
4103
|
};
|
|
4044
|
-
}, [widgetConfig,
|
|
4104
|
+
}, [widgetConfig, isCallback, handleSdkError]);
|
|
4045
4105
|
return { PayphoneWidget, status, intentId, error: currentError };
|
|
4046
4106
|
}
|
|
4047
4107
|
function useTransferPayment({
|
|
@@ -4281,7 +4341,7 @@ function usePasswordToggle() {
|
|
|
4281
4341
|
}
|
|
4282
4342
|
|
|
4283
4343
|
// src/index.ts
|
|
4284
|
-
var SDK_VERSION = "0.
|
|
4344
|
+
var SDK_VERSION = "0.10.0";
|
|
4285
4345
|
|
|
4286
4346
|
export { AuthForm, AziridProvider, BASE_PATHS, CheckoutButton, ForgotPasswordForm, InvoiceList, LoginForm, PATHS, PayButton, PayphoneCallback, PayphoneWidgetRenderer, PricingTable, ReferralCard, ReferralStats, ResetPasswordForm, SDK_VERSION, SignupForm, SubscriptionBadge, buildPaths, changePasswordSchema, cn, createAccessClient, createForgotPasswordSchema, createLoginSchema, createMutationHook, createResetPasswordConfirmSchema, createSignupSchema, en, es, forgotPasswordSchema, isAuthError, loginSchema, magicLinkRequestSchema, magicLinkVerifySchema, passkeyRegisterStartSchema, removeStyles, resetPasswordConfirmSchema, resolveMessages, signupSchema, socialLoginSchema, useAccessClient, useAzirid, useBootstrap, useBranding, useChangePassword, useCheckout, useFormState, useInvoices, useLogin, useLogout, useMagicLink, useMessages, usePasskeys, usePasswordReset, usePasswordToggle, usePayButton, usePaymentProviders, usePayphoneCheckout, usePayphoneConfirm, usePlans, useReferral, useReferralStats, useRefresh, useSession, useSignup, useSocialLogin, useSubmitTransferProof, useSubscription, useSwitchTenant, useTenantMembers, useTenants, useTransferPayment, useTransferProofs };
|
|
4287
4347
|
//# sourceMappingURL=index.js.map
|