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

msw-storybook-addon

Package Overview
Dependencies
Maintainers
3
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.122.0f49e5c.0 to 2.0.0--canary.122.133be34.0

7

dist/index.browser.d.ts
import { RequestHandler } from 'msw';
import { SetupWorker } from 'msw/browser';
import { setupWorker } from 'msw/browser';
type SetupWorker = ReturnType<typeof setupWorker>;
type InitializeOptions = Parameters<SetupWorker['start']>[0];

@@ -20,2 +21,4 @@ declare function initialize(options?: InitializeOptions, initialHandlers?: RequestHandler[]): SetupWorker;

export { type Context, type InitializeOptions, type MswParameters, getWorker, initialize, mswDecorator, mswLoader };
declare function applyRequestHandlers(handlersListOrObject: Context['parameters']['msw']): void;
export { type Context, type InitializeOptions, type MswParameters, applyRequestHandlers, getWorker, initialize, mswDecorator, mswLoader };

@@ -1,32 +0,3 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
getWorker: () => getWorker,
initialize: () => initialize,
mswDecorator: () => mswDecorator,
mswLoader: () => mswLoader
});
module.exports = __toCommonJS(src_exports);
// src/initialize.browser.ts
var import_browser = require("msw/browser");
import { setupWorker } from "msw/browser";

@@ -81,3 +52,3 @@ // src/augmentInitializeOptions.ts

function initialize(options, initialHandlers = []) {
const worker = (0, import_browser.setupWorker)(...initialHandlers);
const worker = setupWorker(...initialHandlers);
worker.start(augmentInitializeOptions(options));

@@ -96,3 +67,67 @@ api = worker;

// ../../node_modules/ts-dedent/esm/index.js
function dedent(templ) {
var values = [];
for (var _i = 1; _i < arguments.length; _i++) {
values[_i - 1] = arguments[_i];
}
var strings = Array.from(typeof templ === "string" ? [templ] : templ);
strings[strings.length - 1] = strings[strings.length - 1].replace(/\r?\n([\t ]*)$/, "");
var indentLengths = strings.reduce(function(arr, str) {
var matches = str.match(/\n([\t ]+|(?!\s).)/g);
if (matches) {
return arr.concat(matches.map(function(match) {
var _a, _b;
return (_b = (_a = match.match(/[\t ]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
}));
}
return arr;
}, []);
if (indentLengths.length) {
var pattern_1 = new RegExp("\n[ ]{" + Math.min.apply(Math, indentLengths) + "}", "g");
strings = strings.map(function(str) {
return str.replace(pattern_1, "\n");
});
}
strings[0] = strings[0].replace(/^\r?\n/, "");
var string = strings[0];
values.forEach(function(value, i) {
var endentations = string.match(/(?:^|\n)( *)$/);
var endentation = endentations ? endentations[1] : "";
var indentedValue = value;
if (typeof value === "string" && value.includes("\n")) {
indentedValue = String(value).split("\n").map(function(str, i2) {
return i2 === 0 ? str : "" + endentation + str;
}).join("\n");
}
string += indentedValue + strings[i + 1];
});
return string;
}
// src/util.ts
function once(fn) {
let called = false;
let value;
const wrapper = (...args) => {
if (!called) {
called = true;
value = fn(...args);
}
return value;
};
return wrapper;
}
function deprecate(message) {
return once(() => {
console.warn(dedent(message));
});
}
// src/applyRequestHandlers.ts
var deprecateMessage = deprecate(`
[msw-storybook-addon] You are using parameters.msw as an Array instead of an Object with a property "handlers". This usage is deprecated and will be removed in the next release. Please use the Object syntax instead.
More info: https://github.com/mswjs/msw-storybook-addon/blob/main/MIGRATION.md#parametersmsw-array-notation-deprecated-in-favor-of-object-notation
`);
function applyRequestHandlers(handlersListOrObject) {

@@ -104,2 +139,3 @@ api?.resetHandlers();

if (Array.isArray(handlersListOrObject) && handlersListOrObject.length > 0) {
deprecateMessage();
api.use(...handlersListOrObject);

@@ -121,3 +157,9 @@ return;

// src/decorator.ts
var deprecateMessage2 = deprecate(`
[msw-storybook-addon] The mswDecorator is deprecated and will be removed in the next release. Please use the mswLoader instead.
More info: https://github.com/mswjs/msw-storybook-addon/blob/main/MIGRATION.md#mswdecorator-is-deprecated-in-favor-of-mswloader
`);
var mswDecorator = (storyFn, context) => {
deprecateMessage2();
applyRequestHandlers(context.parameters.msw);

@@ -130,3 +172,3 @@ return storyFn();

applyRequestHandlers(context.parameters.msw);
if (typeof window !== "undefined" && "navigator" in window && navigator.serviceWorker.controller) {
if (typeof window !== "undefined" && "navigator" in window && navigator.serviceWorker?.controller) {
await navigator.serviceWorker.ready;

@@ -136,4 +178,4 @@ }

};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
export {
applyRequestHandlers,
getWorker,

@@ -143,2 +185,2 @@ initialize,

mswLoader
});
};
import { RequestHandler } from 'msw';
import { SetupServer } from 'msw/node';
import { setupServer } from 'msw/node';
type SetupServer = ReturnType<typeof setupServer>;
type InitializeOptions = Parameters<SetupServer['listen']>[0];

@@ -20,2 +21,4 @@ declare function initialize(options?: InitializeOptions, initialHandlers?: RequestHandler[]): SetupServer;

export { type Context, type InitializeOptions, type MswParameters, getWorker, initialize, mswDecorator, mswLoader };
declare function applyRequestHandlers(handlersListOrObject: Context['parameters']['msw']): void;
export { type Context, type InitializeOptions, type MswParameters, applyRequestHandlers, getWorker, initialize, mswDecorator, mswLoader };

@@ -1,32 +0,3 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
getWorker: () => getWorker,
initialize: () => initialize,
mswDecorator: () => mswDecorator,
mswLoader: () => mswLoader
});
module.exports = __toCommonJS(src_exports);
// src/initialize.node.ts
var import_node = require("msw/node");
import { setupServer } from "msw/node";

@@ -81,3 +52,3 @@ // src/augmentInitializeOptions.ts

function initialize(options, initialHandlers = []) {
const server = (0, import_node.setupServer)(...initialHandlers);
const server = setupServer(...initialHandlers);
server.listen(augmentInitializeOptions(options));

@@ -96,3 +67,67 @@ api = server;

// ../../node_modules/ts-dedent/esm/index.js
function dedent(templ) {
var values = [];
for (var _i = 1; _i < arguments.length; _i++) {
values[_i - 1] = arguments[_i];
}
var strings = Array.from(typeof templ === "string" ? [templ] : templ);
strings[strings.length - 1] = strings[strings.length - 1].replace(/\r?\n([\t ]*)$/, "");
var indentLengths = strings.reduce(function(arr, str) {
var matches = str.match(/\n([\t ]+|(?!\s).)/g);
if (matches) {
return arr.concat(matches.map(function(match) {
var _a, _b;
return (_b = (_a = match.match(/[\t ]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
}));
}
return arr;
}, []);
if (indentLengths.length) {
var pattern_1 = new RegExp("\n[ ]{" + Math.min.apply(Math, indentLengths) + "}", "g");
strings = strings.map(function(str) {
return str.replace(pattern_1, "\n");
});
}
strings[0] = strings[0].replace(/^\r?\n/, "");
var string = strings[0];
values.forEach(function(value, i) {
var endentations = string.match(/(?:^|\n)( *)$/);
var endentation = endentations ? endentations[1] : "";
var indentedValue = value;
if (typeof value === "string" && value.includes("\n")) {
indentedValue = String(value).split("\n").map(function(str, i2) {
return i2 === 0 ? str : "" + endentation + str;
}).join("\n");
}
string += indentedValue + strings[i + 1];
});
return string;
}
// src/util.ts
function once(fn) {
let called = false;
let value;
const wrapper = (...args) => {
if (!called) {
called = true;
value = fn(...args);
}
return value;
};
return wrapper;
}
function deprecate(message) {
return once(() => {
console.warn(dedent(message));
});
}
// src/applyRequestHandlers.ts
var deprecateMessage = deprecate(`
[msw-storybook-addon] You are using parameters.msw as an Array instead of an Object with a property "handlers". This usage is deprecated and will be removed in the next release. Please use the Object syntax instead.
More info: https://github.com/mswjs/msw-storybook-addon/blob/main/MIGRATION.md#parametersmsw-array-notation-deprecated-in-favor-of-object-notation
`);
function applyRequestHandlers(handlersListOrObject) {

@@ -104,2 +139,3 @@ api?.resetHandlers();

if (Array.isArray(handlersListOrObject) && handlersListOrObject.length > 0) {
deprecateMessage();
api.use(...handlersListOrObject);

@@ -121,3 +157,9 @@ return;

// src/decorator.ts
var deprecateMessage2 = deprecate(`
[msw-storybook-addon] The mswDecorator is deprecated and will be removed in the next release. Please use the mswLoader instead.
More info: https://github.com/mswjs/msw-storybook-addon/blob/main/MIGRATION.md#mswdecorator-is-deprecated-in-favor-of-mswloader
`);
var mswDecorator = (storyFn, context) => {
deprecateMessage2();
applyRequestHandlers(context.parameters.msw);

@@ -130,3 +172,3 @@ return storyFn();

applyRequestHandlers(context.parameters.msw);
if (typeof window !== "undefined" && "navigator" in window && navigator.serviceWorker.controller) {
if (typeof window !== "undefined" && "navigator" in window && navigator.serviceWorker?.controller) {
await navigator.serviceWorker.ready;

@@ -136,4 +178,4 @@ }

};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
export {
applyRequestHandlers,
getWorker,

@@ -143,2 +185,2 @@ initialize,

mswLoader
});
};
import { RequestHandler } from 'msw';
import { SetupServer } from 'msw/node';
import { setupServer } from 'msw/native';
type SetupServer = ReturnType<typeof setupServer>;
type InitializeOptions = Parameters<SetupServer['listen']>[0];

@@ -20,2 +21,4 @@ declare function initialize(options?: InitializeOptions, initialHandlers?: RequestHandler[]): SetupServer;

export { type Context, type InitializeOptions, type MswParameters, getWorker, initialize, mswDecorator, mswLoader };
declare function applyRequestHandlers(handlersListOrObject: Context['parameters']['msw']): void;
export { type Context, type InitializeOptions, type MswParameters, applyRequestHandlers, getWorker, initialize, mswDecorator, mswLoader };

@@ -1,32 +0,3 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
getWorker: () => getWorker,
initialize: () => initialize,
mswDecorator: () => mswDecorator,
mswLoader: () => mswLoader
});
module.exports = __toCommonJS(src_exports);
// src/initialize.react-native.ts
var import_native = require("msw/native");
import { setupServer } from "msw/native";

@@ -81,3 +52,3 @@ // src/augmentInitializeOptions.ts

function initialize(options, initialHandlers = []) {
const server = (0, import_native.setupServer)(...initialHandlers);
const server = setupServer(...initialHandlers);
server.listen(augmentInitializeOptions(options));

@@ -96,3 +67,67 @@ api = server;

// ../../node_modules/ts-dedent/esm/index.js
function dedent(templ) {
var values = [];
for (var _i = 1; _i < arguments.length; _i++) {
values[_i - 1] = arguments[_i];
}
var strings = Array.from(typeof templ === "string" ? [templ] : templ);
strings[strings.length - 1] = strings[strings.length - 1].replace(/\r?\n([\t ]*)$/, "");
var indentLengths = strings.reduce(function(arr, str) {
var matches = str.match(/\n([\t ]+|(?!\s).)/g);
if (matches) {
return arr.concat(matches.map(function(match) {
var _a, _b;
return (_b = (_a = match.match(/[\t ]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
}));
}
return arr;
}, []);
if (indentLengths.length) {
var pattern_1 = new RegExp("\n[ ]{" + Math.min.apply(Math, indentLengths) + "}", "g");
strings = strings.map(function(str) {
return str.replace(pattern_1, "\n");
});
}
strings[0] = strings[0].replace(/^\r?\n/, "");
var string = strings[0];
values.forEach(function(value, i) {
var endentations = string.match(/(?:^|\n)( *)$/);
var endentation = endentations ? endentations[1] : "";
var indentedValue = value;
if (typeof value === "string" && value.includes("\n")) {
indentedValue = String(value).split("\n").map(function(str, i2) {
return i2 === 0 ? str : "" + endentation + str;
}).join("\n");
}
string += indentedValue + strings[i + 1];
});
return string;
}
// src/util.ts
function once(fn) {
let called = false;
let value;
const wrapper = (...args) => {
if (!called) {
called = true;
value = fn(...args);
}
return value;
};
return wrapper;
}
function deprecate(message) {
return once(() => {
console.warn(dedent(message));
});
}
// src/applyRequestHandlers.ts
var deprecateMessage = deprecate(`
[msw-storybook-addon] You are using parameters.msw as an Array instead of an Object with a property "handlers". This usage is deprecated and will be removed in the next release. Please use the Object syntax instead.
More info: https://github.com/mswjs/msw-storybook-addon/blob/main/MIGRATION.md#parametersmsw-array-notation-deprecated-in-favor-of-object-notation
`);
function applyRequestHandlers(handlersListOrObject) {

@@ -104,2 +139,3 @@ api?.resetHandlers();

if (Array.isArray(handlersListOrObject) && handlersListOrObject.length > 0) {
deprecateMessage();
api.use(...handlersListOrObject);

@@ -121,3 +157,9 @@ return;

// src/decorator.ts
var deprecateMessage2 = deprecate(`
[msw-storybook-addon] The mswDecorator is deprecated and will be removed in the next release. Please use the mswLoader instead.
More info: https://github.com/mswjs/msw-storybook-addon/blob/main/MIGRATION.md#mswdecorator-is-deprecated-in-favor-of-mswloader
`);
var mswDecorator = (storyFn, context) => {
deprecateMessage2();
applyRequestHandlers(context.parameters.msw);

@@ -130,3 +172,3 @@ return storyFn();

applyRequestHandlers(context.parameters.msw);
if (typeof window !== "undefined" && "navigator" in window && navigator.serviceWorker.controller) {
if (typeof window !== "undefined" && "navigator" in window && navigator.serviceWorker?.controller) {
await navigator.serviceWorker.ready;

@@ -136,4 +178,4 @@ }

};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
export {
applyRequestHandlers,
getWorker,

@@ -143,2 +185,2 @@ initialize,

mswLoader
});
};
{
"name": "msw-storybook-addon",
"version": "2.0.0--canary.122.133be34.0",
"description": "Mock API requests in Storybook with Mock Service Worker.",
"version": "2.0.0--canary.122.0f49e5c.0",
"main": "./dist/index.browser.js",
"types": "./dist/index.browser.d.ts",
"exports": {
"browser": {
"types": "./dist/index.browser.d.ts",
"default": "./dist/index.browser.js"
},
"react-native": {
"types": "./dist/index.react-native.d.ts",
"default": "./dist/index.react-native.js"
},
"node": {
"types": "./dist/index.node.d.ts",
"default": "./dist/index.node.js"
}
},
"scripts": {
"dev": "yarn build --watch",
"clean": "rimraf ./dist",
"build": "tsup",
"prepublishOnly": "yarn clean && yarn build",
"release": "auto shipit"
},
"files": [
"dist/"
],
"repository": {
"type": "git",
"url": "git+https://github.com/mswjs/msw-storybook-addon.git",
"directory": "packages/msw-addon"
},
"keywords": [

@@ -45,8 +14,34 @@ "storybook-addon",

],
"author": "Aditya Agarwal (@dev__adi)",
"homepage": "https://msw-sb.vercel.app/",
"bugs": {
"url": "https://github.com/mswjs/msw-storybook-addon/issues"
},
"homepage": "https://msw-sb.vercel.app/",
"repository": {
"type": "git",
"url": "git+https://github.com/mswjs/msw-storybook-addon.git",
"directory": "packages/msw-addon"
},
"license": "MIT",
"author": "Aditya Agarwal (@dev__adi)",
"type": "module",
"exports": {
".": {
"types": "./dist/index.browser.d.ts",
"browser": "./dist/index.browser.js",
"react-native": "./dist/index.react-native.js",
"node": "./dist/index.node.js",
"default": "./dist/index.browser.js"
}
},
"main": "./dist/index.browser.js",
"types": "./dist/index.browser.d.ts",
"files": [
"dist/"
],
"scripts": {
"build": "tsup",
"dev": "yarn build --watch",
"prepublishOnly": "yarn build",
"release": "auto shipit"
},
"dependencies": {

@@ -56,6 +51,6 @@ "is-node-process": "^1.0.1"

"devDependencies": {
"@auto-it/released": "^10.32.2",
"auto": "^10.32.2",
"@auto-it/released": "^11.1.1",
"auto": "^11.1.1",
"msw": "^2.0.9",
"rimraf": "^5.0.5",
"ts-dedent": "^2.2.0",
"tsup": "^8.0.1",

@@ -67,6 +62,2 @@ "typescript": "^5.2.2"

},
"storybook": {
"displayName": "Mock Service Worker",
"icon": "https://user-images.githubusercontent.com/1671563/144888802-84346d8f-77c9-4377-98c7-4b0364797978.png"
},
"auto": {

@@ -81,3 +72,7 @@ "prereleaseBranches": [

]
},
"storybook": {
"displayName": "Mock Service Worker",
"icon": "https://user-images.githubusercontent.com/1671563/144888802-84346d8f-77c9-4377-98c7-4b0364797978.png"
}
}
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