@zenstackhq/plugin-policy 3.5.0-beta.3 → 3.5.0-beta.4

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/dist/index.d.cts CHANGED
@@ -3,7 +3,18 @@ import * as _zenstackhq_orm from '@zenstackhq/orm';
3
3
  import { RuntimePlugin, OnKyselyQueryArgs } from '@zenstackhq/orm';
4
4
  import { SchemaDef } from '@zenstackhq/orm/schema';
5
5
 
6
- declare class PolicyPlugin implements RuntimePlugin<SchemaDef, {}, {}> {
6
+ type PolicyPluginOptions = {
7
+ /**
8
+ * Dangerously bypasses access-policy enforcement for raw SQL queries.
9
+ * Raw queries remain in the current transaction, but the policy plugin will
10
+ * not inspect or reject them.
11
+ */
12
+ dangerouslyAllowRawSql?: boolean;
13
+ };
14
+
15
+ declare class PolicyPlugin implements RuntimePlugin<SchemaDef, {}, {}, {}> {
16
+ private readonly options;
17
+ constructor(options?: PolicyPluginOptions);
7
18
  get id(): "policy";
8
19
  get name(): string;
9
20
  get description(): string;
@@ -13,4 +24,4 @@ declare class PolicyPlugin implements RuntimePlugin<SchemaDef, {}, {}> {
13
24
  onKyselyQuery({ query, client, proceed }: OnKyselyQueryArgs<SchemaDef>): Promise<kysely.QueryResult<any>>;
14
25
  }
15
26
 
16
- export { PolicyPlugin };
27
+ export { PolicyPlugin, type PolicyPluginOptions };
package/dist/index.d.ts CHANGED
@@ -3,7 +3,18 @@ import * as _zenstackhq_orm from '@zenstackhq/orm';
3
3
  import { RuntimePlugin, OnKyselyQueryArgs } from '@zenstackhq/orm';
4
4
  import { SchemaDef } from '@zenstackhq/orm/schema';
5
5
 
6
- declare class PolicyPlugin implements RuntimePlugin<SchemaDef, {}, {}> {
6
+ type PolicyPluginOptions = {
7
+ /**
8
+ * Dangerously bypasses access-policy enforcement for raw SQL queries.
9
+ * Raw queries remain in the current transaction, but the policy plugin will
10
+ * not inspect or reject them.
11
+ */
12
+ dangerouslyAllowRawSql?: boolean;
13
+ };
14
+
15
+ declare class PolicyPlugin implements RuntimePlugin<SchemaDef, {}, {}, {}> {
16
+ private readonly options;
17
+ constructor(options?: PolicyPluginOptions);
7
18
  get id(): "policy";
8
19
  get name(): string;
9
20
  get description(): string;
@@ -13,4 +24,4 @@ declare class PolicyPlugin implements RuntimePlugin<SchemaDef, {}, {}> {
13
24
  onKyselyQuery({ query, client, proceed }: OnKyselyQueryArgs<SchemaDef>): Promise<kysely.QueryResult<any>>;
14
25
  }
15
26
 
16
- export { PolicyPlugin };
27
+ export { PolicyPlugin, type PolicyPluginOptions };
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { ExpressionWrapper as ExpressionWrapper3, ValueNode as ValueNode4 } from
10
10
  import { invariant as invariant3 } from "@zenstackhq/common-helpers";
11
11
  import { getCrudDialect as getCrudDialect2, QueryUtils as QueryUtils2, RejectedByPolicyReason, SchemaUtils as SchemaUtils2 } from "@zenstackhq/orm";
12
12
  import { ExpressionUtils as ExpressionUtils4 } from "@zenstackhq/orm/schema";
13
- import { AliasNode as AliasNode3, BinaryOperationNode as BinaryOperationNode3, ColumnNode as ColumnNode3, DeleteQueryNode, expressionBuilder as expressionBuilder2, ExpressionWrapper as ExpressionWrapper2, FromNode as FromNode2, IdentifierNode as IdentifierNode2, InsertQueryNode, OperationNodeTransformer, OperatorNode as OperatorNode3, ParensNode as ParensNode2, PrimitiveValueListNode, ReferenceNode as ReferenceNode3, ReturningNode, SelectAllNode, SelectionNode as SelectionNode2, SelectQueryNode as SelectQueryNode2, sql, TableNode as TableNode3, UpdateQueryNode, ValueNode as ValueNode3, ValuesNode, WhereNode as WhereNode2 } from "kysely";
13
+ import { AliasNode as AliasNode3, BinaryOperationNode as BinaryOperationNode3, ColumnNode as ColumnNode3, DeleteQueryNode, expressionBuilder as expressionBuilder2, ExpressionWrapper as ExpressionWrapper2, FromNode as FromNode2, IdentifierNode as IdentifierNode2, InsertQueryNode, OperationNodeTransformer, OperatorNode as OperatorNode3, ParensNode as ParensNode2, PrimitiveValueListNode, RawNode, ReferenceNode as ReferenceNode3, ReturningNode, SelectAllNode, SelectionNode as SelectionNode2, SelectQueryNode as SelectQueryNode2, sql, TableNode as TableNode3, UpdateQueryNode, ValueNode as ValueNode3, ValuesNode, WhereNode as WhereNode2 } from "kysely";
14
14
  import { match as match3 } from "ts-pattern";
15
15
 
16
16
  // src/column-collector.ts
@@ -985,18 +985,19 @@ var PolicyHandler = class extends OperationNodeTransformer {
985
985
  __name(this, "PolicyHandler");
986
986
  }
987
987
  client;
988
+ options;
988
989
  dialect;
989
990
  eb = expressionBuilder2();
990
- constructor(client) {
991
- super(), this.client = client;
991
+ constructor(client, options = {}) {
992
+ super(), this.client = client, this.options = options;
992
993
  this.dialect = getCrudDialect2(this.client.$schema, this.client.$options);
993
994
  }
994
- get kysely() {
995
- return this.client.$qb;
996
- }
997
995
  // #region main entry point
998
996
  async handle(node, proceed) {
999
997
  if (!this.isCrudQueryNode(node)) {
998
+ if (this.options.dangerouslyAllowRawSql && RawNode.is(node)) {
999
+ return proceed(node);
1000
+ }
1000
1001
  throw createRejectedByPolicyError(void 0, RejectedByPolicyReason.OTHER, "non-CRUD queries are not allowed");
1001
1002
  }
1002
1003
  if (!this.isMutationQueryNode(node)) {
@@ -1923,6 +1924,10 @@ var PolicyPlugin = class {
1923
1924
  static {
1924
1925
  __name(this, "PolicyPlugin");
1925
1926
  }
1927
+ options;
1928
+ constructor(options = {}) {
1929
+ this.options = options;
1930
+ }
1926
1931
  get id() {
1927
1932
  return "policy";
1928
1933
  }
@@ -1938,7 +1943,7 @@ var PolicyPlugin = class {
1938
1943
  };
1939
1944
  }
1940
1945
  onKyselyQuery({ query, client, proceed }) {
1941
- const handler = new PolicyHandler(client);
1946
+ const handler = new PolicyHandler(client, this.options);
1942
1947
  return handler.handle(query, proceed);
1943
1948
  }
1944
1949
  };