Skip to content

Commit

Permalink
Merge pull request #2247 from stripe/latest-codegen-beta
Browse files Browse the repository at this point in the history
Update generated code for beta
  • Loading branch information
stripe-openapi[bot] authored Jan 18, 2025
2 parents ba774c3 + b23576b commit b67f513
Show file tree
Hide file tree
Showing 44 changed files with 795 additions and 373 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[justfile]
indent_size = 4
10 changes: 6 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,19 @@ module.exports = {
parserOptions: {
ecmaVersion: 2018,
},
plugins: ['prettier', 'import'],
extends: ['plugin:prettier/recommended'],
plugins: ['import'],
// disable formatting rules - prettier will handle this itself
extends: ['prettier'],
overrides: [
{
files: ['**/*.ts'],
plugins: ['@typescript-eslint', 'prettier'],
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
// disable formatting rules - prettier will handle this itself
'prettier',
],
rules: {
'@typescript-eslint/no-use-before-define': 0,
Expand Down
48 changes: 23 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ on:
- sdk-release/**
- feature/**


jobs:
build:
name: Build
runs-on: ubuntu-latest
name: 'Static Checks'
runs-on: 'ubuntu-24.04'

steps:
- uses: extractions/setup-just@v2
- uses: actions/checkout@v2

- name: Setup node
Expand All @@ -41,30 +41,32 @@ jobs:
restore-keys: |
${{ runner.os }}-yarn-
- name: Build Typescript
run: yarn && yarn build
- name: Verify Linting
run: just lint-check

- name: Lint
run: yarn lint
- name: Verify Formatting
run: just format-check

test:
name: Test (${{ matrix.node }})
needs: [build]
strategy:
fail-fast: false
matrix:
os:
- "ubuntu-latest"
- 'ubuntu-24.04'
node:
# should include even numbers >= 12
# see: https://nodejs.org/en/about/previous-releases
- "22"
- "20"
- "18"
- "16"
- "14"
- "12"
- '22'
- '20'
- '18'
- '16'
- '14'
- '12'
runs-on: ${{ matrix.os }}
steps:
- uses: extractions/setup-just@v2
- uses: actions/checkout@v2

- name: Setup node
Expand All @@ -75,6 +77,7 @@ jobs:
- name: Print Node.js version
run: node -v

# used for one of the integration tests
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
Expand All @@ -91,22 +94,15 @@ jobs:
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
# searching very deep deps can time out, so only cache on the root yarn.lock
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- uses: stripe/openapi/actions/stripe-mock@master

- name: Test
run: make ci-test

- name: Coveralls
run: yarn report && yarn coveralls
if: env.COVERALLS_REPO_TOKEN && matrix.node == '18'
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
COVERALLS_FLAG_NAME: node-${{ matrix.node }}
run: just ci-test

publish:
name: Publish
Expand All @@ -115,8 +111,10 @@ jobs:
startsWith(github.ref, 'refs/tags/v') &&
endsWith(github.actor, '-stripe')
needs: [build, test]
runs-on: ubuntu-latest
runs-on: 'ubuntu-24.04'
steps:
# just is called in `yarn prepack`, which is called during the `publish` operation
- uses: extractions/setup-just@v2
- uses: actions/checkout@v2
- run: sudo apt-get install -y oathtool
- name: Publish to NPM
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# internal files of the nextjs example
.next
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

# Contributing

We welcome bug reports, feature requests, and code contributions in a pull request.

For most pull requests, we request that you identify or create an associated issue that has the necessary context. We use these issues to reach agreement on an approach and save the PR author from having to redo work. Fixing typos or documentation issues likely do not need an issue; for any issue that introduces substantial code changes, changes the public interface, or if you aren't sure, please find or [create an issue](https://www.github.com/stripe/stripe-node/issues/new/choose).

## Contributor License Agreement

All contributors must sign the Contributor License Agreement (CLA) before we can accept their contribution. If you have not yet signed the agreement, you will be given an option to do so when you open a pull request. You can then sign by clicking on the badge in the comment from @CLAassistant.

## Generated code

This project has a combination of manually maintained code and code generated from our private code generator. If your contribution involves changes to generated code, please call this out in the issue or pull request as we will likely need to make a change to our code generator before accepting the contribution.

To identify files with purely generated code, look for the comment `File generated from our OpenAPI spec.` at the start of the file. Generated blocks of code within hand-written files will be between comments that say `The beginning of the section generated from our OpenAPI spec` and `The end of the section generated from our OpenAPI spec`.

## Compatibility with supported language and runtime versions

This project supports [many different langauge and runtime versions](README.md#requirements) and we are unable to accept any contribution that does not work on _all_ supported versions. If, after discussing the approach in the associated issue, your change must use an API / feature that isn't available in all supported versions, please call this out explicitly in the issue or pull request so we can help figure out the best way forward.

## Set up your dev environment

Please refer to this project's [README.md](README.md#development) for instructions on how to set up your development environment.

2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# NOTE: this file is deprecated and slated for deletion; prefer using the equivalent `just` commands.

.PHONY: codegen-format update-version test ci-test
update-version:
@echo "$(VERSION)" > VERSION
Expand Down
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1437
v1454
39 changes: 23 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![Version](https://img.shields.io/npm/v/stripe.svg)](https://www.npmjs.org/package/stripe)
[![Build Status](https://github.com/stripe/stripe-node/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/stripe/stripe-node/actions?query=branch%3Amaster)
[![Coverage Status](https://coveralls.io/repos/github/stripe/stripe-node/badge.svg?branch=master)](https://coveralls.io/github/stripe/stripe-node?branch=master)
[![Downloads](https://img.shields.io/npm/dm/stripe.svg)](https://www.npmjs.com/package/stripe)
[![Try on RunKit](https://badge.runkitcdn.com/stripe.svg)](https://runkit.com/npm/stripe)

Expand Down Expand Up @@ -597,16 +596,9 @@ New features and bug fixes are released on the latest major version of the `stri

## Development

Run all tests:
[Contribution guidelines for this project](CONTRIBUTING.md)

```bash
$ yarn install
$ yarn test
```

If you do not have `yarn` installed, you can get it with `npm install --global yarn`.

The tests also depends on [stripe-mock][stripe-mock], so make sure to fetch and
The tests depend on [stripe-mock][stripe-mock], so make sure to fetch and
run it from a background terminal ([stripe-mock's README][stripe-mock-usage]
also contains instructions for installing via Homebrew and other methods):

Expand All @@ -615,32 +607,47 @@ go get -u github.com/stripe/stripe-mock
stripe-mock
```

Run a single test suite without a coverage report:
We use [just](https://github.com/casey/just) for conveniently running development tasks. You can use them directly, or copy the commands out of the `justfile`. To our help docs, run `just`.

Run all tests (installing the dependencies first, if needed)

```bash
just test
# or: yarn && yarn test
```

If you do not have `yarn` installed, consult its [installation instructions](https://classic.yarnpkg.com/lang/en/docs/install/).

Run a single test suite:

```bash
$ yarn mocha-only test/Error.spec.ts
just test test/Error.spec.ts
# or: yarn test test/Error.spec.ts
```

Run a single test (case sensitive) in watch mode:

```bash
$ yarn mocha-only test/Error.spec.ts --grep 'Populates with type' --watch
just test test/Error.spec.ts --grep 'StripeError' --watch
# or: yarn test test/Error.spec.ts --grep 'StripeError' --watch
```

If you wish, you may run tests using your Stripe _Test_ API key by setting the
environment variable `STRIPE_TEST_API_KEY` before running the tests:

```bash
$ export STRIPE_TEST_API_KEY='sk_test....'
$ yarn test
export STRIPE_TEST_API_KEY='sk_test....'
just test
# or: yarn test
```

Run prettier:

Add an [editor integration](https://prettier.io/docs/en/editors.html) or:

```bash
$ yarn fix
just format
# or: yarn prettier src/**/*.ts --write
```

[api-keys]: https://dashboard.stripe.com/account/apikeys
Expand Down
81 changes: 81 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
set quiet

import? '../sdk-codegen/utils.just'

# make locally installed binaries available throughout the tree without a longer specifier
# this is useful in this file, but also depended on by webhook tests that expect to be able to call `eslint` and (I think) don't set it up correctly themselves.
export PATH := `pwd` + "/node_modules/.bin:" + env('PATH')

_default:
just --list --unsorted

# this uses positional-args so that mixed quoted and unquoted arguments
# (like filtering for a certain test) work the way we expect
# ⭐ run unit tests
[positional-arguments]
test *args: install build
mocha "$@"

# try to compile the example TS file to make sure exports work
types-test: build
tsc --build types/test

# run full integration tests by installing a bunch of packages and starting servers (slow)
integrations-test: build
RUN_INTEGRATION_TESTS=1 mocha test/Integration.spec.ts

# run the full test suite; you probably want `test`
ci-test: install test types-test integrations-test

_build mode packageType: install
mkdir -p {{ mode }}
tsc -p tsconfig.{{ mode }}.json
echo '{"type":"{{ packageType }}"}' > {{ mode }}/package.json

[private]
build-esm: (_build "esm" "module")

[private]
build-cjs: (_build "cjs" "commonjs")

# generate CJS and ESM versions of the package; mostly used as a pre-req for other steps
build: build-esm build-cjs

# ⭐ run style checks, fixing issues if possible
lint: (lint-check "--fix")

# run style checks without changing anything
lint-check *args: install
eslint --ext .js,.ts . {{ args }}

# reinstall dependencies, if needed
install:
yarn {{ if is_dependency() == "true" { "--silent" } else { "" } }}

[no-exit-message]
[private]
prettier *args: install
# all the project-relevant JS code
prettier "{src,examples,scripts,test,types}/**/*.{ts,js}" {{ args }}

# ⭐ format all files
format: (prettier "--write --loglevel silent") _update-api-version

# verify formatting of files (without changes)
format-check: (prettier "--check")

# propagate automatic changes; should be run after generation
# in practice, that means it runs after formatting, since that's the only recipe that the generator calls
_update-api-version:
./scripts/updateAPIVersion.js

# called by tooling
[private]
update-version version:
echo "{{ version }}" > VERSION
perl -pi -e 's|"version": "[.\-\d\w]+"|"version": "{{ version }}"|' package.json
perl -pi -e "s|Stripe.PACKAGE_VERSION = '[.\-\d\w]+'|Stripe.PACKAGE_VERSION = '{{ version }}'|" src/stripe.core.ts

# remove build artifacts
clean:
rm -rf ./node_modules/.cache ./esm ./cjs
16 changes: 2 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"@typescript-eslint/parser": "^4.33.0",
"chai": "^4.3.6",
"chai-as-promised": "~7.1.1",
"coveralls": "^3.1.1",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-chai-friendly": "^0.7.2",
Expand All @@ -60,19 +59,8 @@
},
"license": "MIT",
"scripts": {
"build": "yarn build-esm && yarn build-cjs",
"build-esm": "mkdir -p esm && tsc -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > esm/package.json",
"build-cjs": "mkdir -p cjs && tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > cjs/package.json",
"clean": "rm -rf ./.nyc_output ./node_modules/.cache ./coverage ./esm ./cjs",
"prepack": "yarn install && yarn build",
"mocha": "nyc mocha",
"mocha-only": "mocha",
"test": "yarn build && yarn test-typescript && yarn mocha",
"test-typescript": "tsc --build types/test",
"lint": "eslint --ext .js,.jsx,.ts .",
"fix": "yarn lint --fix && ./scripts/updateAPIVersion.js",
"report": "nyc -r text -r lcov report",
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
"test": "tsc -p tsconfig.cjs.json && mocha",
"prepack": "just install && just build"
},
"exports": {
"types": "./types/index.d.ts",
Expand Down
7 changes: 6 additions & 1 deletion scripts/updateAPIVersion.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/usr/bin/env node

/**
* Reads the current API version from src/apiVersion.ts and updates all
* references to it in the types/ directory.
*/

/* eslint-disable no-sync,no-nested-ternary */
const fs = require('fs');
const path = require('path');
Expand All @@ -12,7 +17,7 @@ const API_VERSION = '2[0-9][2-9][0-9]-[0-9]{2}-[0-9]{2}.[a-z]+';

const main = () => {
const matches = [
...read('src/apiVersion.ts').matchAll(/ApiVersion . '([^']*)'/g),
...read('src/apiVersion.ts').matchAll(/ApiVersion = '([^']*)'/g),
];
if (matches.length !== 1) {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion src/apiVersion.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// File generated from our OpenAPI spec

export const ApiVersion = '2024-12-18.acacia';
export const ApiVersion = '2025-01-27.acacia';
Loading

0 comments on commit b67f513

Please sign in to comment.