1.0.0 • Published 7 years ago

archetypes v1.0.0

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
7 years ago

archetypesNPM version

Business archetypes logo

License Dependencies' licenses NSP Status Synk Vulnerabilities StackShare Dependency Status devDependencies Status Build Status Coverage percentage Codacy quality All Contributors

quote A business archetype is a primordial thing that occurs consistently and universally in business domains and business software systems.

(Arlow & Neustadt, Enterprise patterns and MDA: building better software with archetype patterns and UML, 2006, p. 5)

commonality/archetypes provides universal, rule-based business collaboration APIs for e-commerce and customer relationship management (CRM). commonality/archetypes specifies semantically-rich models of universally recurring business entities, events, and relationships with OpenAPI 2.0.

What are archetypes?

archetypes model how PartiesPeople and Companiesexchange Products and Services with Payments (normally Money or other Locale-based Currencies like gift-cards). The exchanges are recorded from beginning to end as Orders and managed as Customer Relationships (CRM) between buyers and sellers (with PartyRelationships). When necessary, Rules constrain and determine the types of relationships allowed; how products can be packaged; and whether discounts can be applied.

These business archetypes are expressed as models in open, vendor-neutral OpenAPI/Swagger specifications, which provide:

  1. A common vocabulary and operating framework for how PartiesPeople and Companiesexchange goods and services for Money (with Locale-based Currencies), as well as managing these relationships as Customers (CRM).
  2. Executable documentation that articulates these models and how they interact.
  3. Open-source tools that automatically generate microservice "stubs" and client SDKs.

Table of contents

1. Security

commonality/archetypes provide model-driven OpenAPI specifications for pervasive business patterns. Some of these models contain sensitive personal or company data that require access control and privacy safeguards.

None of commonality/archetypes' specifications come with OpenAPI securityDefinitions. Before exposing any data, please apply the principle of least privilege with your own securityDefinitions as appropriate. You must secure how sensitive data are stored and shared.

2. Installation

Open a Terminal and run this command:

npm install --save archetypes

If your team prefers Yarn:

yarn add archetypes

2.1. Generating servers and clients

quote swagger-api/swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.

Cheng, W., & Tam, T. (2011, August 15). swagger-api/swagger-codegen. Retrieved August 27, 2017, from https://github.com/swagger-api/swagger-codegen

Swagger Codegen will generate servers and clients in many different languages and frameworks.

Follow the Installation and Getting Starting instructions to generate and build servers and clients from workstations, CI-services, or Docker containers.

2.2. Editing OpenAPI specs

  1. Go to https://editor.swagger.io/.
  2. Copy the /archetypes/v1/{archetype}/{archetype}.yaml specification of interest.
  3. Paste the *.yaml source into the editor pane.
  4. Select "Generate Server" or "Generate Client" and choose an option.
  5. If successful, you will prompted to download the ZIPped source code.

3. Usage: API HTTP responses

3.1. curl

The simplest way to test against mock objects at http://api.swindle.net/archetypes/v1/parties with curl in a Terminal.

$ curl \
  -X GET "http://api.swindle.net/archetypes/v1/parties/2e908e75-69a9-47e2-83ae-0c3cc52da84c" \
  -H "accept: application/json"

3.2. Swagger-UI

Go to the api.swindle.net Swagger-UI's "About" section and "Explore" the available Swagger Specs.

The following sections summarize all twelve business archetype patterns as they are released.

4. Party API :package:

REST API

quote The Party archetype represents an identifiable, addressable entity that may have a legal status and that normally has autonomous control over (at least some of) its actions.

Arlow, J., & Neustadt, I. (2006). Party archetype pattern. In Enterprise patterns and MDA: building better software with archetype patterns and UML (p. 122). Boston: Addison-Wesley.

4.1. Standards compliance

StandardContents
OMG Party Management Facility SpecificationA standard that supports party management.
ISO 3166Two- and three-letter country codes and country names.
ISO/IEC 5218:2004Codes for the representation of human sexes.
ITU-T RecommendationsTelecommunication numbering plan.

4.2. Resources

ProposalContents
63 GendersA proposal for describing Gender as a combination of Physical, Personality and Preferential groups.

4.3. OpenAPI 2.0 Specs

Party's Swagger validity YAML (Content-Type: application/x-yaml)

parties/
├── nominative.yaml
├── parties.yaml
└── unique-identifier.yaml

4.4. API and SDK documentation

Business archetypeDefinition
OrganizationsAdministrative and functional structures
PartiesIdentifiable, addressable entity that may have a legal status and that normally has autonomous control over (at least some of) its actions.
PeopleHuman beings.
PreferencesChoices of (or liking for) something, often from a set of possible or offered options.

4.5. Usage example

Retrieve a Party by identifier with JavaScript:

const Party = require("party");

const api = new Party.PartiesApi();

// {String} The universally unique identifier associated with a Party.
const partyIdentifier = "2e908e75-69a9-47e2-83ae-0c3cc52da84c";

const callback = (error, data, response) => {
  if (error) {
    console.error(error);
  } else {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data, null, 2)
    );
  }
  console.log(response);
};
api.getByPartyIdentifier(partyIdentifier, callback);

5. Quantity API :package:

REST API

quote The Quantity archetype represents an amount of something measured according to some standard of measurement.

Arlow, J., & Neustadt, I. (2006). Quantity archetype pattern. In Enterprise patterns and MDA: building better software with archetype patterns and UML (p. 400). Boston: Addison-Wesley.

5.1. Standards compliance

5.2. OpenAPI 2.0 Specs

Quantity's Swagger validity YAML (Content-Type: application/x-yaml)

quantities/
├── metric.yaml
├── quantities.yaml
├── quantity.yaml
├── rounding-strategy.yaml
├── si-system-of-units.yaml
└── system-of-units.yaml

5.3. API and SDK documentation

JavaScript client SDK (Node.js) client SDK.

5.4. Usage example

Retrieve an SiBaseUnit by identifier with JavaScript:

const Quantity = require("quantity");

const api = new Quantity.SIInternationalSystemOfUnitsApi();

// {String} The name of the unit/metric.
const name = "meter";

const callback = (error, data, response) => {
  if (error) {
    console.error(error);
  } else {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data, null, 2)
    );
  }
  console.log(response);
};

api.getBaseUnitByName(name, callback);

6. Money API :package:

REST API

quote The Money archetype represents an amount of a specific Currency that is acceptedIn one or more Locales.

Arlow, J., & Neustadt, I. (2006). Money archetype pattern. In Enterprise patterns and MDA: building better software with archetype patterns and UML (p. 413). Boston: Addison-Wesley.

6.1. Standards compliance

6.2. OpenAPI 2.0 Specs

Quantity's Swagger validity YAML (Content-Type: application/x-yaml)

money/
├── currency.definition.yaml
├── money.definition.yaml
├── money.yaml
├── payment-card.definition.yaml
├── payment-method.definition.yaml
├── payment.definition.yaml
└── README.md

6.3. API documentation

JavaScript client SDK (Node.js)

6.4. Usage examples

Get all ISO 4217 Currencies with JavaScript (Node.js):

const Money = require("money");

const moneyApi = new Money.CurrencyApi();

const callback = (error, data, response) => {
  if (error) {
    console.error(error);
  } else {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data, null, 2)
    );
  }
  console.log(response);
};

moneyApi.getCurrencies(callback);

Retrieve a Currency by its ISO 4217 alphabetic code with JavaScript:

const Money = require("money");

const moneyApi = new Money.CurrencyApi();

// String | An alphabetic code that represents the currency.
const alphabeticCode = "USD";

const callback = (error, data, response) => {
  if (error) {
    console.error(error);
  } else {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data, null, 2)
    );
  }
  console.log(response);
};

moneyApi.getCurrencyByAlphabeticCode(alphabeticCode, callback);

7. PartyRelationship API

REST API

quote The PartyRelationship captures the fact that there is a semantic relationship between two Parties in which each Party plays a specific role.

Arlow, J., & Neustadt, I. (2006). Archetype glossary. In Enterprise patterns and MDA: building better software with archetype patterns and UML (p. 160). Boston: Addison-Wesley.

Roadmap

icon-road-milestone-image MVP3: PartyRelationships and Rules

8. Rule API

REST API

quote The Rule archetype represents a constraint on the operation of the software systems of the businessits semantics are defined by a sequence of RuleElements.

Arlow, J., & Neustadt, I. (2006). Archetype glossary. In Enterprise patterns and MDA: building better software with archetype patterns and UML (p. 449). Boston: Addison-Wesley.

Roadmap

icon-road-milestone-image MVP3: PartyRelationships and Rules

9. Customer relationship management (CRM) API

REST API

quote Customer relationship management (CRM) is about actively managing the relationships between your business and your customers, in order to understand and increase customer value, motivation, and loyalty.

Arlow, J., & Neustadt, I. (2006). Customer relationship management archetype pattern. In Enterprise patterns and MDA: building better software with archetype patterns and UML (p. 187). Boston: Addison-Wesley.

Roadmap

icon-road-milestone-image MVP4: Customer relationship management (CRM)

10. Product API

REST API

quote The Product archetype pattern represents a generalized model for products.

Arlow, J., & Neustadt, I. (2006). Product archetype pattern. In Enterprise patterns and MDA: building better software with archetype patterns and UML (p. 207). Boston: Addison-Wesley.

Roadmap

icon-road-milestone-image MVP5: Product

11. Inventory API

REST API

quote The Inventory archetype represents a collection of InventoryEntries held in stock by a business.

Arlow, J., & Neustadt, I. (2006). Inventory archetype pattern. In Enterprise patterns and MDA: building better software with archetype patterns and UML (p. 271). Boston: Addison-Wesley.

Roadmap

icon-road-milestone-image MVP6: Inventory

12. Order API

REST API

quote The Order archetype represents a request by a buyer for a seller to supply some goods or services.

Arlow, J., & Neustadt, I. (2006). Inventory archetype pattern. In Enterprise patterns and MDA: building better software with archetype patterns and UML (p. 271). Boston: Addison-Wesley.

Roadmap

icon-road-milestone-image MVP7: Inventory

13. Product development and delivery

Packaging

PRs Welcome We welcome contributors and pull requests!

Interested in development contributions? Great! Check out our guidelines for Contributing to archetypes for details.

13.1. Built With

StackShare

archetypes requires the following tech-stack to either run, build, test, or deploy:

DependencyDescriptionVersionLicenseType
@babel/core@^7.1.6Babel compiler core.7.1.6MITdev
all-contributors-cli@^5.4.1Tool to easily add recognition for new contributors5.4.1MITdev
audit@0.0.6Generate performance statistics for async or sync functions0.0.6UNLICENSEDdev
babel-jest@^23.6.0Jest plugin to use babel for transformation.23.6.0MITdev
babel-preset-env@^1.7.0A Babel preset for each environment.1.7.0MITdev
babelify@^10.0.0Babel browserify transform10.0.0MITdev
commitplease@^3.2.0Validates strings as commit messages3.2.0MITdev
coveralls@^3.0.2takes json-cov output into stdin and POSTs to coveralls.io3.0.2BSD-2-Clausedev
eslint@^5.9.0An AST-based pattern checker for JavaScript.5.9.0MITdev
eslint-config-standard@^12.0.0JavaScript Standard Style - ESLint Shareable Config12.0.0MITdev
eslint-config-xo-space@^0.20.0ESLint shareable config for XO with 2-space indent0.20.0MITdev
eslint-plugin-import@^2.14.0Import with sanity.2.14.0MITdev
eslint-plugin-jest@^22.1.0Eslint rules for Jest22.1.0MITdev
eslint-plugin-jsdoc@^3.9.1JSDoc linting rules for ESLint.3.9.1BSD-3-Clausedev
eslint-plugin-no-unsafe-innerhtml@^1.0.16custom ESLint rule to disallows unsafe innerHTML, outerHTML and insertAdjacentHTML1.0.16MPL-2.0dev
eslint-plugin-no-unsanitized@^3.0.2ESLint rule to disallow unsanitized code3.0.2MPL-2.0dev
eslint-plugin-node@^8.0.0Additional ESLint's rules for Node.js8.0.0MITdev
eslint-plugin-promise@^4.0.1Enforce best practices for JavaScript promises4.0.1ISCdev
eslint-plugin-scanjs-rules@^0.2.1ESLint plugin that contains ScanJS rules0.2.1MPL-2.0dev
eslint-plugin-security@^1.4.0Security rules for eslint1.4.0Apache-2.0dev
eslint-plugin-standard@^4.0.0ESlint Plugin for the Standard Linter4.0.0MITdev
eslint-plugin-xss@^0.1.9Validates XSS related issues of mixing HTML and non-HTML content in variables.0.1.9ISCdev
jest@^23.6.0Delightful JavaScript Testing.23.6.0MITdev
jest-cli@^23.6.0Delightful JavaScript Testing.23.6.0MITdev
jest-config@^23.6.023.6.0MITdev
markdown-magic@^0.1.25Automatically update markdown files with content from external sources0.1.25MITdev
markdown-magic-dependency-table@^1.3.2Generate table of information about dependencies automatically in markdown1.3.2MITdev
markdown-magic-directory-tree@^1.2.3Print an archy tree for markdown file1.2.3MITdev
markdown-magic-github-contributors@0.0.3Add github contributors to markdown file0.0.3MITdev
markdown-magic-package-scripts@^1.2.1Print list of scripts in package.json with descriptions1.2.1MITdev
markdown-magic-subpackage-list@^1.1.1Print a list of subpackages for markdown file1.1.1MITdev
markdown-toc@^1.2.0Generate a markdown TOC (table of contents) with Remarkable.1.2.0MITdev
prettier@^1.15.2Prettier is an opinionated code formatter1.15.2MITdev
semantic-release@^15.12....Automated semver compliant package publishing15.12.2MITdev
snyk@^1.110....snyk library and cli utility1.110.2Apache-2.0dev
sonar-scanner@^3.1.0Wrap sonar-scanner as a node module3.1.0MITdev
standard-version@^4.4.0replacement for npm version with automatic CHANGELOG generation4.4.0ISCdev
swagger-parser@^6.0.2Swagger 2.0 and OpenAPI 3.0 parser and validator for Node and browsers6.0.2MITdev
synk@0.0.2schronize a remote directory with a local one, then run a series of preset commands on the server0.0.02UNLICENSEDdev
travis-deploy-once@^5.0.9Run a deployment script only once in the Travis test matrix5.0.9MITdev

Keep track of archetypes' tech-stack with these news and RSS feeds.

13.2. Prerequisite

Node.js: commonality/archetypes product development and delivery require Node.js (version 6.x or greater) and its package manager, npm. for build, test, and release tasks.

13.3. Set up a development environment

Here's a brief intro about what a developer must do in order to start developing the project further:

$ git clone https://github.com/commonality/archetypes.git
$ cd archetypes/
$ npm install

13.4. npm-scripts

Software modules often have funky, irrelative names, which is why we prefix custom tasks by their responsibility and purpose.

PrefixDefinition
build*Source code distribution tasks.
docs*API documentation and automation tasks.
lint*Code style, standards, and vulnerabilty assessments (as well as fixes, if available).
releaseBump the product's semver, update docs, commit, and publish to the npm registry.
security*Security vulnerabilty checks.

The following CLI npm-scripts are available to you (assuming you're human, gentle reader) and CI-services.

ScriptDescription
build:bundle:allnpm run build:bundle:money && npm run build:bundle:parties && npm run build:bundle:quantities
build:bundle:moneyswagger bundle --dereference --outfile ./schemas/v1/money/money.bundle.json ./schemas/v1/money/money.spec.yaml
build:bundle:partiesswagger bundle --dereference --outfile ./schemas/v1/parties/parties.bundle.json ./schemas/v1/parties/parties.yaml
build:bundle:quantitiesswagger bundle --dereference --outfile ./schemas/v1/quantities/quantities.bundle.json ./schemas/v1/quantities/quantities.yaml
docsnode generate-docs.js && npm run docs:toc
docs:contributorsall-contributors
docs:contributors:addall-contributors add
docs:contributors:generateall-contributors generate
docs:toc./node_modules/.bin/markdown-toc -i README.md
lintnpm run lint:js && npm run lint:swagger:all
lint:jseslint . --fix
lint:mdprettier --write README.md
lint:sonarnode_modules/sonar-scanner/bin/sonar-scanner
lint:swagger:allnpm run lint:swagger:parties
lint:swagger:moneyswagger validate schemas/v1/money/money.spec.yaml --debug
lint:swagger:partiesswagger validate schemas/v1/parties/parties.yaml --debug
lint:swagger:quantitiesswagger validate schemas/v1/quantities/quantities.yaml --debug
postbumpecho $npm_package_version
prepublishOnlynpm run docs
preversionnpm run docs
securitynpm run security:nsp:scan && npm run security:snyk:all
security:auditnpm run security:audit:scan
security:audit:scannpm audit
security:snyksnyk
security:snyk:allnpm run security:snyk:auth && npm run security:snyk:monitor && npm run security:snyk:scan
security:snyk:authsnyk auth $SNYK_TOKEN
security:snyk:monitorsnyk monitor --org=commonality
security:snyk:scansnyk test
standard-versionstandard-version
testjest --config=jest.config.json
posttestnpm run security && npm run docs

14. DevSecOps

commonality/archetypes triggers Travis CI builds to execute the ESLint, the Jest test runner, and Node Security Platform (NSP) analysis. Code coverage reports are then sent to Coveralls and SonarCloud.

14.1. Builds

Travis CI

commonality/archetypes uses Travis CI for continuous integration.

For details, please review the .travis.yml build file.

14.2. Tests and quality gates

This repository enforces Swagger quality; Javascript quality; and Javascript unit tests and code coverage.

14.2.1. Swagger validation

Swagger

commonality/archetypes validates Swagger docs with swagger-cli.

swagger-cli validation runs before every test execution:

# These two npm-scripts run lint automatically:
$ npm run pretest

$ npm test

# Only lint the Party OpenAPI specification:
$ npm run lint:swagger:party

# You can also validate your Swagger docs independently with:
$ npm run lint:swagger:all

swagger-api/validator-badges display whether there are syntactic issues with you Swagger/OpenAPI 2.0 document.

14.2.2. Linting

ESLint

commonality/archetypes lints with ESLint and displays real-time results with README badges.

# Code quality analysis runs before every test execution:
$ npm test

# Only validate JavaScript and OpenAPI specs
$ npm run lint

# Only run ESLint:
$ npm run lint:js

14.3.3. Spec (unit test) execution and code coverage

Jest

commonality/archetypes uses jest for BDD spec execution and code coverage analysis. The results are displayed real-time with README badges.

Generate detailed code coverage reports at coverage/lcov-report/index.html and lcov.info and clover.xml files (which you can send to CI test coverage services like Coveralls and OneSonarQube or SonarCloud):

$ npm test

14.3.4. Deploy/Publish

Conventional Commits with Angular commit conventions

Contributors must follow the Angular commit conventions in order to support automated CHANGELOG, package.json, Git release tags, and semantic version updates.

14.3.4.1. Prerequisites

Once a PR has been approved (and passes all checks), topic branches are are merged into master on GitHub.

  1. On the GitHub PR page, select Squash and Merge.
  2. Add a <title>, <body>, and <footer> that comply with the Conventional Commits Specfication.

14.3.4.2. Publish on npm

When you're ready to release (i.e., publish to npm or a local Node package registry), open a Terminal and follow these steps:

  1. Checkout and pull the latest from master:
$ git checkout master; git pull origin master
  1. Create and document a new semantic version:
# The npm-script "release" executes standard-version
$ npm release

npm release executes an npm-script that will:

  1. Bump the version in package.json
  2. Update CHANGELOG.md (with conventional-changelog)
  3. Commit package.json and CHANGELOG.md
  4. Tag a new release

  5. Push all changes, the new version tag to master, and publish on npm:

$ git push --follow-tags origin master; npm publish

Read more... For standard-version configuration details, read "Cut a Release" on the conventional-changelog/standard-version's README page.

15. Style guides

15.1. JavaScript source code

JavaScript Style Guide

Whenever you run npm test, ESLint will automatically reformat your JavaScript to ensure that all souce code conforms to the JavaScript Standard Style.

Open a Terminal and run any of these commands to ensure your JavaScript source code meets the JavaScript Standard Style:

  • Only lint JavaScript source code (with ESLint):
# Runs eslint . --fix
$ npm run lint:js
  • Lint source and validate OpenAPI specs:
# Lint source and validate OpenAPI specs:
$ npm run pretest
  • Or run all quality gates (including source code linting):
# Or run lint and all other quality gates:
$ npm test

15.2. Color palette

The archetypes documentation uses this color palette:

Color palette

The colors are (from left to right):

  • #CFDBD5: Light Grey
  • #E8EDDF: Platinum
  • #F5CB5C: Stil de Grain Yellow
  • #242423: Raisin Black
  • #333533: Jet

View the palette as PDF, PNG, SCSS, or on coolors.com.

16. Semantic version and CHANGELOG

The latest version of commonality/archetypes is 0.0.0. View the CHANGELOG for details.

17. Contributing to commonality/archetypes

PRs Welcome We welcome contributors and pull requests!

Contributions are community-driven stories with a beginning, a middle, and an end, all told through issues, comments, and pull requests. If you're interested in collaborating, please review the:

17.1. Contribution workflows summarized

We use the Git feature-branch-workflow to accept modifications, where contributors:

  1. Create an issue related to the problem you want to fix (good for traceability and cross-reference)
  2. Label the issue as
    • Type: Defect or
    • Type: Feature
  3. Fork the repository
  4. Create a branch (optionally with the reference to the issue in the name)
  5. Work it
  6. Commit incrementally with readable and detailed commit messages
  7. Submit a pull-request against the master branch of this repository.

We'll take care of tagging your issue with the appropriated labels and answer within a week (hopefully less!) to the problem you encounter.

17.2. Contributors

Thanks goes to these wonderful people (emoji key):

Greg Swindle💻 🎨 📖 💡 ⚠️greenkeeper[bot]⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

18. Licenses

Apache-2.0 © Greg Swindle.

Third-party licenses: Please see the NOTICE document for 3rd-Party Software information, or select the FOSSA badge below.

FOSSA Status


Code Style Guide for JavaScript Conventional Commits Greenkeeper badge Readme Score StackShare

Graphic art by icons8.


1.0.0

7 years ago