@aglyn/plugins-data 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.
Files changed (43) hide show
  1. package/package.json +10 -10
  2. package/src/lib/artifact/dataset-schema-artifact.server.js +6 -3
  3. package/src/lib/artifact/dataset-schema-artifact.server.js.map +1 -1
  4. package/src/lib/components/dataset-schema-dialog.component.d.ts +14 -0
  5. package/src/lib/components/dataset-schema-dialog.component.js +317 -239
  6. package/src/lib/components/dataset-schema-dialog.component.js.map +1 -1
  7. package/src/lib/components/host-datasets-card.component.js +71 -34
  8. package/src/lib/components/host-datasets-card.component.js.map +1 -1
  9. package/src/lib/components/use-dataset-writes-blocked.d.ts +50 -12
  10. package/src/lib/components/use-dataset-writes-blocked.js +86 -19
  11. package/src/lib/components/use-dataset-writes-blocked.js.map +1 -1
  12. package/src/lib/declarations.d.ts +25 -0
  13. package/src/lib/declarations.js +37 -0
  14. package/src/lib/declarations.js.map +1 -0
  15. package/src/lib/model/data-permissions.d.ts +34 -0
  16. package/src/lib/model/data-permissions.js +108 -0
  17. package/src/lib/model/data-permissions.js.map +1 -0
  18. package/src/lib/model/dataset-access.d.ts +22 -0
  19. package/src/lib/model/dataset-access.js +30 -0
  20. package/src/lib/model/dataset-access.js.map +1 -0
  21. package/src/lib/model/dataset-record.js +8 -3
  22. package/src/lib/model/dataset-record.js.map +1 -1
  23. package/src/lib/plugin.js +4 -1
  24. package/src/lib/plugin.js.map +1 -1
  25. package/src/lib/server/dataset-access.server.d.ts +41 -0
  26. package/src/lib/server/dataset-access.server.js +49 -0
  27. package/src/lib/server/dataset-access.server.js.map +1 -0
  28. package/src/lib/server/dataset-figures.js +12 -0
  29. package/src/lib/server/dataset-figures.js.map +1 -1
  30. package/src/lib/server/dataset-site-erasure.d.ts +2 -2
  31. package/src/lib/server/dataset-site-erasure.js +4 -26
  32. package/src/lib/server/dataset-site-erasure.js.map +1 -1
  33. package/src/lib/server/datasets-route.d.ts +2 -0
  34. package/src/lib/server/datasets-route.js +178 -27
  35. package/src/lib/server/datasets-route.js.map +1 -1
  36. package/src/lib/site-bundle/datasets-site-bundle.server.d.ts +4 -2
  37. package/src/lib/site-bundle/datasets-site-bundle.server.js +8 -4
  38. package/src/lib/site-bundle/datasets-site-bundle.server.js.map +1 -1
  39. package/src/lib/transfer/dataset-transfer-access.server.d.ts +23 -0
  40. package/src/lib/transfer/dataset-transfer-access.server.js +45 -0
  41. package/src/lib/transfer/dataset-transfer-access.server.js.map +1 -0
  42. package/src/lib/transfer/dataset-transfer-resource.js +2 -1
  43. package/src/lib/transfer/dataset-transfer-resource.js.map +1 -1
@@ -14,7 +14,9 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { type OrgPermission, resolveOrgPermissions } from '@aglyn/aglyn/app-utils/org-permissions';
17
+ import { type AglynOrgCustomRole, type OrgPermission, resolveOrgPermissions } from '@aglyn/aglyn/app-utils/org-permissions';
18
+ import { type ScopePlaced } from '@aglyn/aglyn/app-utils/site-placement';
19
+ import type { TransferInstanceImportAnswer, TransferInstanceImportSubject } from '@aglyn/aglyn/plugin-manager/plugin-transfer-resources';
18
20
  /** What the doors read off a membership document. */
19
21
  type DatasetWriter = NonNullable<Parameters<typeof resolveOrgPermissions>[0]> & {
20
22
  resolvedPermissions?: Readonly<Record<string, unknown>>;
@@ -26,22 +28,58 @@ export declare const DATASETS_WRITE_PERMISSION: OrgPermission;
26
28
  export declare const DATASETS_DELETE_PERMISSION: OrgPermission;
27
29
  export declare const DATASETS_WRITE_REFUSAL: string;
28
30
  export declare const DATASETS_DELETE_REFUSAL: string;
31
+ export declare const DATASETS_VIEW_RECORDS_REFUSAL: string;
32
+ export declare const DATASETS_EXPORT_REFUSAL: string;
29
33
  /**
30
- * A member's answer for a dataset key (AGL-4047), as the rules' `canWriteOrgDatasets`
34
+ * A member's answer for a dataset key (AGL-4047), as the rules' `memberKeyOrOverride`
31
35
  * and the routes' `memberHasOrgPermission` read it: the decision written on
32
36
  * `resolvedPermissions`, or, for a member the projection never stamped, on their
33
- * own `permissions`; else their workspace role's default. A workspace key: no
34
- * site narrows it, so a site's Data page asks the same thing as the workspace's.
37
+ * own `permissions`; else their workspace role's default.
35
38
  */
36
39
  export declare function holdsDatasetPermission(member: DatasetWriter, permission: OrgPermission): boolean;
37
- /**
38
- * Which dataset writes the signed-in member is known not to hold, so those
39
- * controls switch off with the permission named rather than failing on save.
40
- * Neither is blocked until the read lands, nor for a reader with no membership,
41
- * who is staff. Not a security boundary: the rules and routes refuse regardless.
42
- */
43
- export declare function useDatasetWritesBlocked(orgId: string | null | undefined): {
40
+ /** What the signed-in member is known not to be able to do with a dataset, and why. */
41
+ export interface DatasetAccessBlocked {
42
+ /** Whether these answers rest on the member's reads, rather than on their not having landed. */
43
+ known: boolean;
44
+ /** Making a new dataset: "Manage data". */
45
+ creates: boolean;
46
+ /** Changing this dataset's schema or records, or importing into it. */
44
47
  writes: boolean;
48
+ writesReason: string;
49
+ /**
50
+ * The writes are off, and changing who it is shared with stays this member's:
51
+ * they hold "Manage data" across every site, and a site narrows them on the one
52
+ * this dataset sits on. Sharing is not among what a narrowing takes.
53
+ */
54
+ sharingOnly: boolean;
55
+ /** Deleting this dataset. */
45
56
  deletes: boolean;
46
- };
57
+ deletesReason: string;
58
+ /** Reading this dataset's records. */
59
+ records: boolean;
60
+ /** Taking this dataset's records out as a file. */
61
+ exports: boolean;
62
+ }
63
+ /**
64
+ * The verdict for a member and a dataset, as its document places it, as the rule's
65
+ * `canWriteDatasetOn` and the routes' `memberMayActOnDataset` give it, resolved
66
+ * from what the site's stamp is written from. `customRole` is the member's custom
67
+ * role when they carry one and it was read.
68
+ */
69
+ export declare function datasetAccessBlocked(member: DatasetWriter, placed: ScopePlaced | null | undefined, customRole?: AglynOrgCustomRole | null): DatasetAccessBlocked;
70
+ /**
71
+ * Importing into one dataset, for the Import & export hub's row (AGL-4047): the
72
+ * same verdict the Data page's Import reads, and the transfer routes' `importAccess`.
73
+ */
74
+ export declare function datasetInstanceImportAccess(subject: TransferInstanceImportSubject): TransferInstanceImportAnswer;
75
+ /**
76
+ * Which dataset controls switch off with the reason named rather than failing on
77
+ * save, for this dataset, as its document places it. Nothing is blocked until the reads
78
+ * land, nor for a reader with no membership, who is staff. Not a security
79
+ * boundary: the rules and routes refuse regardless.
80
+ *
81
+ * Costs the membership the page already reads, and one read of a custom role
82
+ * only for a member of the whole workspace whom the site decides.
83
+ */
84
+ export declare function useDatasetWritesBlocked(orgId: string | null | undefined, placed?: ScopePlaced | null): DatasetAccessBlocked;
47
85
  export {};
@@ -14,18 +14,23 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */ import { permissionRefusalText, resolveOrgPermissions } from "@aglyn/aglyn/app-utils/org-permissions";
17
+ import { siteMayNarrow } from "@aglyn/aglyn/app-utils/host-permissions";
18
+ import { isOrgWideMember } from "@aglyn/aglyn/app-utils/organizations";
19
+ import { deleteBeyondReach, deleteBeyondReachRefusal, oneSitePlacement, placementVerdict, resolvedPlacementKey } from "@aglyn/aglyn/app-utils/site-placement";
17
20
  import { useFirestore, useFirestoreDoc, useUser } from "@aglyn/tenant-feature-instance";
18
21
  import { doc } from "firebase/firestore";
19
- /** Creating, editing and sharing datasets, and every record write. */ export const DATASETS_WRITE_PERMISSION = 'data.manage';
20
- /** Deleting a whole dataset, which the erase route asks. */ export const DATASETS_DELETE_PERMISSION = 'org.eraseRecords';
22
+ import { DATA_ERASE_PERMISSION, DATA_EXPORT_PERMISSION, DATA_MANAGE_PERMISSION, DATA_SITE_DELETE_PERMISSION, DATA_SITE_MANAGE_PERMISSION, DATA_VIEW_RECORDS_PERMISSION, dataPermissionRefusal } from "../model/dataset-access.js";
23
+ /** Creating, editing and sharing datasets, and every record write. */ export const DATASETS_WRITE_PERMISSION = DATA_MANAGE_PERMISSION;
24
+ /** Deleting a whole dataset, which the erase route asks. */ export const DATASETS_DELETE_PERMISSION = DATA_ERASE_PERMISSION;
21
25
  export const DATASETS_WRITE_REFUSAL = permissionRefusalText(DATASETS_WRITE_PERMISSION);
22
26
  export const DATASETS_DELETE_REFUSAL = permissionRefusalText(DATASETS_DELETE_PERMISSION);
27
+ export const DATASETS_VIEW_RECORDS_REFUSAL = dataPermissionRefusal(DATA_VIEW_RECORDS_PERMISSION);
28
+ export const DATASETS_EXPORT_REFUSAL = dataPermissionRefusal(DATA_EXPORT_PERMISSION);
23
29
  /**
24
- * A member's answer for a dataset key (AGL-4047), as the rules' `canWriteOrgDatasets`
30
+ * A member's answer for a dataset key (AGL-4047), as the rules' `memberKeyOrOverride`
25
31
  * and the routes' `memberHasOrgPermission` read it: the decision written on
26
32
  * `resolvedPermissions`, or, for a member the projection never stamped, on their
27
- * own `permissions`; else their workspace role's default. A workspace key: no
28
- * site narrows it, so a site's Data page asks the same thing as the workspace's.
33
+ * own `permissions`; else their workspace role's default.
29
34
  */ export function holdsDatasetPermission(member, permission) {
30
35
  var _member_resolvedPermissions;
31
36
  var _this;
@@ -33,13 +38,71 @@ export const DATASETS_DELETE_REFUSAL = permissionRefusalText(DATASETS_DELETE_PER
33
38
  if (typeof stamped === 'boolean') return stamped;
34
39
  return resolveOrgPermissions(member)[permission] === true;
35
40
  }
41
+ const NOTHING_BLOCKED = {
42
+ known: false,
43
+ creates: false,
44
+ writes: false,
45
+ writesReason: DATASETS_WRITE_REFUSAL,
46
+ sharingOnly: false,
47
+ deletes: false,
48
+ deletesReason: DATASETS_DELETE_REFUSAL,
49
+ records: false,
50
+ exports: false
51
+ };
36
52
  /**
37
- * Which dataset writes the signed-in member is known not to hold, so those
38
- * controls switch off with the permission named rather than failing on save.
39
- * Neither is blocked until the read lands, nor for a reader with no membership,
40
- * who is staff. Not a security boundary: the rules and routes refuse regardless.
41
- */ export function useDatasetWritesBlocked(orgId) {
42
- var _ref;
53
+ * The verdict for a member and a dataset, as its document places it, as the rule's
54
+ * `canWriteDatasetOn` and the routes' `memberMayActOnDataset` give it, resolved
55
+ * from what the site's stamp is written from. `customRole` is the member's custom
56
+ * role when they carry one and it was read.
57
+ */ export function datasetAccessBlocked(member, placed, customRole) {
58
+ const seat = member;
59
+ const site = oneSitePlacement(placed);
60
+ const writes = placementVerdict({
61
+ member: seat,
62
+ placed,
63
+ workspace: holdsDatasetPermission(member, DATA_MANAGE_PERMISSION),
64
+ site: (hostId)=>resolvedPlacementKey(seat, hostId, DATA_SITE_MANAGE_PERMISSION, customRole)
65
+ });
66
+ const deletes = placementVerdict({
67
+ member: seat,
68
+ placed,
69
+ workspace: holdsDatasetPermission(member, DATA_ERASE_PERMISSION),
70
+ site: (hostId)=>resolvedPlacementKey(seat, hostId, DATA_SITE_DELETE_PERMISSION, customRole)
71
+ });
72
+ const beyond = deleteBeyondReach(seat, placed);
73
+ const holdsManage = holdsDatasetPermission(member, DATA_MANAGE_PERMISSION);
74
+ return {
75
+ known: true,
76
+ creates: !holdsManage,
77
+ writes: !writes,
78
+ sharingOnly: !writes && holdsManage && isOrgWideMember(seat),
79
+ writesReason: site ? dataPermissionRefusal(DATA_SITE_MANAGE_PERMISSION) : DATASETS_WRITE_REFUSAL,
80
+ deletes: beyond || !deletes,
81
+ deletesReason: beyond ? deleteBeyondReachRefusal('dataset') : site ? dataPermissionRefusal(DATA_SITE_DELETE_PERMISSION) : DATASETS_DELETE_REFUSAL,
82
+ records: !holdsDatasetPermission(member, DATA_VIEW_RECORDS_PERMISSION),
83
+ exports: !holdsDatasetPermission(member, DATA_EXPORT_PERMISSION)
84
+ };
85
+ }
86
+ /**
87
+ * Importing into one dataset, for the Import & export hub's row (AGL-4047): the
88
+ * same verdict the Data page's Import reads, and the transfer routes' `importAccess`.
89
+ */ export function datasetInstanceImportAccess(subject) {
90
+ const blocked = datasetAccessBlocked(subject.member, subject.record.facts, subject.customRole);
91
+ return {
92
+ allowed: !blocked.writes,
93
+ reason: blocked.writesReason
94
+ };
95
+ }
96
+ /**
97
+ * Which dataset controls switch off with the reason named rather than failing on
98
+ * save, for this dataset, as its document places it. Nothing is blocked until the reads
99
+ * land, nor for a reader with no membership, who is staff. Not a security
100
+ * boundary: the rules and routes refuse regardless.
101
+ *
102
+ * Costs the membership the page already reads, and one read of a custom role
103
+ * only for a member of the whole workspace whom the site decides.
104
+ */ export function useDatasetWritesBlocked(orgId, placed) {
105
+ var _ref, _role_data;
43
106
  const firestore = useFirestore();
44
107
  const { data: user } = useUser();
45
108
  const uid = (_ref = user == null ? void 0 : user.uid) != null ? _ref : '';
@@ -48,14 +111,18 @@ export const DATASETS_DELETE_REFUSAL = permissionRefusalText(DATASETS_DELETE_PER
48
111
  orgId,
49
112
  uid
50
113
  ]);
51
- if (status !== 'success' || !member) return {
52
- writes: false,
53
- deletes: false
54
- };
55
- return {
56
- writes: !holdsDatasetPermission(member, DATASETS_WRITE_PERMISSION),
57
- deletes: !holdsDatasetPermission(member, DATASETS_DELETE_PERMISSION)
58
- };
114
+ const seat = status === 'success' ? member : null;
115
+ const site = oneSitePlacement(placed);
116
+ // Only someone the site decides: narrowed on it, or on a role wider or narrower here.
117
+ const siteDecides = Boolean(seat && site) && isOrgWideMember(seat) && (Boolean(siteMayNarrow(seat, site)) || !holdsDatasetPermission(seat, DATA_MANAGE_PERMISSION));
118
+ const roleId = siteDecides && typeof (seat == null ? void 0 : seat.roleId) === 'string' ? seat.roleId : '';
119
+ const role = useFirestoreDoc(()=>orgId && roleId ? doc(firestore, 'orgs', orgId, 'roles', roleId) : null, [
120
+ firestore,
121
+ orgId,
122
+ roleId
123
+ ]);
124
+ if (!seat || roleId && role.status === 'loading') return NOTHING_BLOCKED;
125
+ return datasetAccessBlocked(seat, placed, roleId && role.status === 'success' ? (_role_data = role.data) != null ? _role_data : null : null);
59
126
  }
60
127
 
61
128
  //# sourceMappingURL=use-dataset-writes-blocked.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/components/use-dataset-writes-blocked.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 {\n type OrgPermission,\n permissionRefusalText,\n resolveOrgPermissions,\n} from '@aglyn/aglyn/app-utils/org-permissions'\nimport { useFirestore, useFirestoreDoc, useUser } from '@aglyn/tenant-feature-instance'\nimport { doc } from 'firebase/firestore'\n\n/** What the doors read off a membership document. */\ntype DatasetWriter = NonNullable<Parameters<typeof resolveOrgPermissions>[0]> & {\n resolvedPermissions?: Readonly<Record<string, unknown>>\n permissions?: Readonly<Record<string, unknown>>\n}\n\n/** Creating, editing and sharing datasets, and every record write. */\nexport const DATASETS_WRITE_PERMISSION: OrgPermission = 'data.manage'\n/** Deleting a whole dataset, which the erase route asks. */\nexport const DATASETS_DELETE_PERMISSION: OrgPermission = 'org.eraseRecords'\n\nexport const DATASETS_WRITE_REFUSAL = permissionRefusalText(DATASETS_WRITE_PERMISSION)\nexport const DATASETS_DELETE_REFUSAL = permissionRefusalText(DATASETS_DELETE_PERMISSION)\n\n/**\n * A member's answer for a dataset key (AGL-4047), as the rules' `canWriteOrgDatasets`\n * and the routes' `memberHasOrgPermission` read it: the decision written on\n * `resolvedPermissions`, or, for a member the projection never stamped, on their\n * own `permissions`; else their workspace role's default. A workspace key: no\n * site narrows it, so a site's Data page asks the same thing as the workspace's.\n */\nexport function holdsDatasetPermission(member: DatasetWriter, permission: OrgPermission): boolean {\n const stamped = (member.resolvedPermissions ?? member.permissions)?.[permission]\n if (typeof stamped === 'boolean') return stamped\n return resolveOrgPermissions(member)[permission] === true\n}\n\n/**\n * Which dataset writes the signed-in member is known not to hold, so those\n * controls switch off with the permission named rather than failing on save.\n * Neither is blocked until the read lands, nor for a reader with no membership,\n * who is staff. Not a security boundary: the rules and routes refuse regardless.\n */\nexport function useDatasetWritesBlocked(orgId: string | null | undefined): {\n writes: boolean\n deletes: boolean\n} {\n const firestore = useFirestore()\n const { data: user } = useUser()\n const uid = (user as { uid?: string } | undefined)?.uid ?? ''\n const { data: member, status } = useFirestoreDoc<DatasetWriter>(\n () => (orgId && uid ? doc(firestore, 'orgs', orgId, 'members', uid) : null),\n [firestore, orgId, uid],\n )\n if (status !== 'success' || !member) return { writes: false, deletes: false }\n return {\n writes: !holdsDatasetPermission(member, DATASETS_WRITE_PERMISSION),\n deletes: !holdsDatasetPermission(member, DATASETS_DELETE_PERMISSION),\n }\n}\n"],"names":["permissionRefusalText","resolveOrgPermissions","useFirestore","useFirestoreDoc","useUser","doc","DATASETS_WRITE_PERMISSION","DATASETS_DELETE_PERMISSION","DATASETS_WRITE_REFUSAL","DATASETS_DELETE_REFUSAL","holdsDatasetPermission","member","permission","stamped","resolvedPermissions","permissions","useDatasetWritesBlocked","orgId","firestore","data","user","uid","status","writes","deletes"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAEEA,qBAAqB,EACrBC,qBAAqB,QAChB,yCAAwC;AAC/C,SAASC,YAAY,EAAEC,eAAe,EAAEC,OAAO,QAAQ,iCAAgC;AACvF,SAASC,GAAG,QAAQ,qBAAoB;AAQxC,oEAAoE,GACpE,OAAO,MAAMC,4BAA2C,cAAa;AACrE,0DAA0D,GAC1D,OAAO,MAAMC,6BAA4C,mBAAkB;AAE3E,OAAO,MAAMC,yBAAyBR,sBAAsBM,2BAA0B;AACtF,OAAO,MAAMG,0BAA0BT,sBAAsBO,4BAA2B;AAExF;;;;;;CAMC,GACD,OAAO,SAASG,uBAAuBC,MAAqB,EAAEC,UAAyB;QACpED;QAAAA;IAAjB,MAAME,WAAWF,SAAAA,8BAAAA,OAAOG,mBAAmB,YAA1BH,8BAA8BA,OAAOI,WAAW,qBAAjD,AAACJ,KAAmD,CAACC,WAAW;IAChF,IAAI,OAAOC,YAAY,WAAW,OAAOA;IACzC,OAAOZ,sBAAsBU,OAAO,CAACC,WAAW,KAAK;AACvD;AAEA;;;;;CAKC,GACD,OAAO,SAASI,wBAAwBC,KAAgC;;IAItE,MAAMC,YAAYhB;IAClB,MAAM,EAAEiB,MAAMC,IAAI,EAAE,GAAGhB;IACvB,MAAMiB,cAAOD,wBAAD,AAACA,KAAuCC,GAAG,mBAAI;IAC3D,MAAM,EAAEF,MAAMR,MAAM,EAAEW,MAAM,EAAE,GAAGnB,gBAC/B,IAAOc,SAASI,MAAMhB,IAAIa,WAAW,QAAQD,OAAO,WAAWI,OAAO,MACtE;QAACH;QAAWD;QAAOI;KAAI;IAEzB,IAAIC,WAAW,aAAa,CAACX,QAAQ,OAAO;QAAEY,QAAQ;QAAOC,SAAS;IAAM;IAC5E,OAAO;QACLD,QAAQ,CAACb,uBAAuBC,QAAQL;QACxCkB,SAAS,CAACd,uBAAuBC,QAAQJ;IAC3C;AACF"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/components/use-dataset-writes-blocked.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 {\n type AglynOrgCustomRole,\n type OrgPermission,\n permissionRefusalText,\n resolveOrgPermissions,\n} from '@aglyn/aglyn/app-utils/org-permissions'\nimport { siteMayNarrow } from '@aglyn/aglyn/app-utils/host-permissions'\nimport { isOrgWideMember } from '@aglyn/aglyn/app-utils/organizations'\nimport {\n deleteBeyondReach,\n deleteBeyondReachRefusal,\n oneSitePlacement,\n placementVerdict,\n resolvedPlacementKey,\n type ScopePlaced,\n} from '@aglyn/aglyn/app-utils/site-placement'\nimport type { AglynOrgMember } from '@aglyn/aglyn/foundation/definitions/organization.types'\nimport type {\n TransferInstanceImportAnswer,\n TransferInstanceImportSubject,\n} from '@aglyn/aglyn/plugin-manager/plugin-transfer-resources'\nimport { useFirestore, useFirestoreDoc, useUser } from '@aglyn/tenant-feature-instance'\nimport { doc } from 'firebase/firestore'\nimport {\n DATA_ERASE_PERMISSION,\n DATA_EXPORT_PERMISSION,\n DATA_MANAGE_PERMISSION,\n DATA_SITE_DELETE_PERMISSION,\n DATA_SITE_MANAGE_PERMISSION,\n DATA_VIEW_RECORDS_PERMISSION,\n dataPermissionRefusal,\n} from '../model/dataset-access'\n\n/** What the doors read off a membership document. */\ntype DatasetWriter = NonNullable<Parameters<typeof resolveOrgPermissions>[0]> & {\n resolvedPermissions?: Readonly<Record<string, unknown>>\n permissions?: Readonly<Record<string, unknown>>\n}\n\n/** Creating, editing and sharing datasets, and every record write. */\nexport const DATASETS_WRITE_PERMISSION: OrgPermission = DATA_MANAGE_PERMISSION\n/** Deleting a whole dataset, which the erase route asks. */\nexport const DATASETS_DELETE_PERMISSION: OrgPermission = DATA_ERASE_PERMISSION\n\nexport const DATASETS_WRITE_REFUSAL = permissionRefusalText(DATASETS_WRITE_PERMISSION)\nexport const DATASETS_DELETE_REFUSAL = permissionRefusalText(DATASETS_DELETE_PERMISSION)\nexport const DATASETS_VIEW_RECORDS_REFUSAL = dataPermissionRefusal(DATA_VIEW_RECORDS_PERMISSION)\nexport const DATASETS_EXPORT_REFUSAL = dataPermissionRefusal(DATA_EXPORT_PERMISSION)\n\n/**\n * A member's answer for a dataset key (AGL-4047), as the rules' `memberKeyOrOverride`\n * and the routes' `memberHasOrgPermission` read it: the decision written on\n * `resolvedPermissions`, or, for a member the projection never stamped, on their\n * own `permissions`; else their workspace role's default.\n */\nexport function holdsDatasetPermission(member: DatasetWriter, permission: OrgPermission): boolean {\n const stamped = (member.resolvedPermissions ?? member.permissions)?.[permission]\n if (typeof stamped === 'boolean') return stamped\n return resolveOrgPermissions(member)[permission] === true\n}\n\n/** What the signed-in member is known not to be able to do with a dataset, and why. */\nexport interface DatasetAccessBlocked {\n /** Whether these answers rest on the member's reads, rather than on their not having landed. */\n known: boolean\n /** Making a new dataset: \"Manage data\". */\n creates: boolean\n /** Changing this dataset's schema or records, or importing into it. */\n writes: boolean\n writesReason: string\n /**\n * The writes are off, and changing who it is shared with stays this member's:\n * they hold \"Manage data\" across every site, and a site narrows them on the one\n * this dataset sits on. Sharing is not among what a narrowing takes.\n */\n sharingOnly: boolean\n /** Deleting this dataset. */\n deletes: boolean\n deletesReason: string\n /** Reading this dataset's records. */\n records: boolean\n /** Taking this dataset's records out as a file. */\n exports: boolean\n}\n\nconst NOTHING_BLOCKED: DatasetAccessBlocked = {\n known: false,\n creates: false,\n writes: false,\n writesReason: DATASETS_WRITE_REFUSAL,\n sharingOnly: false,\n deletes: false,\n deletesReason: DATASETS_DELETE_REFUSAL,\n records: false,\n exports: false,\n}\n\n/**\n * The verdict for a member and a dataset, as its document places it, as the rule's\n * `canWriteDatasetOn` and the routes' `memberMayActOnDataset` give it, resolved\n * from what the site's stamp is written from. `customRole` is the member's custom\n * role when they carry one and it was read.\n */\nexport function datasetAccessBlocked(\n member: DatasetWriter,\n placed: ScopePlaced | null | undefined,\n customRole?: AglynOrgCustomRole | null,\n): DatasetAccessBlocked {\n const seat = member as Partial<AglynOrgMember>\n const site = oneSitePlacement(placed)\n const writes = placementVerdict<boolean>({\n member: seat,\n placed,\n workspace: holdsDatasetPermission(member, DATA_MANAGE_PERMISSION),\n site: (hostId) => resolvedPlacementKey(seat, hostId, DATA_SITE_MANAGE_PERMISSION, customRole),\n })\n const deletes = placementVerdict<boolean>({\n member: seat,\n placed,\n workspace: holdsDatasetPermission(member, DATA_ERASE_PERMISSION),\n site: (hostId) => resolvedPlacementKey(seat, hostId, DATA_SITE_DELETE_PERMISSION, customRole),\n })\n const beyond = deleteBeyondReach(seat, placed)\n const holdsManage = holdsDatasetPermission(member, DATA_MANAGE_PERMISSION)\n return {\n known: true,\n creates: !holdsManage,\n writes: !writes,\n sharingOnly: !writes && holdsManage && isOrgWideMember(seat),\n writesReason: site ? dataPermissionRefusal(DATA_SITE_MANAGE_PERMISSION) : DATASETS_WRITE_REFUSAL,\n deletes: beyond || !deletes,\n deletesReason: beyond\n ? deleteBeyondReachRefusal('dataset')\n : site\n ? dataPermissionRefusal(DATA_SITE_DELETE_PERMISSION)\n : DATASETS_DELETE_REFUSAL,\n records: !holdsDatasetPermission(member, DATA_VIEW_RECORDS_PERMISSION),\n exports: !holdsDatasetPermission(member, DATA_EXPORT_PERMISSION),\n }\n}\n\n/**\n * Importing into one dataset, for the Import & export hub's row (AGL-4047): the\n * same verdict the Data page's Import reads, and the transfer routes' `importAccess`.\n */\nexport function datasetInstanceImportAccess(subject: TransferInstanceImportSubject): TransferInstanceImportAnswer {\n const blocked = datasetAccessBlocked(\n subject.member as DatasetWriter,\n subject.record.facts,\n subject.customRole as AglynOrgCustomRole | null,\n )\n return { allowed: !blocked.writes, reason: blocked.writesReason }\n}\n\n/**\n * Which dataset controls switch off with the reason named rather than failing on\n * save, for this dataset, as its document places it. Nothing is blocked until the reads\n * land, nor for a reader with no membership, who is staff. Not a security\n * boundary: the rules and routes refuse regardless.\n *\n * Costs the membership the page already reads, and one read of a custom role\n * only for a member of the whole workspace whom the site decides.\n */\nexport function useDatasetWritesBlocked(\n orgId: string | null | undefined,\n placed?: ScopePlaced | null,\n): DatasetAccessBlocked {\n const firestore = useFirestore()\n const { data: user } = useUser()\n const uid = (user as { uid?: string } | undefined)?.uid ?? ''\n const { data: member, status } = useFirestoreDoc<DatasetWriter>(\n () => (orgId && uid ? doc(firestore, 'orgs', orgId, 'members', uid) : null),\n [firestore, orgId, uid],\n )\n const seat = (status === 'success' ? member : null) as (DatasetWriter & { roleId?: unknown }) | null | undefined\n const site = oneSitePlacement(placed)\n // Only someone the site decides: narrowed on it, or on a role wider or narrower here.\n const siteDecides =\n Boolean(seat && site) &&\n isOrgWideMember(seat as Partial<AglynOrgMember>) &&\n (Boolean(siteMayNarrow(seat as Partial<AglynOrgMember>, site)) || !holdsDatasetPermission(seat as DatasetWriter, DATA_MANAGE_PERMISSION))\n const roleId = siteDecides && typeof seat?.roleId === 'string' ? seat.roleId : ''\n const role = useFirestoreDoc<AglynOrgCustomRole>(\n () => (orgId && roleId ? doc(firestore, 'orgs', orgId, 'roles', roleId) : null),\n [firestore, orgId, roleId],\n )\n if (!seat || (roleId && role.status === 'loading')) return NOTHING_BLOCKED\n return datasetAccessBlocked(seat, placed, roleId && role.status === 'success' ? (role.data ?? null) : null)\n}\n"],"names":["permissionRefusalText","resolveOrgPermissions","siteMayNarrow","isOrgWideMember","deleteBeyondReach","deleteBeyondReachRefusal","oneSitePlacement","placementVerdict","resolvedPlacementKey","useFirestore","useFirestoreDoc","useUser","doc","DATA_ERASE_PERMISSION","DATA_EXPORT_PERMISSION","DATA_MANAGE_PERMISSION","DATA_SITE_DELETE_PERMISSION","DATA_SITE_MANAGE_PERMISSION","DATA_VIEW_RECORDS_PERMISSION","dataPermissionRefusal","DATASETS_WRITE_PERMISSION","DATASETS_DELETE_PERMISSION","DATASETS_WRITE_REFUSAL","DATASETS_DELETE_REFUSAL","DATASETS_VIEW_RECORDS_REFUSAL","DATASETS_EXPORT_REFUSAL","holdsDatasetPermission","member","permission","stamped","resolvedPermissions","permissions","NOTHING_BLOCKED","known","creates","writes","writesReason","sharingOnly","deletes","deletesReason","records","exports","datasetAccessBlocked","placed","customRole","seat","site","workspace","hostId","beyond","holdsManage","datasetInstanceImportAccess","subject","blocked","record","facts","allowed","reason","useDatasetWritesBlocked","orgId","role","firestore","data","user","uid","status","siteDecides","Boolean","roleId"],"mappings":"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"}
@@ -0,0 +1,25 @@
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
+ /**
18
+ * The plugin's DECLARATIONS (AGL-4047): the dataset keys the one permission
19
+ * catalog lists beside the core keys. Loaded eagerly by the console (client and
20
+ * server) and the tenant's server through the generated declarations manifest,
21
+ * so the role editor offers them, a custom role or a per-member override keeps
22
+ * them, and the site's stamp carries them. Light by construction: nothing here
23
+ * reaches a provider, Firestore or React.
24
+ */
25
+ export declare function registerDataDeclarations(): void;
@@ -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
+ */ import { registerPluginEntitlements } from "@aglyn/aglyn/plugin-manager/plugin-entitlements";
17
+ import { BUNDLE_ID } from "./constants/bundle-common.js";
18
+ import { DATA_PERMISSIONS } from "./model/dataset-access.js";
19
+ let declared = false;
20
+ /**
21
+ * The plugin's DECLARATIONS (AGL-4047): the dataset keys the one permission
22
+ * catalog lists beside the core keys. Loaded eagerly by the console (client and
23
+ * server) and the tenant's server through the generated declarations manifest,
24
+ * so the role editor offers them, a custom role or a per-member override keeps
25
+ * them, and the site's stamp carries them. Light by construction: nothing here
26
+ * reaches a provider, Firestore or React.
27
+ */ export function registerDataDeclarations() {
28
+ if (declared) return;
29
+ declared = true;
30
+ registerPluginEntitlements({
31
+ pluginId: BUNDLE_ID,
32
+ orgPermissions: DATA_PERMISSIONS
33
+ });
34
+ }
35
+ registerDataDeclarations();
36
+
37
+ //# sourceMappingURL=declarations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../libs/plugins/data/src/lib/declarations.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 { registerPluginEntitlements } from '@aglyn/aglyn/plugin-manager/plugin-entitlements'\nimport { BUNDLE_ID } from './constants/bundle-common'\nimport { DATA_PERMISSIONS } from './model/dataset-access'\n\nlet declared = false\n\n/**\n * The plugin's DECLARATIONS (AGL-4047): the dataset keys the one permission\n * catalog lists beside the core keys. Loaded eagerly by the console (client and\n * server) and the tenant's server through the generated declarations manifest,\n * so the role editor offers them, a custom role or a per-member override keeps\n * them, and the site's stamp carries them. Light by construction: nothing here\n * reaches a provider, Firestore or React.\n */\nexport function registerDataDeclarations(): void {\n if (declared) return\n declared = true\n registerPluginEntitlements({ pluginId: BUNDLE_ID, orgPermissions: DATA_PERMISSIONS })\n}\n\nregisterDataDeclarations()\n"],"names":["registerPluginEntitlements","BUNDLE_ID","DATA_PERMISSIONS","declared","registerDataDeclarations","pluginId","orgPermissions"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,0BAA0B,QAAQ,kDAAiD;AAC5F,SAASC,SAAS,QAAQ,+BAA2B;AACrD,SAASC,gBAAgB,QAAQ,4BAAwB;AAEzD,IAAIC,WAAW;AAEf;;;;;;;CAOC,GACD,OAAO,SAASC;IACd,IAAID,UAAU;IACdA,WAAW;IACXH,2BAA2B;QAAEK,UAAUJ;QAAWK,gBAAgBJ;IAAiB;AACrF;AAEAE"}
@@ -0,0 +1,34 @@
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
+ import type { PluginOrgPermissionDeclaration } from '@aglyn/aglyn/plugin-manager/plugin-entitlements';
19
+ /** The workspace key on creating and writing datasets, which also covers the CRM and lists. */
20
+ export declare const DATA_MANAGE_PERMISSION = "data.manage";
21
+ /** The workspace key on deleting a whole dataset, which also covers contacts and lists. */
22
+ export declare const DATA_ERASE_PERMISSION = "org.eraseRecords";
23
+ /** The site's verdict on writing a dataset placed on that site alone. */
24
+ export declare const DATA_SITE_MANAGE_PERMISSION = "data.siteManage";
25
+ /** The site's verdict on deleting a dataset placed on that site alone. */
26
+ export declare const DATA_SITE_DELETE_PERMISSION = "data.siteDelete";
27
+ /** Reading a dataset's records. */
28
+ export declare const DATA_VIEW_RECORDS_PERMISSION = "data.viewRecords";
29
+ /** Taking a dataset's records out as a file. */
30
+ export declare const DATA_EXPORT_PERMISSION = "data.export";
31
+ /** Who holds the site's verdict by their access to it: the site's Admin and Editor. */
32
+ export declare const DATA_SITE_ROLE_PRESET: Readonly<Record<HostAccessRole, boolean>>;
33
+ /** The keys as this plugin declares them into the permission catalog. */
34
+ export declare const DATA_PERMISSIONS: readonly PluginOrgPermissionDeclaration[];
@@ -0,0 +1,108 @@
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
+ * WHO MAY DO WHAT TO A DATASET (AGL-4047). Roles are only presets of these.
18
+ *
19
+ * A dataset placed on exactly one site belongs to that site, and its writes
20
+ * answer to that site's verdict as well as the workspace's (`site-placement` in
21
+ * the platform core is the verdict):
22
+ *
23
+ * - "Manage this site's data" and "Delete this site's datasets" are the site's
24
+ * verdict. For a member of the whole workspace each follows its workspace
25
+ * key ("Manage data", "Delete workspace records"), so a role or a member
26
+ * deciding those decides these. A site that narrows an editor to Author or
27
+ * Viewer takes them there, unless the member keeps them ("Keep this
28
+ * permission") or the site grants them back. A site that raises a viewer to
29
+ * Admin or Editor gives them. A site collaborator holds them by their site
30
+ * role, refined by the site's toggle.
31
+ * - Holding the workspace key still admits, on any site that does not narrow
32
+ * the member, so a collaborator handed "Manage data" keeps what it gave them.
33
+ *
34
+ * A dataset on every site or on several answers to the workspace key alone: no
35
+ * one site can be asked, and a rule cannot look through a list of them.
36
+ *
37
+ * Three doors ask this, and must keep answering alike: the rule's
38
+ * `canWriteDatasetOn` (`firebase-firestore.rules`), the routes through
39
+ * `dataset-access.server.ts`, and the console through `use-dataset-writes-blocked`.
40
+ */ /** The workspace key on creating and writing datasets, which also covers the CRM and lists. */ export const DATA_MANAGE_PERMISSION = 'data.manage';
41
+ /** The workspace key on deleting a whole dataset, which also covers contacts and lists. */ export const DATA_ERASE_PERMISSION = 'org.eraseRecords';
42
+ /** The site's verdict on writing a dataset placed on that site alone. */ export const DATA_SITE_MANAGE_PERMISSION = 'data.siteManage';
43
+ /** The site's verdict on deleting a dataset placed on that site alone. */ export const DATA_SITE_DELETE_PERMISSION = 'data.siteDelete';
44
+ /** Reading a dataset's records. */ export const DATA_VIEW_RECORDS_PERMISSION = 'data.viewRecords';
45
+ /** Taking a dataset's records out as a file. */ export const DATA_EXPORT_PERMISSION = 'data.export';
46
+ /** Who holds the site's verdict by their access to it: the site's Admin and Editor. */ export const DATA_SITE_ROLE_PRESET = {
47
+ admin: true,
48
+ editor: true,
49
+ author: false,
50
+ viewer: false
51
+ };
52
+ const WORKSPACE_WRITERS = {
53
+ owner: true,
54
+ admin: true,
55
+ editor: true,
56
+ viewer: false
57
+ };
58
+ const EVERY_ROLE = {
59
+ owner: true,
60
+ admin: true,
61
+ editor: true,
62
+ viewer: true
63
+ };
64
+ /** The keys as this plugin declares them into the permission catalog. */ export const DATA_PERMISSIONS = [
65
+ {
66
+ key: DATA_SITE_MANAGE_PERMISSION,
67
+ label: 'Manage this site’s data',
68
+ description: 'Change the schema and records of a dataset placed on this site alone, and import into it. Follows “Manage data” for a member of the whole workspace.',
69
+ roleDefaults: WORKSPACE_WRITERS,
70
+ hostRoleDefaults: DATA_SITE_ROLE_PRESET,
71
+ group: 'datasets',
72
+ follows: DATA_MANAGE_PERMISSION,
73
+ narrowsPerSite: {
74
+ editor: true
75
+ },
76
+ raisesPerSite: true
77
+ },
78
+ {
79
+ key: DATA_SITE_DELETE_PERMISSION,
80
+ label: 'Delete this site’s datasets',
81
+ description: 'Delete a dataset placed on this site alone, with its records. Follows “Delete workspace records” for a member of the whole workspace.',
82
+ roleDefaults: WORKSPACE_WRITERS,
83
+ hostRoleDefaults: DATA_SITE_ROLE_PRESET,
84
+ group: 'datasets',
85
+ follows: DATA_ERASE_PERMISSION,
86
+ narrowsPerSite: {
87
+ editor: true
88
+ },
89
+ raisesPerSite: true
90
+ },
91
+ {
92
+ key: DATA_VIEW_RECORDS_PERMISSION,
93
+ label: 'View dataset records',
94
+ description: 'Read the records of the datasets this member can see. Published sites show records either way.',
95
+ roleDefaults: EVERY_ROLE,
96
+ group: 'datasets'
97
+ },
98
+ {
99
+ key: DATA_EXPORT_PERMISSION,
100
+ label: 'Export data',
101
+ description: 'Take the records of the datasets this member can see out as a file. Needs “View dataset records”.',
102
+ roleDefaults: EVERY_ROLE,
103
+ group: 'datasets',
104
+ refines: DATA_VIEW_RECORDS_PERMISSION
105
+ }
106
+ ];
107
+
108
+ //# sourceMappingURL=data-permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/model/data-permissions.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 { HostAccessRole } from '@aglyn/aglyn/foundation/definitions/organization.types'\nimport type { PluginOrgPermissionDeclaration } from '@aglyn/aglyn/plugin-manager/plugin-entitlements'\n\n/*\n * WHO MAY DO WHAT TO A DATASET (AGL-4047). Roles are only presets of these.\n *\n * A dataset placed on exactly one site belongs to that site, and its writes\n * answer to that site's verdict as well as the workspace's (`site-placement` in\n * the platform core is the verdict):\n *\n * - \"Manage this site's data\" and \"Delete this site's datasets\" are the site's\n * verdict. For a member of the whole workspace each follows its workspace\n * key (\"Manage data\", \"Delete workspace records\"), so a role or a member\n * deciding those decides these. A site that narrows an editor to Author or\n * Viewer takes them there, unless the member keeps them (\"Keep this\n * permission\") or the site grants them back. A site that raises a viewer to\n * Admin or Editor gives them. A site collaborator holds them by their site\n * role, refined by the site's toggle.\n * - Holding the workspace key still admits, on any site that does not narrow\n * the member, so a collaborator handed \"Manage data\" keeps what it gave them.\n *\n * A dataset on every site or on several answers to the workspace key alone: no\n * one site can be asked, and a rule cannot look through a list of them.\n *\n * Three doors ask this, and must keep answering alike: the rule's\n * `canWriteDatasetOn` (`firebase-firestore.rules`), the routes through\n * `dataset-access.server.ts`, and the console through `use-dataset-writes-blocked`.\n */\n\n/** The workspace key on creating and writing datasets, which also covers the CRM and lists. */\nexport const DATA_MANAGE_PERMISSION = 'data.manage'\n/** The workspace key on deleting a whole dataset, which also covers contacts and lists. */\nexport const DATA_ERASE_PERMISSION = 'org.eraseRecords'\n/** The site's verdict on writing a dataset placed on that site alone. */\nexport const DATA_SITE_MANAGE_PERMISSION = 'data.siteManage'\n/** The site's verdict on deleting a dataset placed on that site alone. */\nexport const DATA_SITE_DELETE_PERMISSION = 'data.siteDelete'\n/** Reading a dataset's records. */\nexport const DATA_VIEW_RECORDS_PERMISSION = 'data.viewRecords'\n/** Taking a dataset's records out as a file. */\nexport const DATA_EXPORT_PERMISSION = 'data.export'\n\n/** Who holds the site's verdict by their access to it: the site's Admin and Editor. */\nexport const DATA_SITE_ROLE_PRESET: Readonly<Record<HostAccessRole, boolean>> = {\n admin: true,\n editor: true,\n author: false,\n viewer: false,\n}\n\nconst WORKSPACE_WRITERS = { owner: true, admin: true, editor: true, viewer: false } as const\nconst EVERY_ROLE = { owner: true, admin: true, editor: true, viewer: true } as const\n\n/** The keys as this plugin declares them into the permission catalog. */\nexport const DATA_PERMISSIONS: readonly PluginOrgPermissionDeclaration[] = [\n {\n key: DATA_SITE_MANAGE_PERMISSION,\n label: 'Manage this site’s data',\n description:\n 'Change the schema and records of a dataset placed on this site alone, and import into it. Follows “Manage data” for a member of the whole workspace.',\n roleDefaults: WORKSPACE_WRITERS,\n hostRoleDefaults: DATA_SITE_ROLE_PRESET,\n group: 'datasets',\n follows: DATA_MANAGE_PERMISSION,\n narrowsPerSite: { editor: true },\n raisesPerSite: true,\n },\n {\n key: DATA_SITE_DELETE_PERMISSION,\n label: 'Delete this site’s datasets',\n description:\n 'Delete a dataset placed on this site alone, with its records. Follows “Delete workspace records” for a member of the whole workspace.',\n roleDefaults: WORKSPACE_WRITERS,\n hostRoleDefaults: DATA_SITE_ROLE_PRESET,\n group: 'datasets',\n follows: DATA_ERASE_PERMISSION,\n narrowsPerSite: { editor: true },\n raisesPerSite: true,\n },\n {\n key: DATA_VIEW_RECORDS_PERMISSION,\n label: 'View dataset records',\n description: 'Read the records of the datasets this member can see. Published sites show records either way.',\n roleDefaults: EVERY_ROLE,\n group: 'datasets',\n },\n {\n key: DATA_EXPORT_PERMISSION,\n label: 'Export data',\n description: 'Take the records of the datasets this member can see out as a file. Needs “View dataset records”.',\n roleDefaults: EVERY_ROLE,\n group: 'datasets',\n refines: DATA_VIEW_RECORDS_PERMISSION,\n },\n]\n"],"names":["DATA_MANAGE_PERMISSION","DATA_ERASE_PERMISSION","DATA_SITE_MANAGE_PERMISSION","DATA_SITE_DELETE_PERMISSION","DATA_VIEW_RECORDS_PERMISSION","DATA_EXPORT_PERMISSION","DATA_SITE_ROLE_PRESET","admin","editor","author","viewer","WORKSPACE_WRITERS","owner","EVERY_ROLE","DATA_PERMISSIONS","key","label","description","roleDefaults","hostRoleDefaults","group","follows","narrowsPerSite","raisesPerSite","refines"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAKD;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GAED,6FAA6F,GAC7F,OAAO,MAAMA,yBAAyB,cAAa;AACnD,yFAAyF,GACzF,OAAO,MAAMC,wBAAwB,mBAAkB;AACvD,uEAAuE,GACvE,OAAO,MAAMC,8BAA8B,kBAAiB;AAC5D,wEAAwE,GACxE,OAAO,MAAMC,8BAA8B,kBAAiB;AAC5D,iCAAiC,GACjC,OAAO,MAAMC,+BAA+B,mBAAkB;AAC9D,8CAA8C,GAC9C,OAAO,MAAMC,yBAAyB,cAAa;AAEnD,qFAAqF,GACrF,OAAO,MAAMC,wBAAmE;IAC9EC,OAAO;IACPC,QAAQ;IACRC,QAAQ;IACRC,QAAQ;AACV,EAAC;AAED,MAAMC,oBAAoB;IAAEC,OAAO;IAAML,OAAO;IAAMC,QAAQ;IAAME,QAAQ;AAAM;AAClF,MAAMG,aAAa;IAAED,OAAO;IAAML,OAAO;IAAMC,QAAQ;IAAME,QAAQ;AAAK;AAE1E,uEAAuE,GACvE,OAAO,MAAMI,mBAA8D;IACzE;QACEC,KAAKb;QACLc,OAAO;QACPC,aACE;QACFC,cAAcP;QACdQ,kBAAkBb;QAClBc,OAAO;QACPC,SAASrB;QACTsB,gBAAgB;YAAEd,QAAQ;QAAK;QAC/Be,eAAe;IACjB;IACA;QACER,KAAKZ;QACLa,OAAO;QACPC,aACE;QACFC,cAAcP;QACdQ,kBAAkBb;QAClBc,OAAO;QACPC,SAASpB;QACTqB,gBAAgB;YAAEd,QAAQ;QAAK;QAC/Be,eAAe;IACjB;IACA;QACER,KAAKX;QACLY,OAAO;QACPC,aAAa;QACbC,cAAcL;QACdO,OAAO;IACT;IACA;QACEL,KAAKV;QACLW,OAAO;QACPC,aAAa;QACbC,cAAcL;QACdO,OAAO;QACPI,SAASpB;IACX;CACD,CAAA"}
@@ -0,0 +1,22 @@
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
+ export { DATA_ERASE_PERMISSION, DATA_EXPORT_PERMISSION, DATA_MANAGE_PERMISSION, DATA_PERMISSIONS, DATA_SITE_DELETE_PERMISSION, DATA_SITE_MANAGE_PERMISSION, DATA_SITE_ROLE_PRESET, DATA_VIEW_RECORDS_PERMISSION, } from './data-permissions';
18
+ /**
19
+ * The refusal for one of these keys, naming it, from this table rather than the
20
+ * live catalog: a module can ask before the declarations have registered.
21
+ */
22
+ export declare function dataPermissionRefusal(key: string): string;
@@ -0,0 +1,30 @@
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 { permissionRefusalText } from "@aglyn/aglyn/app-utils/org-permissions";
17
+ import { DATA_PERMISSIONS } from "./data-permissions.js";
18
+ // The keys live in `data-permissions.ts`, which imports only types so that the
19
+ // native contracts can assemble them into `ORG_ROLE_GRANTS`.
20
+ export { DATA_ERASE_PERMISSION, DATA_EXPORT_PERMISSION, DATA_MANAGE_PERMISSION, DATA_PERMISSIONS, DATA_SITE_DELETE_PERMISSION, DATA_SITE_MANAGE_PERMISSION, DATA_SITE_ROLE_PRESET, DATA_VIEW_RECORDS_PERMISSION } from "./data-permissions.js";
21
+ /**
22
+ * The refusal for one of these keys, naming it, from this table rather than the
23
+ * live catalog: a module can ask before the declarations have registered.
24
+ */ export function dataPermissionRefusal(key) {
25
+ var _DATA_PERMISSIONS_find;
26
+ const label = (_DATA_PERMISSIONS_find = DATA_PERMISSIONS.find((permission)=>permission.key === key)) == null ? void 0 : _DATA_PERMISSIONS_find.label;
27
+ return label ? `Your role does not include "${label}" — ask an organization admin` : permissionRefusalText(key);
28
+ }
29
+
30
+ //# sourceMappingURL=dataset-access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/model/dataset-access.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 OrgPermission, permissionRefusalText } from '@aglyn/aglyn/app-utils/org-permissions'\nimport { DATA_PERMISSIONS } from './data-permissions'\n\n// The keys live in `data-permissions.ts`, which imports only types so that the\n// native contracts can assemble them into `ORG_ROLE_GRANTS`.\nexport {\n DATA_ERASE_PERMISSION,\n DATA_EXPORT_PERMISSION,\n DATA_MANAGE_PERMISSION,\n DATA_PERMISSIONS,\n DATA_SITE_DELETE_PERMISSION,\n DATA_SITE_MANAGE_PERMISSION,\n DATA_SITE_ROLE_PRESET,\n DATA_VIEW_RECORDS_PERMISSION,\n} from './data-permissions'\n\n/**\n * The refusal for one of these keys, naming it, from this table rather than the\n * live catalog: a module can ask before the declarations have registered.\n */\nexport function dataPermissionRefusal(key: string): string {\n const label = DATA_PERMISSIONS.find((permission) => permission.key === key)?.label\n return label ? `Your role does not include \"${label}\" — ask an organization admin` : permissionRefusalText(key as OrgPermission)\n}\n"],"names":["permissionRefusalText","DATA_PERMISSIONS","DATA_ERASE_PERMISSION","DATA_EXPORT_PERMISSION","DATA_MANAGE_PERMISSION","DATA_SITE_DELETE_PERMISSION","DATA_SITE_MANAGE_PERMISSION","DATA_SITE_ROLE_PRESET","DATA_VIEW_RECORDS_PERMISSION","dataPermissionRefusal","key","label","find","permission"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAA6BA,qBAAqB,QAAQ,yCAAwC;AAClG,SAASC,gBAAgB,QAAQ,wBAAoB;AAErD,+EAA+E;AAC/E,6DAA6D;AAC7D,SACEC,qBAAqB,EACrBC,sBAAsB,EACtBC,sBAAsB,EACtBH,gBAAgB,EAChBI,2BAA2B,EAC3BC,2BAA2B,EAC3BC,qBAAqB,EACrBC,4BAA4B,QACvB,wBAAoB;AAE3B;;;CAGC,GACD,OAAO,SAASC,sBAAsBC,GAAW;QACjCT;IAAd,MAAMU,SAAQV,yBAAAA,iBAAiBW,IAAI,CAAC,CAACC,aAAeA,WAAWH,GAAG,KAAKA,yBAAzDT,uBAA+DU,KAAK;IAClF,OAAOA,QAAQ,CAAC,4BAA4B,EAAEA,MAAM,6BAA6B,CAAC,GAAGX,sBAAsBU;AAC7G"}
@@ -37,7 +37,7 @@ import { datasetDisplayName } from "./datasets.js";
37
37
  return {
38
38
  id,
39
39
  name: datasetDisplayName(data) || id,
40
- facts: {
40
+ facts: _extends({
41
41
  fields: model.order.map((fieldId)=>{
42
42
  var _ref;
43
43
  var _model_fields_fieldId, _model_fields_fieldId1, _model_fields_fieldId2, _model_fields_fieldId3;
@@ -49,9 +49,14 @@ import { datasetDisplayName } from "./datasets.js";
49
49
  customType: String((_model_fields_fieldId3 = model.fields[fieldId]) == null ? void 0 : _model_fields_fieldId3.customType)
50
50
  } : {});
51
51
  }),
52
- visibleTo: Array.isArray(data['visibleTo']) ? data['visibleTo'] : [],
52
+ visibleTo: Array.isArray(data['visibleTo']) ? data['visibleTo'] : []
53
+ }, data['scopeMode'] !== undefined ? {
54
+ scopeMode: data['scopeMode']
55
+ } : {}, data['scopeExcept'] !== undefined ? {
56
+ scopeExcept: data['scopeExcept']
57
+ } : {}, {
53
58
  installedFrom: installedFrom(data['source'])
54
- }
59
+ })
55
60
  };
56
61
  }
57
62
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/model/dataset-record.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 { PluginIndexedRecord } from '@aglyn/aglyn/plugin-manager/plugin-record-index'\nimport { type DatasetModel, effectiveDatasetModel } from './dataset-models'\nimport { datasetDisplayName } from './datasets'\n\n/**\n * One stored dataset as this plugin shares it with another (AGL-3080) — the\n * one shape its server index (`dataset-record-index.ts`) and its console list\n * source (`dataset-record-list.ts`) both answer, so a reader on either side\n * reads the same record.\n *\n * `null` for a deleted dataset. Otherwise its id, its name as the Data page\n * shows it, and `facts`:\n * `fields` — its fields in the dataset page's order, each\n * `{ id, name, type }`; `visibleTo` — the scope tokens it is shared\n * with, so a reader acting for a member can apply the platform's own\n * visibility rule to them; and `installedFrom` — `{ listingId, version }`\n * for a dataset installed from a listing (`version` as the install\n * stamped it), `null` for one the workspace made. Never a record of it.\n */\nexport function datasetIndexedRecord(\n id: string,\n data: Readonly<Record<string, unknown>> | undefined,\n): PluginIndexedRecord | null {\n if (!data || data['deletedAt'] != null) return null\n const model = effectiveDatasetModel(data as { model?: DatasetModel; fields?: string[] })\n const text = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')\n return {\n id,\n name: datasetDisplayName(data) || id,\n facts: {\n fields: model.order.map((fieldId) => ({\n id: fieldId,\n name: text(model.fields[fieldId]?.name) || fieldId,\n type: String(model.fields[fieldId]?.type ?? 'text'),\n // A named type riding the storage one: a record's photo is `image` (AGL-3616).\n ...(model.fields[fieldId]?.customType ? { customType: String(model.fields[fieldId]?.customType) } : {}),\n })),\n visibleTo: Array.isArray(data['visibleTo']) ? (data['visibleTo'] as string[]) : [],\n installedFrom: installedFrom(data['source']),\n },\n }\n}\n\n/**\n * Where an installed dataset came from. Read from its `source` stamp, which\n * every dataset install has written — the ones from before install\n * provenance (AGL-1015) included, which carry no `installedFrom`.\n */\nfunction installedFrom(source: unknown): { listingId: string; version: unknown } | null {\n const stamp = (source ?? {}) as Record<string, unknown>\n const listingId = typeof stamp['listingId'] === 'string' ? stamp['listingId'] : ''\n return listingId ? { listingId, version: stamp['version'] ?? null } : null\n}\n"],"names":["effectiveDatasetModel","datasetDisplayName","datasetIndexedRecord","id","data","model","text","value","trim","name","facts","fields","order","map","fieldId","type","String","customType","visibleTo","Array","isArray","installedFrom","source","stamp","listingId","version"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SAA4BA,qBAAqB,QAAQ,sBAAkB;AAC3E,SAASC,kBAAkB,QAAQ,gBAAY;AAE/C;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,qBACdC,EAAU,EACVC,IAAmD;IAEnD,IAAI,CAACA,QAAQA,IAAI,CAAC,YAAY,IAAI,MAAM,OAAO;IAC/C,MAAMC,QAAQL,sBAAsBI;IACpC,MAAME,OAAO,CAACC,QAA4B,OAAOA,UAAU,WAAWA,MAAMC,IAAI,KAAK;IACrF,OAAO;QACLL;QACAM,MAAMR,mBAAmBG,SAASD;QAClCO,OAAO;YACLC,QAAQN,MAAMO,KAAK,CAACC,GAAG,CAAC,CAACC;;oBAEZT,uBACEA,wBAETA,wBAAyDA;uBALzB;oBACpCF,IAAIW;oBACJL,MAAMH,MAAKD,wBAAAA,MAAMM,MAAM,CAACG,QAAQ,qBAArBT,sBAAuBI,IAAI,KAAKK;oBAC3CC,MAAMC,gBAAOX,yBAAAA,MAAMM,MAAM,CAACG,QAAQ,qBAArBT,uBAAuBU,IAAI,mBAAI;mBAExCV,EAAAA,yBAAAA,MAAMM,MAAM,CAACG,QAAQ,qBAArBT,uBAAuBY,UAAU,IAAG;oBAAEA,YAAYD,QAAOX,yBAAAA,MAAMM,MAAM,CAACG,QAAQ,qBAArBT,uBAAuBY,UAAU;gBAAE,IAAI,CAAC;;YAEvGC,WAAWC,MAAMC,OAAO,CAAChB,IAAI,CAAC,YAAY,IAAKA,IAAI,CAAC,YAAY,GAAgB,EAAE;YAClFiB,eAAeA,cAAcjB,IAAI,CAAC,SAAS;QAC7C;IACF;AACF;AAEA;;;;CAIC,GACD,SAASiB,cAAcC,MAAe;QAGKC;IAFzC,MAAMA,QAASD,iBAAAA,SAAU,CAAC;IAC1B,MAAME,YAAY,OAAOD,KAAK,CAAC,YAAY,KAAK,WAAWA,KAAK,CAAC,YAAY,GAAG;IAChF,OAAOC,YAAY;QAAEA;QAAWC,OAAO,GAAEF,iBAAAA,KAAK,CAAC,UAAU,YAAhBA,iBAAoB;IAAK,IAAI;AACxE"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/model/dataset-record.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 { PluginIndexedRecord } from '@aglyn/aglyn/plugin-manager/plugin-record-index'\nimport { type DatasetModel, effectiveDatasetModel } from './dataset-models'\nimport { datasetDisplayName } from './datasets'\n\n/**\n * One stored dataset as this plugin shares it with another (AGL-3080) — the\n * one shape its server index (`dataset-record-index.ts`) and its console list\n * source (`dataset-record-list.ts`) both answer, so a reader on either side\n * reads the same record.\n *\n * `null` for a deleted dataset. Otherwise its id, its name as the Data page\n * shows it, and `facts`:\n * `fields` — its fields in the dataset page's order, each\n * `{ id, name, type }`; `visibleTo` — the scope tokens it is shared\n * with, so a reader acting for a member can apply the platform's own\n * visibility rule to them; and `installedFrom` — `{ listingId, version }`\n * for a dataset installed from a listing (`version` as the install\n * stamped it), `null` for one the workspace made. Never a record of it.\n */\nexport function datasetIndexedRecord(\n id: string,\n data: Readonly<Record<string, unknown>> | undefined,\n): PluginIndexedRecord | null {\n if (!data || data['deletedAt'] != null) return null\n const model = effectiveDatasetModel(data as { model?: DatasetModel; fields?: string[] })\n const text = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')\n return {\n id,\n name: datasetDisplayName(data) || id,\n facts: {\n fields: model.order.map((fieldId) => ({\n id: fieldId,\n name: text(model.fields[fieldId]?.name) || fieldId,\n type: String(model.fields[fieldId]?.type ?? 'text'),\n // A named type riding the storage one: a record's photo is `image` (AGL-3616).\n ...(model.fields[fieldId]?.customType ? { customType: String(model.fields[fieldId]?.customType) } : {}),\n })),\n visibleTo: Array.isArray(data['visibleTo']) ? (data['visibleTo'] as string[]) : [],\n // Shared with all sites except some: what a reader of `visibleTo` needs in\n // order not to take it for a dataset on those sites alone (AGL-4047).\n ...(data['scopeMode'] !== undefined ? { scopeMode: data['scopeMode'] } : {}),\n ...(data['scopeExcept'] !== undefined ? { scopeExcept: data['scopeExcept'] } : {}),\n installedFrom: installedFrom(data['source']),\n },\n }\n}\n\n/**\n * Where an installed dataset came from. Read from its `source` stamp, which\n * every dataset install has written — the ones from before install\n * provenance (AGL-1015) included, which carry no `installedFrom`.\n */\nfunction installedFrom(source: unknown): { listingId: string; version: unknown } | null {\n const stamp = (source ?? {}) as Record<string, unknown>\n const listingId = typeof stamp['listingId'] === 'string' ? stamp['listingId'] : ''\n return listingId ? { listingId, version: stamp['version'] ?? null } : null\n}\n"],"names":["effectiveDatasetModel","datasetDisplayName","datasetIndexedRecord","id","data","model","text","value","trim","name","facts","fields","order","map","fieldId","type","String","customType","visibleTo","Array","isArray","undefined","scopeMode","scopeExcept","installedFrom","source","stamp","listingId","version"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SAA4BA,qBAAqB,QAAQ,sBAAkB;AAC3E,SAASC,kBAAkB,QAAQ,gBAAY;AAE/C;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,qBACdC,EAAU,EACVC,IAAmD;IAEnD,IAAI,CAACA,QAAQA,IAAI,CAAC,YAAY,IAAI,MAAM,OAAO;IAC/C,MAAMC,QAAQL,sBAAsBI;IACpC,MAAME,OAAO,CAACC,QAA4B,OAAOA,UAAU,WAAWA,MAAMC,IAAI,KAAK;IACrF,OAAO;QACLL;QACAM,MAAMR,mBAAmBG,SAASD;QAClCO,OAAO;YACLC,QAAQN,MAAMO,KAAK,CAACC,GAAG,CAAC,CAACC;;oBAEZT,uBACEA,wBAETA,wBAAyDA;uBALzB;oBACpCF,IAAIW;oBACJL,MAAMH,MAAKD,wBAAAA,MAAMM,MAAM,CAACG,QAAQ,qBAArBT,sBAAuBI,IAAI,KAAKK;oBAC3CC,MAAMC,gBAAOX,yBAAAA,MAAMM,MAAM,CAACG,QAAQ,qBAArBT,uBAAuBU,IAAI,mBAAI;mBAExCV,EAAAA,yBAAAA,MAAMM,MAAM,CAACG,QAAQ,qBAArBT,uBAAuBY,UAAU,IAAG;oBAAEA,YAAYD,QAAOX,yBAAAA,MAAMM,MAAM,CAACG,QAAQ,qBAArBT,uBAAuBY,UAAU;gBAAE,IAAI,CAAC;;YAEvGC,WAAWC,MAAMC,OAAO,CAAChB,IAAI,CAAC,YAAY,IAAKA,IAAI,CAAC,YAAY,GAAgB,EAAE;WAG9EA,IAAI,CAAC,YAAY,KAAKiB,YAAY;YAAEC,WAAWlB,IAAI,CAAC,YAAY;QAAC,IAAI,CAAC,GACtEA,IAAI,CAAC,cAAc,KAAKiB,YAAY;YAAEE,aAAanB,IAAI,CAAC,cAAc;QAAC,IAAI,CAAC;YAChFoB,eAAeA,cAAcpB,IAAI,CAAC,SAAS;;IAE/C;AACF;AAEA;;;;CAIC,GACD,SAASoB,cAAcC,MAAe;QAGKC;IAFzC,MAAMA,QAASD,iBAAAA,SAAU,CAAC;IAC1B,MAAME,YAAY,OAAOD,KAAK,CAAC,YAAY,KAAK,WAAWA,KAAK,CAAC,YAAY,GAAG;IAChF,OAAOC,YAAY;QAAEA;QAAWC,OAAO,GAAEF,iBAAAA,KAAK,CAAC,UAAU,YAAhBA,iBAAoB;IAAK,IAAI;AACxE"}