Socket
Socket
Sign inDemoInstall

@pact-foundation/pact-node

Package Overview
Dependencies
Maintainers
4
Versions
187
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pact-foundation/pact-node - npm Package Compare versions

Comparing version 9.0.7 to 10.0.0

19

CHANGELOG.md

@@ -5,2 +5,21 @@ # Change Log

# [10.0.0](https://github.com/pact-foundation/pact-node/compare/v9.0.7...v10.0.0) (2019-10-28)
### Features
* **can-i-deploy:** Add custom error type CannotDeployError for when the deploy check fails ([635b449](https://github.com/pact-foundation/pact-node/commit/635b449))
* **can-i-deploy:** allow multiple pacticipants to be specified to CanDeploy ([b4b3921](https://github.com/pact-foundation/pact-node/commit/b4b3921))
* **canDeploy:** resolve with output on success ([d20744e](https://github.com/pact-foundation/pact-node/commit/d20744e))
* **CanDeploy:** Set json output as the default for CanDeploy ([200abe7](https://github.com/pact-foundation/pact-node/commit/200abe7))
### BREAKING CHANGES
* **can-i-deploy:** Options for CanDeploy have changed. Now, pacticipants are specified by an array of { name: <string>, latest?: <string | boolean>, version?: <string> }, allowing more than one pacticipant to be specified. You must specify one of latest
or version. If latest is `true`, the latest pact is used. If it is string, then the latest pact with that tag is used.
* **CanDeploy:** CanDeploy now defaults to json output (and returns the parsed object as the result of the promise. If you were using CanDeploy and relied on parsing the logged output, you will need to explicitly set `output: table` in your CanDeploy options.
## [9.0.7](https://github.com/pact-foundation/pact-node/compare/v9.0.6...v9.0.7) (2019-10-23)

@@ -7,0 +26,0 @@

2

package.json
{
"name": "@pact-foundation/pact-node",
"version": "9.0.7",
"version": "10.0.0",
"description": "A wrapper for the Ruby version of Pact to work within Node",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -307,7 +307,14 @@ <img src="https://raw.githubusercontent.com/pact-foundation/pact-logo/master/media/logo-black.png" width="200">

pact.canDeploy(opts)
.then(function () {
// Deployment worked
.then(function (result) {
// You can deploy this
// If output is not specified or is json, result describes the result of the check.
// If outout is 'table', it is the human readable string returned by the check
})
.catch(function() {
// Deployment failed
.catch(function(error) {
// You can't deploy this
// if output is not specified, or is json, error will be an object describing
// the result of the check (if the check failed),
// if output is 'table', then the error will be a string describing the output from the binary,
// In both cases, `error` will be an Error object if something went wrong during the check.
});

@@ -320,14 +327,14 @@ ```

| -------------------- | --------- | ----------- | ----------------------------------------------------------------------------------- |
| `participant` | true | string | The participant name. Required. |
| `participantVersion` | true | string | Version of the participant. Must follow after the participant. Required. |
| `latest` | false | string | Use the latest participant version, Must follow after participant. Optional |
| `to` | false | string | Which tag are you deploying to, Must follow after participant. Optional |
| `pactBroker` | true | string | URL of the Pact Broker to publish pacts to. Required. |
| `pacticipants` | true | string | An array of { name: String, latest? string | boolean, version? string } objects. To |
| | | | specify a tag, use the tagname with latest. Specify one of these per pacticipant |
| | | | that you want to deploy |
| `pactBroker` | true | string | URL of the Pact Broker to query about deployment. Required. |
| `pactBrokerUsername` | false | string | Username for Pact Broker basic authentication. Optional |
| `pactBrokerPassword` | false | string | Password for Pact Broker basic authentication. Optional |
| `pactBrokerToken` | false | string | Bearer token for Pact Broker authentication. Optional |
| `output` | false | json,table | Specify output to show, json or table. Optional |
| `pactBrokerToken` | false | string | Bearer token for Pact Broker authentication. Optional |
| `output` | false | json,table | Specify output to show, json or table. Optional, Defaults to json. |
| `verbose` | false | flag | Set logging mode to verbose. Optional |
| `retryWhileUnknown` | false | number | The number of times to retry while there is an unknown verification result. Optional|
| `retryInterval` | false | number | The time between retries in seconds, use with retryWhileUnknown. Optional |
| `to` | false | string | The tag that you want to deploy to (eg, 'prod') |

@@ -334,0 +341,0 @@ ### Stub Servers

import q = require('q');
export declare class CannotDeployError extends Error {
output: CanDeployResponse | string;
constructor(output: CanDeployResponse | string);
}
export declare class CanDeploy {

@@ -7,11 +11,13 @@ static convertForSpawnBinary(options: CanDeployOptions): CanDeployOptions[];

constructor(options: CanDeployOptions);
canDeploy(): q.Promise<any>;
canDeploy(): q.Promise<CanDeployResponse | string>;
}
declare const _default: (options: CanDeployOptions) => CanDeploy;
export default _default;
export interface CanDeployPacticipant {
name: string;
version?: string;
latest?: string | boolean;
}
export interface CanDeployOptions {
participant?: string;
participantVersion?: string;
to?: string;
latest?: boolean | string;
pacticipants: CanDeployPacticipant[];
pactBroker: string;

@@ -23,2 +29,3 @@ pactBrokerToken?: string;

verbose?: boolean;
to?: string;
retryWhileUnknown?: number;

@@ -28,1 +35,19 @@ retryInterval?: number;

}
export interface CanDeployResponse {
summary: {
deployable: boolean;
reason: string;
unknown: number;
};
matrix: Array<{
consumer: CanDeployPacticipant;
provider: CanDeployPacticipant;
verificationResult: {
verifiedAt: string;
success: boolean;
};
pact: {
createdAt: string;
};
}>;
}
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });

@@ -7,9 +20,21 @@ var q = require("q");

var pact_standalone_1 = require("./pact-standalone");
var spawn_2 = require("./spawn");
var _ = require("underscore");
var checkTypes = require('check-types');
var CannotDeployError = (function (_super) {
__extends(CannotDeployError, _super);
function CannotDeployError(output) {
var _this = _super.call(this, 'can-i-deploy result: it is not safe to deploy') || this;
_this.name = 'CannotDeployError';
_this.output = output;
return _this;
}
return CannotDeployError;
}(Error));
exports.CannotDeployError = CannotDeployError;
var CanDeploy = (function () {
function CanDeploy(options) {
this.__argMapping = {
participant: '--pacticipant',
participantVersion: '--version',
name: '--pacticipant',
version: '--version',
latest: '--latest',

@@ -28,8 +53,7 @@ to: '--to',

options.timeout = options.timeout || 60000;
checkTypes.assert.nonEmptyString(options.participant, 'Must provide the participant argument');
checkTypes.assert.nonEmptyString(options.participantVersion, 'Must provide the participant version argument');
if (!options.output) {
options.output = 'json';
}
checkTypes.assert.nonEmptyArray(options.pacticipants, 'Must provide at least one pacticipant');
checkTypes.assert.nonEmptyString(options.pactBroker, 'Must provide the pactBroker argument');
options.latest !== undefined &&
checkTypes.assert.nonEmptyString(options.latest.toString());
options.to !== undefined && checkTypes.assert.nonEmptyString(options.to);
options.pactBrokerToken !== undefined &&

@@ -48,13 +72,13 @@ checkTypes.assert.nonEmptyString(options.pactBrokerToken);

CanDeploy.convertForSpawnBinary = function (options) {
var keys = ['participant', 'participantVersion', 'latest', 'to'];
var args = [_.omit(options, keys)];
keys.reverse().forEach(function (key) {
var val = options[key];
if (options[key] !== undefined) {
var obj = {};
obj[key] = val;
args.unshift(obj);
}
});
return args;
return _.flatten([_.omit(options, 'pacticipants')].concat(options.pacticipants.map(function (_a) {
var name = _a.name, latest = _a.latest, version = _a.version;
return [
{ name: name },
version
? { version: version }
: {
latest: latest === true ? spawn_2.PACT_NODE_NO_VALUE : latest,
},
];
})));
};

@@ -70,16 +94,22 @@ CanDeploy.prototype.canDeploy = function () {

instance.once('close', function (code) {
var o = output.join('\n');
var success = false;
var result = output.join('\n');
if (_this.options.output === 'json') {
success = JSON.parse(o).summary.deployable;
try {
var parsed = JSON.parse(result);
if (code === 0 && parsed.summary.deployable) {
return deferred.resolve(parsed);
}
return deferred.reject(new CannotDeployError(parsed));
}
catch (e) {
logger_1.default.error("can-i-deploy produced non-json output:\n" + result);
return deferred.reject(new Error(result));
}
}
else {
success = /Computer says yes/gim.exec(o) !== null;
if (code === 0) {
logger_1.default.info(result);
return deferred.resolve(result);
}
if (code === 0 || success) {
logger_1.default.info(o);
return deferred.resolve();
}
logger_1.default.error("can-i-deploy did not return success message:\n" + o);
return deferred.reject(new Error(o));
logger_1.default.error("can-i-deploy did not return success message:\n" + result);
return deferred.reject(new CannotDeployError(result));
});

@@ -86,0 +116,0 @@ return deferred.promise.timeout(this.options.timeout, "Timeout waiting for verification process to complete (PID: " + instance.pid + ")");

@@ -38,12 +38,11 @@ "use strict";

it('produces an array of SpawnArguments', function () {
var value = { pactBroker: 'some broker' };
var value = { pactBroker: 'some broker', pacticipants: [] };
var result = can_deploy_1.CanDeploy.convertForSpawnBinary(value);
expect(result).to.be.an('array');
expect(result.length).to.be.equal(1);
expect(result[0]).to.be.deep.equal(value);
expect(result).to.be.deep.equal([{ pactBroker: 'some broker' }]);
});
it('has version and participant in the right order', function () {
var result = can_deploy_1.CanDeploy.convertForSpawnBinary({
participantVersion: 'v1',
participant: 'one',
pacticipants: [{ version: 'v2', name: 'one' }],
pactBroker: 'some broker',

@@ -54,4 +53,2 @@ pactBrokerUsername: 'username',

expect(result).to.eql([
{ participant: 'one' },
{ participantVersion: 'v1' },
{

@@ -62,2 +59,4 @@ pactBroker: 'some broker',

},
{ name: 'one' },
{ version: 'v2' },
]);

@@ -67,14 +66,26 @@ });

var result = can_deploy_1.CanDeploy.convertForSpawnBinary({
latest: 'v2',
participant: 'two',
pacticipants: [{ name: 'two', latest: 'SOME_TAG' }],
pactBroker: 'some broker',
});
expect(result).to.eql([
{ participant: 'two' },
{ latest: 'v2' },
{
pactBroker: 'some broker',
},
{ name: 'two' },
{ latest: 'SOME_TAG' },
]);
});
it("understands 'true' for latest", function () {
var result = can_deploy_1.CanDeploy.convertForSpawnBinary({
pacticipants: [{ name: 'two', latest: true }],
pactBroker: 'some broker',
});
expect(result).to.eql([
{
pactBroker: 'some broker',
},
{ name: 'two' },
{ latest: 'PACT_NODE_NO_VALUE' },
]);
});
});

@@ -85,47 +96,10 @@ context('when invalid options are set', function () {

});
it('should fail with an Error when not given participant', function () {
it('should fail with an error when there are no paticipants', function () {
expect(function () {
return can_deploy_1.default({
pactBroker: 'http://localhost',
participantVersion: 'v1',
pacticipants: [],
});
}).to.throw(Error);
});
it('should fail with an Error when not given version', function () {
expect(function () {
return can_deploy_1.default({
pactBroker: 'http://localhost',
participant: 'p1',
});
}).to.throw(Error);
});
it('should fail with an error when version and paticipants are empty', function () {
expect(function () {
return can_deploy_1.default({
pactBroker: 'http://localhost',
participantVersion: undefined,
participant: undefined,
});
}).to.throw(Error);
});
it("should fail with an error when 'latest' is an empty string", function () {
expect(function () {
return can_deploy_1.default({
pactBroker: 'http://localhost',
participantVersion: 'v1',
participant: 'p1',
latest: '',
});
}).to.throw(Error);
});
it("should fail with an error when 'to' is an empty string", function () {
expect(function () {
return can_deploy_1.default({
pactBroker: 'http://localhost',
participantVersion: 'v1',
participant: 'p1',
to: '',
});
}).to.throw(Error);
});
});

@@ -136,4 +110,3 @@ context('when valid options are set', function () {

pactBroker: 'http://localhost',
participantVersion: 'v1',
participant: 'p1',
pacticipants: [{ name: 'two', version: '2' }],
});

@@ -143,13 +116,2 @@ expect(c).to.be.ok;

});
it("should work when using 'latest' with either a boolean or a string", function () {
var opts = {
pactBroker: 'http://localhost',
participantVersion: 'v1',
participant: 'p1',
};
opts.latest = true;
expect(can_deploy_1.default(opts)).to.be.ok;
opts.latest = 'tag';
expect(can_deploy_1.default(opts)).to.be.ok;
});
});

@@ -160,13 +122,88 @@ context('candeploy function', function () {

pactBroker: "http://localhost:" + PORT,
participantVersion: '4',
participant: 'Foo',
pacticipants: [{ name: 'Foo', version: '4' }],
};
var ding = can_deploy_1.default(opts);
ding.canDeploy().then(done);
ding.canDeploy().then(function (results) {
expect(results).not.to.be.null;
done();
});
});
context('with latest true', function () {
it('should return success with a table result deployable true', function (done) {
var opts = {
pactBroker: "http://localhost:" + PORT,
pacticipants: [{ name: 'Foo', latest: true }],
};
var ding = can_deploy_1.default(opts);
ding.canDeploy().then(function (results) {
expect(results).not.to.be.null;
done();
});
});
it('should throw an error with a table result deployable false', function () {
var opts = {
pactBroker: "http://localhost:" + PORT,
pacticipants: [{ name: 'FooFail', latest: true }],
};
var ding = can_deploy_1.default(opts);
return ding
.canDeploy()
.then(function () { return expect.fail(); })
.catch(function (message) { return expect(message).not.be.null; });
});
});
context('with latest a string', function () {
it('should return success with a table result deployable true', function (done) {
var opts = {
pactBroker: "http://localhost:" + PORT,
pacticipants: [{ name: 'Foo', latest: 'tag' }],
};
var ding = can_deploy_1.default(opts);
ding.canDeploy().then(function (results) {
expect(results).not.to.be.null;
done();
});
});
it('should throw an error with a table result deployable false', function () {
var opts = {
pactBroker: "http://localhost:" + PORT,
pacticipants: [{ name: 'FooFail', latest: 'tag' }],
};
var ding = can_deploy_1.default(opts);
return ding
.canDeploy()
.then(function () { return expect.fail(); })
.catch(function (message) { return expect(message).not.be.null; });
});
});
context('with latest a string, and a to', function () {
it('should return success with a table result deployable true', function (done) {
var opts = {
pactBroker: "http://localhost:" + PORT,
pacticipants: [{ name: 'Foo', latest: 'tag' }],
to: 'prod',
};
var ding = can_deploy_1.default(opts);
ding.canDeploy().then(function (results) {
expect(results).not.to.be.null;
done();
});
});
it('should throw an error with a table result deployable false', function () {
var opts = {
pactBroker: "http://localhost:" + PORT,
pacticipants: [{ name: 'FooFail', latest: 'tag' }],
to: 'prod',
};
var ding = can_deploy_1.default(opts);
return ding
.canDeploy()
.then(function () { return expect.fail(); })
.catch(function (message) { return expect(message).not.be.null; });
});
});
it('should throw an error with a table result deployable false', function () {
var opts = {
pactBroker: "http://localhost:" + PORT,
participantVersion: '4',
participant: 'FooFail',
pacticipants: [{ name: 'FooFail', version: '4' }],
};

@@ -182,8 +219,10 @@ var ding = can_deploy_1.default(opts);

pactBroker: "http://localhost:" + PORT,
participantVersion: '4',
participant: 'Foo',
pacticipants: [{ name: 'Foo', version: '4' }],
output: 'json',
};
var ding = can_deploy_1.default(opts);
ding.canDeploy().then(done);
ding.canDeploy().then(function (results) {
expect(results).not.to.be.null;
done();
});
});

@@ -193,4 +232,3 @@ it('should throw an error with a json result deployable false', function () {

pactBroker: "http://localhost:" + PORT,
participantVersion: '4',
participant: 'FooFail',
pacticipants: [{ name: 'FooFail', version: '4' }],
output: 'json',

@@ -197,0 +235,0 @@ };

@@ -7,1 +7,2 @@ import pact from './pact';

export * from './stub';
export * from './can-deploy';

@@ -13,2 +13,3 @@ "use strict";

__export(require("./stub"));
__export(require("./can-deploy"));
//# sourceMappingURL=index.js.map

@@ -7,3 +7,3 @@ import * as q from 'q';

import { PublisherOptions } from './publisher';
import { CanDeployOptions } from './can-deploy';
import { CanDeployOptions, CanDeployResponse } from './can-deploy';
import { LogLevels } from './logger';

@@ -26,5 +26,5 @@ import { AbstractService } from './service';

publishPacts(options: PublisherOptions): q.Promise<string[]>;
canDeploy(options: CanDeployOptions): q.Promise<string[]>;
canDeploy(options: CanDeployOptions): q.Promise<CanDeployResponse | string>;
}
declare const _default: Pact;
export default _default;

@@ -8,2 +8,3 @@ import { CanDeployOptions } from '../can-deploy';

export declare const DEFAULT_ARG = "DEFAULT";
export declare const PACT_NODE_NO_VALUE = "PACT_NODE_NO_VALUE";
export declare class Arguments {

@@ -10,0 +11,0 @@ toArgumentsArray(args: SpawnArguments, mappings: {

@@ -6,2 +6,17 @@ "use strict";

exports.DEFAULT_ARG = 'DEFAULT';
exports.PACT_NODE_NO_VALUE = 'PACT_NODE_NO_VALUE';
var valFor = function (v) {
return v !== exports.PACT_NODE_NO_VALUE ? ["'" + v + "'"] : [];
};
var mapFor = function (mapping, v) {
return mapping === exports.DEFAULT_ARG ? valFor(v) : [mapping].concat(valFor(v));
};
var convertValue = function (mapping, v) {
if (v && mapping) {
return checkTypes.array(v)
? _.flatten(v.map(function (val) { return mapFor(mapping, val); }))
: mapFor(mapping, v);
}
return [];
};
var Arguments = (function () {

@@ -20,14 +35,5 @@ function Arguments() {

.reduce(function (acc, value, key) {
if (value && mappings[key]) {
var mapping_1 = mappings[key];
var f_1 = acc.push.bind(acc);
if (mapping_1 === exports.DEFAULT_ARG) {
mapping_1 = '';
f_1 = acc.unshift.bind(acc);
}
_.map(checkTypes.array(value) ? value : [value], function (v) {
return f_1([mapping_1, "'" + v + "'"]);
});
}
return acc;
return mappings[key] === exports.DEFAULT_ARG
? convertValue(mappings[key], value).concat(acc)
: acc.concat(convertValue(mappings[key], value));
}, [])

@@ -34,0 +40,0 @@ .flatten()

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc