@stripe/extensibility-custom-objects
v0.8.0
Published
TypeScript decorators and runtime for defining Stripe custom objects.
Maintainers
Keywords
Readme
@stripe/extensibility-custom-objects
TypeScript decorators and runtime for defining Stripe custom objects.
Installation
npm install @stripe/extensibility-custom-objects
npm install --save-dev @stripe/extensibility-custom-objects-toolsQuick Start
Define a custom object using the two-class pattern — a fields class for data and an outer class for behavior:
import { CustomObject, CustomFields, Action } from '@stripe/extensibility-custom-objects';
import { Field } from '@stripe/extensibility-jsonschema';
@CustomFields
export class ShipmentFields {
/** @primaryField @displayName Tracking Number */
trackingNumber!: string;
/** @secondaryField @displayName Delivered */
delivered!: boolean;
/** @displayName Weight (lbs) */
weightInLbs: number = 0;
}
/**
* @apiName shipment
* @displayName Shipment
*/
@CustomObject
export class Shipment extends BaseObject<ShipmentFields> {
/**
* @apiName mark_delivered
* @displayName Mark Delivered
*/
@Action
async markDelivered(): Promise<void> {
this.data.delivered = true;
await this.save();
}
/** @apiName export_manifest */
@Action
async exportManifest(): Promise<string> {
return `${this.data.trackingNumber}: ${this.data.weightInLbs}lbs`;
}
}Build your code:
custom-objects-build --input src --output distSee Custom Object DSL Reference for full documentation.
