@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.
Files changed (133) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +463 -0
  3. package/dist/cjs/consumer-helpers/create-provider-state.d.ts +18 -0
  4. package/dist/cjs/consumer-helpers/create-provider-state.d.ts.map +1 -0
  5. package/dist/cjs/consumer-helpers/create-provider-state.js +18 -0
  6. package/dist/cjs/consumer-helpers/create-provider-state.js.map +1 -0
  7. package/dist/cjs/consumer-helpers/index.d.ts +6 -0
  8. package/dist/cjs/consumer-helpers/index.d.ts.map +1 -0
  9. package/dist/cjs/consumer-helpers/index.js +11 -0
  10. package/dist/cjs/consumer-helpers/index.js.map +1 -0
  11. package/dist/cjs/consumer-helpers/set-json-content.d.ts +32 -0
  12. package/dist/cjs/consumer-helpers/set-json-content.d.ts.map +1 -0
  13. package/dist/cjs/consumer-helpers/set-json-content.js +28 -0
  14. package/dist/cjs/consumer-helpers/set-json-content.js.map +1 -0
  15. package/dist/cjs/consumer-helpers/to-json-map.d.ts +13 -0
  16. package/dist/cjs/consumer-helpers/to-json-map.d.ts.map +1 -0
  17. package/dist/cjs/consumer-helpers/to-json-map.js +34 -0
  18. package/dist/cjs/consumer-helpers/to-json-map.js.map +1 -0
  19. package/dist/cjs/index.d.ts +7 -0
  20. package/dist/cjs/index.d.ts.map +1 -0
  21. package/dist/cjs/index.js +19 -0
  22. package/dist/cjs/index.js.map +1 -0
  23. package/dist/cjs/pact-types.d.ts +45 -0
  24. package/dist/cjs/pact-types.d.ts.map +1 -0
  25. package/dist/cjs/pact-types.js +11 -0
  26. package/dist/cjs/pact-types.js.map +1 -0
  27. package/dist/cjs/provider-verifier/build-verifier-options.d.ts +49 -0
  28. package/dist/cjs/provider-verifier/build-verifier-options.d.ts.map +1 -0
  29. package/dist/cjs/provider-verifier/build-verifier-options.js +113 -0
  30. package/dist/cjs/provider-verifier/build-verifier-options.js.map +1 -0
  31. package/dist/cjs/provider-verifier/handle-url-and-selectors.d.ts +18 -0
  32. package/dist/cjs/provider-verifier/handle-url-and-selectors.d.ts.map +1 -0
  33. package/dist/cjs/provider-verifier/handle-url-and-selectors.js +137 -0
  34. package/dist/cjs/provider-verifier/handle-url-and-selectors.js.map +1 -0
  35. package/dist/cjs/provider-verifier/index.d.ts +3 -0
  36. package/dist/cjs/provider-verifier/index.d.ts.map +1 -0
  37. package/dist/cjs/provider-verifier/index.js +10 -0
  38. package/dist/cjs/provider-verifier/index.js.map +1 -0
  39. package/dist/cjs/request-filter/create-request-filter.d.ts +19 -0
  40. package/dist/cjs/request-filter/create-request-filter.d.ts.map +1 -0
  41. package/dist/cjs/request-filter/create-request-filter.js +39 -0
  42. package/dist/cjs/request-filter/create-request-filter.js.map +1 -0
  43. package/dist/cjs/request-filter/index.d.ts +2 -0
  44. package/dist/cjs/request-filter/index.d.ts.map +1 -0
  45. package/dist/cjs/request-filter/index.js +7 -0
  46. package/dist/cjs/request-filter/index.js.map +1 -0
  47. package/dist/cjs/zod-to-pact/index.d.ts +2 -0
  48. package/dist/cjs/zod-to-pact/index.d.ts.map +1 -0
  49. package/dist/cjs/zod-to-pact/index.js +6 -0
  50. package/dist/cjs/zod-to-pact/index.js.map +1 -0
  51. package/dist/cjs/zod-to-pact/zod-to-pact.d.ts +37 -0
  52. package/dist/cjs/zod-to-pact/zod-to-pact.d.ts.map +1 -0
  53. package/dist/cjs/zod-to-pact/zod-to-pact.js +151 -0
  54. package/dist/cjs/zod-to-pact/zod-to-pact.js.map +1 -0
  55. package/dist/esm/consumer-helpers/create-provider-state.d.ts +18 -0
  56. package/dist/esm/consumer-helpers/create-provider-state.d.ts.map +1 -0
  57. package/dist/esm/consumer-helpers/create-provider-state.js +18 -0
  58. package/dist/esm/consumer-helpers/create-provider-state.js.map +1 -0
  59. package/dist/esm/consumer-helpers/index.d.ts +6 -0
  60. package/dist/esm/consumer-helpers/index.d.ts.map +1 -0
  61. package/dist/esm/consumer-helpers/index.js +11 -0
  62. package/dist/esm/consumer-helpers/index.js.map +1 -0
  63. package/dist/esm/consumer-helpers/set-json-content.d.ts +32 -0
  64. package/dist/esm/consumer-helpers/set-json-content.d.ts.map +1 -0
  65. package/dist/esm/consumer-helpers/set-json-content.js +28 -0
  66. package/dist/esm/consumer-helpers/set-json-content.js.map +1 -0
  67. package/dist/esm/consumer-helpers/to-json-map.d.ts +13 -0
  68. package/dist/esm/consumer-helpers/to-json-map.d.ts.map +1 -0
  69. package/dist/esm/consumer-helpers/to-json-map.js +34 -0
  70. package/dist/esm/consumer-helpers/to-json-map.js.map +1 -0
  71. package/dist/esm/index.d.ts +7 -0
  72. package/dist/esm/index.d.ts.map +1 -0
  73. package/dist/esm/index.js +19 -0
  74. package/dist/esm/index.js.map +1 -0
  75. package/dist/esm/pact-types.d.ts +45 -0
  76. package/dist/esm/pact-types.d.ts.map +1 -0
  77. package/dist/esm/pact-types.js +11 -0
  78. package/dist/esm/pact-types.js.map +1 -0
  79. package/dist/esm/provider-verifier/build-verifier-options.d.ts +49 -0
  80. package/dist/esm/provider-verifier/build-verifier-options.d.ts.map +1 -0
  81. package/dist/esm/provider-verifier/build-verifier-options.js +113 -0
  82. package/dist/esm/provider-verifier/build-verifier-options.js.map +1 -0
  83. package/dist/esm/provider-verifier/handle-url-and-selectors.d.ts +18 -0
  84. package/dist/esm/provider-verifier/handle-url-and-selectors.d.ts.map +1 -0
  85. package/dist/esm/provider-verifier/handle-url-and-selectors.js +137 -0
  86. package/dist/esm/provider-verifier/handle-url-and-selectors.js.map +1 -0
  87. package/dist/esm/provider-verifier/index.d.ts +3 -0
  88. package/dist/esm/provider-verifier/index.d.ts.map +1 -0
  89. package/dist/esm/provider-verifier/index.js +10 -0
  90. package/dist/esm/provider-verifier/index.js.map +1 -0
  91. package/dist/esm/request-filter/create-request-filter.d.ts +19 -0
  92. package/dist/esm/request-filter/create-request-filter.d.ts.map +1 -0
  93. package/dist/esm/request-filter/create-request-filter.js +39 -0
  94. package/dist/esm/request-filter/create-request-filter.js.map +1 -0
  95. package/dist/esm/request-filter/index.d.ts +2 -0
  96. package/dist/esm/request-filter/index.d.ts.map +1 -0
  97. package/dist/esm/request-filter/index.js +7 -0
  98. package/dist/esm/request-filter/index.js.map +1 -0
  99. package/dist/esm/zod-to-pact/index.d.ts +2 -0
  100. package/dist/esm/zod-to-pact/index.d.ts.map +1 -0
  101. package/dist/esm/zod-to-pact/index.js +6 -0
  102. package/dist/esm/zod-to-pact/index.js.map +1 -0
  103. package/dist/esm/zod-to-pact/zod-to-pact.d.ts +37 -0
  104. package/dist/esm/zod-to-pact/zod-to-pact.d.ts.map +1 -0
  105. package/dist/esm/zod-to-pact/zod-to-pact.js +151 -0
  106. package/dist/esm/zod-to-pact/zod-to-pact.js.map +1 -0
  107. package/dist/types/consumer-helpers/create-provider-state.d.ts +18 -0
  108. package/dist/types/consumer-helpers/create-provider-state.d.ts.map +1 -0
  109. package/dist/types/consumer-helpers/index.d.ts +6 -0
  110. package/dist/types/consumer-helpers/index.d.ts.map +1 -0
  111. package/dist/types/consumer-helpers/set-json-content.d.ts +32 -0
  112. package/dist/types/consumer-helpers/set-json-content.d.ts.map +1 -0
  113. package/dist/types/consumer-helpers/to-json-map.d.ts +13 -0
  114. package/dist/types/consumer-helpers/to-json-map.d.ts.map +1 -0
  115. package/dist/types/index.d.ts +7 -0
  116. package/dist/types/index.d.ts.map +1 -0
  117. package/dist/types/pact-types.d.ts +45 -0
  118. package/dist/types/pact-types.d.ts.map +1 -0
  119. package/dist/types/provider-verifier/build-verifier-options.d.ts +49 -0
  120. package/dist/types/provider-verifier/build-verifier-options.d.ts.map +1 -0
  121. package/dist/types/provider-verifier/handle-url-and-selectors.d.ts +18 -0
  122. package/dist/types/provider-verifier/handle-url-and-selectors.d.ts.map +1 -0
  123. package/dist/types/provider-verifier/index.d.ts +3 -0
  124. package/dist/types/provider-verifier/index.d.ts.map +1 -0
  125. package/dist/types/request-filter/create-request-filter.d.ts +19 -0
  126. package/dist/types/request-filter/create-request-filter.d.ts.map +1 -0
  127. package/dist/types/request-filter/index.d.ts +2 -0
  128. package/dist/types/request-filter/index.d.ts.map +1 -0
  129. package/dist/types/zod-to-pact/index.d.ts +2 -0
  130. package/dist/types/zod-to-pact/index.d.ts.map +1 -0
  131. package/dist/types/zod-to-pact/zod-to-pact.d.ts +37 -0
  132. package/dist/types/zod-to-pact/zod-to-pact.d.ts.map +1 -0
  133. package/package.json +136 -0
@@ -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,gCAAgC,CAEnD,CAAA;IACD,mBAAmB,GAAG,GAAG,CAAC,kBAAkB,CAAA;AAC9C,CAAC;AAAC,MAAM,CAAC;IACP,sDAAsD;AACxD,CAAC;AAED,MAAM,iBAAiB,GAAG,CAAC,MAAoB,EAAW,EAAE;IAC1D,IAAI,CAAC;QACH,OAAO,mBAAmB,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC,CAAA;AAED,MAAM,cAAc,GAAG,CAAC,MAAoB,EAAE,QAAkB,EAAW,EAAE,CAC3E,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAA;AAE/D,MAAM,GAAG,GAAG,CAAC,MAAoB,EAAU,EAAE,CAAC,MAAM,CAAC,GAAwB,CAAA;AAE7E,MAAM,cAAc,GAAG,CAAC,CAAS,EAAW,EAAE;IAC5C,MAAM,MAAM,GAAI,CAAC,CAAC,MAAqD,IAAI,EAAE,CAAA;IAC7E,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC,CAAA;AACvE,CAAC,CAAA;AAED,M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4B;IACxC,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,GAAG,EAAE,WAAW;IAChB,OAAO,EAAE,YAAY;IACrB,IAAI,EAAE,GAAG,EAAE,CAAC,iBAAU,CAAC,SAAS,EAAE;IAClC,QAAQ,EAAE,YAAY;IACtB,QAAQ,EAAE,YAAY;IACtB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;IACnB,KAAK,EAAE,UAAU;IACjB,KAAK,EAAE,UAAU;IACjB,OAAO,EAAE,YAAY;IACrB,IAAI,EAAE,SAAS;CAChB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,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,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,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,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,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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pact-types.d.ts","sourceRoot":"","sources":["../../src/pact-types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAA;AAE5E,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,CAAA;AAEtC,MAAM,MAAM,OAAO,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAA;AAEhD,MAAM,MAAM,SAAS,GAAG,CAAC,UAAU,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;AAEzE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,kBAAkB,GAAG,SAAS,CAAA;AAEzD,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,CAC1B,GAAG,EAAE;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAA;IACtD,IAAI,CAAC,EAAE,OAAO,CAAA;CACf,EACD,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,MAAM,IAAI,GAAG,SAAS,KACzB,OAAO,CAAA;AAEZ;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA"}
@@ -0,0 +1,49 @@
1
+ import type { MessageProviders, MessageStateHandlers, PactMessageProviderOptions, VerifierOptions } from '@pact-foundation/pact';
2
+ import type { StateHandlers, RequestFilter } from '../pact-types';
3
+ /**
4
+ * Builds a `VerifierOptions` object for Pact HTTP provider verification.
5
+ * Encapsulates common provider test setup including state handlers,
6
+ * consumer version selectors, and pact broker options.
7
+ */
8
+ export declare function buildVerifierOptions({ provider, port, logLevel, stateHandlers, beforeEach, afterEach, includeMainAndDeployed, consumer, enablePending, requestFilter, publishVerificationResult, pactBrokerToken, providerVersion, providerVersionBranch, providerVersionTags, pactUrls, pactBrokerUrl, pactPayloadUrl }: {
9
+ provider: string;
10
+ port: string;
11
+ logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error';
12
+ stateHandlers?: StateHandlers & MessageStateHandlers;
13
+ beforeEach?: () => Promise<unknown>;
14
+ afterEach?: () => Promise<unknown>;
15
+ includeMainAndDeployed: boolean;
16
+ consumer?: string;
17
+ enablePending?: boolean;
18
+ requestFilter?: RequestFilter;
19
+ publishVerificationResult?: boolean;
20
+ pactBrokerToken?: string;
21
+ providerVersion?: string;
22
+ providerVersionBranch?: string;
23
+ providerVersionTags?: string[];
24
+ pactUrls?: string[];
25
+ pactBrokerUrl?: string;
26
+ pactPayloadUrl?: string;
27
+ }): VerifierOptions;
28
+ /**
29
+ * Builds a `PactMessageProviderOptions` object for message-based Pact verification.
30
+ * Encapsulates common provider test setup for message handlers and Pact Broker options.
31
+ */
32
+ export declare function buildMessageVerifierOptions({ provider, messageProviders, includeMainAndDeployed, stateHandlers, consumer, enablePending, logLevel, publishVerificationResult, pactBrokerToken, providerVersion, providerVersionBranch, providerVersionTags, pactUrls, pactBrokerUrl, pactPayloadUrl }: {
33
+ provider: string;
34
+ messageProviders: MessageProviders;
35
+ includeMainAndDeployed: boolean;
36
+ stateHandlers?: StateHandlers & MessageStateHandlers;
37
+ consumer?: string;
38
+ enablePending?: boolean;
39
+ logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error';
40
+ publishVerificationResult?: boolean;
41
+ pactBrokerToken?: string;
42
+ providerVersion?: string;
43
+ providerVersionBranch?: string;
44
+ providerVersionTags?: string[];
45
+ pactUrls?: string[];
46
+ pactBrokerUrl?: string;
47
+ pactPayloadUrl?: string;
48
+ }): PactMessageProviderOptions;
49
+ //# sourceMappingURL=build-verifier-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-verifier-options.d.ts","sourceRoot":"","sources":["../../../src/provider-verifier/build-verifier-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gB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;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,QAAQ,EACR,gBAAgB,EAChB,sBAAsB,EACtB,aAAa,EACb,QAAQ,EACR,aAAqB,EACrB,QAAiB,EACjB,yBAAgC,EAChC,eAA+C,EAC/C,eAAqD,EACrD,qBAA2D,EAC3D,mBAA8C,EAC9C,QAAQ,EACR,aAAgD,EAChD,cAA6C,EAC9C,EAAE;IACD,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,sBAAsB,EAAE,OAAO,CAAA;IAC/B,aAAa,CAAC,EAAE,aAAa,GAAG,oBAAoB,CAAA;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;IACxD,yBAAyB,CAAC,EAAE,OAAO,CAAA;IACnC,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC9B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,GAAG,0BAA0B,CAiD7B"}
@@ -0,0 +1,18 @@
1
+ import type { PactMessageProviderOptions, VerifierOptions } from '@pact-foundation/pact';
2
+ /**
3
+ * Handles the conditional logic for selecting the Pact Broker URL and consumer version selectors.
4
+ * Updates the verifier options based on the availability of the Pact payload URL or Pact Broker base URL.
5
+ */
6
+ export declare function handlePactBrokerUrlAndSelectors({ pactPayloadUrl, pactBrokerUrl, consumer, includeMainAndDeployed, options }: {
7
+ pactPayloadUrl?: string;
8
+ pactBrokerUrl?: string;
9
+ consumer?: string;
10
+ includeMainAndDeployed: boolean;
11
+ options: PactMessageProviderOptions | VerifierOptions;
12
+ }): void;
13
+ /**
14
+ * Generates an array of tags to associate with the provider version.
15
+ * Tags are only used in Webhooks, therefore we use is-ci.
16
+ */
17
+ export declare function getProviderVersionTags(): string[];
18
+ //# sourceMappingURL=handle-url-and-selectors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-url-and-selectors.d.ts","sourceRoot":"","sources":["../../../src/provider-verifier/handle-url-and-selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,eAAe,EAChB,MAAM,uBAAuB,CAAA;AAI9B;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,EAC9C,cAAc,EACd,aAAa,EACb,QAAQ,EACR,sBAAsB,EACtB,OAAO,EACR,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,sBAAsB,EAAE,OAAO,CAAA;IAC/B,OAAO,EAAE,0BAA0B,GAAG,eAAe,CAAA;CACtD,GAAG,IAAI,CAkBP;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAmBjD"}
@@ -0,0 +1,3 @@
1
+ export { buildVerifierOptions, buildMessageVerifierOptions } from './build-verifier-options';
2
+ export { handlePactBrokerUrlAndSelectors, getProviderVersionTags } from './handle-url-and-selectors';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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,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,2 @@
1
+ export { createRequestFilter, noOpRequestFilter } from './create-request-filter';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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,2 @@
1
+ export { zodToPactMatchers } from './zod-to-pact';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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,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"}
package/package.json ADDED
@@ -0,0 +1,136 @@
1
+ {
2
+ "name": "@seontechnologies/pactjs-utils",
3
+ "version": "1.0.0",
4
+ "description": "A collection of utilities for Pact.js contract testing.",
5
+ "workspaces": [
6
+ "sample-app/*"
7
+ ],
8
+ "author": "Murat Ozcan",
9
+ "license": "Apache-2.0",
10
+ "main": "dist/cjs/index.js",
11
+ "module": "dist/esm/index.js",
12
+ "types": "dist/types/index.d.ts",
13
+ "files": [
14
+ "dist",
15
+ "README.md"
16
+ ],
17
+ "homepage": "https://github.com/seontechnologies/pactjs-utils#readme",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/seontechnologies/pactjs-utils.git"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/seontechnologies/pactjs-utils/issues"
24
+ },
25
+ "keywords": [
26
+ "pactjs",
27
+ "utils"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "scripts": {
33
+ "start:sample-app": "npm-run-all --parallel start:backend start:frontend",
34
+ "start:frontend": "cd sample-app/frontend && npm start",
35
+ "start:backend": "cd sample-app/backend && npm start",
36
+ "start:pact-server": "cd sample-app/backend && npm run start:pact",
37
+ "prepare": "command -v husky >/dev/null 2>&1 && husky || exit 0",
38
+ "publish:local": "./scripts/publish.sh",
39
+ "build": "npm run clean && npm run build:types && npm run build:cjs && npm run build:esm",
40
+ "clean": "rm -rf dist",
41
+ "build:types": "tsc -p tsconfig-build-types.json --declaration --declarationDir dist/types --emitDeclarationOnly",
42
+ "build:cjs": "tsc -p tsconfig-cjs.json",
43
+ "build:esm": "tsc -p tsconfig-esm.json",
44
+ "prettier": "prettier --ignore-path .gitignore \"**/*.+(js|ts|json)\"",
45
+ "fix:format": "npm run prettier -- --write",
46
+ "validate": "npm-run-all --parallel typecheck lint test fix:format",
47
+ "test:lib": "vitest run",
48
+ "test:backend": "cd sample-app/backend && npm run test",
49
+ "test:frontend": "cd sample-app/frontend && npm run vitest:run",
50
+ "test:pact:consumer": "./scripts/check-pact-determinism.sh 'npm run test:pact:consumer:run' 3 ./pacts",
51
+ "test:pact:consumer:run": "npm run test:pact:consumer:http && npm run test:pact:consumer:message",
52
+ "test:pact:consumer:http": "vitest run --config pact/http/vitest.consumer.config.mts",
53
+ "test:pact:consumer:message": "vitest run --config pact/message/vitest.consumer.config.mts",
54
+ "test:pact:provider:local": "npm run test:pact:provider:local:contract && npm run test:pact:provider:local:message",
55
+ "test:pact:provider:local:contract": "start-server-and-test start:pact-server http://localhost:3001 'vitest run --config pact/http/vitest.provider.config.mts'",
56
+ "test:pact:provider:local:message": "vitest run --config pact/message/vitest.provider.config.mts",
57
+ "test:pact:local": "npm run test:pact:consumer && npm run test:pact:provider:local",
58
+ "publish:pact": ". ./scripts/env-setup.sh && ./scripts/publish-pact.sh",
59
+ "test:pact:provider:remote": "npm run test:pact:provider:remote:contract && npm run test:pact:provider:remote:message",
60
+ "test:pact:provider:remote:contract": ". ./scripts/env-setup.sh && start-server-and-test start:pact-server http://localhost:3001 'vitest run --config pact/http/vitest.provider.config.mts'",
61
+ "test:pact:provider:remote:message": ". ./scripts/env-setup.sh && vitest run --config pact/message/vitest.provider.config.mts",
62
+ "can:i:deploy:consumer": ". ./scripts/env-setup.sh && PACTICIPANT=SampleAppConsumer ./scripts/can-i-deploy.sh",
63
+ "can:i:deploy:provider": ". ./scripts/env-setup.sh && PACTICIPANT=SampleMoviesAPI ./scripts/can-i-deploy.sh",
64
+ "record:consumer:deployment": ". ./scripts/env-setup.sh && PACTICIPANT=SampleAppConsumer ./scripts/record-deployment.sh",
65
+ "record:provider:deployment": ". ./scripts/env-setup.sh && PACTICIPANT=SampleMoviesAPI ./scripts/record-deployment.sh",
66
+ "publish:provider:contract": ". ./scripts/env-setup.sh && ./scripts/publish-provider-contract.sh",
67
+ "test": "npm-run-all --parallel test:lib test:backend test:frontend",
68
+ "typecheck": "tsc --noEmit -p tsconfig.json",
69
+ "typecheck:clear-cache": "find . -name \"*.tsbuildinfo\" -delete && rm -rf node_modules/.cache/typescript",
70
+ "lint": "eslint . --cache-location node_modules/.cache/eslint --fix",
71
+ "docs:dev": "DOCS_BASE=/ vitepress dev docs",
72
+ "docs:lint": "vitepress build docs",
73
+ "docs:build": "vitepress build docs",
74
+ "docs:preview": "DOCS_BASE=/ vitepress preview docs"
75
+ },
76
+ "lint-staged": {
77
+ "*.{ts,js}": [
78
+ "eslint --fix --cache-location node_modules/.cache/eslint",
79
+ "prettier --write --ignore-unknown"
80
+ ],
81
+ "*.{json,md,yml,yaml}": [
82
+ "prettier --write --ignore-unknown"
83
+ ]
84
+ },
85
+ "peerDependencies": {
86
+ "@pact-foundation/pact": ">=16.2.0",
87
+ "zod": ">=4.0.0",
88
+ "@asteasolutions/zod-to-openapi": ">=7.0.0"
89
+ },
90
+ "peerDependenciesMeta": {
91
+ "zod": {
92
+ "optional": true
93
+ },
94
+ "@asteasolutions/zod-to-openapi": {
95
+ "optional": true
96
+ }
97
+ },
98
+ "devDependencies": {
99
+ "@faker-js/faker": "9.9.0",
100
+ "@pact-foundation/pact": "16.3.0",
101
+ "@pact-foundation/pact-cli": "^16.1.7",
102
+ "@types/express": "4.17.21",
103
+ "@types/express-serve-static-core": "5.1.1",
104
+ "@types/lodash": "4.17.24",
105
+ "@types/node": "22.19.17",
106
+ "@typescript-eslint/eslint-plugin": "8.59.1",
107
+ "@typescript-eslint/parser": "8.59.1",
108
+ "dotenv": "16.6.1",
109
+ "eslint": "8.57.1",
110
+ "eslint-config-prettier": "10.1.8",
111
+ "eslint-import-resolver-typescript": "4.4.4",
112
+ "eslint-plugin-filenames": "1.3.2",
113
+ "eslint-plugin-implicit-dependencies": "1.1.1",
114
+ "eslint-plugin-import": "2.32.0",
115
+ "eslint-plugin-no-only-tests": "3.3.0",
116
+ "eslint-plugin-prettier": "5.5.5",
117
+ "husky": "^9.1.7",
118
+ "lint-staged": "^16.4.0",
119
+ "lodash": "4.18.1",
120
+ "mermaid": "^11.14.0",
121
+ "npm-run-all2": "7.0.2",
122
+ "prettier": "3.8.3",
123
+ "start-server-and-test": "^2.1.5",
124
+ "ts-node": "10.9.2",
125
+ "tsx": "4.21.0",
126
+ "typescript": "5.9.3",
127
+ "vite": "6.4.2",
128
+ "vitepress": "^1.6.4",
129
+ "vitepress-plugin-mermaid": "^2.0.17",
130
+ "vitest": "^3.2.0",
131
+ "zod": "4.3.6"
132
+ },
133
+ "dependencies": {
134
+ "is-ci": "^4.1.0"
135
+ }
136
+ }