Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Request Stamping Functionality to Server and Browser SDK #410

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/chilled-vans-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@turnkey/sdk-browser": minor
"@turnkey/sdk-server": minor
---

Added functionality for constructing and returning stamped requests for all packages
18 changes: 17 additions & 1 deletion packages/sdk-browser/scripts/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ const generateSDKClientFromSwagger = async (swaggerSpec, targetPath) => {
const imports = [];

imports.push(
'import { TERMINAL_ACTIVITY_STATUSES, TActivityResponse, TActivityStatus } from "@turnkey/http";'
'import { TERMINAL_ACTIVITY_STATUSES, TActivityResponse, TActivityStatus, TSignedRequest } from "@turnkey/http";'
);

imports.push(
Expand Down Expand Up @@ -451,6 +451,22 @@ export class TurnkeySDKClientBase {
}`
);
}
// generate a stamping method for each method
codeBuffer.push(
`\n\tstamp${operationNameWithoutNamespace} = async (input: SdkApiTypes.${inputType}): Promise<TSignedRequest | undefined> => {
if (!this.config.stamper) {
return undefined;
}
const fullUrl = this.config.apiBaseUrl + "${endpointPath}";
const body = JSON.stringify(input);
const stamp = await this.config.stamper.stamp(body);
return {
body: body,
stamp: stamp,
url: fullUrl,
};
}`
);
}

// End of the TurnkeySDKClient Class Definition
Expand Down
Loading
Loading