@apolitical/sdk 10.0.2-beta.0 → 10.0.2-rc.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 +1 -1
- package/package.json +2 -2
package/build/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
!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,i){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=i},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 o[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 T},auth:function(){return $},buildAnswer:function(){return ia},buildCardCtaClickHandler:function(){return la},buildCarouselCard:function(){return sa},buildQuestion:function(){return jr},carouselCards:function(){return Cr},contentInteraction:function(){return X},decodeBase64:function(){return wa},default:function(){return ya},editorialPages:function(){return Mr},features:function(){return et},getEntries:function(){return t.getEntries},getEntry:function(){return t.getEntry},management:function(){return pt},mgmt:function(){return Nt},payments:function(){return $t},people:function(){return Ve},peopleEngagement:function(){return Xe},predictPlace:function(){return Ia},qaQuestions:function(){return Fr},reportError:function(){return e.reportError},search:function(){return rr},socials:function(){return $r}});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"}},MGMT_API:{BASE_URL:"/api/mgmt-api",ENDPOINTS:{REFERRALS:"/referrals",BULK_REFERRALS:"/bulk-referrals",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",COMMUNITIES:"/communities",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_REFERRALS:"/referrals",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"},PATHS:{ACTIVITIES:"activities",REACTIONS:"reactions"}}},CONTENTFUL:{ARTICLES:{TYPE:"solutionArticle"},CAROUSELS:{CARD_TYPES:{communityPage:{INCLUDE:1,SELECT:"fields.bannerSection,fields.slug,fields.title"},customCard:{INCLUDE:1,SELECT:"fields.icon,fields.label,fields.image,fields.primaryText,fields.secondaryText,fields.authorName,fields.authorImage,fields.link,fields.openInNewTab"},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"}}},COMMUNITY:{TYPE:"communityPage"},COURSES:{TYPE:"microcourse"},CUSTOM_CARD:{TYPE:"customCard"},EDITORIAL_PAGES:{INCLUDE:1,SELECT:"fields.carousels,fields.slug,fields.showCarouselCta,fields.header,fields.subHeader",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"}},GOOGLE:{MAPS:{LIBRARIES:{PLACES:"places"},VERSION:"weekly"}},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"},STATUS_CODES:{INVALID_TOKEN:498},ERROR_MESSAGES:{INVALID_TOKEN:"Invalid token error: Logging user out..."}};const{APOLITICAL:{WEBSITES:{LIVE:n,LOCALHOST:s,STAGING:i,STAGING_SPLITTER:o},ENVIRONMENTS:{PRODUCTION:c,LOCAL:E}}}=a,{HUBSPOT:{ENVIRONMENTS_MAPPING:S,EMAIL_IDS:d}}=a;let p={emailIds:{}};const h=()=>p;var I=l(300),g=l.n(I);const w=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:y,ENDPOINTS:{USERS:m,CERTIFICATES:A}}}}=a;var T={certificates:{create:async(t,e)=>{let r=[];try{const{data:a}=await g().post(`${y}${m}/${t}${A}`,e);a&&(r=a)}catch(t){await w(t)}return r}}};const{APIS:{AUTH_API:{BASE_URL:N,ENDPOINTS:{USER_PASSWORD:f,USERS:R}}},USERS:{MYSELF:P}}=a;var $={userPassword:{update:async t=>{let e=null;try{e=await g().put(`${N}${R}/${P}${f}`,t)}catch(t){e={message:(((t||{}).response||{}).data||{}).message},await w(t)}return e}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:L,ENDPOINTS:{ANSWERS:O,QUESTIONS:U,LIKES:C}}}}=a,_=`${L}${U}`;var v={create:async({questionSlug:t},e)=>{try{await g().post(`${_}/${encodeURIComponent(t)}${O}`,e)}catch(t){const e=await w(t);throw new Error(e)}},remove:async({questionSlug:t,answerSlug:e})=>{try{await g().delete(`${_}/${encodeURIComponent(t)}${O}/${encodeURIComponent(e)}`)}catch(t){const e=await w(t);throw new Error(e)}},update:async({questionSlug:t,answerSlug:e},r)=>{try{return await g().put(`${_}/${encodeURIComponent(t)}${O}/${encodeURIComponent(e)}`,r)}catch(t){const e=await w(t);throw new Error(e)}},like:async({questionSlug:t,answerSlug:e},r)=>{try{return await g().post(`${_}/${encodeURIComponent(t)}${O}/${encodeURIComponent(e)}${C}`,r)}catch(t){const e=await w(t);throw new Error(e)}},unlike:async({questionSlug:t,answerSlug:e})=>{try{return await g().delete(`${_}/${encodeURIComponent(t)}${O}/${encodeURIComponent(e)}${C}`)}catch(t){const e=await w(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:b,ENDPOINTS:{QUESTIONS:D}}}}=a,M=`${b}${D}`;var B={create:async t=>{try{return await g().post(M,t)}catch(t){const e=await w(t);throw new Error(e)}},remove:async({questionSlug:t})=>{try{await g().delete(`${M}/${encodeURIComponent(t)}`)}catch(t){const e=await w(t);throw new Error(e)}},update:async({questionSlug:t},e)=>{try{return await g().put(`${M}/${encodeURIComponent(t)}`,e)}catch(t){const e=await w(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:k,ENDPOINTS:{REPLIES:q,ANSWERS:G,QUESTIONS:x,LIKES:V}}}}=a,Y=`${k}${x}`,F=({questionSlug:t,answerSlug:e,replySlug:r},a=!1)=>{let n=`${Y}/${encodeURIComponent(t)}${G}/${encodeURIComponent(e)}${q}`;return r&&(n=`${n}/${encodeURIComponent(r)}`,a&&(n=`${n}${V}`)),n};var j={create:async({questionSlug:t,answerSlug:e},r)=>{try{return await g().post(F({questionSlug:t,answerSlug:e}),r)}catch(t){const e=await w(t);throw new Error(e)}},update:async({questionSlug:t,answerSlug:e,replySlug:r},a)=>{try{return await g().put(F({questionSlug:t,answerSlug:e,replySlug:r}),a)}catch(t){const e=await w(t);throw new Error(e)}},remove:async({questionSlug:t,answerSlug:e,replySlug:r})=>{try{await g().delete(F({questionSlug:t,answerSlug:e,replySlug:r}))}catch(t){const e=await w(t);throw new Error(e)}},like:async({questionSlug:t,answerSlug:e,replySlug:r,payload:a})=>{try{await g().post(F({questionSlug:t,answerSlug:e,replySlug:r},!0),a)}catch(t){const e=await w(t);throw new Error(e)}},unlike:async({questionSlug:t,answerSlug:e,replySlug:r})=>{try{await g().delete(F({questionSlug:t,answerSlug:e,replySlug:r},!0))}catch(t){const e=await w(t);throw new Error(e)}},getReplyUrl:F};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:K,ENDPOINTS:{QUESTIONS:H,ANSWERS:Q,LIKES:W}}}}=a,J=`${K}${H}`;var X={answers:v,questions:B,replies:j,likes:{create:async({questionSlug:t,answerSlug:e})=>{try{return await g().post(`${J}/${encodeURIComponent(t)}${Q}/${encodeURIComponent(e)}${W}`)}catch(t){const e=await w(t);throw new Error(e)}},remove:async({questionSlug:t,answerSlug:e})=>{try{return await g().delete(`${J}/${encodeURIComponent(t)}${Q}/${encodeURIComponent(e)}${W}`)}catch(t){const e=await w(t);throw new Error(e)}}}};const{APIS:{FEATURES_API:{BASE_URL:Z,ENDPOINTS:{FLAGS:z}}}}=a,tt=`${Z}${z}`;var et={flags:{read:async t=>{let e=null;try{const{data:r}=await g().get(`${tt}/${encodeURIComponent(t)}`);r?.name&&r?.featureState&&(e=r)}catch(t){await w(t)}return e}}};const{APIS:{MANAGEMENT_API:{BASE_URL:rt,ENDPOINTS:{ACCOUNTS:at}}}}=a;var nt={create:async t=>{try{await g().post(`${rt}${at}`,t)}catch(t){throw await w(t),t}},read:async t=>{let e=null;try{({data:e}=await g().get(`${rt}${at}/${encodeURIComponent(t)}`))}catch(t){await w(t)}return e},update:async(t,e)=>{try{await g().put(`${rt}${at}/${encodeURIComponent(t)}`,e)}catch(t){throw await w(t),t}}};const{APIS:{MANAGEMENT_API:{BASE_URL:st,ENDPOINTS:{EVENT_REGISTRATIONS:it}}}}=a;var ot={create:async t=>{try{await g().post(`${st}${it}`,t)}catch(t){const e=await w(t);throw new Error(e)}}};const{APIS:{MANAGEMENT_API:{BASE_URL:ct,ENDPOINTS:{LOGINS:lt,LOGIN_PASSWORDLESS:ut}}}}=a,Et=`${ct}${lt}`;var St={update:async t=>{try{await g().put(`${Et}/${encodeURIComponent(t)}${ut}`)}catch(t){throw await w(t),t}}};const{APIS:{MANAGEMENT_API:{BASE_URL:dt}}}=a;var pt={accounts:nt,eventRegistrations:ot,passwordless:St,userProducts:{create:async t=>{try{await g().post(`${dt}/users/${t.id}/products`,t)}catch(t){const e=await w(t);throw new Error(e)}}}};const{APIS:{MGMT_API:{BASE_URL:ht,ENDPOINTS:{REFERRALS:It}}}}=a;var gt={create:async t=>{try{await g().post(`${ht}${It}`,t)}catch(t){throw await w(t),t}}};const{APIS:{MGMT_API:{BASE_URL:wt,ENDPOINTS:{BULK_REFERRALS:yt}}}}=a;var mt={create:async t=>{try{await g().post(`${wt}${yt}`,t)}catch(t){throw await w(t),t}}};const{APIS:{MGMT_API:{BASE_URL:At,ENDPOINTS:{BULK_ENROLMENTS:Tt}}}}=a;var Nt={referrals:gt,bulkReferrals:mt,bulkEnrolments:{create:async t=>{try{await g().post(`${At}${Tt}`,t)}catch(t){throw await w(t),t}}}};const{APIS:{PAYMENTS_API:{BASE_URL_V2:ft,ENDPOINTS:{PRODUCTS:Rt}}}}=a,Pt=`${ft}${Rt}`;var $t={products:{list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await g().get(Pt,r);t&&t.length&&(e=t)}catch(t){await w(t)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Lt,ENDPOINTS:{BULK_ENROLMENTS:Ot}}}}=a;var Ut={list:async t=>{let e=[];try{const{data:r}=await g().get(`${Lt}${Ot}`,{params:t});r&&r.length&&(e=r)}catch(t){await w(t)}return e}},Ct=l(25);const{OK:_t,MULTIPLE_CHOICES:vt,NOT_FOUND:bt,FORBIDDEN:Dt}=Ct.StatusCodes,Mt=t=>t>=_t&&t<vt||t===Dt||t===bt,{APIS:{PEOPLE_API:{BASE_URL_V2:Bt,ENDPOINTS:{USERS:kt}}},STATUS_CODES:{INVALID_TOKEN:qt},ERROR_MESSAGES:{INVALID_TOKEN:Gt}}=a,xt=async t=>{let e=null;try{const{data:r}=await g().get(`${Bt}${kt}/${encodeURIComponent(t)}`,{validateStatus:Mt});r&&r.id&&(e=r)}catch(t){if(t?.response?.status===qt)throw new Error(Gt);await w(t)}return e},Vt=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 g().get(`${Bt}${kt}?${r}`,{validateStatus:Mt});a&&a.length&&(e=a)}catch(t){await w(t)}return e};var Yt={read:xt,update:async(t,e)=>{let r=!1;try{const{data:a}=await g().put(`${Bt}${kt}/${encodeURIComponent(t)}`,e);r=!(!a||!a.id)}catch(t){await w(t)}return r},list:Vt};const{APIS:{PEOPLE_API:{BASE_URL_V2:Ft,ENDPOINTS:{USERS:jt,USER_LIKES:Kt}}},USERS:{MYSELF:Ht}}=a,Qt=`${Ft}${jt}/${Ht}${Kt}`,Wt=async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await g().get(Qt,r);t&&t.length&&(e=t)}catch(t){await w(t)}return e};var Jt={list:Wt};var Xt={authors:{readQuestionAuthors:async(t,e,r)=>{try{if(t.author=await xt(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 xt(t.authorId)||{};const[r]=e?await Wt({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 w(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 xt(t[0]);r&&e.push(r)}else if(t&&t.length>1){const r=await Vt(t);r&&r.length>0&&(e=r)}}catch(t){throw await w(t),new Error(`Cannot read authors: ${t.message}`)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL:Zt,ENDPOINTS:{REGISTRATIONS:zt}}}}=a;var te={list:async t=>{let e=[];try{const{data:r}=await g().get(`${Zt}${zt}`,{params:t});r&&r.length&&(e=r)}catch(t){await w(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:ee,ENDPOINTS:{COMMUNITIES:re,USERS:ae}}}}=a,ne=`${ee}${ae}`;function se(t){const e=t["content-range"].split(" ")[1].split("/"),[r,a,n]=[...e[0].split("-"),e[1]].map((t=>parseInt(t,10)||0));return{start:r,end:a,total:n}}var ie={list:async(t="me",e={})=>{let r={items:[],start:0,end:0,total:0},a=e?{params:e}:{params:{}};try{const{data:e,headers:n}=await g().get(`${ne}/${t}${re}`,{...a,headers:{"Cache-Control":"no-cache",Pragma:"no-cache",Expires:0}});return e?.length>0&&(r={data:e,pagination:se(n)}),r}catch(t){await w(t)}return r}};const{APIS:{PEOPLE_API:{BASE_URL_V2:oe,ENDPOINTS:{USERS:ce,USER_COURSES:le}}},USERS:{MYSELF:ue}}=a,Ee=`${oe}${ce}/${ue}${le}`;var Se={create:async t=>{try{await g().post(Ee,t)}catch(t){await w(t)}},list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await g().get(Ee,r);t&&t.length&&(e=t)}catch(t){await w(t)}return e},update:async(t,e)=>{try{await g().put(`${Ee}/${t}`,e)}catch(t){await w(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:de,ENDPOINTS:{USERS:pe,USER_EVENTS:he}}},USERS:{MYSELF:Ie}}=a,ge=`${de}${pe}/${Ie}${he}`;var we={list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await g().get(ge,r);t&&t.length&&(e=t)}catch(t){await w(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:ye,ENDPOINTS:{USERS:me,USER_LESSONS:Ae}}},USERS:{MYSELF:Te}}=a,Ne=`${ye}${me}/${Te}${Ae}`;var fe={create:async t=>{let e=null;try{e=await g().post(Ne,t)}catch(t){await w(t)}return e},list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await g().get(Ne,r);t&&t.length&&(e=t)}catch(t){await w(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Re,ENDPOINTS:{USERS:Pe,USER_PRODUCTS:$e}}},USERS:{MYSELF:Le}}=a,Oe=`${Re}${Pe}/${Le}${$e}`;var Ue={create:async t=>{let e=null;try{e=await g().post(Oe,t)}catch(t){await w(t)}return e},list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await g().get(Oe,r);t&&t.length&&(e=t)}catch(t){await w(t)}return e},update:async(t,e)=>{try{await g().put(`${Oe}/${t}`,e)}catch(t){await w(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Ce,ENDPOINTS:{USERS:_e,USER_RATINGS:ve}}},USERS:{MYSELF:be}}=a,De=`${Ce}${_e}/${be}${ve}`;var Me={create:async t=>{let e=null;try{const{data:r}=await g().post(De,t);r?.id&&(e=r)}catch(t){await w(t)}return e},update:async(t,e)=>{try{await g().put(`${De}/${t}`,e)}catch(t){await w(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Be,ENDPOINTS:{USERS:ke,USER_REFERRALS:qe}}},USERS:{MYSELF:Ge}}=a,xe=`${Be}${ke}/${Ge}${qe}`;var Ve={bulkEnrolments:Ut,handlers:Xt,registrations:te,users:Yt,userCommunities:ie,userCourses:Se,userEvents:we,userLessons:fe,userLikes:Jt,userProducts:Ue,userRatings:Me,userReferrals:{list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await g().get(xe,r);t&&t.length&&(e=t)}catch(t){await w(t)}return e}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:Ye,ENDPOINTS:{ENQUIRY_EMAILS:Fe}}}}=a;var je={create:async t=>{let e=null;try{const{data:r}=await g().post(`${Ye}${Fe}`,t);r&&(e=r)}catch(t){await w(t)}return e}},Ke={forms:{sendEnquiryEmails:async t=>{let e=null;try{const{emailIds:r}=h();e=await Xe.emails.create({...r,...t})}catch(t){await w(t)}return e}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:He,ENDPOINTS:{USERS:Qe,USER_PROPERTIES:We}}},USERS:{MYSELF:Je}}=a;var Xe={emails:je,handlers:Ke,userProperties:{update:async(t,e)=>{try{await g().put(`${He}${Qe}/${Je}${We}/${t}`,e)}catch(t){await w(t)}}}},Ze=l(130);const{APIS:{SEARCH_API:{BASE_URL:ze,ENDPOINTS:{SEARCH:tr}}}}=a,er=`${ze}${tr}`;var rr={ask:async t=>{try{let e=null;const{data:r}=await g().get(er,{params:{question:t}});return r?.answer&&r?.references&&r?.version&&(e=r),e}catch(t){const e=await w(t);throw new Error(e)}},stream:(t,e,r)=>{const a=(0,Ze.io)(void 0,{path:"/api/search-api/web-sockets"});function n(){a.emit("search",{question:t})}function s(t){r(t),i(),a.disconnect()}function i(){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),i}};const{APIS:{SOCIALS_API:{BASE_URL:ar,ENDPOINTS:{COMMUNITIES:nr},PATHS:{ACTIVITIES:sr}}}}=a,ir=`${ar}${nr}`;var or={read:async(t,e)=>{let r=null;try{const{data:a}=await g().get(`${ir}/${encodeURIComponent(t)}/${sr}/${e}`);a&&(r=a)}catch(t){await w(t)}return r},list:async(t,e={})=>{let r=null;try{const{data:a}=await g().get(`${ir}/${encodeURIComponent(t)}/${sr}`,{params:e});a&&(r=a)}catch(t){await w(t)}return r},create:async(t,e)=>{let r=null;try{const{data:a}=await g().post(`${ir}/${encodeURIComponent(t)}/${sr}`,e);(a?.content||a?.title)&&(r=a)}catch(t){await w(t)}return r},update:async(t,e,r)=>{let a=null;try{const{data:n}=await g().put(`${ir}/${encodeURIComponent(t)}/${sr}/${e}`,r);(n?.content||n?.title)&&(a=n)}catch(t){await w(t)}return a},remove:async(t,e)=>{let r=null;try{const{data:a}=await g().delete(`${ir}/${encodeURIComponent(t)}/${sr}/${e}`);r=a}catch(t){await w(t)}return r}};const{APIS:{SOCIALS_API:{BASE_URL:cr,ENDPOINTS:{COMMUNITIES:lr}}}}=a,ur=`${cr}${lr}`;var Er={read:async t=>{let e=null;try{const{data:r}=await g().get(`${ur}/${encodeURIComponent(t)}`);r?.title&&(e=r)}catch(t){await w(t)}return e},join:async(t,e)=>{let r=null;try{const{data:a}=await g().post(`${ur}/${encodeURIComponent(t)}/members`,e);r=a}catch(t){await w(t)}return r},leave:async t=>{let e=null;try{const{data:r}=await g().delete(`${ur}/${encodeURIComponent(t)}/members/me`);e=r}catch(t){await w(t)}return e}};const{APIS:{SOCIALS_API:{BASE_URL:Sr,ENDPOINTS:{COMMUNITIES:dr},PATHS:{ACTIVITIES:pr,REACTIONS:hr}}}}=a,Ir=`${Sr}${dr}`;var gr={create:async({slug:t,activityId:e,reactionId:r})=>{let a=null;const n={kind:"like"};let s=`${Ir}/${encodeURIComponent(t)}`;s=e?`${s}/${pr}/${e}/${hr}`:`${s}/${hr}/${r}/${hr}`;try{const{data:t}=await g().post(s,n);a=t}catch(t){await w(t)}return a},remove:async({slug:t,reactionId:e})=>{let r=null;try{const{data:a}=await g().delete(`${Ir}/${encodeURIComponent(t)}/${hr}/${e}`);r=a}catch(t){await w(t)}return r}};const{APIS:{SOCIALS_API:{BASE_URL:wr,ENDPOINTS:{COMMUNITIES:yr}}}}=a,mr=`${wr}${yr}`;var Ar={list:async(t,e)=>{let r={data:[],pagination:{start:0,end:0,total:0}},a=e?{params:e}:{params:{}};try{const{data:e}=await g().get(`${mr}/${encodeURIComponent(t)}/members`,{...a,headers:{"Cache-Control":"no-cache",Pragma:"no-cache",Expires:0}});e?.data?.length>0&&(r=e)}catch(t){await w(t)}return r}};const{APIS:{SOCIALS_API:{BASE_URL:Tr,ENDPOINTS:{COMMUNITIES:Nr},PATHS:{ACTIVITIES:fr,REACTIONS:Rr}}}}=a,Pr=`${Tr}${Nr}`;var $r={activities:or,communities:Er,members:Ar,likes:gr,reactions:{create:async(t,e,r,a)=>{let n=null,s=`${Pr}/${encodeURIComponent(t)}`;s=e?`${s}/${fr}/${e}/${Rr}`:`${s}/${Rr}/${r}/${Rr}`;try{const{data:t}=await g().post(s,a);n=t}catch(t){await w(t)}return n},list:async(t,{activityId:e,reactionId:r},a={})=>{let n=null,s=`${Pr}/${encodeURIComponent(t)}`;s=e?`${s}/${fr}/${e}/${Rr}`:`${s}/${Rr}/${r}/${Rr}`;try{const{data:t}=await g().get(s,{params:a});t&&(n=t)}catch(t){await w(t)}return n},remove:async(t,e)=>{let r=null;try{const{data:a}=await g().delete(`${Pr}/${encodeURIComponent(t)}/${Rr}/${e}`);r=a}catch(t){await w(t)}return r},update:async(t,e,r,a)=>{let n=null,s=`${Pr}/${encodeURIComponent(t)}`;s=e?`${s}/${fr}/${e}`:`${s}/${Rr}/${r}`;try{const{data:t}=await g().put(s,a);n=t}catch(t){await w(t)}return n}}};const{CONTENTFUL:Lr}=a,{CARD_TYPES:Or}=Lr.CAROUSELS,Ur={read:async(e,r)=>{try{if(!r||!r.sys||!r.sys.id)throw new Error("Invalid link to card");if(!e||!Or[e])throw new Error("Unsupported card content type");const{INCLUDE:a,SELECT:n}=Or[e];return await(0,t.getEntry)({content_type:e,"sys.id":r.sys.id,include:a,select:n},{assetDetails:!0})}catch(t){throw await w(t),new Error(`Cannot read carousel card: ${t.message}`)}}};var Cr=Ur;const{CONTENTFUL:_r}=a,{INCLUDE:vr,SELECT:br,TYPE:Dr}=_r.EDITORIAL_PAGES;var Mr={read:async e=>{try{return await(0,t.getEntry)({content_type:Dr,"fields.slug":e,include:vr,select:br})}catch(t){throw await w(t),new Error(`Cannot read editorial page: ${t.message}`)}}};const{CONTENTFUL:Br}=a,{TYPE:kr,ORDER:qr,SELECT:Gr,SKIP:xr,LIMIT:Vr,INCLUDE:Yr}=Br.QUESTIONS;var Fr={read:async e=>{try{return await(0,t.getEntry)({content_type:kr,"fields.slug":e,include:2,select:Gr})}catch(t){throw await w(t),new Error(`Cannot read question: ${t.message}`)}},list:async(e={})=>{try{return await(0,t.getEntries)({content_type:kr,include:Yr,limit:Vr,order:qr,select:Gr,skip:xr,...e})}catch(t){throw await w(t),new Error(`Cannot list questions: ${t.message}`)}}},jr=async(t,e,r={ignoreAnswersAuthors:!1})=>{try{let a={};return a=await Fr.read(t),a=await Ve.handlers.authors.readQuestionAuthors(a,e,r),a}catch(t){throw await w(t),new Error(`Cannot build question: ${t.message}`)}};const{ARTICLES:{TYPE:Kr},COURSES:{TYPE:Hr},CUSTOM_CARD:{TYPE:Qr},COMMUNITY:{TYPE:Wr},EVENTS:{TYPE:Jr},LISTS:{TYPE:Xr},QUESTIONS:{TYPE:Zr},LEARNING_HUB:{TYPE:zr}}=a.CONTENTFUL,ta={ClosedHidden:"closed-hidden",ClosedVisible:"closed-visible",OpenHidden:"open-hidden",OpenVisible:"open-visible"},ea=t=>t&&t.url?(Object.assign(t,{aspect:"responsiveCard",query:"q=90&fit=fill"}),t):null,ra=t=>t&&t.url?`${t.url}?w=100&h=100&fit=thumb&f=center`:null,aa=t=>t.toLowerCase().split(" ")[0],na={[Kr]:async t=>{const{authorIds:e,authorTag:r,image:a,publishedDate:n,readingTime:s,slug:i,title:o}=t,c=await Ve.handlers.authors.readAuthors(e),l=c&&c.length?c:r?[aa(r)]:null;return{banner:ea(a),contributors:l,publishedDate:n,readingTime:s,slug:i,title:o}},[Wr]:async t=>{const{title:e,slug:r,bannerSection:a,privacy:n,createdAt:s}=t,i=await $r.communities.read(r),o=await $r.members.list(r,{count:1}),c=[ta.ClosedVisible,ta.ClosedHidden].includes(n),l=[ta.OpenVisible,ta.ClosedVisible].includes(n);return{banner:a?.image?ea(a.image):null,slug:r,title:e,privacy:n,isPrivate:c,isVisible:l,createdAt:s,members:{isMember:!!i?.member,memberType:i?.member?.role||null,count:o?.pagination?.total||0}}},[Hr]:async(t,e)=>{const{banner:r,freeCourse:a,partnershipDetails:n,slug:s,title:i,registered:o,courseType:c}=t,l={banner:ea(r),slug:s,title:i,pill:a?"free":"premium",registered:!!o,courseType:c};if(n){const{partners:t}=n;if(t)if(t.length>1){let e=[];for(let r=0;r<t.length;r++)e.push(t[r].title);l.partner=e}else l.partner=[t[0].title]}if(void 0===o&&e){const[t]=await Ve.userProducts.list({courseSlug:s,isEnrolled:!0,scope:"active"});l.registered=!!t}return l},[Qr]:t=>{const{authorName:e,authorImage:r,icon:a,image:n,label:s,link:i,primaryText:o}=t;return{...t,banner:n?ea(n):null,customIcon:a?a.toLowerCase():null,customLabel:s,contributors:e?[{name:e,image:r?{thumbnail:ra(r)}:null}]:null,slug:i,text:o}},[Jr]:async(t,e)=>{const{bannerImage:r,defaultStartDate:a,isEventOngoing:n,slug:s,speakers:i,title:o,registered:c}=t,l=new Date(a),u=!!l&&l<new Date;if(i&&i.length)for(const t of i)t.image=ra(t.image);const E={banner:ea(r),dateHasPassed:u,title:o,slug:s,isOngoingEvent:n,contributors:i,startDate:l,registered:!!c};if(void 0===c&&e){const[t]=await Ve.userEvents.list({eventSlug:s});E.registered=!!t}return E},[Xr]:async t=>{const{hero:e,slug:r,title:a}=t;return{banner:ea(e),slug:r,title:a}},[Zr]:async t=>{const{answers:e,authorId:r,createdAt:a,slug:n,title:s}=t;let i=null;if(r){const t=await Ve.users.read(r);t&&(i=t)}return{answers:e&&e.length?e.length:0,contributors:i?[i]:[],createdAt:a,slug:n,title:s}},[zr]:t=>{const{bannerSection:e,customLabel:r,slug:a,title:n}=t;return{banner:ea(e.image),slug:a,title:n,customLabel:r}},people:t=>{const{id:e,name:r,jobTitle:a,location:n,image:s,customLink:i}=t;return{profile:s,slug:i?.link||e,title:r,text:a,secondaryText:n,customLinkText:i?.text}}};var sa=async({contentType:t,...e}={},r)=>{try{if(!na[t])throw new Error("Content type not supported");if("function"!=typeof na[t])throw new Error("No builder function for content type");return"people"!==t&&e.sys&&e.sys.type&&"Link"===e.sys.type&&(e=await Cr.read(t,e)),{contentType:t,...await na[t](e,r)}}catch(t){throw await w(t),new Error(`Cannot build carousel card: ${t.message}`)}},ia=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 xt(r.authorId)||{};const[n]=e?await Wt({contentType:a.CONTENTFUL.REPLIES.TYPE,contentSlug:r.slug}):[null];r.userLiked=!!n}return t.replies=n,t}catch(t){throw await w(t),new Error(`Cannot build replies for answer: ${t.message}`)}};const oa="success",ca="error";var la=t=>async e=>{const{contentType:r}=e;switch(r){case"event":try{return await pt.eventRegistrations.create({eventSlug:e.slug,expectation:null,userEmail:t.email,startsAt:new Date(e.startDate).toISOString()}),oa}catch(t){return reportError(new Error(`Error registering for event: ${JSON.stringify(t)}`)),ca}case"microcourse":try{return await pt.userProducts.create({id:t.id,courseSlug:e.slug,email:t.email,courseType:e.courseType}),oa}catch(t){return reportError(new Error(`Error registering for microcourse: ${JSON.stringify(t)}`)),ca}case"communityPage":try{return await $r.communities.join(e.slug,{...t.jobTitle&&{jobTitle:t.jobTitle},...t.organization&&{organization:t.organization},...t.image.thumbnail&&{thumbnail:t.image.thumbnail}}),oa}catch(t){return reportError(new Error(`Error joining community: ${JSON.stringify(t)}`)),ca}default:return ca}};var ua=function t(e,r){if(e===r)return!0;if(e&&r&&"object"==typeof e&&"object"==typeof r){if(e.constructor!==r.constructor)return!1;var a,n,s;if(Array.isArray(e)){if((a=e.length)!=r.length)return!1;for(n=a;0!=n--;)if(!t(e[n],r[n]))return!1;return!0}if(e.constructor===RegExp)return e.source===r.source&&e.flags===r.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===r.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===r.toString();if((a=(s=Object.keys(e)).length)!==Object.keys(r).length)return!1;for(n=a;0!=n--;)if(!Object.prototype.hasOwnProperty.call(r,s[n]))return!1;for(n=a;0!=n--;){var i=s[n];if(!t(e[i],r[i]))return!1}return!0}return e!=e&&r!=r};const Ea="__googleMapsScriptId";var Sa;!function(t){t[t.INITIALIZED=0]="INITIALIZED",t[t.LOADING=1]="LOADING",t[t.SUCCESS=2]="SUCCESS",t[t.FAILURE=3]="FAILURE"}(Sa||(Sa={}));class da{constructor({apiKey:t,authReferrerPolicy:e,channel:r,client:a,id:n=Ea,language:s,libraries:i=[],mapIds:o,nonce:c,region:l,retries:u=3,url:E="https://maps.googleapis.com/maps/api/js",version:S}){if(this.callbacks=[],this.done=!1,this.loading=!1,this.errors=[],this.apiKey=t,this.authReferrerPolicy=e,this.channel=r,this.client=a,this.id=n||Ea,this.language=s,this.libraries=i,this.mapIds=o,this.nonce=c,this.region=l,this.retries=u,this.url=E,this.version=S,da.instance){if(!ua(this.options,da.instance.options))throw new Error(`Loader must not be called again with different options. ${JSON.stringify(this.options)} !== ${JSON.stringify(da.instance.options)}`);return da.instance}da.instance=this}get options(){return{version:this.version,apiKey:this.apiKey,channel:this.channel,client:this.client,id:this.id,libraries:this.libraries,language:this.language,region:this.region,mapIds:this.mapIds,nonce:this.nonce,url:this.url,authReferrerPolicy:this.authReferrerPolicy}}get status(){return this.errors.length?Sa.FAILURE:this.done?Sa.SUCCESS:this.loading?Sa.LOADING:Sa.INITIALIZED}get failed(){return this.done&&!this.loading&&this.errors.length>=this.retries+1}createUrl(){let t=this.url;return t+="?callback=__googleMapsCallback",this.apiKey&&(t+=`&key=${this.apiKey}`),this.channel&&(t+=`&channel=${this.channel}`),this.client&&(t+=`&client=${this.client}`),this.libraries.length>0&&(t+=`&libraries=${this.libraries.join(",")}`),this.language&&(t+=`&language=${this.language}`),this.region&&(t+=`®ion=${this.region}`),this.version&&(t+=`&v=${this.version}`),this.mapIds&&(t+=`&map_ids=${this.mapIds.join(",")}`),this.authReferrerPolicy&&(t+=`&auth_referrer_policy=${this.authReferrerPolicy}`),t}deleteScript(){const t=document.getElementById(this.id);t&&t.remove()}load(){return this.loadPromise()}loadPromise(){return new Promise(((t,e)=>{this.loadCallback((r=>{r?e(r.error):t(window.google)}))}))}importLibrary(t){return this.execute(),google.maps.importLibrary(t)}loadCallback(t){this.callbacks.push(t),this.execute()}setScript(){var t,e;if(document.getElementById(this.id))return void this.callback();const r={key:this.apiKey,channel:this.channel,client:this.client,libraries:this.libraries.length&&this.libraries,v:this.version,mapIds:this.mapIds,language:this.language,region:this.region,authReferrerPolicy:this.authReferrerPolicy};Object.keys(r).forEach((t=>!r[t]&&delete r[t])),(null===(e=null===(t=null===window||void 0===window?void 0:window.google)||void 0===t?void 0:t.maps)||void 0===e?void 0:e.importLibrary)||(t=>{let e,r,a,n="The Google Maps JavaScript API",s="google",i="importLibrary",o="__ib__",c=document,l=window;l=l[s]||(l[s]={});const u=l.maps||(l.maps={}),E=new Set,S=new URLSearchParams,d=()=>e||(e=new Promise(((i,l)=>{return d=this,p=void 0,I=function*(){var d;for(a in yield r=c.createElement("script"),r.id=this.id,S.set("libraries",[...E]+""),t)S.set(a.replace(/[A-Z]/g,(t=>"_"+t[0].toLowerCase())),t[a]);S.set("callback",s+".maps."+o),r.src=this.url+"?"+S,u[o]=i,r.onerror=()=>e=l(Error(n+" could not load.")),r.nonce=this.nonce||(null===(d=c.querySelector("script[nonce]"))||void 0===d?void 0:d.nonce)||"",c.head.append(r)},new((h=void 0)||(h=Promise))((function(t,e){function r(t){try{n(I.next(t))}catch(t){e(t)}}function a(t){try{n(I.throw(t))}catch(t){e(t)}}function n(e){var n;e.done?t(e.value):(n=e.value,n instanceof h?n:new h((function(t){t(n)}))).then(r,a)}n((I=I.apply(d,p||[])).next())}));var d,p,h,I})));u[i]?console.warn(n+" only loads once. Ignoring:",t):u[i]=(t,...e)=>E.add(t)&&d().then((()=>u[i](t,...e)))})(r);const a=this.libraries.map((t=>this.importLibrary(t)));a.length||a.push(this.importLibrary("core")),Promise.all(a).then((()=>this.callback()),(t=>{const e=new ErrorEvent("error",{error:t});this.loadErrorCallback(e)}))}reset(){this.deleteScript(),this.done=!1,this.loading=!1,this.errors=[],this.onerrorEvent=null}resetIfRetryingFailed(){this.failed&&this.reset()}loadErrorCallback(t){if(this.errors.push(t),this.errors.length<=this.retries){const t=this.errors.length*Math.pow(2,this.errors.length);console.error(`Failed to load Google Maps script, retrying in ${t} ms.`),setTimeout((()=>{this.deleteScript(),this.setScript()}),t)}else this.onerrorEvent=t,this.callback()}callback(){this.done=!0,this.loading=!1,this.callbacks.forEach((t=>{t(this.onerrorEvent)})),this.callbacks=[]}execute(){if(this.resetIfRetryingFailed(),this.done)this.callback();else{if(window.google&&window.google.maps&&window.google.maps.version)return console.warn("Google Maps already loaded outside @googlemaps/js-api-loader.This may result in undesirable behavior as options and script parameters may not match."),void this.callback();this.loading||(this.loading=!0,this.setScript())}}}const{GOOGLE:{MAPS:{LIBRARIES:pa,VERSION:ha}}}=a;var Ia=function(t){return{city:async function(e){try{const r=await async function(){try{const{AutocompleteService:t}=await async function(t=pa.PLACES){const e=h(),r=new da({apiKey:e?.googleMaps?.apiKey,version:ha});return await r.importLibrary(t)}();return new t}catch(t){throw new Error("Unable to load google library:",t)}}();return new Promise((a=>{r.getPlacePredictions({...t,input:e,types:["(cities)"]},((t=[],e)=>{a("OK"===e?t:[])}))}))}catch(t){return console.error("Error with Autocomplete Service:",t),[]}}}},ga=l(408);const wa=t=>t&&ga.Buffer.from(t,"base64").toString("ascii");function ya({contentContext:a=null,errorsContext:l=null,googleMapsContext:u=null,gtmContext:h=null,origin:I}){try{const g=(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(i);return a?r=a[1].split(o)[0]:e===n?r=c:e.includes(s)&&(r=E),r||new Error(`Cannot select environment: No rule for website ${e}`),r})(I);return a&&(0,t.setContext)(Object.assign({},a,{environment:g})),l&&(0,e.setContext)(Object.assign({},l,{environment:g})),u&&(({apiKey:t})=>{p.googleMaps={apiKey:t}})(Object.assign({},u,{environment:g})),h&&((0,r.setContext)(Object.assign({},h,{environment:g})),(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:g})),g}catch(t){console.warn(`Cannot load SDK: ${t.message}`)}}}(),u}()}));
|
|
2
|
+
!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,i){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=i},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 o[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 T},auth:function(){return $},buildAnswer:function(){return ra},buildCardCtaClickHandler:function(){return sa},buildCarouselCard:function(){return ea},buildQuestion:function(){return xr},carouselCards:function(){return $r},contentInteraction:function(){return X},decodeBase64:function(){return pa},default:function(){return ha},editorialPages:function(){return _r},getEntries:function(){return t.getEntries},getEntry:function(){return t.getEntry},management:function(){return ut},mgmt:function(){return yt},payments:function(){return Nt},people:function(){return ke},peopleEngagement:function(){return He},predictPlace:function(){return Sa},qaQuestions:function(){return Gr},reportError:function(){return e.reportError},search:function(){return Ze},socials:function(){return Nr}});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"}},MANAGEMENT_API:{BASE_URL:"/api/management-api",ENDPOINTS:{ACCOUNTS:"/accounts",EVENT_REGISTRATIONS:"/event-registrations",LOGINS:"/logins",LOGIN_PASSWORDLESS:"/passwordless",BULK_ENROLMENTS:"/bulk-enrolments"}},MGMT_API:{BASE_URL:"/api/mgmt-api",ENDPOINTS:{REFERRALS:"/referrals",BULK_REFERRALS:"/bulk-referrals",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",COMMUNITIES:"/communities",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_REFERRALS:"/referrals",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"},PATHS:{ACTIVITIES:"activities",REACTIONS:"reactions"}}},CONTENTFUL:{ARTICLES:{TYPE:"solutionArticle"},CAROUSELS:{CARD_TYPES:{communityPage:{INCLUDE:1,SELECT:"fields.bannerSection,fields.slug,fields.title"},customCard:{INCLUDE:1,SELECT:"fields.icon,fields.label,fields.image,fields.primaryText,fields.secondaryText,fields.authorName,fields.authorImage,fields.link,fields.openInNewTab"},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"}}},COMMUNITY:{TYPE:"communityPage"},COURSES:{TYPE:"microcourse"},CUSTOM_CARD:{TYPE:"customCard"},EDITORIAL_PAGES:{INCLUDE:1,SELECT:"fields.carousels,fields.slug,fields.showCarouselCta,fields.header,fields.subHeader",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"}},GOOGLE:{MAPS:{LIBRARIES:{PLACES:"places"},VERSION:"weekly"}},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"},STATUS_CODES:{INVALID_TOKEN:498},ERROR_MESSAGES:{INVALID_TOKEN:"Invalid token error: Logging user out..."}};const{APOLITICAL:{WEBSITES:{LIVE:n,LOCALHOST:s,STAGING:i,STAGING_SPLITTER:o},ENVIRONMENTS:{PRODUCTION:c,LOCAL:E}}}=a,{HUBSPOT:{ENVIRONMENTS_MAPPING:S,EMAIL_IDS:d}}=a;let p={emailIds:{}};const h=()=>p;var I=l(300),g=l.n(I);const w=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:y,ENDPOINTS:{USERS:m,CERTIFICATES:A}}}}=a;var T={certificates:{create:async(t,e)=>{let r=[];try{const{data:a}=await g().post(`${y}${m}/${t}${A}`,e);a&&(r=a)}catch(t){await w(t)}return r}}};const{APIS:{AUTH_API:{BASE_URL:N,ENDPOINTS:{USER_PASSWORD:f,USERS:R}}},USERS:{MYSELF:P}}=a;var $={userPassword:{update:async t=>{let e=null;try{e=await g().put(`${N}${R}/${P}${f}`,t)}catch(t){e={message:(((t||{}).response||{}).data||{}).message},await w(t)}return e}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:L,ENDPOINTS:{ANSWERS:O,QUESTIONS:U,LIKES:C}}}}=a,_=`${L}${U}`;var v={create:async({questionSlug:t},e)=>{try{await g().post(`${_}/${encodeURIComponent(t)}${O}`,e)}catch(t){const e=await w(t);throw new Error(e)}},remove:async({questionSlug:t,answerSlug:e})=>{try{await g().delete(`${_}/${encodeURIComponent(t)}${O}/${encodeURIComponent(e)}`)}catch(t){const e=await w(t);throw new Error(e)}},update:async({questionSlug:t,answerSlug:e},r)=>{try{return await g().put(`${_}/${encodeURIComponent(t)}${O}/${encodeURIComponent(e)}`,r)}catch(t){const e=await w(t);throw new Error(e)}},like:async({questionSlug:t,answerSlug:e},r)=>{try{return await g().post(`${_}/${encodeURIComponent(t)}${O}/${encodeURIComponent(e)}${C}`,r)}catch(t){const e=await w(t);throw new Error(e)}},unlike:async({questionSlug:t,answerSlug:e})=>{try{return await g().delete(`${_}/${encodeURIComponent(t)}${O}/${encodeURIComponent(e)}${C}`)}catch(t){const e=await w(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:b,ENDPOINTS:{QUESTIONS:D}}}}=a,M=`${b}${D}`;var B={create:async t=>{try{return await g().post(M,t)}catch(t){const e=await w(t);throw new Error(e)}},remove:async({questionSlug:t})=>{try{await g().delete(`${M}/${encodeURIComponent(t)}`)}catch(t){const e=await w(t);throw new Error(e)}},update:async({questionSlug:t},e)=>{try{return await g().put(`${M}/${encodeURIComponent(t)}`,e)}catch(t){const e=await w(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:k,ENDPOINTS:{REPLIES:q,ANSWERS:G,QUESTIONS:x,LIKES:V}}}}=a,Y=`${k}${x}`,j=({questionSlug:t,answerSlug:e,replySlug:r},a=!1)=>{let n=`${Y}/${encodeURIComponent(t)}${G}/${encodeURIComponent(e)}${q}`;return r&&(n=`${n}/${encodeURIComponent(r)}`,a&&(n=`${n}${V}`)),n};var K={create:async({questionSlug:t,answerSlug:e},r)=>{try{return await g().post(j({questionSlug:t,answerSlug:e}),r)}catch(t){const e=await w(t);throw new Error(e)}},update:async({questionSlug:t,answerSlug:e,replySlug:r},a)=>{try{return await g().put(j({questionSlug:t,answerSlug:e,replySlug:r}),a)}catch(t){const e=await w(t);throw new Error(e)}},remove:async({questionSlug:t,answerSlug:e,replySlug:r})=>{try{await g().delete(j({questionSlug:t,answerSlug:e,replySlug:r}))}catch(t){const e=await w(t);throw new Error(e)}},like:async({questionSlug:t,answerSlug:e,replySlug:r,payload:a})=>{try{await g().post(j({questionSlug:t,answerSlug:e,replySlug:r},!0),a)}catch(t){const e=await w(t);throw new Error(e)}},unlike:async({questionSlug:t,answerSlug:e,replySlug:r})=>{try{await g().delete(j({questionSlug:t,answerSlug:e,replySlug:r},!0))}catch(t){const e=await w(t);throw new Error(e)}},getReplyUrl:j};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:F,ENDPOINTS:{QUESTIONS:H,ANSWERS:Q,LIKES:W}}}}=a,J=`${F}${H}`;var X={answers:v,questions:B,replies:K,likes:{create:async({questionSlug:t,answerSlug:e})=>{try{return await g().post(`${J}/${encodeURIComponent(t)}${Q}/${encodeURIComponent(e)}${W}`)}catch(t){const e=await w(t);throw new Error(e)}},remove:async({questionSlug:t,answerSlug:e})=>{try{return await g().delete(`${J}/${encodeURIComponent(t)}${Q}/${encodeURIComponent(e)}${W}`)}catch(t){const e=await w(t);throw new Error(e)}}}};const{APIS:{MANAGEMENT_API:{BASE_URL:Z,ENDPOINTS:{ACCOUNTS:z}}}}=a;var tt={create:async t=>{try{await g().post(`${Z}${z}`,t)}catch(t){throw await w(t),t}},read:async t=>{let e=null;try{({data:e}=await g().get(`${Z}${z}/${encodeURIComponent(t)}`))}catch(t){await w(t)}return e},update:async(t,e)=>{try{await g().put(`${Z}${z}/${encodeURIComponent(t)}`,e)}catch(t){throw await w(t),t}}};const{APIS:{MANAGEMENT_API:{BASE_URL:et,ENDPOINTS:{EVENT_REGISTRATIONS:rt}}}}=a;var at={create:async t=>{try{await g().post(`${et}${rt}`,t)}catch(t){const e=await w(t);throw new Error(e)}}};const{APIS:{MANAGEMENT_API:{BASE_URL:nt,ENDPOINTS:{LOGINS:st,LOGIN_PASSWORDLESS:it}}}}=a,ot=`${nt}${st}`;var ct={update:async t=>{try{await g().put(`${ot}/${encodeURIComponent(t)}${it}`)}catch(t){throw await w(t),t}}};const{APIS:{MANAGEMENT_API:{BASE_URL:lt}}}=a;var ut={accounts:tt,eventRegistrations:at,passwordless:ct,userProducts:{create:async t=>{try{await g().post(`${lt}/users/${t.id}/products`,t)}catch(t){const e=await w(t);throw new Error(e)}}}};const{APIS:{MGMT_API:{BASE_URL:Et,ENDPOINTS:{REFERRALS:St}}}}=a;var dt={create:async t=>{try{await g().post(`${Et}${St}`,t)}catch(t){throw await w(t),t}}};const{APIS:{MGMT_API:{BASE_URL:pt,ENDPOINTS:{BULK_REFERRALS:ht}}}}=a;var It={create:async t=>{try{await g().post(`${pt}${ht}`,t)}catch(t){throw await w(t),t}}};const{APIS:{MGMT_API:{BASE_URL:gt,ENDPOINTS:{BULK_ENROLMENTS:wt}}}}=a;var yt={referrals:dt,bulkReferrals:It,bulkEnrolments:{create:async t=>{try{await g().post(`${gt}${wt}`,t)}catch(t){throw await w(t),t}}}};const{APIS:{PAYMENTS_API:{BASE_URL_V2:mt,ENDPOINTS:{PRODUCTS:At}}}}=a,Tt=`${mt}${At}`;var Nt={products:{list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await g().get(Tt,r);t&&t.length&&(e=t)}catch(t){await w(t)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:ft,ENDPOINTS:{BULK_ENROLMENTS:Rt}}}}=a;var Pt={list:async t=>{let e=[];try{const{data:r}=await g().get(`${ft}${Rt}`,{params:t});r&&r.length&&(e=r)}catch(t){await w(t)}return e}},$t=l(25);const{OK:Lt,MULTIPLE_CHOICES:Ot,NOT_FOUND:Ut,FORBIDDEN:Ct}=$t.StatusCodes,_t=t=>t>=Lt&&t<Ot||t===Ct||t===Ut,{APIS:{PEOPLE_API:{BASE_URL_V2:vt,ENDPOINTS:{USERS:bt}}},STATUS_CODES:{INVALID_TOKEN:Dt},ERROR_MESSAGES:{INVALID_TOKEN:Mt}}=a,Bt=async t=>{let e=null;try{const{data:r}=await g().get(`${vt}${bt}/${encodeURIComponent(t)}`,{validateStatus:_t});r&&r.id&&(e=r)}catch(t){if(t?.response?.status===Dt)throw new Error(Mt);await w(t)}return e},kt=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 g().get(`${vt}${bt}?${r}`,{validateStatus:_t});a&&a.length&&(e=a)}catch(t){await w(t)}return e};var qt={read:Bt,update:async(t,e)=>{let r=!1;try{const{data:a}=await g().put(`${vt}${bt}/${encodeURIComponent(t)}`,e);r=!(!a||!a.id)}catch(t){await w(t)}return r},list:kt};const{APIS:{PEOPLE_API:{BASE_URL_V2:Gt,ENDPOINTS:{USERS:xt,USER_LIKES:Vt}}},USERS:{MYSELF:Yt}}=a,jt=`${Gt}${xt}/${Yt}${Vt}`,Kt=async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await g().get(jt,r);t&&t.length&&(e=t)}catch(t){await w(t)}return e};var Ft={list:Kt};var Ht={authors:{readQuestionAuthors:async(t,e,r)=>{try{if(t.author=await Bt(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 Bt(t.authorId)||{};const[r]=e?await Kt({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 w(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 Bt(t[0]);r&&e.push(r)}else if(t&&t.length>1){const r=await kt(t);r&&r.length>0&&(e=r)}}catch(t){throw await w(t),new Error(`Cannot read authors: ${t.message}`)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL:Qt,ENDPOINTS:{REGISTRATIONS:Wt}}}}=a;var Jt={list:async t=>{let e=[];try{const{data:r}=await g().get(`${Qt}${Wt}`,{params:t});r&&r.length&&(e=r)}catch(t){await w(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Xt,ENDPOINTS:{COMMUNITIES:Zt,USERS:zt}}}}=a,te=`${Xt}${zt}`;function ee(t){const e=t["content-range"].split(" ")[1].split("/"),[r,a,n]=[...e[0].split("-"),e[1]].map((t=>parseInt(t,10)||0));return{start:r,end:a,total:n}}var re={list:async(t="me",e={})=>{let r={items:[],start:0,end:0,total:0},a=e?{params:e}:{params:{}};try{const{data:e,headers:n}=await g().get(`${te}/${t}${Zt}`,{...a,headers:{"Cache-Control":"no-cache",Pragma:"no-cache",Expires:0}});return e?.length>0&&(r={data:e,pagination:ee(n)}),r}catch(t){await w(t)}return r}};const{APIS:{PEOPLE_API:{BASE_URL_V2:ae,ENDPOINTS:{USERS:ne,USER_COURSES:se}}},USERS:{MYSELF:ie}}=a,oe=`${ae}${ne}/${ie}${se}`;var ce={create:async t=>{try{await g().post(oe,t)}catch(t){await w(t)}},list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await g().get(oe,r);t&&t.length&&(e=t)}catch(t){await w(t)}return e},update:async(t,e)=>{try{await g().put(`${oe}/${t}`,e)}catch(t){await w(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:le,ENDPOINTS:{USERS:ue,USER_EVENTS:Ee}}},USERS:{MYSELF:Se}}=a,de=`${le}${ue}/${Se}${Ee}`;var pe={list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await g().get(de,r);t&&t.length&&(e=t)}catch(t){await w(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:he,ENDPOINTS:{USERS:Ie,USER_LESSONS:ge}}},USERS:{MYSELF:we}}=a,ye=`${he}${Ie}/${we}${ge}`;var me={create:async t=>{let e=null;try{e=await g().post(ye,t)}catch(t){await w(t)}return e},list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await g().get(ye,r);t&&t.length&&(e=t)}catch(t){await w(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Ae,ENDPOINTS:{USERS:Te,USER_PRODUCTS:Ne}}},USERS:{MYSELF:fe}}=a,Re=`${Ae}${Te}/${fe}${Ne}`;var Pe={create:async t=>{let e=null;try{e=await g().post(Re,t)}catch(t){await w(t)}return e},list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await g().get(Re,r);t&&t.length&&(e=t)}catch(t){await w(t)}return e},update:async(t,e)=>{try{await g().put(`${Re}/${t}`,e)}catch(t){await w(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:$e,ENDPOINTS:{USERS:Le,USER_RATINGS:Oe}}},USERS:{MYSELF:Ue}}=a,Ce=`${$e}${Le}/${Ue}${Oe}`;var _e={create:async t=>{let e=null;try{const{data:r}=await g().post(Ce,t);r?.id&&(e=r)}catch(t){await w(t)}return e},update:async(t,e)=>{try{await g().put(`${Ce}/${t}`,e)}catch(t){await w(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:ve,ENDPOINTS:{USERS:be,USER_REFERRALS:De}}},USERS:{MYSELF:Me}}=a,Be=`${ve}${be}/${Me}${De}`;var ke={bulkEnrolments:Pt,handlers:Ht,registrations:Jt,users:qt,userCommunities:re,userCourses:ce,userEvents:pe,userLessons:me,userLikes:Ft,userProducts:Pe,userRatings:_e,userReferrals:{list:async t=>{let e=[],r=t?{params:t}:{params:{}};try{const{data:t}=await g().get(Be,r);t&&t.length&&(e=t)}catch(t){await w(t)}return e}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:qe,ENDPOINTS:{ENQUIRY_EMAILS:Ge}}}}=a;var xe={create:async t=>{let e=null;try{const{data:r}=await g().post(`${qe}${Ge}`,t);r&&(e=r)}catch(t){await w(t)}return e}},Ve={forms:{sendEnquiryEmails:async t=>{let e=null;try{const{emailIds:r}=h();e=await He.emails.create({...r,...t})}catch(t){await w(t)}return e}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:Ye,ENDPOINTS:{USERS:je,USER_PROPERTIES:Ke}}},USERS:{MYSELF:Fe}}=a;var He={emails:xe,handlers:Ve,userProperties:{update:async(t,e)=>{try{await g().put(`${Ye}${je}/${Fe}${Ke}/${t}`,e)}catch(t){await w(t)}}}},Qe=l(130);const{APIS:{SEARCH_API:{BASE_URL:We,ENDPOINTS:{SEARCH:Je}}}}=a,Xe=`${We}${Je}`;var Ze={ask:async t=>{try{let e=null;const{data:r}=await g().get(Xe,{params:{question:t}});return r?.answer&&r?.references&&r?.version&&(e=r),e}catch(t){const e=await w(t);throw new Error(e)}},stream:(t,e,r)=>{const a=(0,Qe.io)(void 0,{path:"/api/search-api/web-sockets"});function n(){a.emit("search",{question:t})}function s(t){r(t),i(),a.disconnect()}function i(){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),i}};const{APIS:{SOCIALS_API:{BASE_URL:ze,ENDPOINTS:{COMMUNITIES:tr},PATHS:{ACTIVITIES:er}}}}=a,rr=`${ze}${tr}`;var ar={read:async(t,e)=>{let r=null;try{const{data:a}=await g().get(`${rr}/${encodeURIComponent(t)}/${er}/${e}`);a&&(r=a)}catch(t){await w(t)}return r},list:async(t,e={})=>{let r=null;try{const{data:a}=await g().get(`${rr}/${encodeURIComponent(t)}/${er}`,{params:e});a&&(r=a)}catch(t){await w(t)}return r},create:async(t,e)=>{let r=null;try{const{data:a}=await g().post(`${rr}/${encodeURIComponent(t)}/${er}`,e);a?.content&&(r=a)}catch(t){await w(t)}return r},update:async(t,e,r)=>{let a=null;try{const{data:n}=await g().put(`${rr}/${encodeURIComponent(t)}/${er}/${e}`,r);n?.content&&(a=n)}catch(t){await w(t)}return a},remove:async(t,e)=>{let r=null;try{const{data:a}=await g().delete(`${rr}/${encodeURIComponent(t)}/${er}/${e}`);r=a}catch(t){await w(t)}return r}};const{APIS:{SOCIALS_API:{BASE_URL:nr,ENDPOINTS:{COMMUNITIES:sr}}}}=a,ir=`${nr}${sr}`;var or={read:async t=>{let e=null;try{const{data:r}=await g().get(`${ir}/${encodeURIComponent(t)}`);r?.title&&(e=r)}catch(t){await w(t)}return e},join:async(t,e)=>{let r=null;try{const{data:a}=await g().post(`${ir}/${encodeURIComponent(t)}/members`,e);r=a}catch(t){await w(t)}return r},leave:async t=>{let e=null;try{const{data:r}=await g().delete(`${ir}/${encodeURIComponent(t)}/members/me`);e=r}catch(t){await w(t)}return e}};const{APIS:{SOCIALS_API:{BASE_URL:cr,ENDPOINTS:{COMMUNITIES:lr},PATHS:{ACTIVITIES:ur,REACTIONS:Er}}}}=a,Sr=`${cr}${lr}`;var dr={create:async({slug:t,activityId:e,reactionId:r})=>{let a=null;const n={kind:"like"};let s=`${Sr}/${encodeURIComponent(t)}`;s=e?`${s}/${ur}/${e}/${Er}`:`${s}/${Er}/${r}/${Er}`;try{const{data:t}=await g().post(s,n);a=t}catch(t){await w(t)}return a},remove:async({slug:t,reactionId:e})=>{let r=null;try{const{data:a}=await g().delete(`${Sr}/${encodeURIComponent(t)}/${Er}/${e}`);r=a}catch(t){await w(t)}return r}};const{APIS:{SOCIALS_API:{BASE_URL:pr,ENDPOINTS:{COMMUNITIES:hr}}}}=a,Ir=`${pr}${hr}`;var gr={list:async(t,e)=>{let r={data:[],pagination:{start:0,end:0,total:0}},a=e?{params:e}:{params:{}};try{const{data:e}=await g().get(`${Ir}/${encodeURIComponent(t)}/members`,{...a,headers:{"Cache-Control":"no-cache",Pragma:"no-cache",Expires:0}});e?.data?.length>0&&(r=e)}catch(t){await w(t)}return r}};const{APIS:{SOCIALS_API:{BASE_URL:wr,ENDPOINTS:{COMMUNITIES:yr},PATHS:{ACTIVITIES:mr,REACTIONS:Ar}}}}=a,Tr=`${wr}${yr}`;var Nr={activities:ar,communities:or,members:gr,likes:dr,reactions:{create:async(t,e,r,a)=>{let n=null,s=`${Tr}/${encodeURIComponent(t)}`;s=e?`${s}/${mr}/${e}/${Ar}`:`${s}/${Ar}/${r}/${Ar}`;try{const{data:t}=await g().post(s,a);n=t}catch(t){await w(t)}return n},list:async(t,{activityId:e,reactionId:r},a={})=>{let n=null,s=`${Tr}/${encodeURIComponent(t)}`;s=e?`${s}/${mr}/${e}/${Ar}`:`${s}/${Ar}/${r}/${Ar}`;try{const{data:t}=await g().get(s,{params:a});t&&(n=t)}catch(t){await w(t)}return n},remove:async(t,e)=>{let r=null;try{const{data:a}=await g().delete(`${Tr}/${encodeURIComponent(t)}/${Ar}/${e}`);r=a}catch(t){await w(t)}return r},update:async(t,e,r,a)=>{let n=null,s=`${Tr}/${encodeURIComponent(t)}`;s=e?`${s}/${mr}/${e}`:`${s}/${Ar}/${r}`;try{const{data:t}=await g().put(s,a);n=t}catch(t){await w(t)}return n}}};const{CONTENTFUL:fr}=a,{CARD_TYPES:Rr}=fr.CAROUSELS,Pr={read:async(e,r)=>{try{if(!r||!r.sys||!r.sys.id)throw new Error("Invalid link to card");if(!e||!Rr[e])throw new Error("Unsupported card content type");const{INCLUDE:a,SELECT:n}=Rr[e];return await(0,t.getEntry)({content_type:e,"sys.id":r.sys.id,include:a,select:n},{assetDetails:!0})}catch(t){throw await w(t),new Error(`Cannot read carousel card: ${t.message}`)}}};var $r=Pr;const{CONTENTFUL:Lr}=a,{INCLUDE:Or,SELECT:Ur,TYPE:Cr}=Lr.EDITORIAL_PAGES;var _r={read:async e=>{try{return await(0,t.getEntry)({content_type:Cr,"fields.slug":e,include:Or,select:Ur})}catch(t){throw await w(t),new Error(`Cannot read editorial page: ${t.message}`)}}};const{CONTENTFUL:vr}=a,{TYPE:br,ORDER:Dr,SELECT:Mr,SKIP:Br,LIMIT:kr,INCLUDE:qr}=vr.QUESTIONS;var Gr={read:async e=>{try{return await(0,t.getEntry)({content_type:br,"fields.slug":e,include:2,select:Mr})}catch(t){throw await w(t),new Error(`Cannot read question: ${t.message}`)}},list:async(e={})=>{try{return await(0,t.getEntries)({content_type:br,include:qr,limit:kr,order:Dr,select:Mr,skip:Br,...e})}catch(t){throw await w(t),new Error(`Cannot list questions: ${t.message}`)}}},xr=async(t,e,r={ignoreAnswersAuthors:!1})=>{try{let a={};return a=await Gr.read(t),a=await ke.handlers.authors.readQuestionAuthors(a,e,r),a}catch(t){throw await w(t),new Error(`Cannot build question: ${t.message}`)}};const{ARTICLES:{TYPE:Vr},COURSES:{TYPE:Yr},CUSTOM_CARD:{TYPE:jr},COMMUNITY:{TYPE:Kr},EVENTS:{TYPE:Fr},LISTS:{TYPE:Hr},QUESTIONS:{TYPE:Qr},LEARNING_HUB:{TYPE:Wr}}=a.CONTENTFUL,Jr={ClosedHidden:"closed-hidden",ClosedVisible:"closed-visible",OpenHidden:"open-hidden",OpenVisible:"open-visible"},Xr=t=>t&&t.url?(Object.assign(t,{aspect:"responsiveCard",query:"q=90&fit=fill"}),t):null,Zr=t=>t&&t.url?`${t.url}?w=100&h=100&fit=thumb&f=center`:null,zr=t=>t.toLowerCase().split(" ")[0],ta={[Vr]:async t=>{const{authorIds:e,authorTag:r,image:a,publishedDate:n,readingTime:s,slug:i,title:o}=t,c=await ke.handlers.authors.readAuthors(e),l=c&&c.length?c:r?[zr(r)]:null;return{banner:Xr(a),contributors:l,publishedDate:n,readingTime:s,slug:i,title:o}},[Kr]:async t=>{const{title:e,slug:r,bannerSection:a,privacy:n,createdAt:s}=t,i=await Nr.communities.read(r),o=await Nr.members.list(r,{count:1}),c=[Jr.ClosedVisible,Jr.ClosedHidden].includes(n),l=[Jr.OpenVisible,Jr.ClosedVisible].includes(n);return{banner:a?.image?Xr(a.image):null,slug:r,title:e,privacy:n,isPrivate:c,isVisible:l,createdAt:s,members:{isMember:!!i?.member,memberType:i?.member?.role||null,count:o?.pagination?.total||0}}},[Yr]:async(t,e)=>{const{banner:r,freeCourse:a,partnershipDetails:n,slug:s,title:i,registered:o,courseType:c}=t,l={banner:Xr(r),slug:s,title:i,pill:a?"free":"premium",registered:!!o,courseType:c};if(n){const{partners:t}=n;if(t)if(t.length>1){let e=[];for(let r=0;r<t.length;r++)e.push(t[r].title);l.partner=e}else l.partner=[t[0].title]}if(void 0===o&&e){const[t]=await ke.userProducts.list({courseSlug:s,isEnrolled:!0,scope:"active"});l.registered=!!t}return l},[jr]:t=>{const{authorName:e,authorImage:r,icon:a,image:n,label:s,link:i,primaryText:o}=t;return{...t,banner:n?Xr(n):null,customIcon:a?a.toLowerCase():null,customLabel:s,contributors:e?[{name:e,image:r?{thumbnail:Zr(r)}:null}]:null,slug:i,text:o}},[Fr]:async(t,e)=>{const{bannerImage:r,defaultStartDate:a,isEventOngoing:n,slug:s,speakers:i,title:o,registered:c}=t,l=new Date(a),u=!!l&&l<new Date;if(i&&i.length)for(const t of i)t.image=Zr(t.image);const E={banner:Xr(r),dateHasPassed:u,title:o,slug:s,isOngoingEvent:n,contributors:i,startDate:l,registered:!!c};if(void 0===c&&e){const[t]=await ke.userEvents.list({eventSlug:s});E.registered=!!t}return E},[Hr]:async t=>{const{hero:e,slug:r,title:a}=t;return{banner:Xr(e),slug:r,title:a}},[Qr]:async t=>{const{answers:e,authorId:r,createdAt:a,slug:n,title:s}=t;let i=null;if(r){const t=await ke.users.read(r);t&&(i=t)}return{answers:e&&e.length?e.length:0,contributors:i?[i]:[],createdAt:a,slug:n,title:s}},[Wr]:t=>{const{bannerSection:e,customLabel:r,slug:a,title:n}=t;return{banner:Xr(e.image),slug:a,title:n,customLabel:r}},people:t=>{const{id:e,name:r,jobTitle:a,location:n,image:s,customLink:i}=t;return{profile:s,slug:i?.link||e,title:r,text:a,secondaryText:n,customLinkText:i?.text}}};var ea=async({contentType:t,...e}={},r)=>{try{if(!ta[t])throw new Error("Content type not supported");if("function"!=typeof ta[t])throw new Error("No builder function for content type");return"people"!==t&&e.sys&&e.sys.type&&"Link"===e.sys.type&&(e=await $r.read(t,e)),{contentType:t,...await ta[t](e,r)}}catch(t){throw await w(t),new Error(`Cannot build carousel card: ${t.message}`)}},ra=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 Bt(r.authorId)||{};const[n]=e?await Kt({contentType:a.CONTENTFUL.REPLIES.TYPE,contentSlug:r.slug}):[null];r.userLiked=!!n}return t.replies=n,t}catch(t){throw await w(t),new Error(`Cannot build replies for answer: ${t.message}`)}};const aa="success",na="error";var sa=t=>async e=>{const{contentType:r}=e;switch(r){case"event":try{return await ut.eventRegistrations.create({eventSlug:e.slug,expectation:null,userEmail:t.email,startsAt:new Date(e.startDate).toISOString()}),aa}catch(t){return reportError(new Error(`Error registering for event: ${JSON.stringify(t)}`)),na}case"microcourse":try{return await ut.userProducts.create({id:t.id,courseSlug:e.slug,email:t.email,courseType:e.courseType}),aa}catch(t){return reportError(new Error(`Error registering for microcourse: ${JSON.stringify(t)}`)),na}case"communityPage":try{return await Nr.communities.join(e.slug,{...t.jobTitle&&{jobTitle:t.jobTitle},...t.organization&&{organization:t.organization},...t.image.thumbnail&&{thumbnail:t.image.thumbnail}}),aa}catch(t){return reportError(new Error(`Error joining community: ${JSON.stringify(t)}`)),na}default:return na}};var ia=function t(e,r){if(e===r)return!0;if(e&&r&&"object"==typeof e&&"object"==typeof r){if(e.constructor!==r.constructor)return!1;var a,n,s;if(Array.isArray(e)){if((a=e.length)!=r.length)return!1;for(n=a;0!=n--;)if(!t(e[n],r[n]))return!1;return!0}if(e.constructor===RegExp)return e.source===r.source&&e.flags===r.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===r.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===r.toString();if((a=(s=Object.keys(e)).length)!==Object.keys(r).length)return!1;for(n=a;0!=n--;)if(!Object.prototype.hasOwnProperty.call(r,s[n]))return!1;for(n=a;0!=n--;){var i=s[n];if(!t(e[i],r[i]))return!1}return!0}return e!=e&&r!=r};const oa="__googleMapsScriptId";var ca;!function(t){t[t.INITIALIZED=0]="INITIALIZED",t[t.LOADING=1]="LOADING",t[t.SUCCESS=2]="SUCCESS",t[t.FAILURE=3]="FAILURE"}(ca||(ca={}));class la{constructor({apiKey:t,authReferrerPolicy:e,channel:r,client:a,id:n=oa,language:s,libraries:i=[],mapIds:o,nonce:c,region:l,retries:u=3,url:E="https://maps.googleapis.com/maps/api/js",version:S}){if(this.callbacks=[],this.done=!1,this.loading=!1,this.errors=[],this.apiKey=t,this.authReferrerPolicy=e,this.channel=r,this.client=a,this.id=n||oa,this.language=s,this.libraries=i,this.mapIds=o,this.nonce=c,this.region=l,this.retries=u,this.url=E,this.version=S,la.instance){if(!ia(this.options,la.instance.options))throw new Error(`Loader must not be called again with different options. ${JSON.stringify(this.options)} !== ${JSON.stringify(la.instance.options)}`);return la.instance}la.instance=this}get options(){return{version:this.version,apiKey:this.apiKey,channel:this.channel,client:this.client,id:this.id,libraries:this.libraries,language:this.language,region:this.region,mapIds:this.mapIds,nonce:this.nonce,url:this.url,authReferrerPolicy:this.authReferrerPolicy}}get status(){return this.errors.length?ca.FAILURE:this.done?ca.SUCCESS:this.loading?ca.LOADING:ca.INITIALIZED}get failed(){return this.done&&!this.loading&&this.errors.length>=this.retries+1}createUrl(){let t=this.url;return t+="?callback=__googleMapsCallback",this.apiKey&&(t+=`&key=${this.apiKey}`),this.channel&&(t+=`&channel=${this.channel}`),this.client&&(t+=`&client=${this.client}`),this.libraries.length>0&&(t+=`&libraries=${this.libraries.join(",")}`),this.language&&(t+=`&language=${this.language}`),this.region&&(t+=`®ion=${this.region}`),this.version&&(t+=`&v=${this.version}`),this.mapIds&&(t+=`&map_ids=${this.mapIds.join(",")}`),this.authReferrerPolicy&&(t+=`&auth_referrer_policy=${this.authReferrerPolicy}`),t}deleteScript(){const t=document.getElementById(this.id);t&&t.remove()}load(){return this.loadPromise()}loadPromise(){return new Promise(((t,e)=>{this.loadCallback((r=>{r?e(r.error):t(window.google)}))}))}importLibrary(t){return this.execute(),google.maps.importLibrary(t)}loadCallback(t){this.callbacks.push(t),this.execute()}setScript(){var t,e;if(document.getElementById(this.id))return void this.callback();const r={key:this.apiKey,channel:this.channel,client:this.client,libraries:this.libraries.length&&this.libraries,v:this.version,mapIds:this.mapIds,language:this.language,region:this.region,authReferrerPolicy:this.authReferrerPolicy};Object.keys(r).forEach((t=>!r[t]&&delete r[t])),(null===(e=null===(t=null===window||void 0===window?void 0:window.google)||void 0===t?void 0:t.maps)||void 0===e?void 0:e.importLibrary)||(t=>{let e,r,a,n="The Google Maps JavaScript API",s="google",i="importLibrary",o="__ib__",c=document,l=window;l=l[s]||(l[s]={});const u=l.maps||(l.maps={}),E=new Set,S=new URLSearchParams,d=()=>e||(e=new Promise(((i,l)=>{return d=this,p=void 0,I=function*(){var d;for(a in yield r=c.createElement("script"),r.id=this.id,S.set("libraries",[...E]+""),t)S.set(a.replace(/[A-Z]/g,(t=>"_"+t[0].toLowerCase())),t[a]);S.set("callback",s+".maps."+o),r.src=this.url+"?"+S,u[o]=i,r.onerror=()=>e=l(Error(n+" could not load.")),r.nonce=this.nonce||(null===(d=c.querySelector("script[nonce]"))||void 0===d?void 0:d.nonce)||"",c.head.append(r)},new((h=void 0)||(h=Promise))((function(t,e){function r(t){try{n(I.next(t))}catch(t){e(t)}}function a(t){try{n(I.throw(t))}catch(t){e(t)}}function n(e){var n;e.done?t(e.value):(n=e.value,n instanceof h?n:new h((function(t){t(n)}))).then(r,a)}n((I=I.apply(d,p||[])).next())}));var d,p,h,I})));u[i]?console.warn(n+" only loads once. Ignoring:",t):u[i]=(t,...e)=>E.add(t)&&d().then((()=>u[i](t,...e)))})(r);const a=this.libraries.map((t=>this.importLibrary(t)));a.length||a.push(this.importLibrary("core")),Promise.all(a).then((()=>this.callback()),(t=>{const e=new ErrorEvent("error",{error:t});this.loadErrorCallback(e)}))}reset(){this.deleteScript(),this.done=!1,this.loading=!1,this.errors=[],this.onerrorEvent=null}resetIfRetryingFailed(){this.failed&&this.reset()}loadErrorCallback(t){if(this.errors.push(t),this.errors.length<=this.retries){const t=this.errors.length*Math.pow(2,this.errors.length);console.error(`Failed to load Google Maps script, retrying in ${t} ms.`),setTimeout((()=>{this.deleteScript(),this.setScript()}),t)}else this.onerrorEvent=t,this.callback()}callback(){this.done=!0,this.loading=!1,this.callbacks.forEach((t=>{t(this.onerrorEvent)})),this.callbacks=[]}execute(){if(this.resetIfRetryingFailed(),this.done)this.callback();else{if(window.google&&window.google.maps&&window.google.maps.version)return console.warn("Google Maps already loaded outside @googlemaps/js-api-loader.This may result in undesirable behavior as options and script parameters may not match."),void this.callback();this.loading||(this.loading=!0,this.setScript())}}}const{GOOGLE:{MAPS:{LIBRARIES:ua,VERSION:Ea}}}=a;var Sa=function(t){return{city:async function(e){try{const r=await async function(){try{const{AutocompleteService:t}=await async function(t=ua.PLACES){const e=h(),r=new la({apiKey:e?.googleMaps?.apiKey,version:Ea});return await r.importLibrary(t)}();return new t}catch(t){throw new Error("Unable to load google library:",t)}}();return new Promise((a=>{r.getPlacePredictions({...t,input:e,types:["(cities)"]},((t=[],e)=>{a("OK"===e?t:[])}))}))}catch(t){return console.error("Error with Autocomplete Service:",t),[]}}}},da=l(408);const pa=t=>t&&da.Buffer.from(t,"base64").toString("ascii");function ha({contentContext:a=null,errorsContext:l=null,googleMapsContext:u=null,gtmContext:h=null,origin:I}){try{const g=(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(i);return a?r=a[1].split(o)[0]:e===n?r=c:e.includes(s)&&(r=E),r||new Error(`Cannot select environment: No rule for website ${e}`),r})(I);return a&&(0,t.setContext)(Object.assign({},a,{environment:g})),l&&(0,e.setContext)(Object.assign({},l,{environment:g})),u&&(({apiKey:t})=>{p.googleMaps={apiKey:t}})(Object.assign({},u,{environment:g})),h&&((0,r.setContext)(Object.assign({},h,{environment:g})),(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:g})),g}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": "10.0.2-
|
|
3
|
+
"version": "10.0.2-rc.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": "cd
|
|
19
|
+
"prepare": "cd ../../../../../ && husky install frontend/modules/v1/apolitical-sdk/.husky",
|
|
20
20
|
"prepack": "yarn build"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|