Skip to content
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/api-contract",
"version": "0.1.10",
"version": "0.1.11",
"description": "API Contract for moneydevkit",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down
37 changes: 37 additions & 0 deletions src/contracts/onboarding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { oc } from "@orpc/contract";
import type { z } from "zod";
import {
BootstrapInputSchema,
BootstrapOutputSchema,
PollDeviceAuthInputSchema,
PollDeviceAuthOutputSchema,
StartDeviceAuthInputSchema,
StartDeviceAuthOutputSchema,
} from "../schemas/onboarding";

export type StartDeviceAuth = z.infer<typeof StartDeviceAuthInputSchema>;
export type StartDeviceAuthResponse = z.infer<
typeof StartDeviceAuthOutputSchema
>;
export type PollDeviceAuth = z.infer<typeof PollDeviceAuthInputSchema>;
export type PollDeviceAuthResponse = z.infer<typeof PollDeviceAuthOutputSchema>;
export type BootstrapOnboarding = z.infer<typeof BootstrapInputSchema>;
export type BootstrapOnboardingResponse = z.infer<typeof BootstrapOutputSchema>;

export const startDeviceAuthContract = oc
.input(StartDeviceAuthInputSchema)
.output(StartDeviceAuthOutputSchema);

export const pollDeviceAuthContract = oc
.input(PollDeviceAuthInputSchema)
.output(PollDeviceAuthOutputSchema);

export const bootstrapContract = oc
.input(BootstrapInputSchema)
.output(BootstrapOutputSchema);

export const onboarding = {
startDeviceAuth: startDeviceAuthContract,
pollDeviceAuth: pollDeviceAuthContract,
bootstrap: bootstrapContract,
};
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { checkout } from "./contracts/checkout";
import { onboarding } from "./contracts/onboarding";
export type {
StartDeviceAuth,
StartDeviceAuthResponse,
PollDeviceAuth,
PollDeviceAuthResponse,
BootstrapOnboarding,
BootstrapOnboardingResponse,
} from "./contracts/onboarding";

export type { StartDeviceAuth as StartDeviceAuthInput } from "./contracts/onboarding";
export { CheckoutSchema } from "./schemas/checkout";
export type {
CreateCheckout,
Expand All @@ -7,4 +18,5 @@ export type {
PaymentReceived,
} from "./contracts/checkout";
export type { Checkout } from "./schemas/checkout";
export const contract = { checkout };

export const contract = { checkout, onboarding };
54 changes: 54 additions & 0 deletions src/schemas/onboarding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { z } from "zod";

export const StartDeviceAuthInputSchema = z.object({
clientDisplayName: z.string().optional(),
webhookUrl: z.string().url().optional(),
forceNewWebhook: z.boolean().optional(),
});

export const StartDeviceAuthOutputSchema = z.object({
deviceCode: z.string(),
userCode: z.string(),
verificationUri: z.string().url(),
expiresIn: z.number().int().positive(),
interval: z.number().int().positive(),
});

export const PollDeviceAuthInputSchema = z.object({
deviceCode: z.string(),
});

export const PollDeviceAuthOutputSchema = z.discriminatedUnion("status", [
z.object({
status: z.literal("pending"),
expiresIn: z.number().int().nonnegative(),
}),
z.object({
status: z.literal("authorized"),
bootstrapToken: z.string(),
expiresIn: z.number().int().nonnegative().optional(),
}),
z.object({
status: z.literal("expired"),
}),
z.object({
status: z.literal("denied"),
}),
]);

export const BootstrapInputSchema = z.object({
bootstrapToken: z.string(),
webhookUrl: z.string().url().optional(),
projectName: z.string().optional(),
forceNewWebhook: z.boolean().optional(),
});

export const BootstrapOutputSchema = z.object({
apiKey: z.string(),
apiKeyPreview: z.string(),
apiKeyId: z.string(),
webhookId: z.string(),
webhookSecret: z.string(),
organizationId: z.string(),
webhookUrl: z.string().url(),
});