@aglyn/tenant-feature-instance 1.12.0 → 1.14.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/tenant-feature-instance",
3
- "version": "1.12.0",
3
+ "version": "1.14.0",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,12 +25,12 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/aglyn": "1.12.0",
29
- "@aglyn/shared-data-enums": "1.12.0",
30
- "@aglyn/shared-ui-jsx": "1.12.0",
31
- "@aglyn/shared-util-email": "1.12.0",
32
- "@aglyn/shared-util-http": "1.12.0",
33
- "@aglyn/shared-util-timestamp": "1.12.0",
28
+ "@aglyn/aglyn": "1.14.0",
29
+ "@aglyn/shared-data-enums": "1.14.0",
30
+ "@aglyn/shared-ui-jsx": "1.14.0",
31
+ "@aglyn/shared-util-email": "1.14.0",
32
+ "@aglyn/shared-util-http": "1.14.0",
33
+ "@aglyn/shared-util-timestamp": "1.14.0",
34
34
  "@swc/helpers": "0.5.23",
35
35
  "lodash-es": "^4.18.1",
36
36
  "mobx": "^7.0.5"
@@ -144,7 +144,10 @@ export interface SendingIdentityView {
144
144
  */
145
145
  lastIssueError?: string | null;
146
146
  }[];
147
+ /** "Manage workspace settings": what this site sends as, and its senders. */
147
148
  canManage: boolean;
149
+ /** "Sending domains": adding, checking and removing a domain (AGL-4047). */
150
+ canManageDomains: boolean;
148
151
  entitled: boolean;
149
152
  /**
150
153
  * The OFFER of a platform sending domain — never the fact of having one,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/tenant/feature/instance/src/lib/hooks/use-sending-identity-api.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport type { SenderReadiness } from '@aglyn/shared-util-email'\nimport { useUser } from './firebase/firebase-services'\nimport { useCallback, useRef } from 'react'\nimport {\n describeCallFailure,\n resolveIdToken,\n type TokenSource,\n} from '@aglyn/shared-util-http/authorized-token'\n\n/**\n * The client of the console's sending-identity routes (`/api/email/*`).\n *\n * Which address a site's mail leaves from, and the domains and senders behind\n * it, are the platform's mail rail: the console serves the routes, and every\n * message goes out under that identity whichever plugin wrote it. So the hook\n * that calls them is here, beside the other client hooks a plugin may import,\n * and a one-to-one composer reads the identity without importing the plugin\n * whose settings page edits it.\n */\n\n/** What one call answered with. `payload` is `{}` on an unparseable body. */\nexport interface SendingApiResult {\n response: Response\n payload: Record<string, any>\n}\n\n/**\n * A refusal the caller reads the same way it reads the route's own.\n *\n * `401` because that is what the request would have been answered with had it\n * gone out, and the reason travels in `payload.error`, which is the field\n * every caller already renders.\n */\nconst refusedForCaller = (message: string): SendingApiResult => ({\n response: {\n ok: false,\n status: 401,\n json: async () => ({ error: message }),\n } as unknown as Response,\n payload: { error: message },\n})\n\n/** One DNS record, exactly as the server issued it. */\nexport interface SendingDnsRecordView {\n type: 'TXT' | 'MX'\n name: string\n value: string\n priority?: number\n purpose: 'spf' | 'dkim' | 'return-path' | 'dmarc'\n required: boolean\n note: string\n}\n\n/** One org sending domain, as the domains route reports it. */\nexport interface SendingDomainView {\n domain: string\n status: 'requested' | 'records-issued' | 'verified' | 'failed'\n records?: SendingDnsRecordView[]\n lines?: string[]\n lastMissing?: string[] | null\n lastIssueError?: string | null\n verifiedAtMs?: number | null\n lastCheckedAtMs?: number | null\n dmarc?: {\n policy: 'reject' | 'quarantine' | 'none' | 'absent'\n record: string | null\n consequence: string\n } | null\n dmarcSuggestion?: SendingDnsRecordView | null\n /** How receivers will judge mail from it (AGL-3328); none before a key is issued. */\n readiness?: SenderReadiness | null\n pendingProvider?: boolean\n providerDetail?: string | null\n}\n\n/**\n * One sender this site holds — `hosts/{hostId}/senders/{senderId}`.\n *\n * `from` is the whole address, assembled by the server for the reason\n * `IdentityOption.from` is: a surface that built `${localPart}@${domain}`\n * itself would be a second derivation of the address, and the two would\n * disagree the first time either moved. It is `null` for a row whose mailbox\n * is not in effect — a site on the pooled Aglyn address has one fixed mailbox,\n * shared with the other sites on it.\n */\nexport interface HostSenderView {\n id: string\n localPart: string\n fromName: string | null\n replyTo: string | null\n /** Whether an email that names no sender goes out as this one. */\n isDefault: boolean\n from: string | null\n}\n\n/** What this site sends as, and what it is allowed to send as. */\nexport interface SendingIdentityView {\n orgId: string | null\n selected: string\n /**\n * The site's own provisioned domain inside the platform mail apex, or `''`\n * when it has none and its transactional mail rides the shared pool.\n */\n platformDomain: string\n /**\n * The plan that carries sending as a domain the CUSTOMER owns, and the plan\n * that carries a domain the platform provisions for the site — as names\n * ready to print, `null` when no plan carries that gate.\n *\n * Both come from the server because both are derived from the entitlement\n * tables there. A tier name written into this component would be pricing\n * copy that keeps rendering after the gate beneath it moves.\n */\n customDomainPlan: string | null\n dedicatedDomainPlan: string | null\n /** The mailbox this site sends as — the part before the `@`. */\n localPart: string\n /**\n * Whether that mailbox is the one actually in use.\n *\n * False for a site on the pooled Aglyn address, whose mailbox is fixed. The\n * stored value is real and is kept; it takes effect when the site has a\n * domain of its own, and until then the card says so rather than showing a\n * name that no recipient will see.\n */\n localPartInUse: boolean\n /** The site's default sender name, or null. Composers start from it. */\n fromName: string | null\n /** The site's default reply address, or null. */\n replyTo: string | null\n /**\n * Every sender this site may send as, the default among them.\n *\n * Never empty: a site with no `senders` subcollection has exactly one\n * sender, and the server synthesizes it from the three fields the host\n * document has always carried rather than reporting an absence.\n */\n senders: HostSenderView[]\n identity: string\n /**\n * `'custom'` for a domain this site has verified, `'shared'` for the pooled\n * Aglyn address a site uses until it has one, `null` when the send is\n * refused. `'platform'` is in the union because the resolver can return it,\n * and never reaches this view: it is Aglyn's own `aglyn.com` identity, which\n * a host-scoped resolution cannot produce.\n */\n identitySource: 'custom' | 'shared' | 'platform' | null\n refusal: {\n code: string\n domain: string | null\n message: string\n missing: string[]\n } | null\n options: {\n value: string\n from: string | null\n selectable: boolean\n status: string\n }[]\n domains: {\n domain: string\n status: SendingDomainView['status']\n verifiedAtMs: number | null\n lastCheckedAtMs: number | null\n /**\n * Why the last attempt to issue a key produced none, or `null`.\n *\n * Carried in the LIST and not only on the domain's own page, because one\n * of its values is not a fault: a claim held at the mail provider's domain\n * allowance is `requested` with a reason, and a list that could not see\n * the reason would label it \"Waiting on a signing key\" — a state whose\n * whole instruction is to press a button that will not move it.\n */\n lastIssueError?: string | null\n }[]\n canManage: boolean\n entitled: boolean\n /**\n * The OFFER of a platform sending domain — never the fact of having one,\n * which `platformDomain` above answers.\n *\n * A dedicated subdomain is no longer issued on upgrade: it costs a provider\n * domain slot and three records in Aglyn's own zone, so it is requested by\n * somebody who wants it rather than handed to every paying site.\n *\n * Optional because a console deployment can be older than the field. A\n * surface reading it must treat its absence as \"no offer to show\", never as\n * \"the offer was refused\".\n */\n dedicated?: {\n /** The plan carries one and this site has none. */\n available: boolean\n /** The name a request would most likely take. Not a reservation. */\n proposed: string | null\n }\n}\n\n/**\n * ONE AUTHORIZED CALL TO THE SENDING-IDENTITY AND SENDING-DOMAIN ROUTES.\n *\n * The same shape as `useCampaignSendApi`, including why the user is held in a\n * ref: this callback is a dependency of effects that load on open, and the\n * user object is a new object on most renders, so depending on it directly\n * would re-issue the request on every render of the surface. The token is\n * fetched at call time either way.\n *\n * The two paths are fixed here rather than taken as an argument, for the\n * reason the campaign hook gives: a hook that accepted a URL from a component\n * would be a way to post the console's credentials somewhere the console does\n * not own.\n *\n * The token is obtained under a deadline, for the reason `useCampaignApi`\n * gives: it is awaited in front of the request, so an unbounded refresh is a\n * call that never reaches `fetch` and never reports anything.\n *\n * ## An unobtainable token ANSWERS here rather than throwing\n *\n * Unlike the campaign hook, whose callers must tell a send that never left\n * the browser apart from one the route refused. Everything on this side reads\n * or edits a configuration surface, where both are the same news to the\n * reader — and every caller already renders `payload.error` on a refusal, so\n * answering in that shape is what puts the real reason on screen and leaves\n * the button that started the call usable.\n */\nexport function useSendingApi() {\n const { data: user } = useUser()\n const userRef = useRef(user)\n userRef.current = user\n\n return useCallback(\n async (options: {\n path: 'sending-identity' | 'sending-domains'\n method: 'GET' | 'POST' | 'DELETE'\n query?: Record<string, string>\n body?: Record<string, unknown>\n }): Promise<SendingApiResult> => {\n let idToken: string\n try {\n idToken = await resolveIdToken(\n userRef.current as TokenSource | null | undefined,\n )\n } catch (error) {\n return refusedForCaller(\n describeCallFailure(error, 'Your sign-in could not be confirmed'),\n )\n }\n const search = new URLSearchParams(options.query ?? {}).toString()\n const response = await fetch(\n `/api/email/${options.path}${search ? `?${search}` : ''}`,\n {\n method: options.method,\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${idToken}`,\n },\n ...(options.body ? { body: JSON.stringify(options.body) } : {}),\n },\n )\n const json = await response.json().catch(() => ({}))\n return { response, payload: json as Record<string, any> }\n },\n [],\n )\n}\n"],"names":["useUser","useCallback","useRef","describeCallFailure","resolveIdToken","refusedForCaller","message","response","ok","status","json","error","payload","useSendingApi","data","user","userRef","current","options","idToken","search","URLSearchParams","query","toString","fetch","path","method","headers","Authorization","body","JSON","stringify","catch"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAGA,SAASA,OAAO,QAAQ,kCAA8B;AACtD,SAASC,WAAW,EAAEC,MAAM,QAAQ,QAAO;AAC3C,SACEC,mBAAmB,EACnBC,cAAc,QAET,2CAA0C;AAmBjD;;;;;;CAMC,GACD,MAAMC,mBAAmB,CAACC,UAAuC,CAAA;QAC/DC,UAAU;YACRC,IAAI;YACJC,QAAQ;YACRC,MAAM,UAAa,CAAA;oBAAEC,OAAOL;gBAAQ,CAAA;QACtC;QACAM,SAAS;YAAED,OAAOL;QAAQ;IAC5B,CAAA;AA6JA;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,OAAO,SAASO;IACd,MAAM,EAAEC,MAAMC,IAAI,EAAE,GAAGf;IACvB,MAAMgB,UAAUd,OAAOa;IACvBC,QAAQC,OAAO,GAAGF;IAElB,OAAOd,YACL,OAAOiB;YAgB8BA;QAVnC,IAAIC;QACJ,IAAI;YACFA,UAAU,MAAMf,eACdY,QAAQC,OAAO;QAEnB,EAAE,OAAON,OAAO;YACd,OAAON,iBACLF,oBAAoBQ,OAAO;QAE/B;QACA,MAAMS,SAAS,IAAIC,iBAAgBH,iBAAAA,QAAQI,KAAK,YAAbJ,iBAAiB,CAAC,GAAGK,QAAQ;QAChE,MAAMhB,WAAW,MAAMiB,MACrB,CAAC,WAAW,EAAEN,QAAQO,IAAI,GAAGL,SAAS,CAAC,CAAC,EAAEA,QAAQ,GAAG,IAAI,EACzD;YACEM,QAAQR,QAAQQ,MAAM;YACtBC,SAAS;gBACP,gBAAgB;gBAChBC,eAAe,CAAC,OAAO,EAAET,SAAS;YACpC;WACID,QAAQW,IAAI,GAAG;YAAEA,MAAMC,KAAKC,SAAS,CAACb,QAAQW,IAAI;QAAE,IAAI,CAAC;QAGjE,MAAMnB,OAAO,MAAMH,SAASG,IAAI,GAAGsB,KAAK,CAAC,IAAO,CAAA,CAAC,CAAA;QACjD,OAAO;YAAEzB;YAAUK,SAASF;QAA4B;IAC1D,GACA,EAAE;AAEN"}
1
+ {"version":3,"sources":["../../../../../../../../libs/tenant/feature/instance/src/lib/hooks/use-sending-identity-api.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport type { SenderReadiness } from '@aglyn/shared-util-email'\nimport { useUser } from './firebase/firebase-services'\nimport { useCallback, useRef } from 'react'\nimport {\n describeCallFailure,\n resolveIdToken,\n type TokenSource,\n} from '@aglyn/shared-util-http/authorized-token'\n\n/**\n * The client of the console's sending-identity routes (`/api/email/*`).\n *\n * Which address a site's mail leaves from, and the domains and senders behind\n * it, are the platform's mail rail: the console serves the routes, and every\n * message goes out under that identity whichever plugin wrote it. So the hook\n * that calls them is here, beside the other client hooks a plugin may import,\n * and a one-to-one composer reads the identity without importing the plugin\n * whose settings page edits it.\n */\n\n/** What one call answered with. `payload` is `{}` on an unparseable body. */\nexport interface SendingApiResult {\n response: Response\n payload: Record<string, any>\n}\n\n/**\n * A refusal the caller reads the same way it reads the route's own.\n *\n * `401` because that is what the request would have been answered with had it\n * gone out, and the reason travels in `payload.error`, which is the field\n * every caller already renders.\n */\nconst refusedForCaller = (message: string): SendingApiResult => ({\n response: {\n ok: false,\n status: 401,\n json: async () => ({ error: message }),\n } as unknown as Response,\n payload: { error: message },\n})\n\n/** One DNS record, exactly as the server issued it. */\nexport interface SendingDnsRecordView {\n type: 'TXT' | 'MX'\n name: string\n value: string\n priority?: number\n purpose: 'spf' | 'dkim' | 'return-path' | 'dmarc'\n required: boolean\n note: string\n}\n\n/** One org sending domain, as the domains route reports it. */\nexport interface SendingDomainView {\n domain: string\n status: 'requested' | 'records-issued' | 'verified' | 'failed'\n records?: SendingDnsRecordView[]\n lines?: string[]\n lastMissing?: string[] | null\n lastIssueError?: string | null\n verifiedAtMs?: number | null\n lastCheckedAtMs?: number | null\n dmarc?: {\n policy: 'reject' | 'quarantine' | 'none' | 'absent'\n record: string | null\n consequence: string\n } | null\n dmarcSuggestion?: SendingDnsRecordView | null\n /** How receivers will judge mail from it (AGL-3328); none before a key is issued. */\n readiness?: SenderReadiness | null\n pendingProvider?: boolean\n providerDetail?: string | null\n}\n\n/**\n * One sender this site holds — `hosts/{hostId}/senders/{senderId}`.\n *\n * `from` is the whole address, assembled by the server for the reason\n * `IdentityOption.from` is: a surface that built `${localPart}@${domain}`\n * itself would be a second derivation of the address, and the two would\n * disagree the first time either moved. It is `null` for a row whose mailbox\n * is not in effect — a site on the pooled Aglyn address has one fixed mailbox,\n * shared with the other sites on it.\n */\nexport interface HostSenderView {\n id: string\n localPart: string\n fromName: string | null\n replyTo: string | null\n /** Whether an email that names no sender goes out as this one. */\n isDefault: boolean\n from: string | null\n}\n\n/** What this site sends as, and what it is allowed to send as. */\nexport interface SendingIdentityView {\n orgId: string | null\n selected: string\n /**\n * The site's own provisioned domain inside the platform mail apex, or `''`\n * when it has none and its transactional mail rides the shared pool.\n */\n platformDomain: string\n /**\n * The plan that carries sending as a domain the CUSTOMER owns, and the plan\n * that carries a domain the platform provisions for the site — as names\n * ready to print, `null` when no plan carries that gate.\n *\n * Both come from the server because both are derived from the entitlement\n * tables there. A tier name written into this component would be pricing\n * copy that keeps rendering after the gate beneath it moves.\n */\n customDomainPlan: string | null\n dedicatedDomainPlan: string | null\n /** The mailbox this site sends as — the part before the `@`. */\n localPart: string\n /**\n * Whether that mailbox is the one actually in use.\n *\n * False for a site on the pooled Aglyn address, whose mailbox is fixed. The\n * stored value is real and is kept; it takes effect when the site has a\n * domain of its own, and until then the card says so rather than showing a\n * name that no recipient will see.\n */\n localPartInUse: boolean\n /** The site's default sender name, or null. Composers start from it. */\n fromName: string | null\n /** The site's default reply address, or null. */\n replyTo: string | null\n /**\n * Every sender this site may send as, the default among them.\n *\n * Never empty: a site with no `senders` subcollection has exactly one\n * sender, and the server synthesizes it from the three fields the host\n * document has always carried rather than reporting an absence.\n */\n senders: HostSenderView[]\n identity: string\n /**\n * `'custom'` for a domain this site has verified, `'shared'` for the pooled\n * Aglyn address a site uses until it has one, `null` when the send is\n * refused. `'platform'` is in the union because the resolver can return it,\n * and never reaches this view: it is Aglyn's own `aglyn.com` identity, which\n * a host-scoped resolution cannot produce.\n */\n identitySource: 'custom' | 'shared' | 'platform' | null\n refusal: {\n code: string\n domain: string | null\n message: string\n missing: string[]\n } | null\n options: {\n value: string\n from: string | null\n selectable: boolean\n status: string\n }[]\n domains: {\n domain: string\n status: SendingDomainView['status']\n verifiedAtMs: number | null\n lastCheckedAtMs: number | null\n /**\n * Why the last attempt to issue a key produced none, or `null`.\n *\n * Carried in the LIST and not only on the domain's own page, because one\n * of its values is not a fault: a claim held at the mail provider's domain\n * allowance is `requested` with a reason, and a list that could not see\n * the reason would label it \"Waiting on a signing key\" — a state whose\n * whole instruction is to press a button that will not move it.\n */\n lastIssueError?: string | null\n }[]\n /** \"Manage workspace settings\": what this site sends as, and its senders. */\n canManage: boolean\n /** \"Sending domains\": adding, checking and removing a domain (AGL-4047). */\n canManageDomains: boolean\n entitled: boolean\n /**\n * The OFFER of a platform sending domain — never the fact of having one,\n * which `platformDomain` above answers.\n *\n * A dedicated subdomain is no longer issued on upgrade: it costs a provider\n * domain slot and three records in Aglyn's own zone, so it is requested by\n * somebody who wants it rather than handed to every paying site.\n *\n * Optional because a console deployment can be older than the field. A\n * surface reading it must treat its absence as \"no offer to show\", never as\n * \"the offer was refused\".\n */\n dedicated?: {\n /** The plan carries one and this site has none. */\n available: boolean\n /** The name a request would most likely take. Not a reservation. */\n proposed: string | null\n }\n}\n\n/**\n * ONE AUTHORIZED CALL TO THE SENDING-IDENTITY AND SENDING-DOMAIN ROUTES.\n *\n * The same shape as `useCampaignSendApi`, including why the user is held in a\n * ref: this callback is a dependency of effects that load on open, and the\n * user object is a new object on most renders, so depending on it directly\n * would re-issue the request on every render of the surface. The token is\n * fetched at call time either way.\n *\n * The two paths are fixed here rather than taken as an argument, for the\n * reason the campaign hook gives: a hook that accepted a URL from a component\n * would be a way to post the console's credentials somewhere the console does\n * not own.\n *\n * The token is obtained under a deadline, for the reason `useCampaignApi`\n * gives: it is awaited in front of the request, so an unbounded refresh is a\n * call that never reaches `fetch` and never reports anything.\n *\n * ## An unobtainable token ANSWERS here rather than throwing\n *\n * Unlike the campaign hook, whose callers must tell a send that never left\n * the browser apart from one the route refused. Everything on this side reads\n * or edits a configuration surface, where both are the same news to the\n * reader — and every caller already renders `payload.error` on a refusal, so\n * answering in that shape is what puts the real reason on screen and leaves\n * the button that started the call usable.\n */\nexport function useSendingApi() {\n const { data: user } = useUser()\n const userRef = useRef(user)\n userRef.current = user\n\n return useCallback(\n async (options: {\n path: 'sending-identity' | 'sending-domains'\n method: 'GET' | 'POST' | 'DELETE'\n query?: Record<string, string>\n body?: Record<string, unknown>\n }): Promise<SendingApiResult> => {\n let idToken: string\n try {\n idToken = await resolveIdToken(\n userRef.current as TokenSource | null | undefined,\n )\n } catch (error) {\n return refusedForCaller(\n describeCallFailure(error, 'Your sign-in could not be confirmed'),\n )\n }\n const search = new URLSearchParams(options.query ?? {}).toString()\n const response = await fetch(\n `/api/email/${options.path}${search ? `?${search}` : ''}`,\n {\n method: options.method,\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${idToken}`,\n },\n ...(options.body ? { body: JSON.stringify(options.body) } : {}),\n },\n )\n const json = await response.json().catch(() => ({}))\n return { response, payload: json as Record<string, any> }\n },\n [],\n )\n}\n"],"names":["useUser","useCallback","useRef","describeCallFailure","resolveIdToken","refusedForCaller","message","response","ok","status","json","error","payload","useSendingApi","data","user","userRef","current","options","idToken","search","URLSearchParams","query","toString","fetch","path","method","headers","Authorization","body","JSON","stringify","catch"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAGA,SAASA,OAAO,QAAQ,kCAA8B;AACtD,SAASC,WAAW,EAAEC,MAAM,QAAQ,QAAO;AAC3C,SACEC,mBAAmB,EACnBC,cAAc,QAET,2CAA0C;AAmBjD;;;;;;CAMC,GACD,MAAMC,mBAAmB,CAACC,UAAuC,CAAA;QAC/DC,UAAU;YACRC,IAAI;YACJC,QAAQ;YACRC,MAAM,UAAa,CAAA;oBAAEC,OAAOL;gBAAQ,CAAA;QACtC;QACAM,SAAS;YAAED,OAAOL;QAAQ;IAC5B,CAAA;AAgKA;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,OAAO,SAASO;IACd,MAAM,EAAEC,MAAMC,IAAI,EAAE,GAAGf;IACvB,MAAMgB,UAAUd,OAAOa;IACvBC,QAAQC,OAAO,GAAGF;IAElB,OAAOd,YACL,OAAOiB;YAgB8BA;QAVnC,IAAIC;QACJ,IAAI;YACFA,UAAU,MAAMf,eACdY,QAAQC,OAAO;QAEnB,EAAE,OAAON,OAAO;YACd,OAAON,iBACLF,oBAAoBQ,OAAO;QAE/B;QACA,MAAMS,SAAS,IAAIC,iBAAgBH,iBAAAA,QAAQI,KAAK,YAAbJ,iBAAiB,CAAC,GAAGK,QAAQ;QAChE,MAAMhB,WAAW,MAAMiB,MACrB,CAAC,WAAW,EAAEN,QAAQO,IAAI,GAAGL,SAAS,CAAC,CAAC,EAAEA,QAAQ,GAAG,IAAI,EACzD;YACEM,QAAQR,QAAQQ,MAAM;YACtBC,SAAS;gBACP,gBAAgB;gBAChBC,eAAe,CAAC,OAAO,EAAET,SAAS;YACpC;WACID,QAAQW,IAAI,GAAG;YAAEA,MAAMC,KAAKC,SAAS,CAACb,QAAQW,IAAI;QAAE,IAAI,CAAC;QAGjE,MAAMnB,OAAO,MAAMH,SAASG,IAAI,GAAGsB,KAAK,CAAC,IAAO,CAAA,CAAC,CAAA;QACjD,OAAO;YAAEzB;YAAUK,SAASF;QAA4B;IAC1D,GACA,EAAE;AAEN"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { HostAccessRole } from '@aglyn/aglyn/foundation/definitions/organization.types';
18
+ /** A key's site-role preset, as the plugin that declares it tables it. */
19
+ export type SiteKeyPreset = Readonly<Partial<Record<HostAccessRole, boolean>>>;
20
+ export interface SiteKeys {
21
+ /**
22
+ * Whether this member is known NOT to hold the key on the site, so a control
23
+ * switches off with the permission named beside it. `false` until the answer
24
+ * is in, so nobody sees a control flash off while it loads; `false` too for a
25
+ * reader who is not on the site's roster, who is staff, whom the doors admit:
26
+ * there the server answers.
27
+ */
28
+ blocked(key: string, preset: SiteKeyPreset): boolean;
29
+ }
30
+ /**
31
+ * The signed-in member's verdict on a site's keys (AGL-4047), read as the doors
32
+ * read them: the site's `memberPermissions` stamp, else the preset of their
33
+ * `memberRoles` entry (`holdsStampedSiteKey`). For a plugin's card, which cannot
34
+ * reach the console's permission context. One listener on the host document,
35
+ * which the Firestore client shares with every other reader of it on the page.
36
+ */
37
+ export declare function useSiteKeys(hostId: string | null | undefined): SiteKeys;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { holdsStampedSiteKey } from "@aglyn/aglyn/app-utils/host-permissions";
17
+ import { doc } from "firebase/firestore";
18
+ import { useCallback } from "react";
19
+ import { useFirestore, useUser } from "./firebase/firebase-services.js";
20
+ import { useFirestoreDoc } from "./use-firestore-doc.js";
21
+ /**
22
+ * The signed-in member's verdict on a site's keys (AGL-4047), read as the doors
23
+ * read them: the site's `memberPermissions` stamp, else the preset of their
24
+ * `memberRoles` entry (`holdsStampedSiteKey`). For a plugin's card, which cannot
25
+ * reach the console's permission context. One listener on the host document,
26
+ * which the Firestore client shares with every other reader of it on the page.
27
+ */ export function useSiteKeys(hostId) {
28
+ var _ref;
29
+ var _host_memberRoles;
30
+ const firestore = useFirestore();
31
+ const { data: user } = useUser();
32
+ const uid = (_ref = user == null ? void 0 : user.uid) != null ? _ref : '';
33
+ const site = hostId || '';
34
+ const hostRead = useFirestoreDoc(()=>site ? doc(firestore, 'hosts', site) : null, [
35
+ firestore,
36
+ site
37
+ ]);
38
+ const known = hostRead.status === 'success';
39
+ const host = known ? hostRead.data : null;
40
+ const onRoster = Boolean(uid && (host == null ? void 0 : (_host_memberRoles = host.memberRoles) == null ? void 0 : _host_memberRoles[uid]));
41
+ const blocked = useCallback((key, preset)=>known && onRoster && !holdsStampedSiteKey(host, uid, key, preset), [
42
+ known,
43
+ onRoster,
44
+ host,
45
+ uid
46
+ ]);
47
+ return {
48
+ blocked
49
+ };
50
+ }
51
+
52
+ //# sourceMappingURL=use-site-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/tenant/feature/instance/src/lib/hooks/use-site-keys.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { type HostDocumentLike, holdsStampedSiteKey } from '@aglyn/aglyn/app-utils/host-permissions'\nimport type { HostAccessRole } from '@aglyn/aglyn/foundation/definitions/organization.types'\nimport { doc } from 'firebase/firestore'\nimport { useCallback } from 'react'\nimport { useFirestore, useUser } from './firebase/firebase-services'\nimport { useFirestoreDoc } from './use-firestore-doc'\n\n/** A key's site-role preset, as the plugin that declares it tables it. */\nexport type SiteKeyPreset = Readonly<Partial<Record<HostAccessRole, boolean>>>\n\nexport interface SiteKeys {\n /**\n * Whether this member is known NOT to hold the key on the site, so a control\n * switches off with the permission named beside it. `false` until the answer\n * is in, so nobody sees a control flash off while it loads; `false` too for a\n * reader who is not on the site's roster, who is staff, whom the doors admit:\n * there the server answers.\n */\n blocked(key: string, preset: SiteKeyPreset): boolean\n}\n\n/**\n * The signed-in member's verdict on a site's keys (AGL-4047), read as the doors\n * read them: the site's `memberPermissions` stamp, else the preset of their\n * `memberRoles` entry (`holdsStampedSiteKey`). For a plugin's card, which cannot\n * reach the console's permission context. One listener on the host document,\n * which the Firestore client shares with every other reader of it on the page.\n */\nexport function useSiteKeys(hostId: string | null | undefined): SiteKeys {\n const firestore = useFirestore()\n const { data: user } = useUser()\n const uid = user?.uid ?? ''\n const site = hostId || ''\n const hostRead = useFirestoreDoc<{ memberRoles?: Record<string, unknown>; memberPermissions?: unknown }>(\n () => (site ? doc(firestore, 'hosts', site) : null),\n [firestore, site],\n )\n const known = hostRead.status === 'success'\n const host = known ? hostRead.data : null\n const onRoster = Boolean(uid && host?.memberRoles?.[uid])\n const blocked = useCallback(\n (key: string, preset: SiteKeyPreset) =>\n known && onRoster && !holdsStampedSiteKey(host as HostDocumentLike, uid, key, preset),\n [known, onRoster, host, uid],\n )\n return { blocked }\n}\n"],"names":["holdsStampedSiteKey","doc","useCallback","useFirestore","useUser","useFirestoreDoc","useSiteKeys","hostId","host","firestore","data","user","uid","site","hostRead","known","status","onRoster","Boolean","memberRoles","blocked","key","preset"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAAgCA,mBAAmB,QAAQ,0CAAyC;AAEpG,SAASC,GAAG,QAAQ,qBAAoB;AACxC,SAASC,WAAW,QAAQ,QAAO;AACnC,SAASC,YAAY,EAAEC,OAAO,QAAQ,kCAA8B;AACpE,SAASC,eAAe,QAAQ,yBAAqB;AAgBrD;;;;;;CAMC,GACD,OAAO,SAASC,YAAYC,MAAiC;;QAW3BC;IAVhC,MAAMC,YAAYN;IAClB,MAAM,EAAEO,MAAMC,IAAI,EAAE,GAAGP;IACvB,MAAMQ,cAAMD,wBAAAA,KAAMC,GAAG,mBAAI;IACzB,MAAMC,OAAON,UAAU;IACvB,MAAMO,WAAWT,gBACf,IAAOQ,OAAOZ,IAAIQ,WAAW,SAASI,QAAQ,MAC9C;QAACJ;QAAWI;KAAK;IAEnB,MAAME,QAAQD,SAASE,MAAM,KAAK;IAClC,MAAMR,OAAOO,QAAQD,SAASJ,IAAI,GAAG;IACrC,MAAMO,WAAWC,QAAQN,QAAOJ,yBAAAA,oBAAAA,KAAMW,WAAW,qBAAjBX,iBAAmB,CAACI,IAAI;IACxD,MAAMQ,UAAUlB,YACd,CAACmB,KAAaC,SACZP,SAASE,YAAY,CAACjB,oBAAoBQ,MAA0BI,KAAKS,KAAKC,SAChF;QAACP;QAAOE;QAAUT;QAAMI;KAAI;IAE9B,OAAO;QAAEQ;IAAQ;AACnB"}