feat: implement JWT token provider with access and refresh token generation

This commit is contained in:
2026-03-11 19:01:23 +07:00
parent dc06412f79
commit 9276603a70
19 changed files with 3749 additions and 42 deletions

View File

@@ -0,0 +1,719 @@
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
// protoc-gen-ts_proto v2.11.4
// protoc unknown
// source: v1/common.proto
/* eslint-disable */
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
import { Timestamp } from "../google/protobuf/timestamp";
export const protobufPackage = "stream.common.v1";
export interface RequestContext {
userId?: string | undefined;
email?: string | undefined;
role?: string | undefined;
requestId?: string | undefined;
source?: string | undefined;
}
export interface PaginationRequest {
page?: number | undefined;
pageSize?: number | undefined;
}
export interface PaginationResponse {
page?: number | undefined;
pageSize?: number | undefined;
total?: number | undefined;
}
export interface Money {
amount?: number | undefined;
currency?: string | undefined;
}
export interface Empty {
}
export interface IdRequest {
id?: string | undefined;
}
export interface DeleteResponse {
message?: string | undefined;
}
export interface TimestampRange {
from?: string | undefined;
to?: string | undefined;
}
function createBaseRequestContext(): RequestContext {
return { userId: "", email: "", role: "", requestId: "", source: "" };
}
export const RequestContext: MessageFns<RequestContext> = {
encode(message: RequestContext, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.userId !== undefined && message.userId !== "") {
writer.uint32(10).string(message.userId);
}
if (message.email !== undefined && message.email !== "") {
writer.uint32(18).string(message.email);
}
if (message.role !== undefined && message.role !== "") {
writer.uint32(26).string(message.role);
}
if (message.requestId !== undefined && message.requestId !== "") {
writer.uint32(34).string(message.requestId);
}
if (message.source !== undefined && message.source !== "") {
writer.uint32(42).string(message.source);
}
return writer;
},
decode(input: BinaryReader | Uint8Array, length?: number): RequestContext {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
const end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseRequestContext();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
if (tag !== 10) {
break;
}
message.userId = reader.string();
continue;
}
case 2: {
if (tag !== 18) {
break;
}
message.email = reader.string();
continue;
}
case 3: {
if (tag !== 26) {
break;
}
message.role = reader.string();
continue;
}
case 4: {
if (tag !== 34) {
break;
}
message.requestId = reader.string();
continue;
}
case 5: {
if (tag !== 42) {
break;
}
message.source = reader.string();
continue;
}
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skip(tag & 7);
}
return message;
},
fromJSON(object: any): RequestContext {
return {
userId: isSet(object.userId)
? globalThis.String(object.userId)
: isSet(object.user_id)
? globalThis.String(object.user_id)
: "",
email: isSet(object.email) ? globalThis.String(object.email) : "",
role: isSet(object.role) ? globalThis.String(object.role) : "",
requestId: isSet(object.requestId)
? globalThis.String(object.requestId)
: isSet(object.request_id)
? globalThis.String(object.request_id)
: "",
source: isSet(object.source) ? globalThis.String(object.source) : "",
};
},
toJSON(message: RequestContext): unknown {
const obj: any = {};
if (message.userId !== undefined && message.userId !== "") {
obj.userId = message.userId;
}
if (message.email !== undefined && message.email !== "") {
obj.email = message.email;
}
if (message.role !== undefined && message.role !== "") {
obj.role = message.role;
}
if (message.requestId !== undefined && message.requestId !== "") {
obj.requestId = message.requestId;
}
if (message.source !== undefined && message.source !== "") {
obj.source = message.source;
}
return obj;
},
create<I extends Exact<DeepPartial<RequestContext>, I>>(base?: I): RequestContext {
return RequestContext.fromPartial(base ?? ({} as any));
},
fromPartial<I extends Exact<DeepPartial<RequestContext>, I>>(object: I): RequestContext {
const message = createBaseRequestContext();
message.userId = object.userId ?? "";
message.email = object.email ?? "";
message.role = object.role ?? "";
message.requestId = object.requestId ?? "";
message.source = object.source ?? "";
return message;
},
};
function createBasePaginationRequest(): PaginationRequest {
return { page: 0, pageSize: 0 };
}
export const PaginationRequest: MessageFns<PaginationRequest> = {
encode(message: PaginationRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.page !== undefined && message.page !== 0) {
writer.uint32(8).int32(message.page);
}
if (message.pageSize !== undefined && message.pageSize !== 0) {
writer.uint32(16).int32(message.pageSize);
}
return writer;
},
decode(input: BinaryReader | Uint8Array, length?: number): PaginationRequest {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
const end = length === undefined ? reader.len : reader.pos + length;
const message = createBasePaginationRequest();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
if (tag !== 8) {
break;
}
message.page = reader.int32();
continue;
}
case 2: {
if (tag !== 16) {
break;
}
message.pageSize = reader.int32();
continue;
}
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skip(tag & 7);
}
return message;
},
fromJSON(object: any): PaginationRequest {
return {
page: isSet(object.page) ? globalThis.Number(object.page) : 0,
pageSize: isSet(object.pageSize)
? globalThis.Number(object.pageSize)
: isSet(object.page_size)
? globalThis.Number(object.page_size)
: 0,
};
},
toJSON(message: PaginationRequest): unknown {
const obj: any = {};
if (message.page !== undefined && message.page !== 0) {
obj.page = Math.round(message.page);
}
if (message.pageSize !== undefined && message.pageSize !== 0) {
obj.pageSize = Math.round(message.pageSize);
}
return obj;
},
create<I extends Exact<DeepPartial<PaginationRequest>, I>>(base?: I): PaginationRequest {
return PaginationRequest.fromPartial(base ?? ({} as any));
},
fromPartial<I extends Exact<DeepPartial<PaginationRequest>, I>>(object: I): PaginationRequest {
const message = createBasePaginationRequest();
message.page = object.page ?? 0;
message.pageSize = object.pageSize ?? 0;
return message;
},
};
function createBasePaginationResponse(): PaginationResponse {
return { page: 0, pageSize: 0, total: 0 };
}
export const PaginationResponse: MessageFns<PaginationResponse> = {
encode(message: PaginationResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.page !== undefined && message.page !== 0) {
writer.uint32(8).int32(message.page);
}
if (message.pageSize !== undefined && message.pageSize !== 0) {
writer.uint32(16).int32(message.pageSize);
}
if (message.total !== undefined && message.total !== 0) {
writer.uint32(24).int64(message.total);
}
return writer;
},
decode(input: BinaryReader | Uint8Array, length?: number): PaginationResponse {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
const end = length === undefined ? reader.len : reader.pos + length;
const message = createBasePaginationResponse();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
if (tag !== 8) {
break;
}
message.page = reader.int32();
continue;
}
case 2: {
if (tag !== 16) {
break;
}
message.pageSize = reader.int32();
continue;
}
case 3: {
if (tag !== 24) {
break;
}
message.total = longToNumber(reader.int64());
continue;
}
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skip(tag & 7);
}
return message;
},
fromJSON(object: any): PaginationResponse {
return {
page: isSet(object.page) ? globalThis.Number(object.page) : 0,
pageSize: isSet(object.pageSize)
? globalThis.Number(object.pageSize)
: isSet(object.page_size)
? globalThis.Number(object.page_size)
: 0,
total: isSet(object.total) ? globalThis.Number(object.total) : 0,
};
},
toJSON(message: PaginationResponse): unknown {
const obj: any = {};
if (message.page !== undefined && message.page !== 0) {
obj.page = Math.round(message.page);
}
if (message.pageSize !== undefined && message.pageSize !== 0) {
obj.pageSize = Math.round(message.pageSize);
}
if (message.total !== undefined && message.total !== 0) {
obj.total = Math.round(message.total);
}
return obj;
},
create<I extends Exact<DeepPartial<PaginationResponse>, I>>(base?: I): PaginationResponse {
return PaginationResponse.fromPartial(base ?? ({} as any));
},
fromPartial<I extends Exact<DeepPartial<PaginationResponse>, I>>(object: I): PaginationResponse {
const message = createBasePaginationResponse();
message.page = object.page ?? 0;
message.pageSize = object.pageSize ?? 0;
message.total = object.total ?? 0;
return message;
},
};
function createBaseMoney(): Money {
return { amount: 0, currency: "" };
}
export const Money: MessageFns<Money> = {
encode(message: Money, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.amount !== undefined && message.amount !== 0) {
writer.uint32(9).double(message.amount);
}
if (message.currency !== undefined && message.currency !== "") {
writer.uint32(18).string(message.currency);
}
return writer;
},
decode(input: BinaryReader | Uint8Array, length?: number): Money {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
const end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseMoney();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
if (tag !== 9) {
break;
}
message.amount = reader.double();
continue;
}
case 2: {
if (tag !== 18) {
break;
}
message.currency = reader.string();
continue;
}
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skip(tag & 7);
}
return message;
},
fromJSON(object: any): Money {
return {
amount: isSet(object.amount) ? globalThis.Number(object.amount) : 0,
currency: isSet(object.currency) ? globalThis.String(object.currency) : "",
};
},
toJSON(message: Money): unknown {
const obj: any = {};
if (message.amount !== undefined && message.amount !== 0) {
obj.amount = message.amount;
}
if (message.currency !== undefined && message.currency !== "") {
obj.currency = message.currency;
}
return obj;
},
create<I extends Exact<DeepPartial<Money>, I>>(base?: I): Money {
return Money.fromPartial(base ?? ({} as any));
},
fromPartial<I extends Exact<DeepPartial<Money>, I>>(object: I): Money {
const message = createBaseMoney();
message.amount = object.amount ?? 0;
message.currency = object.currency ?? "";
return message;
},
};
function createBaseEmpty(): Empty {
return {};
}
export const Empty: MessageFns<Empty> = {
encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
return writer;
},
decode(input: BinaryReader | Uint8Array, length?: number): Empty {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
const end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseEmpty();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skip(tag & 7);
}
return message;
},
fromJSON(_: any): Empty {
return {};
},
toJSON(_: Empty): unknown {
const obj: any = {};
return obj;
},
create<I extends Exact<DeepPartial<Empty>, I>>(base?: I): Empty {
return Empty.fromPartial(base ?? ({} as any));
},
fromPartial<I extends Exact<DeepPartial<Empty>, I>>(_: I): Empty {
const message = createBaseEmpty();
return message;
},
};
function createBaseIdRequest(): IdRequest {
return { id: "" };
}
export const IdRequest: MessageFns<IdRequest> = {
encode(message: IdRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.id !== undefined && message.id !== "") {
writer.uint32(10).string(message.id);
}
return writer;
},
decode(input: BinaryReader | Uint8Array, length?: number): IdRequest {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
const end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseIdRequest();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
if (tag !== 10) {
break;
}
message.id = reader.string();
continue;
}
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skip(tag & 7);
}
return message;
},
fromJSON(object: any): IdRequest {
return { id: isSet(object.id) ? globalThis.String(object.id) : "" };
},
toJSON(message: IdRequest): unknown {
const obj: any = {};
if (message.id !== undefined && message.id !== "") {
obj.id = message.id;
}
return obj;
},
create<I extends Exact<DeepPartial<IdRequest>, I>>(base?: I): IdRequest {
return IdRequest.fromPartial(base ?? ({} as any));
},
fromPartial<I extends Exact<DeepPartial<IdRequest>, I>>(object: I): IdRequest {
const message = createBaseIdRequest();
message.id = object.id ?? "";
return message;
},
};
function createBaseDeleteResponse(): DeleteResponse {
return { message: "" };
}
export const DeleteResponse: MessageFns<DeleteResponse> = {
encode(message: DeleteResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.message !== undefined && message.message !== "") {
writer.uint32(10).string(message.message);
}
return writer;
},
decode(input: BinaryReader | Uint8Array, length?: number): DeleteResponse {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
const end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseDeleteResponse();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
if (tag !== 10) {
break;
}
message.message = reader.string();
continue;
}
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skip(tag & 7);
}
return message;
},
fromJSON(object: any): DeleteResponse {
return { message: isSet(object.message) ? globalThis.String(object.message) : "" };
},
toJSON(message: DeleteResponse): unknown {
const obj: any = {};
if (message.message !== undefined && message.message !== "") {
obj.message = message.message;
}
return obj;
},
create<I extends Exact<DeepPartial<DeleteResponse>, I>>(base?: I): DeleteResponse {
return DeleteResponse.fromPartial(base ?? ({} as any));
},
fromPartial<I extends Exact<DeepPartial<DeleteResponse>, I>>(object: I): DeleteResponse {
const message = createBaseDeleteResponse();
message.message = object.message ?? "";
return message;
},
};
function createBaseTimestampRange(): TimestampRange {
return { from: undefined, to: undefined };
}
export const TimestampRange: MessageFns<TimestampRange> = {
encode(message: TimestampRange, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.from !== undefined) {
Timestamp.encode(toTimestamp(message.from), writer.uint32(10).fork()).join();
}
if (message.to !== undefined) {
Timestamp.encode(toTimestamp(message.to), writer.uint32(18).fork()).join();
}
return writer;
},
decode(input: BinaryReader | Uint8Array, length?: number): TimestampRange {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
const end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseTimestampRange();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
if (tag !== 10) {
break;
}
message.from = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
continue;
}
case 2: {
if (tag !== 18) {
break;
}
message.to = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
continue;
}
}
if ((tag & 7) === 4 || tag === 0) {
break;
}
reader.skip(tag & 7);
}
return message;
},
fromJSON(object: any): TimestampRange {
return {
from: isSet(object.from) ? globalThis.String(object.from) : undefined,
to: isSet(object.to) ? globalThis.String(object.to) : undefined,
};
},
toJSON(message: TimestampRange): unknown {
const obj: any = {};
if (message.from !== undefined) {
obj.from = message.from;
}
if (message.to !== undefined) {
obj.to = message.to;
}
return obj;
},
create<I extends Exact<DeepPartial<TimestampRange>, I>>(base?: I): TimestampRange {
return TimestampRange.fromPartial(base ?? ({} as any));
},
fromPartial<I extends Exact<DeepPartial<TimestampRange>, I>>(object: I): TimestampRange {
const message = createBaseTimestampRange();
message.from = object.from ?? undefined;
message.to = object.to ?? undefined;
return message;
},
};
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
export type DeepPartial<T> = T extends Builtin ? T
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;
type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
function toTimestamp(dateStr: string): Timestamp {
const date = new globalThis.Date(dateStr);
const seconds = Math.trunc(date.getTime() / 1_000);
const nanos = (date.getTime() % 1_000) * 1_000_000;
return { seconds, nanos };
}
function fromTimestamp(t: Timestamp): string {
let millis = (t.seconds || 0) * 1_000;
millis += (t.nanos || 0) / 1_000_000;
return new globalThis.Date(millis).toISOString();
}
function longToNumber(int64: { toString(): string }): number {
const num = globalThis.Number(int64.toString());
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
}
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}
export interface MessageFns<T> {
encode(message: T, writer?: BinaryWriter): BinaryWriter;
decode(input: BinaryReader | Uint8Array, length?: number): T;
fromJSON(object: any): T;
toJSON(message: T): unknown;
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}