@apolitical/sdk 7.3.0-beta.0 → 7.3.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@apolitical/content"),require("@apolitical/error-reporting"),require("@apolitical/gtm"),require("axios"),require("http-status-codes"),require("buffer")):"function"==typeof define&&define.amd?define(["@apolitical/content","@apolitical/error-reporting","@apolitical/gtm","axios","http-status-codes","buffer"],e):"object"==typeof exports?exports.ApoliticalSDK=e(require("@apolitical/content"),require("@apolitical/error-reporting"),require("@apolitical/gtm"),require("axios"),require("http-status-codes"),require("buffer")):t.ApoliticalSDK=e(t["@apolitical/content"],t["@apolitical/error-reporting"],t["@apolitical/gtm"],t.axios,t["http-status-codes"],t.buffer)}(this,(function(t,e,r,a,n,s){return function(){"use strict";var o={809:function(e){e.exports=t},30:function(t){t.exports=e},36:function(t){t.exports=r},300:function(t){t.exports=a},408:function(t){t.exports=s},25:function(t){t.exports=n}},i={};function c(t){var e=i[t];if(void 0!==e)return e.exports;var r=i[t]={exports:{}};return o[t](r,r.exports,c),r.exports}c.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return c.d(e,{a:e}),e},c.d=function(t,e){for(var r in e)c.o(e,r)&&!c.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},c.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},c.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var l={};return function(){c.r(l),c.d(l,{assets:function(){return h},auth:function(){return U},buildAnswer:function(){return Ge},buildCarouselCard:function(){return Me},buildQuestion:function(){return Le},carouselCards:function(){return Ie},contentInteraction:function(){return X},decodeBase64:function(){return xe},default:function(){return Ve},editorialPages:function(){return he},getEntries:function(){return t.getEntries},getEntry:function(){return t.getEntry},management:function(){return it},payments:function(){return Et},people:function(){return ae},peopleEngagement:function(){return Se},qaQuestions:function(){return $e},reportError:function(){return e.reportError}});var t=c(809),e=c(30),r=c(36),a={APOLITICAL:{WEBSITES:{LIVE:"https://apolitical.co",LOCALHOST:"localhost",STAGING:/https:\/\/([\w|\d|-]+)\.apolitical\.co/i,STAGING_SPLITTER:"-"},ENVIRONMENTS:{PRODUCTION:"live",LOCAL:"local"}},APIS:{ASSETS_API:{BASE_URL:"/api/assets-api",ENDPOINTS:{USERS:"/users",CERTIFICATES:"/certificates"}},AUTH_API:{BASE_URL:"/api/auth-api",ENDPOINTS:{USER_PASSWORD:"/password",USERS:"/users"}},CONTENT_INTERACTION_API:{BASE_URL:"/api/content-interaction-api",ENDPOINTS:{QUESTIONS:"/questions",ANSWERS:"/answers",REPLIES:"/replies",LIKES:"/likes"}},MANAGEMENT_API:{BASE_URL:"/api/management-api",ENDPOINTS:{ACCOUNTS:"/accounts",EVENT_REGISTRATIONS:"/event-registrations",LOGINS:"/logins",LOGIN_PASSWORDLESS:"/passwordless"}},PAYMENTS_API:{BASE_URL:"/api/payments-api",BASE_URL_V2:"/api/payments-api/v2",ENDPOINTS:{PRODUCTS:"/products"}},PEOPLE_API:{BASE_URL:"/api/people-api",BASE_URL_V2:"/api/people-api/v2",ENDPOINTS:{REGISTRATIONS:"/registrations",USERS:"/users",USER_ANSWERS:"/answers",USER_COURSES:"/courses",USER_EVENTS:"/events",USER_LIKES:"/likes",USER_LESSONS:"/lessons",USER_PRODUCTS:"/products",USER_SUBSCRIPTIONS:"/subscriptions"}},PEOPLE_ENGAGEMENT_API:{BASE_URL:"/api/people-engagement-api",ENDPOINTS:{ENQUIRY_EMAILS:"/enquiry-emails",USERS:"/users",USER_PROPERTIES:"/properties"}}},CONTENTFUL:{ARTICLES:{TYPE:"solutionArticle"},CAROUSELS:{CARD_TYPES:{solutionArticle:{INCLUDE:1,SELECT:"fields.authorIds,fields.authorTag,fields.image,fields.publishedDate,fields.readingTime,fields.slug,fields.title"},microcourse:{INCLUDE:2,SELECT:"fields.banner,fields.freeCourse,fields.partnershipDetails,fields.slug,fields.title"},event:{INCLUDE:1,SELECT:"fields.bannerImage,fields.defaultStartDate,fields.slug,fields.speakers,fields.title,fields.isEventOngoing"},listPage:{INCLUDE:1,SELECT:"fields.hero,fields.slug,fields.title"},qaQuestion:{INCLUDE:0,SELECT:"fields.answers,fields.authorId,fields.slug,fields.title,sys.createdAt"}}},COURSES:{TYPE:"microcourse"},EDITORIAL_PAGES:{INCLUDE:1,SELECT:"fields.carousels,fields.slug",TYPE:"editorialPage"},EVENTS:{TYPE:"event"},LISTS:{TYPE:"listPage"},QUESTIONS:{TYPE:"qaQuestion",INCLUDE:1,LIMIT:10,ORDER:"-sys.createdAt",SELECT:"sys.createdAt,sys.updatedAt,fields.title,fields.slug,fields.authorId,fields.answers,fields.isEdited",SKIP:0},ANSWERS:{TYPE:"qaAnswer"},REPLIES:{TYPE:"reply"}},HUBSPOT:{ENVIRONMENTS_MAPPING:{local:"SANDBOX",beta:"SANDBOX",rc:"SANDBOX",live:"LIVE"},EMAIL_IDS:{SANDBOX:{internalEmailId:49099078634,externalEmailId:55196526554},LIVE:{internalEmailId:55233583049,externalEmailId:55231159239}}},USERS:{MYSELF:"me"}};const{APOLITICAL:{WEBSITES:{LIVE:n,LOCALHOST:s,STAGING:o,STAGING_SPLITTER:i},ENVIRONMENTS:{PRODUCTION:u,LOCAL:E}}}=a,{HUBSPOT:{ENVIRONMENTS_MAPPING:S,EMAIL_IDS:d}}=a;let p={emailIds:{}};var w=c(300),I=c.n(w);const g=async t=>{try{const{message:r,response:a,request:n}=t;let s=r;return a?s+=` - The request was made and the server responded with ${JSON.stringify({status:a.status,data:a.data})}`:n&&(s+=" - The request was made but no response was received"),console.warn(s),await(0,e.reportError)(new Error(s)),s}catch(t){return console.warn(`Cannot handle error: ${t.message}`),t.message}},{APIS:{ASSETS_API:{BASE_URL:N,ENDPOINTS:{USERS:T,CERTIFICATES:A}}}}=a;var h={certificates:{create:async(t,e)=>{let r=[];try{const{data:a}=await I().post(`${N}${T}/${t}${A}`,e);a&&(r=a)}catch(t){await g(t)}return r}}};const{APIS:{AUTH_API:{BASE_URL:y,ENDPOINTS:{USER_PASSWORD:P,USERS:R}}},USERS:{MYSELF:f}}=a;var U={userPassword:{update:async t=>{let e=null;try{e=await I().put(`${y}${R}/${f}${P}`,t)}catch(t){e={message:(((t||{}).response||{}).data||{}).message},await g(t)}return e}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:O,ENDPOINTS:{ANSWERS:m,QUESTIONS:$,LIKES:L}}}}=a,C=`${O}${$}`;var _={create:async({questionSlug:t},e)=>{try{await I().post(`${C}/${encodeURIComponent(t)}${m}`,e)}catch(t){const e=await g(t);throw new Error(e)}},remove:async({questionSlug:t,answerSlug:e})=>{try{await I().delete(`${C}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}`)}catch(t){const e=await g(t);throw new Error(e)}},update:async({questionSlug:t,answerSlug:e},r)=>{try{return await I().put(`${C}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}`,r)}catch(t){const e=await g(t);throw new Error(e)}},like:async({questionSlug:t,answerSlug:e})=>{try{return await I().post(`${C}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}${L}`)}catch(t){const e=await g(t);throw new Error(e)}},unlike:async({questionSlug:t,answerSlug:e})=>{try{return await I().delete(`${C}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}${L}`)}catch(t){const e=await g(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:D,ENDPOINTS:{QUESTIONS:v}}}}=a,b=`${D}${v}`;var q={create:async t=>{try{return await I().post(b,t)}catch(t){const e=await g(t);throw new Error(e)}},remove:async({questionSlug:t})=>{try{await I().delete(`${b}/${encodeURIComponent(t)}`)}catch(t){const e=await g(t);throw new Error(e)}},update:async({questionSlug:t},e)=>{try{return await I().put(`${b}/${encodeURIComponent(t)}`,e)}catch(t){const e=await g(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:B,ENDPOINTS:{REPLIES:M,ANSWERS:G,QUESTIONS:Y,LIKES:x}}}}=a,V=`${B}${Y}`,F=({questionSlug:t,answerSlug:e,replySlug:r},a=!1)=>{let n=`${V}/${encodeURIComponent(t)}${G}/${encodeURIComponent(e)}${M}`;return r&&(n=`${n}/${encodeURIComponent(r)}`,a&&(n=`${n}${x}`)),n};var k={create:async({questionSlug:t,answerSlug:e},r)=>{try{return await I().post(F({questionSlug:t,answerSlug:e}),r)}catch(t){const e=await g(t);throw new Error(e)}},update:async({questionSlug:t,answerSlug:e,replySlug:r},a)=>{try{return await I().put(F({questionSlug:t,answerSlug:e,replySlug:r}),a)}catch(t){const e=await g(t);throw new Error(e)}},remove:async({questionSlug:t,answerSlug:e,replySlug:r})=>{try{await I().delete(F({questionSlug:t,answerSlug:e,replySlug:r}))}catch(t){const e=await g(t);throw new Error(e)}},like:async({questionSlug:t,answerSlug:e,replySlug:r})=>{try{await I().post(F({questionSlug:t,answerSlug:e,replySlug:r},!0))}catch(t){const e=await g(t);throw new Error(e)}},unlike:async({questionSlug:t,answerSlug:e,replySlug:r})=>{try{await I().delete(F({questionSlug:t,answerSlug:e,replySlug:r},!0))}catch(t){const e=await g(t);throw new Error(e)}},getReplyUrl:F};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:Q,ENDPOINTS:{QUESTIONS:W,ANSWERS:j,LIKES:K}}}}=a,H=`${Q}${W}`;var X={answers:_,questions:q,replies:k,likes:{create:async(t,e)=>{try{return await I().post(`${H}/${encodeURIComponent(t)}${j}/${encodeURIComponent(e)}${K}`)}catch(t){const e=await g(t);throw new Error(e)}},remove:async(t,e)=>{try{return await I().delete(`${H}/${encodeURIComponent(t)}${j}/${encodeURIComponent(e)}${K}`)}catch(t){const e=await g(t);throw new Error(e)}}}};const{APIS:{MANAGEMENT_API:{BASE_URL:J,ENDPOINTS:{ACCOUNTS:z}}}}=a;var Z={create:async t=>{try{await I().post(`${J}${z}`,t)}catch(t){throw await g(t),t}},read:async t=>{let e=null;try{({data:e}=await I().get(`${J}${z}/${encodeURIComponent(t)}`))}catch(t){await g(t)}return e},update:async(t,e)=>{try{await I().put(`${J}${z}/${encodeURIComponent(t)}`,e)}catch(t){throw await g(t),t}}};const{APIS:{MANAGEMENT_API:{BASE_URL:tt,ENDPOINTS:{EVENT_REGISTRATIONS:et}}}}=a;var rt={create:async t=>{try{await I().post(`${tt}${et}`,t)}catch(t){const e=await g(t);throw new Error(e)}}};const{APIS:{MANAGEMENT_API:{BASE_URL:at,ENDPOINTS:{LOGINS:nt,LOGIN_PASSWORDLESS:st}}}}=a,ot=`${at}${nt}`;var it={accounts:Z,eventRegistrations:rt,passwordless:{update:async t=>{try{await I().put(`${ot}/${encodeURIComponent(t)}${st}`)}catch(t){throw await g(t),t}}}};const{APIS:{PAYMENTS_API:{BASE_URL_V2:ct,ENDPOINTS:{PRODUCTS:lt}}}}=a,ut=`${ct}${lt}`;var Et={products:{list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(ut,r);t&&t.length&&(e=t)}catch(t){await g(t)}return e}}},St=c(25);const{OK:dt,MULTIPLE_CHOICES:pt,NOT_FOUND:wt,FORBIDDEN:It}=St.StatusCodes,gt=t=>t>=dt&&t<pt||t===It||t===wt,{APIS:{PEOPLE_API:{BASE_URL_V2:Nt,ENDPOINTS:{USERS:Tt}}}}=a,At=async t=>{let e=null;try{const{data:r}=await I().get(`${Nt}${Tt}/${encodeURIComponent(t)}`,{validateStatus:gt});r&&r.id&&(e=r)}catch(t){await g(t)}return e},ht=async t=>{let e=[];try{if(t&&t.length<2)throw new Error("users list method requires at least two ids");const r=t.map((t=>`ids=${encodeURIComponent(t)}`)).join("&"),a=await I().get(`${Nt}${Tt}?${r}`,{validateStatus:gt});a&&a.length&&(e=a)}catch(t){await g(t)}return e};var yt={read:At,update:async(t,e)=>{let r=!1;try{const{data:a}=await I().put(`${Nt}${Tt}/${encodeURIComponent(t)}`,e);r=!(!a||!a.id)}catch(t){await g(t)}return r},list:ht};const{APIS:{PEOPLE_API:{BASE_URL_V2:Pt,ENDPOINTS:{USERS:Rt,USER_LIKES:ft}}},USERS:{MYSELF:Ut}}=a,Ot=`${Pt}${Rt}/${Ut}${ft}`,mt=async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(Ot,r);t&&t.length&&(e=t)}catch(t){await g(t)}return e};var $t={list:mt};var Lt={authors:{readQuestionAuthors:async(t,e,r)=>{try{if(t.author=await At(t.authorId),t.answers&&t.answers.length&&!r.ignoreAnswersAuthors){t.answers.sort(((t,e)=>new Date(e.updatedAt)-new Date(t.updatedAt))),t.totalAnswers=t.answers.length;let n=t.answers;if(r.limit&&r.pageNumber){const e=r.limit*(r.pageNumber-1);n=t.answers.slice(e,e+r.limit)}for(let t of n){t.author=t.authorId&&await At(t.authorId)||{};const[r]=e?await mt({contentType:a.CONTENTFUL.ANSWERS.TYPE,contentSlug:t.slug}):[null];t.userLiked=!!r}t.answers=n}else t.answers||(t.answers=[]);return t}catch(t){throw await g(t),new Error(`Cannot read authors for question: ${t.message}`)}},readAuthors:async(t=[])=>{let e=[];try{if(!1===Array.isArray(t))throw new Error("authorIds is not an array!");if(t&&1===t.length){const r=await At(t[0]);r&&e.push(r)}else if(t&&t.length>1){const r=await ht(t);r&&r.length>0&&(e=r)}}catch(t){throw await g(t),new Error(`Cannot read authors: ${t.message}`)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL:Ct,ENDPOINTS:{REGISTRATIONS:_t}}}}=a;var Dt={list:async t=>{let e=[];try{const{data:r}=await I().get(`${Ct}${_t}`,{params:t});r&&r.length&&(e=r)}catch(t){await g(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:vt,ENDPOINTS:{USERS:bt,USER_COURSES:qt}}},USERS:{MYSELF:Bt}}=a,Mt=`${vt}${bt}/${Bt}${qt}`;var Gt={create:async t=>{try{await I().post(Mt,t)}catch(t){await g(t)}},list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(Mt,r);t&&t.length&&(e=t)}catch(t){await g(t)}return e},update:async(t,e)=>{try{await I().put(`${Mt}/${t}`,e)}catch(t){await g(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Yt,ENDPOINTS:{USERS:xt,USER_EVENTS:Vt}}},USERS:{MYSELF:Ft}}=a,kt=`${Yt}${xt}/${Ft}${Vt}`;var Qt={list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(kt,r);t&&t.length&&(e=t)}catch(t){await g(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Wt,ENDPOINTS:{USERS:jt,USER_LESSONS:Kt}}},USERS:{MYSELF:Ht}}=a,Xt=`${Wt}${jt}/${Ht}${Kt}`;var Jt={create:async t=>{let e=null;try{e=await I().post(Xt,t)}catch(t){await g(t)}return e},list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(Xt,r);t&&t.length&&(e=t)}catch(t){await g(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:zt,ENDPOINTS:{USERS:Zt,USER_PRODUCTS:te}}},USERS:{MYSELF:ee}}=a,re=`${zt}${Zt}/${ee}${te}`;var ae={handlers:Lt,registrations:Dt,users:yt,userCourses:Gt,userEvents:Qt,userLessons:Jt,userLikes:$t,userProducts:{create:async t=>{let e=null;try{e=await I().post(re,t)}catch(t){await g(t)}return e},list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(re,r);t&&t.length&&(e=t)}catch(t){await g(t)}return e},update:async(t,e)=>{try{await I().put(`${re}/${t}`,e)}catch(t){await g(t)}}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:ne,ENDPOINTS:{ENQUIRY_EMAILS:se}}}}=a;var oe={create:async t=>{let e=null;try{const{data:r}=await I().post(`${ne}${se}`,t);r&&(e=r)}catch(t){await g(t)}return e}},ie={forms:{sendEnquiryEmails:async t=>{let e=null;try{const{emailIds:r}=p;e=await Se.emails.create({...r,...t})}catch(t){await g(t)}return e}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:ce,ENDPOINTS:{USERS:le,USER_PROPERTIES:ue}}},USERS:{MYSELF:Ee}}=a;var Se={emails:oe,handlers:ie,userProperties:{update:async(t,e)=>{try{await I().put(`${ce}${le}/${Ee}${ue}/${t}`,e)}catch(t){await g(t)}}}};const{CONTENTFUL:de}=a,{CARD_TYPES:pe}=de.CAROUSELS,we={read:async(e,r)=>{try{if(!r||!r.sys||!r.sys.id)throw new Error("Invalid link to card");if(!e||!pe[e])throw new Error("Unsupported card content type");const{INCLUDE:a,SELECT:n}=pe[e];return await(0,t.getEntry)({content_type:e,"sys.id":r.sys.id,include:a,select:n},{assetDetails:!0})}catch(t){throw await g(t),new Error(`Cannot read carousel card: ${t.message}`)}}};var Ie=we;const{CONTENTFUL:ge}=a,{INCLUDE:Ne,SELECT:Te,TYPE:Ae}=ge.EDITORIAL_PAGES;var he={read:async e=>{try{return await(0,t.getEntry)({content_type:Ae,"fields.slug":e,include:Ne,select:Te})}catch(t){throw await g(t),new Error(`Cannot read editorial page: ${t.message}`)}}};const{CONTENTFUL:ye}=a,{TYPE:Pe,ORDER:Re,SELECT:fe,SKIP:Ue,LIMIT:Oe,INCLUDE:me}=ye.QUESTIONS;var $e={read:async e=>{try{return await(0,t.getEntry)({content_type:Pe,"fields.slug":e,include:2,select:fe})}catch(t){throw await g(t),new Error(`Cannot read question: ${t.message}`)}},list:async(e={})=>{try{return await(0,t.getEntries)({content_type:Pe,include:me,limit:Oe,order:Re,select:fe,skip:Ue,"fields.private[ne]":!0,...e})}catch(t){throw await g(t),new Error(`Cannot list questions: ${t.message}`)}}},Le=async(t,e,r={ignoreAnswersAuthors:!1})=>{try{let a={};return a=await $e.read(t),a=await ae.handlers.authors.readQuestionAuthors(a,e,r),a}catch(t){throw await g(t),new Error(`Cannot build question: ${t.message}`)}};const{ARTICLES:{TYPE:Ce},COURSES:{TYPE:_e},EVENTS:{TYPE:De},LISTS:{TYPE:ve},QUESTIONS:{TYPE:be}}=a.CONTENTFUL,qe=t=>t&&t.url?(Object.assign(t,{aspect:"responsiveCard",query:"q=90&fit=fill"}),t):null,Be={[Ce]:async t=>{const{authorIds:e,authorTag:r,image:a,publishedDate:n,readingTime:s,slug:o,title:i}=t,c=await ae.handlers.authors.readAuthors(e),l=c&&c.length?c:r?[r]:null;return{banner:qe(a),contributors:l,publishedDate:n,readingTime:s,slug:o,title:i}},[_e]:async(t,e)=>{const{banner:r,freeCourse:a,partnershipDetails:n,slug:s,title:o,registered:i}=t,c={banner:qe(r),slug:s,title:o,pill:a?"free":"premium",registered:!!i};if(n){const{partners:t}=n;c.partner=t&&t.length&&n.partners[0]}if(void 0===i&&e){const[t]=await ae.userProducts.list({courseSlug:s,isEnrolled:!0,scope:"active"});c.registered=!!t}return c},[De]:async(t,e)=>{const{bannerImage:r,defaultStartDate:a,isEventOngoing:n,slug:s,speakers:o,title:i,registered:c}=t,l=new Date(a),u=!!l&&l<new Date;if(o&&o.length)for(const t of o)t.image=(E=t.image)&&E.url?`${E.url}?w=100&h=100&fit=thumb&f=center`:null;var E;const S={banner:qe(r),dateHasPassed:u,title:i,slug:s,isOngoingEvent:n,contributors:o,startDate:l,registered:!!c};if(void 0===c&&e){const[t]=await ae.userEvents.list({eventSlug:s});S.registered=!!t}return S},[ve]:async t=>{const{hero:e,slug:r,title:a}=t;return{banner:qe(e),slug:r,title:a}},[be]:async t=>{const{answers:e,authorId:r,createdAt:a,slug:n,title:s}=t;let o=null;if(r){const t=await ae.users.read(r);t&&(o=t)}return{answers:e&&e.length?e.length:0,contributors:o?[o]:[],createdAt:a,slug:n,title:s}}};var Me=async({contentType:t,...e}={},r)=>{try{if(!Be[t])throw new Error("Content type not supported");if("function"!=typeof Be[t])throw new Error("No builder function for content type");return e.sys&&e.sys.type&&"Link"===e.sys.type&&(e=await Ie.read(t,e)),{contentType:t,...await Be[t](e,r)}}catch(t){throw await g(t),new Error(`Cannot build carousel card: ${t.message}`)}},Ge=async(t,e,r={})=>{try{if(!t.replies||0===t.replies.length)return t.replies=[],t;t.replies.sort(((t,e)=>new Date(t.createdAt)-new Date(e.createdAt))),t.totalReplies=t.totalReplies||t.replies.length;let n=t.replies;if(r.limit&&r.pageNumber){const e=r.limit*(r.pageNumber-1);n=t.replies.slice(e,e+r.limit)}for(const r of n){if(r.authorId===t.authorId){r.author=t.author,r.userLiked=!1;continue}r.author=r.authorId&&await At(r.authorId)||{};const[n]=e?await mt({contentType:a.CONTENTFUL.REPLIES.TYPE,contentSlug:r.slug}):[null];r.userLiked=!!n}return t.replies=n,t}catch(t){throw await g(t),new Error(`Cannot build replies for answer: ${t.message}`)}},Ye=c(408);const xe=t=>t&&Ye.Buffer.from(t,"base64").toString("ascii");function Ve({contentContext:a=null,errorsContext:c=null,gtmContext:l=null,origin:w}){try{const I=(t=>{let e=null;t?e=t:"undefined"!=typeof window&&(e=window.origin||window.location.origin),e||new Error("Cannot select environment: Website not defined");let r=null;const a=e.match(o);return a?r=a[1].split(i)[0]:e===n?r=u:e.includes(s)&&(r=E),r||new Error(`Cannot select environment: No rule for website ${e}`),r})(w);return a&&(0,t.setContext)(Object.assign({},a,{environment:I})),c&&(0,e.setContext)(Object.assign({},c,{environment:I})),l&&((0,r.setContext)(Object.assign({},l,{environment:I})),(0,r.setupGTM)()),(({environment:t})=>{const e=(t=>{if(!t)throw new Error("Cannot map environment: Environment not defined");if(!S[t])throw new Error(`Cannot map environment: No mapping found for environment ${t}`);return S[t]})(t);p.emailIds=d[e]})(Object.assign({},{environment:I})),I}catch(t){console.warn(`Cannot load SDK: ${t.message}`)}}}(),l}()}));
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@apolitical/content"),require("@apolitical/error-reporting"),require("@apolitical/gtm"),require("axios"),require("http-status-codes"),require("buffer")):"function"==typeof define&&define.amd?define(["@apolitical/content","@apolitical/error-reporting","@apolitical/gtm","axios","http-status-codes","buffer"],e):"object"==typeof exports?exports.ApoliticalSDK=e(require("@apolitical/content"),require("@apolitical/error-reporting"),require("@apolitical/gtm"),require("axios"),require("http-status-codes"),require("buffer")):t.ApoliticalSDK=e(t["@apolitical/content"],t["@apolitical/error-reporting"],t["@apolitical/gtm"],t.axios,t["http-status-codes"],t.buffer)}(this,(function(t,e,r,a,n,s){return function(){"use strict";var o={809:function(e){e.exports=t},30:function(t){t.exports=e},36:function(t){t.exports=r},300:function(t){t.exports=a},408:function(t){t.exports=s},25:function(t){t.exports=n}},i={};function c(t){var e=i[t];if(void 0!==e)return e.exports;var r=i[t]={exports:{}};return o[t](r,r.exports,c),r.exports}c.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return c.d(e,{a:e}),e},c.d=function(t,e){for(var r in e)c.o(e,r)&&!c.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},c.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},c.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var l={};return function(){c.r(l),c.d(l,{assets:function(){return h},auth:function(){return U},buildAnswer:function(){return Ve},buildCarouselCard:function(){return xe},buildQuestion:function(){return De},carouselCards:function(){return Te},contentInteraction:function(){return X},decodeBase64:function(){return ke},default:function(){return Qe},editorialPages:function(){return Re},getEntries:function(){return t.getEntries},getEntry:function(){return t.getEntry},management:function(){return it},payments:function(){return Et},people:function(){return oe},peopleEngagement:function(){return we},qaQuestions:function(){return _e},reportError:function(){return e.reportError}});var t=c(809),e=c(30),r=c(36),a={APOLITICAL:{WEBSITES:{LIVE:"https://apolitical.co",LOCALHOST:"localhost",STAGING:/https:\/\/([\w|\d|-]+)\.apolitical\.co/i,STAGING_SPLITTER:"-"},ENVIRONMENTS:{PRODUCTION:"live",LOCAL:"local"}},APIS:{ASSETS_API:{BASE_URL:"/api/assets-api",ENDPOINTS:{USERS:"/users",CERTIFICATES:"/certificates"}},AUTH_API:{BASE_URL:"/api/auth-api",ENDPOINTS:{USER_PASSWORD:"/password",USERS:"/users"}},CONTENT_INTERACTION_API:{BASE_URL:"/api/content-interaction-api",ENDPOINTS:{QUESTIONS:"/questions",ANSWERS:"/answers",REPLIES:"/replies",LIKES:"/likes"}},MANAGEMENT_API:{BASE_URL:"/api/management-api",ENDPOINTS:{ACCOUNTS:"/accounts",EVENT_REGISTRATIONS:"/event-registrations",LOGINS:"/logins",LOGIN_PASSWORDLESS:"/passwordless"}},PAYMENTS_API:{BASE_URL:"/api/payments-api",BASE_URL_V2:"/api/payments-api/v2",ENDPOINTS:{PRODUCTS:"/products"}},PEOPLE_API:{BASE_URL:"/api/people-api",BASE_URL_V2:"/api/people-api/v2",ENDPOINTS:{BULK_ENROLMENTS:"/bulk-enrolments",REGISTRATIONS:"/registrations",USERS:"/users",USER_ANSWERS:"/answers",USER_COURSES:"/courses",USER_EVENTS:"/events",USER_LIKES:"/likes",USER_LESSONS:"/lessons",USER_PRODUCTS:"/products",USER_SUBSCRIPTIONS:"/subscriptions"}},PEOPLE_ENGAGEMENT_API:{BASE_URL:"/api/people-engagement-api",ENDPOINTS:{ENQUIRY_EMAILS:"/enquiry-emails",USERS:"/users",USER_PROPERTIES:"/properties"}}},CONTENTFUL:{ARTICLES:{TYPE:"solutionArticle"},CAROUSELS:{CARD_TYPES:{solutionArticle:{INCLUDE:1,SELECT:"fields.authorIds,fields.authorTag,fields.image,fields.publishedDate,fields.readingTime,fields.slug,fields.title"},microcourse:{INCLUDE:2,SELECT:"fields.banner,fields.freeCourse,fields.partnershipDetails,fields.slug,fields.title"},event:{INCLUDE:1,SELECT:"fields.bannerImage,fields.defaultStartDate,fields.slug,fields.speakers,fields.title,fields.isEventOngoing"},listPage:{INCLUDE:1,SELECT:"fields.hero,fields.slug,fields.title"},qaQuestion:{INCLUDE:0,SELECT:"fields.answers,fields.authorId,fields.slug,fields.title,sys.createdAt"}}},COURSES:{TYPE:"microcourse"},EDITORIAL_PAGES:{INCLUDE:1,SELECT:"fields.carousels,fields.slug",TYPE:"editorialPage"},EVENTS:{TYPE:"event"},LISTS:{TYPE:"listPage"},QUESTIONS:{TYPE:"qaQuestion",INCLUDE:1,LIMIT:10,ORDER:"-sys.createdAt",SELECT:"sys.createdAt,sys.updatedAt,fields.title,fields.slug,fields.authorId,fields.answers,fields.isEdited",SKIP:0},ANSWERS:{TYPE:"qaAnswer"},REPLIES:{TYPE:"reply"}},HUBSPOT:{ENVIRONMENTS_MAPPING:{local:"SANDBOX",beta:"SANDBOX",rc:"SANDBOX",live:"LIVE"},EMAIL_IDS:{SANDBOX:{internalEmailId:49099078634,externalEmailId:55196526554},LIVE:{internalEmailId:55233583049,externalEmailId:55231159239}}},USERS:{MYSELF:"me"}};const{APOLITICAL:{WEBSITES:{LIVE:n,LOCALHOST:s,STAGING:o,STAGING_SPLITTER:i},ENVIRONMENTS:{PRODUCTION:u,LOCAL:E}}}=a,{HUBSPOT:{ENVIRONMENTS_MAPPING:S,EMAIL_IDS:d}}=a;let p={emailIds:{}};var w=c(300),I=c.n(w);const g=async t=>{try{const{message:r,response:a,request:n}=t;let s=r;return a?s+=` - The request was made and the server responded with ${JSON.stringify({status:a.status,data:a.data})}`:n&&(s+=" - The request was made but no response was received"),console.warn(s),await(0,e.reportError)(new Error(s)),s}catch(t){return console.warn(`Cannot handle error: ${t.message}`),t.message}},{APIS:{ASSETS_API:{BASE_URL:N,ENDPOINTS:{USERS:T,CERTIFICATES:A}}}}=a;var h={certificates:{create:async(t,e)=>{let r=[];try{const{data:a}=await I().post(`${N}${T}/${t}${A}`,e);a&&(r=a)}catch(t){await g(t)}return r}}};const{APIS:{AUTH_API:{BASE_URL:y,ENDPOINTS:{USER_PASSWORD:P,USERS:R}}},USERS:{MYSELF:f}}=a;var U={userPassword:{update:async t=>{let e=null;try{e=await I().put(`${y}${R}/${f}${P}`,t)}catch(t){e={message:(((t||{}).response||{}).data||{}).message},await g(t)}return e}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:O,ENDPOINTS:{ANSWERS:m,QUESTIONS:L,LIKES:$}}}}=a,C=`${O}${L}`;var _={create:async({questionSlug:t},e)=>{try{await I().post(`${C}/${encodeURIComponent(t)}${m}`,e)}catch(t){const e=await g(t);throw new Error(e)}},remove:async({questionSlug:t,answerSlug:e})=>{try{await I().delete(`${C}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}`)}catch(t){const e=await g(t);throw new Error(e)}},update:async({questionSlug:t,answerSlug:e},r)=>{try{return await I().put(`${C}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}`,r)}catch(t){const e=await g(t);throw new Error(e)}},like:async({questionSlug:t,answerSlug:e})=>{try{return await I().post(`${C}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}${$}`)}catch(t){const e=await g(t);throw new Error(e)}},unlike:async({questionSlug:t,answerSlug:e})=>{try{return await I().delete(`${C}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}${$}`)}catch(t){const e=await g(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:D,ENDPOINTS:{QUESTIONS:v}}}}=a,b=`${D}${v}`;var q={create:async t=>{try{return await I().post(b,t)}catch(t){const e=await g(t);throw new Error(e)}},remove:async({questionSlug:t})=>{try{await I().delete(`${b}/${encodeURIComponent(t)}`)}catch(t){const e=await g(t);throw new Error(e)}},update:async({questionSlug:t},e)=>{try{return await I().put(`${b}/${encodeURIComponent(t)}`,e)}catch(t){const e=await g(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:B,ENDPOINTS:{REPLIES:M,ANSWERS:G,QUESTIONS:Y,LIKES:x}}}}=a,V=`${B}${Y}`,F=({questionSlug:t,answerSlug:e,replySlug:r},a=!1)=>{let n=`${V}/${encodeURIComponent(t)}${G}/${encodeURIComponent(e)}${M}`;return r&&(n=`${n}/${encodeURIComponent(r)}`,a&&(n=`${n}${x}`)),n};var k={create:async({questionSlug:t,answerSlug:e},r)=>{try{return await I().post(F({questionSlug:t,answerSlug:e}),r)}catch(t){const e=await g(t);throw new Error(e)}},update:async({questionSlug:t,answerSlug:e,replySlug:r},a)=>{try{return await I().put(F({questionSlug:t,answerSlug:e,replySlug:r}),a)}catch(t){const e=await g(t);throw new Error(e)}},remove:async({questionSlug:t,answerSlug:e,replySlug:r})=>{try{await I().delete(F({questionSlug:t,answerSlug:e,replySlug:r}))}catch(t){const e=await g(t);throw new Error(e)}},like:async({questionSlug:t,answerSlug:e,replySlug:r})=>{try{await I().post(F({questionSlug:t,answerSlug:e,replySlug:r},!0))}catch(t){const e=await g(t);throw new Error(e)}},unlike:async({questionSlug:t,answerSlug:e,replySlug:r})=>{try{await I().delete(F({questionSlug:t,answerSlug:e,replySlug:r},!0))}catch(t){const e=await g(t);throw new Error(e)}},getReplyUrl:F};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:Q,ENDPOINTS:{QUESTIONS:K,ANSWERS:W,LIKES:j}}}}=a,H=`${Q}${K}`;var X={answers:_,questions:q,replies:k,likes:{create:async(t,e)=>{try{return await I().post(`${H}/${encodeURIComponent(t)}${W}/${encodeURIComponent(e)}${j}`)}catch(t){const e=await g(t);throw new Error(e)}},remove:async(t,e)=>{try{return await I().delete(`${H}/${encodeURIComponent(t)}${W}/${encodeURIComponent(e)}${j}`)}catch(t){const e=await g(t);throw new Error(e)}}}};const{APIS:{MANAGEMENT_API:{BASE_URL:J,ENDPOINTS:{ACCOUNTS:z}}}}=a;var Z={create:async t=>{try{await I().post(`${J}${z}`,t)}catch(t){throw await g(t),t}},read:async t=>{let e=null;try{({data:e}=await I().get(`${J}${z}/${encodeURIComponent(t)}`))}catch(t){await g(t)}return e},update:async(t,e)=>{try{await I().put(`${J}${z}/${encodeURIComponent(t)}`,e)}catch(t){throw await g(t),t}}};const{APIS:{MANAGEMENT_API:{BASE_URL:tt,ENDPOINTS:{EVENT_REGISTRATIONS:et}}}}=a;var rt={create:async t=>{try{await I().post(`${tt}${et}`,t)}catch(t){const e=await g(t);throw new Error(e)}}};const{APIS:{MANAGEMENT_API:{BASE_URL:at,ENDPOINTS:{LOGINS:nt,LOGIN_PASSWORDLESS:st}}}}=a,ot=`${at}${nt}`;var it={accounts:Z,eventRegistrations:rt,passwordless:{update:async t=>{try{await I().put(`${ot}/${encodeURIComponent(t)}${st}`)}catch(t){throw await g(t),t}}}};const{APIS:{PAYMENTS_API:{BASE_URL_V2:ct,ENDPOINTS:{PRODUCTS:lt}}}}=a,ut=`${ct}${lt}`;var Et={products:{list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(ut,r);t&&t.length&&(e=t)}catch(t){await g(t)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL:St,ENDPOINTS:{BULK_ENROLMENTS:dt}}}}=a;var pt={list:async t=>{let e=[];try{const{data:r}=await I().get(`${St}${dt}`,{params:t});r&&r.length&&(e=r)}catch(t){await g(t)}return e}},wt=c(25);const{OK:It,MULTIPLE_CHOICES:gt,NOT_FOUND:Nt,FORBIDDEN:Tt}=wt.StatusCodes,At=t=>t>=It&&t<gt||t===Tt||t===Nt,{APIS:{PEOPLE_API:{BASE_URL_V2:ht,ENDPOINTS:{USERS:yt}}}}=a,Pt=async t=>{let e=null;try{const{data:r}=await I().get(`${ht}${yt}/${encodeURIComponent(t)}`,{validateStatus:At});r&&r.id&&(e=r)}catch(t){await g(t)}return e},Rt=async t=>{let e=[];try{if(t&&t.length<2)throw new Error("users list method requires at least two ids");const r=t.map((t=>`ids=${encodeURIComponent(t)}`)).join("&"),a=await I().get(`${ht}${yt}?${r}`,{validateStatus:At});a&&a.length&&(e=a)}catch(t){await g(t)}return e};var ft={read:Pt,update:async(t,e)=>{let r=!1;try{const{data:a}=await I().put(`${ht}${yt}/${encodeURIComponent(t)}`,e);r=!(!a||!a.id)}catch(t){await g(t)}return r},list:Rt};const{APIS:{PEOPLE_API:{BASE_URL_V2:Ut,ENDPOINTS:{USERS:Ot,USER_LIKES:mt}}},USERS:{MYSELF:Lt}}=a,$t=`${Ut}${Ot}/${Lt}${mt}`,Ct=async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get($t,r);t&&t.length&&(e=t)}catch(t){await g(t)}return e};var _t={list:Ct};var Dt={authors:{readQuestionAuthors:async(t,e,r)=>{try{if(t.author=await Pt(t.authorId),t.answers&&t.answers.length&&!r.ignoreAnswersAuthors){t.answers.sort(((t,e)=>new Date(e.updatedAt)-new Date(t.updatedAt))),t.totalAnswers=t.answers.length;let n=t.answers;if(r.limit&&r.pageNumber){const e=r.limit*(r.pageNumber-1);n=t.answers.slice(e,e+r.limit)}for(let t of n){t.author=t.authorId&&await Pt(t.authorId)||{};const[r]=e?await Ct({contentType:a.CONTENTFUL.ANSWERS.TYPE,contentSlug:t.slug}):[null];t.userLiked=!!r}t.answers=n}else t.answers||(t.answers=[]);return t}catch(t){throw await g(t),new Error(`Cannot read authors for question: ${t.message}`)}},readAuthors:async(t=[])=>{let e=[];try{if(!1===Array.isArray(t))throw new Error("authorIds is not an array!");if(t&&1===t.length){const r=await Pt(t[0]);r&&e.push(r)}else if(t&&t.length>1){const r=await Rt(t);r&&r.length>0&&(e=r)}}catch(t){throw await g(t),new Error(`Cannot read authors: ${t.message}`)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL:vt,ENDPOINTS:{REGISTRATIONS:bt}}}}=a;var qt={list:async t=>{let e=[];try{const{data:r}=await I().get(`${vt}${bt}`,{params:t});r&&r.length&&(e=r)}catch(t){await g(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Bt,ENDPOINTS:{USERS:Mt,USER_COURSES:Gt}}},USERS:{MYSELF:Yt}}=a,xt=`${Bt}${Mt}/${Yt}${Gt}`;var Vt={create:async t=>{try{await I().post(xt,t)}catch(t){await g(t)}},list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(xt,r);t&&t.length&&(e=t)}catch(t){await g(t)}return e},update:async(t,e)=>{try{await I().put(`${xt}/${t}`,e)}catch(t){await g(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Ft,ENDPOINTS:{USERS:kt,USER_EVENTS:Qt}}},USERS:{MYSELF:Kt}}=a,Wt=`${Ft}${kt}/${Kt}${Qt}`;var jt={list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(Wt,r);t&&t.length&&(e=t)}catch(t){await g(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Ht,ENDPOINTS:{USERS:Xt,USER_LESSONS:Jt}}},USERS:{MYSELF:zt}}=a,Zt=`${Ht}${Xt}/${zt}${Jt}`;var te={create:async t=>{let e=null;try{e=await I().post(Zt,t)}catch(t){await g(t)}return e},list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(Zt,r);t&&t.length&&(e=t)}catch(t){await g(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:ee,ENDPOINTS:{USERS:re,USER_PRODUCTS:ae}}},USERS:{MYSELF:ne}}=a,se=`${ee}${re}/${ne}${ae}`;var oe={bulkEnrolments:pt,handlers:Dt,registrations:qt,users:ft,userCourses:Vt,userEvents:jt,userLessons:te,userLikes:_t,userProducts:{create:async t=>{let e=null;try{e=await I().post(se,t)}catch(t){await g(t)}return e},list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(se,r);t&&t.length&&(e=t)}catch(t){await g(t)}return e},update:async(t,e)=>{try{await I().put(`${se}/${t}`,e)}catch(t){await g(t)}}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:ie,ENDPOINTS:{ENQUIRY_EMAILS:ce}}}}=a;var le={create:async t=>{let e=null;try{const{data:r}=await I().post(`${ie}${ce}`,t);r&&(e=r)}catch(t){await g(t)}return e}},ue={forms:{sendEnquiryEmails:async t=>{let e=null;try{const{emailIds:r}=p;e=await we.emails.create({...r,...t})}catch(t){await g(t)}return e}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:Ee,ENDPOINTS:{USERS:Se,USER_PROPERTIES:de}}},USERS:{MYSELF:pe}}=a;var we={emails:le,handlers:ue,userProperties:{update:async(t,e)=>{try{await I().put(`${Ee}${Se}/${pe}${de}/${t}`,e)}catch(t){await g(t)}}}};const{CONTENTFUL:Ie}=a,{CARD_TYPES:ge}=Ie.CAROUSELS,Ne={read:async(e,r)=>{try{if(!r||!r.sys||!r.sys.id)throw new Error("Invalid link to card");if(!e||!ge[e])throw new Error("Unsupported card content type");const{INCLUDE:a,SELECT:n}=ge[e];return await(0,t.getEntry)({content_type:e,"sys.id":r.sys.id,include:a,select:n},{assetDetails:!0})}catch(t){throw await g(t),new Error(`Cannot read carousel card: ${t.message}`)}}};var Te=Ne;const{CONTENTFUL:Ae}=a,{INCLUDE:he,SELECT:ye,TYPE:Pe}=Ae.EDITORIAL_PAGES;var Re={read:async e=>{try{return await(0,t.getEntry)({content_type:Pe,"fields.slug":e,include:he,select:ye})}catch(t){throw await g(t),new Error(`Cannot read editorial page: ${t.message}`)}}};const{CONTENTFUL:fe}=a,{TYPE:Ue,ORDER:Oe,SELECT:me,SKIP:Le,LIMIT:$e,INCLUDE:Ce}=fe.QUESTIONS;var _e={read:async e=>{try{return await(0,t.getEntry)({content_type:Ue,"fields.slug":e,include:2,select:me})}catch(t){throw await g(t),new Error(`Cannot read question: ${t.message}`)}},list:async(e={})=>{try{return await(0,t.getEntries)({content_type:Ue,include:Ce,limit:$e,order:Oe,select:me,skip:Le,"fields.private[ne]":!0,...e})}catch(t){throw await g(t),new Error(`Cannot list questions: ${t.message}`)}}},De=async(t,e,r={ignoreAnswersAuthors:!1})=>{try{let a={};return a=await _e.read(t),a=await oe.handlers.authors.readQuestionAuthors(a,e,r),a}catch(t){throw await g(t),new Error(`Cannot build question: ${t.message}`)}};const{ARTICLES:{TYPE:ve},COURSES:{TYPE:be},EVENTS:{TYPE:qe},LISTS:{TYPE:Be},QUESTIONS:{TYPE:Me}}=a.CONTENTFUL,Ge=t=>t&&t.url?(Object.assign(t,{aspect:"responsiveCard",query:"q=90&fit=fill"}),t):null,Ye={[ve]:async t=>{const{authorIds:e,authorTag:r,image:a,publishedDate:n,readingTime:s,slug:o,title:i}=t,c=await oe.handlers.authors.readAuthors(e),l=c&&c.length?c:r?[r]:null;return{banner:Ge(a),contributors:l,publishedDate:n,readingTime:s,slug:o,title:i}},[be]:async(t,e)=>{const{banner:r,freeCourse:a,partnershipDetails:n,slug:s,title:o,registered:i}=t,c={banner:Ge(r),slug:s,title:o,pill:a?"free":"premium",registered:!!i};if(n){const{partners:t}=n;c.partner=t&&t.length&&n.partners[0]}if(void 0===i&&e){const[t]=await oe.userProducts.list({courseSlug:s,isEnrolled:!0,scope:"active"});c.registered=!!t}return c},[qe]:async(t,e)=>{const{bannerImage:r,defaultStartDate:a,isEventOngoing:n,slug:s,speakers:o,title:i,registered:c}=t,l=new Date(a),u=!!l&&l<new Date;if(o&&o.length)for(const t of o)t.image=(E=t.image)&&E.url?`${E.url}?w=100&h=100&fit=thumb&f=center`:null;var E;const S={banner:Ge(r),dateHasPassed:u,title:i,slug:s,isOngoingEvent:n,contributors:o,startDate:l,registered:!!c};if(void 0===c&&e){const[t]=await oe.userEvents.list({eventSlug:s});S.registered=!!t}return S},[Be]:async t=>{const{hero:e,slug:r,title:a}=t;return{banner:Ge(e),slug:r,title:a}},[Me]:async t=>{const{answers:e,authorId:r,createdAt:a,slug:n,title:s}=t;let o=null;if(r){const t=await oe.users.read(r);t&&(o=t)}return{answers:e&&e.length?e.length:0,contributors:o?[o]:[],createdAt:a,slug:n,title:s}}};var xe=async({contentType:t,...e}={},r)=>{try{if(!Ye[t])throw new Error("Content type not supported");if("function"!=typeof Ye[t])throw new Error("No builder function for content type");return e.sys&&e.sys.type&&"Link"===e.sys.type&&(e=await Te.read(t,e)),{contentType:t,...await Ye[t](e,r)}}catch(t){throw await g(t),new Error(`Cannot build carousel card: ${t.message}`)}},Ve=async(t,e,r={})=>{try{if(!t.replies||0===t.replies.length)return t.replies=[],t;t.replies.sort(((t,e)=>new Date(t.createdAt)-new Date(e.createdAt))),t.totalReplies=t.totalReplies||t.replies.length;let n=t.replies;if(r.limit&&r.pageNumber){const e=r.limit*(r.pageNumber-1);n=t.replies.slice(e,e+r.limit)}for(const r of n){if(r.authorId===t.authorId){r.author=t.author,r.userLiked=!1;continue}r.author=r.authorId&&await Pt(r.authorId)||{};const[n]=e?await Ct({contentType:a.CONTENTFUL.REPLIES.TYPE,contentSlug:r.slug}):[null];r.userLiked=!!n}return t.replies=n,t}catch(t){throw await g(t),new Error(`Cannot build replies for answer: ${t.message}`)}},Fe=c(408);const ke=t=>t&&Fe.Buffer.from(t,"base64").toString("ascii");function Qe({contentContext:a=null,errorsContext:c=null,gtmContext:l=null,origin:w}){try{const I=(t=>{let e=null;t?e=t:"undefined"!=typeof window&&(e=window.origin||window.location.origin),e||new Error("Cannot select environment: Website not defined");let r=null;const a=e.match(o);return a?r=a[1].split(i)[0]:e===n?r=u:e.includes(s)&&(r=E),r||new Error(`Cannot select environment: No rule for website ${e}`),r})(w);return a&&(0,t.setContext)(Object.assign({},a,{environment:I})),c&&(0,e.setContext)(Object.assign({},c,{environment:I})),l&&((0,r.setContext)(Object.assign({},l,{environment:I})),(0,r.setupGTM)()),(({environment:t})=>{const e=(t=>{if(!t)throw new Error("Cannot map environment: Environment not defined");if(!S[t])throw new Error(`Cannot map environment: No mapping found for environment ${t}`);return S[t]})(t);p.emailIds=d[e]})(Object.assign({},{environment:I})),I}catch(t){console.warn(`Cannot load SDK: ${t.message}`)}}}(),l}()}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apolitical/sdk",
3
- "version": "7.3.0-beta.0",
3
+ "version": "7.3.1-beta.0",
4
4
  "description": "Browser library to interact with Apolitical's APIs",
5
5
  "author": "Apolitical Group Limited <engineering@apolitical.co>",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "lint": "eslint --ext .js ./lib",
17
17
  "format": "prettier --write 'lib/**/*.+(js|json)'",
18
18
  "lint-format": "lint-staged",
19
- "prepare": "husky install",
19
+ "prepare": "cd ../../../ && husky install modules/v1/apolitical-sdk/.husky",
20
20
  "prepack": "yarn build"
21
21
  },
22
22
  "keywords": [
@@ -112,4 +112,4 @@
112
112
  "prettier --single-quote --write --ignore-path .gitignore"
113
113
  ]
114
114
  }
115
- }
115
+ }
package/CHANGELOG.md DELETED
@@ -1,255 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [7.3.0] - 2023-05-04
9
- ### Changed
10
- - Update `buildRepliesForAnswer` to order replies chronologically.
11
-
12
- ## [7.2.0] - 2023-04-20
13
- ### Added
14
- - `buildRepliesForAnswer` fxn to...build replies for an answer
15
-
16
- ## [7.1.0] - 2023-04-20
17
- ### Removed
18
- - `content-suggestions` API resources
19
-
20
- ## [7.0.0] - 2023-04-18
21
- ### Added
22
- - list to user resources
23
- - readAuthors to authors handlers
24
- - removed buildQuestions to solvers
25
-
26
- ## [6.0.0] - 2023-04-04
27
- ### Added
28
- - Exposed Create, Update, Delete, (Un)Like for Replies on content-interaction-api
29
-
30
- ### Changed
31
- - Added (un)like of Answers inside of the Answers resource for content-interaction-api
32
- - Deprecate the create/delete of likes for Answers in the likes resource
33
- - Deprecate userAnswers resource in favour of userLikes
34
- - Update buildQuestion to work with userLikes resource
35
-
36
- ## [5.0.1] - 2023-03-21
37
- ### Changed
38
- - `@apolitical/content` version
39
-
40
- ## [5.0.0] - 2023-03-21
41
- ### Added
42
- - Support for paginated answers
43
-
44
- ## [4.2.0] - 2023-03-15
45
- ### Added
46
- - API call to expose POST `/event-registrations` request on the Management API
47
-
48
- ## [4.1.4] - 2023-03-16
49
- ### Fixed
50
- - buildCarouselCard to handle event email boot camps
51
- ### Changed
52
- - qaQuestions sort by createdAt field instead of updatedAt
53
-
54
- ## [4.1.3] - 2023-03-15
55
- ### Fixed
56
- - buildCarouselCard to handle event speakers
57
-
58
- ## [4.1.2] - 2023-03-06
59
- ### Changed
60
- - buildCarouselCard to handle registered courses and events
61
-
62
- ## [4.1.1] - 2023-02-09
63
- ### Added
64
- - Entry support for buildCarouselCard
65
-
66
- ## [4.1.0] - 2023-02-06
67
- ### Added
68
- - Functionality to read an editorial page
69
- - Functionality to build slider card
70
-
71
- ## [4.0.1] - 2023-01-31
72
- ### Added
73
- - Renovate config file
74
-
75
- ## [4.0.0] - 2023-01-24
76
- ### Removed
77
- - Use of `@apolitical/auth` on the SDK
78
-
79
- ## [3.1.1] - 2023-01-18
80
- ### Changed
81
- - apolitical/content version to 0.7.0
82
-
83
- ## [3.1.0] - 2023-01-12
84
- ### Added
85
- - Functionality to resend verification code (starts passwordless login)
86
-
87
- ## [3.0.2] - 2023-01-05
88
- ### Changed
89
- - Creating a question returns the question
90
- - buildQuestion and readQuestionAuthors takes an optional arg `ignoreAnswersAuthors` (to not request answer author info if unnecessary to reduce People API calls)
91
- - buildQuestions and Listing questions takes an optional arg `query` to filter
92
-
93
- ## [3.0.1] - 2022-12-14
94
- ### Added
95
- - Filter to exclude private questions from qaQuestions list method
96
-
97
- ## [3.0.0] - 2022-12-06
98
- ### Added
99
- - Solver methods: `buildQuestion` and `buildQuestions`
100
- - Likes to contentInteraction resources
101
- - userAnswers to people resources
102
- - Contentful API
103
- ### Changed
104
- - Error handling in for answers and questions resources
105
- - questions to qaQuestions in contentful (breaking change)
106
-
107
- ## [2.0.0] - 2022-10-21
108
- ### Fixed
109
- - GTM dependency import and setup optimisation
110
-
111
- ## [1.1.0] - 2022-10-20
112
- ### Added
113
- - `peopleEngagement/emails` resource
114
- - `peopleEngagement` form handlers
115
-
116
- ## [1.0.0] - 2022-10-20
117
- ### Changed
118
- - `people` resource to use v2 endpoints
119
- ### Added
120
- - `contentSuggestion` resource
121
- - `auth` resource
122
- - `contentInteraction` resource
123
- - `payments` resource
124
-
125
- ## [0.11.2] - 2022-10-04
126
- ### Updated
127
- - apolitical-content version
128
-
129
- ## [0.11.1] - 2022-10-07
130
- ### Updated
131
- - Internal dependencies (Apolitical Content)
132
-
133
- ## [0.11.0] - 2022-09-02
134
- ### Updated
135
- - Internal dependencies (Apolitical modules)
136
-
137
- ## [0.10.0] - 2022-08-04
138
- ### Added
139
- - List, Update and Create user products to people resources
140
-
141
- ## [0.9.3] - 2022-06-28
142
- ### Changed
143
- - Pipeline refs
144
-
145
- ## [0.9.2] - 2022-05-19
146
- ### Changed
147
- - Use `apolitical/gtm` version `v1.2.0`
148
-
149
- ## [0.9.1] - 2022-05-13
150
- ### Fixed
151
- - Error handling on select environment function
152
-
153
- ## [0.9.0] - 2022-05-11
154
- ### Added
155
- - Global environment definition to avoid duplication on other modules
156
-
157
- ## [0.8.7] - 2022-04-25
158
- ### Changed
159
- - `@apolitical/auth` version
160
-
161
- ## [0.8.6] - 2022-04-19
162
- ### Fixed
163
- - Conditional when checking if data is returning from create certificate
164
-
165
- ## [0.8.5] - 2022-04-13
166
- ### Changed
167
- - Create user lesson to return response from people-api
168
-
169
- ## [0.8.4] - 2022-04-08
170
- ### Added
171
- - Use `apolitical/gtm` version `v1.0.1`
172
-
173
- ## [0.8.3] - 2022-04-07
174
- ### Added
175
- - Create user lesson
176
- - List user lesson
177
-
178
- ## [0.8.2] - 2022-04-07
179
- ### Added
180
- - Add `apolitical/gtm` module to set up GTM context
181
-
182
- ## [0.8.1] - 2022-03-28
183
- ### Added
184
- - Create user certificate
185
- - Update user course
186
-
187
- ## [0.8.0] - 2022-03-24
188
- ### Changed
189
- - Use `me` rather than passing in a `userSlug` as params when creating a user course
190
- ### Added
191
- - List user course
192
-
193
- ## [0.7.1] - 2022-03-22
194
- ### Fixed
195
- - Updated version in package.json
196
-
197
- ## [0.7.0] - 2022-03-22
198
- ### Added
199
- - Create user course
200
- - Update user property
201
-
202
- ## [0.6.0] - 2022-03-09
203
- ### Added
204
- - List registrations
205
-
206
- ## [0.5.1] - 2022-03-08
207
- ### Updated
208
- - @apolitical/auth version
209
-
210
- ## [0.5.0] - 2022-03-03
211
- ### Added
212
- - Update account functionality
213
-
214
- ## [0.4.1] - 2022-02-28
215
- ### Added
216
- - Expose `sendVerificationEmail` from auth module
217
- ### Changed
218
- - Create account to only call Management API
219
-
220
- ## [0.4.0] - 2022-02-22
221
- ### Added
222
- - Auth0 Web Auth
223
- - Create account in Management API
224
-
225
- ## [0.3.0] - 2022-02-08
226
- ### Added
227
- - Management API Accounts Resource
228
-
229
- ## [0.2.0] - 2022-02-01
230
- ### Changed
231
- - SDK interface
232
-
233
- ## [0.1.0] - 2022-01-31
234
- ### Fixed
235
- - Buffer dependency
236
- - Node.js version
237
- ### Added
238
- - Decode base64 functionality
239
- - Apolitical content
240
- ### Removed
241
- - Template example
242
-
243
- ## [0.0.3] - 2022-01-12
244
- ### Added
245
- - Exposed `reportError` function
246
- ### Fixed
247
- - Resources naming (must be plural)
248
-
249
- ## [0.0.2] - 2022-01-06
250
- ### Added
251
- - First example function `ping`
252
-
253
- ## [0.0.1] - 2022-01-05
254
- ### Added
255
- - Initial setup