0.0.13 • Published 1 year ago

@okeeffed/postman-tools v0.0.13

Weekly downloads
-
License
CC-BY-NC-4.0
Repository
-
Last release
1 year ago

Postman tools

Simple tools to generate local Postman files.

Useful for drag-and-drop updates when you don't have an API Key available to you.

Roadmap

  • Generate environments
  • Generate collections from Swagger files
  • Initialize configuration file
  • Support multi-environment configurations.
  • Support more overrides.
  • Support switching off query variables across all endpoints by default.
  • Support scripts.

Getting started

# Run help
$ npm i -D @okeeffed/postman-tools
$ npx @okeeffed/postman-tools --help

Setup a configuration file.

$ npx @okeeffed/postman-tools init
INFO Attempting to initialise
CREATED .../.postmanrc.ts

An example configuration:

import type { PostmanConfiguration } from "./src/types";

const stages = ["dev", "stage", "sandbox", "prod"] as const;

export default {
  stages,
  environment: {
    name: "Example environment",
    values: [
      {
        key: "example",
        type: "default",
        default: "default",
        dev: "dev-only-env-value",
        stage: "stage-only-env-value",
        sandbox: "sandbox-only-env-value",
        prod: "prod-only-env-value",
      },
      {
        key: "secret",
        type: "secret",
        default: "this is a secret value",
      },
    ],
  },
  collection: [
    {
      in: "tmp/swagger-alt.json",
      out: "postman.collection.json",
      baseUrl: "{{URL}}",
      headers: {
        "x-correlation-id": "{{$guid}}",
        "x-api-key": "{{API_KEY}}",
      },
      auth: {
        type: "bearer",
        bearer: [
          {
            key: "token",
            value: "{{BEARER_TOKEN}}",
            type: "string",
          },
        ],
      },
    },
  ],
} satisfies PostmanConfiguration<typeof stages>;

Run a test to generate the environment configurations:

$ npx @okeeffed/postman-tools env:generate

INFO Generating environment variables...
GENERATED /.../exampleEnvironment.dev.env.json
GENERATED /.../exampleEnvironment.stage.env.json
GENERATED /.../exampleEnvironment.sandbox.env.json
GENERATED /.../exampleEnvironment.prod.env.json
INFO Finished generating environment variables JSON files

For generating a Postman collection.

$ npx @okeeffed/postman-tools env:generate

INFO Generating Postman collection...
GENERATED postman.collection.json

Configuration

There are three top-level configuration options:

OptionsDoes
stagesDefines the different stage environments you need to support
environmentObject for defining different environment configurations
collectionArray of objects for supporting multiple OpenAPI spec input files

Things to note:

  • Define stages as a const e.g. ["dev"] as const to get the type benefits within the configuration.
  • environment.values object relies on the stages type. If you define dev as a stage, it will be available as a key for a "dev" environment value override.
  • For collection[number], you should define a different in and out file.

Caveats

The override configurations (e.g. headers, auth) will apply to all endpoints.

I will consider making this more flexible (with likely breaking changes), but for now you are best configuring it with the overrides that are likely necessary for each endpoint.

Repo todo

  • Clean up repo configuration for build
  • Set some standard generator files
  • Automate releases with GitHub actions
0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago