New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

civicrm-api

Package Overview
Dependencies
Maintainers
0
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

civicrm-api - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

dist/index.js

4

dist/api3/request-builder.d.ts

@@ -6,6 +6,6 @@ import { Api3 } from "./types";

private params?;
private opts;
private options;
constructor(entity: string, request: Api3.RequestFn<Response>, actions: A);
get requestParams(): Api3.RequestParams;
addOption(option: string, value: Api3.Value): this;
option(option: string, value: Api3.Value): this;
}
import { Api3 } from "./types";
import { Authentication, RequestOptions } from "../types";
export declare function request(this: {

@@ -6,2 +7,2 @@ baseUrl: string;

debug?: boolean;
}, [entity, action, params, options]: Api3.RequestParams, requestOptions?: RequestInit): Promise<any>;
}, [entity, action, params, options]: Api3.RequestParams, requestOptions?: RequestOptions, auth?: Authentication): Promise<any>;
import { Api4 } from "./types";
import { Authentication, RequestOptions } from "../types";
export declare function request(this: {

@@ -6,2 +7,2 @@ baseUrl: string;

debug?: boolean;
}, [entity, action, params, index]: Api4.RequestParams, requestOptions?: RequestInit): Promise<any>;
}, [entity, action, params, index]: Api4.RequestParams, requestOptions?: RequestOptions, auth?: Authentication): Promise<any>;

@@ -1,2 +0,2 @@

import{isEmpty as t,mapValues as e,forIn as i}from"lodash-es";import{bold as s,gray as r,yellow as n}from"picocolors";function o(){return o=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s])}return t},o.apply(this,arguments)}const a=["headers"];async function h(t,e,i={}){let{headers:h}=i,u=function(t,e){if(null==t)return{};var i,s,r={},n=Object.keys(t);for(s=0;s<n.length;s++)e.indexOf(i=n[s])>=0||(r[i]=t[i]);return r}(i,a);const p=crypto.randomUUID(),d=new URL(t,this.baseUrl);e&&(d.search=e.toString());const m=performance.now(),l=await fetch(d,o({method:"POST",headers:o({"X-Civi-Auth":`Bearer ${this.apiKey}`,"Content-Type":"application/x-www-form-urlencoded","X-Requested-With":"XMLHttpRequest","X-Request-ID":p},h)},u));if(this.debug){const t=`${Math.round(performance.now()-m)}ms`;console.group(`${s("CiviCRM request")} ${p} ${r(l.url)} ${l.status} in ${n(t)}`)}if(!l.ok){const t=await l.text();c.call(this,t)}const f=await l.json();return f.is_error&&c.call(this,f),this.debug&&console.groupEnd(),f.values}function c(t){throw this.debug&&(console.error(t),console.groupEnd()),new Error("CiviCRM request failed")}async function u([e,i,s,r],n={}){const o=`civicrm/ajax/api4/${e}/${i}`,a=new URLSearchParams;return t(s)||a.append("params",JSON.stringify(s)),void 0!==r&&a.append("index",String(r)),h.bind(this)(o,a,n)}var p;!function(t){var e;(e=t.Action||(t.Action={})).get="get",e.create="create",e.update="update",e.save="save",e.delete="delete",e.getChecksum="getChecksum"}(p||(p={}));class d{constructor(t,e){this.entity=void 0,this.request=void 0,this.innerPromise=void 0,this.requestOptions={},this.entity=t,this.request=e}options(t){return this.requestOptions=t,this}get requestParams(){throw new Error}then(t,e){return this.getInnerPromise().then(t,e)}getInnerPromise(){return this.innerPromise||(this.innerPromise=this.request(this.requestParams,this.requestOptions)),this.innerPromise}}class m extends d{constructor(t,e){super(t,e),this.action=void 0,this.params=void 0,this.index=void 0,this.chains={}}get requestParams(){const i=o({},this.params);return t(this.chains)||(i.chain=e(this.chains,t=>t.requestParams)),[this.entity,this.action,i,this.index]}get(t){return this.action=p.Action.get,this.params=t,this}create(t){return this.action=p.Action.create,this.params=t,this}update(t){return this.action=p.Action.update,this.params=t,this}save(t){return this.action=p.Action.save,this.params=t,this}delete(t){return this.action=p.Action.delete,this.params=t,this}getChecksum(t){return this.action=p.Action.getChecksum,this.params=t,this}one(){return this.index=0,this}chain(t,e){return this.chains[t]=e,this}}function l(t){const e={};return i(t.entities,(i,s)=>{Reflect.defineProperty(e,s,{get:()=>new m(i,(e,i)=>u.bind(t)(e,o({},t.requestOptions,i)))})}),e}const f="civicrm/ajax/rest";async function g([e,i,s,r],n={}){const a=t(r)?o({},s):o({},s,{options:r}),c=new URLSearchParams({entity:e,action:i,json:JSON.stringify(a)});return h.bind(this)(f,c,n)}class v extends d{constructor(t,e,s){super(t,e),this.action=void 0,this.params=void 0,this.opts={},i(s,(t,e)=>{this[e]=e=>(this.action=t,this.params=e,this)})}get requestParams(){return[this.entity,this.action,this.params,this.opts]}addOption(t,e){return this.opts[t]=e,this}}function w(t){const e={};return i(t.api3.entities,({name:i,actions:s},r)=>{Reflect.defineProperty(e,r,{get:()=>new v(i,(e,i)=>g.bind(t)(e,o({},t.requestOptions,i)),s)})}),e}function y(t){var e;if(!t.baseUrl)throw new Error("baseUrl is required");if(!t.apiKey)throw new Error("apiKey is required");const i=l(t);return null!=(e=t.api3)&&e.enabled&&(i.api3=w(t)),i}export{y as createClient};
function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},t.apply(this,arguments)}var e="object"==typeof global&&global&&global.Object===Object&&global,r="object"==typeof self&&self&&self.Object===Object&&self,n=e||r||Function("return this")(),o=n.Symbol,i=Object.prototype,a=i.hasOwnProperty,u=i.toString,c=o?o.toStringTag:void 0,s=Object.prototype.toString,f="[object Null]",h="[object Undefined]",l=o?o.toStringTag:void 0;function p(t){return null==t?void 0===t?h:f:l&&l in Object(t)?function(t){var e=a.call(t,c),r=t[c];try{t[c]=void 0;var n=!0}catch(t){}var o=u.call(t);return n&&(e?t[c]=r:delete t[c]),o}(t):function(t){return s.call(t)}(t)}function v(t){return null!=t&&"object"==typeof t}var y="[object Symbol]";function b(t){return"symbol"==typeof t||v(t)&&p(t)==y}var d=Array.isArray,_=1/0,g=o?o.prototype:void 0,j=g?g.toString:void 0;function m(t){if("string"==typeof t)return t;if(d(t))return function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}(t,m)+"";if(b(t))return j?j.call(t):"";var e=t+"";return"0"==e&&1/t==-_?"-0":e}function w(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function O(t){return t}var A="[object AsyncFunction]",P="[object Function]",x="[object GeneratorFunction]",S="[object Proxy]";function z(t){if(!w(t))return!1;var e=p(t);return e==P||e==x||e==A||e==S}var q,$=n["__core-js_shared__"],E=(q=/[^.]+$/.exec($&&$.keys&&$.keys.IE_PROTO||""))?"Symbol(src)_1."+q:"",k=Function.prototype.toString;function C(t){if(null!=t){try{return k.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var R=/^\[object .+?Constructor\]$/,U=RegExp("^"+Function.prototype.toString.call(Object.prototype.hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function M(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return function(t){return!(!w(t)||(e=t,E&&E in e))&&(z(t)?U:R).test(C(t));var e}(r)?r:void 0}var T=M(n,"WeakMap"),B=function(){try{var t=M(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),I=B,F=9007199254740991,L=/^(?:0|[1-9]\d*)$/;function D(t,e){var r=typeof t;return!!(e=null==e?F:e)&&("number"==r||"symbol"!=r&&L.test(t))&&t>-1&&t%1==0&&t<e}function N(t,e){return t===e||t!=t&&e!=e}var V=9007199254740991;function W(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=V}function X(t){return null!=t&&W(t.length)&&!z(t)}var K=Object.prototype;function J(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||K)}function G(t){return v(t)&&"[object Arguments]"==p(t)}var H=Object.prototype,Q=H.hasOwnProperty,Y=H.propertyIsEnumerable,Z=G(function(){return arguments}())?G:function(t){return v(t)&&Q.call(t,"callee")&&!Y.call(t,"callee")},tt="object"==typeof exports&&exports&&!exports.nodeType&&exports,et=tt&&"object"==typeof module&&module&&!module.nodeType&&module,rt=et&&et.exports===tt?n.Buffer:void 0,nt=(rt?rt.isBuffer:void 0)||function(){return!1},ot={};ot["[object Float32Array]"]=ot["[object Float64Array]"]=ot["[object Int8Array]"]=ot["[object Int16Array]"]=ot["[object Int32Array]"]=ot["[object Uint8Array]"]=ot["[object Uint8ClampedArray]"]=ot["[object Uint16Array]"]=ot["[object Uint32Array]"]=!0,ot["[object Arguments]"]=ot["[object Array]"]=ot["[object ArrayBuffer]"]=ot["[object Boolean]"]=ot["[object DataView]"]=ot["[object Date]"]=ot["[object Error]"]=ot["[object Function]"]=ot["[object Map]"]=ot["[object Number]"]=ot["[object Object]"]=ot["[object RegExp]"]=ot["[object Set]"]=ot["[object String]"]=ot["[object WeakMap]"]=!1;var it,at="object"==typeof exports&&exports&&!exports.nodeType&&exports,ut=at&&"object"==typeof module&&module&&!module.nodeType&&module,ct=ut&&ut.exports===at&&e.process,st=function(){try{return ut&&ut.require&&ut.require("util").types||ct&&ct.binding&&ct.binding("util")}catch(t){}}(),ft=st&&st.isTypedArray,ht=ft?(it=ft,function(t){return it(t)}):function(t){return v(t)&&W(t.length)&&!!ot[p(t)]},lt=Object.prototype.hasOwnProperty;function pt(t,e){var r=d(t),n=!r&&Z(t),o=!r&&!n&&nt(t),i=!r&&!n&&!o&&ht(t),a=r||n||o||i,u=a?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],c=u.length;for(var s in t)!e&&!lt.call(t,s)||a&&("length"==s||o&&("offset"==s||"parent"==s)||i&&("buffer"==s||"byteLength"==s||"byteOffset"==s)||D(s,c))||u.push(s);return u}var vt=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),yt=vt,bt=Object.prototype.hasOwnProperty;function dt(t){if(!J(t))return yt(t);var e=[];for(var r in Object(t))bt.call(t,r)&&"constructor"!=r&&e.push(r);return e}function _t(t){return X(t)?pt(t):dt(t)}var gt=Object.prototype.hasOwnProperty;function jt(t){return X(t)?pt(t,!0):function(t){if(!w(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=J(t),r=[];for(var n in t)("constructor"!=n||!e&&gt.call(t,n))&&r.push(n);return r}(t)}var mt=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,wt=/^\w*$/;function Ot(t,e){if(d(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!b(t))||wt.test(t)||!mt.test(t)||null!=e&&t in Object(e)}var At=M(Object,"create"),Pt=Object.prototype.hasOwnProperty,xt=Object.prototype.hasOwnProperty;function St(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function zt(t,e){for(var r=t.length;r--;)if(N(t[r][0],e))return r;return-1}St.prototype.clear=function(){this.__data__=At?At(null):{},this.size=0},St.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},St.prototype.get=function(t){var e=this.__data__;if(At){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Pt.call(e,t)?e[t]:void 0},St.prototype.has=function(t){var e=this.__data__;return At?void 0!==e[t]:xt.call(e,t)},St.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=At&&void 0===e?"__lodash_hash_undefined__":e,this};var qt=Array.prototype.splice;function $t(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}$t.prototype.clear=function(){this.__data__=[],this.size=0},$t.prototype.delete=function(t){var e=this.__data__,r=zt(e,t);return!(r<0||(r==e.length-1?e.pop():qt.call(e,r,1),--this.size,0))},$t.prototype.get=function(t){var e=this.__data__,r=zt(e,t);return r<0?void 0:e[r][1]},$t.prototype.has=function(t){return zt(this.__data__,t)>-1},$t.prototype.set=function(t,e){var r=this.__data__,n=zt(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var Et=M(n,"Map");function kt(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function Ct(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Rt(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],i=r.cache;if(i.has(o))return i.get(o);var a=t.apply(this,n);return r.cache=i.set(o,a)||i,a};return r.cache=new(Rt.Cache||Ct),r}Ct.prototype.clear=function(){this.size=0,this.__data__={hash:new St,map:new(Et||$t),string:new St}},Ct.prototype.delete=function(t){var e=kt(this,t).delete(t);return this.size-=e?1:0,e},Ct.prototype.get=function(t){return kt(this,t).get(t)},Ct.prototype.has=function(t){return kt(this,t).has(t)},Ct.prototype.set=function(t,e){var r=kt(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this},Rt.Cache=Ct;var Ut,Mt,Tt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Bt=/\\(\\)?/g,It=(Ut=Rt(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(Tt,function(t,r,n,o){e.push(n?o.replace(Bt,"$1"):r||t)}),e},function(t){return 500===Mt.size&&Mt.clear(),t}),Mt=Ut.cache,Ut);function Ft(t,e){return d(t)?t:Ot(t,e)?[t]:It(function(t){return null==t?"":m(t)}(t))}var Lt=1/0;function Dt(t){if("string"==typeof t||b(t))return t;var e=t+"";return"0"==e&&1/t==-Lt?"-0":e}function Nt(t,e){for(var r=0,n=(e=Ft(e,t)).length;null!=t&&r<n;)t=t[Dt(e[r++])];return r&&r==n?t:void 0}function Vt(t){var e=this.__data__=new $t(t);this.size=e.size}Vt.prototype.clear=function(){this.__data__=new $t,this.size=0},Vt.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Vt.prototype.get=function(t){return this.__data__.get(t)},Vt.prototype.has=function(t){return this.__data__.has(t)},Vt.prototype.set=function(t,e){var r=this.__data__;if(r instanceof $t){var n=r.__data__;if(!Et||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Ct(n)}return r.set(t,e),this.size=r.size,this};var Wt=Object.prototype.propertyIsEnumerable,Xt=Object.getOwnPropertySymbols,Kt=Xt?function(t){return null==t?[]:(t=Object(t),function(e,r){for(var n=-1,o=null==e?0:e.length,i=0,a=[];++n<o;){var u=e[n];Wt.call(t,u)&&(a[i++]=u)}return a}(Xt(t)))}:function(){return[]};function Jt(t){return function(t,e,r){var n=_t(t);return d(t)?n:function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}(n,r(t))}(t,0,Kt)}var Gt=M(n,"DataView"),Ht=M(n,"Promise"),Qt=M(n,"Set"),Yt="[object Map]",Zt="[object Promise]",te="[object Set]",ee="[object WeakMap]",re="[object DataView]",ne=C(Gt),oe=C(Et),ie=C(Ht),ae=C(Qt),ue=C(T),ce=p;(Gt&&ce(new Gt(new ArrayBuffer(1)))!=re||Et&&ce(new Et)!=Yt||Ht&&ce(Ht.resolve())!=Zt||Qt&&ce(new Qt)!=te||T&&ce(new T)!=ee)&&(ce=function(t){var e=p(t),r="[object Object]"==e?t.constructor:void 0,n=r?C(r):"";if(n)switch(n){case ne:return re;case oe:return Yt;case ie:return Zt;case ae:return te;case ue:return ee}return e});var se=ce,fe=n.Uint8Array;function he(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new Ct;++e<r;)this.add(t[e])}function le(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1}he.prototype.add=he.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},he.prototype.has=function(t){return this.__data__.has(t)};var pe=1,ve=2;function ye(t,e,r,n,o,i){var a=r&pe,u=t.length,c=e.length;if(u!=c&&!(a&&c>u))return!1;var s=i.get(t),f=i.get(e);if(s&&f)return s==e&&f==t;var h=-1,l=!0,p=r&ve?new he:void 0;for(i.set(t,e),i.set(e,t);++h<u;){var v=t[h],y=e[h];if(n)var b=a?n(y,v,h,e,t,i):n(v,y,h,t,e,i);if(void 0!==b){if(b)continue;l=!1;break}if(p){if(!le(e,function(t,e){if(!p.has(e)&&(v===t||o(v,t,r,n,i)))return p.push(e)})){l=!1;break}}else if(v!==y&&!o(v,y,r,n,i)){l=!1;break}}return i.delete(t),i.delete(e),l}function be(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r}function de(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r}var _e=o?o.prototype:void 0,ge=_e?_e.valueOf:void 0,je=Object.prototype.hasOwnProperty,me="[object Arguments]",we="[object Array]",Oe="[object Object]",Ae=Object.prototype.hasOwnProperty;function Pe(t,e,r,n,o){return t===e||(null==t||null==e||!v(t)&&!v(e)?t!=t&&e!=e:function(t,e,r,n,o,i){var a=d(t),u=d(e),c=a?we:se(t),s=u?we:se(e),f=(c=c==me?Oe:c)==Oe,h=(s=s==me?Oe:s)==Oe,l=c==s;if(l&&nt(t)){if(!nt(e))return!1;a=!0,f=!1}if(l&&!f)return i||(i=new Vt),a||ht(t)?ye(t,e,r,n,o,i):function(t,e,r,n,o,i,a){switch(r){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!i(new fe(t),new fe(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return N(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var u=be;case"[object Set]":if(u||(u=de),t.size!=e.size&&!(1&n))return!1;var c=a.get(t);if(c)return c==e;n|=2,a.set(t,e);var s=ye(u(t),u(e),n,o,i,a);return a.delete(t),s;case"[object Symbol]":if(ge)return ge.call(t)==ge.call(e)}return!1}(t,e,c,r,n,o,i);if(!(1&r)){var p=f&&Ae.call(t,"__wrapped__"),v=h&&Ae.call(e,"__wrapped__");if(p||v){var y=p?t.value():t,b=v?e.value():e;return i||(i=new Vt),o(y,b,r,n,i)}}return!!l&&(i||(i=new Vt),function(t,e,r,n,o,i){var a=1&r,u=Jt(t),c=u.length;if(c!=Jt(e).length&&!a)return!1;for(var s=c;s--;){var f=u[s];if(!(a?f in e:je.call(e,f)))return!1}var h=i.get(t),l=i.get(e);if(h&&l)return h==e&&l==t;var p=!0;i.set(t,e),i.set(e,t);for(var v=a;++s<c;){var y=t[f=u[s]],b=e[f];if(n)var d=a?n(b,y,f,e,t,i):n(y,b,f,t,e,i);if(!(void 0===d?y===b||o(y,b,r,n,i):d)){p=!1;break}v||(v="constructor"==f)}if(p&&!v){var _=t.constructor,g=e.constructor;_==g||!("constructor"in t)||!("constructor"in e)||"function"==typeof _&&_ instanceof _&&"function"==typeof g&&g instanceof g||(p=!1)}return i.delete(t),i.delete(e),p}(t,e,r,n,o,i))}(t,e,r,n,Pe,o))}function xe(t){return t==t&&!w(t)}function Se(t,e){return function(r){return null!=r&&r[t]===e&&(void 0!==e||t in Object(r))}}function ze(t,e){return null!=t&&e in Object(t)}var qe=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),a=i.length;a--;){var u=i[++n];if(!1===e(o[u],u,o))break}return t};function $e(t,e){return null==t?t:qe(t,"function"==typeof(r=e)?r:O,jt);var r}var Ee="[object Map]",ke="[object Set]",Ce=Object.prototype.hasOwnProperty;function Re(t){if(null==t)return!0;if(X(t)&&(d(t)||"string"==typeof t||"function"==typeof t.splice||nt(t)||ht(t)||Z(t)))return!t.length;var e=se(t);if(e==Ee||e==ke)return!t.size;if(J(t))return!dt(t).length;for(var r in t)if(Ce.call(t,r))return!1;return!0}const Ue=["headers"];function Me(t){if(!t)throw new Error("auth is required, configure it in client config or using the auth method");if("apiKey"in t)return`Bearer ${t.apiKey}`;if("jwt"in t)return`Bearer ${t.jwt}`;if("username"in t)return`Basic ${btoa(`${t.username}:${t.password}`)}`;throw new Error("auth must contain apiKey, jwt, or username/password")}function Te(t){throw this.debug&&(console.error(t),console.groupEnd()),new Error("CiviCRM request failed")}function Be(e,r){return(n,o,i)=>e.bind(r)(n,t({},r.requestOptions,o),t({},r.auth,i))}async function Ie(e,r,n={},o){let{headers:i}=n,a=function(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)e.indexOf(r=i[n])>=0||(o[r]=t[r]);return o}(n,Ue);const u=crypto.randomUUID(),c=new URL(e,this.baseUrl);r&&(c.search=r.toString());const s=performance.now(),f=await fetch(c,t({method:"POST",headers:t({"X-Civi-Auth":Me(o),"Content-Type":"application/x-www-form-urlencoded","X-Requested-With":"XMLHttpRequest","X-Request-ID":u},i)},a));if(this.debug){const t=`${Math.round(performance.now()-s)}ms`;console.group(`CiviCRM request ${u} ${f.url} ${f.status} in ${t}`)}if(!f.ok){const t=await f.text();Te.call(this,t)}const h=await f.json();return h.is_error&&Te.call(this,h),this.debug&&console.groupEnd(),h.values}async function Fe([t,e,r,n],o={},i){const a=`civicrm/ajax/api4/${t}/${e}`,u=new URLSearchParams;return Re(r)||u.append("params",JSON.stringify(r)),void 0!==n&&u.append("index",String(n)),Ie.bind(this)(a,u,o,i)}var Le;!function(t){var e;(e=t.Action||(t.Action={})).get="get",e.create="create",e.update="update",e.save="save",e.delete="delete",e.getChecksum="getChecksum"}(Le||(Le={}));class De{constructor(t,e){this.entity=void 0,this.request=void 0,this.innerPromise=void 0,this._requestOptions={},this._auth=void 0,this.entity=t,this.request=e}requestOptions(t){return this._requestOptions=t,this}auth(t){return this._auth=t,this}get requestParams(){throw new Error}then(t,e){return this.getInnerPromise().then(t,e)}getInnerPromise(){return this.innerPromise||(this.innerPromise=this.request(this.requestParams,this._requestOptions,this._auth)),this.innerPromise}}class Ne extends De{constructor(t,e){super(t,e),this.action=void 0,this.params=void 0,this.index=void 0,this.chains={}}get requestParams(){const e=t({},this.params);return Re(this.chains)||(e.chain=function(t,e){var r,n,o,i={};return e="function"==typeof(r=e)?r:null==r?O:"object"==typeof r?d(r)?function(t,e){return Ot(t)&&xe(e)?Se(Dt(t),e):function(r){var n=function(t,e,r){var n=null==t?void 0:Nt(t,e);return void 0===n?void 0:n}(r,t);return void 0===n&&n===e?function(t,e){return null!=t&&function(t,e,r){for(var n=-1,o=(e=Ft(e,t)).length,i=!1;++n<o;){var a=Dt(e[n]);if(!(i=null!=t&&r(t,a)))break;t=t[a]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&W(o)&&D(a,o)&&(d(t)||Z(t))}(t,e,ze)}(r,t):Pe(e,n,3)}}(r[0],r[1]):(o=function(t){for(var e=_t(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,xe(o)]}return e}(n=r),1==o.length&&o[0][2]?Se(o[0][0],o[0][1]):function(t){return t===n||function(t,e,r,n){var o=r.length,i=o;if(null==t)return!i;for(t=Object(t);o--;){var a=r[o];if(a[2]?a[1]!==t[a[0]]:!(a[0]in t))return!1}for(;++o<i;){var u=(a=r[o])[0],c=t[u];if(a[2]){if(void 0===c&&!(u in t))return!1}else if(!Pe(a[1],c,3,void 0,new Vt))return!1}return!0}(t,0,o)}):function(t){return Ot(t)?(e=Dt(t),function(t){return null==t?void 0:t[e]}):function(t){return function(e){return Nt(e,t)}}(t);var e}(r),function(t,e){t&&qe(t,e,_t)}(t,function(t,r,n){!function(t,e,r){"__proto__"==e&&I?I(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}(i,r,e(t,r,n))}),i}(this.chains,t=>t.requestParams)),[this.entity,this.action,e,this.index]}get(t){return this.action=Le.Action.get,this.params=t,this}create(t){return this.action=Le.Action.create,this.params=t,this}update(t){return this.action=Le.Action.update,this.params=t,this}save(t){return this.action=Le.Action.save,this.params=t,this}delete(t){return this.action=Le.Action.delete,this.params=t,this}getChecksum(t){return this.action=Le.Action.getChecksum,this.params=t,this}one(){return this.index=0,this}chain(t,e){return this.chains[t]=e,this}}const Ve="civicrm/ajax/rest";async function We([e,r,n,o],i={},a){const u=Re(o)?t({},n):t({},n,{options:o}),c=new URLSearchParams({entity:e,action:r,json:JSON.stringify(u)});return Ie.bind(this)(Ve,c,i,a)}class Xe extends De{constructor(t,e,r){super(t,e),this.action=void 0,this.params=void 0,this.options={},$e(r,(t,e)=>{this[e]=e=>(this.action=t,this.params=e,this)})}get requestParams(){return[this.entity,this.action,this.params,this.options]}option(t,e){return this.options[t]=e,this}}function Ke(e){var r;!function(t){if(!t.baseUrl)throw new Error("baseUrl is required")}(e);const n=function(t){const e=Be(Fe,t),r={};return $e(t.entities,(t,n)=>{Reflect.defineProperty(r,n,{get:()=>new Ne(t,e)})}),r}(e);return n.request=(r,n,o,i)=>Ie.bind(e)(r,n,t({},e.requestOptions,o),t({},e.auth,i)),null!=(r=e.api3)&&r.enabled&&(n.api3=function(t){const e=Be(We,t),r={};return $e(t.api3.entities,(t,n)=>{Reflect.defineProperty(r,n,{get:()=>new Xe(t.name,e,t.actions)})}),r}(e)),n}export{Ke as createClient};
//# sourceMappingURL=index.modern.js.map

@@ -1,2 +0,2 @@

import{isEmpty as t,mapValues as e,forIn as r}from"lodash-es";import{bold as n,gray as i,yellow as o}from"picocolors";function s(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:String(e)}function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,s(n.key),n)}}function u(t,e,r){return e&&a(t.prototype,e),r&&a(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function c(){return c=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},c.apply(this,arguments)}function h(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,f(t,e)}function f(t,e){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},f(t,e)}var p=["headers"],v=function(t,e,r){var s=void 0===r?{}:r,a=s.headers,u=function(t,e){if(null==t)return{};var r,n,i={},o=Object.keys(t);for(n=0;n<o.length;n++)e.indexOf(r=o[n])>=0||(i[r]=t[r]);return i}(s,p);try{var h=this,f=crypto.randomUUID(),v=new URL(t,h.baseUrl);e&&(v.search=e.toString());var l=performance.now();return Promise.resolve(fetch(v,c({method:"POST",headers:c({"X-Civi-Auth":"Bearer "+h.apiKey,"Content-Type":"application/x-www-form-urlencoded","X-Requested-With":"XMLHttpRequest","X-Request-ID":f},a)},u))).then(function(t){function e(){return Promise.resolve(t.json()).then(function(t){return t.is_error&&d.call(h,t),h.debug&&console.groupEnd(),t.values})}if(h.debug){var r=Math.round(performance.now()-l)+"ms";console.group(n("CiviCRM request")+" "+f+" "+i(t.url)+" "+t.status+" in "+o(r))}var s=function(){if(!t.ok)return Promise.resolve(t.text()).then(function(t){d.call(h,t)})}();return s&&s.then?s.then(e):e()})}catch(t){return Promise.reject(t)}};function d(t){throw this.debug&&(console.error(t),console.groupEnd()),new Error("CiviCRM request failed")}var l,m=function(e,r){var n=e[0],i=e[1],o=e[2],s=e[3];void 0===r&&(r={});try{var a="civicrm/ajax/api4/"+n+"/"+i,u=new URLSearchParams;return t(o)||u.append("params",JSON.stringify(o)),void 0!==s&&u.append("index",String(s)),Promise.resolve(v.bind(this)(a,u,r))}catch(t){return Promise.reject(t)}};!function(t){var e;(e=t.Action||(t.Action={})).get="get",e.create="create",e.update="update",e.save="save",e.delete="delete",e.getChecksum="getChecksum"}(l||(l={}));var y=/*#__PURE__*/function(){function t(t,e){this.entity=void 0,this.request=void 0,this.innerPromise=void 0,this.requestOptions={},this.entity=t,this.request=e}var e=t.prototype;return e.options=function(t){return this.requestOptions=t,this},e.then=function(t,e){return this.getInnerPromise().then(t,e)},e.getInnerPromise=function(){return this.innerPromise||(this.innerPromise=this.request(this.requestParams,this.requestOptions)),this.innerPromise},u(t,[{key:"requestParams",get:function(){throw new Error}}]),t}(),g=/*#__PURE__*/function(r){function n(t,e){var n;return(n=r.call(this,t,e)||this).action=void 0,n.params=void 0,n.index=void 0,n.chains={},n}h(n,r);var i=n.prototype;return i.get=function(t){return this.action=l.Action.get,this.params=t,this},i.create=function(t){return this.action=l.Action.create,this.params=t,this},i.update=function(t){return this.action=l.Action.update,this.params=t,this},i.save=function(t){return this.action=l.Action.save,this.params=t,this},i.delete=function(t){return this.action=l.Action.delete,this.params=t,this},i.getChecksum=function(t){return this.action=l.Action.getChecksum,this.params=t,this},i.one=function(){return this.index=0,this},i.chain=function(t,e){return this.chains[t]=e,this},u(n,[{key:"requestParams",get:function(){var r=c({},this.params);return t(this.chains)||(r.chain=e(this.chains,function(t){return t.requestParams})),[this.entity,this.action,r,this.index]}}]),n}(y),b=function(e,r){var n=e[0],i=e[1],o=e[2],s=e[3];void 0===r&&(r={});try{var a=t(s)?c({},o):c({},o,{options:s}),u=new URLSearchParams({entity:n,action:i,json:JSON.stringify(a)});return Promise.resolve(v.bind(this)(P,u,r))}catch(t){return Promise.reject(t)}},P="civicrm/ajax/rest",w=/*#__PURE__*/function(t){function e(e,n,i){var o;return(o=t.call(this,e,n)||this).action=void 0,o.params=void 0,o.opts={},r(i,function(t,e){o[e]=function(e){return o.action=t,o.params=e,function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(o)}}),o}return h(e,t),e.prototype.addOption=function(t,e){return this.opts[t]=e,this},u(e,[{key:"requestParams",get:function(){return[this.entity,this.action,this.params,this.opts]}}]),e}(y);function O(t){var e;if(!t.baseUrl)throw new Error("baseUrl is required");if(!t.apiKey)throw new Error("apiKey is required");var n=function(t){var e={};return r(t.entities,function(r,n){Reflect.defineProperty(e,n,{get:function(){return new g(r,function(e,r){return m.bind(t)(e,c({},t.requestOptions,r))})}})}),e}(t);return null!=(e=t.api3)&&e.enabled&&(n.api3=function(t){var e={};return r(t.api3.entities,function(r,n){var i=r.name,o=r.actions;Reflect.defineProperty(e,n,{get:function(){return new w(i,function(e,r){return b.bind(t)(e,c({},t.requestOptions,r))},o)}})}),e}(t)),n}export{O as createClient};
function t(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:String(e)}function e(e,r){for(var n=0;n<r.length;n++){var o=r[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,t(o.key),o)}}function r(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(){return n=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},n.apply(this,arguments)}function o(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,i(t,e)}function i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}var u="object"==typeof global&&global&&global.Object===Object&&global,a="object"==typeof self&&self&&self.Object===Object&&self,c=u||a||Function("return this")(),s=c.Symbol,f=Object.prototype,l=f.hasOwnProperty,p=f.toString,h=s?s.toStringTag:void 0,v=Object.prototype.toString,y="[object Null]",b="[object Undefined]",d=s?s.toStringTag:void 0;function _(t){return null==t?void 0===t?b:y:d&&d in Object(t)?function(t){var e=l.call(t,h),r=t[h];try{t[h]=void 0;var n=!0}catch(t){}var o=p.call(t);return n&&(e?t[h]=r:delete t[h]),o}(t):function(t){return v.call(t)}(t)}function g(t){return null!=t&&"object"==typeof t}var j="[object Symbol]";function m(t){return"symbol"==typeof t||g(t)&&_(t)==j}var w=Array.isArray,O=1/0,P=s?s.prototype:void 0,A=P?P.toString:void 0;function S(t){if("string"==typeof t)return t;if(w(t))return function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}(t,S)+"";if(m(t))return A?A.call(t):"";var e=t+"";return"0"==e&&1/t==-O?"-0":e}function x(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function z(t){return t}var q="[object AsyncFunction]",k="[object Function]",E="[object GeneratorFunction]",C="[object Proxy]";function R(t){if(!x(t))return!1;var e=_(t);return e==k||e==E||e==q||e==C}var U,M=c["__core-js_shared__"],T=(U=/[^.]+$/.exec(M&&M.keys&&M.keys.IE_PROTO||""))?"Symbol(src)_1."+U:"",B=Function.prototype.toString;function I(t){if(null!=t){try{return B.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var $=/^\[object .+?Constructor\]$/,F=RegExp("^"+Function.prototype.toString.call(Object.prototype.hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function L(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return function(t){return!(!x(t)||(e=t,T&&T in e))&&(R(t)?F:$).test(I(t));var e}(r)?r:void 0}var D=L(c,"WeakMap"),N=function(){try{var t=L(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),V=N,W=9007199254740991,X=/^(?:0|[1-9]\d*)$/;function K(t,e){var r=typeof t;return!!(e=null==e?W:e)&&("number"==r||"symbol"!=r&&X.test(t))&&t>-1&&t%1==0&&t<e}function J(t,e){return t===e||t!=t&&e!=e}var G=9007199254740991;function H(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=G}function Q(t){return null!=t&&H(t.length)&&!R(t)}var Y=Object.prototype;function Z(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Y)}function tt(t){return g(t)&&"[object Arguments]"==_(t)}var et=Object.prototype,rt=et.hasOwnProperty,nt=et.propertyIsEnumerable,ot=tt(function(){return arguments}())?tt:function(t){return g(t)&&rt.call(t,"callee")&&!nt.call(t,"callee")},it="object"==typeof exports&&exports&&!exports.nodeType&&exports,ut=it&&"object"==typeof module&&module&&!module.nodeType&&module,at=ut&&ut.exports===it?c.Buffer:void 0,ct=(at?at.isBuffer:void 0)||function(){return!1},st={};st["[object Float32Array]"]=st["[object Float64Array]"]=st["[object Int8Array]"]=st["[object Int16Array]"]=st["[object Int32Array]"]=st["[object Uint8Array]"]=st["[object Uint8ClampedArray]"]=st["[object Uint16Array]"]=st["[object Uint32Array]"]=!0,st["[object Arguments]"]=st["[object Array]"]=st["[object ArrayBuffer]"]=st["[object Boolean]"]=st["[object DataView]"]=st["[object Date]"]=st["[object Error]"]=st["[object Function]"]=st["[object Map]"]=st["[object Number]"]=st["[object Object]"]=st["[object RegExp]"]=st["[object Set]"]=st["[object String]"]=st["[object WeakMap]"]=!1;var ft,lt="object"==typeof exports&&exports&&!exports.nodeType&&exports,pt=lt&&"object"==typeof module&&module&&!module.nodeType&&module,ht=pt&&pt.exports===lt&&u.process,vt=function(){try{return pt&&pt.require&&pt.require("util").types||ht&&ht.binding&&ht.binding("util")}catch(t){}}(),yt=vt&&vt.isTypedArray,bt=yt?(ft=yt,function(t){return ft(t)}):function(t){return g(t)&&H(t.length)&&!!st[_(t)]},dt=Object.prototype.hasOwnProperty;function _t(t,e){var r=w(t),n=!r&&ot(t),o=!r&&!n&&ct(t),i=!r&&!n&&!o&&bt(t),u=r||n||o||i,a=u?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],c=a.length;for(var s in t)!e&&!dt.call(t,s)||u&&("length"==s||o&&("offset"==s||"parent"==s)||i&&("buffer"==s||"byteLength"==s||"byteOffset"==s)||K(s,c))||a.push(s);return a}var gt=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),jt=gt,mt=Object.prototype.hasOwnProperty;function wt(t){if(!Z(t))return jt(t);var e=[];for(var r in Object(t))mt.call(t,r)&&"constructor"!=r&&e.push(r);return e}function Ot(t){return Q(t)?_t(t):wt(t)}var Pt=Object.prototype.hasOwnProperty;function At(t){return Q(t)?_t(t,!0):function(t){if(!x(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=Z(t),r=[];for(var n in t)("constructor"!=n||!e&&Pt.call(t,n))&&r.push(n);return r}(t)}var St=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,xt=/^\w*$/;function zt(t,e){if(w(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!m(t))||xt.test(t)||!St.test(t)||null!=e&&t in Object(e)}var qt=L(Object,"create"),kt=Object.prototype.hasOwnProperty,Et=Object.prototype.hasOwnProperty;function Ct(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Rt(t,e){for(var r=t.length;r--;)if(J(t[r][0],e))return r;return-1}Ct.prototype.clear=function(){this.__data__=qt?qt(null):{},this.size=0},Ct.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Ct.prototype.get=function(t){var e=this.__data__;if(qt){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return kt.call(e,t)?e[t]:void 0},Ct.prototype.has=function(t){var e=this.__data__;return qt?void 0!==e[t]:Et.call(e,t)},Ct.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=qt&&void 0===e?"__lodash_hash_undefined__":e,this};var Ut=Array.prototype.splice;function Mt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Mt.prototype.clear=function(){this.__data__=[],this.size=0},Mt.prototype.delete=function(t){var e=this.__data__,r=Rt(e,t);return!(r<0||(r==e.length-1?e.pop():Ut.call(e,r,1),--this.size,0))},Mt.prototype.get=function(t){var e=this.__data__,r=Rt(e,t);return r<0?void 0:e[r][1]},Mt.prototype.has=function(t){return Rt(this.__data__,t)>-1},Mt.prototype.set=function(t,e){var r=this.__data__,n=Rt(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var Tt=L(c,"Map");function Bt(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function It(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function $t(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],i=r.cache;if(i.has(o))return i.get(o);var u=t.apply(this,n);return r.cache=i.set(o,u)||i,u};return r.cache=new($t.Cache||It),r}It.prototype.clear=function(){this.size=0,this.__data__={hash:new Ct,map:new(Tt||Mt),string:new Ct}},It.prototype.delete=function(t){var e=Bt(this,t).delete(t);return this.size-=e?1:0,e},It.prototype.get=function(t){return Bt(this,t).get(t)},It.prototype.has=function(t){return Bt(this,t).has(t)},It.prototype.set=function(t,e){var r=Bt(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this},$t.Cache=It;var Ft,Lt,Dt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Nt=/\\(\\)?/g,Vt=(Ft=$t(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(Dt,function(t,r,n,o){e.push(n?o.replace(Nt,"$1"):r||t)}),e},function(t){return 500===Lt.size&&Lt.clear(),t}),Lt=Ft.cache,Ft);function Wt(t,e){return w(t)?t:zt(t,e)?[t]:Vt(function(t){return null==t?"":S(t)}(t))}var Xt=1/0;function Kt(t){if("string"==typeof t||m(t))return t;var e=t+"";return"0"==e&&1/t==-Xt?"-0":e}function Jt(t,e){for(var r=0,n=(e=Wt(e,t)).length;null!=t&&r<n;)t=t[Kt(e[r++])];return r&&r==n?t:void 0}function Gt(t){var e=this.__data__=new Mt(t);this.size=e.size}Gt.prototype.clear=function(){this.__data__=new Mt,this.size=0},Gt.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Gt.prototype.get=function(t){return this.__data__.get(t)},Gt.prototype.has=function(t){return this.__data__.has(t)},Gt.prototype.set=function(t,e){var r=this.__data__;if(r instanceof Mt){var n=r.__data__;if(!Tt||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new It(n)}return r.set(t,e),this.size=r.size,this};var Ht=Object.prototype.propertyIsEnumerable,Qt=Object.getOwnPropertySymbols,Yt=Qt?function(t){return null==t?[]:(t=Object(t),function(e,r){for(var n=-1,o=null==e?0:e.length,i=0,u=[];++n<o;){var a=e[n];Ht.call(t,a)&&(u[i++]=a)}return u}(Qt(t)))}:function(){return[]};function Zt(t){return function(t,e,r){var n=Ot(t);return w(t)?n:function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}(n,r(t))}(t,0,Yt)}var te=L(c,"DataView"),ee=L(c,"Promise"),re=L(c,"Set"),ne="[object Map]",oe="[object Promise]",ie="[object Set]",ue="[object WeakMap]",ae="[object DataView]",ce=I(te),se=I(Tt),fe=I(ee),le=I(re),pe=I(D),he=_;(te&&he(new te(new ArrayBuffer(1)))!=ae||Tt&&he(new Tt)!=ne||ee&&he(ee.resolve())!=oe||re&&he(new re)!=ie||D&&he(new D)!=ue)&&(he=function(t){var e=_(t),r="[object Object]"==e?t.constructor:void 0,n=r?I(r):"";if(n)switch(n){case ce:return ae;case se:return ne;case fe:return oe;case le:return ie;case pe:return ue}return e});var ve=he,ye=c.Uint8Array;function be(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new It;++e<r;)this.add(t[e])}function de(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1}be.prototype.add=be.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},be.prototype.has=function(t){return this.__data__.has(t)};var _e=1,ge=2;function je(t,e,r,n,o,i){var u=r&_e,a=t.length,c=e.length;if(a!=c&&!(u&&c>a))return!1;var s=i.get(t),f=i.get(e);if(s&&f)return s==e&&f==t;var l=-1,p=!0,h=r&ge?new be:void 0;for(i.set(t,e),i.set(e,t);++l<a;){var v=t[l],y=e[l];if(n)var b=u?n(y,v,l,e,t,i):n(v,y,l,t,e,i);if(void 0!==b){if(b)continue;p=!1;break}if(h){if(!de(e,function(t,e){if(!h.has(e)&&(v===t||o(v,t,r,n,i)))return h.push(e)})){p=!1;break}}else if(v!==y&&!o(v,y,r,n,i)){p=!1;break}}return i.delete(t),i.delete(e),p}function me(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r}function we(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r}var Oe=s?s.prototype:void 0,Pe=Oe?Oe.valueOf:void 0,Ae=Object.prototype.hasOwnProperty,Se="[object Arguments]",xe="[object Array]",ze="[object Object]",qe=Object.prototype.hasOwnProperty;function ke(t,e,r,n,o){return t===e||(null==t||null==e||!g(t)&&!g(e)?t!=t&&e!=e:function(t,e,r,n,o,i){var u=w(t),a=w(e),c=u?xe:ve(t),s=a?xe:ve(e),f=(c=c==Se?ze:c)==ze,l=(s=s==Se?ze:s)==ze,p=c==s;if(p&&ct(t)){if(!ct(e))return!1;u=!0,f=!1}if(p&&!f)return i||(i=new Gt),u||bt(t)?je(t,e,r,n,o,i):function(t,e,r,n,o,i,u){switch(r){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!i(new ye(t),new ye(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return J(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var a=me;case"[object Set]":if(a||(a=we),t.size!=e.size&&!(1&n))return!1;var c=u.get(t);if(c)return c==e;n|=2,u.set(t,e);var s=je(a(t),a(e),n,o,i,u);return u.delete(t),s;case"[object Symbol]":if(Pe)return Pe.call(t)==Pe.call(e)}return!1}(t,e,c,r,n,o,i);if(!(1&r)){var h=f&&qe.call(t,"__wrapped__"),v=l&&qe.call(e,"__wrapped__");if(h||v){var y=h?t.value():t,b=v?e.value():e;return i||(i=new Gt),o(y,b,r,n,i)}}return!!p&&(i||(i=new Gt),function(t,e,r,n,o,i){var u=1&r,a=Zt(t),c=a.length;if(c!=Zt(e).length&&!u)return!1;for(var s=c;s--;){var f=a[s];if(!(u?f in e:Ae.call(e,f)))return!1}var l=i.get(t),p=i.get(e);if(l&&p)return l==e&&p==t;var h=!0;i.set(t,e),i.set(e,t);for(var v=u;++s<c;){var y=t[f=a[s]],b=e[f];if(n)var d=u?n(b,y,f,e,t,i):n(y,b,f,t,e,i);if(!(void 0===d?y===b||o(y,b,r,n,i):d)){h=!1;break}v||(v="constructor"==f)}if(h&&!v){var _=t.constructor,g=e.constructor;_==g||!("constructor"in t)||!("constructor"in e)||"function"==typeof _&&_ instanceof _&&"function"==typeof g&&g instanceof g||(h=!1)}return i.delete(t),i.delete(e),h}(t,e,r,n,o,i))}(t,e,r,n,ke,o))}function Ee(t){return t==t&&!x(t)}function Ce(t,e){return function(r){return null!=r&&r[t]===e&&(void 0!==e||t in Object(r))}}function Re(t,e){return null!=t&&e in Object(t)}var Ue=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),u=i.length;u--;){var a=i[++n];if(!1===e(o[a],a,o))break}return t};function Me(t,e){return null==t?t:Ue(t,"function"==typeof(r=e)?r:z,At);var r}var Te=Object.prototype.hasOwnProperty;function Be(t){if(null==t)return!0;if(Q(t)&&(w(t)||"string"==typeof t||"function"==typeof t.splice||ct(t)||bt(t)||ot(t)))return!t.length;var e=ve(t);if("[object Map]"==e||"[object Set]"==e)return!t.size;if(Z(t))return!wt(t).length;for(var r in t)if(Te.call(t,r))return!1;return!0}var Ie=["headers"];function $e(t){if(!t)throw new Error("auth is required, configure it in client config or using the auth method");if("apiKey"in t)return"Bearer "+t.apiKey;if("jwt"in t)return"Bearer "+t.jwt;if("username"in t)return"Basic "+btoa(t.username+":"+t.password);throw new Error("auth must contain apiKey, jwt, or username/password")}function Fe(t){throw this.debug&&(console.error(t),console.groupEnd()),new Error("CiviCRM request failed")}var Le=function(t,e,r,o){var i=void 0===r?{}:r,u=i.headers,a=function(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)e.indexOf(r=i[n])>=0||(o[r]=t[r]);return o}(i,Ie);try{var c=this,s=crypto.randomUUID(),f=new URL(t,c.baseUrl);e&&(f.search=e.toString());var l=performance.now();return Promise.resolve(fetch(f,n({method:"POST",headers:n({"X-Civi-Auth":$e(o),"Content-Type":"application/x-www-form-urlencoded","X-Requested-With":"XMLHttpRequest","X-Request-ID":s},u)},a))).then(function(t){function e(){return Promise.resolve(t.json()).then(function(t){return t.is_error&&Fe.call(c,t),c.debug&&console.groupEnd(),t.values})}if(c.debug){var r=Math.round(performance.now()-l)+"ms";console.group("CiviCRM request "+s+" "+t.url+" "+t.status+" in "+r)}var n=function(){if(!t.ok)return Promise.resolve(t.text()).then(function(t){Fe.call(c,t)})}();return n&&n.then?n.then(e):e()})}catch(t){return Promise.reject(t)}};function De(t,e){return function(r,o,i){return t.bind(e)(r,n({},e.requestOptions,o),n({},e.auth,i))}}var Ne,Ve=function(t,e,r){var n=t[0],o=t[1],i=t[2],u=t[3];void 0===e&&(e={});try{var a="civicrm/ajax/api4/"+n+"/"+o,c=new URLSearchParams;return Be(i)||c.append("params",JSON.stringify(i)),void 0!==u&&c.append("index",String(u)),Promise.resolve(Le.bind(this)(a,c,e,r))}catch(t){return Promise.reject(t)}};!function(t){var e;(e=t.Action||(t.Action={})).get="get",e.create="create",e.update="update",e.save="save",e.delete="delete",e.getChecksum="getChecksum"}(Ne||(Ne={}));var We=/*#__PURE__*/function(){function t(t,e){this.entity=void 0,this.request=void 0,this.innerPromise=void 0,this._requestOptions={},this._auth=void 0,this.entity=t,this.request=e}var e=t.prototype;return e.requestOptions=function(t){return this._requestOptions=t,this},e.auth=function(t){return this._auth=t,this},e.then=function(t,e){return this.getInnerPromise().then(t,e)},e.getInnerPromise=function(){return this.innerPromise||(this.innerPromise=this.request(this.requestParams,this._requestOptions,this._auth)),this.innerPromise},r(t,[{key:"requestParams",get:function(){throw new Error}}]),t}(),Xe=/*#__PURE__*/function(t){function e(e,r){var n;return(n=t.call(this,e,r)||this).action=void 0,n.params=void 0,n.index=void 0,n.chains={},n}o(e,t);var i=e.prototype;return i.get=function(t){return this.action=Ne.Action.get,this.params=t,this},i.create=function(t){return this.action=Ne.Action.create,this.params=t,this},i.update=function(t){return this.action=Ne.Action.update,this.params=t,this},i.save=function(t){return this.action=Ne.Action.save,this.params=t,this},i.delete=function(t){return this.action=Ne.Action.delete,this.params=t,this},i.getChecksum=function(t){return this.action=Ne.Action.getChecksum,this.params=t,this},i.one=function(){return this.index=0,this},i.chain=function(t,e){return this.chains[t]=e,this},r(e,[{key:"requestParams",get:function(){var t=n({},this.params);return Be(this.chains)||(t.chain=function(t,e){var r,n,o,i={};return e="function"==typeof(r=e)?r:null==r?z:"object"==typeof r?w(r)?function(t,e){return zt(t)&&Ee(e)?Ce(Kt(t),e):function(r){var n=function(t,e,r){var n=null==t?void 0:Jt(t,e);return void 0===n?void 0:n}(r,t);return void 0===n&&n===e?function(t,e){return null!=t&&function(t,e,r){for(var n=-1,o=(e=Wt(e,t)).length,i=!1;++n<o;){var u=Kt(e[n]);if(!(i=null!=t&&r(t,u)))break;t=t[u]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&H(o)&&K(u,o)&&(w(t)||ot(t))}(t,e,Re)}(r,t):ke(e,n,3)}}(r[0],r[1]):(o=function(t){for(var e=Ot(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,Ee(o)]}return e}(n=r),1==o.length&&o[0][2]?Ce(o[0][0],o[0][1]):function(t){return t===n||function(t,e,r,n){var o=r.length,i=o;if(null==t)return!i;for(t=Object(t);o--;){var u=r[o];if(u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<i;){var a=(u=r[o])[0],c=t[a];if(u[2]){if(void 0===c&&!(a in t))return!1}else if(!ke(u[1],c,3,void 0,new Gt))return!1}return!0}(t,0,o)}):function(t){return zt(t)?(e=Kt(t),function(t){return null==t?void 0:t[e]}):function(t){return function(e){return Jt(e,t)}}(t);var e}(r),function(t,e){t&&Ue(t,e,Ot)}(t,function(t,r,n){!function(t,e,r){"__proto__"==e&&V?V(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}(i,r,e(t,r,n))}),i}(this.chains,function(t){return t.requestParams})),[this.entity,this.action,t,this.index]}}]),e}(We),Ke=function(t,e,r){var o=t[0],i=t[1],u=t[2],a=t[3];void 0===e&&(e={});try{var c=Be(a)?n({},u):n({},u,{options:a}),s=new URLSearchParams({entity:o,action:i,json:JSON.stringify(c)});return Promise.resolve(Le.bind(this)(Je,s,e,r))}catch(t){return Promise.reject(t)}},Je="civicrm/ajax/rest",Ge=/*#__PURE__*/function(t){function e(e,r,n){var o;return(o=t.call(this,e,r)||this).action=void 0,o.params=void 0,o.options={},Me(n,function(t,e){o[e]=function(e){return o.action=t,o.params=e,function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(o)}}),o}return o(e,t),e.prototype.option=function(t,e){return this.options[t]=e,this},r(e,[{key:"requestParams",get:function(){return[this.entity,this.action,this.params,this.options]}}]),e}(We);function He(t){var e;!function(t){if(!t.baseUrl)throw new Error("baseUrl is required")}(t);var r=function(t){var e=De(Ve,t),r={};return Me(t.entities,function(t,n){Reflect.defineProperty(r,n,{get:function(){return new Xe(t,e)}})}),r}(t);return r.request=function(e,r,o,i){return Le.bind(t)(e,r,n({},t.requestOptions,o),n({},t.auth,i))},null!=(e=t.api3)&&e.enabled&&(r.api3=function(t){var e=De(Ke,t),r={};return Me(t.api3.entities,function(t,n){Reflect.defineProperty(r,n,{get:function(){return new Ge(t.name,e,t.actions)}})}),r}(t)),r}export{He as createClient};
//# sourceMappingURL=index.module.js.map

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("lodash-es"),require("picocolors")):"function"==typeof define&&define.amd?define(["exports","lodash-es","picocolors"],e):e((t||self).civicrmApi={},t.lodashEs,t.picocolors)}(this,function(t,e,r){function n(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:String(e)}function i(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,n(i.key),i)}}function o(t,e,r){return e&&i(t.prototype,e),r&&i(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function s(){return s=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},s.apply(this,arguments)}function a(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,u(t,e)}function u(t,e){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},u(t,e)}var c=["headers"],h=function(t,e,n){var i=void 0===n?{}:n,o=i.headers,a=function(t,e){if(null==t)return{};var r,n,i={},o=Object.keys(t);for(n=0;n<o.length;n++)e.indexOf(r=o[n])>=0||(i[r]=t[r]);return i}(i,c);try{var u=this,h=crypto.randomUUID(),p=new URL(t,u.baseUrl);e&&(p.search=e.toString());var d=performance.now();return Promise.resolve(fetch(p,s({method:"POST",headers:s({"X-Civi-Auth":"Bearer "+u.apiKey,"Content-Type":"application/x-www-form-urlencoded","X-Requested-With":"XMLHttpRequest","X-Request-ID":h},o)},a))).then(function(t){function e(){return Promise.resolve(t.json()).then(function(t){return t.is_error&&f.call(u,t),u.debug&&console.groupEnd(),t.values})}if(u.debug){var n=Math.round(performance.now()-d)+"ms";console.group(r.bold("CiviCRM request")+" "+h+" "+r.gray(t.url)+" "+t.status+" in "+r.yellow(n))}var i=function(){if(!t.ok)return Promise.resolve(t.text()).then(function(t){f.call(u,t)})}();return i&&i.then?i.then(e):e()})}catch(t){return Promise.reject(t)}};function f(t){throw this.debug&&(console.error(t),console.groupEnd()),new Error("CiviCRM request failed")}var p,d=function(t,r){var n=t[0],i=t[1],o=t[2],s=t[3];void 0===r&&(r={});try{var a="civicrm/ajax/api4/"+n+"/"+i,u=new URLSearchParams;return e.isEmpty(o)||u.append("params",JSON.stringify(o)),void 0!==s&&u.append("index",String(s)),Promise.resolve(h.bind(this)(a,u,r))}catch(t){return Promise.reject(t)}};!function(t){var e;(e=t.Action||(t.Action={})).get="get",e.create="create",e.update="update",e.save="save",e.delete="delete",e.getChecksum="getChecksum"}(p||(p={}));var l=/*#__PURE__*/function(){function t(t,e){this.entity=void 0,this.request=void 0,this.innerPromise=void 0,this.requestOptions={},this.entity=t,this.request=e}var e=t.prototype;return e.options=function(t){return this.requestOptions=t,this},e.then=function(t,e){return this.getInnerPromise().then(t,e)},e.getInnerPromise=function(){return this.innerPromise||(this.innerPromise=this.request(this.requestParams,this.requestOptions)),this.innerPromise},o(t,[{key:"requestParams",get:function(){throw new Error}}]),t}(),v=/*#__PURE__*/function(t){function r(e,r){var n;return(n=t.call(this,e,r)||this).action=void 0,n.params=void 0,n.index=void 0,n.chains={},n}a(r,t);var n=r.prototype;return n.get=function(t){return this.action=p.Action.get,this.params=t,this},n.create=function(t){return this.action=p.Action.create,this.params=t,this},n.update=function(t){return this.action=p.Action.update,this.params=t,this},n.save=function(t){return this.action=p.Action.save,this.params=t,this},n.delete=function(t){return this.action=p.Action.delete,this.params=t,this},n.getChecksum=function(t){return this.action=p.Action.getChecksum,this.params=t,this},n.one=function(){return this.index=0,this},n.chain=function(t,e){return this.chains[t]=e,this},o(r,[{key:"requestParams",get:function(){var t=s({},this.params);return e.isEmpty(this.chains)||(t.chain=e.mapValues(this.chains,function(t){return t.requestParams})),[this.entity,this.action,t,this.index]}}]),r}(l),m=function(t,r){var n=t[0],i=t[1],o=t[2],a=t[3];void 0===r&&(r={});try{var u=e.isEmpty(a)?s({},o):s({},o,{options:a}),c=new URLSearchParams({entity:n,action:i,json:JSON.stringify(u)});return Promise.resolve(h.bind(this)(y,c,r))}catch(t){return Promise.reject(t)}},y="civicrm/ajax/rest",b=/*#__PURE__*/function(t){function r(r,n,i){var o;return(o=t.call(this,r,n)||this).action=void 0,o.params=void 0,o.opts={},e.forIn(i,function(t,e){o[e]=function(e){return o.action=t,o.params=e,function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(o)}}),o}return a(r,t),r.prototype.addOption=function(t,e){return this.opts[t]=e,this},o(r,[{key:"requestParams",get:function(){return[this.entity,this.action,this.params,this.opts]}}]),r}(l);t.createClient=function(t){var r;if(!t.baseUrl)throw new Error("baseUrl is required");if(!t.apiKey)throw new Error("apiKey is required");var n=function(t){var r={};return e.forIn(t.entities,function(e,n){Reflect.defineProperty(r,n,{get:function(){return new v(e,function(e,r){return d.bind(t)(e,s({},t.requestOptions,r))})}})}),r}(t);return null!=(r=t.api3)&&r.enabled&&(n.api3=function(t){var r={};return e.forIn(t.api3.entities,function(e,n){var i=e.name,o=e.actions;Reflect.defineProperty(r,n,{get:function(){return new b(i,function(e,r){return m.bind(t)(e,s({},t.requestOptions,r))},o)}})}),r}(t)),n}});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).civicrmApi={})}(this,function(t){function e(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:String(e)}function r(t,r){for(var n=0;n<r.length;n++){var o=r[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,e(o.key),o)}}function n(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(){return o=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},o.apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,u(t,e)}function u(t,e){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},u(t,e)}var a="object"==typeof global&&global&&global.Object===Object&&global,c="object"==typeof self&&self&&self.Object===Object&&self,s=a||c||Function("return this")(),f=s.Symbol,l=Object.prototype,h=l.hasOwnProperty,p=l.toString,v=f?f.toStringTag:void 0,y=Object.prototype.toString,b="[object Null]",d="[object Undefined]",_=f?f.toStringTag:void 0;function g(t){return null==t?void 0===t?d:b:_&&_ in Object(t)?function(t){var e=h.call(t,v),r=t[v];try{t[v]=void 0;var n=!0}catch(t){}var o=p.call(t);return n&&(e?t[v]=r:delete t[v]),o}(t):function(t){return y.call(t)}(t)}function j(t){return null!=t&&"object"==typeof t}var m="[object Symbol]";function w(t){return"symbol"==typeof t||j(t)&&g(t)==m}var O=Array.isArray,P=1/0,A=f?f.prototype:void 0,S=A?A.toString:void 0;function z(t){if("string"==typeof t)return t;if(O(t))return function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}(t,z)+"";if(w(t))return S?S.call(t):"";var e=t+"";return"0"==e&&1/t==-P?"-0":e}function q(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function k(t){return t}var E="[object AsyncFunction]",x="[object Function]",C="[object GeneratorFunction]",R="[object Proxy]";function T(t){if(!q(t))return!1;var e=g(t);return e==x||e==C||e==E||e==R}var U,M=s["__core-js_shared__"],B=(U=/[^.]+$/.exec(M&&M.keys&&M.keys.IE_PROTO||""))?"Symbol(src)_1."+U:"",I=Function.prototype.toString;function $(t){if(null!=t){try{return I.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var F=/^\[object .+?Constructor\]$/,L=RegExp("^"+Function.prototype.toString.call(Object.prototype.hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function D(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return function(t){return!(!q(t)||(e=t,B&&B in e))&&(T(t)?L:F).test($(t));var e}(r)?r:void 0}var N=D(s,"WeakMap"),V=function(){try{var t=D(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),W=V,X=9007199254740991,K=/^(?:0|[1-9]\d*)$/;function J(t,e){var r=typeof t;return!!(e=null==e?X:e)&&("number"==r||"symbol"!=r&&K.test(t))&&t>-1&&t%1==0&&t<e}function G(t,e){return t===e||t!=t&&e!=e}var H=9007199254740991;function Q(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=H}function Y(t){return null!=t&&Q(t.length)&&!T(t)}var Z=Object.prototype;function tt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Z)}function et(t){return j(t)&&"[object Arguments]"==g(t)}var rt=Object.prototype,nt=rt.hasOwnProperty,ot=rt.propertyIsEnumerable,it=et(function(){return arguments}())?et:function(t){return j(t)&&nt.call(t,"callee")&&!ot.call(t,"callee")},ut=it,at="object"==typeof t&&t&&!t.nodeType&&t,ct=at&&"object"==typeof module&&module&&!module.nodeType&&module,st=ct&&ct.exports===at?s.Buffer:void 0,ft=(st?st.isBuffer:void 0)||function(){return!1},lt={};lt["[object Float32Array]"]=lt["[object Float64Array]"]=lt["[object Int8Array]"]=lt["[object Int16Array]"]=lt["[object Int32Array]"]=lt["[object Uint8Array]"]=lt["[object Uint8ClampedArray]"]=lt["[object Uint16Array]"]=lt["[object Uint32Array]"]=!0,lt["[object Arguments]"]=lt["[object Array]"]=lt["[object ArrayBuffer]"]=lt["[object Boolean]"]=lt["[object DataView]"]=lt["[object Date]"]=lt["[object Error]"]=lt["[object Function]"]=lt["[object Map]"]=lt["[object Number]"]=lt["[object Object]"]=lt["[object RegExp]"]=lt["[object Set]"]=lt["[object String]"]=lt["[object WeakMap]"]=!1;var ht,pt="object"==typeof t&&t&&!t.nodeType&&t,vt=pt&&"object"==typeof module&&module&&!module.nodeType&&module,yt=vt&&vt.exports===pt&&a.process,bt=function(){try{return vt&&vt.require&&vt.require("util").types||yt&&yt.binding&&yt.binding("util")}catch(t){}}(),dt=bt&&bt.isTypedArray,_t=dt?(ht=dt,function(t){return ht(t)}):function(t){return j(t)&&Q(t.length)&&!!lt[g(t)]},gt=Object.prototype.hasOwnProperty;function jt(t,e){var r=O(t),n=!r&&ut(t),o=!r&&!n&&ft(t),i=!r&&!n&&!o&&_t(t),u=r||n||o||i,a=u?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],c=a.length;for(var s in t)!e&&!gt.call(t,s)||u&&("length"==s||o&&("offset"==s||"parent"==s)||i&&("buffer"==s||"byteLength"==s||"byteOffset"==s)||J(s,c))||a.push(s);return a}var mt=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),wt=mt,Ot=Object.prototype.hasOwnProperty;function Pt(t){if(!tt(t))return wt(t);var e=[];for(var r in Object(t))Ot.call(t,r)&&"constructor"!=r&&e.push(r);return e}function At(t){return Y(t)?jt(t):Pt(t)}var St=Object.prototype.hasOwnProperty;function zt(t){return Y(t)?jt(t,!0):function(t){if(!q(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=tt(t),r=[];for(var n in t)("constructor"!=n||!e&&St.call(t,n))&&r.push(n);return r}(t)}var qt=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,kt=/^\w*$/;function Et(t,e){if(O(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!w(t))||kt.test(t)||!qt.test(t)||null!=e&&t in Object(e)}var xt=D(Object,"create"),Ct=Object.prototype.hasOwnProperty,Rt=Object.prototype.hasOwnProperty;function Tt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Ut(t,e){for(var r=t.length;r--;)if(G(t[r][0],e))return r;return-1}Tt.prototype.clear=function(){this.__data__=xt?xt(null):{},this.size=0},Tt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Tt.prototype.get=function(t){var e=this.__data__;if(xt){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Ct.call(e,t)?e[t]:void 0},Tt.prototype.has=function(t){var e=this.__data__;return xt?void 0!==e[t]:Rt.call(e,t)},Tt.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=xt&&void 0===e?"__lodash_hash_undefined__":e,this};var Mt=Array.prototype.splice;function Bt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Bt.prototype.clear=function(){this.__data__=[],this.size=0},Bt.prototype.delete=function(t){var e=this.__data__,r=Ut(e,t);return!(r<0||(r==e.length-1?e.pop():Mt.call(e,r,1),--this.size,0))},Bt.prototype.get=function(t){var e=this.__data__,r=Ut(e,t);return r<0?void 0:e[r][1]},Bt.prototype.has=function(t){return Ut(this.__data__,t)>-1},Bt.prototype.set=function(t,e){var r=this.__data__,n=Ut(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var It=D(s,"Map");function $t(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function Ft(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Lt(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],i=r.cache;if(i.has(o))return i.get(o);var u=t.apply(this,n);return r.cache=i.set(o,u)||i,u};return r.cache=new(Lt.Cache||Ft),r}Ft.prototype.clear=function(){this.size=0,this.__data__={hash:new Tt,map:new(It||Bt),string:new Tt}},Ft.prototype.delete=function(t){var e=$t(this,t).delete(t);return this.size-=e?1:0,e},Ft.prototype.get=function(t){return $t(this,t).get(t)},Ft.prototype.has=function(t){return $t(this,t).has(t)},Ft.prototype.set=function(t,e){var r=$t(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this},Lt.Cache=Ft;var Dt,Nt,Vt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Wt=/\\(\\)?/g,Xt=(Dt=Lt(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(Vt,function(t,r,n,o){e.push(n?o.replace(Wt,"$1"):r||t)}),e},function(t){return 500===Nt.size&&Nt.clear(),t}),Nt=Dt.cache,Dt);function Kt(t,e){return O(t)?t:Et(t,e)?[t]:Xt(function(t){return null==t?"":z(t)}(t))}var Jt=1/0;function Gt(t){if("string"==typeof t||w(t))return t;var e=t+"";return"0"==e&&1/t==-Jt?"-0":e}function Ht(t,e){for(var r=0,n=(e=Kt(e,t)).length;null!=t&&r<n;)t=t[Gt(e[r++])];return r&&r==n?t:void 0}function Qt(t){var e=this.__data__=new Bt(t);this.size=e.size}Qt.prototype.clear=function(){this.__data__=new Bt,this.size=0},Qt.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Qt.prototype.get=function(t){return this.__data__.get(t)},Qt.prototype.has=function(t){return this.__data__.has(t)},Qt.prototype.set=function(t,e){var r=this.__data__;if(r instanceof Bt){var n=r.__data__;if(!It||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Ft(n)}return r.set(t,e),this.size=r.size,this};var Yt=Object.prototype.propertyIsEnumerable,Zt=Object.getOwnPropertySymbols,te=Zt?function(t){return null==t?[]:(t=Object(t),function(e,r){for(var n=-1,o=null==e?0:e.length,i=0,u=[];++n<o;){var a=e[n];Yt.call(t,a)&&(u[i++]=a)}return u}(Zt(t)))}:function(){return[]};function ee(t){return function(t,e,r){var n=e(t);return O(t)?n:function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}(n,r(t))}(t,At,te)}var re=D(s,"DataView"),ne=D(s,"Promise"),oe=D(s,"Set"),ie="[object Map]",ue="[object Promise]",ae="[object Set]",ce="[object WeakMap]",se="[object DataView]",fe=$(re),le=$(It),he=$(ne),pe=$(oe),ve=$(N),ye=g;(re&&ye(new re(new ArrayBuffer(1)))!=se||It&&ye(new It)!=ie||ne&&ye(ne.resolve())!=ue||oe&&ye(new oe)!=ae||N&&ye(new N)!=ce)&&(ye=function(t){var e=g(t),r="[object Object]"==e?t.constructor:void 0,n=r?$(r):"";if(n)switch(n){case fe:return se;case le:return ie;case he:return ue;case pe:return ae;case ve:return ce}return e});var be=ye,de=s.Uint8Array;function _e(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new Ft;++e<r;)this.add(t[e])}function ge(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1}_e.prototype.add=_e.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},_e.prototype.has=function(t){return this.__data__.has(t)};var je=1,me=2;function we(t,e,r,n,o,i){var u=r&je,a=t.length,c=e.length;if(a!=c&&!(u&&c>a))return!1;var s=i.get(t),f=i.get(e);if(s&&f)return s==e&&f==t;var l=-1,h=!0,p=r&me?new _e:void 0;for(i.set(t,e),i.set(e,t);++l<a;){var v=t[l],y=e[l];if(n)var b=u?n(y,v,l,e,t,i):n(v,y,l,t,e,i);if(void 0!==b){if(b)continue;h=!1;break}if(p){if(!ge(e,function(t,e){if(!p.has(e)&&(v===t||o(v,t,r,n,i)))return p.push(e)})){h=!1;break}}else if(v!==y&&!o(v,y,r,n,i)){h=!1;break}}return i.delete(t),i.delete(e),h}function Oe(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r}function Pe(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r}var Ae=f?f.prototype:void 0,Se=Ae?Ae.valueOf:void 0,ze=Object.prototype.hasOwnProperty,qe="[object Arguments]",ke="[object Array]",Ee="[object Object]",xe=Object.prototype.hasOwnProperty;function Ce(t,e,r,n,o){return t===e||(null==t||null==e||!j(t)&&!j(e)?t!=t&&e!=e:function(t,e,r,n,o,i){var u=O(t),a=O(e),c=u?ke:be(t),s=a?ke:be(e),f=(c=c==qe?Ee:c)==Ee,l=(s=s==qe?Ee:s)==Ee,h=c==s;if(h&&ft(t)){if(!ft(e))return!1;u=!0,f=!1}if(h&&!f)return i||(i=new Qt),u||_t(t)?we(t,e,r,n,o,i):function(t,e,r,n,o,i,u){switch(r){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!i(new de(t),new de(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return G(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var a=Oe;case"[object Set]":if(a||(a=Pe),t.size!=e.size&&!(1&n))return!1;var c=u.get(t);if(c)return c==e;n|=2,u.set(t,e);var s=we(a(t),a(e),n,o,i,u);return u.delete(t),s;case"[object Symbol]":if(Se)return Se.call(t)==Se.call(e)}return!1}(t,e,c,r,n,o,i);if(!(1&r)){var p=f&&xe.call(t,"__wrapped__"),v=l&&xe.call(e,"__wrapped__");if(p||v){var y=p?t.value():t,b=v?e.value():e;return i||(i=new Qt),o(y,b,r,n,i)}}return!!h&&(i||(i=new Qt),function(t,e,r,n,o,i){var u=1&r,a=ee(t),c=a.length;if(c!=ee(e).length&&!u)return!1;for(var s=c;s--;){var f=a[s];if(!(u?f in e:ze.call(e,f)))return!1}var l=i.get(t),h=i.get(e);if(l&&h)return l==e&&h==t;var p=!0;i.set(t,e),i.set(e,t);for(var v=u;++s<c;){var y=t[f=a[s]],b=e[f];if(n)var d=u?n(b,y,f,e,t,i):n(y,b,f,t,e,i);if(!(void 0===d?y===b||o(y,b,r,n,i):d)){p=!1;break}v||(v="constructor"==f)}if(p&&!v){var _=t.constructor,g=e.constructor;_==g||!("constructor"in t)||!("constructor"in e)||"function"==typeof _&&_ instanceof _&&"function"==typeof g&&g instanceof g||(p=!1)}return i.delete(t),i.delete(e),p}(t,e,r,n,o,i))}(t,e,r,n,Ce,o))}function Re(t){return t==t&&!q(t)}function Te(t,e){return function(r){return null!=r&&r[t]===e&&(void 0!==e||t in Object(r))}}function Ue(t,e){return null!=t&&e in Object(t)}var Me=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),u=i.length;u--;){var a=i[++n];if(!1===e(o[a],a,o))break}return t};function Be(t,e){return null==t?t:Me(t,"function"==typeof(r=e)?r:k,zt);var r}var Ie=Object.prototype.hasOwnProperty;function $e(t){if(null==t)return!0;if(Y(t)&&(O(t)||"string"==typeof t||"function"==typeof t.splice||ft(t)||_t(t)||ut(t)))return!t.length;var e=be(t);if("[object Map]"==e||"[object Set]"==e)return!t.size;if(tt(t))return!Pt(t).length;for(var r in t)if(Ie.call(t,r))return!1;return!0}var Fe=["headers"];function Le(t){if(!t)throw new Error("auth is required, configure it in client config or using the auth method");if("apiKey"in t)return"Bearer "+t.apiKey;if("jwt"in t)return"Bearer "+t.jwt;if("username"in t)return"Basic "+btoa(t.username+":"+t.password);throw new Error("auth must contain apiKey, jwt, or username/password")}function De(t){throw this.debug&&(console.error(t),console.groupEnd()),new Error("CiviCRM request failed")}var Ne=function(t,e,r,n){var i=void 0===r?{}:r,u=i.headers,a=function(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)e.indexOf(r=i[n])>=0||(o[r]=t[r]);return o}(i,Fe);try{var c=this,s=crypto.randomUUID(),f=new URL(t,c.baseUrl);e&&(f.search=e.toString());var l=performance.now();return Promise.resolve(fetch(f,o({method:"POST",headers:o({"X-Civi-Auth":Le(n),"Content-Type":"application/x-www-form-urlencoded","X-Requested-With":"XMLHttpRequest","X-Request-ID":s},u)},a))).then(function(t){function e(){return Promise.resolve(t.json()).then(function(t){return t.is_error&&De.call(c,t),c.debug&&console.groupEnd(),t.values})}if(c.debug){var r=Math.round(performance.now()-l)+"ms";console.group("CiviCRM request "+s+" "+t.url+" "+t.status+" in "+r)}var n=function(){if(!t.ok)return Promise.resolve(t.text()).then(function(t){De.call(c,t)})}();return n&&n.then?n.then(e):e()})}catch(t){return Promise.reject(t)}};function Ve(t,e){return function(r,n,i){return t.bind(e)(r,o({},e.requestOptions,n),o({},e.auth,i))}}var We,Xe=function(t,e,r){var n=t[0],o=t[1],i=t[2],u=t[3];void 0===e&&(e={});try{var a="civicrm/ajax/api4/"+n+"/"+o,c=new URLSearchParams;return $e(i)||c.append("params",JSON.stringify(i)),void 0!==u&&c.append("index",String(u)),Promise.resolve(Ne.bind(this)(a,c,e,r))}catch(t){return Promise.reject(t)}};!function(t){var e;(e=t.Action||(t.Action={})).get="get",e.create="create",e.update="update",e.save="save",e.delete="delete",e.getChecksum="getChecksum"}(We||(We={}));var Ke=/*#__PURE__*/function(){function t(t,e){this.entity=void 0,this.request=void 0,this.innerPromise=void 0,this._requestOptions={},this._auth=void 0,this.entity=t,this.request=e}var e=t.prototype;return e.requestOptions=function(t){return this._requestOptions=t,this},e.auth=function(t){return this._auth=t,this},e.then=function(t,e){return this.getInnerPromise().then(t,e)},e.getInnerPromise=function(){return this.innerPromise||(this.innerPromise=this.request(this.requestParams,this._requestOptions,this._auth)),this.innerPromise},n(t,[{key:"requestParams",get:function(){throw new Error}}]),t}(),Je=/*#__PURE__*/function(t){function e(e,r){var n;return(n=t.call(this,e,r)||this).action=void 0,n.params=void 0,n.index=void 0,n.chains={},n}i(e,t);var r=e.prototype;return r.get=function(t){return this.action=We.Action.get,this.params=t,this},r.create=function(t){return this.action=We.Action.create,this.params=t,this},r.update=function(t){return this.action=We.Action.update,this.params=t,this},r.save=function(t){return this.action=We.Action.save,this.params=t,this},r.delete=function(t){return this.action=We.Action.delete,this.params=t,this},r.getChecksum=function(t){return this.action=We.Action.getChecksum,this.params=t,this},r.one=function(){return this.index=0,this},r.chain=function(t,e){return this.chains[t]=e,this},n(e,[{key:"requestParams",get:function(){var t=o({},this.params);return $e(this.chains)||(t.chain=function(t,e){var r,n,o,i={};return e="function"==typeof(r=e)?r:null==r?k:"object"==typeof r?O(r)?function(t,e){return Et(t)&&Re(e)?Te(Gt(t),e):function(r){var n=function(t,e,r){var n=null==t?void 0:Ht(t,e);return void 0===n?void 0:n}(r,t);return void 0===n&&n===e?function(t,e){return null!=t&&function(t,e,r){for(var n=-1,o=(e=Kt(e,t)).length,i=!1;++n<o;){var u=Gt(e[n]);if(!(i=null!=t&&r(t,u)))break;t=t[u]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&Q(o)&&J(u,o)&&(O(t)||ut(t))}(t,e,Ue)}(r,t):Ce(e,n,3)}}(r[0],r[1]):(o=function(t){for(var e=At(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,Re(o)]}return e}(n=r),1==o.length&&o[0][2]?Te(o[0][0],o[0][1]):function(t){return t===n||function(t,e,r,n){var o=r.length,i=o;if(null==t)return!i;for(t=Object(t);o--;){var u=r[o];if(u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<i;){var a=(u=r[o])[0],c=t[a];if(u[2]){if(void 0===c&&!(a in t))return!1}else if(!Ce(u[1],c,3,void 0,new Qt))return!1}return!0}(t,0,o)}):function(t){return Et(t)?(e=Gt(t),function(t){return null==t?void 0:t[e]}):function(t){return function(e){return Ht(e,t)}}(t);var e}(r),function(t,e){t&&Me(t,e,At)}(t,function(t,r,n){!function(t,e,r){"__proto__"==e&&W?W(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}(i,r,e(t,r,n))}),i}(this.chains,function(t){return t.requestParams})),[this.entity,this.action,t,this.index]}}]),e}(Ke),Ge=function(t,e,r){var n=t[0],i=t[1],u=t[2],a=t[3];void 0===e&&(e={});try{var c=$e(a)?o({},u):o({},u,{options:a}),s=new URLSearchParams({entity:n,action:i,json:JSON.stringify(c)});return Promise.resolve(Ne.bind(this)(He,s,e,r))}catch(t){return Promise.reject(t)}},He="civicrm/ajax/rest",Qe=/*#__PURE__*/function(t){function e(e,r,n){var o;return(o=t.call(this,e,r)||this).action=void 0,o.params=void 0,o.options={},Be(n,function(t,e){o[e]=function(e){return o.action=t,o.params=e,function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(o)}}),o}return i(e,t),e.prototype.option=function(t,e){return this.options[t]=e,this},n(e,[{key:"requestParams",get:function(){return[this.entity,this.action,this.params,this.options]}}]),e}(Ke);t.createClient=function(t){var e;!function(t){if(!t.baseUrl)throw new Error("baseUrl is required")}(t);var r=function(t){var e=Ve(Xe,t),r={};return Be(t.entities,function(t,n){Reflect.defineProperty(r,n,{get:function(){return new Je(t,e)}})}),r}(t);return r.request=function(e,r,n,i){return Ne.bind(t)(e,r,o({},t.requestOptions,n),o({},t.auth,i))},null!=(e=t.api3)&&e.enabled&&(r.api3=function(t){var e=Ve(Ge,t),r={};return Be(t.api3.entities,function(t,n){Reflect.defineProperty(r,n,{get:function(){return new Qe(t.name,e,t.actions)}})}),r}(t)),r}});
//# sourceMappingURL=index.umd.js.map

@@ -1,2 +0,2 @@

import { BaseRequestFn } from "../types";
import { Authentication, BaseRequestFn, RequestOptions } from "../types";
export declare class RequestBuilder<RequestParams = any, T = any> implements PromiseLike<T> {

@@ -6,5 +6,7 @@ protected readonly entity: string;

protected innerPromise: Promise<T>;
protected requestOptions: RequestInit;
protected _requestOptions: RequestOptions;
protected _auth: Authentication;
constructor(entity: string, request: BaseRequestFn<RequestParams, T>);
options(requestOptions: RequestInit): this;
requestOptions(requestOptions: RequestOptions): this;
auth(auth: Authentication): this;
get requestParams(): RequestParams;

@@ -11,0 +13,0 @@ then<TResult1 = T, TResult2 = never>(onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onRejected?: ((reason: Error) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseLike<TResult1 | TResult2>;

@@ -1,5 +0,3 @@

export declare function request(this: {
baseUrl: string;
apiKey: string;
debug?: boolean;
}, path: string, params?: URLSearchParams, { headers, ...requestOptions }?: RequestInit): Promise<any>;
import { Authentication, BaseRequestFn, ClientConfig, RequestOptions } from "../types";
export declare function bindRequest(requestFn: BaseRequestFn<any, any>, config: ClientConfig<any, any>): BaseRequestFn<any, any>;
export declare function request(this: ClientConfig<any, any>, path: string, params?: URLSearchParams, { headers, ...requestOptions }?: RequestOptions, auth?: Authentication): Promise<any>;
{
"name": "civicrm-api",
"type": "module",
"version": "0.2.1",
"version": "0.3.0",
"source": "src/index.ts",

@@ -19,3 +19,5 @@ "main": "./dist/index.cjs",

"dev": "microbundle watch",
"test": "vitest"
"test": "vitest",
"test:browser": "vitest --config vitest.browser.config.js",
"coverage": "vitest run --coverage"
},

@@ -26,11 +28,16 @@ "license": "MIT",

"@types/lodash-es": "^4.17.12",
"@vitest/browser": "^1.4.0",
"@vitest/coverage-v8": "^1.4.0",
"microbundle": "^0.15.1",
"msw": "^2.2.2",
"prettier": "^3.2.5",
"vitest": "^1.3.1"
"vitest": "^1.3.1",
"webdriverio": "^8.35.1",
"lodash-es": "^4.17.21"
},
"dependencies": {
"lodash-es": "^4.17.21",
"picocolors": "^1.0.0"
"msw": {
"workerDirectory": [
"test/browser/public"
]
}
}

@@ -5,4 +5,2 @@ # CiviCRM API

Currently only tested in Node.js, browser support is work in progress.
## Installation

@@ -21,7 +19,7 @@

baseUrl: "https://example.com/civicrm",
apiKey: "your-api-key",
auth: { apiKey: "<your-api-key>" },
entities: { contact: "Contact" },
});
const contactRequest = client.contact.get({ where: { id: 1 } }).one();
const contactRequest = client.contact.get({ where: [["id", "=", "1"]] }).one();
```

@@ -61,7 +59,21 @@

#### options.apiKey
#### options.auth
The [API key](https://docs.civicrm.org/sysadmin/en/latest/setup/api-keys/) to
use for authentication.
The API key, JWT, or username and password that will be used to authenticate requests. Refer to the [CiviCRM authentication](https://docs.civicrm.org/dev/en/latest/framework/authx/#authentication) documentation.
```ts
const client = createClient({
// ...
auth: { apiKey: "api-key" },
//=> X-Civi-Auth: Bearer api-key
auth: { jwt: "jwt" },
//=> X-Civi-Auth: Bearer jwt
auth: { username: "user", password: "pass" },
//=> X-Civi-Auth: Basic dXNlcjpwYXNz
});
```
#### options.entities

@@ -146,3 +158,3 @@

client.contact
.get({ where: { id: 1 } })
.get({ where: [["id", "=", "1"]] })
.one()

@@ -154,3 +166,3 @@ .then((contact) => {

// Using await
const contact = await client.contact.get({ where: { id: 1 } }).one();
const contact = await client.contact.get({ where: [["id", "=", "1"]] }).one();
```

@@ -192,3 +204,3 @@

const contact = await client.contact
.get({ where: { id: 1 } })
.get({ where: [["id", "=", "1"]] })
.chain(

@@ -225,3 +237,3 @@ "activity",

```ts
client.contact.get().options({
client.contact.get().requestOptions({
headers: {

@@ -259,3 +271,3 @@ "X-Custom-Header": "value",

#### `addOption(option: string, value: Api3.Value): Api3.RequestBuilder`
#### `option(option: string, value: Api3.Value): Api3.RequestBuilder`

@@ -265,3 +277,3 @@ Set [API options](https://docs.civicrm.org/dev/en/latest/api/v3/options/).

```ts
client.api3.contact.getList().addOption("limit", 10);
client.api3.contact.getList().option("limit", 10);
```

@@ -281,3 +293,3 @@

```ts
client.api3.contact.getList().options({
client.api3.contact.getList().requestOptions({
headers: {

@@ -292,3 +304,3 @@ "X-Custom-Header": "value",

- The [civicrm](https://www.npmjs.com/package/civicrm) package from [Tech to The People](https://github.com/TechToThePeople) offers a different approach to building requests and targets browsers and web workers as well as Node.js.
- The [civicrm](https://www.npmjs.com/package/civicrm) package from [Tech to The People](https://github.com/TechToThePeople) offers a different approach to building requests.

@@ -295,0 +307,0 @@ ## Development

@@ -7,2 +7,3 @@ import { forIn } from "lodash-es";

import { ClientConfig } from "../types";
import { bindRequest } from "../lib/request";

@@ -12,16 +13,9 @@ export function createApi3Client<E extends Api3.EntitiesConfig>(

) {
const boundRequest = bindRequest(request, config);
const client = {} as Api3.Client<E>;
forIn(config.api3!.entities, ({ name, actions }: any, entity: string) => {
Reflect.defineProperty(client, entity, {
get: () =>
new RequestBuilder(
name,
(requestParams, requestOptions) =>
request.bind(config)(requestParams, {
...config.requestOptions,
...requestOptions,
}),
actions,
),
forIn(config.api3!.entities, (entity: Api3.EntityConfig, key: string) => {
Reflect.defineProperty(client, key, {
get: () => new RequestBuilder(entity.name, boundRequest, entity.actions),
});

@@ -28,0 +22,0 @@ });

@@ -12,3 +12,3 @@ import { forIn } from "lodash-es";

private params?: Api3.Params;
private opts: Record<string, Api3.Value> = {};
private options: Record<string, Api3.Value> = {};

@@ -20,3 +20,3 @@ constructor(entity: string, request: Api3.RequestFn<Response>, actions: A) {

this[key] = (params?: Api3.Params) => {
this.action = action as any;
this.action = action;
this.params = params;

@@ -30,7 +30,7 @@

get requestParams(): Api3.RequestParams {
return [this.entity, this.action, this.params, this.opts];
return [this.entity, this.action, this.params, this.options];
}
addOption(option: string, value: Api3.Value) {
this.opts[option] = value;
option(option: string, value: Api3.Value) {
this.options[option] = value;

@@ -37,0 +37,0 @@ return this;

@@ -5,2 +5,3 @@ import { isEmpty } from "lodash-es";

import { request as baseRequest } from "../lib/request";
import { Authentication, RequestOptions } from "../types";

@@ -16,3 +17,4 @@ const path = "civicrm/ajax/rest";

[entity, action, params, options]: Api3.RequestParams,
requestOptions: RequestInit = {},
requestOptions: RequestOptions = {},
auth?: Authentication,
) {

@@ -27,3 +29,3 @@ const json = isEmpty(options) ? { ...params } : { ...params, options };

return baseRequest.bind(this)(path, searchParams, requestOptions);
return baseRequest.bind(this)(path, searchParams, requestOptions, auth);
}

@@ -5,9 +5,9 @@ import { RequestBuilder } from "./request-builder";

export namespace Api3 {
export type EntityConfig = {
name: string;
actions: Actions;
};
export type EntitiesConfig = {
[key: string]: {
name: string;
actions: {
[key: string]: string;
};
};
[key: string]: EntityConfig;
};

@@ -18,2 +18,3 @@

};
export type ActionMethods<A extends Actions> = Record<

@@ -20,0 +21,0 @@ keyof A,

@@ -7,2 +7,3 @@ import { forIn } from "lodash-es";

import { ClientConfig } from "../types";
import { bindRequest } from "../lib/request";

@@ -12,2 +13,4 @@ export function createApi4Client<E extends Api4.EntitiesConfig>(

) {
const boundRequest = bindRequest(request, config);
const client = {} as Api4.Client<E>;

@@ -17,9 +20,3 @@

Reflect.defineProperty(client, key, {
get: () =>
new RequestBuilder(entity, (requestParams, requestOptions) =>
request.bind(config)(requestParams, {
...config.requestOptions,
...requestOptions,
}),
),
get: () => new RequestBuilder(entity, boundRequest),
});

@@ -26,0 +23,0 @@ });

@@ -5,2 +5,3 @@ import { isEmpty } from "lodash-es";

import { request as baseRequest } from "../lib/request";
import { Authentication, RequestOptions } from "../types";

@@ -14,3 +15,4 @@ export async function request(

[entity, action, params, index]: Api4.RequestParams,
requestOptions: RequestInit = {},
requestOptions: RequestOptions = {},
auth?: Authentication,
) {

@@ -28,3 +30,3 @@ const path = `civicrm/ajax/api4/${entity}/${action}`;

return baseRequest.bind(this)(path, searchParams, requestOptions);
return baseRequest.bind(this)(path, searchParams, requestOptions, auth);
}

@@ -6,3 +6,8 @@ import { Client, ClientConfig } from "./types";

import { createApi3Client } from "./api3/client";
import { request } from "./lib/request";
function validateConfig(config: ClientConfig<any, any>): void {
if (!config.baseUrl) throw new Error("baseUrl is required");
}
export function createClient<

@@ -12,12 +17,14 @@ E extends Api4.EntitiesConfig,

>(config: ClientConfig<E, F>): Client<E, F> {
if (!config.baseUrl) {
throw new Error("baseUrl is required");
}
validateConfig(config);
if (!config.apiKey) {
throw new Error("apiKey is required");
}
const client = createApi4Client(config) as Client<E, F>;
client.request = (path, requestParams, requestOptions, auth) =>
request.bind(config)(
path,
requestParams,
{ ...config.requestOptions, ...requestOptions },
{ ...config.auth, ...auth },
);
if (config.api3?.enabled) {

@@ -24,0 +31,0 @@ client.api3 = createApi3Client(config);

@@ -1,2 +0,2 @@

import { BaseRequestFn } from "../types";
import { Authentication, BaseRequestFn, RequestOptions } from "../types";

@@ -9,3 +9,4 @@ export class RequestBuilder<RequestParams = any, T = any>

protected innerPromise: Promise<T>;
protected requestOptions: RequestInit = {};
protected _requestOptions: RequestOptions = {};
protected _auth: Authentication;

@@ -17,4 +18,4 @@ constructor(entity: string, request: BaseRequestFn<RequestParams, T>) {

options(requestOptions: RequestInit) {
this.requestOptions = requestOptions;
requestOptions(requestOptions: RequestOptions) {
this._requestOptions = requestOptions;

@@ -24,2 +25,8 @@ return this;

auth(auth: Authentication) {
this._auth = auth;
return this;
}
get requestParams(): RequestParams {

@@ -44,3 +51,7 @@ throw new Error();

if (!this.innerPromise) {
this.innerPromise = this.request(this.requestParams, this.requestOptions);
this.innerPromise = this.request(
this.requestParams,
this._requestOptions,
this._auth,
);
}

@@ -47,0 +58,0 @@

@@ -1,13 +0,58 @@

import { bold, gray, yellow } from "picocolors";
import {
Authentication,
BaseRequestFn,
ClientConfig,
RequestOptions,
} from "../types";
function authenticationHeader(auth?: Authentication): string {
if (!auth)
throw new Error(
"auth is required, configure it in client config or using the auth method",
);
if ("apiKey" in auth) {
return `Bearer ${auth.apiKey}`;
}
if ("jwt" in auth) {
return `Bearer ${auth.jwt}`;
}
if ("username" in auth) {
return `Basic ${btoa(`${auth.username}:${auth.password}`)}`;
}
throw new Error("auth must contain apiKey, jwt, or username/password");
}
function handleError(error: string) {
if (this.debug) {
console.error(error);
console.groupEnd();
}
// TODO: make this error more informative
throw new Error("CiviCRM request failed");
}
export function bindRequest(
requestFn: BaseRequestFn<any, any>,
config: ClientConfig<any, any>,
): BaseRequestFn<any, any> {
return (requestParams, requestOptions, auth) =>
requestFn.bind(config)(
requestParams,
{ ...config.requestOptions, ...requestOptions },
{ ...config.auth, ...auth },
);
}
export async function request(
this: {
baseUrl: string;
apiKey: string;
debug?: boolean;
},
this: ClientConfig<any, any>,
path: string,
params?: URLSearchParams,
{ headers, ...requestOptions }: RequestInit = {},
) {
{ headers, ...requestOptions }: RequestOptions = {},
auth?: Authentication,
): Promise<any> {
const requestId = crypto.randomUUID();

@@ -26,3 +71,3 @@

headers: {
"X-Civi-Auth": `Bearer ${this.apiKey}`,
"X-Civi-Auth": authenticationHeader(auth),
"Content-Type": "application/x-www-form-urlencoded",

@@ -40,3 +85,3 @@ "X-Requested-With": "XMLHttpRequest",

console.group(
`${bold("CiviCRM request")} ${requestId} ${gray(res.url)} ${res.status} in ${yellow(time)}`,
`CiviCRM request ${requestId} ${res.url} ${res.status} in ${time}`,
);

@@ -62,11 +107,1 @@ }

}
function handleError(error: any) {
if (this.debug) {
console.error(error);
console.groupEnd();
}
// TODO: make this error more informative
throw new Error("CiviCRM request failed");
}

@@ -9,4 +9,18 @@ import { Api4 } from "./api4/types";

api3: Api3.Client<F>;
} & {
request: (
path: string,
params?: URLSearchParams,
requestOptions?: RequestOptions,
auth?: Authentication,
) => Promise<any>;
};
export type Authentication =
| { apiKey: string }
| { jwt: string }
| { username: string; password: string };
export type RequestOptions = RequestInit;
export interface ClientConfig<

@@ -17,5 +31,5 @@ E extends Api4.EntitiesConfig,

baseUrl: string;
apiKey: string;
auth?: Authentication;
entities?: E;
requestOptions?: RequestInit;
requestOptions?: RequestOptions;
debug?: boolean;

@@ -30,3 +44,4 @@ api3?: {

params: RequestParams,
requestOptions: RequestInit,
requestOptions: RequestOptions,
auth?: Authentication,
) => Promise<Response>;

@@ -6,7 +6,7 @@ import { DeferredPromise } from "@open-draft/deferred-promise";

import { createClient } from "../src";
import { server } from "./mock-server";
import { server } from "./mock/server";
const config = {
baseUrl: "https://example.com",
apiKey: "mock-api-key",
auth: { apiKey: "mock-api-key" },
api3: {

@@ -78,3 +78,3 @@ enabled: true,

test("accepts request options", async () => {
await client.api3.contact.options({ cache: "no-cache" }).getList();
await client.api3.contact.requestOptions({ cache: "no-cache" }).getList();
const req = await request;

@@ -87,3 +87,3 @@

await client.api3.contact
.options({ headers: { "X-Correlation-Id": "mock-correlation-id" } })
.requestOptions({ headers: { "X-Correlation-Id": "mock-correlation-id" } })
.getList();

@@ -127,3 +127,3 @@ const req = await request;

test("accepts options", async () => {
await client.api3.contact.getList().addOption("limit", 10);
await client.api3.contact.getList().option("limit", 10);
const req = await request;

@@ -140,3 +140,3 @@

.getList({ input: "mock-input" })
.addOption("limit", 10);
.option("limit", 10);
const req = await request;

@@ -173,3 +173,3 @@

expect(consoleSpy.group).toHaveBeenCalledWith(
`\u001b[1mCiviCRM request\u001b[22m ${requestId} \u001b[90mhttps://example.com/civicrm/ajax/rest?entity=Contact&action=getlist&json=%7B%7D\u001b[39m 200 in \u001b[33m0ms\u001b[39m`,
`CiviCRM request ${requestId} https://example.com/civicrm/ajax/rest?entity=Contact&action=getlist&json=%7B%7D 200 in 0ms`,
);

@@ -176,0 +176,0 @@ expect(consoleSpy.groupEnd).toHaveBeenCalled();

@@ -6,7 +6,7 @@ import { DeferredPromise } from "@open-draft/deferred-promise";

import { createClient } from "../src";
import { server } from "./mock-server";
import { server } from "./mock/server";
const config = {
baseUrl: "https://example.com",
apiKey: "mock-api-key",
auth: { apiKey: "mock-api-key" },
entities: {

@@ -52,3 +52,3 @@ contact: "Contact",

test("accepts request options", async () => {
await client.contact.options({ cache: "no-cache" }).get();
await client.contact.requestOptions({ cache: "no-cache" }).get();
const req = await request;

@@ -61,3 +61,3 @@

await client.contact
.options({ headers: { "X-Correlation-Id": "mock-correlation-id" } })
.requestOptions({ headers: { "X-Correlation-Id": "mock-correlation-id" } })
.get();

@@ -234,3 +234,3 @@ const req = await request;

expect(consoleSpy.group).toHaveBeenCalledWith(
`\u001b[1mCiviCRM request\u001b[22m ${requestId} \u001b[90mhttps://example.com/civicrm/ajax/api4/Contact/get\u001b[39m 200 in \u001b[33m0ms\u001b[39m`,
`CiviCRM request ${requestId} https://example.com/civicrm/ajax/api4/Contact/get 200 in 0ms`,
);

@@ -237,0 +237,0 @@ expect(consoleSpy.groupEnd).toHaveBeenCalled();

@@ -5,7 +5,7 @@ import { DeferredPromise } from "@open-draft/deferred-promise";

import { createClient } from "../src";
import { server } from "./mock-server";
import { server } from "./mock/server";
const clientConfig = {
baseUrl: "https://example.com",
apiKey: "mock-api-key",
auth: { apiKey: "mock-api-key" },
};

@@ -42,9 +42,2 @@

test("requires apiKey", () => {
expect(() => {
// @ts-ignore
createClient({ baseUrl: "https://example.com" });
}).toThrow("apiKey is required");
});
test("creates methods for specified entities", () => {

@@ -51,0 +44,0 @@ expect(client.contact).toBeDefined();

@@ -7,3 +7,8 @@ /// <reference types="vitest" />

test: {
setupFiles: ["./test/mock-server.ts"],
coverage: {
include: ["src/**"],
},
dir: "test",
exclude: ["**/browser/**"],
setupFiles: ["test/mock/server.ts"],
fakeTimers: {

@@ -10,0 +15,0 @@ toFake: [...configDefaults.fakeTimers.toFake, "performance"],

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc