@pipeline-builder/pipeline-data 0.0.1
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/README.md +61 -0
- package/drizzle.config.ts +17 -0
- package/lib/api/access-control-builder.d.ts +148 -0
- package/lib/api/access-control-builder.js +199 -0
- package/lib/api/crud-service.d.ts +343 -0
- package/lib/api/crud-service.js +849 -0
- package/lib/api/query-builders.d.ts +82 -0
- package/lib/api/query-builders.js +460 -0
- package/lib/api/reporting-service.d.ts +685 -0
- package/lib/api/reporting-service.js +1564 -0
- package/lib/api/soft-delete-sweep.d.ts +65 -0
- package/lib/api/soft-delete-sweep.js +124 -0
- package/lib/api/viewer-context.d.ts +29 -0
- package/lib/api/viewer-context.js +63 -0
- package/lib/core/query-filters.d.ts +263 -0
- package/lib/core/query-filters.js +4 -0
- package/lib/database/drizzle-schema.d.ts +7357 -0
- package/lib/database/drizzle-schema.js +66 -0
- package/lib/database/index.d.ts +5 -0
- package/lib/database/index.js +8 -0
- package/lib/database/migrator.d.ts +20 -0
- package/lib/database/migrator.js +80 -0
- package/lib/database/postgres-connection.d.ts +201 -0
- package/lib/database/postgres-connection.js +413 -0
- package/lib/database/retry-strategy.d.ts +68 -0
- package/lib/database/retry-strategy.js +122 -0
- package/lib/database/schema/alert.d.ts +588 -0
- package/lib/database/schema/alert.js +130 -0
- package/lib/database/schema/compliance.d.ts +3319 -0
- package/lib/database/schema/compliance.js +377 -0
- package/lib/database/schema/dashboard.d.ts +474 -0
- package/lib/database/schema/dashboard.js +129 -0
- package/lib/database/schema/message-attachment.d.ts +183 -0
- package/lib/database/schema/message-attachment.js +40 -0
- package/lib/database/schema/message.d.ts +411 -0
- package/lib/database/schema/message.js +114 -0
- package/lib/database/schema/pipeline-template.d.ts +466 -0
- package/lib/database/schema/pipeline-template.js +80 -0
- package/lib/database/schema/pipeline.d.ts +1613 -0
- package/lib/database/schema/pipeline.js +332 -0
- package/lib/database/schema/plugin.d.ts +749 -0
- package/lib/database/schema/plugin.js +166 -0
- package/lib/database/tenancy.d.ts +103 -0
- package/lib/database/tenancy.js +167 -0
- package/lib/index.d.ts +32 -0
- package/lib/index.js +38 -0
- package/package.json +161 -0
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 [yyyy] [name of copyright owner]
|
|
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/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @pipeline-builder/pipeline-data
|
|
2
|
+
|
|
3
|
+
📖 **[View documentation](https://mwashburn160.github.io/pipeline-builder/)**
|
|
4
|
+
|
|
5
|
+
Database layer for [Pipeline Builder](https://mwashburn160.github.io/pipeline-builder/): Drizzle ORM schemas, connection management, query builders, and the generic `CrudService` base class with per-organization (and team) access control.
|
|
6
|
+
|
|
7
|
+
> Internal workspace package — consumed by other packages via `workspace:*`.
|
|
8
|
+
|
|
9
|
+
## Responsibilities
|
|
10
|
+
|
|
11
|
+
- Defines the Drizzle ORM schema for every backend table (pipelines, plugins, messages, pipeline events, and the compliance suite).
|
|
12
|
+
- Manages the PostgreSQL connection lifecycle with retry logic.
|
|
13
|
+
- Provides the generic `CrudService` base class with built-in multi-tenant (org/team) access control and pagination.
|
|
14
|
+
- Supplies filter-to-SQL query/condition builders and `AsyncLocalStorage`-backed tenant-context primitives for transactions.
|
|
15
|
+
- Hosts the `ReportingService` used to ingest pipeline events and serve org-scoped reporting.
|
|
16
|
+
|
|
17
|
+
## Key exports
|
|
18
|
+
|
|
19
|
+
### Database
|
|
20
|
+
| Export | Purpose |
|
|
21
|
+
|---|---|
|
|
22
|
+
| `db` | Shared Drizzle database instance |
|
|
23
|
+
| `getConnection`, `closeConnection` | PostgreSQL connection lifecycle (with retry strategy) |
|
|
24
|
+
| `schema` | All Drizzle table definitions and their `*Insert` / `*Update` types |
|
|
25
|
+
| `runMigrations` (`MigrateOptions`) | Drizzle migration runner |
|
|
26
|
+
| `tenantContext`, `runWithTenantContext`, `getTenantContext`, `withTenantTx` | Tenant-context primitives for scoped/RLS transactions |
|
|
27
|
+
|
|
28
|
+
### Services
|
|
29
|
+
| Export | Purpose |
|
|
30
|
+
|---|---|
|
|
31
|
+
| `CrudService<TEntity, TFilter, TInsert, TUpdate>` | Abstract base providing `find`, `findById`, `findPaginated`, `count`, `create`, `update`, `delete` (soft), `setDefault`, `updateMany` with multi-tenant access control |
|
|
32
|
+
| `ReportingService` / `reportingService` | Aggregate-query base for pipeline-event ingestion and org-scoped reporting |
|
|
33
|
+
|
|
34
|
+
### Query builders & filters
|
|
35
|
+
| Export | Purpose |
|
|
36
|
+
|---|---|
|
|
37
|
+
| `AccessControlQueryBuilder` | Row-level, org-scoped condition builder enforcing tenant isolation and the three-rung `visibility` ladder |
|
|
38
|
+
| `buildPipelineConditions`, `buildPluginConditions`, `buildMessageConditions`, and the compliance condition builders | Filter-to-SQL translators used by the services |
|
|
39
|
+
| `PipelineFilter`, `PluginFilter`, `MessageFilter`, the compliance filter types | Typed filter interfaces |
|
|
40
|
+
| `drizzleRows`, `drizzleCount` | Drizzle result type helpers |
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { CrudService, db, schema } from '@pipeline-builder/pipeline-data';
|
|
46
|
+
|
|
47
|
+
class PipelineService extends CrudService<Pipeline, PipelineFilter, PipelineInsert, PipelineUpdate> {
|
|
48
|
+
// implement buildConditions + a few column accessors; inherit the rest
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Development
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pnpm build # projen build (compile + lint + test + package)
|
|
56
|
+
pnpm test # run the Jest test suite
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
Apache-2.0. See [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright 2026 Pipeline Builder Contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { defineConfig } from 'drizzle-kit';
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
schema: './src/database/drizzle-schema.ts',
|
|
8
|
+
out: './drizzle',
|
|
9
|
+
dialect: 'postgresql',
|
|
10
|
+
dbCredentials: {
|
|
11
|
+
host: process.env.DB_HOST || 'localhost',
|
|
12
|
+
port: parseInt(process.env.DB_PORT || '5432', 10),
|
|
13
|
+
user: process.env.DB_USER || 'postgres',
|
|
14
|
+
password: process.env.DB_PASSWORD || 'password',
|
|
15
|
+
database: process.env.DATABASE || 'pipeline_builder',
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { SQL } from 'drizzle-orm';
|
|
2
|
+
import type { AnyColumn } from 'drizzle-orm/column';
|
|
3
|
+
/**
|
|
4
|
+
* Escape SQL LIKE wildcard characters to prevent wildcard injection.
|
|
5
|
+
* Replaces `%` → `\\%`, `_` → `\\_`, and `\\` → `\\\\`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function escapeLikeWildcards(str: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Build a condition that checks if a JSONB text array column contains a keyword (case-insensitive).
|
|
10
|
+
* Used for keywords/tags filtering on pipelines, plugins, and compliance rules.
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildJsonbKeywordCondition(column: AnyColumn, keyword: string): SQL;
|
|
13
|
+
/**
|
|
14
|
+
* Parse boolean filter value from string or boolean
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseBooleanFilter(value: unknown): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Normalize string filter value to lowercase
|
|
19
|
+
*/
|
|
20
|
+
export declare function normalizeStringFilter(value: unknown): string;
|
|
21
|
+
/**
|
|
22
|
+
* Build an ID predicate with UUID prefix matching.
|
|
23
|
+
*
|
|
24
|
+
* - Full UUID → exact match
|
|
25
|
+
* - Partial UUID → prefix match via `LIKE` (a list-search affordance)
|
|
26
|
+
* - Absent → `null` (no predicate)
|
|
27
|
+
*
|
|
28
|
+
* Standalone so entities that DON'T use {@link AccessControlQueryBuilder}'s
|
|
29
|
+
* access control (e.g. pipeline templates, which carry their own three-rung
|
|
30
|
+
* visibility ladder) still share one id-matching implementation.
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildIdCondition(idColumn: AnyColumn, id: unknown): SQL | null;
|
|
33
|
+
/**
|
|
34
|
+
* Build the `isDefault` / `isActive` predicates shared by every catalog entity.
|
|
35
|
+
* `isActive` defaults to true so soft-deleted rows stay out of normal reads.
|
|
36
|
+
* Standalone for the same reason as {@link buildIdCondition}.
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildBooleanConditions(columns: {
|
|
39
|
+
isDefault: AnyColumn;
|
|
40
|
+
isActive: AnyColumn;
|
|
41
|
+
}, filter: {
|
|
42
|
+
isDefault?: unknown;
|
|
43
|
+
isActive?: unknown;
|
|
44
|
+
}): SQL[];
|
|
45
|
+
/**
|
|
46
|
+
* Schema table interface for access control queries. Every catalog entity
|
|
47
|
+
* carries the same five columns, which is what lets ONE predicate serve
|
|
48
|
+
* pipelines, plugins and templates alike.
|
|
49
|
+
*/
|
|
50
|
+
export interface AccessControlSchema {
|
|
51
|
+
id: AnyColumn;
|
|
52
|
+
orgId: AnyColumn;
|
|
53
|
+
/** Three-rung sharing ladder — see api-core's `Visibility`. */
|
|
54
|
+
visibility: AnyColumn;
|
|
55
|
+
/** Author. Owns the `private` rung. */
|
|
56
|
+
createdBy: AnyColumn;
|
|
57
|
+
isDefault: AnyColumn;
|
|
58
|
+
isActive: AnyColumn;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Base filter interface with common access control fields.
|
|
62
|
+
*
|
|
63
|
+
* `viewerUserId` / `viewerIsSuperAdmin` are SERVER-SET (stamped from the request's
|
|
64
|
+
* tenant context by `withViewerContext`), never client-supplied — see
|
|
65
|
+
* `viewer-context.ts` for why the tenant context is the channel.
|
|
66
|
+
*/
|
|
67
|
+
export interface BaseAccessFilter {
|
|
68
|
+
id?: string | string[];
|
|
69
|
+
visibility?: string;
|
|
70
|
+
isDefault?: boolean | string;
|
|
71
|
+
isActive?: boolean | string;
|
|
72
|
+
viewerUserId?: string;
|
|
73
|
+
viewerIsSuperAdmin?: boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Generic access control query builder for multi-tenant entities.
|
|
77
|
+
*
|
|
78
|
+
* Consolidates duplicate access control logic shared across pipeline and plugin queries.
|
|
79
|
+
* Handles:
|
|
80
|
+
* - Multi-tenant access control (public/private/org-and-public)
|
|
81
|
+
* - UUID prefix matching for ID filters
|
|
82
|
+
* - Boolean field normalization
|
|
83
|
+
*
|
|
84
|
+
* @typeParam TSchema - Schema table type with access control fields
|
|
85
|
+
* @typeParam TFilter - Filter type extending BaseAccessFilter
|
|
86
|
+
*/
|
|
87
|
+
export declare class AccessControlQueryBuilder<TSchema extends AccessControlSchema, TFilter extends BaseAccessFilter> {
|
|
88
|
+
private schema;
|
|
89
|
+
constructor(schema: TSchema);
|
|
90
|
+
/**
|
|
91
|
+
* Build the caller's visible slice of a catalog, from the three-rung
|
|
92
|
+
* `visibility` ladder shared by every catalog entity.
|
|
93
|
+
*
|
|
94
|
+
* Effective read set for a caller in org `O` as user `V` whose parent org is `P`:
|
|
95
|
+
*
|
|
96
|
+
* (org_id = O AND (visibility <> 'private' OR created_by = V))
|
|
97
|
+
* OR (visibility = 'public' AND (org_id = 'system' OR org_id = P))
|
|
98
|
+
*
|
|
99
|
+
* i.e. your own org's shared rungs plus your own drafts, widened by the system
|
|
100
|
+
* org's public catalog (the standing "system-org content is visible from every
|
|
101
|
+
* org" rule) and — for a team — its parent's public rows. The `public`-only
|
|
102
|
+
* restriction applies solely to those OTHER orgs' rows; within your own org you
|
|
103
|
+
* always see everything you are entitled to, or a freshly-created private row
|
|
104
|
+
* would vanish from its own author's listing.
|
|
105
|
+
*
|
|
106
|
+
* An explicit `visibility` filter NARROWS within that set, never widens it —
|
|
107
|
+
* so `?visibility=public` still surfaces the system-org catalog.
|
|
108
|
+
*
|
|
109
|
+
* Fails CLOSED on both axes: no `orgId` (anonymous) ⇒ system-org public only;
|
|
110
|
+
* no `viewerUserId` ⇒ the private rung matches nothing rather than everything.
|
|
111
|
+
* `viewerIsSuperAdmin` lifts the private rung only — a platform operator
|
|
112
|
+
* administers the whole catalog.
|
|
113
|
+
*
|
|
114
|
+
* @param filter - Filter criteria
|
|
115
|
+
* @param orgId - User's organization ID (optional)
|
|
116
|
+
* @param parentOrgId - Parent org ID when the caller is a team (optional)
|
|
117
|
+
* @returns Array of SQL conditions for access control
|
|
118
|
+
*/
|
|
119
|
+
protected buildAccessControl(filter: Partial<TFilter>, orgId?: string, parentOrgId?: string): SQL[];
|
|
120
|
+
/**
|
|
121
|
+
* Build ID filter with UUID prefix matching support
|
|
122
|
+
*
|
|
123
|
+
* - Full UUID: Exact match
|
|
124
|
+
* - Partial UUID: Prefix match using SQL LIKE
|
|
125
|
+
*
|
|
126
|
+
* @param id - ID filter value (full or partial UUID)
|
|
127
|
+
* @returns SQL condition or null if no ID filter
|
|
128
|
+
*/
|
|
129
|
+
protected buildIdFilter(id: unknown): SQL | null;
|
|
130
|
+
/**
|
|
131
|
+
* Build boolean field conditions (isDefault, isActive)
|
|
132
|
+
*
|
|
133
|
+
* @param filter - Filter criteria
|
|
134
|
+
* @returns Array of SQL conditions for boolean fields
|
|
135
|
+
*/
|
|
136
|
+
protected buildBooleanFilters(filter: Partial<TFilter>): SQL[];
|
|
137
|
+
/**
|
|
138
|
+
* Build all common conditions (access control + ID + booleans)
|
|
139
|
+
*
|
|
140
|
+
* This combines all the generic filters that apply to any access-controlled entity.
|
|
141
|
+
* Subclasses should call this and add entity-specific conditions.
|
|
142
|
+
*
|
|
143
|
+
* @param filter - Filter criteria
|
|
144
|
+
* @param orgId - User's organization ID (optional — falls back to system-public-only)
|
|
145
|
+
* @returns Array of SQL conditions
|
|
146
|
+
*/
|
|
147
|
+
buildCommonConditions(filter: Partial<TFilter>, orgId?: string, parentOrgId?: string): SQL[];
|
|
148
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Copyright 2026 Pipeline Builder Contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { SYSTEM_ORG_ID } from '@pipeline-builder/api-core';
|
|
4
|
+
import { and, eq, ne, or, sql, SQL } from 'drizzle-orm';
|
|
5
|
+
const FULL_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
6
|
+
/**
|
|
7
|
+
* Escape SQL LIKE wildcard characters to prevent wildcard injection.
|
|
8
|
+
* Replaces `%` → `\\%`, `_` → `\\_`, and `\\` → `\\\\`.
|
|
9
|
+
*/
|
|
10
|
+
export function escapeLikeWildcards(str) {
|
|
11
|
+
return str.replace(/\\/g, '\\\\').replace(/%/g, '\\%').replace(/_/g, '\\_');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Build a condition that checks if a JSONB text array column contains a keyword (case-insensitive).
|
|
15
|
+
* Used for keywords/tags filtering on pipelines, plugins, and compliance rules.
|
|
16
|
+
*/
|
|
17
|
+
export function buildJsonbKeywordCondition(column, keyword) {
|
|
18
|
+
const escaped = escapeLikeWildcards(keyword.toLowerCase());
|
|
19
|
+
return sql `EXISTS (SELECT 1 FROM jsonb_array_elements_text(${column}) AS el WHERE lower(el) LIKE ${'%' + escaped + '%'})`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parse boolean filter value from string or boolean
|
|
23
|
+
*/
|
|
24
|
+
export function parseBooleanFilter(value) {
|
|
25
|
+
if (typeof value === 'boolean')
|
|
26
|
+
return value;
|
|
27
|
+
if (typeof value === 'string')
|
|
28
|
+
return value === 'true';
|
|
29
|
+
return Boolean(value);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Normalize string filter value to lowercase
|
|
33
|
+
*/
|
|
34
|
+
export function normalizeStringFilter(value) {
|
|
35
|
+
return typeof value === 'string' ? value.toLowerCase() : String(value).toLowerCase();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Build an ID predicate with UUID prefix matching.
|
|
39
|
+
*
|
|
40
|
+
* - Full UUID → exact match
|
|
41
|
+
* - Partial UUID → prefix match via `LIKE` (a list-search affordance)
|
|
42
|
+
* - Absent → `null` (no predicate)
|
|
43
|
+
*
|
|
44
|
+
* Standalone so entities that DON'T use {@link AccessControlQueryBuilder}'s
|
|
45
|
+
* access control (e.g. pipeline templates, which carry their own three-rung
|
|
46
|
+
* visibility ladder) still share one id-matching implementation.
|
|
47
|
+
*/
|
|
48
|
+
export function buildIdCondition(idColumn, id) {
|
|
49
|
+
if (id === undefined || id === null)
|
|
50
|
+
return null;
|
|
51
|
+
const idString = String(id).toLowerCase();
|
|
52
|
+
if (FULL_UUID.test(idString)) {
|
|
53
|
+
return eq(idColumn, idString);
|
|
54
|
+
}
|
|
55
|
+
// Escape SQL LIKE wildcards to prevent wildcard injection
|
|
56
|
+
const escaped = escapeLikeWildcards(idString);
|
|
57
|
+
return sql `${idColumn}::text LIKE ${escaped + '%'} ESCAPE '\\'`;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build the `isDefault` / `isActive` predicates shared by every catalog entity.
|
|
61
|
+
* `isActive` defaults to true so soft-deleted rows stay out of normal reads.
|
|
62
|
+
* Standalone for the same reason as {@link buildIdCondition}.
|
|
63
|
+
*/
|
|
64
|
+
export function buildBooleanConditions(columns, filter) {
|
|
65
|
+
const conditions = [];
|
|
66
|
+
if (filter.isDefault !== undefined) {
|
|
67
|
+
conditions.push(eq(columns.isDefault, parseBooleanFilter(filter.isDefault)));
|
|
68
|
+
}
|
|
69
|
+
if (filter.isActive !== undefined) {
|
|
70
|
+
conditions.push(eq(columns.isActive, parseBooleanFilter(filter.isActive)));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// Default to active records only to exclude soft-deleted entities
|
|
74
|
+
conditions.push(eq(columns.isActive, true));
|
|
75
|
+
}
|
|
76
|
+
return conditions;
|
|
77
|
+
}
|
|
78
|
+
/** Fail-closed predicate: matches no rows. */
|
|
79
|
+
const NO_ROWS = sql `false`;
|
|
80
|
+
/**
|
|
81
|
+
* Generic access control query builder for multi-tenant entities.
|
|
82
|
+
*
|
|
83
|
+
* Consolidates duplicate access control logic shared across pipeline and plugin queries.
|
|
84
|
+
* Handles:
|
|
85
|
+
* - Multi-tenant access control (public/private/org-and-public)
|
|
86
|
+
* - UUID prefix matching for ID filters
|
|
87
|
+
* - Boolean field normalization
|
|
88
|
+
*
|
|
89
|
+
* @typeParam TSchema - Schema table type with access control fields
|
|
90
|
+
* @typeParam TFilter - Filter type extending BaseAccessFilter
|
|
91
|
+
*/
|
|
92
|
+
export class AccessControlQueryBuilder {
|
|
93
|
+
schema;
|
|
94
|
+
constructor(schema) {
|
|
95
|
+
this.schema = schema;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Build the caller's visible slice of a catalog, from the three-rung
|
|
99
|
+
* `visibility` ladder shared by every catalog entity.
|
|
100
|
+
*
|
|
101
|
+
* Effective read set for a caller in org `O` as user `V` whose parent org is `P`:
|
|
102
|
+
*
|
|
103
|
+
* (org_id = O AND (visibility <> 'private' OR created_by = V))
|
|
104
|
+
* OR (visibility = 'public' AND (org_id = 'system' OR org_id = P))
|
|
105
|
+
*
|
|
106
|
+
* i.e. your own org's shared rungs plus your own drafts, widened by the system
|
|
107
|
+
* org's public catalog (the standing "system-org content is visible from every
|
|
108
|
+
* org" rule) and — for a team — its parent's public rows. The `public`-only
|
|
109
|
+
* restriction applies solely to those OTHER orgs' rows; within your own org you
|
|
110
|
+
* always see everything you are entitled to, or a freshly-created private row
|
|
111
|
+
* would vanish from its own author's listing.
|
|
112
|
+
*
|
|
113
|
+
* An explicit `visibility` filter NARROWS within that set, never widens it —
|
|
114
|
+
* so `?visibility=public` still surfaces the system-org catalog.
|
|
115
|
+
*
|
|
116
|
+
* Fails CLOSED on both axes: no `orgId` (anonymous) ⇒ system-org public only;
|
|
117
|
+
* no `viewerUserId` ⇒ the private rung matches nothing rather than everything.
|
|
118
|
+
* `viewerIsSuperAdmin` lifts the private rung only — a platform operator
|
|
119
|
+
* administers the whole catalog.
|
|
120
|
+
*
|
|
121
|
+
* @param filter - Filter criteria
|
|
122
|
+
* @param orgId - User's organization ID (optional)
|
|
123
|
+
* @param parentOrgId - Parent org ID when the caller is a team (optional)
|
|
124
|
+
* @returns Array of SQL conditions for access control
|
|
125
|
+
*/
|
|
126
|
+
buildAccessControl(filter, orgId, parentOrgId) {
|
|
127
|
+
const conditions = [];
|
|
128
|
+
const requested = filter.visibility;
|
|
129
|
+
if (!orgId) {
|
|
130
|
+
// No org context — only the system org's public catalog.
|
|
131
|
+
conditions.push(eq(this.schema.orgId, SYSTEM_ORG_ID));
|
|
132
|
+
conditions.push(eq(this.schema.visibility, 'public'));
|
|
133
|
+
// An anonymous caller asking for a narrower rung gets nothing, rather than
|
|
134
|
+
// having the narrowing silently ignored.
|
|
135
|
+
if (requested !== undefined && requested !== 'public')
|
|
136
|
+
conditions.push(NO_ROWS);
|
|
137
|
+
return conditions;
|
|
138
|
+
}
|
|
139
|
+
const normalizedOrgId = orgId.toLowerCase();
|
|
140
|
+
// Own-org rows: everything EXCEPT other people's private drafts.
|
|
141
|
+
const ownDraftsOnly = filter.viewerUserId ? eq(this.schema.createdBy, filter.viewerUserId) : NO_ROWS;
|
|
142
|
+
const ownOrg = filter.viewerIsSuperAdmin
|
|
143
|
+
? eq(this.schema.orgId, normalizedOrgId)
|
|
144
|
+
: and(eq(this.schema.orgId, normalizedOrgId), or(ne(this.schema.visibility, 'private'), ownDraftsOnly));
|
|
145
|
+
// Rows from OTHER orgs are only ever visible at the `public` rung.
|
|
146
|
+
const otherOrgScopes = [eq(this.schema.orgId, SYSTEM_ORG_ID)];
|
|
147
|
+
if (parentOrgId)
|
|
148
|
+
otherOrgScopes.push(eq(this.schema.orgId, parentOrgId.toLowerCase()));
|
|
149
|
+
const otherOrgsPublic = and(eq(this.schema.visibility, 'public'), or(...otherOrgScopes));
|
|
150
|
+
conditions.push(or(ownOrg, otherOrgsPublic));
|
|
151
|
+
if (requested !== undefined)
|
|
152
|
+
conditions.push(eq(this.schema.visibility, requested));
|
|
153
|
+
return conditions;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Build ID filter with UUID prefix matching support
|
|
157
|
+
*
|
|
158
|
+
* - Full UUID: Exact match
|
|
159
|
+
* - Partial UUID: Prefix match using SQL LIKE
|
|
160
|
+
*
|
|
161
|
+
* @param id - ID filter value (full or partial UUID)
|
|
162
|
+
* @returns SQL condition or null if no ID filter
|
|
163
|
+
*/
|
|
164
|
+
buildIdFilter(id) {
|
|
165
|
+
return buildIdCondition(this.schema.id, id);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Build boolean field conditions (isDefault, isActive)
|
|
169
|
+
*
|
|
170
|
+
* @param filter - Filter criteria
|
|
171
|
+
* @returns Array of SQL conditions for boolean fields
|
|
172
|
+
*/
|
|
173
|
+
buildBooleanFilters(filter) {
|
|
174
|
+
return buildBooleanConditions(this.schema, filter);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Build all common conditions (access control + ID + booleans)
|
|
178
|
+
*
|
|
179
|
+
* This combines all the generic filters that apply to any access-controlled entity.
|
|
180
|
+
* Subclasses should call this and add entity-specific conditions.
|
|
181
|
+
*
|
|
182
|
+
* @param filter - Filter criteria
|
|
183
|
+
* @param orgId - User's organization ID (optional — falls back to system-public-only)
|
|
184
|
+
* @returns Array of SQL conditions
|
|
185
|
+
*/
|
|
186
|
+
buildCommonConditions(filter, orgId, parentOrgId) {
|
|
187
|
+
const conditions = [];
|
|
188
|
+
// Access control (multi-tenant) — handles visibility internally
|
|
189
|
+
conditions.push(...this.buildAccessControl(filter, orgId, parentOrgId));
|
|
190
|
+
// ID filter with prefix matching
|
|
191
|
+
const idCondition = this.buildIdFilter(filter.id);
|
|
192
|
+
if (idCondition)
|
|
193
|
+
conditions.push(idCondition);
|
|
194
|
+
// Boolean filters
|
|
195
|
+
conditions.push(...this.buildBooleanFilters(filter));
|
|
196
|
+
return conditions;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWNjZXNzLWNvbnRyb2wtYnVpbGRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9hcGkvYWNjZXNzLWNvbnRyb2wtYnVpbGRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSwrQ0FBK0M7QUFDL0Msc0NBQXNDO0FBRXRDLE9BQU8sRUFBRSxhQUFhLEVBQUUsTUFBTSw0QkFBNEIsQ0FBQztBQUMzRCxPQUFPLEVBQUUsR0FBRyxFQUFFLEVBQUUsRUFBRSxFQUFFLEVBQUUsRUFBRSxFQUFFLEdBQUcsRUFBRSxHQUFHLEVBQUUsTUFBTSxhQUFhLENBQUM7QUFHeEQsTUFBTSxTQUFTLEdBQUcsaUVBQWlFLENBQUM7QUFFcEY7OztHQUdHO0FBQ0gsTUFBTSxVQUFVLG1CQUFtQixDQUFDLEdBQVc7SUFDN0MsT0FBTyxHQUFHLENBQUMsT0FBTyxDQUFDLEtBQUssRUFBRSxNQUFNLENBQUMsQ0FBQyxPQUFPLENBQUMsSUFBSSxFQU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