@eifi1/ui-kit 0.32.2 → 0.33.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 +16 -8
- package/dist/account/delete-account-setting.d.ts +10 -10
- package/dist/account/delete-account-setting.js +2 -1
- package/dist/account/delete-account-setting.js.map +1 -1
- package/dist/account/email-change-setting.d.ts +5 -0
- package/dist/account/email-change-setting.js +4 -3
- package/dist/account/email-change-setting.js.map +1 -1
- package/dist/account/sessions-setting.d.ts +4 -0
- package/dist/account/sessions-setting.js +3 -2
- package/dist/account/sessions-setting.js.map +1 -1
- package/dist/admin/admin-action-confirm.d.ts +10 -10
- package/dist/admin/admin-action-confirm.js.map +1 -1
- package/dist/admin/invitations-panel.d.ts +10 -10
- package/dist/admin/invitations-panel.js +4 -3
- package/dist/admin/invitations-panel.js.map +1 -1
- package/dist/admin/plan-change.d.ts +100 -0
- package/dist/admin/plan-change.js +208 -0
- package/dist/admin/plan-change.js.map +1 -0
- package/dist/admin/reviewer-scope-editor.d.ts +10 -10
- package/dist/admin/reviewer-scope-editor.js.map +1 -1
- package/dist/admin/role-select.d.ts +7 -7
- package/dist/admin/role-select.js.map +1 -1
- package/dist/admin/transfer-ownership-dialog.d.ts +10 -10
- package/dist/admin/user-roster.d.ts +7 -7
- package/dist/admin/user-roster.js +2 -2
- package/dist/admin/user-roster.js.map +1 -1
- package/dist/auth/auth-errors.d.ts +13 -2
- package/dist/auth/auth-errors.js +5 -1
- package/dist/auth/auth-errors.js.map +1 -1
- package/dist/auth/complete-name-dialog.d.ts +4 -1
- package/dist/auth/complete-name-dialog.js +2 -1
- package/dist/auth/complete-name-dialog.js.map +1 -1
- package/dist/auth/register-form.d.ts +10 -10
- package/dist/billing/billing-banner.d.ts +13 -11
- package/dist/billing/billing-banner.js.map +1 -1
- package/dist/billing/billing-labels.d.ts +10 -10
- package/dist/billing/billing-labels.js +10 -1
- package/dist/billing/billing-labels.js.map +1 -1
- package/dist/billing/billing-lock.d.ts +39 -12
- package/dist/billing/billing-lock.js +9 -3
- package/dist/billing/billing-lock.js.map +1 -1
- package/dist/billing/billing-overview.d.ts +154 -0
- package/dist/billing/billing-overview.js +2 -0
- package/dist/billing/billing-overview.js.map +1 -0
- package/dist/billing/billing-standing.d.ts +10 -10
- package/dist/billing/checkout-processing.d.ts +217 -0
- package/dist/billing/checkout-processing.js +198 -0
- package/dist/billing/checkout-processing.js.map +1 -0
- package/dist/billing/checkout-return.d.ts +51 -0
- package/dist/billing/checkout-return.js +43 -0
- package/dist/billing/checkout-return.js.map +1 -0
- package/dist/billing/pay-page.d.ts +210 -0
- package/dist/billing/pay-page.js +113 -0
- package/dist/billing/pay-page.js.map +1 -0
- package/dist/billing/plan-card.d.ts +10 -10
- package/dist/billing/plan-limit-notice.d.ts +10 -10
- package/dist/billing/plan-limit-toast.d.ts +143 -0
- package/dist/billing/plan-limit-toast.js +40 -0
- package/dist/billing/plan-limit-toast.js.map +1 -0
- package/dist/billing/subscription-actions.d.ts +38 -15
- package/dist/billing/subscription-actions.js +9 -2
- package/dist/billing/subscription-actions.js.map +1 -1
- package/dist/billing/subscription-status-chip.d.ts +9 -9
- package/dist/bin/eifi1-pay-page.mjs +166 -0
- package/dist/chart.d.ts +10 -10
- package/dist/components/account-chips.d.ts +6 -1
- package/dist/components/account-settings.d.ts +4 -1
- package/dist/components/account-settings.js +2 -1
- package/dist/components/account-settings.js.map +1 -1
- package/dist/components/amount-input.d.ts +10 -10
- package/dist/components/autocomplete.d.ts +2 -1
- package/dist/components/autocomplete.js +3 -1
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/button-group.d.ts +10 -10
- package/dist/components/button-group.js +1 -1
- package/dist/components/button-group.js.map +1 -1
- package/dist/components/calculator.d.ts +10 -10
- package/dist/components/calculator.js +3 -3
- package/dist/components/calculator.js.map +1 -1
- package/dist/components/checkbox-group.d.ts +2 -1
- package/dist/components/checkbox-group.js.map +1 -1
- package/dist/components/checkbox.d.ts +2 -1
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/chip.d.ts +2 -1
- package/dist/components/chip.js +19 -17
- package/dist/components/chip.js.map +1 -1
- package/dist/components/choice-card.d.ts +3 -1
- package/dist/components/choice-card.js +1 -1
- package/dist/components/choice-card.js.map +1 -1
- package/dist/components/combobox.d.ts +4 -3
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/confirm-dialog.d.ts +10 -10
- package/dist/components/confirm-dialog.js +6 -3
- package/dist/components/confirm-dialog.js.map +1 -1
- package/dist/components/copy-button.d.ts +11 -11
- package/dist/components/country-select.d.ts +2 -1
- package/dist/components/country-select.js.map +1 -1
- package/dist/components/danger-confirm.d.ts +10 -10
- package/dist/components/danger-confirm.js.map +1 -1
- package/dist/components/data-table-cells.d.ts +12 -1
- package/dist/components/data-table-filter-popover.d.ts +12 -1
- package/dist/components/data-table-filters.d.ts +12 -1
- package/dist/components/data-table-labels.d.ts +12 -1
- package/dist/components/data-table-pagination.d.ts +12 -1
- package/dist/components/data-table.d.ts +12 -1
- package/dist/components/data-table.js +3 -3
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.js +6 -4
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/entity-combobox.d.ts +3 -2
- package/dist/components/entity-combobox.js.map +1 -1
- package/dist/components/facing-pair.d.ts +10 -10
- package/dist/components/field-parts.d.ts +32 -4
- package/dist/components/field-parts.js +54 -19
- package/dist/components/field-parts.js.map +1 -1
- package/dist/components/file-button.d.ts +10 -10
- package/dist/components/file-button.js +3 -2
- package/dist/components/file-button.js.map +1 -1
- package/dist/components/file-dropzone.d.ts +11 -11
- package/dist/components/file-dropzone.js.map +1 -1
- package/dist/components/floating-panel.js +5 -5
- package/dist/components/floating-panel.js.map +1 -1
- package/dist/components/form-actions.d.ts +9 -9
- package/dist/components/form-actions.js +3 -3
- package/dist/components/form-actions.js.map +1 -1
- package/dist/components/iban-input.d.ts +10 -10
- package/dist/components/inline-edit-field.d.ts +2 -1
- package/dist/components/inline-edit-field.js +6 -6
- package/dist/components/inline-edit-field.js.map +1 -1
- package/dist/components/language-select.d.ts +10 -10
- package/dist/components/legal-page.d.ts +10 -10
- package/dist/components/legal.d.ts +10 -10
- package/dist/components/list.d.ts +2 -1
- package/dist/components/list.js +4 -5
- package/dist/components/list.js.map +1 -1
- package/dist/components/money-field.d.ts +10 -10
- package/dist/components/month-picker.js +54 -44
- package/dist/components/month-picker.js.map +1 -1
- package/dist/components/multi-entity-combobox.d.ts +3 -2
- package/dist/components/multi-entity-combobox.js.map +1 -1
- package/dist/components/number-field.d.ts +10 -10
- package/dist/components/number-input.d.ts +10 -10
- package/dist/components/numpad-sheet.d.ts +10 -10
- package/dist/components/numpad-sheet.js +2 -2
- package/dist/components/numpad-sheet.js.map +1 -1
- package/dist/components/phone-input.d.ts +10 -10
- package/dist/components/row-actions.d.ts +5 -5
- package/dist/components/row-actions.js +130 -32
- package/dist/components/row-actions.js.map +1 -1
- package/dist/components/series-chart.d.ts +10 -10
- package/dist/components/settings-fields.d.ts +10 -10
- package/dist/components/share-card.d.ts +7 -7
- package/dist/components/share-card.js +26 -10
- package/dist/components/share-card.js.map +1 -1
- package/dist/components/status-dot.d.ts +1 -0
- package/dist/components/status-dot.js +2 -2
- package/dist/components/status-dot.js.map +1 -1
- package/dist/components/swatch-picker.d.ts +2 -1
- package/dist/components/swatch-picker.js.map +1 -1
- package/dist/components/swipeable-row.d.ts +88 -17
- package/dist/components/swipeable-row.js +46 -9
- package/dist/components/swipeable-row.js.map +1 -1
- package/dist/components/switch.d.ts +2 -1
- package/dist/components/switch.js.map +1 -1
- package/dist/components/table.d.ts +2 -1
- package/dist/components/table.js +6 -0
- package/dist/components/table.js.map +1 -1
- package/dist/components/text-link.d.ts +9 -9
- package/dist/components/time-input.d.ts +10 -10
- package/dist/components/toggle-group.d.ts +2 -1
- package/dist/components/toggle-group.js +1 -1
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/translation-review-editor.d.ts +4 -0
- package/dist/components/translation-review-editor.js +4 -3
- package/dist/components/translation-review-editor.js.map +1 -1
- package/dist/components/translation-review-parts.d.ts +1 -0
- package/dist/components/translation-review.d.ts +1 -0
- package/dist/components/translation-review.js +15 -18
- package/dist/components/translation-review.js.map +1 -1
- package/dist/components/ui.d.ts +9 -9
- package/dist/components/ui.js +47 -27
- package/dist/components/ui.js.map +1 -1
- package/dist/components/use-table-state.d.ts +12 -1
- package/dist/components/user-avatar.d.ts +1 -0
- package/dist/components/write-lock.d.ts +101 -13
- package/dist/components/write-lock.js +37 -13
- package/dist/components/write-lock.js.map +1 -1
- package/dist/{data-table-labels-kpAAVi6g.d.ts → data-table-labels-BJ5JE_X2.d.ts} +17 -0
- package/dist/data-table.d.ts +12 -1
- package/dist/{delete-account-setting-Dy4kJgUm.d.ts → delete-account-setting-DiPX4Vue.d.ts} +355 -41
- package/dist/feedback/feedback-attachment.d.ts +10 -10
- package/dist/feedback/feedback-attachment.js +7 -7
- package/dist/feedback/feedback-attachment.js.map +1 -1
- package/dist/feedback/feedback-context.d.ts +10 -10
- package/dist/feedback/feedback-crash.d.ts +10 -10
- package/dist/feedback/feedback-dialog.d.ts +10 -10
- package/dist/feedback/feedback-inbox.d.ts +9 -9
- package/dist/feedback/feedback-inbox.js +7 -3
- package/dist/feedback/feedback-inbox.js.map +1 -1
- package/dist/feedback/feedback-labels.d.ts +10 -10
- package/dist/feedback/feedback-menu.d.ts +3 -3
- package/dist/feedback/feedback-record.d.ts +10 -10
- package/dist/feedback/feedback-row-detail.d.ts +10 -10
- package/dist/feedback/feedback-row-detail.js.map +1 -1
- package/dist/feedback/feedback-status-undo.d.ts +10 -10
- package/dist/feedback/feedback-submit.d.ts +10 -10
- package/dist/feedback/feedback-swipe.d.ts +10 -10
- package/dist/feedback/feedback-swipe.js +3 -6
- package/dist/feedback/feedback-swipe.js.map +1 -1
- package/dist/feedback/feedback-table.d.ts +10 -10
- package/dist/feedback/feedback-table.js.map +1 -1
- package/dist/feedback/feedback-thread.d.ts +10 -10
- package/dist/feedback.d.ts +10 -10
- package/dist/hooks/use-file-drop.d.ts +10 -10
- package/dist/i18n/defaults.d.ts +10 -10
- package/dist/i18n/defaults.js +2 -0
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.d.ts +10 -10
- package/dist/i18n/german.js +34 -1
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +4 -4
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/languages.d.ts +10 -10
- package/dist/i18n/locales/de-CH.d.ts +10 -10
- package/dist/i18n/locales/en.d.ts +10 -10
- package/dist/i18n/locales/es.d.ts +10 -10
- package/dist/i18n/locales/es.js +34 -1
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +10 -10
- package/dist/i18n/locales/fr.js +35 -1
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +10 -10
- package/dist/i18n/locales/hu.js +36 -1
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +10 -10
- package/dist/i18n/locales/it.js +34 -1
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +10 -10
- package/dist/i18n/locales/zh.js +34 -1
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.d.ts +10 -10
- package/dist/i18n/review.js +8 -1
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.js +40 -2
- package/dist/index.js.map +1 -1
- package/dist/landing/landing-actions.d.ts +10 -10
- package/dist/landing/landing-sections.d.ts +10 -10
- package/dist/landing/public-header.d.ts +10 -10
- package/dist/landing/routing.d.ts +10 -10
- package/dist/pay/.well-known/apple-developer-merchantid-domain-association +1 -0
- package/dist/pay/index.html +30 -0
- package/dist/pay/pay.css +126 -0
- package/dist/pay/pay.js +198 -0
- package/dist/rhf/fields.d.ts +10 -10
- package/dist/rhf/form.d.ts +10 -10
- package/dist/rhf.d.ts +10 -10
- package/dist/settings/settings-section.d.ts +10 -10
- package/dist/shell/app-shell.d.ts +9 -9
- package/dist/shell/top-bar-brand.d.ts +10 -10
- package/dist/shell/topbar-action-menu.d.ts +1 -0
- package/dist/shell.d.ts +10 -10
- package/dist/testing/css-variables.d.ts +74 -0
- package/dist/testing/css-variables.generated.d.ts +7 -0
- package/dist/testing/css-variables.generated.js +8 -0
- package/dist/testing/css-variables.generated.js.map +1 -0
- package/dist/testing/css-variables.js +93 -0
- package/dist/testing/css-variables.js.map +1 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.js +12 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/theme/contrast-tokens.d.ts +44 -1
- package/dist/theme/contrast-tokens.js +21 -0
- package/dist/theme/contrast-tokens.js.map +1 -1
- package/dist/theme/contrast.d.ts +2 -2
- package/dist/theme/palette-derive.js +60 -11
- package/dist/theme/palette-derive.js.map +1 -1
- package/dist/theme/palette-presets.js +45 -43
- package/dist/theme/palette-presets.js.map +1 -1
- package/dist/wizard/stepper-nav.d.ts +11 -11
- package/dist/wizard/stepper-nav.js.map +1 -1
- package/dist/wizard.d.ts +10 -10
- package/package.json +10 -2
- package/src/account/delete-account-setting.tsx +6 -1
- package/src/account/email-change-setting.tsx +9 -3
- package/src/account/sessions-setting.tsx +7 -2
- package/src/admin/admin-action-confirm.tsx +2 -1
- package/src/admin/invitations-panel.tsx +9 -3
- package/src/admin/plan-change.tsx +459 -0
- package/src/admin/reviewer-scope-editor.tsx +2 -1
- package/src/admin/role-select.tsx +2 -1
- package/src/admin/user-roster.tsx +5 -3
- package/src/auth/auth-errors.ts +25 -2
- package/src/auth/complete-name-dialog.tsx +6 -2
- package/src/billing/billing-banner.tsx +3 -1
- package/src/billing/billing-labels.ts +45 -0
- package/src/billing/billing-lock.ts +36 -3
- package/src/billing/billing-overview.ts +58 -0
- package/src/billing/checkout-processing.ts +391 -0
- package/src/billing/checkout-return.ts +90 -0
- package/src/billing/pay-page.ts +242 -0
- package/src/billing/plan-limit-toast.tsx +91 -0
- package/src/billing/subscription-actions.tsx +41 -8
- package/src/components/account-settings.tsx +6 -2
- package/src/components/autocomplete.tsx +5 -2
- package/src/components/button-group.tsx +4 -1
- package/src/components/calculator.tsx +10 -6
- package/src/components/checkbox-group.tsx +2 -2
- package/src/components/checkbox.tsx +2 -1
- package/src/components/chip.tsx +37 -32
- package/src/components/choice-card.tsx +4 -2
- package/src/components/combobox.tsx +4 -4
- package/src/components/confirm-dialog.tsx +13 -6
- package/src/components/country-select.tsx +2 -2
- package/src/components/danger-confirm.tsx +2 -2
- package/src/components/data-table.tsx +20 -9
- package/src/components/date-picker.tsx +10 -7
- package/src/components/entity-combobox.tsx +3 -3
- package/src/components/field-parts.tsx +61 -14
- package/src/components/file-button.tsx +5 -4
- package/src/components/file-dropzone.tsx +2 -2
- package/src/components/floating-panel.tsx +7 -5
- package/src/components/form-actions.tsx +12 -5
- package/src/components/inline-edit-field.tsx +13 -13
- package/src/components/list.tsx +10 -9
- package/src/components/month-picker.tsx +8 -2
- package/src/components/multi-entity-combobox.tsx +3 -3
- package/src/components/numpad-sheet.tsx +8 -4
- package/src/components/row-actions.tsx +208 -58
- package/src/components/share-card.tsx +67 -13
- package/src/components/status-dot.tsx +7 -7
- package/src/components/swatch-picker.tsx +2 -2
- package/src/components/swipeable-row.tsx +138 -27
- package/src/components/switch.tsx +2 -1
- package/src/components/table.tsx +8 -1
- package/src/components/toggle-group.tsx +5 -3
- package/src/components/translation-review-editor.tsx +8 -3
- package/src/components/translation-review.tsx +18 -22
- package/src/components/ui.tsx +92 -43
- package/src/components/write-lock.tsx +150 -24
- package/src/feedback/feedback-attachment.tsx +13 -9
- package/src/feedback/feedback-inbox.tsx +10 -6
- package/src/feedback/feedback-row-detail.tsx +3 -2
- package/src/feedback/feedback-swipe.tsx +6 -11
- package/src/feedback/feedback-table.tsx +2 -1
- package/src/i18n/defaults.ts +2 -0
- package/src/i18n/german.ts +38 -0
- package/src/i18n/kit-labels.tsx +4 -0
- package/src/i18n/locales/es.ts +34 -0
- package/src/i18n/locales/fr.ts +39 -0
- package/src/i18n/locales/hu.ts +37 -0
- package/src/i18n/locales/it.ts +35 -0
- package/src/i18n/locales/zh.ts +33 -0
- package/src/i18n/review.ts +7 -0
- package/src/index.ts +48 -4
- package/src/testing/css-variables.generated.ts +112 -0
- package/src/testing/css-variables.ts +191 -0
- package/src/testing/index.ts +13 -0
- package/src/theme/contrast-tokens.ts +53 -2
- package/src/theme/palette-derive.ts +87 -10
- package/src/theme/palette-presets.ts +45 -43
- package/src/wizard/stepper-nav.tsx +2 -1
- package/tokens.css +306 -46
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { DateInput } from '../lib/format.js';
|
|
2
|
+
import { BillingStanding } from './billing-standing.js';
|
|
3
|
+
import '../delete-account-setting-DiPX4Vue.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
import '../components/tooltip.js';
|
|
6
|
+
import '../hooks/use-anchored-rect.js';
|
|
7
|
+
import '../lib/clipping.js';
|
|
8
|
+
import '../data-table-labels-BJ5JE_X2.js';
|
|
9
|
+
import '../components/data-table-sort.js';
|
|
10
|
+
import '../components/swipeable-row.js';
|
|
11
|
+
import '../components/status-dot.js';
|
|
12
|
+
import '../components/progress-bar.js';
|
|
13
|
+
import '../components/signed-amount.js';
|
|
14
|
+
import '../components/stat-tile.js';
|
|
15
|
+
import '../components/chip.js';
|
|
16
|
+
import 'lucide-react';
|
|
17
|
+
import '../components/field-parts.js';
|
|
18
|
+
import '../components/write-lock.js';
|
|
19
|
+
import '../components/mini-calendar.js';
|
|
20
|
+
import '../components/calendar-heatmap.js';
|
|
21
|
+
import '../components/popover.js';
|
|
22
|
+
import '../hooks/use-breakpoint.js';
|
|
23
|
+
import '../components/field-sync.js';
|
|
24
|
+
import '../wizard/types.js';
|
|
25
|
+
import '../tour/tour.js';
|
|
26
|
+
import '../search/command-palette.js';
|
|
27
|
+
import '../search/global-search.js';
|
|
28
|
+
import '../search/search-index.js';
|
|
29
|
+
import '../components/month-picker.js';
|
|
30
|
+
import '../components/page-contents.js';
|
|
31
|
+
import '../components/series-chart-labels.js';
|
|
32
|
+
import '../components/pie-chart-labels.js';
|
|
33
|
+
import '../components/sparkline.js';
|
|
34
|
+
import '../components/signature-pad.js';
|
|
35
|
+
import '../components/password-strength.js';
|
|
36
|
+
import '../components/swatch-picker.js';
|
|
37
|
+
import '../components/tile-radio.js';
|
|
38
|
+
import '../components/icon-picker.js';
|
|
39
|
+
import '../components/dialog-frame.js';
|
|
40
|
+
import '../components/modal.js';
|
|
41
|
+
import '../hooks/use-search-param-state.js';
|
|
42
|
+
import '../components/measured-grid.js';
|
|
43
|
+
import '../components/user-avatar.js';
|
|
44
|
+
import '../lib/person-name.js';
|
|
45
|
+
import '../shell/topbar-action-menu.js';
|
|
46
|
+
import '../components/menu-item.js';
|
|
47
|
+
import '../components/floating-panel.js';
|
|
48
|
+
import '../hooks/use-authed-src.js';
|
|
49
|
+
import '../components/account-settings-labels.js';
|
|
50
|
+
import '../components/bulk-action-bar.js';
|
|
51
|
+
import '../components/list.js';
|
|
52
|
+
import '../components/breadcrumbs.js';
|
|
53
|
+
import '../components/toast.js';
|
|
54
|
+
import '../components/description-list.js';
|
|
55
|
+
import '../components/line-items.js';
|
|
56
|
+
import '../components/error-boundary.js';
|
|
57
|
+
import '../components/authed-image.js';
|
|
58
|
+
import '../components/image-grid.js';
|
|
59
|
+
import '../components/lightbox.js';
|
|
60
|
+
import '../auth/sign-in-form.js';
|
|
61
|
+
import '../landing/access.js';
|
|
62
|
+
import '../landing/landing-labels.js';
|
|
63
|
+
import '../shell/topbar-controls.js';
|
|
64
|
+
import '../theme/palette-presets.js';
|
|
65
|
+
import '../theme/chart-palette.js';
|
|
66
|
+
import '../theme/theme-store.js';
|
|
67
|
+
import 'zustand/middleware';
|
|
68
|
+
import 'zustand';
|
|
69
|
+
import '../auth/complete-name-dialog.js';
|
|
70
|
+
import '../auth/forgot-password-form.js';
|
|
71
|
+
import '../auth/status-parts.js';
|
|
72
|
+
import '../auth/reset-password-form.js';
|
|
73
|
+
import '../auth/verify-email.js';
|
|
74
|
+
import '../auth/not-found-page.js';
|
|
75
|
+
import '../auth/accept-invitation.js';
|
|
76
|
+
import '../shell/company-switcher.js';
|
|
77
|
+
import '../account/email-change-setting.js';
|
|
78
|
+
import '../account/sessions-setting.js';
|
|
79
|
+
import '../account/data-export-setting.js';
|
|
80
|
+
import '../components/account-chips.js';
|
|
81
|
+
import '../admin/admin-parts.js';
|
|
82
|
+
import '../admin/admin-action-log.js';
|
|
83
|
+
import '../settings/settings-labels.js';
|
|
84
|
+
import '../demo/demo-labels.js';
|
|
85
|
+
import '../components/appearance-labels.js';
|
|
86
|
+
import '../theme/contrast.js';
|
|
87
|
+
import '../theme/text-size.js';
|
|
88
|
+
import '../components/reauth-dialog.js';
|
|
89
|
+
import '../components/server-wake.js';
|
|
90
|
+
import '../lib/server-wake.js';
|
|
91
|
+
import '../components/translation-review-labels.js';
|
|
92
|
+
import '../lib/translation-review.js';
|
|
93
|
+
import '../components/country-select.js';
|
|
94
|
+
import '../components/inline-edit-field.js';
|
|
95
|
+
import '../lib/iban.js';
|
|
96
|
+
import '../lib/phone.js';
|
|
97
|
+
import '../components/sign-chip.js';
|
|
98
|
+
import '../components/column-mapper.js';
|
|
99
|
+
import '../lib/column-mapping.js';
|
|
100
|
+
import '../lib/table-text.js';
|
|
101
|
+
import '../components/focus-ring.js';
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* "Payment processing" after the way back from a checkout (docs/billing-harmonization.md
|
|
105
|
+
* §12.21, §14.4; keksdose's `features/billing/checkout-return.ts`, made router-agnostic).
|
|
106
|
+
*
|
|
107
|
+
* The provider tells the app about a payment by WEBHOOK, and the webhook may land after
|
|
108
|
+
* the buyer is back: Cloud Run scales to zero, and a cold start can outlast the
|
|
109
|
+
* provider's redirect. Without this, someone who has just paid comes back to a page that
|
|
110
|
+
* still says their trial has ended. So the return is recognised (`?checkout=done`,
|
|
111
|
+
* `isCheckoutReturn`), the page says "your payment is being processed"
|
|
112
|
+
* (`BillingBanner kind="processing"`), and the overview is asked again every few seconds
|
|
113
|
+
* until it has moved.
|
|
114
|
+
*
|
|
115
|
+
* **"Landed" is judged against the overview at departure** ({@link checkoutFingerprint},
|
|
116
|
+
* noted by {@link noteCheckoutStarted}), not by "is it `active` yet": a trial and a beta
|
|
117
|
+
* grant can both buy, and a running free grant keeps its status whatever the provider
|
|
118
|
+
* says (§12.11) — only its period end moves — so "active" alone would wait for ever on
|
|
119
|
+
* one of them. A return with no departure on record (another tab, another device) waits
|
|
120
|
+
* for `active`. kastlan's 60-second poll for `source === "provider"` is the case this
|
|
121
|
+
* replaces: a payer who bought under a grant never matched it.
|
|
122
|
+
*
|
|
123
|
+
* **Bounded:** after `timeoutMs` (10 minutes) the device stops asking, and the page says
|
|
124
|
+
* what the overview says, whatever that is — a checkout abandoned at the provider must
|
|
125
|
+
* not leave "processing" up for good.
|
|
126
|
+
*
|
|
127
|
+
* **Remembered across the whole-page return, per payer.** The departure goes into the
|
|
128
|
+
* browser's storage through the kit's safe storage (a throwing storage — Safari's
|
|
129
|
+
* private mode — keeps it in memory for this page instead), under `storageKey`; a mark
|
|
130
|
+
* names its payer, so it never speaks for another account on a shared device. It is a
|
|
131
|
+
* browser entry on the app's origin: an app whose privacy text lists its entries names
|
|
132
|
+
* it (Kurvenschmiede passes its own key).
|
|
133
|
+
*/
|
|
134
|
+
/** The overview fields a completed checkout changes (wire names, `GET /billing/overview`).
|
|
135
|
+
* Pass the overview as it came; the other fields are ignored. */
|
|
136
|
+
type CheckoutOverview = Pick<BillingStanding, "status" | "in_good_standing"> & {
|
|
137
|
+
plan: string;
|
|
138
|
+
source: string;
|
|
139
|
+
current_period_end?: DateInput;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* What of the overview a completed checkout changes, as one string: the plan (read
|
|
143
|
+
* without case, §12.16), the status, the source, the standing and the period's end (read
|
|
144
|
+
* as an instant, so `…Z` and `…+00:00` agree).
|
|
145
|
+
*/
|
|
146
|
+
declare function checkoutFingerprint(o: CheckoutOverview): string;
|
|
147
|
+
/**
|
|
148
|
+
* Whether the overview `now` shows the checkout: it differs from the fingerprint taken
|
|
149
|
+
* at departure (`before`), or — with no departure on record — it is `active`.
|
|
150
|
+
*/
|
|
151
|
+
declare function checkoutLanded(before: string | null, now: CheckoutOverview): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Note the departure for a checkout — just before the page leaves for the provider (or
|
|
154
|
+
* for the pay page, `payPageUrl(url, locale)`):
|
|
155
|
+
*
|
|
156
|
+
* noteCheckoutStarted(user.id, overview.data);
|
|
157
|
+
* window.location.assign(payPageUrl(url, i18n.language));
|
|
158
|
+
*
|
|
159
|
+
* `payer` is the user's or the company's id: a mark never speaks for another payer.
|
|
160
|
+
* `overview` is what the page shows now; left out, the return waits for `active`. Pass
|
|
161
|
+
* the same `storageKey` as the hook's.
|
|
162
|
+
*/
|
|
163
|
+
declare function noteCheckoutStarted(payer: string | number, overview?: CheckoutOverview, opts?: {
|
|
164
|
+
storageKey?: string;
|
|
165
|
+
}): void;
|
|
166
|
+
interface CheckoutProcessingOptions {
|
|
167
|
+
/** The signed-in payer — the user's or the company's id; null while unknown (the
|
|
168
|
+
* marker then waits in the URL). */
|
|
169
|
+
payer: string | number | null;
|
|
170
|
+
/** The page was reached as the way back: `isCheckoutReturn(location.search)`. */
|
|
171
|
+
returned: boolean;
|
|
172
|
+
/** Drop the marker, with replace — `setSearchParams((p) => withoutCheckoutReturn(p),
|
|
173
|
+
* { replace: true })`. Called once per return, by the first instance that sees it. */
|
|
174
|
+
onConsumed: () => void;
|
|
175
|
+
/** The overview query's data, judged here against the departure. */
|
|
176
|
+
overview: CheckoutOverview | undefined;
|
|
177
|
+
/** The overview query's refetch: the hook polls with it — one timer for every
|
|
178
|
+
* instance, with the latest mounted one's — and "Check again" calls it. */
|
|
179
|
+
refetch: () => unknown;
|
|
180
|
+
/** Once per landing: refresh what a new standing changes — the plans, the items whose
|
|
181
|
+
* `locked` may have lifted. The overview itself is already fresh. */
|
|
182
|
+
onLanded?: () => void;
|
|
183
|
+
/** How long a return keeps "processing". Default 600 000 (10 minutes). */
|
|
184
|
+
timeoutMs?: number;
|
|
185
|
+
/** How often the overview is asked meanwhile. Default 4 000. */
|
|
186
|
+
pollMs?: number;
|
|
187
|
+
/** The browser entry. Default `"eifi1-billing-checkout"`. */
|
|
188
|
+
storageKey?: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Whether this payer is back from a checkout whose payment the overview has not shown
|
|
192
|
+
* yet — and the "Check again" for the banner that says so:
|
|
193
|
+
*
|
|
194
|
+
* const [params, setParams] = useSearchParams();
|
|
195
|
+
* const overview = useQuery(billingOverviewQuery);
|
|
196
|
+
* const { processing, checkAgain } = useCheckoutProcessing({
|
|
197
|
+
* payer: user?.id ?? null,
|
|
198
|
+
* returned: isCheckoutReturn(params),
|
|
199
|
+
* onConsumed: () => setParams((p) => withoutCheckoutReturn(p), { replace: true }),
|
|
200
|
+
* overview: overview.data,
|
|
201
|
+
* refetch: overview.refetch,
|
|
202
|
+
* onLanded: () => void qc.invalidateQueries({ queryKey: ["budgets"] }),
|
|
203
|
+
* });
|
|
204
|
+
* processing && <BillingBanner kind="processing" onAction={checkAgain} />
|
|
205
|
+
*
|
|
206
|
+
* The kit has no router: the app says whether the URL returned and how to drop the
|
|
207
|
+
* marker. Mount it wherever the return lands and the banner shows — every instance with
|
|
208
|
+
* the same `storageKey` shares one state: the first that sees the marker consumes it,
|
|
209
|
+
* one timer polls, and `onLanded` runs once. The app's `refetchOnWindowFocus` doesn't
|
|
210
|
+
* matter.
|
|
211
|
+
*/
|
|
212
|
+
declare function useCheckoutProcessing(options: CheckoutProcessingOptions): {
|
|
213
|
+
processing: boolean;
|
|
214
|
+
checkAgain: () => void;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export { type CheckoutOverview, type CheckoutProcessingOptions, checkoutFingerprint, checkoutLanded, noteCheckoutStarted, useCheckoutProcessing };
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useSyncExternalStore } from "react";
|
|
3
|
+
import { toDate } from "../lib/format.js";
|
|
4
|
+
import { readStored, writeStored } from "../lib/safe-storage.js";
|
|
5
|
+
const PROCESSING_FOR = 10 * 6e4;
|
|
6
|
+
const POLL_EVERY = 4e3;
|
|
7
|
+
const STORAGE_KEY = "eifi1-billing-checkout";
|
|
8
|
+
function checkoutFingerprint(o) {
|
|
9
|
+
const end = toDate(o.current_period_end ?? null);
|
|
10
|
+
return [
|
|
11
|
+
String(o.plan ?? "").toLowerCase(),
|
|
12
|
+
o.status,
|
|
13
|
+
o.source,
|
|
14
|
+
String(o.in_good_standing),
|
|
15
|
+
end ? end.toISOString() : ""
|
|
16
|
+
].join("|");
|
|
17
|
+
}
|
|
18
|
+
function checkoutLanded(before, now) {
|
|
19
|
+
return before === null ? now.status === "active" : checkoutFingerprint(now) !== before;
|
|
20
|
+
}
|
|
21
|
+
const stores = /* @__PURE__ */ new Map();
|
|
22
|
+
function readPending(key) {
|
|
23
|
+
const raw = readStored(key);
|
|
24
|
+
if (raw === null) return null;
|
|
25
|
+
try {
|
|
26
|
+
const value = JSON.parse(raw);
|
|
27
|
+
if (value && typeof value.payer === "string" && (value.before === null || typeof value.before === "string") && (value.returnedAt === null || typeof value.returnedAt === "number")) {
|
|
28
|
+
return { payer: value.payer, before: value.before, returnedAt: value.returnedAt };
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
function forget(key) {
|
|
35
|
+
if (typeof window === "undefined") return;
|
|
36
|
+
try {
|
|
37
|
+
window.localStorage.removeItem(key);
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function storeOf(key) {
|
|
42
|
+
let store = stores.get(key);
|
|
43
|
+
if (!store) {
|
|
44
|
+
store = {
|
|
45
|
+
key,
|
|
46
|
+
pending: readPending(key),
|
|
47
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
48
|
+
instances: [],
|
|
49
|
+
poll: null,
|
|
50
|
+
pollEvery: 0,
|
|
51
|
+
expiry: null,
|
|
52
|
+
expiryAt: null,
|
|
53
|
+
consuming: false
|
|
54
|
+
};
|
|
55
|
+
stores.set(key, store);
|
|
56
|
+
}
|
|
57
|
+
return store;
|
|
58
|
+
}
|
|
59
|
+
function setPending(store, next) {
|
|
60
|
+
store.pending = next;
|
|
61
|
+
if (next) writeStored(store.key, JSON.stringify(next));
|
|
62
|
+
else forget(store.key);
|
|
63
|
+
for (const listener of store.listeners) listener();
|
|
64
|
+
sync(store);
|
|
65
|
+
}
|
|
66
|
+
function refetchLatest(store) {
|
|
67
|
+
const latest = store.instances.at(-1);
|
|
68
|
+
if (!latest) return;
|
|
69
|
+
try {
|
|
70
|
+
const result = latest.refetch();
|
|
71
|
+
if (result && typeof result.then === "function") result.then(void 0, () => {
|
|
72
|
+
});
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function sync(store) {
|
|
77
|
+
const pending = store.pending;
|
|
78
|
+
const latest = store.instances.at(-1);
|
|
79
|
+
const returnedAt = pending?.returnedAt ?? null;
|
|
80
|
+
if (returnedAt === null) {
|
|
81
|
+
if (store.expiry) clearTimeout(store.expiry);
|
|
82
|
+
store.expiry = null;
|
|
83
|
+
store.expiryAt = null;
|
|
84
|
+
} else {
|
|
85
|
+
const at = returnedAt + (latest?.timeoutMs ?? PROCESSING_FOR);
|
|
86
|
+
if (at <= Date.now()) {
|
|
87
|
+
setPending(store, null);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (store.expiryAt !== at) {
|
|
91
|
+
if (store.expiry) clearTimeout(store.expiry);
|
|
92
|
+
store.expiryAt = at;
|
|
93
|
+
store.expiry = setTimeout(() => {
|
|
94
|
+
store.expiry = null;
|
|
95
|
+
store.expiryAt = null;
|
|
96
|
+
if (store.pending === pending) setPending(store, null);
|
|
97
|
+
}, at - Date.now());
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const watching = returnedAt !== null && store.instances.some((i) => i.payer === pending.payer);
|
|
101
|
+
const every = latest?.pollMs ?? POLL_EVERY;
|
|
102
|
+
if (!watching) {
|
|
103
|
+
if (store.poll) clearInterval(store.poll);
|
|
104
|
+
store.poll = null;
|
|
105
|
+
} else if (!store.poll || store.pollEvery !== every) {
|
|
106
|
+
if (store.poll) clearInterval(store.poll);
|
|
107
|
+
store.pollEvery = every;
|
|
108
|
+
store.poll = setInterval(() => refetchLatest(store), every);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function register(store, instance) {
|
|
112
|
+
store.instances.push(instance);
|
|
113
|
+
return () => {
|
|
114
|
+
store.instances = store.instances.filter((i) => i !== instance);
|
|
115
|
+
sync(store);
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function claimReturn(store) {
|
|
119
|
+
if (store.consuming) return false;
|
|
120
|
+
store.consuming = true;
|
|
121
|
+
void Promise.resolve().then(() => {
|
|
122
|
+
store.consuming = false;
|
|
123
|
+
});
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
function noteCheckoutStarted(payer, overview, opts = {}) {
|
|
127
|
+
const store = storeOf(opts.storageKey ?? STORAGE_KEY);
|
|
128
|
+
setPending(store, {
|
|
129
|
+
payer: String(payer),
|
|
130
|
+
before: overview ? checkoutFingerprint(overview) : null,
|
|
131
|
+
returnedAt: null
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function useCheckoutProcessing(options) {
|
|
135
|
+
const {
|
|
136
|
+
payer,
|
|
137
|
+
returned,
|
|
138
|
+
onConsumed,
|
|
139
|
+
overview,
|
|
140
|
+
refetch,
|
|
141
|
+
onLanded,
|
|
142
|
+
timeoutMs = PROCESSING_FOR,
|
|
143
|
+
pollMs = POLL_EVERY,
|
|
144
|
+
storageKey = STORAGE_KEY
|
|
145
|
+
} = options;
|
|
146
|
+
const payerKey = payer === null || payer === void 0 ? null : String(payer);
|
|
147
|
+
const store = storeOf(storageKey);
|
|
148
|
+
const subscribe = useCallback(
|
|
149
|
+
(notify) => {
|
|
150
|
+
store.listeners.add(notify);
|
|
151
|
+
return () => {
|
|
152
|
+
store.listeners.delete(notify);
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
[store]
|
|
156
|
+
);
|
|
157
|
+
const snapshot = () => store.pending;
|
|
158
|
+
const pending = useSyncExternalStore(subscribe, snapshot, snapshot);
|
|
159
|
+
const processing = payerKey !== null && pending?.payer === payerKey && pending.returnedAt !== null;
|
|
160
|
+
const instanceRef = useRef({ payer: payerKey, refetch, onLanded, timeoutMs, pollMs });
|
|
161
|
+
useLayoutEffect(() => register(store, instanceRef.current), [store]);
|
|
162
|
+
useLayoutEffect(() => {
|
|
163
|
+
Object.assign(instanceRef.current, { payer: payerKey, refetch, onLanded, timeoutMs, pollMs });
|
|
164
|
+
sync(store);
|
|
165
|
+
});
|
|
166
|
+
const consumed = useEffectEvent(() => onConsumed());
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
if (!returned || payerKey === null || !claimReturn(store)) return;
|
|
169
|
+
const before = store.pending?.payer === payerKey ? store.pending.before : null;
|
|
170
|
+
setPending(store, { payer: payerKey, before, returnedAt: Date.now() });
|
|
171
|
+
consumed();
|
|
172
|
+
}, [returned, payerKey, store]);
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
if (!processing || !overview) return;
|
|
175
|
+
const live = store.pending;
|
|
176
|
+
if (!live || live.payer !== payerKey || live.returnedAt === null) return;
|
|
177
|
+
if (!checkoutLanded(live.before, overview)) return;
|
|
178
|
+
setPending(store, null);
|
|
179
|
+
const latest = [...store.instances].reverse().find((i) => i.onLanded);
|
|
180
|
+
latest?.onLanded?.();
|
|
181
|
+
}, [processing, overview, payerKey, store]);
|
|
182
|
+
const checkAgain = useCallback(() => {
|
|
183
|
+
try {
|
|
184
|
+
const result = instanceRef.current.refetch();
|
|
185
|
+
if (result && typeof result.then === "function") result.then(void 0, () => {
|
|
186
|
+
});
|
|
187
|
+
} catch {
|
|
188
|
+
}
|
|
189
|
+
}, []);
|
|
190
|
+
return { processing, checkAgain };
|
|
191
|
+
}
|
|
192
|
+
export {
|
|
193
|
+
checkoutFingerprint,
|
|
194
|
+
checkoutLanded,
|
|
195
|
+
noteCheckoutStarted,
|
|
196
|
+
useCheckoutProcessing
|
|
197
|
+
};
|
|
198
|
+
//# sourceMappingURL=checkout-processing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/billing/checkout-processing.ts"],"sourcesContent":["import { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useSyncExternalStore } from \"react\";\n\nimport { toDate } from \"../lib/format\";\nimport type { DateInput } from \"../lib/format\";\nimport { readStored, writeStored } from \"../lib/safe-storage\";\nimport type { BillingStanding } from \"./billing-standing\";\n\n/**\n * \"Payment processing\" after the way back from a checkout (docs/billing-harmonization.md\n * §12.21, §14.4; keksdose's `features/billing/checkout-return.ts`, made router-agnostic).\n *\n * The provider tells the app about a payment by WEBHOOK, and the webhook may land after\n * the buyer is back: Cloud Run scales to zero, and a cold start can outlast the\n * provider's redirect. Without this, someone who has just paid comes back to a page that\n * still says their trial has ended. So the return is recognised (`?checkout=done`,\n * `isCheckoutReturn`), the page says \"your payment is being processed\"\n * (`BillingBanner kind=\"processing\"`), and the overview is asked again every few seconds\n * until it has moved.\n *\n * **\"Landed\" is judged against the overview at departure** ({@link checkoutFingerprint},\n * noted by {@link noteCheckoutStarted}), not by \"is it `active` yet\": a trial and a beta\n * grant can both buy, and a running free grant keeps its status whatever the provider\n * says (§12.11) — only its period end moves — so \"active\" alone would wait for ever on\n * one of them. A return with no departure on record (another tab, another device) waits\n * for `active`. kastlan's 60-second poll for `source === \"provider\"` is the case this\n * replaces: a payer who bought under a grant never matched it.\n *\n * **Bounded:** after `timeoutMs` (10 minutes) the device stops asking, and the page says\n * what the overview says, whatever that is — a checkout abandoned at the provider must\n * not leave \"processing\" up for good.\n *\n * **Remembered across the whole-page return, per payer.** The departure goes into the\n * browser's storage through the kit's safe storage (a throwing storage — Safari's\n * private mode — keeps it in memory for this page instead), under `storageKey`; a mark\n * names its payer, so it never speaks for another account on a shared device. It is a\n * browser entry on the app's origin: an app whose privacy text lists its entries names\n * it (Kurvenschmiede passes its own key).\n */\n\n/** The overview fields a completed checkout changes (wire names, `GET /billing/overview`).\n * Pass the overview as it came; the other fields are ignored. */\nexport type CheckoutOverview = Pick<BillingStanding, \"status\" | \"in_good_standing\"> & {\n plan: string;\n source: string;\n current_period_end?: DateInput;\n};\n\n/** How long a return keeps the page in \"processing\" before it trusts the overview. */\nconst PROCESSING_FOR = 10 * 60_000;\n/** How often the overview is asked meanwhile. */\nconst POLL_EVERY = 4_000;\n/** The browser entry, unless the app names its own. */\nconst STORAGE_KEY = \"eifi1-billing-checkout\";\n\n/**\n * What of the overview a completed checkout changes, as one string: the plan (read\n * without case, §12.16), the status, the source, the standing and the period's end (read\n * as an instant, so `…Z` and `…+00:00` agree).\n */\nexport function checkoutFingerprint(o: CheckoutOverview): string {\n const end = toDate(o.current_period_end ?? null);\n return [\n String(o.plan ?? \"\").toLowerCase(),\n o.status,\n o.source,\n String(o.in_good_standing),\n end ? end.toISOString() : \"\",\n ].join(\"|\");\n}\n\n/**\n * Whether the overview `now` shows the checkout: it differs from the fingerprint taken\n * at departure (`before`), or — with no departure on record — it is `active`.\n */\nexport function checkoutLanded(before: string | null, now: CheckoutOverview): boolean {\n return before === null ? now.status === \"active\" : checkoutFingerprint(now) !== before;\n}\n\n/* ── The store: one per storage key, shared by every mounted instance ─────── */\n\ninterface PendingCheckout {\n /** Whose checkout: a user's or a company's id, as a string. */\n payer: string;\n /** The overview's fingerprint at departure, or null when it was not known. */\n before: string | null;\n /** When the buyer came back; null while they are (or were) at the provider. */\n returnedAt: number | null;\n}\n\n/** One mounted hook: what the shared timers call, kept current on every render. */\ninterface Instance {\n payer: string | null;\n refetch: () => unknown;\n onLanded: (() => void) | undefined;\n timeoutMs: number;\n pollMs: number;\n}\n\ninterface CheckoutStore {\n key: string;\n pending: PendingCheckout | null;\n listeners: Set<() => void>;\n /** The mounted instances, in mount order: the last is the latest. */\n instances: Instance[];\n poll: ReturnType<typeof setInterval> | null;\n pollEvery: number;\n expiry: ReturnType<typeof setTimeout> | null;\n expiryAt: number | null;\n /** An instance consumed the marker in this commit; the others leave it be. */\n consuming: boolean;\n}\n\n/** Module-level, so the banner's instance and the subscription page's share one state,\n * one poll and one landing (keksdose mounts the hook twice, §14.4). */\nconst stores = new Map<string, CheckoutStore>();\n\nfunction readPending(key: string): PendingCheckout | null {\n const raw = readStored(key);\n if (raw === null) return null;\n try {\n const value = JSON.parse(raw) as Partial<PendingCheckout> | null;\n if (\n value &&\n typeof value.payer === \"string\" &&\n (value.before === null || typeof value.before === \"string\") &&\n (value.returnedAt === null || typeof value.returnedAt === \"number\")\n ) {\n return { payer: value.payer, before: value.before, returnedAt: value.returnedAt };\n }\n } catch {\n // Not ours, or damaged: as if nothing was noted.\n }\n return null;\n}\n\n/** Drop the browser entry. lib/safe-storage reads and writes; removing needs the same\n * guard (a blocked storage throws on access). */\nfunction forget(key: string): void {\n if (typeof window === \"undefined\") return;\n try {\n window.localStorage.removeItem(key);\n } catch {\n // ignore (private mode, partitioned storage)\n }\n}\n\nfunction storeOf(key: string): CheckoutStore {\n let store = stores.get(key);\n if (!store) {\n store = {\n key,\n pending: readPending(key),\n listeners: new Set(),\n instances: [],\n poll: null,\n pollEvery: 0,\n expiry: null,\n expiryAt: null,\n consuming: false,\n };\n stores.set(key, store);\n }\n return store;\n}\n\nfunction setPending(store: CheckoutStore, next: PendingCheckout | null): void {\n store.pending = next;\n if (next) writeStored(store.key, JSON.stringify(next));\n else forget(store.key);\n for (const listener of store.listeners) listener();\n sync(store);\n}\n\n/** The latest mounted instance's refetch, failures swallowed: a poll that fails is\n * simply asked again at the next tick. */\nfunction refetchLatest(store: CheckoutStore): void {\n const latest = store.instances.at(-1);\n if (!latest) return;\n try {\n const result = latest.refetch() as PromiseLike<unknown> | undefined;\n if (result && typeof result.then === \"function\") result.then(undefined, () => {});\n } catch {\n // as above\n }\n}\n\n/** Arms or stops the store's two timers — the bound and the poll — for its state. */\nfunction sync(store: CheckoutStore): void {\n const pending = store.pending;\n const latest = store.instances.at(-1);\n const returnedAt = pending?.returnedAt ?? null;\n\n if (returnedAt === null) {\n if (store.expiry) clearTimeout(store.expiry);\n store.expiry = null;\n store.expiryAt = null;\n } else {\n const at = returnedAt + (latest?.timeoutMs ?? PROCESSING_FOR);\n if (at <= Date.now()) {\n setPending(store, null);\n return;\n }\n if (store.expiryAt !== at) {\n if (store.expiry) clearTimeout(store.expiry);\n store.expiryAt = at;\n store.expiry = setTimeout(() => {\n store.expiry = null;\n store.expiryAt = null;\n if (store.pending === pending) setPending(store, null);\n }, at - Date.now());\n }\n }\n\n // One poll for every instance, while a mounted one is the mark's payer.\n const watching = returnedAt !== null && store.instances.some((i) => i.payer === pending!.payer);\n const every = latest?.pollMs ?? POLL_EVERY;\n if (!watching) {\n if (store.poll) clearInterval(store.poll);\n store.poll = null;\n } else if (!store.poll || store.pollEvery !== every) {\n if (store.poll) clearInterval(store.poll);\n store.pollEvery = every;\n store.poll = setInterval(() => refetchLatest(store), every);\n }\n}\n\n/** A mounted instance joins the store's timers; the latest is the one they call. */\nfunction register(store: CheckoutStore, instance: Instance): () => void {\n store.instances.push(instance);\n return () => {\n store.instances = store.instances.filter((i) => i !== instance);\n sync(store);\n };\n}\n\n/**\n * Whether this instance is the one to consume a return marker: the first in a commit is.\n * Another instance in the same commit sees the same marker and leaves it be; the claim\n * lapses once the commit's effects have run.\n */\nfunction claimReturn(store: CheckoutStore): boolean {\n if (store.consuming) return false;\n store.consuming = true;\n void Promise.resolve().then(() => {\n store.consuming = false;\n });\n return true;\n}\n\n/**\n * Note the departure for a checkout — just before the page leaves for the provider (or\n * for the pay page, `payPageUrl(url, locale)`):\n *\n * noteCheckoutStarted(user.id, overview.data);\n * window.location.assign(payPageUrl(url, i18n.language));\n *\n * `payer` is the user's or the company's id: a mark never speaks for another payer.\n * `overview` is what the page shows now; left out, the return waits for `active`. Pass\n * the same `storageKey` as the hook's.\n */\nexport function noteCheckoutStarted(\n payer: string | number,\n overview?: CheckoutOverview,\n opts: { storageKey?: string } = {},\n): void {\n const store = storeOf(opts.storageKey ?? STORAGE_KEY);\n setPending(store, {\n payer: String(payer),\n before: overview ? checkoutFingerprint(overview) : null,\n returnedAt: null,\n });\n}\n\nexport interface CheckoutProcessingOptions {\n /** The signed-in payer — the user's or the company's id; null while unknown (the\n * marker then waits in the URL). */\n payer: string | number | null;\n /** The page was reached as the way back: `isCheckoutReturn(location.search)`. */\n returned: boolean;\n /** Drop the marker, with replace — `setSearchParams((p) => withoutCheckoutReturn(p),\n * { replace: true })`. Called once per return, by the first instance that sees it. */\n onConsumed: () => void;\n /** The overview query's data, judged here against the departure. */\n overview: CheckoutOverview | undefined;\n /** The overview query's refetch: the hook polls with it — one timer for every\n * instance, with the latest mounted one's — and \"Check again\" calls it. */\n refetch: () => unknown;\n /** Once per landing: refresh what a new standing changes — the plans, the items whose\n * `locked` may have lifted. The overview itself is already fresh. */\n onLanded?: () => void;\n /** How long a return keeps \"processing\". Default 600 000 (10 minutes). */\n timeoutMs?: number;\n /** How often the overview is asked meanwhile. Default 4 000. */\n pollMs?: number;\n /** The browser entry. Default `\"eifi1-billing-checkout\"`. */\n storageKey?: string;\n}\n\n/**\n * Whether this payer is back from a checkout whose payment the overview has not shown\n * yet — and the \"Check again\" for the banner that says so:\n *\n * const [params, setParams] = useSearchParams();\n * const overview = useQuery(billingOverviewQuery);\n * const { processing, checkAgain } = useCheckoutProcessing({\n * payer: user?.id ?? null,\n * returned: isCheckoutReturn(params),\n * onConsumed: () => setParams((p) => withoutCheckoutReturn(p), { replace: true }),\n * overview: overview.data,\n * refetch: overview.refetch,\n * onLanded: () => void qc.invalidateQueries({ queryKey: [\"budgets\"] }),\n * });\n * processing && <BillingBanner kind=\"processing\" onAction={checkAgain} />\n *\n * The kit has no router: the app says whether the URL returned and how to drop the\n * marker. Mount it wherever the return lands and the banner shows — every instance with\n * the same `storageKey` shares one state: the first that sees the marker consumes it,\n * one timer polls, and `onLanded` runs once. The app's `refetchOnWindowFocus` doesn't\n * matter.\n */\nexport function useCheckoutProcessing(options: CheckoutProcessingOptions): {\n processing: boolean;\n checkAgain: () => void;\n} {\n const {\n payer,\n returned,\n onConsumed,\n overview,\n refetch,\n onLanded,\n timeoutMs = PROCESSING_FOR,\n pollMs = POLL_EVERY,\n storageKey = STORAGE_KEY,\n } = options;\n const payerKey = payer === null || payer === undefined ? null : String(payer);\n const store = storeOf(storageKey);\n const subscribe = useCallback(\n (notify: () => void) => {\n store.listeners.add(notify);\n return () => {\n store.listeners.delete(notify);\n };\n },\n [store],\n );\n const snapshot = () => store.pending;\n const pending = useSyncExternalStore(subscribe, snapshot, snapshot);\n const processing = payerKey !== null && pending?.payer === payerKey && pending.returnedAt !== null;\n\n // This instance, as the shared timers see it. Registered before paint, so a mark that\n // ran out while the page was closed is dropped before \"processing\" can flash.\n const instanceRef = useRef<Instance>({ payer: payerKey, refetch, onLanded, timeoutMs, pollMs });\n useLayoutEffect(() => register(store, instanceRef.current), [store]);\n useLayoutEffect(() => {\n Object.assign(instanceRef.current, { payer: payerKey, refetch, onLanded, timeoutMs, pollMs });\n sync(store);\n });\n\n // The return: note it, then drop the marker so a reload does not count it twice.\n const consumed = useEffectEvent(() => onConsumed());\n useEffect(() => {\n if (!returned || payerKey === null || !claimReturn(store)) return;\n const before = store.pending?.payer === payerKey ? store.pending.before : null;\n setPending(store, { payer: payerKey, before, returnedAt: Date.now() });\n consumed();\n }, [returned, payerKey, store]);\n\n // Caught up: the overview has moved since the departure. Judged against the store as\n // it is NOW, so a second instance in the same commit finds the mark gone.\n useEffect(() => {\n if (!processing || !overview) return;\n const live = store.pending;\n if (!live || live.payer !== payerKey || live.returnedAt === null) return;\n if (!checkoutLanded(live.before, overview)) return;\n setPending(store, null);\n const latest = [...store.instances].reverse().find((i) => i.onLanded);\n latest?.onLanded?.();\n }, [processing, overview, payerKey, store]);\n\n const checkAgain = useCallback(() => {\n try {\n const result = instanceRef.current.refetch() as PromiseLike<unknown> | undefined;\n if (result && typeof result.then === \"function\") result.then(undefined, () => {});\n } catch {\n // The banner stays; the next poll asks again.\n }\n }, []);\n\n return { processing, checkAgain };\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The way back from the provider's checkout (docs/billing-harmonization.md §14.4,
|
|
3
|
+
* decision 20): `?checkout=done` on the app's subscription page — kastlan's
|
|
4
|
+
* `/admin/billing`, keksdose's and Kurvenschmiede's `/settings/subscription`.
|
|
5
|
+
*
|
|
6
|
+
* The checkout request carries NO success URL: a redirect the client chooses is an open
|
|
7
|
+
* redirect, and Paddle's create-transaction takes none. The way back is configuration
|
|
8
|
+
* instead — the pay page's Paddle.js `successUrl` (`checkoutReturnUrl(returnUrl)`), or a
|
|
9
|
+
* hosted checkout's redirect in Paddle's dashboard — and the page that lands reads the
|
|
10
|
+
* marker with {@link isCheckoutReturn}, then drops it with `replace`
|
|
11
|
+
* ({@link withoutCheckoutReturn}) so a reload or a shared link does not count twice.
|
|
12
|
+
*
|
|
13
|
+
* Pure and router-agnostic, and imports nothing: the pay page (`dist/pay/`, no React)
|
|
14
|
+
* bundles this module too. server-kit names the same two values
|
|
15
|
+
* (`CHECKOUT_RETURN_PARAM`, `CHECKOUT_RETURN_VALUE`, `checkout_return_url`) for the
|
|
16
|
+
* deploy notes and its tests.
|
|
17
|
+
*/
|
|
18
|
+
/** The query parameter of the way back. */
|
|
19
|
+
declare const CHECKOUT_RETURN_PARAM = "checkout";
|
|
20
|
+
/** Its one value: the buyer came back from a completed checkout. */
|
|
21
|
+
declare const CHECKOUT_RETURN_VALUE = "done";
|
|
22
|
+
/**
|
|
23
|
+
* Whether the page was reached as the way back from a checkout: `?checkout=done`.
|
|
24
|
+
*
|
|
25
|
+
* const returned = isCheckoutReturn(location.search); // react-router's useLocation()
|
|
26
|
+
* const returned = isCheckoutReturn(searchParams); // useSearchParams()[0]
|
|
27
|
+
*/
|
|
28
|
+
declare function isCheckoutReturn(where: string | URLSearchParams | {
|
|
29
|
+
search: string;
|
|
30
|
+
}): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* The same parameters without the marker — every other one kept, in order. A new
|
|
33
|
+
* object; the one passed in is not changed:
|
|
34
|
+
*
|
|
35
|
+
* setSearchParams((p) => withoutCheckoutReturn(p), { replace: true });
|
|
36
|
+
*/
|
|
37
|
+
declare function withoutCheckoutReturn(params: URLSearchParams): URLSearchParams;
|
|
38
|
+
/**
|
|
39
|
+
* The subscription page's way-back URL: `page` with `checkout=done` in its query —
|
|
40
|
+
* after any query it already has, before its hash. A marker already there is replaced,
|
|
41
|
+
* not doubled.
|
|
42
|
+
*
|
|
43
|
+
* checkoutReturnUrl("https://keksdose.app/settings/subscription")
|
|
44
|
+
* // → "https://keksdose.app/settings/subscription?checkout=done"
|
|
45
|
+
*
|
|
46
|
+
* What the pay page hands Paddle.js as `successUrl`, and what a hosted checkout's
|
|
47
|
+
* redirect is set to in Paddle's dashboard.
|
|
48
|
+
*/
|
|
49
|
+
declare function checkoutReturnUrl(page: string): string;
|
|
50
|
+
|
|
51
|
+
export { CHECKOUT_RETURN_PARAM, CHECKOUT_RETURN_VALUE, checkoutReturnUrl, isCheckoutReturn, withoutCheckoutReturn };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const CHECKOUT_RETURN_PARAM = "checkout";
|
|
3
|
+
const CHECKOUT_RETURN_VALUE = "done";
|
|
4
|
+
function paramsOf(where) {
|
|
5
|
+
if (where instanceof URLSearchParams) return where;
|
|
6
|
+
const text = typeof where === "string" ? where : where.search;
|
|
7
|
+
const query = text.includes("?") ? text.slice(text.indexOf("?") + 1) : text;
|
|
8
|
+
return new URLSearchParams(query.split("#")[0]);
|
|
9
|
+
}
|
|
10
|
+
function isCheckoutReturn(where) {
|
|
11
|
+
return paramsOf(where).get(CHECKOUT_RETURN_PARAM) === CHECKOUT_RETURN_VALUE;
|
|
12
|
+
}
|
|
13
|
+
function withoutCheckoutReturn(params) {
|
|
14
|
+
const next = new URLSearchParams(params);
|
|
15
|
+
next.delete(CHECKOUT_RETURN_PARAM);
|
|
16
|
+
return next;
|
|
17
|
+
}
|
|
18
|
+
function checkoutReturnUrl(page) {
|
|
19
|
+
const hashAt = page.indexOf("#");
|
|
20
|
+
const hash = hashAt === -1 ? "" : page.slice(hashAt);
|
|
21
|
+
const beforeHash = hashAt === -1 ? page : page.slice(0, hashAt);
|
|
22
|
+
const queryAt = beforeHash.indexOf("?");
|
|
23
|
+
const path = queryAt === -1 ? beforeHash : beforeHash.slice(0, queryAt);
|
|
24
|
+
const kept = (queryAt === -1 ? "" : beforeHash.slice(queryAt + 1)).split("&").filter((part) => part !== "" && decodeKey(part) !== CHECKOUT_RETURN_PARAM);
|
|
25
|
+
kept.push(`${CHECKOUT_RETURN_PARAM}=${CHECKOUT_RETURN_VALUE}`);
|
|
26
|
+
return `${path}?${kept.join("&")}${hash}`;
|
|
27
|
+
}
|
|
28
|
+
function decodeKey(part) {
|
|
29
|
+
const key = part.split("=")[0].replace(/\+/g, " ");
|
|
30
|
+
try {
|
|
31
|
+
return decodeURIComponent(key);
|
|
32
|
+
} catch {
|
|
33
|
+
return key;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
CHECKOUT_RETURN_PARAM,
|
|
38
|
+
CHECKOUT_RETURN_VALUE,
|
|
39
|
+
checkoutReturnUrl,
|
|
40
|
+
isCheckoutReturn,
|
|
41
|
+
withoutCheckoutReturn
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=checkout-return.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/billing/checkout-return.ts"],"sourcesContent":["/**\n * The way back from the provider's checkout (docs/billing-harmonization.md §14.4,\n * decision 20): `?checkout=done` on the app's subscription page — kastlan's\n * `/admin/billing`, keksdose's and Kurvenschmiede's `/settings/subscription`.\n *\n * The checkout request carries NO success URL: a redirect the client chooses is an open\n * redirect, and Paddle's create-transaction takes none. The way back is configuration\n * instead — the pay page's Paddle.js `successUrl` (`checkoutReturnUrl(returnUrl)`), or a\n * hosted checkout's redirect in Paddle's dashboard — and the page that lands reads the\n * marker with {@link isCheckoutReturn}, then drops it with `replace`\n * ({@link withoutCheckoutReturn}) so a reload or a shared link does not count twice.\n *\n * Pure and router-agnostic, and imports nothing: the pay page (`dist/pay/`, no React)\n * bundles this module too. server-kit names the same two values\n * (`CHECKOUT_RETURN_PARAM`, `CHECKOUT_RETURN_VALUE`, `checkout_return_url`) for the\n * deploy notes and its tests.\n */\n\n/** The query parameter of the way back. */\nexport const CHECKOUT_RETURN_PARAM = \"checkout\";\n/** Its one value: the buyer came back from a completed checkout. */\nexport const CHECKOUT_RETURN_VALUE = \"done\";\n\n/** The query of `where`, however the app holds it: a search string (\"?a=1\"), a whole\n * URL, `URLSearchParams`, or a location (`{ search }`). */\nfunction paramsOf(where: string | URLSearchParams | { search: string }): URLSearchParams {\n if (where instanceof URLSearchParams) return where;\n const text = typeof where === \"string\" ? where : where.search;\n const query = text.includes(\"?\") ? text.slice(text.indexOf(\"?\") + 1) : text;\n // A whole URL's hash is not part of its query.\n return new URLSearchParams(query.split(\"#\")[0]);\n}\n\n/**\n * Whether the page was reached as the way back from a checkout: `?checkout=done`.\n *\n * const returned = isCheckoutReturn(location.search); // react-router's useLocation()\n * const returned = isCheckoutReturn(searchParams); // useSearchParams()[0]\n */\nexport function isCheckoutReturn(where: string | URLSearchParams | { search: string }): boolean {\n return paramsOf(where).get(CHECKOUT_RETURN_PARAM) === CHECKOUT_RETURN_VALUE;\n}\n\n/**\n * The same parameters without the marker — every other one kept, in order. A new\n * object; the one passed in is not changed:\n *\n * setSearchParams((p) => withoutCheckoutReturn(p), { replace: true });\n */\nexport function withoutCheckoutReturn(params: URLSearchParams): URLSearchParams {\n const next = new URLSearchParams(params);\n next.delete(CHECKOUT_RETURN_PARAM);\n return next;\n}\n\n/**\n * The subscription page's way-back URL: `page` with `checkout=done` in its query —\n * after any query it already has, before its hash. A marker already there is replaced,\n * not doubled.\n *\n * checkoutReturnUrl(\"https://keksdose.app/settings/subscription\")\n * // → \"https://keksdose.app/settings/subscription?checkout=done\"\n *\n * What the pay page hands Paddle.js as `successUrl`, and what a hosted checkout's\n * redirect is set to in Paddle's dashboard.\n */\nexport function checkoutReturnUrl(page: string): string {\n const hashAt = page.indexOf(\"#\");\n const hash = hashAt === -1 ? \"\" : page.slice(hashAt);\n const beforeHash = hashAt === -1 ? page : page.slice(0, hashAt);\n const queryAt = beforeHash.indexOf(\"?\");\n const path = queryAt === -1 ? beforeHash : beforeHash.slice(0, queryAt);\n // Kept as written, part by part: a URLSearchParams round trip would re-encode the\n // page's own parameters (a space as \"+\").\n const kept = (queryAt === -1 ? \"\" : beforeHash.slice(queryAt + 1))\n .split(\"&\")\n .filter((part) => part !== \"\" && decodeKey(part) !== CHECKOUT_RETURN_PARAM);\n kept.push(`${CHECKOUT_RETURN_PARAM}=${CHECKOUT_RETURN_VALUE}`);\n return `${path}?${kept.join(\"&\")}${hash}`;\n}\n\n/** The decoded key of one `key=value` part of a query. */\nfunction decodeKey(part: string): string {\n const key = part.split(\"=\")[0].replace(/\\+/g, \" \");\n try {\n return decodeURIComponent(key);\n } catch {\n return key;\n }\n}\n"],"mappings":";AAmBO,MAAM,wBAAwB;AAE9B,MAAM,wBAAwB;AAIrC,SAAS,SAAS,OAAuE;AACvF,MAAI,iBAAiB,gBAAiB,QAAO;AAC7C,QAAM,OAAO,OAAO,UAAU,WAAW,QAAQ,MAAM;AACvD,QAAM,QAAQ,KAAK,SAAS,GAAG,IAAI,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAI,CAAC,IAAI;AAEvE,SAAO,IAAI,gBAAgB,MAAM,MAAM,GAAG,EAAE,CAAC,CAAC;AAChD;AAQO,SAAS,iBAAiB,OAA+D;AAC9F,SAAO,SAAS,KAAK,EAAE,IAAI,qBAAqB,MAAM;AACxD;AAQO,SAAS,sBAAsB,QAA0C;AAC9E,QAAM,OAAO,IAAI,gBAAgB,MAAM;AACvC,OAAK,OAAO,qBAAqB;AACjC,SAAO;AACT;AAaO,SAAS,kBAAkB,MAAsB;AACtD,QAAM,SAAS,KAAK,QAAQ,GAAG;AAC/B,QAAM,OAAO,WAAW,KAAK,KAAK,KAAK,MAAM,MAAM;AACnD,QAAM,aAAa,WAAW,KAAK,OAAO,KAAK,MAAM,GAAG,MAAM;AAC9D,QAAM,UAAU,WAAW,QAAQ,GAAG;AACtC,QAAM,OAAO,YAAY,KAAK,aAAa,WAAW,MAAM,GAAG,OAAO;AAGtE,QAAM,QAAQ,YAAY,KAAK,KAAK,WAAW,MAAM,UAAU,CAAC,GAC7D,MAAM,GAAG,EACT,OAAO,CAAC,SAAS,SAAS,MAAM,UAAU,IAAI,MAAM,qBAAqB;AAC5E,OAAK,KAAK,GAAG,qBAAqB,IAAI,qBAAqB,EAAE;AAC7D,SAAO,GAAG,IAAI,IAAI,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI;AACzC;AAGA,SAAS,UAAU,MAAsB;AACvC,QAAM,MAAM,KAAK,MAAM,GAAG,EAAE,CAAC,EAAE,QAAQ,OAAO,GAAG;AACjD,MAAI;AACF,WAAO,mBAAmB,GAAG;AAAA,EAC/B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|