Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kasko/fe-mock-api-lib

Package Overview
Dependencies
Maintainers
17
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kasko/fe-mock-api-lib

KASKO platform API request mocking made easy.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
17
Created
Source

Frontend Mock API Library

KASKO platform API request mocking made easy.

Usage

  1. Install the dependency
yarn add -D @kasko/fe-mock-api-lib
  1. Use it in webpack
+ const mockApi = require('@kasko/fe-mock-api-lib');

module.exports = {
  mode: 'development',
  devServer: {
    open: true,
    port: 3000,
+     before(app) {
+       mockApi(app, path.resolve('./mock-api/api.js'));
+     },
+
+     // Optional: reload page after changes are made
+     contentBase: [
+       path.resolve('./src'),
+       path.resolve('./mock-api'),
+     ],
+     watchContentBase: true,
  },
};
  1. Implement the local API overrides in mock-api folder:

mock-api/api.js

const path = require('path');
const mockApi = require('@kasko/fe-mock-api-lib');

const item = require('./resources/item.json');
const itemContents = mockApi.parseCsvFile(path.resolve(__dirname, './resources/item-contents.csv'));
const itemFieldDefinitions = require('./resources/item-field-definitions.json');
const itemManifest = require('./resources/item-webapp-manifest.json');

module.exports = mockApi.constructRoutes({
  'GET /touchpoints/:touchpoint/items/:item': async (req, res) => {
    item.content.data = await itemContents;
    item.webapp_manifest = itemManifest;
    item.field_definition = itemFieldDefinitions;
    return res.json(item);
  },
});

mock-api/resources/item-contents.csv

"hello.world","Hello!"

mock-api/resources/item-field-definitions.json

{
  "policy": [
    {
      "name": "salutation",
      "validation": "required|string|in:mr,ms"
    }
  ],
  "quote": [
    {
      "name": "duration",
      "validation": "required|string|in:P1Y,P2Y,P3Y"
    }
  ]
}

mock-api/resources/item-webapp-manifest.json

{
  "version": "1.0",
  "schema": {
    "config": {
      "initial_screen": "start",
      "default_values": {
        "duration": "P1Y"
      },
      "requests": [
        {
          "type": "quote"
        },
        {
          "type": "policy"
        },
        {
          "type": "payment"
        }
      ],
      "content_key": {
        "insurer_name": "insurer_name"
      }
    },
    "flow": [
      // ...
    ]
  }
}

mock-api/resources/item.json

{
  "id": "id_hash",
  "object": "item",
  "currency": "eur",
  "currency_profile_id": "id_hash",
  "field_definition": {},
  "config": {
    "tax_rate": 0.19
  },
  "webapp_manifest": {},
  "tags": [],
  "payment_methods": [
    {
      "payment_method": "creditcard",
      "provider": "stripe",
      "keys": {
        "public_key": "pk_test_123"
      }
    }
  ],
  "subscription_plans": [],
  "content": {
    "id": "id_hash",
    "object": "content",
    "data": {}
  },
  "assets": []
}

Development

yarn install

Testing

yarn test
yarn lint

FAQs

Package last updated on 14 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc