mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
Delete packages/ee/ and packages/trpc/server/enterprise-router/. The features
those directories gated — limits, custom email domains, SAML/SSO authentication
portal, account linking — are now permanently available to every user. Stripe
billing surface (subscriptions, plans, invoices, paywall webhook) is gone in
its entirety.
- Move limits provider/server/client/handler/schema/constants from
packages/ee/server-only/limits/ into packages/lib/server-only/limits/.
getServerLimits always returns the self-hosted unlimited plan; no plan tier
lookup, no IS_BILLING_ENABLED gating.
- Move email-domain helpers (create/delete/verify/reregister) from
packages/ee/server-only/lib/ into packages/lib/server-only/email-domain/.
- Move link-organisation-account + send-organisation-account-link-confirmation
-email from packages/ee/server-only/lib/ into
packages/lib/server-only/organisation/.
- Move every non-stripe route from packages/trpc/server/enterprise-router/
into packages/trpc/server/organisation-router/ and expose them at
trpc.organisation.{email,emailDomain,authenticationPortal}.*.
- Delete the entire stripe subtree (ee + lib stripe SDK + lib billing utils
+ apps/remix stripe.webhook route).
- IS_BILLING_ENABLED() now always returns false; downstream paywall branches
become dead code that always opens the feature up.
- Strip the billing settings page and dialog, billing banner/portal button,
billing-plans selector, and stripe-customer admin route.
94 lines
2.1 KiB
TypeScript
94 lines
2.1 KiB
TypeScript
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
|
|
|
import { isDeepEqual } from 'remeda';
|
|
|
|
import { getLimits } from '../client';
|
|
import { DEFAULT_MINIMUM_ENVELOPE_ITEM_COUNT, FREE_PLAN_LIMITS } from '../constants';
|
|
import type { TLimitsResponseSchema } from '../schema';
|
|
|
|
export type LimitsContextValue = TLimitsResponseSchema & { refreshLimits: () => Promise<void> };
|
|
|
|
const LimitsContext = createContext<LimitsContextValue | null>(null);
|
|
|
|
export const useLimits = () => {
|
|
const limits = useContext(LimitsContext);
|
|
|
|
if (!limits) {
|
|
throw new Error('useLimits must be used within a LimitsProvider');
|
|
}
|
|
|
|
return limits;
|
|
};
|
|
|
|
export type LimitsProviderProps = {
|
|
initialValue?: TLimitsResponseSchema;
|
|
|
|
/**
|
|
* Bypass limits for embed authoring. This is just client side bypass since
|
|
* all embeds should be paid plans.
|
|
*/
|
|
disableLimitsFetch?: boolean;
|
|
teamId: number;
|
|
children?: React.ReactNode;
|
|
};
|
|
|
|
export const LimitsProvider = ({
|
|
initialValue = {
|
|
quota: FREE_PLAN_LIMITS,
|
|
remaining: FREE_PLAN_LIMITS,
|
|
maximumEnvelopeItemCount: DEFAULT_MINIMUM_ENVELOPE_ITEM_COUNT,
|
|
},
|
|
disableLimitsFetch,
|
|
teamId,
|
|
children,
|
|
}: LimitsProviderProps) => {
|
|
const [limits, setLimits] = useState(() => initialValue);
|
|
|
|
const refreshLimits = useCallback(async () => {
|
|
if (disableLimitsFetch) {
|
|
return;
|
|
}
|
|
|
|
const newLimits = await getLimits({ teamId });
|
|
|
|
setLimits((oldLimits) => {
|
|
if (isDeepEqual(oldLimits, newLimits)) {
|
|
return oldLimits;
|
|
}
|
|
|
|
return newLimits;
|
|
});
|
|
}, [teamId]);
|
|
|
|
useEffect(() => {
|
|
void refreshLimits();
|
|
}, [refreshLimits]);
|
|
|
|
useEffect(() => {
|
|
if (disableLimitsFetch) {
|
|
return;
|
|
}
|
|
|
|
const onFocus = () => {
|
|
void refreshLimits();
|
|
};
|
|
|
|
window.addEventListener('focus', onFocus);
|
|
|
|
return () => {
|
|
window.removeEventListener('focus', onFocus);
|
|
};
|
|
}, [refreshLimits]);
|
|
|
|
return (
|
|
<LimitsContext.Provider
|
|
value={{
|
|
...limits,
|
|
refreshLimits,
|
|
}}
|
|
>
|
|
{children}
|
|
</LimitsContext.Provider>
|
|
);
|
|
};
|