@apolitical/sdk 3.1.1 → 3.2.0-rc.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/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [3.2.0] - 2023-01-19
9
+ ### Added
10
+ - Functionality to read an editorial page
11
+ - Functionality to build slider card
12
+
8
13
  ## [3.1.1] - 2023-01-18
9
14
  ### Changed
10
15
  - apolitical/content version to 0.7.0
package/build/index.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@apolitical/auth"),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/auth","@apolitical/content","@apolitical/error-reporting","@apolitical/gtm","axios","http-status-codes","buffer"],e):"object"==typeof exports?exports.ApoliticalSDK=e(require("@apolitical/auth"),require("@apolitical/content"),require("@apolitical/error-reporting"),require("@apolitical/gtm"),require("axios"),require("http-status-codes"),require("buffer")):t.ApoliticalSDK=e(t["@apolitical/auth"],t["@apolitical/content"],t["@apolitical/error-reporting"],t["@apolitical/gtm"],t.axios,t["http-status-codes"],t.buffer)}(this,(function(t,e,a,n,r,o,s){return function(){"use strict";var i={654:function(e){e.exports=t},809:function(t){t.exports=e},30:function(t){t.exports=a},36:function(t){t.exports=n},300:function(t){t.exports=r},408:function(t){t.exports=s},25:function(t){t.exports=o}},c={};function S(t){var e=c[t];if(void 0!==e)return e.exports;var a=c[t]={exports:{}};return i[t](a,a.exports,S),a.exports}S.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return S.d(e,{a:e}),e},S.d=function(t,e){for(var a in e)S.o(e,a)&&!S.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:e[a]})},S.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},S.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var E={};return function(){S.r(E),S.d(E,{assets:function(){return T},auth:function(){return _},buildQuestion:function(){return Se},buildQuestions:function(){return Ee},contentInteraction:function(){return F},contentSuggestion:function(){return J},decodeBase64:function(){return le},default:function(){return pe},getAuthContext:function(){return t.getContext},getEntries:function(){return e.getEntries},getEntry:function(){return e.getEntry},management:function(){return ot},passwordlessLogin:function(){return t.passwordlessLogin},payments:function(){return St},people:function(){return Kt},peopleEngagement:function(){return ne},reportError:function(){return a.reportError},sendVerificationEmail:function(){return t.sendVerificationEmail}});var t=S(654),e=S(809),a=S(30),n=S(36),r={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",LIKES:"/likes"}},CONTENT_SUGGESTIONS_API:{BASE_URL:"/api/content-suggestions-api",ENDPOINTS:{SUGGESTIONS:"/suggest"}},MANAGEMENT_API:{BASE_URL:"/api/management-api",ENDPOINTS:{ACCOUNTS:"/accounts",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_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:{QUESTIONS:{TYPE:"qaQuestion",ORDER:"-sys.updatedAt",FIELDS:"sys.createdAt,sys.updatedAt,fields.title,fields.slug,fields.authorId,fields.answers,fields.isEdited"}},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:o,LOCALHOST:s,STAGING:i,STAGING_SPLITTER:c},ENVIRONMENTS:{PRODUCTION:u,LOCAL:l}}}=r,{HUBSPOT:{ENVIRONMENTS_MAPPING:p,EMAIL_IDS:I}}=r;let d={emailIds:{}};var N=S(300),w=S.n(N);const A=async t=>{try{const{message:e,response:n,request:r}=t;let o=e;return n?o+=` - The request was made and the server responded with ${JSON.stringify({status:n.status,data:n.data})}`:r&&(o+=" - The request was made but no response was received"),console.warn(o),await(0,a.reportError)(new Error(o)),o}catch(t){return console.warn(`Cannot handle error: ${t.message}`),t.message}},{APIS:{ASSETS_API:{BASE_URL:P,ENDPOINTS:{USERS:R,CERTIFICATES:O}}}}=r;var T={certificates:{create:async(t,e)=>{let a=[];try{const{data:n}=await w().post(`${P}${R}/${t}${O}`,e);n&&(a=n)}catch(t){await A(t)}return a}}};const{APIS:{AUTH_API:{BASE_URL:U,ENDPOINTS:{USER_PASSWORD:h,USERS:y}}},USERS:{MYSELF:$}}=r;var _={userPassword:{update:async t=>{let e=null;try{e=await w().put(`${U}${y}/${$}${h}`,t)}catch(t){e={message:(((t||{}).response||{}).data||{}).message},await A(t)}return e}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:m,ENDPOINTS:{ANSWERS:f,QUESTIONS:g}}}}=r,L=`${m}${g}`;var C={create:async(t,e)=>{try{await w().post(`${L}/${encodeURIComponent(t)}${f}`,e)}catch(t){const e=await A(t);throw new Error(e)}},remove:async(t,e)=>{try{await w().delete(`${L}/${encodeURIComponent(t)}${f}/${encodeURIComponent(e)}`)}catch(t){const e=await A(t);throw new Error(e)}},update:async(t,e,a)=>{try{return await w().put(`${L}/${encodeURIComponent(t)}${f}/${encodeURIComponent(e)}`,{body:a})}catch(t){const e=await A(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:v,ENDPOINTS:{QUESTIONS:D}}}}=r,B=`${v}${D}`;var G={create:async t=>{try{return await w().post(B,t)}catch(t){const e=await A(t);throw new Error(e)}},remove:async t=>{try{await w().delete(`${B}/${encodeURIComponent(t)}`)}catch(t){const e=await A(t);throw new Error(e)}},update:async(t,e)=>{try{return await w().put(`${B}/${encodeURIComponent(t)}`,{title:e})}catch(t){const e=await A(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:M,ENDPOINTS:{QUESTIONS:b,ANSWERS:x,LIKES:q}}}}=r,V=`${M}${b}`;var F={answers:C,questions:G,likes:{create:async(t,e)=>{try{return await w().post(`${V}/${encodeURIComponent(t)}${x}/${encodeURIComponent(e)}${q}`)}catch(t){const e=await A(t);throw new Error(e)}},remove:async(t,e)=>{try{return await w().delete(`${V}/${encodeURIComponent(t)}${x}/${encodeURIComponent(e)}${q}`)}catch(t){const e=await A(t);throw new Error(e)}}}},Y=S(25);const{OK:j,MULTIPLE_CHOICES:Q,NOT_FOUND:W,FORBIDDEN:H}=Y.StatusCodes,K=t=>t>=j&&t<Q||t===H||t===W,{APIS:{CONTENT_SUGGESTIONS_API:{BASE_URL:k,ENDPOINTS:{SUGGESTIONS:X}}}}=r;var J={suggestions:{list:async(t={})=>{let e=[],a=Object.assign({validateStatus:K},t);try{const{data:t}=await w().get(`${k}${X}`,a);t&&t.length&&(e=t)}catch(t){await A(t)}return e}}};const{APIS:{MANAGEMENT_API:{BASE_URL:z,ENDPOINTS:{ACCOUNTS:Z}}}}=r;var tt={create:async t=>{try{await w().post(`${z}${Z}`,t)}catch(t){throw await A(t),t}},read:async t=>{let e=null;try{({data:e}=await w().get(`${z}${Z}/${encodeURIComponent(t)}`))}catch(t){await A(t)}return e},update:async(t,e)=>{try{await w().put(`${z}${Z}/${encodeURIComponent(t)}`,e)}catch(t){throw await A(t),t}}};const{APIS:{MANAGEMENT_API:{BASE_URL:et,ENDPOINTS:{LOGINS:at,LOGIN_PASSWORDLESS:nt}}}}=r,rt=`${et}${at}`;var ot={accounts:tt,passwordless:{update:async t=>{try{await w().put(`${rt}/${encodeURIComponent(t)}${nt}`)}catch(t){throw await A(t),t}}}};const{APIS:{PAYMENTS_API:{BASE_URL_V2:st,ENDPOINTS:{PRODUCTS:it}}}}=r,ct=`${st}${it}`;var St={products:{list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await w().get(ct,a);t&&t.length&&(e=t)}catch(t){await A(t)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Et,ENDPOINTS:{USERS:ut}}}}=r,lt=async t=>{let e=null;try{const{data:a}=await w().get(`${Et}${ut}/${encodeURIComponent(t)}`,{validateStatus:K});a&&a.id&&(e=a)}catch(t){await A(t)}return e};var pt={read:lt,update:async(t,e)=>{let a=!1;try{const{data:n}=await w().put(`${Et}${ut}/${encodeURIComponent(t)}`,e);a=!(!n||!n.id)}catch(t){await A(t)}return a}};const{APIS:{PEOPLE_API:{BASE_URL_V2:It,ENDPOINTS:{USERS:dt,USER_ANSWERS:Nt}}},USERS:{MYSELF:wt}}=r,At=`${It}${dt}/${wt}${Nt}`,Pt=async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await w().get(At,a);t&&t.length&&(e=t)}catch(t){await A(t)}return e};var Rt={list:Pt},Ot={authors:{readQuestionAuthors:async(t,e,a=!1)=>{try{if(t.author=await lt(t.authorId),t.answers&&t.answers.length&&!a){const a=[];if(e){const e=(await Pt("me",t.slug)).filter((t=>t.liked));for(const t of e)a.push(t.answerSlug)}for(let e of t.answers)e.author=e.authorId&&await lt(e.authorId)||{},e.userLiked=a.includes(e.slug);t.answers.sort(((t,e)=>new Date(e.updatedAt)-new Date(t.updatedAt)))}return t}catch(t){throw await A(t),new Error(`Cannot read question authors: ${t.message}`)}}}};const{APIS:{PEOPLE_API:{BASE_URL:Tt,ENDPOINTS:{REGISTRATIONS:Ut}}}}=r;var ht={list:async t=>{let e=[];try{const{data:a}=await w().get(`${Tt}${Ut}`,{params:t});a&&a.length&&(e=a)}catch(t){await A(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:yt,ENDPOINTS:{USERS:$t,USER_COURSES:_t}}},USERS:{MYSELF:mt}}=r,ft=`${yt}${$t}/${mt}${_t}`;var gt={create:async t=>{try{await w().post(ft,t)}catch(t){await A(t)}},list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await w().get(ft,a);t&&t.length&&(e=t)}catch(t){await A(t)}return e},update:async(t,e)=>{try{await w().put(`${ft}/${t}`,e)}catch(t){await A(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Lt,ENDPOINTS:{USERS:Ct,USER_EVENTS:vt}}},USERS:{MYSELF:Dt}}=r,Bt=`${Lt}${Ct}/${Dt}${vt}`;var Gt={list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await w().get(Bt,a);t&&t.length&&(e=t)}catch(t){await A(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Mt,ENDPOINTS:{USERS:bt,USER_LESSONS:xt}}},USERS:{MYSELF:qt}}=r,Vt=`${Mt}${bt}/${qt}${xt}`;var Ft={create:async t=>{let e=null;try{e=await w().post(Vt,t)}catch(t){await A(t)}return e},list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await w().get(Vt,a);t&&t.length&&(e=t)}catch(t){await A(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Yt,ENDPOINTS:{USERS:jt,USER_PRODUCTS:Qt}}},USERS:{MYSELF:Wt}}=r,Ht=`${Yt}${jt}/${Wt}${Qt}`;var Kt={handlers:Ot,registrations:ht,users:pt,userAnswers:Rt,userCourses:gt,userEvents:Gt,userLessons:Ft,userProducts:{create:async t=>{let e=null;try{e=await w().post(Ht,t)}catch(t){await A(t)}return e},list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await w().get(Ht,a);t&&t.length&&(e=t)}catch(t){await A(t)}return e},update:async(t,e)=>{try{await w().put(`${Ht}/${t}`,e)}catch(t){await A(t)}}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:kt,ENDPOINTS:{ENQUIRY_EMAILS:Xt}}}}=r;var Jt={create:async t=>{let e=null;try{const{data:a}=await w().post(`${kt}${Xt}`,t);a&&(e=a)}catch(t){await A(t)}return e}},zt={forms:{sendEnquiryEmails:async t=>{let e=null;try{const{emailIds:a}=d;e=await ne.emails.create({...a,...t})}catch(t){await A(t)}return e}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:Zt,ENDPOINTS:{USERS:te,USER_PROPERTIES:ee}}},USERS:{MYSELF:ae}}=r;var ne={emails:Jt,handlers:zt,userProperties:{update:async(t,e)=>{try{await w().put(`${Zt}${te}/${ae}${ee}/${t}`,e)}catch(t){await A(t)}}}};const{CONTENTFUL:re}=r,{TYPE:oe,ORDER:se,FIELDS:ie}=re.QUESTIONS;var ce={read:async t=>{try{return await(0,e.getEntry)({content_type:oe,"fields.slug":t,include:2,select:ie})}catch(t){throw await A(t),new Error(`Cannot read question: ${t.message}`)}},list:async(t=10,a=0,n={})=>{try{return await(0,e.getEntries)({content_type:oe,include:1,limit:t,order:se,select:ie,"fields.private[ne]":!0,skip:a,...n})}catch(t){throw await A(t),new Error(`Cannot list questions: ${t.message}`)}}},Se=async(t,e,a=!1)=>{try{let n={};return n=await ce.read(t),n=await Kt.handlers.authors.readQuestionAuthors(n,e,a),n}catch(t){throw await A(t),new Error(`Cannot build question: ${t.message}`)}},Ee=async(t,e=10,a={})=>{try{let n=[];const r=e*(t-1);n=await ce.list(e,r,a);for(let t of n)t.author=t.authorId&&await Kt.users.read(t.authorId)||{};return n}catch(t){throw await A(t),new Error(`Cannot build questions: ${t.message}`)}},ue=S(408);const le=t=>t&&ue.Buffer.from(t,"base64").toString("ascii");function pe({authContext:r=null,contentContext:S=null,errorsContext:E=null,gtmContext:N=null,origin:w}){try{const A=(t=>{let e=null;t?e=t:"undefined"!=typeof window&&(e=window.origin||window.location.origin),e||new Error("Cannot select environment: Website not defined");let a=null;const n=e.match(i);return n?a=n[1].split(c)[0]:e===o?a=u:e.includes(s)&&(a=l),a||new Error(`Cannot select environment: No rule for website ${e}`),a})(w);r&&(0,t.setContext)(Object.assign({},r,{environment:A,origin:w})),S&&(0,e.setContext)(Object.assign({},S,{environment:A})),E&&(0,a.setContext)(Object.assign({},E,{environment:A})),N&&((0,n.setContext)(Object.assign({},N,{environment:A})),(0,n.setupGTM)()),(({environment:t})=>{const e=(t=>{if(!t)throw new Error("Cannot map environment: Environment not defined");if(!p[t])throw new Error(`Cannot map environment: No mapping found for environment ${t}`);return p[t]})(t);d.emailIds=I[e]})(Object.assign({},{environment:A}))}catch(t){console.warn(`Cannot load SDK: ${t.message}`)}}}(),E}()}));
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@apolitical/auth"),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/auth","@apolitical/content","@apolitical/error-reporting","@apolitical/gtm","axios","http-status-codes","buffer"],e):"object"==typeof exports?exports.ApoliticalSDK=e(require("@apolitical/auth"),require("@apolitical/content"),require("@apolitical/error-reporting"),require("@apolitical/gtm"),require("axios"),require("http-status-codes"),require("buffer")):t.ApoliticalSDK=e(t["@apolitical/auth"],t["@apolitical/content"],t["@apolitical/error-reporting"],t["@apolitical/gtm"],t.axios,t["http-status-codes"],t.buffer)}(this,(function(t,e,a,n,r,o,s){return function(){"use strict";var i={654:function(e){e.exports=t},809:function(t){t.exports=e},30:function(t){t.exports=a},36:function(t){t.exports=n},300:function(t){t.exports=r},408:function(t){t.exports=s},25:function(t){t.exports=o}},c={};function u(t){var e=c[t];if(void 0!==e)return e.exports;var a=c[t]={exports:{}};return i[t](a,a.exports,u),a.exports}u.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return u.d(e,{a:e}),e},u.d=function(t,e){for(var a in e)u.o(e,a)&&!u.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:e[a]})},u.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},u.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var E={};return function(){u.r(E),u.d(E,{assets:function(){return O},auth:function(){return U},buildQuestion:function(){return Se},buildQuestions:function(){return le},buildSliderCard:function(){return Oe},contentInteraction:function(){return V},contentSuggestion:function(){return J},decodeBase64:function(){return ye},default:function(){return fe},getAuthContext:function(){return t.getContext},getEntries:function(){return e.getEntries},getEntry:function(){return e.getEntry},management:function(){return ot},passwordlessLogin:function(){return t.passwordlessLogin},payments:function(){return ut},people:function(){return Ht},peopleEngagement:function(){return ne},reportError:function(){return a.reportError},sendVerificationEmail:function(){return t.sendVerificationEmail}});var t=u(654),e=u(809),a=u(30),n=u(36),r={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",LIKES:"/likes"}},CONTENT_SUGGESTIONS_API:{BASE_URL:"/api/content-suggestions-api",ENDPOINTS:{SUGGESTIONS:"/suggest"}},MANAGEMENT_API:{BASE_URL:"/api/management-api",ENDPOINTS:{ACCOUNTS:"/accounts",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_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"},COURSES:{TYPE:"microcourse"},EDITORIAL_PAGES:{TYPE:"editorialPage"},EVENTS:{TYPE:"event"},LISTS:{TYPE:"listPage"},QUESTIONS:{TYPE:"qaQuestion",ORDER:"-sys.updatedAt",FIELDS:"sys.createdAt,sys.updatedAt,fields.title,fields.slug,fields.authorId,fields.answers,fields.isEdited"}},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:o,LOCALHOST:s,STAGING:i,STAGING_SPLITTER:c},ENVIRONMENTS:{PRODUCTION:S,LOCAL:l}}}=r,{HUBSPOT:{ENVIRONMENTS_MAPPING:p,EMAIL_IDS:d}}=r;let I={emailIds:{}};var w=u(300),N=u.n(w);const T=async t=>{try{const{message:e,response:n,request:r}=t;let o=e;return n?o+=` - The request was made and the server responded with ${JSON.stringify({status:n.status,data:n.data})}`:r&&(o+=" - The request was made but no response was received"),console.warn(o),await(0,a.reportError)(new Error(o)),o}catch(t){return console.warn(`Cannot handle error: ${t.message}`),t.message}},{APIS:{ASSETS_API:{BASE_URL:A,ENDPOINTS:{USERS:P,CERTIFICATES:h}}}}=r;var O={certificates:{create:async(t,e)=>{let a=[];try{const{data:n}=await N().post(`${A}${P}/${t}${h}`,e);n&&(a=n)}catch(t){await T(t)}return a}}};const{APIS:{AUTH_API:{BASE_URL:R,ENDPOINTS:{USER_PASSWORD:y,USERS:f}}},USERS:{MYSELF:g}}=r;var U={userPassword:{update:async t=>{let e=null;try{e=await N().put(`${R}${f}/${g}${y}`,t)}catch(t){e={message:(((t||{}).response||{}).data||{}).message},await T(t)}return e}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:m,ENDPOINTS:{ANSWERS:$,QUESTIONS:_}}}}=r,L=`${m}${_}`;var C={create:async(t,e)=>{try{await N().post(`${L}/${encodeURIComponent(t)}${$}`,e)}catch(t){const e=await T(t);throw new Error(e)}},remove:async(t,e)=>{try{await N().delete(`${L}/${encodeURIComponent(t)}${$}/${encodeURIComponent(e)}`)}catch(t){const e=await T(t);throw new Error(e)}},update:async(t,e,a)=>{try{return await N().put(`${L}/${encodeURIComponent(t)}${$}/${encodeURIComponent(e)}`,{body:a})}catch(t){const e=await T(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:D,ENDPOINTS:{QUESTIONS:v}}}}=r,b=`${D}${v}`;var B={create:async t=>{try{return await N().post(b,t)}catch(t){const e=await T(t);throw new Error(e)}},remove:async t=>{try{await N().delete(`${b}/${encodeURIComponent(t)}`)}catch(t){const e=await T(t);throw new Error(e)}},update:async(t,e)=>{try{return await N().put(`${b}/${encodeURIComponent(t)}`,{title:e})}catch(t){const e=await T(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:M,ENDPOINTS:{QUESTIONS:G,ANSWERS:x,LIKES:q}}}}=r,Y=`${M}${G}`;var V={answers:C,questions:B,likes:{create:async(t,e)=>{try{return await N().post(`${Y}/${encodeURIComponent(t)}${x}/${encodeURIComponent(e)}${q}`)}catch(t){const e=await T(t);throw new Error(e)}},remove:async(t,e)=>{try{return await N().delete(`${Y}/${encodeURIComponent(t)}${x}/${encodeURIComponent(e)}${q}`)}catch(t){const e=await T(t);throw new Error(e)}}}},F=u(25);const{OK:j,MULTIPLE_CHOICES:Q,NOT_FOUND:W,FORBIDDEN:k}=F.StatusCodes,H=t=>t>=j&&t<Q||t===k||t===W,{APIS:{CONTENT_SUGGESTIONS_API:{BASE_URL:K,ENDPOINTS:{SUGGESTIONS:X}}}}=r;var J={suggestions:{list:async(t={})=>{let e=[],a=Object.assign({validateStatus:H},t);try{const{data:t}=await N().get(`${K}${X}`,a);t&&t.length&&(e=t)}catch(t){await T(t)}return e}}};const{APIS:{MANAGEMENT_API:{BASE_URL:z,ENDPOINTS:{ACCOUNTS:Z}}}}=r;var tt={create:async t=>{try{await N().post(`${z}${Z}`,t)}catch(t){throw await T(t),t}},read:async t=>{let e=null;try{({data:e}=await N().get(`${z}${Z}/${encodeURIComponent(t)}`))}catch(t){await T(t)}return e},update:async(t,e)=>{try{await N().put(`${z}${Z}/${encodeURIComponent(t)}`,e)}catch(t){throw await T(t),t}}};const{APIS:{MANAGEMENT_API:{BASE_URL:et,ENDPOINTS:{LOGINS:at,LOGIN_PASSWORDLESS:nt}}}}=r,rt=`${et}${at}`;var ot={accounts:tt,passwordless:{update:async t=>{try{await N().put(`${rt}/${encodeURIComponent(t)}${nt}`)}catch(t){throw await T(t),t}}}};const{APIS:{PAYMENTS_API:{BASE_URL_V2:st,ENDPOINTS:{PRODUCTS:it}}}}=r,ct=`${st}${it}`;var ut={products:{list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(ct,a);t&&t.length&&(e=t)}catch(t){await T(t)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Et,ENDPOINTS:{USERS:St}}}}=r,lt=async t=>{let e=null;try{const{data:a}=await N().get(`${Et}${St}/${encodeURIComponent(t)}`,{validateStatus:H});a&&a.id&&(e=a)}catch(t){await T(t)}return e};var pt={read:lt,update:async(t,e)=>{let a=!1;try{const{data:n}=await N().put(`${Et}${St}/${encodeURIComponent(t)}`,e);a=!(!n||!n.id)}catch(t){await T(t)}return a}};const{APIS:{PEOPLE_API:{BASE_URL_V2:dt,ENDPOINTS:{USERS:It,USER_ANSWERS:wt}}},USERS:{MYSELF:Nt}}=r,Tt=`${dt}${It}/${Nt}${wt}`,At=async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(Tt,a);t&&t.length&&(e=t)}catch(t){await T(t)}return e};var Pt={list:At},ht={authors:{readQuestionAuthors:async(t,e,a=!1)=>{try{if(t.author=await lt(t.authorId),t.answers&&t.answers.length&&!a){const a=[];if(e){const e=(await At("me",t.slug)).filter((t=>t.liked));for(const t of e)a.push(t.answerSlug)}for(let e of t.answers)e.author=e.authorId&&await lt(e.authorId)||{},e.userLiked=a.includes(e.slug);t.answers.sort(((t,e)=>new Date(e.updatedAt)-new Date(t.updatedAt)))}return t}catch(t){throw await T(t),new Error(`Cannot read question authors: ${t.message}`)}}}};const{APIS:{PEOPLE_API:{BASE_URL:Ot,ENDPOINTS:{REGISTRATIONS:Rt}}}}=r;var yt={list:async t=>{let e=[];try{const{data:a}=await N().get(`${Ot}${Rt}`,{params:t});a&&a.length&&(e=a)}catch(t){await T(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:ft,ENDPOINTS:{USERS:gt,USER_COURSES:Ut}}},USERS:{MYSELF:mt}}=r,$t=`${ft}${gt}/${mt}${Ut}`;var _t={create:async t=>{try{await N().post($t,t)}catch(t){await T(t)}},list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get($t,a);t&&t.length&&(e=t)}catch(t){await T(t)}return e},update:async(t,e)=>{try{await N().put(`${$t}/${t}`,e)}catch(t){await T(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Lt,ENDPOINTS:{USERS:Ct,USER_EVENTS:Dt}}},USERS:{MYSELF:vt}}=r,bt=`${Lt}${Ct}/${vt}${Dt}`;var Bt={list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(bt,a);t&&t.length&&(e=t)}catch(t){await T(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Mt,ENDPOINTS:{USERS:Gt,USER_LESSONS:xt}}},USERS:{MYSELF:qt}}=r,Yt=`${Mt}${Gt}/${qt}${xt}`;var Vt={create:async t=>{let e=null;try{e=await N().post(Yt,t)}catch(t){await T(t)}return e},list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(Yt,a);t&&t.length&&(e=t)}catch(t){await T(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Ft,ENDPOINTS:{USERS:jt,USER_PRODUCTS:Qt}}},USERS:{MYSELF:Wt}}=r,kt=`${Ft}${jt}/${Wt}${Qt}`;var Ht={handlers:ht,registrations:yt,users:pt,userAnswers:Pt,userCourses:_t,userEvents:Bt,userLessons:Vt,userProducts:{create:async t=>{let e=null;try{e=await N().post(kt,t)}catch(t){await T(t)}return e},list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(kt,a);t&&t.length&&(e=t)}catch(t){await T(t)}return e},update:async(t,e)=>{try{await N().put(`${kt}/${t}`,e)}catch(t){await T(t)}}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:Kt,ENDPOINTS:{ENQUIRY_EMAILS:Xt}}}}=r;var Jt={create:async t=>{let e=null;try{const{data:a}=await N().post(`${Kt}${Xt}`,t);a&&(e=a)}catch(t){await T(t)}return e}},zt={forms:{sendEnquiryEmails:async t=>{let e=null;try{const{emailIds:a}=I;e=await ne.emails.create({...a,...t})}catch(t){await T(t)}return e}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:Zt,ENDPOINTS:{USERS:te,USER_PROPERTIES:ee}}},USERS:{MYSELF:ae}}=r;var ne={emails:Jt,handlers:zt,userProperties:{update:async(t,e)=>{try{await N().put(`${Zt}${te}/${ae}${ee}/${t}`,e)}catch(t){await T(t)}}}};const{CONTENTFUL:re}=r,{TYPE:oe}=re.EDITORIAL_PAGES;const{CONTENTFUL:se}=r,{TYPE:ie,ORDER:ce,FIELDS:ue}=se.QUESTIONS;var Ee={read:async t=>{try{return await(0,e.getEntry)({content_type:ie,"fields.slug":t,include:2,select:ue})}catch(t){throw await T(t),new Error(`Cannot read question: ${t.message}`)}},list:async(t=10,a=0,n={})=>{try{return await(0,e.getEntries)({content_type:ie,include:1,limit:t,order:ce,select:ue,"fields.private[ne]":!0,skip:a,...n})}catch(t){throw await T(t),new Error(`Cannot list questions: ${t.message}`)}}},Se=async(t,e,a=!1)=>{try{let n={};return n=await Ee.read(t),n=await Ht.handlers.authors.readQuestionAuthors(n,e,a),n}catch(t){throw await T(t),new Error(`Cannot build question: ${t.message}`)}},le=async(t,e=10,a={})=>{try{let n=[];const r=e*(t-1);n=await Ee.list(e,r,a);for(let t of n)t.author=t.authorId&&await Ht.users.read(t.authorId)||{};return n}catch(t){throw await T(t),new Error(`Cannot build questions: ${t.message}`)}};const{ARTICLES:{TYPE:pe},COURSES:{TYPE:de},EVENTS:{TYPE:Ie},LISTS:{TYPE:we},QUESTIONS:{TYPE:Ne}}=r.CONTENTFUL,Te=t=>(t&&t.url&&Object.assign(t,{aspect:"responsiveCard",query:"q=90&fit=fill"}),null),Ae=t=>{const e=t.replace(/(<([^>]+)>)/gi,"").split(/\s/g).length/200;return Math.ceil(e)},Pe=t=>{const e=Math.round((Date.now()-Date.parse(t))/36e5);if(e<=23)return`${e<1?"1":e}h`;const a=Math.round(e/24);if(a<=(1===new Date(t).getMonth()?28:29))return`${a}d`;const n=Math.round(a/30);return n<=11?`${n}m`:`${Math.round(n/12)}y`},he={[pe]:async t=>{const{authorIds:e,authorTag:a,body:n,image:r,publishedDate:o,slug:s,title:i}=t;let c=[];if(e&&e.length)for(const t of e){const e=await Ht.users.read(t);e&&c.push(e)}const u=c&&c.length?c:a?[a]:null;return{banner:Te(r),contributors:u,publishedDate:Pe(o),readingTime:Ae(n),slug:s,title:i}},[de]:async t=>{const{banner:e,freeCourse:a,partnershipDetails:n,slug:r,title:o}=t,s={banner:Te(e),slug:r,title:o,pill:a?"free":"premium"};if(n){const{partners:t}=n;s.partner=t&&t.length&&n.partners[0]}return s},[Ie]:async t=>{const{bannerImage:e,defaultStartDate:a,slug:n,speakers:r,title:o}=t;if(r&&r.length)for(const t of r)t.image=(s=t.image)&&s.url?`${s.url}?w=100&h=100&fit=thumb&f=center`:null;var s;return{banner:Te(e),slug:n,startDate:new Date(a),title:o,speakers:r}},[we]:async t=>{const{hero:e,slug:a,title:n}=t;return{banner:Te(e),slug:a,title:n}},[Ne]:async t=>{const{answers:e,authorId:a,slug:n,title:r}=t;let o=null;if(a){const t=await Ht.users.read(a);t&&(o=t)}return{answers:e&&e.length?e.length:0,contributors:[o],slug:n,title:r}}};var Oe=async({contentType:t,...e}={})=>{try{if(!he[t])throw new Error("Content type not supported");if("function"!=typeof he[t])throw new Error("No builder function for content type");return{contentType:t,...await he[t](e)}}catch(t){throw await T(t),new Error(`Cannot build slider card: ${t.message}`)}},Re=u(408);const ye=t=>t&&Re.Buffer.from(t,"base64").toString("ascii");function fe({authContext:r=null,contentContext:u=null,errorsContext:E=null,gtmContext:w=null,origin:N}){try{const T=(t=>{let e=null;t?e=t:"undefined"!=typeof window&&(e=window.origin||window.location.origin),e||new Error("Cannot select environment: Website not defined");let a=null;const n=e.match(i);return n?a=n[1].split(c)[0]:e===o?a=S:e.includes(s)&&(a=l),a||new Error(`Cannot select environment: No rule for website ${e}`),a})(N);r&&(0,t.setContext)(Object.assign({},r,{environment:T,origin:N})),u&&(0,e.setContext)(Object.assign({},u,{environment:T})),E&&(0,a.setContext)(Object.assign({},E,{environment:T})),w&&((0,n.setContext)(Object.assign({},w,{environment:T})),(0,n.setupGTM)()),(({environment:t})=>{const e=(t=>{if(!t)throw new Error("Cannot map environment: Environment not defined");if(!p[t])throw new Error(`Cannot map environment: No mapping found for environment ${t}`);return p[t]})(t);I.emailIds=d[e]})(Object.assign({},{environment:T}))}catch(t){console.warn(`Cannot load SDK: ${t.message}`)}}}(),E}()}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apolitical/sdk",
3
- "version": "3.1.1",
3
+ "version": "3.2.0-rc.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",