@schmock/angular 1.0.1 → 1.0.3

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,56 @@
1
+ import type { HttpInterceptor, HttpRequest } from "@angular/common/http";
2
+ import type { CallableMockInstance, ResponseResult } from "@schmock/core";
3
+ /**
4
+ * Configuration options for Angular adapter
5
+ */
6
+ export interface AngularAdapterOptions {
7
+ /**
8
+ * Base URL to intercept (e.g., '/api')
9
+ * If not provided, intercepts all requests
10
+ */
11
+ baseUrl?: string;
12
+ /**
13
+ * Whether to pass through requests that don't match any route
14
+ * @default true
15
+ */
16
+ passthrough?: boolean;
17
+ /**
18
+ * Custom error formatter
19
+ * @param error - The error that occurred
20
+ * @param request - Angular HTTP request
21
+ * @returns Custom error response
22
+ */
23
+ errorFormatter?: (error: Error, request: HttpRequest<any>) => any;
24
+ /**
25
+ * Request transformer - modify request before passing to Schmock
26
+ * @param request - Angular HTTP request
27
+ * @returns Modified request data
28
+ */
29
+ transformRequest?: (request: HttpRequest<any>) => {
30
+ method?: string;
31
+ path?: string;
32
+ headers?: Record<string, string>;
33
+ body?: any;
34
+ query?: Record<string, string>;
35
+ };
36
+ /**
37
+ * Response transformer - modify Schmock response before returning
38
+ * @param response - Response from Schmock
39
+ * @param request - Original Angular request
40
+ * @returns Modified response
41
+ */
42
+ transformResponse?: (response: ResponseResult, request: HttpRequest<any>) => ResponseResult;
43
+ }
44
+ /**
45
+ * Create an Angular HTTP interceptor from a Schmock instance
46
+ */
47
+ export declare function createSchmockInterceptor(mock: CallableMockInstance, options?: AngularAdapterOptions): new () => HttpInterceptor;
48
+ /**
49
+ * Provider configuration for Angular module
50
+ */
51
+ export declare function provideSchmockInterceptor(mock: CallableMockInstance, options?: AngularAdapterOptions): {
52
+ provide: string;
53
+ useClass: new () => HttpInterceptor;
54
+ multi: boolean;
55
+ };
56
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,eAAe,EACf,WAAW,EACZ,MAAM,sBAAsB,CAAC;AAO9B,OAAO,KAAK,EACV,oBAAoB,EAEpB,cAAc,EACf,MAAM,eAAe,CAAC;AAwBvB;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;IAElE;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,KAAK;QAChD,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAChC,CAAC;IAEF;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,CAClB,QAAQ,EAAE,cAAc,EACxB,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,KACtB,cAAc,CAAC;CACrB;AA2CD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,oBAAoB,EAC1B,OAAO,GAAE,qBAA0B,GAClC,UAAU,eAAe,CAsH3B;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,oBAAoB,EAC1B,OAAO,CAAC,EAAE,qBAAqB;;wBA7HpB,eAAe;;EAoI3B"}
package/dist/index.js CHANGED
@@ -35121,6 +35121,24 @@ var CACHE_OPTIONS = new InjectionToken(ngDevMode ? "HTTP_TRANSFER_STATE_CACHE_OP
35121
35121
 
35122
35122
  // src/index.ts
35123
35123
  var import_rxjs3 = __toESM(require_cjs(), 1);
35124
+ var HTTP_METHODS = [
35125
+ "GET",
35126
+ "POST",
35127
+ "PUT",
35128
+ "DELETE",
35129
+ "PATCH",
35130
+ "HEAD",
35131
+ "OPTIONS"
35132
+ ];
35133
+ function isHttpMethod(method) {
35134
+ return HTTP_METHODS.includes(method);
35135
+ }
35136
+ function toHttpMethod(method) {
35137
+ if (isHttpMethod(method)) {
35138
+ return method;
35139
+ }
35140
+ return "GET";
35141
+ }
35124
35142
  function extractQueryParams(url) {
35125
35143
  const queryStart = url.indexOf("?");
35126
35144
  if (queryStart === -1)
@@ -35163,7 +35181,7 @@ function createSchmockInterceptor(mock, options = {}) {
35163
35181
  const path = extractPath(req.url);
35164
35182
  const query = extractQueryParams(req.url);
35165
35183
  let requestData = {
35166
- method: req.method,
35184
+ method: toHttpMethod(req.method),
35167
35185
  path,
35168
35186
  headers: headersToObject(req),
35169
35187
  body: req.body,
@@ -35174,7 +35192,7 @@ function createSchmockInterceptor(mock, options = {}) {
35174
35192
  requestData = {
35175
35193
  ...requestData,
35176
35194
  ...transformed,
35177
- method: transformed.method || requestData.method
35195
+ method: toHttpMethod(transformed.method ?? req.method)
35178
35196
  };
35179
35197
  }
35180
35198
  return new import_rxjs3.Observable((observer) => {
@@ -35210,11 +35228,12 @@ function createSchmockInterceptor(mock, options = {}) {
35210
35228
  }).catch((error) => {
35211
35229
  let errorBody;
35212
35230
  if (errorFormatter) {
35213
- errorBody = errorFormatter(error, req);
35231
+ errorBody = errorFormatter(error instanceof Error ? error : new Error(String(error)), req);
35214
35232
  } else {
35233
+ const errorWithCode = error;
35215
35234
  errorBody = {
35216
35235
  error: error instanceof Error ? error.message : "Internal Server Error",
35217
- code: error.code || "INTERNAL_ERROR"
35236
+ code: errorWithCode.code ?? "INTERNAL_ERROR"
35218
35237
  };
35219
35238
  }
35220
35239
  observer.error(new HttpErrorResponse({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schmock/angular",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Angular HTTP interceptor adapter for Schmock",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "clean": "rm -rf dist",
14
14
  "build": "bun run clean && bun run build:lib && bun run build:types",
15
15
  "build:lib": "bun build src/index.ts --outdir dist --target node --format esm",
16
- "build:types": "tsc --emitDeclarationOnly --declaration --outDir dist",
16
+ "build:types": "rm -f tsconfig.tsbuildinfo && tsc --build",
17
17
  "test": "vitest run",
18
18
  "test:watch": "vitest",
19
19
  "lint": "biome check src",