@apolitical/sdk 7.5.3-beta.1 → 7.5.4

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.
Files changed (2) hide show
  1. package/build/index.js +1 -1
  2. package/package.json +1 -1
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("socket.io-client"),require("buffer")):"function"==typeof define&&define.amd?define(["@apolitical/content","@apolitical/error-reporting","@apolitical/gtm","axios","http-status-codes","socket.io-client","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("socket.io-client"),require("buffer")):t.ApoliticalSDK=e(t["@apolitical/content"],t["@apolitical/error-reporting"],t["@apolitical/gtm"],t.axios,t["http-status-codes"],t["socket.io-client"],t.buffer)}(this,(function(t,e,a,n,r,s,o){return function(){"use strict";var i={809:function(e){e.exports=t},30:function(t){t.exports=e},36:function(t){t.exports=a},300:function(t){t.exports=n},408:function(t){t.exports=o},25:function(t){t.exports=r},130:function(t){t.exports=s}},c={};function l(t){var e=c[t];if(void 0!==e)return e.exports;var a=c[t]={exports:{}};return i[t](a,a.exports,l),a.exports}l.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return l.d(e,{a:e}),e},l.d=function(t,e){for(var a in e)l.o(e,a)&&!l.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:e[a]})},l.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},l.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var u={};return function(){l.r(u),l.d(u,{assets:function(){return y},auth:function(){return U},buildAnswer:function(){return Ra},buildCarouselCard:function(){return Pa},buildQuestion:function(){return da},carouselCards:function(){return Ze},contentInteraction:function(){return X},decodeBase64:function(){return $a},default:function(){return Ua},editorialPages:function(){return ra},features:function(){return tt},getEntries:function(){return t.getEntries},getEntry:function(){return t.getEntry},management:function(){return It},payments:function(){return At},people:function(){return Te},peopleEngagement:function(){return me},qaQuestions:function(){return Sa},reportError:function(){return e.reportError},search:function(){return ve},socials:function(){return We}});var t=l(809),e=l(30),a=l(36),n={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"}},FEATURES_API:{BASE_URL:"/api/features-api",ENDPOINTS:{FLAGS:"/features"}},MANAGEMENT_API:{BASE_URL:"/api/management-api",ENDPOINTS:{ACCOUNTS:"/accounts",EVENT_REGISTRATIONS:"/event-registrations",LOGINS:"/logins",LOGIN_PASSWORDLESS:"/passwordless",BULK_ENROLMENTS:"/bulk-enrolments"}},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_RATINGS:"/ratings",USER_SUBSCRIPTIONS:"/subscriptions"}},PEOPLE_ENGAGEMENT_API:{BASE_URL:"/api/people-engagement-api",ENDPOINTS:{ENQUIRY_EMAILS:"/enquiry-emails",USERS:"/users",USER_PROPERTIES:"/properties"}},SEARCH_API:{BASE_URL:"/api/search-api",ENDPOINTS:{SEARCH:"/search"}},SOCIALS_API:{BASE_URL:"/api/socials-api",ENDPOINTS:{COMMUNITIES:"/communities"}}},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,fields.projectNames"},learningHub:{INCLUDE:1,SELECT:"fields.bannerSection,fields.customLabel,fields.slug,fields.title"}}},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,fields.projectNames",SKIP:0},ANSWERS:{TYPE:"qaAnswer"},REPLIES:{TYPE:"reply"},LEARNING_HUB:{TYPE:"learningHub"}},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:r,LOCALHOST:s,STAGING:o,STAGING_SPLITTER:i},ENVIRONMENTS:{PRODUCTION:c,LOCAL:E}}}=n,{HUBSPOT:{ENVIRONMENTS_MAPPING:S,EMAIL_IDS:d}}=n;let I={emailIds:{}};var p=l(300),w=l.n(p);const N=async t=>{try{const{message:a,response:n,request:r}=t;let s=a;return n?s+=` - The request was made and the server responded with ${JSON.stringify({status:n.status,data:n.data})}`:r&&(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:A,ENDPOINTS:{USERS:T,CERTIFICATES:g}}}}=n;var y={certificates:{create:async(t,e)=>{let a=[];try{const{data:n}=await w().post(`${A}${T}/${t}${g}`,e);n&&(a=n)}catch(t){await N(t)}return a}}};const{APIS:{AUTH_API:{BASE_URL:P,ENDPOINTS:{USER_PASSWORD:R,USERS:h}}},USERS:{MYSELF:$}}=n;var U={userPassword:{update:async t=>{let e=null;try{e=await w().put(`${P}${h}/${$}${R}`,t)}catch(t){e={message:(((t||{}).response||{}).data||{}).message},await N(t)}return e}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:f,ENDPOINTS:{ANSWERS:m,QUESTIONS:L,LIKES:O}}}}=n,C=`${f}${L}`;var _={create:async({questionSlug:t},e)=>{try{await w().post(`${C}/${encodeURIComponent(t)}${m}`,e)}catch(t){const e=await N(t);throw new Error(e)}},remove:async({questionSlug:t,answerSlug:e})=>{try{await w().delete(`${C}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}`)}catch(t){const e=await N(t);throw new Error(e)}},update:async({questionSlug:t,answerSlug:e},a)=>{try{return await w().put(`${C}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}`,a)}catch(t){const e=await N(t);throw new Error(e)}},like:async({questionSlug:t,answerSlug:e},a)=>{try{return await w().post(`${C}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}${O}`,a)}catch(t){const e=await N(t);throw new Error(e)}},unlike:async({questionSlug:t,answerSlug:e})=>{try{return await w().delete(`${C}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}${O}`)}catch(t){const e=await N(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:v,ENDPOINTS:{QUESTIONS:D}}}}=n,b=`${v}${D}`;var B={create:async t=>{try{return await w().post(b,t)}catch(t){const e=await N(t);throw new Error(e)}},remove:async({questionSlug:t})=>{try{await w().delete(`${b}/${encodeURIComponent(t)}`)}catch(t){const e=await N(t);throw new Error(e)}},update:async({questionSlug:t},e)=>{try{return await w().put(`${b}/${encodeURIComponent(t)}`,e)}catch(t){const e=await N(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:M,ENDPOINTS:{REPLIES:q,ANSWERS:G,QUESTIONS:Y,LIKES:k}}}}=n,x=`${M}${Y}`,V=({questionSlug:t,answerSlug:e,replySlug:a},n=!1)=>{let r=`${x}/${encodeURIComponent(t)}${G}/${encodeURIComponent(e)}${q}`;return a&&(r=`${r}/${encodeURIComponent(a)}`,n&&(r=`${r}${k}`)),r};var F={create:async({questionSlug:t,answerSlug:e},a)=>{try{return await w().post(V({questionSlug:t,answerSlug:e}),a)}catch(t){const e=await N(t);throw new Error(e)}},update:async({questionSlug:t,answerSlug:e,replySlug:a},n)=>{try{return await w().put(V({questionSlug:t,answerSlug:e,replySlug:a}),n)}catch(t){const e=await N(t);throw new Error(e)}},remove:async({questionSlug:t,answerSlug:e,replySlug:a})=>{try{await w().delete(V({questionSlug:t,answerSlug:e,replySlug:a}))}catch(t){const e=await N(t);throw new Error(e)}},like:async({questionSlug:t,answerSlug:e,replySlug:a},n)=>{try{await w().post(V({questionSlug:t,answerSlug:e,replySlug:a},!0),n)}catch(t){const e=await N(t);throw new Error(e)}},unlike:async({questionSlug:t,answerSlug:e,replySlug:a})=>{try{await w().delete(V({questionSlug:t,answerSlug:e,replySlug:a},!0))}catch(t){const e=await N(t);throw new Error(e)}},getReplyUrl:V};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:j,ENDPOINTS:{QUESTIONS:H,ANSWERS:K,LIKES:Q}}}}=n,W=`${j}${H}`;var X={answers:_,questions:B,replies:F,likes:{create:async(t,e)=>{try{return await w().post(`${W}/${encodeURIComponent(t)}${K}/${encodeURIComponent(e)}${Q}`)}catch(t){const e=await N(t);throw new Error(e)}},remove:async(t,e)=>{try{return await w().delete(`${W}/${encodeURIComponent(t)}${K}/${encodeURIComponent(e)}${Q}`)}catch(t){const e=await N(t);throw new Error(e)}}}};const{APIS:{FEATURES_API:{BASE_URL:J,ENDPOINTS:{FLAGS:z}}}}=n,Z=`${J}${z}`;var tt={flags:{read:async t=>{let e=null;try{const{data:a}=await w().get(`${Z}/${encodeURIComponent(t)}`);a?.name&&a?.featureState&&(e=a)}catch(t){await N(t)}return e}}};const{APIS:{MANAGEMENT_API:{BASE_URL:et,ENDPOINTS:{ACCOUNTS:at}}}}=n;var nt={create:async t=>{try{await w().post(`${et}${at}`,t)}catch(t){throw await N(t),t}},read:async t=>{let e=null;try{({data:e}=await w().get(`${et}${at}/${encodeURIComponent(t)}`))}catch(t){await N(t)}return e},update:async(t,e)=>{try{await w().put(`${et}${at}/${encodeURIComponent(t)}`,e)}catch(t){throw await N(t),t}}};const{APIS:{MANAGEMENT_API:{BASE_URL:rt,ENDPOINTS:{BULK_ENROLMENTS:st}}}}=n;var ot={create:async t=>{try{await w().post(`${rt}${st}`,t)}catch(t){throw await N(t),t}}};const{APIS:{MANAGEMENT_API:{BASE_URL:it,ENDPOINTS:{EVENT_REGISTRATIONS:ct}}}}=n;var lt={create:async t=>{try{await w().post(`${it}${ct}`,t)}catch(t){const e=await N(t);throw new Error(e)}}};const{APIS:{MANAGEMENT_API:{BASE_URL:ut,ENDPOINTS:{LOGINS:Et,LOGIN_PASSWORDLESS:St}}}}=n,dt=`${ut}${Et}`;var It={accounts:nt,bulkEnrolments:ot,eventRegistrations:lt,passwordless:{update:async t=>{try{await w().put(`${dt}/${encodeURIComponent(t)}${St}`)}catch(t){throw await N(t),t}}}};const{APIS:{PAYMENTS_API:{BASE_URL_V2:pt,ENDPOINTS:{PRODUCTS:wt}}}}=n,Nt=`${pt}${wt}`;var At={products:{list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await w().get(Nt,a);t&&t.length&&(e=t)}catch(t){await N(t)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Tt,ENDPOINTS:{BULK_ENROLMENTS:gt}}}}=n;var yt={list:async t=>{let e=[];try{const{data:a}=await w().get(`${Tt}${gt}`,{params:t});a&&a.length&&(e=a)}catch(t){await N(t)}return e}},Pt=l(25);const{OK:Rt,MULTIPLE_CHOICES:ht,NOT_FOUND:$t,FORBIDDEN:Ut}=Pt.StatusCodes,ft=t=>t>=Rt&&t<ht||t===Ut||t===$t,{APIS:{PEOPLE_API:{BASE_URL_V2:mt,ENDPOINTS:{USERS:Lt}}}}=n,Ot=async t=>{let e=null;try{const{data:a}=await w().get(`${mt}${Lt}/${encodeURIComponent(t)}`,{validateStatus:ft});a&&a.id&&(e=a)}catch(t){await N(t)}return e},Ct=async t=>{let e=[];try{if(t&&t.length<2)throw new Error("users list method requires at least two ids");const a=t.map((t=>`ids=${encodeURIComponent(t)}`)).join("&"),n=await w().get(`${mt}${Lt}?${a}`,{validateStatus:ft});n&&n.length&&(e=n)}catch(t){await N(t)}return e};var _t={read:Ot,update:async(t,e)=>{let a=!1;try{const{data:n}=await w().put(`${mt}${Lt}/${encodeURIComponent(t)}`,e);a=!(!n||!n.id)}catch(t){await N(t)}return a},list:Ct};const{APIS:{PEOPLE_API:{BASE_URL_V2:vt,ENDPOINTS:{USERS:Dt,USER_LIKES:bt}}},USERS:{MYSELF:Bt}}=n,Mt=`${vt}${Dt}/${Bt}${bt}`,qt=async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await w().get(Mt,a);t&&t.length&&(e=t)}catch(t){await N(t)}return e};var Gt={list:qt};var Yt={authors:{readQuestionAuthors:async(t,e,a)=>{try{if(t.author=await Ot(t.authorId),t.answers&&t.answers.length&&!a.ignoreAnswersAuthors){t.answers.sort(((t,e)=>new Date(e.updatedAt)-new Date(t.updatedAt))),t.totalAnswers=t.answers.length;let r=t.answers;if(a.limit&&a.pageNumber){const e=a.limit*(a.pageNumber-1);r=t.answers.slice(e,e+a.limit)}for(let t of r){t.author=t.authorId&&await Ot(t.authorId)||{};const[a]=e?await qt({contentType:n.CONTENTFUL.ANSWERS.TYPE,contentSlug:t.slug}):[null];t.userLiked=!!a}t.answers=r}else t.answers||(t.answers=[]);return t}catch(t){throw await N(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 a=await Ot(t[0]);a&&e.push(a)}else if(t&&t.length>1){const a=await Ct(t);a&&a.length>0&&(e=a)}}catch(t){throw await N(t),new Error(`Cannot read authors: ${t.message}`)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL:kt,ENDPOINTS:{REGISTRATIONS:xt}}}}=n;var Vt={list:async t=>{let e=[];try{const{data:a}=await w().get(`${kt}${xt}`,{params:t});a&&a.length&&(e=a)}catch(t){await N(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Ft,ENDPOINTS:{USERS:jt,USER_COURSES:Ht}}},USERS:{MYSELF:Kt}}=n,Qt=`${Ft}${jt}/${Kt}${Ht}`;var Wt={create:async t=>{try{await w().post(Qt,t)}catch(t){await N(t)}},list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await w().get(Qt,a);t&&t.length&&(e=t)}catch(t){await N(t)}return e},update:async(t,e)=>{try{await w().put(`${Qt}/${t}`,e)}catch(t){await N(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Xt,ENDPOINTS:{USERS:Jt,USER_EVENTS:zt}}},USERS:{MYSELF:Zt}}=n,te=`${Xt}${Jt}/${Zt}${zt}`;var ee={list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await w().get(te,a);t&&t.length&&(e=t)}catch(t){await N(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:ae,ENDPOINTS:{USERS:ne,USER_LESSONS:re}}},USERS:{MYSELF:se}}=n,oe=`${ae}${ne}/${se}${re}`;var ie={create:async t=>{let e=null;try{e=await w().post(oe,t)}catch(t){await N(t)}return e},list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await w().get(oe,a);t&&t.length&&(e=t)}catch(t){await N(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:ce,ENDPOINTS:{USERS:le,USER_PRODUCTS:ue}}},USERS:{MYSELF:Ee}}=n,Se=`${ce}${le}/${Ee}${ue}`;var de={create:async t=>{let e=null;try{e=await w().post(Se,t)}catch(t){await N(t)}return e},list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await w().get(Se,a);t&&t.length&&(e=t)}catch(t){await N(t)}return e},update:async(t,e)=>{try{await w().put(`${Se}/${t}`,e)}catch(t){await N(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Ie,ENDPOINTS:{USERS:pe,USER_RATINGS:we}}},USERS:{MYSELF:Ne}}=n,Ae=`${Ie}${pe}/${Ne}${we}`;var Te={bulkEnrolments:yt,handlers:Yt,registrations:Vt,users:_t,userCourses:Wt,userEvents:ee,userLessons:ie,userLikes:Gt,userProducts:de,userRatings:{create:async t=>{let e=null;try{const{data:a}=await w().post(Ae,t);a?.id&&(e=a)}catch(t){await N(t)}return e},update:async(t,e)=>{try{await w().put(`${Ae}/${t}`,e)}catch(t){await N(t)}}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:ge,ENDPOINTS:{ENQUIRY_EMAILS:ye}}}}=n;var Pe={create:async t=>{let e=null;try{const{data:a}=await w().post(`${ge}${ye}`,t);a&&(e=a)}catch(t){await N(t)}return e}},Re={forms:{sendEnquiryEmails:async t=>{let e=null;try{const{emailIds:a}=I;e=await me.emails.create({...a,...t})}catch(t){await N(t)}return e}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:he,ENDPOINTS:{USERS:$e,USER_PROPERTIES:Ue}}},USERS:{MYSELF:fe}}=n;var me={emails:Pe,handlers:Re,userProperties:{update:async(t,e)=>{try{await w().put(`${he}${$e}/${fe}${Ue}/${t}`,e)}catch(t){await N(t)}}}},Le=l(130);const{APIS:{SEARCH_API:{BASE_URL:Oe,ENDPOINTS:{SEARCH:Ce}}}}=n,_e=`${Oe}${Ce}`;var ve={ask:async t=>{try{let e=null;const{data:a}=await w().get(_e,{params:{question:t}});return a?.answer&&a?.references&&a?.version&&(e=a),e}catch(t){const e=await N(t);throw new Error(e)}},stream:(t,e,a)=>{const n=(0,Le.io)(void 0,{path:"/api/search-api/web-sockets"});function r(){n.emit("search",{question:t})}function s(t){a(t),o(),n.disconnect()}function o(){n.off("connect",r),n.off("update",e),n.off("result",s)}return n.on("connect",r),n.on("update",e),n.on("result",s),o}};const{APIS:{SOCIALS_API:{BASE_URL:De,ENDPOINTS:{COMMUNITIES:be}}}}=n,Be=`${De}${be}`;var Me={read:async t=>{let e=null;try{const{data:a}=await w().get(`${Be}/${encodeURIComponent(t)}`);a?.title&&(e=a)}catch(t){await N(t)}return e},join:async(t,e)=>{let a=null;try{const{data:n}=await w().post(`${Be}/${encodeURIComponent(t)}/members`,e);a=n}catch(t){await N(t)}return a}};const{APIS:{SOCIALS_API:{BASE_URL:qe,ENDPOINTS:{COMMUNITIES:Ge}}}}=n,Ye=`${qe}${Ge}`;var ke={read:async(t,e={})=>{let a=null;try{const{data:n}=await w().get(`${Ye}/${encodeURIComponent(t)}/feed`,{params:e});n?.results&&(a=n.results)}catch(t){await N(t)}return a},create:async(t,e)=>{let a=null;try{const{data:n}=await w().post(`${Ye}/${encodeURIComponent(t)}/activities`,e);n?.content&&(a=n)}catch(t){await N(t)}return a},remove:async(t,e)=>{let a=null;try{const{data:n}=await w().delete(`${Ye}/${encodeURIComponent(t)}/activities/${e}`);a=n}catch(t){await N(t)}return a}};const{APIS:{SOCIALS_API:{BASE_URL:xe,ENDPOINTS:{COMMUNITIES:Ve}}}}=n,Fe=`${xe}${Ve}`;var je={create:async(t,e,a,n)=>{let r=null,s=`${Fe}/${encodeURIComponent(t)}`;s=e?`${s}/activities/${e}/reactions`:`${s}/reactions/${a}/reactions`;try{const{data:t}=await w().post(s,n);r=t}catch(t){await N(t)}return r},remove:async(t,e)=>{let a=null;try{const{data:n}=await w().delete(`${Fe}/${encodeURIComponent(t)}/reactions/${e}`);a=n}catch(t){await N(t)}return a}};const{APIS:{SOCIALS_API:{BASE_URL:He,ENDPOINTS:{COMMUNITIES:Ke}}}}=n,Qe=`${He}${Ke}`;var We={activities:ke,communities:Me,likes:{create:async(t,e,a)=>{let n=null;const r={kind:"like"};let s=`${Qe}/${encodeURIComponent(t)}`;s=e?`${s}/activities/${e}/reactions`:`${s}/reactions/${a}/reactions`;try{const{data:t}=await w().post(s,r);n=t}catch(t){await N(t)}return n},remove:async(t,e)=>{let a=null;try{const{data:n}=await w().delete(`${Qe}/${encodeURIComponent(t)}/reactions/${e}`);a=n}catch(t){await N(t)}return a}},reactions:je};const{CONTENTFUL:Xe}=n,{CARD_TYPES:Je}=Xe.CAROUSELS,ze={read:async(e,a)=>{try{if(!a||!a.sys||!a.sys.id)throw new Error("Invalid link to card");if(!e||!Je[e])throw new Error("Unsupported card content type");const{INCLUDE:n,SELECT:r}=Je[e];return await(0,t.getEntry)({content_type:e,"sys.id":a.sys.id,include:n,select:r},{assetDetails:!0})}catch(t){throw await N(t),new Error(`Cannot read carousel card: ${t.message}`)}}};var Ze=ze;const{CONTENTFUL:ta}=n,{INCLUDE:ea,SELECT:aa,TYPE:na}=ta.EDITORIAL_PAGES;var ra={read:async e=>{try{return await(0,t.getEntry)({content_type:na,"fields.slug":e,include:ea,select:aa})}catch(t){throw await N(t),new Error(`Cannot read editorial page: ${t.message}`)}}};const{CONTENTFUL:sa}=n,{TYPE:oa,ORDER:ia,SELECT:ca,SKIP:la,LIMIT:ua,INCLUDE:Ea}=sa.QUESTIONS;var Sa={read:async e=>{try{return await(0,t.getEntry)({content_type:oa,"fields.slug":e,include:2,select:ca})}catch(t){throw await N(t),new Error(`Cannot read question: ${t.message}`)}},list:async(e={})=>{try{return await(0,t.getEntries)({content_type:oa,include:Ea,limit:ua,order:ia,select:ca,skip:la,...e})}catch(t){throw await N(t),new Error(`Cannot list questions: ${t.message}`)}}},da=async(t,e,a={ignoreAnswersAuthors:!1})=>{try{let n={};return n=await Sa.read(t),n=await Te.handlers.authors.readQuestionAuthors(n,e,a),n}catch(t){throw await N(t),new Error(`Cannot build question: ${t.message}`)}};const{ARTICLES:{TYPE:Ia},COURSES:{TYPE:pa},EVENTS:{TYPE:wa},LISTS:{TYPE:Na},QUESTIONS:{TYPE:Aa},LEARNING_HUB:{TYPE:Ta}}=n.CONTENTFUL,ga=t=>t&&t.url?(Object.assign(t,{aspect:"responsiveCard",query:"q=90&fit=fill"}),t):null,ya={[Ia]:async t=>{const{authorIds:e,authorTag:a,image:n,publishedDate:r,readingTime:s,slug:o,title:i}=t,c=await Te.handlers.authors.readAuthors(e),l=c&&c.length?c:a?[a]:null;return{banner:ga(n),contributors:l,publishedDate:r,readingTime:s,slug:o,title:i}},[pa]:async(t,e)=>{const{banner:a,freeCourse:n,partnershipDetails:r,slug:s,title:o,registered:i}=t,c={banner:ga(a),slug:s,title:o,pill:n?"free":"premium",registered:!!i};if(r){const{partners:t}=r;c.partner=t&&t.length&&r.partners[0]}if(void 0===i&&e){const[t]=await Te.userProducts.list({courseSlug:s,isEnrolled:!0,scope:"active"});c.registered=!!t}return c},[wa]:async(t,e)=>{const{bannerImage:a,defaultStartDate:n,isEventOngoing:r,slug:s,speakers:o,title:i,registered:c}=t,l=new Date(n),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:ga(a),dateHasPassed:u,title:i,slug:s,isOngoingEvent:r,contributors:o,startDate:l,registered:!!c};if(void 0===c&&e){const[t]=await Te.userEvents.list({eventSlug:s});S.registered=!!t}return S},[Na]:async t=>{const{hero:e,slug:a,title:n}=t;return{banner:ga(e),slug:a,title:n}},[Aa]:async t=>{const{answers:e,authorId:a,createdAt:n,slug:r,title:s}=t;let o=null;if(a){const t=await Te.users.read(a);t&&(o=t)}return{answers:e&&e.length?e.length:0,contributors:o?[o]:[],createdAt:n,slug:r,title:s}},[Ta]:t=>{const{bannerSection:e,customLabel:a,slug:n,title:r}=t;return{banner:ga(e.image),slug:n,title:r,customLabel:a}},people:t=>{const{id:e,name:a,jobTitle:n,location:r,image:s}=t;return{profile:s,slug:e,title:a,text:n,secondaryText:r}}};var Pa=async({contentType:t,...e}={},a)=>{try{if(!ya[t])throw new Error("Content type not supported");if("function"!=typeof ya[t])throw new Error("No builder function for content type");return"people"!==t&&e.sys&&e.sys.type&&"Link"===e.sys.type&&(e=await Ze.read(t,e)),{contentType:t,...await ya[t](e,a)}}catch(t){throw await N(t),new Error(`Cannot build carousel card: ${t.message}`)}},Ra=async(t,e,a={})=>{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 r=t.replies;if(a.limit&&a.pageNumber){const e=a.limit*(a.pageNumber-1);r=t.replies.slice(e,e+a.limit)}for(const a of r){if(a.authorId===t.authorId){a.author=t.author,a.userLiked=!1;continue}a.author=a.authorId&&await Ot(a.authorId)||{};const[r]=e?await qt({contentType:n.CONTENTFUL.REPLIES.TYPE,contentSlug:a.slug}):[null];a.userLiked=!!r}return t.replies=r,t}catch(t){throw await N(t),new Error(`Cannot build replies for answer: ${t.message}`)}},ha=l(408);const $a=t=>t&&ha.Buffer.from(t,"base64").toString("ascii");function Ua({contentContext:n=null,errorsContext:l=null,gtmContext:u=null,origin:p}){try{const w=(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 a=null;const n=e.match(o);return n?a=n[1].split(i)[0]:e===r?a=c:e.includes(s)&&(a=E),a||new Error(`Cannot select environment: No rule for website ${e}`),a})(p);return n&&(0,t.setContext)(Object.assign({},n,{environment:w})),l&&(0,e.setContext)(Object.assign({},l,{environment:w})),u&&((0,a.setContext)(Object.assign({},u,{environment:w})),(0,a.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);I.emailIds=d[e]})(Object.assign({},{environment:w})),w}catch(t){console.warn(`Cannot load SDK: ${t.message}`)}}}(),u}()}));
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("socket.io-client"),require("buffer")):"function"==typeof define&&define.amd?define(["@apolitical/content","@apolitical/error-reporting","@apolitical/gtm","axios","http-status-codes","socket.io-client","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("socket.io-client"),require("buffer")):t.ApoliticalSDK=e(t["@apolitical/content"],t["@apolitical/error-reporting"],t["@apolitical/gtm"],t.axios,t["http-status-codes"],t["socket.io-client"],t.buffer)}(this,(function(t,e,r,a,n,s,o){return function(){"use strict";var i={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=o},25:function(t){t.exports=n},130:function(t){t.exports=s}},c={};function l(t){var e=c[t];if(void 0!==e)return e.exports;var r=c[t]={exports:{}};return i[t](r,r.exports,l),r.exports}l.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return l.d(e,{a:e}),e},l.d=function(t,e){for(var r in e)l.o(e,r)&&!l.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},l.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},l.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var u={};return function(){l.r(u),l.d(u,{assets:function(){return h},auth:function(){return U},buildAnswer:function(){return lr},buildCarouselCard:function(){return cr},buildQuestion:function(){return Ze},carouselCards:function(){return Ge},contentInteraction:function(){return X},decodeBase64:function(){return Er},default:function(){return Sr},editorialPages:function(){return Fe},features:function(){return tt},getEntries:function(){return t.getEntries},getEntry:function(){return t.getEntry},management:function(){return It},payments:function(){return Tt},people:function(){return he},peopleEngagement:function(){return Oe},qaQuestions:function(){return ze},reportError:function(){return e.reportError},search:function(){return be}});var t=l(809),e=l(30),r=l(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"}},FEATURES_API:{BASE_URL:"/api/features-api",ENDPOINTS:{FLAGS:"/features"}},MANAGEMENT_API:{BASE_URL:"/api/management-api",ENDPOINTS:{ACCOUNTS:"/accounts",EVENT_REGISTRATIONS:"/event-registrations",LOGINS:"/logins",LOGIN_PASSWORDLESS:"/passwordless",BULK_ENROLMENTS:"/bulk-enrolments"}},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_RATINGS:"/ratings",USER_SUBSCRIPTIONS:"/subscriptions"}},PEOPLE_ENGAGEMENT_API:{BASE_URL:"/api/people-engagement-api",ENDPOINTS:{ENQUIRY_EMAILS:"/enquiry-emails",USERS:"/users",USER_PROPERTIES:"/properties"}},SEARCH_API:{BASE_URL:"/api/search-api",ENDPOINTS:{SEARCH:"/search"}}},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,fields.courseType"},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,fields.projectNames"},learningHub:{INCLUDE:1,SELECT:"fields.bannerSection,fields.customLabel,fields.slug,fields.title"}}},COURSES:{TYPE:"microcourse"},EDITORIAL_PAGES:{INCLUDE:1,SELECT:"fields.carousels,fields.slug,fields.showCarouselCta",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,fields.projectNames",SKIP:0},ANSWERS:{TYPE:"qaAnswer"},REPLIES:{TYPE:"reply"},LEARNING_HUB:{TYPE:"learningHub"}},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:c,LOCAL:E}}}=a,{HUBSPOT:{ENVIRONMENTS_MAPPING:S,EMAIL_IDS:d}}=a;let p={emailIds:{}};var w=l(300),I=l.n(w);const N=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:A,ENDPOINTS:{USERS:g,CERTIFICATES:T}}}}=a;var h={certificates:{create:async(t,e)=>{let r=[];try{const{data:a}=await I().post(`${A}${g}/${t}${T}`,e);a&&(r=a)}catch(t){await N(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 N(t)}return e}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:L,ENDPOINTS:{ANSWERS:m,QUESTIONS:$,LIKES:O}}}}=a,_=`${L}${$}`;var C={create:async({questionSlug:t},e)=>{try{await I().post(`${_}/${encodeURIComponent(t)}${m}`,e)}catch(t){const e=await N(t);throw new Error(e)}},remove:async({questionSlug:t,answerSlug:e})=>{try{await I().delete(`${_}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}`)}catch(t){const e=await N(t);throw new Error(e)}},update:async({questionSlug:t,answerSlug:e},r)=>{try{return await I().put(`${_}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}`,r)}catch(t){const e=await N(t);throw new Error(e)}},like:async({questionSlug:t,answerSlug:e},r)=>{try{return await I().post(`${_}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}${O}`,r)}catch(t){const e=await N(t);throw new Error(e)}},unlike:async({questionSlug:t,answerSlug:e})=>{try{return await I().delete(`${_}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}${O}`)}catch(t){const e=await N(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:D,ENDPOINTS:{QUESTIONS:v}}}}=a,b=`${D}${v}`;var B={create:async t=>{try{return await I().post(b,t)}catch(t){const e=await N(t);throw new Error(e)}},remove:async({questionSlug:t})=>{try{await I().delete(`${b}/${encodeURIComponent(t)}`)}catch(t){const e=await N(t);throw new Error(e)}},update:async({questionSlug:t},e)=>{try{return await I().put(`${b}/${encodeURIComponent(t)}`,e)}catch(t){const e=await N(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:q,ENDPOINTS:{REPLIES:M,ANSWERS:G,QUESTIONS:Y,LIKES:x}}}}=a,k=`${q}${Y}`,V=({questionSlug:t,answerSlug:e,replySlug:r},a=!1)=>{let n=`${k}/${encodeURIComponent(t)}${G}/${encodeURIComponent(e)}${M}`;return r&&(n=`${n}/${encodeURIComponent(r)}`,a&&(n=`${n}${x}`)),n};var F={create:async({questionSlug:t,answerSlug:e},r)=>{try{return await I().post(V({questionSlug:t,answerSlug:e}),r)}catch(t){const e=await N(t);throw new Error(e)}},update:async({questionSlug:t,answerSlug:e,replySlug:r},a)=>{try{return await I().put(V({questionSlug:t,answerSlug:e,replySlug:r}),a)}catch(t){const e=await N(t);throw new Error(e)}},remove:async({questionSlug:t,answerSlug:e,replySlug:r})=>{try{await I().delete(V({questionSlug:t,answerSlug:e,replySlug:r}))}catch(t){const e=await N(t);throw new Error(e)}},like:async({questionSlug:t,answerSlug:e,replySlug:r},a)=>{try{await I().post(V({questionSlug:t,answerSlug:e,replySlug:r},!0),a)}catch(t){const e=await N(t);throw new Error(e)}},unlike:async({questionSlug:t,answerSlug:e,replySlug:r})=>{try{await I().delete(V({questionSlug:t,answerSlug:e,replySlug:r},!0))}catch(t){const e=await N(t);throw new Error(e)}},getReplyUrl:V};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:j,ENDPOINTS:{QUESTIONS:H,ANSWERS:K,LIKES:Q}}}}=a,W=`${j}${H}`;var X={answers:C,questions:B,replies:F,likes:{create:async(t,e)=>{try{return await I().post(`${W}/${encodeURIComponent(t)}${K}/${encodeURIComponent(e)}${Q}`)}catch(t){const e=await N(t);throw new Error(e)}},remove:async(t,e)=>{try{return await I().delete(`${W}/${encodeURIComponent(t)}${K}/${encodeURIComponent(e)}${Q}`)}catch(t){const e=await N(t);throw new Error(e)}}}};const{APIS:{FEATURES_API:{BASE_URL:J,ENDPOINTS:{FLAGS:z}}}}=a,Z=`${J}${z}`;var tt={flags:{read:async t=>{let e=null;try{const{data:r}=await I().get(`${Z}/${encodeURIComponent(t)}`);r?.name&&r?.featureState&&(e=r)}catch(t){await N(t)}return e}}};const{APIS:{MANAGEMENT_API:{BASE_URL:et,ENDPOINTS:{ACCOUNTS:rt}}}}=a;var at={create:async t=>{try{await I().post(`${et}${rt}`,t)}catch(t){throw await N(t),t}},read:async t=>{let e=null;try{({data:e}=await I().get(`${et}${rt}/${encodeURIComponent(t)}`))}catch(t){await N(t)}return e},update:async(t,e)=>{try{await I().put(`${et}${rt}/${encodeURIComponent(t)}`,e)}catch(t){throw await N(t),t}}};const{APIS:{MANAGEMENT_API:{BASE_URL:nt,ENDPOINTS:{BULK_ENROLMENTS:st}}}}=a;var ot={create:async t=>{try{await I().post(`${nt}${st}`,t)}catch(t){throw await N(t),t}}};const{APIS:{MANAGEMENT_API:{BASE_URL:it,ENDPOINTS:{EVENT_REGISTRATIONS:ct}}}}=a;var lt={create:async t=>{try{await I().post(`${it}${ct}`,t)}catch(t){const e=await N(t);throw new Error(e)}}};const{APIS:{MANAGEMENT_API:{BASE_URL:ut}}}=a;var Et={create:async t=>{try{await I().post(`${ut}/users/${t.id}/products`,t)}catch(t){const e=await N(t);throw new Error(e)}}};const{APIS:{MANAGEMENT_API:{BASE_URL:St,ENDPOINTS:{LOGINS:dt,LOGIN_PASSWORDLESS:pt}}}}=a,wt=`${St}${dt}`;var It={accounts:at,bulkEnrolments:ot,eventRegistrations:lt,freeCourseRegistrations:Et,passwordless:{update:async t=>{try{await I().put(`${wt}/${encodeURIComponent(t)}${pt}`)}catch(t){throw await N(t),t}}}};const{APIS:{PAYMENTS_API:{BASE_URL_V2:Nt,ENDPOINTS:{PRODUCTS:At}}}}=a,gt=`${Nt}${At}`;var Tt={products:{list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(gt,r);t&&t.length&&(e=t)}catch(t){await N(t)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:ht,ENDPOINTS:{BULK_ENROLMENTS:yt}}}}=a;var Pt={list:async t=>{let e=[];try{const{data:r}=await I().get(`${ht}${yt}`,{params:t});r&&r.length&&(e=r)}catch(t){await N(t)}return e}},Rt=l(25);const{OK:ft,MULTIPLE_CHOICES:Ut,NOT_FOUND:Lt,FORBIDDEN:mt}=Rt.StatusCodes,$t=t=>t>=ft&&t<Ut||t===mt||t===Lt,{APIS:{PEOPLE_API:{BASE_URL_V2:Ot,ENDPOINTS:{USERS:_t}}}}=a,Ct=async t=>{let e=null;try{const{data:r}=await I().get(`${Ot}${_t}/${encodeURIComponent(t)}`,{validateStatus:$t});r&&r.id&&(e=r)}catch(t){await N(t)}return e},Dt=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(`${Ot}${_t}?${r}`,{validateStatus:$t});a&&a.length&&(e=a)}catch(t){await N(t)}return e};var vt={read:Ct,update:async(t,e)=>{let r=!1;try{const{data:a}=await I().put(`${Ot}${_t}/${encodeURIComponent(t)}`,e);r=!(!a||!a.id)}catch(t){await N(t)}return r},list:Dt};const{APIS:{PEOPLE_API:{BASE_URL_V2:bt,ENDPOINTS:{USERS:Bt,USER_LIKES:qt}}},USERS:{MYSELF:Mt}}=a,Gt=`${bt}${Bt}/${Mt}${qt}`,Yt=async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(Gt,r);t&&t.length&&(e=t)}catch(t){await N(t)}return e};var xt={list:Yt};var kt={authors:{readQuestionAuthors:async(t,e,r)=>{try{if(t.author=await Ct(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 Ct(t.authorId)||{};const[r]=e?await Yt({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 N(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 Ct(t[0]);r&&e.push(r)}else if(t&&t.length>1){const r=await Dt(t);r&&r.length>0&&(e=r)}}catch(t){throw await N(t),new Error(`Cannot read authors: ${t.message}`)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL:Vt,ENDPOINTS:{REGISTRATIONS:Ft}}}}=a;var jt={list:async t=>{let e=[];try{const{data:r}=await I().get(`${Vt}${Ft}`,{params:t});r&&r.length&&(e=r)}catch(t){await N(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Ht,ENDPOINTS:{USERS:Kt,USER_COURSES:Qt}}},USERS:{MYSELF:Wt}}=a,Xt=`${Ht}${Kt}/${Wt}${Qt}`;var Jt={create:async t=>{try{await I().post(Xt,t)}catch(t){await N(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 N(t)}return e},update:async(t,e)=>{try{await I().put(`${Xt}/${t}`,e)}catch(t){await N(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:zt,ENDPOINTS:{USERS:Zt,USER_EVENTS:te}}},USERS:{MYSELF:ee}}=a,re=`${zt}${Zt}/${ee}${te}`;var ae={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 N(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:ne,ENDPOINTS:{USERS:se,USER_LESSONS:oe}}},USERS:{MYSELF:ie}}=a,ce=`${ne}${se}/${ie}${oe}`;var le={create:async t=>{let e=null;try{e=await I().post(ce,t)}catch(t){await N(t)}return e},list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(ce,r);t&&t.length&&(e=t)}catch(t){await N(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:ue,ENDPOINTS:{USERS:Ee,USER_PRODUCTS:Se}}},USERS:{MYSELF:de}}=a,pe=`${ue}${Ee}/${de}${Se}`;var we={create:async t=>{let e=null;try{e=await I().post(pe,t)}catch(t){await N(t)}return e},list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await I().get(pe,r);t&&t.length&&(e=t)}catch(t){await N(t)}return e},update:async(t,e)=>{try{await I().put(`${pe}/${t}`,e)}catch(t){await N(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Ie,ENDPOINTS:{USERS:Ne,USER_RATINGS:Ae}}},USERS:{MYSELF:ge}}=a,Te=`${Ie}${Ne}/${ge}${Ae}`;var he={bulkEnrolments:Pt,handlers:kt,registrations:jt,users:vt,userCourses:Jt,userEvents:ae,userLessons:le,userLikes:xt,userProducts:we,userRatings:{create:async t=>{let e=null;try{const{data:r}=await I().post(Te,t);r?.id&&(e=r)}catch(t){await N(t)}return e},update:async(t,e)=>{try{await I().put(`${Te}/${t}`,e)}catch(t){await N(t)}}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:ye,ENDPOINTS:{ENQUIRY_EMAILS:Pe}}}}=a;var Re={create:async t=>{let e=null;try{const{data:r}=await I().post(`${ye}${Pe}`,t);r&&(e=r)}catch(t){await N(t)}return e}},fe={forms:{sendEnquiryEmails:async t=>{let e=null;try{const{emailIds:r}=p;e=await Oe.emails.create({...r,...t})}catch(t){await N(t)}return e}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:Ue,ENDPOINTS:{USERS:Le,USER_PROPERTIES:me}}},USERS:{MYSELF:$e}}=a;var Oe={emails:Re,handlers:fe,userProperties:{update:async(t,e)=>{try{await I().put(`${Ue}${Le}/${$e}${me}/${t}`,e)}catch(t){await N(t)}}}},_e=l(130);const{APIS:{SEARCH_API:{BASE_URL:Ce,ENDPOINTS:{SEARCH:De}}}}=a,ve=`${Ce}${De}`;var be={ask:async t=>{try{let e=null;const{data:r}=await I().get(ve,{params:{question:t}});return r?.answer&&r?.references&&r?.version&&(e=r),e}catch(t){const e=await N(t);throw new Error(e)}},stream:(t,e,r)=>{const a=(0,_e.io)(void 0,{path:"/api/search-api/web-sockets"});function n(){a.emit("search",{question:t})}function s(t){r(t),o(),a.disconnect()}function o(){a.off("connect",n),a.off("update",e),a.off("result",s)}return a.on("connect",n),a.on("update",e),a.on("result",s),o}};const{CONTENTFUL:Be}=a,{CARD_TYPES:qe}=Be.CAROUSELS,Me={read:async(e,r)=>{try{if(!r||!r.sys||!r.sys.id)throw new Error("Invalid link to card");if(!e||!qe[e])throw new Error("Unsupported card content type");const{INCLUDE:a,SELECT:n}=qe[e];return await(0,t.getEntry)({content_type:e,"sys.id":r.sys.id,include:a,select:n},{assetDetails:!0})}catch(t){throw await N(t),new Error(`Cannot read carousel card: ${t.message}`)}}};var Ge=Me;const{CONTENTFUL:Ye}=a,{INCLUDE:xe,SELECT:ke,TYPE:Ve}=Ye.EDITORIAL_PAGES;var Fe={read:async e=>{try{return await(0,t.getEntry)({content_type:Ve,"fields.slug":e,include:xe,select:ke})}catch(t){throw await N(t),new Error(`Cannot read editorial page: ${t.message}`)}}};const{CONTENTFUL:je}=a,{TYPE:He,ORDER:Ke,SELECT:Qe,SKIP:We,LIMIT:Xe,INCLUDE:Je}=je.QUESTIONS;var ze={read:async e=>{try{return await(0,t.getEntry)({content_type:He,"fields.slug":e,include:2,select:Qe})}catch(t){throw await N(t),new Error(`Cannot read question: ${t.message}`)}},list:async(e={})=>{try{return await(0,t.getEntries)({content_type:He,include:Je,limit:Xe,order:Ke,select:Qe,skip:We,...e})}catch(t){throw await N(t),new Error(`Cannot list questions: ${t.message}`)}}},Ze=async(t,e,r={ignoreAnswersAuthors:!1})=>{try{let a={};return a=await ze.read(t),a=await he.handlers.authors.readQuestionAuthors(a,e,r),a}catch(t){throw await N(t),new Error(`Cannot build question: ${t.message}`)}};const{ARTICLES:{TYPE:tr},COURSES:{TYPE:er},EVENTS:{TYPE:rr},LISTS:{TYPE:ar},QUESTIONS:{TYPE:nr},LEARNING_HUB:{TYPE:sr}}=a.CONTENTFUL,or=t=>t&&t.url?(Object.assign(t,{aspect:"responsiveCard",query:"q=90&fit=fill"}),t):null,ir={[tr]:async t=>{const{authorIds:e,authorTag:r,image:a,publishedDate:n,readingTime:s,slug:o,title:i}=t,c=await he.handlers.authors.readAuthors(e),l=c&&c.length?c:r?[r]:null;return{banner:or(a),contributors:l,publishedDate:n,readingTime:s,slug:o,title:i}},[er]:async(t,e)=>{const{banner:r,freeCourse:a,partnershipDetails:n,slug:s,title:o,registered:i,courseType:c}=t,l={banner:or(r),slug:s,title:o,pill:a?"free":"premium",registered:!!i,courseType:c};if(n){const{partners:t}=n;l.partner=t&&t.length&&n.partners[0]}if(void 0===i&&e){const[t]=await he.userProducts.list({courseSlug:s,isEnrolled:!0,scope:"active"});l.registered=!!t}return l},[rr]: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:or(r),dateHasPassed:u,title:i,slug:s,isOngoingEvent:n,contributors:o,startDate:l,registered:!!c};if(void 0===c&&e){const[t]=await he.userEvents.list({eventSlug:s});S.registered=!!t}return S},[ar]:async t=>{const{hero:e,slug:r,title:a}=t;return{banner:or(e),slug:r,title:a}},[nr]:async t=>{const{answers:e,authorId:r,createdAt:a,slug:n,title:s}=t;let o=null;if(r){const t=await he.users.read(r);t&&(o=t)}return{answers:e&&e.length?e.length:0,contributors:o?[o]:[],createdAt:a,slug:n,title:s}},[sr]:t=>{const{bannerSection:e,customLabel:r,slug:a,title:n}=t;return{banner:or(e.image),slug:a,title:n,customLabel:r}},people:t=>{const{id:e,name:r,jobTitle:a,location:n,image:s}=t;return{profile:s,slug:e,title:r,text:a,secondaryText:n}}};var cr=async({contentType:t,...e}={},r)=>{try{if(!ir[t])throw new Error("Content type not supported");if("function"!=typeof ir[t])throw new Error("No builder function for content type");return"people"!==t&&e.sys&&e.sys.type&&"Link"===e.sys.type&&(e=await Ge.read(t,e)),{contentType:t,...await ir[t](e,r)}}catch(t){throw await N(t),new Error(`Cannot build carousel card: ${t.message}`)}},lr=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 Ct(r.authorId)||{};const[n]=e?await Yt({contentType:a.CONTENTFUL.REPLIES.TYPE,contentSlug:r.slug}):[null];r.userLiked=!!n}return t.replies=n,t}catch(t){throw await N(t),new Error(`Cannot build replies for answer: ${t.message}`)}},ur=l(408);const Er=t=>t&&ur.Buffer.from(t,"base64").toString("ascii");function Sr({contentContext:a=null,errorsContext:l=null,gtmContext:u=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=c: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})),l&&(0,e.setContext)(Object.assign({},l,{environment:I})),u&&((0,r.setContext)(Object.assign({},u,{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}`)}}}(),u}()}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apolitical/sdk",
3
- "version": "7.5.3-beta.1",
3
+ "version": "7.5.4",
4
4
  "description": "Browser library to interact with Apolitical's APIs",
5
5
  "author": "Apolitical Group Limited <engineering@apolitical.co>",
6
6
  "license": "MIT",