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

msw-storybook-addon

Package Overview
Dependencies
Maintainers
2
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

msw-storybook-addon - npm Package Compare versions

Comparing version 2.0.0--canary.111.c10b8bb.0 to 2.0.0--canary.122.06f0c92.0

dist/mswDecorator.d.ts

30

dist/index.d.ts

@@ -1,29 +0,1 @@

import { SetupWorkerApi, RequestHandler } from 'msw';
import { SetupServerApi } from 'msw/node';
type SetupApi = SetupWorkerApi | SetupServerApi;
type InitializeOptions = Parameters<SetupWorkerApi['start']>[0] | Parameters<SetupServerApi['listen']>[0];
type MswParameters = {
msw?: RequestHandler[] | {
handlers: RequestHandler[] | Record<string, RequestHandler>;
};
};
type Context = {
parameters: MswParameters;
};
declare function initialize(options?: InitializeOptions): Promise<SetupApi>;
declare function getWorker(): SetupApi;
/**
* @deprecated Use mswLoader instead, as it is much more reliable.
* ```diff
* - import { mswDecorator } from 'msw-storybook-addon';
* + import { mswLoader } from 'msw-storybook-addon';
*
* - export const decorators = [mswDecorator];
* + export const loaders = [mswLoader];
* ```
*/
declare const mswDecorator: <Story extends (...args: any[]) => any>(storyFn: Story, context: Context) => any;
declare const mswLoader: (context: Context) => Promise<{}>;
export { InitializeOptions, MswParameters, SetupApi, getWorker, initialize, mswDecorator, mswLoader };
export * from './mswDecorator';

@@ -1,75 +0,17 @@

'use strict';
var isNodeProcess = require('is-node-process');
var msw = require('msw');
// src/index.ts
var IS_BROWSER = !isNodeProcess.isNodeProcess();
var api;
var workerPromise;
async function initialize(options) {
const defaultHandlers = [
msw.rest.get("/hot-update/*", (req) => req.passthrough()),
msw.rest.get("/node_modules/*", (req) => req.passthrough())
];
if (IS_BROWSER) {
const { setupWorker } = await import('msw');
const worker = setupWorker(...defaultHandlers);
workerPromise = worker.start(options);
api = worker;
} else {
const { setupServer } = await import('msw/node');
const server = setupServer(...defaultHandlers);
workerPromise = Promise.resolve(server.listen(options));
api = server;
}
return api;
}
function getWorker() {
if (api === void 0) {
throw new Error(
`[MSW] Failed to retrieve the worker: no active worker found. Did you forget to call "initialize"?`
);
}
return api;
}
var setupHandlers = (msw) => {
if (api) {
api.resetHandlers();
if (msw) {
if (Array.isArray(msw) && msw.length > 0) {
api.use(...msw);
} else if ("handlers" in msw && msw.handlers) {
const handlers = Object.values(msw.handlers).filter(Boolean).reduce(
(handlers2, handlersList) => handlers2.concat(handlersList),
[]
);
if (handlers.length > 0) {
api.use(...handlers);
}
}
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var mswDecorator = (storyFn, context) => {
const {
parameters: { msw }
} = context;
setupHandlers(msw);
return storyFn();
};
var mswLoader = async (context) => {
const {
parameters: { msw }
} = context;
setupHandlers(msw);
if (workerPromise) {
await workerPromise;
}
return {};
};
exports.getWorker = getWorker;
exports.initialize = initialize;
exports.mswDecorator = mswDecorator;
exports.mswLoader = mswLoader;
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./mswDecorator"), exports);
{
"name": "msw-storybook-addon",
"description": "Mock API requests in Storybook with Mock Service Worker.",
"version": "2.0.0--canary.111.c10b8bb.0",
"version": "2.0.0--canary.122.06f0c92.0",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"typings": "dist/index.d.ts",
"scripts": {
"build": "tsup",
"dev": "yarn build --watch",
"build": "tsc",
"prepublishOnly": "yarn build",

@@ -15,14 +14,4 @@ "release": "auto shipit"

"files": [
"dist/**/*",
"README.md",
"*.js",
"*.d.ts"
"dist/"
],
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
},
"repository": {

@@ -54,7 +43,7 @@ "type": "git",

"auto": "^10.32.2",
"tsup": "^6.6.3",
"typescript": "^5.0.4"
"typescript": "^5.2.2",
"msw": "^2.0.9"
},
"peerDependencies": {
"msw": ">=0.35.0 <2.0.0"
"msw": "^2.0.9"
},

@@ -61,0 +50,0 @@ "storybook": {

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