@seontechnologies/pactjs-utils 1.0.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.
- package/LICENSE +190 -0
- package/README.md +463 -0
- package/dist/cjs/consumer-helpers/create-provider-state.d.ts +18 -0
- package/dist/cjs/consumer-helpers/create-provider-state.d.ts.map +1 -0
- package/dist/cjs/consumer-helpers/create-provider-state.js +18 -0
- package/dist/cjs/consumer-helpers/create-provider-state.js.map +1 -0
- package/dist/cjs/consumer-helpers/index.d.ts +6 -0
- package/dist/cjs/consumer-helpers/index.d.ts.map +1 -0
- package/dist/cjs/consumer-helpers/index.js +11 -0
- package/dist/cjs/consumer-helpers/index.js.map +1 -0
- package/dist/cjs/consumer-helpers/set-json-content.d.ts +32 -0
- package/dist/cjs/consumer-helpers/set-json-content.d.ts.map +1 -0
- package/dist/cjs/consumer-helpers/set-json-content.js +28 -0
- package/dist/cjs/consumer-helpers/set-json-content.js.map +1 -0
- package/dist/cjs/consumer-helpers/to-json-map.d.ts +13 -0
- package/dist/cjs/consumer-helpers/to-json-map.d.ts.map +1 -0
- package/dist/cjs/consumer-helpers/to-json-map.js +34 -0
- package/dist/cjs/consumer-helpers/to-json-map.js.map +1 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/pact-types.d.ts +45 -0
- package/dist/cjs/pact-types.d.ts.map +1 -0
- package/dist/cjs/pact-types.js +11 -0
- package/dist/cjs/pact-types.js.map +1 -0
- package/dist/cjs/provider-verifier/build-verifier-options.d.ts +49 -0
- package/dist/cjs/provider-verifier/build-verifier-options.d.ts.map +1 -0
- package/dist/cjs/provider-verifier/build-verifier-options.js +113 -0
- package/dist/cjs/provider-verifier/build-verifier-options.js.map +1 -0
- package/dist/cjs/provider-verifier/handle-url-and-selectors.d.ts +18 -0
- package/dist/cjs/provider-verifier/handle-url-and-selectors.d.ts.map +1 -0
- package/dist/cjs/provider-verifier/handle-url-and-selectors.js +137 -0
- package/dist/cjs/provider-verifier/handle-url-and-selectors.js.map +1 -0
- package/dist/cjs/provider-verifier/index.d.ts +3 -0
- package/dist/cjs/provider-verifier/index.d.ts.map +1 -0
- package/dist/cjs/provider-verifier/index.js +10 -0
- package/dist/cjs/provider-verifier/index.js.map +1 -0
- package/dist/cjs/request-filter/create-request-filter.d.ts +19 -0
- package/dist/cjs/request-filter/create-request-filter.d.ts.map +1 -0
- package/dist/cjs/request-filter/create-request-filter.js +39 -0
- package/dist/cjs/request-filter/create-request-filter.js.map +1 -0
- package/dist/cjs/request-filter/index.d.ts +2 -0
- package/dist/cjs/request-filter/index.d.ts.map +1 -0
- package/dist/cjs/request-filter/index.js +7 -0
- package/dist/cjs/request-filter/index.js.map +1 -0
- package/dist/cjs/zod-to-pact/index.d.ts +2 -0
- package/dist/cjs/zod-to-pact/index.d.ts.map +1 -0
- package/dist/cjs/zod-to-pact/index.js +6 -0
- package/dist/cjs/zod-to-pact/index.js.map +1 -0
- package/dist/cjs/zod-to-pact/zod-to-pact.d.ts +37 -0
- package/dist/cjs/zod-to-pact/zod-to-pact.d.ts.map +1 -0
- package/dist/cjs/zod-to-pact/zod-to-pact.js +151 -0
- package/dist/cjs/zod-to-pact/zod-to-pact.js.map +1 -0
- package/dist/esm/consumer-helpers/create-provider-state.d.ts +18 -0
- package/dist/esm/consumer-helpers/create-provider-state.d.ts.map +1 -0
- package/dist/esm/consumer-helpers/create-provider-state.js +18 -0
- package/dist/esm/consumer-helpers/create-provider-state.js.map +1 -0
- package/dist/esm/consumer-helpers/index.d.ts +6 -0
- package/dist/esm/consumer-helpers/index.d.ts.map +1 -0
- package/dist/esm/consumer-helpers/index.js +11 -0
- package/dist/esm/consumer-helpers/index.js.map +1 -0
- package/dist/esm/consumer-helpers/set-json-content.d.ts +32 -0
- package/dist/esm/consumer-helpers/set-json-content.d.ts.map +1 -0
- package/dist/esm/consumer-helpers/set-json-content.js +28 -0
- package/dist/esm/consumer-helpers/set-json-content.js.map +1 -0
- package/dist/esm/consumer-helpers/to-json-map.d.ts +13 -0
- package/dist/esm/consumer-helpers/to-json-map.d.ts.map +1 -0
- package/dist/esm/consumer-helpers/to-json-map.js +34 -0
- package/dist/esm/consumer-helpers/to-json-map.js.map +1 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +19 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/pact-types.d.ts +45 -0
- package/dist/esm/pact-types.d.ts.map +1 -0
- package/dist/esm/pact-types.js +11 -0
- package/dist/esm/pact-types.js.map +1 -0
- package/dist/esm/provider-verifier/build-verifier-options.d.ts +49 -0
- package/dist/esm/provider-verifier/build-verifier-options.d.ts.map +1 -0
- package/dist/esm/provider-verifier/build-verifier-options.js +113 -0
- package/dist/esm/provider-verifier/build-verifier-options.js.map +1 -0
- package/dist/esm/provider-verifier/handle-url-and-selectors.d.ts +18 -0
- package/dist/esm/provider-verifier/handle-url-and-selectors.d.ts.map +1 -0
- package/dist/esm/provider-verifier/handle-url-and-selectors.js +137 -0
- package/dist/esm/provider-verifier/handle-url-and-selectors.js.map +1 -0
- package/dist/esm/provider-verifier/index.d.ts +3 -0
- package/dist/esm/provider-verifier/index.d.ts.map +1 -0
- package/dist/esm/provider-verifier/index.js +10 -0
- package/dist/esm/provider-verifier/index.js.map +1 -0
- package/dist/esm/request-filter/create-request-filter.d.ts +19 -0
- package/dist/esm/request-filter/create-request-filter.d.ts.map +1 -0
- package/dist/esm/request-filter/create-request-filter.js +39 -0
- package/dist/esm/request-filter/create-request-filter.js.map +1 -0
- package/dist/esm/request-filter/index.d.ts +2 -0
- package/dist/esm/request-filter/index.d.ts.map +1 -0
- package/dist/esm/request-filter/index.js +7 -0
- package/dist/esm/request-filter/index.js.map +1 -0
- package/dist/esm/zod-to-pact/index.d.ts +2 -0
- package/dist/esm/zod-to-pact/index.d.ts.map +1 -0
- package/dist/esm/zod-to-pact/index.js +6 -0
- package/dist/esm/zod-to-pact/index.js.map +1 -0
- package/dist/esm/zod-to-pact/zod-to-pact.d.ts +37 -0
- package/dist/esm/zod-to-pact/zod-to-pact.d.ts.map +1 -0
- package/dist/esm/zod-to-pact/zod-to-pact.js +151 -0
- package/dist/esm/zod-to-pact/zod-to-pact.js.map +1 -0
- package/dist/types/consumer-helpers/create-provider-state.d.ts +18 -0
- package/dist/types/consumer-helpers/create-provider-state.d.ts.map +1 -0
- package/dist/types/consumer-helpers/index.d.ts +6 -0
- package/dist/types/consumer-helpers/index.d.ts.map +1 -0
- package/dist/types/consumer-helpers/set-json-content.d.ts +32 -0
- package/dist/types/consumer-helpers/set-json-content.d.ts.map +1 -0
- package/dist/types/consumer-helpers/to-json-map.d.ts +13 -0
- package/dist/types/consumer-helpers/to-json-map.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/pact-types.d.ts +45 -0
- package/dist/types/pact-types.d.ts.map +1 -0
- package/dist/types/provider-verifier/build-verifier-options.d.ts +49 -0
- package/dist/types/provider-verifier/build-verifier-options.d.ts.map +1 -0
- package/dist/types/provider-verifier/handle-url-and-selectors.d.ts +18 -0
- package/dist/types/provider-verifier/handle-url-and-selectors.d.ts.map +1 -0
- package/dist/types/provider-verifier/index.d.ts +3 -0
- package/dist/types/provider-verifier/index.d.ts.map +1 -0
- package/dist/types/request-filter/create-request-filter.d.ts +19 -0
- package/dist/types/request-filter/create-request-filter.d.ts.map +1 -0
- package/dist/types/request-filter/index.d.ts +2 -0
- package/dist/types/request-filter/index.d.ts.map +1 -0
- package/dist/types/zod-to-pact/index.d.ts +2 -0
- package/dist/types/zod-to-pact/index.d.ts.map +1 -0
- package/dist/types/zod-to-pact/zod-to-pact.d.ts +37 -0
- package/dist/types/zod-to-pact/zod-to-pact.d.ts.map +1 -0
- package/package.json +136 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/provider-verifier/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC5B,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,+BAA+B,EAC/B,sBAAsB,EACvB,MAAM,4BAA4B,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProviderVersionTags = exports.handlePactBrokerUrlAndSelectors = exports.buildMessageVerifierOptions = exports.buildVerifierOptions = void 0;
|
|
4
|
+
var build_verifier_options_1 = require("./build-verifier-options");
|
|
5
|
+
Object.defineProperty(exports, "buildVerifierOptions", { enumerable: true, get: function () { return build_verifier_options_1.buildVerifierOptions; } });
|
|
6
|
+
Object.defineProperty(exports, "buildMessageVerifierOptions", { enumerable: true, get: function () { return build_verifier_options_1.buildMessageVerifierOptions; } });
|
|
7
|
+
var handle_url_and_selectors_1 = require("./handle-url-and-selectors");
|
|
8
|
+
Object.defineProperty(exports, "handlePactBrokerUrlAndSelectors", { enumerable: true, get: function () { return handle_url_and_selectors_1.handlePactBrokerUrlAndSelectors; } });
|
|
9
|
+
Object.defineProperty(exports, "getProviderVersionTags", { enumerable: true, get: function () { return handle_url_and_selectors_1.getProviderVersionTags; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/provider-verifier/index.ts"],"names":[],"mappings":";;;AAAA,mEAGiC;AAF/B,8HAAA,oBAAoB,OAAA;AACpB,qIAAA,2BAA2B,OAAA;AAE7B,uEAGmC;AAFjC,2IAAA,+BAA+B,OAAA;AAC/B,kIAAA,sBAAsB,OAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RequestFilter } from '../pact-types';
|
|
2
|
+
type RequestFilterOptions = {
|
|
3
|
+
tokenGenerator?: () => string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Creates a request filter that adds an Authorization header if not present.
|
|
7
|
+
* Designed as a higher-order function to allow customization of token generation
|
|
8
|
+
* and to fulfill Pact's express-like type requirements (req, res, next).
|
|
9
|
+
*
|
|
10
|
+
* Bearer prefix contract: tokenGenerator returns raw value,
|
|
11
|
+
* createRequestFilter adds "Bearer " once.
|
|
12
|
+
*/
|
|
13
|
+
export declare const createRequestFilter: (options?: RequestFilterOptions) => RequestFilter;
|
|
14
|
+
/**
|
|
15
|
+
* A no-op request filter that passes the request through without modification.
|
|
16
|
+
*/
|
|
17
|
+
export declare const noOpRequestFilter: RequestFilter;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=create-request-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-request-filter.d.ts","sourceRoot":"","sources":["../../../src/request-filter/create-request-filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AASlD,KAAK,oBAAoB,GAAG;IAC1B,cAAc,CAAC,EAAE,MAAM,MAAM,CAAA;CAC9B,CAAA;AAiBD;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAC7B,UAAU,oBAAoB,KAAG,aAajC,CAAA;AAEH;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,aACH,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noOpRequestFilter = exports.createRequestFilter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Handles environments with and without Express-like `next()` middleware.
|
|
6
|
+
* If `next()` is present, it calls it; otherwise, it returns the modified request.
|
|
7
|
+
*/
|
|
8
|
+
const handleExpressEnv = (req, next) => {
|
|
9
|
+
if (next && typeof next === 'function') {
|
|
10
|
+
next();
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return req;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Creates a request filter that adds an Authorization header if not present.
|
|
18
|
+
* Designed as a higher-order function to allow customization of token generation
|
|
19
|
+
* and to fulfill Pact's express-like type requirements (req, res, next).
|
|
20
|
+
*
|
|
21
|
+
* Bearer prefix contract: tokenGenerator returns raw value,
|
|
22
|
+
* createRequestFilter adds "Bearer " once.
|
|
23
|
+
*/
|
|
24
|
+
const createRequestFilter = (options) => (req, _, next) => {
|
|
25
|
+
const defaultTokenGenerator = () => new Date().toISOString();
|
|
26
|
+
const tokenGenerator = options?.tokenGenerator || defaultTokenGenerator;
|
|
27
|
+
const hasAuth = Object.keys(req.headers).some((key) => key.toLowerCase() === 'authorization');
|
|
28
|
+
if (!hasAuth) {
|
|
29
|
+
req.headers['authorization'] = `Bearer ${tokenGenerator()}`;
|
|
30
|
+
}
|
|
31
|
+
return handleExpressEnv(req, next);
|
|
32
|
+
};
|
|
33
|
+
exports.createRequestFilter = createRequestFilter;
|
|
34
|
+
/**
|
|
35
|
+
* A no-op request filter that passes the request through without modification.
|
|
36
|
+
*/
|
|
37
|
+
const noOpRequestFilter = (req, _, next) => handleExpressEnv(req, next);
|
|
38
|
+
exports.noOpRequestFilter = noOpRequestFilter;
|
|
39
|
+
//# sourceMappingURL=create-request-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-request-filter.js","sourceRoot":"","sources":["../../../src/request-filter/create-request-filter.ts"],"names":[],"mappings":";;;AAaA;;;GAGG;AACH,MAAM,gBAAgB,GAAG,CACvB,GAAgB,EAChB,IAAkB,EACO,EAAE;IAC3B,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;QACvC,IAAI,EAAE,CAAA;IACR,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,CAAA;IACZ,CAAC;AACH,CAAC,CAAA;AAED;;;;;;;GAOG;AACI,MAAM,mBAAmB,GAC9B,CAAC,OAA8B,EAAiB,EAAE,CAClD,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;IACf,MAAM,qBAAqB,GAAG,GAAW,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACpE,MAAM,cAAc,GAAG,OAAO,EAAE,cAAc,IAAI,qBAAqB,CAAA;IAEvE,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAC3C,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,eAAe,CAC/C,CAAA;IACD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,cAAc,EAAE,EAAE,CAAA;IAC7D,CAAC;IAED,OAAO,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;AACpC,CAAC,CAAA;AAdU,QAAA,mBAAmB,uBAc7B;AAEH;;GAEG;AACI,MAAM,iBAAiB,GAAkB,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,CAC/D,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;AADhB,QAAA,iBAAiB,qBACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/request-filter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noOpRequestFilter = exports.createRequestFilter = void 0;
|
|
4
|
+
var create_request_filter_1 = require("./create-request-filter");
|
|
5
|
+
Object.defineProperty(exports, "createRequestFilter", { enumerable: true, get: function () { return create_request_filter_1.createRequestFilter; } });
|
|
6
|
+
Object.defineProperty(exports, "noOpRequestFilter", { enumerable: true, get: function () { return create_request_filter_1.noOpRequestFilter; } });
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/request-filter/index.ts"],"names":[],"mappings":";;;AAAA,iEAAgF;AAAvE,4HAAA,mBAAmB,OAAA;AAAE,0HAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/zod-to-pact/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.zodToPactMatchers = void 0;
|
|
4
|
+
var zod_to_pact_1 = require("./zod-to-pact");
|
|
5
|
+
Object.defineProperty(exports, "zodToPactMatchers", { enumerable: true, get: function () { return zod_to_pact_1.zodToPactMatchers; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/zod-to-pact/index.ts"],"names":[],"mappings":";;;AAAA,6CAAiD;AAAxC,gHAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a Zod schema into Pact V3 matchers.
|
|
4
|
+
*
|
|
5
|
+
* Each Zod type maps to the appropriate Pact matcher: `z.string()` → `string()`,
|
|
6
|
+
* `z.number().int()` → `integer()`, `z.number()` → `decimal()`, etc.
|
|
7
|
+
* Nested objects and arrays are handled recursively.
|
|
8
|
+
*
|
|
9
|
+
* Example values are resolved in priority order:
|
|
10
|
+
* 1. The `example` argument (takes precedence)
|
|
11
|
+
* 2. `.openapi({ example: ... })` metadata on the schema field
|
|
12
|
+
* 3. A type-appropriate default (`'string'`, `1.0`, `true`)
|
|
13
|
+
*
|
|
14
|
+
* Intended for use with consumer-curated schemas — schemas that describe only
|
|
15
|
+
* the fields the consumer actually reads. Passing a shared full-response schema
|
|
16
|
+
* risks turning contract tests into schema tests (see Pact docs on consumer-driven contracts).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // pact/http/helpers/consumer-schemas.ts
|
|
20
|
+
* export const ConsumerMovieSchema = z.object({
|
|
21
|
+
* id: z.number().int(),
|
|
22
|
+
* name: z.string(),
|
|
23
|
+
* year: z.number().int(),
|
|
24
|
+
* rating: z.number(),
|
|
25
|
+
* director: z.string()
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* // pact/http/consumer/movies-read.pacttest.ts
|
|
29
|
+
* import { zodToPactMatchers } from '@seontechnologies/pactjs-utils'
|
|
30
|
+
* import { ConsumerMovieSchema } from '../helpers/consumer-schemas'
|
|
31
|
+
*
|
|
32
|
+
* const movie = { id: 1, name: 'My movie', year: 1999, rating: 8.5, director: 'John Doe' }
|
|
33
|
+
* data: zodToPactMatchers(ConsumerMovieSchema, movie)
|
|
34
|
+
* // { id: integer(1), name: string('My movie'), year: integer(1999), rating: decimal(8.5), director: string('John Doe') }
|
|
35
|
+
*/
|
|
36
|
+
export declare const zodToPactMatchers: (schema: z.ZodTypeAny, example?: unknown) => unknown;
|
|
37
|
+
//# sourceMappingURL=zod-to-pact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-to-pact.d.ts","sourceRoot":"","sources":["../../../src/zod-to-pact/zod-to-pact.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AA+H5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,CAAC,CAAC,UAAU,EACpB,UAAU,OAAO,KAChB,OAMF,CAAA"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.zodToPactMatchers = void 0;
|
|
4
|
+
const pact_1 = require("@pact-foundation/pact");
|
|
5
|
+
// Lazily resolve getOpenApiMetadata from @asteasolutions/zod-to-openapi if present.
|
|
6
|
+
// The library treats it as optional — openapi example extraction silently skips when unavailable.
|
|
7
|
+
let _getOpenApiMetadata = null;
|
|
8
|
+
try {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
10
|
+
const mod = require('@asteasolutions/zod-to-openapi');
|
|
11
|
+
_getOpenApiMetadata = mod.getOpenApiMetadata;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
// optional peer — openapi example extraction disabled
|
|
15
|
+
}
|
|
16
|
+
const getOpenApiExample = (schema) => {
|
|
17
|
+
try {
|
|
18
|
+
return _getOpenApiMetadata?.(schema)?.example;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const resolveExample = (schema, provided) => provided !== undefined ? provided : getOpenApiExample(schema);
|
|
25
|
+
const def = (schema) => schema.def;
|
|
26
|
+
const isIntegerCheck = (d) => {
|
|
27
|
+
const checks = d.checks ?? [];
|
|
28
|
+
return checks.some((c) => c.isInt === true || c.format === 'safeint');
|
|
29
|
+
};
|
|
30
|
+
const matchString = (schema, example) => {
|
|
31
|
+
const ex = resolveExample(schema, example);
|
|
32
|
+
return pact_1.MatchersV3.string(typeof ex === 'string' ? ex : 'string');
|
|
33
|
+
};
|
|
34
|
+
const matchNumber = (schema, example) => {
|
|
35
|
+
const d = def(schema);
|
|
36
|
+
const ex = resolveExample(schema, example);
|
|
37
|
+
const numEx = typeof ex === 'number' ? ex : undefined;
|
|
38
|
+
return d.type === 'int' || isIntegerCheck(d)
|
|
39
|
+
? pact_1.MatchersV3.integer(numEx)
|
|
40
|
+
: pact_1.MatchersV3.decimal(numEx ?? 1.0);
|
|
41
|
+
};
|
|
42
|
+
const matchBoolean = (schema, example) => {
|
|
43
|
+
const ex = resolveExample(schema, example);
|
|
44
|
+
return pact_1.MatchersV3.boolean(typeof ex === 'boolean' ? ex : true);
|
|
45
|
+
};
|
|
46
|
+
const matchWrapper = (schema, example) => {
|
|
47
|
+
const inner = def(schema).innerType;
|
|
48
|
+
return (0, exports.zodToPactMatchers)(inner, example);
|
|
49
|
+
};
|
|
50
|
+
const matchObject = (schema, example) => {
|
|
51
|
+
const shape = schema.shape;
|
|
52
|
+
const exObj = typeof example === 'object' && example !== null
|
|
53
|
+
? example
|
|
54
|
+
: {};
|
|
55
|
+
return Object.fromEntries(Object.entries(shape).map(([key, fieldSchema]) => [
|
|
56
|
+
key,
|
|
57
|
+
(0, exports.zodToPactMatchers)(fieldSchema, exObj[key])
|
|
58
|
+
]));
|
|
59
|
+
};
|
|
60
|
+
const matchArray = (schema, example) => {
|
|
61
|
+
const d = def(schema);
|
|
62
|
+
const itemSchema = (d.element ?? d.type);
|
|
63
|
+
if (!itemSchema)
|
|
64
|
+
return pact_1.MatchersV3.like(example ?? null);
|
|
65
|
+
const firstItem = Array.isArray(example) && example.length > 0 ? example[0] : undefined;
|
|
66
|
+
return pact_1.MatchersV3.eachLike((0, exports.zodToPactMatchers)(itemSchema, firstItem));
|
|
67
|
+
};
|
|
68
|
+
const matchUnion = (schema, example) => {
|
|
69
|
+
const options = def(schema).options;
|
|
70
|
+
return (0, exports.zodToPactMatchers)(options[0], example);
|
|
71
|
+
};
|
|
72
|
+
const matchLiteral = (schema) => {
|
|
73
|
+
const d = def(schema);
|
|
74
|
+
const val = Array.isArray(d.values)
|
|
75
|
+
? d.values[0]
|
|
76
|
+
: d.value;
|
|
77
|
+
if (typeof val === 'string')
|
|
78
|
+
return pact_1.MatchersV3.string(val);
|
|
79
|
+
if (typeof val === 'number')
|
|
80
|
+
return Number.isInteger(val)
|
|
81
|
+
? pact_1.MatchersV3.integer(val)
|
|
82
|
+
: pact_1.MatchersV3.decimal(val);
|
|
83
|
+
if (typeof val === 'boolean')
|
|
84
|
+
return pact_1.MatchersV3.boolean(val);
|
|
85
|
+
return pact_1.MatchersV3.like(val);
|
|
86
|
+
};
|
|
87
|
+
const matchEnum = (schema) => {
|
|
88
|
+
const d = def(schema);
|
|
89
|
+
const firstValue = Array.isArray(d.values)
|
|
90
|
+
? d.values[0]
|
|
91
|
+
: Object.keys(d.entries)[0];
|
|
92
|
+
return pact_1.MatchersV3.string(firstValue);
|
|
93
|
+
};
|
|
94
|
+
const matchers = {
|
|
95
|
+
string: matchString,
|
|
96
|
+
number: matchNumber,
|
|
97
|
+
int: matchNumber,
|
|
98
|
+
boolean: matchBoolean,
|
|
99
|
+
null: () => pact_1.MatchersV3.nullValue(),
|
|
100
|
+
optional: matchWrapper,
|
|
101
|
+
nullable: matchWrapper,
|
|
102
|
+
default: matchWrapper,
|
|
103
|
+
object: matchObject,
|
|
104
|
+
array: matchArray,
|
|
105
|
+
union: matchUnion,
|
|
106
|
+
literal: matchLiteral,
|
|
107
|
+
enum: matchEnum
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Converts a Zod schema into Pact V3 matchers.
|
|
111
|
+
*
|
|
112
|
+
* Each Zod type maps to the appropriate Pact matcher: `z.string()` → `string()`,
|
|
113
|
+
* `z.number().int()` → `integer()`, `z.number()` → `decimal()`, etc.
|
|
114
|
+
* Nested objects and arrays are handled recursively.
|
|
115
|
+
*
|
|
116
|
+
* Example values are resolved in priority order:
|
|
117
|
+
* 1. The `example` argument (takes precedence)
|
|
118
|
+
* 2. `.openapi({ example: ... })` metadata on the schema field
|
|
119
|
+
* 3. A type-appropriate default (`'string'`, `1.0`, `true`)
|
|
120
|
+
*
|
|
121
|
+
* Intended for use with consumer-curated schemas — schemas that describe only
|
|
122
|
+
* the fields the consumer actually reads. Passing a shared full-response schema
|
|
123
|
+
* risks turning contract tests into schema tests (see Pact docs on consumer-driven contracts).
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* // pact/http/helpers/consumer-schemas.ts
|
|
127
|
+
* export const ConsumerMovieSchema = z.object({
|
|
128
|
+
* id: z.number().int(),
|
|
129
|
+
* name: z.string(),
|
|
130
|
+
* year: z.number().int(),
|
|
131
|
+
* rating: z.number(),
|
|
132
|
+
* director: z.string()
|
|
133
|
+
* })
|
|
134
|
+
*
|
|
135
|
+
* // pact/http/consumer/movies-read.pacttest.ts
|
|
136
|
+
* import { zodToPactMatchers } from '@seontechnologies/pactjs-utils'
|
|
137
|
+
* import { ConsumerMovieSchema } from '../helpers/consumer-schemas'
|
|
138
|
+
*
|
|
139
|
+
* const movie = { id: 1, name: 'My movie', year: 1999, rating: 8.5, director: 'John Doe' }
|
|
140
|
+
* data: zodToPactMatchers(ConsumerMovieSchema, movie)
|
|
141
|
+
* // { id: integer(1), name: string('My movie'), year: integer(1999), rating: decimal(8.5), director: string('John Doe') }
|
|
142
|
+
*/
|
|
143
|
+
const zodToPactMatchers = (schema, example) => {
|
|
144
|
+
const typeName = schema.type;
|
|
145
|
+
const matcher = matchers[typeName];
|
|
146
|
+
return matcher
|
|
147
|
+
? matcher(schema, example)
|
|
148
|
+
: pact_1.MatchersV3.like(resolveExample(schema, example) ?? null);
|
|
149
|
+
};
|
|
150
|
+
exports.zodToPactMatchers = zodToPactMatchers;
|
|
151
|
+
//# sourceMappingURL=zod-to-pact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-to-pact.js","sourceRoot":"","sources":["../../../src/zod-to-pact/zod-to-pact.ts"],"names":[],"mappings":";;;AAAA,gDAAkD;AAMlD,oFAAoF;AACpF,kGAAkG;AAClG,IAAI,mBAAmB,GACrB,IAAI,CAAA;AACN,IAAI,CAAC;IACH,iEAAiE;IACjE,MAAM,GAAG,GAAG,OAAO,CAAC,gC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AED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACI,MAAM,iBAAiB,GAAG,CAC/B,MAAoB,EACpB,OAAiB,EACR,EAAE;IACX,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAc,CAAA;IACtC,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAClC,OAAO,OAAO;QACZ,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC;QAC1B,CAAC,CAAC,iBAAU,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,CAAA;AAC9D,CAAC,CAAA;AATY,QAAA,iBAAiB,qBAS7B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { JsonMap } from '../pact-types';
|
|
2
|
+
export type ProviderStateInput = {
|
|
3
|
+
name: string;
|
|
4
|
+
params: Record<string, unknown>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Creates a tuple representing a provider state for use with Pact.
|
|
8
|
+
* Converts the parameters into a JsonMap where all values are Pact-compatible.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const state = createProviderState({
|
|
12
|
+
* name: 'An existing movie exists',
|
|
13
|
+
* params: { name: 'Inception', year: 2010 }
|
|
14
|
+
* })
|
|
15
|
+
* provider.given(...state)
|
|
16
|
+
*/
|
|
17
|
+
export declare const createProviderState: ({ name, params }: ProviderStateInput) => [string, JsonMap];
|
|
18
|
+
//# sourceMappingURL=create-provider-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-provider-state.d.ts","sourceRoot":"","sources":["../../../src/consumer-helpers/create-provider-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAG5C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAChC,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAAI,kBAGjC,kBAAkB,KAAG,CAAC,MAAM,EAAE,OAAO,CAA8B,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createProviderState = void 0;
|
|
4
|
+
const to_json_map_1 = require("./to-json-map");
|
|
5
|
+
/**
|
|
6
|
+
* Creates a tuple representing a provider state for use with Pact.
|
|
7
|
+
* Converts the parameters into a JsonMap where all values are Pact-compatible.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const state = createProviderState({
|
|
11
|
+
* name: 'An existing movie exists',
|
|
12
|
+
* params: { name: 'Inception', year: 2010 }
|
|
13
|
+
* })
|
|
14
|
+
* provider.given(...state)
|
|
15
|
+
*/
|
|
16
|
+
const createProviderState = ({ name, params }) => [name, (0, to_json_map_1.toJsonMap)(params)];
|
|
17
|
+
exports.createProviderState = createProviderState;
|
|
18
|
+
//# sourceMappingURL=create-provider-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-provider-state.js","sourceRoot":"","sources":["../../../src/consumer-helpers/create-provider-state.ts"],"names":[],"mappings":";;;AACA,+CAAyC;AAOzC;;;;;;;;;;GAUG;AACI,MAAM,mBAAmB,GAAG,CAAC,EAClC,IAAI,EACJ,MAAM,EACa,EAAqB,EAAE,CAAC,CAAC,IAAI,EAAE,IAAA,uBAAS,EAAC,MAAM,CAAC,CAAC,CAAA;AAHzD,QAAA,mBAAmB,uBAGsC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { toJsonMap } from './to-json-map';
|
|
2
|
+
export { createProviderState } from './create-provider-state';
|
|
3
|
+
export type { ProviderStateInput } from './create-provider-state';
|
|
4
|
+
export { setJsonContent, setJsonBody } from './set-json-content';
|
|
5
|
+
export type { JsonContentInput } from './set-json-content';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/consumer-helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,YAAY,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChE,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setJsonBody = exports.setJsonContent = exports.createProviderState = exports.toJsonMap = void 0;
|
|
4
|
+
var to_json_map_1 = require("./to-json-map");
|
|
5
|
+
Object.defineProperty(exports, "toJsonMap", { enumerable: true, get: function () { return to_json_map_1.toJsonMap; } });
|
|
6
|
+
var create_provider_state_1 = require("./create-provider-state");
|
|
7
|
+
Object.defineProperty(exports, "createProviderState", { enumerable: true, get: function () { return create_provider_state_1.createProviderState; } });
|
|
8
|
+
var set_json_content_1 = require("./set-json-content");
|
|
9
|
+
Object.defineProperty(exports, "setJsonContent", { enumerable: true, get: function () { return set_json_content_1.setJsonContent; } });
|
|
10
|
+
Object.defineProperty(exports, "setJsonBody", { enumerable: true, get: function () { return set_json_content_1.setJsonBody; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/consumer-helpers/index.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AAAhC,wGAAA,SAAS,OAAA;AAClB,iEAA6D;AAApD,4HAAA,mBAAmB,OAAA;AAE5B,uDAAgE;AAAvD,kHAAA,cAAc,OAAA;AAAE,+GAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Matcher } from '@pact-foundation/pact';
|
|
2
|
+
/**
|
|
3
|
+
* Local aliases for Pact template structures.
|
|
4
|
+
* We intentionally avoid deep imports from @pact-foundation/pact internals.
|
|
5
|
+
* Shapes mirror the public Pact v3 template contracts for v4 HTTP builders.
|
|
6
|
+
*/
|
|
7
|
+
type PactTemplateHeaders = Record<string, string | Matcher<string> | Array<string | Matcher<string>>>;
|
|
8
|
+
type PactTemplateQuery = Record<string, string | Matcher<string | number | boolean> | Array<string | Matcher<string | number | boolean>>>;
|
|
9
|
+
type JsonContentBuilder = {
|
|
10
|
+
headers: (headers: PactTemplateHeaders) => unknown;
|
|
11
|
+
jsonBody: (body: unknown) => unknown;
|
|
12
|
+
query?: (query: PactTemplateQuery) => unknown;
|
|
13
|
+
};
|
|
14
|
+
export type JsonContentInput = {
|
|
15
|
+
body?: unknown;
|
|
16
|
+
headers?: PactTemplateHeaders;
|
|
17
|
+
query?: PactTemplateQuery;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Curried Pact builder helper for request/response JSON interactions.
|
|
21
|
+
*
|
|
22
|
+
* Supports query + headers + JSON body in one reusable function.
|
|
23
|
+
* - Request builders apply `query`, `headers`, and `body`
|
|
24
|
+
* - Response builders apply `headers` and `body` (ignore `query`)
|
|
25
|
+
*/
|
|
26
|
+
export declare const setJsonContent: ({ body, headers, query }: JsonContentInput) => (builder: JsonContentBuilder) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Backward-compatible convenience alias for body-only usage.
|
|
29
|
+
*/
|
|
30
|
+
export declare const setJsonBody: (body: unknown) => (builder: JsonContentBuilder) => void;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=set-json-content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-json-content.d.ts","sourceRoot":"","sources":["../../../src/consumer-helpers/set-json-content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD;;;;GAIG;AACH,KAAK,mBAAmB,GAAG,MAAM,CAC/B,MAAM,EACN,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAC3D,CAAA;AAED,KAAK,iBAAiB,GAAG,MAAM,CAC7B,MAAM,EACJ,MAAM,GACN,OAAO,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAClC,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,CACrD,CAAA;AAED,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,OAAO,CAAA;IAClD,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAA;IACpC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,OAAO,CAAA;CAC9C,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,OAAO,CAAC,EAAE,mBAAmB,CAAA;IAC7B,KAAK,CAAC,EAAE,iBAAiB,CAAA;CAC1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GACxB,0BAA0B,gBAAgB,MAC1C,SAAS,kBAAkB,KAAG,IAY9B,CAAA;AAEH;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,OAAO,eAjB7B,kBAAkB,KAAG,IAiBqC,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setJsonBody = exports.setJsonContent = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Curried Pact builder helper for request/response JSON interactions.
|
|
6
|
+
*
|
|
7
|
+
* Supports query + headers + JSON body in one reusable function.
|
|
8
|
+
* - Request builders apply `query`, `headers`, and `body`
|
|
9
|
+
* - Response builders apply `headers` and `body` (ignore `query`)
|
|
10
|
+
*/
|
|
11
|
+
const setJsonContent = ({ body, headers, query }) => (builder) => {
|
|
12
|
+
if (query && builder.query) {
|
|
13
|
+
builder.query(query);
|
|
14
|
+
}
|
|
15
|
+
if (headers) {
|
|
16
|
+
builder.headers(headers);
|
|
17
|
+
}
|
|
18
|
+
if (body !== undefined) {
|
|
19
|
+
builder.jsonBody(body);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.setJsonContent = setJsonContent;
|
|
23
|
+
/**
|
|
24
|
+
* Backward-compatible convenience alias for body-only usage.
|
|
25
|
+
*/
|
|
26
|
+
const setJsonBody = (body) => (0, exports.setJsonContent)({ body });
|
|
27
|
+
exports.setJsonBody = setJsonBody;
|
|
28
|
+
//# sourceMappingURL=set-json-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-json-content.js","sourceRoot":"","sources":["../../../src/consumer-helpers/set-json-content.ts"],"names":[],"mappings":";;;AA+BA;;;;;;GAMG;AACI,MAAM,cAAc,GACzB,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAoB,EAAE,EAAE,CAC/C,CAAC,OAA2B,EAAQ,EAAE;IACpC,IAAI,KAAK,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAC3B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC;IAED,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;IAED,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACxB,CAAC;AACH,CAAC,CAAA;AAdU,QAAA,cAAc,kBAcxB;AAEH;;GAEG;AACI,MAAM,WAAW,GAAG,CAAC,IAAa,EAAE,EAAE,CAAC,IAAA,sBAAc,EAAC,EAAE,IAAI,EAAE,CAAC,CAAA;AAAzD,QAAA,WAAW,eAA8C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { JsonMap } from '../pact-types';
|
|
2
|
+
/**
|
|
3
|
+
* Converts an object with arbitrary value types to a `JsonMap` where all values are compatible with Pact's expectations.
|
|
4
|
+
*
|
|
5
|
+
* Handles various data types:
|
|
6
|
+
* - `null` and `undefined`: Converted to the string `"null"`.
|
|
7
|
+
* - `object`: Serialized using `JSON.stringify` unless it's a Date or Array.
|
|
8
|
+
* - `number` and `boolean`: Preserved as is.
|
|
9
|
+
* - `Date`: Converted to an ISO string format.
|
|
10
|
+
* - `Array`: Converted to a comma-separated string via `String()`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const toJsonMap: (obj: Record<string, unknown>) => JsonMap;
|
|
13
|
+
//# sourceMappingURL=to-json-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-json-map.d.ts","sourceRoot":"","sources":["../../../src/consumer-helpers/to-json-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,OAmBtD,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toJsonMap = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Converts an object with arbitrary value types to a `JsonMap` where all values are compatible with Pact's expectations.
|
|
6
|
+
*
|
|
7
|
+
* Handles various data types:
|
|
8
|
+
* - `null` and `undefined`: Converted to the string `"null"`.
|
|
9
|
+
* - `object`: Serialized using `JSON.stringify` unless it's a Date or Array.
|
|
10
|
+
* - `number` and `boolean`: Preserved as is.
|
|
11
|
+
* - `Date`: Converted to an ISO string format.
|
|
12
|
+
* - `Array`: Converted to a comma-separated string via `String()`.
|
|
13
|
+
*/
|
|
14
|
+
const toJsonMap = (obj) => Object.fromEntries(Object.entries(obj).map(([key, value]) => {
|
|
15
|
+
if (value === null || value === undefined) {
|
|
16
|
+
return [key, 'null'];
|
|
17
|
+
}
|
|
18
|
+
else if (typeof value === 'object' &&
|
|
19
|
+
!(value instanceof Date) &&
|
|
20
|
+
!Array.isArray(value)) {
|
|
21
|
+
return [key, JSON.stringify(value)];
|
|
22
|
+
}
|
|
23
|
+
else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
24
|
+
return [key, value];
|
|
25
|
+
}
|
|
26
|
+
else if (value instanceof Date) {
|
|
27
|
+
return [key, value.toISOString()];
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return [key, String(value)];
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
exports.toJsonMap = toJsonMap;
|
|
34
|
+
//# sourceMappingURL=to-json-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-json-map.js","sourceRoot":"","sources":["../../../src/consumer-helpers/to-json-map.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;GASG;AACI,MAAM,SAAS,GAAG,CAAC,GAA4B,EAAW,EAAE,CACjE,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;IACvC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IACtB,CAAC;SAAM,IACL,OAAO,KAAK,KAAK,QAAQ;QACzB,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC;QACxB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EACrB,CAAC;QACD,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;IACrC,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QACnE,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IACrB,CAAC;SAAM,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QACjC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,CAAA;IACnC,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAC7B,CAAC;AACH,CAAC,CAAC,CACH,CAAA;AAnBU,QAAA,SAAS,aAmBnB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createProviderState, toJsonMap, setJsonContent, setJsonBody } from './consumer-helpers';
|
|
2
|
+
export type { ProviderStateInput, JsonContentInput } from './consumer-helpers';
|
|
3
|
+
export { createRequestFilter, noOpRequestFilter } from './request-filter';
|
|
4
|
+
export { buildVerifierOptions, buildMessageVerifierOptions, handlePactBrokerUrlAndSelectors, getProviderVersionTags } from './provider-verifier';
|
|
5
|
+
export type { StateHandlers, StateHandler, StateFunc, StateFuncWithSetup, RequestFilter, JsonMap, AnyJson, JsonArray, ConsumerVersionSelector } from './pact-types';
|
|
6
|
+
export { zodToPactMatchers } from './zod-to-pact';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,cAAc,EACd,WAAW,EACZ,MAAM,oBAAoB,CAAA;AAC3B,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC9E,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACzE,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,+BAA+B,EAC/B,sBAAsB,EACvB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EACV,aAAa,EACb,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,aAAa,EACb,OAAO,EACP,OAAO,EACP,SAAS,EACT,uBAAuB,EACxB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.zodToPactMatchers = exports.getProviderVersionTags = exports.handlePactBrokerUrlAndSelectors = exports.buildMessageVerifierOptions = exports.buildVerifierOptions = exports.noOpRequestFilter = exports.createRequestFilter = exports.setJsonBody = exports.setJsonContent = exports.toJsonMap = exports.createProviderState = void 0;
|
|
4
|
+
var consumer_helpers_1 = require("./consumer-helpers");
|
|
5
|
+
Object.defineProperty(exports, "createProviderState", { enumerable: true, get: function () { return consumer_helpers_1.createProviderState; } });
|
|
6
|
+
Object.defineProperty(exports, "toJsonMap", { enumerable: true, get: function () { return consumer_helpers_1.toJsonMap; } });
|
|
7
|
+
Object.defineProperty(exports, "setJsonContent", { enumerable: true, get: function () { return consumer_helpers_1.setJsonContent; } });
|
|
8
|
+
Object.defineProperty(exports, "setJsonBody", { enumerable: true, get: function () { return consumer_helpers_1.setJsonBody; } });
|
|
9
|
+
var request_filter_1 = require("./request-filter");
|
|
10
|
+
Object.defineProperty(exports, "createRequestFilter", { enumerable: true, get: function () { return request_filter_1.createRequestFilter; } });
|
|
11
|
+
Object.defineProperty(exports, "noOpRequestFilter", { enumerable: true, get: function () { return request_filter_1.noOpRequestFilter; } });
|
|
12
|
+
var provider_verifier_1 = require("./provider-verifier");
|
|
13
|
+
Object.defineProperty(exports, "buildVerifierOptions", { enumerable: true, get: function () { return provider_verifier_1.buildVerifierOptions; } });
|
|
14
|
+
Object.defineProperty(exports, "buildMessageVerifierOptions", { enumerable: true, get: function () { return provider_verifier_1.buildMessageVerifierOptions; } });
|
|
15
|
+
Object.defineProperty(exports, "handlePactBrokerUrlAndSelectors", { enumerable: true, get: function () { return provider_verifier_1.handlePactBrokerUrlAndSelectors; } });
|
|
16
|
+
Object.defineProperty(exports, "getProviderVersionTags", { enumerable: true, get: function () { return provider_verifier_1.getProviderVersionTags; } });
|
|
17
|
+
var zod_to_pact_1 = require("./zod-to-pact");
|
|
18
|
+
Object.defineProperty(exports, "zodToPactMatchers", { enumerable: true, get: function () { return zod_to_pact_1.zodToPactMatchers; } });
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAK2B;AAJzB,uHAAA,mBAAmB,OAAA;AACnB,6GAAA,SAAS,OAAA;AACT,kHAAA,cAAc,OAAA;AACd,+GAAA,WAAW,OAAA;AAGb,mDAAyE;AAAhE,qHAAA,mBAAmB,OAAA;AAAE,mHAAA,iBAAiB,OAAA;AAC/C,yDAK4B;AAJ1B,yHAAA,oBAAoB,OAAA;AACpB,gIAAA,2BAA2B,OAAA;AAC3B,oIAAA,+BAA+B,OAAA;AAC/B,2HAAA,sBAAsB,OAAA;AAaxB,6CAAiD;AAAxC,gHAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local type definitions for @pact-foundation/pact internal types
|
|
3
|
+
* that are not re-exported from the main package entry point.
|
|
4
|
+
*
|
|
5
|
+
* These mirror the types from:
|
|
6
|
+
* - @pact-foundation/pact/src/common/jsonTypes
|
|
7
|
+
* - @pact-foundation/pact/src/dsl/verifier/proxy/types
|
|
8
|
+
*/
|
|
9
|
+
export type AnyJson = boolean | number | string | null | JsonArray | JsonMap;
|
|
10
|
+
export type JsonArray = Array<AnyJson>;
|
|
11
|
+
export type JsonMap = {
|
|
12
|
+
[key: string]: AnyJson;
|
|
13
|
+
};
|
|
14
|
+
export type StateFunc = (parameters?: AnyJson) => Promise<JsonMap | void>;
|
|
15
|
+
export type StateFuncWithSetup = {
|
|
16
|
+
setup?: StateFunc;
|
|
17
|
+
teardown?: StateFunc;
|
|
18
|
+
};
|
|
19
|
+
export type StateHandler = StateFuncWithSetup | StateFunc;
|
|
20
|
+
export type StateHandlers = {
|
|
21
|
+
[name: string]: StateHandler;
|
|
22
|
+
};
|
|
23
|
+
export type RequestFilter = (req: {
|
|
24
|
+
headers: Record<string, string | string[] | undefined>;
|
|
25
|
+
body?: unknown;
|
|
26
|
+
}, res: unknown, next: () => void | undefined) => unknown;
|
|
27
|
+
/**
|
|
28
|
+
* Locally defined type matching the shape of ConsumerVersionSelector
|
|
29
|
+
* from @pact-foundation/pact-core/src/verifier/types.
|
|
30
|
+
* Defined here to avoid deep internal imports that could break with pact updates.
|
|
31
|
+
*/
|
|
32
|
+
export type ConsumerVersionSelector = {
|
|
33
|
+
mainBranch?: boolean;
|
|
34
|
+
matchingBranch?: boolean;
|
|
35
|
+
deployedOrReleased?: boolean;
|
|
36
|
+
deployed?: boolean;
|
|
37
|
+
released?: boolean;
|
|
38
|
+
consumer?: string;
|
|
39
|
+
branch?: string;
|
|
40
|
+
tag?: string;
|
|
41
|
+
latest?: boolean;
|
|
42
|
+
fallbackTag?: string;
|
|
43
|
+
fallbackBranch?: string;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=pact-types.d.ts.map
|