@aglyn/plugins-inbox 1.0.0-beta.220 → 1.0.0-beta.222

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.
@@ -0,0 +1,67 @@
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 { visibleToHost } from "@aglyn/aglyn/app-utils/scope-tokens";
17
+ import { registerPluginPersonRecords } from "@aglyn/aglyn/plugin-manager/plugin-person-records";
18
+ /**
19
+ * A plugin that keeps people, standing in for the one that does (AGL-3080).
20
+ *
21
+ * The Inbox asks for the person behind an address through
22
+ * `plugin-person-records` and imports no record system, so its specs stand an
23
+ * owner up the way the loader would. One plugin may not import another, which
24
+ * is why this is here rather than borrowed from the CRM.
25
+ *
26
+ * It finds a person in the spec's own store, by the address or by an
27
+ * alternate one a merge folded in, narrowed to the site when asked — what the
28
+ * owner answers, imitated over the spec's double. That the real owner answers
29
+ * the same is held by the CRM's own `person-records.spec.ts`.
30
+ */ export function standInPersonRecords(options) {
31
+ const asked = [];
32
+ const prefix = `orgs/${options.orgId}/contacts/`;
33
+ registerPluginPersonRecords({
34
+ async find (request) {
35
+ var _request_email;
36
+ asked.push(request);
37
+ const email = String((_request_email = request.email) != null ? _request_email : '').trim().toLowerCase();
38
+ if (!email.includes('@')) return null;
39
+ for (const [path, data] of Object.entries(options.store())){
40
+ var _data_email;
41
+ if (!data || !path.startsWith(prefix) || path.slice(prefix.length).includes('/')) continue;
42
+ const alternates = Array.isArray(data['alternateEmails']) ? data['alternateEmails'] : [];
43
+ if (data['email'] !== email && !alternates.includes(email)) continue;
44
+ // One address names one person: a record the site may not see is
45
+ // nobody, not a reason to look further.
46
+ if (request.onlyVisibleToSite && request.hostId && !visibleToHost(data['visibleTo'], request.hostId)) {
47
+ return null;
48
+ }
49
+ return {
50
+ kind: 'contact',
51
+ id: path.slice(prefix.length),
52
+ email: String((_data_email = data['email']) != null ? _data_email : ''),
53
+ data
54
+ };
55
+ }
56
+ return null;
57
+ },
58
+ async read (request) {
59
+ return request.records.map(()=>null);
60
+ }
61
+ }, {
62
+ pluginId: 'record-system'
63
+ });
64
+ return asked;
65
+ }
66
+
67
+ //# sourceMappingURL=stand-in-person-records.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/inbox/src/lib/testing/stand-in-person-records.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 { visibleToHost } from '@aglyn/aglyn/app-utils/scope-tokens'\nimport {\n registerPluginPersonRecords,\n type PluginPersonFindRequest,\n} from '@aglyn/aglyn/plugin-manager/plugin-person-records'\n\n/**\n * A plugin that keeps people, standing in for the one that does (AGL-3080).\n *\n * The Inbox asks for the person behind an address through\n * `plugin-person-records` and imports no record system, so its specs stand an\n * owner up the way the loader would. One plugin may not import another, which\n * is why this is here rather than borrowed from the CRM.\n *\n * It finds a person in the spec's own store, by the address or by an\n * alternate one a merge folded in, narrowed to the site when asked — what the\n * owner answers, imitated over the spec's double. That the real owner answers\n * the same is held by the CRM's own `person-records.spec.ts`.\n */\nexport function standInPersonRecords(options: {\n /** The spec's documents, by path. */\n store: () => Readonly<Record<string, Record<string, unknown> | undefined>>\n orgId: string\n}): PluginPersonFindRequest[] {\n const asked: PluginPersonFindRequest[] = []\n const prefix = `orgs/${options.orgId}/contacts/`\n registerPluginPersonRecords(\n {\n async find(request) {\n asked.push(request)\n const email = String(request.email ?? '').trim().toLowerCase()\n if (!email.includes('@')) return null\n for (const [path, data] of Object.entries(options.store())) {\n if (!data || !path.startsWith(prefix) || path.slice(prefix.length).includes('/')) continue\n const alternates = Array.isArray(data['alternateEmails']) ? data['alternateEmails'] : []\n if (data['email'] !== email && !alternates.includes(email)) continue\n // One address names one person: a record the site may not see is\n // nobody, not a reason to look further.\n if (\n request.onlyVisibleToSite &&\n request.hostId &&\n !visibleToHost(data['visibleTo'] as string[] | undefined, request.hostId)\n ) {\n return null\n }\n return { kind: 'contact', id: path.slice(prefix.length), email: String(data['email'] ?? ''), data }\n }\n return null\n },\n async read(request) {\n return request.records.map(() => null)\n },\n },\n { pluginId: 'record-system' },\n )\n return asked\n}\n"],"names":["visibleToHost","registerPluginPersonRecords","standInPersonRecords","options","asked","prefix","orgId","find","request","push","email","String","trim","toLowerCase","includes","path","data","Object","entries","store","startsWith","slice","length","alternates","Array","isArray","onlyVisibleToSite","hostId","kind","id","read","records","map","pluginId"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,aAAa,QAAQ,sCAAqC;AACnE,SACEC,2BAA2B,QAEtB,oDAAmD;AAE1D;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,qBAAqBC,OAIpC;IACC,MAAMC,QAAmC,EAAE;IAC3C,MAAMC,SAAS,CAAC,KAAK,EAAEF,QAAQG,KAAK,CAAC,UAAU,CAAC;IAChDL,4BACE;QACE,MAAMM,MAAKC,OAAO;gBAEKA;YADrBJ,MAAMK,IAAI,CAACD;YACX,MAAME,QAAQC,QAAOH,iBAAAA,QAAQE,KAAK,YAAbF,iBAAiB,IAAII,IAAI,GA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