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