@pact-foundation/pact-core 13.5.1 → 13.6.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 (61) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/binding.gyp +141 -0
  3. package/build/Makefile +334 -0
  4. package/build/binding.Makefile +6 -0
  5. package/build/copy_release_artifacts.target.mk +47 -0
  6. package/build/pact.target.mk +174 -0
  7. package/build/set_osx_install_name.target.mk +18 -0
  8. package/ffi/{v0.0.3-libpact_ffi-osx-aarch64-apple-darwin.dylib → libpact_ffi.dylib} +0 -0
  9. package/ffi/{v0.0.3-libpact_ffi-linux-x86_64.so → libpact_ffi.so} +0 -0
  10. package/ffi/libpact_ffi.so.gz +0 -0
  11. package/ffi/{v0.0.3-libpact_ffi-osx-x86_64.dylib → osxaarch64/libpact_ffi.dylib} +0 -0
  12. package/ffi/pact-cpp.h +2344 -0
  13. package/ffi/{v0.0.3-pact.h → pact.h} +667 -119
  14. package/ffi/{v0.0.3-pact_ffi-windows-x86_64.dll → pact_ffi.dll} +0 -0
  15. package/ffi/pact_ffi.dll.lib +0 -0
  16. package/native/addon.cc +68 -0
  17. package/native/consumer.cc +1570 -0
  18. package/native/consumer.h +124 -0
  19. package/native/ffi.cc +148 -0
  20. package/native/ffi.h +18 -0
  21. package/native/plugin.cc +6 -0
  22. package/native/plugin.h +7 -0
  23. package/native/provider.cc +815 -0
  24. package/native/provider.h +38 -0
  25. package/package.json +12 -9
  26. package/src/consumer/checkErrors.d.ts +7 -0
  27. package/src/consumer/checkErrors.js +41 -0
  28. package/src/consumer/checkErrors.js.map +1 -0
  29. package/src/consumer/index.d.ts +5 -0
  30. package/src/consumer/index.js +222 -0
  31. package/src/consumer/index.js.map +1 -0
  32. package/src/consumer/types.d.ts +132 -0
  33. package/src/{ffi/internals → consumer}/types.js +0 -0
  34. package/src/{ffi/internals → consumer}/types.js.map +0 -0
  35. package/src/ffi/index.d.ts +4 -3
  36. package/src/ffi/index.js +6 -9
  37. package/src/ffi/index.js.map +1 -1
  38. package/src/ffi/internals/index.d.ts +0 -2
  39. package/src/ffi/internals/index.js +1 -11
  40. package/src/ffi/internals/index.js.map +1 -1
  41. package/src/ffi/types.d.ts +100 -0
  42. package/src/ffi/types.js +70 -0
  43. package/src/ffi/types.js.map +1 -0
  44. package/src/index.d.ts +2 -0
  45. package/src/index.js +2 -0
  46. package/src/index.js.map +1 -1
  47. package/src/logger/index.d.ts +5 -2
  48. package/src/logger/index.js +15 -2
  49. package/src/logger/index.js.map +1 -1
  50. package/src/verifier/argumentMapper/arguments.js +8 -0
  51. package/src/verifier/argumentMapper/arguments.js.map +1 -1
  52. package/src/verifier/index.js +1 -7
  53. package/src/verifier/index.js.map +1 -1
  54. package/src/verifier/nativeVerifier.js +74 -15
  55. package/src/verifier/nativeVerifier.js.map +1 -1
  56. package/src/verifier/types.d.ts +10 -2
  57. package/test.js +52 -0
  58. package/src/ffi/declarations.d.ts +0 -136
  59. package/src/ffi/declarations.js +0 -92
  60. package/src/ffi/declarations.js.map +0 -1
  61. package/src/ffi/internals/types.d.ts +0 -23
@@ -0,0 +1,815 @@
1
+ #include <napi.h>
2
+ #include <map>
3
+ #include "pact-cpp.h"
4
+ #include <vector>
5
+
6
+ using namespace Napi;
7
+
8
+ // To save passing the struct around. Remove once the rust types are made opaque
9
+ std::map<int, VerifierHandle*> handles;
10
+
11
+ std::vector<const char*> NapiArrayToCStringVector(Napi::Array arr) {
12
+ std::vector<const char*> cVec;
13
+ for(size_t i = 0; i < arr.Length(); i++) {
14
+ std::string tag = arr.Get(i).As<Napi::String>().Utf8Value();
15
+ char *cstr = strdup(tag.c_str());
16
+ cVec.push_back(cstr);
17
+ }
18
+
19
+ return cVec;
20
+ }
21
+
22
+ class VerificationWorker : public AsyncWorker {
23
+ public:
24
+ VerificationWorker(Function& callback, size_t handle)
25
+ : AsyncWorker(callback), handle(handle) {}
26
+
27
+ ~VerificationWorker() {}
28
+
29
+ // This code will be executed on the worker thread
30
+ void Execute() override {
31
+ VerifierHandle *h = handles[handle];
32
+ result = pactffi_verifier_execute(h);
33
+ }
34
+
35
+ void OnOK() override {
36
+ HandleScope scope(Env());
37
+ Callback().Call({Env().Null(), Number::New(Env(), result)});
38
+ }
39
+
40
+ private:
41
+ int result;
42
+ int handle;
43
+
44
+ };
45
+
46
+ /**
47
+ * Get a Handle to a newly created verifier. You should call `pactffi_verifier_shutdown` when
48
+ * done with the verifier to free all allocated resources
49
+ *
50
+ *
51
+ * Returns a new `VerifierHandle`.
52
+ *
53
+ * C interface:
54
+ *
55
+ * struct VerifierHandle *pactffi_verifier_new_for_application(const char *name, const char *version);
56
+ *
57
+ */
58
+ Napi::Value PactffiVerifierNewForApplication(const Napi::CallbackInfo& info) {
59
+ Napi::Env env = info.Env();
60
+ if (info.Length() < 2) {
61
+ throw Napi::Error::New(env, "PactffiNewForApplication received < 2 arguments");
62
+ }
63
+
64
+ if (!info[0].IsString()) {
65
+ throw Napi::Error::New(env, "PactffiNewForApplication(arg 0) expected a string");
66
+ }
67
+
68
+ if (!info[1].IsString()) {
69
+ throw Napi::Error::New(env, "PactffiNewForApplication(arg 1) expected a string");
70
+ }
71
+
72
+ // Extract arguments to verifier
73
+ std::string name = info[0].As<Napi::String>().Utf8Value();
74
+ std::string version = info[1].As<Napi::String>().Utf8Value();
75
+
76
+ // Store the pointer
77
+ VerifierHandle *handle = pactffi_verifier_new_for_application(name.c_str(), version.c_str());
78
+ handles[handles.size()] = handle;
79
+
80
+ return Number::New(env, handles.size() - 1);
81
+ }
82
+
83
+ /**
84
+ * External interface to verifier a provider
85
+ *
86
+ * * `args` - the same as the CLI interface, except newline delimited
87
+ *
88
+ * # Errors
89
+ *
90
+ * Errors are returned as non-zero numeric values.
91
+ *
92
+ * | Error | Description |
93
+ * |-------|-------------|
94
+ * | 1 | The verification process failed, see output for errors |
95
+ * | 2 | A null pointer was received |
96
+ * | 3 | The method panicked |
97
+ * | 4 | Invalid arguments were provided to the verification process |
98
+ *
99
+ * # Safety
100
+ *
101
+ * Exported functions are inherently unsafe. Deal.
102
+ *
103
+ * C interface:
104
+ *
105
+ * int32_t pactffi_verify(const char *args);
106
+ */
107
+ Napi::Value PactffiVerifierExecute(const Napi::CallbackInfo& info) {
108
+ Napi::Env env = info.Env();
109
+
110
+ if (info.Length() < 1) {
111
+ throw Napi::Error::New(env, "PactffiInit(arguments) received < 1 argument");
112
+ }
113
+
114
+ if (!info[0].IsNumber()) {
115
+ throw Napi::Error::New(env, "PactffiInit(arguments) expected a number");
116
+ }
117
+
118
+ // Extract arguments to verifier
119
+ size_t handle = info[0].As<Napi::Number>().Uint32Value();
120
+
121
+ // Execute the function asynchronously
122
+ Napi::Function callback = info[1].As<Napi::Function>();
123
+ VerificationWorker* verificationWorker = new VerificationWorker(callback, handle);
124
+ verificationWorker->Queue();
125
+
126
+ return info.Env().Undefined();
127
+ }
128
+
129
+
130
+ /**
131
+ * Shutdown the verifier and release all resources
132
+ *
133
+ * C interface:
134
+ *
135
+ * void pactffi_verifier_shutdown(VerifierHandle *handle);
136
+ *
137
+ */
138
+ Napi::Value PactffiVerifierShutdown(const Napi::CallbackInfo& info) {
139
+ Napi::Env env = info.Env();
140
+ if (info.Length() < 1) {
141
+ throw Napi::Error::New(env, "PactffiVerifierShutdown received < 1 argument");
142
+ }
143
+
144
+ if (!info[0].IsNumber()) {
145
+ throw Napi::Error::New(env, "PactffiVerifierShutdown(arg 0) expected a VerifierHandle (uint32_t)");
146
+ }
147
+
148
+ uint32_t handleId = info[0].As<Napi::Number>().Uint32Value();
149
+
150
+ pactffi_verifier_shutdown(handles[handleId]);
151
+
152
+ return info.Env().Undefined();
153
+ }
154
+
155
+
156
+ /**
157
+ * Set the provider details for the Pact verifier. Passing a NULL for any field will
158
+ * use the default value for that field.
159
+ *
160
+ * # Safety
161
+ *
162
+ * All string fields must contain valid UTF-8. Invalid UTF-8
163
+ * will be replaced with U+FFFD REPLACEMENT CHARACTER.
164
+ *
165
+ * C interface:
166
+ *
167
+ * void pactffi_verifier_set_provider_info(VerifierHandle *handle,
168
+ * const char *name,
169
+ * const char *scheme,
170
+ * const char *host,
171
+ * unsigned short port,
172
+ * const char *path);
173
+ *
174
+ * */
175
+ Napi::Value PactffiVerifierSetProviderInfo(const Napi::CallbackInfo& info) {
176
+ Napi::Env env = info.Env();
177
+ if (info.Length() < 6) {
178
+ throw Napi::Error::New(env, "PactffiVerifierSetProviderInfo received < 6 arguments");
179
+ }
180
+
181
+ if (!info[0].IsNumber()) {
182
+ throw Napi::Error::New(env, "pactffiVerifierSetProviderInfo(arg 0) expected a VerifierHandle");
183
+ }
184
+
185
+ if (!info[1].IsString()) {
186
+ throw Napi::Error::New(env, "pactffiVerifierSetProviderInfo(arg 1) expected a string");
187
+ }
188
+
189
+ if (!info[2].IsString()) {
190
+ throw Napi::Error::New(env, "pactffiVerifierSetProviderInfo(arg 2 expected a string");
191
+ }
192
+
193
+ if (!info[3].IsString()) {
194
+ throw Napi::Error::New(env, "pactffiVerifierSetProviderInfo(arg 3 expected a string");
195
+ }
196
+
197
+ if (!info[4].IsNumber()) {
198
+ throw Napi::Error::New(env, "pactffiVerifierSetProviderInfo(arg 4) expected a number");
199
+ }
200
+
201
+ if (!info[5].IsString()) {
202
+ throw Napi::Error::New(env, "pactffiVerifierSetProviderInfo(arg 5) expected a string");
203
+ }
204
+
205
+ uint32_t handleId = info[0].As<Napi::Number>().Uint32Value();
206
+ std::string name = info[1].As<Napi::String>().Utf8Value();
207
+ std::string scheme = info[2].As<Napi::String>().Utf8Value();
208
+ std::string host = info[3].As<Napi::String>().Utf8Value();
209
+ uint32_t port = info[4].As<Napi::Number>().Uint32Value();
210
+ std::string path = info[5].As<Napi::String>().Utf8Value();
211
+
212
+ pactffi_verifier_set_provider_info(handles[handleId], name.c_str(), scheme.c_str(), host.c_str(), port, path.c_str());
213
+
214
+ return info.Env().Undefined();
215
+ }
216
+
217
+ /**
218
+ * Set the filters for the Pact verifier.
219
+ *
220
+ * If `filter_description` is not empty, it needs to be as a regular expression.
221
+ *
222
+ * `filter_no_state` is a boolean value. Set it to greater than zero to turn the option on.
223
+ *
224
+ * # Safety
225
+ *
226
+ * All string fields must contain valid UTF-8. Invalid UTF-8
227
+ * will be replaced with U+FFFD REPLACEMENT CHARACTER.
228
+ *
229
+ * C interface:
230
+ *
231
+ * void pactffi_verifier_set_filter_info(VerifierHandle *handle,
232
+ * const char *filter_description,
233
+ * const char *filter_state,
234
+ * unsigned char filter_no_state);
235
+ */
236
+ Napi::Value PactffiVerifierSetFilterInfo(const Napi::CallbackInfo& info) {
237
+ Napi::Env env = info.Env();
238
+ if (info.Length() < 4) {
239
+ throw Napi::Error::New(env, "PactffiVerifierSetFilterInfo received < 4 arguments");
240
+ }
241
+
242
+ if (!info[0].IsNumber()) {
243
+ throw Napi::Error::New(env, "pactffiVerifierSetFilterInfo(arg 0) expected a VerifierHandle");
244
+ }
245
+
246
+ if (!info[1].IsString()) {
247
+ throw Napi::Error::New(env, "pactffiVerifierSetFilterInfo(arg 1) expected a string");
248
+ }
249
+
250
+ if (!info[2].IsString()) {
251
+ throw Napi::Error::New(env, "pactffiVerifierSetFilterInfo(arg 2 expected a string");
252
+ }
253
+
254
+ if (!info[3].IsBoolean()) {
255
+ throw Napi::Error::New(env, "pactffiVerifierSetFilterInfo(arg 3 expected a boolean");
256
+ }
257
+
258
+ uint32_t handleId = info[0].As<Napi::Number>().Uint32Value();
259
+ std::string description = info[1].As<Napi::String>().Utf8Value();
260
+ std::string filterState = info[2].As<Napi::String>().Utf8Value();
261
+ bool filterNoState = info[3].As<Napi::Boolean>().Value();
262
+
263
+ pactffi_verifier_set_filter_info(handles[handleId], description.c_str(), filterState.c_str(), filterNoState);
264
+
265
+ return info.Env().Undefined();
266
+ }
267
+
268
+ /**
269
+ * Set the provider state for the Pact verifier.
270
+ *
271
+ * `teardown` is a boolean value. Set it to greater than zero to turn the option on.
272
+ * `body` is a boolean value. Set it to greater than zero to turn the option on.
273
+ *
274
+ * # Safety
275
+ *
276
+ * All string fields must contain valid UTF-8. Invalid UTF-8
277
+ * will be replaced with U+FFFD REPLACEMENT CHARACTER.
278
+ *
279
+ * C interface:
280
+ *
281
+ * VerifierHandle *handle, const char *url, unsigned char teardown, unsigned char body);
282
+ */
283
+ Napi::Value PactffiVerifierSetProviderState(const Napi::CallbackInfo& info) {
284
+ Napi::Env env = info.Env();
285
+ if (info.Length() < 4) {
286
+ throw Napi::Error::New(env, "PactffiVerifierSetProviderState received < 4 arguments");
287
+ }
288
+
289
+ if (!info[0].IsNumber()) {
290
+ throw Napi::Error::New(env, "pactffiVerifierSetProviderState(arg 0) expected a VerifierHandle");
291
+ }
292
+
293
+ if (!info[1].IsString()) {
294
+ throw Napi::Error::New(env, "pactffiVerifierSetProviderState(arg 1) expected a string");
295
+ }
296
+
297
+ if (!info[2].IsBoolean()) {
298
+ throw Napi::Error::New(env, "pactffiVerifierSetProviderState(arg 2 expected a boolean");
299
+ }
300
+
301
+ if (!info[3].IsBoolean()) {
302
+ throw Napi::Error::New(env, "pactffiVerifierSetProviderState(arg 3 expected a boolean");
303
+ }
304
+
305
+ uint32_t handleId = info[0].As<Napi::Number>().Uint32Value();
306
+ std::string url = info[1].As<Napi::String>().Utf8Value();
307
+ bool teardown = info[2].As<Napi::Boolean>().Value();
308
+ bool body = info[3].As<Napi::Boolean>().Value();
309
+
310
+ pactffi_verifier_set_provider_state(handles[handleId], url.c_str(), teardown, body);
311
+
312
+ return info.Env().Undefined();
313
+ }
314
+
315
+ /**
316
+ * Set the verification options for the Pact verifier.
317
+ *
318
+ * `disable_ssl_verification` is a boolean value. Set it to greater than zero to turn the option on.
319
+ *
320
+ * # Safety
321
+ *
322
+ * All string fields must contain valid UTF-8. Invalid UTF-8
323
+ * will be replaced with U+FFFD REPLACEMENT CHARACTER.
324
+ *
325
+ * C interface:
326
+ *
327
+ * int pactffi_verifier_set_verification_options(VerifierHandle *handle,
328
+ * unsigned char disable_ssl_verification,
329
+ * unsigned long request_timeout);
330
+ */
331
+ Napi::Value PactffiVerifierSetVerificationOptions(const Napi::CallbackInfo& info) {
332
+ Napi::Env env = info.Env();
333
+ if (info.Length() < 3) {
334
+ throw Napi::Error::New(env, "PactffiVerifierSetVerificationOptions received < 3 arguments");
335
+ }
336
+
337
+ if (!info[0].IsNumber()) {
338
+ throw Napi::Error::New(env, "pactffiVerifierSetVerificationOptions(arg 0) expected a VerifierHandle");
339
+ }
340
+
341
+ if (!info[1].IsBoolean()) {
342
+ throw Napi::Error::New(env, "pactffiVerifierSetVerificationOptions(arg 1) expected a boolean");
343
+ }
344
+
345
+ if (!info[2].IsNumber()) {
346
+ throw Napi::Error::New(env, "pactffiVerifierSetVerificationOptions(arg 2) expected a number");
347
+ }
348
+
349
+ uint32_t handleId = info[0].As<Napi::Number>().Uint32Value();
350
+ bool disableSslVerification = info[1].As<Napi::Boolean>().Value();
351
+ uint32_t requestTimeout = info[2].As<Napi::Number>().Uint32Value();
352
+
353
+ pactffi_verifier_set_verification_options(handles[handleId],
354
+ disableSslVerification,
355
+ requestTimeout);
356
+
357
+ return info.Env().Undefined();
358
+ }
359
+
360
+ /**
361
+ * Set the options used when publishing verification results to the Pact Broker
362
+ *
363
+ * # Args
364
+ *
365
+ * - `handle` - The pact verifier handle to update
366
+ * - `provider_version` - Version of the provider to publish
367
+ * - `build_url` - URL to the build which ran the verification
368
+ * - `provider_tags` - Collection of tags for the provider
369
+ * - `provider_tags_len` - Number of provider tags supplied
370
+ * - `provider_branch` - Name of the branch used for verification
371
+ *
372
+ * # Safety
373
+ *
374
+ * All string fields must contain valid UTF-8. Invalid UTF-8
375
+ * will be replaced with U+FFFD REPLACEMENT CHARACTER.
376
+ *
377
+ * C interface:
378
+ *
379
+ * int pactffi_verifier_set_publish_options(VerifierHandle *handle,
380
+ * const char *provider_version,
381
+ * const char *build_url,
382
+ * const char *const *provider_tags,
383
+ * unsigned short provider_tags_len,
384
+ * const char *provider_branch);
385
+ */
386
+ Napi::Value PactffiVerifierSetPublishOptions(const Napi::CallbackInfo& info) {
387
+ Napi::Env env = info.Env();
388
+ if (info.Length() < 5) {
389
+ throw Napi::Error::New(env, "PactffiVerifierSetPublishOptions received < 5 arguments");
390
+ }
391
+
392
+ if (!info[0].IsNumber()) {
393
+ throw Napi::Error::New(env, "pactffiVerifierSetPublishOptions(arg 0) expected a VerifierHandle");
394
+ }
395
+
396
+ if (!info[1].IsString()) {
397
+ throw Napi::Error::New(env, "pactffiVerifierSetPublishOptions(arg 1 expected a string");
398
+ }
399
+
400
+ if (!info[2].IsString()) {
401
+ throw Napi::Error::New(env, "pactffiVerifierSetPublishOptions(arg 2 expected a string");
402
+ }
403
+
404
+ if (!info[3].IsArray()) {
405
+ throw Napi::Error::New(env, "pactffiVerifierSetPublishOptions(arg 3) expected an array of strings");
406
+ }
407
+
408
+ if (!info[4].IsString()) {
409
+ throw Napi::Error::New(env, "pactffiVerifierSetPublishOptions(arg 3 expected a string");
410
+ }
411
+
412
+ uint32_t handleId = info[0].As<Napi::Number>().Uint32Value();
413
+ std::string providerVersion = info[1].As<Napi::String>().Utf8Value();
414
+ std::string buildUrl = info[2].As<Napi::String>().Utf8Value();
415
+ Napi::Array providerTagsRaw = info[3].As<Napi::Array>();
416
+ std::string providerBranch = info[4].As<Napi::String>().Utf8Value();
417
+
418
+ pactffi_verifier_set_publish_options(handles[handleId],
419
+ providerVersion.c_str(),
420
+ buildUrl.c_str(),
421
+ &NapiArrayToCStringVector(providerTagsRaw)[0],
422
+ providerTagsRaw.Length(),
423
+ providerBranch.c_str());
424
+
425
+ return info.Env().Undefined();
426
+ }
427
+
428
+ /**
429
+ * Set the consumer filters for the Pact verifier.
430
+ *
431
+ * # Safety
432
+ *
433
+ * All string fields must contain valid UTF-8. Invalid UTF-8
434
+ * will be replaced with U+FFFD REPLACEMENT CHARACTER.
435
+ *
436
+ * C interface:
437
+ *
438
+ * void pactffi_verifier_set_consumer_filters(VerifierHandle *handle,
439
+ * const char *const *consumer_filters,
440
+ * unsigned short consumer_filters_len);
441
+ *
442
+ */
443
+ Napi::Value PactffiVerifierSetConsumerFilters(const Napi::CallbackInfo& info) {
444
+ Napi::Env env = info.Env();
445
+ if (info.Length() < 2) {
446
+ throw Napi::Error::New(env, "PactffiVerifierSetConsumerFilters received < 2 arguments");
447
+ }
448
+
449
+ if (!info[0].IsNumber()) {
450
+ throw Napi::Error::New(env, "pactffiVerifierSetConsumerFilters(arg 0) expected a VerifierHandle");
451
+ }
452
+
453
+ if (!info[1].IsArray()) {
454
+ throw Napi::Error::New(env, "pactffiVerifierSetConsumerFilters(arg 1) expected an array of strings");
455
+ }
456
+
457
+ uint32_t handleId = info[0].As<Napi::Number>().Uint32Value();
458
+ Napi::Array consumerFilters = info[1].As<Napi::Array>();
459
+
460
+ pactffi_verifier_set_consumer_filters(handles[handleId],
461
+ &NapiArrayToCStringVector(consumerFilters)[0],
462
+ consumerFilters.Length());
463
+
464
+ return info.Env().Undefined();
465
+ }
466
+
467
+ /**
468
+ * Adds a custom header to be added to the requests made to the provider.
469
+ *
470
+ * # Safety
471
+ *
472
+ * The header name and value must point to a valid NULL terminated string and must contain
473
+ * valid UTF-8.
474
+ *
475
+ * C interface:
476
+ *
477
+ * void pactffi_verifier_add_custom_header(VerifierHandle *handle,
478
+ * const char *header_name,
479
+ * const char *header_value);
480
+ *
481
+ */
482
+ Napi::Value PactffiVerifierAddCustomHeader(const Napi::CallbackInfo& info) {
483
+ Napi::Env env = info.Env();
484
+ if (info.Length() < 2) {
485
+ throw Napi::Error::New(env, "PactffiVerifierAddCustomHeader received < 3 arguments");
486
+ }
487
+
488
+ if (!info[0].IsNumber()) {
489
+ throw Napi::Error::New(env, "PactffiVerifierAddCustomHeader(arg 0) expected a VerifierHandle");
490
+ }
491
+
492
+ if (!info[1].IsString()) {
493
+ throw Napi::Error::New(env, "PactffiVerifierAddCustomHeader(arg 1 expected a string");
494
+ }
495
+
496
+ if (!info[2].IsString()) {
497
+ throw Napi::Error::New(env, "PactffiVerifierAddCustomHeader(arg 2 expected a string");
498
+ }
499
+
500
+ uint32_t handleId = info[0].As<Napi::Number>().Uint32Value();
501
+ std::string name = info[1].As<Napi::String>().Utf8Value();
502
+ std::string value = info[2].As<Napi::String>().Utf8Value();
503
+
504
+ pactffi_verifier_add_custom_header(handles[handleId],
505
+ name.c_str(),
506
+ value.c_str());
507
+
508
+ return info.Env().Undefined();
509
+ }
510
+
511
+ /**
512
+ * Adds a Pact file as a source to verify.
513
+ *
514
+ * # Safety
515
+ *
516
+ * All string fields must contain valid UTF-8. Invalid UTF-8
517
+ * will be replaced with U+FFFD REPLACEMENT CHARACTER.
518
+ *
519
+ * C interface:
520
+ *
521
+ * void pactffi_verifier_add_file_source(VerifierHandle *handle, const char *file);
522
+ */
523
+ Napi::Value PactffiVerifierAddFileSource(const Napi::CallbackInfo& info) {
524
+ Napi::Env env = info.Env();
525
+ if (info.Length() < 2) {
526
+ throw Napi::Error::New(env, "PactffiVerifierAddFileSource received < 2 arguments");
527
+ }
528
+
529
+ if (!info[0].IsNumber()) {
530
+ throw Napi::Error::New(env, "pactffiVerifierAddFileSource(arg 0) expected a VerifierHandle");
531
+ }
532
+
533
+ if (!info[1].IsString()) {
534
+ throw Napi::Error::New(env, "pactffiVerifierAddFileSource(arg 1) expected a string");
535
+ }
536
+
537
+ uint32_t handleId = info[0].As<Napi::Number>().Uint32Value();
538
+ std::string file = info[1].As<Napi::String>().Utf8Value();
539
+
540
+ pactffi_verifier_add_file_source(handles[handleId], file.c_str());
541
+
542
+ return info.Env().Undefined();
543
+ }
544
+
545
+ /**
546
+ * Adds a Pact directory as a source to verify. All pacts from the directory that match the
547
+ * provider name will be verified.
548
+ *
549
+ * # Safety
550
+ *
551
+ * All string fields must contain valid UTF-8. Invalid UTF-8
552
+ * will be replaced with U+FFFD REPLACEMENT CHARACTER.
553
+ *
554
+ * C interface:
555
+ *
556
+ * void pactffi_verifier_add_directory_source(VerifierHandle *handle, const char *directory);
557
+ */
558
+ Napi::Value PactffiVerifierAddDirectorySource(const Napi::CallbackInfo& info) {
559
+ Napi::Env env = info.Env();
560
+ if (info.Length() < 2) {
561
+ throw Napi::Error::New(env, "PactffiVerifierAddDirectorySource received < 2 arguments");
562
+ }
563
+
564
+ if (!info[0].IsNumber()) {
565
+ throw Napi::Error::New(env, "pactffiVerifierAddDirectorySource(arg 0) expected a VerifierHandle");
566
+ }
567
+
568
+ if (!info[1].IsString()) {
569
+ throw Napi::Error::New(env, "pactffiVerifierAddDirectorySource(arg 1) expected a string");
570
+ }
571
+
572
+ uint32_t handleId = info[0].As<Napi::Number>().Uint32Value();
573
+ std::string dir = info[1].As<Napi::String>().Utf8Value();
574
+
575
+ pactffi_verifier_add_directory_source(handles[handleId], dir.c_str());
576
+
577
+ return info.Env().Undefined();
578
+ }
579
+
580
+ /**
581
+ * Adds a URL as a source to verify. The Pact file will be fetched from the URL.
582
+ *
583
+ * If a username and password is given, then basic authentication will be used when fetching
584
+ * the pact file. If a token is provided, then bearer token authentication will be used.
585
+ *
586
+ * # Safety
587
+ *
588
+ * All string fields must contain valid UTF-8. Invalid UTF-8
589
+ * will be replaced with U+FFFD REPLACEMENT CHARACTER.
590
+ *
591
+ * C interface:
592
+ *
593
+ * void pactffi_verifier_url_source(VerifierHandle *handle,
594
+ * const char *url,
595
+ * const char *username,
596
+ * const char *password,
597
+ * const char *token);
598
+ */
599
+ Napi::Value PactffiVerifierUrlSource(const Napi::CallbackInfo& info) {
600
+ Napi::Env env = info.Env();
601
+ if (info.Length() < 5) {
602
+ throw Napi::Error::New(env, "PactffiVerifierUrlSource received < 5 arguments");
603
+ }
604
+
605
+ if (!info[0].IsNumber()) {
606
+ throw Napi::Error::New(env, "pactffiVerifierUrlSource(arg 0) expected a VerifierHandle");
607
+ }
608
+
609
+ if (!info[1].IsString()) {
610
+ throw Napi::Error::New(env, "pactffiVerifierUrlSource(arg 1) expected a string");
611
+ }
612
+
613
+ if (!info[2].IsString()) {
614
+ throw Napi::Error::New(env, "pactffiVerifierUrlSource(arg 2) expected a string");
615
+ }
616
+
617
+ if (!info[3].IsString()) {
618
+ throw Napi::Error::New(env, "pactffiVerifierUrlSource(arg 3) expected a string");
619
+ }
620
+
621
+ if (!info[4].IsString()) {
622
+ throw Napi::Error::New(env, "pactffiVerifierUrlSource(arg 4) expected a string");
623
+ }
624
+
625
+ uint32_t handleId = info[0].As<Napi::Number>().Uint32Value();
626
+ std::string url = info[1].As<Napi::String>().Utf8Value();
627
+ std::string username = info[2].As<Napi::String>().Utf8Value();
628
+ std::string password = info[3].As<Napi::String>().Utf8Value();
629
+ std::string token = info[4].As<Napi::String>().Utf8Value();
630
+
631
+ pactffi_verifier_url_source(handles[handleId], url.c_str(), username.c_str(), password.c_str(), token.c_str());
632
+
633
+ return info.Env().Undefined();
634
+ }
635
+
636
+ // Deprecated
637
+ // /**
638
+ // * Adds a Pact broker as a source to verify. This will fetch all the pact files from the broker
639
+ // * that match the provider name.
640
+ // *
641
+ // * If a username and password is given, then basic authentication will be used when fetching
642
+ // * the pact file. If a token is provided, then bearer token authentication will be used.
643
+ // *
644
+ // * # Safety
645
+ // *
646
+ // * All string fields must contain valid UTF-8. Invalid UTF-8
647
+ // * will be replaced with U+FFFD REPLACEMENT CHARACTER.
648
+ // *
649
+ // * C interface:
650
+ // *
651
+ // * void pactffi_verifier_broker_source(VerifierHandle *handle,
652
+ // * const char *url,
653
+ // * const char *provider_name,
654
+ // * const char *username,
655
+ // * const char *password,
656
+ // * const char *token);
657
+ // */
658
+ // Napi::Value PactffiVerifierBrokerSource(const Napi::CallbackInfo& info) {
659
+ // Napi::Env env = info.Env();
660
+ // if (info.Length() < 5) {
661
+ // throw Napi::Error::New(env, "PactffiVerifierUrlSource received < 5 arguments");
662
+ // }
663
+
664
+ // if (!info[0].IsNumber()) {
665
+ // throw Napi::Error::New(env, "PactffiVerifierUrlSource(arg 0) expected a VerifierHandle");
666
+ // }
667
+
668
+ // if (!info[1].IsString()) {
669
+ // throw Napi::Error::New(env, "PactffiVerifierUrlSource(arg 1) expected a string");
670
+ // }
671
+
672
+ // if (!info[2].IsString()) {
673
+ // throw Napi::Error::New(env, "PactffiVerifierUrlSource(arg 2) expected a string");
674
+ // }
675
+
676
+ // if (!info[3].IsString()) {
677
+ // throw Napi::Error::New(env, "PactffiVerifierUrlSource(arg 3) expected a string");
678
+ // }
679
+
680
+ // if (!info[4].IsString()) {
681
+ // throw Napi::Error::New(env, "PactffiVerifierUrlSource(arg 4) expected a string");
682
+ // }
683
+
684
+ // uint32_t handleId = info[0].As<Napi::Number>().Uint32Value();
685
+ // std::string url = info[1].As<Napi::String>().Utf8Value();
686
+ // std::string username = info[2].As<Napi::String>().Utf8Value();
687
+ // std::string password = info[3].As<Napi::String>().Utf8Value();
688
+ // std::string token = info[4].As<Napi::String>().Utf8Value();
689
+
690
+ // pactffi_verifier_broker_source(handles[handleId], url.c_str(), username.c_str(), password.c_str(), token.c_str());
691
+
692
+ // return info.Env().Undefined();
693
+ // }
694
+
695
+ /**
696
+ * Adds a Pact broker as a source to verify. This will fetch all the pact files from the broker
697
+ * that match the provider name and the consumer version selectors
698
+ * (See `https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors/`).
699
+ *
700
+ * The consumer version selectors must be passed in in JSON format.
701
+ *
702
+ * `enable_pending` is a boolean value. Set it to greater than zero to turn the option on.
703
+ *
704
+ * If the `include_wip_pacts_since` option is provided, it needs to be a date formatted in
705
+ * ISO format (YYYY-MM-DD).
706
+ *
707
+ * If a username and password is given, then basic authentication will be used when fetching
708
+ * the pact file. If a token is provided, then bearer token authentication will be used.
709
+ *
710
+ * # Safety
711
+ *
712
+ * All string fields must contain valid UTF-8. Invalid UTF-8
713
+ * will be replaced with U+FFFD REPLACEMENT CHARACTER.
714
+ *
715
+ * C interface:
716
+ *
717
+ * void pactffi_verifier_broker_source_with_selectors(VerifierHandle *handle,
718
+ * const char *url,
719
+ * const char *provider_name,
720
+ * const char *username,
721
+ * const char *password,
722
+ * const char *token,
723
+ * unsigned char enable_pending,
724
+ * const char *include_wip_pacts_since,
725
+ * const char *const *provider_tags,
726
+ * unsigned short provider_tags_len,
727
+ * const char *provider_branch,
728
+ * const char *const *consumer_version_selectors,
729
+ * unsigned short consumer_version_selectors_len,
730
+ * const char *const *consumer_version_tags,
731
+ * unsigned short consumer_version_tags_len);
732
+ */
733
+ Napi::Value PactffiVerifierBrokerSourceWithSelectors(const Napi::CallbackInfo& info) {
734
+ Napi::Env env = info.Env();
735
+ if (info.Length() < 11) {
736
+ throw Napi::Error::New(env, "PactffiVerifierBrokerSourceWithSelectors received < 11 arguments");
737
+ }
738
+
739
+ if (!info[0].IsNumber()) {
740
+ throw Napi::Error::New(env, "pactffiVerifierBrokerSourceWithSelectors(arg 0) expected a VerifierHandle");
741
+ }
742
+
743
+ if (!info[1].IsString()) {
744
+ throw Napi::Error::New(env, "pactffiVerifierBrokerSourceWithSelectors(arg 1 expected a string");
745
+ }
746
+
747
+ if (!info[2].IsString()) {
748
+ throw Napi::Error::New(env, "pactffiVerifierBrokerSourceWithSelectors(arg 2 expected a string");
749
+ }
750
+
751
+ if (!info[3].IsString()) {
752
+ throw Napi::Error::New(env, "pactffiVerifierBrokerSourceWithSelectors(arg 3 expected a string");
753
+ }
754
+
755
+ if (!info[4].IsString()) {
756
+ throw Napi::Error::New(env, "pactffiVerifierBrokerSourceWithSelectors(arg 4 expected a string");
757
+ }
758
+
759
+ if (!info[5].IsBoolean()) {
760
+ throw Napi::Error::New(env, "pactffiVerifierBrokerSourceWithSelectors(arg 5) expected a boolean");
761
+ }
762
+
763
+ if (!info[6].IsString()) {
764
+ throw Napi::Error::New(env, "pactffiVerifierBrokerSourceWithSelectors(arg 6 expected a string");
765
+ }
766
+
767
+ if (!info[7].IsArray()) {
768
+ throw Napi::Error::New(env, "pactffiVerifierBrokerSourceWithSelectors(arg 7) expected an array of strings");
769
+ }
770
+
771
+ if (!info[8].IsString()) {
772
+ throw Napi::Error::New(env, "pactffiVerifierBrokerSourceWithSelectors(arg 8 expected a string");
773
+ }
774
+
775
+ if (!info[9].IsArray()) {
776
+ throw Napi::Error::New(env, "pactffiVerifierBrokerSourceWithSelectors(arg 9) expected an array of strings");
777
+ }
778
+
779
+ if (!info[10].IsArray()) {
780
+ throw Napi::Error::New(env, "pactffiVerifierBrokerSourceWithSelectors(arg 10) expected an array of strings");
781
+ }
782
+
783
+ uint32_t handleId = info[0].As<Napi::Number>().Uint32Value();
784
+ std::string url = info[1].As<Napi::String>().Utf8Value();
785
+ std::string username = info[2].As<Napi::String>().Utf8Value();
786
+ std::string password = info[3].As<Napi::String>().Utf8Value();
787
+ std::string token = info[4].As<Napi::String>().Utf8Value();
788
+ bool enablePending = info[5].As<Napi::Boolean>().Value();
789
+ std::string includeWipPactsSince = info[6].As<Napi::String>().Utf8Value();
790
+ Napi::Array providerTags = info[7].As<Napi::Array>();
791
+ std::string providerBranch = info[8].As<Napi::String>().Utf8Value();
792
+ Napi::Array consumerVersionSelectors = info[9].As<Napi::Array>();
793
+ Napi::Array consumerVersionTags = info[10].As<Napi::Array>();
794
+
795
+ auto cProviderTags = NapiArrayToCStringVector(providerTags);
796
+ auto cConsumerVersionSelectors = NapiArrayToCStringVector(consumerVersionSelectors);
797
+ auto cConsumerVersionTags = NapiArrayToCStringVector(consumerVersionTags);
798
+
799
+ pactffi_verifier_broker_source_with_selectors(handles[handleId],
800
+ url.c_str(),
801
+ username.c_str(),
802
+ password.c_str(),
803
+ token.c_str(),
804
+ enablePending,
805
+ includeWipPactsSince.c_str(),
806
+ &cProviderTags[0],
807
+ providerTags.Length(),
808
+ providerBranch.c_str(),
809
+ &cConsumerVersionSelectors[0],
810
+ consumerVersionSelectors.Length(),
811
+ &cConsumerVersionTags[0],
812
+ consumerVersionTags.Length());
813
+
814
+ return info.Env().Undefined();
815
+ }