@stonecrop/casl-middleware 0.13.4 → 0.13.6

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.
@@ -95,7 +95,7 @@ export declare interface FieldPermission {
95
95
  * Middleware function that wraps a GraphQL resolver with authorization logic
96
96
  * @public
97
97
  */
98
- export declare type MiddlewareFn = (resolve: ResolverFn, root: any, args: any, context: Context, info: GraphQLResolveInfo) => Promise<any> | any;
98
+ export declare type MiddlewareFn = (resolve: ResolverFn, root: any, args: any, context: Context, info: GraphQLResolveInfo) => any;
99
99
 
100
100
  /**
101
101
  * Configuration options for CASL middleware
@@ -140,7 +140,7 @@ export declare interface PluginOptions extends MiddlewareOptions {
140
140
  * GraphQL resolver function type
141
141
  * @public
142
142
  */
143
- export declare type ResolverFn = (root: any, args: any, context: Context, info: GraphQLResolveInfo) => Promise<any> | any;
143
+ export declare type ResolverFn = (root: any, args: any, context: Context, info: GraphQLResolveInfo) => any;
144
144
 
145
145
  /**
146
146
  * User information for authorization
@@ -164,22 +164,22 @@ function Ce(e) {
164
164
  }
165
165
  function Z(e, t) {
166
166
  const n = e.locationOffset.column - 1, s = "".padStart(n) + e.body, i = t.line - 1, r = e.locationOffset.line - 1, a = t.line + r, l = t.line === 1 ? n : 0, p = t.column + l, u = `${e.name}:${a}:${p}
167
- `, h = s.split(/\r\n|[\n\r]/g), d = h[i];
168
- if (d.length > 120) {
169
- const f = Math.floor(p / 80), x = p % 80, E = [];
170
- for (let N = 0; N < d.length; N += 80)
171
- E.push(d.slice(N, N + 80));
167
+ `, h = s.split(/\r\n|[\n\r]/g), E = h[i];
168
+ if (E.length > 120) {
169
+ const d = Math.floor(p / 80), x = p % 80, f = [];
170
+ for (let N = 0; N < E.length; N += 80)
171
+ f.push(E.slice(N, N + 80));
172
172
  return u + Y([
173
- [`${a} |`, E[0]],
174
- ...E.slice(1, f + 1).map((N) => ["|", N]),
173
+ [`${a} |`, f[0]],
174
+ ...f.slice(1, d + 1).map((N) => ["|", N]),
175
175
  ["|", "^".padStart(x)],
176
- ["|", E[f + 1]]
176
+ ["|", f[d + 1]]
177
177
  ]);
178
178
  }
179
179
  return u + Y([
180
180
  // Lines specified like this: ["prefix", "string"],
181
181
  [`${a - 1} |`, h[i - 1]],
182
- [`${a} |`, d],
182
+ [`${a} |`, E],
183
183
  ["|", "^".padStart(p)],
184
184
  [`${a + 1} |`, h[i + 1]]
185
185
  ]);
@@ -252,18 +252,18 @@ class B extends Error {
252
252
  */
253
253
  constructor(t, ...n) {
254
254
  var s, i, r;
255
- const { nodes: a, source: l, positions: p, path: u, originalError: h, extensions: d } = ke(n);
255
+ const { nodes: a, source: l, positions: p, path: u, originalError: h, extensions: E } = ke(n);
256
256
  super(t), this.name = "GraphQLError", this.path = u ?? void 0, this.originalError = h ?? void 0, this.nodes = J(
257
257
  Array.isArray(a) ? a : a ? [a] : void 0
258
258
  );
259
- const f = J(
260
- (s = this.nodes) === null || s === void 0 ? void 0 : s.map((E) => E.loc).filter((E) => E != null)
259
+ const d = J(
260
+ (s = this.nodes) === null || s === void 0 ? void 0 : s.map((f) => f.loc).filter((f) => f != null)
261
261
  );
262
- this.source = l ?? (f == null || (i = f[0]) === null || i === void 0 ? void 0 : i.source), this.positions = p ?? f?.map((E) => E.start), this.locations = p && l ? p.map((E) => M(l, E)) : f?.map((E) => M(E.source, E.start));
262
+ this.source = l ?? (d == null || (i = d[0]) === null || i === void 0 ? void 0 : i.source), this.positions = p ?? d?.map((f) => f.start), this.locations = p && l ? p.map((f) => M(l, f)) : d?.map((f) => M(f.source, f.start));
263
263
  const x = ve(
264
264
  h?.extensions
265
265
  ) ? h?.extensions : void 0;
266
- this.extensions = (r = d ?? x) !== null && r !== void 0 ? r : /* @__PURE__ */ Object.create(null), Object.defineProperties(this, {
266
+ this.extensions = (r = E ?? x) !== null && r !== void 0 ? r : /* @__PURE__ */ Object.create(null), Object.defineProperties(this, {
267
267
  message: {
268
268
  writable: !0,
269
269
  enumerable: !0
@@ -2170,13 +2170,13 @@ function ze(e, t, n = ee) {
2170
2170
  const s = /* @__PURE__ */ new Map();
2171
2171
  for (const y of Object.values(c))
2172
2172
  s.set(y, He(t, y));
2173
- let i, r = Array.isArray(e), a = [e], l = -1, p = [], u = e, h, d;
2174
- const f = [], x = [];
2173
+ let i, r = Array.isArray(e), a = [e], l = -1, p = [], u = e, h, E;
2174
+ const d = [], x = [];
2175
2175
  do {
2176
2176
  l++;
2177
2177
  const y = l === a.length, C = y && p.length !== 0;
2178
2178
  if (y) {
2179
- if (h = x.length === 0 ? void 0 : f[f.length - 1], u = d, d = x.pop(), C)
2179
+ if (h = x.length === 0 ? void 0 : d[d.length - 1], u = E, E = x.pop(), C)
2180
2180
  if (r) {
2181
2181
  u = u.slice();
2182
2182
  let A = 0;
@@ -2190,33 +2190,33 @@ function ze(e, t, n = ee) {
2190
2190
  u[A] = F;
2191
2191
  }
2192
2192
  l = i.index, a = i.keys, p = i.edits, r = i.inArray, i = i.prev;
2193
- } else if (d) {
2194
- if (h = r ? l : a[l], u = d[h], u == null)
2193
+ } else if (E) {
2194
+ if (h = r ? l : a[l], u = E[h], u == null)
2195
2195
  continue;
2196
- f.push(h);
2196
+ d.push(h);
2197
2197
  }
2198
2198
  let I;
2199
2199
  if (!Array.isArray(u)) {
2200
- var E, N;
2200
+ var f, N;
2201
2201
  Q(u) || b(!1, `Invalid AST Node: ${V(u)}.`);
2202
- const A = y ? (E = s.get(u.kind)) === null || E === void 0 ? void 0 : E.leave : (N = s.get(u.kind)) === null || N === void 0 ? void 0 : N.enter;
2203
- if (I = A?.call(t, u, h, d, f, x), I === qe)
2202
+ const A = y ? (f = s.get(u.kind)) === null || f === void 0 ? void 0 : f.leave : (N = s.get(u.kind)) === null || N === void 0 ? void 0 : N.enter;
2203
+ if (I = A?.call(t, u, h, E, d, x), I === qe)
2204
2204
  break;
2205
2205
  if (I === !1) {
2206
2206
  if (!y) {
2207
- f.pop();
2207
+ d.pop();
2208
2208
  continue;
2209
2209
  }
2210
2210
  } else if (I !== void 0 && (p.push([h, I]), !y))
2211
2211
  if (Q(I))
2212
2212
  u = I;
2213
2213
  else {
2214
- f.pop();
2214
+ d.pop();
2215
2215
  continue;
2216
2216
  }
2217
2217
  }
2218
2218
  if (I === void 0 && C && p.push([h, u]), y)
2219
- f.pop();
2219
+ d.pop();
2220
2220
  else {
2221
2221
  var S;
2222
2222
  i = {
@@ -2225,7 +2225,7 @@ function ze(e, t, n = ee) {
2225
2225
  keys: a,
2226
2226
  edits: p,
2227
2227
  prev: i
2228
- }, r = Array.isArray(u), a = r ? u : (S = n[u.kind]) !== null && S !== void 0 ? S : [], l = -1, p = [], d && x.push(d), d = u;
2228
+ }, r = Array.isArray(u), a = r ? u : (S = n[u.kind]) !== null && S !== void 0 ? S : [], l = -1, p = [], E && x.push(E), E = u;
2229
2229
  }
2230
2230
  } while (i !== void 0);
2231
2231
  return p.length !== 0 ? p[p.length - 1][1] : e;
@@ -2277,17 +2277,17 @@ const We = (e) => e.operation.operation.toLowerCase(), Ze = (e) => e.path.typena
2277
2277
  } = e;
2278
2278
  return async (a, l, p, u, h) => {
2279
2279
  u.ability || (u.ability = await z(u.user, i));
2280
- const d = We(h), f = Ze(h), x = n[d] || d, E = h.parentType.name, N = t[E] || E;
2281
- if (r && console.log(`Checking permission: ${x} on ${N} at ${f}`), s[f] && !s[f].some(
2280
+ const E = We(h), d = Ze(h), x = n[E] || E, f = h.parentType.name, N = t[f] || f;
2281
+ if (r && console.debug(`Checking permission: ${x} on ${N} at ${d}`), s[d] && !s[d].some(
2282
2282
  (I) => (
2283
2283
  // Don't pass resolver args here - only use them if the permission defines conditions
2284
2284
  P(u, I.action, I.subject, I.conditions)
2285
2285
  )
2286
2286
  ))
2287
- throw new $(`Access denied for field ${f}`);
2287
+ throw new $(`Access denied for field ${d}`);
2288
2288
  if (!P(u, x, N))
2289
2289
  throw new $(`Access denied for ${x} on ${N}`);
2290
- if (d === "mutation" && p.input) {
2290
+ if (E === "mutation" && p.input) {
2291
2291
  const y = h.operation.loc?.source.body;
2292
2292
  if (y) {
2293
2293
  const C = Ke(y);
@@ -2341,25 +2341,22 @@ const We = (e) => e.operation.operation.toLowerCase(), Ze = (e) => e.path.typena
2341
2341
  Mutation: {
2342
2342
  plans: {
2343
2343
  async createAbility(i, r) {
2344
- const a = r.getRaw().input, l = a.userId, p = a.roles;
2345
- return s(
2346
- [l, p],
2347
- async ([u, h]) => {
2348
- try {
2349
- return {
2350
- success: !0,
2351
- ability: (await z({ id: u, roles: h })).rules,
2352
- message: "Ability created successfully"
2353
- };
2354
- } catch (d) {
2355
- return {
2356
- success: !1,
2357
- ability: null,
2358
- message: d instanceof Error ? d.message : "Unknown error occurred"
2359
- };
2360
- }
2344
+ const a = r.getRaw().input.userId, l = r.getRaw().input.roles;
2345
+ return s([a, l], async ([p, u]) => {
2346
+ try {
2347
+ return {
2348
+ success: !0,
2349
+ ability: (await z({ id: p, roles: u })).rules,
2350
+ message: "Ability created successfully"
2351
+ };
2352
+ } catch (h) {
2353
+ return {
2354
+ success: !1,
2355
+ ability: null,
2356
+ message: h instanceof Error ? h.message : "Unknown error occurred"
2357
+ };
2361
2358
  }
2362
- );
2359
+ });
2363
2360
  }
2364
2361
  }
2365
2362
  }