@pipeline-builder/pipeline-data 3.1.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/README.md +34 -0
- package/drizzle.config.ts +17 -0
- package/lib/api/access-control-builder.d.ts +109 -0
- package/lib/api/access-control-builder.js +181 -0
- package/lib/api/crud-service.d.ts +170 -0
- package/lib/api/crud-service.js +387 -0
- package/lib/api/query-builders.d.ts +74 -0
- package/lib/api/query-builders.js +336 -0
- package/lib/api/reporting-service.d.ts +131 -0
- package/lib/api/reporting-service.js +248 -0
- package/lib/core/query-filters.d.ts +235 -0
- package/lib/core/query-filters.js +23 -0
- package/lib/database/drizzle-schema.d.ts +10043 -0
- package/lib/database/drizzle-schema.js +715 -0
- package/lib/database/index.d.ts +3 -0
- package/lib/database/index.js +22 -0
- package/lib/database/postgres-connection.d.ts +232 -0
- package/lib/database/postgres-connection.js +456 -0
- package/lib/database/retry-strategy.d.ts +68 -0
- package/lib/database/retry-strategy.js +126 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.js +52 -0
- package/package.json +125 -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,34 @@
|
|
|
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 built-in multi-tenant access control used by every backend service.
|
|
6
|
+
|
|
7
|
+
## Key Exports
|
|
8
|
+
|
|
9
|
+
### Connection
|
|
10
|
+
- `getConnection`, `db` — Shared PostgreSQL pool and Drizzle client
|
|
11
|
+
- `ConnectionRetryStrategy` — Retry logic for transient connection failures
|
|
12
|
+
|
|
13
|
+
### Schemas
|
|
14
|
+
- `schema` — All Drizzle table definitions (pipeline, plugin, compliance, events, …)
|
|
15
|
+
- Entity types: `Pipeline`, `Plugin`, `ComplianceRule`, `PipelineEvent`, `Message`
|
|
16
|
+
|
|
17
|
+
### CrudService
|
|
18
|
+
- `CrudService<TEntity, TFilter, TInsert, TUpdate>` — Abstract base providing `find`, `findById`, `create`, `update`, `delete`, `findPaginated`, plus per-entity lifecycle hooks and multi-tenant access control
|
|
19
|
+
- `FilterBuilder` — Type-safe pagination/sort/filter builder
|
|
20
|
+
|
|
21
|
+
### Query Builders
|
|
22
|
+
- `BaseQueryBuilder` — Generic insert/update/delete
|
|
23
|
+
- `pipelineBuilder`, `pluginBuilder` — Entity-specific query helpers
|
|
24
|
+
|
|
25
|
+
### Helpers
|
|
26
|
+
- `withTimestamps`, `softDelete` — Common column decorators
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
Apache-2.0. See [LICENSE](./LICENSE).
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
**Keywords:** aws, codepipeline, codebuild, cicd, ci-cd, devops, cdk, aws-cdk, cloudformation, pipeline, pipeline-as-code, containerized, docker, kubernetes, plugins, typescript, self-service, multi-tenant, compliance, automation, infrastructure-as-code, iac, cli
|
|
@@ -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,109 @@
|
|
|
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
|
+
* Schema table interface for access control queries
|
|
23
|
+
*/
|
|
24
|
+
export interface AccessControlSchema {
|
|
25
|
+
id: AnyColumn;
|
|
26
|
+
orgId: AnyColumn;
|
|
27
|
+
accessModifier: AnyColumn;
|
|
28
|
+
isDefault: AnyColumn;
|
|
29
|
+
isActive: AnyColumn;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Base filter interface with common access control fields
|
|
33
|
+
*/
|
|
34
|
+
export interface BaseAccessFilter {
|
|
35
|
+
id?: string | string[];
|
|
36
|
+
accessModifier?: string;
|
|
37
|
+
isDefault?: boolean | string;
|
|
38
|
+
isActive?: boolean | string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Generic access control query builder for multi-tenant entities.
|
|
42
|
+
*
|
|
43
|
+
* Consolidates duplicate access control logic shared across pipeline and plugin queries.
|
|
44
|
+
* Handles:
|
|
45
|
+
* - Multi-tenant access control (public/private/org-and-public)
|
|
46
|
+
* - UUID prefix matching for ID filters
|
|
47
|
+
* - Boolean field normalization
|
|
48
|
+
*
|
|
49
|
+
* @typeParam TSchema - Schema table type with access control fields
|
|
50
|
+
* @typeParam TFilter - Filter type extending BaseAccessFilter
|
|
51
|
+
*/
|
|
52
|
+
export declare class AccessControlQueryBuilder<TSchema extends AccessControlSchema, TFilter extends BaseAccessFilter> {
|
|
53
|
+
private schema;
|
|
54
|
+
constructor(schema: TSchema);
|
|
55
|
+
/**
|
|
56
|
+
* Build access control conditions based on orgId and accessModifier filter.
|
|
57
|
+
*
|
|
58
|
+
* Without orgId (anonymous):
|
|
59
|
+
* orgId='system' AND accessModifier='public'
|
|
60
|
+
*
|
|
61
|
+
* With orgId:
|
|
62
|
+
* - accessModifier='private': orgId=$org AND accessModifier='private'
|
|
63
|
+
* - accessModifier='public': orgId=$org AND accessModifier='public'
|
|
64
|
+
* - no accessModifier: accessModifier='public' AND (orgId=$org OR orgId='system')
|
|
65
|
+
*
|
|
66
|
+
* @param filter - Filter criteria
|
|
67
|
+
* @param orgId - User's organization ID (optional)
|
|
68
|
+
* @returns Array of SQL conditions for access control
|
|
69
|
+
*/
|
|
70
|
+
protected buildAccessControl(filter: Partial<TFilter>, orgId?: string): SQL[];
|
|
71
|
+
/**
|
|
72
|
+
* Build ID filter with UUID prefix matching support
|
|
73
|
+
*
|
|
74
|
+
* - Full UUID: Exact match
|
|
75
|
+
* - Partial UUID: Prefix match using SQL LIKE
|
|
76
|
+
*
|
|
77
|
+
* @param id - ID filter value (full or partial UUID)
|
|
78
|
+
* @returns SQL condition or null if no ID filter
|
|
79
|
+
*/
|
|
80
|
+
protected buildIdFilter(id: unknown): SQL | null;
|
|
81
|
+
/**
|
|
82
|
+
* Build boolean field conditions (isDefault, isActive)
|
|
83
|
+
*
|
|
84
|
+
* @param filter - Filter criteria
|
|
85
|
+
* @returns Array of SQL conditions for boolean fields
|
|
86
|
+
*/
|
|
87
|
+
protected buildBooleanFilters(filter: Partial<TFilter>): SQL[];
|
|
88
|
+
/**
|
|
89
|
+
* Build explicit accessModifier filter
|
|
90
|
+
*
|
|
91
|
+
* Note: This is separate from access control logic - it filters by the exact
|
|
92
|
+
* accessModifier value rather than applying multi-tenant access rules.
|
|
93
|
+
*
|
|
94
|
+
* @param accessModifier - Access modifier filter value
|
|
95
|
+
* @returns SQL condition or null if no accessModifier filter
|
|
96
|
+
*/
|
|
97
|
+
protected buildAccessModifierFilter(accessModifier: unknown): SQL | null;
|
|
98
|
+
/**
|
|
99
|
+
* Build all common conditions (access control + ID + booleans)
|
|
100
|
+
*
|
|
101
|
+
* This combines all the generic filters that apply to any access-controlled entity.
|
|
102
|
+
* Subclasses should call this and add entity-specific conditions.
|
|
103
|
+
*
|
|
104
|
+
* @param filter - Filter criteria
|
|
105
|
+
* @param orgId - User's organization ID (optional — falls back to system-public-only)
|
|
106
|
+
* @returns Array of SQL conditions
|
|
107
|
+
*/
|
|
108
|
+
buildCommonConditions(filter: Partial<TFilter>, orgId?: string): SQL[];
|
|
109
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2026 Pipeline Builder Contributors
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.AccessControlQueryBuilder = void 0;
|
|
6
|
+
exports.escapeLikeWildcards = escapeLikeWildcards;
|
|
7
|
+
exports.buildJsonbKeywordCondition = buildJsonbKeywordCondition;
|
|
8
|
+
exports.parseBooleanFilter = parseBooleanFilter;
|
|
9
|
+
exports.normalizeStringFilter = normalizeStringFilter;
|
|
10
|
+
const api_core_1 = require("@pipeline-builder/api-core");
|
|
11
|
+
const drizzle_orm_1 = require("drizzle-orm");
|
|
12
|
+
const FULL_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
13
|
+
/**
|
|
14
|
+
* Escape SQL LIKE wildcard characters to prevent wildcard injection.
|
|
15
|
+
* Replaces `%` → `\\%`, `_` → `\\_`, and `\\` → `\\\\`.
|
|
16
|
+
*/
|
|
17
|
+
function escapeLikeWildcards(str) {
|
|
18
|
+
return str.replace(/\\/g, '\\\\').replace(/%/g, '\\%').replace(/_/g, '\\_');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build a condition that checks if a JSONB text array column contains a keyword (case-insensitive).
|
|
22
|
+
* Used for keywords/tags filtering on pipelines, plugins, and compliance rules.
|
|
23
|
+
*/
|
|
24
|
+
function buildJsonbKeywordCondition(column, keyword) {
|
|
25
|
+
const escaped = escapeLikeWildcards(keyword.toLowerCase());
|
|
26
|
+
return (0, drizzle_orm_1.sql) `EXISTS (SELECT 1 FROM jsonb_array_elements_text(${column}) AS el WHERE lower(el) LIKE ${'%' + escaped + '%'})`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parse boolean filter value from string or boolean
|
|
30
|
+
*/
|
|
31
|
+
function parseBooleanFilter(value) {
|
|
32
|
+
if (typeof value === 'boolean')
|
|
33
|
+
return value;
|
|
34
|
+
if (typeof value === 'string')
|
|
35
|
+
return value === 'true';
|
|
36
|
+
return Boolean(value);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Normalize string filter value to lowercase
|
|
40
|
+
*/
|
|
41
|
+
function normalizeStringFilter(value) {
|
|
42
|
+
return typeof value === 'string' ? value.toLowerCase() : String(value).toLowerCase();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Generic access control query builder for multi-tenant entities.
|
|
46
|
+
*
|
|
47
|
+
* Consolidates duplicate access control logic shared across pipeline and plugin queries.
|
|
48
|
+
* Handles:
|
|
49
|
+
* - Multi-tenant access control (public/private/org-and-public)
|
|
50
|
+
* - UUID prefix matching for ID filters
|
|
51
|
+
* - Boolean field normalization
|
|
52
|
+
*
|
|
53
|
+
* @typeParam TSchema - Schema table type with access control fields
|
|
54
|
+
* @typeParam TFilter - Filter type extending BaseAccessFilter
|
|
55
|
+
*/
|
|
56
|
+
class AccessControlQueryBuilder {
|
|
57
|
+
schema;
|
|
58
|
+
constructor(schema) {
|
|
59
|
+
this.schema = schema;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Build access control conditions based on orgId and accessModifier filter.
|
|
63
|
+
*
|
|
64
|
+
* Without orgId (anonymous):
|
|
65
|
+
* orgId='system' AND accessModifier='public'
|
|
66
|
+
*
|
|
67
|
+
* With orgId:
|
|
68
|
+
* - accessModifier='private': orgId=$org AND accessModifier='private'
|
|
69
|
+
* - accessModifier='public': orgId=$org AND accessModifier='public'
|
|
70
|
+
* - no accessModifier: accessModifier='public' AND (orgId=$org OR orgId='system')
|
|
71
|
+
*
|
|
72
|
+
* @param filter - Filter criteria
|
|
73
|
+
* @param orgId - User's organization ID (optional)
|
|
74
|
+
* @returns Array of SQL conditions for access control
|
|
75
|
+
*/
|
|
76
|
+
buildAccessControl(filter, orgId) {
|
|
77
|
+
const conditions = [];
|
|
78
|
+
if (!orgId) {
|
|
79
|
+
// No org context — only system org's public records
|
|
80
|
+
conditions.push((0, drizzle_orm_1.eq)(this.schema.orgId, api_core_1.SYSTEM_ORG_ID));
|
|
81
|
+
conditions.push((0, drizzle_orm_1.eq)(this.schema.accessModifier, api_core_1.AccessModifier.PUBLIC));
|
|
82
|
+
return conditions;
|
|
83
|
+
}
|
|
84
|
+
const normalizedOrgId = orgId.toLowerCase();
|
|
85
|
+
const accessModifier = filter.accessModifier;
|
|
86
|
+
if (accessModifier !== undefined) {
|
|
87
|
+
// Explicit filter: scope to user's org + requested access modifier
|
|
88
|
+
const normalized = typeof accessModifier === 'string'
|
|
89
|
+
? accessModifier.toLowerCase()
|
|
90
|
+
: String(accessModifier).toLowerCase();
|
|
91
|
+
conditions.push((0, drizzle_orm_1.eq)(this.schema.orgId, normalizedOrgId));
|
|
92
|
+
conditions.push((0, drizzle_orm_1.eq)(this.schema.accessModifier, normalized));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// Default: user's org public + system org public
|
|
96
|
+
conditions.push((0, drizzle_orm_1.eq)(this.schema.accessModifier, api_core_1.AccessModifier.PUBLIC));
|
|
97
|
+
conditions.push((0, drizzle_orm_1.or)((0, drizzle_orm_1.eq)(this.schema.orgId, normalizedOrgId), (0, drizzle_orm_1.eq)(this.schema.orgId, api_core_1.SYSTEM_ORG_ID)));
|
|
98
|
+
}
|
|
99
|
+
return conditions;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Build ID filter with UUID prefix matching support
|
|
103
|
+
*
|
|
104
|
+
* - Full UUID: Exact match
|
|
105
|
+
* - Partial UUID: Prefix match using SQL LIKE
|
|
106
|
+
*
|
|
107
|
+
* @param id - ID filter value (full or partial UUID)
|
|
108
|
+
* @returns SQL condition or null if no ID filter
|
|
109
|
+
*/
|
|
110
|
+
buildIdFilter(id) {
|
|
111
|
+
if (id === undefined || id === null)
|
|
112
|
+
return null;
|
|
113
|
+
const idString = String(id).toLowerCase();
|
|
114
|
+
if (FULL_UUID.test(idString)) {
|
|
115
|
+
return (0, drizzle_orm_1.eq)(this.schema.id, idString);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// Escape SQL LIKE wildcards to prevent wildcard injection
|
|
119
|
+
const escaped = escapeLikeWildcards(idString);
|
|
120
|
+
return (0, drizzle_orm_1.sql) `${this.schema.id}::text LIKE ${escaped + '%'} ESCAPE '\\'`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Build boolean field conditions (isDefault, isActive)
|
|
125
|
+
*
|
|
126
|
+
* @param filter - Filter criteria
|
|
127
|
+
* @returns Array of SQL conditions for boolean fields
|
|
128
|
+
*/
|
|
129
|
+
buildBooleanFilters(filter) {
|
|
130
|
+
const conditions = [];
|
|
131
|
+
if (filter.isDefault !== undefined) {
|
|
132
|
+
conditions.push((0, drizzle_orm_1.eq)(this.schema.isDefault, parseBooleanFilter(filter.isDefault)));
|
|
133
|
+
}
|
|
134
|
+
if (filter.isActive !== undefined) {
|
|
135
|
+
conditions.push((0, drizzle_orm_1.eq)(this.schema.isActive, parseBooleanFilter(filter.isActive)));
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// Default to active records only to exclude soft-deleted entities
|
|
139
|
+
conditions.push((0, drizzle_orm_1.eq)(this.schema.isActive, true));
|
|
140
|
+
}
|
|
141
|
+
return conditions;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Build explicit accessModifier filter
|
|
145
|
+
*
|
|
146
|
+
* Note: This is separate from access control logic - it filters by the exact
|
|
147
|
+
* accessModifier value rather than applying multi-tenant access rules.
|
|
148
|
+
*
|
|
149
|
+
* @param accessModifier - Access modifier filter value
|
|
150
|
+
* @returns SQL condition or null if no accessModifier filter
|
|
151
|
+
*/
|
|
152
|
+
buildAccessModifierFilter(accessModifier) {
|
|
153
|
+
if (accessModifier === undefined)
|
|
154
|
+
return null;
|
|
155
|
+
return (0, drizzle_orm_1.sql) `${this.schema.accessModifier} = ${normalizeStringFilter(accessModifier)}`;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Build all common conditions (access control + ID + booleans)
|
|
159
|
+
*
|
|
160
|
+
* This combines all the generic filters that apply to any access-controlled entity.
|
|
161
|
+
* Subclasses should call this and add entity-specific conditions.
|
|
162
|
+
*
|
|
163
|
+
* @param filter - Filter criteria
|
|
164
|
+
* @param orgId - User's organization ID (optional — falls back to system-public-only)
|
|
165
|
+
* @returns Array of SQL conditions
|
|
166
|
+
*/
|
|
167
|
+
buildCommonConditions(filter, orgId) {
|
|
168
|
+
const conditions = [];
|
|
169
|
+
// Access control (multi-tenant) — handles accessModifier internally
|
|
170
|
+
conditions.push(...this.buildAccessControl(filter, orgId));
|
|
171
|
+
// ID filter with prefix matching
|
|
172
|
+
const idCondition = this.buildIdFilter(filter.id);
|
|
173
|
+
if (idCondition)
|
|
174
|
+
conditions.push(idCondition);
|
|
175
|
+
// Boolean filters
|
|
176
|
+
conditions.push(...this.buildBooleanFilters(filter));
|
|
177
|
+
return conditions;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.AccessControlQueryBuilder = AccessControlQueryBuilder;
|
|
181
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWNjZXNzLWNvbnRyb2wtYnVpbGRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9hcGkvYWNjZXNzLWNvbnRyb2wtYnVpbGRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsK0NBQStDO0FBQy9DLHNDQUFzQzs7O0FBWXRDLGtEQUVDO0FBTUQsZ0VBR0M7QUFLRCxnREFJQztBQUtELHNEQUVDO0FBckNELHlEQUEyRTtBQUMzRSw2Q0FBK0M7QUFHL0MsTUFBTSxTQUFTLEdBQUcsaUVBQWlFLENBQUM7QUFFcEY7OztHQUdHO0FBQ0gsU0FBZ0IsbUJBQW1CLENBQUMsR0FBVztJQUM3QyxPQUFPLEdBQUcsQ0FBQyxPQUFPLENBQUMsS0FBSyxFQUFFLE1BQU0sQ0FBQyxDQUFDLE9BQU8sQ0FBQyxJQUFJLEVBQUUsS0FBSyxDQUFDLENBQUMs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