Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@kasko/fe-mock-api-lib
Advanced tools
KASKO platform API request mocking made easy.
yarn add -D @kasko/fe-mock-api-lib
+ 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,
},
};
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": []
}
yarn install
yarn test
yarn lint
FAQs
KASKO platform API request mocking made easy.
We found that @kasko/fe-mock-api-lib demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 18 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.