@planningcenter/api-client
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -1,2 +0,2 @@ | ||
var e=require("lodash"),t=require("urijs"),a=require("@planningcenter/url"),n=require("lodash-inflection");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(e),u=r(t),i=r(a),d=r(n);const l=e=>{const t=new WeakMap,a=n=>(e=>!(s.default.isObject(e)&&(s.default.isArray(e)||s.default.isFunction(e))||!s.default.isObject(e)))(n)?s.default.reduce(n,(r,s,u)=>(t.has(n)||t.set(n,r),r[e(u)]=t.get(s)||a(s),r),{}):s.default.isArray(n)?s.default.map(n,a):n;return a},c=l(e=>e.replace(/(\_[a-z])/g,e=>e.toUpperCase().replace("_",""))),o=l(e=>{return e<0?e:(t=e).startsWith("_")?`_${s.default.snakeCase(t)}`:s.default.snakeCase(t);var t}),f=e=>e.endsWith("-staging.planningcenteronline.com")||e.endsWith("/staging.planningcenteronline.com")||e.endsWith(".staging.churchcenter.com")||e.endsWith("/staging.churchcenter.com")?"staging":e.endsWith(".planningcenteronline.com")||e.endsWith(".churchcenter.com")||e.endsWith("/churchcenter.com")?"production":e.endsWith("pco.codes")||e.endsWith("pco.dev")||e.endsWith("pco.test")||e.endsWith("churchcenter.test")?"development":"production",p=({fields:e,where:t,include:a,walk:n,...r})=>({...s.default.reduce(e,(e,t,a)=>({...e,[`fields[${a}]`]:s.default.isArray(t)?t.join(","):t}),{}),...s.default.reduce(t,(e,t,a)=>({...e,...h({key:`where[${a}]`,value:t})}),{}),...o({perPage:100,...r}),include:s.default.isArray(a)?a.join(","):a});function h({key:e,value:t}){return s.default.isArray(t)?{[e]:t.join(",")}:s.default.isObject(t)?Object.keys(t).reduce((a,n)=>({...a,...h({key:`${e}[${n}]`,value:t[n]})}),{}):{[e]:t}}s.default.mixin({...d.default}),s.default.singular(/^(media)$/i,"$1"),s.default.plural(/^(media)$/i,"$1");const g=e=>s.default.thru(parseInt(e,10),t=>t==e?t:e),m=e=>Object.keys(e||{}).reduce((t,a)=>{const n=e[a];if(s.default.isArray(n.data)){const e=s.default.map(n.data,({id:e})=>g(e));return{...t,[`${s.default.singularize(a)}_ids`]:e}}{const e=s.default.get(n,"data.id"),r=s.default.get(n,"data.type",null);return{...t,[`${a}_id`]:e?g(e):null,[`${a}_type`]:r}}},{}),y=(e,t,a)=>{const{id:n,attributes:r,links:u,relationships:i,type:d}=e;if(a.has(e))return a.get(e);{const l={id:g(n),type:d,links:u,...m(i),...s.default.mapKeys(r,(e,t)=>"length"===t?`${d.charAt(0).toLowerCase()}${d.slice(1)}Length`:t,{})};return a.set(e,l),((e,t,a,n)=>Object.keys(e||{}).reduce((n,r)=>{const u=e[r];if(s.default.isArray(u.data)){const e=s.default(u.data).map(e=>s.default.find(t,e)).compact().value();return{...n,[s.default.pluralize(r)]:s.default.map(e,e=>y(e,t,a))}}{const[e,i]=s.default.at(u,["data.id","data.type"]);if(e&&i){const u=s.default.find(t,{id:e,type:i});return s.default.set(n,r,u?y(u,t,a):null)}return n}},n))(i,t,a,l)}},v=s.default.flowRight(c,e=>{if(s.default.isEmpty(e))return e;const{data:t,included:a,meta:n}=e,r=new WeakMap;return s.default.isArray(t)?{data:t.map(e=>y(e,a,r)),meta:n}:{data:{...y(t,a,r)},meta:n}}),$=["total_count","count","prev","next","can_order_by","can_query_by","can_include","can_filter","parent"],w=function(e,t){try{return Promise.resolve(e(t)).then(function(e){return Promise.resolve(v(e))})}catch(e){return Promise.reject(e)}},k=s.default.includes(["development","test"],process.env.NODE_ENV)?(e,t)=>q(t.url).then(()=>_(e,t)).then(v):w,E=s.default.includes(["development","test"],process.env.NODE_ENV)?(e,t)=>q(t.url).then(e).then(v):w,q=e=>{if(new u.default(e).search().length)throw new Error("Must pass query params as data arg");return Promise.resolve()},_=function(e,t){try{const a=s.default.get(t,"data.fields");if(!a)throw new Error(`Must pass fields for request: ${t.url}`);const n=Object.keys(a);return Promise.resolve(e(t)).then(function(e){const a=s.default(e.data).castArray().map("type").value(),r=s.default.map(e.included,"type"),u=s.default.uniq(a.concat(r)),i=s.default.difference(u,n);if(i.length)throw new Error(`Must include fields for types: ${((e,t="and")=>(t=`${e.length>2?",":""} ${t}`,e.join(", ").replace(/,\s([^,]+$)/,`${t} $1`)))(i)} for request ${t.url}`);return e})}catch(e){return Promise.reject(e)}},j=({url:e,app:t,env:a})=>{const n=s.default.startsWith(e,"/"),r=`${i.default(a)("api")}/${t}/v2${n?"":"/"}`;return s.default.startsWith(e,r)?e:`${r}${e}`},O=({url:e,data:t={},app:a,version:n,env:r,action:i})=>new Promise((d,l)=>{const c=new XMLHttpRequest;c.withCredentials=!0,c.open(i,((e,t,a,n,r=!1)=>{const i=u.default(e),d=i.query(!0),l=i.query({}).toString();if(r){const e=s.default.merge(p(t),d);return u.default(j({url:l,app:a,env:n})).query(e).toString()}return u.default(j({url:l,app:a,env:n})).toString()})(e,t,a,r,"GET"===i)),n&&c.setRequestHeader("X-PCO-API-Version",n),c.setRequestHeader("X-CSRF-Token","test"===process.env.NODE_ENV?"TEST_TOKEN":document.querySelector('meta[name="csrf-token"]').content),c.setRequestHeader("Content-Type","application/json;charset=UTF-8"),c.onerror=l,c.onload=()=>{if(204===c.status)d();else if(c.status>=200&&c.status<300)try{d(JSON.parse(c.response))}catch(e){l(c)}else try{l(JSON.parse(c.response))}catch(e){l(c)}},c.send(JSON.stringify(t))});exports.Client=class{constructor({app:e,version:t,env:a=f(window.location.origin)}){if(!e)throw new Error("You must pass an app");if(!a)throw new Error("env cannot be blank!");this.app=e,this.env=a,this.version=t}get(e){const t=s.default.get(e,"data.walk",!1),a=({url:e,data:n={},acc:r={data:[],included:[]},...u})=>O({action:"GET",data:n,url:e,...u,...this.config}).then(({links:e,...n})=>{const u=s.default.isArray(n.data)&&t?((e,t)=>({data:[...e.data,...t.data],included:[...e.included,...t.included],meta:s.default.pick(t.meta,$)}))(r,n):n;return t&&s.default.get(e,"next")?a({url:e.next,data:{},acc:u}):u});return k(a,e)}patch(e){return E(()=>O({...e,action:"PATCH",...this.config}),e)}post(e){return E(()=>O({...e,action:"POST",...this.config}),e)}delete(e){return O({...e,action:"DELETE",...this.config})}get config(){return{app:this.app,version:this.version,env:this.env}}},exports.transformRequestData=p,exports.transformResponse=v; | ||
var e=require("lodash"),t=require("urijs"),a=require("@planningcenter/url"),n=require("lodash-inflection/lib/lodash-inflection");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(e),u=r(t),i=r(a),d=r(n);const l=e=>{const t=new WeakMap,a=n=>(e=>!(s.default.isObject(e)&&(s.default.isArray(e)||s.default.isFunction(e))||!s.default.isObject(e)))(n)?s.default.reduce(n,(r,s,u)=>(t.has(n)||t.set(n,r),r[e(u)]=t.get(s)||a(s),r),{}):s.default.isArray(n)?s.default.map(n,a):n;return a},o=l(e=>e.replace(/(\_[a-z])/g,e=>e.toUpperCase().replace("_",""))),c=l(e=>{return e<0?e:(t=e).startsWith("_")?`_${s.default.snakeCase(t)}`:s.default.snakeCase(t);var t}),f=e=>e.endsWith("-staging.planningcenteronline.com")||e.endsWith("/staging.planningcenteronline.com")||e.endsWith(".staging.churchcenter.com")||e.endsWith("/staging.churchcenter.com")?"staging":e.endsWith(".planningcenteronline.com")||e.endsWith(".churchcenter.com")||e.endsWith("/churchcenter.com")?"production":e.endsWith("pco.codes")||e.endsWith("pco.dev")||e.endsWith("pco.test")||e.endsWith("churchcenter.test")?"development":"production",p=({fields:e,where:t,include:a,walk:n,...r})=>({...s.default.reduce(e,(e,t,a)=>({...e,[`fields[${a}]`]:s.default.isArray(t)?t.join(","):t}),{}),...s.default.reduce(t,(e,t,a)=>({...e,...h({key:`where[${a}]`,value:t})}),{}),...c({perPage:100,...r}),include:s.default.isArray(a)?a.join(","):a});function h({key:e,value:t}){return s.default.isArray(t)?{[e]:t.join(",")}:s.default.isObject(t)?Object.keys(t).reduce((a,n)=>({...a,...h({key:`${e}[${n}]`,value:t[n]})}),{}):{[e]:t}}s.default.mixin({...d.default}),s.default.singular(/^(media)$/i,"$1"),s.default.plural(/^(media)$/i,"$1");const g=e=>s.default.thru(parseInt(e,10),t=>t==e?t:e),m=e=>Object.keys(e||{}).reduce((t,a)=>{const n=e[a];if(s.default.isArray(n.data)){const e=s.default.map(n.data,({id:e})=>g(e));return{...t,[`${s.default.singularize(a)}_ids`]:e}}{const e=s.default.get(n,"data.id"),r=s.default.get(n,"data.type",null);return{...t,[`${a}_id`]:e?g(e):null,[`${a}_type`]:r}}},{}),y=(e,t,a)=>{const{id:n,attributes:r,links:u,relationships:i,type:d}=e;if(a.has(e))return a.get(e);{const l={id:g(n),type:d,links:u,...m(i),...s.default.mapKeys(r,(e,t)=>"length"===t?`${d.charAt(0).toLowerCase()}${d.slice(1)}Length`:t,{})};return a.set(e,l),((e,t,a,n)=>Object.keys(e||{}).reduce((n,r)=>{const u=e[r];if(s.default.isArray(u.data)){const e=s.default(u.data).map(e=>s.default.find(t,e)).compact().value();return{...n,[s.default.pluralize(r)]:s.default.map(e,e=>y(e,t,a))}}{const[e,i]=s.default.at(u,["data.id","data.type"]);if(e&&i){const u=s.default.find(t,{id:e,type:i});return s.default.set(n,r,u?y(u,t,a):null)}return n}},n))(i,t,a,l)}},v=s.default.flowRight(o,e=>{if(s.default.isEmpty(e))return e;const{data:t,included:a,meta:n}=e,r=new WeakMap;return s.default.isArray(t)?{data:t.map(e=>y(e,a,r)),meta:n}:{data:{...y(t,a,r)},meta:n}}),$=["total_count","count","prev","next","can_order_by","can_query_by","can_include","can_filter","parent"],w=function(e,t){try{return Promise.resolve(e(t)).then(function(e){return Promise.resolve(v(e))})}catch(e){return Promise.reject(e)}},k=s.default.includes(["development","test"],process.env.NODE_ENV)?(e,t)=>q(t.url).then(()=>_(e,t)).then(v):w,E=s.default.includes(["development","test"],process.env.NODE_ENV)?(e,t)=>q(t.url).then(e).then(v):w,q=e=>{if(new u.default(e).search().length)throw new Error("Must pass query params as data arg");return Promise.resolve()},_=function(e,t){try{const a=s.default.get(t,"data.fields");if(!a)throw new Error(`Must pass fields for request: ${t.url}`);const n=Object.keys(a);return Promise.resolve(e(t)).then(function(e){const a=s.default(e.data).castArray().map("type").value(),r=s.default.map(e.included,"type"),u=s.default.uniq(a.concat(r)),i=s.default.difference(u,n);if(i.length)throw new Error(`Must include fields for types: ${((e,t="and")=>(t=`${e.length>2?",":""} ${t}`,e.join(", ").replace(/,\s([^,]+$)/,`${t} $1`)))(i)} for request ${t.url}`);return e})}catch(e){return Promise.reject(e)}},j=({url:e,app:t,env:a})=>{const n=s.default.startsWith(e,"/"),r=`${i.default(a)("api")}/${t}/v2${n?"":"/"}`;return s.default.startsWith(e,r)?e:`${r}${e}`},O=({url:e,data:t={},app:a,version:n,env:r,action:i})=>new Promise((d,l)=>{const o=new XMLHttpRequest;o.withCredentials=!0,o.open(i,((e,t,a,n,r=!1)=>{const i=u.default(e),d=i.query(!0),l=i.query({}).toString();if(r){const e=s.default.merge(p(t),d);return u.default(j({url:l,app:a,env:n})).query(e).toString()}return u.default(j({url:l,app:a,env:n})).toString()})(e,t,a,r,"GET"===i)),n&&o.setRequestHeader("X-PCO-API-Version",n),o.setRequestHeader("X-CSRF-Token","test"===process.env.NODE_ENV?"TEST_TOKEN":document.querySelector('meta[name="csrf-token"]').content),o.setRequestHeader("Content-Type","application/json;charset=UTF-8"),o.onerror=l,o.onload=()=>{if(204===o.status)d();else if(o.status>=200&&o.status<300)try{d(JSON.parse(o.response))}catch(e){l(o)}else try{l(JSON.parse(o.response))}catch(e){l(o)}},o.send(JSON.stringify(t))});exports.Client=class{constructor({app:e,version:t,env:a=f(window.location.origin)}){if(!e)throw new Error("You must pass an app");if(!a)throw new Error("env cannot be blank!");this.app=e,this.env=a,this.version=t}get(e){const t=s.default.get(e,"data.walk",!1),a=({url:e,data:n={},acc:r={data:[],included:[]},...u})=>O({action:"GET",data:n,url:e,...u,...this.config}).then(({links:e,...n})=>{const u=s.default.isArray(n.data)&&t?((e,t)=>({data:[...e.data,...t.data],included:[...e.included,...t.included],meta:s.default.pick(t.meta,$)}))(r,n):n;return t&&s.default.get(e,"next")?a({url:e.next,data:{},acc:u}):u});return k(a,e)}patch(e){return E(()=>O({...e,action:"PATCH",...this.config}),e)}post(e){return E(()=>O({...e,action:"POST",...this.config}),e)}delete(e){return O({...e,action:"DELETE",...this.config})}get config(){return{app:this.app,version:this.version,env:this.env}}},exports.transformRequestData=p,exports.transformResponse=v; | ||
//# sourceMappingURL=api-client.js.map |
{ | ||
"name": "@planningcenter/api-client", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "A Planning Center JavaScript API client that will make you smile", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:planningcenter/js-api-client.git", |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
25
0
33617
4