@apolitical/sdk 0.0.1-beta.8 → 0.4.0-beta.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 CHANGED
@@ -6,6 +6,12 @@ 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
8
 
9
+ ## [0.0.3] - 2022-01-12
10
+ ### Added
11
+ - Exposed `reportError` function
12
+ ### Fixed
13
+ - Resources naming (must be plural)
14
+
9
15
  ## [0.0.2] - 2022-01-06
10
16
  ### Added
11
17
  - First example function `ping`
package/README.md CHANGED
@@ -38,11 +38,22 @@ Publishes the library to NPM.
38
38
 
39
39
  ## Usage
40
40
 
41
- The recommended way to use `@apolitical/sdk` is to use the provided functionality:
41
+ The recommended way to use `@apolitical/sdk` is to load the SDK first:
42
42
 
43
43
  ```js
44
- const { ping } = require('@apolitical/sdk');
44
+ const loadSdk = require('@apolitical/sdk');
45
45
 
46
- const result = ping();
47
- console.log(result);
46
+ const sdk = loadSdk({
47
+ origin: window.origin || window.location.origin,
48
+ gcpErrorsApiKey: process.env.REACT_APP_GCP_ERRORS_API_KEY,
49
+ serviceName: 'some-service',
50
+ });
51
+ ```
52
+
53
+ And then, you can use all the functionality provided by the SDK. For example:
54
+
55
+ ```js
56
+ sdk.template.dummy.read().then((result) => {
57
+ console.info('SDK ping:', result);
58
+ });
48
59
  ```
package/build/index.js CHANGED
@@ -1 +1 @@
1
- !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("@apolitical/error-reporting"),require("axios"),require("http-status-codes")):"function"==typeof define&&define.amd?define(["@apolitical/error-reporting","axios","http-status-codes"],r):"object"==typeof exports?exports.ApoliticalSDK=r(require("@apolitical/error-reporting"),require("axios"),require("http-status-codes")):e.ApoliticalSDK=r(e["@apolitical/error-reporting"],e.axios,e["http-status-codes"])}(this,(function(e,r,t){return function(){"use strict";var o={30:function(r){r.exports=e},300:function(e){e.exports=r},25:function(e){e.exports=t}},n={};function a(e){var r=n[e];if(void 0!==r)return r.exports;var t=n[e]={exports:{}};return o[e](t,t.exports,a),t.exports}a.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(r,{a:r}),r},a.d=function(e,r){for(var t in r)a.o(r,t)&&!a.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},a.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return function(){a.r(i),a.d(i,{default:function(){return E}});var e=a(30),r=a(300),t=a.n(r),o={APIS:{BACKEND_TEMPLATE:{BASE_URL:"/api/backend-template",ENDPOINTS:{DUMMY:"/dummy"}},PEOPLE_API:{BASE_URL:"/api/people-api",ENDPOINTS:{USERS:"/users"}}}},n=a(25);const s=async r=>{try{let t=!1,o="Error at Apolitical SDK: ";if(r.response){switch(r.response.status){case n.StatusCodes.NOT_FOUND:case n.StatusCodes.FORBIDDEN:t=!0}o+=JSON.stringify(r.response)}else r.request?o+=JSON.stringify(r.request):o+=r.message;if(console.warn(o),t)return;await(0,e.reportError)(new Error(o))}catch(e){console.warn(`Cannot handle error: ${e.message}`)}},{APIS:{PEOPLE_API:{BASE_URL:u,ENDPOINTS:{USERS:c}}}}=o;var p={user:{read:async e=>{let r=null;try{({data:r}=await t().get(`${u}${c}/${e}`))}catch(e){await s(e)}return r}}};const{APIS:{BACKEND_TEMPLATE:{BASE_URL:l,ENDPOINTS:{DUMMY:f}}}}=o;var d={people:p,template:{dummy:{read:async()=>{let e=null;try{({data:e}=await t().get(`${l}${f}`))}catch(e){await s(e)}return e}}}};function E({origin:r,gcpErrorsApiKey:t,serviceName:o}){return(0,e.setContext)({origin:r,accessToken:t,serviceName:o}),{...d,reportError:e.reportError}}}(),i}()}));
1
+ !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("@apolitical/error-reporting"),require("axios"),require("http-status-codes")):"function"==typeof define&&define.amd?define(["@apolitical/error-reporting","axios","http-status-codes"],r):"object"==typeof exports?exports.ApoliticalSDK=r(require("@apolitical/error-reporting"),require("axios"),require("http-status-codes")):e.ApoliticalSDK=r(e["@apolitical/error-reporting"],e.axios,e["http-status-codes"])}(this,(function(e,r,t){return function(){"use strict";var o={30:function(r){r.exports=e},300:function(e){e.exports=r},25:function(e){e.exports=t}},n={};function a(e){var r=n[e];if(void 0!==r)return r.exports;var t=n[e]={exports:{}};return o[e](t,t.exports,a),t.exports}a.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(r,{a:r}),r},a.d=function(e,r){for(var t in r)a.o(r,t)&&!a.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},a.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return function(){a.r(i),a.d(i,{default:function(){return N},reportError:function(){return e.reportError}});var e=a(30),r=a(300),t=a.n(r),o={APIS:{BACKEND_TEMPLATE:{BASE_URL:"/api/backend-template",ENDPOINTS:{DUMMY:"/dummy"}},MANAGEMENT_API:{BASE_URL:"/api/management-api",ENDPOINTS:{ACCOUNTS:"/accounts/:email"}},PEOPLE_API:{BASE_URL:"/api/people-api",ENDPOINTS:{USERS:"/users"}}}},n=a(25);const s=async r=>{try{let t=!1,o="Error at Apolitical SDK: ";if(r.response){switch(r.response.status){case n.StatusCodes.NOT_FOUND:case n.StatusCodes.FORBIDDEN:t=!0}o+=JSON.stringify(r.response)}else r.request?o+=JSON.stringify(r.request):o+=r.message;if(console.warn(o),t)return;await(0,e.reportError)(new Error(o))}catch(e){console.warn(`Cannot handle error: ${e.message}`)}},{APIS:{PEOPLE_API:{BASE_URL:u,ENDPOINTS:{USERS:c}}}}=o;var p={users:{read:async e=>{let r=null;try{({data:r}=await t().get(`${u}${c}/${e}`))}catch(e){await s(e)}return r}}};const{APIS:{BACKEND_TEMPLATE:{BASE_URL:l,ENDPOINTS:{DUMMY:f}}}}=o;var E={dummy:{read:async()=>{let e=null;try{({data:e}=await t().get(`${l}${f}`))}catch(e){await s(e)}return e}}};const{APIS:{MANAGEMENT_API:{BASE_URL:d,ENDPOINTS:{ACCOUNTS:S}}}}=o;var A={management:{accounts:{read:async e=>{let r=null;try{({data:r}=await t().get(`${d}${S}/${e}`))}catch(e){await s(e)}return r}}},people:p,template:E};function N({origin:r,gcpErrorsApiKey:t,serviceName:o}){return(0,e.setContext)({origin:r,accessToken:t,serviceName:o}),{...A,reportError:e.reportError}}}(),i}()}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apolitical/sdk",
3
- "version": "0.0.1-beta.8",
3
+ "version": "0.4.0-beta.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",