@apolitical/sdk 3.1.0-beta.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/build/index.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,20 @@ 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.1.0] - 2023-01-12
|
|
9
|
+
### Added
|
|
10
|
+
- Functionality to resend verification code (starts passwordless login)
|
|
11
|
+
|
|
12
|
+
## [3.0.2] - 2023-01-05
|
|
13
|
+
### Changed
|
|
14
|
+
- Creating a question returns the question
|
|
15
|
+
- buildQuestion and readQuestionAuthors takes an optional arg `ignoreAnswersAuthors` (to not request answer author info if unnecessary to reduce People API calls)
|
|
16
|
+
- buildQuestions and Listing questions takes an optional arg `query` to filter
|
|
17
|
+
|
|
18
|
+
## [3.0.1] - 2022-12-14
|
|
19
|
+
### Added
|
|
20
|
+
- Filter to exclude private questions from qaQuestions list method
|
|
21
|
+
|
|
8
22
|
## [3.0.0] - 2022-12-06
|
|
9
23
|
### Added
|
|
10
24
|
- Solver methods: `buildQuestion` and `buildQuestions`
|
package/README.md
CHANGED
|
@@ -87,7 +87,7 @@ Inside the API folder itself, there are two other folders
|
|
|
87
87
|
|
|
88
88
|
Under `/lib/contentful/` we implement functionality to interact with Contentful Delivery (and Preview) API.
|
|
89
89
|
|
|
90
|
-
Each content type will have it's own folder, for example, `/lib/contentful/
|
|
90
|
+
Each content type will have it's own folder, for example, `/lib/contentful/questions/` for the Q&A Question content type.
|
|
91
91
|
|
|
92
92
|
Internally, the functionality will be implemented with the help of the `@apolitical/content` module.
|
|
93
93
|
|
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 O},auth:function(){return $},buildQuestion:function(){return Ee},buildQuestions:function(){return ue},contentInteraction:function(){return F},contentSuggestion:function(){return J},decodeBase64:function(){return pe},default:function(){return Ie},getAuthContext:function(){return t.getContext},getEntries:function(){return e.getEntries},getEntry:function(){return e.getEntry},management:function(){return tt},passwordlessLogin:function(){return t.passwordlessLogin},payments:function(){return rt},people:function(){return kt},peopleEngagement:function(){return re},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"}},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_QUESTIONS:"/questions",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 w=S(300),N=S.n(w);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:T}}}}=r;var O={certificates:{create:async(t,e)=>{let a=[];try{const{data:n}=await N().post(`${P}${R}/${t}${T}`,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 N().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 N().post(`${L}/${encodeURIComponent(t)}${f}`,e)}catch(t){const e=await A(t);throw new Error(e)}},remove:async(t,e)=>{try{await N().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 N().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 M={create:async t=>{try{await N().post(B,t)}catch(t){const e=await A(t);throw new Error(e)}},remove:async t=>{try{await N().delete(`${B}/${encodeURIComponent(t)}`)}catch(t){const e=await A(t);throw new Error(e)}},update:async(t,e)=>{try{return await N().put(`${B}/${encodeURIComponent(t)}`,{title:e})}catch(t){const e=await A(t);throw new Error(e)}}};const{APIS:{CONTENT_INTERACTION_API:{BASE_URL:b,ENDPOINTS:{QUESTIONS:x,ANSWERS:G,LIKES:q}}}}=r,V=`${b}${x}`;var F={answers:C,questions:M,likes:{create:async(t,e)=>{try{return await N().post(`${V}/${encodeURIComponent(t)}${G}/${encodeURIComponent(e)}${q}`)}catch(t){const e=await A(t);throw new Error(e)}},remove:async(t,e)=>{try{return await N().delete(`${V}/${encodeURIComponent(t)}${G}/${encodeURIComponent(e)}${q}`)}catch(t){const e=await A(t);throw new Error(e)}}}},Q=S(25);const{OK:Y,MULTIPLE_CHOICES:j,NOT_FOUND:W,FORBIDDEN:H}=Q.StatusCodes,K=t=>t>=Y&&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 A(t)}return e}}};const{APIS:{MANAGEMENT_API:{BASE_URL:z,ENDPOINTS:{ACCOUNTS:Z}}}}=r;var tt={accounts:{create:async t=>{try{await N().post(`${z}${Z}`,t)}catch(t){throw await A(t),t}},read:async t=>{let e=null;try{({data:e}=await N().get(`${z}${Z}/${encodeURIComponent(t)}`))}catch(t){await A(t)}return e},update:async(t,e)=>{try{await N().put(`${z}${Z}/${encodeURIComponent(t)}`,e)}catch(t){throw await A(t),t}}}};const{APIS:{PAYMENTS_API:{BASE_URL_V2:et,ENDPOINTS:{PRODUCTS:at}}}}=r,nt=`${et}${at}`;var rt={products:{list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(nt,a);t&&t.length&&(e=t)}catch(t){await A(t)}return e}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:ot,ENDPOINTS:{USERS:st}}}}=r,it=async t=>{let e=null;try{const{data:a}=await N().get(`${ot}${st}/${encodeURIComponent(t)}`,{validateStatus:K});a&&a.id&&(e=a)}catch(t){await A(t)}return e};var ct={read:it,update:async(t,e)=>{let a=!1;try{const{data:n}=await N().put(`${ot}${st}/${encodeURIComponent(t)}`,e);a=!(!n||!n.id)}catch(t){await A(t)}return a}};const{APIS:{PEOPLE_API:{BASE_URL_V2:St,ENDPOINTS:{USERS:Et,USER_ANSWERS:ut}}},USERS:{MYSELF:lt}}=r,pt=`${St}${Et}/${lt}${ut}`,It=async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(pt,a);t&&t.length&&(e=t)}catch(t){await A(t)}return e};var dt={list:It},wt={authors:{readQuestionAuthors:async(t,e)=>{try{if(t.author=await it(t.authorId),t.answers&&t.answers.length){const a=[];if(e){const e=(await It("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 it(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:Nt,ENDPOINTS:{REGISTRATIONS:At}}}}=r;var Pt={list:async t=>{let e=[];try{const{data:a}=await N().get(`${Nt}${At}`,{params:t});a&&a.length&&(e=a)}catch(t){await A(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Rt,ENDPOINTS:{USERS:Tt,USER_COURSES:Ot}}},USERS:{MYSELF:Ut}}=r,ht=`${Rt}${Tt}/${Ut}${Ot}`;var yt={create:async t=>{try{await N().post(ht,t)}catch(t){await A(t)}},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 A(t)}return e},update:async(t,e)=>{try{await N().put(`${ht}/${t}`,e)}catch(t){await A(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:_t,ENDPOINTS:{USERS:$t,USER_EVENTS:mt}}},USERS:{MYSELF:ft}}=r,gt=`${_t}${$t}/${ft}${mt}`;var Lt={list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(gt,a);t&&t.length&&(e=t)}catch(t){await A(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Ct,ENDPOINTS:{USERS:vt,USER_LESSONS:Dt}}},USERS:{MYSELF:Bt}}=r,Mt=`${Ct}${vt}/${Bt}${Dt}`;var bt={create:async t=>{let e=null;try{e=await N().post(Mt,t)}catch(t){await A(t)}return e},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 A(t)}return e}};const{APIS:{PEOPLE_API:{BASE_URL_V2:xt,ENDPOINTS:{USERS:Gt,USER_PRODUCTS:qt}}},USERS:{MYSELF:Vt}}=r,Ft=`${xt}${Gt}/${Vt}${qt}`;var Qt={create:async t=>{let e=null;try{e=await N().post(Ft,t)}catch(t){await A(t)}return e},list:async t=>{let e=[],a=t?{params:t}:{params:{}};try{const{data:t}=await N().get(Ft,a);t&&t.length&&(e=t)}catch(t){await A(t)}return e},update:async(t,e)=>{try{await N().put(`${Ft}/${t}`,e)}catch(t){await A(t)}}};const{APIS:{PEOPLE_API:{BASE_URL_V2:Yt,ENDPOINTS:{USERS:jt,USER_QUESTIONS:Wt}}},USERS:{MYSELF:Ht}}=r,Kt=`${Yt}${jt}/${Ht}${Wt}`;var kt={handlers:wt,registrations:Pt,users:ct,userAnswers:dt,userCourses:yt,userEvents:Lt,userLessons:bt,userProducts:Qt,userQuestions:{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 A(t)}return e}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:Xt,ENDPOINTS:{ENQUIRY_EMAILS:Jt}}}}=r;var zt={create:async t=>{let e=null;try{const{data:a}=await N().post(`${Xt}${Jt}`,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 re.emails.create({...a,...t})}catch(t){await A(t)}return e}}};const{APIS:{PEOPLE_ENGAGEMENT_API:{BASE_URL:te,ENDPOINTS:{USERS:ee,USER_PROPERTIES:ae}}},USERS:{MYSELF:ne}}=r;var re={emails:zt,handlers:Zt,userProperties:{update:async(t,e)=>{try{await N().put(`${te}${ee}/${ne}${ae}/${t}`,e)}catch(t){await A(t)}}}};const{CONTENTFUL:oe}=r,{TYPE:se,ORDER:ie,FIELDS:ce}=oe.QUESTIONS;var Se={read:async t=>{try{return await(0,e.getEntry)({content_type:se,"fields.slug":t,include:2,select:ce})}catch(t){throw await A(t),new Error(`Cannot read question: ${t.message}`)}},list:async(t=10,a=0)=>{try{return await(0,e.getEntries)({content_type:se,include:1,limit:t,order:ie,select:ce,skip:a})}catch(t){throw await A(t),new Error(`Cannot list questions: ${t.message}`)}}},Ee=async(t,e)=>{try{let a={};return a=await Se.read(t),a=await kt.handlers.authors.readQuestionAuthors(a,e),a}catch(t){throw await A(t),new Error(`Cannot build question: ${t.message}`)}},ue=async(t,e=10)=>{try{let a=[];const n=e*(t-1);a=await Se.list(e,n);for(let t of a)t.author=t.authorId&&await kt.users.read(t.authorId)||{};return a}catch(t){throw await A(t),new Error(`Cannot build questions: ${t.message}`)}},le=S(408);const pe=t=>t&&le.Buffer.from(t,"base64").toString("ascii");function Ie({authContext:r=null,contentContext:S=null,errorsContext:E=null,gtmContext:w=null,origin:N}){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})(N);r&&(0,t.setContext)(Object.assign({},r,{environment:A,origin:N})),S&&(0,e.setContext)(Object.assign({},S,{environment:A})),E&&(0,a.setContext)(Object.assign({},E,{environment:A})),w&&((0,n.setContext)(Object.assign({},w,{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 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}()}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apolitical/sdk",
|
|
3
|
-
"version": "3.1.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Browser library to interact with Apolitical's APIs",
|
|
5
5
|
"author": "Apolitical Group Limited <engineering@apolitical.co>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"http-status-codes": "2.2.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@apolitical/eslint-config": "2.0
|
|
46
|
+
"@apolitical/eslint-config": "2.1.0",
|
|
47
47
|
"@babel/core": "7.17.10",
|
|
48
48
|
"@babel/eslint-parser": "7.17.0",
|
|
49
49
|
"@babel/plugin-transform-runtime": "7.17.10",
|