From 50b471c385fff76a36223a67b9b7a2312dafdbe8 Mon Sep 17 00:00:00 2001 From: Loic Gouttefangeas Date: Wed, 4 Mar 2026 15:47:56 +0100 Subject: [PATCH] build(ci): Update SDK generation method --- .github/workflows/pr.yaml | 12 +- .github/workflows/release.yaml | 13 +- .github/workflows/update.yaml | 32 +- package-lock.json | 633 ++++++++++++++++++++++++++++++++- package.json | 7 +- rebilly-php.config.ts | 293 +++++++++++++++ 6 files changed, 968 insertions(+), 22 deletions(-) create mode 100644 rebilly-php.config.ts diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index e80046047..c7e3af187 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -101,16 +101,20 @@ jobs: with: fetch-depth: 0 - - name: Setup Node.js 20 - if: ${{ ! startsWith(github.head_ref, 'changeset-release/') }} - uses: actions/setup-node@v3 + - name: Setup Node.js + uses: actions/setup-node@v6 with: node-version: 20 - cache: 'npm' + cache: "npm" + registry-url: "https://npm.pkg.github.com/" + scope: "@rebilly" + cache-dependency-path: "package-lock.json" - name: Install Dependencies if: ${{ ! startsWith(github.head_ref, 'changeset-release/') }} run: npm ci + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Check Changesets if: ${{ ! startsWith(github.head_ref, 'changeset-release/') }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 48b7d69e1..37274b226 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -5,7 +5,7 @@ on: branches: - main -concurrency: +concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true @@ -20,14 +20,19 @@ jobs: fetch-depth: 0 token: ${{ secrets.MACHINE_USER_PAT }} - - name: Setup Node.js 20 - uses: actions/setup-node@v3 + - name: Setup Node.js + uses: actions/setup-node@v6 with: node-version: 20 - cache: 'npm' + cache: "npm" + registry-url: "https://npm.pkg.github.com/" + scope: "@rebilly" + cache-dependency-path: "package-lock.json" - name: Install Dependencies run: npm ci + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create Release Pull Request uses: changesets/action@v1 diff --git a/.github/workflows/update.yaml b/.github/workflows/update.yaml index 3446c653a..6769b896f 100644 --- a/.github/workflows/update.yaml +++ b/.github/workflows/update.yaml @@ -53,6 +53,16 @@ jobs: extensions: mbstring, intl, curl, json tools: composer:v2 + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: 24 + cache: "npm" + registry-url: "https://npm.pkg.github.com/" + scope: "@rebilly" + cache-dependency-path: "sdk/package-lock.json" + + - name: Install api-definitions dependencies working-directory: ./api-definitions run: npm install @@ -68,20 +78,18 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.MACHINE_USER_PAT }} + - name: Install Dependencies + working-directory: ./sdk + run: npm ci --dev + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Build SDK + working-directory: ./sdk run: | mkdir /tmp/sdk - docker run --rm \ - -u $(id -u ${USER}):$(id -g ${USER}) \ - -v "/tmp/sdk:/out" \ - -v "$(pwd)/api-definitions/catalog:/api-definitions" \ - ghcr.io/rebilly/regenerator:latest generate \ - -g rebilly-php \ - -D /out/openapi.json \ - -o /out \ - -C '{"rootNameSpace": "Rebilly.Sdk", "customOperationGroupMapping": "/shared/custom-resource-names.json"}' \ - "/api-definitions/all.yaml" - ls -lAh /tmp/ /tmp/sdk/ + rm -rf src + npm run generate /tmp/sdk ../api-definitions/catalog/all.yaml - name: Bundle SDK run: | @@ -129,6 +137,8 @@ jobs: echo "Added a patch changeset '${CHANGESET_ID}': '${{ github.event.inputs.trigger-reason }}'" echo "id=${CHANGESET_ID}" >> $GITHUB_OUTPUT fi + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create PR id: cpr diff --git a/package-lock.json b/package-lock.json index b7ee21f48..2dd27ac70 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,9 @@ "version": "3.1.6", "devDependencies": { "@changesets/cli": "^2.26.2", - "@changesets/write": "^0.2.3" + "@changesets/write": "^0.2.3", + "@rebilly/regenerator": "^0.0.4", + "ts-node": "^10.9.2" } }, "node_modules/@babel/code-frame": { @@ -288,6 +290,64 @@ "prettier": "^2.7.1" } }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.27.3.tgz", + "integrity": "sha512-Czi8yzXUWIQYAtL/2y6vogER8pvcsOsk5cpwL4Gk5nJqH5UZiVByIY8Eorm5R13gq+DQKYg0+JyQoytLQas4dA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", + "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", + "dev": true, + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@manypkg/find-root": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@manypkg/find-root/-/find-root-1.1.0.tgz", @@ -383,6 +443,138 @@ "node": ">= 8" } }, + "node_modules/@rebilly/regenerator": { + "version": "0.0.4", + "resolved": "https://npm.pkg.github.com/download/@rebilly/regenerator/0.0.4/849c7344b7d18dfa1a7c6219c2e692b450e7f6bb", + "integrity": "sha512-3Q12MnBzhoeU54TfVLE9bKV8y4cM7qsjY9KHT95qDz2uIe+a+1HuKBKdVhoXXFs0fB4xJUaiMvi+hsZ0VIM9Tw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@redocly/openapi-core": "^2.3.1", + "es-toolkit": "^1.39.10", + "handlebars": "^4.7.8", + "tsx": "^4.20.3", + "yargs": "^17.7.2" + }, + "bin": { + "regenerator": "lib/index.js" + }, + "engines": { + "node": ">=15.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@redocly/ajv": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/@redocly/ajv/-/ajv-8.18.0.tgz", + "integrity": "sha512-F+LMD2IDIXuHxgpLJh3nkLj9+tSaEzoUWd+7fONGq5pe2169FUDjpEkOfEpoGLz1sbZni/69p07OsecNfAOpqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/@redocly/config": { + "version": "0.44.0", + "resolved": "https://registry.npmjs.org/@redocly/config/-/config-0.44.0.tgz", + "integrity": "sha512-UHKkWcCNZrGiKBbrQ1CE08ElrOUGm5H97Zn8+wkp80Uu2AT/go5In1sbqvhHxViPYtu1MLdy7qKiifSyOL3W/A==", + "dev": true, + "license": "MIT", + "dependencies": { + "json-schema-to-ts": "2.7.2" + } + }, + "node_modules/@redocly/openapi-core": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/@redocly/openapi-core/-/openapi-core-2.20.3.tgz", + "integrity": "sha512-i+yVsGvieqfL5ySq9N0+qQ1nxNTW0e1uTH9B+EIgkWNogV6Fuj1tcMZKlhUX7CGRIOZ+lR1AXDcAFuWVYlp9YA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@redocly/ajv": "^8.18.0", + "@redocly/config": "^0.44.0", + "ajv": "npm:@redocly/ajv@8.18.0", + "ajv-formats": "^3.0.1", + "colorette": "^1.2.0", + "js-levenshtein": "^1.1.6", + "js-yaml": "^4.1.0", + "picomatch": "^4.0.3", + "pluralize": "^8.0.0", + "yaml-ast-parser": "0.0.43" + }, + "engines": { + "node": ">=22.12.0 || >=20.19.0 <21.0.0", + "npm": ">=10" + } + }, + "node_modules/@redocly/openapi-core/node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true, + "license": "Python-2.0" + }, + "node_modules/@redocly/openapi-core/node_modules/js-yaml": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz", + "integrity": "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==", + "dev": true, + "license": "MIT", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/@redocly/openapi-core/node_modules/picomatch": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", + "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/@tsconfig/node10": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.12.tgz", + "integrity": "sha512-UCYBaeFvM11aU2y3YPZ//O5Rhj+xKyzy7mvcIoAjASbigy8mHMryP5cK7dgjlz2hWxh1g5pLw084E0a/wlUSFQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true, + "license": "MIT" + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/is-ci": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/@types/is-ci/-/is-ci-3.0.2.tgz", @@ -392,6 +584,13 @@ "ci-info": "^3.1.0" } }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/minimist": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.3.tgz", @@ -416,6 +615,68 @@ "integrity": "sha512-OxepLK9EuNEIPxWNME+C6WwbRAOOI2o2BaQEGzz5Lu2e4Z5eDnEo+/aVEDMIXywoJitJ7xWd641wrGLZdtwRyw==", "dev": true }, + "node_modules/acorn": { + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", + "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-walk": { + "version": "8.3.5", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.5.tgz", + "integrity": "sha512-HEHNfbars9v4pgpW6SO1KSPkfoS0xVOM/9UzkJltjlsHZmJasxg8aXkuZa7SMf8vKGIBhpUsPluQSqhJFCqebw==", + "dev": true, + "license": "MIT", + "dependencies": { + "acorn": "^8.11.0" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/ajv": { + "name": "@redocly/ajv", + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/@redocly/ajv/-/ajv-8.18.0.tgz", + "integrity": "sha512-F+LMD2IDIXuHxgpLJh3nkLj9+tSaEzoUWd+7fONGq5pe2169FUDjpEkOfEpoGLz1sbZni/69p07OsecNfAOpqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, "node_modules/ansi-colors": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", @@ -446,6 +707,13 @@ "node": ">=4" } }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true, + "license": "MIT" + }, "node_modules/argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -682,6 +950,20 @@ "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, + "node_modules/colorette": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.4.0.tgz", + "integrity": "sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==", + "dev": true, + "license": "MIT" + }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true, + "license": "MIT" + }, "node_modules/cross-spawn": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", @@ -828,6 +1110,16 @@ "node": ">=8" } }, + "node_modules/diff": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.4.tgz", + "integrity": "sha512-X07nttJQkwkfKfvTPG/KSnE2OMdcUCao6+eXF3wmnIQRn2aPAHH3VxDbDOdegkd6JbPsXqShpvEOHfAT+nCNwQ==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/dir-glob": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", @@ -961,6 +1253,59 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/es-toolkit": { + "version": "1.45.1", + "resolved": "https://registry.npmjs.org/es-toolkit/-/es-toolkit-1.45.1.tgz", + "integrity": "sha512-/jhoOj/Fx+A+IIyDNOvO3TItGmlMKhtX8ISAHKE90c4b/k1tqaqEZ+uUqfpU8DMnW5cgNJv606zS55jGvza0Xw==", + "dev": true, + "license": "MIT", + "workspaces": [ + "docs", + "benchmarks" + ] + }, + "node_modules/esbuild": { + "version": "0.27.3", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.3.tgz", + "integrity": "sha512-8VwMnyGCONIs6cWue2IdpHxHnAjzxnw2Zr7MkVxB2vjmQ2ivqGFb4LEG3SMnv0Gb2F/G/2yA8zUaiL1gywDCCg==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.27.3", + "@esbuild/android-arm": "0.27.3", + "@esbuild/android-arm64": "0.27.3", + "@esbuild/android-x64": "0.27.3", + "@esbuild/darwin-arm64": "0.27.3", + "@esbuild/darwin-x64": "0.27.3", + "@esbuild/freebsd-arm64": "0.27.3", + "@esbuild/freebsd-x64": "0.27.3", + "@esbuild/linux-arm": "0.27.3", + "@esbuild/linux-arm64": "0.27.3", + "@esbuild/linux-ia32": "0.27.3", + "@esbuild/linux-loong64": "0.27.3", + "@esbuild/linux-mips64el": "0.27.3", + "@esbuild/linux-ppc64": "0.27.3", + "@esbuild/linux-riscv64": "0.27.3", + "@esbuild/linux-s390x": "0.27.3", + "@esbuild/linux-x64": "0.27.3", + "@esbuild/netbsd-arm64": "0.27.3", + "@esbuild/netbsd-x64": "0.27.3", + "@esbuild/openbsd-arm64": "0.27.3", + "@esbuild/openbsd-x64": "0.27.3", + "@esbuild/openharmony-arm64": "0.27.3", + "@esbuild/sunos-x64": "0.27.3", + "@esbuild/win32-arm64": "0.27.3", + "@esbuild/win32-ia32": "0.27.3", + "@esbuild/win32-x64": "0.27.3" + } + }, "node_modules/escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -1012,6 +1357,13 @@ "node": ">=4" } }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true, + "license": "MIT" + }, "node_modules/fast-glob": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz", @@ -1028,6 +1380,23 @@ "node": ">=8.6.0" } }, + "node_modules/fast-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.0.tgz", + "integrity": "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, "node_modules/fastq": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", @@ -1168,6 +1537,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-tsconfig": { + "version": "4.13.6", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.6.tgz", + "integrity": "sha512-shZT/QMiSHc/YBLxxOkMtgSid5HFoauqCE3/exfsEcwg1WkeqjG+V40yBbBrsD+jW2HDXcs28xOfcbm2jI8Ddw==", + "dev": true, + "license": "MIT", + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, "node_modules/glob-parent": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", @@ -1239,6 +1621,28 @@ "integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==", "dev": true }, + "node_modules/handlebars": { + "version": "4.7.8", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz", + "integrity": "sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "minimist": "^1.2.5", + "neo-async": "^2.6.2", + "source-map": "^0.6.1", + "wordwrap": "^1.0.0" + }, + "bin": { + "handlebars": "bin/handlebars" + }, + "engines": { + "node": ">=0.4.7" + }, + "optionalDependencies": { + "uglify-js": "^3.1.4" + } + }, "node_modules/hard-rejection": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/hard-rejection/-/hard-rejection-2.1.0.tgz", @@ -1674,6 +2078,16 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, + "node_modules/js-levenshtein": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz", + "integrity": "sha512-X2BB11YZtrRqY4EnQcLX5Rh373zbK4alC1FW7D7MBhL2gtcC17cTnr6DmfHZeS0s2rTHjUTMMHfG7gO8SSdw+g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -1700,6 +2114,28 @@ "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", "dev": true }, + "node_modules/json-schema-to-ts": { + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/json-schema-to-ts/-/json-schema-to-ts-2.7.2.tgz", + "integrity": "sha512-R1JfqKqbBR4qE8UyBR56Ms30LL62/nlhoz+1UkfI/VE7p54Awu919FZ6ZUPG8zIa3XB65usPJgr1ONVncUGSaQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.18.3", + "@types/json-schema": "^7.0.9", + "ts-algebra": "^1.2.0" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "dev": true, + "license": "MIT" + }, "node_modules/jsonfile": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", @@ -1778,6 +2214,13 @@ "node": ">=10" } }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true, + "license": "ISC" + }, "node_modules/map-obj": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-4.3.0.tgz", @@ -1846,6 +2289,16 @@ "node": ">=4" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/minimist-options": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/minimist-options/-/minimist-options-4.1.0.tgz", @@ -1869,6 +2322,13 @@ "node": ">= 8.0.0" } }, + "node_modules/neo-async": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", + "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", + "dev": true, + "license": "MIT" + }, "node_modules/normalize-package-data": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", @@ -2073,6 +2533,16 @@ "node": ">=8" } }, + "node_modules/pluralize": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-8.0.0.tgz", + "integrity": "sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/preferred-pm": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/preferred-pm/-/preferred-pm-3.1.2.tgz", @@ -2309,6 +2779,16 @@ "node": ">=0.10.0" } }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/require-main-filename": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", @@ -2341,6 +2821,16 @@ "node": ">=8" } }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, "node_modules/reusify": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", @@ -2603,6 +3093,16 @@ "node": ">=8" } }, + "node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/spawndamnit": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/spawndamnit/-/spawndamnit-2.0.0.tgz", @@ -2821,6 +3321,77 @@ "node": ">=8" } }, + "node_modules/ts-algebra": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/ts-algebra/-/ts-algebra-1.2.2.tgz", + "integrity": "sha512-kloPhf1hq3JbCPOTYoOWDKxebWjNb2o/LKnNfkWhxVVisFFmMJPPdJeGoGmM+iRLyoXAR61e08Pb+vUXINg8aA==", + "dev": true, + "license": "MIT" + }, + "node_modules/ts-node": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/tsx": { + "version": "4.21.0", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.21.0.tgz", + "integrity": "sha512-5C1sg4USs1lfG0GFb2RLXsdpXqBSEhAaA/0kPL01wxzpMqLILNxIxIOKiILz+cdg/pLnOUxFYOR5yhHU666wbw==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "~0.27.0", + "get-tsconfig": "^4.7.5" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, "node_modules/tty-table": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/tty-table/-/tty-table-4.2.2.tgz", @@ -2989,6 +3560,35 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/uglify-js": { + "version": "3.19.3", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.19.3.tgz", + "integrity": "sha512-v3Xu+yuwBXisp6QYTcH4UbH+xYJXqnq2m/LtQVWKWzYc1iehYnLixoQDN9FH6/j9/oybfd6W9Ghwkl8+UMKTKQ==", + "dev": true, + "license": "BSD-2-Clause", + "optional": true, + "bin": { + "uglifyjs": "bin/uglifyjs" + }, + "engines": { + "node": ">=0.8.0" + } + }, "node_modules/unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -3013,6 +3613,13 @@ "node": ">= 4.0.0" } }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true, + "license": "MIT" + }, "node_modules/validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", @@ -3098,6 +3705,13 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/wordwrap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", + "integrity": "sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==", + "dev": true, + "license": "MIT" + }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -3163,6 +3777,13 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, + "node_modules/yaml-ast-parser": { + "version": "0.0.43", + "resolved": "https://registry.npmjs.org/yaml-ast-parser/-/yaml-ast-parser-0.0.43.tgz", + "integrity": "sha512-2PTINUwsRqSd+s8XxKaJWQlUuEMHJQyEuh2edBbW8KNJz0SJPwUSD2zRWqezFEdN7IzAgeuYHFUCF7o8zRdZ0A==", + "dev": true, + "license": "Apache-2.0" + }, "node_modules/yargs": { "version": "17.7.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", @@ -3203,6 +3824,16 @@ "node": ">=12" } }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index 2e055ba90..3b1b0de8e 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,12 @@ "version": "3.1.6", "devDependencies": { "@changesets/cli": "^2.26.2", - "@changesets/write": "^0.2.3" + "@changesets/write": "^0.2.3", + "@rebilly/regenerator": "^0.0.4", + "ts-node": "^10.9.2" }, "scripts": { - "version": "npx changeset version && npm i && node scripts/update-sdk-version.js" + "version": "npx changeset version && npm i && node scripts/update-sdk-version.js", + "generate": "regenerator generate -g rebilly-php -o" } } diff --git a/rebilly-php.config.ts b/rebilly-php.config.ts new file mode 100644 index 000000000..efc3d1fa2 --- /dev/null +++ b/rebilly-php.config.ts @@ -0,0 +1,293 @@ +import { + GeneratorConfig, + Operation, + Model, + appendImport, + PHPCodeGen, + AnyStaticContext, + PhpPropertyType, fqcnToClassName, nullFirstTypeComparator, onlyUnique, +} from '@rebilly/regenerator'; + + +export function typesToTypeHints(types: PhpPropertyType[], consume: boolean): string | null { + if (types.length === 0) { + return null; + } + const typeHints: string[] = []; + let hadContainedType = false; + for (const type of types) { + if (!type.containedTypes) { + typeHints.push(fqcnToClassName(type.name)); + } else if (type.isDictionary) { + const dictionaryInnerHint = typesToTypeHints(type.containedTypes, consume); + typeHints.push(dictionaryInnerHint ? `array` : 'array'); + hadContainedType = dictionaryInnerHint !== null; + } else { + for (const containedType of type.containedTypes) { + hadContainedType = true; + typeHints.push( + type.isModel + ? `${fqcnToClassName(type.name)}<${fqcnToClassName(containedType.name)}>` + : fqcnToClassName(containedType.name) + '[]', + ); + if (!consume) { + continue; + } + if (containedType.isModel) { + typeHints.push('array[]'); + } else if (containedType.name === 'DateTimeImmutable' || containedType.name === 'float') { + typeHints.push('string[]'); + } + } + } + } + const uniqueTypeHints = typeHints.filter(onlyUnique); + if ( + !consume && + !hadContainedType && + uniqueTypeHints.length === 2 && + uniqueTypeHints.some((name) => name === 'null') + ) { + return '?' + uniqueTypeHints.find((name) => name !== 'null'); + } + + return uniqueTypeHints.sort(nullFirstTypeComparator).join('|'); +} + +const config: GeneratorConfig = { + packageInfo: { + name: 'rebilly/client-php', + description: 'Rebilly PHP Client', + keywords: ['payment processing', 'api', 'transactions', 'subscriptions'], + homepage: 'http://rebilly.com/', + authors: [ + { + name: 'Rebilly', + homepage: 'https://github.com/rebilly', + }, + ], + autoload: { + 'psr-4': { + 'Rebilly\\Sdk\\': 'src', + }, + }, + 'autoload-dev': { + 'psr-4': { + 'Rebilly\\Sdk\\Tests\\': ['tests', 'examples'], + }, + }, + scripts: { + test: 'phpunit', + 'diff-files': 'f() { git diff --name-only --diff-filter=ACMRTUXB $1 | grep -i \\.php$ ; }; f', + cs: 'php-cs-fixer fix -vv --dry-run || true', + 'cs-fix': 'php-cs-fixer fix -vv || true', + 'cs-feature': 'composer cs -- "$(composer diff-files origin/main)"', + 'cs-fix-feature': 'composer cs-fix -- "$(composer diff-files origin/main)"', + 'cs-changes': 'composer cs -- "$(composer diff-files HEAD)"', + 'cs-fix-changes': 'composer cs-fix -- "$(composer diff-files HEAD)"', + }, + extra: { + 'branch-alias': { + 'dev-main': '3.x-dev', + 'dev-v2.x': '2.x-dev', + }, + }, + }, + + buildConfig: { + outputFilename: 'rebilly-php', + }, + + rootNameSpace: 'Rebilly\\Sdk', + + customTemplates: { + models: { + ConfigurablePlan: (model: Model) => ({ + 'model-factory-ConfigurablePlan.php.handlebars': `src/Model/${model.className}Factory.php`, + }), + FlexiblePlan: (model: Model) => ({ + 'model-factory-Plan.php.handlebars': `src/Model/${model.className}Factory.php`, + }), + Plan: (model: Model) => ({ + 'model-factory-Plan.php.handlebars': `src/Model/${model.className}Factory.php`, + }), + }, + }, + + codegen: { + processOperation: >(operation: T, context: any): T => { + for (const response of operation.responses) { + if ( + response.responseType?.some((type: any) => type.containedTypes) && + operation.arguments.has('limit') && + operation.arguments.has('offset') + ) { + appendImport(operation.imports, [ + { + source: context.rootNameSpace, + target: 'Collection', + isDefault: false, + }, + { + source: context.rootNameSpace, + target: 'Paginator', + isDefault: false, + }, + ]); + } + if (response.mimeType === 'application/pdf') { + appendImport(operation.imports, { + source: 'Psr\\Http\\Message', + target: 'StreamInterface', + isDefault: false, + }); + } + } + + return operation; + }, + }, + + operationTemplates: (operation: Operation, defaultTemplates: any[]): any[] => { + const templates = [...defaultTemplates]; + + for (const response of operation.responses) { + switch (response.mimeType) { + case 'application/json': + if ( + response.responseType?.some((type: any) => type.containedTypes) && + operation.arguments.has('limit') && + operation.arguments.has('offset') + ) { + const allContainedTypes: any[] = []; + for (const type of response.responseType) { + const containedTypes = type.containedTypes as any[] | undefined; + if (containedTypes) { + allContainedTypes.push(...containedTypes); + } + } + + templates.push({ + name: 'operation-json-collection', + context: { + methodName: operation.methodName, + accept: response.mimeType, + returnType: 'Collection', + returnTypeHint: typesToTypeHints( + [ + { + name: 'Collection', + format: null, + isPrimitive: false, + isStdLib: false, + isModel: true, + containedTypes: allContainedTypes, + isDictionary: false, + }, + ], + false, + ), + responseType: response.responseType, + }, + }); + + templates.push({ + name: 'operation-paginator', + context: { + methodName: `${operation.methodName}Paginator`, + originalMethodName: operation.methodName, + accept: response.mimeType, + returnType: 'Paginator', + returnTypeHint: typesToTypeHints( + [ + { + name: 'Paginator', + format: null, + isPrimitive: false, + isStdLib: false, + isModel: true, + containedTypes: allContainedTypes, + isDictionary: false, + }, + ], + false, + ), + }, + }); + + const jsonArrayOperations = templates.findIndex( + (template: any) => template.name === 'operation-json-array', + ); + if (jsonArrayOperations !== -1) { + templates.splice(jsonArrayOperations, 1); + } + } + break; + + case 'application/pdf': + templates.push({ + name: 'operation-pdf', + context: { + methodName: `${operation.methodName}Pdf`, + accept: response.mimeType, + returnType: 'StreamInterface', + }, + }); + break; + } + } + + return templates; + }, + + staticTemplates: (context: any, defaultTemplates: any[]): any[] => { + // TODO: use servers in Rebilly PHP SDK + const filteredDefaults = defaultTemplates.filter( + (template: any) => + ![ + 'static/src/ApiServer.php.handlebars', + 'static/src/ApiServerVariable.php.handlebars', + ].includes(template.name), + ); + + const rebillyStaticFiles = [ + { + name: 'static/src/Collection.php.handlebars', + targetLocation: 'src/Collection.php', + context, + }, + { + name: 'static/src/Paginator.php.handlebars', + targetLocation: 'src/Paginator.php', + context, + }, + { + name: 'static/src/CombinedService.php.handlebars', + targetLocation: 'src/CombinedService.php', + context, + }, + { + name: 'static/src/Exception/DataValidationException.php.handlebars', + targetLocation: 'src/Exception/DataValidationException.php', + context, + }, + { + name: 'static/src/Middleware/BaseUri.php.handlebars', + targetLocation: 'src/Middleware/BaseUri.php', + context, + }, + ]; + + return [...filteredDefaults, ...rebillyStaticFiles]; + }, + + partials: { + 'operation-json-collection': 'operation-json-collection.php.handlebars', + 'operation-paginator': 'operation-paginator.php.handlebars', + 'operation-pdf': 'operation-pdf.php.handlebars', + }, + + templateDirs: ['@bundled/rebilly-php'], +}; + +export default config;