@sparkrewards/sra-sdk
v0.0.4
Published
@sparkrewards/sra-sdk server
Downloads
572
Readme
@sparkrewards/app-api-server-sdk
TypeScript server-side SDK for the Spark Rewards App 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/app-api-server-sdk
# or
yarn add @sparkrewards/app-api-server-sdkBasic usage
import {
AppAPIService,
getAppAPIServiceHandler,
} from "@sparkrewards/app-api-server-sdk";
const service: AppAPIService<unknown> = {
async GetUser(input, ctx) {
// implement your business logic here
return {
message: "ok",
user: {
// ... user fields ...
},
};
},
// implement other operations...
};
export const handler = getAppAPIServiceHandler(service);OpenAPI export
The server SDK also exports the OpenAPI specification for the App API:
import { OpenApiJSON } from "@sparkrewards/app-api-server-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
