@nacre.work/core 0.0.0 → 0.2.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/LICENSE +202 -0
- package/NOTICE +9 -0
- package/dist/audit.d.ts +41 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +18 -0
- package/dist/audit.js.map +1 -0
- package/dist/authz/cache.d.ts +20 -0
- package/dist/authz/cache.d.ts.map +1 -1
- package/dist/authz/cache.js +29 -0
- package/dist/authz/cache.js.map +1 -1
- package/dist/authz/filter.d.ts +54 -3
- package/dist/authz/filter.d.ts.map +1 -1
- package/dist/authz/filter.js +45 -9
- package/dist/authz/filter.js.map +1 -1
- package/dist/authz/index.d.ts +3 -3
- package/dist/authz/index.d.ts.map +1 -1
- package/dist/authz/index.js +2 -2
- package/dist/authz/index.js.map +1 -1
- package/dist/config.d.ts +55 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +245 -7
- package/dist/config.js.map +1 -1
- package/dist/db/client.d.ts +39 -0
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +82 -0
- package/dist/db/client.js.map +1 -1
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +49 -0
- package/dist/db/migrate.js.map +1 -1
- package/dist/index.d.ts +21 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/dist/lifecycle.d.ts +57 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +84 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/logging.d.ts +46 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +110 -0
- package/dist/logging.js.map +1 -0
- package/dist/metadata.d.ts +50 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +127 -0
- package/dist/metadata.js.map +1 -0
- package/dist/metrics.d.ts +19 -1
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js +84 -2
- package/dist/metrics.js.map +1 -1
- package/dist/migrations/0008_authenticating_lookup.sql +124 -0
- package/dist/migrations/0009_refresh_tokens.sql +73 -0
- package/dist/migrations/0010_definer_search_path.sql +22 -0
- package/dist/migrations/0011_sweep_lease.sql +36 -0
- package/dist/migrations/0012_prune.sql +118 -0
- package/dist/migrations/0013_reindex.sql +65 -0
- package/dist/migrations/0014_retired_collections.sql +68 -0
- package/dist/oauth.d.ts +45 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +53 -0
- package/dist/oauth.js.map +1 -0
- package/dist/observability.d.ts.map +1 -1
- package/dist/observability.js +100 -13
- package/dist/observability.js.map +1 -1
- package/dist/passwords.d.ts +37 -0
- package/dist/passwords.d.ts.map +1 -0
- package/dist/passwords.js +234 -0
- package/dist/passwords.js.map +1 -0
- package/dist/redis.d.ts +46 -0
- package/dist/redis.d.ts.map +1 -0
- package/dist/redis.js +234 -0
- package/dist/redis.js.map +1 -0
- package/dist/reindex.d.ts +87 -0
- package/dist/reindex.d.ts.map +1 -0
- package/dist/reindex.js +97 -0
- package/dist/reindex.js.map +1 -0
- package/dist/s3.d.ts +111 -0
- package/dist/s3.d.ts.map +1 -0
- package/dist/s3.js +242 -0
- package/dist/s3.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/vector/query.d.ts +49 -4
- package/dist/vector/query.d.ts.map +1 -1
- package/dist/vector/query.js +43 -10
- package/dist/vector/query.js.map +1 -1
- package/dist/vector/search.d.ts +175 -4
- package/dist/vector/search.d.ts.map +1 -1
- package/dist/vector/search.js +320 -7
- package/dist/vector/search.js.map +1 -1
- package/package.json +26 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Nacre
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Nacre
|
|
2
|
+
Copyright 2026 Nacre
|
|
3
|
+
|
|
4
|
+
This product includes software developed at Nacre (https://nacre.work).
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0. See LICENSE.
|
|
7
|
+
|
|
8
|
+
"Nacre" and the Nacre mark are trademarks. Section 6 of the Apache License
|
|
9
|
+
grants no trademark rights; permitted use is described in TRADEMARK.md.
|
package/dist/audit.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the journal is allowed to say about a query.
|
|
3
|
+
*
|
|
4
|
+
* `docs/audit.md` is normative and says two things here. Neither was true:
|
|
5
|
+
*
|
|
6
|
+
* > **Never:** document contents, chunk text, and — with
|
|
7
|
+
* > `NACRE_AUDIT_QUERY_TEXT=false`, the default — full query text. A query
|
|
8
|
+
* > hash is stored instead.
|
|
9
|
+
*
|
|
10
|
+
* There was no hash. The `detail` written for a search carried a count and
|
|
11
|
+
* nothing about the query at all, so the promise that a hash is "enough to
|
|
12
|
+
* investigate an incident" was a promise about a field that did not exist —
|
|
13
|
+
* and `NACRE_AUDIT_QUERY_TEXT` was validated at startup and read by nothing,
|
|
14
|
+
* so the deployments that had decided otherwise got the same nothing.
|
|
15
|
+
*
|
|
16
|
+
* ─── why the hash is unconditional and the text is not ───
|
|
17
|
+
*
|
|
18
|
+
* The hash answers the question an investigation actually asks — *did this
|
|
19
|
+
* agent run this query, and how often* — by comparing hashes, and it cannot
|
|
20
|
+
* leak what was searched for. The text answers a different question, is a
|
|
21
|
+
* decision with a compliance owner, and is the reason the flag exists.
|
|
22
|
+
*
|
|
23
|
+
* One function so the two surfaces cannot disagree. A search over MCP and the
|
|
24
|
+
* same search over REST must leave the same record; that they did not is what
|
|
25
|
+
* `nacre_acl_denials_total` and the rate limiter both had to be fixed for.
|
|
26
|
+
*/
|
|
27
|
+
export interface QueryAudit {
|
|
28
|
+
/** `sha256:` and hex, the same shape as `documents.content_hash`. */
|
|
29
|
+
readonly query_hash: string;
|
|
30
|
+
/** Present only where a deployment set `NACRE_AUDIT_QUERY_TEXT`. */
|
|
31
|
+
readonly query?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Bounded, because the journal is not a place to put an unbounded caller
|
|
35
|
+
* string. A query longer than this is truncated in the record and still hashed
|
|
36
|
+
* whole — the hash is of what was asked, not of what was stored, or two records
|
|
37
|
+
* of the same long query would not match each other.
|
|
38
|
+
*/
|
|
39
|
+
export declare const MAX_AUDITED_QUERY = 1024;
|
|
40
|
+
export declare function queryAudit(query: string, includeText: boolean): QueryAudit;
|
|
41
|
+
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../audit.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,UAAU;IACzB,qEAAqE;IACrE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,oEAAoE;IACpE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,OAAO,CAAA;AAErC,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAG,UAAU,CAO1E"}
|
package/dist/audit.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Bounded, because the journal is not a place to put an unbounded caller
|
|
4
|
+
* string. A query longer than this is truncated in the record and still hashed
|
|
5
|
+
* whole — the hash is of what was asked, not of what was stored, or two records
|
|
6
|
+
* of the same long query would not match each other.
|
|
7
|
+
*/
|
|
8
|
+
export const MAX_AUDITED_QUERY = 1024;
|
|
9
|
+
export function queryAudit(query, includeText) {
|
|
10
|
+
const hash = `sha256:${createHash('sha256').update(query, 'utf8').digest('hex')}`;
|
|
11
|
+
if (!includeText)
|
|
12
|
+
return { query_hash: hash };
|
|
13
|
+
return {
|
|
14
|
+
query_hash: hash,
|
|
15
|
+
query: query.length > MAX_AUDITED_QUERY ? `${query.slice(0, MAX_AUDITED_QUERY)}…` : query,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../audit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAmCxC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAA;AAErC,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,WAAoB;IAC5D,MAAM,IAAI,GAAG,UAAU,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;IACjF,IAAI,CAAC,WAAW;QAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAA;IAC7C,OAAO;QACL,UAAU,EAAE,IAAI;QAChB,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK;KAC1F,CAAA;AACH,CAAC"}
|
package/dist/authz/cache.d.ts
CHANGED
|
@@ -23,6 +23,26 @@ export interface CacheStore {
|
|
|
23
23
|
get(key: string): Promise<string | undefined>;
|
|
24
24
|
set(key: string, value: string, ttlSeconds: number): Promise<void>;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* The shared implementation, over the Redis this deployment already runs.
|
|
28
|
+
*
|
|
29
|
+
* Lives here rather than in `packages/api` because MCP needs the same one, and
|
|
30
|
+
* two processes caching effective principals under two different key schemes
|
|
31
|
+
* would give the two surfaces different answers for the same principal — which
|
|
32
|
+
* is the failure mode `NACRE_RATE_*` had before both surfaces shared a bucket.
|
|
33
|
+
*
|
|
34
|
+
* Every method swallows nothing: `cachedEffectivePrincipals` is what decides
|
|
35
|
+
* that a cache failure falls through to the graph, and it can only decide that
|
|
36
|
+
* if the failure reaches it.
|
|
37
|
+
*/
|
|
38
|
+
export declare class RedisCache implements CacheStore {
|
|
39
|
+
private readonly redis;
|
|
40
|
+
constructor(redis: {
|
|
41
|
+
command(...parts: string[]): Promise<string | number | null | unknown[]>;
|
|
42
|
+
});
|
|
43
|
+
get(key: string): Promise<string | undefined>;
|
|
44
|
+
set(key: string, value: string, ttlSeconds: number): Promise<void>;
|
|
45
|
+
}
|
|
26
46
|
/** For a single process, and for tests. Redis is the shared implementation. */
|
|
27
47
|
export declare class MemoryCache implements CacheStore {
|
|
28
48
|
#private;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../authz/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEtE;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IAC7C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACnE;AAED,+EAA+E;AAC/E,qBAAa,WAAY,YAAW,U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ACnC,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CA2BpC"}
|
package/dist/authz/cache.js
CHANGED
|
@@ -1,4 +1,33 @@
|
|
|
1
1
|
import { effectivePrincipals } from './principals.js';
|
|
2
|
+
/**
|
|
3
|
+
* The shared implementation, over the Redis this deployment already runs.
|
|
4
|
+
*
|
|
5
|
+
* Lives here rather than in `packages/api` because MCP needs the same one, and
|
|
6
|
+
* two processes caching effective principals under two different key schemes
|
|
7
|
+
* would give the two surfaces different answers for the same principal — which
|
|
8
|
+
* is the failure mode `NACRE_RATE_*` had before both surfaces shared a bucket.
|
|
9
|
+
*
|
|
10
|
+
* Every method swallows nothing: `cachedEffectivePrincipals` is what decides
|
|
11
|
+
* that a cache failure falls through to the graph, and it can only decide that
|
|
12
|
+
* if the failure reaches it.
|
|
13
|
+
*/
|
|
14
|
+
export class RedisCache {
|
|
15
|
+
redis;
|
|
16
|
+
constructor(redis) {
|
|
17
|
+
this.redis = redis;
|
|
18
|
+
}
|
|
19
|
+
async get(key) {
|
|
20
|
+
const reply = await this.redis.command('GET', key);
|
|
21
|
+
return typeof reply === 'string' ? reply : undefined;
|
|
22
|
+
}
|
|
23
|
+
async set(key, value, ttlSeconds) {
|
|
24
|
+
// EX rather than a separate EXPIRE: two commands leave a window where a
|
|
25
|
+
// crash between them writes a key that never expires, and this key is
|
|
26
|
+
// per principal per version — the set of them that never expire is
|
|
27
|
+
// unbounded.
|
|
28
|
+
await this.redis.command('SET', key, value, 'EX', String(Math.max(1, Math.floor(ttlSeconds))));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
2
31
|
/** For a single process, and for tests. Redis is the shared implementation. */
|
|
3
32
|
export class MemoryCache {
|
|
4
33
|
#entries = new Map();
|
package/dist/authz/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../authz/cache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAmB,MAAM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.ts
CHANGED
|
@@ -25,12 +25,12 @@ export interface VectorFilter {
|
|
|
25
25
|
export type FilterClause = {
|
|
26
26
|
readonly key: string;
|
|
27
27
|
readonly match: {
|
|
28
|
-
readonly value: string | boolean;
|
|
28
|
+
readonly value: string | number | boolean;
|
|
29
29
|
};
|
|
30
30
|
} | {
|
|
31
31
|
readonly key: string;
|
|
32
32
|
readonly match: {
|
|
33
|
-
readonly any: readonly string[];
|
|
33
|
+
readonly any: readonly (string | number | boolean)[];
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
@@ -56,5 +56,56 @@ export type QueryablePlan = Exclude<AccessPlan, {
|
|
|
56
56
|
* Omitting it from one branch is a leak, and the branches are far enough apart
|
|
57
57
|
* in the query document for that to look like a formatting difference.
|
|
58
58
|
*/
|
|
59
|
-
|
|
59
|
+
/**
|
|
60
|
+
* A restriction the *caller* asked for, on top of the one the permissions
|
|
61
|
+
* impose.
|
|
62
|
+
*
|
|
63
|
+
* Only ever narrowing, and the type is what says so: a list of layer ids that
|
|
64
|
+
* results must be in. It becomes a `must` clause, which intersects with the
|
|
65
|
+
* permission `should` rather than replacing it — a caller asking for a layer
|
|
66
|
+
* they cannot read still gets nothing from it, because both constraints apply.
|
|
67
|
+
*
|
|
68
|
+
* The alternative shape, and the one to avoid, is narrowing `plan.layers`
|
|
69
|
+
* before building. That looks equivalent and is not: a scoped plan also carries
|
|
70
|
+
* `extraDocs` from document-level grants, which sit in the same `should`, so
|
|
71
|
+
* narrowing the plan would leave those documents matching regardless of which
|
|
72
|
+
* layers the caller asked for. `must` is the constraint the caller meant.
|
|
73
|
+
*
|
|
74
|
+
* An empty list must never reach here. `[]` as a `must` on `layer_id` matches
|
|
75
|
+
* nothing at all, which is the right answer for "you asked for layers you
|
|
76
|
+
* cannot read" — but it is the caller's job to spot that and skip the query, so
|
|
77
|
+
* that "no such layer" and "no permitted results" stay the same answer. This
|
|
78
|
+
* function refuses it rather than encoding the distinction.
|
|
79
|
+
*/
|
|
80
|
+
/** A value a caller may narrow a search to. Scalars and lists of them, nothing else. */
|
|
81
|
+
export type MetadataValue = string | number | boolean | readonly (string | number | boolean)[];
|
|
82
|
+
/**
|
|
83
|
+
* Where a caller's metadata lands in the vector payload.
|
|
84
|
+
*
|
|
85
|
+
* Every key a caller supplies is written and read under this one object, so
|
|
86
|
+
* `meta.org_id` is a different field from `org_id` and there is no key a caller
|
|
87
|
+
* can choose that reaches a permission field. That is the whole reason for the
|
|
88
|
+
* prefix: without it, `filters: {"deleted": false}` would be a caller reaching
|
|
89
|
+
* invariant I5's clause, and `metadata: {"acl_tags": [...]}` on ingest would be
|
|
90
|
+
* a caller writing their own permission tags.
|
|
91
|
+
*
|
|
92
|
+
* Structural, not a check. A denylist of forbidden keys would have to stay in
|
|
93
|
+
* step with every payload field ever added; a namespace cannot fall out of step
|
|
94
|
+
* with anything.
|
|
95
|
+
*/
|
|
96
|
+
export declare const METADATA_PREFIX = "meta";
|
|
97
|
+
export interface Narrowing {
|
|
98
|
+
readonly layers?: readonly string[];
|
|
99
|
+
/**
|
|
100
|
+
* Document metadata the caller asked to restrict to, key to value.
|
|
101
|
+
*
|
|
102
|
+
* Equality only, and every entry becomes a `must` — so like `layers`, this can
|
|
103
|
+
* only ever remove results. There is deliberately no negation, no range and no
|
|
104
|
+
* disjunction across keys: each of those is a way to *widen* if it is ever
|
|
105
|
+
* composed wrongly, and none of them is needed to answer "only documents from
|
|
106
|
+
* this source".
|
|
107
|
+
*/
|
|
108
|
+
readonly metadata?: Readonly<Record<string, MetadataValue>>;
|
|
109
|
+
}
|
|
110
|
+
export declare function buildFilter(orgId: string, plan: QueryablePlan, narrow?: Narrowing): VectorFilter;
|
|
60
111
|
//# sourceMappingURL=filter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../authz/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,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MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAEjE;;;;;;;;;;;GAWG;AACH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wFAAwF;AACxF,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,CAAA;AAE9F;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,SAAS,CAAA;AAErC,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACnC;;;;;;;;OAQG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAA;CAC5D;AAED,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,aAAa,EACnB,MAAM,CAAC,EAAE,SAAS,GACjB,YAAY,CAkFd"}
|
package/dist/authz/filter.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Where a caller's metadata lands in the vector payload.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Every key a caller supplies is written and read under this one object, so
|
|
5
|
+
* `meta.org_id` is a different field from `org_id` and there is no key a caller
|
|
6
|
+
* can choose that reaches a permission field. That is the whole reason for the
|
|
7
|
+
* prefix: without it, `filters: {"deleted": false}` would be a caller reaching
|
|
8
|
+
* invariant I5's clause, and `metadata: {"acl_tags": [...]}` on ingest would be
|
|
9
|
+
* a caller writing their own permission tags.
|
|
8
10
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
11
|
+
* Structural, not a check. A denylist of forbidden keys would have to stay in
|
|
12
|
+
* step with every payload field ever added; a namespace cannot fall out of step
|
|
13
|
+
* with anything.
|
|
12
14
|
*/
|
|
13
|
-
export
|
|
15
|
+
export const METADATA_PREFIX = 'meta';
|
|
16
|
+
export function buildFilter(orgId, plan, narrow) {
|
|
14
17
|
// org_id and deleted are unconditional.
|
|
15
18
|
//
|
|
16
19
|
// org_id is duplicated in the payload even when each tenant has its own
|
|
@@ -25,6 +28,39 @@ export function buildFilter(orgId, plan) {
|
|
|
25
28
|
{ key: 'org_id', match: { value: orgId } },
|
|
26
29
|
{ key: 'deleted', match: { value: false } },
|
|
27
30
|
];
|
|
31
|
+
if (narrow?.layers !== undefined) {
|
|
32
|
+
if (narrow.layers.length === 0) {
|
|
33
|
+
// See Narrowing. An empty `any` is not "match nothing" in Qdrant, it is a
|
|
34
|
+
// clause that matches nothing *usefully* — and relying on that would put
|
|
35
|
+
// the "the caller asked for a layer they cannot see" case in the query
|
|
36
|
+
// builder, where it becomes one refactor away from being dropped. The
|
|
37
|
+
// caller returns no results without querying.
|
|
38
|
+
throw new Error('refusing to build a filter narrowed to no layers — the caller must ' +
|
|
39
|
+
'return an empty result instead of querying');
|
|
40
|
+
}
|
|
41
|
+
// A `must`, so it intersects with the permission constraint rather than
|
|
42
|
+
// replacing it. This can only ever remove results.
|
|
43
|
+
must.push({ key: 'layer_id', match: { any: [...narrow.layers] } });
|
|
44
|
+
}
|
|
45
|
+
for (const [key, value] of Object.entries(narrow?.metadata ?? {})) {
|
|
46
|
+
// Namespaced, always. The caller chooses the key and never the field: a
|
|
47
|
+
// filter on `deleted` becomes a filter on `meta.deleted`, which is a
|
|
48
|
+
// different field and cannot touch invariant I5's clause.
|
|
49
|
+
const field = `${METADATA_PREFIX}.${key}`;
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
if (value.length === 0) {
|
|
52
|
+
// Same refusal as an empty layer list, for the same reason: an empty
|
|
53
|
+
// `any` is not "match nothing" in Qdrant. The caller decides what an
|
|
54
|
+
// impossible restriction means, and answers empty without querying.
|
|
55
|
+
throw new Error(`refusing to build a filter narrowed to no values for ${key} — the ` +
|
|
56
|
+
'caller must return an empty result instead of querying');
|
|
57
|
+
}
|
|
58
|
+
must.push({ key: field, match: { any: [...value] } });
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
must.push({ key: field, match: { value: value } });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
28
64
|
if (plan.kind === 'all')
|
|
29
65
|
return { must };
|
|
30
66
|
// Only non-empty lists become clauses. An empty `any` adds nothing and an
|
package/dist/authz/filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../authz/filter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../authz/filter.ts"],"names":[],"mappings":"AA+EA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAA;AAgBrC,MAAM,UAAU,WAAW,CACzB,KAAa,EACb,IAAmB,EACnB,MAAkB;IAElB,wCAAwC;IACxC,EAAE;IACF,wEAAwE;IACxE,wEAAwE;IACxE,uCAAuC;IACvC,EAAE;IACF,2EAA2E;IAC3E,qEAAqE;IACrE,yEAAyE;IACzE,eAAe;IACf,MAAM,IAAI,GAAmB;QAC3B,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QAC1C,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;KAC5C,CAAA;IAED,IAAI,MAAM,EAAE,MAAM,KAAK,SAAS,EAAE,CAAC;QACjC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,0EAA0E;YAC1E,yEAAyE;YACzE,uEAAuE;YACvE,sEAAsE;YACtE,8CAA8C;YAC9C,MAAM,IAAI,KAAK,C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E,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IACzF,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;IAE7F,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,wEAAwE;QACxE,uEAAuE;QACvE,yEAAyE;QACzE,2EAA2E;QAC3E,sEAAsE;QACtE,MAAM,IAAI,KAAK,CACb,0EAA0E;YACxE,qDAAqD,CACxD,CAAA;IACH,CAAC;IAED,OAAO;QACL,IAAI;QACJ,MAAM;QACN,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;YAC5B,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE;YACpE,CAAC,CAAC,EAAE,CAAC;KACR,CAAA;AACH,CAAC"}
|
package/dist/authz/index.d.ts
CHANGED
|
@@ -5,11 +5,11 @@ export { resolve } from './resolve.js';
|
|
|
5
5
|
export type { AccessPlan, ResolveInput } from './resolve.js';
|
|
6
6
|
export { referenceAllows } from './reference.js';
|
|
7
7
|
export type { ReferenceInput } from './reference.js';
|
|
8
|
-
export { buildFilter } from './filter.js';
|
|
9
|
-
export type { FilterClause, QueryablePlan, VectorFilter } from './filter.js';
|
|
8
|
+
export { buildFilter, METADATA_PREFIX } from './filter.js';
|
|
9
|
+
export type { FilterClause, MetadataValue, Narrowing, QueryablePlan, VectorFilter } from './filter.js';
|
|
10
10
|
export { ancestry, MemoryScopeTree } from './scope-tree.js';
|
|
11
11
|
export type { ScopeTree, ScopeTreeData } from './scope-tree.js';
|
|
12
12
|
export { aclTags, principalTag, DEFAULT_TAG_BYTES } from './tags.js';
|
|
13
|
-
export { cachedEffectivePrincipals, MemoryCache, principalsCacheKey } from './cache.js';
|
|
13
|
+
export { cachedEffectivePrincipals, MemoryCache, RedisCache, principalsCacheKey } from './cache.js';
|
|
14
14
|
export type { CacheStore, CachedPrincipalsOptions } from './cache.js';
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../authz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACvE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../authz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACvE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC1D,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACtG,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAC3D,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/D,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AACpE,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACnG,YAAY,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/authz/index.js
CHANGED
|
@@ -2,8 +2,8 @@ export { implied, satisfies } from './permissions.js';
|
|
|
2
2
|
export { effectivePrincipals, MemoryGroupGraph } from './principals.js';
|
|
3
3
|
export { resolve } from './resolve.js';
|
|
4
4
|
export { referenceAllows } from './reference.js';
|
|
5
|
-
export { buildFilter } from './filter.js';
|
|
5
|
+
export { buildFilter, METADATA_PREFIX } from './filter.js';
|
|
6
6
|
export { ancestry, MemoryScopeTree } from './scope-tree.js';
|
|
7
7
|
export { aclTags, principalTag, DEFAULT_TAG_BYTES } from './tags.js';
|
|
8
|
-
export { cachedEffectivePrincipals, MemoryCache, principalsCacheKey } from './cache.js';
|
|
8
|
+
export { cachedEffectivePrincipals, MemoryCache, RedisCache, principalsCacheKey } from './cache.js';
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/dist/authz/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../authz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEvE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../authz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEvE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE1D,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAE3D,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AACpE,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA"}
|