@calimero-network/mero-react 11.4.0 → 11.6.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/dist/index.cjs +470 -112
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -8
- package/dist/index.d.ts +93 -8
- package/dist/index.js +469 -114
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { styleInject, MeroContext, useNodeVerification, useCard, describeShield, hostOf, shortHash } from './chunk-MMJOGIM5.js';
|
|
2
2
|
export { MeroContext } from './chunk-MMJOGIM5.js';
|
|
3
3
|
import { useState, useEffect, useMemo, useRef, useCallback, useContext, useId, useSyncExternalStore, Fragment as Fragment$1 } from 'react';
|
|
4
|
-
import { CalimeroClient, AppError, TrapError, LoginRequired, ConfirmRequired, ConfirmCancelled, WrongNode, UnavailableError, NotFound, ReleaseDeadlineError, ConsentStale, ArgsTooLarge, IdempotencyMismatch, CalimeroError, DirectoryError, SealedTransportError, browserPasskey, consentReturn, presenceState, passkeyConfirm,
|
|
4
|
+
import { ORG_CAPABILITIES, CalimeroClient, AppError, TrapError, LoginRequired, ConfirmRequired, ConfirmCancelled, WrongNode, UnavailableError, NotFound, ReleaseDeadlineError, ConsentStale, ArgsTooLarge, IdempotencyMismatch, CalimeroError, DirectoryError, SealedTransportError, browserPasskey, consentReturn, presenceState, createOrgConsent, passkeyConfirm, createInviteConsent, acceptInviteConsent } from '@calimero-network/mero-js';
|
|
5
5
|
export * from '@calimero-network/mero-js';
|
|
6
6
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
7
|
import { createPortal } from 'react-dom';
|
|
@@ -1456,9 +1456,9 @@ function useApiKeys(options) {
|
|
|
1456
1456
|
const { withClient, ...state } = useClientAction(options);
|
|
1457
1457
|
const create = useCallback(
|
|
1458
1458
|
(input = {}) => withClient(async (c) => {
|
|
1459
|
-
const
|
|
1459
|
+
const created = await c.auth.apikeyCreate({ ...input }, confirmWith(passkey));
|
|
1460
1460
|
void refetch();
|
|
1461
|
-
return
|
|
1461
|
+
return created;
|
|
1462
1462
|
}),
|
|
1463
1463
|
[withClient, passkey, refetch]
|
|
1464
1464
|
);
|
|
@@ -1872,7 +1872,51 @@ function ConnectButton({
|
|
|
1872
1872
|
styleInject('.mero-cw,\n.mero-cw-review {\n --_ink: var(--cw-ink, light-dark(#0f1117, #eceef5));\n --_muted: var(--cw-muted, light-dark(#6b7280, #9097ab));\n --_line: var(--cw-line, light-dark(#e6e8ee, rgba(255, 255, 255, 0.16)));\n --_surface: var(--cw-surface, light-dark(#ffffff, #161b2b));\n --_primary-bg: var(--cw-primary-bg, light-dark(#0f1117, #eceef5));\n --_primary-ink: var(--cw-primary-ink, light-dark(#ffffff, #0f1117));\n --_focus: var(--cw-link, light-dark(#3b5bfd, #9aafff));\n --_good-bg: var(--cw-good-bg, light-dark(#dcfce7, #0e3324));\n --_good-ink: var(--cw-good-ink, light-dark(#15803d, #7fe0b0));\n --_bad-bg: var(--cw-bad-bg, light-dark(#ffe4ea, #3d0f1e));\n --_bad-ink: var(--cw-bad-ink, light-dark(#a2194b, #f78bb0));\n --_busy-bg: var(--cw-busy-bg, light-dark(#e3e9ff, #1c2650));\n --_busy-ink: var(--cw-busy-ink, light-dark(#3451d1, #9aafff));\n --_warn-bg: var(--cw-warn-bg, light-dark(#fff1d6, #3a2a08));\n --_warn-ink: var(--cw-warn-ink, light-dark(#8a5a00, #f2c36b));\n --_code-bg: var(--cw-code-bg, light-dark(#f4f5f8, #1f2538));\n font-family: var(--cw-font, inherit);\n}\n.mero-cw-review [data-kind=verified] {\n --_tone: var(--_good-ink);\n --_tone-bg: var(--_good-bg);\n}\n.mero-cw-review [data-kind=refused] {\n --_tone: var(--_bad-ink);\n --_tone-bg: var(--_bad-bg);\n}\n.mero-cw-review [data-kind=checking] {\n --_tone: var(--_busy-ink);\n --_tone-bg: var(--_busy-bg);\n}\n.mero-cw-review [data-kind=unsealed] {\n --_tone: var(--_muted);\n --_tone-bg: color-mix(in srgb, var(--_muted) 14%, var(--_surface));\n}\n.mero-cw-shield__icon {\n flex: none;\n color: var(--_tone);\n}\n.mero-cw-shield__tick {\n flex: none;\n margin-top: 2px;\n color: var(--_muted);\n}\n@media (prefers-reduced-motion: no-preference) {\n [data-kind=checking] .mero-cw-shield__icon {\n animation: mero-cw-shield-pulse 1.4s ease-in-out infinite;\n }\n}\n@keyframes mero-cw-shield-pulse {\n 50% {\n opacity: 0.4;\n }\n}\n.mero-cw-review {\n box-sizing: border-box;\n width: 100%;\n color: var(--_ink);\n font-size: 14px;\n line-height: 1.45;\n text-align: left;\n}\n.mero-cw-review *,\n.mero-cw-review *::before,\n.mero-cw-review *::after {\n box-sizing: border-box;\n}\n.mero-cw-review__title {\n margin: 0;\n font-size: 18px;\n font-weight: 700;\n line-height: 1.3;\n}\n.mero-cw-review__title:focus {\n outline: none;\n}\n.mero-cw-review__lede {\n margin: 4px 0 6px;\n color: var(--_muted);\n}\n.mero-cw-review__muted,\n.mero-cw-review__sub {\n color: var(--_muted);\n font-size: 12.5px;\n}\n.mero-cw-review__muted {\n margin: 8px 0 0;\n}\n.mero-cw-review__sub {\n display: block;\n margin-top: 2px;\n}\n.mero-cw-review__mono {\n font-family:\n ui-monospace,\n "SF Mono",\n SFMono-Regular,\n Menlo,\n Consolas,\n monospace;\n font-size: 12.5px;\n overflow-wrap: anywhere;\n}\n.mero-cw-review__icon {\n flex: none;\n}\n.mero-cw-review__nobreak {\n white-space: nowrap;\n}\n.mero-cw-review__sec {\n padding: 14px 0;\n border-top: 1px solid var(--_line);\n}\n.mero-cw-review__h {\n display: flex;\n align-items: center;\n gap: 7px;\n margin: 0 0 10px;\n font-size: 13px;\n font-weight: 700;\n letter-spacing: 0.02em;\n}\n.mero-cw-review__h .mero-cw-shield__icon {\n margin-top: -1px;\n}\n.mero-cw-review__kv {\n display: flex;\n flex-direction: column;\n gap: 6px;\n margin: 0;\n}\n.mero-cw-review__kv > div {\n display: grid;\n grid-template-columns: 96px minmax(0, 1fr);\n gap: 12px;\n}\n.mero-cw-review__kv dt {\n color: var(--_muted);\n}\n.mero-cw-review__kv dd {\n margin: 0;\n overflow-wrap: anywhere;\n}\n.mero-cw-review__kv--raw {\n margin-bottom: 12px;\n}\n.mero-cw-review__tone--good {\n color: var(--_good-ink);\n}\n.mero-cw-review__tone--bad {\n color: var(--_bad-ink);\n font-weight: 600;\n}\n.mero-cw-review__copy,\n.mero-cw-review__link {\n margin-left: 8px;\n padding: 0;\n border: 0;\n background: none;\n color: var(--_focus);\n font: inherit;\n font-size: 12.5px;\n font-weight: 600;\n text-decoration: none;\n cursor: pointer;\n}\n.mero-cw-review__link {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n}\n.mero-cw-review__copy:hover,\n.mero-cw-review__link:hover {\n text-decoration: underline;\n}\n.mero-cw-review__sum {\n display: flex;\n flex-direction: column;\n gap: 10px;\n margin: 0;\n padding: 0;\n list-style: none;\n}\n.mero-cw-review__sum li {\n display: flex;\n align-items: flex-start;\n gap: 10px;\n}\n.mero-cw-review__ic {\n display: grid;\n place-items: center;\n flex: none;\n width: 28px;\n height: 28px;\n border-radius: 50%;\n background: var(--_chip-bg);\n color: var(--_muted);\n}\n.mero-cw-review__sum li[data-tone=warn] .mero-cw-review__ic {\n background: var(--_warn-bg);\n color: var(--_warn-ink);\n}\n.mero-cw-review__sum li[data-tone=ok] .mero-cw-review__ic {\n background: var(--_good-bg);\n color: var(--_good-ink);\n}\n.mero-cw-review__tx {\n display: flex;\n flex-direction: column;\n min-width: 0;\n padding-top: 3px;\n}\n.mero-cw-review__tx span {\n color: var(--_muted);\n font-size: 12.5px;\n overflow-wrap: anywhere;\n}\n.mero-cw-review__more {\n margin-top: 0;\n}\n.mero-cw-review__sum + .mero-cw-review__more {\n margin-top: 10px;\n}\n.mero-cw-review__more > summary,\n.mero-cw-review__how > summary {\n display: flex;\n align-items: center;\n gap: 6px;\n min-height: 32px;\n color: var(--_focus);\n font-weight: 600;\n cursor: pointer;\n list-style: none;\n}\n.mero-cw-review summary::-webkit-details-marker {\n display: none;\n}\n.mero-cw-review__more > summary::after,\n.mero-cw-review__how > summary::after,\n.mero-cw-review__grp > summary::after,\n.mero-cw-review__act > summary::after {\n content: "";\n flex: none;\n width: 7px;\n height: 7px;\n margin: 0 3px;\n border: solid currentColor;\n border-width: 0 2px 2px 0;\n transform: rotate(-45deg);\n transition: transform 0.15s ease;\n}\n.mero-cw-review details[open] > summary::after {\n transform: rotate(45deg);\n}\n.mero-cw-review summary:focus-visible,\n.mero-cw-review__btn:focus-visible,\n.mero-cw-review__chip:focus-visible,\n.mero-cw-review__copy:focus-visible,\n.mero-cw-review__link:focus-visible {\n outline: 2px solid var(--_focus);\n outline-offset: 2px;\n border-radius: 6px;\n}\n.mero-cw-review__chips {\n display: flex;\n flex-wrap: wrap;\n gap: 6px;\n margin: 4px 0 10px;\n}\n.mero-cw-review__chip {\n min-height: 30px;\n padding: 0 11px;\n border: 1px solid var(--_line);\n border-radius: 999px;\n background: var(--_surface);\n color: var(--_ink);\n font: inherit;\n font-size: 12.5px;\n font-weight: 600;\n cursor: pointer;\n}\n.mero-cw-review__chip[aria-pressed=true] {\n border-color: transparent;\n background: var(--_primary-bg);\n color: var(--_primary-ink);\n}\n.mero-cw-review__grp {\n margin-top: 8px;\n border: 1px solid var(--_line);\n border-radius: 12px;\n}\n.mero-cw-review__grp > summary {\n display: flex;\n align-items: center;\n gap: 10px;\n min-height: 48px;\n padding: 8px 12px;\n cursor: pointer;\n list-style: none;\n color: var(--_muted);\n}\n.mero-cw-review__grp-text {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-width: 0;\n}\n.mero-cw-review__grp-text b {\n color: var(--_ink);\n}\n.mero-cw-review__grp-text span {\n font-size: 12.5px;\n}\n.mero-cw-review__count {\n flex: none;\n min-width: 22px;\n padding: 1px 7px;\n border-radius: 999px;\n background: var(--_chip-bg);\n color: var(--_ink);\n font-size: 12px;\n font-weight: 600;\n text-align: center;\n}\n.mero-cw-review__acts {\n border-top: 1px solid var(--_line);\n}\n.mero-cw-review__act + .mero-cw-review__act {\n border-top: 1px solid var(--_line);\n}\n.mero-cw-review__act > summary,\n.mero-cw-review__act-head {\n display: flex;\n align-items: center;\n gap: 8px;\n min-height: 40px;\n padding: 6px 12px;\n cursor: pointer;\n list-style: none;\n color: var(--_muted);\n}\n.mero-cw-review__act-head {\n cursor: default;\n}\n.mero-cw-review__act-main {\n display: flex;\n flex: 1 1 0;\n flex-direction: column;\n gap: 1px;\n min-width: 0;\n}\n.mero-cw-review__act-title {\n color: var(--_ink);\n font-weight: 600;\n overflow-wrap: anywhere;\n}\n.mero-cw-review__act-doc {\n font-size: 12px;\n font-style: italic;\n overflow-wrap: anywhere;\n}\n.mero-cw-review__act-doc code,\n.mero-cw-review__said code {\n font-family:\n ui-monospace,\n "SF Mono",\n SFMono-Regular,\n Menlo,\n Consolas,\n monospace;\n font-size: 0.92em;\n font-style: normal;\n}\n.mero-cw-review__act > summary::after {\n margin-left: 0;\n}\n.mero-cw-review__tags {\n display: flex;\n flex: none;\n flex-wrap: wrap;\n justify-content: flex-end;\n gap: 4px;\n max-width: 55%;\n}\n.mero-cw-review__tag {\n padding: 1px 8px;\n border-radius: 999px;\n background: var(--_chip-bg);\n color: var(--_muted);\n font-size: 11.5px;\n font-weight: 600;\n white-space: nowrap;\n}\n.mero-cw-review__tag--passkey {\n background: var(--_warn-bg);\n color: var(--_warn-ink);\n}\n.mero-cw-review__tag--public {\n background: var(--_busy-bg);\n color: var(--_busy-ink);\n}\n.mero-cw-review__facts {\n padding: 2px 12px 12px;\n}\n.mero-cw-review__facts .mero-cw-review__kv {\n font-size: 12.5px;\n}\n.mero-cw-review__said {\n margin-top: 10px;\n padding: 8px 10px;\n border: 1px dashed var(--_line);\n border-radius: 8px;\n}\n.mero-cw-review__said span {\n color: var(--_muted);\n font-size: 11.5px;\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.04em;\n}\n.mero-cw-review__said p {\n margin: 2px 0 0;\n font-style: italic;\n overflow-wrap: anywhere;\n}\n.mero-cw-review__note {\n margin: 10px 0 0;\n color: var(--_muted);\n font-size: 12px;\n}\n.mero-cw-review__claims {\n display: flex;\n flex-direction: column;\n gap: 6px;\n margin: 0;\n padding: 0;\n list-style: none;\n}\n.mero-cw-review__claims li {\n display: flex;\n align-items: flex-start;\n gap: 7px;\n}\n.mero-cw-review__claims .mero-cw-shield__tick {\n margin-top: 3px;\n color: var(--_good-ink);\n}\n.mero-cw-review__claims--plain b {\n font-weight: 500;\n color: var(--_muted);\n}\n.mero-cw-review__claims + .mero-cw-review__grey {\n margin-top: 10px;\n}\n.mero-cw-review__how {\n margin-top: 6px;\n}\n.mero-cw-review__how ul {\n margin: 0 0 4px;\n padding-left: 18px;\n color: var(--_muted);\n font-size: 12.5px;\n}\n.mero-cw-review__except {\n display: flex;\n flex-direction: column;\n gap: 6px;\n margin: 10px 0 0;\n padding: 0;\n list-style: none;\n}\n.mero-cw-review__except li {\n display: flex;\n align-items: flex-start;\n gap: 8px;\n padding: 8px 10px;\n border-radius: 10px;\n background: var(--_warn-bg);\n color: var(--_warn-ink);\n font-weight: 600;\n overflow-wrap: anywhere;\n}\n.mero-cw-review__except .mero-cw-review__icon {\n margin-top: 2px;\n}\n.mero-cw-review__grey {\n display: flex;\n flex-direction: column;\n gap: 2px;\n margin: 0;\n padding: 10px 12px;\n border-radius: 10px;\n background: var(--_tone-bg);\n color: var(--_ink);\n}\n.mero-cw-review__grey span {\n color: var(--_muted);\n font-size: 12.5px;\n}\n.mero-cw-review__alert {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n justify-content: space-between;\n gap: 8px 12px;\n margin: 10px 0 4px;\n padding: 10px 12px;\n border-radius: 10px;\n background: var(--_bad-bg);\n color: var(--_bad-ink);\n}\n.mero-cw-review__alert p {\n flex: 1 1 220px;\n margin: 0;\n font-weight: 600;\n overflow-wrap: anywhere;\n}\n.mero-cw-review__buttons {\n position: sticky;\n bottom: calc(0px - var(--cw-review-inset, 0px));\n z-index: 1;\n display: flex;\n justify-content: space-between;\n gap: 10px;\n margin-top: 6px;\n padding: 14px 0 calc(env(safe-area-inset-bottom, 0px) + 8px);\n border-top: 1px solid var(--_line);\n background: var(--_surface);\n}\n.mero-cw-review__btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-height: 40px;\n padding: 0 18px;\n border: 1px solid var(--_line);\n border-radius: 999px;\n background: var(--_surface);\n color: var(--_ink);\n font: inherit;\n font-weight: 600;\n cursor: pointer;\n}\n.mero-cw-review__btn:hover:not(:disabled) {\n border-color: var(--_ink);\n}\n.mero-cw-review__btn:disabled {\n opacity: 0.55;\n cursor: not-allowed;\n}\n.mero-cw-review__buttons .mero-cw-review__btn {\n white-space: nowrap;\n}\n.mero-cw-review__btn--primary {\n border-color: transparent;\n background: var(--_primary-bg);\n color: var(--_primary-ink);\n}\n.mero-cw-review__btn--primary:hover:not(:disabled) {\n border-color: transparent;\n opacity: 0.88;\n}\n@media (max-width: 480px) {\n .mero-cw-review__kv > div {\n grid-template-columns: minmax(0, 1fr);\n gap: 0;\n }\n .mero-cw-review__kv dt {\n font-size: 12px;\n }\n .mero-cw-review__buttons .mero-cw-review__btn {\n flex: 1;\n padding: 0 12px;\n }\n .mero-cw-review__buttons .mero-cw-review__btn--primary {\n flex: 2;\n }\n}\n');
|
|
1873
1873
|
|
|
1874
1874
|
// src/create-workspace/createWorkspace.css
|
|
1875
|
-
styleInject('.mero-cw-overlay {\n position: fixed;\n inset: 0;\n z-index: var(--cw-z, 2147483000);\n display: grid;\n place-items: center;\n padding: 16px;\n background: rgba(15, 17, 23, 0.45);\n}\n.mero-cw-card {\n position: relative;\n box-sizing: border-box;\n width: 100%;\n max-width: 420px;\n max-height: calc(100dvh - 32px);\n display: flex;\n flex-direction: column;\n overflow: hidden;\n border-radius: 18px;\n background: var(--_surface);\n color: var(--_ink);\n box-shadow: 0 10px 30px rgba(15, 17, 23, 0.18);\n}\n.mero-cw-body {\n flex: 1 1 auto;\n min-height: 0;\n overflow-y: auto;\n padding: 20px 22px 0;\n}\n.mero-cw-body > :last-child {\n margin-bottom: 20px;\n}\n.mero-cw-body .mero-cw-review__buttons {\n margin-bottom: 0;\n padding-bottom: 18px;\n}\n.mero-cw-card *,\n.mero-cw-card *::before,\n.mero-cw-card *::after {\n box-sizing: border-box;\n}\n.mero-cw-x {\n position: absolute;\n top: 12px;\n right: 14px;\n z-index: 2;\n display: grid;\n place-items: center;\n width: 28px;\n height: 28px;\n padding: 0;\n border: 0;\n border-radius: 50%;\n background: none;\n color: var(--_muted);\n cursor: pointer;\n}\n.mero-cw-x:hover {\n background: var(--_code-bg);\n color: var(--_ink);\n}\n.mero-cw-title {\n margin: 0 0 4px;\n padding-right: 28px;\n font-size: 17px;\n font-weight: 700;\n}\n.mero-cw-sub {\n margin: 0 0 14px;\n color: var(--_muted);\n font-size: 12.5px;\n line-height: 1.45;\n}\n.mero-cw-field {\n margin: 0 0 12px;\n}\n.mero-cw-field label {\n display: block;\n margin: 0 0 5px;\n font-size: 12px;\n font-weight: 600;\n}\n.mero-cw-field input {\n width: 100%;\n padding: 9px 11px;\n border: 1px solid var(--_line);\n border-radius: 10px;\n background: var(--_surface);\n color: var(--_ink);\n font: inherit;\n font-size: 13px;\n}\n.mero-cw-field input:focus-visible {\n outline: 2px solid var(--_focus);\n outline-offset: 1px;\n}\n.mero-cw-btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-height: 38px;\n padding: 0 16px;\n border: 1px solid var(--_line);\n border-radius: 999px;\n background: var(--_surface);\n color: var(--_ink);\n font: inherit;\n font-size: 13px;\n font-weight: 600;\n cursor: pointer;\n}\n.mero-cw-btn:disabled {\n opacity: 0.55;\n cursor: not-allowed;\n}\n.mero-cw-btn--primary {\n border-color: transparent;\n background: var(--_primary-bg);\n color: var(--_primary-ink);\n}\n.mero-cw-btn--full {\n width: 100%;\n}\n.mero-cw-btn:focus-visible,\n.mero-cw-link:focus-visible,\n.mero-cw-x:focus-visible {\n outline: 2px solid var(--_focus);\n outline-offset: 2px;\n}\n.mero-cw-link {\n border: 0;\n background: none;\n color: var(--_focus);\n font: inherit;\n font-size: 12.5px;\n font-weight: 600;\n cursor: pointer;\n}\n.mero-cw-link:hover {\n text-decoration: underline;\n}\n.mero-cw-row {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 10px;\n margin-top: 14px;\n}\n.mero-cw-code {\n margin: 10px 0;\n padding: 10px;\n border-radius: 12px;\n background: var(--_code-bg);\n font-family:\n ui-monospace,\n "SF Mono",\n SFMono-Regular,\n Menlo,\n Consolas,\n monospace;\n font-size: 22px;\n font-weight: 700;\n letter-spacing: 3px;\n text-align: center;\n}\n.mero-cw-wait {\n display: flex;\n align-items: center;\n gap: 8px;\n color: var(--_muted);\n font-size: 12.5px;\n}\n.mero-cw-dot {\n width: 8px;\n height: 8px;\n border-radius: 50%;\n background: var(--_focus);\n}\n@media (prefers-reduced-motion: no-preference) {\n .mero-cw-dot {\n animation: mero-cw-pulse 1.2s infinite;\n }\n}\n@keyframes mero-cw-pulse {\n 50% {\n opacity: 0.25;\n }\n}\n.mero-cw-error {\n margin: 0 0 12px;\n padding: 10px 12px;\n border-radius: 10px;\n background: var(--_bad-bg);\n color: var(--_bad-ink);\n font-size: 13px;\n font-weight: 600;\n overflow-wrap: anywhere;\n}\n.mero-cw-notice {\n position: fixed;\n right: 16px;\n bottom: 16px;\n z-index: var(--cw-z, 2147483000);\n max-width: 360px;\n padding: 10px 14px;\n border-radius: 10px;\n background: var(--_surface);\n color: var(--_ink);\n font-size: 13px;\n line-height: 1.4;\n box-shadow: 0 0 0 1px var(--_line), 0 12px 28px -12px rgba(14, 18, 34, 0.4);\n}\n');
|
|
1875
|
+
styleInject('.mero-cw-overlay {\n position: fixed;\n inset: 0;\n z-index: var(--cw-z, 2147483000);\n display: grid;\n place-items: center;\n padding: 16px;\n background: rgba(15, 17, 23, 0.45);\n}\n.mero-cw-card {\n position: relative;\n box-sizing: border-box;\n width: 100%;\n max-width: 420px;\n max-height: calc(100dvh - 32px);\n display: flex;\n flex-direction: column;\n overflow: hidden;\n border-radius: 18px;\n background: var(--_surface);\n color: var(--_ink);\n box-shadow: 0 10px 30px rgba(15, 17, 23, 0.18);\n}\n.mero-cw-body {\n flex: 1 1 auto;\n min-height: 0;\n overflow-y: auto;\n padding: 20px 22px 0;\n}\n.mero-cw-body > :last-child {\n margin-bottom: 20px;\n}\n.mero-cw-body .mero-cw-review__buttons {\n margin-bottom: 0;\n padding-bottom: 18px;\n}\n.mero-cw-card *,\n.mero-cw-card *::before,\n.mero-cw-card *::after {\n box-sizing: border-box;\n}\n.mero-cw-x {\n position: absolute;\n top: 12px;\n right: 14px;\n z-index: 2;\n display: grid;\n place-items: center;\n width: 28px;\n height: 28px;\n padding: 0;\n border: 0;\n border-radius: 50%;\n background: none;\n color: var(--_muted);\n cursor: pointer;\n}\n.mero-cw-x:hover {\n background: var(--_code-bg);\n color: var(--_ink);\n}\n.mero-cw-title {\n margin: 0 0 4px;\n padding-right: 28px;\n font-size: 17px;\n font-weight: 700;\n}\n.mero-cw-sub {\n margin: 0 0 14px;\n color: var(--_muted);\n font-size: 12.5px;\n line-height: 1.45;\n}\n.mero-cw-field {\n margin: 0 0 12px;\n}\n.mero-cw-field label {\n display: block;\n margin: 0 0 5px;\n font-size: 12px;\n font-weight: 600;\n}\n.mero-cw-field input {\n width: 100%;\n padding: 9px 11px;\n border: 1px solid var(--_line);\n border-radius: 10px;\n background: var(--_surface);\n color: var(--_ink);\n font: inherit;\n font-size: 13px;\n}\n.mero-cw-field input:focus-visible {\n outline: 2px solid var(--_focus);\n outline-offset: 1px;\n}\n.mero-cw-btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-height: 38px;\n padding: 0 16px;\n border: 1px solid var(--_line);\n border-radius: 999px;\n background: var(--_surface);\n color: var(--_ink);\n font: inherit;\n font-size: 13px;\n font-weight: 600;\n cursor: pointer;\n}\n.mero-cw-btn:disabled {\n opacity: 0.55;\n cursor: not-allowed;\n}\n.mero-cw-btn--primary {\n border-color: transparent;\n background: var(--_primary-bg);\n color: var(--_primary-ink);\n}\n.mero-cw-btn--full {\n width: 100%;\n}\n.mero-cw-btn:focus-visible,\n.mero-cw-link:focus-visible,\n.mero-cw-x:focus-visible {\n outline: 2px solid var(--_focus);\n outline-offset: 2px;\n}\n.mero-cw-link {\n border: 0;\n background: none;\n color: var(--_focus);\n font: inherit;\n font-size: 12.5px;\n font-weight: 600;\n cursor: pointer;\n}\n.mero-cw-link:hover {\n text-decoration: underline;\n}\n.mero-cw-row {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 10px;\n margin-top: 14px;\n}\n.mero-cw-code {\n margin: 10px 0;\n padding: 10px;\n border-radius: 12px;\n background: var(--_code-bg);\n font-family:\n ui-monospace,\n "SF Mono",\n SFMono-Regular,\n Menlo,\n Consolas,\n monospace;\n font-size: 22px;\n font-weight: 700;\n letter-spacing: 3px;\n text-align: center;\n}\n.mero-cw-wait {\n display: flex;\n align-items: center;\n gap: 8px;\n color: var(--_muted);\n font-size: 12.5px;\n}\n.mero-cw-dot {\n width: 8px;\n height: 8px;\n border-radius: 50%;\n background: var(--_focus);\n}\n@media (prefers-reduced-motion: no-preference) {\n .mero-cw-dot {\n animation: mero-cw-pulse 1.2s infinite;\n }\n}\n@keyframes mero-cw-pulse {\n 50% {\n opacity: 0.25;\n }\n}\n.mero-cw-error {\n margin: 0 0 12px;\n padding: 10px 12px;\n border-radius: 10px;\n background: var(--_bad-bg);\n color: var(--_bad-ink);\n font-size: 13px;\n font-weight: 600;\n overflow-wrap: anywhere;\n}\n.mero-cw-notice {\n position: fixed;\n right: 16px;\n bottom: 16px;\n z-index: var(--cw-z, 2147483000);\n max-width: 360px;\n padding: 10px 14px;\n border-radius: 10px;\n background: var(--_surface);\n color: var(--_ink);\n font-size: 13px;\n line-height: 1.4;\n box-shadow: 0 0 0 1px var(--_line), 0 12px 28px -12px rgba(14, 18, 34, 0.4);\n}\n.mero-cw-choices {\n display: flex;\n flex-direction: column;\n gap: 8px;\n margin: 0 0 12px;\n padding: 0;\n border: 0;\n}\n.mero-cw-choice {\n display: flex;\n align-items: flex-start;\n gap: 10px;\n padding: 10px 12px;\n border: 1px solid var(--_line);\n border-radius: 12px;\n cursor: pointer;\n}\n.mero-cw-choice:has(input:checked) {\n border-color: var(--_ink);\n}\n.mero-cw-choice input {\n margin-top: 3px;\n accent-color: var(--_primary-bg);\n}\n.mero-cw-choice b {\n display: block;\n font-size: 13px;\n}\n.mero-cw-choice .mero-cw-sub {\n display: block;\n margin: 2px 0 0;\n}\n.mero-cw-caps {\n display: flex;\n flex-direction: column;\n gap: 2px;\n margin: 0 0 14px;\n padding: 6px 4px;\n border-top: 1px solid var(--_line);\n border-bottom: 1px solid var(--_line);\n max-height: 220px;\n overflow-y: auto;\n}\n.mero-cw-cap {\n display: flex;\n flex-wrap: wrap;\n align-items: baseline;\n gap: 0 10px;\n padding: 6px 8px;\n font-size: 13px;\n}\n.mero-cw-cap label {\n display: flex;\n align-items: center;\n gap: 10px;\n cursor: pointer;\n}\n.mero-cw-cap[data-disabled] {\n color: var(--_muted);\n}\n.mero-cw-cap[data-disabled] label {\n cursor: not-allowed;\n}\n.mero-cw-cap input {\n margin: 0;\n accent-color: var(--_primary-bg);\n}\n.mero-cw-hint {\n display: inline;\n color: var(--_muted);\n font-size: 11.5px;\n}\n.mero-cw-visually-hidden {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip: rect(0 0 0 0);\n white-space: nowrap;\n}\n');
|
|
1876
|
+
var subscribeNothing = () => () => void 0;
|
|
1877
|
+
var useMounted = () => useSyncExternalStore(subscribeNothing, () => true, () => false);
|
|
1878
|
+
var CloseIcon = () => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "16", height: "16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "m6 6 12 12M18 6 6 18", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) });
|
|
1879
|
+
function DialogShell({ label, locked = false, onClose, children }) {
|
|
1880
|
+
const mounted = useMounted();
|
|
1881
|
+
if (!mounted) return null;
|
|
1882
|
+
return createPortal(
|
|
1883
|
+
/* @__PURE__ */ jsx("div", { className: "mero-cw mero-cw-overlay", onKeyDown: (e) => e.key === "Escape" && !locked && onClose(), children: /* @__PURE__ */ jsxs("div", { className: "mero-cw-card", role: "dialog", "aria-modal": "true", "aria-label": label, children: [
|
|
1884
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-x", "aria-label": "Close", onClick: onClose, children: /* @__PURE__ */ jsx(CloseIcon, {}) }),
|
|
1885
|
+
/* @__PURE__ */ jsx("div", { className: "mero-cw-body", children })
|
|
1886
|
+
] }) }),
|
|
1887
|
+
document.body
|
|
1888
|
+
);
|
|
1889
|
+
}
|
|
1890
|
+
function WithClient({ client, passkey, children }) {
|
|
1891
|
+
const sessionStore = useMemo(() => ({ load: () => client?.session ?? null, save: () => void 0, clear: () => void 0 }), [client]);
|
|
1892
|
+
return client ? /* @__PURE__ */ jsx(MeroProvider, { client, sessionStore, passkey, children }) : /* @__PURE__ */ jsx(Fragment, { children });
|
|
1893
|
+
}
|
|
1894
|
+
function ApprovalCard({
|
|
1895
|
+
redirecting,
|
|
1896
|
+
code,
|
|
1897
|
+
onCancel,
|
|
1898
|
+
onProceed,
|
|
1899
|
+
onReopen
|
|
1900
|
+
}) {
|
|
1901
|
+
return /* @__PURE__ */ jsxs("div", { className: "mero-cw-approve", children: [
|
|
1902
|
+
/* @__PURE__ */ jsx("h2", { className: "mero-cw-title", children: "Approve with your passkey" }),
|
|
1903
|
+
/* @__PURE__ */ jsx("p", { className: "mero-cw-sub", children: redirecting ? "Your node will open its own page to ask for your passkey. Check that it shows this code." : "A window from your node opened. Check it shows this code, then approve there." }),
|
|
1904
|
+
/* @__PURE__ */ jsx("div", { className: "mero-cw-code", "aria-live": "polite", children: code ?? "..." }),
|
|
1905
|
+
redirecting ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1906
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-btn mero-cw-btn--primary mero-cw-btn--full", onClick: onProceed, children: "Continue to your node" }),
|
|
1907
|
+
/* @__PURE__ */ jsx("div", { className: "mero-cw-row", children: /* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-btn", onClick: onCancel, children: "Cancel" }) })
|
|
1908
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1909
|
+
/* @__PURE__ */ jsxs("div", { className: "mero-cw-wait", role: "status", children: [
|
|
1910
|
+
/* @__PURE__ */ jsx("span", { className: "mero-cw-dot", "aria-hidden": "true" }),
|
|
1911
|
+
"Waiting for your approval..."
|
|
1912
|
+
] }),
|
|
1913
|
+
/* @__PURE__ */ jsxs("div", { className: "mero-cw-row", children: [
|
|
1914
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-btn", onClick: onCancel, children: "Cancel" }),
|
|
1915
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-link", onClick: onReopen, children: "Open the window again" })
|
|
1916
|
+
] })
|
|
1917
|
+
] })
|
|
1918
|
+
] });
|
|
1919
|
+
}
|
|
1876
1920
|
|
|
1877
1921
|
// src/create-workspace/clusterName.ts
|
|
1878
1922
|
var LOCAL_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
@@ -1947,7 +1991,7 @@ var EVERY_UNITS = { s: "second", m: "minute", h: "hour" };
|
|
|
1947
1991
|
var INVITED_ONLY = "Only people invited to it can open it";
|
|
1948
1992
|
var NOT_READABLE = "Calimero can't read it.";
|
|
1949
1993
|
var TEST_SERVER_ENFORCES = ", as this test server enforces it";
|
|
1950
|
-
var
|
|
1994
|
+
var control = (viewer, noun) => "Only you control it" ;
|
|
1951
1995
|
var MAX_DOC_CHARS = 4e3;
|
|
1952
1996
|
var WORD_TAIL = 8;
|
|
1953
1997
|
var ABBREVIATIONS = /* @__PURE__ */ new Set(["e.g", "i.e", "etc", "vs", "cf"]);
|
|
@@ -2151,9 +2195,10 @@ function codeLine(card, evidence, signed = true) {
|
|
|
2151
2195
|
const fromRelease = `bundle ${shortHash(card.bundle)}, from ${signed ? "the signed release" : "the release as this test server lists it"}`;
|
|
2152
2196
|
return { text: fromRelease };
|
|
2153
2197
|
}
|
|
2154
|
-
function dataStatements(kind, viewer) {
|
|
2155
|
-
|
|
2156
|
-
if (kind === "
|
|
2198
|
+
function dataStatements(kind, viewer, noun = "workspace") {
|
|
2199
|
+
const CONTROL = control();
|
|
2200
|
+
if (kind === "verified") return [`${CONTROL}.`, `${INVITED_ONLY}.`, NOT_READABLE];
|
|
2201
|
+
if (kind === "unsealed") return [`${CONTROL}${TEST_SERVER_ENFORCES}`, `${INVITED_ONLY}${TEST_SERVER_ENFORCES}`];
|
|
2157
2202
|
return [];
|
|
2158
2203
|
}
|
|
2159
2204
|
var OPEN_GROUP_MAX = 3;
|
|
@@ -2275,7 +2320,7 @@ function Diverged({ divergence }) {
|
|
|
2275
2320
|
/* @__PURE__ */ jsx("span", { children: "This node runs different code than the release, so no statement about your data is made here." })
|
|
2276
2321
|
] }) });
|
|
2277
2322
|
}
|
|
2278
|
-
function ReviewBody({ review, release, cluster, local }) {
|
|
2323
|
+
function ReviewBody({ review, release, cluster, local, noun }) {
|
|
2279
2324
|
const { client, state, loaded, retry } = review;
|
|
2280
2325
|
const view = describeShield(state, { code: null });
|
|
2281
2326
|
const card = loaded.status === "ready" ? loaded.card : null;
|
|
@@ -2284,7 +2329,7 @@ function ReviewBody({ review, release, cluster, local }) {
|
|
|
2284
2329
|
const code = card ? codeLine(card, null, sealed) : null;
|
|
2285
2330
|
const summary = card ? summarize(card, sealed) : [];
|
|
2286
2331
|
const risks = card ? exceptions(card, sealed) : [];
|
|
2287
|
-
const statements = dataStatements(view.kind, "creator");
|
|
2332
|
+
const statements = dataStatements(view.kind, "creator", noun);
|
|
2288
2333
|
const nodes = client && !local ? `${client.nodes.length} ${client.nodes.length === 1 ? "node" : "nodes"}` : "";
|
|
2289
2334
|
const unreleased = loaded.status === "none";
|
|
2290
2335
|
const unknown = unreleased ? "This build has no signed release, so what it can do and what leaves the sealed hardware is not known." : !card ? "What leaves the sealed hardware is not known until the app's details load." : !card.abi ? "This app publishes no action list, so what it makes visible to anyone is not known." : null;
|
|
@@ -2292,7 +2337,7 @@ function ReviewBody({ review, release, cluster, local }) {
|
|
|
2292
2337
|
loaded.status === "error" && /* @__PURE__ */ jsxs("div", { className: "mero-cw-review__alert", role: "alert", children: [
|
|
2293
2338
|
/* @__PURE__ */ jsxs("p", { children: [
|
|
2294
2339
|
loaded.message,
|
|
2295
|
-
client ?
|
|
2340
|
+
client ? ` You can still create the ${noun}.` : ""
|
|
2296
2341
|
] }),
|
|
2297
2342
|
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-review__btn", onClick: retry, children: "Try again" })
|
|
2298
2343
|
] }),
|
|
@@ -2388,19 +2433,19 @@ function ReviewBody({ review, release, cluster, local }) {
|
|
|
2388
2433
|
] }) })
|
|
2389
2434
|
] });
|
|
2390
2435
|
}
|
|
2391
|
-
function WorkspaceReview({ client, cluster, local, release, creating = false, disabled = false, onBack, onCreate }) {
|
|
2436
|
+
function WorkspaceReview({ client, cluster, local, noun = "workspace", release, creating = false, disabled = false, onBack, onCreate }) {
|
|
2392
2437
|
const heading = useRef(null);
|
|
2393
2438
|
useEffect(() => heading.current?.focus(), []);
|
|
2394
2439
|
const review = useReview(client, release);
|
|
2395
2440
|
const refused = review.state.status === "refused";
|
|
2396
2441
|
return /* @__PURE__ */ jsxs("div", { className: "mero-cw-review", children: [
|
|
2397
2442
|
/* @__PURE__ */ jsx("h2", { ref: heading, tabIndex: -1, className: "mero-cw-review__title", children: "Review before creating" }),
|
|
2398
|
-
/* @__PURE__ */ jsx("p", { className: "mero-cw-review__lede", children:
|
|
2399
|
-
/* @__PURE__ */ jsx(ReviewBody, { review, release, cluster, local }),
|
|
2443
|
+
/* @__PURE__ */ jsx("p", { className: "mero-cw-review__lede", children: `Check what this app can do and where it will run before you create the ${noun}.` }),
|
|
2444
|
+
/* @__PURE__ */ jsx(ReviewBody, { review, release, cluster, local, noun }),
|
|
2400
2445
|
refused && /* @__PURE__ */ jsx("p", { className: "mero-cw-review__muted", children: "Create is unavailable: this node did not pass its check." }),
|
|
2401
2446
|
/* @__PURE__ */ jsxs("div", { className: "mero-cw-review__buttons", children: [
|
|
2402
2447
|
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-review__btn", disabled: creating, onClick: onBack, children: "Back" }),
|
|
2403
|
-
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-review__btn mero-cw-review__btn--primary", disabled: creating || disabled || refused, onClick: onCreate, children: creating ? "Creating\u2026" :
|
|
2448
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-review__btn mero-cw-review__btn--primary", disabled: creating || disabled || refused, onClick: onCreate, children: creating ? "Creating\u2026" : `Create ${noun}` })
|
|
2404
2449
|
] })
|
|
2405
2450
|
] });
|
|
2406
2451
|
}
|
|
@@ -2426,48 +2471,41 @@ function ConsentPopupReturn({ children }) {
|
|
|
2426
2471
|
return returned === "null" ? /* @__PURE__ */ jsx(Fragment, { children }) : null;
|
|
2427
2472
|
}
|
|
2428
2473
|
|
|
2429
|
-
// src/
|
|
2430
|
-
var INTENT_KEY = "mero-react:create-workspace-intent";
|
|
2474
|
+
// src/consent-flow/useNodeConsent.ts
|
|
2431
2475
|
var POPUP_FEATURES = "popup,width=480,height=720";
|
|
2432
2476
|
var NARROW_PX = 640;
|
|
2433
2477
|
var CLOSED_POLL_MS = 400;
|
|
2434
2478
|
var WAIT_POLL_MS = 1500;
|
|
2435
|
-
var
|
|
2436
|
-
declined: "You declined the request on your node. Nothing was
|
|
2437
|
-
closed: "The approval window was closed before you approved. Nothing was
|
|
2438
|
-
expired: "The request expired before you approved it. Nothing was
|
|
2439
|
-
noOrg: "Your node approved the request but named no workspace. Nothing was created."
|
|
2479
|
+
var CONSENT_MSG = {
|
|
2480
|
+
declined: "You declined the request on your node. Nothing was changed.",
|
|
2481
|
+
closed: "The approval window was closed before you approved. Nothing was changed.",
|
|
2482
|
+
expired: "The request expired before you approved it. Nothing was changed."
|
|
2440
2483
|
};
|
|
2441
|
-
|
|
2484
|
+
var messageOf2 = (e) => e instanceof Error ? e.message : String(e);
|
|
2485
|
+
var codeOf = (e) => typeof e?.code === "string" ? e.code : null;
|
|
2486
|
+
function readIntent(key2, valid) {
|
|
2442
2487
|
try {
|
|
2443
|
-
const v = JSON.parse(sessionStorage.getItem(
|
|
2444
|
-
return v
|
|
2488
|
+
const v = JSON.parse(sessionStorage.getItem(key2) ?? "null");
|
|
2489
|
+
return valid(v) ? v : null;
|
|
2445
2490
|
} catch {
|
|
2446
2491
|
return null;
|
|
2447
2492
|
}
|
|
2448
2493
|
}
|
|
2449
|
-
function keepIntent(intent) {
|
|
2494
|
+
function keepIntent(key2, intent) {
|
|
2450
2495
|
try {
|
|
2451
|
-
sessionStorage.setItem(
|
|
2496
|
+
sessionStorage.setItem(key2, JSON.stringify(intent));
|
|
2452
2497
|
} catch {
|
|
2453
2498
|
}
|
|
2454
2499
|
}
|
|
2455
|
-
function forgetIntent() {
|
|
2500
|
+
function forgetIntent(key2) {
|
|
2456
2501
|
try {
|
|
2457
|
-
sessionStorage.removeItem(
|
|
2502
|
+
sessionStorage.removeItem(key2);
|
|
2458
2503
|
} catch {
|
|
2459
2504
|
}
|
|
2460
2505
|
}
|
|
2461
|
-
|
|
2462
|
-
function created(result) {
|
|
2463
|
-
if (result.status === "declined") return { error: MSG.declined };
|
|
2464
|
-
const orgId = result.status === "approved" && result.kind === "createOrg" ? result.outcome?.orgId : void 0;
|
|
2465
|
-
return orgId ? { orgId } : { error: MSG.noOrg };
|
|
2466
|
-
}
|
|
2467
|
-
function useCreateWorkspace({ returnTo, onCreated }) {
|
|
2506
|
+
function useNodeConsent({ storageKey }) {
|
|
2468
2507
|
const { client } = useMero();
|
|
2469
2508
|
const consent = useConsent({ throwOnError: true });
|
|
2470
|
-
const orgs = useCreateOrg({ throwOnError: true });
|
|
2471
2509
|
const [bound, setBound] = useState(null);
|
|
2472
2510
|
const [phase, setPhase] = useState("idle");
|
|
2473
2511
|
const [error, setError] = useState(null);
|
|
@@ -2487,16 +2525,16 @@ function useCreateWorkspace({ returnTo, onCreated }) {
|
|
|
2487
2525
|
};
|
|
2488
2526
|
}, [client]);
|
|
2489
2527
|
useEffect(() => () => stop.current?.(), []);
|
|
2490
|
-
const approveInPopup = async (win,
|
|
2491
|
-
if (!client) return;
|
|
2492
|
-
const started = await consent.open(
|
|
2528
|
+
const approveInPopup = async (win, request) => {
|
|
2529
|
+
if (!client) return null;
|
|
2530
|
+
const started = await consent.open(request, {
|
|
2493
2531
|
navigate: (url) => {
|
|
2494
2532
|
if (popup.current) popup.current.url = url;
|
|
2495
2533
|
win.location.href = url;
|
|
2496
2534
|
},
|
|
2497
2535
|
confirm: () => true
|
|
2498
2536
|
});
|
|
2499
|
-
if (!started) return;
|
|
2537
|
+
if (!started) return null;
|
|
2500
2538
|
let cause = null;
|
|
2501
2539
|
const ctrl = new AbortController();
|
|
2502
2540
|
const end = (why) => {
|
|
@@ -2516,23 +2554,25 @@ function useCreateWorkspace({ returnTo, onCreated }) {
|
|
|
2516
2554
|
result = await client.consent.pageResult({ request: started.requestId });
|
|
2517
2555
|
}
|
|
2518
2556
|
if (result.status === "pending") {
|
|
2519
|
-
if (cause !== "cancelled") setError(cause === "closed" ?
|
|
2520
|
-
return;
|
|
2557
|
+
if (cause !== "cancelled") setError({ message: cause === "closed" ? CONSENT_MSG.closed : CONSENT_MSG.expired, code: null });
|
|
2558
|
+
return null;
|
|
2559
|
+
}
|
|
2560
|
+
if (result.status === "declined") {
|
|
2561
|
+
setError({ message: CONSENT_MSG.declined, code: null });
|
|
2562
|
+
return null;
|
|
2521
2563
|
}
|
|
2522
|
-
|
|
2523
|
-
if ("error" in made) setError(made.error);
|
|
2524
|
-
else onCreated({ orgId: made.orgId, name, selfName });
|
|
2564
|
+
return result;
|
|
2525
2565
|
} finally {
|
|
2526
2566
|
clearInterval(timer);
|
|
2527
2567
|
window.removeEventListener("message", onMessage);
|
|
2528
2568
|
stop.current = null;
|
|
2529
2569
|
}
|
|
2530
2570
|
};
|
|
2531
|
-
const redirect = async (
|
|
2532
|
-
keepIntent(
|
|
2571
|
+
const redirect = async (request, intent) => {
|
|
2572
|
+
keepIntent(storageKey, intent);
|
|
2533
2573
|
let went = false;
|
|
2534
2574
|
try {
|
|
2535
|
-
await consent.open(
|
|
2575
|
+
await consent.open(request, {
|
|
2536
2576
|
// The page opens once the person has seen the code and chosen to go.
|
|
2537
2577
|
confirm: async () => {
|
|
2538
2578
|
setPhase("redirect");
|
|
@@ -2543,13 +2583,13 @@ function useCreateWorkspace({ returnTo, onCreated }) {
|
|
|
2543
2583
|
}
|
|
2544
2584
|
});
|
|
2545
2585
|
} catch (e) {
|
|
2546
|
-
forgetIntent();
|
|
2586
|
+
forgetIntent(storageKey);
|
|
2547
2587
|
throw e;
|
|
2548
2588
|
}
|
|
2549
|
-
if (!went) forgetIntent();
|
|
2589
|
+
if (!went) forgetIntent(storageKey);
|
|
2550
2590
|
else await new Promise(() => void 0);
|
|
2551
2591
|
};
|
|
2552
|
-
const
|
|
2592
|
+
const start = ({ request, intent, direct, done }) => {
|
|
2553
2593
|
if (busy.current || bound === null) return;
|
|
2554
2594
|
busy.current = true;
|
|
2555
2595
|
setError(null);
|
|
@@ -2558,13 +2598,16 @@ function useCreateWorkspace({ returnTo, onCreated }) {
|
|
|
2558
2598
|
setPhase(win ? "approving" : "creating");
|
|
2559
2599
|
void (async () => {
|
|
2560
2600
|
try {
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2601
|
+
let outcome = null;
|
|
2602
|
+
if (!bound) outcome = { direct: await direct() };
|
|
2603
|
+
else if (win) {
|
|
2604
|
+
const result = await approveInPopup(win, request);
|
|
2605
|
+
if (result) outcome = { consent: result };
|
|
2606
|
+
} else await redirect(request, intent);
|
|
2607
|
+
const problem = outcome && done(outcome);
|
|
2608
|
+
if (problem) setError({ message: problem, code: null });
|
|
2566
2609
|
} catch (e) {
|
|
2567
|
-
setError(messageOf2(e));
|
|
2610
|
+
setError({ message: messageOf2(e), code: codeOf(e) });
|
|
2568
2611
|
} finally {
|
|
2569
2612
|
if (win && !win.closed) win.close();
|
|
2570
2613
|
popup.current = null;
|
|
@@ -2584,46 +2627,101 @@ function useCreateWorkspace({ returnTo, onCreated }) {
|
|
|
2584
2627
|
if (p.url) p.win.location.href = p.url;
|
|
2585
2628
|
p.win.focus();
|
|
2586
2629
|
}, []);
|
|
2587
|
-
|
|
2630
|
+
const clearError = useCallback(() => setError(null), []);
|
|
2631
|
+
return {
|
|
2632
|
+
start,
|
|
2633
|
+
cancel,
|
|
2634
|
+
reopen,
|
|
2635
|
+
proceed,
|
|
2636
|
+
clearError,
|
|
2637
|
+
phase,
|
|
2638
|
+
error: error?.message ?? null,
|
|
2639
|
+
errorCode: error?.code ?? null,
|
|
2640
|
+
code: consent.code,
|
|
2641
|
+
ready: bound !== null,
|
|
2642
|
+
bound
|
|
2643
|
+
};
|
|
2588
2644
|
}
|
|
2589
|
-
function
|
|
2645
|
+
function useConsentResume({
|
|
2646
|
+
storageKey,
|
|
2647
|
+
valid,
|
|
2648
|
+
onApproved
|
|
2649
|
+
}) {
|
|
2590
2650
|
const { client } = useMero();
|
|
2591
2651
|
const [message, setMessage] = useState(null);
|
|
2592
2652
|
const started = useRef(false);
|
|
2593
|
-
const latest = useRef(
|
|
2594
|
-
latest.current =
|
|
2653
|
+
const latest = useRef({ valid, onApproved });
|
|
2654
|
+
latest.current = { valid, onApproved };
|
|
2595
2655
|
useEffect(() => {
|
|
2596
2656
|
if (!client || started.current || !consentReturn(window.location.href)) return;
|
|
2597
|
-
const intent = readIntent();
|
|
2657
|
+
const intent = readIntent(storageKey, latest.current.valid);
|
|
2598
2658
|
if (!intent) return;
|
|
2599
2659
|
started.current = true;
|
|
2600
2660
|
void (async () => {
|
|
2601
2661
|
try {
|
|
2602
2662
|
const result = await client.resumeConsent();
|
|
2603
2663
|
if (!result) return;
|
|
2604
|
-
|
|
2605
|
-
if ("
|
|
2606
|
-
else latest.current(
|
|
2664
|
+
if (result.status === "declined") setMessage(CONSENT_MSG.declined);
|
|
2665
|
+
else if (result.status === "pending") setMessage(CONSENT_MSG.expired);
|
|
2666
|
+
else setMessage(latest.current.onApproved(intent, result) ?? null);
|
|
2607
2667
|
} catch (e) {
|
|
2608
2668
|
setMessage(messageOf2(e));
|
|
2609
2669
|
} finally {
|
|
2610
|
-
forgetIntent();
|
|
2670
|
+
forgetIntent(storageKey);
|
|
2611
2671
|
}
|
|
2612
2672
|
})();
|
|
2613
|
-
}, [client]);
|
|
2673
|
+
}, [client, storageKey]);
|
|
2614
2674
|
return { message };
|
|
2615
2675
|
}
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
};
|
|
2625
|
-
|
|
2626
|
-
|
|
2676
|
+
|
|
2677
|
+
// src/create-workspace/useCreateWorkspace.ts
|
|
2678
|
+
var INTENT_KEY = "mero-react:create-workspace-intent";
|
|
2679
|
+
var NO_ORG = "Your node approved the request but named no workspace. Nothing was created.";
|
|
2680
|
+
var isIntent = (v) => !!v && typeof v.name === "string" && typeof v.selfName === "string";
|
|
2681
|
+
var orgIdOf = (result) => result.status === "approved" && result.kind === "createOrg" ? result.outcome?.orgId : void 0;
|
|
2682
|
+
function useCreateWorkspace({ returnTo, onCreated }) {
|
|
2683
|
+
const orgs = useCreateOrg({ throwOnError: true });
|
|
2684
|
+
const { start, ...flow } = useNodeConsent({ storageKey: INTENT_KEY });
|
|
2685
|
+
const create = (name, selfName) => start({
|
|
2686
|
+
request: createOrgConsent(name, returnTo),
|
|
2687
|
+
intent: { name, selfName },
|
|
2688
|
+
direct: () => orgs.create(name),
|
|
2689
|
+
done: (outcome) => {
|
|
2690
|
+
const orgId = "direct" in outcome ? outcome.direct : orgIdOf(outcome.consent);
|
|
2691
|
+
if (!orgId) return NO_ORG;
|
|
2692
|
+
onCreated({ orgId, name, selfName });
|
|
2693
|
+
return void 0;
|
|
2694
|
+
}
|
|
2695
|
+
});
|
|
2696
|
+
return { create, ...flow };
|
|
2697
|
+
}
|
|
2698
|
+
function useCreateWorkspaceResume({ onCreated }) {
|
|
2699
|
+
return useConsentResume({
|
|
2700
|
+
storageKey: INTENT_KEY,
|
|
2701
|
+
valid: isIntent,
|
|
2702
|
+
onApproved: (intent, result) => {
|
|
2703
|
+
const orgId = orgIdOf(result);
|
|
2704
|
+
if (!orgId) return NO_ORG;
|
|
2705
|
+
onCreated({ orgId, name: intent.name, selfName: intent.selfName });
|
|
2706
|
+
return void 0;
|
|
2707
|
+
}
|
|
2708
|
+
});
|
|
2709
|
+
}
|
|
2710
|
+
var NOUN = "workspace";
|
|
2711
|
+
function wording(labels) {
|
|
2712
|
+
const noun = labels?.noun ?? NOUN;
|
|
2713
|
+
return {
|
|
2714
|
+
noun,
|
|
2715
|
+
title: `Create ${noun}`,
|
|
2716
|
+
subtitle: `Name your ${noun}, and choose how others in it will see you.`,
|
|
2717
|
+
nameLabel: `${noun.charAt(0).toUpperCase()}${noun.slice(1)} name`,
|
|
2718
|
+
namePlaceholder: "",
|
|
2719
|
+
selfLabel: "Your name",
|
|
2720
|
+
selfPlaceholder: "",
|
|
2721
|
+
next: "Continue",
|
|
2722
|
+
...labels
|
|
2723
|
+
};
|
|
2724
|
+
}
|
|
2627
2725
|
function ResumeNotice({ onCreated }) {
|
|
2628
2726
|
const { message } = useCreateWorkspaceResume({ onCreated });
|
|
2629
2727
|
const [dismissed, setDismissed] = useState(null);
|
|
@@ -2638,14 +2736,11 @@ function ResumeNotice({ onCreated }) {
|
|
|
2638
2736
|
document.body
|
|
2639
2737
|
);
|
|
2640
2738
|
}
|
|
2641
|
-
var CloseIcon = () => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "16", height: "16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "m6 6 12 12M18 6 6 18", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) });
|
|
2642
2739
|
function CreateWorkspaceDialog({ client, passkey, ...props }) {
|
|
2643
|
-
|
|
2644
|
-
const inner = /* @__PURE__ */ jsx(Dialog, { ...props });
|
|
2645
|
-
return client ? /* @__PURE__ */ jsx(MeroProvider, { client, sessionStore, passkey, children: inner }) : inner;
|
|
2740
|
+
return /* @__PURE__ */ jsx(WithClient, { client, passkey, children: /* @__PURE__ */ jsx(Dialog, { ...props }) });
|
|
2646
2741
|
}
|
|
2647
|
-
function Dialog({ open, onClose, release, onCreated, returnTo, labels, defaultSelfName = "", cluster }) {
|
|
2648
|
-
const text =
|
|
2742
|
+
function Dialog({ open, onClose, release, onCreated, returnTo, labels, defaultSelfName = "", cluster, fields, fieldsValid = true }) {
|
|
2743
|
+
const text = wording(labels);
|
|
2649
2744
|
const { client, cluster: ambientCluster, nodeUrl } = useMero();
|
|
2650
2745
|
const flow = useCreateWorkspace({ returnTo: returnTo ?? `${typeof window === "undefined" ? "" : window.location.origin}/`, onCreated });
|
|
2651
2746
|
const [step, setStep] = useState("names");
|
|
@@ -2653,7 +2748,6 @@ function Dialog({ open, onClose, release, onCreated, returnTo, labels, defaultSe
|
|
|
2653
2748
|
const [selfName, setSelfName] = useState(defaultSelfName);
|
|
2654
2749
|
const ids = [useId(), useId()];
|
|
2655
2750
|
const first = useRef(null);
|
|
2656
|
-
const mounted = useMounted();
|
|
2657
2751
|
useEffect(() => {
|
|
2658
2752
|
if (open && release && step === "names") first.current?.focus();
|
|
2659
2753
|
}, [open, release, step]);
|
|
@@ -2662,29 +2756,12 @@ function Dialog({ open, onClose, release, onCreated, returnTo, labels, defaultSe
|
|
|
2662
2756
|
const trimmed = { name: name.trim(), self: selfName.trim() };
|
|
2663
2757
|
const redirecting = flow.phase === "redirect";
|
|
2664
2758
|
const approving = flow.phase === "approving" || redirecting;
|
|
2665
|
-
const body = !release ? /* @__PURE__ */ jsx("p", { className: "mero-cw-sub", role: "status", children: "Checking the newest release\u2026" }) : approving ? /* @__PURE__ */
|
|
2666
|
-
/* @__PURE__ */ jsx("h2", { className: "mero-cw-title", children: "Approve with your passkey" }),
|
|
2667
|
-
/* @__PURE__ */ jsx("p", { className: "mero-cw-sub", children: redirecting ? "Your node will open its own page to ask for your passkey. Check that it shows this code." : "A window from your node opened. Check it shows this code, then approve there." }),
|
|
2668
|
-
/* @__PURE__ */ jsx("div", { className: "mero-cw-code", "aria-live": "polite", children: flow.code ?? "..." }),
|
|
2669
|
-
redirecting ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2670
|
-
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-btn mero-cw-btn--primary mero-cw-btn--full", onClick: flow.proceed, children: "Continue to your node" }),
|
|
2671
|
-
/* @__PURE__ */ jsx("div", { className: "mero-cw-row", children: /* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-btn", onClick: flow.cancel, children: "Cancel" }) })
|
|
2672
|
-
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2673
|
-
/* @__PURE__ */ jsxs("div", { className: "mero-cw-wait", role: "status", children: [
|
|
2674
|
-
/* @__PURE__ */ jsx("span", { className: "mero-cw-dot", "aria-hidden": "true" }),
|
|
2675
|
-
"Waiting for your approval..."
|
|
2676
|
-
] }),
|
|
2677
|
-
/* @__PURE__ */ jsxs("div", { className: "mero-cw-row", children: [
|
|
2678
|
-
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-btn", onClick: flow.cancel, children: "Cancel" }),
|
|
2679
|
-
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-link", onClick: flow.reopen, children: "Open the window again" })
|
|
2680
|
-
] })
|
|
2681
|
-
] })
|
|
2682
|
-
] }) : step === "names" ? /* @__PURE__ */ jsxs(
|
|
2759
|
+
const body = !release ? /* @__PURE__ */ jsx("p", { className: "mero-cw-sub", role: "status", children: "Checking the newest release\u2026" }) : approving ? /* @__PURE__ */ jsx(ApprovalCard, { redirecting, code: flow.code, onCancel: flow.cancel, onProceed: flow.proceed, onReopen: flow.reopen }) : step === "names" ? /* @__PURE__ */ jsxs(
|
|
2683
2760
|
"form",
|
|
2684
2761
|
{
|
|
2685
2762
|
onSubmit: (e) => {
|
|
2686
2763
|
e.preventDefault();
|
|
2687
|
-
if (trimmed.name && trimmed.self) setStep("review");
|
|
2764
|
+
if (trimmed.name && trimmed.self && fieldsValid) setStep("review");
|
|
2688
2765
|
},
|
|
2689
2766
|
children: [
|
|
2690
2767
|
/* @__PURE__ */ jsx("h2", { className: "mero-cw-title", children: text.title }),
|
|
@@ -2697,7 +2774,8 @@ function Dialog({ open, onClose, release, onCreated, returnTo, labels, defaultSe
|
|
|
2697
2774
|
/* @__PURE__ */ jsx("label", { htmlFor: ids[1], children: text.selfLabel }),
|
|
2698
2775
|
/* @__PURE__ */ jsx("input", { id: ids[1], value: selfName, placeholder: text.selfPlaceholder, onChange: (e) => setSelfName(e.target.value) })
|
|
2699
2776
|
] }),
|
|
2700
|
-
|
|
2777
|
+
fields,
|
|
2778
|
+
/* @__PURE__ */ jsx("button", { type: "submit", className: "mero-cw-btn mero-cw-btn--primary mero-cw-btn--full", disabled: !trimmed.name || !trimmed.self || !fieldsValid, children: text.next })
|
|
2701
2779
|
]
|
|
2702
2780
|
}
|
|
2703
2781
|
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -2708,6 +2786,7 @@ function Dialog({ open, onClose, release, onCreated, returnTo, labels, defaultSe
|
|
|
2708
2786
|
client,
|
|
2709
2787
|
cluster: where,
|
|
2710
2788
|
local: !!node && clusterName(node) === "merod local",
|
|
2789
|
+
noun: text.noun,
|
|
2711
2790
|
release,
|
|
2712
2791
|
creating: flow.phase === "creating",
|
|
2713
2792
|
disabled: !flow.ready,
|
|
@@ -2718,16 +2797,292 @@ function Dialog({ open, onClose, release, onCreated, returnTo, labels, defaultSe
|
|
|
2718
2797
|
] });
|
|
2719
2798
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2720
2799
|
/* @__PURE__ */ jsx(ResumeNotice, { onCreated }),
|
|
2721
|
-
open &&
|
|
2722
|
-
/* @__PURE__ */ jsx("div", { className: "mero-cw mero-cw-overlay", onKeyDown: (e) => e.key === "Escape" && !approving && onClose(), children: /* @__PURE__ */ jsxs("div", { className: "mero-cw-card", role: "dialog", "aria-modal": "true", "aria-label": text.title, children: [
|
|
2723
|
-
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-x", "aria-label": "Close", onClick: () => approving ? flow.cancel() : onClose(), children: /* @__PURE__ */ jsx(CloseIcon, {}) }),
|
|
2724
|
-
/* @__PURE__ */ jsx("div", { className: "mero-cw-body", children: body })
|
|
2725
|
-
] }) }),
|
|
2726
|
-
document.body
|
|
2727
|
-
)
|
|
2800
|
+
open && /* @__PURE__ */ jsx(DialogShell, { label: text.title, locked: approving, onClose: () => approving ? flow.cancel() : onClose(), children: body })
|
|
2728
2801
|
] });
|
|
2729
2802
|
}
|
|
2803
|
+
var CAPABILITY_LABELS = [
|
|
2804
|
+
{ name: "CREATE_APP", label: "Add apps" },
|
|
2805
|
+
{ name: "INVITE_MEMBERS", label: "Invite people" },
|
|
2806
|
+
{ name: "JOIN_OPEN_TEAMS", label: "Join open teams" },
|
|
2807
|
+
{ name: "MANAGE_MEMBERS", label: "Manage team members" },
|
|
2808
|
+
{ name: "MANAGE_APPLICATION", label: "Upgrade apps" },
|
|
2809
|
+
{ name: "CREATE_TEAM", label: "Create teams" },
|
|
2810
|
+
{ name: "CREATE_CHILD_TEAM", label: "Create child teams" },
|
|
2811
|
+
{ name: "DELETE_TEAM", label: "Delete teams" },
|
|
2812
|
+
{ name: "MANAGE_VISIBILITY", label: "Change who can join a team" },
|
|
2813
|
+
{ name: "MANAGE_METADATA", label: "Rename the workspace and its teams" },
|
|
2814
|
+
{ name: "APPROVE_RELEASES", label: "Approve app releases" }
|
|
2815
|
+
];
|
|
2816
|
+
var ALL_CAPABILITIES = Object.values(ORG_CAPABILITIES).reduce((mask, bit) => mask | bit, 0);
|
|
2817
|
+
function describeCapabilities(mask) {
|
|
2818
|
+
return CAPABILITY_LABELS.filter(({ name }) => (mask & ORG_CAPABILITIES[name]) !== 0).map(({ label }) => label);
|
|
2819
|
+
}
|
|
2820
|
+
function heldCapabilities(org, account) {
|
|
2821
|
+
const role = account ? org.members[account] : void 0;
|
|
2822
|
+
if (role === "owner" || role === "admin") return ALL_CAPABILITIES;
|
|
2823
|
+
return account ? org.capabilities[account] ?? org.defaultCapabilities : 0;
|
|
2824
|
+
}
|
|
2825
|
+
var INVITE_KEY = "mero-react:invite-intent";
|
|
2826
|
+
var ACCEPT_KEY = "mero-react:accept-invite-intent";
|
|
2827
|
+
var NO_TOKEN = "Your node approved the request but made no invite. Nothing was changed.";
|
|
2828
|
+
var NO_ORG2 = "Your node approved the request but named no workspace. Nothing was changed.";
|
|
2829
|
+
var isInviteIntent = (v) => !!v && typeof v.role === "string";
|
|
2830
|
+
var isObject = (v) => !!v && typeof v === "object";
|
|
2831
|
+
var tokenOf = (r) => r.status === "approved" && r.kind === "createInvite" ? r.outcome?.token : void 0;
|
|
2832
|
+
var orgOf = (r) => r.status === "approved" && r.kind === "acceptInvite" ? r.outcome?.org : void 0;
|
|
2833
|
+
function useInviteCreate({ returnTo, linkBase, onCreated }) {
|
|
2834
|
+
const { client, passkey } = useMero();
|
|
2835
|
+
const { start, ...flow } = useNodeConsent({ storageKey: INVITE_KEY });
|
|
2836
|
+
const finish = (token, capabilities) => {
|
|
2837
|
+
if (!token) return NO_TOKEN;
|
|
2838
|
+
onCreated({ token, link: inviteLink(token, linkBase), ...capabilities === void 0 ? {} : { capabilities } });
|
|
2839
|
+
return void 0;
|
|
2840
|
+
};
|
|
2841
|
+
const create = ({ org, role, teams, capabilities }) => start({
|
|
2842
|
+
request: createInviteConsent({ org, role, ...teams?.length ? { teams } : {}, ...capabilities === void 0 ? {} : { capabilities } }, returnTo),
|
|
2843
|
+
intent: { role, ...capabilities === void 0 ? {} : { capabilities } },
|
|
2844
|
+
direct: async () => {
|
|
2845
|
+
if (!client) throw new Error("Not connected to a node.");
|
|
2846
|
+
const answer = await client.orgs.inviteCreate(
|
|
2847
|
+
{ org, role, ...teams?.length ? { teams } : {}, ...capabilities === void 0 ? {} : { capabilities } },
|
|
2848
|
+
confirmWith(passkey)
|
|
2849
|
+
);
|
|
2850
|
+
return answer.token;
|
|
2851
|
+
},
|
|
2852
|
+
done: (outcome) => finish("direct" in outcome ? outcome.direct : tokenOf(outcome.consent), capabilities)
|
|
2853
|
+
});
|
|
2854
|
+
return { create, ...flow };
|
|
2855
|
+
}
|
|
2856
|
+
function useInviteResume({ linkBase, onCreated }) {
|
|
2857
|
+
return useConsentResume({
|
|
2858
|
+
storageKey: INVITE_KEY,
|
|
2859
|
+
valid: isInviteIntent,
|
|
2860
|
+
onApproved: (intent, result) => {
|
|
2861
|
+
const token = tokenOf(result);
|
|
2862
|
+
if (!token) return NO_TOKEN;
|
|
2863
|
+
onCreated({ token, link: inviteLink(token, linkBase), ...intent.capabilities === void 0 ? {} : { capabilities: intent.capabilities } });
|
|
2864
|
+
return void 0;
|
|
2865
|
+
}
|
|
2866
|
+
});
|
|
2867
|
+
}
|
|
2868
|
+
function useInviteAccept({ returnTo, onJoined }) {
|
|
2869
|
+
const ctx = useMero();
|
|
2870
|
+
const { start, ...flow } = useNodeConsent({ storageKey: ACCEPT_KEY });
|
|
2871
|
+
const accept = (token) => start({
|
|
2872
|
+
request: acceptInviteConsent(token, returnTo),
|
|
2873
|
+
intent: {},
|
|
2874
|
+
direct: async () => {
|
|
2875
|
+
if (!ctx.client) throw new Error("Not connected to a node.");
|
|
2876
|
+
return (await ctx.client.orgs.inviteRedeem({ token })).org;
|
|
2877
|
+
},
|
|
2878
|
+
done: (outcome) => {
|
|
2879
|
+
const org = "direct" in outcome ? outcome.direct : orgOf(outcome.consent);
|
|
2880
|
+
if (!org) return NO_ORG2;
|
|
2881
|
+
onJoined({ org });
|
|
2882
|
+
return void 0;
|
|
2883
|
+
}
|
|
2884
|
+
});
|
|
2885
|
+
return { accept, ...flow };
|
|
2886
|
+
}
|
|
2887
|
+
function useAcceptResume({ onJoined }) {
|
|
2888
|
+
return useConsentResume({
|
|
2889
|
+
storageKey: ACCEPT_KEY,
|
|
2890
|
+
valid: isObject,
|
|
2891
|
+
onApproved: (_intent, result) => {
|
|
2892
|
+
const org = orgOf(result);
|
|
2893
|
+
if (!org) return NO_ORG2;
|
|
2894
|
+
onJoined({ org });
|
|
2895
|
+
return void 0;
|
|
2896
|
+
}
|
|
2897
|
+
});
|
|
2898
|
+
}
|
|
2899
|
+
var REFUSALS = {
|
|
2900
|
+
FEATURE_NOT_ACTIVE: { text: "This cluster doesn't support custom permissions yet.", fallback: true },
|
|
2901
|
+
CANNOT_GRANT_UNHELD: { text: "You can't give a permission you don't have.", fallback: false },
|
|
2902
|
+
UNKNOWN_CAPABILITIES: { text: "This cluster does not know one of the permissions you chose.", fallback: true }
|
|
2903
|
+
};
|
|
2904
|
+
var DEFAULT_LABELS = {
|
|
2905
|
+
title: "Invite people",
|
|
2906
|
+
subtitle: "Choose what the people you invite can do.",
|
|
2907
|
+
next: "Create invite"
|
|
2908
|
+
};
|
|
2909
|
+
function useOrgFacts(org) {
|
|
2910
|
+
const { client, accountId } = useMero();
|
|
2911
|
+
const [facts, setFacts] = useState(null);
|
|
2912
|
+
useEffect(() => {
|
|
2913
|
+
if (!client) return;
|
|
2914
|
+
let live = true;
|
|
2915
|
+
setFacts(null);
|
|
2916
|
+
client.orgs.get({ org }).then(
|
|
2917
|
+
(info) => live && setFacts({ defaults: info.defaultCapabilities, held: heldCapabilities(info, accountId) }),
|
|
2918
|
+
() => live && setFacts("unreadable")
|
|
2919
|
+
);
|
|
2920
|
+
return () => {
|
|
2921
|
+
live = false;
|
|
2922
|
+
};
|
|
2923
|
+
}, [client, org, accountId]);
|
|
2924
|
+
return facts;
|
|
2925
|
+
}
|
|
2926
|
+
var originRoot = () => `${typeof window === "undefined" ? "" : window.location.origin}/`;
|
|
2927
|
+
function InviteDialog({ client, passkey, ...props }) {
|
|
2928
|
+
return /* @__PURE__ */ jsx(WithClient, { client, passkey, children: /* @__PURE__ */ jsx(Dialog2, { ...props }) });
|
|
2929
|
+
}
|
|
2930
|
+
function Dialog2({ open, onClose, org, teams, role = "member", appName, labels, onInvited, linkBase, returnTo }) {
|
|
2931
|
+
const text = { ...DEFAULT_LABELS, ...labels };
|
|
2932
|
+
const facts = useOrgFacts(org);
|
|
2933
|
+
const [mode, setMode] = useState("default");
|
|
2934
|
+
const [picked, setPicked] = useState(null);
|
|
2935
|
+
const [shared, setShared] = useState(null);
|
|
2936
|
+
const [copied, copy] = useCopy();
|
|
2937
|
+
const ids = [useId(), useId()];
|
|
2938
|
+
const onCreated = (invite) => {
|
|
2939
|
+
setShared(invite);
|
|
2940
|
+
onInvited?.(invite);
|
|
2941
|
+
};
|
|
2942
|
+
const flow = useInviteCreate({ returnTo: returnTo ?? originRoot(), linkBase, onCreated });
|
|
2943
|
+
const resume = useInviteResume({ linkBase, onCreated });
|
|
2944
|
+
const [dismissed, setDismissed] = useState(null);
|
|
2945
|
+
const readable = facts !== null && facts !== "unreadable";
|
|
2946
|
+
const bits = picked ?? (readable ? facts.defaults & facts.held : 0);
|
|
2947
|
+
const redirecting = flow.phase === "redirect";
|
|
2948
|
+
const approving = flow.phase === "approving" || redirecting;
|
|
2949
|
+
const notice = resume.message && dismissed !== resume.message ? resume.message : null;
|
|
2950
|
+
const refusal = flow.errorCode ? REFUSALS[flow.errorCode] : void 0;
|
|
2951
|
+
const close = () => {
|
|
2952
|
+
setShared(null);
|
|
2953
|
+
onClose();
|
|
2954
|
+
};
|
|
2955
|
+
if (!open && !shared && !notice) return null;
|
|
2956
|
+
let body;
|
|
2957
|
+
if (approving) {
|
|
2958
|
+
body = /* @__PURE__ */ jsx(ApprovalCard, { redirecting, code: flow.code, onCancel: flow.cancel, onProceed: flow.proceed, onReopen: flow.reopen });
|
|
2959
|
+
} else if (shared) {
|
|
2960
|
+
const perms = shared.capabilities === void 0 ? null : describeCapabilities(shared.capabilities);
|
|
2961
|
+
body = /* @__PURE__ */ jsxs("div", { children: [
|
|
2962
|
+
/* @__PURE__ */ jsx("h2", { className: "mero-cw-title", children: "Invite link ready" }),
|
|
2963
|
+
/* @__PURE__ */ jsxs("p", { className: "mero-cw-sub", children: [
|
|
2964
|
+
"Anyone with this link can join as a ",
|
|
2965
|
+
role,
|
|
2966
|
+
appName ? ` in ${appName}` : "",
|
|
2967
|
+
".",
|
|
2968
|
+
" ",
|
|
2969
|
+
perms ? perms.length ? `They can: ${perms.join(", ")}.` : "They get basic access only." : "They get the workspace's member defaults."
|
|
2970
|
+
] }),
|
|
2971
|
+
/* @__PURE__ */ jsxs("div", { className: "mero-cw-field", children: [
|
|
2972
|
+
/* @__PURE__ */ jsx("label", { htmlFor: ids[0], children: "Invite link" }),
|
|
2973
|
+
/* @__PURE__ */ jsx("input", { id: ids[0], readOnly: true, value: shared.link, onFocus: (e) => e.currentTarget.select() })
|
|
2974
|
+
] }),
|
|
2975
|
+
/* @__PURE__ */ jsxs("div", { className: "mero-cw-row", children: [
|
|
2976
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-btn mero-cw-btn--primary", onClick: () => copy(shared.link), children: "Copy link" }),
|
|
2977
|
+
/* @__PURE__ */ jsx("span", { className: "mero-cw-wait", role: "status", children: copied === "done" ? "Copied" : copied === "failed" ? "Could not copy" : "" }),
|
|
2978
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-btn", onClick: close, children: "Done" })
|
|
2979
|
+
] })
|
|
2980
|
+
] });
|
|
2981
|
+
} else {
|
|
2982
|
+
const defaultWords = !readable ? "the workspace's member defaults" : describeCapabilities(facts.defaults).join(", ") || "basic access only";
|
|
2983
|
+
body = /* @__PURE__ */ jsxs("div", { children: [
|
|
2984
|
+
/* @__PURE__ */ jsx("h2", { className: "mero-cw-title", children: text.title }),
|
|
2985
|
+
/* @__PURE__ */ jsx("p", { className: "mero-cw-sub", children: text.subtitle }),
|
|
2986
|
+
notice && /* @__PURE__ */ jsxs("p", { className: "mero-cw-error", role: "alert", children: [
|
|
2987
|
+
notice,
|
|
2988
|
+
" ",
|
|
2989
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-link", onClick: () => setDismissed(notice), children: "Dismiss" })
|
|
2990
|
+
] }),
|
|
2991
|
+
flow.error && /* @__PURE__ */ jsxs("p", { className: "mero-cw-error", role: "alert", children: [
|
|
2992
|
+
refusal ? refusal.text : flow.error,
|
|
2993
|
+
refusal?.fallback && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2994
|
+
" ",
|
|
2995
|
+
/* @__PURE__ */ jsx(
|
|
2996
|
+
"button",
|
|
2997
|
+
{
|
|
2998
|
+
type: "button",
|
|
2999
|
+
className: "mero-cw-link",
|
|
3000
|
+
onClick: () => {
|
|
3001
|
+
setMode("default");
|
|
3002
|
+
flow.clearError();
|
|
3003
|
+
},
|
|
3004
|
+
children: "Send a default invite"
|
|
3005
|
+
}
|
|
3006
|
+
)
|
|
3007
|
+
] })
|
|
3008
|
+
] }),
|
|
3009
|
+
facts === "unreadable" && /* @__PURE__ */ jsx("p", { className: "mero-cw-sub", children: "We could not read this workspace's permissions, so only a default invite is available." }),
|
|
3010
|
+
/* @__PURE__ */ jsxs("fieldset", { className: "mero-cw-choices", children: [
|
|
3011
|
+
/* @__PURE__ */ jsx("legend", { className: "mero-cw-visually-hidden", children: "Permissions" }),
|
|
3012
|
+
/* @__PURE__ */ jsxs("label", { className: "mero-cw-choice", children: [
|
|
3013
|
+
/* @__PURE__ */ jsx("input", { type: "radio", name: ids[1], checked: mode === "default", onChange: () => setMode("default") }),
|
|
3014
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
3015
|
+
/* @__PURE__ */ jsx("b", { children: "Default" }),
|
|
3016
|
+
/* @__PURE__ */ jsx("span", { className: "mero-cw-sub", children: `They get the workspace's member defaults: ${defaultWords}.` })
|
|
3017
|
+
] })
|
|
3018
|
+
] }),
|
|
3019
|
+
/* @__PURE__ */ jsxs("label", { className: "mero-cw-choice", children: [
|
|
3020
|
+
/* @__PURE__ */ jsx("input", { type: "radio", name: ids[1], checked: mode === "custom", disabled: !readable, onChange: () => setMode("custom") }),
|
|
3021
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
3022
|
+
/* @__PURE__ */ jsx("b", { children: "Custom" }),
|
|
3023
|
+
/* @__PURE__ */ jsx("span", { className: "mero-cw-sub", children: "Choose exactly what they can do." })
|
|
3024
|
+
] })
|
|
3025
|
+
] })
|
|
3026
|
+
] }),
|
|
3027
|
+
mode === "custom" && readable && /* @__PURE__ */ jsx("div", { className: "mero-cw-caps", children: CAPABILITY_LABELS.map(({ name, label }) => {
|
|
3028
|
+
const bit = ORG_CAPABILITIES[name];
|
|
3029
|
+
const mine = (facts.held & bit) !== 0;
|
|
3030
|
+
return /* @__PURE__ */ jsxs("div", { className: "mero-cw-cap", "data-disabled": mine ? void 0 : "", children: [
|
|
3031
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
3032
|
+
/* @__PURE__ */ jsx("input", { type: "checkbox", checked: mine && (bits & bit) !== 0, disabled: !mine, "aria-describedby": mine ? void 0 : `${ids[1]}-${name}`, onChange: (e) => setPicked(e.target.checked ? bits | bit : bits & ~bit) }),
|
|
3033
|
+
label
|
|
3034
|
+
] }),
|
|
3035
|
+
!mine && /* @__PURE__ */ jsx("span", { id: `${ids[1]}-${name}`, className: "mero-cw-hint", children: "You don't have this" })
|
|
3036
|
+
] }, name);
|
|
3037
|
+
}) }),
|
|
3038
|
+
/* @__PURE__ */ jsx(
|
|
3039
|
+
"button",
|
|
3040
|
+
{
|
|
3041
|
+
type: "button",
|
|
3042
|
+
className: "mero-cw-btn mero-cw-btn--primary mero-cw-btn--full",
|
|
3043
|
+
disabled: !flow.ready || flow.phase !== "idle" || mode === "custom" && !readable,
|
|
3044
|
+
onClick: () => flow.create({ org, role, teams, ...mode === "custom" ? { capabilities: bits } : {} }),
|
|
3045
|
+
children: flow.phase === "creating" ? "Creating\u2026" : text.next
|
|
3046
|
+
}
|
|
3047
|
+
)
|
|
3048
|
+
] });
|
|
3049
|
+
}
|
|
3050
|
+
return /* @__PURE__ */ jsx(DialogShell, { label: text.title, locked: approving, onClose: () => approving ? flow.cancel() : close(), children: body });
|
|
3051
|
+
}
|
|
3052
|
+
function AcceptInviteDialog({ client, passkey, ...props }) {
|
|
3053
|
+
return /* @__PURE__ */ jsx(WithClient, { client, passkey, children: /* @__PURE__ */ jsx(Dialog3, { ...props }) });
|
|
3054
|
+
}
|
|
3055
|
+
function Dialog3({ open, onClose, token, appName, onJoined, returnTo }) {
|
|
3056
|
+
const flow = useInviteAccept({ returnTo: returnTo ?? `${typeof window === "undefined" ? "" : window.location.origin}/`, onJoined });
|
|
3057
|
+
const resume = useAcceptResume({ onJoined });
|
|
3058
|
+
const [dismissed, setDismissed] = useState(null);
|
|
3059
|
+
const notice = resume.message && dismissed !== resume.message ? resume.message : null;
|
|
3060
|
+
const redirecting = flow.phase === "redirect";
|
|
3061
|
+
const approving = flow.phase === "approving" || redirecting;
|
|
3062
|
+
if (!open && !notice) return null;
|
|
3063
|
+
return /* @__PURE__ */ jsx(DialogShell, { label: "Join workspace", locked: approving, onClose: () => approving ? flow.cancel() : onClose(), children: approving ? /* @__PURE__ */ jsx(ApprovalCard, { redirecting, code: flow.code, onCancel: flow.cancel, onProceed: flow.proceed, onReopen: flow.reopen }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
3064
|
+
/* @__PURE__ */ jsx("h2", { className: "mero-cw-title", children: "Join workspace" }),
|
|
3065
|
+
/* @__PURE__ */ jsx("p", { className: "mero-cw-sub", children: `You were invited to a workspace${appName ? ` in ${appName}` : ""}. Join it with your account.` }),
|
|
3066
|
+
[notice, flow.error].filter(Boolean).map((message) => /* @__PURE__ */ jsxs("p", { className: "mero-cw-error", role: "alert", children: [
|
|
3067
|
+
message,
|
|
3068
|
+
message === notice && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3069
|
+
" ",
|
|
3070
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "mero-cw-link", onClick: () => setDismissed(message), children: "Dismiss" })
|
|
3071
|
+
] })
|
|
3072
|
+
] }, message)),
|
|
3073
|
+
/* @__PURE__ */ jsx(
|
|
3074
|
+
"button",
|
|
3075
|
+
{
|
|
3076
|
+
type: "button",
|
|
3077
|
+
className: "mero-cw-btn mero-cw-btn--primary mero-cw-btn--full",
|
|
3078
|
+
disabled: !flow.ready || flow.phase !== "idle",
|
|
3079
|
+
onClick: () => flow.accept(token),
|
|
3080
|
+
children: flow.phase === "creating" ? "Joining\u2026" : "Join"
|
|
3081
|
+
}
|
|
3082
|
+
)
|
|
3083
|
+
] }) });
|
|
3084
|
+
}
|
|
2730
3085
|
|
|
2731
|
-
export { CONSENT_RETURN_MESSAGE, CalimeroLogo, ConnectButton, ConsentPopupReturn, CreateWorkspaceDialog, LoginModal, MERO_CSS_VARS, MeroProvider, NoAppError, NotConnectedError, SessionReportingClient, WorkspaceReview, clearAllStorage, clearAppId, clearCluster, clearNodeUrl, clusterName, cssVar, defaultMeroTheme, describeError, followEvents, getAppId, getCluster, getNodeUrl, inviteLink, isLoginRequired, jsonCodec, localStorageSessionStore, memorySessionStore, readInviteToken, reportSessions, resolveMeroTheme, resolvePolicy, setAppId, setCluster, setNodeUrl, shortAccount, themeToCssVars, useAccount, useApiKeys, useApp, useAppAbi, useApps, useBlobInfo, useBlobUrl, useBlobs, useConsent, useCreateApp, useCreateInvite, useCreateOrg, useCreateTeam, useCreateWorkspace, useCreateWorkspaceResume, useDeleteApp, useDeleteBlob, useDeleteOrg, useDeleteTeam, useEphemeral, useExecute, useInviteRedemption, useMero, useOrg, usePackages, usePasskeys, useRedeemInvite, useRemoveMember, useRemoveTeamMember, useSetAppMetadata, useSetCapabilities, useSetMember, useSetMemberMetadata, useSetOrgMetadata, useSetTeamMember, useSubscription, useTeam, useUpdateTeam, useUpgradeApp, useUploadBlob, useView };
|
|
3086
|
+
export { AcceptInviteDialog, CONSENT_RETURN_MESSAGE, CalimeroLogo, ConnectButton, ConsentPopupReturn, CreateWorkspaceDialog, InviteDialog, LoginModal, MERO_CSS_VARS, MeroProvider, NoAppError, NotConnectedError, SessionReportingClient, WorkspaceReview, clearAllStorage, clearAppId, clearCluster, clearNodeUrl, clusterName, cssVar, defaultMeroTheme, describeCapabilities, describeError, followEvents, getAppId, getCluster, getNodeUrl, inviteLink, isLoginRequired, jsonCodec, localStorageSessionStore, memorySessionStore, readInviteToken, reportSessions, resolveMeroTheme, resolvePolicy, setAppId, setCluster, setNodeUrl, shortAccount, themeToCssVars, useAccount, useApiKeys, useApp, useAppAbi, useApps, useBlobInfo, useBlobUrl, useBlobs, useConsent, useCreateApp, useCreateInvite, useCreateOrg, useCreateTeam, useCreateWorkspace, useCreateWorkspaceResume, useDeleteApp, useDeleteBlob, useDeleteOrg, useDeleteTeam, useEphemeral, useExecute, useInviteRedemption, useMero, useOrg, usePackages, usePasskeys, useRedeemInvite, useRemoveMember, useRemoveTeamMember, useSetAppMetadata, useSetCapabilities, useSetMember, useSetMemberMetadata, useSetOrgMetadata, useSetTeamMember, useSubscription, useTeam, useUpdateTeam, useUpgradeApp, useUploadBlob, useView };
|
|
2732
3087
|
//# sourceMappingURL=index.js.map
|
|
2733
3088
|
//# sourceMappingURL=index.js.map
|