@apolitical/sdk 0.0.1 → 0.0.2

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
- ## [0.0.1] - 2021-01-18
8
+
9
+ ## [0.0.2] - 2022-01-06
10
+ ### Added
11
+ - First example function `ping`
12
+
13
+ ## [0.0.1] - 2022-01-05
9
14
  ### Added
10
15
  - Initial setup
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,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("axios")):"function"==typeof define&&define.amd?define(["axios"],t):"object"==typeof exports?exports.ApoliticalSDK=t(require("axios")):e.ApoliticalSDK=t(e.axios)}(this,(function(e){return function(){"use strict";var t={300:function(t){t.exports=e}},o={};function n(e){var r=o[e];if(void 0!==r)return r.exports;var u=o[e]={exports:{}};return t[e](u,u.exports,n),u.exports}n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,{a:t}),t},n.d=function(e,t){for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return function(){n.r(r),n.d(r,{default:function(){return a}});var e=n(300),t=n.n(e);const{APIS:{BACKEND_TEMPLATE:{BASE_URL:o,ENDPOINTS:{DUMMY:u}}}}={APIS:{BACKEND_TEMPLATE:{BASE_URL:"/api/backend-template",ENDPOINTS:{DUMMY:"/dummy"}}}};var a={template:{ping:async()=>{let e=null;try{e=await t().get(`${o}${u}`)}catch(e){(e=>{e.response?console.warn(e.response.data,e.response.status,e.response.headers):e.request?console.warn(e.request):console.warn(e.message)})(e)}return e}}}}(),r}()}));
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}()}));
package/package.json CHANGED
@@ -1,19 +1,13 @@
1
1
  {
2
2
  "name": "@apolitical/sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Browser library to interact with Apolitical's APIs",
5
5
  "author": "Apolitical Group Limited <engineering@apolitical.co>",
6
- "contributors": [
7
- "Anouska Hopkins <anouska.hopkins@apolitical.co>",
8
- "Antonio Cordasco <antonio.cordasco@apolitical.co>",
9
- "Dorothy Yau <dorothy.yau@apolitical.co>",
10
- "Laura Hanna-White <laura.hanna-white@apolitical.co>",
11
- "Fatimat Gbajabiamila <fatimat.gbajabiamila@apolitical.co>",
12
- "Renzo Rozza <renzo.rozza@apolitical.co>",
13
- "Rihards Jukna <rihards.jukna@apolitical.co>"
14
- ],
15
6
  "license": "MIT",
16
7
  "main": "build/index.js",
8
+ "files": [
9
+ "build/**"
10
+ ],
17
11
  "scripts": {
18
12
  "test": "jest --runInBand",
19
13
  "unit-test": "jest test/unit/* --bail --runInBand --passWithNoTests",
@@ -30,10 +24,14 @@
30
24
  "SDK"
31
25
  ],
32
26
  "dependencies": {
33
- "axios": "0.24.0"
27
+ "@apolitical/error-reporting": "0.0.1",
28
+ "axios": "0.24.0",
29
+ "http-status-codes": "2.2.0"
34
30
  },
35
31
  "peerDependencies": {
36
- "axios": "0.24.0"
32
+ "@apolitical/error-reporting": "0.0.1",
33
+ "axios": "0.24.0",
34
+ "http-status-codes": "2.2.0"
37
35
  },
38
36
  "devDependencies": {
39
37
  "@apolitical/eslint-config": "0.0.1",
@@ -44,7 +42,7 @@
44
42
  "husky": "7.0.4",
45
43
  "jest": "27.4.7",
46
44
  "jest-junit": "13.0.0",
47
- "lint-staged": "12.1.5",
45
+ "lint-staged": "12.1.7",
48
46
  "webpack": "5.65.0",
49
47
  "webpack-cli": "4.9.1"
50
48
  },
package/.gitlab-ci.yml DELETED
@@ -1,25 +0,0 @@
1
- # External jobs
2
- include:
3
- - project: 'apolitical/templates/gitlab-pipelines'
4
- ref: master
5
- file: 'Node-Testing.gitlab-ci.yml'
6
-
7
- stages:
8
- - cache
9
- - test
10
- - publish
11
-
12
- # Publish jobs
13
-
14
- publish-module:
15
- stage: publish
16
- image: node:12.20.1-alpine3.11
17
- extends: .yarn-install
18
- only:
19
- - tags
20
- - /^v\d+\.\d+\.\d+$/
21
- before_script:
22
- - yarn build
23
- script:
24
- - echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > ~/.npmrc
25
- - yarn publish --access=public
package/.husky/pre-commit DELETED
@@ -1,8 +0,0 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
- yarn lint-format
5
-
6
- yarn build
7
-
8
- yarn test
package/default.env DELETED
File without changes
@@ -1,27 +0,0 @@
1
- import axios from 'axios';
2
-
3
- import config from '../config';
4
- import { handleError } from '../helpers/errors';
5
-
6
- const {
7
- APIS: {
8
- BACKEND_TEMPLATE: {
9
- BASE_URL,
10
- ENDPOINTS: { DUMMY },
11
- },
12
- },
13
- } = config;
14
-
15
- /*
16
- * Returns a random number after calling the Backend Template
17
- * @return {Object} payload - random number generated by the API
18
- */
19
- export const ping = async () => {
20
- let payload = null;
21
- try {
22
- payload = await axios.get(`${BASE_URL}${DUMMY}`);
23
- } catch (error) {
24
- handleError(error);
25
- }
26
- return payload;
27
- };
package/lib/config.js DELETED
@@ -1,12 +0,0 @@
1
- const config = {
2
- APIS: {
3
- BACKEND_TEMPLATE: {
4
- BASE_URL: '/api/backend-template',
5
- ENDPOINTS: {
6
- DUMMY: '/dummy',
7
- },
8
- },
9
- },
10
- };
11
-
12
- export default config;
package/lib/context.js DELETED
@@ -1,13 +0,0 @@
1
- // TODO: Define context when external configurations are required for the SDK to work
2
-
3
- // let context = {
4
- // token: null,
5
- // };
6
-
7
- // export const setContext = ({ token }) => {
8
- // context.token = token;
9
- // };
10
-
11
- // export const getContext = () => {
12
- // return context;
13
- // };
@@ -1,12 +0,0 @@
1
- export const handleError = (error) => {
2
- if (error.response) {
3
- // The request was made and the server responded with a status code that falls out of the range of 2xx
4
- console.warn(error.response.data, error.response.status, error.response.headers);
5
- } else if (error.request) {
6
- // The request was made but no response was received
7
- console.warn(error.request);
8
- } else {
9
- // Something happened in setting up the request that triggered an error
10
- console.warn(error.message);
11
- }
12
- };
package/lib/index.js DELETED
@@ -1,9 +0,0 @@
1
- import { ping } from './apis/template';
2
-
3
- const sdk = {
4
- template: {
5
- ping,
6
- },
7
- };
8
-
9
- export default sdk;
@@ -1,4 +0,0 @@
1
- // Overrides console error & warn when testing
2
- // Importnat: Comment out this line to check errors when testing
3
- console.error = jest.fn();
4
- console.warn = jest.fn();
@@ -1,27 +0,0 @@
1
- import axios from 'axios';
2
-
3
- import sdk from '../lib';
4
-
5
- const {
6
- template: { ping },
7
- } = sdk;
8
-
9
- jest.mock('axios');
10
-
11
- describe('Apolitical SDK', () => {
12
- describe('Backend Template', () => {
13
- describe('Ping (Dummy)', () => {
14
- test('should return a number', async () => {
15
- axios.get.mockResolvedValueOnce({ result: 123 });
16
- const { result } = await ping();
17
- expect(result).toEqual(expect.any(Number));
18
- });
19
-
20
- test('should catch unexpected errors', async () => {
21
- axios.get.mockRejectedValueOnce(new Error('Something went wrong'));
22
- const result = await ping();
23
- expect(result).toStrictEqual(null);
24
- });
25
- });
26
- });
27
- });
package/webpack.config.js DELETED
@@ -1,28 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
-
5
- module.exports = {
6
- mode: 'production',
7
- entry: {
8
- index: path.resolve(__dirname, 'lib', 'index.js'),
9
- },
10
- output: {
11
- path: path.resolve(__dirname, 'build'),
12
- filename: 'index.js',
13
- library: {
14
- name: 'ApoliticalSDK',
15
- type: 'umd',
16
- },
17
- globalObject: 'this',
18
- },
19
- externals: {
20
- axios: 'axios',
21
- },
22
- optimization: {
23
- splitChunks: {
24
- chunks: 'all',
25
- },
26
- minimize: true,
27
- },
28
- };