chore: 初始化 TypeScript monorepo
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "@drift/contracts",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": "./src/index.ts",
|
||||
"scripts": {
|
||||
"test": "vitest run src/index.test.ts"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { ErrorCode, ok } from "./index";
|
||||
|
||||
describe("contracts", () => {
|
||||
it("creates the uniform response envelope", () => {
|
||||
expect(ok({ id: "1" }, "req-1")).toEqual({
|
||||
code: ErrorCode.OK,
|
||||
message: "success",
|
||||
data: { id: "1" },
|
||||
requestId: "req-1",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
export enum ErrorCode {
|
||||
OK = "OK",
|
||||
AUTH_TOKEN_EXPIRED = "AUTH_TOKEN_EXPIRED",
|
||||
AUTH_REFRESH_REUSED = "AUTH_REFRESH_REUSED",
|
||||
BOTTLE_DAILY_LIMIT = "BOTTLE_DAILY_LIMIT",
|
||||
BOTTLE_POOL_EMPTY = "BOTTLE_POOL_EMPTY",
|
||||
BOTTLE_LEASE_EXPIRED = "BOTTLE_LEASE_EXPIRED",
|
||||
CONTENT_REJECTED = "CONTENT_REJECTED",
|
||||
USER_BLOCKED = "USER_BLOCKED",
|
||||
CONVERSATION_FORBIDDEN = "CONVERSATION_FORBIDDEN",
|
||||
MESSAGE_DUPLICATE = "MESSAGE_DUPLICATE",
|
||||
}
|
||||
|
||||
export const ok = <T>(data: T, requestId: string) => ({
|
||||
code: ErrorCode.OK,
|
||||
message: "success",
|
||||
data,
|
||||
requestId,
|
||||
});
|
||||
Reference in New Issue
Block a user