@sparkrewards/srw-sdk
v0.1.1
Published
@sparkrewards/srw-sdk server
Readme
@sparkrewards/srw-sdk
TypeScript server-side SDK for the Spark Rewards Website (SRW) API, generated from the Smithy service model. It contains:
- Strongly typed request/response models for all operations.
- Operation handlers and service interfaces to implement the API.
- A generated OpenAPI JSON export (
OpenApiJSON) that can be used with tooling like CDK.
Installation
npm install @sparkrewards/srw-sdk
# or
yarn add @sparkrewards/srw-sdkBasic usage
import {
BusinessAPIService,
getBusinessAPIServiceHandler,
} from "@sparkrewards/srw-sdk";
const service: BusinessAPIService<unknown> = {
async GetUser(input, ctx) {
// implement your business logic here
return {
message: "ok",
user: {
// ... user fields ...
},
};
},
// implement other operations...
};
export const handler = getBusinessAPIServiceHandler(service);OpenAPI export
The server SDK also exports the OpenAPI specification for the Spark Rewards Website (SRW) API:
import { OpenApiJSON } from "@sparkrewards/srw-sdk";
console.log(OpenApiJSON.openapi); // "3.1.0"This is used by the CDK stack to configure API Gateway.
Regenerating from the Smithy model
This package is generated by the typescript-ssdk-codegen Smithy plugin. To regenerate it:
./gradlew :smithy:smithyBuildThe generated package lives under:
smithy/build/smithyprojections/smithy/source/typescript-ssdk-codegen
