tempest-react-sdk 0.2.0 → 0.4.0

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.
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(e){return e.map(t=>({method:t.method,path:t.path,status:t.status??200,body:t.body??null,headers:t.headers??{"Content-Type":"application/json"},delayMs:t.delayMs??0}))}exports.createMockHandlers=o;
2
+ //# sourceMappingURL=testing.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.cjs","sources":["../src/testing/create-mock-handlers.ts"],"sourcesContent":["/**\n * Lightweight, MSW-shaped mock request handler factory. Returns plain\n * objects with `{ method, path, status, body }` that callers feed into\n * `msw`'s `http.<method>` helpers OR a custom test harness — the SDK\n * does **not** declare `msw` as a peer dep, so this helper is purely\n * data-driven.\n *\n * Use cases:\n * - Define request fixtures in a single file, share between tests and\n * Storybook stories (when used).\n * - Standardise the \"happy path\" + \"error path\" shape across services.\n *\n * @example\n * import { http, HttpResponse } from \"msw\";\n * import { setupServer } from \"msw/node\";\n * import { createMockHandlers } from \"tempest-react-sdk/testing\";\n *\n * const fixtures = createMockHandlers([\n * { method: \"GET\", path: \"/users/me\", status: 200, body: { id: \"u1\", name: \"Mauricio\" } },\n * { method: \"POST\", path: \"/orders\", status: 201, body: { id: \"o1\" } },\n * { method: \"GET\", path: \"/explode\", status: 500, body: { detail: \"kaboom\" } },\n * ]);\n *\n * const handlers = fixtures.map((f) =>\n * (http as Record<string, Function>)[f.method.toLowerCase()](f.path, () =>\n * HttpResponse.json(f.body, { status: f.status }),\n * ),\n * );\n *\n * setupServer(...handlers);\n */\n\nexport type MockHandlerMethod = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\nexport interface MockHandlerInput {\n method: MockHandlerMethod;\n path: string;\n /** HTTP status code. Default `200`. */\n status?: number;\n /** Response body — anything JSON-serialisable. Default `null`. */\n body?: unknown;\n /** Optional response headers. */\n headers?: Record<string, string>;\n /** Optional artificial delay in ms. Useful to test loading states. */\n delayMs?: number;\n}\n\nexport interface MockHandler {\n method: MockHandlerMethod;\n path: string;\n status: number;\n body: unknown;\n headers: Record<string, string>;\n delayMs: number;\n}\n\n/**\n * Normalise a list of request fixtures into MSW-friendly handler descriptors.\n * Default `status` is `200`, default `body` is `null`, default `delayMs` is `0`,\n * default `headers` is `{ \"Content-Type\": \"application/json\" }`.\n */\nexport function createMockHandlers(handlers: MockHandlerInput[]): MockHandler[] {\n return handlers.map((handler) => ({\n method: handler.method,\n path: handler.path,\n status: handler.status ?? 200,\n body: handler.body ?? null,\n headers: handler.headers ?? { \"Content-Type\": \"application/json\" },\n delayMs: handler.delayMs ?? 0,\n }));\n}\n"],"names":["createMockHandlers","handlers","handler"],"mappings":"gFA6DO,SAASA,EAAmBC,EAA6C,CAC5E,OAAOA,EAAS,IAAKC,IAAa,CAC9B,OAAQA,EAAQ,OAChB,KAAMA,EAAQ,KACd,OAAQA,EAAQ,QAAU,IAC1B,KAAMA,EAAQ,MAAQ,KACtB,QAASA,EAAQ,SAAW,CAAE,eAAgB,kBAAA,EAC9C,QAASA,EAAQ,SAAW,CAAA,EAC9B,CACN"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Normalise a list of request fixtures into MSW-friendly handler descriptors.
3
+ * Default `status` is `200`, default `body` is `null`, default `delayMs` is `0`,
4
+ * default `headers` is `{ "Content-Type": "application/json" }`.
5
+ */
6
+ export declare function createMockHandlers(handlers: MockHandlerInput[]): MockHandler[];
7
+
8
+ export declare interface MockHandler {
9
+ method: MockHandlerMethod;
10
+ path: string;
11
+ status: number;
12
+ body: unknown;
13
+ headers: Record<string, string>;
14
+ delayMs: number;
15
+ }
16
+
17
+ export declare interface MockHandlerInput {
18
+ method: MockHandlerMethod;
19
+ path: string;
20
+ /** HTTP status code. Default `200`. */
21
+ status?: number;
22
+ /** Response body — anything JSON-serialisable. Default `null`. */
23
+ body?: unknown;
24
+ /** Optional response headers. */
25
+ headers?: Record<string, string>;
26
+ /** Optional artificial delay in ms. Useful to test loading states. */
27
+ delayMs?: number;
28
+ }
29
+
30
+ /**
31
+ * Lightweight, MSW-shaped mock request handler factory. Returns plain
32
+ * objects with `{ method, path, status, body }` that callers feed into
33
+ * `msw`'s `http.<method>` helpers OR a custom test harness — the SDK
34
+ * does **not** declare `msw` as a peer dep, so this helper is purely
35
+ * data-driven.
36
+ *
37
+ * Use cases:
38
+ * - Define request fixtures in a single file, share between tests and
39
+ * Storybook stories (when used).
40
+ * - Standardise the "happy path" + "error path" shape across services.
41
+ *
42
+ * @example
43
+ * import { http, HttpResponse } from "msw";
44
+ * import { setupServer } from "msw/node";
45
+ * import { createMockHandlers } from "tempest-react-sdk/testing";
46
+ *
47
+ * const fixtures = createMockHandlers([
48
+ * { method: "GET", path: "/users/me", status: 200, body: { id: "u1", name: "Mauricio" } },
49
+ * { method: "POST", path: "/orders", status: 201, body: { id: "o1" } },
50
+ * { method: "GET", path: "/explode", status: 500, body: { detail: "kaboom" } },
51
+ * ]);
52
+ *
53
+ * const handlers = fixtures.map((f) =>
54
+ * (http as Record<string, Function>)[f.method.toLowerCase()](f.path, () =>
55
+ * HttpResponse.json(f.body, { status: f.status }),
56
+ * ),
57
+ * );
58
+ *
59
+ * setupServer(...handlers);
60
+ */
61
+ export declare type MockHandlerMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
62
+
63
+ export { }
@@ -0,0 +1,14 @@
1
+ function o(e) {
2
+ return e.map((t) => ({
3
+ method: t.method,
4
+ path: t.path,
5
+ status: t.status ?? 200,
6
+ body: t.body ?? null,
7
+ headers: t.headers ?? { "Content-Type": "application/json" },
8
+ delayMs: t.delayMs ?? 0
9
+ }));
10
+ }
11
+ export {
12
+ o as createMockHandlers
13
+ };
14
+ //# sourceMappingURL=testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.js","sources":["../src/testing/create-mock-handlers.ts"],"sourcesContent":["/**\n * Lightweight, MSW-shaped mock request handler factory. Returns plain\n * objects with `{ method, path, status, body }` that callers feed into\n * `msw`'s `http.<method>` helpers OR a custom test harness — the SDK\n * does **not** declare `msw` as a peer dep, so this helper is purely\n * data-driven.\n *\n * Use cases:\n * - Define request fixtures in a single file, share between tests and\n * Storybook stories (when used).\n * - Standardise the \"happy path\" + \"error path\" shape across services.\n *\n * @example\n * import { http, HttpResponse } from \"msw\";\n * import { setupServer } from \"msw/node\";\n * import { createMockHandlers } from \"tempest-react-sdk/testing\";\n *\n * const fixtures = createMockHandlers([\n * { method: \"GET\", path: \"/users/me\", status: 200, body: { id: \"u1\", name: \"Mauricio\" } },\n * { method: \"POST\", path: \"/orders\", status: 201, body: { id: \"o1\" } },\n * { method: \"GET\", path: \"/explode\", status: 500, body: { detail: \"kaboom\" } },\n * ]);\n *\n * const handlers = fixtures.map((f) =>\n * (http as Record<string, Function>)[f.method.toLowerCase()](f.path, () =>\n * HttpResponse.json(f.body, { status: f.status }),\n * ),\n * );\n *\n * setupServer(...handlers);\n */\n\nexport type MockHandlerMethod = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\nexport interface MockHandlerInput {\n method: MockHandlerMethod;\n path: string;\n /** HTTP status code. Default `200`. */\n status?: number;\n /** Response body — anything JSON-serialisable. Default `null`. */\n body?: unknown;\n /** Optional response headers. */\n headers?: Record<string, string>;\n /** Optional artificial delay in ms. Useful to test loading states. */\n delayMs?: number;\n}\n\nexport interface MockHandler {\n method: MockHandlerMethod;\n path: string;\n status: number;\n body: unknown;\n headers: Record<string, string>;\n delayMs: number;\n}\n\n/**\n * Normalise a list of request fixtures into MSW-friendly handler descriptors.\n * Default `status` is `200`, default `body` is `null`, default `delayMs` is `0`,\n * default `headers` is `{ \"Content-Type\": \"application/json\" }`.\n */\nexport function createMockHandlers(handlers: MockHandlerInput[]): MockHandler[] {\n return handlers.map((handler) => ({\n method: handler.method,\n path: handler.path,\n status: handler.status ?? 200,\n body: handler.body ?? null,\n headers: handler.headers ?? { \"Content-Type\": \"application/json\" },\n delayMs: handler.delayMs ?? 0,\n }));\n}\n"],"names":["createMockHandlers","handlers","handler"],"mappings":"AA6DO,SAASA,EAAmBC,GAA6C;AAC5E,SAAOA,EAAS,IAAI,CAACC,OAAa;AAAA,IAC9B,QAAQA,EAAQ;AAAA,IAChB,MAAMA,EAAQ;AAAA,IACd,QAAQA,EAAQ,UAAU;AAAA,IAC1B,MAAMA,EAAQ,QAAQ;AAAA,IACtB,SAASA,EAAQ,WAAW,EAAE,gBAAgB,mBAAA;AAAA,IAC9C,SAASA,EAAQ,WAAW;AAAA,EAAA,EAC9B;AACN;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tempest-react-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "SDK público da Tempest com componentes, hooks e integrações para projetos React.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -28,16 +28,21 @@
28
28
  ],
29
29
  "main": "./dist/tempest-react-sdk.cjs",
30
30
  "module": "./dist/tempest-react-sdk.js",
31
- "types": "./dist/index.d.ts",
31
+ "types": "./dist/tempest-react-sdk.d.ts",
32
32
  "sideEffects": [
33
33
  "**/*.css"
34
34
  ],
35
35
  "exports": {
36
36
  ".": {
37
- "types": "./dist/index.d.ts",
37
+ "types": "./dist/tempest-react-sdk.d.ts",
38
38
  "import": "./dist/tempest-react-sdk.js",
39
39
  "require": "./dist/tempest-react-sdk.cjs"
40
40
  },
41
+ "./testing": {
42
+ "types": "./dist/testing.d.ts",
43
+ "import": "./dist/testing.js",
44
+ "require": "./dist/testing.cjs"
45
+ },
41
46
  "./styles.css": "./dist/styles.css",
42
47
  "./package.json": "./package.json"
43
48
  },