UNPKG

@swell/cli

Version:

Swell's command line interface/utility

44 lines (43 loc) 1.75 kB
import { Args, Flags } from '@oclif/core'; import { HttpMethod } from '../../lib/api.js'; import { SwellApiCommand, headerFlag } from '../../swell-api-command.js'; export default class ApiPost extends SwellApiCommand { static summary = 'Send a POST request to the Swell API.'; static description = `Create new resources in the Swell API. You can provide a JSON body directly or specify a file path containing JSON data. Use --api frontend for public key authentication scoped to your app or user.`; static args = { path: Args.string({ description: 'API endpoint path (must start with /)', required: true, }), }; static flags = { body: Flags.string({ description: 'Request body (inline JSON or file path)', }), live: Flags.boolean({ description: 'Use live environment instead of test', default: false, }), api: Flags.string({ description: 'Use frontend or backend API (frontend uses public key auth).', options: ['backend', 'frontend'], default: 'backend', }), header: headerFlag, }; static examples = [ 'swell api post /products --body \'{"name": "Product", "price": 100}\'', 'swell api post /products --body ./product.json', 'swell api post /functions/my-app/create-order --body \'{"items":["sku-1"]}\'', `swell api post /functions/my-app/webhook --body @./payload.json -H 'Stripe-Signature: t=123,v1=abc'`, `swell api post /products --body '{"name": "Product"}' --api frontend`, ]; get method() { return HttpMethod.POST; } async run() { await this.request(ApiPost); } }