@apolitical/sdk 3.2.0-rc.6 → 4.0.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 +3 -4
- package/build/index.js +1 -1
- package/package.json +1 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,10 +5,9 @@ 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
|
-
## [
|
|
9
|
-
###
|
|
10
|
-
-
|
|
11
|
-
- Functionality to build slider card
|
|
8
|
+
## [4.0.0] - 2023-01-24
|
|
9
|
+
### Removed
|
|
10
|
+
- Use of `@apolitical/auth` on the SDK
|
|
12
11
|
|
|
13
12
|
## [3.1.1] - 2023-01-18
|
|
14
13
|
### Changed
|
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 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},buildCarouselCard:function(){return Re},buildQuestion:function(){return le},buildQuestions:function(){return pe},contentInteraction:function(){return V},contentSuggestion:function(){return J},decodeBase64:function(){return ge},default:function(){return fe},editorialPages:function(){return se},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 kt},peopleEngagement:function(){return ne},qaQuestions:function(){return Se},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:g}}},USERS:{MYSELF:f}}=r;var U={userPassword:{update:async t=>{let e=null;try{e=await N().put(`${R}${g}/${f}${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:Q,MULTIPLE_CHOICES:j,NOT_FOUND:W,FORBIDDEN:H}=F.StatusCodes,k=t=>t>=Q&&t<j||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 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:k});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:gt,ENDPOINTS:{USERS:ft,USER_COURSES:Ut}}},USERS:{MYSELF:mt}}=r,$t=`${gt}${ft}/${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:Qt,USER_PRODUCTS:jt}}},USERS:{MYSELF:Wt}}=r,Ht=`${Ft}${Qt}/${Wt}${jt}`;var kt={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(Ht,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(Ht,a);t&&t.length&&(e=t)}catch(t){await T(t)}return e},update:async(t,e)=>{try{await N().put(`${Ht}/${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;var se={read:async t=>{try{return await(0,e.getEntry)({content_type:oe,"fields.slug":t,include:4},{assetDetails:!0})}catch(t){throw await T(t),new Error(`Cannot read editorial page: ${t.message}`)}}};const{CONTENTFUL:ie}=r,{TYPE:ce,ORDER:ue,FIELDS:Ee}=ie.QUESTIONS;var Se={read:async t=>{try{return await(0,e.getEntry)({content_type:ce,"fields.slug":t,include:2,select:Ee})}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:ce,include:1,limit:t,order:ue,select:Ee,"fields.private[ne]":!0,skip:a,...n})}catch(t){throw await T(t),new Error(`Cannot list questions: ${t.message}`)}}},le=async(t,e,a=!1)=>{try{let n={};return n=await Se.read(t),n=await kt.handlers.authors.readQuestionAuthors(n,e,a),n}catch(t){throw await T(t),new Error(`Cannot build question: ${t.message}`)}},pe=async(t,e=10,a={})=>{try{let n=[];const r=e*(t-1);n=await Se.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 T(t),new Error(`Cannot build questions: ${t.message}`)}};const{ARTICLES:{TYPE:de},COURSES:{TYPE:Ie},EVENTS:{TYPE:we},LISTS:{TYPE:Ne},QUESTIONS:{TYPE:Te}}=r.CONTENTFUL,Ae=t=>t&&t.url?(Object.assign(t,{aspect:"responsiveCard",query:"q=90&fit=fill"}),t):null,Pe=t=>{const e=t.replace(/(<([^>]+)>)/gi,"").split(/\s/g).length/200;return Math.ceil(e)},he=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`},Oe={[de]: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 kt.users.read(t);e&&c.push(e)}const u=c&&c.length?c:a?[a]:null;return{banner:Ae(r),contributors:u,publishedDate:he(o),readingTime:Pe(n),slug:s,title:i}},[Ie]:async t=>{const{banner:e,freeCourse:a,partnershipDetails:n,slug:r,title:o}=t,s={banner:Ae(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},[we]: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;const i=new Date(a),c=!!i&&i<new Date;return{banner:Ae(e),dateHasPassed:c,title:o,slug:n,speakers:r,startDate:i}},[Ne]:async t=>{const{hero:e,slug:a,title:n}=t;return{banner:Ae(e),slug:a,title:n}},[Te]:async t=>{const{answers:e,authorId:a,slug:n,title:r}=t;let o=null;if(a){const t=await kt.users.read(a);t&&(o=t)}return{answers:e&&e.length?e.length:0,contributors:o?[o]:[],slug:n,title:r}}};var Re=async({contentType:t,...e}={})=>{try{if(!Oe[t])throw new Error("Content type not supported");if("function"!=typeof Oe[t])throw new Error("No builder function for content type");return{contentType:t,...await Oe[t](e)}}catch(t){throw await T(t),new Error(`Cannot build carousel card: ${t.message}`)}},ye=u(408);const ge=t=>t&&ye.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}()}));
|
|
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,a,n,r,o){return function(){"use strict";var s={809:function(e){e.exports=t},30:function(t){t.exports=e},36:function(t){t.exports=a},300:function(t){t.exports=n},408:function(t){t.exports=o},25:function(t){t.exports=r}},i={};function c(t){var e=i[t];if(void 0!==e)return e.exports;var a=i[t]={exports:{}};return s[t](a,a.exports,c),a.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 a in e)c.o(e,a)&&!c.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:e[a]})},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 S={};return function(){c.r(S),c.d(S,{assets:function(){return O},auth:function(){return _},buildQuestion:function(){return ce},buildQuestions:function(){return Se},contentInteraction:function(){return V},contentSuggestion:function(){return X},decodeBase64:function(){return ue},default:function(){return le},getEntries:function(){return t.getEntries},getEntry:function(){return t.getEntry},management:function(){return rt},payments:function(){return ct},people:function(){return Ht},peopleEngagement:function(){return ae},reportError:function(){return e.reportError}});var t=c(809),e=c(30),a=c(36),n={APOLITICAL:{WEBSITES:{LIVE:"https://apolitical.co",LOCALHOST:"localhost",STAGING:/https:\/\/([\w|\d|-]+)\.apolitical\.co/i,STAGING_SPLITTER:"-"},ENVIRONMENTS:{PRODUCTION:"live",LOCAL:"local"}},APIS:{ASSETS_API:{BASE_URL:"/api/assets-api",ENDPOINTS:{USERS:"/users",CERTIFICATES:"/certificates"}},AUTH_API:{BASE_URL:"/api/auth-api",ENDPOINTS:{USER_PASSWORD:"/password",USERS:"/users"}},CONTENT_INTERACTION_API:{BASE_URL:"/api/content-interaction-api",ENDPOINTS:{QUESTIONS:"/questions",ANSWERS:"/answers",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:r,LOCALHOST:o,STAGING:s,STAGING_SPLITTER:i},ENVIRONMENTS:{PRODUCTION:E,LOCAL:u}}}=n,{HUBSPOT:{ENVIRONMENTS_MAPPING:l,EMAIL_IDS:I}}=n;let p={emailIds:{}};var d=c(300),N=c.n(d);const w=async t=>{try{const{message:a,response:n,request:r}=t;let o=a;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,e.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:R}}}}=n;var O={certificates:{create:async(t,e)=>{let a=[];try{const{data:n}=await N().post(`${A}${P}/${t}${R}`,e);n&&(a=n)}catch(t){await w(t)}return a}}};const{APIS:{AUTH_API:{BASE_URL:T,ENDPOINTS:{USER_PASSWORD:U,USERS:y}}},USERS:{MYSELF:$}}=n;var _={userPassword:{update:async t=>{let e=null;try{e=await N().put(`${T}${y}/${$}${U}`,t)}catch(t){e={message:(((t||{}).response||{}).data||{}).message},await w(t)}return e}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:h,ENDPOINTS:{ANSWERS:m,QUESTIONS:f}}}}=n,L=`${h}${f}`;var g={create:async(t,e)=>{try{await N().post(`${L}/${encodeURIComponent(t)}${m}`,e)}catch(t){const e=await w(t);throw new Error(e)}},remove:async(t,e)=>{try{await N().delete(`${L}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}`)}catch(t){const e=await w(t);throw new Error(e)}},update:async(t,e,a)=>{try{return await N().put(`${L}/${encodeURIComponent(t)}${m}/${encodeURIComponent(e)}`,{body:a})}catch(t){const e=await w(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:C,ENDPOINTS:{QUESTIONS:v}}}}=n,D=`${C}${v}`;var B={create:async t=>{try{return await N().post(D,t)}catch(t){const e=await w(t);throw new Error(e)}},remove:async t=>{try{await N().delete(`${D}/${encodeURIComponent(t)}`)}catch(t){const e=await w(t);throw new Error(e)}},update:async(t,e)=>{try{return await N().put(`${D}/${encodeURIComponent(t)}`,{title:e})}catch(t){const e=await w(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:G,ENDPOINTS:{QUESTIONS:M,ANSWERS:b,LIKES:x}}}}=n,q=`${G}${M}`;var V={answers:g,questions:B,likes:{create:async(t,e)=>{try{return await N().post(`${q}/${encodeURIComponent(t)}${b}/${encodeURIComponent(e)}${x}`)}catch(t){const e=await w(t);throw new Error(e)}},remove:async(t,e)=>{try{return await N().delete(`${q}/${encodeURIComponent(t)}${b}/${encodeURIComponent(e)}${x}`)}catch(t){const e=await w(t);throw new Error(e)}}}},F=c(25);const{OK:Y,MULTIPLE_CHOICES:Q,NOT_FOUND:j,FORBIDDEN:W}=F.StatusCodes,H=t=>t>=Y&&t<Q||t===W||t===j,{APIS:{CONTENT_SUGGESTIONS_API:{BASE_URL:K,ENDPOINTS:{SUGGESTIONS:k}}}}=n;var X={suggestions:{list:async(t={})=>{let e=[],a=Object.assign({validateStatus:H},t);try{const{data:t}=await N().get(`${K}${k}`,a);t&&t.length&&(e=t)}catch(t){await w(t)}return e}}};const{APIS:{MANAGEMENT_API:{BASE_URL:J,ENDPOINTS:{ACCOUNTS:z}}}}=n;var Z={create:async t=>{try{await N().post(`${J}${z}`,t)}catch(t){throw await w(t),t}},read:async t=>{let e=null;try{({data:e}=await N().get(`${J}${z}/${encodeURIComponent(t)}`))}catch(t){await w(t)}return e},update:async(t,e)=>{try{await N().put(`${J}${z}/${encodeURIComponent(t)}`,e)}catch(t){throw await w(t),t}}};const{APIS:{MANAGEMENT_API:{BASE_URL:tt,ENDPOINTS:{LOGINS:et,LOGIN_PASSWORDLESS:at}}}}=n,nt=`${tt}${et}`;var rt={accounts:Z,passwordless:{update:async t=>{try{await N().put(`${nt}/${encodeURIComponent(t)}${at}`)}catch(t){throw await w(t),t}}}};const{APIS:{PAYMENTS_API:{BASE_URL_V2:ot,ENDPOINTS:{PRODUCTS:st}}}}=n,it=`${ot}${st}`;var ct={products:{list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(it,a);t&&t.length&&(e=t)}catch(t){await w(t)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:St,ENDPOINTS:{USERS:Et}}}}=n,ut=async t=>{let e=null;try{const{data:a}=await N().get(`${St}${Et}/${encodeURIComponent(t)}`,{validateStatus:H});a&&a.id&&(e=a)}catch(t){await w(t)}return e};var lt={read:ut,update:async(t,e)=>{let a=!1;try{const{data:n}=await N().put(`${St}${Et}/${encodeURIComponent(t)}`,e);a=!(!n||!n.id)}catch(t){await w(t)}return a}};const{APIS:{PEOPLE_API:{BASE_URL_V2:It,ENDPOINTS:{USERS:pt,USER_ANSWERS:dt}}},USERS:{MYSELF:Nt}}=n,wt=`${It}${pt}/${Nt}${dt}`,At=async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(wt,a);t&&t.length&&(e=t)}catch(t){await w(t)}return e};var Pt={list:At},Rt={authors:{readQuestionAuthors:async(t,e,a=!1)=>{try{if(t.author=await ut(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 ut(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 w(t),new Error(`Cannot read question authors: ${t.message}`)}}}};const{APIS:{PEOPLE_API:{BASE_URL:Ot,ENDPOINTS:{REGISTRATIONS:Tt}}}}=n;var Ut={list:async t=>{let e=[];try{const{data:a}=await N().get(`${Ot}${Tt}`,{params:t});a&&a.length&&(e=a)}catch(t){await w(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:yt,ENDPOINTS:{USERS:$t,USER_COURSES:_t}}},USERS:{MYSELF:ht}}=n,mt=`${yt}${$t}/${ht}${_t}`;var ft={create:async t=>{try{await N().post(mt,t)}catch(t){await w(t)}},list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(mt,a);t&&t.length&&(e=t)}catch(t){await w(t)}return e},update:async(t,e)=>{try{await N().put(`${mt}/${t}`,e)}catch(t){await w(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Lt,ENDPOINTS:{USERS:gt,USER_EVENTS:Ct}}},USERS:{MYSELF:vt}}=n,Dt=`${Lt}${gt}/${vt}${Ct}`;var Bt={list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(Dt,a);t&&t.length&&(e=t)}catch(t){await w(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Gt,ENDPOINTS:{USERS:Mt,USER_LESSONS:bt}}},USERS:{MYSELF:xt}}=n,qt=`${Gt}${Mt}/${xt}${bt}`;var Vt={create:async t=>{let e=null;try{e=await N().post(qt,t)}catch(t){await w(t)}return e},list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(qt,a);t&&t.length&&(e=t)}catch(t){await w(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Ft,ENDPOINTS:{USERS:Yt,USER_PRODUCTS:Qt}}},USERS:{MYSELF:jt}}=n,Wt=`${Ft}${Yt}/${jt}${Qt}`;var Ht={handlers:Rt,registrations:Ut,users:lt,userAnswers:Pt,userCourses:ft,userEvents:Bt,userLessons:Vt,userProducts:{create:async t=>{let e=null;try{e=await N().post(Wt,t)}catch(t){await w(t)}return e},list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(Wt,a);t&&t.length&&(e=t)}catch(t){await w(t)}return e},update:async(t,e)=>{try{await N().put(`${Wt}/${t}`,e)}catch(t){await w(t)}}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:Kt,ENDPOINTS:{ENQUIRY_EMAILS:kt}}}}=n;var Xt={create:async t=>{let e=null;try{const{data:a}=await N().post(`${Kt}${kt}`,t);a&&(e=a)}catch(t){await w(t)}return e}},Jt={forms:{sendEnquiryEmails:async t=>{let e=null;try{const{emailIds:a}=p;e=await ae.emails.create({...a,...t})}catch(t){await w(t)}return e}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:zt,ENDPOINTS:{USERS:Zt,USER_PROPERTIES:te}}},USERS:{MYSELF:ee}}=n;var ae={emails:Xt,handlers:Jt,userProperties:{update:async(t,e)=>{try{await N().put(`${zt}${Zt}/${ee}${te}/${t}`,e)}catch(t){await w(t)}}}};const{CONTENTFUL:ne}=n,{TYPE:re,ORDER:oe,FIELDS:se}=ne.QUESTIONS;var ie={read:async e=>{try{return await(0,t.getEntry)({content_type:re,"fields.slug":e,include:2,select:se})}catch(t){throw await w(t),new Error(`Cannot read question: ${t.message}`)}},list:async(e=10,a=0,n={})=>{try{return await(0,t.getEntries)({content_type:re,include:1,limit:e,order:oe,select:se,"fields.private[ne]":!0,skip:a,...n})}catch(t){throw await w(t),new Error(`Cannot list questions: ${t.message}`)}}},ce=async(t,e,a=!1)=>{try{let n={};return n=await ie.read(t),n=await Ht.handlers.authors.readQuestionAuthors(n,e,a),n}catch(t){throw await w(t),new Error(`Cannot build question: ${t.message}`)}},Se=async(t,e=10,a={})=>{try{let n=[];const r=e*(t-1);n=await ie.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 w(t),new Error(`Cannot build questions: ${t.message}`)}},Ee=c(408);const ue=t=>t&&Ee.Buffer.from(t,"base64").toString("ascii");function le({contentContext:n=null,errorsContext:c=null,gtmContext:S=null,origin:d}){try{const N=(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(s);return n?a=n[1].split(i)[0]:e===r?a=E:e.includes(o)&&(a=u),a||new Error(`Cannot select environment: No rule for website ${e}`),a})(d);n&&(0,t.setContext)(Object.assign({},n,{environment:N})),c&&(0,e.setContext)(Object.assign({},c,{environment:N})),S&&((0,a.setContext)(Object.assign({},S,{environment:N})),(0,a.setupGTM)()),(({environment:t})=>{const e=(t=>{if(!t)throw new Error("Cannot map environment: Environment not defined");if(!l[t])throw new Error(`Cannot map environment: No mapping found for environment ${t}`);return l[t]})(t);p.emailIds=I[e]})(Object.assign({},{environment:N}))}catch(t){console.warn(`Cannot load SDK: ${t.message}`)}}}(),S}()}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apolitical/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.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",
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"SDK"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@apolitical/auth": "0.1.2",
|
|
29
28
|
"@apolitical/content": "0.7.0",
|
|
30
29
|
"@apolitical/error-reporting": "0.2.2",
|
|
31
30
|
"@apolitical/gtm": "1.2.1",
|
|
@@ -34,7 +33,6 @@
|
|
|
34
33
|
"http-status-codes": "2.2.0"
|
|
35
34
|
},
|
|
36
35
|
"peerDependencies": {
|
|
37
|
-
"@apolitical/auth": "0.1.2",
|
|
38
36
|
"@apolitical/content": "0.7.0",
|
|
39
37
|
"@apolitical/error-reporting": "0.2.2",
|
|
40
38
|
"@apolitical/gtm": "1.2.1",
|