@liquisio/wix-access 0.0.1-probe.1 → 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/README.md CHANGED
@@ -10,10 +10,10 @@ into both. `wix-*` and `@wix/*` stay external; `@casl/ability` is inlined.
10
10
  ```
11
11
  npm install
12
12
  npm run verify # build + node --test
13
- npm publish --tag probe
13
+ npm publish
14
14
  ```
15
15
 
16
- On the site: `wix install @liquisio/wix-access@probe` (and `wix install @casl/ability`
16
+ On the site: `wix install @liquisio/wix-access` (and `wix install @casl/ability`
17
17
  for the direct-import comparison), then copy `probes/probes-pkg.web.js` to
18
18
  `src/backend/` and `probes/pkg-probe.js` to `src/public/`, and uncomment the two
19
19
  lines at the top of the widget.
package/backend.js CHANGED
@@ -1 +1 @@
1
- var T=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames;var We=Object.prototype.hasOwnProperty;var Xe=(t,e)=>{for(var r in e)T(t,r,{get:e[r],enumerable:!0})},Ze=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of He(e))!We.call(t,s)&&s!==r&&T(t,s,{get:()=>e[s],enumerable:!(n=Ye(e,s))||n.enumerable});return t};var et=t=>Ze(T({},"__esModule",{value:!0}),t);var Lt={};Xe(Lt,{CASES:()=>we,PACKAGE_VERSION:()=>be,abilityFor:()=>Je,abilityFromRules:()=>ve,backendMemberId:()=>Dt,backendPing:()=>zt,caseTable:()=>Qe,resolvePlaceholders:()=>v,rulesFor:()=>$e});module.exports=et(Lt);var Ge=require("wix-members-backend");var w=class{constructor(e,r){this.operator=e,this.value=r,Object.defineProperty(this,"t",{writable:!0})}get notes(){return this.t}addNote(e){this.t=this.t||[],this.t.push(e)}},y=class extends w{},p=class extends y{constructor(e,r){if(!Array.isArray(r))throw new Error(`"${e}" operator expects to receive an array of conditions`);super(e,r)}},l="__itself__",f=class extends w{constructor(e,r,n){super(e,n),this.field=r}},k=new y("__null__",null),R=Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);function tt(t,e){return e instanceof p&&e.operator===t}function q(t,e){return e.length===1?e[0]:new p(t,(function r(n,s,o){let i=o||[];for(let a=0,c=s.length;a<c;a++){let u=s[a];tt(n,u)?r(n,u.value,i):i.push(u)}return i})(t,e))}var rt=t=>t,xe=()=>Object.create(null),je=Object.defineProperty(xe(),"__@type@__",{value:"ignore value"});function nt(t,e,r=!1){if(!t||t&&t.constructor!==Object)return!1;for(let n in t)if(R(t,n)&&R(e,n)&&(!r||t[n]!==je))return!0;return!1}function st(t){let e=[];for(let r in t)R(t,r)&&t[r]!==je&&e.push(r);return e}function N(t,e){e!==k&&t.push(e)}var z=t=>q("and",t);var x={compound(t,e,r){let n=(Array.isArray(e)?e:[e]).map(s=>r.parse(s));return new p(t.name,n)},field:(t,e,r)=>new f(t.name,r.field,e),document:(t,e)=>new y(t.name,e)},g=class{constructor(e,r=xe()){this.o=void 0,this.s=void 0,this.i=void 0,this.u=void 0,this.h=void 0,this.parse=this.parse.bind(this),this.u={operatorToConditionName:r.operatorToConditionName||rt,defaultOperatorName:r.defaultOperatorName||"eq",mergeFinalConditions:r.mergeFinalConditions||z},this.o=Object.keys(e).reduce((n,s)=>(n[s]=Object.assign({name:this.u.operatorToConditionName(s)},e[s]),n),{}),this.s=Object.assign({},r.fieldContext,{field:"",query:{},parse:this.parse,hasOperators:n=>nt(n,this.o,r.useIgnoreValue)}),this.i=Object.assign({},r.documentContext,{parse:this.parse,query:{}}),this.h=r.useIgnoreValue?st:Object.keys}setParse(e){this.parse=e,this.s.parse=e,this.i.parse=e}parseField(e,r,n,s){let o=this.o[r];if(!o)throw new Error(`Unsupported operator "${r}"`);if(o.type!=="field")throw new Error(`Unexpected ${o.type} operator "${r}" at field level`);return this.s.field=e,this.s.query=s,this.parseInstruction(o,n,this.s)}parseInstruction(e,r,n){return typeof e.validate=="function"&&e.validate(e,r),(e.parse||x[e.type])(e,r,n)}parseFieldOperators(e,r){let n=[],s=this.h(r);for(let o=0,i=s.length;o<i;o++){let a=s[o];if(!this.o[a])throw new Error(`Field query for "${e}" may contain only operators or a plain object as a value`);N(n,this.parseField(e,a,r[a],r))}return n}parse(e){let r=[],n=this.h(e);this.i.query=e;for(let s=0,o=n.length;s<o;s++){let i=n[s],a=e[i],c=this.o[i];if(c){if(c.type!=="document"&&c.type!=="compound")throw new Error(`Cannot use parsing instruction for operator "${i}" in "document" context as it is supposed to be used in "${c.type}" context`);N(r,this.parseInstruction(c,a,this.i))}else this.s.hasOperators(a)?r.push(...this.parseFieldOperators(i,a)):N(r,this.parseField(i,this.u.defaultOperatorName,a,e))}return this.u.mergeFinalConditions(r)}};function S(t,e){let r=t[e];if(typeof r!="function")throw new Error(`Unable to interpret "${e}" condition. Did you forget to register interpreter for it?`);return r}function ot(t){return t.operator}function Oe(t,e){let r=e,n=r&&r.getInterpreterName||ot,s;switch(r?r.numberOfArguments:0){case 1:s=i=>{let a=n(i,r);return S(t,a)(i,o)};break;case 3:s=(i,a,c)=>{let u=n(i,r);return S(t,u)(i,a,c,o)};break;default:s=(i,a)=>{let c=n(i,r);return S(t,c)(i,a,o)}}let o=Object.assign({},r,{interpret:s});return o.interpret}function Ae(t,e){return(r,...n)=>{let s=t(r,...n),o=e.bind(null,s);return o.ast=s,o}}var Vt=g.prototype.parseInstruction;function Ee(t,e){if(!Array.isArray(e))throw new Error(`"${t.name}" expects value to be an array`)}function Fe(t,e){if(Ee(t,e),!e.length)throw new Error(`"${t.name}" expects to have at least one element in array`)}var D=t=>(e,r)=>{if(typeof r!==t)throw new Error(`"${e.name}" expects value to be a "${t}"`)},Ce={type:"compound",validate:Fe,parse(t,e,{parse:r}){let n=e.map(s=>r(s));return q(t.name,n)}},it=Ce,at={type:"compound",validate:Fe},ct={type:"field",validate(t,e){if(!(e&&(e instanceof RegExp||e.constructor===Object)))throw new Error(`"${t.name}" expects to receive either regular expression or object of field operators`)},parse(t,e,r){let n=e instanceof RegExp?new f("regex",r.field,e):r.parse(e,r);return new p(t.name,[n])}},L={type:"field",validate(t,e){if(!e||e.constructor!==Object)throw new Error(`"${t.name}" expects to receive an object with nested query or field level operators`)},parse(t,e,{parse:r,field:n,hasOperators:s}){let o=s(e)?r(e,{field:l}):r(e);return new f(t.name,n,o)}},U={type:"field",validate:D("number")},m={type:"field",validate:Ee},V=m,B=m,ut={type:"field",validate(t,e){if(!Array.isArray(e)||e.length!==2)throw new Error(`"${t.name}" expects an array with 2 numeric elements`)}},J={type:"field",validate:D("boolean")},O={type:"field",validate:function(t,e){if(!(typeof e=="string"||typeof e=="number"||e instanceof Date))throw new Error(`"${t.name}" expects value to be comparable (i.e., string, number or date)`)}},b=O,Q=b,G=b,A={type:"field"},K=A,Y={type:"field",validate(t,e){if(!(e instanceof RegExp)&&typeof e!="string")throw new Error(`"${t.name}" expects value to be a regular expression or a string that represents regular expression`)},parse(t,e,r){let n=typeof e=="string"?new RegExp(e,r.query.$options||""):e;return new f(t.name,r.field,n)}},H={type:"field",parse:()=>k},lt={type:"document",validate:D("function")},pt=Object.freeze({__proto__:null,$and:Ce,$or:it,$nor:at,$not:ct,$elemMatch:L,$size:U,$in:m,$nin:V,$all:B,$mod:ut,$exists:J,$gte:O,$gt:b,$lt:Q,$lte:G,$eq:A,$ne:K,$regex:Y,$options:H,$where:lt}),j=class extends g{constructor(e){super(e,{defaultOperatorName:"$eq",operatorToConditionName:r=>r.slice(1)})}parse(e,r){return r&&r.field?z(this.parseFieldOperators(r.field,e)):super.parse(e)}},E=pt;function W(t,e,r){for(let n=0,s=t.length;n<s;n++)if(r(t[n],e)===0)return!0;return!1}function X(t,e){return Array.isArray(t)&&Number.isNaN(Number(e))}function Me(t,e,r){if(!X(t,e))return r(t,e);let n=[];for(let s=0;s<t.length;s++){let o=r(t[s],e);o!==void 0&&(n=n.concat(o))}return n}function h(t){return(e,r,n)=>{let s=n.get(r,e.field);return Array.isArray(s)?s.some(o=>t(e,o,n)):t(e,s,n)}}var ft=Object.hasOwn||Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty),ht=(t,e)=>t[e];function _e(t,e,r){let n=e.lastIndexOf(".");return n===-1?[t,e]:[r(t,e.slice(0,n)),e.slice(n+1)]}function dt(t,e,r=ht){if(e===l)return t;if(!t)throw new Error(`Unable to get field "${e}" out of ${String(t)}.`);return(function(n,s,o){if(s.indexOf(".")===-1)return Me(n,s,o);let i=s.split("."),a=n;for(let c=0,u=i.length;c<u;c++)if(a=Me(a,i[c],o),!a||typeof a!="object")return c<u-1?void 0:a;return a})(t,e,r)}function Z(t,e){return t===e?0:t>e?1:-1}function ee(t,e={}){return Oe(t,Object.assign({get:dt,compare:Z},e))}var Ie=(t,e,{interpret:r})=>t.value.some(n=>r(n,e)),yt=(t,e,r)=>!Ie(t,e,r),te=(t,e,{interpret:r})=>t.value.every(n=>r(n,e)),gt=(t,e,{interpret:r})=>!r(t.value[0],e),F=(t,e,{compare:r,get:n})=>{let s=n(e,t.field);return Array.isArray(s)&&!Array.isArray(t.value)?W(s,t.value,r):r(s,t.value)===0},re=(t,e,r)=>!F(t,e,r),ne=h((t,e,r)=>{let n=r.compare(e,t.value);return n===0||n===-1}),se=h((t,e,r)=>r.compare(e,t.value)===-1),oe=h((t,e,r)=>r.compare(e,t.value)===1),ie=h((t,e,r)=>{let n=r.compare(e,t.value);return n===0||n===1}),ae=(t,e,{get:r})=>{if(t.field===l)return e!==void 0;let[n,s]=_e(e,t.field,r),o=i=>i==null?!!i===t.value:ft(i,s)===t.value;return X(n,s)?n.some(o):o(n)},mt=h((t,e)=>typeof e=="number"&&e%t.value[0]===t.value[1]),ce=(t,e,{get:r})=>{let[n,s]=_e(e,t.field,r),o=i=>{let a=r(i,s);return Array.isArray(a)&&a.length===t.value};return t.field!==l&&X(n,s)?n.some(o):o(n)},ue=h((t,e)=>typeof e=="string"&&t.value.test(e)),$=h((t,e,{compare:r})=>W(t.value,e,r)),le=(t,e,r)=>!$(t,e,r),pe=(t,e,{compare:r,get:n})=>{let s=n(e,t.field);return Array.isArray(s)&&t.value.every(o=>W(s,o,r))},fe=(t,e,{interpret:r,get:n})=>{let s=n(e,t.field);return Array.isArray(s)&&s.some(o=>r(t.value,o))},bt=(t,e)=>t.value.call(e),$t=Object.freeze({__proto__:null,or:Ie,nor:yt,and:te,not:gt,eq:F,ne:re,lte:ne,lt:se,gt:oe,gte:ie,exists:ae,mod:mt,size:ce,regex:ue,within:$,nin:le,all:pe,elemMatch:fe,where:bt}),C=Object.assign({},$t,{in:$}),Yt=ee(C);function Pe(t){return t===null||typeof t!="object"?t:t instanceof Date?t.getTime():t&&typeof t.toJSON=="function"?t.toJSON():t}var vt=(t,e)=>Z(Pe(t),Pe(e));function M(t,e,r){let n=new j(t),s=ee(e,Object.assign({compare:vt},r));if(r&&r.forPrimitives){let o={field:l},i=n.parse;n.setParse(a=>i(a,o))}return Ae(n.parse,s)}var er=M(E,C),tr=M(["$and","$or"].reduce((t,e)=>(t[e]=Object.assign({},t[e],{type:"field"}),t),Object.assign({},E,{$nor:Object.assign({},E.$nor,{type:"field",parse:x.compound})})),C,{forPrimitives:!0});var qe=Object.hasOwn||((t,e)=>Object.prototype.hasOwnProperty.call(t,e));function he(t){return Array.isArray(t)?t:[t]}var d="__caslSubjectType__";function ze(t,e){if(e){if(!qe(e,d))Object.defineProperty(e,d,{value:t});else if(t!==e[d])throw new Error(`Trying to cast object to subject type ${t} but previously it was casted to ${e[d]}`)}return e}var I=t=>{let e=typeof t;return e==="string"||e==="function"},De=t=>t.modelName||t.name;function wt(t){return typeof t=="string"?t:De(t)}function Le(t){return qe(t,d)?t[d]:De(t.constructor)}var Te={function:t=>t.constructor,string:Le};function Ne(t,e,r){for(let n=r;n<e.length;n++)t.push(e[n])}function Se(t,e){if(!t||!t.length)return e||[];if(!e||!e.length)return t||[];let r=0,n=0,s=[];for(;r<t.length&&n<e.length;)t[r].priority<e[n].priority?(s.push(t[r]),r++):t[r].priority>e[n].priority?(s.push(e[n]),n++):(s.push(t[r]),r++,n++);return Ne(s,t,r),Ne(s,e,n),s}function _(t,e,r){let n=t.get(e);return n||(n=r(),t.set(e,n)),n}var xt=t=>t;function jt(t,e){let r;for(let n=0;n<t.length;n++){let s=e(t[n]);r&&s&&r.push(t[n]),s||(r??=t.slice(0,n))}return r||t}function Ot(t,e){if(Array.isArray(t.fields)&&!t.fields.length)throw new Error("`rawRule.fields` cannot be an empty array. https://bit.ly/390miLa");if(t.fields&&!e.fieldMatcher)throw new Error('You need to pass "fieldMatcher" option in order to restrict access by fields');if(t.conditions&&!e.conditionsMatcher)throw new Error('You need to pass "conditionsMatcher" option in order to restrict access by conditions')}var de=class{constructor(e,r,n=0){Ot(e,r),this.action=r.resolveAction(e.action),this.subject=e.subject,this.inverted=!!e.inverted,this.conditions=e.conditions,this.reason=e.reason,this.origin=e,this.fields=e.fields?he(e.fields):void 0,this.priority=n,this.t=r}i(){return this.conditions&&!this.o&&(this.o=this.t.conditionsMatcher(this.conditions)),this.o}get ast(){let e=this.i();return e?e.ast:void 0}matchesConditions(e){return this.conditions?!e||I(e)?!this.inverted:this.i()(e):!0}matchesField(e){return this.fields?e?(this.u||(this.u=this.t.fieldMatcher(this.fields)),this.u(e)):!this.inverted:!0}};function At(t,e){let r={value:t,prev:e,next:null};return e&&(e.next=r),r}function Et(t){t.next&&(t.next.prev=t.prev),t.prev&&(t.prev.next=t.next),t.next=t.prev=null}var Re=()=>({rules:[],merged:!1}),ke=()=>new Map,ye=class{constructor(e=[],r={}){this.h=!1,this.l=new Map,this.p={conditionsMatcher:r.conditionsMatcher,fieldMatcher:r.fieldMatcher,resolveAction:r.resolveAction||xt},this.$=r.anyAction||"manage",this.A=r.anySubjectType||"all",this.m=e,this.M=!!r.detectSubjectType,this.j=r.detectSubjectType||Le,this.v(e)}get rules(){return this.m}detectSubjectType(e){return I(e)?e:e?this.j(e):this.A}update(e){let r={rules:e,ability:this,target:this};return this._("update",r),this.m=e,this.v(e),this._("updated",r),this}v(e){let r=new Map,n;for(let s=e.length-1;s>=0;s--){let o=e.length-s-1,i=new de(e[s],this.p,o),a=he(i.action),c=he(i.subject||this.A);!this.h&&i.fields&&(this.h=!0);for(let u=0;u<c.length;u++){let Ke=_(r,c[u],ke);n===void 0&&(n=typeof c[u]),typeof c[u]!==n&&n!=="mixed"&&(n="mixed");for(let P=0;P<a.length;P++)_(Ke,a[P],Re).rules.push(i)}}if(this.l=r,n!=="mixed"&&!this.M){let s=Te[n]||Te.string;this.j=s}}possibleRulesFor(e,r=this.A){if(!I(r))throw new Error('"possibleRulesFor" accepts only subject types (i.e., string or class) as the 2nd parameter');let n=_(this.l,r,ke),s=_(n,e,Re);if(s.merged)return s.rules;let o=e!==this.$&&n.has(this.$)?n.get(this.$).rules:void 0,i=Se(s.rules,o);return r!==this.A&&(i=Se(i,this.possibleRulesFor(e,this.A))),s.rules=i,s.merged=!0,i}rulesFor(e,r,n){let s=this.possibleRulesFor(e,r);if(n&&typeof n!="string")throw new Error("The 3rd, `field` parameter is expected to be a string. See https://stalniy.github.io/casl/en/api/casl-ability#can-of-pure-ability for details");return this.h?jt(s,o=>o.matchesField(n)):s}actionsFor(e){if(!I(e))throw new Error('"actionsFor" accepts only subject types (i.e., string or class) as a parameter');let r=new Set,n=this.l.get(e);n&&Array.from(n.keys()).forEach(o=>r.add(o));let s=e!==this.A?this.l.get(this.A):void 0;return s&&Array.from(s.keys()).forEach(o=>r.add(o)),Array.from(r)}on(e,r){this.F=this.F||new Map;let n=this.F,s=n.get(e)||null,o=At(r,s);return n.set(e,o),()=>{let i=n.get(e);!o.next&&!o.prev&&i===o?n.delete(e):o===i&&n.set(e,o.prev),Et(o)}}_(e,r){if(!this.F)return;let n=this.F.get(e)||null,s=[];for(;n!==null;)s.push(n.value),n=n.prev;for(let o=0;o<s.length;o++)s[o](r)}},ge=class extends ye{can(e,r,n){let s=this.relevantRuleFor(e,r,n);return!!s&&!s.inverted}relevantRuleFor(e,r,n){let s=this.detectSubjectType(r),o=this.rulesFor(e,s,n);for(let i=0,a=o.length;i<a;i++)if(o[i].matchesConditions(r))return o[i];return null}cannot(e,r,n){return!this.can(e,r,n)}},Ft={$eq:A,$ne:K,$lt:Q,$lte:G,$gt:b,$gte:O,$in:m,$nin:V,$all:B,$size:U,$regex:Y,$options:H,$elemMatch:L,$exists:J},Ct={eq:F,ne:re,lt:se,lte:ne,gt:oe,gte:ie,in:$,nin:le,all:pe,size:ce,regex:ue,elemMatch:fe,exists:ae,and:te};var Mt=M(Ft,Ct),_t=/[-/\\^$+?.()|[\]{}]/g,It=/\.?\*+\.?/g,Pt=/\*+/,Tt=/\./g;function Nt(t,e,r){let n=r[0]==="*"||t[0]==="."&&t[t.length-1]==="."?"+":"*",s=t.indexOf("**")===-1?"[^.]":".",o=t.replace(Tt,"\\$&").replace(Pt,s+n);return e+t.length===r.length?`(?:${o})?`:o}function St(t,e,r){return t==="."&&(r[e-1]==="*"||r[e+1]==="*")?t:`\\${t}`}function Rt(t){let e=t.map(n=>n.replace(_t,St).replace(It,Nt)),r=e.length>1?`(?:${e.join("|")})`:e[0];return new RegExp(`^${r}$`)}var kt=t=>{let e;return r=>(typeof e>"u"&&(e=t.every(n=>n.indexOf("*")===-1)?null:Rt(t)),e===null?t.indexOf(r)!==-1:e.test(r))};function Ue(t=[],e={}){return new ge(t,Object.assign({conditionsMatcher:Mt,fieldMatcher:kt},e))}var qt=t=>`Cannot execute "${t.action}" on "${t.subjectType}"`,Ve=function(e){this.message=e};Ve.prototype=Object.create(Error.prototype);var me=class extends Ve{static setDefaultMessage(e){this.P=typeof e=="string"?()=>e:e}static from(e){return new this(e)}constructor(e){super(""),this.ability=e,typeof Error.captureStackTrace=="function"&&(this.name="ForbiddenError",Error.captureStackTrace(this,this.constructor))}setMessage(e){return this.message=e,this}throwUnlessCan(e,r,n){let s=this.unlessCan(e,r,n);if(s)throw s}unlessCan(e,r,n){let s=this.ability.relevantRuleFor(e,r,n);if(s&&!s.inverted)return;this.action=e,this.subject=r,this.subjectType=wt(this.ability.detectSubjectType(r)),this.field=n;let o=s?s.reason:"";return this.message=this.message||o||this.constructor.P(this),this}};me.P=qt;var ar=Object.freeze({__proto__:null});var be="0.0.1-probe.1";function Be(t){return{ok:!0,side:t,version:be}}function v(t,e){if(t==null)return t;if(typeof t=="string")return t.indexOf("$principal.")===0?t.slice(11).split(".").reduce((n,s)=>n==null?n:n[s],e):t;if(Array.isArray(t))return t.map(r=>v(r,e));if(typeof t=="object"){let r={};for(let n of Object.keys(t))r[n]=v(t[n],e);return r}return t}function $e(t,e){let r=new Set(t&&t.subjects||[]);return(e.rules||[]).filter(n=>r.has(n.subject)).map(n=>{let s={action:n.actions,subject:n.resource};return n.where&&(s.conditions=v(n.where,t)),s})}function ve(t){return Ue(t)}function Je(t,e){return ve($e(t,e))}var we=[{action:"read",type:"Booking",object:{customerId:"m-1"}},{action:"read",type:"Booking",object:{customerId:"m-2"}},{action:"cancel",type:"Booking",object:{customerId:"m-1"}},{action:"delete",type:"Booking",object:{customerId:"m-1"}},{action:"manage",type:"Vendor",object:{_id:"v-1"}}];function Qe(t){return we.map(e=>({action:e.action,type:e.type,object:e.object,can:t.can(e.action,ze(e.type,Object.assign({},e.object)))}))}function zt(){return Be("backend")}async function Dt(){try{let t=await Ge.currentMember.getMember();return t&&t._id||null}catch{return null}}0&&(module.exports={CASES,PACKAGE_VERSION,abilityFor,abilityFromRules,backendMemberId,backendPing,caseTable,resolvePlaceholders,rulesFor});
1
+ var T=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames;var We=Object.prototype.hasOwnProperty;var Xe=(t,e)=>{for(var r in e)T(t,r,{get:e[r],enumerable:!0})},Ze=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of He(e))!We.call(t,s)&&s!==r&&T(t,s,{get:()=>e[s],enumerable:!(n=Ye(e,s))||n.enumerable});return t};var et=t=>Ze(T({},"__esModule",{value:!0}),t);var Lt={};Xe(Lt,{CASES:()=>we,PACKAGE_VERSION:()=>be,abilityFor:()=>Je,abilityFromRules:()=>ve,backendMemberId:()=>Dt,backendPing:()=>zt,caseTable:()=>Qe,resolvePlaceholders:()=>v,rulesFor:()=>$e});module.exports=et(Lt);var Ge=require("wix-members-backend");var w=class{constructor(e,r){this.operator=e,this.value=r,Object.defineProperty(this,"t",{writable:!0})}get notes(){return this.t}addNote(e){this.t=this.t||[],this.t.push(e)}},y=class extends w{},p=class extends y{constructor(e,r){if(!Array.isArray(r))throw new Error(`"${e}" operator expects to receive an array of conditions`);super(e,r)}},l="__itself__",f=class extends w{constructor(e,r,n){super(e,n),this.field=r}},k=new y("__null__",null),R=Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);function tt(t,e){return e instanceof p&&e.operator===t}function q(t,e){return e.length===1?e[0]:new p(t,(function r(n,s,o){let i=o||[];for(let a=0,c=s.length;a<c;a++){let u=s[a];tt(n,u)?r(n,u.value,i):i.push(u)}return i})(t,e))}var rt=t=>t,xe=()=>Object.create(null),je=Object.defineProperty(xe(),"__@type@__",{value:"ignore value"});function nt(t,e,r=!1){if(!t||t&&t.constructor!==Object)return!1;for(let n in t)if(R(t,n)&&R(e,n)&&(!r||t[n]!==je))return!0;return!1}function st(t){let e=[];for(let r in t)R(t,r)&&t[r]!==je&&e.push(r);return e}function N(t,e){e!==k&&t.push(e)}var z=t=>q("and",t);var x={compound(t,e,r){let n=(Array.isArray(e)?e:[e]).map(s=>r.parse(s));return new p(t.name,n)},field:(t,e,r)=>new f(t.name,r.field,e),document:(t,e)=>new y(t.name,e)},g=class{constructor(e,r=xe()){this.o=void 0,this.s=void 0,this.i=void 0,this.u=void 0,this.h=void 0,this.parse=this.parse.bind(this),this.u={operatorToConditionName:r.operatorToConditionName||rt,defaultOperatorName:r.defaultOperatorName||"eq",mergeFinalConditions:r.mergeFinalConditions||z},this.o=Object.keys(e).reduce((n,s)=>(n[s]=Object.assign({name:this.u.operatorToConditionName(s)},e[s]),n),{}),this.s=Object.assign({},r.fieldContext,{field:"",query:{},parse:this.parse,hasOperators:n=>nt(n,this.o,r.useIgnoreValue)}),this.i=Object.assign({},r.documentContext,{parse:this.parse,query:{}}),this.h=r.useIgnoreValue?st:Object.keys}setParse(e){this.parse=e,this.s.parse=e,this.i.parse=e}parseField(e,r,n,s){let o=this.o[r];if(!o)throw new Error(`Unsupported operator "${r}"`);if(o.type!=="field")throw new Error(`Unexpected ${o.type} operator "${r}" at field level`);return this.s.field=e,this.s.query=s,this.parseInstruction(o,n,this.s)}parseInstruction(e,r,n){return typeof e.validate=="function"&&e.validate(e,r),(e.parse||x[e.type])(e,r,n)}parseFieldOperators(e,r){let n=[],s=this.h(r);for(let o=0,i=s.length;o<i;o++){let a=s[o];if(!this.o[a])throw new Error(`Field query for "${e}" may contain only operators or a plain object as a value`);N(n,this.parseField(e,a,r[a],r))}return n}parse(e){let r=[],n=this.h(e);this.i.query=e;for(let s=0,o=n.length;s<o;s++){let i=n[s],a=e[i],c=this.o[i];if(c){if(c.type!=="document"&&c.type!=="compound")throw new Error(`Cannot use parsing instruction for operator "${i}" in "document" context as it is supposed to be used in "${c.type}" context`);N(r,this.parseInstruction(c,a,this.i))}else this.s.hasOperators(a)?r.push(...this.parseFieldOperators(i,a)):N(r,this.parseField(i,this.u.defaultOperatorName,a,e))}return this.u.mergeFinalConditions(r)}};function S(t,e){let r=t[e];if(typeof r!="function")throw new Error(`Unable to interpret "${e}" condition. Did you forget to register interpreter for it?`);return r}function ot(t){return t.operator}function Oe(t,e){let r=e,n=r&&r.getInterpreterName||ot,s;switch(r?r.numberOfArguments:0){case 1:s=i=>{let a=n(i,r);return S(t,a)(i,o)};break;case 3:s=(i,a,c)=>{let u=n(i,r);return S(t,u)(i,a,c,o)};break;default:s=(i,a)=>{let c=n(i,r);return S(t,c)(i,a,o)}}let o=Object.assign({},r,{interpret:s});return o.interpret}function Ae(t,e){return(r,...n)=>{let s=t(r,...n),o=e.bind(null,s);return o.ast=s,o}}var Vt=g.prototype.parseInstruction;function Ee(t,e){if(!Array.isArray(e))throw new Error(`"${t.name}" expects value to be an array`)}function Fe(t,e){if(Ee(t,e),!e.length)throw new Error(`"${t.name}" expects to have at least one element in array`)}var D=t=>(e,r)=>{if(typeof r!==t)throw new Error(`"${e.name}" expects value to be a "${t}"`)},Ce={type:"compound",validate:Fe,parse(t,e,{parse:r}){let n=e.map(s=>r(s));return q(t.name,n)}},it=Ce,at={type:"compound",validate:Fe},ct={type:"field",validate(t,e){if(!(e&&(e instanceof RegExp||e.constructor===Object)))throw new Error(`"${t.name}" expects to receive either regular expression or object of field operators`)},parse(t,e,r){let n=e instanceof RegExp?new f("regex",r.field,e):r.parse(e,r);return new p(t.name,[n])}},L={type:"field",validate(t,e){if(!e||e.constructor!==Object)throw new Error(`"${t.name}" expects to receive an object with nested query or field level operators`)},parse(t,e,{parse:r,field:n,hasOperators:s}){let o=s(e)?r(e,{field:l}):r(e);return new f(t.name,n,o)}},U={type:"field",validate:D("number")},m={type:"field",validate:Ee},V=m,B=m,ut={type:"field",validate(t,e){if(!Array.isArray(e)||e.length!==2)throw new Error(`"${t.name}" expects an array with 2 numeric elements`)}},J={type:"field",validate:D("boolean")},O={type:"field",validate:function(t,e){if(!(typeof e=="string"||typeof e=="number"||e instanceof Date))throw new Error(`"${t.name}" expects value to be comparable (i.e., string, number or date)`)}},b=O,Q=b,G=b,A={type:"field"},K=A,Y={type:"field",validate(t,e){if(!(e instanceof RegExp)&&typeof e!="string")throw new Error(`"${t.name}" expects value to be a regular expression or a string that represents regular expression`)},parse(t,e,r){let n=typeof e=="string"?new RegExp(e,r.query.$options||""):e;return new f(t.name,r.field,n)}},H={type:"field",parse:()=>k},lt={type:"document",validate:D("function")},pt=Object.freeze({__proto__:null,$and:Ce,$or:it,$nor:at,$not:ct,$elemMatch:L,$size:U,$in:m,$nin:V,$all:B,$mod:ut,$exists:J,$gte:O,$gt:b,$lt:Q,$lte:G,$eq:A,$ne:K,$regex:Y,$options:H,$where:lt}),j=class extends g{constructor(e){super(e,{defaultOperatorName:"$eq",operatorToConditionName:r=>r.slice(1)})}parse(e,r){return r&&r.field?z(this.parseFieldOperators(r.field,e)):super.parse(e)}},E=pt;function W(t,e,r){for(let n=0,s=t.length;n<s;n++)if(r(t[n],e)===0)return!0;return!1}function X(t,e){return Array.isArray(t)&&Number.isNaN(Number(e))}function Me(t,e,r){if(!X(t,e))return r(t,e);let n=[];for(let s=0;s<t.length;s++){let o=r(t[s],e);o!==void 0&&(n=n.concat(o))}return n}function h(t){return(e,r,n)=>{let s=n.get(r,e.field);return Array.isArray(s)?s.some(o=>t(e,o,n)):t(e,s,n)}}var ft=Object.hasOwn||Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty),ht=(t,e)=>t[e];function _e(t,e,r){let n=e.lastIndexOf(".");return n===-1?[t,e]:[r(t,e.slice(0,n)),e.slice(n+1)]}function dt(t,e,r=ht){if(e===l)return t;if(!t)throw new Error(`Unable to get field "${e}" out of ${String(t)}.`);return(function(n,s,o){if(s.indexOf(".")===-1)return Me(n,s,o);let i=s.split("."),a=n;for(let c=0,u=i.length;c<u;c++)if(a=Me(a,i[c],o),!a||typeof a!="object")return c<u-1?void 0:a;return a})(t,e,r)}function Z(t,e){return t===e?0:t>e?1:-1}function ee(t,e={}){return Oe(t,Object.assign({get:dt,compare:Z},e))}var Ie=(t,e,{interpret:r})=>t.value.some(n=>r(n,e)),yt=(t,e,r)=>!Ie(t,e,r),te=(t,e,{interpret:r})=>t.value.every(n=>r(n,e)),gt=(t,e,{interpret:r})=>!r(t.value[0],e),F=(t,e,{compare:r,get:n})=>{let s=n(e,t.field);return Array.isArray(s)&&!Array.isArray(t.value)?W(s,t.value,r):r(s,t.value)===0},re=(t,e,r)=>!F(t,e,r),ne=h((t,e,r)=>{let n=r.compare(e,t.value);return n===0||n===-1}),se=h((t,e,r)=>r.compare(e,t.value)===-1),oe=h((t,e,r)=>r.compare(e,t.value)===1),ie=h((t,e,r)=>{let n=r.compare(e,t.value);return n===0||n===1}),ae=(t,e,{get:r})=>{if(t.field===l)return e!==void 0;let[n,s]=_e(e,t.field,r),o=i=>i==null?!!i===t.value:ft(i,s)===t.value;return X(n,s)?n.some(o):o(n)},mt=h((t,e)=>typeof e=="number"&&e%t.value[0]===t.value[1]),ce=(t,e,{get:r})=>{let[n,s]=_e(e,t.field,r),o=i=>{let a=r(i,s);return Array.isArray(a)&&a.length===t.value};return t.field!==l&&X(n,s)?n.some(o):o(n)},ue=h((t,e)=>typeof e=="string"&&t.value.test(e)),$=h((t,e,{compare:r})=>W(t.value,e,r)),le=(t,e,r)=>!$(t,e,r),pe=(t,e,{compare:r,get:n})=>{let s=n(e,t.field);return Array.isArray(s)&&t.value.every(o=>W(s,o,r))},fe=(t,e,{interpret:r,get:n})=>{let s=n(e,t.field);return Array.isArray(s)&&s.some(o=>r(t.value,o))},bt=(t,e)=>t.value.call(e),$t=Object.freeze({__proto__:null,or:Ie,nor:yt,and:te,not:gt,eq:F,ne:re,lte:ne,lt:se,gt:oe,gte:ie,exists:ae,mod:mt,size:ce,regex:ue,within:$,nin:le,all:pe,elemMatch:fe,where:bt}),C=Object.assign({},$t,{in:$}),Yt=ee(C);function Pe(t){return t===null||typeof t!="object"?t:t instanceof Date?t.getTime():t&&typeof t.toJSON=="function"?t.toJSON():t}var vt=(t,e)=>Z(Pe(t),Pe(e));function M(t,e,r){let n=new j(t),s=ee(e,Object.assign({compare:vt},r));if(r&&r.forPrimitives){let o={field:l},i=n.parse;n.setParse(a=>i(a,o))}return Ae(n.parse,s)}var er=M(E,C),tr=M(["$and","$or"].reduce((t,e)=>(t[e]=Object.assign({},t[e],{type:"field"}),t),Object.assign({},E,{$nor:Object.assign({},E.$nor,{type:"field",parse:x.compound})})),C,{forPrimitives:!0});var qe=Object.hasOwn||((t,e)=>Object.prototype.hasOwnProperty.call(t,e));function he(t){return Array.isArray(t)?t:[t]}var d="__caslSubjectType__";function ze(t,e){if(e){if(!qe(e,d))Object.defineProperty(e,d,{value:t});else if(t!==e[d])throw new Error(`Trying to cast object to subject type ${t} but previously it was casted to ${e[d]}`)}return e}var I=t=>{let e=typeof t;return e==="string"||e==="function"},De=t=>t.modelName||t.name;function wt(t){return typeof t=="string"?t:De(t)}function Le(t){return qe(t,d)?t[d]:De(t.constructor)}var Te={function:t=>t.constructor,string:Le};function Ne(t,e,r){for(let n=r;n<e.length;n++)t.push(e[n])}function Se(t,e){if(!t||!t.length)return e||[];if(!e||!e.length)return t||[];let r=0,n=0,s=[];for(;r<t.length&&n<e.length;)t[r].priority<e[n].priority?(s.push(t[r]),r++):t[r].priority>e[n].priority?(s.push(e[n]),n++):(s.push(t[r]),r++,n++);return Ne(s,t,r),Ne(s,e,n),s}function _(t,e,r){let n=t.get(e);return n||(n=r(),t.set(e,n)),n}var xt=t=>t;function jt(t,e){let r;for(let n=0;n<t.length;n++){let s=e(t[n]);r&&s&&r.push(t[n]),s||(r??=t.slice(0,n))}return r||t}function Ot(t,e){if(Array.isArray(t.fields)&&!t.fields.length)throw new Error("`rawRule.fields` cannot be an empty array. https://bit.ly/390miLa");if(t.fields&&!e.fieldMatcher)throw new Error('You need to pass "fieldMatcher" option in order to restrict access by fields');if(t.conditions&&!e.conditionsMatcher)throw new Error('You need to pass "conditionsMatcher" option in order to restrict access by conditions')}var de=class{constructor(e,r,n=0){Ot(e,r),this.action=r.resolveAction(e.action),this.subject=e.subject,this.inverted=!!e.inverted,this.conditions=e.conditions,this.reason=e.reason,this.origin=e,this.fields=e.fields?he(e.fields):void 0,this.priority=n,this.t=r}i(){return this.conditions&&!this.o&&(this.o=this.t.conditionsMatcher(this.conditions)),this.o}get ast(){let e=this.i();return e?e.ast:void 0}matchesConditions(e){return this.conditions?!e||I(e)?!this.inverted:this.i()(e):!0}matchesField(e){return this.fields?e?(this.u||(this.u=this.t.fieldMatcher(this.fields)),this.u(e)):!this.inverted:!0}};function At(t,e){let r={value:t,prev:e,next:null};return e&&(e.next=r),r}function Et(t){t.next&&(t.next.prev=t.prev),t.prev&&(t.prev.next=t.next),t.next=t.prev=null}var Re=()=>({rules:[],merged:!1}),ke=()=>new Map,ye=class{constructor(e=[],r={}){this.h=!1,this.l=new Map,this.p={conditionsMatcher:r.conditionsMatcher,fieldMatcher:r.fieldMatcher,resolveAction:r.resolveAction||xt},this.$=r.anyAction||"manage",this.A=r.anySubjectType||"all",this.m=e,this.M=!!r.detectSubjectType,this.j=r.detectSubjectType||Le,this.v(e)}get rules(){return this.m}detectSubjectType(e){return I(e)?e:e?this.j(e):this.A}update(e){let r={rules:e,ability:this,target:this};return this._("update",r),this.m=e,this.v(e),this._("updated",r),this}v(e){let r=new Map,n;for(let s=e.length-1;s>=0;s--){let o=e.length-s-1,i=new de(e[s],this.p,o),a=he(i.action),c=he(i.subject||this.A);!this.h&&i.fields&&(this.h=!0);for(let u=0;u<c.length;u++){let Ke=_(r,c[u],ke);n===void 0&&(n=typeof c[u]),typeof c[u]!==n&&n!=="mixed"&&(n="mixed");for(let P=0;P<a.length;P++)_(Ke,a[P],Re).rules.push(i)}}if(this.l=r,n!=="mixed"&&!this.M){let s=Te[n]||Te.string;this.j=s}}possibleRulesFor(e,r=this.A){if(!I(r))throw new Error('"possibleRulesFor" accepts only subject types (i.e., string or class) as the 2nd parameter');let n=_(this.l,r,ke),s=_(n,e,Re);if(s.merged)return s.rules;let o=e!==this.$&&n.has(this.$)?n.get(this.$).rules:void 0,i=Se(s.rules,o);return r!==this.A&&(i=Se(i,this.possibleRulesFor(e,this.A))),s.rules=i,s.merged=!0,i}rulesFor(e,r,n){let s=this.possibleRulesFor(e,r);if(n&&typeof n!="string")throw new Error("The 3rd, `field` parameter is expected to be a string. See https://stalniy.github.io/casl/en/api/casl-ability#can-of-pure-ability for details");return this.h?jt(s,o=>o.matchesField(n)):s}actionsFor(e){if(!I(e))throw new Error('"actionsFor" accepts only subject types (i.e., string or class) as a parameter');let r=new Set,n=this.l.get(e);n&&Array.from(n.keys()).forEach(o=>r.add(o));let s=e!==this.A?this.l.get(this.A):void 0;return s&&Array.from(s.keys()).forEach(o=>r.add(o)),Array.from(r)}on(e,r){this.F=this.F||new Map;let n=this.F,s=n.get(e)||null,o=At(r,s);return n.set(e,o),()=>{let i=n.get(e);!o.next&&!o.prev&&i===o?n.delete(e):o===i&&n.set(e,o.prev),Et(o)}}_(e,r){if(!this.F)return;let n=this.F.get(e)||null,s=[];for(;n!==null;)s.push(n.value),n=n.prev;for(let o=0;o<s.length;o++)s[o](r)}},ge=class extends ye{can(e,r,n){let s=this.relevantRuleFor(e,r,n);return!!s&&!s.inverted}relevantRuleFor(e,r,n){let s=this.detectSubjectType(r),o=this.rulesFor(e,s,n);for(let i=0,a=o.length;i<a;i++)if(o[i].matchesConditions(r))return o[i];return null}cannot(e,r,n){return!this.can(e,r,n)}},Ft={$eq:A,$ne:K,$lt:Q,$lte:G,$gt:b,$gte:O,$in:m,$nin:V,$all:B,$size:U,$regex:Y,$options:H,$elemMatch:L,$exists:J},Ct={eq:F,ne:re,lt:se,lte:ne,gt:oe,gte:ie,in:$,nin:le,all:pe,size:ce,regex:ue,elemMatch:fe,exists:ae,and:te};var Mt=M(Ft,Ct),_t=/[-/\\^$+?.()|[\]{}]/g,It=/\.?\*+\.?/g,Pt=/\*+/,Tt=/\./g;function Nt(t,e,r){let n=r[0]==="*"||t[0]==="."&&t[t.length-1]==="."?"+":"*",s=t.indexOf("**")===-1?"[^.]":".",o=t.replace(Tt,"\\$&").replace(Pt,s+n);return e+t.length===r.length?`(?:${o})?`:o}function St(t,e,r){return t==="."&&(r[e-1]==="*"||r[e+1]==="*")?t:`\\${t}`}function Rt(t){let e=t.map(n=>n.replace(_t,St).replace(It,Nt)),r=e.length>1?`(?:${e.join("|")})`:e[0];return new RegExp(`^${r}$`)}var kt=t=>{let e;return r=>(typeof e>"u"&&(e=t.every(n=>n.indexOf("*")===-1)?null:Rt(t)),e===null?t.indexOf(r)!==-1:e.test(r))};function Ue(t=[],e={}){return new ge(t,Object.assign({conditionsMatcher:Mt,fieldMatcher:kt},e))}var qt=t=>`Cannot execute "${t.action}" on "${t.subjectType}"`,Ve=function(e){this.message=e};Ve.prototype=Object.create(Error.prototype);var me=class extends Ve{static setDefaultMessage(e){this.P=typeof e=="string"?()=>e:e}static from(e){return new this(e)}constructor(e){super(""),this.ability=e,typeof Error.captureStackTrace=="function"&&(this.name="ForbiddenError",Error.captureStackTrace(this,this.constructor))}setMessage(e){return this.message=e,this}throwUnlessCan(e,r,n){let s=this.unlessCan(e,r,n);if(s)throw s}unlessCan(e,r,n){let s=this.ability.relevantRuleFor(e,r,n);if(s&&!s.inverted)return;this.action=e,this.subject=r,this.subjectType=wt(this.ability.detectSubjectType(r)),this.field=n;let o=s?s.reason:"";return this.message=this.message||o||this.constructor.P(this),this}};me.P=qt;var ar=Object.freeze({__proto__:null});var be="0.2.0";function Be(t){return{ok:!0,side:t,version:be}}function v(t,e){if(t==null)return t;if(typeof t=="string")return t.indexOf("$principal.")===0?t.slice(11).split(".").reduce((n,s)=>n==null?n:n[s],e):t;if(Array.isArray(t))return t.map(r=>v(r,e));if(typeof t=="object"){let r={};for(let n of Object.keys(t))r[n]=v(t[n],e);return r}return t}function $e(t,e){let r=new Set(t&&t.subjects||[]);return(e.rules||[]).filter(n=>r.has(n.subject)).map(n=>{let s={action:n.actions,subject:n.resource};return n.where&&(s.conditions=v(n.where,t)),s})}function ve(t){return Ue(t)}function Je(t,e){return ve($e(t,e))}var we=[{action:"read",type:"Booking",object:{customerId:"m-1"}},{action:"read",type:"Booking",object:{customerId:"m-2"}},{action:"cancel",type:"Booking",object:{customerId:"m-1"}},{action:"delete",type:"Booking",object:{customerId:"m-1"}},{action:"manage",type:"Vendor",object:{_id:"v-1"}}];function Qe(t){return we.map(e=>({action:e.action,type:e.type,object:e.object,can:t.can(e.action,ze(e.type,Object.assign({},e.object)))}))}function zt(){return Be("backend")}async function Dt(){try{let t=await Ge.currentMember.getMember();return t&&t._id||null}catch{return null}}0&&(module.exports={CASES,PACKAGE_VERSION,abilityFor,abilityFromRules,backendMemberId,backendPing,caseTable,resolvePlaceholders,rulesFor});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liquisio/wix-access",
3
- "version": "0.0.1-probe.1",
3
+ "version": "0.2.0",
4
4
  "description": "Probe stub for @liquisio/wix-access: proves the two-bundle layout (backend.js + public.js, shared pure core, CASL inlined) on a real Wix site before the real package is built.",
5
5
  "main": "./index.js",
6
6
  "types": "./types.d.ts",
package/public.js CHANGED
@@ -1 +1 @@
1
- var P=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames;var We=Object.prototype.hasOwnProperty;var Xe=(t,e)=>{for(var r in e)P(t,r,{get:e[r],enumerable:!0})},Ze=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of He(e))!We.call(t,n)&&n!==r&&P(t,n,{get:()=>e[n],enumerable:!(s=Ye(e,n))||s.enumerable});return t};var et=t=>Ze(P({},"__esModule",{value:!0}),t);var Lt={};Xe(Lt,{CASES:()=>we,PACKAGE_VERSION:()=>be,abilityFor:()=>Je,abilityFromRules:()=>ve,caseTable:()=>Qe,frontendRoleTitles:()=>Dt,publicPing:()=>zt,resolvePlaceholders:()=>v,rulesFor:()=>$e});module.exports=et(Lt);var Ge=require("wix-members-frontend");var w=class{constructor(e,r){this.operator=e,this.value=r,Object.defineProperty(this,"t",{writable:!0})}get notes(){return this.t}addNote(e){this.t=this.t||[],this.t.push(e)}},y=class extends w{},p=class extends y{constructor(e,r){if(!Array.isArray(r))throw new Error(`"${e}" operator expects to receive an array of conditions`);super(e,r)}},l="__itself__",f=class extends w{constructor(e,r,s){super(e,s),this.field=r}},q=new y("__null__",null),R=Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);function tt(t,e){return e instanceof p&&e.operator===t}function k(t,e){return e.length===1?e[0]:new p(t,(function r(s,n,o){let i=o||[];for(let a=0,c=n.length;a<c;a++){let u=n[a];tt(s,u)?r(s,u.value,i):i.push(u)}return i})(t,e))}var rt=t=>t,xe=()=>Object.create(null),je=Object.defineProperty(xe(),"__@type@__",{value:"ignore value"});function st(t,e,r=!1){if(!t||t&&t.constructor!==Object)return!1;for(let s in t)if(R(t,s)&&R(e,s)&&(!r||t[s]!==je))return!0;return!1}function nt(t){let e=[];for(let r in t)R(t,r)&&t[r]!==je&&e.push(r);return e}function N(t,e){e!==q&&t.push(e)}var z=t=>k("and",t);var x={compound(t,e,r){let s=(Array.isArray(e)?e:[e]).map(n=>r.parse(n));return new p(t.name,s)},field:(t,e,r)=>new f(t.name,r.field,e),document:(t,e)=>new y(t.name,e)},g=class{constructor(e,r=xe()){this.o=void 0,this.s=void 0,this.i=void 0,this.u=void 0,this.h=void 0,this.parse=this.parse.bind(this),this.u={operatorToConditionName:r.operatorToConditionName||rt,defaultOperatorName:r.defaultOperatorName||"eq",mergeFinalConditions:r.mergeFinalConditions||z},this.o=Object.keys(e).reduce((s,n)=>(s[n]=Object.assign({name:this.u.operatorToConditionName(n)},e[n]),s),{}),this.s=Object.assign({},r.fieldContext,{field:"",query:{},parse:this.parse,hasOperators:s=>st(s,this.o,r.useIgnoreValue)}),this.i=Object.assign({},r.documentContext,{parse:this.parse,query:{}}),this.h=r.useIgnoreValue?nt:Object.keys}setParse(e){this.parse=e,this.s.parse=e,this.i.parse=e}parseField(e,r,s,n){let o=this.o[r];if(!o)throw new Error(`Unsupported operator "${r}"`);if(o.type!=="field")throw new Error(`Unexpected ${o.type} operator "${r}" at field level`);return this.s.field=e,this.s.query=n,this.parseInstruction(o,s,this.s)}parseInstruction(e,r,s){return typeof e.validate=="function"&&e.validate(e,r),(e.parse||x[e.type])(e,r,s)}parseFieldOperators(e,r){let s=[],n=this.h(r);for(let o=0,i=n.length;o<i;o++){let a=n[o];if(!this.o[a])throw new Error(`Field query for "${e}" may contain only operators or a plain object as a value`);N(s,this.parseField(e,a,r[a],r))}return s}parse(e){let r=[],s=this.h(e);this.i.query=e;for(let n=0,o=s.length;n<o;n++){let i=s[n],a=e[i],c=this.o[i];if(c){if(c.type!=="document"&&c.type!=="compound")throw new Error(`Cannot use parsing instruction for operator "${i}" in "document" context as it is supposed to be used in "${c.type}" context`);N(r,this.parseInstruction(c,a,this.i))}else this.s.hasOperators(a)?r.push(...this.parseFieldOperators(i,a)):N(r,this.parseField(i,this.u.defaultOperatorName,a,e))}return this.u.mergeFinalConditions(r)}};function S(t,e){let r=t[e];if(typeof r!="function")throw new Error(`Unable to interpret "${e}" condition. Did you forget to register interpreter for it?`);return r}function ot(t){return t.operator}function Oe(t,e){let r=e,s=r&&r.getInterpreterName||ot,n;switch(r?r.numberOfArguments:0){case 1:n=i=>{let a=s(i,r);return S(t,a)(i,o)};break;case 3:n=(i,a,c)=>{let u=s(i,r);return S(t,u)(i,a,c,o)};break;default:n=(i,a)=>{let c=s(i,r);return S(t,c)(i,a,o)}}let o=Object.assign({},r,{interpret:n});return o.interpret}function Ae(t,e){return(r,...s)=>{let n=t(r,...s),o=e.bind(null,n);return o.ast=n,o}}var Vt=g.prototype.parseInstruction;function Ee(t,e){if(!Array.isArray(e))throw new Error(`"${t.name}" expects value to be an array`)}function Fe(t,e){if(Ee(t,e),!e.length)throw new Error(`"${t.name}" expects to have at least one element in array`)}var D=t=>(e,r)=>{if(typeof r!==t)throw new Error(`"${e.name}" expects value to be a "${t}"`)},Ce={type:"compound",validate:Fe,parse(t,e,{parse:r}){let s=e.map(n=>r(n));return k(t.name,s)}},it=Ce,at={type:"compound",validate:Fe},ct={type:"field",validate(t,e){if(!(e&&(e instanceof RegExp||e.constructor===Object)))throw new Error(`"${t.name}" expects to receive either regular expression or object of field operators`)},parse(t,e,r){let s=e instanceof RegExp?new f("regex",r.field,e):r.parse(e,r);return new p(t.name,[s])}},L={type:"field",validate(t,e){if(!e||e.constructor!==Object)throw new Error(`"${t.name}" expects to receive an object with nested query or field level operators`)},parse(t,e,{parse:r,field:s,hasOperators:n}){let o=n(e)?r(e,{field:l}):r(e);return new f(t.name,s,o)}},U={type:"field",validate:D("number")},m={type:"field",validate:Ee},V=m,B=m,ut={type:"field",validate(t,e){if(!Array.isArray(e)||e.length!==2)throw new Error(`"${t.name}" expects an array with 2 numeric elements`)}},J={type:"field",validate:D("boolean")},O={type:"field",validate:function(t,e){if(!(typeof e=="string"||typeof e=="number"||e instanceof Date))throw new Error(`"${t.name}" expects value to be comparable (i.e., string, number or date)`)}},b=O,Q=b,G=b,A={type:"field"},K=A,Y={type:"field",validate(t,e){if(!(e instanceof RegExp)&&typeof e!="string")throw new Error(`"${t.name}" expects value to be a regular expression or a string that represents regular expression`)},parse(t,e,r){let s=typeof e=="string"?new RegExp(e,r.query.$options||""):e;return new f(t.name,r.field,s)}},H={type:"field",parse:()=>q},lt={type:"document",validate:D("function")},pt=Object.freeze({__proto__:null,$and:Ce,$or:it,$nor:at,$not:ct,$elemMatch:L,$size:U,$in:m,$nin:V,$all:B,$mod:ut,$exists:J,$gte:O,$gt:b,$lt:Q,$lte:G,$eq:A,$ne:K,$regex:Y,$options:H,$where:lt}),j=class extends g{constructor(e){super(e,{defaultOperatorName:"$eq",operatorToConditionName:r=>r.slice(1)})}parse(e,r){return r&&r.field?z(this.parseFieldOperators(r.field,e)):super.parse(e)}},E=pt;function W(t,e,r){for(let s=0,n=t.length;s<n;s++)if(r(t[s],e)===0)return!0;return!1}function X(t,e){return Array.isArray(t)&&Number.isNaN(Number(e))}function Me(t,e,r){if(!X(t,e))return r(t,e);let s=[];for(let n=0;n<t.length;n++){let o=r(t[n],e);o!==void 0&&(s=s.concat(o))}return s}function h(t){return(e,r,s)=>{let n=s.get(r,e.field);return Array.isArray(n)?n.some(o=>t(e,o,s)):t(e,n,s)}}var ft=Object.hasOwn||Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty),ht=(t,e)=>t[e];function _e(t,e,r){let s=e.lastIndexOf(".");return s===-1?[t,e]:[r(t,e.slice(0,s)),e.slice(s+1)]}function dt(t,e,r=ht){if(e===l)return t;if(!t)throw new Error(`Unable to get field "${e}" out of ${String(t)}.`);return(function(s,n,o){if(n.indexOf(".")===-1)return Me(s,n,o);let i=n.split("."),a=s;for(let c=0,u=i.length;c<u;c++)if(a=Me(a,i[c],o),!a||typeof a!="object")return c<u-1?void 0:a;return a})(t,e,r)}function Z(t,e){return t===e?0:t>e?1:-1}function ee(t,e={}){return Oe(t,Object.assign({get:dt,compare:Z},e))}var Ie=(t,e,{interpret:r})=>t.value.some(s=>r(s,e)),yt=(t,e,r)=>!Ie(t,e,r),te=(t,e,{interpret:r})=>t.value.every(s=>r(s,e)),gt=(t,e,{interpret:r})=>!r(t.value[0],e),F=(t,e,{compare:r,get:s})=>{let n=s(e,t.field);return Array.isArray(n)&&!Array.isArray(t.value)?W(n,t.value,r):r(n,t.value)===0},re=(t,e,r)=>!F(t,e,r),se=h((t,e,r)=>{let s=r.compare(e,t.value);return s===0||s===-1}),ne=h((t,e,r)=>r.compare(e,t.value)===-1),oe=h((t,e,r)=>r.compare(e,t.value)===1),ie=h((t,e,r)=>{let s=r.compare(e,t.value);return s===0||s===1}),ae=(t,e,{get:r})=>{if(t.field===l)return e!==void 0;let[s,n]=_e(e,t.field,r),o=i=>i==null?!!i===t.value:ft(i,n)===t.value;return X(s,n)?s.some(o):o(s)},mt=h((t,e)=>typeof e=="number"&&e%t.value[0]===t.value[1]),ce=(t,e,{get:r})=>{let[s,n]=_e(e,t.field,r),o=i=>{let a=r(i,n);return Array.isArray(a)&&a.length===t.value};return t.field!==l&&X(s,n)?s.some(o):o(s)},ue=h((t,e)=>typeof e=="string"&&t.value.test(e)),$=h((t,e,{compare:r})=>W(t.value,e,r)),le=(t,e,r)=>!$(t,e,r),pe=(t,e,{compare:r,get:s})=>{let n=s(e,t.field);return Array.isArray(n)&&t.value.every(o=>W(n,o,r))},fe=(t,e,{interpret:r,get:s})=>{let n=s(e,t.field);return Array.isArray(n)&&n.some(o=>r(t.value,o))},bt=(t,e)=>t.value.call(e),$t=Object.freeze({__proto__:null,or:Ie,nor:yt,and:te,not:gt,eq:F,ne:re,lte:se,lt:ne,gt:oe,gte:ie,exists:ae,mod:mt,size:ce,regex:ue,within:$,nin:le,all:pe,elemMatch:fe,where:bt}),C=Object.assign({},$t,{in:$}),Yt=ee(C);function Te(t){return t===null||typeof t!="object"?t:t instanceof Date?t.getTime():t&&typeof t.toJSON=="function"?t.toJSON():t}var vt=(t,e)=>Z(Te(t),Te(e));function M(t,e,r){let s=new j(t),n=ee(e,Object.assign({compare:vt},r));if(r&&r.forPrimitives){let o={field:l},i=s.parse;s.setParse(a=>i(a,o))}return Ae(s.parse,n)}var er=M(E,C),tr=M(["$and","$or"].reduce((t,e)=>(t[e]=Object.assign({},t[e],{type:"field"}),t),Object.assign({},E,{$nor:Object.assign({},E.$nor,{type:"field",parse:x.compound})})),C,{forPrimitives:!0});var ke=Object.hasOwn||((t,e)=>Object.prototype.hasOwnProperty.call(t,e));function he(t){return Array.isArray(t)?t:[t]}var d="__caslSubjectType__";function ze(t,e){if(e){if(!ke(e,d))Object.defineProperty(e,d,{value:t});else if(t!==e[d])throw new Error(`Trying to cast object to subject type ${t} but previously it was casted to ${e[d]}`)}return e}var I=t=>{let e=typeof t;return e==="string"||e==="function"},De=t=>t.modelName||t.name;function wt(t){return typeof t=="string"?t:De(t)}function Le(t){return ke(t,d)?t[d]:De(t.constructor)}var Pe={function:t=>t.constructor,string:Le};function Ne(t,e,r){for(let s=r;s<e.length;s++)t.push(e[s])}function Se(t,e){if(!t||!t.length)return e||[];if(!e||!e.length)return t||[];let r=0,s=0,n=[];for(;r<t.length&&s<e.length;)t[r].priority<e[s].priority?(n.push(t[r]),r++):t[r].priority>e[s].priority?(n.push(e[s]),s++):(n.push(t[r]),r++,s++);return Ne(n,t,r),Ne(n,e,s),n}function _(t,e,r){let s=t.get(e);return s||(s=r(),t.set(e,s)),s}var xt=t=>t;function jt(t,e){let r;for(let s=0;s<t.length;s++){let n=e(t[s]);r&&n&&r.push(t[s]),n||(r??(r=t.slice(0,s)))}return r||t}function Ot(t,e){if(Array.isArray(t.fields)&&!t.fields.length)throw new Error("`rawRule.fields` cannot be an empty array. https://bit.ly/390miLa");if(t.fields&&!e.fieldMatcher)throw new Error('You need to pass "fieldMatcher" option in order to restrict access by fields');if(t.conditions&&!e.conditionsMatcher)throw new Error('You need to pass "conditionsMatcher" option in order to restrict access by conditions')}var de=class{constructor(e,r,s=0){Ot(e,r),this.action=r.resolveAction(e.action),this.subject=e.subject,this.inverted=!!e.inverted,this.conditions=e.conditions,this.reason=e.reason,this.origin=e,this.fields=e.fields?he(e.fields):void 0,this.priority=s,this.t=r}i(){return this.conditions&&!this.o&&(this.o=this.t.conditionsMatcher(this.conditions)),this.o}get ast(){let e=this.i();return e?e.ast:void 0}matchesConditions(e){return this.conditions?!e||I(e)?!this.inverted:this.i()(e):!0}matchesField(e){return this.fields?e?(this.u||(this.u=this.t.fieldMatcher(this.fields)),this.u(e)):!this.inverted:!0}};function At(t,e){let r={value:t,prev:e,next:null};return e&&(e.next=r),r}function Et(t){t.next&&(t.next.prev=t.prev),t.prev&&(t.prev.next=t.next),t.next=t.prev=null}var Re=()=>({rules:[],merged:!1}),qe=()=>new Map,ye=class{constructor(e=[],r={}){this.h=!1,this.l=new Map,this.p={conditionsMatcher:r.conditionsMatcher,fieldMatcher:r.fieldMatcher,resolveAction:r.resolveAction||xt},this.$=r.anyAction||"manage",this.A=r.anySubjectType||"all",this.m=e,this.M=!!r.detectSubjectType,this.j=r.detectSubjectType||Le,this.v(e)}get rules(){return this.m}detectSubjectType(e){return I(e)?e:e?this.j(e):this.A}update(e){let r={rules:e,ability:this,target:this};return this._("update",r),this.m=e,this.v(e),this._("updated",r),this}v(e){let r=new Map,s;for(let n=e.length-1;n>=0;n--){let o=e.length-n-1,i=new de(e[n],this.p,o),a=he(i.action),c=he(i.subject||this.A);!this.h&&i.fields&&(this.h=!0);for(let u=0;u<c.length;u++){let Ke=_(r,c[u],qe);s===void 0&&(s=typeof c[u]),typeof c[u]!==s&&s!=="mixed"&&(s="mixed");for(let T=0;T<a.length;T++)_(Ke,a[T],Re).rules.push(i)}}if(this.l=r,s!=="mixed"&&!this.M){let n=Pe[s]||Pe.string;this.j=n}}possibleRulesFor(e,r=this.A){if(!I(r))throw new Error('"possibleRulesFor" accepts only subject types (i.e., string or class) as the 2nd parameter');let s=_(this.l,r,qe),n=_(s,e,Re);if(n.merged)return n.rules;let o=e!==this.$&&s.has(this.$)?s.get(this.$).rules:void 0,i=Se(n.rules,o);return r!==this.A&&(i=Se(i,this.possibleRulesFor(e,this.A))),n.rules=i,n.merged=!0,i}rulesFor(e,r,s){let n=this.possibleRulesFor(e,r);if(s&&typeof s!="string")throw new Error("The 3rd, `field` parameter is expected to be a string. See https://stalniy.github.io/casl/en/api/casl-ability#can-of-pure-ability for details");return this.h?jt(n,o=>o.matchesField(s)):n}actionsFor(e){if(!I(e))throw new Error('"actionsFor" accepts only subject types (i.e., string or class) as a parameter');let r=new Set,s=this.l.get(e);s&&Array.from(s.keys()).forEach(o=>r.add(o));let n=e!==this.A?this.l.get(this.A):void 0;return n&&Array.from(n.keys()).forEach(o=>r.add(o)),Array.from(r)}on(e,r){this.F=this.F||new Map;let s=this.F,n=s.get(e)||null,o=At(r,n);return s.set(e,o),()=>{let i=s.get(e);!o.next&&!o.prev&&i===o?s.delete(e):o===i&&s.set(e,o.prev),Et(o)}}_(e,r){if(!this.F)return;let s=this.F.get(e)||null,n=[];for(;s!==null;)n.push(s.value),s=s.prev;for(let o=0;o<n.length;o++)n[o](r)}},ge=class extends ye{can(e,r,s){let n=this.relevantRuleFor(e,r,s);return!!n&&!n.inverted}relevantRuleFor(e,r,s){let n=this.detectSubjectType(r),o=this.rulesFor(e,n,s);for(let i=0,a=o.length;i<a;i++)if(o[i].matchesConditions(r))return o[i];return null}cannot(e,r,s){return!this.can(e,r,s)}},Ft={$eq:A,$ne:K,$lt:Q,$lte:G,$gt:b,$gte:O,$in:m,$nin:V,$all:B,$size:U,$regex:Y,$options:H,$elemMatch:L,$exists:J},Ct={eq:F,ne:re,lt:ne,lte:se,gt:oe,gte:ie,in:$,nin:le,all:pe,size:ce,regex:ue,elemMatch:fe,exists:ae,and:te};var Mt=M(Ft,Ct),_t=/[-/\\^$+?.()|[\]{}]/g,It=/\.?\*+\.?/g,Tt=/\*+/,Pt=/\./g;function Nt(t,e,r){let s=r[0]==="*"||t[0]==="."&&t[t.length-1]==="."?"+":"*",n=t.indexOf("**")===-1?"[^.]":".",o=t.replace(Pt,"\\$&").replace(Tt,n+s);return e+t.length===r.length?`(?:${o})?`:o}function St(t,e,r){return t==="."&&(r[e-1]==="*"||r[e+1]==="*")?t:`\\${t}`}function Rt(t){let e=t.map(s=>s.replace(_t,St).replace(It,Nt)),r=e.length>1?`(?:${e.join("|")})`:e[0];return new RegExp(`^${r}$`)}var qt=t=>{let e;return r=>(typeof e>"u"&&(e=t.every(s=>s.indexOf("*")===-1)?null:Rt(t)),e===null?t.indexOf(r)!==-1:e.test(r))};function Ue(t=[],e={}){return new ge(t,Object.assign({conditionsMatcher:Mt,fieldMatcher:qt},e))}var kt=t=>`Cannot execute "${t.action}" on "${t.subjectType}"`,Ve=function(e){this.message=e};Ve.prototype=Object.create(Error.prototype);var me=class extends Ve{static setDefaultMessage(e){this.P=typeof e=="string"?()=>e:e}static from(e){return new this(e)}constructor(e){super(""),this.ability=e,typeof Error.captureStackTrace=="function"&&(this.name="ForbiddenError",Error.captureStackTrace(this,this.constructor))}setMessage(e){return this.message=e,this}throwUnlessCan(e,r,s){let n=this.unlessCan(e,r,s);if(n)throw n}unlessCan(e,r,s){let n=this.ability.relevantRuleFor(e,r,s);if(n&&!n.inverted)return;this.action=e,this.subject=r,this.subjectType=wt(this.ability.detectSubjectType(r)),this.field=s;let o=n?n.reason:"";return this.message=this.message||o||this.constructor.P(this),this}};me.P=kt;var ar=Object.freeze({__proto__:null});var be="0.0.1-probe.1";function Be(t){return{ok:!0,side:t,version:be}}function v(t,e){if(t==null)return t;if(typeof t=="string")return t.indexOf("$principal.")===0?t.slice(11).split(".").reduce((s,n)=>s==null?s:s[n],e):t;if(Array.isArray(t))return t.map(r=>v(r,e));if(typeof t=="object"){let r={};for(let s of Object.keys(t))r[s]=v(t[s],e);return r}return t}function $e(t,e){let r=new Set(t&&t.subjects||[]);return(e.rules||[]).filter(s=>r.has(s.subject)).map(s=>{let n={action:s.actions,subject:s.resource};return s.where&&(n.conditions=v(s.where,t)),n})}function ve(t){return Ue(t)}function Je(t,e){return ve($e(t,e))}var we=[{action:"read",type:"Booking",object:{customerId:"m-1"}},{action:"read",type:"Booking",object:{customerId:"m-2"}},{action:"cancel",type:"Booking",object:{customerId:"m-1"}},{action:"delete",type:"Booking",object:{customerId:"m-1"}},{action:"manage",type:"Vendor",object:{_id:"v-1"}}];function Qe(t){return we.map(e=>({action:e.action,type:e.type,object:e.object,can:t.can(e.action,ze(e.type,Object.assign({},e.object)))}))}function zt(){return Be("public")}async function Dt(){try{return(await Ge.currentMember.getRoles()).map(e=>e.title)}catch{return[]}}0&&(module.exports={CASES,PACKAGE_VERSION,abilityFor,abilityFromRules,caseTable,frontendRoleTitles,publicPing,resolvePlaceholders,rulesFor});
1
+ var P=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames;var We=Object.prototype.hasOwnProperty;var Xe=(t,e)=>{for(var r in e)P(t,r,{get:e[r],enumerable:!0})},Ze=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of He(e))!We.call(t,n)&&n!==r&&P(t,n,{get:()=>e[n],enumerable:!(s=Ye(e,n))||s.enumerable});return t};var et=t=>Ze(P({},"__esModule",{value:!0}),t);var Lt={};Xe(Lt,{CASES:()=>we,PACKAGE_VERSION:()=>be,abilityFor:()=>Je,abilityFromRules:()=>ve,caseTable:()=>Qe,frontendRoleTitles:()=>Dt,publicPing:()=>zt,resolvePlaceholders:()=>v,rulesFor:()=>$e});module.exports=et(Lt);var Ge=require("wix-members-frontend");var w=class{constructor(e,r){this.operator=e,this.value=r,Object.defineProperty(this,"t",{writable:!0})}get notes(){return this.t}addNote(e){this.t=this.t||[],this.t.push(e)}},y=class extends w{},p=class extends y{constructor(e,r){if(!Array.isArray(r))throw new Error(`"${e}" operator expects to receive an array of conditions`);super(e,r)}},l="__itself__",f=class extends w{constructor(e,r,s){super(e,s),this.field=r}},q=new y("__null__",null),R=Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);function tt(t,e){return e instanceof p&&e.operator===t}function k(t,e){return e.length===1?e[0]:new p(t,(function r(s,n,o){let i=o||[];for(let a=0,c=n.length;a<c;a++){let u=n[a];tt(s,u)?r(s,u.value,i):i.push(u)}return i})(t,e))}var rt=t=>t,xe=()=>Object.create(null),je=Object.defineProperty(xe(),"__@type@__",{value:"ignore value"});function st(t,e,r=!1){if(!t||t&&t.constructor!==Object)return!1;for(let s in t)if(R(t,s)&&R(e,s)&&(!r||t[s]!==je))return!0;return!1}function nt(t){let e=[];for(let r in t)R(t,r)&&t[r]!==je&&e.push(r);return e}function N(t,e){e!==q&&t.push(e)}var z=t=>k("and",t);var x={compound(t,e,r){let s=(Array.isArray(e)?e:[e]).map(n=>r.parse(n));return new p(t.name,s)},field:(t,e,r)=>new f(t.name,r.field,e),document:(t,e)=>new y(t.name,e)},g=class{constructor(e,r=xe()){this.o=void 0,this.s=void 0,this.i=void 0,this.u=void 0,this.h=void 0,this.parse=this.parse.bind(this),this.u={operatorToConditionName:r.operatorToConditionName||rt,defaultOperatorName:r.defaultOperatorName||"eq",mergeFinalConditions:r.mergeFinalConditions||z},this.o=Object.keys(e).reduce((s,n)=>(s[n]=Object.assign({name:this.u.operatorToConditionName(n)},e[n]),s),{}),this.s=Object.assign({},r.fieldContext,{field:"",query:{},parse:this.parse,hasOperators:s=>st(s,this.o,r.useIgnoreValue)}),this.i=Object.assign({},r.documentContext,{parse:this.parse,query:{}}),this.h=r.useIgnoreValue?nt:Object.keys}setParse(e){this.parse=e,this.s.parse=e,this.i.parse=e}parseField(e,r,s,n){let o=this.o[r];if(!o)throw new Error(`Unsupported operator "${r}"`);if(o.type!=="field")throw new Error(`Unexpected ${o.type} operator "${r}" at field level`);return this.s.field=e,this.s.query=n,this.parseInstruction(o,s,this.s)}parseInstruction(e,r,s){return typeof e.validate=="function"&&e.validate(e,r),(e.parse||x[e.type])(e,r,s)}parseFieldOperators(e,r){let s=[],n=this.h(r);for(let o=0,i=n.length;o<i;o++){let a=n[o];if(!this.o[a])throw new Error(`Field query for "${e}" may contain only operators or a plain object as a value`);N(s,this.parseField(e,a,r[a],r))}return s}parse(e){let r=[],s=this.h(e);this.i.query=e;for(let n=0,o=s.length;n<o;n++){let i=s[n],a=e[i],c=this.o[i];if(c){if(c.type!=="document"&&c.type!=="compound")throw new Error(`Cannot use parsing instruction for operator "${i}" in "document" context as it is supposed to be used in "${c.type}" context`);N(r,this.parseInstruction(c,a,this.i))}else this.s.hasOperators(a)?r.push(...this.parseFieldOperators(i,a)):N(r,this.parseField(i,this.u.defaultOperatorName,a,e))}return this.u.mergeFinalConditions(r)}};function S(t,e){let r=t[e];if(typeof r!="function")throw new Error(`Unable to interpret "${e}" condition. Did you forget to register interpreter for it?`);return r}function ot(t){return t.operator}function Oe(t,e){let r=e,s=r&&r.getInterpreterName||ot,n;switch(r?r.numberOfArguments:0){case 1:n=i=>{let a=s(i,r);return S(t,a)(i,o)};break;case 3:n=(i,a,c)=>{let u=s(i,r);return S(t,u)(i,a,c,o)};break;default:n=(i,a)=>{let c=s(i,r);return S(t,c)(i,a,o)}}let o=Object.assign({},r,{interpret:n});return o.interpret}function Ae(t,e){return(r,...s)=>{let n=t(r,...s),o=e.bind(null,n);return o.ast=n,o}}var Vt=g.prototype.parseInstruction;function Ee(t,e){if(!Array.isArray(e))throw new Error(`"${t.name}" expects value to be an array`)}function Fe(t,e){if(Ee(t,e),!e.length)throw new Error(`"${t.name}" expects to have at least one element in array`)}var D=t=>(e,r)=>{if(typeof r!==t)throw new Error(`"${e.name}" expects value to be a "${t}"`)},Ce={type:"compound",validate:Fe,parse(t,e,{parse:r}){let s=e.map(n=>r(n));return k(t.name,s)}},it=Ce,at={type:"compound",validate:Fe},ct={type:"field",validate(t,e){if(!(e&&(e instanceof RegExp||e.constructor===Object)))throw new Error(`"${t.name}" expects to receive either regular expression or object of field operators`)},parse(t,e,r){let s=e instanceof RegExp?new f("regex",r.field,e):r.parse(e,r);return new p(t.name,[s])}},L={type:"field",validate(t,e){if(!e||e.constructor!==Object)throw new Error(`"${t.name}" expects to receive an object with nested query or field level operators`)},parse(t,e,{parse:r,field:s,hasOperators:n}){let o=n(e)?r(e,{field:l}):r(e);return new f(t.name,s,o)}},U={type:"field",validate:D("number")},m={type:"field",validate:Ee},V=m,B=m,ut={type:"field",validate(t,e){if(!Array.isArray(e)||e.length!==2)throw new Error(`"${t.name}" expects an array with 2 numeric elements`)}},J={type:"field",validate:D("boolean")},O={type:"field",validate:function(t,e){if(!(typeof e=="string"||typeof e=="number"||e instanceof Date))throw new Error(`"${t.name}" expects value to be comparable (i.e., string, number or date)`)}},b=O,Q=b,G=b,A={type:"field"},K=A,Y={type:"field",validate(t,e){if(!(e instanceof RegExp)&&typeof e!="string")throw new Error(`"${t.name}" expects value to be a regular expression or a string that represents regular expression`)},parse(t,e,r){let s=typeof e=="string"?new RegExp(e,r.query.$options||""):e;return new f(t.name,r.field,s)}},H={type:"field",parse:()=>q},lt={type:"document",validate:D("function")},pt=Object.freeze({__proto__:null,$and:Ce,$or:it,$nor:at,$not:ct,$elemMatch:L,$size:U,$in:m,$nin:V,$all:B,$mod:ut,$exists:J,$gte:O,$gt:b,$lt:Q,$lte:G,$eq:A,$ne:K,$regex:Y,$options:H,$where:lt}),j=class extends g{constructor(e){super(e,{defaultOperatorName:"$eq",operatorToConditionName:r=>r.slice(1)})}parse(e,r){return r&&r.field?z(this.parseFieldOperators(r.field,e)):super.parse(e)}},E=pt;function W(t,e,r){for(let s=0,n=t.length;s<n;s++)if(r(t[s],e)===0)return!0;return!1}function X(t,e){return Array.isArray(t)&&Number.isNaN(Number(e))}function Me(t,e,r){if(!X(t,e))return r(t,e);let s=[];for(let n=0;n<t.length;n++){let o=r(t[n],e);o!==void 0&&(s=s.concat(o))}return s}function h(t){return(e,r,s)=>{let n=s.get(r,e.field);return Array.isArray(n)?n.some(o=>t(e,o,s)):t(e,n,s)}}var ft=Object.hasOwn||Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty),ht=(t,e)=>t[e];function _e(t,e,r){let s=e.lastIndexOf(".");return s===-1?[t,e]:[r(t,e.slice(0,s)),e.slice(s+1)]}function dt(t,e,r=ht){if(e===l)return t;if(!t)throw new Error(`Unable to get field "${e}" out of ${String(t)}.`);return(function(s,n,o){if(n.indexOf(".")===-1)return Me(s,n,o);let i=n.split("."),a=s;for(let c=0,u=i.length;c<u;c++)if(a=Me(a,i[c],o),!a||typeof a!="object")return c<u-1?void 0:a;return a})(t,e,r)}function Z(t,e){return t===e?0:t>e?1:-1}function ee(t,e={}){return Oe(t,Object.assign({get:dt,compare:Z},e))}var Ie=(t,e,{interpret:r})=>t.value.some(s=>r(s,e)),yt=(t,e,r)=>!Ie(t,e,r),te=(t,e,{interpret:r})=>t.value.every(s=>r(s,e)),gt=(t,e,{interpret:r})=>!r(t.value[0],e),F=(t,e,{compare:r,get:s})=>{let n=s(e,t.field);return Array.isArray(n)&&!Array.isArray(t.value)?W(n,t.value,r):r(n,t.value)===0},re=(t,e,r)=>!F(t,e,r),se=h((t,e,r)=>{let s=r.compare(e,t.value);return s===0||s===-1}),ne=h((t,e,r)=>r.compare(e,t.value)===-1),oe=h((t,e,r)=>r.compare(e,t.value)===1),ie=h((t,e,r)=>{let s=r.compare(e,t.value);return s===0||s===1}),ae=(t,e,{get:r})=>{if(t.field===l)return e!==void 0;let[s,n]=_e(e,t.field,r),o=i=>i==null?!!i===t.value:ft(i,n)===t.value;return X(s,n)?s.some(o):o(s)},mt=h((t,e)=>typeof e=="number"&&e%t.value[0]===t.value[1]),ce=(t,e,{get:r})=>{let[s,n]=_e(e,t.field,r),o=i=>{let a=r(i,n);return Array.isArray(a)&&a.length===t.value};return t.field!==l&&X(s,n)?s.some(o):o(s)},ue=h((t,e)=>typeof e=="string"&&t.value.test(e)),$=h((t,e,{compare:r})=>W(t.value,e,r)),le=(t,e,r)=>!$(t,e,r),pe=(t,e,{compare:r,get:s})=>{let n=s(e,t.field);return Array.isArray(n)&&t.value.every(o=>W(n,o,r))},fe=(t,e,{interpret:r,get:s})=>{let n=s(e,t.field);return Array.isArray(n)&&n.some(o=>r(t.value,o))},bt=(t,e)=>t.value.call(e),$t=Object.freeze({__proto__:null,or:Ie,nor:yt,and:te,not:gt,eq:F,ne:re,lte:se,lt:ne,gt:oe,gte:ie,exists:ae,mod:mt,size:ce,regex:ue,within:$,nin:le,all:pe,elemMatch:fe,where:bt}),C=Object.assign({},$t,{in:$}),Yt=ee(C);function Te(t){return t===null||typeof t!="object"?t:t instanceof Date?t.getTime():t&&typeof t.toJSON=="function"?t.toJSON():t}var vt=(t,e)=>Z(Te(t),Te(e));function M(t,e,r){let s=new j(t),n=ee(e,Object.assign({compare:vt},r));if(r&&r.forPrimitives){let o={field:l},i=s.parse;s.setParse(a=>i(a,o))}return Ae(s.parse,n)}var er=M(E,C),tr=M(["$and","$or"].reduce((t,e)=>(t[e]=Object.assign({},t[e],{type:"field"}),t),Object.assign({},E,{$nor:Object.assign({},E.$nor,{type:"field",parse:x.compound})})),C,{forPrimitives:!0});var ke=Object.hasOwn||((t,e)=>Object.prototype.hasOwnProperty.call(t,e));function he(t){return Array.isArray(t)?t:[t]}var d="__caslSubjectType__";function ze(t,e){if(e){if(!ke(e,d))Object.defineProperty(e,d,{value:t});else if(t!==e[d])throw new Error(`Trying to cast object to subject type ${t} but previously it was casted to ${e[d]}`)}return e}var I=t=>{let e=typeof t;return e==="string"||e==="function"},De=t=>t.modelName||t.name;function wt(t){return typeof t=="string"?t:De(t)}function Le(t){return ke(t,d)?t[d]:De(t.constructor)}var Pe={function:t=>t.constructor,string:Le};function Ne(t,e,r){for(let s=r;s<e.length;s++)t.push(e[s])}function Se(t,e){if(!t||!t.length)return e||[];if(!e||!e.length)return t||[];let r=0,s=0,n=[];for(;r<t.length&&s<e.length;)t[r].priority<e[s].priority?(n.push(t[r]),r++):t[r].priority>e[s].priority?(n.push(e[s]),s++):(n.push(t[r]),r++,s++);return Ne(n,t,r),Ne(n,e,s),n}function _(t,e,r){let s=t.get(e);return s||(s=r(),t.set(e,s)),s}var xt=t=>t;function jt(t,e){let r;for(let s=0;s<t.length;s++){let n=e(t[s]);r&&n&&r.push(t[s]),n||(r??(r=t.slice(0,s)))}return r||t}function Ot(t,e){if(Array.isArray(t.fields)&&!t.fields.length)throw new Error("`rawRule.fields` cannot be an empty array. https://bit.ly/390miLa");if(t.fields&&!e.fieldMatcher)throw new Error('You need to pass "fieldMatcher" option in order to restrict access by fields');if(t.conditions&&!e.conditionsMatcher)throw new Error('You need to pass "conditionsMatcher" option in order to restrict access by conditions')}var de=class{constructor(e,r,s=0){Ot(e,r),this.action=r.resolveAction(e.action),this.subject=e.subject,this.inverted=!!e.inverted,this.conditions=e.conditions,this.reason=e.reason,this.origin=e,this.fields=e.fields?he(e.fields):void 0,this.priority=s,this.t=r}i(){return this.conditions&&!this.o&&(this.o=this.t.conditionsMatcher(this.conditions)),this.o}get ast(){let e=this.i();return e?e.ast:void 0}matchesConditions(e){return this.conditions?!e||I(e)?!this.inverted:this.i()(e):!0}matchesField(e){return this.fields?e?(this.u||(this.u=this.t.fieldMatcher(this.fields)),this.u(e)):!this.inverted:!0}};function At(t,e){let r={value:t,prev:e,next:null};return e&&(e.next=r),r}function Et(t){t.next&&(t.next.prev=t.prev),t.prev&&(t.prev.next=t.next),t.next=t.prev=null}var Re=()=>({rules:[],merged:!1}),qe=()=>new Map,ye=class{constructor(e=[],r={}){this.h=!1,this.l=new Map,this.p={conditionsMatcher:r.conditionsMatcher,fieldMatcher:r.fieldMatcher,resolveAction:r.resolveAction||xt},this.$=r.anyAction||"manage",this.A=r.anySubjectType||"all",this.m=e,this.M=!!r.detectSubjectType,this.j=r.detectSubjectType||Le,this.v(e)}get rules(){return this.m}detectSubjectType(e){return I(e)?e:e?this.j(e):this.A}update(e){let r={rules:e,ability:this,target:this};return this._("update",r),this.m=e,this.v(e),this._("updated",r),this}v(e){let r=new Map,s;for(let n=e.length-1;n>=0;n--){let o=e.length-n-1,i=new de(e[n],this.p,o),a=he(i.action),c=he(i.subject||this.A);!this.h&&i.fields&&(this.h=!0);for(let u=0;u<c.length;u++){let Ke=_(r,c[u],qe);s===void 0&&(s=typeof c[u]),typeof c[u]!==s&&s!=="mixed"&&(s="mixed");for(let T=0;T<a.length;T++)_(Ke,a[T],Re).rules.push(i)}}if(this.l=r,s!=="mixed"&&!this.M){let n=Pe[s]||Pe.string;this.j=n}}possibleRulesFor(e,r=this.A){if(!I(r))throw new Error('"possibleRulesFor" accepts only subject types (i.e., string or class) as the 2nd parameter');let s=_(this.l,r,qe),n=_(s,e,Re);if(n.merged)return n.rules;let o=e!==this.$&&s.has(this.$)?s.get(this.$).rules:void 0,i=Se(n.rules,o);return r!==this.A&&(i=Se(i,this.possibleRulesFor(e,this.A))),n.rules=i,n.merged=!0,i}rulesFor(e,r,s){let n=this.possibleRulesFor(e,r);if(s&&typeof s!="string")throw new Error("The 3rd, `field` parameter is expected to be a string. See https://stalniy.github.io/casl/en/api/casl-ability#can-of-pure-ability for details");return this.h?jt(n,o=>o.matchesField(s)):n}actionsFor(e){if(!I(e))throw new Error('"actionsFor" accepts only subject types (i.e., string or class) as a parameter');let r=new Set,s=this.l.get(e);s&&Array.from(s.keys()).forEach(o=>r.add(o));let n=e!==this.A?this.l.get(this.A):void 0;return n&&Array.from(n.keys()).forEach(o=>r.add(o)),Array.from(r)}on(e,r){this.F=this.F||new Map;let s=this.F,n=s.get(e)||null,o=At(r,n);return s.set(e,o),()=>{let i=s.get(e);!o.next&&!o.prev&&i===o?s.delete(e):o===i&&s.set(e,o.prev),Et(o)}}_(e,r){if(!this.F)return;let s=this.F.get(e)||null,n=[];for(;s!==null;)n.push(s.value),s=s.prev;for(let o=0;o<n.length;o++)n[o](r)}},ge=class extends ye{can(e,r,s){let n=this.relevantRuleFor(e,r,s);return!!n&&!n.inverted}relevantRuleFor(e,r,s){let n=this.detectSubjectType(r),o=this.rulesFor(e,n,s);for(let i=0,a=o.length;i<a;i++)if(o[i].matchesConditions(r))return o[i];return null}cannot(e,r,s){return!this.can(e,r,s)}},Ft={$eq:A,$ne:K,$lt:Q,$lte:G,$gt:b,$gte:O,$in:m,$nin:V,$all:B,$size:U,$regex:Y,$options:H,$elemMatch:L,$exists:J},Ct={eq:F,ne:re,lt:ne,lte:se,gt:oe,gte:ie,in:$,nin:le,all:pe,size:ce,regex:ue,elemMatch:fe,exists:ae,and:te};var Mt=M(Ft,Ct),_t=/[-/\\^$+?.()|[\]{}]/g,It=/\.?\*+\.?/g,Tt=/\*+/,Pt=/\./g;function Nt(t,e,r){let s=r[0]==="*"||t[0]==="."&&t[t.length-1]==="."?"+":"*",n=t.indexOf("**")===-1?"[^.]":".",o=t.replace(Pt,"\\$&").replace(Tt,n+s);return e+t.length===r.length?`(?:${o})?`:o}function St(t,e,r){return t==="."&&(r[e-1]==="*"||r[e+1]==="*")?t:`\\${t}`}function Rt(t){let e=t.map(s=>s.replace(_t,St).replace(It,Nt)),r=e.length>1?`(?:${e.join("|")})`:e[0];return new RegExp(`^${r}$`)}var qt=t=>{let e;return r=>(typeof e>"u"&&(e=t.every(s=>s.indexOf("*")===-1)?null:Rt(t)),e===null?t.indexOf(r)!==-1:e.test(r))};function Ue(t=[],e={}){return new ge(t,Object.assign({conditionsMatcher:Mt,fieldMatcher:qt},e))}var kt=t=>`Cannot execute "${t.action}" on "${t.subjectType}"`,Ve=function(e){this.message=e};Ve.prototype=Object.create(Error.prototype);var me=class extends Ve{static setDefaultMessage(e){this.P=typeof e=="string"?()=>e:e}static from(e){return new this(e)}constructor(e){super(""),this.ability=e,typeof Error.captureStackTrace=="function"&&(this.name="ForbiddenError",Error.captureStackTrace(this,this.constructor))}setMessage(e){return this.message=e,this}throwUnlessCan(e,r,s){let n=this.unlessCan(e,r,s);if(n)throw n}unlessCan(e,r,s){let n=this.ability.relevantRuleFor(e,r,s);if(n&&!n.inverted)return;this.action=e,this.subject=r,this.subjectType=wt(this.ability.detectSubjectType(r)),this.field=s;let o=n?n.reason:"";return this.message=this.message||o||this.constructor.P(this),this}};me.P=kt;var ar=Object.freeze({__proto__:null});var be="0.2.0";function Be(t){return{ok:!0,side:t,version:be}}function v(t,e){if(t==null)return t;if(typeof t=="string")return t.indexOf("$principal.")===0?t.slice(11).split(".").reduce((s,n)=>s==null?s:s[n],e):t;if(Array.isArray(t))return t.map(r=>v(r,e));if(typeof t=="object"){let r={};for(let s of Object.keys(t))r[s]=v(t[s],e);return r}return t}function $e(t,e){let r=new Set(t&&t.subjects||[]);return(e.rules||[]).filter(s=>r.has(s.subject)).map(s=>{let n={action:s.actions,subject:s.resource};return s.where&&(n.conditions=v(s.where,t)),n})}function ve(t){return Ue(t)}function Je(t,e){return ve($e(t,e))}var we=[{action:"read",type:"Booking",object:{customerId:"m-1"}},{action:"read",type:"Booking",object:{customerId:"m-2"}},{action:"cancel",type:"Booking",object:{customerId:"m-1"}},{action:"delete",type:"Booking",object:{customerId:"m-1"}},{action:"manage",type:"Vendor",object:{_id:"v-1"}}];function Qe(t){return we.map(e=>({action:e.action,type:e.type,object:e.object,can:t.can(e.action,ze(e.type,Object.assign({},e.object)))}))}function zt(){return Be("public")}async function Dt(){try{return(await Ge.currentMember.getRoles()).map(e=>e.title)}catch{return[]}}0&&(module.exports={CASES,PACKAGE_VERSION,abilityFor,abilityFromRules,caseTable,frontendRoleTitles,publicPing,resolvePlaceholders,rulesFor});